Skip to content
C2k-studioPublic

About

simu86: run ARM64 and x86-64 programs and small kernels on a simulated CPU and look inside - step, registers, memory

Topics

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

simu86

Run a program on a simulated CPU and look inside. simu86 is a command line tool and its engine simu: step one instruction, read the registers and the memory, stop at an address, see in words what a program did, and boot a program on an empty machine with no operating system, which is the start of writing your own OS. Written in Jex. It runs on an ARM64 Linux system (a phone with Termux or exshell works).

CPU now next
ARM64 Linux programs (static) and the bare virt board: integer, scalar floating point, exceptions, timer, MMU, serial port, disk, screen more of the vector instructions, a faster engine
x86-64 Linux programs (static): integer, SSE and SSE2 (floating point and vectors), the usual system calls: simu86 run, stats, trace, info (the core came from the tool jx86) a bare machine for an operating system, AVX, threads

Try it

simu86 run prog-x86      # a static x86-64 Linux program (the file tells the CPU): run it
simu86 stats prog-x86    # run it and say what kinds of instructions it did, and how fast
simu86 trace prog-x86 20 # the address and the bytes of the first 20 instructions
simu86 info FILE         # what a program file is, and whether simu86 can run it
simu86 cpus              # what each CPU can do
simu86 demo                     # a small machine is built, run and explained
simu86 examples/hello.jex       # build and run a program for the empty machine
simu86 stats my.jex             # run it and say what kinds of instructions it did
simu86                          # the prompt: type / to see the commands

The prompt

simu86> /load examples/hello.jex
loaded examples/hello.jex: a bare ARM64 program on the empty machine (RAM 64 MB), starts at 0x400000b0
simu86> /step 3
0x400000b0  140000e6  jump
...
simu86> /regs
simu86> /mem 0x40100000 64
simu86> /break 0x40000448
simu86> /run
command what it does
/dir [FOLDER], /cd FOLDER, /pwd look for files (folders end with /, * marks a .jex); ~/ :/ f:/ are home, 0:/ the phone storage
/boot FILE load it on the empty machine (a raw kernel linked at a low address; a source with #target or #!library is recognised by itself)
/load FILE [ARGS] a .jex source (built with jexcmp) or a static ARM64 program
/run run to the end, to a break point or to the limit
/step [N] one instruction (or N): address, instruction word, its kind, the registers that changed
/regs x0..x30, sp, pc, the flags (and the exception level on the empty machine)
/mem ADDRESS [BYTES] memory as bytes and letters
/break ADDRESS, /break off stop there; forget the stops
/stats run and report the share of every kind of instruction
/reset start the program again
/info what is loaded and where it is
/demo a small empty-machine program
/config, /set NAME VALUE, /defaults the settings
/help, /exit

The same words work as commands: simu86 [run] PROGRAM [ARGS], simu86 boot KERNEL, simu86 stats PROGRAM, simu86 demo, simu86 config, simu86 set NAME VALUE, simu86 help. The exit code is the one of the program (139: it used an address with no memory; 132: an instruction that is not simulated yet; 124: the limit).

Settings

Kept in ~/.config/simu86/config (a text file).

name values (the first is the usual one) meaning
cpu auto, arm64, x86-64 the CPU (auto: the file tells)
ram 64 MB of the empty machine, 1..1024
limit 0 stop after so many instructions (0: no limit)
regs changed, all what /step shows
base hex, dec how numbers are shown
color on, off
report off, on the report after every run
compiler jexcmp what builds a .jex file

The empty machine

A program with a #target virt block has no operating system under it: it starts at entry, its memory is the ram you name, the byte register console is the serial port and writing to exit stops the machine. See examples/ and the guide BARE.md of Jex (vectors, interrupts, the timer, the MMU).

Build and test

sh build.sh      # _out/simu86   (needs jexcmp; JCMP=path chooses it)
sh test.sh

Install

In exshell: ex install simu86. Anywhere on Linux ARM64 (a phone with Termux too), from the releases of this repository:

curl -fsSL https://raw.githubusercontent.com/C2k-studio/simu86/main/install.sh | sh

wget -qO- or jurl -fsSL work in the place of curl -fsSL. Options after sh -s --: --dir FOLDER, --version 0.2.2. The program is also on the releases page with its SHA-256. To build a .jex source you need the compiler Jexcmp (jexcmp).

A short lesson

  1. simu86 demo and read the program and the report.
  2. simu86, then /load examples/uart.jex, /step 5, /regs.
  3. Change the text in examples/uart.jex, /load it again and /run.

Files

file or folder what is in it
simu86.jex the command line: commands, settings, building a source, reports
s86_line.j the line editor of the prompt (from the tool ascode)
simu/ the engine: the CPU, the system calls, the machine and its devices. It has its own interface, documents and tests and uses nothing outside its folder: copy the folder into your project and #import "simu"

How to help: CONTRIBUTING.md. The plan: simu/docs/roadmap.md. License: Mozilla Public License 2.0.

About

simu86: run ARM64 and x86-64 programs and small kernels on a simulated CPU and look inside - step, registers, memory

Topics

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages