README.md (4579B)
1 [](https://github.com/gboncoffee/egg/actions/workflows/go.yml) 2 [](https://github.com/gboncoffee/egg/actions/workflows/github-code-scanning/codeql) 3 4 [Ler esse documento em português](README-pt.md) 5 6 # EGG, a generic processor emulator 7 8 [Video tutorial](https://youtu.be/RtKvvXgdVak?si=OtjkNxSGmRGNou67) 9 10 [Documentation](https://egg.gboncoffee.dev.br/docs/en) 11 12 [Contributing, bugs, feature requests](CONTRIBUTING.md) 13 14 EGG stands for "Emulador Genérico do Gabriel" ("Gabriel's Generic Emulator", in 15 portuguese). It's a modular emulator for processor architetures, made for 16 educational purpouses. 17 18 The `egg` package itself provides only an interface for interacting with 19 machines, thus supporting different architeture backends. Currently, there are 20 RISC-V IM 32 bits, MIPS32 and a fantasy 8 bit architecture "Sagui" backends 21 implemented. 22 23 `egg/assembler` also provides a small library for creating assemblers, and the 24 support for EGG's debugger. 25 26 ### UFPR students 27 28 Have any questions, or want some help? Mail me: `ggb23@inf.ufpr.br`. Or find me 29 at the campus and the laboratories! 30 31 ## Installation 32 33 Simply grab the static binary for your OS at the 34 [releases](https://github.com/gboncoffee/egg/releases) page. Or, if you have the 35 Go compiler, build the project from source. 36 37 Note: I always test the binary for Linux x86_64. I test Darwin (x86_64 and 38 ARM64) if I manage to. Other binaries are not tested but should work properly. 39 40 ## Quickstart 41 42 EGG is a command line application, you must run it from a terminal emulator. 43 44 Running the emulator with an Assembly file will assemble it and start a machine 45 to run it on. By default, the machine is a RISC-V IM 32 bits. Use the flag `-a` 46 or `-arch` to change the architeture. Run `egg -h` to see all command line 47 options and `egg -l` to see all supported architetures. 48 49 The Assembly syntax is architeture-dependent. Though, a library is provided for 50 creating assembler, so backends may use the same overall syntax (both RISC-V and 51 MIPS uses it). 52 53 An example follows: 54 55 ```asm 56 ; Semicolon makes a comment til the end of line. 57 58 ; A label is defined with :. 59 label: 60 ; Instruction arguments starts with destination. 61 addi t0, zero, 2 62 63 ; You may also put instructions after the labels. 64 label2: add t0, t0, t0 65 66 ; There's no parenthesis as in RARS, store uses common immediates. 67 sb t0, ra, 3 68 69 ; Hex, octal and binary immediates are supported. 70 addi t1, zero, 0xff 71 addi t1, zero, 0b010110 72 addi t1, zero, 0o644 73 addi t1, zero, 0755 ; A leading 0 also defines an octal. 74 75 ; A # defines a literal til the end of the line. 76 ; Literals are inserted unchanged to the binary (as 'db' in other assemblers). 77 ; If a % is followed by two hex digits, the hex value is inserted instead. Use 78 ; %% to escape it. 79 msg: 80 #Hello, World!%0a 81 82 ; Some directives are supported. "bitsxx" ones creates literal numbers in the 83 ; code, with the bit length specified: 84 .bits8 0xca 0xfe 0xba 0xbe 0xde 0xad 0xbe 0xef 85 .bits16 0xcafe 0xbabe 0xdead 0xbeef 86 .bits32 0xcafebabe 0xdeadbeef 87 .bits64 0xcafebabedeadbeef 88 ; The "space" directive adds some bytes of spacing in the code: 89 .space 16 90 ; The "include" directive "copy-pastes" another file in the code: 91 .include other-asm.asm 92 ``` 93 94 Each architeture folder has test Assembly files you may use as examples. 95 96 ## Calls 97 98 Standard calls handled by the emulator are as follows. Refer to the architeture 99 documentation on how to perform them: 100 101 - BREAK (Number 1): Transfer control to debugger or stop the machine. 102 No arguments. 103 - READ (Number 2): Read input. 104 - Argument 1: Buffer address. 105 - Argument 2: Size of input in bytes. 106 - WRITE (Number 3): Write output. 107 - Argument 1: Buffer address. 108 - Argument 2: Size of output in bytes. 109 110 ## Debugger 111 112 The debugger interface is kinda similar to `gdb`, though much smaller. Use the 113 `-d` flag to enter debugger uppon startup. There's no need of `run` command, as 114 there's no process. The `next` or the `continue` commands may be used to start 115 running the program normally. Use `help` to see all available commands. 116 117 ## Supporting the project 118 119 EGG is actively used for computer science education and maintained by myself and 120 other volunteers. You can support our work by joining us writing code, helping 121 with the docs and checking for bugs. 122 123 If you want to support us financially, please consider instead 124 [donating to Ukraine](https://u24.gov.ua/). 125 126 :brazil: :ukraine: