OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 27, 2024 7:32 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Trying to load the GDT using gcc's extended inline assembly
PostPosted: Mon Jan 22, 2024 12:25 pm 
Offline

Joined: Sat Jul 15, 2023 11:26 am
Posts: 7
Hey, so I wanted to use load the GDT using inline gcc assembly based on the following code:

Code:
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:
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:
/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.


Top
 Profile  
 
 Post subject: Re: Trying to load the GDT using gcc's extended inline assem
PostPosted: Mon Jan 22, 2024 8:37 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
This question was asked and answered elsewhere in the time it took for the post to get approved.


Top
 Profile  
 
 Post subject: Re: Trying to load the GDT using gcc's extended inline assem
PostPosted: Mon Jan 22, 2024 8:38 pm 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
Octocontrabass wrote:

Why do we even bother to run this place any more...

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: Trying to load the GDT using gcc's extended inline assem
PostPosted: Mon Jan 22, 2024 8:40 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
Because the user interface is much, much better.


Top
 Profile  
 
 Post subject: Re: Trying to load the GDT using gcc's extended inline assem
PostPosted: Tue Jan 23, 2024 7:32 am 
Offline

Joined: Sat Jul 15, 2023 11:26 am
Posts: 7
Octocontrabass wrote:


Sorry, I had assumed my post was rejected.


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: eekee and 28 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