What does the declaration“extern struct cpu *cpu asm(“%gs:0”);” mean?

后端 未结 2 1831
被撕碎了的回忆
被撕碎了的回忆 2020-12-18 04:39

When I\'m reading the xv6 source code, I\'m confused about the syntax of the declaration below. Can anyone explain it to me?

extern struct cpu *cpu asm(\"%gs         


        
2条回答
  •  孤城傲影
    2020-12-18 05:16

    It is a special case of an asm label. It instructs the compiler to emit %gs:0 instead of the usual symbol name if you reference the cpu variable. Presumably %gs has been previously set up as a per-cpu storage area, with a struct cpu pointer at offset zero. The purpose is to allow each cpu to access its own data.

提交回复
热议问题