makefile change
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,2 @@
|
|||||||
#executables
|
#executables
|
||||||
*.out
|
*.out
|
||||||
*.exe
|
|
||||||
14
makefile
14
makefile
@@ -1,2 +1,12 @@
|
|||||||
default:
|
CC := gcc
|
||||||
gcc src/*.c -o tinyriscv
|
FLAGS := -Wall -O2
|
||||||
|
|
||||||
|
SRC := src/*.c
|
||||||
|
TARGET := tinyriscv.out
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(CC) $(SRC) $(FLAGS) -o $(TARGET)
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm $(TARGET)
|
||||||
12
src/main.c
12
src/main.c
@@ -107,10 +107,12 @@ void regdump(const tinyriscv_core* core){
|
|||||||
|
|
||||||
void memdump(const tinyriscv_core* core, uint32_t addr){
|
void memdump(const tinyriscv_core* core, uint32_t addr){
|
||||||
addr -= tinyriscv_MEM_OFFSET;
|
addr -= tinyriscv_MEM_OFFSET;
|
||||||
if(addr + 256 > core->mem_size) help("memdump: Address out of memory range.");
|
if(addr + 256 > core->mem_size){
|
||||||
|
help("memdump: Address out of memory range.");
|
||||||
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" Address Memory ASCII\n ");
|
printf(" Address Memory ASCII\n");
|
||||||
for(unsigned int i = 0; i < 73; i++) printf("─");
|
for(unsigned int i = 0; i < 73; i++) printf("─");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
@@ -157,7 +159,10 @@ void load_mem_from_file(tinyriscv_core* core, const char* file_path){
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fread(core->mem, 1, file_size, file);
|
if(fread(core->mem, 1, file_size, file) != file_size){
|
||||||
|
perror("ERROR: 'fread' count different from expected file size.");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,6 +182,7 @@ int main(int argc, char** argv){
|
|||||||
else if(!strcmp(argv[i], "--bin")){
|
else if(!strcmp(argv[i], "--bin")){
|
||||||
if(i + 1 >= argc) help("Invalid file path.");
|
if(i + 1 >= argc) help("Invalid file path.");
|
||||||
strncpy(file_path, argv[i++ + 1], 256);
|
strncpy(file_path, argv[i++ + 1], 256);
|
||||||
|
file_path[255] = '\0';
|
||||||
}
|
}
|
||||||
else if(!strcmp(argv[i], "--mem_size")){
|
else if(!strcmp(argv[i], "--mem_size")){
|
||||||
if(i + 1 >= argc) help("Invalid [mem_size] value.");
|
if(i + 1 >= argc) help("Invalid [mem_size] value.");
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ void tinyriscv_step(tinyriscv_core* core){
|
|||||||
#define rs1 (inst >> 15 & 0x1f)
|
#define rs1 (inst >> 15 & 0x1f)
|
||||||
#define rs2 (inst >> 20 & 0x1f)
|
#define rs2 (inst >> 20 & 0x1f)
|
||||||
#define imm_i ((i32)inst >> 20)
|
#define imm_i ((i32)inst >> 20)
|
||||||
#define imm_s (imm_i & 0xffffffe0 | rd)
|
#define imm_s ((imm_i & 0xffffffe0) | rd)
|
||||||
|
|
||||||
#define imm_b (((i32)(inst & 0x80000000) >> 19) | \
|
#define imm_b (((i32)(inst & 0x80000000) >> 19) | \
|
||||||
((inst & 0x80) << 4) | (inst >> 20 & 0x7e0) | (inst >> 7 & 0x1e))
|
((inst & 0x80) << 4) | (inst >> 20 & 0x7e0) | (inst >> 7 & 0x1e))
|
||||||
|
|||||||
BIN
tests/1.bin
BIN
tests/1.bin
Binary file not shown.
@@ -1,8 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
uint32_t* ptr = 0x800000F0;
|
|
||||||
|
|
||||||
*ptr = 1;
|
|
||||||
while(*ptr) (*ptr)++;
|
|
||||||
}
|
|
||||||
37
tests/1.s
37
tests/1.s
@@ -1,37 +0,0 @@
|
|||||||
.file "1.c"
|
|
||||||
.option nopic
|
|
||||||
.attribute arch, "rv32i2p1"
|
|
||||||
.attribute unaligned_access, 0
|
|
||||||
.attribute stack_align, 16
|
|
||||||
.text
|
|
||||||
.align 2
|
|
||||||
.globl main
|
|
||||||
.type main, @function
|
|
||||||
main:
|
|
||||||
addi sp,sp,-32
|
|
||||||
sw s0,28(sp)
|
|
||||||
addi s0,sp,32
|
|
||||||
li a5,-2147483648
|
|
||||||
addi a5,a5,240
|
|
||||||
sw a5,-20(s0)
|
|
||||||
lw a5,-20(s0)
|
|
||||||
li a4,1
|
|
||||||
sw a4,0(a5)
|
|
||||||
j .L2
|
|
||||||
.L3:
|
|
||||||
lw a5,-20(s0)
|
|
||||||
lw a5,0(a5)
|
|
||||||
addi a4,a5,1
|
|
||||||
lw a5,-20(s0)
|
|
||||||
sw a4,0(a5)
|
|
||||||
.L2:
|
|
||||||
lw a5,-20(s0)
|
|
||||||
lw a5,0(a5)
|
|
||||||
bne a5,zero,.L3
|
|
||||||
li a5,0
|
|
||||||
mv a0,a5
|
|
||||||
lw s0,28(sp)
|
|
||||||
addi sp,sp,32
|
|
||||||
jr ra
|
|
||||||
.size main, .-main
|
|
||||||
.ident "GCC: () 13.2.0"
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
unsigned int x, y;
|
|
||||||
x = 20;
|
|
||||||
x = 5;
|
|
||||||
|
|
||||||
x *= y;
|
|
||||||
}
|
|
||||||
32
tests/mult.s
32
tests/mult.s
@@ -1,32 +0,0 @@
|
|||||||
.file "mult.c"
|
|
||||||
.option nopic
|
|
||||||
.attribute arch, "rv32i2p1"
|
|
||||||
.attribute unaligned_access, 0
|
|
||||||
.attribute stack_align, 16
|
|
||||||
.text
|
|
||||||
.globl __mulsi3
|
|
||||||
.align 2
|
|
||||||
.globl main
|
|
||||||
.type main, @function
|
|
||||||
main:
|
|
||||||
addi sp,sp,-32
|
|
||||||
sw ra,28(sp)
|
|
||||||
sw s0,24(sp)
|
|
||||||
addi s0,sp,32
|
|
||||||
li a5,20
|
|
||||||
sw a5,-20(s0)
|
|
||||||
li a5,5
|
|
||||||
sw a5,-20(s0)
|
|
||||||
lw a1,-24(s0)
|
|
||||||
lw a0,-20(s0)
|
|
||||||
call __mulsi3
|
|
||||||
mv a5,a0
|
|
||||||
sw a5,-20(s0)
|
|
||||||
li a5,0
|
|
||||||
mv a0,a5
|
|
||||||
lw ra,28(sp)
|
|
||||||
lw s0,24(sp)
|
|
||||||
addi sp,sp,32
|
|
||||||
jr ra
|
|
||||||
.size main, .-main
|
|
||||||
.ident "GCC: () 13.2.0"
|
|
||||||
Reference in New Issue
Block a user