risc-v asm thingy
This commit is contained in:
parent
2fc057b6e8
commit
b568eca60d
6 changed files with 46 additions and 1 deletions
1
experiments/riscv-asm/.gitignore
vendored
Normal file
1
experiments/riscv-asm/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
build/
|
17
experiments/riscv-asm/build.sh
Normal file
17
experiments/riscv-asm/build.sh
Normal file
|
@ -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"
|
4
experiments/riscv-asm/clean.sh
Normal file
4
experiments/riscv-asm/clean.sh
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
rm -rf build
|
||||||
|
|
19
experiments/riscv-asm/main.s
Normal file
19
experiments/riscv-asm/main.s
Normal file
|
@ -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"
|
4
experiments/riscv-asm/run.sh
Normal file
4
experiments/riscv-asm/run.sh
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
[ "$1" = "build" ] && sh ./build.sh
|
||||||
|
qemu-riscv64 build/main
|
2
wiki
2
wiki
|
@ -1 +1 @@
|
||||||
Subproject commit 4d6611aef6deca10807075574c596f98d8769d46
|
Subproject commit b04ae4e652f236922a65fe4fbfdde36da732d24b
|
Loading…
Reference in a new issue