Skip to content

Commit 92b06fe

Browse files
authored
Merge pull request #1 from git-bruh/main
Use a docker image for cross compilation
2 parents 7274449 + 3f2cfe9 commit 92b06fe

File tree

6 files changed

+53
-38
lines changed

6 files changed

+53
-38
lines changed

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# RISCulator Makefile
2+
3+
DOCKER_IMAGE = dockcross/linux-riscv32
4+
5+
DISASSEMBLY = target/out.txt
6+
DOCKER_DISASM_SCRIPT = src/scripts/docker_disasm.sh
7+
8+
all: risculator $(DISASSEMBLY) run
9+
10+
$(DISASSEMBLY): src/test/main.c $(DOCKER_DISASM_SCRIPT)
11+
$(DOCKER_DISASM_SCRIPT)
12+
13+
risculator: $(DISASSEMBLY)
14+
cargo build
15+
16+
run: risculator $(DISASSEMBLY)
17+
cargo run -- $(DISASSEMBLY)
18+
19+
clean:
20+
rm -rf target

README.md

+3-13
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@ To be updated. WIP.
77

88
## Installation
99

10-
### RISC-V GCC Compiler installation
11-
12-
#### Option 1:
13-
- Head to https://github.com/riscv-collab/riscv-gnu-toolchain and build the compiler.
14-
15-
#### Option 2:
16-
- Head to https://www.embecosm.com/resources/tool-chain-downloads/ and install a pre-built distro-specific compiler image and add the bin directory to PATH.
17-
18-
**Note:** Make sure you install both 32-bit and 64-bit compilers. RISCulator will support both instruction length emulation.
19-
2010
### RISCulator installation
2111
- Install the Rust compiler 'rustc' using rustup.
2212

@@ -28,11 +18,11 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
2818
```bash
2919
git clone https://github.com/skudlur/RISCulator.git
3020
```
31-
- Change directory to RISCulator/src and run the following
21+
- Change directory to RISCulator and run the following
3222

3323
```bash
34-
cd RISCulator/src
35-
make all
24+
cd RISCulator
25+
make
3626
```
3727

3828
### Checklist

src/Makefile

-22
This file was deleted.

src/main.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::thread::spawn;
1616
use std::fmt::Binary;
1717
use colored::*;
1818
use std::mem::MaybeUninit;
19+
use std::env;
1920

2021
// Utilities and other imports here
2122
mod utils;
@@ -317,7 +318,13 @@ impl Vproc {
317318

318319
// RISCulator main function
319320
fn main() {
320-
let mut path: String = "test/main.c".to_string();
321+
let args: Vec<String> = env::args().collect();
322+
323+
if args.len() < 2 {
324+
println!("Not enough arguments! Must pass the path of the disassembly as the first argument");
325+
return
326+
}
327+
321328
utils::logo_display();
322329
println!("{}", "|----------------- A lightweight RISC-V emulator -----------------|".red());
323330
utils::boot_seq(XLEN, EXTENSION, REG_SIZE, RAM_SIZE);
@@ -385,7 +392,7 @@ fn main() {
385392
", "Fetch".green());
386393
log::info!("Stage 1: Fetch stage starting");
387394
log::info!("Prepping for fetch operations");
388-
let program_parsed = utils::program_parser("test/out.txt", &mut proc.ram_module);
395+
let program_parsed = utils::program_parser(&args[1], &mut proc.ram_module);
389396
log::info!("Program loaded to main memory!");
390397
proc.ram_module.print_dirty();
391398
println!("

src/scripts/docker_disasm.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
TRIPLET=riscv32-unknown-linux-gnu
6+
7+
docker run \
8+
-v ./src:/src \
9+
-v ./target:/artifact \
10+
--rm -i dockcross/linux-riscv32 \
11+
sh - <<EOF
12+
cd /artifact
13+
${TRIPLET}-cc -march=rv32id -c /src/test/main.c -o main.o
14+
${TRIPLET}-objcopy -O binary -j .text main.o binfile
15+
${TRIPLET}-objdump -d main.o > out.txt
16+
17+
# Hack to make the created files and dirs rw by all users
18+
# since docker creates files in mounted volumes as root...
19+
chmod 777 -R /artifact
20+
EOF

src/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static mut PC: isize = 0x0000;
3434
// Logo displaying function
3535
pub fn logo_display() {
3636
/* RISCulator logo */
37-
let filename = "assets/logo.txt";
37+
let filename = "src/assets/logo.txt";
3838
let logo_con = fs::read_to_string(filename)
3939
.expect("Failed to read the file");
4040
println!("{}", logo_con.yellow());

0 commit comments

Comments
 (0)