リンカスクリプトで "。= 0x7c00"と正確に何ができますか?リンカスクリプトで "。= 0x7c00"と正確に何ができますか?
具体的には、. = 0x7c00
をリンカースクリプトの先頭に配置すると、結果の出力ファイルが0x7c00 = 31,744のゼロで始まるのはなぜですか?
PCが起動すると、BIOSは512バイトのMBRをメモリアドレス0x7c00に配置します。しかし、リンカのロケーションカウンタがどのように出力ファイルがどのようにレイアウトされているかがわかります。
(コンテキストの場合、私は徹底的に「x86のベアメタル」プロジェクトからのサンプルコードを理解しようとしている。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);
}
}