diff options
author | stefan <stefan@s00.xyz> | 2023-04-08 20:42:18 -0400 |
---|---|---|
committer | stefan <stefan@s00.xyz> | 2023-04-08 20:42:18 -0400 |
commit | 1aac36f788834699b6891aea7a83eb950bd5e8f6 (patch) | |
tree | 18e0a6c26b83e71c101193e60149f49b1641daf0 /sys/include | |
parent | a1a97aa7b2b0c3d1f3b6766446d605f83de1c561 (diff) | |
download | sv-1aac36f788834699b6891aea7a83eb950bd5e8f6.tar.gz |
no idea whot i changed lol
Diffstat (limited to 'sys/include')
-rw-r--r-- | sys/include/asm.h | 55 | ||||
-rw-r--r-- | sys/include/cpu.h | 10 | ||||
-rw-r--r-- | sys/include/fdt.h | 18 | ||||
-rw-r--r-- | sys/include/smp.h | 0 | ||||
-rw-r--r-- | sys/include/spinlock.h | 11 |
5 files changed, 94 insertions, 0 deletions
diff --git a/sys/include/asm.h b/sys/include/asm.h new file mode 100644 index 0000000..86e6354 --- /dev/null +++ b/sys/include/asm.h @@ -0,0 +1,55 @@ +#ifndef _ASM_H +#define _ASM_H + +#include <stdint.h> + +#define SSTATUS_SIE (1L << 1) + +static inline uint64_t +csrr_sstatus(void) +{ + uint64_t x; + asm volatile("csrr %0, sstatus" : "=r"(x)); + return x; +} + +static inline void +csrw_sstatus(uint64_t x) +{ + asm volatile("csrw sstatus, %0" : : "r"(x)); +} + +/* will enable all supervisor interrupts using the bit in sstatus */ +static inline void +sie_enable(void) +{ + csrw_sstatus(csrr_sstatus() | SSTATUS_SIE); +} + +/* will disable all supervisor interrupts by using the bitin sstatus (though sie can also be used) */ +static inline void +sie_disable(void) +{ + csrw_sstatus(csrr_sstatus() & ~SSTATUS_SIE); +} + +/* returns the status of the sie bit in sstatus + * 1 if enabled, 0 if disabled. + * for more specific info see the sie register + */ +static inline uint64_t +sie_status() +{ + return (csrr_sstatus() & SSTATUS_SIE) != 0; + +} + +/* we use tp to store hartid */ +static inline uint64_t +read_tp(void) +{ + uint64_t x; + asm volatile("addi %0, tp, 0" : "=r"(x)); +} + +#endif /* _ASM_H */ diff --git a/sys/include/cpu.h b/sys/include/cpu.h new file mode 100644 index 0000000..9567496 --- /dev/null +++ b/sys/include/cpu.h @@ -0,0 +1,10 @@ +#ifndef _CPU_H +#define _CPU_H + +struct hart { + int intr_stack; +}; + +struct hart harts[NPROC] = {0}; + +#endif /* _CPU_H */ diff --git a/sys/include/fdt.h b/sys/include/fdt.h index 92e5695..ca1cea0 100644 --- a/sys/include/fdt.h +++ b/sys/include/fdt.h @@ -1,5 +1,6 @@ #include <stdint.h> #include <endian.h> +#include <printf.h> #ifndef _FDT_H #define _FDT_H @@ -34,4 +35,21 @@ struct fdt_reserve_entry { uint64_t size; }; +struct fdt_node_header { + uint32_t tag; + char name[]; +}; + +void walk_fdt(struct fdt_header *header); + +#define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */ +#define FDT_TAGSIZE sizeof(fdt32_t) + +#define FDT_BEGIN_NODE 0x1 /* Start node: full name */ +#define FDT_END_NODE 0x2 /* End node */ +#define FDT_PROP 0x3 /* Property: name off, + size, content */ +#define FDT_NOP 0x4 /* nop */ +#define FDT_END 0x9 + #endif /* _FDT_H */ diff --git a/sys/include/smp.h b/sys/include/smp.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/sys/include/smp.h diff --git a/sys/include/spinlock.h b/sys/include/spinlock.h new file mode 100644 index 0000000..3400445 --- /dev/null +++ b/sys/include/spinlock.h @@ -0,0 +1,11 @@ +#ifndef _LOCK_H +#define _LOCK_H + +struct spinlock { + int locked; + const char *name; +}; + +void initlock(struct spinlock *, const char *); + +#endif /* _LOCK_H */ |