linker.ld 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. SECTIONS
  2. {
  3. /* We could also pass the -Ttext 0x7C00 to as instead of doing this.
  4. * If your program does not have any memory accesses, you can omit this.
  5. */
  6. . = 0x7c00;
  7. .text :
  8. {
  9. __start = .;
  10. /* We are going to stuff everything
  11. * into a text segment for now, including data.
  12. * Who cares? Other segments only exist to appease C compilers.
  13. */
  14. *(.text)
  15. /* Magic bytes. 0x1FE == 510.
  16. *
  17. * We could add this on each Gas file separately with `.word`,
  18. * but this is the perfect place to DRY that out.
  19. */
  20. . = 0x1FE;
  21. SHORT(0xAA55)
  22. /* This is only needed if we are going to use a 2 stage boot process,
  23. * e.g. by reading more disk than the default 512 bytes with BIOS `int 0x13`.
  24. */
  25. *(.stage2)
  26. /* Number of sectors in stage 2. Used by the `int 13` to load it from disk.
  27. *
  28. * The value gets put into memory as the very last thing
  29. * in the `.stage` section if it exists.
  30. *
  31. * We must put it *before* the final `. = ALIGN(512)`,
  32. * or else it would fall out of the loaded memory.
  33. *
  34. * This must be absolute, or else it would get converted
  35. * to the actual address relative to this section (7c00 + ...)
  36. * and linking would fail with "Relocation truncated to fit"
  37. * because we are trying to put that into al for the int 13.
  38. */
  39. __stage2_nsectors = ABSOLUTE((. - __start) / 512);
  40. /* Ensure that the generated image is a multiple of 512 bytes long. */
  41. . = ALIGN(512);
  42. __end = .;
  43. __end_align_4k = ALIGN(4k);
  44. }
  45. }