diff --git a/c/Makefile.msys b/c/Makefile.msys new file mode 100644 index 0000000..f6f21a6 --- /dev/null +++ b/c/Makefile.msys @@ -0,0 +1,22 @@ +CC=/opt/riscv/bin/riscv32-unknown-elf-gcc.exe +AS=/opt/riscv/bin/riscv32-unknown-elf-as.exe +LD=/opt/riscv/bin/riscv32-unknown-elf-ld.exe +COPTS= -Wall -pedantic + +all : test + ./gen_mem_msys.sh test + rm setup.o test.o + +test : test.o setup.o + echo "---------------------------------------------------------" >> /dev/null + echo "-- Do not call anything main() - it will end up linked at" >> /dev/null + echo "-- the start of the program, rather than the setup code" >> /dev/null + echo "---------------------------------------------------------" >> /dev/null + ${LD} -Ttext 0xF0000000 -Tdata 0x10000000 -T linker_script setup.o test.o -o test + + +setup.o : setup.s + $(AS) -o setup.o --march=rv32i setup.s + +test.o : test.c + $(CC) -c test.c $(COPTS) diff --git a/c/gen_mem_msys.sh b/c/gen_mem_msys.sh new file mode 100644 index 0000000..b91df1f --- /dev/null +++ b/c/gen_mem_msys.sh @@ -0,0 +1,84 @@ +#!/bin/bash +############################################################################### +# gen_mem.sh - script to generate HDL memory files +# +# Part of the Rudi-RV32I project +# +# See https://github.com/hamsternz/Rudi-RV32I +# +# MIT License +# +############################################################################### +# +# Copyright (c) 2020 Mike Field +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +############################################################################### +OBJCOPY=/opt/riscv/bin/riscv32-unknown-elf-objcopy + +if [ ! -f "$1" ] +then + echo No file name given + exit +fi + +$OBJCOPY $1 /dev/null --dump-section .data=data.section.$$ --dump-section .text=text.section.$$ + +if [ ! -f data.section.$$ -o ! -f text.section.$$ ] +then + echo Unable to dump sections + exit +fi + +( + ############################# + ##### Output file header + ############################# + grep ^H: template_program_memory.vhd | cut -c 3- + + ############################# + ##### Output Program data + ############################# + cat text.section.$$ | od -An -w4 -v -tx4 | awk '{ print " " NR-1 " => x\"" $1 "\"," }' + + ############################# + ##### Output file footer + ############################# + grep ^F: template_program_memory.vhd | cut -c 3- +) > ../src/program_memory/program_memory_$1.vhd + +( + ############################# + ##### Output file header + ############################# + grep ^H: template_ram_memory.vhd | cut -c 3- + + ############################# + ##### Output Program data + ############################# + cat data.section.$$ | od -An -w4 -v -tx4 | awk '{ print " " NR-1 " => x\"" $1 "\"," }' + + ############################# + ##### Output file footer + ############################# + grep ^F: template_ram_memory.vhd | cut -c 3- +) > ../src/program_memory/ram_memory_$1.vhd + +rm data.section.$$ text.section.$$ diff --git a/c/setup.s b/c/setup.s index 89286a4..a84f557 100644 --- a/c/setup.s +++ b/c/setup.s @@ -35,11 +35,11 @@ .align 2 .globl _start .type _start, @function - .org 0 + .org 0 _start: lui a1,0x10001 - # Set the stack address to 0x10000FFC + # Set the stack address to 0x10000FFC addi sp, a1, -4 - # Call the main function - jal ra, test_program - j _start + # Call the main function + jal ra, test_program + j _start