diff options
author | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2024-05-08 10:55:45 +0200 |
---|---|---|
committer | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2024-05-08 10:55:45 +0200 |
commit | aa005bc8b667668eb43c0ae62e00aefd1c3c1af5 (patch) | |
tree | a491b20a750cf0dac413aa10deb2ead3b6266fc3 /prog | |
parent | 80fee7a2db703f029989c40e823c2ccdeb078fca (diff) | |
download | riscv_cpu-aa005bc8b667668eb43c0ae62e00aefd1c3c1af5.tar.gz riscv_cpu-aa005bc8b667668eb43c0ae62e00aefd1c3c1af5.zip |
assemble simple rom
Diffstat (limited to 'prog')
-rwxr-xr-x | prog/build.sh | 6 | ||||
-rw-r--r-- | prog/link.ld | 16 | ||||
-rwxr-xr-x | prog/main.bin | bin | 0 -> 16 bytes | |||
-rwxr-xr-x | prog/main.elf | bin | 0 -> 8764 bytes | |||
-rw-r--r-- | prog/main.hex | 16 | ||||
-rw-r--r-- | prog/main.o | bin | 0 -> 4880 bytes | |||
-rw-r--r-- | prog/main.s | 24 |
7 files changed, 62 insertions, 0 deletions
diff --git a/prog/build.sh b/prog/build.sh new file mode 100755 index 0000000..22557b4 --- /dev/null +++ b/prog/build.sh @@ -0,0 +1,6 @@ +#!/bin/sh +riscv64-unknown-elf-as -march=rv32i -mabi=ilp32 -o main.o main.s +riscv64-unknown-elf-ld -T link.ld -m elf32lriscv -o main.elf main.o +riscv64-unknown-elf-objcopy -O binary main.elf main.bin +xxd -g 1 -c 1 -p main.bin >main.hex +cp -f main.hex ../rom/rom.hex diff --git a/prog/link.ld b/prog/link.ld new file mode 100644 index 0000000..98658c3 --- /dev/null +++ b/prog/link.ld @@ -0,0 +1,16 @@ +OUTPUT_ARCH( "riscv" ) +ENTRY(_start) + +MEMORY +{ + ROM (rx) : ORIGIN = 0x00010000, LENGTH = 0xF0000 # 0x0001_0000 - 0x000F_FFFF + RAM (rwx) : ORIGIN = 0x00100000, LENGTH = 0xFEFFFFF # 0x0010_0000 - 0xFF0F_FFFF +} + +SECTIONS +{ + .text : { *(.text) } > ROM + .data : { *(.data) } > RAM + .bss : { *(.bss) } > RAM + .stack : { *(.stack) } > RAM +} diff --git a/prog/main.bin b/prog/main.bin Binary files differnew file mode 100755 index 0000000..ba70022 --- /dev/null +++ b/prog/main.bin diff --git a/prog/main.elf b/prog/main.elf Binary files differnew file mode 100755 index 0000000..4c53d74 --- /dev/null +++ b/prog/main.elf diff --git a/prog/main.hex b/prog/main.hex new file mode 100644 index 0000000..116b9b4 --- /dev/null +++ b/prog/main.hex @@ -0,0 +1,16 @@ +93 +02 +50 +00 +13 +03 +30 +00 +b3 +83 +62 +00 +6f +00 +00 +00 diff --git a/prog/main.o b/prog/main.o Binary files differnew file mode 100644 index 0000000..e50c4a8 --- /dev/null +++ b/prog/main.o diff --git a/prog/main.s b/prog/main.s new file mode 100644 index 0000000..bbae5bb --- /dev/null +++ b/prog/main.s @@ -0,0 +1,24 @@ +.section .text +.globl _start + +_start: + #la sp, stack_top + + #li a0, 10 + #li a1, 20 + #add a2, a0, a1 + addi t0, zero, 5 + addi t1, zero, 3 + add t2, t0, t1 + +halt_loop: + j halt_loop + +.section .data + + +.section .bss + +.section .stack + .space 0x1000 # Allocate stack space +stack_top: |