tari

LIFOS linker

May 19th, 2010
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;Program var types:
  2. ;;Unrelocatable (NRP):
  3. ;;  Assembled to run only from $8100 in RAM
  4. ;;Fully relocatable (FRP):
  5. ;;  May be run from anywhere in RAM (uses relative references only)
  6. ;;DRP (dynamically relocatable):
  7. ;;  May be run from anywhere in RAM, but must first be dynamically linked by the OS
  8. ;;  to account for absolute data references.
  9. ;;
  10. ;;VAT entry spec:
  11. ;;  type | 1 [VtProg*]
  12. ;;  page | 1
  13. ;;  addr | 2
  14. ;;  name | 10
  15. ;;New header spec:
  16. ;;  size | 2        | Variable size (including header)
  17. ;;  version | 2     | Minimum OS version
  18. ;;==== Special entries valid only for DRPs ====
  19. ;;TDS: transient data segment- linked in after program code and initialized
  20. ;;     to all 0.
  21. ;;PDS: persistent data segment- is stored elsewhere and preserved across
  22. ;;     program invocations.  Linked in after the TDS.
  23. ;;==== Current DRP header version: 0       ====
  24. ;;  headerv | 1     | DRP header version (flags, too?)
  25. ;;  pdssize | 1     | Size of PDS    \Optional?  headerv could flag presence of
  26. ;;  pdssig  | 4     | PDS signature  |PDS and VDS, allowing them to be omitted.
  27. ;;  tdssize | 2     | Size of TDS    /
  28. ;;  data    | n     | Program code- main entry point
  29. ;;==== Linker Notes                        ====
  30. ;;The linker first calls allocVar at the lowest available location in user
  31. ;;memory, then allocates a chunk of memory after that for the VDS.  The PDS
  32. ;;file with matching signature will be allocated immediately following the VDS,
  33. ;;and a PDS file will be created first if it does not exist.
  34. ;;Finally, the linker creates the ULS (unlink segment) for its own use.
  35. ;;
  36. ;;Beginning at the main entry point, the reassembling linker traces program
  37. ;;flow from the main entry point, locating relink markers, likely a rarely-used
  38. ;;but legal instruction (`ld a,a', etc?) followed by relative address (offset
  39. ;;from 0x0000).  Various relink markers are modified to become absolute
  40. ;;references, perhaps `ld a,a' (0x7F) becomes `call' (0xCD), and the base link
  41. ;;address of this instance of the program is added to the immediately following
  42. ;;constant, resulting in a valid absolute reference.  The address of the relink
  43. ;;marker is then appended to the ULS so the reassembly can be undone when the
  44. ;;program exits.
  45. ;;
  46. ;;Possible table of relocation markers:
  47. ;; ld b,b       -> ld bc,nnnn
  48. ;; ld d,d       -> ld de,nnnn
  49. ;; ld h,h       -> ld hl,nnnn
  50. ;; ld c,c       -> ld bc,(nnnn)
  51. ;; ld e,e       -> ld de,(nnnn)
  52. ;; ld l,l       -> ld hl,(nnnn)
  53. ;; ld a,a       -> jp nnnn
  54. ;; ld (hl),(hl) -> call nnnn
  55. ;;
  56. ;;Example: [p+n] is n bytes from the program entry point
  57. ;; Program loaded at 0x81C2, with call to p+0x72F and reference to p+0x1024
  58. ;; (which, for demonstration, can be in the PDS) by HL immediately following.
  59. ;;Assembled/stored as:
  60. ;; ld (hl),(hl)
  61. ;; .dw 0x72F
  62. ;; ld h,h
  63. ;; .dw 0x1024
  64. ;;Linked as:
  65. ;; call 0x88F1
  66. ;; ld hl,0x91E6
Add Comment
Please, Sign In to add comment