Skip to content
Snippets Groups Projects
Commit a7ca0016 authored by Yuxiao Mao's avatar Yuxiao Mao
Browse files

build : rom with _start and crt; Mv src files to /src

parent 1a740088
No related branches found
No related tags found
No related merge requests found
......@@ -2,67 +2,72 @@ CROSS_COMPILER = riscv32-unknown-elf-
CC = $(CROSS_COMPILER)gcc
LD = $(CROSS_COMPILER)ld
OBJCOPY = $(CROSS_COMPILER)objcopy
OBJDUMP = $(CROSS_COMPILER)objdump
SRCDIR = src/
MAINFILES = $(SRCDIR)crt.S $(SRCDIR)main.c
MAINOBJ = crt.o main.o
# -O0
CCFLAGS =
CCFLAGS = -I$(SRCDIR)lib
TOOLS = tools/
BIN2HEX = $(TOOLS)bin2hex
################### COMMANDS ###################
# make : build .s (debug) .hex (synthesis) .mem (data2mem) file
# make debug : generate .s
# make debug : generate .s for main.c, and generate progdump for overall system
# make bitgen : with .bit .mem .bmm generate new .bit
# make bitdump : dump old and new .bit file
# make clean : clean all (include new .bit)
################### RULES ###################
all: $(BIN2HEX) debug rom
################### C ###################
all: $(BIN2HEX) rom
# Tools
$(BIN2HEX): $(BIN2HEX).c
gcc $< -o $@
# Debug
debug: main.s
# Main
rom: prog.elf
$(OBJCOPY) -I elf32-little -O binary prog.elf prog.bin
$(BIN2HEX) prog.bin
%.s: %.c
$(CC) -o $@ -c $< -S $(CCFLAGS)
prog.elf: $(SRCDIR)link.ld $(MAINOBJ)
$(LD) -o $@ -T $^
# Main
rom: main.bin
$(BIN2HEX) $<
$(MAINOBJ): $(MAINFILES)
$(CC) -c $^ $(CCFLAGS)
main.bin: main.elf
$(OBJCOPY) -I elf32-little -O binary $< $@
# DEBUG : dump .c, .S, prog.elf
debug: main.s progdump.txt
%.elf: %.o link.ld
$(LD) -o $@ -T link.ld $<
%.s: $(SRCDIR)%.c
$(CC) -o $@ -c $< $(CCFLAGS) -S
%.o: %.s
$(CC) -o $@ -c $< $(CCFLAGS)
progdump.txt : prog.elf
$(OBJDUMP) -D $< > $@
################### XILINX ENV ###################
# Gen bit : generate new .bit file
bitgen: myorca_new.bit
myorca_new.bit: bramlayout.bmm main.mem myorca.bit
@echo "ATTENTION : [Verify .bit and .bmm after each re-implement]"
data2mem -bm bramlayout.bmm -bd main.mem -bt myorca.bit -o b myorca_new.bit
myorca_new.bit: $(SRCDIR)bramlayout.bmm prog.mem myorca.bit
@echo "ATTENTION : [Verify .bit(link) and .bmm(BRAM position) after each re-implement]"
data2mem -bm $(SRCDIR)bramlayout.bmm -bd prog.mem -bt myorca.bit -o b $@
main.mem: main.elf
data2mem -bd $< -d -o m main.mem
prog.mem: prog.elf
data2mem -bd $< -d -o m $@
# Dump .bit files.
# DEBUG : Dump .bit files.
bitdump: myorca_bitdump.txt myorca_new_bitdump.txt
@echo "Tips : [Search \"BRAM data\" or instance name ex \"tdp_ram/Mram_ram\" in the out put txt]"
myorca_bitdump.txt: bramlayout.bmm myorca.bit
data2mem -bm bramlayout.bmm -bt myorca.bit -d > myorca_bitdump.txt
myorca_bitdump.txt: $(SRCDIR)bramlayout.bmm myorca.bit
data2mem -bm $(SRCDIR)bramlayout.bmm -bt myorca.bit -d > $@
myorca_new_bitdump.txt: bramlayout.bmm myorca_new.bit
data2mem -bm bramlayout.bmm -bt myorca_new.bit -d > myorca_new_bitdump.txt
myorca_new_bitdump.txt: $(SRCDIR)bramlayout.bmm myorca_new.bit
data2mem -bm $(SRCDIR)bramlayout.bmm -bt myorca_new.bit -d > $@
clean:
rm -f *.s *.o *.elf *.bin *.hex
rm -f *.mem *bitdump.txt myorca_new.bit
rm -f *.mem *dump.txt myorca_new.bit
File moved
.section .text.init
.globl _start
_start:
la gp, _gp
la sp, _end_of_memory
jal main
//Store result in t3 and hit an ecall for 'test_done'
mv t3, a0
fence.i
ecall
1:
j 1b
#ifndef __MYORCA_UART_H
#define __MYORCA_UART_H
// Memory I/O macro
#define mmio32(x) (*(volatile unsigned long *)(x))
......@@ -12,50 +15,6 @@
// RO : get receive fifo element count
#define UART_3 (UART_BASE + 0x000C)
void uart_printc(char c);
void uart_printf(char *str);
char uart_read_char();
unsigned int uart_get_send_fifo_count();
unsigned int uart_get_read_fifo_count();
void wait(unsigned int n);
// Main must be the first function body in this file
int main(void)
{
static int data1 = 20;
static int data2 = 5;
static int result;
result = data1 * data2;
// Store the value in a6
asm volatile("mv a6,%0\n\t"
"rdtime a5"
:
: "r" (result)
: "a6");
uart_printf("M\r\n");
unsigned int uart_send_fifo_count = uart_get_send_fifo_count();
unsigned int uart_read_fifo_count = 0;
while (1) {
wait(1000);
uart_read_fifo_count = uart_get_read_fifo_count();
if (uart_read_fifo_count > 0) {
char read_value = uart_read_char();
uart_printf("Received value from Uart: (");
uart_printc(read_value);
uart_printf(").\r\n");
}
}
return 0;
}
void uart_printc(char c) {
mmio32(UART_0) = c; // write
......@@ -86,3 +45,5 @@ void wait(unsigned int n) {
asm volatile("nop"::);
}
}
#endif //#ifndef __MYORCA_UART_H
......@@ -21,13 +21,13 @@ MEMORY
/*----------------------------------------------------------------------*/
/* Sections */
/*----------------------------------------------------------------------*/
ENTRY(main)
ENTRY(_start)
SECTIONS
{
/* text: test code section */
. = 0x100;
/* text: test code section. init=RESET_VECTOR*/
. = 0x000;
.text.init . :
{
*(.text.init)
......
#include "myorca_uart.h"
// Main must be the first function body in this file
int main(void)
{
static int data1 = 20;
static int data2 = 5;
static int result;
result = data1 * data2;
// Store the value in a6
asm volatile("mv a6,%0\n\t"
"rdtime a5"
:
: "r" (result)
: "a6");
uart_printf("M\r\n");
unsigned int uart_send_fifo_count = uart_get_send_fifo_count();
unsigned int uart_read_fifo_count = 0;
while (1) {
wait(1000);
uart_read_fifo_count = uart_get_read_fifo_count();
if (uart_read_fifo_count > 0) {
char read_value = uart_read_char();
uart_printf("Received value from Uart: (");
uart_printc(read_value);
uart_printf(").\r\n");
}
}
return 0;
}
......@@ -59,7 +59,7 @@ int main(int argc, char *argv[])
}
while(1) {
if(fread(w, 4, 1, fdi) <= 0) break;
fprintf(fdo, "%02hhx%02hhx%02hhx%02hhx\n", w[0], w[1], w[2], w[3]);
fprintf(fdo, "%02hhx %02hhx %02hhx %02hhx\n", w[3], w[2], w[1], w[0]);
fprintf(fdo0, "%02hhx\n", w[0]);
fprintf(fdo1, "%02hhx\n", w[1]);
fprintf(fdo2, "%02hhx\n", w[2]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment