Trying to load the GDT using gcc's extended inline assembly

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
jarebear
Posts: 7
Joined: Sat Jul 15, 2023 11:26 am
Libera.chat IRC: jare-bear

Trying to load the GDT using gcc's extended inline assembly

Post by jarebear »

Hey, so I wanted to use load the GDT using inline gcc assembly based on the following code:

Code: Select all

gdtr DW 0 ; For limit storage
     DD 0 ; For base storage
 
setGdt:
   MOV   AX, [esp + 4]
   MOV   [gdtr], AX
   MOV   EAX, [ESP + 8]
   MOV   [gdtr + 2], EAX
   LGDT  [gdtr]
   RET

And I understand this just fine, but the issue arises when trying to this in in extended gcc inline assembly

Code: Select all

struct GDTR
{
    std::uint16_t base;
    std::uint32_t limit;
};

void load_gtdr(GDTR gdt_register)
{
    asm("gdtr: DW 0 DD 0");
    asm("mov (%0) (gdtr)" : "=m"(gdt_register.base));
    asm("mov (%0) (gdtr + 2)" : "=m"(gdt_register.limit));
    asm("lgdt (gdtr)");
}
I get the following errors:

Code: Select all

/tmp/ccqXDjYf.s:22: Error: no such instruction: `dw 0 DD 0'
/tmp/ccqXDjYf.s:26: Error: found '(', expected: ')'
/tmp/ccqXDjYf.s:26: Error: junk `(%ebp))(gdtr)' after expression
/tmp/ccqXDjYf.s:26: Error: number of operands mismatch for `mov'
/tmp/ccqXDjYf.s:30: Error: found '(', expected: ')'
/tmp/ccqXDjYf.s:30: Error: junk `(%ebp))(gdtr+2)' after expression
It's interpreting define word and define double as instructions, which
I don't want. And the other errors, well, I'm having a hard time debugging.

I'm also more familiar with intel synax as oppsed to AT&T, but I'm trying
to change that.
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: Trying to load the GDT using gcc's extended inline assem

Post by klange »

Why do we even bother to run this place any more...
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: Trying to load the GDT using gcc's extended inline assem

Post by Octocontrabass »

Because the user interface is much, much better.
jarebear
Posts: 7
Joined: Sat Jul 15, 2023 11:26 am
Libera.chat IRC: jare-bear

Re: Trying to load the GDT using gcc's extended inline assem

Post by jarebear »

Sorry, I had assumed my post was rejected.
Post Reply