Files
x86-bare-metal-examples/linker.ld

51 lines
1.7 KiB
Plaintext
Raw Normal View History

2015-09-06 16:17:39 +02:00
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.
*/
2015-09-06 16:17:39 +02:00
. = 0x7c00;
2015-09-06 21:45:05 +02:00
.text :
2015-09-06 16:17:39 +02:00
{
__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.
2015-10-04 19:59:15 +02:00
*/
*(.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)
2015-10-04 19:59:15 +02:00
/* This is only needed if we are going to use a 2 stage boot process,
* e.g. by reading more disk than the default 512 bytes with BIOS `int 0x13`.
2015-10-04 19:59:15 +02:00
*/
*(.stage2)
2015-10-06 12:27:24 +02:00
/* Number of sectors in stage 2. Used by the `int 13` to load it from disk.
*
* The value gets put into memory as the very last thing
* in the `.stage` section if it exists.
*
* We must put it *before* the final `. = ALIGN(512)`,
* or else it would fall out of the loaded memory.
*
* This must be absolute, or else it would get converted
* to the actual address relative to this section (7c00 + ...)
* and linking would fail with "Relocation truncated to fit"
* because we are trying to put that into al for the int 13.
2015-10-06 12:27:24 +02:00
*/
__stage2_nsectors = ABSOLUTE((. - __start) / 512);
2015-10-06 12:27:24 +02:00
/* Ensure that the generated image is a multiple of 512 bytes long. */
2015-10-06 12:27:24 +02:00
. = ALIGN(512);
2015-10-27 09:04:46 +01:00
__end = .;
__end_align_4k = ALIGN(4k);
2015-09-06 16:17:39 +02:00
}
}