1
0
Fork 0

risc-v asm thingy

This commit is contained in:
Strix 2024-01-15 03:26:07 +01:00
parent 2fc057b6e8
commit b568eca60d
No known key found for this signature in database
GPG key ID: 5F35B3B8537287A7
6 changed files with 46 additions and 1 deletions

1
experiments/riscv-asm/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
build/

View 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"

View file

@ -0,0 +1,4 @@
#!/bin/sh
rm -rf build

View 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"

View file

@ -0,0 +1,4 @@
#!/bin/sh
[ "$1" = "build" ] && sh ./build.sh
qemu-riscv64 build/main

2
wiki

@ -1 +1 @@
Subproject commit 4d6611aef6deca10807075574c596f98d8769d46 Subproject commit b04ae4e652f236922a65fe4fbfdde36da732d24b