Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine I/O comments #354

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
#include <stdint.h>
#include <string.h>

/* Directly map a memory with a size of 2^32 bytes. All memory read/write
* operations can access this memory through the memory subsystem.
*/

typedef struct {
uint8_t *mem_base;
uint64_t mem_size;
} memory_t;

/* create a memory instance */
memory_t *memory_new(uint32_t size);

/* delete a memory instance */
void memory_delete(memory_t *m);

/* read an instruction from memory */
Expand All @@ -35,6 +34,7 @@ uint8_t memory_read_b(uint32_t addr);
/* read a length of data from memory */
void memory_read(const memory_t *m, uint8_t *dst, uint32_t addr, uint32_t size);

/* write a length of data to memory */
static inline void memory_write(memory_t *m,
uint32_t addr,
const uint8_t *src,
Expand All @@ -43,12 +43,16 @@ static inline void memory_write(memory_t *m,
memcpy(m->mem_base + addr, src, size);
}

/* write a word to memory */
void memory_write_w(uint32_t addr, const uint8_t *src);

/* write a short to memory */
void memory_write_s(uint32_t addr, const uint8_t *src);

/* write a byte to memory */
void memory_write_b(uint32_t addr, const uint8_t *src);

/* write a length of certain value to memory */
static inline void memory_fill(memory_t *m,
uint32_t addr,
uint32_t size,
Expand Down
Loading