diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2017-05-20 11:18:45 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2017-05-20 11:18:45 +0200 |
commit | 4c59f7360514aa6c67ba2fbaa09d4cc9e3139957 (patch) | |
tree | a94058e9991cee41903e0685825faaa1f2c2074b | |
parent | e82a5474b7d50e313a3a9022841744914bdef78d (diff) | |
download | abaos-4c59f7360514aa6c67ba2fbaa09d4cc9e3139957.tar.gz abaos-4c59f7360514aa6c67ba2fbaa09d4cc9e3139957.tar.bz2 |
documented early GDT in assembly (following Nick Bundells osdev guide).
renamed gdt.asm to boot_gdt.asm (because later we will have a gdt.asm
when playing with memory managers and process isolation).
This boot sequence is for legacy machines, for UEFI and multiboot kernels
the whole thing looks different
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/README | 2 | ||||
-rw-r--r-- | src/boot_gdt.asm (renamed from src/gdt.asm) | 28 | ||||
-rw-r--r-- | src/switch_mode.asm | 5 |
4 files changed, 19 insertions, 18 deletions
diff --git a/src/Makefile b/src/Makefile index 34b1cb4..8507c72 100644 --- a/src/Makefile +++ b/src/Makefile @@ -19,7 +19,7 @@ image.bin: boot.bin kernel.bin magic.bin truncate -s 8192 image.tmp cat image.tmp magic.bin > image.bin -boot.bin: boot.asm gdt.asm stage1_functions.asm stage2_functions.asm switch_mode.asm +boot.bin: boot.asm boot_gdt.asm stage1_functions.asm stage2_functions.asm switch_mode.asm $(NASM) boot.asm -DMAGIC='"$(MAGIC)"' -f bin -o boot.bin kernel.bin: kernel.elf @@ -1,7 +1,7 @@ * boot.bin - boot sector (stage 1 and 2, total 2k), offset 0x7c00 * boot.asm - the main boot sector code using: * kernel.bin - linked kernel with fix start offset 0x8400 - * gdt.asm - the early GDT, flat memory model, no protection + * boot_gdt.asm - the early GDT, flat memory model, no protection * stage1_functions.asm - real mode functions of the bootloader * stage2_functions.asm - protected mode primitive VGA routines * switch_mode.asm - early GTD loading and switching from real to protected mode diff --git a/src/gdt.asm b/src/boot_gdt.asm index 15fe924..87e1585 100644 --- a/src/gdt.asm +++ b/src/boot_gdt.asm @@ -14,28 +14,28 @@ gdt_null: ; granularity: 4kb pages, 32-bit mode, no 64-bit segment, AVL would ; be for our own extensions gdt_code: - dw 0xffff - dw 0x0 - db 0x0 - db 10011010b - db 11001111b - db 0x0 + dw 0xffff ; limit (bits 0-15) + dw 0x0 ; base (bits 0-15) + db 0x0 ; base (bits 16-23) + db 10011010b ; flags + db 11001111b ; flags, limit (bits 16-19) + db 0x0 ; base (bit 24-31) ; flat model, same as code segment, but flags are ; flags: ring 0, gdt_data: - dw 0xffff - dw 0x0 - db 0x0 - db 10010010b - db 11001111b - db 0x0 + dw 0xffff ; limit (bits 0-15) + dw 0x0 ; base (bits 0-15) + db 0x0 ; base (bits 16-23) + db 10010010b ; flags + db 11001111b ; flags, limit (bits 16-19) + db 0x0 ; base (bit 24-31) gdt_end: gdt_descriptor: - dw gdt_end -gdt_start - 1 ; size - dd gdt_start ; start address of the GDT + dw gdt_end -gdt_start - 1 ; size + dd gdt_start ; start address of the GDT ; constants representing the segment bases CODE_SEGMENT equ gdt_code - gdt_start diff --git a/src/switch_mode.asm b/src/switch_mode.asm index bc38b5a..4082fda 100644 --- a/src/switch_mode.asm +++ b/src/switch_mode.asm @@ -1,6 +1,6 @@ [bits 16] -%include "gdt.asm" +%include "boot_gdt.asm" switch_to_protected_mode: ; switch off interrupts for now, we don't @@ -15,7 +15,8 @@ switch_to_protected_mode: or eax, 0x1 mov cr0, eax - ; unconditional far jump into code segment + ; unconditional far jump into code segment, + ; wipes the instruction prefetch pipeline jmp CODE_SEGMENT:init_pm [bits 32] |