Skip to content

Commit

Permalink
Draft
Browse files Browse the repository at this point in the history
  • Loading branch information
qwe661234 committed May 29, 2023
1 parent 1f9cbea commit a7b8455
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"assert.h": "c"
}
}
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ include mk/toolchain.mk
OUT ?= build
BIN := $(OUT)/rv32emu

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

Expand Down
25 changes: 17 additions & 8 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,38 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdio.h>

#include "io.h"
#include "mpool.h"

#define MEM_SIZE (512 * 1024 * 1024)
static const uint32_t mask_lo = 0xffff;
static const uint32_t mask_hi = ~(0xffff);

static struct mpool *mp;
static uint32_t mem_base;

memory_t *memory_new()
void memory_new()
{
memory_t *m = calloc(1, sizeof(memory_t));
/* Initialize the mpool size to sizeof(chunk_t) << 2, and it will extend
* automatically if needed */
mp = mpool_create(sizeof(chunk_t) << 2, sizeof(chunk_t));
return m;
mem_base = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (mem_base == MAP_FAILED) {
fprintf(stderr, "Could not map RAM\n");
}
// memory_t *m = calloc(1, sizeof(memory_t));
// /* Initialize the mpool size to sizeof(chunk_t) << 2, and it will extend
// * automatically if needed */
// mp = mpool_create(sizeof(chunk_t) << 2, sizeof(chunk_t));
// return m;
}

void memory_delete(memory_t *m)
{
if (!m)
return;
mpool_destory(mp);
// mpool_destory(mp);
free(m);
}

Expand Down
2 changes: 1 addition & 1 deletion src/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ typedef struct {
chunk_t *chunks[0x10000];
} memory_t;

memory_t *memory_new();
void memory_new();
void memory_delete(memory_t *m);

/* read a C-style string from memory */
Expand Down
4 changes: 2 additions & 2 deletions src/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ typedef struct {
static inline state_t *state_new()
{
state_t *s = malloc(sizeof(state_t));
s->mem = memory_new();
// s->mem = memory_new();
s->break_addr = 0;

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

map_delete(s->fd_map);
memory_delete(s->mem);
// memory_delete(s->mem);
free(s);
}

0 comments on commit a7b8455

Please sign in to comment.