diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-10-28 00:00:21 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-10-28 00:00:21 +0300 |
| commit | d96b8c7d12fc61ec609d6138627b9d6d18139a9a (patch) | |
| tree | 82bc9a4c2b22de6c021097fb79a57b6d7756a127 /triscv/include | |
| download | tri-d96b8c7d12fc61ec609d6138627b9d6d18139a9a.tar.gz tri-d96b8c7d12fc61ec609d6138627b9d6d18139a9a.zip | |
move to monorepo
+ Will probably have to make some changes to dir layout to make things
make more sense
Diffstat (limited to 'triscv/include')
| -rw-r--r-- | triscv/include/triscv/common.h | 28 | ||||
| -rw-r--r-- | triscv/include/triscv/cpu.h | 14 | ||||
| -rw-r--r-- | triscv/include/triscv/csr.h | 8 | ||||
| -rw-r--r-- | triscv/include/triscv/mem.h | 13 | ||||
| -rw-r--r-- | triscv/include/triscv/mmu.h | 40 | ||||
| -rw-r--r-- | triscv/include/triscv/tmb.h | 18 | ||||
| -rw-r--r-- | triscv/include/triscv/uart.h | 12 |
7 files changed, 133 insertions, 0 deletions
diff --git a/triscv/include/triscv/common.h b/triscv/include/triscv/common.h new file mode 100644 index 0000000..865f6e5 --- /dev/null +++ b/triscv/include/triscv/common.h @@ -0,0 +1,28 @@ +#ifndef TRISCV_COMMON_H +#define TRISCV_COMMON_H + +#include <tri.h> +#include <stdint.h> + +typedef uint64_t vm_t; +typedef uint64_t pm_t; + +/* forward declarations */ +struct cpu; +struct tmb; +struct mmu; +struct mem; +struct uart; + +enum stat { + OK = 0, + ERR_FULL, + ERR_EXISTS, + ERR_OOB, +}; + +typedef enum stat stat_t; + +const char *err_str(stat_t s); + +#endif diff --git a/triscv/include/triscv/cpu.h b/triscv/include/triscv/cpu.h new file mode 100644 index 0000000..05f8b78 --- /dev/null +++ b/triscv/include/triscv/cpu.h @@ -0,0 +1,14 @@ +#ifndef TRISCV_CPU_H +#define TRISCV_CPU_H + +#include <triscv/common.h> + +struct cpu *cpu_create(struct mmu *mmu, struct tmb *tmb); +void cpu_reset(struct cpu *cpu); +void cpu_destroy(struct cpu *cpu); + +/** @todo how should external interrupts be handled? add some list of devices to + * update after each cycle? */ +void cpu_run(struct cpu *cpu, vm_t start); + +#endif diff --git a/triscv/include/triscv/csr.h b/triscv/include/triscv/csr.h new file mode 100644 index 0000000..a805702 --- /dev/null +++ b/triscv/include/triscv/csr.h @@ -0,0 +1,8 @@ +#ifndef TRISCV_CSR_H +#define TRISCV_CSR_H + +/* first trit is sleep mode, R/W, second trit shutdown, R/W */ +#define CSR_MPOWER 0 +#define RW_MPOWER 0b1111 + +#endif diff --git a/triscv/include/triscv/mem.h b/triscv/include/triscv/mem.h new file mode 100644 index 0000000..81b5d11 --- /dev/null +++ b/triscv/include/triscv/mem.h @@ -0,0 +1,13 @@ +#ifndef TRISCV_MEM_H +#define TRISCV_MEM_H + +#include <triscv/common.h> +#include <triscv/mmu.h> + +struct mem *mem_create(size_t size); +void mem_destroy(struct mem *mem); +void mem_init(struct mem *mem, const void *buf, size_t len); + +struct dev mem_dev(struct mem *mem); + +#endif diff --git a/triscv/include/triscv/mmu.h b/triscv/include/triscv/mmu.h new file mode 100644 index 0000000..c885814 --- /dev/null +++ b/triscv/include/triscv/mmu.h @@ -0,0 +1,40 @@ +#ifndef TRISCV_MMU_H +#define TRISCV_MMU_H + +#include <triscv/common.h> +#include <triscv/cpu.h> + +typedef void (*dev_write1_t)(struct cpu *cpu, void *dev, pm_t addr, tri_t t); +typedef void (*dev_write3_t)(struct cpu *cpu, void *dev, pm_t addr, tri_t t); +typedef tri_t (*dev_read1_t)(struct cpu *cpu, void *dev, pm_t addr); +typedef tri_t (*dev_read3_t)(struct cpu *cpu, void *dev, pm_t addr); + +/* only character devices for now */ +struct dev { + void *dev; + size_t size; + dev_write1_t write1; + dev_write3_t write3; + dev_read1_t read1; + dev_read3_t read3; +}; + +struct mmu *mmu_create(); +void mmu_destroy(struct mmu *mmu); + +/* not thread safe */ +stat_t mmu_map_dev(struct mmu *mmu, pm_t start, struct dev dev); + +void mmu_enable(struct mmu *mmu); +void mmu_disable(struct mmu *mmu); + +bool mmu_valid(struct mmu *mmu, vm_t addr); + +/* mmu can raise signals, so we pass cpu along */ +tri_t mmu_read1(struct cpu *cpu, struct mmu *mmu, vm_t addr); +tri_t mmu_read3(struct cpu *cpu, struct mmu *mmu, vm_t addr); + +void mmu_write1(struct cpu *cpu, struct mmu *mmu, vm_t addr, tri_t t); +void mmu_write3(struct cpu *cpu, struct mmu *mmu, vm_t addr, tri_t t); + +#endif diff --git a/triscv/include/triscv/tmb.h b/triscv/include/triscv/tmb.h new file mode 100644 index 0000000..0c8a5b6 --- /dev/null +++ b/triscv/include/triscv/tmb.h @@ -0,0 +1,18 @@ +#ifndef TRISCV_TMB_H +#define TRISCV_TMB_H + +#include <triscv/common.h> +#include <triscv/cpu.h> + +struct tmb *tmb_create(); +void tmb_destroy(struct tmb *tmb); + +size_t tmb_size(struct cpu *cpu); + +void tmb_clear(struct cpu *cpu); +void tmb_cancel(struct cpu *cpu); +void tmb_store1(struct cpu *cpu, vm_t addr, tri_t t); +void tmb_store3(struct cpu *cpu, vm_t addr, tri_t t); +bool tmb_commit(struct cpu *cpu); + +#endif diff --git a/triscv/include/triscv/uart.h b/triscv/include/triscv/uart.h new file mode 100644 index 0000000..531da1d --- /dev/null +++ b/triscv/include/triscv/uart.h @@ -0,0 +1,12 @@ +#ifndef TRISCV_UART_H +#define TRISCV_UART_H + +#include <triscv/common.h> +#include <triscv/mmu.h> + +struct uart *uart_create(); +void uart_destroy(struct uart *uart); + +struct dev uart_dev(struct uart *uart); + +#endif |
