Skip to content

Commit 715ebba

Browse files
committed
Run CoreMark, add single-step switch, improve register display, fix off-by-one error in loader mod
1 parent dfd1467 commit 715ebba

File tree

13 files changed

+527
-182
lines changed

13 files changed

+527
-182
lines changed

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ asm: $(ASM_PROGRAMS)
1212
.PHONY: rust
1313
rust: $(RUST_PROGRAMS)
1414

15+
.PHONY: coremark
16+
coremark:
17+
cd coremark/coremark && $(MAKE) PORT_DIR=../mlogv32 ITERATIONS=10 load
18+
1519
$(ASM_PROGRAMS): %: build/%.bin build/%.dump
1620

1721
$(RUST_PROGRAMS): %: build/rust/%.bin
@@ -25,16 +29,16 @@ build/rust/%.bin: FORCE | build/rust
2529
cd rust/$* && cargo robjcopy ../../build/rust/$*.bin
2630

2731
build/%.bin: build/%.out
28-
riscv64-unknown-elf-objcopy --output-target binary build/$*.out build/$*.bin
32+
riscv32-unknown-elf-objcopy --output-target binary build/$*.out build/$*.bin
2933

3034
build/%.dump: build/%.out
31-
riscv64-unknown-elf-objdump --disassemble build/$*.out > build/$*.dump
35+
riscv32-unknown-elf-objdump --disassemble build/$*.out > build/$*.dump
3236

3337
build/%.out: build/%.o
34-
riscv64-unknown-elf-ld -melf32lriscv --script=rust/mlogv32/link.x -o build/$*.out build/$*.o
38+
riscv32-unknown-elf-ld --script=rust/mlogv32/link.x -o build/$*.out build/$*.o
3539

3640
build/%.o: asm/%.s | build
37-
riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 --compile -o build/$*.o asm/$*.s
41+
riscv32-unknown-elf-gcc --compile -o build/$*.o asm/$*.s
3842

3943
build:
4044
mkdir -p build
@@ -52,5 +56,9 @@ clean-rust: $(addprefix clean-rust/,$(RUST_PROJECTS))
5256
clean-rust/%:
5357
cd rust/$* && cargo clean
5458

59+
.PHONY: clean-coremark
60+
clean-coremark:
61+
cd coremark/coremark && $(MAKE) PORT_DIR=../mlogv32 clean
62+
5563
.PHONY: FORCE
5664
FORCE:

coremark/mlogv32/core_portme.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ portable_init(core_portable *p, int *argc, char *argv[])
135135
(void)argc; // prevent unused warning
136136
(void)argv; // prevent unused warning
137137

138+
init_printf();
139+
138140
if (sizeof(ee_ptr_int) != sizeof(ee_u8 *))
139141
{
140142
ee_printf(
@@ -155,9 +157,5 @@ portable_fini(core_portable *p)
155157
{
156158
p->portable_id = 0;
157159

158-
ecall(DrawReset, 0, 0, 0, 0, 0, 0, 0);
159-
ecall(DrawClear, 0, 0, 0, 0, 0, 0, 0);
160-
ecall(DrawColor, 255, 255, 255, 255, 0, 0, 0);
161-
ecall(DrawPrint, 6, 508, 7, 0, 0, 0, 0);
162-
ecall(DrawFlush, 0, 0, 0, 0, 0, 0, 0);
160+
ecall(0, 0, 0, 0, 0, 0, 0, Halt);
163161
}

coremark/mlogv32/core_portme.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ Original Author: Shay Gal-on
2222
#ifndef CORE_PORTME_H
2323
#define CORE_PORTME_H
2424

25-
// TODO: tune this value
26-
// #define ITERATIONS 10
27-
28-
// #define PERFORMANCE_RUN 1
29-
// #define VALIDATION_RUN 0
30-
3125
/************************/
3226
/* Data types and settings */
3327
/************************/
@@ -215,4 +209,6 @@ void portable_fini(core_portable *p);
215209

216210
int ee_printf(const char *fmt, ...);
217211

212+
void init_printf();
213+
218214
#endif /* CORE_PORTME_H */

coremark/mlogv32/core_portme.mak

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,22 @@
1717
#File : core_portme.mak
1818

1919
RISCV_ARCH = rv32i_zicsr
20-
RISCV_ABI = ilp32
2120

2221
# Flag : OUTFLAG
2322
# Use this flag to define how to to get an executable (e.g -o)
2423
OUTFLAG= -o
2524
# Flag : CC
2625
# Use this flag to define compiler to use
27-
CC = riscv64-unknown-elf-gcc
26+
CC = riscv32-unknown-elf-gcc
2827
# Flag : LD
2928
# Use this flag to define compiler to use
30-
LD = riscv64-unknown-elf-gcc
29+
LD = riscv32-unknown-elf-gcc
3130
# Flag : AS
3231
# Use this flag to define compiler to use
33-
AS = riscv64-unknown-elf-gcc
32+
AS = riscv32-unknown-elf-gcc
3433
# Flag : CFLAGS
3534
# Use this flag to define compiler options. Note, you can add compiler options from the command line using XCFLAGS="other flags"
36-
PORT_CFLAGS = -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -nostdlib -nostartfiles -static -lgcc --compile -O0 -g
35+
PORT_CFLAGS = -march=$(RISCV_ARCH) --compile -O0 -g -nostdlib -nostartfiles
3736
FLAGS_STR = "$(PORT_CFLAGS) $(XCFLAGS) $(XLFLAGS) $(LFLAGS_END)"
3837
CFLAGS = $(PORT_CFLAGS) -I$(PORT_DIR) -I. -DFLAGS_STR=\"$(FLAGS_STR)\"
3938
#Flag : LFLAGS_END
@@ -43,20 +42,20 @@ SEPARATE_COMPILE=1
4342
# Flag : SEPARATE_COMPILE
4443
# You must also define below how to create an object file, and how to link.
4544
OBJOUT = -o
46-
LFLAGS = -march=$(RISCV_ARCH) -nostdlib -nostartfiles -static -lgcc -T$(PORT_DIR)/../../rust/mlogv32/link.x
47-
ASFLAGS = -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) --compile
45+
LFLAGS = -T$(PORT_DIR)/../../rust/mlogv32/link.x -nostartfiles
46+
ASFLAGS = --compile
4847
OFLAG = -o
4948
COUT = -c
5049

5150
LFLAGS_END =
5251
# Flag : PORT_SRCS
5352
# Port specific source files can be added here
5453
# You may also need cvt.c if the fcvt functions are not provided as intrinsics by your compiler!
55-
PORT_SRCS = $(PORT_DIR)/core_portme.c $(PORT_DIR)/ee_printf.c $(PORT_DIR)/ecall.c
54+
PORT_SRCS = $(PORT_DIR)/core_portme.c $(PORT_DIR)/ee_printf.c $(PORT_DIR)/ecall.c $(PORT_DIR)/entry.s
5655
vpath %.c $(PORT_DIR)
5756
vpath %.s $(PORT_DIR)
5857

59-
PORT_OBJS = $(PORT_DIR)/core_portme.o $(PORT_DIR)/ee_printf.o $(PORT_DIR)/ecall.o
58+
PORT_OBJS = $(PORT_DIR)/core_portme.o $(PORT_DIR)/ee_printf.o $(PORT_DIR)/ecall.o $(PORT_DIR)/entry.o
6059

6160
# Flag : LOAD
6261
# For a simple port, we assume self hosted compile and run, no load needed.
@@ -68,7 +67,7 @@ LOAD = echo "Please set LOAD to the process of loading the executable to the fla
6867
RUN = echo "Please set LOAD to the process of running the executable (e.g. via jtag, or board reset)"
6968

7069
OEXT = .o
71-
EXE = .bin
70+
EXE = .out
7271

7372
$(OPATH)$(PORT_DIR)/%$(OEXT) : %.c
7473
$(CC) $(CFLAGS) $(XCFLAGS) $(COUT) $< $(OBJOUT) $@
@@ -79,11 +78,42 @@ $(OPATH)%$(OEXT) : %.c
7978
$(OPATH)$(PORT_DIR)/%$(OEXT) : %.s
8079
$(AS) $(ASFLAGS) $< $(OBJOUT) $@
8180

82-
# Target : port_pre% and port_post%
83-
# For the purpose of this simple port, no pre or post steps needed.
84-
85-
.PHONY : port_prebuild port_postbuild port_prerun port_postrun port_preload port_postload
86-
port_pre% port_post% :
81+
PORT_CLEAN = $(OPATH)coremark.bin $(OPATH)coremark.dump
82+
83+
.PHONY: port_prebuild
84+
port_prebuild:
85+
86+
# Target: port_postbuild
87+
# Generate any files that are needed after actual build end.
88+
# E.g. change format to srec, bin, zip in order to be able to load into flash
89+
.PHONY: port_postbuild
90+
port_postbuild:
91+
riscv32-unknown-elf-objcopy --output-target binary $(OUTFILE) $(OPATH)coremark.bin
92+
riscv32-unknown-elf-objdump --disassemble $(OUTFILE) > $(OPATH)coremark.dump
93+
94+
# Target: port_prerun
95+
# Do platform specific before run stuff.
96+
# E.g. reset the board, backup the logfiles etc.
97+
.PHONY: port_prerun
98+
port_prerun:
99+
100+
# Target: port_postrun
101+
# Do platform specific after run stuff.
102+
# E.g. reset the board, backup the logfiles etc.
103+
.PHONY: port_postrun
104+
port_postrun:
105+
106+
# Target: port_preload
107+
# Do platform specific before load stuff.
108+
# E.g. reset the reset power to the flash eraser
109+
.PHONY: port_preload
110+
port_preload:
111+
112+
# Target: port_postload
113+
# Do platform specific after load stuff.
114+
# E.g. reset the reset power to the flash eraser
115+
.PHONY: port_postload
116+
port_postload:
87117

88118
# FLAG : OPATH
89119
# Path to the output folder. Default - current folder.

coremark/mlogv32/ecall.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
// https://github.com/torvalds/linux/blob/a5806cd506af5a7c19bcd596e4708b5c464bfd21/arch/riscv/kernel/sbi_ecall.c#L20
66
unsigned int ecall(
7-
unsigned int which,
87
unsigned int arg0,
98
unsigned int arg1,
109
unsigned int arg2,
1110
unsigned int arg3,
1211
unsigned int arg4,
1312
unsigned int arg5,
14-
unsigned int arg6
13+
unsigned int arg6,
14+
Syscall which
1515
) {
1616
register ee_ptr_int a0 asm ("a0") = (ee_ptr_int)(arg0);
1717
register ee_ptr_int a1 asm ("a1") = (ee_ptr_int)(arg1);
@@ -24,6 +24,6 @@ unsigned int ecall(
2424
asm volatile ("ecall"
2525
: "+r" (a0)
2626
: "r" (a1), "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7)
27-
: "memory");
27+
:);
2828
return a0;
2929
}

coremark/mlogv32/ecall.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
enum Syscall {
1+
typedef enum {
22
Halt,
33
PrintChar,
44
PrintFlush,
@@ -19,15 +19,15 @@ enum Syscall {
1919
DrawRotate,
2020
DrawReset,
2121
DrawFlush,
22-
};
22+
} Syscall;
2323

2424
unsigned int ecall(
25-
unsigned int which,
2625
unsigned int arg0,
2726
unsigned int arg1,
2827
unsigned int arg2,
2928
unsigned int arg3,
3029
unsigned int arg4,
3130
unsigned int arg5,
32-
unsigned int arg6
31+
unsigned int arg6,
32+
Syscall which
3333
);

coremark/mlogv32/ee_printf.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,22 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
660660
return str - buf;
661661
}
662662

663+
static unsigned int print_width = 0;
664+
static unsigned int print_y = 508;
665+
663666
void
664667
uart_send_char(char c)
665668
{
666-
ecall(PrintChar, c, 0, 0, 0, 0, 0, 0);
669+
ecall(c, 0, 0, 0, 0, 0, 0, PrintChar);
670+
}
671+
672+
void init_printf() {
673+
print_width = 0;
674+
print_y = 508;
675+
ecall(0, 0, 0, 0, 0, 0, 0, DrawReset);
676+
ecall(0, 0, 0, 0, 0, 0, 0, DrawClear);
677+
ecall(255, 255, 255, 255, 0, 0, 0, DrawColor);
678+
ecall(0, 0, 0, 0, 0, 0, 0, DrawFlush);
667679
}
668680

669681
int
@@ -673,6 +685,8 @@ ee_printf(const char *fmt, ...)
673685
va_list args;
674686
int n = 0;
675687

688+
int new_print_y = print_y;
689+
676690
va_start(args, fmt);
677691
ee_vsprintf(buf, fmt, args);
678692
va_end(args);
@@ -682,7 +696,20 @@ ee_printf(const char *fmt, ...)
682696
uart_send_char(*p);
683697
n++;
684698
p++;
699+
print_width += 1;
700+
if (*p == '\n' || print_width > 70) {
701+
if (print_width > 70) {
702+
uart_send_char('\n');
703+
}
704+
new_print_y -= 13;
705+
print_width = 0;
706+
}
685707
}
686708

709+
ecall(7, print_y, 7, 0, 0, 0, 0, DrawPrint);
710+
ecall(0, 0, 0, 0, 0, 0, 0, DrawFlush);
711+
print_width = 0;
712+
print_y = new_print_y;
713+
687714
return n;
688715
}

coremark/mlogv32/entry.s

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.section .text.start
2+
.global _start
3+
4+
_start:
5+
la t1, _stack_start
6+
andi sp, t1, -16
7+
add s0, sp, zero
8+
9+
la gp, __global_pointer$
10+
11+
# Clear BSS section
12+
la t0, __sbss
13+
la t1, __ebss
14+
clear_bss:
15+
bgeu t0, t1, bss_done
16+
sb zero, 0(t0)
17+
addi t0, t0, 1
18+
j clear_bss
19+
bss_done:
20+
21+
# Jump to C code
22+
call main
23+
24+
# In case main returns
25+
1: j 1b

mod/scripts/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function flashMlogv32Processor(processor, file) {
8585
let ram = getRam();
8686

8787
for (let i = 0; i < data.length; i += 4) {
88-
if (varIndex >= RAM_PROC_SIZE) {
88+
if (varIndex > RAM_PROC_SIZE) {
8989
ramIndex++;
9090
varIndex = 1;
9191
ram = getRam();

rust/mlogv32/link.x

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ MEMORY {
88
/*
99
LENGTH = num_ram_procs * 4096*4
1010
0x10000000 = 128*128 * 4096*4
11+
0x8000000 = 128*64 * 4096*4
1112
*/
12-
ram (rwx) : ORIGIN = 0, LENGTH = 0x10000000
13+
ram (rwx) : ORIGIN = 0, LENGTH = 0x8000000
1314
}
1415

1516
REGION_ALIAS("REGION_TEXT", ram);

0 commit comments

Comments
 (0)