diff options
Diffstat (limited to 'src/boot')
| -rw-r--r-- | src/boot/boot.stage1.asm | 50 | ||||
| -rw-r--r-- | src/boot/boot.stage1.print.asm | 21 | ||||
| -rw-r--r-- | src/boot/boot.stage2.a20.asm | 4 | ||||
| -rw-r--r-- | src/boot/boot.stage2.asm | 5 | ||||
| -rw-r--r-- | src/boot/boot.stage2.gdt32.asm | 6 | ||||
| -rw-r--r-- | src/boot/boot.stage2.pm.asm | 20 |
6 files changed, 61 insertions, 45 deletions
diff --git a/src/boot/boot.stage1.asm b/src/boot/boot.stage1.asm index 801860e..5fa3b7a 100644 --- a/src/boot/boot.stage1.asm +++ b/src/boot/boot.stage1.asm @@ -1,11 +1,11 @@ ;; boot.stage1.asm - %include "boot.common.asm" - %include "boot.stage1.print.asm" [org 0x7c00] [bits 16] - %define READ_SECTORS_NUM 64 + %include "boot.common.asm" + + %define READ_SECTORS_NUM 1 %define BOOT_LOAD_ADDR 0x7c00 %define SECTOR_SIZE 512 @@ -26,9 +26,10 @@ _start: clc + mov [drive], dl mov si, disk_addr_packet mov ah, 0x42 ; BIOS extended read function - mov dl, 0x80 ; Drive number + mov dl, [drive] ; Drive number int 0x13 ; BIOS disk services jc _disk_read_err @@ -44,21 +45,38 @@ _disk_read_err: hlt jmp _disk_read_err +_print_string: + pusha + mov ah, 0x0e + mov bh, 0x00 + +.print_loop: + lodsb + test al, al + je .print_return + int 0x10 + jmp .print_loop + +.print_return: + popa + ret + _end: - hlt - jmp _end + hlt + jmp _end +drive: db 0 disk_read_err_msg: db "Failed to read disk", 13, 10, 0 disk_read_success_msg: db "Read the disk successfully", 13, 10, 0 disk_addr_packet: - db 0x10 - db 0x00 - dw READ_SECTORS_NUM - dw 0x0000 - dw 0x7e00 - dq 1 + db 0x10 + db 0x00 + dw READ_SECTORS_NUM + dw 0x7e00 + dw 0x0000 + dq 1 - ;; Padding and magic number - times 510 - ($ - $$) db 0 - dw 0xaa55 - + ;; Padding and magic number + times 510 - ($ - $$) db 0 + dw 0xaa55 + diff --git a/src/boot/boot.stage1.print.asm b/src/boot/boot.stage1.print.asm deleted file mode 100644 index aff2e0d..0000000 --- a/src/boot/boot.stage1.print.asm +++ /dev/null @@ -1,21 +0,0 @@ - ;; boot.stage1.print.asm - - [bits 16] -_print_string: - pusha - mov ah, 0x0e - -_print_string_loop: - cmp byte [bx], 0 - je _print_string_return - - mov al, [bx] - int 0x10 - - inc bx - jmp _print_string_loop - -_print_string_return: - popa - ret - align 4 diff --git a/src/boot/boot.stage2.a20.asm b/src/boot/boot.stage2.a20.asm index 6a9c250..8fa3d37 100644 --- a/src/boot/boot.stage2.a20.asm +++ b/src/boot/boot.stage2.a20.asm @@ -22,7 +22,7 @@ _enable_a20: .halt: hlt jmp .halt - .end + .end: ret _check_a20: @@ -143,5 +143,5 @@ _enable_a20_io92: or al, 2 and al, 0xfe out 0x92, al - .end + .end: ret diff --git a/src/boot/boot.stage2.asm b/src/boot/boot.stage2.asm index 56ab73a..8f4885b 100644 --- a/src/boot/boot.stage2.asm +++ b/src/boot/boot.stage2.asm @@ -5,7 +5,10 @@ %include "boot.stage2.a20.asm" %include "boot.stage2.pm.asm" + + %define KERNEL_OFFSET 0x1000 _s2_entry: call _enable_a20 - call _enter_pm + call _enable_pm [bits 32] + diff --git a/src/boot/boot.stage2.gdt32.asm b/src/boot/boot.stage2.gdt32.asm index f9f27a5..f766d82 100644 --- a/src/boot/boot.stage2.gdt32.asm +++ b/src/boot/boot.stage2.gdt32.asm @@ -1,4 +1,4 @@ -y ;; boot.stage2.gdt32.asm + ;; boot.stage2.gdt32.asm GDT32: @@ -25,5 +25,5 @@ GDT32_ptr: .limit: dw GDT32_end - GDT32 - 1 .base: dd GDT32 - CODE_SEG32 equ gdt32_code_segment - gdt32_start - DATA_SEG32 equ gdt32_data_segment - gdt32_start + CODE_SEG32 equ GDT32.code - GDT32 + DATA_SEG32 equ GDT32.data - GDT32 diff --git a/src/boot/boot.stage2.pm.asm b/src/boot/boot.stage2.pm.asm index 77f5f61..8897be6 100644 --- a/src/boot/boot.stage2.pm.asm +++ b/src/boot/boot.stage2.pm.asm @@ -4,9 +4,25 @@ [bits 16] %include "boot.stage2.gdt32.asm" -_ +_enable_pm: cli lgdt [GDT32_ptr] - ;; Enable Protected Mode + mov eax, cr0 + or eax, 1 + mov cr0, eax + + jmp CODE_SEG32:_protected_mode + +[bits 32] +_protected_mode: + mov ax, DATA_SEG32 + mov ds, ax + mov ss, ax + mov es, ax + mov fs, ax + mov gs, ax + + ret + |
