Code: Select all
.intel_syntax noprefix
.extern thegdtptr #it is a struct in another file
.global gdt_flush
.type gdt_flush, @function
gdt_flush:
lgdt [thegdtptr] # should load our GDT ptr!
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:Section2
Section2:
ret
Now, I decided it would be neat if I could just pass the gdt pointer struct to gdt_flush like in any other function. So I changed it to this:
Code: Select all
.intel_syntax noprefix
.extern thegdtptr #it is a struct in another file; this time I just forgot to take it out; decided to keep it in this post for the sake of accuracy
.global gdt_flush
.type gdt_flush, @function
gdt_flush:
lgdt [esp] # should load our GDT ptr!
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:Section2
Section2:
ret
Now, from what I understand, the struct should be in the range from address "esp" to "esp + 6", since the GDT pointer struct is 48 bits long. So, it should load just fine, correct? However, the new code caused a triple fault as soon as I attempted to reload the registers, so obviously I am loading from the stack incorrectly. I tried adding 6 to esp in the lgdt instruction, but that triple faulted too. So, can someone clear things up for me please?