flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Long mode ISR triple fault

Author
Thread Post new topic Reply to topic
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 09 Jan 2012, 18:36
It looks like I've hit the classic triple fault in my long mode ISRs but after two days of debugging I have no idea what's wrong having gone through the GDT(R), IDT(R), page table and TSS. Since VirtualBox doesn't moan about triple fault the only way I knew about this was QEMU's log dump which shows #GP with error code 0202 (GDT selector 0040 from IDT ? but all selectors use 0008) followed by #GP error code 0000, double fault, triple fault. At the very least it seems both will die at the same points, having tried both HW and SW interrupts, so it;s likely to be something fundamental.

I was wondering if anyone has any ideas on what this might be or even if anyone is prepared to look at it if I sent them the source?

edit: typos


Last edited by cod3b453 on 09 Jan 2012, 22:51; edited 3 times in total
Post 09 Jan 2012, 18:36
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 09 Jan 2012, 20:35
I probably can't help by reading your source. Though I can add some trouble shooting ideas. Try using Bochs, VirtualBox, and Virtual PC. If you can download VM Ware, use the trial and check it there too.

What is weird is you say "(GDT selector 0040 from IDT ? but all sectors use 0008)" so I assume you expected them to be the same? Are the ISRs in one and the general routines (for the IDT) in a separate one and are they segment registers being updated correctly? (BTW, I'm used to a flat 32 bit mode, so a page table and TSS are simply words I've not applied yet).

Just some thoughts, hope it helps. Smile
Post 09 Jan 2012, 20:35
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 09 Jan 2012, 22:38
My VM breakdown is:

Bochs - never worked originally
VirtualPC - VGA and 32bit only
VM Ware - does not boot (drivers hang)
VirtualBox - 32bit VESA or VGA, ATAPI or ATA, 64bit
QEMU - 24bit VESA or VGA, ATAPI or ATA, 64bit

(I have hex dump routines in the 32bit loader stage that can show the values on VGA or VESA)

----

The error code shown in QEMU suggests selector 0040 but I have no idea where it's pulling this from since all the ISRs use 0008 in their entries.
Quote:
IN:
0x0000000002000096: hlt

Servicing hardware INT=0x20
383: v=20 e=0000 i=0 cpl=0 IP=0008:0000000002000097 pc=0000000002000097 SP=0020:0000000002000000 EAX=000000000200fff0
RAX=000000000200fff0 RBX=0000000000000004 RCX=00000000c0000080 RDX=0000000000000020
RSI=0000000000000000 RDI=000000000000b727 RBP=000000000000b52f RSP=0000000002000000
R8 =0000000000000000 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=0000000002000097 RFL=00000202 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 ffffffff 00af9300 DPL=0 DS16 [-WA]
CS =0008 0000000000000000 ffffffff 00af9a00 DPL=0 CS64 [-R-]
SS =0020 0000000000000000 ffffffff 00af9300 DPL=0 DS16 [-WA]
DS =0010 0000000000000000 ffffffff 00af9300 DPL=0 DS16 [-WA]
FS =0010 0000000000000000 ffffffff 00af9300 DPL=0 DS16 [-WA]
GS =0010 0000000000000000 ffffffff 00af9300 DPL=0 DS16 [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =fff0 0000000003212000 0fffffff 03908921 DPL=0 TSS64-avl
GDT= 0000000003201000 0000ffff
IDT= 0000000003211000 00000fff
CR0=80000011 CR2=0000000000000000 CR3=0000000003000000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0000000000000004 CCD=0000000000000000 CCO=EFLAGS
check_exception old: 0xffffffff new 0xd
384: v=0d e=0202 i=0 cpl=0 IP=0008:0000000002000097 pc=0000000002000097 SP=0020:0000000002000000 EAX=000000000200fff0
RAX=000000000200fff0 RBX=0000000000000004 RCX=00000000c0000080 RDX=0000000000000020
RSI=0000000000000000 RDI=000000000000b727 RBP=000000000000b52f RSP=0000000002000000
R8 =0000000000000000 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=0000000002000097 RFL=00000202 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 ffffffff 00af9300 DPL=0 DS16 [-WA]
CS =0008 0000000000000000 ffffffff 00af9a00 DPL=0 CS64 [-R-]
SS =0020 0000000000000000 ffffffff 00af9300 DPL=0 DS16 [-WA]
DS =0010 0000000000000000 ffffffff 00af9300 DPL=0 DS16 [-WA]
FS =0010 0000000000000000 ffffffff 00af9300 DPL=0 DS16 [-WA]
GS =0010 0000000000000000 ffffffff 00af9300 DPL=0 DS16 [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =fff0 0000000003212000 0fffffff 03908921 DPL=0 TSS64-avl
GDT= 0000000003201000 0000ffff
IDT= 0000000003211000 00000fff
CR0=80000011 CR2=0000000000000000 CR3=0000000003000000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0000000000000004 CCD=0000000000000000 CCO=EFLAGS
Post 09 Jan 2012, 22:38
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 10 Jan 2012, 15:54
I'm not sure I see what you're saying, but it does seem like all of your other segments are 0010 except the Stack, which is 0020, and your Code at 0008. What does your GDT look like? Is 0040 specific to the IDT or are the routines (base ones) within 0040? Where could that change within your code, perhaps one of your ISRs is changing it from what it should be to 0040?
Post 10 Jan 2012, 15:54
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 10 Jan 2012, 18:08
This trace only shows the current state not the state it tried to load. I'll post hex dumps shortly.

edit: A zip with images of the hex dumps, memory map table and example ISO, hd images can been seen here: [removed]

As shown in idt.png, the selector field is 0008 not the 0040 suggested.


Last edited by cod3b453 on 11 Jan 2012, 21:09; edited 1 time in total
Post 10 Jan 2012, 18:08
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 10 Jan 2012, 20:37
I'll check it out, I'll traveling so I may not get to it until Friday-ish. I will try them on what I have here, but at home I can do more.

I will study the hex dumps. Right now I cannot make heads or tails out of them, though at first glance they look symmetric (the TSS one I will have to study TSS to get a clue).
Post 10 Jan 2012, 20:37
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 11 Jan 2012, 20:27
OK I think I have realised what the issue is - I have accidentally zeroed the Type field in IDT entry generator which should be 8E at offset 5 not 80...though some other issue is currently happening.

edit: OK I had made a minor mistake in the ISR Embarassed it now works! Cool

Just to explain the issues here - I had used a normal code segment descriptor definition for the GDT entry used by the IDT entries but this should have been an interrupt gate descriptor (with type = 0xE). One other important field is the IST, which can be set to a non-zero value (1..7) to perform a stack switch (RSP) before calling the ISR (and swaps back on iretq).

This should then look like this in memory (dpl=0):

xx xx ss ss 01 8E yy yy zz zz zz zz 00 00 00 00

where the ISR is at zz zz zz zz yy yy xx xx, selector (and rpl) is ss ss

thanks for looking smiddy


Last edited by cod3b453 on 12 Jan 2012, 00:31; edited 1 time in total
Post 11 Jan 2012, 20:27
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 11 Jan 2012, 23:21
No problem...happy to help (if I did). Smile
Post 11 Jan 2012, 23:21
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.