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

build : rom rdtime

parent 2c1cac0e
No related branches found
No related tags found
No related merge requests found
......@@ -3,26 +3,37 @@ CC = $(CROSS_COMPILER)gcc
LD = $(CROSS_COMPILER)ld
OBJCOPY = $(CROSS_COMPILER)objcopy
# -O0
CCFLAGS =
TOOLS = tools/
BIN2MEM = $(TOOLS)bin2mem
################### RULES ###################
all: $(BIN2MEM) rom
all: $(BIN2MEM) debug rom
# Tools
$(BIN2MEM): $(BIN2MEM).c
gcc $< -o $@
# Debug
debug: main.s
%.s: %.c
$(CC) -o $@ -c $< -S $(CCFLAGS)
# Main
rom: main.bin
$(BIN2MEM) $<
%.bin: %.elf
main.bin: main.elf
$(OBJCOPY) -I elf32-little -O binary $< $@
%.elf: %.o
%.elf: %.o link.ld
$(LD) -o $@ -T link.ld $<
%.o: %.c
$(CC) -o $@ -c $< -O0
%.o: %.s
$(CC) -o $@ -c $< $(CCFLAGS)
clean:
rm -f *.s *.o *.elf *.bin *.hex
......@@ -14,7 +14,9 @@
OUTPUT_ARCH( "riscv" )
MEMORY
{
MEM : ORIGIN = 0x0, LENGTH = 32K
IMEM : ORIGIN = 0x0, LENGTH = 16K
DMEM : ORIGIN = 16K, LENGTH = 16K
FMEM : ORIGIN = 32K, LENGTH = 200K
}
/*----------------------------------------------------------------------*/
/* Sections */
......@@ -25,42 +27,42 @@ SECTIONS
{
/* text: test code section */
. = 0x000;
. = 0x100;
.text.init . :
{
*(.text.init)
}>MEM
}>IMEM
.text :
{
*(.text)
}>MEM
}>IMEM
/* data segment */
.data : { *(.data) }>MEM
.rodata : { *(.rodata) }>MEM
.data : { *(.data) }>DMEM
.rodata : { *(.rodata) }>FMEM
.sdata : {
_gp = . + 0x800;
*(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata*)
*(.sdata .sdata.* .gnu.linkonce.s.*)
}>MEM
}>DMEM
/* bss segment */
.sbss : {
*(.sbss .sbss.* .gnu.linkonce.sb.*)
*(.scommon)
}>MEM
.bss : { *(.bss) }>MEM
}>DMEM
.bss : { *(.bss) }>DMEM
/* thread-local data segment */
.tdata :
{
_tls_data = .;
*(.tdata)
}>MEM
}>DMEM
.tbss :
{
*(.tbss)
}>MEM
}>DMEM
......
int main() {
int a=5, b=13;
int c=a+b;
return 0;
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");
while (1) ;
return 0;
}
......@@ -59,7 +59,6 @@ int main(int argc, char *argv[])
}
while(1) {
if(fread(w, 4, 1, fdi) <= 0) break;
// fdo just for easy humain read
fprintf(fdo, "%02hhx%02hhx%02hhx%02hhx\n", w[0], w[1], w[2], w[3]);
fprintf(fdo0, "%02hhx\n", w[0]);
fprintf(fdo1, "%02hhx\n", w[1]);
......
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