x86 - Understanding assembly code of setting up stack for C code -


i want know how values of "bootstacktop" , "bootstack" calculated assembler, when code sets value %esp:

# set stack pointer movl    $(bootstacktop),%esp 

at end of same assembly file, "definition" of "bootstacktop" given:

################################################################### # boot stack ###################################################################     .p2align    pgshift     # force page alignment     .globl      bootstack bootstack:     .space      kstksize     .globl      bootstacktop    bootstacktop: 

i found value, looking @ deassebly, 'bootstacktop', here part of deassembly above 'mov' instruction:

# set stack pointer movl    $(bootstacktop),%esp f0100034:   bc 00 40 11 f0          mov    $0xf0114000,%esp 

value of kstksize 8*4096, pgshift 12. how did value of 'bootsacktop' become '0xf0114000'? , whats value of 'bootstack'?

here linker script: http://pastebin.com/9dpakfgx

since posted linker file know working jos os. somewhere @ top of assembler file code snippet showing line including file memlayout.h . file defines values pgshift , kstksize. code:

################################################################### # boot stack ###################################################################     .p2align    pgshift     # force page alignment     .globl      bootstack bootstack:     .space      kstksize     .globl      bootstacktop    bootstacktop: 

will align page bootstack whatever value defined in pgshift. bootstack label (memory address) happens have space allocated after .space kstksize (amount of space allocated = kstksize). kstksize defined in memlayout.h. .globl bootstacktop directive says label made global (like variable declared extern in c). bootstackstop label (memory address) address after last byte in bootstack. declared globally other objects use. bootstacktop - bootstack = kstksize

the layout of items in image or executable determined linker placed these objects in final image. linker script drives more complex image layouts. if have linker script may wish consult see how final image/executable laid out.

you don't whether disassembled image file on disk or whether disassembly done after program loaded in memory, based on value 0xf0100034 guess virtual or physical address of sort determined kernel when loaded file memory (likely elf object or equivalent). combination of memory location image loaded memory kernel , offsets of objects within image file linker generated.

your question doesn't supply enough information definitively how particular value arrived @ because don't have image(executable) used, type of layout image in (was elf/pe etc) , memory location used os load image.


Comments