Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions c/Makefile.msys
Original file line number Diff line number Diff line change
@@ -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)
84 changes: 84 additions & 0 deletions c/gen_mem_msys.sh
Original file line number Diff line number Diff line change
@@ -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.$$
10 changes: 5 additions & 5 deletions c/setup.s
Original file line number Diff line number Diff line change
Expand Up @@ -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