Page 1 of 1

LDT load causing GPF

Posted: Tue Jul 03, 2007 3:54 pm
by mmiikkee12
Whenever I try to switch tasks, I get a GPF with error code 0x18. I set up my LDT in the GDT with type 2, granularity bit 0, base as the start address of my LDT, and limit as size of the ldt - 1.

Code: Select all

extern old_esp
global _irq0
_irq0:
	pusha
	pushf
	mov eax, [old_esp]
	mov [eax], esp
	jmp isr32

Code: Select all

; The old esp is saved by the interrupt handler.
extern current_esp, current_ldt
global do_task_switch
do_task_switch:
	mov esp, [current_esp]
	popf
	popa
	lldt [current_ldt]
	iret
current_esp and current_ldt are definitely getting set correctly.

Also, when I tried 0x03 instead of 0x18 for the LDT selector, it loaded the LDT without a crash, but then GPFed again when I tried to set CS to 0x04. I used the same flags for the LDT's code segment as I did for the GDT's one at 0x08.