链接描述文件中的“。= 0x7c00”究竟做了什么?链接器脚本中的“。= 0x7c00”究竟做了什么?
更具体地说,当我把. = 0x7c00
在链接脚本的开始,为什么不将生成的输出文件与0x7c00 = 31,744零开始?
据我所知,当电脑启动时,BIOS会将512字节的MBR放在内存地址0x7c00处。但是,我很困惑链接器的位置计数器如何影响输出文件的布局。
(对于背景下,我想从“86裸机”项目彻底了解示例代码。https://github.com/cirosantilli/x86-bare-metal-examples。我已经包括上下文整个链接下面的脚本。)
SECTIONS
{
/*
We could also pass the -Ttext 0x7C00 to as instead of doing this.
If your program does not have any memory accesses, you can omit this.
*/
. = 0x7c00;
.text :
{
__start = .;
/*
We are going to stuff everything
into a text segment for now, including data.
Who cares? Other segments only exist to appease C compilers.
*/
*(.text)
/*
Magic bytes. 0x1FE == 510.
We could add this on each Gas file separately with `.word`,
but this is the perfect place to DRY that out.
*/
. = 0x1FE;
SHORT(0xAA55)
*(.stage2)
__stage2_nsectors = ABSOLUTE((. - __start)/512);
. = ALIGN(512);
__end = .;
__end_align_4k = ALIGN(4k);
}
}