File: internal-structure.md

package info (click to toggle)
riscemu 2.2.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,036 kB
  • sloc: python: 5,669; asm: 780; sh: 28; makefile: 26
file content (32 lines) | stat: -rw-r--r-- 1,550 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Internal Structure

## Loading assembly files:
In order to load an assembly file, you need to instantiate a CPU with the capabilities you want. Loading an assembly
file is the done in multiple steps:


* An `RiscVInput` is created, this represents the file internally
* An `RiscVTokenizer` is created by calling `cpu.get_tokenizer()`.
* The input is tokenized by calling `.tokenize()` on the tokenizer.
* The tokens can then be converted to an Executable, this will then
  hold all the information such as name, sections, symbols, etc.
  This is done by creating an `ExecutableParser(tk: RiscVTokenizer)`
  and the calling `parse()`.
* Now you have a representation of the assembly file that can be loaded
  into memory by calling `cpu.load(executable)`, this will internally
  construct a `LoadedExecutable`, which represents the actual memory
  regions the executable contains (and some meta information such as
  symbols).
* You can load as many executables as you want into memory. If you want
  to run one, you pass it to `run_loaded(loaded_bin)` method of the cpu.

You shouldn't have to do this manually, as the `riscemu/__main__.py` has all the necessary code.

## Instruction sets
Each instruction set is in a separate file in `riscemu/instructions/`. All instruction sets have to inherit from the
`InstructionSet` class that sets up all the relevant helpers and loading code.

Creating a cpu with certain instruction sets is done by passing the CPU constructor a list of instruction set classes:
```
cpu = CPU(config, [RV32I, RV32M])
```