diff --git a/Cargo.lock b/Cargo.lock index a4e53d9..1af0f32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -145,6 +145,16 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "i8086-rs" +version = "0.1.0" +dependencies = [ + "clap", + "env", + "env_logger", + "log", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -193,16 +203,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "minix-8086-rs" -version = "0.1.0" -dependencies = [ - "clap", - "env", - "env_logger", - "log", -] - [[package]] name = "num_threads" version = "0.1.7" diff --git a/Cargo.toml b/Cargo.toml index d18ba80..462b4b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "minix-8086-rs" +name = "i8086-rs" version = "0.1.0" edition = "2024" diff --git a/README.md b/README.md index 3a20ede..0f19b89 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ It includes: - a.out Parser to parse legacy MINIX 1.x executables. - 8086 disassembler to parse the 16-bit instructions into an IR and prints them in a `objdump(1)`-style fashion. -- 8086 interpreter which interprets the instructions with MINIX 1.x conventions (e.g. interrupts, memory layout, ...) in mind and obeys segment register indirection, which enables the usage of the entire 20-bit memory bus. +- 8086 interpreter which interprets the instructions with MINIX 1.x conventions (e.g. interrupts, memory layout, ...) in mind and obeys segment register indirection, which enables the usage of the **entire 20-bit memory bus**. ## Usage @@ -27,19 +27,22 @@ RUST_LOG=debug cargo run -- interpret -p ./a.out 2>&1 | less CLI Options: ``` $ cargo run -- --help -Simple program to disassemble and interpret 8086 a.out compilates, e.g. such for MINIX - -Usage: 8086-rs [OPTIONS] - -Commands: - disasm Disassemble the binary into 8086 instructions - interpret Interpret the 8086 instructions - help Print this message or the help of the given subcommand(s) - -Options: - -p, --path Path of the binary - -d, --dump Dump progress of disassembly, in case of encountering an error - -h, --help Print help +Simple program to disassemble and interpret 8086 a.out compilates, e.g. such for MINIX + +Usage: i8086-rs [OPTIONS] [ARGV]... + +Commands: + disassemble Disassemble the binary into 8086 instructions [aliases: d] + interpret Interpret the 8086 instructions [aliases: i] + help Print this message or the help of the given subcommand(s) + +Arguments: + [ARGV]... argv passed to the program, which will be interpreted + +Options: + -p, --path Path of the binary + -d, --dump Dump progress of disassembly, in case of encountering an error + -h, --help Print help -V, --version Print version ``` @@ -54,16 +57,18 @@ But first I want to implement all features correctly and add tests for all of th ## Caveats -Interpreted code is disassembled into a Vector, which will also be used for execution. -This means, that the code is not actually loaded into memory, but the `CS:IP` addressing scheme is still being used. +Code is currently not fetched from memory, but from a seperate vector, stored inside the Disassembler struct, which fetches and parses the next instruction from the instruction pointer. +Although, the `CS:IP` addressing scheme is still being used, to allow for 20-bit access, but does currently now allow for self-modifying code. +Also the disassmbler just uses an initial sweep for disassembly, which has a high probability of not being accurate, when compared to the runtime. +E.g. maybe there is a jump to a memory address during interpretation, which was not identified as an instruction by the disassembler. ## Documentation The documentation of the project itself can be accessed by using `cargo doc`. ``` $ cargo doc -$ firefox target/doc/8086_rs/index.html +$ firefox target/doc/i8086_rs/index.html ``` For the implementation of the disassembly, I used the Intel "8086 16-BIT HMOS MICROPROCESSOR" Spec, as well as [this](http://www.mlsite.net/8086/8086_table.txt) overview of all Opcode variants used in conjunction with [this](http://www.mlsite.net/8086/) decoding matrix. diff --git a/src/main.rs b/src/main.rs index 24bbfca..7697dce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,9 +15,11 @@ mod register; #[derive(Subcommand, Debug)] enum Command { /// Disassemble the binary into 8086 instructions - Disasm, + #[clap(visible_alias("d"))] + Disassemble, /// Interpret the 8086 instructions + #[clap(visible_alias("i"))] Interpret, } @@ -52,7 +54,7 @@ fn main() { log::debug!("{:?}", args); match args.command { - Command::Disasm => { + Command::Disassemble => { let mut disasm = Disassembler::new(&args); let instructions = disasm.disassemble(args.dump); match instructions {