Skip to content

Commit a7b8455

Browse files
committed
Draft
1 parent 1f9cbea commit a7b8455

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"assert.h": "c"
4+
}
5+
}

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ include mk/toolchain.mk
44
OUT ?= build
55
BIN := $(OUT)/rv32emu
66

7-
CFLAGS = -std=gnu99 -O2 -Wall -Wextra
7+
# CFLAGS = -std=gnu99 -O2 -Wall -Wextra
8+
CFLAGS = -std=gnu99 -Ofast -DNDEBUG -Wall -Wextra
89
CFLAGS += -Wno-unused-label
910
CFLAGS += -include src/common.h
1011

src/io.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,38 @@
77
#include <stdint.h>
88
#include <stdlib.h>
99
#include <string.h>
10+
#include <sys/mman.h>
11+
#include <unistd.h>
12+
#include <stdio.h>
1013

1114
#include "io.h"
1215
#include "mpool.h"
13-
16+
#define MEM_SIZE (512 * 1024 * 1024)
1417
static const uint32_t mask_lo = 0xffff;
1518
static const uint32_t mask_hi = ~(0xffff);
1619

1720
static struct mpool *mp;
21+
static uint32_t mem_base;
1822

19-
memory_t *memory_new()
23+
void memory_new()
2024
{
21-
memory_t *m = calloc(1, sizeof(memory_t));
22-
/* Initialize the mpool size to sizeof(chunk_t) << 2, and it will extend
23-
* automatically if needed */
24-
mp = mpool_create(sizeof(chunk_t) << 2, sizeof(chunk_t));
25-
return m;
25+
mem_base = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE,
26+
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
27+
if (mem_base == MAP_FAILED) {
28+
fprintf(stderr, "Could not map RAM\n");
29+
}
30+
// memory_t *m = calloc(1, sizeof(memory_t));
31+
// /* Initialize the mpool size to sizeof(chunk_t) << 2, and it will extend
32+
// * automatically if needed */
33+
// mp = mpool_create(sizeof(chunk_t) << 2, sizeof(chunk_t));
34+
// return m;
2635
}
2736

2837
void memory_delete(memory_t *m)
2938
{
3039
if (!m)
3140
return;
32-
mpool_destory(mp);
41+
// mpool_destory(mp);
3342
free(m);
3443
}
3544

src/io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ typedef struct {
1515
chunk_t *chunks[0x10000];
1616
} memory_t;
1717

18-
memory_t *memory_new();
18+
void memory_new();
1919
void memory_delete(memory_t *m);
2020

2121
/* read a C-style string from memory */

src/state.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ typedef struct {
2525
static inline state_t *state_new()
2626
{
2727
state_t *s = malloc(sizeof(state_t));
28-
s->mem = memory_new();
28+
// s->mem = memory_new();
2929
s->break_addr = 0;
3030

3131
s->fd_map = map_init(int, FILE *, map_cmp_int);
@@ -42,6 +42,6 @@ static inline void state_delete(state_t *s)
4242
return;
4343

4444
map_delete(s->fd_map);
45-
memory_delete(s->mem);
45+
// memory_delete(s->mem);
4646
free(s);
4747
}

0 commit comments

Comments
 (0)