I assume you understand what extern struct cpu *cpu means. You have a question: what does the asm("%gs:0") part asm("%gs:0") mean?
This code uses the gcc extension, called asm labels , to say that the cpu variable is defined by the assembler string %gs:0 .
This is NOT how this extension is intended to be used and is considered a hack .
Here's a great discussion of gs (and fs) here , but in a nutshell gs points to the current local memory of the stream. The data format in gs depends on your OS (Windows is very different from Linux). This specific code says that at offset 0 from gs there is a pointer to struct cpu .
source share