# rrcc (Red Rock Canyon Compiler) Toolchain for assembly and compilation of new code for FM10000 Instruction Processor Boot State Machine NOTE: **This is a Work In Progress project** ### Requirements * cmake >= 3.13 * g++ (GCC C++) or clang * make ### Compilation * `$ mkdir build && cd build` * `$ cmake ../ && make` * An executable named `./rrc-as` should now exist. * Feel free to move the executable to your desired installation directory, resources have been embedded. ## rrc-as Assembler and linker, kind-of 2-Pass. Quite loose token syntax defined in [Token.h](src/Token.h). A quite-more-than-working educational implementation. Contains extensions to original FM10000 Instruction set. Here are some of them: * **Automatic selection of Immediate/Register instructions**: No need to hardcode them, best pick will be selected. * **Call Stack, Frame & Stack pointers**: You have full access to a stack, POP/PUSH/GET/PUT and more! * `PUSH [N=1] / PUSH , [..., Vn]`, `POP [N=1]`, `POPI [N=1]`, `POPP (to be deprecated)`: Add/remove from stack. * `GET`, `PUT`: In-place stack data handling. * Uses `BSM_ADDR_OFFSET[2]` as frame pointer. * Uses `BSM_ADDR_OFFSET[3]` as stack pointer. * **Call/FastCall system**: For easy calling of other functions, and passing/returning values. * `CALL `, `FASTCALL [P1, P2, ..., Pn]` * `RET [V]` * Uses stack system. * **Scratch reservation system**: Statically allocate scratch space and assert other code does not use it. * **Aliases / Offsets / shifts in-place**: Stop hardcoding all your parameters! * **Shorthand aliases for instructions**: For directly using AND / ADD / BEQ / BNE and more. * `ADD`, `OR`, `AND`, `SUB`, `SHL`, `SHR`, `SAR` * `BNE`, `BEQ`, `PNE`, `PEQ` * **Extended instructions virtually**: Some instructions did not allow registers on them. * `SET , , `: Now registers allowed in all operands, with offsets. * `MOV , , [...Vn]`: Automatically select between WRITE and COPY depending on operands. Allows multi-word. * TODO: branch instructions to allow registers. * **New virtual instructions**: Several new mathematical and bitwise operations added: * `XOR , `: implemented via `a ^ b = a + b - (a & b) - (a & b)` in four native instructions. TODO: handle offsets. * `NOT , `: implemented via `~a = 0xFFFFFFFF - a` in one or three native instructions, depending on offsets. * **Basic stdlib functions**: Adds some must-have complex operations, and other quality of life ones. * `std_multiply `: Multiply two integers. Implemented with shift + add multiplication. * `std_divide `: Divide two integers, get quotient and remainder. Implemented with shift + add division. * Definition of standard value return registers. * Definition of standard ephemeral registers. * **Bitfield creation**: Parametrized bitfield shifts and mask creation. * `.bitfield REGISTER.Field [bitSize]` ### Usage * `$ rrc-as version` * `$ rrc-as code.asm [code2.asm ...] output.bin` * The function named `entrypoint` will be called by init asm * Multiple asm files can be specified. They are interpreted from first in arguments to last. * You can call functions across files, as they will be linked together when used. * Directive resolution occurs at parsing time, so while you can override values it does not affect previously parsed files. * Directives like `.constant`, `.reserve`, `.bitfield`, etc. are passed to the next files. * These files will be automatically included in front every time: * *[asm/registers.asm](asm/registers.asm)*: Base named registers for platform. * *[asm/config.asm](asm/config.asm)*: Contains user-configurable parameters. * *[asm/api.asm](asm/api.asm)*: Registers used for some driver/switch manager operations. * *[asm/stdlib.asm](asm/stdlib.asm)*: Standard library and other miscellaneous utilities. * *[asm/init.asm](asm/init.asm)*: Sets up some required registers and other config. ### Usage example Check out the [rrc-open-firmware](https://git.gammaspectra.live/FM10K/rrc-open-firmware) project for an in-depth look at the assembly and usage. Do note it uses its own rrcc tagged version. ## License * BSD-3-Clause * See [COPYING](COPYING) for the full license.