Page 1 of 1

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

Posted: Mon Jan 22, 2024 12:25 pm
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.

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

Posted: Mon Jan 22, 2024 8:37 pm
by Octocontrabass

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

Posted: Mon Jan 22, 2024 8:38 pm
by klange
Why do we even bother to run this place any more...

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

Posted: Mon Jan 22, 2024 8:40 pm
by Octocontrabass
Because the user interface is much, much better.

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

Posted: Tue Jan 23, 2024 7:32 am
by jarebear
Sorry, I had assumed my post was rejected.