.code32
.globl var
var:
.long 0
Let's assume elf binary format.
This is a piece of assembly ( I have no idea what exactly assembly it is,
I am familiar with nasm
).
I cannot understand what does it mean.
How is it interpreted? . It looks like global variable, but where it in an elf format file? In global section or in data section? When will be known address of var? After compilation or after linking?
Actually, the problem is with understanding Pintos's start.S
file.
https://github.com/abhinav-upadhyay/Pintos/blob/master/threads/start.S
Please note, that in line 202
there is the same issue. But, I cannot understand why in the line 48
:
addr32 movl %eax, init_ram_pages - LOADER_PHYS_BASE - 0x20000
It looks like init_ram_pages
was virutal address. But, please note that in the line 48
the CPU is in real mode still!
It's AT&T syntax.. Google gas at&t syntax
and the front page is full of links that look useful.
The official manual for GNU as (aka gas) is https://sourceware.org/binutils/docs/as/. See also the x86 tag wiki.
The NASM equivalent is
BITS 32 ;; .code32
;section .text ;; This is the default for gas, same as for NASM
global var ;; .globl var
var: ;; var:
dd 0 ;; .long 0 (GAS's terminology comes from before AMD64. .quad is a qword)
where it in an elf format file? In global section or in data section?
IIRC, the default section is .text
. There is no "global" section.
When will be known address of var? After compilation or after linking?
Same as for NASM: symbol addresses are link-time constants, but the difference between two addresses in the same section is an assemble-time constant.
addr32 movl %eax, init_ram_pages - LOADER_PHYS_BASE - 0x20000
addr32 means use an address-size prefix if necessary, and encode the addressing mode using the 32-bit machine encoding.
Michael Petch's comment may shed some light on what address is filled in by the linker vs. how you should use it before paging is enabled, to answer the last part of your multi-part question.