Setting up a basic GDT

This commit is contained in:
Thomas Oltmann 2025-07-04 15:29:41 +02:00
parent 5fee8cbbcf
commit bc400a814b

View file

@ -4,24 +4,39 @@
.text
.code16
_start:
_start: cli
cld
mov %cs, %ax
mov %ax, %ds
push $message
mov $message, %si
call print
add $2, %sp
call enable_a20
lea message, %si
call print
lgdt gdt_ptr
call enter_prot
1: hlt
jmp 1b
print: push %bp
mov %sp, %bp
push %bx
push %si
xor %bx, %bx
mov 4(%bp), %si
enable_a20: // TODO more thorough implementation
inb $0x92, %al
or $2, %al
outb %al, $0x92
ret
enter_prot: mov %cr0, %eax
or $1, %al
mov %eax, %cr0
ret
print: xor %bx, %bx
1: lodsb
or %al, %al
@ -30,10 +45,31 @@ print: push %bp
int $0x10
jmp 1b
2: pop %si
pop %bx
mov %bp, %sp
pop %bp
ret
2: ret
message: .asciz "Hello, World!"
gdt: // entry 0: null descriptor
.word 0
.word 0
.byte 0
.byte 0
.byte 0
.byte 0
// entry 1: code segment
.word 0xFFFF
.word 0
.byte 0
.byte 0b10011010
.byte 0x8F
.byte 0
// entry 2: data segment
.word 0xFFFF
.word 0
.byte 0
.byte 0b10010010
.byte 0x8F
.byte 0
.set gdt_size, .-gdt
gdt_ptr: .word gdt_size-1
.long gdt
message: .asciz "Hello, World!\r\n"