Skip to content

Commit 9623615

Browse files
committed
RV32C Integrated
Co-authored-by: ccs100203
1 parent c9d4671 commit 9623615

File tree

13 files changed

+792
-153
lines changed

13 files changed

+792
-153
lines changed

Makefile

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CFLAGS += -D ENABLE_RV32M
1515
CFLAGS += -D ENABLE_Zicsr
1616
CFLAGS += -D ENABLE_Zifencei
1717
CFLAGS += -D ENABLE_RV32A
18+
CFLAGS += -D ENABLE_RV32C
1819
CFLAGS += -D DEFAULT_STACK_ADDR=0xFFFFF000
1920

2021
# Experimental SDL oriented system calls
@@ -25,22 +26,11 @@ LDFLAGS += `sdl2-config --libs`
2526
# Whether to enable computed goto in riscv.c
2627
ENABLE_COMPUTED_GOTO ?= 1
2728
ifeq ("$(ENABLE_COMPUTED_GOTO)", "1")
28-
<<<<<<< HEAD
29-
<<<<<<< HEAD
3029
ifneq ($(filter $(CC), gcc clang),)
31-
=======
32-
>>>>>>> Add support for clang in Makefile
33-
=======
34-
ifneq ($(filter $(CC), gcc clang),)
35-
>>>>>>> Improve compiler support for ENABLE_COMPUTED_GOTO
3630
riscv.o: CFLAGS += -D ENABLE_COMPUTED_GOTO
3731
ifeq ("$(CC)", "gcc")
3832
riscv.o: CFLAGS += -fno-gcse -fno-crossjumping
3933
endif
40-
<<<<<<< HEAD
41-
endif
42-
=======
43-
>>>>>>> Add support for clang in Makefile
4434
endif
4535
endif
4636

@@ -71,7 +61,7 @@ OBJS = \
7161
elf.o \
7262
main.o \
7363
syscall.o \
74-
syscall_sdl.o
64+
syscall_sdl.o
7565

7666
deps := $(OBJS:%.o=%.o.d)
7767

elf.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,17 @@ const char *elf_find_symbol(elf_t *e, uint32_t addr)
269269
return c_map_at_end(e->symbols, &it) ? NULL : c_map_iter_value(&it, char *);
270270
}
271271

272-
bool elf_get_data_section_range(elf_t *e, uint32_t *start, uint32_t *end) {
272+
bool elf_get_data_section_range(elf_t *e, uint32_t *start, uint32_t *end)
273+
{
273274
const struct Elf32_Shdr *shdr = get_section_header(e, ".data");
274-
if (!shdr) return false;
275-
if (shdr->sh_type == SHT_NOBITS) return false;
275+
if (!shdr)
276+
return false;
277+
if (shdr->sh_type == SHT_NOBITS)
278+
return false;
276279
*start = shdr->sh_addr;
277280
*end = *start + shdr->sh_size;
278281
return true;
279-
}
282+
}
280283

281284
bool elf_load(elf_t *e, struct riscv_t *rv, memory_t *mem)
282285
{

io.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ uint32_t memory_read_str(memory_t *m, uint8_t *dst, uint32_t addr, uint32_t max)
7070
uint32_t memory_read_ifetch(memory_t *m, uint32_t addr)
7171
{
7272
const uint32_t addr_lo = addr & mask_lo;
73+
74+
#ifdef ENABLE_RV32C
75+
assert((addr_lo & 1) == 0);
76+
#else
7377
assert((addr_lo & 3) == 0);
78+
#endif
7479

7580
chunk_t *c = m->chunks[addr >> 16];
7681
assert(c);
@@ -115,6 +120,14 @@ uint8_t memory_read_b(memory_t *m, uint32_t addr)
115120

116121
void memory_write(memory_t *m, uint32_t addr, const uint8_t *src, uint32_t size)
117122
{
123+
uint32_t p = addr + size;
124+
uint32_t x = p >> 16;
125+
chunk_t *c = m->chunks[x];
126+
if (!c) {
127+
c = malloc(sizeof(chunk_t));
128+
memset(c->data, 0, sizeof(c->data));
129+
m->chunks[x] = c;
130+
}
118131
for (uint32_t i = 0; i < size; ++i) {
119132
uint32_t p = addr + i;
120133
uint32_t x = p >> 16;
@@ -126,6 +139,14 @@ void memory_write(memory_t *m, uint32_t addr, const uint8_t *src, uint32_t size)
126139
}
127140
c->data[p & 0xffff] = src[i];
128141
}
142+
p = addr + size;
143+
x = p >> 16;
144+
c = m->chunks[x];
145+
if (!c) {
146+
c = malloc(sizeof(chunk_t));
147+
memset(c->data, 0, sizeof(c->data));
148+
m->chunks[x] = c;
149+
}
129150
}
130151

131152
void memory_fill(memory_t *m, uint32_t addr, uint32_t size, uint8_t val)

main.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ static void on_on_ecall(struct riscv_t *rv)
6969
syscall_handler(rv);
7070
}
7171

72-
static void on_on_ebreak(struct riscv_t *rv)
73-
{
74-
rv_halt(rv);
75-
}
72+
static void on_on_ebreak(struct riscv_t *rv) {}
7673

7774
/* run: printing out an instruction trace */
7875
static void run_and_trace(struct riscv_t *rv, elf_t *elf)
@@ -106,7 +103,8 @@ static void print_usage(const char *filename)
106103
"Usage: %s [options] [filename]\n"
107104
"Options:\n"
108105
" --trace : print executable trace\n"
109-
" --compliance [signature filename] : dump signature to the given file for compliance test\n",
106+
" --compliance [signature filename] : dump signature to the given "
107+
"file for compliance test\n",
110108
filename);
111109
}
112110

@@ -127,7 +125,8 @@ static bool parse_args(int argc, char **args)
127125
opt_compliance = true;
128126
if (i + 1 >= argc) {
129127
fprintf(stderr,
130-
"Filename for signature output required in compliance mode.\n");
128+
"Filename for signature output required in "
129+
"compliance mode.\n");
131130
return false;
132131
}
133132
signature_out_file = args[++i];

riscv-compliance

Submodule riscv-compliance deleted from 2e95f18

0 commit comments

Comments
 (0)