OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:05 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Segment based referencing in c
PostPosted: Thu Mar 15, 2018 2:21 am 
Offline
Member
Member

Joined: Tue Feb 26, 2008 10:47 am
Posts: 89
Location: Sweden
Some xv6 code mirrors have the following line:
Code:
extern struct cpu *cpu asm("%gs:0");

[github]

This is a hack using the assembly label attribute available in some compilers which works by accident rather than by design - if at all.

However, having a simple way of automatically referencing an offset from fs/gs is damn convenient, and having it be a variable rather than a function carries a measure of elegance.

Can the same thing somehow be be done The Right Way™?

_________________
Blawg


Top
 Profile  
 
 Post subject: Re: Segment based referencing in c
PostPosted: Thu Mar 15, 2018 2:39 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
Yes, using GCC's Named Address Spaces extensions.


Top
 Profile  
 
 Post subject: Re: Segment based referencing in c
PostPosted: Thu Mar 15, 2018 3:09 am 
Offline
Member
Member

Joined: Tue Feb 26, 2008 10:47 am
Posts: 89
Location: Sweden
Works like a charm! Thank you!

_________________
Blawg


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 30 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