Page 1 of 1

Segment based referencing in c

Posted: Thu Mar 15, 2018 2:21 am
by thomasloven
Some xv6 code mirrors have the following line:

Code: Select all

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™?

Re: Segment based referencing in c

Posted: Thu Mar 15, 2018 2:39 am
by Octocontrabass

Re: Segment based referencing in c

Posted: Thu Mar 15, 2018 3:09 am
by thomasloven
Works like a charm! Thank you!