Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.5KB

  1. ; zasm
  2. ;
  3. ; Reads input from specified blkdev ID, assemble the binary in two passes and
  4. ; spit the result in another specified blkdev ID.
  5. ;
  6. ; We don't buffer the whole source in memory, so we need our input blkdev to
  7. ; support Seek so we can read the file a second time. So, for input, we need
  8. ; GetB and Seek.
  9. ;
  10. ; For output, we only need PutB. Output doesn't start until the second pass.
  11. ;
  12. ; The goal of the second pass is to assign values to all symbols so that we
  13. ; can have forward references (instructions referencing a label that happens
  14. ; later).
  15. ;
  16. ; Labels and constants are both treated the same way, that is, they can be
  17. ; forward-referenced in instructions. ".equ" directives, however, are evaluated
  18. ; during the first pass so forward references are not allowed.
  19. ;
  20. ; *** Requirements ***
  21. ; strncmp
  22. ; upcase
  23. ; findchar
  24. ; blkSel
  25. ; blkSet
  26. ; fsFindFN
  27. ; fsOpen
  28. ; fsGetB
  29. ; _blkGetB
  30. ; _blkPutB
  31. ; _blkSeek
  32. ; _blkTell
  33. ; printstr
  34. ; printcrlf
  35. .inc "user.h"
  36. .org 0x85e0
  37. .equ USER_RAMSTART USER_CODE
  38. ; *** Overridable consts ***
  39. ; NOTE: These limits below are designed to be *just* enough for zasm to assemble
  40. ; itself. Considering that this app is Collapse OS' biggest app, it's safe to
  41. ; assume that it will be enough for many many use cases. If you need to compile
  42. ; apps with lots of big symbols, you'll need to adjust these.
  43. ; With these default settings, zasm runs with less than 0x1800 bytes of RAM!
  44. ; Maximum number of symbols we can have in the global and consts registry
  45. .equ ZASM_REG_MAXCNT 0xff
  46. ; Maximum number of symbols we can have in the local registry
  47. .equ ZASM_LREG_MAXCNT 0x20
  48. ; Size of the symbol name buffer size. This is a pool. There is no maximum name
  49. ; length for a single symbol, just a maximum size for the whole pool.
  50. ; Global labels and consts have the same buf size
  51. .equ ZASM_REG_BUFSZ 0x700
  52. ; Size of the names buffer for the local context registry
  53. .equ ZASM_LREG_BUFSZ 0x100
  54. ; ******
  55. .inc "err.h"
  56. .inc "ascii.h"
  57. .inc "blkdev.h"
  58. .inc "fs.h"
  59. jp zasmMain
  60. .inc "core.asm"
  61. .inc "zasm/const.asm"
  62. .inc "lib/util.asm"
  63. .inc "lib/ari.asm"
  64. .inc "lib/parse.asm"
  65. .inc "zasm/util.asm"
  66. .equ IO_RAMSTART USER_RAMSTART
  67. .inc "zasm/io.asm"
  68. .equ TOK_RAMSTART IO_RAMEND
  69. .inc "zasm/tok.asm"
  70. .equ INS_RAMSTART TOK_RAMEND
  71. .inc "zasm/instr.asm"
  72. .equ DIREC_RAMSTART INS_RAMEND
  73. .inc "zasm/directive.asm"
  74. .inc "zasm/parse.asm"
  75. .equ EXPR_PARSE parseNumberOrSymbol
  76. .inc "lib/expr.asm"
  77. .equ SYM_RAMSTART DIREC_RAMEND
  78. .inc "zasm/symbol.asm"
  79. .equ ZASM_RAMSTART SYM_RAMEND
  80. .inc "zasm/main.asm"
  81. USER_RAMSTART: