Trying to load the GDT using gcc's extended inline assembly
Posted: Mon Jan 22, 2024 12:25 pm
Hey, so I wanted to use load the GDT using inline gcc assembly based on the following code:
And I understand this just fine, but the issue arises when trying to this in in extended gcc inline assembly
I get the following errors:
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.
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)");
}
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
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.