Skip to content

Commit

Permalink
Finally correct calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
firatkucuk committed Oct 25, 2018
1 parent b6a57ee commit 5d05f4f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 73 deletions.
25 changes: 25 additions & 0 deletions MEMORY_MAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
```
--------------------------------------------------------------------------------------------------------------------------
| Low Memory (the first MiB) |
--------------------------------------------------------------------------------------------------------------------------
| 0x00000000 | 0x000003FF | 1 KiB | RAM - partially unusable | Real Mode IVT |
| | | | | (Interrupt Vector Table) |
--------------------------------------------------------------------------------------------------------------------------
| 0x00000400 | 0x000004FF | 256 bytes | RAM - partially unusable | BDA (BIOS data area) |
--------------------------------------------------------------------------------------------------------------------------
| 0x00000500 | 0x00007BFF | almost 30 KiB | RAM (guaranteed free for use) | Conventional memory |
--------------------------------------------------------------------------------------------------------------------------
| 0x00007C00 | 0x00007DFF | 512 bytes | RAM - partially unusable | Your OS BootSector |
| (typical location) | | | | |
--------------------------------------------------------------------------------------------------------------------------
| 0x00007E00 | 0x0007FFFF | 480.5 KiB | RAM (guaranteed free for use) | Conventional memory |
--------------------------------------------------------------------------------------------------------------------------
| 0x00080000 | 0x0009FBFF | approximately 120 KiB, | RAM (free for use, if it exists) | Conventional memory |
| | | depending on EBDA size | | |
--------------------------------------------------------------------------------------------------------------------------
| 0x0009FC00 | 0x0009FFFF | 1 KiB | RAM (unusable) | EBDA (Extended BIOS |
| (typical location) | | | | Data Area) |
--------------------------------------------------------------------------------------------------------------------------
| 0x000A0000 | 0x000FFFFF | 384 KiB | various (unusable) | Video memory, ROM Area |
--------------------------------------------------------------------------------------------------------------------------
```
80 changes: 13 additions & 67 deletions bootloader.asm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ BITS 16


; ------------------------------------------------------------------------------
; Start Section
start:
jmp main ; jump over BIOS Parameter Block
nop ; No Operation Instruction for 3 bytes
Expand All @@ -31,7 +32,6 @@ db 'POTATOS1'
; ------------------------------------------------------------------------------
; BIOS Parameter Block


dw 0x0200 ; Bytes per Sector 200h (512)
db 0x01 ; Sector(s) per Cluster
dw 0x0001 ; Reserved sector count
Expand All @@ -51,6 +51,8 @@ db 'FAT12', 0x20, 0x20, 0x20 ; File System ID (8 Bytes)


; ------------------------------------------------------------------------------
; Main Section

main:
; Set data segment to where we're loaded so we can use lodsb instruction and
; variables without any modification
Expand All @@ -62,16 +64,20 @@ main:
mov es, ax
mov bx, 0x0000 ; Offset
mov ah, 0x02 ; INT 13h / AH = 02h
mov al, 0x24 ; Number of sectors to be read
mov ch, 0x00 ; Cylinder number
mov cl, 0x12 ; Sector number
mov dh, 0x00 ; Head number
mov al, 0x01 ; Number of sectors to be read
mov dl, 0x00 ; Drive number
mov ch, 0x00 ; Cylinder number
mov dh, 0x01 ; Head number
mov cl, 0x11 ; Sector number
int 0x13

jc .error_message ; jump if clear flag set

jmp 0x2400 ; Diff between A000 - 7C00
mov ax, KERNEL_LOAD_SEGMENT ; Set data segment to where we're loaded
mov ds, ax

jmp 0x200 ; Diff between 7E00 - 7C00
; Jump to the kernel

.error_message:
mov si, error_text ; Put string position into SI
Expand All @@ -84,6 +90,7 @@ main:



; print string routine
; ------------------------------------------------------------------------------
print_string: ; Routine: output string in SI to screen
mov ah, 0Eh ; int 10h 'print char' function
Expand All @@ -100,64 +107,3 @@ print_string: ; Routine: output string in SI to screen

times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC boot signature

; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------

; mov ax, 07C0h ; Set up 4K stack space after this bootloader
; add ax, 512 ; (4096 + 512) / 16 bytes per paragraph
; mov ss, ax
; mov sp, 4096

; mov ax, 07C0h ; Set data segment to where we're loaded
; mov ds, ax

; mov ah, 0 ; Set video mode function for int 10h
; mov al, 12h ; Video graphics mode 640x480 16-color
; int 10h

; mov si, text_string ; Put string position into SI
; call print_string ; Call our string-printing routine

; .next_line:
; mov si, prompt
; call print_string
; .infinite:
; mov ah, 0 ; Character input service for kbd int.
; int 16h ; Keyboard interrupt puts key in al

; cmp al, `\r` ; Check for carriage return (enter key)
; je .next_line

; mov ah, 0Eh
; add bl, 01h ; change color
; int 0x10

; jmp .infinite ; Jump here - infinite loop!

; text_string db 'PotatOS 1.3', 0
; prompt db `\r`, `\n`, ' $ ', 0 ; "$ " on the start of a new line



; print_string: ; Routine: output string in SI to screen
; mov bl, 01h ; first color in the palette

; .repeat
; lodsb ; Get character from string (source segment)
; cmp al, 0
; je .done ; If char is zero, end of string

; mov ah, 0Eh ; int 10h 'print char' function TTY mode
; add bl, 01h ; change color
; int 10h ; Otherwise, print it

; jmp .repeat

; .done:
; ret


; times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
; dw 0xAA55 ; The standard PC boot signature
9 changes: 3 additions & 6 deletions kernel.asm
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
; CONSTANTS

%define KERNEL_START_SEGMENT 0x0A00
BITS 16



; ------------------------------------------------------------------------------
; Main Section
main:
mov ax, KERNEL_START_SEGMENT ; Set data segment to where we're loaded
mov ds, ax

mov si, message ; Put string position into SI
call print_string ; Call our string-printing routine

Expand All @@ -20,6 +16,7 @@ main:


; ------------------------------------------------------------------------------
; Print Routine
print_string: ; Routine: output string in SI to screen
mov ah, 0Eh ; int 10h 'print char' function

Expand Down

0 comments on commit 5d05f4f

Please sign in to comment.