From b568eca60d0b79a663138df77c6254e8ee94fb0c Mon Sep 17 00:00:00 2001 From: Raine Date: Mon, 15 Jan 2024 03:26:07 +0100 Subject: [PATCH] risc-v asm thingy --- experiments/riscv-asm/.gitignore | 1 + experiments/riscv-asm/build.sh | 17 +++++++++++++++++ experiments/riscv-asm/clean.sh | 4 ++++ experiments/riscv-asm/main.s | 19 +++++++++++++++++++ experiments/riscv-asm/run.sh | 4 ++++ wiki | 2 +- 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 experiments/riscv-asm/.gitignore create mode 100644 experiments/riscv-asm/build.sh create mode 100644 experiments/riscv-asm/clean.sh create mode 100644 experiments/riscv-asm/main.s create mode 100644 experiments/riscv-asm/run.sh diff --git a/experiments/riscv-asm/.gitignore b/experiments/riscv-asm/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/experiments/riscv-asm/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/experiments/riscv-asm/build.sh b/experiments/riscv-asm/build.sh new file mode 100644 index 0000000..4630752 --- /dev/null +++ b/experiments/riscv-asm/build.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e + +echo "Building for RISC-V 64..." + +[ -d "build" ] || mkdir build +rm -rf build/* + +riscv64-linux-gnu-as main.s -o build/main.o +riscv64-linux-gnu-gcc \ + build/main.o \ + -o build/main \ + -nostdlib \ + -static + +echo "OK" diff --git a/experiments/riscv-asm/clean.sh b/experiments/riscv-asm/clean.sh new file mode 100644 index 0000000..bcca65a --- /dev/null +++ b/experiments/riscv-asm/clean.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +rm -rf build + diff --git a/experiments/riscv-asm/main.s b/experiments/riscv-asm/main.s new file mode 100644 index 0000000..4313c80 --- /dev/null +++ b/experiments/riscv-asm/main.s @@ -0,0 +1,19 @@ +.global _start + +_start: + addi a7, x0, 64 # syscall write + addi a0, x0, 1 # stdout fd + la a1, str_helloworld # load label into reg: a1 + addi a2, x0, 13 # length of string + ecall # call kernel + + beqz x0, _exit # branch if = to zero + +_exit: + addi a7, x0, 93 # syscall exit + addi a0, x0, 0 # exit code + ecall # call kernel + + +str_helloworld: + .ascii "Hello World!\n" diff --git a/experiments/riscv-asm/run.sh b/experiments/riscv-asm/run.sh new file mode 100644 index 0000000..39f4b8a --- /dev/null +++ b/experiments/riscv-asm/run.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +[ "$1" = "build" ] && sh ./build.sh +qemu-riscv64 build/main diff --git a/wiki b/wiki index 4d6611a..b04ae4e 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 4d6611aef6deca10807075574c596f98d8769d46 +Subproject commit b04ae4e652f236922a65fe4fbfdde36da732d24b