cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

jalsenz
Journeyman III

Problem with GDT switch in long mode

Hello!

 

I'm currently trying to build a small hypervisor.

I am already in long mode with most stuff set up. IDT vor example seems to work fine.

But I fail to relocate the GDT to a different position...

I already successfully changed it in protected mode, but now I can't seem to get it working. This is, what I do:

    daffhy_gdt_reg64_t my_gdt_reg;
   
    asm volatile("sgdt %0;" // store gdt register
            : "=m" (my_gdt_reg));
   
    daffhy_uint64_t* my_gdt = malloc(my_gdt_reg.limit+1);
    daffhy_memcpy(my_gdt, (daffhy_uint64_t*)(my_gdt_reg.base), my_gdt_reg.limit+1); // copy the GDT
   
    my_gdt_reg.base = (daffhy_uint64_t)my_gdt;
  
    asm volatile("lgdt %0;" // load our gdt
                ::"m" (my_gdt_reg));

typedef struct __attribute__ ((__packed__)){
    daffhy_uint16_t limit;
    daffhy_uint64_t base;
} daffhy_gdt_reg64_t;

Interrupts are currently activated at this point, but none are thrown.

It crashes (after a retrun and call) at a jmp instruction with a #DF (int 😎 (that doesn't return an error code).

I'm working with simnow at the moment, and already checked all obvious option.

 

Anyone any ideas? What am I doing wrong?

 

Thanks and Greets,

 

Jan

0 Likes
1 Reply
jalsenz
Journeyman III

Ok, I found it now.

The Problem wasn't the GDT change. (Seems I didn't try to run through without changing the GDT and activted interrupts before...).

 

But it is still strange: simnow seems to generate interrupts after a while if the code has an endless loop.

I will post the details soon.

 

Greets,

 

Jan

0 Likes