LTR causes #GP
Posted: Wed Jun 02, 2021 1:32 pm
I'm currently working on dispatcher. I've already implemented few things like switching stack, address space, segment registers, restoring registers etc. Now I'm trying to implement user mode. I'm using our wiki's tutorial for this (https://wiki.osdev.org/Getting_to_Ring_3), except that I'm doing this in long mode so I have 64bit TSS, different iret stack frame etc. (I want to use the iret method).
I really don't know why LTR gives me #GP.
Here's the code:
Saved rip (in #GP handler) points to "ltr ax" instruction.
Here's my TSS:
access = 0xE9 = 11101001 =
accessed: 1
read_write: 0
conforming_expand_down: 0
code: 1
code_data_segment: 0
DPL: 3 = 11
present: 1
Here you have my whole GDT:
I really don't know why LTR gives me #GP.
Here's the code:
Code: Select all
mov ax, (5 * 8) | 3
ltr ax
Here's my TSS:
Code: Select all
tss = {
limit_low = 0x1000, base_low = 0x5000, base_middle = 0x11,
access = 0xe9, granularity = 0x0, base_high = 0x0}
accessed: 1
read_write: 0
conforming_expand_down: 0
code: 1
code_data_segment: 0
DPL: 3 = 11
present: 1
Here you have my whole GDT:
Code: Select all
{null = {limit_low = 0xffff, base_low = 0x0, base_middle = 0x0,
access = 0x0, granularity = 0x1, base_high = 0x0}, code0 = {
limit_low = 0x0, base_low = 0x0, base_middle = 0x0, access = 0x9a,
granularity = 0xaf, base_high = 0x0}, data0 = {limit_low = 0x0,
base_low = 0x0, base_middle = 0x0, access = 0x93, granularity = 0x8f,
base_high = 0x0}, code3 = {limit_low = 0x0, base_low = 0x0,
base_middle = 0x0, access = 0xfa, granularity = 0xaf, base_high = 0x0},
data3 = {limit_low = 0x0, base_low = 0x0, base_middle = 0x0,
access = 0xf2, granularity = 0x8f, base_high = 0x0}, tss = {
limit_low = 0x1000, base_low = 0x5000, base_middle = 0x11,
access = 0xe9, granularity = 0x0, base_high = 0x0}, pointer = {
limit = 0x2f, base = 0x100100130}}