鏈接描述文件中的「。= 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);
}
}