OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:33 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Trying to execute RETF after loading GDT causes triple fault
PostPosted: Mon Dec 28, 2020 12:40 pm 
Offline

Joined: Mon Dec 28, 2020 12:30 pm
Posts: 1
I've been trying to get a GDT to work for like 2 days and i tried countless methods.
My "kernel" is in long mode

Code:
void GDTInstall();

void LoadGDT()
{
    // NULL DESCRIPTOR
    PushEntry(0x0000000000000000);

    // DATA
    PushEntry(0xFFFF00000092C700);

    // CODE
    PushEntry(0x0000000000BAAF00);

    __gdt_pointer.limit = sizeof(struct GDTEntry) * 3 - 1;
    __gdt_pointer.addr = &entries[0];

    GDTInstall();
}


This is Util.asm

Code:
section .text

extern __gdt_pointer

global GDTInstall

GDTInstall:
    CLI
    LGDT [__gdt_pointer]

    PUSH WORD 0x10
    PUSH QWORD Stage2
    RETF

Stage2:
    MOV AX, 0x8
    MOV DS, AX
    MOV ES, AX
    MOV FS, AX
    MOV GS, AX
    MOV SS, AX
    STI


Top
 Profile  
 
 Post subject: Re: Trying to execute RETF after loading GDT causes triple f
PostPosted: Mon Dec 28, 2020 8:28 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Code:
    PUSH WORD 0x10

RETF pops an entire qword for the segment selector, even though it uses only the low 16 bits. You must push an entire qword onto the stack.

Code:
GDTInstall:
...
    STI

What is executed after this STI instruction?

There may be additional problems in code that you didn't post. I suggest examining the CPU state at the first exception that leads to the triple fault using an emulator or virtual machine with built-in debugging tools (such as QEMU or Bochs).


Top
 Profile  
 
 Post subject: Re: Trying to execute RETF after loading GDT causes triple f
PostPosted: Tue Dec 29, 2020 2:28 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
Code:
   // DATA
    PushEntry(0xFFFF00000092C700);

    // CODE
    PushEntry(0x0000000000BAAF00);

That is the wrong way around. And the code segment has the wrong DPL. For kernel data, use 0x00af92000000ffff and for kernel code use 0x00af9a000000ffff. For user code and user data, replace the 9s with Fs. The only other segment I have in the GDT is the TSS. And my code for that is:
Code:
    gdt[TSS_DESC] = (tssp << 16) & 0xffffff0000 | (tssp << 32) & 0xff00000000000000 | sizeof (struct tss) - 1 | (uint64_t)0x89 << 40;
    gdt[TSSU_DESC] = tssp >> 32;
Where tssp is the pointer to the TSS as an integer, and struct tss is the data structure I'm using for it. Ensure that TSSU_DESC is exactly one larger than TSS_DESC (you need them in that order).

_________________
Carpe diem!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot] and 56 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group