diff options
| -rw-r--r-- | arch/riscv64/kernel/head.S | 76 | ||||
| -rw-r--r-- | arch/riscv64/kernel/timer.c | 2 | ||||
| -rw-r--r-- | arch/riscv64/source.mk | 2 | ||||
| -rw-r--r-- | include/apos/utils.h | 132 |
4 files changed, 117 insertions, 95 deletions
diff --git a/arch/riscv64/kernel/head.S b/arch/riscv64/kernel/head.S index b8ad295..d2a1927 100644 --- a/arch/riscv64/kernel/head.S +++ b/arch/riscv64/kernel/head.S @@ -1,26 +1,34 @@ #include <csr.h> +#if __riscv_xlen == 64 +#define sr sd +#define lr ld +#else +#define sr sw +#define lr lw +#endif + .section .text .global handle_irq handle_irq: addi sp,sp,-144 - sd ra,136(sp) - sd t0,128(sp) - sd t1,120(sp) - sd t2,112(sp) - sd s0,104(sp) - sd a0,96(sp) - sd a1,88(sp) - sd a2,80(sp) - sd a3,72(sp) - sd a4,64(sp) - sd a5,56(sp) - sd a6,48(sp) - sd a7,40(sp) - sd t3,32(sp) - sd t4,24(sp) - sd t5,16(sp) - sd t6,8(sp) + sr ra,136(sp) + sr t0,128(sp) + sr t1,120(sp) + sr t2,112(sp) + sr s0,104(sp) + sr a0,96(sp) + sr a1,88(sp) + sr a2,80(sp) + sr a3,72(sp) + sr a4,64(sp) + sr a5,56(sp) + sr a6,48(sp) + sr a7,40(sp) + sr t3,32(sp) + sr t4,24(sp) + sr t5,16(sp) + sr t6,8(sp) addi s0,sp,144 /* load supervisor cause */ csrr s4, CSR_SCAUSE @@ -40,25 +48,25 @@ handle_syscall: j restore_noreturn restore_all: - ld a0,96(sp) + lr a0,96(sp) restore_noreturn: - ld ra,136(sp) - ld t0,128(sp) - ld t1,120(sp) - ld t2,112(sp) - ld s0,104(sp) - ld a1,88(sp) - ld a2,80(sp) - ld a3,72(sp) - ld a4,64(sp) - ld a5,56(sp) - ld a6,48(sp) - ld a7,40(sp) - ld t3,32(sp) - ld t4,24(sp) - ld t5,16(sp) - ld t6,8(sp) + lr ra,136(sp) + lr t0,128(sp) + lr t1,120(sp) + lr t2,112(sp) + lr s0,104(sp) + lr a1,88(sp) + lr a2,80(sp) + lr a3,72(sp) + lr a4,64(sp) + lr a5,56(sp) + lr a6,48(sp) + lr a7,40(sp) + lr t3,32(sp) + lr t4,24(sp) + lr t5,16(sp) + lr t6,8(sp) addi sp,sp,144 /* assume supervisor for now */ sret diff --git a/arch/riscv64/kernel/timer.c b/arch/riscv64/kernel/timer.c index b6d828e..02f080c 100644 --- a/arch/riscv64/kernel/timer.c +++ b/arch/riscv64/kernel/timer.c @@ -1,4 +1,5 @@ #include <arch/timer.h> +#include <sbi.h> ticks_t stat_timer(const void *fdt) { @@ -9,6 +10,7 @@ ticks_t stat_timer(const void *fdt) void set_timer(ticks_t ticks) { /* TODO */ + sbi_set_timer(ticks); } ticks_t current_ticks() diff --git a/arch/riscv64/source.mk b/arch/riscv64/source.mk index ce229a4..fec5f80 100644 --- a/arch/riscv64/source.mk +++ b/arch/riscv64/source.mk @@ -4,7 +4,7 @@ INIT_SOURCES += arch/riscv64/init/*.[cS] CLEANUP_CMD := ./arch/riscv64/conf/rmimage.sh -ARCH_CFLAGS := -mcmodel=medany -fno-strict-aliasing +ARCH_CFLAGS := -mcmodel=medany ARCH_LDFLAGS := # llvm compilation doesn't seem to work, either bfd reads the object files wrong diff --git a/include/apos/utils.h b/include/apos/utils.h index 03e1a59..d7dd8b9 100644 --- a/include/apos/utils.h +++ b/include/apos/utils.h @@ -51,20 +51,22 @@ /* clang-format doesn't like _Generic, but I guess that's fine. */ #define align_up(x, y) \ - _Generic((x), int8_t \ - : align_up_int8_t, int16_t \ - : align_up_int16_t, int32_t \ - : align_up_int32_t, int64_t \ - : align_up_int64_t, \ + _Generic((x), signed char \ + : align_up_c, signed short \ + : align_up_s, signed int \ + : align_up_i, signed long \ + : align_up_l, signed long long \ + : align_up_ll,\ \ - uint8_t \ - : align_up_uint8_t, uint16_t \ - : align_up_uint16_t, uint32_t \ - : align_up_uint32_t, uint64_t \ - : align_up_uint64_t)((x), (y)) + unsigned char \ + : align_up_uc, unsigned short \ + : align_up_us, unsigned int \ + : align_up_ui, unsigned long \ + : align_up_ul, unsigned long long\ + : align_up_ull)((x), (y)) -#define DEFINE_ALIGN_UP(type) \ - static inline type align_up_##type(type val, type a) \ +#define DEFINE_ALIGN_UP(name, type) \ + static inline type align_up_##name(type val, type a) \ { \ if (!a) \ return val; \ @@ -77,31 +79,35 @@ return val + a - rem; \ } -DEFINE_ALIGN_UP(int8_t); -DEFINE_ALIGN_UP(int16_t); -DEFINE_ALIGN_UP(int32_t); -DEFINE_ALIGN_UP(int64_t); +DEFINE_ALIGN_UP(c, signed char); +DEFINE_ALIGN_UP(s, signed short); +DEFINE_ALIGN_UP(i, signed int); +DEFINE_ALIGN_UP(l, signed long); +DEFINE_ALIGN_UP(ll, signed long long); -DEFINE_ALIGN_UP(uint8_t); -DEFINE_ALIGN_UP(uint16_t); -DEFINE_ALIGN_UP(uint32_t); -DEFINE_ALIGN_UP(uint64_t); +DEFINE_ALIGN_UP(uc, unsigned char); +DEFINE_ALIGN_UP(us, unsigned short); +DEFINE_ALIGN_UP(ui, unsigned int); +DEFINE_ALIGN_UP(ul, unsigned long); +DEFINE_ALIGN_UP(ull, unsigned long long); #define align_down(x, y) \ - _Generic((x), int8_t \ - : align_down_int8_t, int16_t \ - : align_down_int16_t, int32_t \ - : align_down_int32_t, int64_t \ - : align_down_int64_t, \ + _Generic((x), signed char \ + : align_down_c, signed short \ + : align_down_s, signed int \ + : align_down_i, signed long \ + : align_down_l, signed long long \ + : align_down_ll,\ \ - uint8_t \ - : align_down_uint8_t, uint16_t \ - : align_down_uint16_t, uint32_t \ - : align_down_uint32_t, uint64_t \ - : align_down_uint64_t)((x), (y)) + unsigned char \ + : align_down_uc, unsigned short \ + : align_down_us, unsigned int \ + : align_down_ui, unsigned long \ + : align_down_ul, unsigned long long\ + : align_down_ull)((x), (y)) -#define DEFINE_ALIGN_DOWN(type) \ - static inline type align_down_##type(type val, type a) \ +#define DEFINE_ALIGN_DOWN(name, type) \ + static inline type align_down_##name(type val, type a) \ { \ if (!a) \ return val; \ @@ -109,31 +115,35 @@ DEFINE_ALIGN_UP(uint64_t); return val - (val % a); \ } -DEFINE_ALIGN_DOWN(int8_t); -DEFINE_ALIGN_DOWN(int16_t); -DEFINE_ALIGN_DOWN(int32_t); -DEFINE_ALIGN_DOWN(int64_t); +DEFINE_ALIGN_DOWN(c, signed char); +DEFINE_ALIGN_DOWN(s, signed short); +DEFINE_ALIGN_DOWN(i, signed int); +DEFINE_ALIGN_DOWN(l, signed long); +DEFINE_ALIGN_DOWN(ll, signed long long); -DEFINE_ALIGN_DOWN(uint8_t); -DEFINE_ALIGN_DOWN(uint16_t); -DEFINE_ALIGN_DOWN(uint32_t); -DEFINE_ALIGN_DOWN(uint64_t); +DEFINE_ALIGN_DOWN(uc, unsigned char); +DEFINE_ALIGN_DOWN(us, unsigned short); +DEFINE_ALIGN_DOWN(ui, unsigned int); +DEFINE_ALIGN_DOWN(ul, unsigned long); +DEFINE_ALIGN_DOWN(ull, unsigned long long); #define is_aligned(x, y) \ - _Generic((x), int8_t \ - : is_aligned_int8_t, int16_t \ - : is_aligned_int16_t, int32_t \ - : is_aligned_int32_t, int64_t \ - : is_aligned_int64_t, \ + _Generic((x), signed char \ + : is_aligned_c, signed short \ + : is_aligned_s, signed int \ + : is_aligned_i, signed long \ + : is_aligned_l, signed long long \ + : is_aligned_ll,\ \ - uint8_t \ - : is_aligned_uint8_t, uint16_t \ - : is_aligned_uint16_t, uint32_t \ - : is_aligned_uint32_t, uint64_t \ - : is_aligned_uint64_t)((x), (y)) + unsigned char \ + : is_aligned_uc, unsigned short \ + : is_aligned_us, unsigned int \ + : is_aligned_ui, unsigned long \ + : is_aligned_ul, unsigned long long \ + : is_aligned_ll)((x), (y)) -#define DEFINE_ALIGNED(type) \ - static inline bool is_aligned_##type(type val, type a) \ +#define DEFINE_ALIGNED(name, type) \ + static inline bool is_aligned_##name(type val, type a) \ { \ if (!a) \ return true; \ @@ -141,15 +151,17 @@ DEFINE_ALIGN_DOWN(uint64_t); return val % a == 0; \ } -DEFINE_ALIGNED(int8_t); -DEFINE_ALIGNED(int16_t); -DEFINE_ALIGNED(int32_t); -DEFINE_ALIGNED(int64_t); +DEFINE_ALIGNED(c, signed char); +DEFINE_ALIGNED(s, signed short); +DEFINE_ALIGNED(i, signed int); +DEFINE_ALIGNED(l, signed long); +DEFINE_ALIGNED(ll, signed long long); -DEFINE_ALIGNED(uint8_t); -DEFINE_ALIGNED(uint16_t); -DEFINE_ALIGNED(uint32_t); -DEFINE_ALIGNED(uint64_t); +DEFINE_ALIGNED(uc, unsigned char); +DEFINE_ALIGNED(us, unsigned short); +DEFINE_ALIGNED(ui, unsigned int); +DEFINE_ALIGNED(ul, unsigned long); +DEFINE_ALIGNED(ull, unsigned long long); static inline int asciinum(char c) { |
