OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 11:38 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: visit GDT and IDT under UEFI?
PostPosted: Mon Oct 26, 2015 3:41 am 
Offline

Joined: Thu Nov 27, 2014 8:23 pm
Posts: 11
I do that by this:
in file systemlib.asm:
global save_gdt
save_gdt:
sgdt [rcx]
ret
just like this

in file uefi_main.c:
extern __int64 __fastcall save_gdt(GDTR_t*);
extern __int64 __fastcall load_gdt(GDTR_t*);
extern __int64 __fastcall save_idt(IDTR_t*);
extern __int64 __fastcall load_idt(IDTR_t*);
......
IDTR_t idtr;
idtr.addr = 0;
idtr.limit = 0;
save_idt(&idtr);

sth. like that,but I what I get is
GDT starts at 0x0 and ends at 0x3F, all empty
IDT starts at 0x0 and ends at 0xFFF, all empty again

I understand GDT is usually useless under long mode,
but doesn't my UEFI BIOS use interruption ?
Am I doing it right ?


Top
 Profile  
 
 Post subject: Re: visit GDT and IDT under UEFI?
PostPosted: Mon Oct 26, 2015 3:51 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

For fun, fill your "GDTR_t" with trash (e.g. base = 0x55AA55AA55AA55AA, limit = 0x55AA) and then call "save_gdt()".

This will help determine if you're saving the GDTR properly, or just reading "random zeros" because you're not saving GDTR properly or because you forgot to pack the structure or something.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: visit GDT and IDT under UEFI?
PostPosted: Mon Oct 26, 2015 4:21 am 
Offline

Joined: Thu Nov 27, 2014 8:23 pm
Posts: 11
Brendan wrote:
Hi,

For fun, fill your "GDTR_t" with trash (e.g. base = 0x55AA55AA55AA55AA, limit = 0x55AA) and then call "save_gdt()".

This will help determine if you're saving the GDTR properly, or just reading "random zeros" because you're not saving GDTR properly or because you forgot to pack the structure or something.


Cheers,

Brendan


indeed I filled it with zeros as shown above, and at least the gdtr.limit changed after the call

and the GDTR_t is defined as this:
typedef struct {
__int16 limit;
__int64 addr;
}GDTR_t;
and IDTR_t is just the same


Top
 Profile  
 
 Post subject: Re: visit GDT and IDT under UEFI?
PostPosted: Mon Oct 26, 2015 4:30 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

wyj wrote:
and the GDTR_t is defined as this:
typedef struct {
__int16 limit;
__int64 addr;
}GDTR_t;
and IDTR_t is just the same


That's not packed; so the compiler will probably add an extra 6 bytes of padding between "limit" and "addr" (so that "addr" is aligned nicely) and cause it to be wrong. ;)

Try something more like:

Code:
typedef struct {
   __int16 limit;
   __int64 addr;
} __attribute__(packed) GDTR_t;



Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: visit GDT and IDT under UEFI?
PostPosted: Mon Oct 26, 2015 4:34 am 
Offline

Joined: Thu Nov 27, 2014 8:23 pm
Posts: 11
Brendan wrote:
Hi,

wyj wrote:
and the GDTR_t is defined as this:
typedef struct {
__int16 limit;
__int64 addr;
}GDTR_t;
and IDTR_t is just the same


That's not packed; so the compiler will probably add an extra 6 bytes of padding between "limit" and "addr" (so that "addr" is aligned nicely) and cause it to be wrong. ;)

Try something more like:

Code:
typedef struct {
   __int16 limit;
   __int64 addr;
} __attribute__(packed) GDTR_t;



Cheers,

Brendan


It works, thank you.
and for me I choose to #include<packon.h>,which is in the gnu-efi package.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: ravi and 158 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