Installing GDT - Request For Review
Posted: Wed Feb 23, 2022 2:40 am
Hi,
I wrote this boot.S file using information I gathered from different sources (mostly osdev wiki). It is supposed to set up very basic GDT right after being booted by GRUB. I intend to use this GDT until I set up paging. It seems to be working so far, at least it is not crashing. I would like to know what you think about it:
I wrote this boot.S file using information I gathered from different sources (mostly osdev wiki). It is supposed to set up very basic GDT right after being booted by GRUB. I intend to use this GDT until I set up paging. It seems to be working so far, at least it is not crashing. I would like to know what you think about it:
Code: Select all
/* Constants */
.set ALIGN, 1 /* Page Alignment */
.set MEMINFO, 1<<1 /* Provide Meminfo */
.set FLAGS, ALIGN | MEMINFO
.set MAGIC, 0x1BADB002
.set CHECKSUM, -(MAGIC + FLAGS)
.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM
.section .bss
.align 16
_stack_bottom:
.skip 16384
_stack_top:
.section .text
.global _start
.type _start, @function
_start:
// LOAD GDT
lgdt (gdtr)
// refresh segment registers
jmp $0x08,$_reload_segment_registers // for CS
_reload_segment_registers:
mov $0x10, %cx
mov %cx,%ds
mov %cx,%es
mov %cx,%fs
mov %cx,%gs
mov %cx,%ss
mov $_stack_top, %esp
// Save ebx and eax so _init doesnt trash it
push %ebx
push %eax
call _init /* Global Constructors */
// TODO: Install IDT Here
call kernel_main
sleep:
hlt
jmp sleep
.size _start, . - _start
.section .rodata
.align 4
gdt:
.long 0x0 // null descriptor
.long 0x0
.long 0xFFFF // kernel mode code segment
.long 0xC09A00
.long 0xFFFF // kernel mode data segment
.long 0xC09200
gdtr:
.word . - gdt - 1 // limit
.long gdt // base