2024-10-15 17:07:18 +02:00
|
|
|
#ifndef ADDRESS_SPACE_H
|
|
|
|
#define ADDRESS_SPACE_H
|
|
|
|
|
2024-10-14 19:48:56 +02:00
|
|
|
#include <stdint.h>
|
2024-10-21 19:42:27 +02:00
|
|
|
#include <stdbool.h>
|
2024-10-14 19:48:56 +02:00
|
|
|
|
|
|
|
struct AddressSpace_s {
|
2024-10-21 19:42:27 +02:00
|
|
|
// A pointer to a ROM array. The array can vary in length.
|
2024-10-14 19:48:56 +02:00
|
|
|
uint8_t *rom;
|
2024-10-21 19:42:27 +02:00
|
|
|
// The size of ROM.
|
|
|
|
uint32_t romSize; // TODO look into making it const
|
|
|
|
// Is ROM read only
|
|
|
|
bool romLocked;
|
|
|
|
|
|
|
|
// A pointer to a RAM array. The array can vary in length.
|
2024-10-14 19:48:56 +02:00
|
|
|
uint8_t *ram;
|
2024-10-21 19:42:27 +02:00
|
|
|
// The size of RAM.
|
2024-10-14 19:48:56 +02:00
|
|
|
uint32_t ramSize;
|
2024-10-24 11:38:13 +02:00
|
|
|
|
|
|
|
// The CSRs, size is always 4096 (12 bits)
|
|
|
|
uint32_t *csr;
|
2024-10-14 19:48:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct AddressSpace_s AddressSpace;
|
|
|
|
|
2024-10-15 17:07:18 +02:00
|
|
|
AddressSpace *create_address_space(const uint32_t romSize, const uint32_t ramSize);
|
|
|
|
int read_address_space(const AddressSpace *addressSpace, const uint32_t address, const int n, void *dest);
|
|
|
|
int write_address_space(const AddressSpace *addressSpace, const uint32_t address, const int n, void *src);
|
2024-10-24 11:38:13 +02:00
|
|
|
int read_csr(const AddressSpace *addressSpace, const uint16_t address, void *dest);
|
|
|
|
int write_csr(const AddressSpace *addressSpace, const uint16_t address, void *src);
|
2024-10-15 17:07:18 +02:00
|
|
|
|
|
|
|
#endif
|