2 Assembler
| (require ledum/define/asm) | package: ledum-definers |
This module turns the current module into a assembly language with rudimentary macro opcode support. The macro support is not intended for the generated language but it is to be used for specifying compound "opcodes" for underlying ISA created using define-isa.
It also reprovides the entity and not-entity syntax classes for syntax so that they can be matched (in addition to specific entities) in macro opcodes.
When #:private keyword is at the end of the #lang line, private opcodes are allowed.
The front-end currently supports the following command-line options:
[-o | --output filename] - specifies output filename which defaults to the module name with extension changed from ".rkt" to ".bin".
[-q | --quiet] - suppresses any non-error messages.
[-c | --color] - enable color.
[-n | --no-color] - disable color.
[-v | --verbose] - increases verbosity level, can be specified multiple times.
If used as a stand-alone program, it supports the following options:
[-V | --validate] - validates the ISA by printing its opcode tree, showing any collisions.
[-d | --disassemble fname] - disassembles given binary.
[-u | --unused] - analyzes unused opcode space.
[-c | --color] - enables color output.
[-n | --no-color] - disables color output.
[-a | --addrs] - outputs each disassembled instruction address as an end-of-line comment.
[-x | --hex] - outputs each disassembled instruction hexadecimal value as an end-of-line comment.
2.1 Macro Opcodes
| (require ledum/define/asm/macro) | package: ledum-definers |
This module contains the the macro opcode specification forms.
A default documentation for the macro syntax form is generated. Any prose text can be added to it with the #:doc keyword - as is the case in define-opcode. This is especially useful coupled with the at-exp meta-language.
Take the following example code:
(define-macro-opcode (ldw r w:isa-word) #:doc @{Loads the word @racket[w] into register @racket[r].} (define wl (bitwise-and w #xff)) (define wh (bitwise-and (arithmetic-shift w -8) #xff)) (ldl r wl) (when/pass (> wh 0) (ldh r wh))) It produces the documentation as follows:
macro opcode
(ldw r w:isa-word)
Loads the word w into register r.
2.2 Assembler Passes
| (require ledum/define/asm/passes) | package: ledum-definers |
A module implementing a simple multi-pass mechanism required for supporting label resolution.
parameter
(asm-output) → bufwriter?
(asm-output output) → void? output : bufwriter?
parameter
(asm-pass-number) → exact-nonnegative-integer?
(asm-pass-number number) → void? number : exact-nonnegative-integer?
syntax
id : identifier?
At the very beginning the label bindings are defined. Then in the first pass they are populated with actual addresses and in the second pass their usage reflects their actual values.
procedure
(reset-asm-pass-success) → void?
procedure
(asm-offset) → exact-nonnegative-integer?
procedure
(asm-labels-resolved?) → boolean?
syntax
off : exact-nonnegative-integer?
syntax
amt : exact-integer?
syntax
val : exact-nonnegative-integer?
syntax
val : exact-nonnegative-integer?
2.3 Buffered Writer
| (require ledum/define/asm/writer) | package: ledum-definers |
Memory-backed writer with skip and seek capability.
struct
(struct bufwriter (buf pos size bitw))
buf : vector? pos : exact-nonnegative-integer? size : exact-nonnegative-integer? bitw : exact-positive-integer?
procedure
(make-bufwriter bitw [initial-prealloc]) → bufwriter?
bitw : exact-positive-integer? initial-prealloc : exact-positive-integer? = 16
procedure
bw : bufwriter?
procedure
(bufwriter-write bw v) → void?
bw : bufwriter? v : exact-nonnegative-integer?
procedure
(bufwriter-skip bw n) → void?
bw : bufwriter? n : exact-positive-integer?
procedure
(bufwriter-seek bw n) → void?
bw : bufwriter? n : exact-nonnegative-integer?
procedure
(bufwriter-output bw) → void?
bw : bufwriter?
2.4 Assembler Printer
| (require ledum/define/asm/print) | package: ledum-definers |
This module unifies printing of the assembler and disassembler at various verbosity levels.
parameter
(asm-verbosity) → exact-nonnegative-integer?
(asm-verbosity verbosity) → void? verbosity : exact-nonnegative-integer?
If the dots keyword #::: are at the end of the expression, no newline is printed.