From 1fc281e871e43bd6e902c1c17ef68a36051ff7dd Mon Sep 17 00:00:00 2001 From: Henrik Karlsson Date: Thu, 17 Oct 2024 23:52:15 +0200 Subject: [PATCH] Restructure the repository. --- ...cv64-unknown-elf@include@_newlib_version.h | 11 + ...unknown-elf@include@_newlib_version.h.blob | Bin 0 -> 1282 bytes ...known-elf@include@machine@_default_types.h | 249 ++++++ ...-elf@include@machine@_default_types.h.blob | Bin 0 -> 3983 bytes ...riscv@riscv64-unknown-elf@include@stdint.h | 465 ++++++++++ ...@riscv64-unknown-elf@include@stdint.h.blob | Bin 0 -> 9395 bytes ...@riscv64-unknown-elf@include@sys@_intsup.h | 199 +++++ ...v64-unknown-elf@include@sys@_intsup.h.blob | Bin 0 -> 2917 bytes ...@riscv64-unknown-elf@include@sys@_stdint.h | 90 ++ ...v64-unknown-elf@include@sys@_stdint.h.blob | Bin 0 -> 3840 bytes ...riscv64-unknown-elf@include@sys@features.h | 542 +++++++++++ ...64-unknown-elf@include@sys@features.h.blob | Bin 0 -> 2690 bytes .../@usr@include@features-time64.h | 37 + .../@usr@include@features-time64.h.blob | Bin 0 -> 971 bytes .../@usr@include@features.h | 494 ++++++++++ .../@usr@include@features.h.blob | Bin 0 -> 4001 bytes .../@usr@include@stdc-predef.h | 64 ++ .../@usr@include@stdc-predef.h.blob | Bin 0 -> 1398 bytes .../@@home@hak@dev@s3k/@usr@include@stdint.h | 307 +++++++ .../@usr@include@stdint.h.blob | Bin 0 -> 7042 bytes .../@@home@hak@dev@s3k/@usr@include@string.h | 449 ++++++++++ .../@usr@include@string.h.blob | Bin 0 -> 8789 bytes .../@@home@hak@dev@s3k/@usr@include@strings.h | 129 +++ .../@usr@include@strings.h.blob | Bin 0 -> 3007 bytes ...@x86_64-linux-gnu@bits@libc-header-start.h | 109 +++ ...64-linux-gnu@bits@libc-header-start.h.blob | Bin 0 -> 1688 bytes ...nclude@x86_64-linux-gnu@bits@long-double.h | 21 + ...e@x86_64-linux-gnu@bits@long-double.h.blob | Bin 0 -> 907 bytes ...nclude@x86_64-linux-gnu@bits@stdint-intn.h | 29 + ...e@x86_64-linux-gnu@bits@stdint-intn.h.blob | Bin 0 -> 1272 bytes ...clude@x86_64-linux-gnu@bits@stdint-uintn.h | 29 + ...@x86_64-linux-gnu@bits@stdint-uintn.h.blob | Bin 0 -> 1273 bytes ...usr@include@x86_64-linux-gnu@bits@time64.h | 36 + ...nclude@x86_64-linux-gnu@bits@time64.h.blob | Bin 0 -> 1344 bytes ...r@include@x86_64-linux-gnu@bits@timesize.h | 27 + ...lude@x86_64-linux-gnu@bits@timesize.h.blob | Bin 0 -> 980 bytes ...@usr@include@x86_64-linux-gnu@bits@types.h | 226 +++++ ...include@x86_64-linux-gnu@bits@types.h.blob | Bin 0 -> 4147 bytes ...e@x86_64-linux-gnu@bits@types@__locale_t.h | 42 + ..._64-linux-gnu@bits@types@__locale_t.h.blob | Bin 0 -> 1835 bytes ...ude@x86_64-linux-gnu@bits@types@locale_t.h | 26 + ...86_64-linux-gnu@bits@types@locale_t.h.blob | Bin 0 -> 933 bytes ...@include@x86_64-linux-gnu@bits@typesizes.h | 108 +++ ...ude@x86_64-linux-gnu@bits@typesizes.h.blob | Bin 0 -> 5156 bytes ...@usr@include@x86_64-linux-gnu@bits@wchar.h | 49 + ...include@x86_64-linux-gnu@bits@wchar.h.blob | Bin 0 -> 1387 bytes ...r@include@x86_64-linux-gnu@bits@wordsize.h | 16 + ...lude@x86_64-linux-gnu@bits@wordsize.h.blob | Bin 0 -> 1099 bytes ...sr@include@x86_64-linux-gnu@gnu@stubs-64.h | 17 + ...clude@x86_64-linux-gnu@gnu@stubs-64.h.blob | Bin 0 -> 1419 bytes .../@usr@include@x86_64-linux-gnu@gnu@stubs.h | 13 + ...@include@x86_64-linux-gnu@gnu@stubs.h.blob | Bin 0 -> 916 bytes .../@usr@include@x86_64-linux-gnu@sys@cdefs.h | 657 ++++++++++++++ ...@include@x86_64-linux-gnu@sys@cdefs.h.blob | Bin 0 -> 10090 bytes ...lang@14.0.6@include@__stddef_max_align_t.h | 25 + ...14.0.6@include@__stddef_max_align_t.h.blob | Bin 0 -> 844 bytes ...@llvm-14@lib@clang@14.0.6@include@stdarg.h | 35 + ...-14@lib@clang@14.0.6@include@stdarg.h.blob | Bin 0 -> 1372 bytes ...llvm-14@lib@clang@14.0.6@include@stdbool.h | 31 + ...14@lib@clang@14.0.6@include@stdbool.h.blob | Bin 0 -> 1231 bytes ...@llvm-14@lib@clang@14.0.6@include@stddef.h | 122 +++ ...-14@lib@clang@14.0.6@include@stddef.h.blob | Bin 0 -> 1295 bytes ...@llvm-14@lib@clang@14.0.6@include@stdint.h | 841 ++++++++++++++++++ ...-14@lib@clang@14.0.6@include@stdint.h.blob | Bin 0 -> 1315 bytes .../@home@hak@dev@s3k/common@inc@altc@altio.h | 12 + .../common@inc@altc@altio.h.blob | Bin 0 -> 1375 bytes .../@home@hak@dev@s3k/common@src@altc@init.c | 8 + .../common@src@altc@init.c.blob | Bin 0 -> 193 bytes .../common@src@altc@printf.c | 23 + .../common@src@altc@printf.c.blob | Bin 0 -> 1714 bytes .../common@src@drivers@time.c | 24 + .../common@src@drivers@time.c.blob | Bin 0 -> 525 bytes .../common@src@drivers@uart@ns16550a.c | 47 + .../common@src@drivers@uart@ns16550a.c.blob | Bin 0 -> 1557 bytes .../common@src@drivers@uart@sifive.c | 48 + .../common@src@drivers@uart@sifive.c.blob | Bin 0 -> 1482 bytes .../@home@hak@dev@s3k/common@src@s3k@s3k.c | 317 +++++++ .../common@src@s3k@s3k.c.blob | Bin 0 -> 2218 bytes .../common@src@s3k@syscall.c | 634 +++++++++++++ .../common@src@s3k@syscall.c.blob | Bin 0 -> 4596 bytes .../projects@demonstrator@app0@main.c | 7 + .../projects@demonstrator@app0@main.c.blob | Bin 0 -> 1110 bytes .../projects@demonstrator@app1@main.c | 7 + .../projects@demonstrator@app1@main.c.blob | Bin 0 -> 1110 bytes .../projects@demonstrator@boot@main.c | 217 +++++ .../projects@demonstrator@boot@main.c.blob | Bin 0 -> 3921 bytes .../projects@demonstrator@config.h | 39 + .../projects@demonstrator@config.h.blob | Bin 0 -> 2554 bytes .../projects@demonstrator@crypto@aes128.c | 336 +++++++ ...projects@demonstrator@crypto@aes128.c.blob | Bin 0 -> 5000 bytes .../projects@demonstrator@crypto@aes128.h | 21 + ...projects@demonstrator@crypto@aes128.h.blob | Bin 0 -> 2039 bytes .../projects@demonstrator@crypto@main.c | 77 ++ .../projects@demonstrator@crypto@main.c.blob | Bin 0 -> 2845 bytes .../projects@demonstrator@monitor@main.c | 203 +++++ .../projects@demonstrator@monitor@main.c.blob | Bin 0 -> 2926 bytes .../projects@demonstrator@uartppp@main.c | 78 ++ .../projects@demonstrator@uartppp@main.c.blob | Bin 0 -> 732 bytes .../projects@hello@app0@main.c | 72 ++ .../projects@hello@app0@main.c.blob | Bin 0 -> 1151 bytes .../projects@hello@app1@main.c | 8 + .../projects@hello@app1@main.c.blob | Bin 0 -> 196 bytes .../projects@hello@kern@qemu.h | 9 + .../projects@hello@kern@qemu.h.blob | Bin 0 -> 1523 bytes .../projects@ping-pong@app0@main.c | 94 ++ .../projects@ping-pong@app0@main.c.blob | Bin 0 -> 1274 bytes .../projects@ping-pong@app1@main.c | 21 + .../projects@ping-pong@app1@main.c.blob | Bin 0 -> 1102 bytes .../projects@trapped@app0@main.c | 83 ++ .../projects@trapped@app0@main.c.blob | Bin 0 -> 1180 bytes .../@home@hak@dev@s3k/sys@includes@alt@io.h | 44 + .../sys@includes@alt@io.h.blob | Bin 0 -> 6997 bytes .../sys@includes@drivers@time.h | 6 + .../sys@includes@drivers@time.h.blob | Bin 0 -> 695 bytes .../sys@includes@drivers@uart@ns16550a.h | 20 + .../sys@includes@drivers@uart@ns16550a.h.blob | Bin 0 -> 1779 bytes .../@home@hak@dev@s3k/sys@includes@kern@cap.h | 148 +++ .../sys@includes@kern@cap.h.blob | Bin 0 -> 11077 bytes .../@home@hak@dev@s3k/sys@includes@kern@csr.h | 33 + .../sys@includes@kern@csr.h.blob | Bin 0 -> 1992 bytes .../sys@includes@kern@error.h | 15 + .../sys@includes@kern@error.h.blob | Bin 0 -> 1193 bytes .../sys@includes@kern@exception.h | 12 + .../sys@includes@kern@exception.h.blob | Bin 0 -> 1501 bytes .../sys@includes@kern@interrupt.h | 6 + .../sys@includes@kern@interrupt.h.blob | Bin 0 -> 1266 bytes .../sys@includes@kern@kassert.h | 40 + .../sys@includes@kern@kassert.h.blob | Bin 0 -> 1669 bytes .../sys@includes@kern@kprintf.h | 11 + .../sys@includes@kern@kprintf.h.blob | Bin 0 -> 1704 bytes .../sys@includes@kern@macro.h | 25 + .../sys@includes@kern@macro.h.blob | Bin 0 -> 2107 bytes .../sys@includes@kern@macro.inc | 16 + .../sys@includes@kern@macro.inc.blob | Bin 0 -> 506 bytes .../sys@includes@kern@offsets.h | 0 .../sys@includes@kern@offsets.h.blob | Bin 0 -> 3943 bytes .../sys@includes@kern@proc.h | 76 ++ .../sys@includes@kern@proc.h.blob | Bin 0 -> 7569 bytes .../sys@includes@kern@sched.h | 35 + .../sys@includes@kern@sched.h.blob | Bin 0 -> 2501 bytes .../sys@includes@kern@syscall.h | 6 + .../sys@includes@kern@syscall.h.blob | Bin 0 -> 1524 bytes .../sys@includes@kern@trap.h | 13 + .../sys@includes@kern@trap.h.blob | Bin 0 -> 1818 bytes .../sys@includes@kern@types.h | 11 + .../sys@includes@kern@types.h.blob | Bin 0 -> 1335 bytes .../sys@includes@kern@utils.h | 50 ++ .../sys@includes@kern@utils.h.blob | Bin 0 -> 3766 bytes .../@home@hak@dev@s3k/sys@includes@kern@wfi.h | 13 + .../sys@includes@kern@wfi.h.blob | Bin 0 -> 1588 bytes .../sys@includes@smp@semaphore.h | 35 + .../sys@includes@smp@semaphore.h.blob | Bin 0 -> 2279 bytes .../@home@hak@dev@s3k/sys@src@alt@fprintf.c | 131 +++ .../sys@src@alt@fprintf.c.blob | Bin 0 -> 1941 bytes .../@home@hak@dev@s3k/sys@src@alt@printf.c | 58 ++ .../sys@src@alt@printf.c.blob | Bin 0 -> 2350 bytes .../@home@hak@dev@s3k/sys@src@alt@snprintf.c | 77 ++ .../sys@src@alt@snprintf.c.blob | Bin 0 -> 2810 bytes .../@home@hak@dev@s3k/sys@src@alt@sprintf.c | 67 ++ .../sys@src@alt@sprintf.c.blob | Bin 0 -> 1666 bytes .../@home@hak@dev@s3k/sys@src@drivers@time.c | 24 + .../sys@src@drivers@time.c.blob | Bin 0 -> 920 bytes .../sys@src@drivers@uart@ns16550a.c | 47 + .../sys@src@drivers@uart@ns16550a.c.blob | Bin 0 -> 1567 bytes .../sys@src@drivers@uart@sifive.c | 51 ++ .../sys@src@drivers@uart@sifive.c.blob | Bin 0 -> 1163 bytes .../@home@hak@dev@s3k/sys@src@kern@cap.c | 374 ++++++++ .../@home@hak@dev@s3k/sys@src@kern@cap.c.blob | Bin 0 -> 20169 bytes .../sys@src@kern@exception.c | 36 + .../sys@src@kern@exception.c.blob | Bin 0 -> 2407 bytes .../@home@hak@dev@s3k/sys@src@kern@head.S | 85 ++ .../sys@src@kern@head.S.blob | Bin 0 -> 784 bytes .../sys@src@kern@interrupt.c | 9 + .../sys@src@kern@interrupt.c.blob | Bin 0 -> 1513 bytes .../sys@src@kern@plat@qemu.c | 20 + .../sys@src@kern@plat@qemu.c.blob | Bin 0 -> 2542 bytes .../@home@hak@dev@s3k/sys@src@kern@proc.c | 125 +++ .../sys@src@kern@proc.c.blob | Bin 0 -> 3943 bytes .../@home@hak@dev@s3k/sys@src@kern@sched.c | 82 ++ .../sys@src@kern@sched.c.blob | Bin 0 -> 4001 bytes .../@home@hak@dev@s3k/sys@src@kern@syscall.c | 148 +++ .../sys@src@kern@syscall.c.blob | Bin 0 -> 5585 bytes .../@home@hak@dev@s3k/sys@src@kern@trap.S | 136 +++ .../sys@src@kern@trap.S.blob | Bin 0 -> 2034 bytes .../@home@hak@dev@s3k/sys@src@smp@mcslock.c | 53 ++ .../sys@src@smp@mcslock.c.blob | Bin 0 -> 922 bytes .../@home@hak@dev@s3k/sys@src@smp@semaphore.c | 0 .../sys@src@smp@semaphore.c.blob | Bin 0 -> 592 bytes .../@home@hak@dev@s3k/sys@src@smp@taslock.c | 25 + .../sys@src@smp@taslock.c.blob | Bin 0 -> 652 bytes .ccls-root | 0 .clang-format | 2 +- Makefile | 25 +- common/inc/altc/altio.h | 3 +- common/inc/plat/qemu_virt.h | 11 - common/inc/plat/qemu_virt4.h | 19 +- common/inc/plat/sifive_unleashed.h | 15 +- common/inc/plat/sifive_unleashed4.h | 19 +- common/inc/s3k/syscall.h | 42 +- common/inc/s3k/util.h | 9 +- common/src/altc/gets.c | 23 - common/src/altc/printf.c | 131 +-- common/src/altc/puts.c | 29 - common/src/s3k/s3k.c | 64 +- common/src/s3k/syscall.c | 177 ++-- kernel/Makefile | 91 -- kernel/inc/cap_ipc.h | 18 - kernel/inc/cap_lock.h | 5 - kernel/inc/cap_monitor.h | 174 ---- kernel/inc/cap_ops.h | 11 - kernel/inc/cap_pmp.h | 7 - kernel/inc/cap_table.h | 24 - kernel/inc/cap_types.h | 120 --- kernel/inc/cap_util.h | 33 - kernel/inc/csr.h | 38 - kernel/inc/error.h | 24 - kernel/inc/init.h | 26 - kernel/inc/interrupt.h | 5 - kernel/inc/kernel.h | 14 - kernel/inc/kprintf.h | 4 - kernel/inc/proc.h | 127 --- kernel/inc/smp/mcslock.h | 19 - kernel/inc/syscall.h | 159 ---- kernel/inc/uart.h | 144 --- kernel/src/cap_ipc.c | 239 ----- kernel/src/cap_lock.c | 23 - kernel/src/cap_monitor.c | 119 --- kernel/src/cap_ops.c | 426 --------- kernel/src/cap_pmp.c | 39 - kernel/src/cap_table.c | 111 --- kernel/src/cap_util.c | 152 ---- kernel/src/exception.c | 41 - kernel/src/interrupt.c | 9 - kernel/src/kernel.c | 32 - kernel/src/kprintf.c | 35 - kernel/src/proc.c | 142 --- kernel/src/sched.c | 162 ---- kernel/src/stack.S | 6 - kernel/src/syscall.c | 620 ------------- kernel/src/trap.S | 127 --- kernel/src/trap.c | 21 - projects/demonstrator/boot/main.c | 30 +- projects/demonstrator/crypto/aes128.c | 303 +++---- projects/demonstrator/crypto/aes128.h | 9 +- projects/demonstrator/monitor/main.c | 15 +- projects/hello/Makefile | 43 +- projects/hello/app0/qemu.ld | 40 + projects/hello/app1/qemu.ld | 40 + projects/hello/kern/Makefile | 6 + projects/hello/kern/qemu.h | 9 + projects/ping-pong/app0/main.c | 11 +- projects/trapped/app0/main.c | 4 +- sys/includes/alt/io.h | 44 + sys/includes/drivers/time.h | 6 + sys/includes/drivers/uart/ns16550a.h | 20 + sys/includes/drivers/uart/sifive.h | 20 + sys/includes/kern/cap.h | 148 +++ sys/includes/kern/csr.h | 33 + sys/includes/kern/error.h | 15 + {kernel/inc => sys/includes/kern}/exception.h | 7 +- sys/includes/kern/interrupt.h | 6 + {kernel/inc => sys/includes/kern}/kassert.h | 4 +- sys/includes/kern/kprintf.h | 11 + {kernel/inc => sys/includes/kern}/macro.h | 2 + {kernel/inc => sys/includes/kern}/macro.inc | 9 +- sys/includes/kern/offsets.h | 55 ++ sys/includes/kern/proc.h | 76 ++ {kernel/inc => sys/includes/kern}/sched.h | 18 +- sys/includes/kern/syscall.h | 6 + {kernel/inc => sys/includes/kern}/trap.h | 11 +- sys/includes/kern/types.h | 11 + sys/includes/kern/utils.h | 50 ++ {kernel/inc => sys/includes/kern}/wfi.h | 2 +- {kernel/inc => sys/includes}/smp/semaphore.h | 10 +- {kernel/inc => sys/includes}/smp/taslock.h | 0 sys/src/alt/fprintf.c | 131 +++ sys/src/alt/printf.c | 58 ++ sys/src/alt/snprintf.c | 77 ++ sys/src/alt/sprintf.c | 67 ++ sys/src/drivers/time.c | 24 + sys/src/drivers/uart/ns16550a.c | 47 + sys/src/drivers/uart/sifive.c | 51 ++ sys/src/kern/cap.c | 375 ++++++++ sys/src/kern/exception.c | 37 + {kernel/src => sys/src/kern}/head.S | 13 +- sys/src/kern/interrupt.c | 10 + sys/src/kern/plat/qemu.c | 20 + sys/src/kern/proc.c | 126 +++ sys/src/kern/sched.c | 83 ++ sys/src/kern/syscall.c | 149 ++++ sys/src/kern/trap.S | 136 +++ {kernel => sys}/src/smp/mcslock.c | 9 +- sys/src/smp/semaphore.c | 38 + {kernel => sys}/src/smp/taslock.c | 5 +- kernel/s3k_conf.h => tools/kern/default.h | 0 {kernel => tools/kern}/linker.ld | 0 tools/kern/qemu.ld | 39 + tools/kern/qemu.mk | 53 ++ tools/scripts/clang-format.sh | 4 + {scripts => tools/scripts}/gdb-openocd.sh | 0 {scripts => tools/scripts}/gdb.sh | 0 {scripts => tools/scripts}/qemu.sh | 0 tools.mk => tools/tools.mk | 0 303 files changed, 12501 insertions(+), 4084 deletions(-) create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@_newlib_version.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@_newlib_version.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@machine@_default_types.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@machine@_default_types.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@stdint.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@stdint.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_intsup.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_intsup.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_stdint.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_stdint.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@features.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@features.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@features-time64.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@features-time64.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@features.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@features.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@stdc-predef.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@stdc-predef.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@stdint.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@stdint.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@string.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@string.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@strings.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@strings.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@libc-header-start.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@libc-header-start.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@long-double.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@long-double.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@stdint-intn.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@stdint-intn.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@stdint-uintn.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@stdint-uintn.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@time64.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@time64.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@timesize.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@timesize.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types@__locale_t.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types@__locale_t.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types@locale_t.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types@locale_t.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@typesizes.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@typesizes.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wchar.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wchar.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wordsize.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wordsize.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs-64.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs-64.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@sys@cdefs.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@sys@cdefs.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@__stddef_max_align_t.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@__stddef_max_align_t.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdarg.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdarg.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdbool.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdbool.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stddef.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stddef.h.blob create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdint.h create mode 100644 .ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdint.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@inc@altc@altio.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@inc@altc@altio.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@altc@init.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@altc@init.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@altc@printf.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@altc@printf.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@drivers@time.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@drivers@time.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@ns16550a.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@ns16550a.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@sifive.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@sifive.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@s3k@s3k.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@s3k@s3k.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@s3k@syscall.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/common@src@s3k@syscall.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app0@main.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app0@main.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app1@main.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app1@main.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@boot@main.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@boot@main.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@config.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@config.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@aes128.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@aes128.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@aes128.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@aes128.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@main.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@main.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@monitor@main.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@monitor@main.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@uartppp@main.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@demonstrator@uartppp@main.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@hello@app0@main.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@hello@app0@main.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@hello@app1@main.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@hello@app1@main.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@hello@kern@qemu.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@hello@kern@qemu.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@ping-pong@app0@main.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@ping-pong@app0@main.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@ping-pong@app1@main.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@ping-pong@app1@main.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@trapped@app0@main.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/projects@trapped@app0@main.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@alt@io.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@alt@io.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@time.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@time.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@uart@ns16550a.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@uart@ns16550a.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@cap.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@cap.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@csr.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@csr.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@error.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@error.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@exception.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@exception.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@interrupt.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@interrupt.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@kassert.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@kassert.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@kprintf.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@kprintf.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@macro.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@macro.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@macro.inc create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@macro.inc.blob rename kernel/inc/offsets.h => .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@offsets.h (100%) create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@offsets.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@proc.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@proc.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@sched.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@sched.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@syscall.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@syscall.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@trap.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@trap.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@types.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@types.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@utils.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@utils.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@wfi.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@wfi.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@smp@semaphore.h create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@includes@smp@semaphore.h.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@alt@fprintf.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@alt@fprintf.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@alt@printf.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@alt@printf.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@alt@snprintf.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@alt@snprintf.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@alt@sprintf.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@alt@sprintf.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@drivers@time.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@drivers@time.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@ns16550a.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@ns16550a.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@sifive.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@sifive.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@cap.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@cap.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@exception.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@exception.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@head.S create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@head.S.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@interrupt.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@interrupt.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@plat@qemu.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@plat@qemu.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@proc.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@proc.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@sched.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@sched.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@syscall.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@syscall.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@trap.S create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@kern@trap.S.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@smp@mcslock.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@smp@mcslock.c.blob rename kernel/src/smp/semaphore.c => .ccls-cache/@home@hak@dev@s3k/sys@src@smp@semaphore.c (100%) create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@smp@semaphore.c.blob create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@smp@taslock.c create mode 100644 .ccls-cache/@home@hak@dev@s3k/sys@src@smp@taslock.c.blob create mode 100644 .ccls-root delete mode 100644 common/src/altc/gets.c delete mode 100644 common/src/altc/puts.c delete mode 100644 kernel/Makefile delete mode 100644 kernel/inc/cap_ipc.h delete mode 100644 kernel/inc/cap_lock.h delete mode 100644 kernel/inc/cap_monitor.h delete mode 100644 kernel/inc/cap_ops.h delete mode 100644 kernel/inc/cap_pmp.h delete mode 100644 kernel/inc/cap_table.h delete mode 100644 kernel/inc/cap_types.h delete mode 100644 kernel/inc/cap_util.h delete mode 100644 kernel/inc/csr.h delete mode 100644 kernel/inc/error.h delete mode 100644 kernel/inc/init.h delete mode 100644 kernel/inc/interrupt.h delete mode 100644 kernel/inc/kernel.h delete mode 100644 kernel/inc/kprintf.h delete mode 100644 kernel/inc/proc.h delete mode 100644 kernel/inc/smp/mcslock.h delete mode 100644 kernel/inc/syscall.h delete mode 100644 kernel/inc/uart.h delete mode 100644 kernel/src/cap_ipc.c delete mode 100644 kernel/src/cap_lock.c delete mode 100644 kernel/src/cap_monitor.c delete mode 100644 kernel/src/cap_ops.c delete mode 100644 kernel/src/cap_pmp.c delete mode 100644 kernel/src/cap_table.c delete mode 100644 kernel/src/cap_util.c delete mode 100644 kernel/src/exception.c delete mode 100644 kernel/src/interrupt.c delete mode 100644 kernel/src/kernel.c delete mode 100644 kernel/src/kprintf.c delete mode 100644 kernel/src/proc.c delete mode 100644 kernel/src/sched.c delete mode 100644 kernel/src/stack.S delete mode 100644 kernel/src/syscall.c delete mode 100644 kernel/src/trap.S delete mode 100644 kernel/src/trap.c create mode 100644 projects/hello/app0/qemu.ld create mode 100644 projects/hello/app1/qemu.ld create mode 100644 projects/hello/kern/Makefile create mode 100644 projects/hello/kern/qemu.h create mode 100644 sys/includes/alt/io.h create mode 100644 sys/includes/drivers/time.h create mode 100644 sys/includes/drivers/uart/ns16550a.h create mode 100644 sys/includes/drivers/uart/sifive.h create mode 100644 sys/includes/kern/cap.h create mode 100644 sys/includes/kern/csr.h create mode 100644 sys/includes/kern/error.h rename {kernel/inc => sys/includes/kern}/exception.h (56%) create mode 100644 sys/includes/kern/interrupt.h rename {kernel/inc => sys/includes/kern}/kassert.h (91%) create mode 100644 sys/includes/kern/kprintf.h rename {kernel/inc => sys/includes/kern}/macro.h (93%) rename {kernel/inc => sys/includes/kern}/macro.inc (62%) create mode 100644 sys/includes/kern/offsets.h create mode 100644 sys/includes/kern/proc.h rename {kernel/inc => sys/includes/kern}/sched.h (72%) create mode 100644 sys/includes/kern/syscall.h rename {kernel/inc => sys/includes/kern}/trap.h (51%) create mode 100644 sys/includes/kern/types.h create mode 100644 sys/includes/kern/utils.h rename {kernel/inc => sys/includes/kern}/wfi.h (85%) rename {kernel/inc => sys/includes}/smp/semaphore.h (66%) rename {kernel/inc => sys/includes}/smp/taslock.h (100%) create mode 100644 sys/src/alt/fprintf.c create mode 100644 sys/src/alt/printf.c create mode 100644 sys/src/alt/snprintf.c create mode 100644 sys/src/alt/sprintf.c create mode 100644 sys/src/drivers/time.c create mode 100644 sys/src/drivers/uart/ns16550a.c create mode 100644 sys/src/drivers/uart/sifive.c create mode 100644 sys/src/kern/cap.c create mode 100644 sys/src/kern/exception.c rename {kernel/src => sys/src/kern}/head.S (88%) create mode 100644 sys/src/kern/interrupt.c create mode 100644 sys/src/kern/plat/qemu.c create mode 100644 sys/src/kern/proc.c create mode 100644 sys/src/kern/sched.c create mode 100644 sys/src/kern/syscall.c create mode 100644 sys/src/kern/trap.S rename {kernel => sys}/src/smp/mcslock.c (82%) create mode 100644 sys/src/smp/semaphore.c rename {kernel => sys}/src/smp/taslock.c (85%) rename kernel/s3k_conf.h => tools/kern/default.h (100%) rename {kernel => tools/kern}/linker.ld (100%) create mode 100644 tools/kern/qemu.ld create mode 100644 tools/kern/qemu.mk create mode 100755 tools/scripts/clang-format.sh rename {scripts => tools/scripts}/gdb-openocd.sh (100%) rename {scripts => tools/scripts}/gdb.sh (100%) rename {scripts => tools/scripts}/qemu.sh (100%) rename tools.mk => tools/tools.mk (100%) diff --git a/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@_newlib_version.h b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@_newlib_version.h new file mode 100644 index 00000000..83165fe7 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@_newlib_version.h @@ -0,0 +1,11 @@ +/* _newlib_version.h. Generated from _newlib_version.hin by configure. */ +/* Version macros for internal and downstream use. */ +#ifndef _NEWLIB_VERSION_H__ +#define _NEWLIB_VERSION_H__ 1 + +#define _NEWLIB_VERSION "4.4.0" +#define __NEWLIB__ 4 +#define __NEWLIB_MINOR__ 4 +#define __NEWLIB_PATCHLEVEL__ 0 + +#endif /* !_NEWLIB_VERSION_H__ */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@_newlib_version.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@_newlib_version.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..6723296e7fb60fb7bcdd8ed53f758f19822c5b16 GIT binary patch literal 1282 zcmb7DL2DC16rQA}4PMNlAYRH+#cFYOlDZ92O`&R_ftb`<>T%f2PO{s~?yNJr2~iOI z6$;*Z@=)*~_yZIV9xNWb>t7I2JT=a4HmRCaA}o(#-h1Es-uKNegQNB0w+|o%kj-6+ zY_p9l+ClPa8_AwTQV`Up!b8OLbpp;H?gvOXl5|kR@dl@&0Yk6t@va9cYr+;G0IIJt z8PV|w3oR-EbWK6*lIRo-$2AFl=nyHQ+lEtOe$h}z;&O|!l1nYq>j79_0k8$&&Ny(u zIgs!!8$X$7?~$5tIa6^h)Cle8KlrQX-o& z#$zhr^lxg#n*FI1N*KmMV;NYE7wGoDknsVL8$<1mEm7sK>FvX5%Bc`sMEDEZwZmzd zjY!>4uVk7jLC>c$nsV@TW9lhtwI(%#Pz+k57l}eC5OW%cv5pH1MtmmB^jfH3=y|<3 z6ay*Y8p{4?=Kdr1-8jh!)}Z839R0kq`adkOvPg#h$fe`I;a~o$*KIotkB}lt z^J5q|?w-xfUPz}@yp(j`{r=cJ6 oI*P-sE+0Hz+4{2d + +/* + * Guess on types by examining *_MIN / *_MAX defines. + */ +#if __GNUC_PREREQ(3, 3) +/* GCC >= 3.3.0 has ____ implicitly defined. */ +#define __EXP(x) __##x##__ +#else +/* Fall back to POSIX versions from */ +#define __EXP(x) x +#include +#endif + +/* Check if "long long" is 64bit wide */ +/* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */ +#if (defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff)) || (defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff)) +#define __have_longlong64 1 +#endif + +/* Check if "long" is 64bit or 32bit wide */ +#if __EXP(LONG_MAX) > 0x7fffffff +#define __have_long64 1 +#elif __EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__) +#define __have_long32 1 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __INT8_TYPE__ +typedef __INT8_TYPE__ __int8_t; +#ifdef __UINT8_TYPE__ +typedef __UINT8_TYPE__ __uint8_t; +#else +typedef unsigned __INT8_TYPE__ __uint8_t; +#endif +#define ___int8_t_defined 1 +#elif __EXP(SCHAR_MAX) == 0x7f +typedef signed char __int8_t; +typedef unsigned char __uint8_t; +#define ___int8_t_defined 1 +#endif + +#ifdef __INT16_TYPE__ +typedef __INT16_TYPE__ __int16_t; +#ifdef __UINT16_TYPE__ +typedef __UINT16_TYPE__ __uint16_t; +#else +typedef unsigned __INT16_TYPE__ __uint16_t; +#endif +#define ___int16_t_defined 1 +#elif __EXP(INT_MAX) == 0x7fff +typedef signed int __int16_t; +typedef unsigned int __uint16_t; +#define ___int16_t_defined 1 +#elif __EXP(SHRT_MAX) == 0x7fff +typedef signed short __int16_t; +typedef unsigned short __uint16_t; +#define ___int16_t_defined 1 +#elif __EXP(SCHAR_MAX) == 0x7fff +typedef signed char __int16_t; +typedef unsigned char __uint16_t; +#define ___int16_t_defined 1 +#endif + +#ifdef __INT32_TYPE__ +typedef __INT32_TYPE__ __int32_t; +#ifdef __UINT32_TYPE__ +typedef __UINT32_TYPE__ __uint32_t; +#else +typedef unsigned __INT32_TYPE__ __uint32_t; +#endif +#define ___int32_t_defined 1 +#elif __EXP(INT_MAX) == 0x7fffffffL +typedef signed int __int32_t; +typedef unsigned int __uint32_t; +#define ___int32_t_defined 1 +#elif __EXP(LONG_MAX) == 0x7fffffffL +typedef signed long __int32_t; +typedef unsigned long __uint32_t; +#define ___int32_t_defined 1 +#elif __EXP(SHRT_MAX) == 0x7fffffffL +typedef signed short __int32_t; +typedef unsigned short __uint32_t; +#define ___int32_t_defined 1 +#elif __EXP(SCHAR_MAX) == 0x7fffffffL +typedef signed char __int32_t; +typedef unsigned char __uint32_t; +#define ___int32_t_defined 1 +#endif + +#ifdef __INT64_TYPE__ +typedef __INT64_TYPE__ __int64_t; +#ifdef __UINT64_TYPE__ +typedef __UINT64_TYPE__ __uint64_t; +#else +typedef unsigned __INT64_TYPE__ __uint64_t; +#endif +#define ___int64_t_defined 1 +#elif __EXP(LONG_MAX) > 0x7fffffff +typedef signed long __int64_t; +typedef unsigned long __uint64_t; +#define ___int64_t_defined 1 + +/* GCC has __LONG_LONG_MAX__ */ +#elif defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) +typedef signed long long __int64_t; +typedef unsigned long long __uint64_t; +#define ___int64_t_defined 1 + +/* POSIX mandates LLONG_MAX in */ +#elif defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) +typedef signed long long __int64_t; +typedef unsigned long long __uint64_t; +#define ___int64_t_defined 1 + +#elif __EXP(INT_MAX) > 0x7fffffff +typedef signed int __int64_t; +typedef unsigned int __uint64_t; +#define ___int64_t_defined 1 +#endif + +#ifdef __INT_LEAST8_TYPE__ +typedef __INT_LEAST8_TYPE__ __int_least8_t; +#ifdef __UINT_LEAST8_TYPE__ +typedef __UINT_LEAST8_TYPE__ __uint_least8_t; +#else +typedef unsigned __INT_LEAST8_TYPE__ __uint_least8_t; +#endif +#define ___int_least8_t_defined 1 +#elif defined(___int8_t_defined) +typedef __int8_t __int_least8_t; +typedef __uint8_t __uint_least8_t; +#define ___int_least8_t_defined 1 +#elif defined(___int16_t_defined) +typedef __int16_t __int_least8_t; +typedef __uint16_t __uint_least8_t; +#define ___int_least8_t_defined 1 +#elif defined(___int32_t_defined) +typedef __int32_t __int_least8_t; +typedef __uint32_t __uint_least8_t; +#define ___int_least8_t_defined 1 +#elif defined(___int64_t_defined) +typedef __int64_t __int_least8_t; +typedef __uint64_t __uint_least8_t; +#define ___int_least8_t_defined 1 +#endif + +#ifdef __INT_LEAST16_TYPE__ +typedef __INT_LEAST16_TYPE__ __int_least16_t; +#ifdef __UINT_LEAST16_TYPE__ +typedef __UINT_LEAST16_TYPE__ __uint_least16_t; +#else +typedef unsigned __INT_LEAST16_TYPE__ __uint_least16_t; +#endif +#define ___int_least16_t_defined 1 +#elif defined(___int16_t_defined) +typedef __int16_t __int_least16_t; +typedef __uint16_t __uint_least16_t; +#define ___int_least16_t_defined 1 +#elif defined(___int32_t_defined) +typedef __int32_t __int_least16_t; +typedef __uint32_t __uint_least16_t; +#define ___int_least16_t_defined 1 +#elif defined(___int64_t_defined) +typedef __int64_t __int_least16_t; +typedef __uint64_t __uint_least16_t; +#define ___int_least16_t_defined 1 +#endif + +#ifdef __INT_LEAST32_TYPE__ +typedef __INT_LEAST32_TYPE__ __int_least32_t; +#ifdef __UINT_LEAST32_TYPE__ +typedef __UINT_LEAST32_TYPE__ __uint_least32_t; +#else +typedef unsigned __INT_LEAST32_TYPE__ __uint_least32_t; +#endif +#define ___int_least32_t_defined 1 +#elif defined(___int32_t_defined) +typedef __int32_t __int_least32_t; +typedef __uint32_t __uint_least32_t; +#define ___int_least32_t_defined 1 +#elif defined(___int64_t_defined) +typedef __int64_t __int_least32_t; +typedef __uint64_t __uint_least32_t; +#define ___int_least32_t_defined 1 +#endif + +#ifdef __INT_LEAST64_TYPE__ +typedef __INT_LEAST64_TYPE__ __int_least64_t; +#ifdef __UINT_LEAST64_TYPE__ +typedef __UINT_LEAST64_TYPE__ __uint_least64_t; +#else +typedef unsigned __INT_LEAST64_TYPE__ __uint_least64_t; +#endif +#define ___int_least64_t_defined 1 +#elif defined(___int64_t_defined) +typedef __int64_t __int_least64_t; +typedef __uint64_t __uint_least64_t; +#define ___int_least64_t_defined 1 +#endif + +#if defined(__INTMAX_TYPE__) +typedef __INTMAX_TYPE__ __intmax_t; +#elif __have_longlong64 +typedef signed long long __intmax_t; +#else +typedef signed long __intmax_t; +#endif + +#if defined(__UINTMAX_TYPE__) +typedef __UINTMAX_TYPE__ __uintmax_t; +#elif __have_longlong64 +typedef unsigned long long __uintmax_t; +#else +typedef unsigned long __uintmax_t; +#endif + +#ifdef __INTPTR_TYPE__ +typedef __INTPTR_TYPE__ __intptr_t; +#ifdef __UINTPTR_TYPE__ +typedef __UINTPTR_TYPE__ __uintptr_t; +#else +typedef unsigned __INTPTR_TYPE__ __uintptr_t; +#endif +#elif defined(__PTRDIFF_TYPE__) +typedef __PTRDIFF_TYPE__ __intptr_t; +typedef unsigned __PTRDIFF_TYPE__ __uintptr_t; +#else +typedef long __intptr_t; +typedef unsigned long __uintptr_t; +#endif + +#undef __EXP + +#ifdef __cplusplus +} +#endif + +#endif /* _MACHINE__DEFAULT_TYPES_H */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@machine@_default_types.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@machine@_default_types.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..e70eeaa0d2e672cabf4d0a6bde726f4276c54ffd GIT binary patch literal 3983 zcma)84{Q_H8GmO=i{KhgAuGm9(<}kx8QbS1u4@v91V|W}95)N;8b-I9W1nM_^If>J z^9QKdGO{rKXlvA}E1i^?0U;}!Xt$7TfsSshX&7NGQ`)X-C_~L$ty9+)S~kSUzIVQ} z@8)bx6g^q~-uL@{f8O1*1>ITax;}{rM2CeaONae!bdc?!rLs0!>Xv9p4A5K6my zO0mP`j70qbW@jWIiTK-=NF~?qa>BYyuKmwkw-tHFjZsqHUdm*cRbiZNZ4h24aHPU75|GT@Vo?3vyvT45*~%}B9egpb+7sX(#^;51b4GLgXc(`?P9`D|xJQ4leHL81H7 ze3_+5dEk`HXG*NQot5yElTWXo?-Yh-JGn>;)4_^TMBvjNWX{@Wxff#nvACETjL$P2 zmqZ#MX^!iN+De@A=K$yDTj>&~-C=jBR?=X53mhIi^T@8~@3SS&5iG47sXPC)J~&^E zI6ejfmg4QIJ|btnDL}7Ap>Zi%Mm~VPKo+A_@k02x7T zWEAy~`_O*!Ao>w`1RW)hqZi0g^lS1AI!|6e7s*TLGWj}si@buak?*0uk?*6A$WPEs z66MWyu8|JkP5qn2aR%8?VVsvDtvnknQ<2NtE1- z@ZW6$ud~J{y#@6Z?sxwmO4Q$#Mwu?129#+utwVV~f46DL%?HdXib4SxFdXZbVlF2D zm`nvgW4wI4*+7h=@n$?v%`$dofIBozin<)S=Tg@H=VMb<; z7GSIEVmxvF?;aH(!yx5>$&?4ZGme=W12KbUYP7xgp15(WYx0Om?M*wWjK@ym`BrN# zU|8&yY6D?GmTE1=yGuX%`b)1ZS(AkUy-FBmrGR0vU>-h)4|w>HPsd}+3)aeeewX}d z7KSEKjh|L)AwW%dCLS{o6KLWwEuC}W+^Xhh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i3u@o~)jLBacdYu?bb?CY1YWJW960~I&PTPr mXq^VUIepRYk(G>5W8e#{sxP +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef ___int_least8_t_defined +typedef __int_least8_t int_least8_t; +typedef __uint_least8_t uint_least8_t; +#define __int_least8_t_defined 1 +#endif + +#ifdef ___int_least16_t_defined +typedef __int_least16_t int_least16_t; +typedef __uint_least16_t uint_least16_t; +#define __int_least16_t_defined 1 +#endif + +#ifdef ___int_least32_t_defined +typedef __int_least32_t int_least32_t; +typedef __uint_least32_t uint_least32_t; +#define __int_least32_t_defined 1 +#endif + +#ifdef ___int_least64_t_defined +typedef __int_least64_t int_least64_t; +typedef __uint_least64_t uint_least64_t; +#define __int_least64_t_defined 1 +#endif + +/* + * Fastest minimum-width integer types + * + * Assume int to be the fastest type for all types with a width + * less than __INT_MAX__ rsp. INT_MAX + */ +#ifdef __INT_FAST8_TYPE__ +typedef __INT_FAST8_TYPE__ int_fast8_t; +typedef __UINT_FAST8_TYPE__ uint_fast8_t; +#define __int_fast8_t_defined 1 +#elif __STDINT_EXP(INT_MAX) >= 0x7f +typedef signed int int_fast8_t; +typedef unsigned int uint_fast8_t; +#define __int_fast8_t_defined 1 +#endif + +#ifdef __INT_FAST16_TYPE__ +typedef __INT_FAST16_TYPE__ int_fast16_t; +typedef __UINT_FAST16_TYPE__ uint_fast16_t; +#define __int_fast16_t_defined 1 +#elif __STDINT_EXP(INT_MAX) >= 0x7fff +typedef signed int int_fast16_t; +typedef unsigned int uint_fast16_t; +#define __int_fast16_t_defined 1 +#endif + +#ifdef __INT_FAST32_TYPE__ +typedef __INT_FAST32_TYPE__ int_fast32_t; +typedef __UINT_FAST32_TYPE__ uint_fast32_t; +#define __int_fast32_t_defined 1 +#elif __STDINT_EXP(INT_MAX) >= 0x7fffffff +typedef signed int int_fast32_t; +typedef unsigned int uint_fast32_t; +#define __int_fast32_t_defined 1 +#endif + +#ifdef __INT_FAST64_TYPE__ +typedef __INT_FAST64_TYPE__ int_fast64_t; +typedef __UINT_FAST64_TYPE__ uint_fast64_t; +#define __int_fast64_t_defined 1 +#elif __STDINT_EXP(INT_MAX) > 0x7fffffff +typedef signed int int_fast64_t; +typedef unsigned int uint_fast64_t; +#define __int_fast64_t_defined 1 +#endif + +/* + * Fall back to [u]int_least_t for [u]int_fast_t types + * not having been defined, yet. + * Leave undefined, if [u]int_least_t should not be available. + */ +#if !__int_fast8_t_defined +#if __int_least8_t_defined +typedef int_least8_t int_fast8_t; +typedef uint_least8_t uint_fast8_t; +#define __int_fast8_t_defined 1 +#endif +#endif + +#if !__int_fast16_t_defined +#if __int_least16_t_defined +typedef int_least16_t int_fast16_t; +typedef uint_least16_t uint_fast16_t; +#define __int_fast16_t_defined 1 +#endif +#endif + +#if !__int_fast32_t_defined +#if __int_least32_t_defined +typedef int_least32_t int_fast32_t; +typedef uint_least32_t uint_fast32_t; +#define __int_fast32_t_defined 1 +#endif +#endif + +#if !__int_fast64_t_defined +#if __int_least64_t_defined +typedef int_least64_t int_fast64_t; +typedef uint_least64_t uint_fast64_t; +#define __int_fast64_t_defined 1 +#endif +#endif + +#ifdef __INTPTR_TYPE__ +#define INTPTR_MIN (-__INTPTR_MAX__ - 1) +#define INTPTR_MAX (__INTPTR_MAX__) +#define UINTPTR_MAX (__UINTPTR_MAX__) +#elif defined(__PTRDIFF_TYPE__) +#define INTPTR_MAX PTRDIFF_MAX +#define INTPTR_MIN PTRDIFF_MIN +#ifdef __UINTPTR_MAX__ +#define UINTPTR_MAX (__UINTPTR_MAX__) +#else +#define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1) +#endif +#else +/* + * Fallback to hardcoded values, + * should be valid on cpu's with 32bit int/32bit void* + */ +#define INTPTR_MAX (__STDINT_EXP(LONG_MAX)) +#define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1) +#define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) +#endif + +/* Limits of Specified-Width Integer Types */ + +#ifdef __INT8_MAX__ +#define INT8_MIN (-__INT8_MAX__ - 1) +#define INT8_MAX (__INT8_MAX__) +#define UINT8_MAX (__UINT8_MAX__) +#elif defined(__int8_t_defined) +#define INT8_MIN (-128) +#define INT8_MAX (127) +#define UINT8_MAX (255) +#endif + +#ifdef __INT_LEAST8_MAX__ +#define INT_LEAST8_MIN (-__INT_LEAST8_MAX__ - 1) +#define INT_LEAST8_MAX (__INT_LEAST8_MAX__) +#define UINT_LEAST8_MAX (__UINT_LEAST8_MAX__) +#elif defined(__int_least8_t_defined) +#define INT_LEAST8_MIN (-128) +#define INT_LEAST8_MAX (127) +#define UINT_LEAST8_MAX (255) +#else +#error required type int_least8_t missing +#endif + +#ifdef __INT16_MAX__ +#define INT16_MIN (-__INT16_MAX__ - 1) +#define INT16_MAX (__INT16_MAX__) +#define UINT16_MAX (__UINT16_MAX__) +#elif defined(__int16_t_defined) +#define INT16_MIN (-32768) +#define INT16_MAX (32767) +#define UINT16_MAX (65535) +#endif + +#ifdef __INT_LEAST16_MAX__ +#define INT_LEAST16_MIN (-__INT_LEAST16_MAX__ - 1) +#define INT_LEAST16_MAX (__INT_LEAST16_MAX__) +#define UINT_LEAST16_MAX (__UINT_LEAST16_MAX__) +#elif defined(__int_least16_t_defined) +#define INT_LEAST16_MIN (-32768) +#define INT_LEAST16_MAX (32767) +#define UINT_LEAST16_MAX (65535) +#else +#error required type int_least16_t missing +#endif + +#ifdef __INT32_MAX__ +#define INT32_MIN (-__INT32_MAX__ - 1) +#define INT32_MAX (__INT32_MAX__) +#define UINT32_MAX (__UINT32_MAX__) +#elif defined(__int32_t_defined) +#if defined(_INT32_EQ_LONG) +#define INT32_MIN (-2147483647L - 1) +#define INT32_MAX (2147483647L) +#define UINT32_MAX (4294967295UL) +#else +#define INT32_MIN (-2147483647 - 1) +#define INT32_MAX (2147483647) +#define UINT32_MAX (4294967295U) +#endif +#endif + +#ifdef __INT_LEAST32_MAX__ +#define INT_LEAST32_MIN (-__INT_LEAST32_MAX__ - 1) +#define INT_LEAST32_MAX (__INT_LEAST32_MAX__) +#define UINT_LEAST32_MAX (__UINT_LEAST32_MAX__) +#elif defined(__int_least32_t_defined) +#if defined(_INT32_EQ_LONG) +#define INT_LEAST32_MIN (-2147483647L - 1) +#define INT_LEAST32_MAX (2147483647L) +#define UINT_LEAST32_MAX (4294967295UL) +#else +#define INT_LEAST32_MIN (-2147483647 - 1) +#define INT_LEAST32_MAX (2147483647) +#define UINT_LEAST32_MAX (4294967295U) +#endif +#else +#error required type int_least32_t missing +#endif + +#ifdef __INT64_MAX__ +#define INT64_MIN (-__INT64_MAX__ - 1) +#define INT64_MAX (__INT64_MAX__) +#define UINT64_MAX (__UINT64_MAX__) +#elif defined(__int64_t_defined) +#if __have_long64 +#define INT64_MIN (-9223372036854775807L - 1L) +#define INT64_MAX (9223372036854775807L) +#define UINT64_MAX (18446744073709551615U) +#elif __have_longlong64 +#define INT64_MIN (-9223372036854775807LL - 1LL) +#define INT64_MAX (9223372036854775807LL) +#define UINT64_MAX (18446744073709551615ULL) +#endif +#endif + +#ifdef __INT_LEAST64_MAX__ +#define INT_LEAST64_MIN (-__INT_LEAST64_MAX__ - 1) +#define INT_LEAST64_MAX (__INT_LEAST64_MAX__) +#define UINT_LEAST64_MAX (__UINT_LEAST64_MAX__) +#elif defined(__int_least64_t_defined) +#if __have_long64 +#define INT_LEAST64_MIN (-9223372036854775807L - 1L) +#define INT_LEAST64_MAX (9223372036854775807L) +#define UINT_LEAST64_MAX (18446744073709551615U) +#elif __have_longlong64 +#define INT_LEAST64_MIN (-9223372036854775807LL - 1LL) +#define INT_LEAST64_MAX (9223372036854775807LL) +#define UINT_LEAST64_MAX (18446744073709551615ULL) +#endif +#endif + +#ifdef __INT_FAST8_MAX__ +#define INT_FAST8_MIN (-__INT_FAST8_MAX__ - 1) +#define INT_FAST8_MAX (__INT_FAST8_MAX__) +#define UINT_FAST8_MAX (__UINT_FAST8_MAX__) +#elif defined(__int_fast8_t_defined) +#if __STDINT_EXP(INT_MAX) >= 0x7f +#define INT_FAST8_MIN (-__STDINT_EXP(INT_MAX) - 1) +#define INT_FAST8_MAX (__STDINT_EXP(INT_MAX)) +#define UINT_FAST8_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) +#else +#define INT_FAST8_MIN INT_LEAST8_MIN +#define INT_FAST8_MAX INT_LEAST8_MAX +#define UINT_FAST8_MAX UINT_LEAST8_MAX +#endif +#endif + +#ifdef __INT_FAST16_MAX__ +#define INT_FAST16_MIN (-__INT_FAST16_MAX__ - 1) +#define INT_FAST16_MAX (__INT_FAST16_MAX__) +#define UINT_FAST16_MAX (__UINT_FAST16_MAX__) +#elif defined(__int_fast16_t_defined) +#if __STDINT_EXP(INT_MAX) >= 0x7fff +#define INT_FAST16_MIN (-__STDINT_EXP(INT_MAX) - 1) +#define INT_FAST16_MAX (__STDINT_EXP(INT_MAX)) +#define UINT_FAST16_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) +#else +#define INT_FAST16_MIN INT_LEAST16_MIN +#define INT_FAST16_MAX INT_LEAST16_MAX +#define UINT_FAST16_MAX UINT_LEAST16_MAX +#endif +#endif + +#ifdef __INT_FAST32_MAX__ +#define INT_FAST32_MIN (-__INT_FAST32_MAX__ - 1) +#define INT_FAST32_MAX (__INT_FAST32_MAX__) +#define UINT_FAST32_MAX (__UINT_FAST32_MAX__) +#elif defined(__int_fast32_t_defined) +#if __STDINT_EXP(INT_MAX) >= 0x7fffffff +#define INT_FAST32_MIN (-__STDINT_EXP(INT_MAX) - 1) +#define INT_FAST32_MAX (__STDINT_EXP(INT_MAX)) +#define UINT_FAST32_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) +#else +#define INT_FAST32_MIN INT_LEAST32_MIN +#define INT_FAST32_MAX INT_LEAST32_MAX +#define UINT_FAST32_MAX UINT_LEAST32_MAX +#endif +#endif + +#ifdef __INT_FAST64_MAX__ +#define INT_FAST64_MIN (-__INT_FAST64_MAX__ - 1) +#define INT_FAST64_MAX (__INT_FAST64_MAX__) +#define UINT_FAST64_MAX (__UINT_FAST64_MAX__) +#elif defined(__int_fast64_t_defined) +#if __STDINT_EXP(INT_MAX) > 0x7fffffff +#define INT_FAST64_MIN (-__STDINT_EXP(INT_MAX) - 1) +#define INT_FAST64_MAX (__STDINT_EXP(INT_MAX)) +#define UINT_FAST64_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) +#else +#define INT_FAST64_MIN INT_LEAST64_MIN +#define INT_FAST64_MAX INT_LEAST64_MAX +#define UINT_FAST64_MAX UINT_LEAST64_MAX +#endif +#endif + +#ifdef __INTMAX_MAX__ +#define INTMAX_MAX (__INTMAX_MAX__) +#define INTMAX_MIN (-INTMAX_MAX - 1) +#elif defined(__INTMAX_TYPE__) +/* All relevant GCC versions prefer long to long long for intmax_t. */ +#define INTMAX_MAX INT64_MAX +#define INTMAX_MIN INT64_MIN +#endif + +#ifdef __UINTMAX_MAX__ +#define UINTMAX_MAX (__UINTMAX_MAX__) +#elif defined(__UINTMAX_TYPE__) +/* All relevant GCC versions prefer long to long long for intmax_t. */ +#define UINTMAX_MAX UINT64_MAX +#endif + +/* This must match size_t in stddef.h, currently long unsigned int */ +#ifdef __SIZE_MAX__ +#define SIZE_MAX (__SIZE_MAX__) +#else +#define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) +#endif + +/* This must match sig_atomic_t in (currently int) */ +#define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1) +#define SIG_ATOMIC_MAX (__STDINT_EXP(INT_MAX)) + +/* This must match ptrdiff_t in (currently long int) */ +#ifdef __PTRDIFF_MAX__ +#define PTRDIFF_MAX (__PTRDIFF_MAX__) +#else +#define PTRDIFF_MAX (__STDINT_EXP(LONG_MAX)) +#endif +#define PTRDIFF_MIN (-PTRDIFF_MAX - 1) + +/* This must match definition in */ +#ifndef WCHAR_MIN +#ifdef __WCHAR_MIN__ +#define WCHAR_MIN (__WCHAR_MIN__) +#elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0) +#define WCHAR_MIN (0 + L'\0') +#else +#define WCHAR_MIN (-0x7fffffff - 1 + L'\0') +#endif +#endif + +/* This must match definition in */ +#ifndef WCHAR_MAX +#ifdef __WCHAR_MAX__ +#define WCHAR_MAX (__WCHAR_MAX__) +#elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0) +#define WCHAR_MAX (0xffffffffu + L'\0') +#else +#define WCHAR_MAX (0x7fffffff + L'\0') +#endif +#endif + +/* wint_t is unsigned int on almost all GCC targets. */ +#ifdef __WINT_MAX__ +#define WINT_MAX (__WINT_MAX__) +#else +#define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) +#endif +#ifdef __WINT_MIN__ +#define WINT_MIN (__WINT_MIN__) +#else +#define WINT_MIN (0U) +#endif + +/** Macros for minimum-width integer constant expressions */ +#ifdef __INT8_C +#define INT8_C(x) __INT8_C(x) +#define UINT8_C(x) __UINT8_C(x) +#else +#define INT8_C(x) x +#if __STDINT_EXP(INT_MAX) > 0x7f +#define UINT8_C(x) x +#else +#define UINT8_C(x) x##U +#endif +#endif + +#ifdef __INT16_C +#define INT16_C(x) __INT16_C(x) +#define UINT16_C(x) __UINT16_C(x) +#else +#define INT16_C(x) x +#if __STDINT_EXP(INT_MAX) > 0x7fff +#define UINT16_C(x) x +#else +#define UINT16_C(x) x##U +#endif +#endif + +#ifdef __INT32_C +#define INT32_C(x) __INT32_C(x) +#define UINT32_C(x) __UINT32_C(x) +#else +#if defined(_INT32_EQ_LONG) +#define INT32_C(x) x##L +#define UINT32_C(x) x##UL +#else +#define INT32_C(x) x +#define UINT32_C(x) x##U +#endif +#endif + +#ifdef __INT64_C +#define INT64_C(x) __INT64_C(x) +#define UINT64_C(x) __UINT64_C(x) +#else +#if __int64_t_defined +#if __have_long64 +#define INT64_C(x) x##L +#define UINT64_C(x) x##UL +#else +#define INT64_C(x) x##LL +#define UINT64_C(x) x##ULL +#endif +#endif +#endif + +/** Macros for greatest-width integer constant expression */ +#ifdef __INTMAX_C +#define INTMAX_C(x) __INTMAX_C(x) +#define UINTMAX_C(x) __UINTMAX_C(x) +#else +#if __have_long64 +#define INTMAX_C(x) x##L +#define UINTMAX_C(x) x##UL +#else +#define INTMAX_C(x) x##LL +#define UINTMAX_C(x) x##ULL +#endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _STDINT_H */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@stdint.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@stdint.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..762f63398b7954d9b9a96f192c45cf726d19b1e1 GIT binary patch literal 9395 zcmb7I3tUuH8o!rNQ)l%`1L45hfCVD~0|O!&phON}g1l66)e&X}7#(J42Jlg>kIHN- zE8EnNY%{CP)YexIcUNtFtUWC??U&ZCGR@wrrMBhBe&_L>d+$J-%@5A`?s@#r_x-=e zxicx!rM#T)-;!j>+T?F`Tbt@;SzYdSYcOk;H8?kD4F;UnS?++(>a1%?cS-}T{+3p2 zz!P+~TkAbOCgo(OwfScG{Ih*&Zf`?cqthv+!Cz_5h#sHQ+vaiyrL^X{fU_w-(4Ld+ zX|8iR=6RgK02!_KjP-y39#-s)~{ zOZU2@G=7jo2b!cbzvQo<$rn*;(*2ibblPlxV3x<%nC9{X+|E{iU~YbQ4O#;JnJ^i& zHo3iCKUGEQr(uh7rf15^HKas4f~_u(uQk0%x>NuT>3#t526Csm1eU+(zUl4DS?&%5 z`~iYL#GHFs8(QbKxPxTF`W1z5U#2MzpL@2~Q}1YZ2ZA2IPne^I&94#B;I3ynj5C`PUHMceI?aoOLKC<%Yxb$P{ z@XNK4c)|g`3bwWUM*ASln>;?Z)!}kC)U|nA9fD$F=@l`TN%Akk#9k(V-U8Ea*(Jhs z*g$EJVYoEXFj^`yluBiWYH6}zy5ur6NM3_aYBjV=w;L8o%M2aTYQtJ-o#AiNR>O8_ zmtmjuj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{K;g$kSInTG-XY(W+tL>lthBDeuA2(BjeG zY#H`$pF8U}5Y|YgXUPd#bgQRq202sLa<9jL*JEfYWfGS9GxJ{wy?NWTcB+s1(f}uj zVi7hah*MYdGm_zqWcsC!N$8&O+io>2-xgX0Mi8E9t<$Cs8^laRS6~4>shouTffh5d zsMjNr`_A2MREq}C`YT04yMh*t5~T!+2DH3r`1<)s(U>>--qrVA+`5IU+AYhOa-3z< zlmyKwicwDT#1w+wbMl>~pN%*edKeA(LN&nnD zk+~p5gdT(+Lm!mQ@YD7xkX8|?>o3w_!CvvbRUPFa T%-3+xu>d-j{))sT{xbSMD6&pc literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_intsup.h b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_intsup.h new file mode 100644 index 00000000..f486b293 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_intsup.h @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2004, 2005 by + * Ralf Corsepius, Ulm/Germany. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#ifndef _SYS__INTSUP_H +#define _SYS__INTSUP_H + +#include + +#if __GNUC_PREREQ(3, 2) +/* gcc > 3.2 implicitly defines the values we are interested */ +#define __STDINT_EXP(x) __##x##__ +#else +#define __STDINT_EXP(x) x +#include +#endif + +/* Determine how intptr_t and intN_t fastN_t and leastN_t are defined by gcc + for this target. This is used to determine the correct printf() constant in + inttypes.h and other constants in stdint.h. + So we end up with + ?(signed|unsigned) char == 0 + ?(signed|unsigned) short == 1 + ?(signed|unsigned) int == 2 + ?(signed|unsigned) short int == 3 + ?(signed|unsigned) long == 4 + ?(signed|unsigned) long int == 6 + ?(signed|unsigned) long long == 8 + ?(signed|unsigned) long long int == 10 + */ +#pragma push_macro("signed") +#pragma push_macro("unsigned") +#pragma push_macro("char") +#pragma push_macro("short") +#pragma push_macro("__int20") +#pragma push_macro("__int20__") +#pragma push_macro("int") +#pragma push_macro("long") +#undef signed +#undef unsigned +#undef char +#undef short +#undef int +#undef __int20 +#undef __int20__ +#undef long +#define signed +0 +#define unsigned +0 +#define char +0 +#define short +1 +#define __int20 +2 +#define __int20__ +2 +#define int +2 +#define long +4 +#if (__INTPTR_TYPE__ == 8 || __INTPTR_TYPE__ == 10) +#define _INTPTR_EQ_LONGLONG +#elif (__INTPTR_TYPE__ == 4 || __INTPTR_TYPE__ == 6) +#define _INTPTR_EQ_LONG +/* Note - the tests for _INTPTR_EQ_INT and _INTPTR_EQ_SHORT are currently + redundant as the values are not used. But one day they may be needed + and so the tests remain. */ +#elif __INTPTR_TYPE__ == 2 +#define _INTPTR_EQ_INT +#elif (__INTPTR_TYPE__ == 1 || __INTPTR_TYPE__ == 3) +#define _INTPTR_EQ_SHORT +#else +#error "Unable to determine type definition of intptr_t" +#endif +#if (__INT32_TYPE__ == 4 || __INT32_TYPE__ == 6) +#define _INT32_EQ_LONG +#elif __INT32_TYPE__ == 2 +/* Nothing to define because int32_t is safe to print as an int. */ +#else +#error "Unable to determine type definition of int32_t" +#endif + +#if (__INT8_TYPE__ == 0) +#define __INT8 "hh" +#elif (__INT8_TYPE__ == 1 || __INT8_TYPE__ == 3) +#define __INT8 "h" +#elif (__INT8_TYPE__ == 2) +#define __INT8 +#elif (__INT8_TYPE__ == 4 || __INT8_TYPE__ == 6) +#define __INT8 "l" +#elif (__INT8_TYPE__ == 8 || __INT8_TYPE__ == 10) +#define __INT8 "ll" +#endif +#if (__INT16_TYPE__ == 1 || __INT16_TYPE__ == 3) +#define __INT16 "h" +#elif (__INT16_TYPE__ == 2) +#define __INT16 +#elif (__INT16_TYPE__ == 4 || __INT16_TYPE__ == 6) +#define __INT16 "l" +#elif (__INT16_TYPE__ == 8 || __INT16_TYPE__ == 10) +#define __INT16 "ll" +#endif +#if (__INT32_TYPE__ == 2) +#define __INT32 +#elif (__INT32_TYPE__ == 4 || __INT32_TYPE__ == 6) +#define __INT32 "l" +#elif (__INT32_TYPE__ == 8 || __INT32_TYPE__ == 10) +#define __INT32 "ll" +#endif +#if (__INT64_TYPE__ == 2) +#define __INT64 +#elif (__INT64_TYPE__ == 4 || __INT64_TYPE__ == 6) +#define __INT64 "l" +#elif (__INT64_TYPE__ == 8 || __INT64_TYPE__ == 10) +#define __INT64 "ll" +#endif +#if (__INT_FAST8_TYPE__ == 0) +#define __FAST8 "hh" +#elif (__INT_FAST8_TYPE__ == 1 || __INT_FAST8_TYPE__ == 3) +#define __FAST8 "h" +#elif (__INT_FAST8_TYPE__ == 2) +#define __FAST8 +#elif (__INT_FAST8_TYPE__ == 4 || __INT_FAST8_TYPE__ == 6) +#define __FAST8 "l" +#elif (__INT_FAST8_TYPE__ == 8 || __INT_FAST8_TYPE__ == 10) +#define __FAST8 "ll" +#endif +#if (__INT_FAST16_TYPE__ == 1 || __INT_FAST16_TYPE__ == 3) +#define __FAST16 "h" +#elif (__INT_FAST16_TYPE__ == 2) +#define __FAST16 +#elif (__INT_FAST16_TYPE__ == 4 || __INT_FAST16_TYPE__ == 6) +#define __FAST16 "l" +#elif (__INT_FAST16_TYPE__ == 8 || __INT_FAST16_TYPE__ == 10) +#define __FAST16 "ll" +#endif +#if (__INT_FAST32_TYPE__ == 2) +#define __FAST32 +#elif (__INT_FAST32_TYPE__ == 4 || __INT_FAST32_TYPE__ == 6) +#define __FAST32 "l" +#elif (__INT_FAST32_TYPE__ == 8 || __INT_FAST32_TYPE__ == 10) +#define __FAST32 "ll" +#endif +#if (__INT_FAST64_TYPE__ == 2) +#define __FAST64 +#elif (__INT_FAST64_TYPE__ == 4 || __INT_FAST64_TYPE__ == 6) +#define __FAST64 "l" +#elif (__INT_FAST64_TYPE__ == 8 || __INT_FAST64_TYPE__ == 10) +#define __FAST64 "ll" +#endif + +#if (__INT_LEAST8_TYPE__ == 0) +#define __LEAST8 "hh" +#elif (__INT_LEAST8_TYPE__ == 1 || __INT_LEAST8_TYPE__ == 3) +#define __LEAST8 "h" +#elif (__INT_LEAST8_TYPE__ == 2) +#define __LEAST8 +#elif (__INT_LEAST8_TYPE__ == 4 || __INT_LEAST8_TYPE__ == 6) +#define __LEAST8 "l" +#elif (__INT_LEAST8_TYPE__ == 8 || __INT_LEAST8_TYPE__ == 10) +#define __LEAST8 "ll" +#endif +#if (__INT_LEAST16_TYPE__ == 1 || __INT_LEAST16_TYPE__ == 3) +#define __LEAST16 "h" +#elif (__INT_LEAST16_TYPE__ == 2) +#define __LEAST16 +#elif (__INT_LEAST16_TYPE__ == 4 || __INT_LEAST16_TYPE__ == 6) +#define __LEAST16 "l" +#elif (__INT_LEAST16_TYPE__ == 8 || __INT_LEAST16_TYPE__ == 10) +#define __LEAST16 "ll" +#endif +#if (__INT_LEAST32_TYPE__ == 2) +#define __LEAST32 +#elif (__INT_LEAST32_TYPE__ == 4 || __INT_LEAST32_TYPE__ == 6) +#define __LEAST32 "l" +#elif (__INT_LEAST32_TYPE__ == 8 || __INT_LEAST32_TYPE__ == 10) +#define __LEAST32 "ll" +#endif +#if (__INT_LEAST64_TYPE__ == 2) +#define __LEAST64 +#elif (__INT_LEAST64_TYPE__ == 4 || __INT_LEAST64_TYPE__ == 6) +#define __LEAST64 "l" +#elif (__INT_LEAST64_TYPE__ == 8 || __INT_LEAST64_TYPE__ == 10) +#define __LEAST64 "ll" +#endif +#undef signed +#undef unsigned +#undef char +#undef short +#undef int +#undef long +#pragma pop_macro("signed") +#pragma pop_macro("unsigned") +#pragma pop_macro("char") +#pragma pop_macro("short") +#pragma pop_macro("__int20") +#pragma pop_macro("__int20__") +#pragma pop_macro("int") +#pragma pop_macro("long") + +#endif /* _SYS__INTSUP_H */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_intsup.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys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&G|xr<3;!Nst9Srm{$ny6%)njIuVVs|D%S{GzfKfMJRmxDxEjr<{?t+ zxA@J#%PtJV7 za3K>2e)eBJHn^ui)T=!SA$mU?VZ%TuH$$Go?Jp!ASQy-`%mbW_ z%Og#LJPUTh4ru`ADt-K9`nI!9N0RutXb-kSzeD^eAMfiw{IMzbo}^T|4&q2*Y_!Xu znP>)9KvjI=L%h;*ysk*2gawv3Bhdt`Wv`CyCp}MUmBDwwE6sa#4=x$$mf1(_1NQ;d zx##X*X?D$Wlv7kgV--lC7O$=Yg0yi{$M|k3Va%xP{RK4fcwt2)}vqVDuiw z+>!4XDJ;%H@h+0$x`-}tPedhd#Wx2XvmUkIeMSkd=PjTleb4=r;-sEUGN)KyoDz{z zD^MT=kOQdRC%=yUxMnD;$*O%znlti_{3TflEBFFvlGI@54d>G#@9mP@-zwIw`95Bg pu2bI$1K7E!GXN*rlCQt~%D?M6Wo6PFPN-HJ#4W@Ys2EU@_8+5+UM>It literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_stdint.h b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_stdint.h new file mode 100644 index 00000000..2433aa81 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_stdint.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2004, 2005 by + * Ralf Corsepius, Ulm/Germany. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#ifndef _SYS__STDINT_H +#define _SYS__STDINT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef ___int8_t_defined +#ifndef _INT8_T_DECLARED +typedef __int8_t int8_t; +#define _INT8_T_DECLARED +#endif +#ifndef _UINT8_T_DECLARED +typedef __uint8_t uint8_t; +#define _UINT8_T_DECLARED +#endif +#define __int8_t_defined 1 +#endif /* ___int8_t_defined */ + +#ifdef ___int16_t_defined +#ifndef _INT16_T_DECLARED +typedef __int16_t int16_t; +#define _INT16_T_DECLARED +#endif +#ifndef _UINT16_T_DECLARED +typedef __uint16_t uint16_t; +#define _UINT16_T_DECLARED +#endif +#define __int16_t_defined 1 +#endif /* ___int16_t_defined */ + +#ifdef ___int32_t_defined +#ifndef _INT32_T_DECLARED +typedef __int32_t int32_t; +#define _INT32_T_DECLARED +#endif +#ifndef _UINT32_T_DECLARED +typedef __uint32_t uint32_t; +#define _UINT32_T_DECLARED +#endif +#define __int32_t_defined 1 +#endif /* ___int32_t_defined */ + +#ifdef ___int64_t_defined +#ifndef _INT64_T_DECLARED +typedef __int64_t int64_t; +#define _INT64_T_DECLARED +#endif +#ifndef _UINT64_T_DECLARED +typedef __uint64_t uint64_t; +#define _UINT64_T_DECLARED +#endif +#define __int64_t_defined 1 +#endif /* ___int64_t_defined */ + +#ifndef _INTMAX_T_DECLARED +typedef __intmax_t intmax_t; +#define _INTMAX_T_DECLARED +#endif + +#ifndef _UINTMAX_T_DECLARED +typedef __uintmax_t uintmax_t; +#define _UINTMAX_T_DECLARED +#endif + +#ifndef _INTPTR_T_DECLARED +typedef __intptr_t intptr_t; +#define _INTPTR_T_DECLARED +#endif + +#ifndef _UINTPTR_T_DECLARED +typedef __uintptr_t uintptr_t; +#define _UINTPTR_T_DECLARED +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _SYS__STDINT_H */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_stdint.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@_stdint.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..fffbb4ac601e273b9d9ed8eddfafcdee57b01974 GIT binary patch literal 3840 zcmb7GeQXnT82(*Ba5jH1b&DJ!N_IhlLZmb*105_6N91Ix{a(3-)Eo<+_UAr-m zpa>?Ks3;?XA3;zI#HooA1Tzvr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b}Hs4DR@=cIW4JpTD9k2e8`t4a32l z39ymULbX^8YH?&}YtIi{Y`(I!URkzsnW8MKUkIQ|HT0RD0J3C+G%?L>BavYo9^ct| z=G*ib<`2#e6PK5ONlglN(GITR$dGt{E zj;9x3q!g2eId07g3&aKBIF1Y}(wT8`Rncb>e`DhRF<@RnaLJyK$KIwqXD@`8e2$ni z%Z4LI@_oANd$sSI=g91=RwY^C(OI&BLv#Qu92u)C`P+7jO>-|}g{8x-O0r7H2~)+X zzzIi&gD(Df^U{>Gy+j>;Ft`Memz*A!H#AA~IYlS94v}w@^I*pr=NqSQ6MdE$4cT+7 z&yp2piL*c-j*QovTFHrq?vpCPN_l98@3}QCEESi+p5w^SZfxH0(v4f^&k!_=T}hRg z*zlx~EoOs892wFQY10Sq+SYHvzQdbf^c}S%g;KE;kZ@#3>GvERf1$Cfgg6g=jPCr< zByqk-ECMWuTwizl=FZuJ%`Xytmd+OEEm@&lEC=UtWW4;xrT(i|Z%-t=;O^0R4NVeW M^Tc_;3nJt7FXc$EV*mgE literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@features.h b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@features.h new file mode 100644 index 00000000..64cb7557 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@features.h @@ -0,0 +1,542 @@ +/* + * Written by Joel Sherrill . + * + * COPYRIGHT (c) 1989-2014. + * + * On-Line Applications Research Corporation (OAR). + * + * Permission to use, copy, modify, and distribute this software for any + * purpose without fee is hereby granted, provided that this entire notice + * is included in all copies of any software which is or includes a copy + * or modification of this software. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION + * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS + * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. + * + * $Id$ + */ + +#ifndef _SYS_FEATURES_H +#define _SYS_FEATURES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <_newlib_version.h> + +/* Macro to test version of GCC. Returns 0 for non-GCC or too old GCC. */ +#ifndef __GNUC_PREREQ +#if defined __GNUC__ && defined __GNUC_MINOR__ +#define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +#else +#define __GNUC_PREREQ(maj, min) 0 +#endif +#endif /* __GNUC_PREREQ */ +/* Version with trailing underscores for BSD compatibility. */ +#define __GNUC_PREREQ__(ma, mi) __GNUC_PREREQ(ma, mi) + +/* + * Feature test macros control which symbols are exposed by the system + * headers. Any of these must be defined before including any headers. + * + * __STRICT_ANSI__ (defined by gcc -ansi, -std=c90, -std=c99, or -std=c11) + * ISO C + * + * _POSIX_SOURCE (deprecated by _POSIX_C_SOURCE=1) + * _POSIX_C_SOURCE >= 1 + * POSIX.1-1990 + * + * _POSIX_C_SOURCE >= 2 + * POSIX.2-1992 + * + * _POSIX_C_SOURCE >= 199309L + * POSIX.1b-1993 Real-time extensions + * + * _POSIX_C_SOURCE >= 199506L + * POSIX.1c-1995 Threads extensions + * + * _POSIX_C_SOURCE >= 200112L + * POSIX.1-2001 and C99 + * + * _POSIX_C_SOURCE >= 200809L + * POSIX.1-2008 + * + * _XOPEN_SOURCE + * POSIX.1-1990 and XPG4 + * + * _XOPEN_SOURCE_EXTENDED + * SUSv1 (POSIX.2-1992 plus XPG4v2) + * + * _XOPEN_SOURCE >= 500 + * SUSv2 (POSIX.1c-1995 plus XSI) + * + * _XOPEN_SOURCE >= 600 + * SUSv3 (POSIX.1-2001 plus XSI) and C99 + * + * _XOPEN_SOURCE >= 700 + * SUSv4 (POSIX.1-2008 plus XSI) + * + * _ISOC99_SOURCE or gcc -std=c99 or g++ + * ISO C99 + * + * _ISOC11_SOURCE or gcc -std=c11 or g++ -std=c++11 + * ISO C11 + * + * _ISOC2x_SOURCE or gcc -std=c2x or g++ -std=c++20 + * ISO C11 + * + * _ATFILE_SOURCE (implied by _POSIX_C_SOURCE >= 200809L) + * "at" functions + * + * _LARGEFILE_SOURCE (deprecated by _XOPEN_SOURCE >= 500) + * fseeko, ftello + * + * _GNU_SOURCE + * All of the above plus GNU extensions + * + * _BSD_SOURCE (deprecated by _DEFAULT_SOURCE) + * _SVID_SOURCE (deprecated by _DEFAULT_SOURCE) + * _DEFAULT_SOURCE (or none of the above) + * POSIX-1.2008 with BSD and SVr4 extensions + * + * _FORTIFY_SOURCE = 1 or 2 + * Object Size Checking function wrappers + */ + +#ifdef _GNU_SOURCE +#undef _ATFILE_SOURCE +#define _ATFILE_SOURCE 1 +#undef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE 1 +#undef _ISOC99_SOURCE +#define _ISOC99_SOURCE 1 +#undef _ISOC11_SOURCE +#define _ISOC11_SOURCE 1 +#undef _ISOC2X_SOURCE +#define _ISOC2X_SOURCE 1 +#undef _POSIX_SOURCE +#define _POSIX_SOURCE 1 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#undef _XOPEN_SOURCE +#define _XOPEN_SOURCE 700 +#undef _XOPEN_SOURCE_EXTENDED +#define _XOPEN_SOURCE_EXTENDED 1 +#endif /* _GNU_SOURCE */ + +#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) \ + || (!defined(__STRICT_ANSI__) && !defined(_ANSI_SOURCE) && !defined(_ISOC99_SOURCE) && !defined(_POSIX_SOURCE) \ + && !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) +#undef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE 1 +#endif + +#if defined(_DEFAULT_SOURCE) +#undef _POSIX_SOURCE +#define _POSIX_SOURCE 1 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + +#if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) \ + && ((!defined(__STRICT_ANSI__) && !defined(_ANSI_SOURCE)) || (_XOPEN_SOURCE - 0) >= 500) +#define _POSIX_SOURCE 1 +#if !defined(_XOPEN_SOURCE) || (_XOPEN_SOURCE - 0) >= 700 +#define _POSIX_C_SOURCE 200809L +#elif (_XOPEN_SOURCE - 0) >= 600 +#define _POSIX_C_SOURCE 200112L +#elif (_XOPEN_SOURCE - 0) >= 500 +#define _POSIX_C_SOURCE 199506L +#elif (_XOPEN_SOURCE - 0) < 500 +#define _POSIX_C_SOURCE 2 +#endif +#endif + +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809 +#undef _ATFILE_SOURCE +#define _ATFILE_SOURCE 1 +#endif + +/* + * The following private macros are used throughout the headers to control + * which symbols should be exposed. They are for internal use only, as + * indicated by the leading double underscore, and must never be used outside + * of these headers. + * + * __POSIX_VISIBLE + * any version of POSIX.1; enabled by default, or with _POSIX_SOURCE, + * any value of _POSIX_C_SOURCE, or _XOPEN_SOURCE >= 500. + * + * __POSIX_VISIBLE >= 2 + * POSIX.2-1992; enabled by default, with _POSIX_C_SOURCE >= 2, + * or _XOPEN_SOURCE >= 500. + * + * __POSIX_VISIBLE >= 199309 + * POSIX.1b-1993; enabled by default, with _POSIX_C_SOURCE >= 199309L, + * or _XOPEN_SOURCE >= 500. + * + * __POSIX_VISIBLE >= 199506 + * POSIX.1c-1995; enabled by default, with _POSIX_C_SOURCE >= 199506L, + * or _XOPEN_SOURCE >= 500. + * + * __POSIX_VISIBLE >= 200112 + * POSIX.1-2001; enabled by default, with _POSIX_C_SOURCE >= 200112L, + * or _XOPEN_SOURCE >= 600. + * + * __POSIX_VISIBLE >= 200809 + * POSIX.1-2008; enabled by default, with _POSIX_C_SOURCE >= 200809L, + * or _XOPEN_SOURCE >= 700. + * + * __XSI_VISIBLE + * XPG4 XSI extensions; enabled with any version of _XOPEN_SOURCE. + * + * __XSI_VISIBLE >= 4 + * SUSv1 XSI extensions; enabled with both _XOPEN_SOURCE and + * _XOPEN_SOURCE_EXTENDED together. + * + * __XSI_VISIBLE >= 500 + * SUSv2 XSI extensions; enabled with _XOPEN_SOURCE >= 500. + * + * __XSI_VISIBLE >= 600 + * SUSv3 XSI extensions; enabled with _XOPEN_SOURCE >= 600. + * + * __XSI_VISIBLE >= 700 + * SUSv4 XSI extensions; enabled with _XOPEN_SOURCE >= 700. + * + * __ISO_C_VISIBLE >= 1999 + * ISO C99; enabled with gcc -std=c99 or newer (on by default since GCC 5), + * any version of C++, or with _ISOC99_SOURCE, _POSIX_C_SOURCE >= 200112L, + * or _XOPEN_SOURCE >= 600. + * + * __ISO_C_VISIBLE >= 2011 + * ISO C11; enabled with gcc -std=c11 or newer (on by default since GCC 5), + * g++ -std=c++11 or newer (on by default since GCC 6), or with + * _ISOC11_SOURCE. + * + * __ISO_C_VISIBLE >= 2020 + * ISO C2x; enabled with gcc -std=c2x or newer, + * g++ -std=c++20 or newer, or with + * _ISOC2X_SOURCE. + * + * __ATFILE_VISIBLE + * "at" functions; enabled by default, with _ATFILE_SOURCE, + * _POSIX_C_SOURCE >= 200809L, or _XOPEN_SOURCE >= 700. + * + * __LARGEFILE_VISIBLE + * fseeko, ftello; enabled with _LARGEFILE_SOURCE or _XOPEN_SOURCE >= 500. + * + * __BSD_VISIBLE + * BSD extensions; enabled by default, or with _BSD_SOURCE. + * + * __SVID_VISIBLE + * SVr4 extensions; enabled by default, or with _SVID_SOURCE. + * + * __MISC_VISIBLE + * Extensions found in both BSD and SVr4 (shorthand for + * (__BSD_VISIBLE || __SVID_VISIBLE)), or newlib-specific + * extensions; enabled by default. + * + * __GNU_VISIBLE + * GNU extensions; enabled with _GNU_SOURCE. + * + * __SSP_FORTIFY_LEVEL + * Object Size Checking; defined to 0 (off), 1, or 2. + * + * In all cases above, "enabled by default" means either by defining + * _DEFAULT_SOURCE, or by not defining any of the public feature test macros. + */ + +#ifdef _ATFILE_SOURCE +#define __ATFILE_VISIBLE 1 +#else +#define __ATFILE_VISIBLE 0 +#endif + +#ifdef _DEFAULT_SOURCE +#define __BSD_VISIBLE 1 +#else +#define __BSD_VISIBLE 0 +#endif + +#ifdef _GNU_SOURCE +#define __GNU_VISIBLE 1 +#else +#define __GNU_VISIBLE 0 +#endif + +#if defined(_ISOC2X_SOURCE) || (__STDC_VERSION__ - 0) > 201710L || (__cplusplus - 0) >= 202002L +#define __ISO_C_VISIBLE 2020 +#elif defined(_ISOC11_SOURCE) || (__STDC_VERSION__ - 0) >= 201112L || (__cplusplus - 0) >= 201103L +#define __ISO_C_VISIBLE 2011 +#elif defined(_ISOC99_SOURCE) || (_POSIX_C_SOURCE - 0) >= 200112L || (__STDC_VERSION__ - 0) >= 199901L \ + || defined(__cplusplus) +#define __ISO_C_VISIBLE 1999 +#else +#define __ISO_C_VISIBLE 1990 +#endif + +#if defined(_LARGEFILE_SOURCE) || (_XOPEN_SOURCE - 0) >= 500 +#define __LARGEFILE_VISIBLE 1 +#else +#define __LARGEFILE_VISIBLE 0 +#endif + +#ifdef _DEFAULT_SOURCE +#define __MISC_VISIBLE 1 +#else +#define __MISC_VISIBLE 0 +#endif + +#if (_POSIX_C_SOURCE - 0) >= 200809L +#define __POSIX_VISIBLE 200809 +#elif (_POSIX_C_SOURCE - 0) >= 200112L +#define __POSIX_VISIBLE 200112 +#elif (_POSIX_C_SOURCE - 0) >= 199506L +#define __POSIX_VISIBLE 199506 +#elif (_POSIX_C_SOURCE - 0) >= 199309L +#define __POSIX_VISIBLE 199309 +#elif (_POSIX_C_SOURCE - 0) >= 2 || defined(_XOPEN_SOURCE) +#define __POSIX_VISIBLE 199209 +#elif defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) +#define __POSIX_VISIBLE 199009 +#else +#define __POSIX_VISIBLE 0 +#endif + +#ifdef _DEFAULT_SOURCE +#define __SVID_VISIBLE 1 +#else +#define __SVID_VISIBLE 0 +#endif + +#if (_XOPEN_SOURCE - 0) >= 700 +#define __XSI_VISIBLE 700 +#elif (_XOPEN_SOURCE - 0) >= 600 +#define __XSI_VISIBLE 600 +#elif (_XOPEN_SOURCE - 0) >= 500 +#define __XSI_VISIBLE 500 +#elif defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED) +#define __XSI_VISIBLE 4 +#elif defined(_XOPEN_SOURCE) +#define __XSI_VISIBLE 1 +#else +#define __XSI_VISIBLE 0 +#endif + +#if _FORTIFY_SOURCE > 0 && !defined(__cplusplus) && !defined(__lint__) && (__OPTIMIZE__ > 0 || defined(__clang__)) \ + && __GNUC_PREREQ__(4, 1) && !defined(_LIBC) +#if _FORTIFY_SOURCE > 1 +#define __SSP_FORTIFY_LEVEL 2 +#else +#define __SSP_FORTIFY_LEVEL 1 +#endif +#else +#define __SSP_FORTIFY_LEVEL 0 +#endif + +/* RTEMS adheres to POSIX -- 1003.1b with some features from annexes. */ + +#ifdef __rtems__ +#define _POSIX_JOB_CONTROL 1 +#define _POSIX_SAVED_IDS 1 +#define _POSIX_VERSION 199309L +#define _POSIX_ASYNCHRONOUS_IO 1 +#define _POSIX_FSYNC 1 +#define _POSIX_MAPPED_FILES 1 +#define _POSIX_MEMLOCK 1 +#define _POSIX_MEMLOCK_RANGE 1 +#define _POSIX_MEMORY_PROTECTION 1 +#define _POSIX_MESSAGE_PASSING 1 +#define _POSIX_MONOTONIC_CLOCK 200112L +#define _POSIX_CLOCK_SELECTION 200112L +#define _POSIX_PRIORITIZED_IO 1 +#define _POSIX_PRIORITY_SCHEDULING 1 +#define _POSIX_REALTIME_SIGNALS 1 +#define _POSIX_SEMAPHORES 1 +#define _POSIX_SHARED_MEMORY_OBJECTS 1 +#define _POSIX_SYNCHRONIZED_IO 1 +#define _POSIX_TIMERS 1 +#define _POSIX_BARRIERS 200112L +#define _POSIX_READER_WRITER_LOCKS 200112L +#define _POSIX_SPIN_LOCKS 200112L + +/* In P1003.1b but defined by drafts at least as early as P1003.1c/D10 */ +#define _POSIX_THREADS 1 +#define _POSIX_THREAD_ATTR_STACKADDR 1 +#define _POSIX_THREAD_ATTR_STACKSIZE 1 +#define _POSIX_THREAD_PRIORITY_SCHEDULING 1 +#define _POSIX_THREAD_PRIO_INHERIT 1 +#define _POSIX_THREAD_PRIO_PROTECT 1 +#define _POSIX_THREAD_PROCESS_SHARED 1 +#define _POSIX_THREAD_SAFE_FUNCTIONS 1 + +/* P1003.4b/D8 defines the constants below this comment. */ +#define _POSIX_SPAWN 1 +#define _POSIX_TIMEOUTS 1 +#define _POSIX_CPUTIME 1 +#define _POSIX_THREAD_CPUTIME 1 +#define _POSIX_SPORADIC_SERVER 1 +#define _POSIX_THREAD_SPORADIC_SERVER 1 +#define _POSIX_DEVICE_CONTROL 1 +#define _POSIX_DEVCTL_DIRECTION 1 +#define _POSIX_INTERRUPT_CONTROL 1 +#define _POSIX_ADVISORY_INFO 1 + +/* UNIX98 added some new pthread mutex attributes */ +#define _UNIX98_THREAD_MUTEX_ATTRIBUTES 1 + +/* POSIX 1003.26-2003 defined device control method */ +#define _POSIX_26_VERSION 200312L + +#endif + +/* XMK loosely adheres to POSIX -- 1003.1 */ +#ifdef __XMK__ +#define _POSIX_THREADS 1 +#define _POSIX_THREAD_PRIORITY_SCHEDULING 1 +#endif + +#ifdef __svr4__ +#define _POSIX_JOB_CONTROL 1 +#define _POSIX_SAVED_IDS 1 +#define _POSIX_VERSION 199009L +#endif + +#ifdef __CYGWIN__ + +#if __POSIX_VISIBLE >= 200809 +#define _POSIX_VERSION 200809L +#define _POSIX2_VERSION 200809L +#elif __POSIX_VISIBLE >= 200112 +#define _POSIX_VERSION 200112L +#define _POSIX2_VERSION 200112L +#elif __POSIX_VISIBLE >= 199506 +#define _POSIX_VERSION 199506L +#define _POSIX2_VERSION 199506L +#elif __POSIX_VISIBLE >= 199309 +#define _POSIX_VERSION 199309L +#define _POSIX2_VERSION 199209L +#elif __POSIX_VISIBLE >= 199209 +#define _POSIX_VERSION 199009L +#define _POSIX2_VERSION 199209L +#elif __POSIX_VISIBLE +#define _POSIX_VERSION 199009L +#endif +#if __XSI_VISIBLE >= 4 +#define _XOPEN_VERSION __XSI_VISIBLE +#endif + +#define _POSIX_ADVISORY_INFO 200809L +#define _POSIX_ASYNCHRONOUS_IO 200809L +#define _POSIX_BARRIERS 200809L +#define _POSIX_CHOWN_RESTRICTED 1 +#define _POSIX_CLOCK_SELECTION 200809L +#define _POSIX_CPUTIME 200809L +#define _POSIX_FSYNC 200809L +#define _POSIX_IPV6 200809L +#define _POSIX_JOB_CONTROL 1 +#define _POSIX_MAPPED_FILES 200809L +/* #define _POSIX_MEMLOCK -1 */ +#define _POSIX_MEMLOCK_RANGE 200809L +#define _POSIX_MEMORY_PROTECTION 200809L +#define _POSIX_MESSAGE_PASSING 200809L +#define _POSIX_MONOTONIC_CLOCK 200809L +#define _POSIX_NO_TRUNC 1 +/* #define _POSIX_PRIORITIZED_IO -1 */ +#define _POSIX_PRIORITY_SCHEDULING 200809L +#define _POSIX_RAW_SOCKETS 200809L +#define _POSIX_READER_WRITER_LOCKS 200809L +#define _POSIX_REALTIME_SIGNALS 200809L +#define _POSIX_REGEXP 1 +#define _POSIX_SAVED_IDS 1 +#define _POSIX_SEMAPHORES 200809L +#define _POSIX_SHARED_MEMORY_OBJECTS 200809L +#define _POSIX_SHELL 1 +#define _POSIX_SPAWN 200809L +#define _POSIX_SPIN_LOCKS 200809L +/* #define _POSIX_SPORADIC_SERVER -1 */ +#define _POSIX_SYNCHRONIZED_IO 200809L +#define _POSIX_THREAD_ATTR_STACKADDR 200809L +#define _POSIX_THREAD_ATTR_STACKSIZE 200809L +#define _POSIX_THREAD_CPUTIME 200809L +/* #define _POSIX_THREAD_PRIO_INHERIT -1 */ +/* #define _POSIX_THREAD_PRIO_PROTECT -1 */ +#define _POSIX_THREAD_PRIORITY_SCHEDULING 200809L +#define _POSIX_THREAD_PROCESS_SHARED 200809L +#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L +/* #define _POSIX_THREAD_SPORADIC_SERVER -1 */ +#define _POSIX_THREADS 200809L +#define _POSIX_TIMEOUTS 200809L +#define _POSIX_TIMERS 200809L +/* #define _POSIX_TRACE -1 */ +/* #define _POSIX_TRACE_EVENT_FILTER -1 */ +/* #define _POSIX_TRACE_INHERIT -1 */ +/* #define _POSIX_TRACE_LOG -1 */ +/* #define _POSIX_TYPED_MEMORY_OBJECTS -1 */ +#define _POSIX_VDISABLE '\0' + +#if __POSIX_VISIBLE >= 2 +#define _POSIX2_C_VERSION _POSIX2_VERSION +#define _POSIX2_C_BIND _POSIX2_VERSION +#define _POSIX2_C_DEV _POSIX2_VERSION +#define _POSIX2_CHAR_TERM _POSIX2_VERSION +/* #define _POSIX2_FORT_DEV -1 */ +/* #define _POSIX2_FORT_RUN -1 */ +/* #define _POSIX2_LOCALEDEF -1 */ +/* #define _POSIX2_PBS -1 */ +/* #define _POSIX2_PBS_ACCOUNTING -1 */ +/* #define _POSIX2_PBS_CHECKPOINT -1 */ +/* #define _POSIX2_PBS_LOCATE -1 */ +/* #define _POSIX2_PBS_MESSAGE -1 */ +/* #define _POSIX2_PBS_TRACK -1 */ +#define _POSIX2_SW_DEV _POSIX2_VERSION +#define _POSIX2_UPE _POSIX2_VERSION +#endif /* __POSIX_VISIBLE >= 2 */ + +#define _POSIX_V6_ILP32_OFF32 -1 +#ifdef __LP64__ +#define _POSIX_V6_ILP32_OFFBIG -1 +#define _POSIX_V6_LP64_OFF64 1 +#define _POSIX_V6_LPBIG_OFFBIG 1 +#else +#define _POSIX_V6_ILP32_OFFBIG 1 +#define _POSIX_V6_LP64_OFF64 -1 +#define _POSIX_V6_LPBIG_OFFBIG -1 +#endif +#define _POSIX_V7_ILP32_OFF32 _POSIX_V6_ILP32_OFF32 +#define _POSIX_V7_ILP32_OFFBIG _POSIX_V6_ILP32_OFFBIG +#define _POSIX_V7_LP64_OFF64 _POSIX_V6_LP64_OFF64 +#define _POSIX_V7_LPBIG_OFFBIG _POSIX_V6_LPBIG_OFFBIG +#define _XBS5_ILP32_OFF32 _POSIX_V6_ILP32_OFF32 +#define _XBS5_ILP32_OFFBIG _POSIX_V6_ILP32_OFFBIG +#define _XBS5_LP64_OFF64 _POSIX_V6_LP64_OFF64 +#define _XBS5_LPBIG_OFFBIG _POSIX_V6_LPBIG_OFFBIG + +#if __XSI_VISIBLE +#define _XOPEN_CRYPT 1 +#define _XOPEN_ENH_I18N 1 +/* #define _XOPEN_LEGACY -1 */ +/* #define _XOPEN_REALTIME -1 */ +/* #define _XOPEN_REALTIME_THREADS -1 */ +#define _XOPEN_SHM 1 +/* #define _XOPEN_STREAMS -1 */ +/* #define _XOPEN_UNIX -1 */ +#endif /* __XSI_VISIBLE */ + +/* + * newlib's wide char conversion functions were updated on + * 2019-01-12 + * to UNICODE version: + * 11.0.0 released 2018-06-05 + */ +#define __STDC_ISO_10646__ 201806L + +#endif /* __CYGWIN__ */ + +#ifdef __cplusplus +} +#endif +#endif /* _SYS_FEATURES_H */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@features.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@opt@riscv@riscv64-unknown-elf@include@sys@features.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..9c85fa0f856c9fd4b0b2ae1db12375a8eb36a032 GIT binary patch literal 2690 zcma)6U2GIp6u!4;aiNq|+Y+#8X05c_pV`?h>!v_kw?A7LDBZf-mO=a5DB3dc9J;#7)P5uHgWT)I=44h4lwf+I%- zPF1wkq|hm5LqSlvjGW@d&J3SQNVABJwjp{P(Zeep=VVz_jYOa0GgCe>g=jMn(ihT* zmXVyCFgNMd_~g=xre|bjQjo^!l%VijPF7|+S7wk^0tQp6!oWHsiqjc75Y%-}Oi1HQAn5b^LKYqjV3&jr z&<p^b7>++9+tbwr!MlGz@ zfuvx)0i+lHw}Na3*#WW(WEkWgun&S91$hYM>#+U?$OVvZfqWa}d61qmU%tK!<+qkq zAXL5l#Ru14{54Q_g^+lBi1bHe!)*TnG7uS!3?PIW>H!1*gIdK*`4PhT{kRIojxtN@ zLdzHqF0*%!J(J_+DnT!N*i-JQ3FGCjK0bEt=!q|v3Iv*c1|qO$i=BxctF!$TnOv?mzrWqTUGv%kUR$sa zyc(K?)=w=@{5F?;?`IM}5GVbS?%|PGBu;ii&9>JEO}N@!4W6{w%x%N(72UqeL)!@1 zH8|2shGLOecgV$)NS5`y`|ZbI^3u z^XZ)*277OwG1)A*v0KgH(l8iKPPl5$3R7V%cJN@o*UDo8eh# z#$Mng{Ne7##rH4yi@Jo6BJ7+EL)PM;ZEkGyHOpavGaGHwos+bS?u&4l zVYX1dxvjP~Hn-;nAw6;DvtTptG?. */ + +/* We need to know the word size in order to check the time size. */ +#include +#include + +#if defined _TIME_BITS +#if _TIME_BITS == 64 +#if !defined(_FILE_OFFSET_BITS) || _FILE_OFFSET_BITS != 64 +#error "_TIME_BITS=64 is allowed only with _FILE_OFFSET_BITS=64" +#elif __TIMESIZE == 32 +#define __USE_TIME_BITS64 1 +#endif +#elif _TIME_BITS == 32 +#if __TIMESIZE > 32 +#error "_TIME_BITS=32 is not compatible with __TIMESIZE > 32" +#endif +#else +#error Invalid _TIME_BITS value (can only be 32 or 64-bit) +#endif +#endif diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@features-time64.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@features-time64.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..7519e212d4a4afceaa9a2c77e7566b5628dcf26f GIT binary patch literal 971 zcmbVLOHRWu5H+wxV#f&(LI`K5h$0qnmdLT)#Kf^He@aVttT_dDVF}_y6^=!rB`%_@ zV&!Gt&y#bsym(r?B7~sP9fyXr!1xsGRSOfN?>Kcfyy&#D&Jd>!grkU0B2-4v0hL76 z|DDG7+O$H|mlF$|A>7C_lrs@?hr{XfW_C(mP){ z2o;8`X>34MiO{?g9k=3ve|g@dV-!ye{|p>6t>bCRP$R_+CyX0x9WibTcW*TbrD@%K z!YxQmiR5LPb1)bibH3W85vlua(Y})DQnriWBHuYrS?-o7URu~`wti{*r@t@F&!MwF Pe7?3Ad&lVHF#NzD;Js*W literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@features.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@features.h new file mode 100644 index 00000000..39a108a5 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@features.h @@ -0,0 +1,494 @@ +/* Copyright (C) 1991-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _FEATURES_H +#define _FEATURES_H 1 + +/* These are defined by the user (or the compiler) + to specify the desired environment: + + __STRICT_ANSI__ ISO Standard C. + _ISOC99_SOURCE Extensions to ISO C89 from ISO C99. + _ISOC11_SOURCE Extensions to ISO C99 from ISO C11. + _ISOC2X_SOURCE Extensions to ISO C99 from ISO C2X. + __STDC_WANT_LIB_EXT2__ + Extensions to ISO C99 from TR 27431-2:2010. + __STDC_WANT_IEC_60559_BFP_EXT__ + Extensions to ISO C11 from TS 18661-1:2014. + __STDC_WANT_IEC_60559_FUNCS_EXT__ + Extensions to ISO C11 from TS 18661-4:2015. + __STDC_WANT_IEC_60559_TYPES_EXT__ + Extensions to ISO C11 from TS 18661-3:2015. + __STDC_WANT_IEC_60559_EXT__ + ISO C2X interfaces defined only in Annex F. + + _POSIX_SOURCE IEEE Std 1003.1. + _POSIX_C_SOURCE If ==1, like _POSIX_SOURCE; if >=2 add IEEE Std 1003.2; + if >=199309L, add IEEE Std 1003.1b-1993; + if >=199506L, add IEEE Std 1003.1c-1995; + if >=200112L, all of IEEE 1003.1-2004 + if >=200809L, all of IEEE 1003.1-2008 + _XOPEN_SOURCE Includes POSIX and XPG things. Set to 500 if + Single Unix conformance is wanted, to 600 for the + sixth revision, to 700 for the seventh revision. + _XOPEN_SOURCE_EXTENDED XPG things and X/Open Unix extensions. + _LARGEFILE_SOURCE Some more functions for correct standard I/O. + _LARGEFILE64_SOURCE Additional functionality from LFS for large files. + _FILE_OFFSET_BITS=N Select default filesystem interface. + _ATFILE_SOURCE Additional *at interfaces. + _DYNAMIC_STACK_SIZE_SOURCE Select correct (but non compile-time constant) + MINSIGSTKSZ, SIGSTKSZ and PTHREAD_STACK_MIN. + _GNU_SOURCE All of the above, plus GNU extensions. + _DEFAULT_SOURCE The default set of features (taking precedence over + __STRICT_ANSI__). + + _FORTIFY_SOURCE Add security hardening to many library functions. + Set to 1 or 2; 2 performs stricter checks than 1. + + _REENTRANT, _THREAD_SAFE + Obsolete; equivalent to _POSIX_C_SOURCE=199506L. + + The `-ansi' switch to the GNU C compiler, and standards conformance + options such as `-std=c99', define __STRICT_ANSI__. If none of + these are defined, or if _DEFAULT_SOURCE is defined, the default is + to have _POSIX_SOURCE set to one and _POSIX_C_SOURCE set to + 200809L, as well as enabling miscellaneous functions from BSD and + SVID. If more than one of these are defined, they accumulate. For + example __STRICT_ANSI__, _POSIX_SOURCE and _POSIX_C_SOURCE together + give you ISO C, 1003.1, and 1003.2, but nothing else. + + These are defined by this file and are used by the + header files to decide what to declare or define: + + __GLIBC_USE (F) Define things from feature set F. This is defined + to 1 or 0; the subsequent macros are either defined + or undefined, and those tests should be moved to + __GLIBC_USE. + __USE_ISOC11 Define ISO C11 things. + __USE_ISOC99 Define ISO C99 things. + __USE_ISOC95 Define ISO C90 AMD1 (C95) things. + __USE_ISOCXX11 Define ISO C++11 things. + __USE_POSIX Define IEEE Std 1003.1 things. + __USE_POSIX2 Define IEEE Std 1003.2 things. + __USE_POSIX199309 Define IEEE Std 1003.1, and .1b things. + __USE_POSIX199506 Define IEEE Std 1003.1, .1b, .1c and .1i things. + __USE_XOPEN Define XPG things. + __USE_XOPEN_EXTENDED Define X/Open Unix things. + __USE_UNIX98 Define Single Unix V2 things. + __USE_XOPEN2K Define XPG6 things. + __USE_XOPEN2KXSI Define XPG6 XSI things. + __USE_XOPEN2K8 Define XPG7 things. + __USE_XOPEN2K8XSI Define XPG7 XSI things. + __USE_LARGEFILE Define correct standard I/O things. + __USE_LARGEFILE64 Define LFS things with separate names. + __USE_FILE_OFFSET64 Define 64bit interface as default. + __USE_MISC Define things from 4.3BSD or System V Unix. + __USE_ATFILE Define *at interfaces and AT_* constants for them. + __USE_DYNAMIC_STACK_SIZE Define correct (but non compile-time constant) + MINSIGSTKSZ, SIGSTKSZ and PTHREAD_STACK_MIN. + __USE_GNU Define GNU extensions. + __USE_FORTIFY_LEVEL Additional security measures used, according to level. + + The macros `__GNU_LIBRARY__', `__GLIBC__', and `__GLIBC_MINOR__' are + defined by this file unconditionally. `__GNU_LIBRARY__' is provided + only for compatibility. All new code should use the other symbols + to test for features. + + All macros listed above as possibly being defined by this file are + explicitly undefined if they are not explicitly defined. + Feature-test macros that are not defined by the user or compiler + but are implied by the other feature-test macros defined (or by the + lack of any definitions) are defined by the file. + + ISO C feature test macros depend on the definition of the macro + when an affected header is included, not when the first system + header is included, and so they are handled in + , which does not have a multiple include + guard. Feature test macros that can be handled from the first + system header included are handled here. */ + +/* Undefine everything, so we get a clean slate. */ +#undef __USE_ISOC11 +#undef __USE_ISOC99 +#undef __USE_ISOC95 +#undef __USE_ISOCXX11 +#undef __USE_POSIX +#undef __USE_POSIX2 +#undef __USE_POSIX199309 +#undef __USE_POSIX199506 +#undef __USE_XOPEN +#undef __USE_XOPEN_EXTENDED +#undef __USE_UNIX98 +#undef __USE_XOPEN2K +#undef __USE_XOPEN2KXSI +#undef __USE_XOPEN2K8 +#undef __USE_XOPEN2K8XSI +#undef __USE_LARGEFILE +#undef __USE_LARGEFILE64 +#undef __USE_FILE_OFFSET64 +#undef __USE_MISC +#undef __USE_ATFILE +#undef __USE_DYNAMIC_STACK_SIZE +#undef __USE_GNU +#undef __USE_FORTIFY_LEVEL +#undef __KERNEL_STRICT_NAMES +#undef __GLIBC_USE_ISOC2X +#undef __GLIBC_USE_DEPRECATED_GETS +#undef __GLIBC_USE_DEPRECATED_SCANF + +/* Suppress kernel-name space pollution unless user expressedly asks + for it. */ +#ifndef _LOOSE_KERNEL_NAMES +#define __KERNEL_STRICT_NAMES +#endif + +/* Convenience macro to test the version of gcc. + Use like this: + #if __GNUC_PREREQ (2,8) + ... code requiring gcc 2.8 or later ... + #endif + Note: only works for GCC 2.0 and later, because __GNUC_MINOR__ was + added in 2.0. */ +#if defined __GNUC__ && defined __GNUC_MINOR__ +#define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +#else +#define __GNUC_PREREQ(maj, min) 0 +#endif + +/* Similarly for clang. Features added to GCC after version 4.2 may + or may not also be available in clang, and clang's definitions of + __GNUC(_MINOR)__ are fixed at 4 and 2 respectively. Not all such + features can be queried via __has_extension/__has_feature. */ +#if defined __clang_major__ && defined __clang_minor__ +#define __glibc_clang_prereq(maj, min) ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min)) +#else +#define __glibc_clang_prereq(maj, min) 0 +#endif + +/* Whether to use feature set F. */ +#define __GLIBC_USE(F) __GLIBC_USE_##F + +/* _BSD_SOURCE and _SVID_SOURCE are deprecated aliases for + _DEFAULT_SOURCE. If _DEFAULT_SOURCE is present we do not + issue a warning; the expectation is that the source is being + transitioned to use the new macro. */ +#if (defined _BSD_SOURCE || defined _SVID_SOURCE) && !defined _DEFAULT_SOURCE +#warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" +#undef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE 1 +#endif + +/* If _GNU_SOURCE was defined by the user, turn on all the other features. */ +#ifdef _GNU_SOURCE +#undef _ISOC95_SOURCE +#define _ISOC95_SOURCE 1 +#undef _ISOC99_SOURCE +#define _ISOC99_SOURCE 1 +#undef _ISOC11_SOURCE +#define _ISOC11_SOURCE 1 +#undef _ISOC2X_SOURCE +#define _ISOC2X_SOURCE 1 +#undef _POSIX_SOURCE +#define _POSIX_SOURCE 1 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#undef _XOPEN_SOURCE +#define _XOPEN_SOURCE 700 +#undef _XOPEN_SOURCE_EXTENDED +#define _XOPEN_SOURCE_EXTENDED 1 +#undef _LARGEFILE64_SOURCE +#define _LARGEFILE64_SOURCE 1 +#undef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE 1 +#undef _ATFILE_SOURCE +#define _ATFILE_SOURCE 1 +#undef _DYNAMIC_STACK_SIZE_SOURCE +#define _DYNAMIC_STACK_SIZE_SOURCE 1 +#endif + +/* If nothing (other than _GNU_SOURCE and _DEFAULT_SOURCE) is defined, + define _DEFAULT_SOURCE. */ +#if (defined _DEFAULT_SOURCE \ + || (!defined __STRICT_ANSI__ && !defined _ISOC99_SOURCE && !defined _ISOC11_SOURCE && !defined _ISOC2X_SOURCE \ + && !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE && !defined _XOPEN_SOURCE)) +#undef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE 1 +#endif + +/* This is to enable the ISO C2X extension. */ +#if (defined _ISOC2X_SOURCE || (defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L)) +#define __GLIBC_USE_ISOC2X 1 +#else +#define __GLIBC_USE_ISOC2X 0 +#endif + +/* This is to enable the ISO C11 extension. */ +#if (defined _ISOC11_SOURCE || defined _ISOC2X_SOURCE || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L)) +#define __USE_ISOC11 1 +#endif + +/* This is to enable the ISO C99 extension. */ +#if (defined _ISOC99_SOURCE || defined _ISOC11_SOURCE || defined _ISOC2X_SOURCE \ + || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)) +#define __USE_ISOC99 1 +#endif + +/* This is to enable the ISO C90 Amendment 1:1995 extension. */ +#if (defined _ISOC99_SOURCE || defined _ISOC11_SOURCE || defined _ISOC2X_SOURCE \ + || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199409L)) +#define __USE_ISOC95 1 +#endif + +#ifdef __cplusplus +/* This is to enable compatibility for ISO C++17. */ +#if __cplusplus >= 201703L +#define __USE_ISOC11 1 +#endif +/* This is to enable compatibility for ISO C++11. + Check the temporary macro for now, too. */ +#if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__ +#define __USE_ISOCXX11 1 +#define __USE_ISOC99 1 +#endif +#endif + +/* If none of the ANSI/POSIX macros are defined, or if _DEFAULT_SOURCE + is defined, use POSIX.1-2008 (or another version depending on + _XOPEN_SOURCE). */ +#ifdef _DEFAULT_SOURCE +#if !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE +#define __USE_POSIX_IMPLICITLY 1 +#endif +#undef _POSIX_SOURCE +#define _POSIX_SOURCE 1 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + +#if ((!defined __STRICT_ANSI__ || (defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 500)) && !defined _POSIX_SOURCE \ + && !defined _POSIX_C_SOURCE) +#define _POSIX_SOURCE 1 +#if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 500 +#define _POSIX_C_SOURCE 2 +#elif defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 600 +#define _POSIX_C_SOURCE 199506L +#elif defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 700 +#define _POSIX_C_SOURCE 200112L +#else +#define _POSIX_C_SOURCE 200809L +#endif +#define __USE_POSIX_IMPLICITLY 1 +#endif + +/* Some C libraries once required _REENTRANT and/or _THREAD_SAFE to be + defined in all multithreaded code. GNU libc has not required this + for many years. We now treat them as compatibility synonyms for + _POSIX_C_SOURCE=199506L, which is the earliest level of POSIX with + comprehensive support for multithreaded code. Using them never + lowers the selected level of POSIX conformance, only raises it. */ +#if ((!defined _POSIX_C_SOURCE || (_POSIX_C_SOURCE - 0) < 199506L) && (defined _REENTRANT || defined _THREAD_SAFE)) +#define _POSIX_SOURCE 1 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199506L +#endif + +#if (defined _POSIX_SOURCE || (defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 1) || defined _XOPEN_SOURCE) +#define __USE_POSIX 1 +#endif + +#if defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 2 || defined _XOPEN_SOURCE +#define __USE_POSIX2 1 +#endif + +#if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 199309L +#define __USE_POSIX199309 1 +#endif + +#if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 199506L +#define __USE_POSIX199506 1 +#endif + +#if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 200112L +#define __USE_XOPEN2K 1 +#undef __USE_ISOC95 +#define __USE_ISOC95 1 +#undef __USE_ISOC99 +#define __USE_ISOC99 1 +#endif + +#if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 200809L +#define __USE_XOPEN2K8 1 +#undef _ATFILE_SOURCE +#define _ATFILE_SOURCE 1 +#endif + +#ifdef _XOPEN_SOURCE +#define __USE_XOPEN 1 +#if (_XOPEN_SOURCE - 0) >= 500 +#define __USE_XOPEN_EXTENDED 1 +#define __USE_UNIX98 1 +#undef _LARGEFILE_SOURCE +#define _LARGEFILE_SOURCE 1 +#if (_XOPEN_SOURCE - 0) >= 600 +#if (_XOPEN_SOURCE - 0) >= 700 +#define __USE_XOPEN2K8 1 +#define __USE_XOPEN2K8XSI 1 +#endif +#define __USE_XOPEN2K 1 +#define __USE_XOPEN2KXSI 1 +#undef __USE_ISOC95 +#define __USE_ISOC95 1 +#undef __USE_ISOC99 +#define __USE_ISOC99 1 +#endif +#else +#ifdef _XOPEN_SOURCE_EXTENDED +#define __USE_XOPEN_EXTENDED 1 +#endif +#endif +#endif + +#ifdef _LARGEFILE_SOURCE +#define __USE_LARGEFILE 1 +#endif + +#ifdef _LARGEFILE64_SOURCE +#define __USE_LARGEFILE64 1 +#endif + +#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 +#define __USE_FILE_OFFSET64 1 +#endif + +#include + +#if defined _DEFAULT_SOURCE +#define __USE_MISC 1 +#endif + +#ifdef _ATFILE_SOURCE +#define __USE_ATFILE 1 +#endif + +#ifdef _DYNAMIC_STACK_SIZE_SOURCE +#define __USE_DYNAMIC_STACK_SIZE 1 +#endif + +#ifdef _GNU_SOURCE +#define __USE_GNU 1 +#endif + +#if defined _FORTIFY_SOURCE && _FORTIFY_SOURCE > 0 && defined __OPTIMIZE__ && __OPTIMIZE__ > 0 +#if !__GNUC_PREREQ(4, 1) +#warning _FORTIFY_SOURCE requires GCC 4.1 or later +#elif _FORTIFY_SOURCE > 2 && (__glibc_clang_prereq(9, 0) || __GNUC_PREREQ(12, 0)) + +#if _FORTIFY_SOURCE > 3 +#warning _FORTIFY_SOURCE > 3 is treated like 3 on this platform +#endif +#define __USE_FORTIFY_LEVEL 3 +#elif _FORTIFY_SOURCE > 1 +#if _FORTIFY_SOURCE > 2 +#warning _FORTIFY_SOURCE > 2 is treated like 2 on this platform +#endif +#define __USE_FORTIFY_LEVEL 2 +#else +#define __USE_FORTIFY_LEVEL 1 +#endif +#endif +#ifndef __USE_FORTIFY_LEVEL +#define __USE_FORTIFY_LEVEL 0 +#endif + +/* The function 'gets' existed in C89, but is impossible to use + safely. It has been removed from ISO C11 and ISO C++14. Note: for + compatibility with various implementations of , this test + must consider only the value of __cplusplus when compiling C++. */ +#if defined __cplusplus ? __cplusplus >= 201402L : defined __USE_ISOC11 +#define __GLIBC_USE_DEPRECATED_GETS 0 +#else +#define __GLIBC_USE_DEPRECATED_GETS 1 +#endif + +/* GNU formerly extended the scanf functions with modified format + specifiers %as, %aS, and %a[...] that allocate a buffer for the + input using malloc. This extension conflicts with ISO C99, which + defines %a as a standalone format specifier that reads a floating- + point number; moreover, POSIX.1-2008 provides the same feature + using the modifier letter 'm' instead (%ms, %mS, %m[...]). + + We now follow C99 unless GNU extensions are active and the compiler + is specifically in C89 or C++98 mode (strict or not). For + instance, with GCC, -std=gnu11 will have C99-compliant scanf with + or without -D_GNU_SOURCE, but -std=c89 -D_GNU_SOURCE will have the + old extension. */ +#if (defined __USE_GNU \ + && (defined __cplusplus ? (__cplusplus < 201103L && !defined __GXX_EXPERIMENTAL_CXX0X__) : \ + (!defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L))) +#define __GLIBC_USE_DEPRECATED_SCANF 1 +#else +#define __GLIBC_USE_DEPRECATED_SCANF 0 +#endif + +/* Get definitions of __STDC_* predefined macros, if the compiler has + not preincluded this header automatically. */ +#include + +/* This macro indicates that the installed library is the GNU C Library. + For historic reasons the value now is 6 and this will stay from now + on. The use of this variable is deprecated. Use __GLIBC__ and + __GLIBC_MINOR__ now (see below) when you want to test for a specific + GNU C library version and use the values in to get + the sonames of the shared libraries. */ +#undef __GNU_LIBRARY__ +#define __GNU_LIBRARY__ 6 + +/* Major and minor version number of the GNU C library package. Use + these macros to test for features in specific releases. */ +#define __GLIBC__ 2 +#define __GLIBC_MINOR__ 36 + +#define __GLIBC_PREREQ(maj, min) ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min)) + +/* This is here only because every header file already includes this one. */ +#ifndef __ASSEMBLER__ +#ifndef _SYS_CDEFS_H +#include +#endif + +/* If we don't have __REDIRECT, prototypes will be missing if + __USE_FILE_OFFSET64 but not __USE_LARGEFILE[64]. */ +#if defined __USE_FILE_OFFSET64 && !defined __REDIRECT +#define __USE_LARGEFILE 1 +#define __USE_LARGEFILE64 1 +#endif + +#endif /* !ASSEMBLER */ + +/* Decide whether we can define 'extern inline' functions in headers. */ +#if __GNUC_PREREQ(2, 7) && defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__ \ + && defined __extern_inline +#define __USE_EXTERN_INLINES 1 +#endif + +/* This is here only because every header file already includes this one. + Get the definitions of all the appropriate `__stub_FUNCTION' symbols. + contains `#define __stub_FUNCTION' when FUNCTION is a stub + that will always return failure (and set errno to ENOSYS). */ +#include + +#endif /* features.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@features.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@features.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..1b69789047807d664ffe7866444e95d204fbb9a0 GIT binary patch literal 4001 zcmbVO3v3%z7M+)*q^V2^E`(o1-3B5j#NWCmi9#CJu^XpuVr-{PN$IO&PZPI}9c+iv z7FsB~AP_355Q~s1v8)yv1XOK1>^ci%hr-23jkGxfrF!vmX-2!dc4Obv;a!N__`OuW^SS+L$RoKCG1quC55hEmB) zHXX^P(iW(3CL{5rIVzM!6OrV=pWSWRkV>zQCkITicp9!!>5Vr`T8OfwAiFm&y zk+^lpWOFc`IkwmwW~YA1k13i;u8j}KyN+&a zd7pVx0dH$`Qm4a|h$lyGGYuq1ESZfNOB6mb@^U$M1cDT}pPpYxRPwC*`!zwVImhVCul zr0%Tn%`9ma5u{6rPPzut4%rO32r>e>5ppx+9gtfg?}EG=@~@CPARmH!81fOwM3hiYL?;OICtkbn!vi0Fe%OS5lzYh7%(2=wGGV;@-Whw| zJ@XBvOZ>jYZW;)Bf}R_(thxrJA5V&gLW^-IvaZ1}6i?O}R?Vs~8dWPbw6qv(&N{<& zxed#FUEM)S4XrmAjPka+{1T%KP$vjPI!!7u8cMkKCD|fO5O|;1lDY4@ZD&tpDD4S( zs4vv*Zfe5(<#|^5`3jqi)Jyaj^+4j9RYoF`fN6nEbInYo74W%&7!iG)u1{wzedGx> z3Ki4d3t!jdeevAntrb>y{8s<1vqXM3E1c=_zEiK&^o(oJ08>>2#^|l9(5#|{ni_)_ zkOwOd)|SZcfC72hjAJj}G(M*kIJsxWxz2Oz+Q<)`Kj1A*2%Q+Rb^++^enJn6vrJU_7QK-$huhHGX8X@k=i+q?C5HBf2lxI20{fPB`g0sb2*6J0M#m^r*+T}jH zopR^7NUzKRX$>4}E)eFjE5kKb=(sYqD`GFW@&?>xs%*!dPNi|dH8-E*;&wB`uigB8`hCqMWS@TQ z0VNgo+VXccw04%|xI-bM^`l9W&XyAPR?h08ntL0+y3+TxQnv15SCkj7YO1hX zt&P?uzuZFRA>4TcmsQc)7-~5_gx0%OYZJ%Me(ZPLE;ehfJz~^!VY!Vna{Nr%!KR%U!G>!MN{pulzpmW#)#+`hn>u4q$SvQNeujimPtalBQyr-Xd zR)Yir3$4!S*}=#$1HcS0c3e~0`To0QQ8v1DHXw2j8NFb%3a9nsUp{(t&R)-p++S~Z zz|&=4+K6SE{|`CAs-=RvS_N0Dh#86Cn%eWXtqJZJzJ0KoH42J9nxHGVl2YL1za4U` z$eRp^j7Z0E-HtOnuGy8u&OQ2hV`_1L1RV-lP zokVyi86elxbbb1thpNXnL{6%Ja-#J48sxt{v;wt6q!Yk6LFOanT&q=5B-G#h_rs5U zir%a_C*Wv$v&NvDUl~%MHspnPQP;{1Wbm OpZ%l*q`Btjq<;Yxu?VpM literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@stdc-predef.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@stdc-predef.h new file mode 100644 index 00000000..91dc13f8 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@stdc-predef.h @@ -0,0 +1,64 @@ +/* Copyright (C) 1991-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STDC_PREDEF_H +#define _STDC_PREDEF_H 1 + +/* This header is separate from features.h so that the compiler can + include it implicitly at the start of every compilation. It must + not itself include or any other header that includes + because the implicit include comes before any feature + test macros that may be defined in a source file before it first + explicitly includes a system header. GCC knows the name of this + header in order to preinclude it. */ + +/* glibc's intent is to support the IEC 559 math functionality, real + and complex. If the GCC (4.9 and later) predefined macros + specifying compiler intent are available, use them to determine + whether the overall intent is to support these features; otherwise, + presume an older compiler has intent to support these features and + define these macros by default. */ + +#ifdef __GCC_IEC_559 +#if __GCC_IEC_559 > 0 +#define __STDC_IEC_559__ 1 +#define __STDC_IEC_60559_BFP__ 201404L +#endif +#else +#define __STDC_IEC_559__ 1 +#define __STDC_IEC_60559_BFP__ 201404L +#endif + +#ifdef __GCC_IEC_559_COMPLEX +#if __GCC_IEC_559_COMPLEX > 0 +#define __STDC_IEC_559_COMPLEX__ 1 +#define __STDC_IEC_60559_COMPLEX__ 201404L +#endif +#else +#define __STDC_IEC_559_COMPLEX__ 1 +#define __STDC_IEC_60559_COMPLEX__ 201404L +#endif + +/* wchar_t uses Unicode 10.0.0. Version 10.0 of the Unicode Standard is + synchronized with ISO/IEC 10646:2017, fifth edition, plus + the following additions from Amendment 1 to the fifth edition: + - 56 emoji characters + - 285 hentaigana + - 3 additional Zanabazar Square characters */ +#define __STDC_ISO_10646__ 201706L + +#endif diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@stdc-predef.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@stdc-predef.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..30eae4ed8dd902b5b168a7b2fc423b3912ec7b0a GIT binary patch literal 1398 zcmbW0O=}ZD7{@1D5Ymh7q6a}FP!Bd_Gn-_(R%m)inxIf^XvLRk^?KB4D<<_= zE7u#A<37My82TQxXcJmi-&P7pyo<)LfbwcygVZss&?L|gOp~S*k_! zAoPgOlYHiQqvU}N*J;r#BHUA0s@=zxZx|ok-l^gn2Ya}nYDmMF{fL*>*ae~v$;7kibWtr_Rkd9JQstF0 zl6b6xaf->tPY0iVzU#g`Hcw^%luI}Az?AGoHw7Q61tVtIbxg?h=5|1T&<> zgTdRQ2w77(yHalmZZ3fvsmO5KNJZRsR?coqJT|7bmxi75!G-Te1kTZX6PX08$fbqP zb$PugrC8jYqE>JHu%ExEkO*qxBDw>V09~kx*hMm`ODPubOnZF(^6>RY`?^0lxyF8N cr&h<;nc0hTt~k?KMmUvM. */ + +/* + * ISO C99: 7.18 Integer types + */ + +#ifndef _STDINT_H +#define _STDINT_H 1 + +#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION +#include +#include +#include +#include + +/* Exact integral types. */ + +/* Signed. */ +#include + +/* Unsigned. */ +#include + +/* Small types. */ + +/* Signed. */ +typedef __int_least8_t int_least8_t; +typedef __int_least16_t int_least16_t; +typedef __int_least32_t int_least32_t; +typedef __int_least64_t int_least64_t; + +/* Unsigned. */ +typedef __uint_least8_t uint_least8_t; +typedef __uint_least16_t uint_least16_t; +typedef __uint_least32_t uint_least32_t; +typedef __uint_least64_t uint_least64_t; + +/* Fast types. */ + +/* Signed. */ +typedef signed char int_fast8_t; +#if __WORDSIZE == 64 +typedef long int int_fast16_t; +typedef long int int_fast32_t; +typedef long int int_fast64_t; +#else +typedef int int_fast16_t; +typedef int int_fast32_t; +__extension__ typedef long long int int_fast64_t; +#endif + +/* Unsigned. */ +typedef unsigned char uint_fast8_t; +#if __WORDSIZE == 64 +typedef unsigned long int uint_fast16_t; +typedef unsigned long int uint_fast32_t; +typedef unsigned long int uint_fast64_t; +#else +typedef unsigned int uint_fast16_t; +typedef unsigned int uint_fast32_t; +__extension__ typedef unsigned long long int uint_fast64_t; +#endif + +/* Types for `void *' pointers. */ +#if __WORDSIZE == 64 +#ifndef __intptr_t_defined +typedef long int intptr_t; +#define __intptr_t_defined +#endif +typedef unsigned long int uintptr_t; +#else +#ifndef __intptr_t_defined +typedef int intptr_t; +#define __intptr_t_defined +#endif +typedef unsigned int uintptr_t; +#endif + +/* Largest integral types. */ +typedef __intmax_t intmax_t; +typedef __uintmax_t uintmax_t; + +#if __WORDSIZE == 64 +#define __INT64_C(c) c##L +#define __UINT64_C(c) c##UL +#else +#define __INT64_C(c) c##LL +#define __UINT64_C(c) c##ULL +#endif + +/* Limits of integral types. */ + +/* Minimum of signed integral types. */ +#define INT8_MIN (-128) +#define INT16_MIN (-32767 - 1) +#define INT32_MIN (-2147483647 - 1) +#define INT64_MIN (-__INT64_C(9223372036854775807) - 1) +/* Maximum of signed integral types. */ +#define INT8_MAX (127) +#define INT16_MAX (32767) +#define INT32_MAX (2147483647) +#define INT64_MAX (__INT64_C(9223372036854775807)) + +/* Maximum of unsigned integral types. */ +#define UINT8_MAX (255) +#define UINT16_MAX (65535) +#define UINT32_MAX (4294967295U) +#define UINT64_MAX (__UINT64_C(18446744073709551615)) + +/* Minimum of signed integral types having a minimum size. */ +#define INT_LEAST8_MIN (-128) +#define INT_LEAST16_MIN (-32767 - 1) +#define INT_LEAST32_MIN (-2147483647 - 1) +#define INT_LEAST64_MIN (-__INT64_C(9223372036854775807) - 1) +/* Maximum of signed integral types having a minimum size. */ +#define INT_LEAST8_MAX (127) +#define INT_LEAST16_MAX (32767) +#define INT_LEAST32_MAX (2147483647) +#define INT_LEAST64_MAX (__INT64_C(9223372036854775807)) + +/* Maximum of unsigned integral types having a minimum size. */ +#define UINT_LEAST8_MAX (255) +#define UINT_LEAST16_MAX (65535) +#define UINT_LEAST32_MAX (4294967295U) +#define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615)) + +/* Minimum of fast signed integral types having a minimum size. */ +#define INT_FAST8_MIN (-128) +#if __WORDSIZE == 64 +#define INT_FAST16_MIN (-9223372036854775807L - 1) +#define INT_FAST32_MIN (-9223372036854775807L - 1) +#else +#define INT_FAST16_MIN (-2147483647 - 1) +#define INT_FAST32_MIN (-2147483647 - 1) +#endif +#define INT_FAST64_MIN (-__INT64_C(9223372036854775807) - 1) +/* Maximum of fast signed integral types having a minimum size. */ +#define INT_FAST8_MAX (127) +#if __WORDSIZE == 64 +#define INT_FAST16_MAX (9223372036854775807L) +#define INT_FAST32_MAX (9223372036854775807L) +#else +#define INT_FAST16_MAX (2147483647) +#define INT_FAST32_MAX (2147483647) +#endif +#define INT_FAST64_MAX (__INT64_C(9223372036854775807)) + +/* Maximum of fast unsigned integral types having a minimum size. */ +#define UINT_FAST8_MAX (255) +#if __WORDSIZE == 64 +#define UINT_FAST16_MAX (18446744073709551615UL) +#define UINT_FAST32_MAX (18446744073709551615UL) +#else +#define UINT_FAST16_MAX (4294967295U) +#define UINT_FAST32_MAX (4294967295U) +#endif +#define UINT_FAST64_MAX (__UINT64_C(18446744073709551615)) + +/* Values to test for integral types holding `void *' pointer. */ +#if __WORDSIZE == 64 +#define INTPTR_MIN (-9223372036854775807L - 1) +#define INTPTR_MAX (9223372036854775807L) +#define UINTPTR_MAX (18446744073709551615UL) +#else +#define INTPTR_MIN (-2147483647 - 1) +#define INTPTR_MAX (2147483647) +#define UINTPTR_MAX (4294967295U) +#endif + +/* Minimum for largest signed integral type. */ +#define INTMAX_MIN (-__INT64_C(9223372036854775807) - 1) +/* Maximum for largest signed integral type. */ +#define INTMAX_MAX (__INT64_C(9223372036854775807)) + +/* Maximum for largest unsigned integral type. */ +#define UINTMAX_MAX (__UINT64_C(18446744073709551615)) + +/* Limits of other integer types. */ + +/* Limits of `ptrdiff_t' type. */ +#if __WORDSIZE == 64 +#define PTRDIFF_MIN (-9223372036854775807L - 1) +#define PTRDIFF_MAX (9223372036854775807L) +#else +#if __WORDSIZE32_PTRDIFF_LONG +#define PTRDIFF_MIN (-2147483647L - 1) +#define PTRDIFF_MAX (2147483647L) +#else +#define PTRDIFF_MIN (-2147483647 - 1) +#define PTRDIFF_MAX (2147483647) +#endif +#endif + +/* Limits of `sig_atomic_t'. */ +#define SIG_ATOMIC_MIN (-2147483647 - 1) +#define SIG_ATOMIC_MAX (2147483647) + +/* Limit of `size_t' type. */ +#if __WORDSIZE == 64 +#define SIZE_MAX (18446744073709551615UL) +#else +#if __WORDSIZE32_SIZE_ULONG +#define SIZE_MAX (4294967295UL) +#else +#define SIZE_MAX (4294967295U) +#endif +#endif + +/* Limits of `wchar_t'. */ +#ifndef WCHAR_MIN +/* These constants might also be defined in . */ +#define WCHAR_MIN __WCHAR_MIN +#define WCHAR_MAX __WCHAR_MAX +#endif + +/* Limits of `wint_t'. */ +#define WINT_MIN (0u) +#define WINT_MAX (4294967295u) + +/* Signed. */ +#define INT8_C(c) c +#define INT16_C(c) c +#define INT32_C(c) c +#if __WORDSIZE == 64 +#define INT64_C(c) c##L +#else +#define INT64_C(c) c##LL +#endif + +/* Unsigned. */ +#define UINT8_C(c) c +#define UINT16_C(c) c +#define UINT32_C(c) c##U +#if __WORDSIZE == 64 +#define UINT64_C(c) c##UL +#else +#define UINT64_C(c) c##ULL +#endif + +/* Maximal type. */ +#if __WORDSIZE == 64 +#define INTMAX_C(c) c##L +#define UINTMAX_C(c) c##UL +#else +#define INTMAX_C(c) c##LL +#define UINTMAX_C(c) c##ULL +#endif + +#if __GLIBC_USE(IEC_60559_BFP_EXT_C2X) + +#define INT8_WIDTH 8 +#define UINT8_WIDTH 8 +#define INT16_WIDTH 16 +#define UINT16_WIDTH 16 +#define INT32_WIDTH 32 +#define UINT32_WIDTH 32 +#define INT64_WIDTH 64 +#define UINT64_WIDTH 64 + +#define INT_LEAST8_WIDTH 8 +#define UINT_LEAST8_WIDTH 8 +#define INT_LEAST16_WIDTH 16 +#define UINT_LEAST16_WIDTH 16 +#define INT_LEAST32_WIDTH 32 +#define UINT_LEAST32_WIDTH 32 +#define INT_LEAST64_WIDTH 64 +#define UINT_LEAST64_WIDTH 64 + +#define INT_FAST8_WIDTH 8 +#define UINT_FAST8_WIDTH 8 +#define INT_FAST16_WIDTH __WORDSIZE +#define UINT_FAST16_WIDTH __WORDSIZE +#define INT_FAST32_WIDTH __WORDSIZE +#define UINT_FAST32_WIDTH __WORDSIZE +#define INT_FAST64_WIDTH 64 +#define UINT_FAST64_WIDTH 64 + +#define INTPTR_WIDTH __WORDSIZE +#define UINTPTR_WIDTH __WORDSIZE + +#define INTMAX_WIDTH 64 +#define UINTMAX_WIDTH 64 + +#define PTRDIFF_WIDTH __WORDSIZE +#define SIG_ATOMIC_WIDTH 32 +#define SIZE_WIDTH __WORDSIZE +#define WCHAR_WIDTH 32 +#define WINT_WIDTH 32 + +#endif + +#endif /* stdint.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@stdint.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@stdint.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..bb7d6ebbe950809aec2913a1e3be1dc06ee886e3 GIT binary patch literal 7042 zcmbVQ3s6+o8NL@aWl^_yy|wtLq3R%7*M(&t;AnJ31Pq{2P)nj$*xk6Ru#nw_fM$#_ z4Qez_)J6?Dny7i0@eyBBAC1~1HA&M%#j2^V8MR4`X?1*z&!GLzz2}^LurO(9Tg&=AHh3PBy$)<(uj8PB%C`KD?;PS3j(!7lLf8@%xMw zo^oSFMQx=a-K>6B-)l@a4^A6wHF~^`iW;ZO=npuZuIC54g@@~BSN>I<$A;=Mt%}ub zsPK4e>I~DpHO6ueA`8@4yZq#Nl7v{F_snW#&hxIaK#i}J!B!mbRJyF@*gWvp`;897 z7u{j@azh}T^6{3n%;irvWfFgm&Kvq|3>kUR;V$#V=D(V8ERn|>FyP~T{8=@RIgO;k zkL8N`CV1j7RQp_1F)=CtI&>J^t}>^~XYdEge1S0TSXGKR$h=)2-21HU922Gb12yH* z*F3tWDym3HRn?SNga;mzbBdxBky2S!r<7HArh66D)iw5i#_FmeRza(RKo4++uF(^w zwlktmina>o80N8hx5n@+Q+8%7&jy1S8N=h@MUWT!3|0X8r-bZIPYdHZl?u~3%@n-) z)xui+d%}nMkA+!vCX2l4|%1hmrm6W26WA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+^1Hwg72Os^vEO7G$V0c6*CaaqYrdCL!qjEHBnMG|OQTisGO${XP$koAqlVQ1%u7+1|UcotYJ&s%joJ$f=;C?0z*;4Qdd`_Eb;u zQ_}pcpIo1iUz!uy5||B6wtgtSC|?94kcIBBmg-jQ%(xFfg2x!uMJ|klbt*CTc5 z_+25y+=d>G$;WV00G84fySuD<-%Ep>4fLNH;VZ_CA^-LuPl#9Lt5|p->zMPJmkil( d^3ZmzS*t7&4O~45q^W)TrgRg18#q{V;(yB8C;. */ + +/* + * ISO C99 Standard: 7.21 String handling + */ + +#ifndef _STRING_H +#define _STRING_H 1 + +#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION +#include + +__BEGIN_DECLS + +/* Get size_t and NULL from . */ +#define __need_size_t +#define __need_NULL +#include + +/* Tell the caller that we provide correct C++ prototypes. */ +#if defined __cplusplus && (__GNUC_PREREQ(4, 4) || __glibc_clang_prereq(3, 5)) +#define __CORRECT_ISO_CPP_STRING_H_PROTO +#endif + +/* Copy N bytes of SRC to DEST. */ +extern void *memcpy(void *__restrict __dest, const void *__restrict __src, size_t __n) __THROW __nonnull((1, 2)); +/* Copy N bytes of SRC to DEST, guaranteeing + correct behavior for overlapping strings. */ +extern void *memmove(void *__dest, const void *__src, size_t __n) __THROW __nonnull((1, 2)); + +/* Copy no more than N bytes of SRC to DEST, stopping when C is found. + Return the position in DEST one byte past where C was copied, + or NULL if C was not found in the first N bytes of SRC. */ +#if defined __USE_MISC || defined __USE_XOPEN || __GLIBC_USE(ISOC2X) +extern void *memccpy(void *__restrict __dest, const void *__restrict __src, int __c, size_t __n) __THROW + __nonnull((1, 2)) __attr_access((__write_only__, 1, 4)); +#endif /* Misc || X/Open. */ + +/* Set N bytes of S to C. */ +extern void *memset(void *__s, int __c, size_t __n) __THROW __nonnull((1)); + +/* Compare N bytes of S1 and S2. */ +extern int memcmp(const void *__s1, const void *__s2, size_t __n) __THROW __attribute_pure__ __nonnull((1, 2)); + +/* Compare N bytes of S1 and S2. Return zero if S1 and S2 are equal. + Return some non-zero value otherwise. + + Essentially __memcmpeq has the exact same semantics as memcmp + except the return value is less constrained. memcmp is always a + correct implementation of __memcmpeq. As well !!memcmp, -memcmp, + or bcmp are correct implementations. + + __memcmpeq is meant to be used by compilers when memcmp return is + only used for its boolean value. + + __memcmpeq is declared only for use by compilers. Programs should + continue to use memcmp. */ +extern int __memcmpeq(const void *__s1, const void *__s2, size_t __n) __THROW __attribute_pure__ __nonnull((1, 2)); + +/* Search N bytes of S for C. */ +#ifdef __CORRECT_ISO_CPP_STRING_H_PROTO +extern "C++" { +extern void *memchr(void *__s, int __c, size_t __n) __THROW __asm("memchr") __attribute_pure__ __nonnull((1)); +extern const void *memchr(const void *__s, int __c, size_t __n) __THROW __asm("memchr") __attribute_pure__ + __nonnull((1)); + +#ifdef __OPTIMIZE__ +__extern_always_inline void *memchr(void *__s, int __c, size_t __n) __THROW +{ + return __builtin_memchr(__s, __c, __n); +} + +__extern_always_inline const void *memchr(const void *__s, int __c, size_t __n) __THROW +{ + return __builtin_memchr(__s, __c, __n); +} +#endif +} +#else +extern void *memchr(const void *__s, int __c, size_t __n) __THROW __attribute_pure__ __nonnull((1)); +#endif + +#ifdef __USE_GNU +/* Search in S for C. This is similar to `memchr' but there is no + length limit. */ +#ifdef __CORRECT_ISO_CPP_STRING_H_PROTO +extern "C++" void *rawmemchr(void *__s, int __c) __THROW __asm("rawmemchr") __attribute_pure__ __nonnull((1)); +extern "C++" const void *rawmemchr(const void *__s, int __c) __THROW __asm("rawmemchr") __attribute_pure__ + __nonnull((1)); +#else +extern void *rawmemchr(const void *__s, int __c) __THROW __attribute_pure__ __nonnull((1)); +#endif + +/* Search N bytes of S for the final occurrence of C. */ +#ifdef __CORRECT_ISO_CPP_STRING_H_PROTO +extern "C++" void *memrchr(void *__s, int __c, size_t __n) __THROW __asm("memrchr") __attribute_pure__ __nonnull((1)) + __attr_access((__read_only__, 1, 3)); +extern "C++" const void *memrchr(const void *__s, int __c, size_t __n) __THROW __asm("memrchr") __attribute_pure__ + __nonnull((1)) __attr_access((__read_only__, 1, 3)); +#else +extern void *memrchr(const void *__s, int __c, size_t __n) __THROW __attribute_pure__ __nonnull((1)) + __attr_access((__read_only__, 1, 3)); +#endif +#endif + +/* Copy SRC to DEST. */ +extern char *strcpy(char *__restrict __dest, const char *__restrict __src) __THROW __nonnull((1, 2)); +/* Copy no more than N characters of SRC to DEST. */ +extern char *strncpy(char *__restrict __dest, const char *__restrict __src, size_t __n) __THROW __nonnull((1, 2)); + +/* Append SRC onto DEST. */ +extern char *strcat(char *__restrict __dest, const char *__restrict __src) __THROW __nonnull((1, 2)); +/* Append no more than N characters from SRC onto DEST. */ +extern char *strncat(char *__restrict __dest, const char *__restrict __src, size_t __n) __THROW __nonnull((1, 2)); + +/* Compare S1 and S2. */ +extern int strcmp(const char *__s1, const char *__s2) __THROW __attribute_pure__ __nonnull((1, 2)); +/* Compare N characters of S1 and S2. */ +extern int strncmp(const char *__s1, const char *__s2, size_t __n) __THROW __attribute_pure__ __nonnull((1, 2)); + +/* Compare the collated forms of S1 and S2. */ +extern int strcoll(const char *__s1, const char *__s2) __THROW __attribute_pure__ __nonnull((1, 2)); +/* Put a transformation of SRC into no more than N bytes of DEST. */ +extern size_t strxfrm(char *__restrict __dest, const char *__restrict __src, size_t __n) __THROW __nonnull((2)) + __attr_access((__write_only__, 1, 3)); + +#ifdef __USE_XOPEN2K8 +/* POSIX.1-2008 extended locale interface (see locale.h). */ +#include + +/* Compare the collated forms of S1 and S2, using sorting rules from L. */ +extern int strcoll_l(const char *__s1, const char *__s2, locale_t __l) __THROW __attribute_pure__ __nonnull((1, 2, 3)); +/* Put a transformation of SRC into no more than N bytes of DEST, + using sorting rules from L. */ +extern size_t strxfrm_l(char *__dest, const char *__src, size_t __n, locale_t __l) __THROW __nonnull((2, 4)) + __attr_access((__write_only__, 1, 3)); +#endif + +#if (defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 || __GLIBC_USE(LIB_EXT2) || __GLIBC_USE(ISOC2X)) +/* Duplicate S, returning an identical malloc'd string. */ +extern char *strdup(const char *__s) __THROW __attribute_malloc__ __nonnull((1)); +#endif + +/* Return a malloc'd copy of at most N bytes of STRING. The + resultant string is terminated even if no null terminator + appears before STRING[N]. */ +#if defined __USE_XOPEN2K8 || __GLIBC_USE(LIB_EXT2) || __GLIBC_USE(ISOC2X) +extern char *strndup(const char *__string, size_t __n) __THROW __attribute_malloc__ __nonnull((1)); +#endif + +#if defined __USE_GNU && defined __GNUC__ +/* Duplicate S, returning an identical alloca'd string. */ +#define strdupa(s) \ + (__extension__({ \ + const char *__old = (s); \ + size_t __len = strlen(__old) + 1; \ + char *__new = (char *)__builtin_alloca(__len); \ + (char *)memcpy(__new, __old, __len); \ + })) + +/* Return an alloca'd copy of at most N bytes of string. */ +#define strndupa(s, n) \ + (__extension__({ \ + const char *__old = (s); \ + size_t __len = strnlen(__old, (n)); \ + char *__new = (char *)__builtin_alloca(__len + 1); \ + __new[__len] = '\0'; \ + (char *)memcpy(__new, __old, __len); \ + })) +#endif + +/* Find the first occurrence of C in S. */ +#ifdef __CORRECT_ISO_CPP_STRING_H_PROTO +extern "C++" { +extern char *strchr(char *__s, int __c) __THROW __asm("strchr") __attribute_pure__ __nonnull((1)); +extern const char *strchr(const char *__s, int __c) __THROW __asm("strchr") __attribute_pure__ __nonnull((1)); + +#ifdef __OPTIMIZE__ +__extern_always_inline char *strchr(char *__s, int __c) __THROW +{ + return __builtin_strchr(__s, __c); +} + +__extern_always_inline const char *strchr(const char *__s, int __c) __THROW +{ + return __builtin_strchr(__s, __c); +} +#endif +} +#else +extern char *strchr(const char *__s, int __c) __THROW __attribute_pure__ __nonnull((1)); +#endif +/* Find the last occurrence of C in S. */ +#ifdef __CORRECT_ISO_CPP_STRING_H_PROTO +extern "C++" { +extern char *strrchr(char *__s, int __c) __THROW __asm("strrchr") __attribute_pure__ __nonnull((1)); +extern const char *strrchr(const char *__s, int __c) __THROW __asm("strrchr") __attribute_pure__ __nonnull((1)); + +#ifdef __OPTIMIZE__ +__extern_always_inline char *strrchr(char *__s, int __c) __THROW +{ + return __builtin_strrchr(__s, __c); +} + +__extern_always_inline const char *strrchr(const char *__s, int __c) __THROW +{ + return __builtin_strrchr(__s, __c); +} +#endif +} +#else +extern char *strrchr(const char *__s, int __c) __THROW __attribute_pure__ __nonnull((1)); +#endif + +#ifdef __USE_GNU +/* This function is similar to `strchr'. But it returns a pointer to + the closing NUL byte in case C is not found in S. */ +#ifdef __CORRECT_ISO_CPP_STRING_H_PROTO +extern "C++" char *strchrnul(char *__s, int __c) __THROW __asm("strchrnul") __attribute_pure__ __nonnull((1)); +extern "C++" const char *strchrnul(const char *__s, int __c) __THROW __asm("strchrnul") __attribute_pure__ + __nonnull((1)); +#else +extern char *strchrnul(const char *__s, int __c) __THROW __attribute_pure__ __nonnull((1)); +#endif +#endif + +/* Return the length of the initial segment of S which + consists entirely of characters not in REJECT. */ +extern size_t strcspn(const char *__s, const char *__reject) __THROW __attribute_pure__ __nonnull((1, 2)); +/* Return the length of the initial segment of S which + consists entirely of characters in ACCEPT. */ +extern size_t strspn(const char *__s, const char *__accept) __THROW __attribute_pure__ __nonnull((1, 2)); +/* Find the first occurrence in S of any character in ACCEPT. */ +#ifdef __CORRECT_ISO_CPP_STRING_H_PROTO +extern "C++" { +extern char *strpbrk(char *__s, const char *__accept) __THROW __asm("strpbrk") __attribute_pure__ __nonnull((1, 2)); +extern const char *strpbrk(const char *__s, const char *__accept) __THROW __asm("strpbrk") __attribute_pure__ + __nonnull((1, 2)); + +#ifdef __OPTIMIZE__ +__extern_always_inline char *strpbrk(char *__s, const char *__accept) __THROW +{ + return __builtin_strpbrk(__s, __accept); +} + +__extern_always_inline const char *strpbrk(const char *__s, const char *__accept) __THROW +{ + return __builtin_strpbrk(__s, __accept); +} +#endif +} +#else +extern char *strpbrk(const char *__s, const char *__accept) __THROW __attribute_pure__ __nonnull((1, 2)); +#endif +/* Find the first occurrence of NEEDLE in HAYSTACK. */ +#ifdef __CORRECT_ISO_CPP_STRING_H_PROTO +extern "C++" { +extern char *strstr(char *__haystack, const char *__needle) __THROW __asm("strstr") __attribute_pure__ + __nonnull((1, 2)); +extern const char *strstr(const char *__haystack, const char *__needle) __THROW __asm("strstr") __attribute_pure__ + __nonnull((1, 2)); + +#ifdef __OPTIMIZE__ +__extern_always_inline char *strstr(char *__haystack, const char *__needle) __THROW +{ + return __builtin_strstr(__haystack, __needle); +} + +__extern_always_inline const char *strstr(const char *__haystack, const char *__needle) __THROW +{ + return __builtin_strstr(__haystack, __needle); +} +#endif +} +#else +extern char *strstr(const char *__haystack, const char *__needle) __THROW __attribute_pure__ __nonnull((1, 2)); +#endif + +/* Divide S into tokens separated by characters in DELIM. */ +extern char *strtok(char *__restrict __s, const char *__restrict __delim) __THROW __nonnull((2)); + +/* Divide S into tokens separated by characters in DELIM. Information + passed between calls are stored in SAVE_PTR. */ +extern char *__strtok_r(char *__restrict __s, const char *__restrict __delim, char **__restrict __save_ptr) __THROW + __nonnull((2, 3)); +#ifdef __USE_POSIX +extern char *strtok_r(char *__restrict __s, const char *__restrict __delim, char **__restrict __save_ptr) __THROW + __nonnull((2, 3)); +#endif + +#ifdef __USE_GNU +/* Similar to `strstr' but this function ignores the case of both strings. */ +#ifdef __CORRECT_ISO_CPP_STRING_H_PROTO +extern "C++" char *strcasestr(char *__haystack, const char *__needle) __THROW __asm("strcasestr") __attribute_pure__ + __nonnull((1, 2)); +extern "C++" const char *strcasestr(const char *__haystack, const char *__needle) __THROW + __asm("strcasestr") __attribute_pure__ __nonnull((1, 2)); +#else +extern char *strcasestr(const char *__haystack, const char *__needle) __THROW __attribute_pure__ __nonnull((1, 2)); +#endif +#endif + +#ifdef __USE_GNU +/* Find the first occurrence of NEEDLE in HAYSTACK. + NEEDLE is NEEDLELEN bytes long; + HAYSTACK is HAYSTACKLEN bytes long. */ +extern void *memmem(const void *__haystack, size_t __haystacklen, const void *__needle, + size_t __needlelen) __THROW __attribute_pure__ __nonnull((1, 3)) + __attr_access((__read_only__, 1, 2)) __attr_access((__read_only__, 3, 4)); + +/* Copy N bytes of SRC to DEST, return pointer to bytes after the + last written byte. */ +extern void *__mempcpy(void *__restrict __dest, const void *__restrict __src, size_t __n) __THROW __nonnull((1, 2)); +extern void *mempcpy(void *__restrict __dest, const void *__restrict __src, size_t __n) __THROW __nonnull((1, 2)); +#endif + +/* Return the length of S. */ +extern size_t strlen(const char *__s) __THROW __attribute_pure__ __nonnull((1)); + +#ifdef __USE_XOPEN2K8 +/* Find the length of STRING, but scan at most MAXLEN characters. + If no '\0' terminator is found in that many characters, return MAXLEN. */ +extern size_t strnlen(const char *__string, size_t __maxlen) __THROW __attribute_pure__ __nonnull((1)); +#endif + +/* Return a string describing the meaning of the `errno' code in ERRNUM. */ +extern char *strerror(int __errnum) __THROW; +#ifdef __USE_XOPEN2K +/* Reentrant version of `strerror'. + There are 2 flavors of `strerror_r', GNU which returns the string + and may or may not use the supplied temporary buffer and POSIX one + which fills the string into the buffer. + To use the POSIX version, -D_XOPEN_SOURCE=600 or -D_POSIX_C_SOURCE=200112L + without -D_GNU_SOURCE is needed, otherwise the GNU version is + preferred. */ +#if defined __USE_XOPEN2K && !defined __USE_GNU +/* Fill BUF with a string describing the meaning of the `errno' code in + ERRNUM. */ +#ifdef __REDIRECT_NTH +extern int __REDIRECT_NTH(strerror_r, (int __errnum, char *__buf, size_t __buflen), __xpg_strerror_r) __nonnull((2)) + __attr_access((__write_only__, 2, 3)); +#else +extern int __xpg_strerror_r(int __errnum, char *__buf, size_t __buflen) __THROW __nonnull((2)) + __attr_access((__write_only__, 2, 3)); +#define strerror_r __xpg_strerror_r +#endif +#else +/* If a temporary buffer is required, at most BUFLEN bytes of BUF will be + used. */ +extern char *strerror_r(int __errnum, char *__buf, size_t __buflen) __THROW __nonnull((2)) __wur + __attr_access((__write_only__, 2, 3)); +#endif + +#ifdef __USE_GNU +/* Return a string describing the meaning of tthe error in ERR. */ +extern const char *strerrordesc_np(int __err) __THROW; +/* Return a string with the error name in ERR. */ +extern const char *strerrorname_np(int __err) __THROW; +#endif +#endif + +#ifdef __USE_XOPEN2K8 +/* Translate error number to string according to the locale L. */ +extern char *strerror_l(int __errnum, locale_t __l) __THROW; +#endif + +#ifdef __USE_MISC +#include + +/* Set N bytes of S to 0. The compiler will not delete a call to this + function, even if S is dead after the call. */ +extern void explicit_bzero(void *__s, size_t __n) __THROW __nonnull((1)) __fortified_attr_access(__write_only__, 1, 2); + +/* Return the next DELIM-delimited token from *STRINGP, + terminating it with a '\0', and update *STRINGP to point past it. */ +extern char *strsep(char **__restrict __stringp, const char *__restrict __delim) __THROW __nonnull((1, 2)); +#endif + +#ifdef __USE_XOPEN2K8 +/* Return a string describing the meaning of the signal number in SIG. */ +extern char *strsignal(int __sig) __THROW; + +#ifdef __USE_GNU +/* Return an abbreviation string for the signal number SIG. */ +extern const char *sigabbrev_np(int __sig) __THROW; +/* Return a string describing the meaning of the signal number in SIG, + the result is not translated. */ +extern const char *sigdescr_np(int __sig) __THROW; +#endif + +/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */ +extern char *__stpcpy(char *__restrict __dest, const char *__restrict __src) __THROW __nonnull((1, 2)); +extern char *stpcpy(char *__restrict __dest, const char *__restrict __src) __THROW __nonnull((1, 2)); + +/* Copy no more than N characters of SRC to DEST, returning the address of + the last character written into DEST. */ +extern char *__stpncpy(char *__restrict __dest, const char *__restrict __src, size_t __n) __THROW __nonnull((1, 2)); +extern char *stpncpy(char *__restrict __dest, const char *__restrict __src, size_t __n) __THROW __nonnull((1, 2)); +#endif + +#ifdef __USE_GNU +/* Compare S1 and S2 as strings holding name & indices/version numbers. */ +extern int strverscmp(const char *__s1, const char *__s2) __THROW __attribute_pure__ __nonnull((1, 2)); + +/* Sautee STRING briskly. */ +extern char *strfry(char *__string) __THROW __nonnull((1)); + +/* Frobnicate N bytes of S. */ +extern void *memfrob(void *__s, size_t __n) __THROW __nonnull((1)) __attr_access((__read_write__, 1, 2)); + +#ifndef basename +/* Return the file name within directory of FILENAME. We don't + declare the function if the `basename' macro is available (defined + in ) which makes the XPG version of this function + available. */ +#ifdef __CORRECT_ISO_CPP_STRING_H_PROTO +extern "C++" char *basename(char *__filename) __THROW __asm("basename") __nonnull((1)); +extern "C++" const char *basename(const char *__filename) __THROW __asm("basename") __nonnull((1)); +#else +extern char *basename(const char *__filename) __THROW __nonnull((1)); +#endif +#endif +#endif + +#if __GNUC_PREREQ(3, 4) +#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function +/* Functions with security checks. */ +#include +#endif +#endif + +__END_DECLS + +#endif /* string.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@string.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@string.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..0692204f9243012840fa6e63d1b5940a3fb4d191 GIT binary patch literal 8789 zcmcIp3vd+W9p62%!c7Vh@tUq_T_Henx#W0+htsGRE(wN5h)GE8gIxFSHo48+?Vh`P zdFZsZRvp^`5etNo1Zt?w)M-g2woo$ALg<6eR0~y#4?yuPRR#rYb&mA+eYbbF_Xvue z-pqab-`(%=|Ns8a?^`=_$+7mHzcCEUIHQ{Clw@Bh>KC1wu1a!yd4O>Sl(6Uw2tlV` z>~w1LgU*PmbcjA(!-KFQqobfJsuQF{uYx3(`%6;49ag`ION%IB0XG>PN)i)|3+(!f38Kc-3ACJK5~6*cmb zK#{#rZh?J@+$Ir(F8%$!%4gE1>|VUkv#_EpB+1e4vUWM@)Os|h4-BLhF=L(JpiGy- z;=+m~Bj!GFedHdWwVYRicF1I!bhkLpbbeo1L=_ECsNCk|a!(0(ePsbr@QZ4hrVFZ` zbMD+@^`3~RIYWw12#KE0IFLf8N4-}fc1R&+qeQ)-+>&Q;mt3T59O$z~#Nnm#csy4o z5giKS_M0^`VczAfhYrexz3X#0K&*xR469{nEB4q`X~R{-Oc95_TajYogDi; zu7_|vh3gx*euV3_mb}&0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5Vam~#zigM~pCu;uzdZ|An7-NEfZJH!p4y~tfe3;a0z z2{jYcOiGo2Dxs7cl$%nmpjs)_3#yk={h;~@HTK2Rc~#|u4fD;sSY|AqK@hyoG7. */ + +#ifndef _STRINGS_H +#define _STRINGS_H 1 + +#include +#define __need_size_t +#include + +/* Tell the caller that we provide correct C++ prototypes. */ +#if defined __cplusplus && __GNUC_PREREQ(4, 4) +#define __CORRECT_ISO_CPP_STRINGS_H_PROTO +#endif + +__BEGIN_DECLS + +#if defined __USE_MISC || !defined __USE_XOPEN2K8 +/* Compare N bytes of S1 and S2 (same as memcmp). */ +extern int bcmp(const void *__s1, const void *__s2, size_t __n) __THROW __attribute_pure__ __nonnull((1, 2)); + +/* Copy N bytes of SRC to DEST (like memmove, but args reversed). */ +extern void bcopy(const void *__src, void *__dest, size_t __n) __THROW __nonnull((1, 2)); + +/* Set N bytes of S to 0. */ +extern void bzero(void *__s, size_t __n) __THROW __nonnull((1)); + +/* Find the first occurrence of C in S (same as strchr). */ +#ifdef __CORRECT_ISO_CPP_STRINGS_H_PROTO +extern "C++" { +extern char *index(char *__s, int __c) __THROW __asm("index") __attribute_pure__ __nonnull((1)); +extern const char *index(const char *__s, int __c) __THROW __asm("index") __attribute_pure__ __nonnull((1)); + +#if defined __OPTIMIZE__ +__extern_always_inline char *index(char *__s, int __c) __THROW +{ + return __builtin_index(__s, __c); +} + +__extern_always_inline const char *index(const char *__s, int __c) __THROW +{ + return __builtin_index(__s, __c); +} +#endif +} +#else +extern char *index(const char *__s, int __c) __THROW __attribute_pure__ __nonnull((1)); +#endif + +/* Find the last occurrence of C in S (same as strrchr). */ +#ifdef __CORRECT_ISO_CPP_STRINGS_H_PROTO +extern "C++" { +extern char *rindex(char *__s, int __c) __THROW __asm("rindex") __attribute_pure__ __nonnull((1)); +extern const char *rindex(const char *__s, int __c) __THROW __asm("rindex") __attribute_pure__ __nonnull((1)); + +#if defined __OPTIMIZE__ +__extern_always_inline char *rindex(char *__s, int __c) __THROW +{ + return __builtin_rindex(__s, __c); +} + +__extern_always_inline const char *rindex(const char *__s, int __c) __THROW +{ + return __builtin_rindex(__s, __c); +} +#endif +} +#else +extern char *rindex(const char *__s, int __c) __THROW __attribute_pure__ __nonnull((1)); +#endif +#endif + +#if defined __USE_MISC || !defined __USE_XOPEN2K8 || defined __USE_XOPEN2K8XSI +/* Return the position of the first bit set in I, or 0 if none are set. + The least-significant bit is position 1, the most-significant 32. */ +extern int ffs(int __i) __THROW __attribute_const__; +#endif + +/* The following two functions are non-standard but necessary for non-32 bit + platforms. */ +#ifdef __USE_MISC +extern int ffsl(long int __l) __THROW __attribute_const__; +__extension__ extern int ffsll(long long int __ll) __THROW __attribute_const__; +#endif + +/* Compare S1 and S2, ignoring case. */ +extern int strcasecmp(const char *__s1, const char *__s2) __THROW __attribute_pure__ __nonnull((1, 2)); + +/* Compare no more than N chars of S1 and S2, ignoring case. */ +extern int strncasecmp(const char *__s1, const char *__s2, size_t __n) __THROW __attribute_pure__ __nonnull((1, 2)); + +#ifdef __USE_XOPEN2K8 +/* POSIX.1-2008 extended locale interface (see locale.h). */ +#include + +/* Compare S1 and S2, ignoring case, using collation rules from LOC. */ +extern int strcasecmp_l(const char *__s1, const char *__s2, locale_t __loc) __THROW __attribute_pure__ + __nonnull((1, 2, 3)); + +/* Compare no more than N chars of S1 and S2, ignoring case, using + collation rules from LOC. */ +extern int strncasecmp_l(const char *__s1, const char *__s2, size_t __n, locale_t __loc) __THROW __attribute_pure__ + __nonnull((1, 2, 4)); +#endif + +__END_DECLS + +#if __GNUC_PREREQ(3, 4) && __USE_FORTIFY_LEVEL > 0 && defined __fortify_function +/* Functions with security checks. */ +#if defined __USE_MISC || !defined __USE_XOPEN2K8 +#include +#endif +#endif + +#endif /* strings.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@strings.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@strings.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..157494f823fe601ab0e3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Qnezo0y z0?+o&9)!KiuRQh3hu#0Qz*mz}O|E=H;h?Y${>d3Iw3lq)P3t#xG?gtXVK`W#@4Yei n+RNwr<)Puh{(;>?@*Y^-SaYwfu1moea>M!!+nczJR=ocMK*6+v literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@libc-header-start.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@libc-header-start.h new file mode 100644 index 00000000..6d237099 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@libc-header-start.h @@ -0,0 +1,109 @@ +/* Handle feature test macros at the start of a header. + Copyright (C) 2016-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This header is internal to glibc and should not be included outside + of glibc headers. Headers including it must define + __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION first. This header + cannot have multiple include guards because ISO C feature test + macros depend on the definition of the macro when an affected + header is included, not when the first system header is + included. */ + +#ifndef __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION +#error "Never include directly." +#endif + +#undef __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION + +#include + +/* ISO/IEC TR 24731-2:2010 defines the __STDC_WANT_LIB_EXT2__ + macro. */ +#undef __GLIBC_USE_LIB_EXT2 +#if (defined __USE_GNU || (defined __STDC_WANT_LIB_EXT2__ && __STDC_WANT_LIB_EXT2__ > 0)) +#define __GLIBC_USE_LIB_EXT2 1 +#else +#define __GLIBC_USE_LIB_EXT2 0 +#endif + +/* ISO/IEC TS 18661-1:2014 defines the __STDC_WANT_IEC_60559_BFP_EXT__ + macro. Most but not all symbols enabled by that macro in TS + 18661-1 are enabled unconditionally in C2X. In C2X, the symbols in + Annex F still require a new feature test macro + __STDC_WANT_IEC_60559_EXT__ instead (C2X does not define + __STDC_WANT_IEC_60559_BFP_EXT__), while a few features from TS + 18661-1 are not included in C2X (and thus should depend on + __STDC_WANT_IEC_60559_BFP_EXT__ even when C2X features are + enabled). + + __GLIBC_USE (IEC_60559_BFP_EXT) controls those features from TS + 18661-1 not included in C2X. + + __GLIBC_USE (IEC_60559_BFP_EXT_C2X) controls those features from TS + 18661-1 that are also included in C2X (with no feature test macro + required in C2X). + + __GLIBC_USE (IEC_60559_EXT) controls those features from TS 18661-1 + that are included in C2X but conditional on + __STDC_WANT_IEC_60559_EXT__. (There are currently no features + conditional on __STDC_WANT_IEC_60559_EXT__ that are not in TS + 18661-1.) */ +#undef __GLIBC_USE_IEC_60559_BFP_EXT +#if defined __USE_GNU || defined __STDC_WANT_IEC_60559_BFP_EXT__ +#define __GLIBC_USE_IEC_60559_BFP_EXT 1 +#else +#define __GLIBC_USE_IEC_60559_BFP_EXT 0 +#endif +#undef __GLIBC_USE_IEC_60559_BFP_EXT_C2X +#if __GLIBC_USE(IEC_60559_BFP_EXT) || __GLIBC_USE(ISOC2X) +#define __GLIBC_USE_IEC_60559_BFP_EXT_C2X 1 +#else +#define __GLIBC_USE_IEC_60559_BFP_EXT_C2X 0 +#endif +#undef __GLIBC_USE_IEC_60559_EXT +#if __GLIBC_USE(IEC_60559_BFP_EXT) || defined __STDC_WANT_IEC_60559_EXT__ +#define __GLIBC_USE_IEC_60559_EXT 1 +#else +#define __GLIBC_USE_IEC_60559_EXT 0 +#endif + +/* ISO/IEC TS 18661-4:2015 defines the + __STDC_WANT_IEC_60559_FUNCS_EXT__ macro. Other than the reduction + functions, the symbols from this TS are enabled unconditionally in + C2X. */ +#undef __GLIBC_USE_IEC_60559_FUNCS_EXT +#if defined __USE_GNU || defined __STDC_WANT_IEC_60559_FUNCS_EXT__ +#define __GLIBC_USE_IEC_60559_FUNCS_EXT 1 +#else +#define __GLIBC_USE_IEC_60559_FUNCS_EXT 0 +#endif +#undef __GLIBC_USE_IEC_60559_FUNCS_EXT_C2X +#if __GLIBC_USE(IEC_60559_FUNCS_EXT) || __GLIBC_USE(ISOC2X) +#define __GLIBC_USE_IEC_60559_FUNCS_EXT_C2X 1 +#else +#define __GLIBC_USE_IEC_60559_FUNCS_EXT_C2X 0 +#endif + +/* ISO/IEC TS 18661-3:2015 defines the + __STDC_WANT_IEC_60559_TYPES_EXT__ macro. */ +#undef __GLIBC_USE_IEC_60559_TYPES_EXT +#if defined __USE_GNU || defined __STDC_WANT_IEC_60559_TYPES_EXT__ +#define __GLIBC_USE_IEC_60559_TYPES_EXT 1 +#else +#define __GLIBC_USE_IEC_60559_TYPES_EXT 0 +#endif diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@libc-header-start.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@libc-header-start.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..60e5c5fd007aeb4f180869bdc0e7732b770d4eca GIT binary patch literal 1688 zcmbW0&rcIU6vt<3Fm+?VtOt!TNJ5NY+zw!=N(38fi>uXEXiZhfw%uLYwbNa)KM=%& z!4pRQ15e&P8ug%wCL~@oh6Ljg;=#L#7fq;d$5M-3pxDFfr1ReQ^S*ChPonixkLNxh zghnvmH~l+)LMUBgosZZ0M6(!L9l#%@wlA*iL>ouBhQ|h2i9>x3PxqY7k+I$u?B{nI7{aNxO5zN?~`E`oZJy zrsb&HH~$fIbpLVG#YIq*6VVkefv$76&^VVxc}_zm4xxROXV3YCW3L8QC21rs4o9T) zSX2_D5h>Ku-+xYurLRTCq-Z83Mfx)Eca3$zlWMx!(L{Pj4?bd%6#q2siiUw@!RF) T*7?Dew>6t^!0oN=G>m@(^T#F7 literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@long-double.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@long-double.h new file mode 100644 index 00000000..350df845 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@long-double.h @@ -0,0 +1,21 @@ +/* Properties of long double type. ldbl-96 version. + Copyright (C) 2016-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* long double is distinct from double, so there is nothing to + define here. */ +#define __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI 0 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@long-double.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@long-double.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..26514ca6b5095ebac85a462a662b606f32baf81c GIT binary patch literal 907 zcmbW0K~KUk7>0}9jV2sC61^F_GF=uf9zY-=At6EZ;H4>BVU?|0+73bff$;};_P=;C zCjKI@n_@KEB6?|-e&73i@Aqyy0?Xrv#VY^+d0{}2M<&RnQzTC(C=%ffb(GW>LCB>N zM1=y8C^At%7&jcS?f8U`|0RXDp_ni}hAtC&NGRrKSqEST#Zn-j4Uz9p187?5b2=57 zmQgiq#JJC1bngcybTq>YcM5qFG zVl}r^;B+2QiTuzZKE?UWj4(}A#lsB~`D%v+`DO-uWSBa`_;21)ss0w-@A2#30hCsc z2QRDpxBWegyUpHZquav$R. */ + +#ifndef _BITS_STDINT_INTN_H +#define _BITS_STDINT_INTN_H 1 + +#include + +typedef __int8_t int8_t; +typedef __int16_t int16_t; +typedef __int32_t int32_t; +typedef __int64_t int64_t; + +#endif /* bits/stdint-intn.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@stdint-intn.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@stdint-intn.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..a4ca70a28c5b63af01169768829f28043308d19a GIT binary patch literal 1272 zcmbVMu};G<5KUoXLxK-LLSjI;rcgx{f&s)pmo9X-T*qxp9lNp}XklaK6PQ?#nE3<5 z2x8?k*kEb7gd$OqB9|dnl=HiL_ugIBgW<;2#ZwRjIMxZrG40}rpJKb+#XX}>ICB<0 zBwAT#sM7{BGw3;u6Dm}h1@lZ&)%hnFooUk*s)Hh7ppZ6$z27W?Wt>`rrD$O(PZLzB z=I?o3T&b2f%OMtu$u#2Fx+vo9avThAE|SL__Z{ljLK0Sy6e{hbj!JP$Kxb~y<2JjW ziQs!*oKL~DId!R-5}ZOnBs{G8F|Y%R8T407_`5iAlPPDjm2z9zs%3m$E_a_j6ggut zHGcea#la$>97^F(Gr+Q@EC^o+ft(EW3?F;%=_O1QLoufjH^@3_+_c<4bt2?DieudU z?Z?C4LT2M=UD_%(ws>%)&h|#9Ejg))7db+{Hiaa#PpA|fMe-J}_g{UfBHyXaU57=F ze%e=B|67rX<%FM8X%xNH@7`aN4RTO#9+TtdVZG5L@HEH~#Mf5Ad!hJBL3p78_@%|A Ma4tJ{f>8+opR;Mwy8r+H literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@stdint-uintn.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@stdint-uintn.h new file mode 100644 index 00000000..37cd1f6d --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@stdint-uintn.h @@ -0,0 +1,29 @@ +/* Define uintN_t types. + Copyright (C) 2017-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _BITS_STDINT_UINTN_H +#define _BITS_STDINT_UINTN_H 1 + +#include + +typedef __uint8_t uint8_t; +typedef __uint16_t uint16_t; +typedef __uint32_t uint32_t; +typedef __uint64_t uint64_t; + +#endif /* bits/stdint-uintn.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@stdint-uintn.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@stdint-uintn.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..920357b7fcb815591852ad53d5faf6f94d966aee GIT binary patch literal 1273 zcmbVMu};G<5KUoXLxPb3i3K5CQ>dyAWdJe2!a|uX*Kr$D$F6J#8kk__6PRFNM&b_; zBZw6S{(}X$gd$OqB9|dnl=HiL_ugHWg7@X~lZPM(aHM07Bih9wKg4#ei+e^NaONz0 zh_$lLP^S%MCha+mV=7dc1(Qrt)%hnF9cj}Qs)IsdppZ7{`fnD&EKaP!Qnav?hcT*D z^Y^?iu2jn_$t2|1x-jJJaumE@p2YV#?mN`4*GR33q)R?2N^lDBxV@$5?#`3`MvI_!D) z)4tNu---D=+vDcRgj| literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@time64.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@time64.h new file mode 100644 index 00000000..1b9371b1 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@time64.h @@ -0,0 +1,36 @@ +/* bits/time64.h -- underlying types for __time64_t. Generic version. + Copyright (C) 2018-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _BITS_TYPES_H +#error "Never include directly; use instead." +#endif + +#ifndef _BITS_TIME64_H +#define _BITS_TIME64_H 1 + +/* Define __TIME64_T_TYPE so that it is always a 64-bit type. */ + +#if __TIMESIZE == 64 +/* If we already have 64-bit time type then use it. */ +#define __TIME64_T_TYPE __TIME_T_TYPE +#else +/* Define a 64-bit time type alongsize the 32-bit one. */ +#define __TIME64_T_TYPE __SQUAD_TYPE +#endif + +#endif /* bits/time64.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@time64.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@time64.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..aeb7be3fac0914d8944ec4ef8868fc7dc89e384e GIT binary patch literal 1344 zcmbVMPiqrF9Gy)s26`x^&_mjy6g+4rljySaP(cd?bFc{J;>BUIJI#*SoelFRP1>7h z@AaS;5%L8J{Q%-o5%HimLHrP28fP}m(wL-fT-arp-@JKm-tW!c0_R&Vk3RwcP?*FN zg`|Z7+ClPe3$;b^occ38E5#e9>#G1jU5$vJV#gi16lrg5hBzT8uYgz=R=6 zMDO0D3b2B-6ewa16h)mFR^4=*@}jC+u9Q8*xF6|&BB_Fa9+X3H{`NTjkm5$A?zV?L z7e)Fu^%mF1ziy6fU0kS8NZ{$wrAMFJdi>c>k8t3a0 zp|W~s+k!v8*!h&>fQNoaL`G(fzuG|KIO7VMm(P#VbHc0@(zrjB$tdw*ThNODwTZym`F9o%VmfzuJDANvU*WdK@Owlg2kn?Bz*xBO3Q4mpF`v z*9FI9(Diw>viEO2_zPw&3*zZ0VI0iZR(fR6?PV_4?&K{?9 tt+aOE8T_n#>Hpe4yNP#e^(Q0Jhi2JY#y3_eRsnEUmsYn5_FEY;`~ieB-|hea literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@timesize.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@timesize.h new file mode 100644 index 00000000..b608e17b --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@timesize.h @@ -0,0 +1,27 @@ +/* Bit size of the time_t type at glibc build time, x86-64 and x32 case. + Copyright (C) 2018-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +#if defined __x86_64__ && defined __ILP32__ +/* For x32, time is 64-bit even though word size is 32-bit. */ +#define __TIMESIZE 64 +#else +/* For others, time size is word size. */ +#define __TIMESIZE __WORDSIZE +#endif diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@timesize.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@timesize.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..8d8e200e8eb599bfc896f2b564867af6973380c9 GIT binary patch literal 980 zcmbVLu};G<5OrXJ1qoF`6$=uG0pXa6C}JoZ9XcQ+Ktf`%QpZh96T7mV($bBY9cKQ8 z5yZd;@Fguy3T. */ + +/* + * Never include this file directly; use instead. + */ + +#ifndef _BITS_TYPES_H +#define _BITS_TYPES_H 1 + +#include +#include +#include + +/* Convenience types. */ +typedef unsigned char __u_char; +typedef unsigned short int __u_short; +typedef unsigned int __u_int; +typedef unsigned long int __u_long; + +/* Fixed-size types, underlying types depend on word size and compiler. */ +typedef signed char __int8_t; +typedef unsigned char __uint8_t; +typedef signed short int __int16_t; +typedef unsigned short int __uint16_t; +typedef signed int __int32_t; +typedef unsigned int __uint32_t; +#if __WORDSIZE == 64 +typedef signed long int __int64_t; +typedef unsigned long int __uint64_t; +#else +__extension__ typedef signed long long int __int64_t; +__extension__ typedef unsigned long long int __uint64_t; +#endif + +/* Smallest types with at least a given width. */ +typedef __int8_t __int_least8_t; +typedef __uint8_t __uint_least8_t; +typedef __int16_t __int_least16_t; +typedef __uint16_t __uint_least16_t; +typedef __int32_t __int_least32_t; +typedef __uint32_t __uint_least32_t; +typedef __int64_t __int_least64_t; +typedef __uint64_t __uint_least64_t; + +/* quad_t is also 64 bits. */ +#if __WORDSIZE == 64 +typedef long int __quad_t; +typedef unsigned long int __u_quad_t; +#else +__extension__ typedef long long int __quad_t; +__extension__ typedef unsigned long long int __u_quad_t; +#endif + +/* Largest integral types. */ +#if __WORDSIZE == 64 +typedef long int __intmax_t; +typedef unsigned long int __uintmax_t; +#else +__extension__ typedef long long int __intmax_t; +__extension__ typedef unsigned long long int __uintmax_t; +#endif + +/* The machine-dependent file defines __*_T_TYPE + macros for each of the OS types we define below. The definitions + of those macros must use the following macros for underlying types. + We define __S_TYPE and __U_TYPE for the signed and unsigned + variants of each of the following integer types on this machine. + + 16 -- "natural" 16-bit type (always short) + 32 -- "natural" 32-bit type (always int) + 64 -- "natural" 64-bit type (long or long long) + LONG32 -- 32-bit type, traditionally long + QUAD -- 64-bit type, traditionally long long + WORD -- natural type of __WORDSIZE bits (int or long) + LONGWORD -- type of __WORDSIZE bits, traditionally long + + We distinguish WORD/LONGWORD, 32/LONG32, and 64/QUAD so that the + conventional uses of `long' or `long long' type modifiers match the + types we define, even when a less-adorned type would be the same size. + This matters for (somewhat) portably writing printf/scanf formats for + these types, where using the appropriate l or ll format modifiers can + make the typedefs and the formats match up across all GNU platforms. If + we used `long' when it's 64 bits where `long long' is expected, then the + compiler would warn about the formats not matching the argument types, + and the programmer changing them to shut up the compiler would break the + program's portability. + + Here we assume what is presently the case in all the GCC configurations + we support: long long is always 64 bits, long is always word/address size, + and int is always 32 bits. */ + +#define __S16_TYPE short int +#define __U16_TYPE unsigned short int +#define __S32_TYPE int +#define __U32_TYPE unsigned int +#define __SLONGWORD_TYPE long int +#define __ULONGWORD_TYPE unsigned long int +#if __WORDSIZE == 32 +#define __SQUAD_TYPE __int64_t +#define __UQUAD_TYPE __uint64_t +#define __SWORD_TYPE int +#define __UWORD_TYPE unsigned int +#define __SLONG32_TYPE long int +#define __ULONG32_TYPE unsigned long int +#define __S64_TYPE __int64_t +#define __U64_TYPE __uint64_t +/* We want __extension__ before typedef's that use nonstandard base types + such as `long long' in C89 mode. */ +#define __STD_TYPE __extension__ typedef +#elif __WORDSIZE == 64 +#define __SQUAD_TYPE long int +#define __UQUAD_TYPE unsigned long int +#define __SWORD_TYPE long int +#define __UWORD_TYPE unsigned long int +#define __SLONG32_TYPE int +#define __ULONG32_TYPE unsigned int +#define __S64_TYPE long int +#define __U64_TYPE unsigned long int +/* No need to mark the typedef with __extension__. */ +#define __STD_TYPE typedef +#else +#error +#endif +#include /* Defines __TIME*_T_TYPE macros. */ +#include /* Defines __*_T_TYPE macros. */ + +__STD_TYPE __DEV_T_TYPE __dev_t; /* Type of device numbers. */ +__STD_TYPE __UID_T_TYPE __uid_t; /* Type of user identifications. */ +__STD_TYPE __GID_T_TYPE __gid_t; /* Type of group identifications. */ +__STD_TYPE __INO_T_TYPE __ino_t; /* Type of file serial numbers. */ +__STD_TYPE __INO64_T_TYPE __ino64_t; /* Type of file serial numbers (LFS).*/ +__STD_TYPE __MODE_T_TYPE __mode_t; /* Type of file attribute bitmasks. */ +__STD_TYPE __NLINK_T_TYPE __nlink_t; /* Type of file link counts. */ +__STD_TYPE __OFF_T_TYPE __off_t; /* Type of file sizes and offsets. */ +__STD_TYPE __OFF64_T_TYPE __off64_t; /* Type of file sizes and offsets (LFS). */ +__STD_TYPE __PID_T_TYPE __pid_t; /* Type of process identifications. */ +__STD_TYPE __FSID_T_TYPE __fsid_t; /* Type of file system IDs. */ +__STD_TYPE __CLOCK_T_TYPE __clock_t; /* Type of CPU usage counts. */ +__STD_TYPE __RLIM_T_TYPE __rlim_t; /* Type for resource measurement. */ +__STD_TYPE __RLIM64_T_TYPE __rlim64_t; /* Type for resource measurement (LFS). */ +__STD_TYPE __ID_T_TYPE __id_t; /* General type for IDs. */ +__STD_TYPE __TIME_T_TYPE __time_t; /* Seconds since the Epoch. */ +__STD_TYPE __USECONDS_T_TYPE __useconds_t; /* Count of microseconds. */ +__STD_TYPE __SUSECONDS_T_TYPE __suseconds_t; /* Signed count of microseconds. */ +__STD_TYPE __SUSECONDS64_T_TYPE __suseconds64_t; + +__STD_TYPE __DADDR_T_TYPE __daddr_t; /* The type of a disk address. */ +__STD_TYPE __KEY_T_TYPE __key_t; /* Type of an IPC key. */ + +/* Clock ID used in clock and timer functions. */ +__STD_TYPE __CLOCKID_T_TYPE __clockid_t; + +/* Timer ID returned by `timer_create'. */ +__STD_TYPE __TIMER_T_TYPE __timer_t; + +/* Type to represent block size. */ +__STD_TYPE __BLKSIZE_T_TYPE __blksize_t; + +/* Types from the Large File Support interface. */ + +/* Type to count number of disk blocks. */ +__STD_TYPE __BLKCNT_T_TYPE __blkcnt_t; +__STD_TYPE __BLKCNT64_T_TYPE __blkcnt64_t; + +/* Type to count file system blocks. */ +__STD_TYPE __FSBLKCNT_T_TYPE __fsblkcnt_t; +__STD_TYPE __FSBLKCNT64_T_TYPE __fsblkcnt64_t; + +/* Type to count file system nodes. */ +__STD_TYPE __FSFILCNT_T_TYPE __fsfilcnt_t; +__STD_TYPE __FSFILCNT64_T_TYPE __fsfilcnt64_t; + +/* Type of miscellaneous file system fields. */ +__STD_TYPE __FSWORD_T_TYPE __fsword_t; + +__STD_TYPE __SSIZE_T_TYPE __ssize_t; /* Type of a byte count, or error. */ + +/* Signed long type used in system calls. */ +__STD_TYPE __SYSCALL_SLONG_TYPE __syscall_slong_t; +/* Unsigned long type used in system calls. */ +__STD_TYPE __SYSCALL_ULONG_TYPE __syscall_ulong_t; + +/* These few don't really vary by system, they always correspond + to one of the other defined types. */ +typedef __off64_t __loff_t; /* Type of file sizes and offsets (LFS). */ +typedef char *__caddr_t; + +/* Duplicates info from stdint.h but this is used in unistd.h. */ +__STD_TYPE __SWORD_TYPE __intptr_t; + +/* Duplicate info from sys/socket.h. */ +__STD_TYPE __U32_TYPE __socklen_t; + +/* C99: An integer type that can be accessed as an atomic entity, + even in the presence of asynchronous interrupts. + It is not currently necessary for this to be machine-specific. */ +typedef int __sig_atomic_t; + +/* Seconds since the Epoch, visible to user code when time_t is too + narrow only for consistency with the old way of widening too-narrow + types. User code should never use __time64_t. */ +#if __TIMESIZE == 64 && defined __LIBC +#define __time64_t __time_t +#elif __TIMESIZE != 64 +__STD_TYPE __TIME64_T_TYPE __time64_t; +#endif + +#undef __STD_TYPE + +#endif /* bits/types.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..cb6d62932b4f4e97e9b40b1a272180e0621da6d0 GIT binary patch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@JLo|uzy*X8AKN~! zHsxdi7!g#zysB0!Wji%akPVpVm!10EXR%4`OJ-Bj3UMKs?V2$4=@sQn0maqfI?{B7 z_El=(m6{Z=kJLfg;?JGQeRH|;)aznGW2Tvy`JwXx zmxL|>6hlS8=fj?l0yVX{**{;JdXKI# z4XzmBTx~801eE*x`>ZdGx0HBG0|q0cIuUvTif}UQBq_pRgw&RHVrV`X5sg6ysvji>I{iompacF9c5;y^@r{{i|xV|Gf=md{O%% z@0jx!}fOV)2upZR|HlPN;M$`z{gqi@GQ8VB^v=6WawE(uF zR=_sY2H1|;0Xt9!U?=JX>_T0D-KZO|2lW8jX%r)i@tq)1CAVsd5^L$ z59g5~DEo8u#p1g3ixiiS^9gr(|IxSh4t=nn;@WUq5^(Z25?rED%1^84#6*tEvN)fJ ze+q@pz5&c8A6J)D6GuL;LL*_tY&NfeH_PQs$+0PFGkwDp;Uel?YNx`adc5b. */ + +#ifndef _BITS_TYPES___LOCALE_T_H +#define _BITS_TYPES___LOCALE_T_H 1 + +/* POSIX.1-2008: the locale_t type, representing a locale context + (implementation-namespace version). This type should be treated + as opaque by applications; some details are exposed for the sake of + efficiency in e.g. ctype functions. */ + +struct __locale_struct { + /* Note: LC_ALL is not a valid index into this array. */ + struct __locale_data *__locales[13]; /* 13 = __LC_LAST. */ + + /* To increase the speed of this solution we add some special members. */ + const unsigned short int *__ctype_b; + const int *__ctype_tolower; + const int *__ctype_toupper; + + /* Note: LC_ALL is not a valid index into this array. */ + const char *__names[13]; +}; + +typedef struct __locale_struct *__locale_t; + +#endif /* bits/types/__locale_t.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types@__locale_t.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types@__locale_t.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..0663b492bde8bb30993fe11d22166e32e6f4739f GIT binary patch literal 1835 zcmbVM&u<%55Po(|TjgM?Mx|ikXp#~XBCpqOBFl1Hm9#{nAxbO72wH?z&%0y$HS2xb z_ueKp5h4eU2rfN>gy5gxj*vLCH!hqxfslHn2V66|{y}MMe(hnkyYuFoZ@zD4SJ{)o zCx;IiV|H71&~EcR+rxcZukG2Pl6TQHnm%-7ppD{2Dw~I4+3s)=6kT@0^?A_xU#ZrC zRC^+5S)Nc-M5^AE;|y5VjNps8`z1U3Em7|SxEgO&BEkR%m# zHa-7XxrQKxV=yf~z!`9!YlR9&?fr8H2_%W;T5aSWDoY!#%na<9>eSE-ro9lg?Ms*Y z=uF2vmYAq&qQ-ww#Fz1G$f)5@7iD%4YlbVwG7_0+485n7r%gx?HY@tm%U3_zA|oT$ zfa8q%^|;|Io6XUoTmXgSxyHbdLBK~*aAjbyYvxu&C-kvHVQz#Btbo%5 zh1^BhN2Te@Yej&1Tj&H0bX!Kg2Mq+HXdBR*;~Heh??niW9?(+z!cCC$CD8OI01pip zz6P!kup3H^9yFy&m}kT{_m`e!f;~cQf?`+aw)Skw({%y zFP(WX|M&~%+Ku|IQ@?#{bJrmrH?MDOZ#s47O|rXmfqtbTK$vv~$}}ePXXal|$M-kb IAfCKG0CUrTtpET3 literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types@locale_t.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types@locale_t.h new file mode 100644 index 00000000..0ebc9f08 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types@locale_t.h @@ -0,0 +1,26 @@ +/* Definition of locale_t. + Copyright (C) 2017-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _BITS_TYPES_LOCALE_T_H +#define _BITS_TYPES_LOCALE_T_H 1 + +#include + +typedef __locale_t locale_t; + +#endif /* bits/types/locale_t.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types@locale_t.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@types@locale_t.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..dca1f2eb761a8e8dc899a22baa3487ff3df64e98 GIT binary patch literal 933 zcmbVLPfNov9L@AD!oI-3+gKWlrFc;A4+DjP!gkP8NYiYMOPi9UbJH*2!JFSeJo+^} zdf(X(vYA!~N?S!QA>{Xa@BQ9O(gusp{p~9N07WupC?aDNvI){VW0Wd+#i-HtAeMr{|r^e-s9mTJtC5e&JqB2vxv%M*YNlxc+o50DU(7`k4uFI181 zIopnpctS-MGNeryvY``!#p7-KQs7plAtNSJOy|Yi?YH7|*T=pG1y8am93>gjGmWUF zs%~F#LBnI_dzF+nD(kEoUy=*BO*kjh{D#%gg%qZWecJooK|yIlqcCD5WD06Sl&Rs) zN3ATCCN07-S@0KQLgrU2vp`gPs~3Sa;g%2|0nSpU5ynDNA{eeVTMe}jG5nf+qy6*y zsME85sIh#WKRnGZ?%wdx>7b7Xm*?F+?wuVU_PTh0Pi#wP%U&Z-SgX3DX KUk|{tVKMJfu2Zl8 literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@typesizes.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@typesizes.h new file mode 100644 index 00000000..29bf6409 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@typesizes.h @@ -0,0 +1,108 @@ +/* bits/typesizes.h -- underlying types for *_t. Linux/x86-64 version. + Copyright (C) 2012-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _BITS_TYPES_H +#error "Never include directly; use instead." +#endif + +#ifndef _BITS_TYPESIZES_H +#define _BITS_TYPESIZES_H 1 + +/* See for the meaning of these macros. This file exists so + that need not vary across different GNU platforms. */ + +/* X32 kernel interface is 64-bit. */ +#if defined __x86_64__ && defined __ILP32__ +#define __SYSCALL_SLONG_TYPE __SQUAD_TYPE +#define __SYSCALL_ULONG_TYPE __UQUAD_TYPE +#else +#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE +#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE +#endif + +#define __DEV_T_TYPE __UQUAD_TYPE +#define __UID_T_TYPE __U32_TYPE +#define __GID_T_TYPE __U32_TYPE +#define __INO_T_TYPE __SYSCALL_ULONG_TYPE +#define __INO64_T_TYPE __UQUAD_TYPE +#define __MODE_T_TYPE __U32_TYPE +#ifdef __x86_64__ +#define __NLINK_T_TYPE __SYSCALL_ULONG_TYPE +#define __FSWORD_T_TYPE __SYSCALL_SLONG_TYPE +#else +#define __NLINK_T_TYPE __UWORD_TYPE +#define __FSWORD_T_TYPE __SWORD_TYPE +#endif +#define __OFF_T_TYPE __SYSCALL_SLONG_TYPE +#define __OFF64_T_TYPE __SQUAD_TYPE +#define __PID_T_TYPE __S32_TYPE +#define __RLIM_T_TYPE __SYSCALL_ULONG_TYPE +#define __RLIM64_T_TYPE __UQUAD_TYPE +#define __BLKCNT_T_TYPE __SYSCALL_SLONG_TYPE +#define __BLKCNT64_T_TYPE __SQUAD_TYPE +#define __FSBLKCNT_T_TYPE __SYSCALL_ULONG_TYPE +#define __FSBLKCNT64_T_TYPE __UQUAD_TYPE +#define __FSFILCNT_T_TYPE __SYSCALL_ULONG_TYPE +#define __FSFILCNT64_T_TYPE __UQUAD_TYPE +#define __ID_T_TYPE __U32_TYPE +#define __CLOCK_T_TYPE __SYSCALL_SLONG_TYPE +#define __TIME_T_TYPE __SYSCALL_SLONG_TYPE +#define __USECONDS_T_TYPE __U32_TYPE +#define __SUSECONDS_T_TYPE __SYSCALL_SLONG_TYPE +#define __SUSECONDS64_T_TYPE __SQUAD_TYPE +#define __DADDR_T_TYPE __S32_TYPE +#define __KEY_T_TYPE __S32_TYPE +#define __CLOCKID_T_TYPE __S32_TYPE +#define __TIMER_T_TYPE void * +#define __BLKSIZE_T_TYPE __SYSCALL_SLONG_TYPE +#define __FSID_T_TYPE \ + struct { \ + int __val[2]; \ + } +#define __SSIZE_T_TYPE __SWORD_TYPE +#define __CPU_MASK_TYPE __SYSCALL_ULONG_TYPE + +#ifdef __x86_64__ +/* Tell the libc code that off_t and off64_t are actually the same type + for all ABI purposes, even if possibly expressed as different base types + for C type-checking purposes. */ +#define __OFF_T_MATCHES_OFF64_T 1 + +/* Same for ino_t and ino64_t. */ +#define __INO_T_MATCHES_INO64_T 1 + +/* And for __rlim_t and __rlim64_t. */ +#define __RLIM_T_MATCHES_RLIM64_T 1 + +/* And for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t. */ +#define __STATFS_MATCHES_STATFS64 1 + +/* And for getitimer, setitimer and rusage */ +#define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 1 +#else +#define __RLIM_T_MATCHES_RLIM64_T 0 + +#define __STATFS_MATCHES_STATFS64 0 + +#define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 0 +#endif + +/* Number of descriptors that can fit in an `fd_set'. */ +#define __FD_SETSIZE 1024 + +#endif /* bits/typesizes.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@typesizes.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@typesizes.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..0a9535605dc03fd366bf860db5068de3230a666d GIT binary patch literal 5156 zcmbVP4QyLi6@Jfc6ATf%xS=hh6enB$JpadWoWx0<H$m6b9TM8mny@A}>6 zI8#cbe6ruU@7(X6^PO{#b=)2OmliH?9A`>qXA`DmY?o;&vD=hy-DR4~Wp^gxg*-f% z&1Uk2T&$4Inc}&AfGmeEW?L z4?huPzA!&oSq>|(&yvc?&QGS5F2FP|xz#W5eVu(H0`IUn zf&#yE;l_b~?Rfn8OQl8dVO@j1!6Wc3<`!6Ox7r5;zSGee7I>$_3AmK4$=&<;r#3HO z?DOD=HyR0S^}=hL?gP=JG6^mFT&=d4tu~J1r_pq?ilB{K;$iiY=HPD|wE@*@7!P_! zhP^=?3VLufFytL`1@Vw8>h^mh^t&BAa6#GsYTnRVVAl!F#C8?INoiNB$?(R5r`* zSc_T>D?b++fg_9S_y7v%RRsN#$EMlfr2o?a8$>e_fMwL-y|P2bpjN}RG9NE!7qn0- zkb>Q@^uyL|UE0ThtsnVyDuUZ3-QiagF4_PnrjNQSIdytI-LsV%aL|d(to)>w69-vQh`Qm|vzy9~0a~G%rq&zX|EvB737qe99 z&{kvxH3LQ^uZy+$)6qZP=!T4!{?^*`HbLOsW;axmNAH2pUaQv!6}0%-|GaPSI&>4` z;b35RuwsZ<3(I4a4ZdEZH>!9*8vO8|erhR8~%ilY3a?qPz_1jwXKJ5(_LI>aYe@?j zm#H$Tke`bokkjfx9!LP7Ao;p=_RLUKt$j|EbQ#HdnPk}sh*sFsJCMVw;sJw_+wX6` z`1s86r!R}~tVj`}DLr2?OUST9;P)horE!nijV`XLptakfPGR# zj{JN2_TiT%Z)4ogmLroi`FWYICe#FR0HjHKy5XH1`tHju7<*hE4{Zn#4Cbt?MLes_ z&5hh}Qb5{;k1ZZr+<7|i5zzDs+~ntF+!|3Ma08^=P6>(_3*pvY0c9DqAboDEZ95D^+Y@)-~!I zp}jTfn*eo2U7x^r>$-acUa$!yU_(C%n+E@W-cUITT(cat%kJ7P@cq{QtpeX}Z3i@14S-93FFUp>H2M+pq@Qii&L4z-3lu14Ra1$YoRUfOIIEE3|6{s$YjHjYM5hU!*jf z7Qc!!u$9@T@*=G`_l|4EJt`iMwt(YDUUluS+wefKtpIU4VbfLu)yz02Pb(}EXWuc+ z82ARH_sgr#-Owj*z5~;w^qLfNM$(LdRfa-yZKw?-4M-*Zsqa*!fB8z&N!%BRLaZT? zWK@k{KX8>LU2YUPZbTbFzkqg0Wo;8rUA}bS(iu7)$f;wLQ5+5=6U$SPxOUVI$^fLw z*pDr#ue%qH$`g|8UFKODpQ!)J4T$eR9Y7tBmfi<1ZmE7?XUki31fiLe#yAKD^OL1G zjg&1BLlV(M;3o?p?c+bcb@319AM4m6cMSHnQ4Ds)hEg(JGg!mXsfKO6dEWuDxC^QfQSN8 z!9Jhdq0W5yXb60i{`h)lJ?YO!Yt+|AzREwxlzHjgu$aB6D5H{{lsX%iKGf$>@qi=6 G)BFz$?*XR( literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wchar.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wchar.h new file mode 100644 index 00000000..404a3e07 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wchar.h @@ -0,0 +1,49 @@ +/* wchar_t type related definitions. + Copyright (C) 2000-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _BITS_WCHAR_H +#define _BITS_WCHAR_H 1 + +/* The fallback definitions, for when __WCHAR_MAX__ or __WCHAR_MIN__ + are not defined, give the right value and type as long as both int + and wchar_t are 32-bit types. Adding L'\0' to a constant value + ensures that the type is correct; it is necessary to use (L'\0' + + 0) rather than just L'\0' so that the type in C++ is the promoted + version of wchar_t rather than the distinct wchar_t type itself. + Because wchar_t in preprocessor #if expressions is treated as + intmax_t or uintmax_t, the expression (L'\0' - 1) would have the + wrong value for WCHAR_MAX in such expressions and so cannot be used + to define __WCHAR_MAX in the unsigned case. */ + +#ifdef __WCHAR_MAX__ +#define __WCHAR_MAX __WCHAR_MAX__ +#elif L'\0' - 1 > 0 +#define __WCHAR_MAX (0xffffffffu + L'\0') +#else +#define __WCHAR_MAX (0x7fffffff + L'\0') +#endif + +#ifdef __WCHAR_MIN__ +#define __WCHAR_MIN __WCHAR_MIN__ +#elif L'\0' - 1 > 0 +#define __WCHAR_MIN (L'\0' + 0) +#else +#define __WCHAR_MIN (-__WCHAR_MAX - 1) +#endif + +#endif /* bits/wchar.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wchar.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wchar.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..115776a1415fafb8c1b452acaf3e0ee76058be30 GIT binary patch literal 1387 zcmbVMzi-n(6uzbc5yXI6#DEY=K|-PG`7lILhccuvv;&p+A?U>EVqcOY=W}#-ZWB7e z3}R$qV&NZPVMc6FAu*u-39M`^4bQGyIl@6#20z*N-uJ!l{Wve8{iT;XUlBs27e}1* zSf7M^iOoe>^gJ=S}v5u@F=$`vcBi2EG>4m(tjzT|VCO^^tLUd*Y-mCwt-~j?#nsLL)Y$ zOp30eS&463d#+Nk>+WV#hwB~|$A>DH(bY3`v~(Jw+41hri>oK^?R}^8@$I$NeR_9& z1Aa^AufRNo;(AD*a4|0KPz;@wCUeQtYfn)yc{9+}w-T}uSL7?m* literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wordsize.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wordsize.h new file mode 100644 index 00000000..396ec03b --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wordsize.h @@ -0,0 +1,16 @@ +/* Determine the wordsize from the preprocessor defines. */ + +#if defined __x86_64__ && !defined __ILP32__ +#define __WORDSIZE 64 +#else +#define __WORDSIZE 32 +#define __WORDSIZE32_SIZE_ULONG 0 +#define __WORDSIZE32_PTRDIFF_LONG 0 +#endif + +#define __WORDSIZE_TIME64_COMPAT32 1 + +#ifdef __x86_64__ +/* Both x86-64 and x32 use the 64-bit system call interface. */ +#define __SYSCALL_WORDSIZE 64 +#endif diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wordsize.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@bits@wordsize.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..eec245f45d563377d07ab1b3ca062a892a69a6a2 GIT binary patch literal 1099 zcmbW0F;5#Y7>0cbLqRQ6h#wHCRfh`4q#P%Pwg>?dNJLa55~7QB@i~c!&yH*#kfJUf znD`Z4tEy}NK*v^Hx^&?mbm+!HurEMp?lP3cXWi%bdB5-V-E(j`e|GX60D#&url=iu zP(%-rUhJT*k_VI+ZC}JvXrn?S6|!5FK0_wT1QZDmMeDw5cqCPai585QvQ|>{US<0L zGbqstan?YbAI7lar~A|xRs8ZoIY3MhogN-@!rnvdTs0NhW+E7KC!pL1TAH&laqlDfHyrm9TeR98uUG@=r4V#*B`CC zKgG8kT;Hm01U_EdslHjQFTSv+{2}+oZS+*BV(C+lr`8K@-Mps%{zd=(IsIH6(k*Q+ SOB*y-oGm^pcy^s1$gcp83xOyA literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs-64.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs-64.h new file mode 100644 index 00000000..285457c7 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs-64.h @@ -0,0 +1,17 @@ +/* This file is automatically generated. + It defines a symbol `__stub_FUNCTION' for each function + in the C library which is a stub, meaning it will fail + every time called, usually setting errno to ENOSYS. */ + +#ifdef _LIBC +#error Applications may not define the macro _LIBC +#endif + +#define __stub___compat_bdflush +#define __stub_chflags +#define __stub_fchflags +#define __stub_gtty +#define __stub_revoke +#define __stub_setlogin +#define __stub_sigreturn +#define __stub_stty diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs-64.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs-64.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..54435a49e04e300c33e8220ccf3771cbd0cd3d51 GIT binary patch literal 1419 zcmbW0&ui2`6vrnK(YD*&oO+NV1)+zf$+WsG9<+aeh*t%{kWD7ZbSIf*X0q+Jcq#N! zdQ*B6#7mD-z1dsAqvE0B#Xmq?@gESnPG++|OwvQWybSZ^`+48@W>N>|D+fED001zg z5rU!9h92rdey0sPjBX%TaJdoDm<#3z%Aj0g^>uJ;x!{URoH+PjwYf=I8^?j^VJ1sa z*1KQy0ctSe3=-Uegmfcwt)bScFkEX`t5y@@*d>XFAQzs8d@BU!Z+4=ON;gXR$Po!c zJWZxO7Ymg)?9$lBL8|()d++l<$gR6gyV)=aj*~4jh!erVkQ?36Bn>ktEH)O ztmt(RhlIKgL3TN_AXHNoN$WBbAvAqaG-;9Yp%jV?=cwG-_T~I3seHxW^c4W@D!5hw z;QC-;n|=-VU!K@Dmrd9l2Mozq7|S1S>6W|{9HXUTPOBNURb53e(B#>{wUgnxrgDlRxv8lLmD&n;oDR5!S}~UnVO+4Z6oR6M$W+~q0JlfbzQ}bu>3lH@&35_ zC?oi8=o2U4C0$HX+MF>byGUb3S>HQ7_;vKNpHU`|#hj6GMw>NeS9BFK#_jq(;jhl3 gjA7d@jXI97Tb@r69!f`64puy(%@{N5x{5>UUoM*SlmGw# literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs.h new file mode 100644 index 00000000..eca396ff --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs.h @@ -0,0 +1,13 @@ +/* This file is automatically generated. + This file selects the right generated file of `__stub_FUNCTION' macros + based on the architecture being compiled for. */ + +#if !defined __x86_64__ +#include +#endif +#if defined __x86_64__ && defined __LP64__ +#include +#endif +#if defined __x86_64__ && defined __ILP32__ +#include +#endif diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@gnu@stubs.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..6ec25b2968e4f9682ccf27a41a782bb03de310a2 GIT binary patch literal 916 zcmbVLOHRWu5H%pgf+8f2fpCV3C}II;i5%NaOdPxNr?hm(np1EWmLN`4VTWI7Tozr$ z%J_Ze&G;OxE}oXJ2q9>6$DtuDFg^o&)xy;1J5HSqKRT_fGsI~F;VAkq5h|nTfJ&n3 zUD5bnn^veAGhu?1HjCS#4|EFN8jzv_DQ6uX=l!`ChH;)vFD*sx?!r-MAQ-W{&@5DhjM;hltqrEP=1bU<-sm2&|u(KBs$-8 zfSu@gk^dN3zY}5(d8F|Jxk`lTL^3NL_!c@w@zn6IQ2M^t<. */ + +#ifndef _SYS_CDEFS_H +#define _SYS_CDEFS_H 1 + +/* We are almost always included from features.h. */ +#ifndef _FEATURES_H +#include +#endif + +/* The GNU libc does not support any K&R compilers or the traditional mode + of ISO C compilers anymore. Check for some of the combinations not + supported anymore. */ +#if defined __GNUC__ && !defined __STDC__ && !defined __cplusplus +#error "You need a ISO C or C++ conforming compiler to use the glibc headers" +#endif + +/* Some user header file might have defined this before. */ +#undef __P +#undef __PMT + +/* Compilers that lack __has_attribute may object to + #if defined __has_attribute && __has_attribute (...) + even though they do not need to evaluate the right-hand side of the &&. + Similarly for __has_builtin, etc. */ +#if (defined __has_attribute && (!defined __clang_minor__ || 3 < __clang_major__ + (5 <= __clang_minor__))) +#define __glibc_has_attribute(attr) __has_attribute(attr) +#else +#define __glibc_has_attribute(attr) 0 +#endif +#ifdef __has_builtin +#define __glibc_has_builtin(name) __has_builtin(name) +#else +#define __glibc_has_builtin(name) 0 +#endif +#ifdef __has_extension +#define __glibc_has_extension(ext) __has_extension(ext) +#else +#define __glibc_has_extension(ext) 0 +#endif + +#if defined __GNUC__ || defined __clang__ + +/* All functions, except those with callbacks or those that + synchronize memory, are leaf functions. */ +#if __GNUC_PREREQ(4, 6) && !defined _LIBC +#define __LEAF , __leaf__ +#define __LEAF_ATTR __attribute__((__leaf__)) +#else +#define __LEAF +#define __LEAF_ATTR +#endif + +/* GCC can always grok prototypes. For C++ programs we add throw() + to help it optimize the function calls. But this only works with + gcc 2.8.x and egcs. For gcc 3.4 and up we even mark C functions + as non-throwing using a function attribute since programs can use + the -fexceptions options for C code as well. */ +#if !defined __cplusplus && (__GNUC_PREREQ(3, 4) || __glibc_has_attribute(__nothrow__)) +#define __THROW __attribute__((__nothrow__ __LEAF)) +#define __THROWNL __attribute__((__nothrow__)) +#define __NTH(fct) __attribute__((__nothrow__ __LEAF)) fct +#define __NTHNL(fct) __attribute__((__nothrow__)) fct +#else +#if defined __cplusplus && (__GNUC_PREREQ(2, 8) || __clang_major >= 4) +#if __cplusplus >= 201103L +#define __THROW noexcept(true) +#else +#define __THROW throw() +#endif +#define __THROWNL __THROW +#define __NTH(fct) __LEAF_ATTR fct __THROW +#define __NTHNL(fct) fct __THROW +#else +#define __THROW +#define __THROWNL +#define __NTH(fct) fct +#define __NTHNL(fct) fct +#endif +#endif + +#else /* Not GCC or clang. */ + +#if (defined __cplusplus || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)) +#define __inline inline +#else +#define __inline /* No inline functions. */ +#endif + +#define __THROW +#define __THROWNL +#define __NTH(fct) fct + +#endif /* GCC || clang. */ + +/* These two macros are not used in glibc anymore. They are kept here + only because some other projects expect the macros to be defined. */ +#define __P(args) args +#define __PMT(args) args + +/* For these things, GCC behaves the ANSI way normally, + and the non-ANSI way under -traditional. */ + +#define __CONCAT(x, y) x##y +#define __STRING(x) #x + +/* This is not a typedef so `const __ptr_t' does the right thing. */ +#define __ptr_t void * + +/* C++ needs to know that types and declarations are C, not C++. */ +#ifdef __cplusplus +#define __BEGIN_DECLS extern "C" { +#define __END_DECLS } +#else +#define __BEGIN_DECLS +#define __END_DECLS +#endif + +/* Fortify support. */ +#define __bos(ptr) __builtin_object_size(ptr, __USE_FORTIFY_LEVEL > 1) +#define __bos0(ptr) __builtin_object_size(ptr, 0) + +/* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available. */ +#if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq(9, 0) || __GNUC_PREREQ(12, 0)) +#define __glibc_objsize0(__o) __builtin_dynamic_object_size(__o, 0) +#define __glibc_objsize(__o) __builtin_dynamic_object_size(__o, 1) +#else +#define __glibc_objsize0(__o) __bos0(__o) +#define __glibc_objsize(__o) __bos(__o) +#endif + +#if __USE_FORTIFY_LEVEL > 0 +/* Compile time conditions to choose between the regular, _chk and _chk_warn + variants. These conditions should get evaluated to constant and optimized + away. */ + +#define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s)) +#define __glibc_unsigned_or_positive(__l) \ + ((__typeof(__l))0 < (__typeof(__l))-1 || (__builtin_constant_p(__l) && (__l) > 0)) + +/* Length is known to be safe at compile time if the __L * __S <= __OBJSZ + condition can be folded to a constant and if it is true, or unknown (-1) */ +#define __glibc_safe_or_unknown_len(__l, __s, __osz) \ + ((__builtin_constant_p(__osz) && (__osz) == (__SIZE_TYPE__)-1) \ + || (__glibc_unsigned_or_positive(__l) \ + && __builtin_constant_p(__glibc_safe_len_cond((__SIZE_TYPE__)(__l), (__s), (__osz))) \ + && __glibc_safe_len_cond((__SIZE_TYPE__)(__l), (__s), (__osz)))) + +/* Conversely, we know at compile time that the length is unsafe if the + __L * __S <= __OBJSZ condition can be folded to a constant and if it is + false. */ +#define __glibc_unsafe_len(__l, __s, __osz) \ + (__glibc_unsigned_or_positive(__l) \ + && __builtin_constant_p(__glibc_safe_len_cond((__SIZE_TYPE__)(__l), __s, __osz)) \ + && !__glibc_safe_len_cond((__SIZE_TYPE__)(__l), __s, __osz)) + +/* Fortify function f. __f_alias, __f_chk and __f_chk_warn must be + declared. */ + +#define __glibc_fortify(f, __l, __s, __osz, ...) \ + (__glibc_safe_or_unknown_len(__l, __s, __osz) ? \ + __##f##_alias(__VA_ARGS__) : \ + (__glibc_unsafe_len(__l, __s, __osz) ? __##f##_chk_warn(__VA_ARGS__, __osz) : \ + __##f##_chk(__VA_ARGS__, __osz))) + +/* Fortify function f, where object size argument passed to f is the number of + elements and not total size. */ + +#define __glibc_fortify_n(f, __l, __s, __osz, ...) \ + (__glibc_safe_or_unknown_len(__l, __s, __osz) ? \ + __##f##_alias(__VA_ARGS__) : \ + (__glibc_unsafe_len(__l, __s, __osz) ? __##f##_chk_warn(__VA_ARGS__, (__osz) / (__s)) : \ + __##f##_chk(__VA_ARGS__, (__osz) / (__s)))) +#endif + +#if __GNUC_PREREQ(4, 3) +#define __warnattr(msg) __attribute__((__warning__(msg))) +#define __errordecl(name, msg) extern void name(void) __attribute__((__error__(msg))) +#else +#define __warnattr(msg) +#define __errordecl(name, msg) extern void name(void) +#endif + +/* Support for flexible arrays. + Headers that should use flexible arrays only if they're "real" + (e.g. only if they won't affect sizeof()) should test + #if __glibc_c99_flexarr_available. */ +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc +#define __flexarr [] +#define __glibc_c99_flexarr_available 1 +#elif __GNUC_PREREQ(2, 97) || defined __clang__ +/* GCC 2.97 and clang support C99 flexible array members as an extension, + even when in C89 mode or compiling C++ (any version). */ +#define __flexarr [] +#define __glibc_c99_flexarr_available 1 +#elif defined __GNUC__ +/* Pre-2.97 GCC did not support C99 flexible arrays but did have + an equivalent extension with slightly different notation. */ +#define __flexarr [0] +#define __glibc_c99_flexarr_available 1 +#else +/* Some other non-C99 compiler. Approximate with [1]. */ +#define __flexarr [1] +#define __glibc_c99_flexarr_available 0 +#endif + +/* __asm__ ("xyz") is used throughout the headers to rename functions + at the assembly language level. This is wrapped by the __REDIRECT + macro, in order to support compilers that can do this some other + way. When compilers don't support asm-names at all, we have to do + preprocessor tricks instead (which don't have exactly the right + semantics, but it's the best we can do). + + Example: + int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */ + +#if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4) + +#define __REDIRECT(name, proto, alias) name proto __asm__(__ASMNAME(#alias)) +#ifdef __cplusplus +#define __REDIRECT_NTH(name, proto, alias) name proto __THROW __asm__(__ASMNAME(#alias)) +#define __REDIRECT_NTHNL(name, proto, alias) name proto __THROWNL __asm__(__ASMNAME(#alias)) +#else +#define __REDIRECT_NTH(name, proto, alias) name proto __asm__(__ASMNAME(#alias)) __THROW +#define __REDIRECT_NTHNL(name, proto, alias) name proto __asm__(__ASMNAME(#alias)) __THROWNL +#endif +#define __ASMNAME(cname) __ASMNAME2(__USER_LABEL_PREFIX__, cname) +#define __ASMNAME2(prefix, cname) __STRING(prefix) cname + +/* +#elif __SOME_OTHER_COMPILER__ + +# define __REDIRECT(name, proto, alias) name proto; \ + _Pragma("let " #name " = " #alias) +*/ +#endif + +/* GCC and clang have various useful declarations that can be made with + the '__attribute__' syntax. All of the ways we use this do fine if + they are omitted for compilers that don't understand it. */ +#if !(defined __GNUC__ || defined __clang__) +#define __attribute__(xyz) /* Ignore */ +#endif + +/* At some point during the gcc 2.96 development the `malloc' attribute + for functions was introduced. We don't want to use it unconditionally + (although this would be possible) since it generates warnings. */ +#if __GNUC_PREREQ(2, 96) || __glibc_has_attribute(__malloc__) +#define __attribute_malloc__ __attribute__((__malloc__)) +#else +#define __attribute_malloc__ /* Ignore */ +#endif + +/* Tell the compiler which arguments to an allocation function + indicate the size of the allocation. */ +#if __GNUC_PREREQ(4, 3) +#define __attribute_alloc_size__(params) __attribute__((__alloc_size__ params)) +#else +#define __attribute_alloc_size__(params) /* Ignore. */ +#endif + +/* Tell the compiler which argument to an allocation function + indicates the alignment of the allocation. */ +#if __GNUC_PREREQ(4, 9) || __glibc_has_attribute(__alloc_align__) +#define __attribute_alloc_align__(param) __attribute__((__alloc_align__ param)) +#else +#define __attribute_alloc_align__(param) /* Ignore. */ +#endif + +/* At some point during the gcc 2.96 development the `pure' attribute + for functions was introduced. We don't want to use it unconditionally + (although this would be possible) since it generates warnings. */ +#if __GNUC_PREREQ(2, 96) || __glibc_has_attribute(__pure__) +#define __attribute_pure__ __attribute__((__pure__)) +#else +#define __attribute_pure__ /* Ignore */ +#endif + +/* This declaration tells the compiler that the value is constant. */ +#if __GNUC_PREREQ(2, 5) || __glibc_has_attribute(__const__) +#define __attribute_const__ __attribute__((__const__)) +#else +#define __attribute_const__ /* Ignore */ +#endif + +#if __GNUC_PREREQ(2, 7) || __glibc_has_attribute(__unused__) +#define __attribute_maybe_unused__ __attribute__((__unused__)) +#else +#define __attribute_maybe_unused__ /* Ignore */ +#endif + +/* At some point during the gcc 3.1 development the `used' attribute + for functions was introduced. We don't want to use it unconditionally + (although this would be possible) since it generates warnings. */ +#if __GNUC_PREREQ(3, 1) || __glibc_has_attribute(__used__) +#define __attribute_used__ __attribute__((__used__)) +#define __attribute_noinline__ __attribute__((__noinline__)) +#else +#define __attribute_used__ __attribute__((__unused__)) +#define __attribute_noinline__ /* Ignore */ +#endif + +/* Since version 3.2, gcc allows marking deprecated functions. */ +#if __GNUC_PREREQ(3, 2) || __glibc_has_attribute(__deprecated__) +#define __attribute_deprecated__ __attribute__((__deprecated__)) +#else +#define __attribute_deprecated__ /* Ignore */ +#endif + +/* Since version 4.5, gcc also allows one to specify the message printed + when a deprecated function is used. clang claims to be gcc 4.2, but + may also support this feature. */ +#if __GNUC_PREREQ(4, 5) || __glibc_has_extension(__attribute_deprecated_with_message__) +#define __attribute_deprecated_msg__(msg) __attribute__((__deprecated__(msg))) +#else +#define __attribute_deprecated_msg__(msg) __attribute_deprecated__ +#endif + +/* At some point during the gcc 2.8 development the `format_arg' attribute + for functions was introduced. We don't want to use it unconditionally + (although this would be possible) since it generates warnings. + If several `format_arg' attributes are given for the same function, in + gcc-3.0 and older, all but the last one are ignored. In newer gccs, + all designated arguments are considered. */ +#if __GNUC_PREREQ(2, 8) || __glibc_has_attribute(__format_arg__) +#define __attribute_format_arg__(x) __attribute__((__format_arg__(x))) +#else +#define __attribute_format_arg__(x) /* Ignore */ +#endif + +/* At some point during the gcc 2.97 development the `strfmon' format + attribute for functions was introduced. We don't want to use it + unconditionally (although this would be possible) since it + generates warnings. */ +#if __GNUC_PREREQ(2, 97) || __glibc_has_attribute(__format__) +#define __attribute_format_strfmon__(a, b) __attribute__((__format__(__strfmon__, a, b))) +#else +#define __attribute_format_strfmon__(a, b) /* Ignore */ +#endif + +/* The nonnull function attribute marks pointer parameters that + must not be NULL. This has the name __nonnull in glibc, + and __attribute_nonnull__ in files shared with Gnulib to avoid + collision with a different __nonnull in DragonFlyBSD 5.9. */ +#ifndef __attribute_nonnull__ +#if __GNUC_PREREQ(3, 3) || __glibc_has_attribute(__nonnull__) +#define __attribute_nonnull__(params) __attribute__((__nonnull__ params)) +#else +#define __attribute_nonnull__(params) +#endif +#endif +#ifndef __nonnull +#define __nonnull(params) __attribute_nonnull__(params) +#endif + +/* The returns_nonnull function attribute marks the return type of the function + as always being non-null. */ +#ifndef __returns_nonnull +#if __GNUC_PREREQ(4, 9) || __glibc_has_attribute(__returns_nonnull__) +#define __returns_nonnull __attribute__((__returns_nonnull__)) +#else +#define __returns_nonnull +#endif +#endif + +/* If fortification mode, we warn about unused results of certain + function calls which can lead to problems. */ +#if __GNUC_PREREQ(3, 4) || __glibc_has_attribute(__warn_unused_result__) +#define __attribute_warn_unused_result__ __attribute__((__warn_unused_result__)) +#if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0 +#define __wur __attribute_warn_unused_result__ +#endif +#else +#define __attribute_warn_unused_result__ /* empty */ +#endif +#ifndef __wur +#define __wur /* Ignore */ +#endif + +/* Forces a function to be always inlined. */ +#if __GNUC_PREREQ(3, 2) || __glibc_has_attribute(__always_inline__) +/* The Linux kernel defines __always_inline in stddef.h (283d7573), and + it conflicts with this definition. Therefore undefine it first to + allow either header to be included first. */ +#undef __always_inline +#define __always_inline __inline __attribute__((__always_inline__)) +#else +#undef __always_inline +#define __always_inline __inline +#endif + +/* Associate error messages with the source location of the call site rather + than with the source location inside the function. */ +#if __GNUC_PREREQ(4, 3) || __glibc_has_attribute(__artificial__) +#define __attribute_artificial__ __attribute__((__artificial__)) +#else +#define __attribute_artificial__ /* Ignore */ +#endif + +/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 + inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__ + or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions + older than 4.3 may define these macros and still not guarantee GNU inlining + semantics. + + clang++ identifies itself as gcc-4.2, but has support for GNU inlining + semantics, that can be checked for by using the __GNUC_STDC_INLINE_ and + __GNUC_GNU_INLINE__ macro definitions. */ +#if (!defined __cplusplus || __GNUC_PREREQ(4, 3) \ + || (defined __clang__ && (defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__))) +#if defined __GNUC_STDC_INLINE__ || defined __cplusplus +#define __extern_inline extern __inline __attribute__((__gnu_inline__)) +#define __extern_always_inline extern __always_inline __attribute__((__gnu_inline__)) +#else +#define __extern_inline extern __inline +#define __extern_always_inline extern __always_inline +#endif +#endif + +#ifdef __extern_always_inline +#define __fortify_function __extern_always_inline __attribute_artificial__ +#endif + +/* GCC 4.3 and above allow passing all anonymous arguments of an + __extern_always_inline function to some other vararg function. */ +#if __GNUC_PREREQ(4, 3) +#define __va_arg_pack() __builtin_va_arg_pack() +#define __va_arg_pack_len() __builtin_va_arg_pack_len() +#endif + +/* It is possible to compile containing GCC extensions even if GCC is + run in pedantic mode if the uses are carefully marked using the + `__extension__' keyword. But this is not generally available before + version 2.8. */ +#if !(__GNUC_PREREQ(2, 8) || defined __clang__) +#define __extension__ /* Ignore */ +#endif + +/* __restrict is known in EGCS 1.2 and above, and in clang. + It works also in C++ mode (outside of arrays), but only when spelled + as '__restrict', not 'restrict'. */ +#if !(__GNUC_PREREQ(2, 92) || __clang_major__ >= 3) +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L +#define __restrict restrict +#else +#define __restrict /* Ignore */ +#endif +#endif + +/* ISO C99 also allows to declare arrays as non-overlapping. The syntax is + array_name[restrict] + GCC 3.1 and clang support this. + This syntax is not usable in C++ mode. */ +#if (__GNUC_PREREQ(3, 1) || __clang_major__ >= 3) && !defined __cplusplus +#define __restrict_arr __restrict +#else +#ifdef __GNUC__ +#define __restrict_arr /* Not supported in old GCC. */ +#else +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L +#define __restrict_arr restrict +#else +/* Some other non-C99 compiler. */ +#define __restrict_arr /* Not supported. */ +#endif +#endif +#endif + +#if (__GNUC__ >= 3) || __glibc_has_builtin(__builtin_expect) +#define __glibc_unlikely(cond) __builtin_expect((cond), 0) +#define __glibc_likely(cond) __builtin_expect((cond), 1) +#else +#define __glibc_unlikely(cond) (cond) +#define __glibc_likely(cond) (cond) +#endif + +#if (!defined _Noreturn && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \ + && !(__GNUC_PREREQ(4, 7) || (3 < __clang_major__ + (5 <= __clang_minor__)))) +#if __GNUC_PREREQ(2, 8) +#define _Noreturn __attribute__((__noreturn__)) +#else +#define _Noreturn +#endif +#endif + +#if __GNUC_PREREQ(8, 0) +/* Describes a char array whose address can safely be passed as the first + argument to strncpy and strncat, as the char array is not necessarily + a NUL-terminated string. */ +#define __attribute_nonstring__ __attribute__((__nonstring__)) +#else +#define __attribute_nonstring__ +#endif + +/* Undefine (also defined in libc-symbols.h). */ +#undef __attribute_copy__ +#if __GNUC_PREREQ(9, 0) +/* Copies attributes from the declaration or type referenced by + the argument. */ +#define __attribute_copy__(arg) __attribute__((__copy__(arg))) +#else +#define __attribute_copy__(arg) +#endif + +#if (!defined _Static_assert && !defined __cplusplus && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \ + && (!(__GNUC_PREREQ(4, 6) || __clang_major__ >= 4) || defined __STRICT_ANSI__)) +#define _Static_assert(expr, diagnostic) \ + extern int(*__Static_assert_function(void))[!!sizeof(struct { int __error_if_negative : (expr) ? 2 : -1; })] +#endif + +/* Gnulib avoids including these, as they don't work on non-glibc or + older glibc platforms. */ +#ifndef __GNULIB_CDEFS +#include +#include +#endif + +#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 +#ifdef __REDIRECT + +/* Alias name defined automatically. */ +#define __LDBL_REDIR(name, proto) ... unused__ldbl_redir +#define __LDBL_REDIR_DECL(name) extern __typeof(name) name __asm(__ASMNAME("__" #name "ieee128")); + +/* Alias name defined automatically, with leading underscores. */ +#define __LDBL_REDIR2_DECL(name) extern __typeof(__##name) __##name __asm(__ASMNAME("__" #name "ieee128")); + +/* Alias name defined manually. */ +#define __LDBL_REDIR1(name, proto, alias) ... unused__ldbl_redir1 +#define __LDBL_REDIR1_DECL(name, alias) extern __typeof(name) name __asm(__ASMNAME(#alias)); + +#define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH(name, proto, alias) +#define __REDIRECT_NTH_LDBL(name, proto, alias) __LDBL_REDIR1_NTH(name, proto, __##alias##ieee128) + +/* Unused. */ +#define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl +#define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth + +#else +_Static_assert(0, "IEEE 128-bits long double requires redirection on this platform"); +#endif +#elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH +#define __LDBL_COMPAT 1 +#ifdef __REDIRECT +#define __LDBL_REDIR1(name, proto, alias) __REDIRECT(name, proto, alias) +#define __LDBL_REDIR(name, proto) __LDBL_REDIR1(name, proto, __nldbl_##name) +#define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH(name, proto, alias) +#define __LDBL_REDIR_NTH(name, proto) __LDBL_REDIR1_NTH(name, proto, __nldbl_##name) +#define __LDBL_REDIR2_DECL(name) extern __typeof(__##name) __##name __asm(__ASMNAME("__nldbl___" #name)); +#define __LDBL_REDIR1_DECL(name, alias) extern __typeof(name) name __asm(__ASMNAME(#alias)); +#define __LDBL_REDIR_DECL(name) extern __typeof(name) name __asm(__ASMNAME("__nldbl_" #name)); +#define __REDIRECT_LDBL(name, proto, alias) __LDBL_REDIR1(name, proto, __nldbl_##alias) +#define __REDIRECT_NTH_LDBL(name, proto, alias) __LDBL_REDIR1_NTH(name, proto, __nldbl_##alias) +#endif +#endif +#if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0) || !defined __REDIRECT +#define __LDBL_REDIR1(name, proto, alias) name proto +#define __LDBL_REDIR(name, proto) name proto +#define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW +#define __LDBL_REDIR_NTH(name, proto) name proto __THROW +#define __LDBL_REDIR2_DECL(name) +#define __LDBL_REDIR_DECL(name) +#ifdef __REDIRECT +#define __REDIRECT_LDBL(name, proto, alias) __REDIRECT(name, proto, alias) +#define __REDIRECT_NTH_LDBL(name, proto, alias) __REDIRECT_NTH(name, proto, alias) +#endif +#endif + +/* __glibc_macro_warning (MESSAGE) issues warning MESSAGE. This is + intended for use in preprocessor macros. + + Note: MESSAGE must be a _single_ string; concatenation of string + literals is not supported. */ +#if __GNUC_PREREQ(4, 8) || __glibc_clang_prereq(3, 5) +#define __glibc_macro_warning1(message) _Pragma(#message) +#define __glibc_macro_warning(message) __glibc_macro_warning1(GCC warning message) +#else +#define __glibc_macro_warning(msg) +#endif + +/* Generic selection (ISO C11) is a C-only feature, available in GCC + since version 4.9. Previous versions do not provide generic + selection, even though they might set __STDC_VERSION__ to 201112L, + when in -std=c11 mode. Thus, we must check for !defined __GNUC__ + when testing __STDC_VERSION__ for generic selection support. + On the other hand, Clang also defines __GNUC__, so a clang-specific + check is required to enable the use of generic selection. */ +#if !defined __cplusplus \ + && (__GNUC_PREREQ(4, 9) || __glibc_has_extension(c_generic_selections) \ + || (!defined __GNUC__ && defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L)) +#define __HAVE_GENERIC_SELECTION 1 +#else +#define __HAVE_GENERIC_SELECTION 0 +#endif + +#if __GNUC_PREREQ(10, 0) +/* Designates a 1-based positional argument ref-index of pointer type + that can be used to access size-index elements of the pointed-to + array according to access mode, or at least one element when + size-index is not provided: + access (access-mode, [, ]) */ +#define __attr_access(x) __attribute__((__access__ x)) +/* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may + use the access attribute to get object sizes from function definition + arguments, so we can't use them on functions we fortify. Drop the object + size hints for such functions. */ +#if __USE_FORTIFY_LEVEL == 3 +#define __fortified_attr_access(a, o, s) __attribute__((__access__(a, o))) +#else +#define __fortified_attr_access(a, o, s) __attr_access((a, o, s)) +#endif +#if __GNUC_PREREQ(11, 0) +#define __attr_access_none(argno) __attribute__((__access__(__none__, argno))) +#else +#define __attr_access_none(argno) +#endif +#else +#define __fortified_attr_access(a, o, s) +#define __attr_access(x) +#define __attr_access_none(argno) +#endif + +#if __GNUC_PREREQ(11, 0) +/* Designates dealloc as a function to call to deallocate objects + allocated by the declared function. */ +#define __attr_dealloc(dealloc, argno) __attribute__((__malloc__(dealloc, argno))) +#define __attr_dealloc_free __attr_dealloc(__builtin_free, 1) +#else +#define __attr_dealloc(dealloc, argno) +#define __attr_dealloc_free +#endif + +/* Specify that a function such as setjmp or vfork may return + twice. */ +#if __GNUC_PREREQ(4, 1) +#define __attribute_returns_twice__ __attribute__((__returns_twice__)) +#else +#define __attribute_returns_twice__ /* Ignore. */ +#endif + +#endif /* sys/cdefs.h */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@sys@cdefs.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@include@x86_64-linux-gnu@sys@cdefs.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..76492e9a3790918b865812d2aeddec7517cda5e8 GIT binary patch literal 10090 zcmbVS3v^V~xjy?4Fo_XjND*St;khPZl1VV6;hoon1di5kX$vitE-i4^l7-eo?zi_oXU-lt!M3y3 z+5eZbAOB}~Vp=S4@R;_7T+Hz;Uu73(?+@|FC&ET7jO>C9^K zN9+w=n41n3@;>MpU^urct3Bw^v}B5W|B$eqE34V#bbEqXp|CR;9$;)Ls%g~#l6JLw zLUv!k<@9+J^D%GeNYxC5BMtwGMSKD3B7sPQ&)g^jGszlYR&MCQEzk5(lz&Yl))kKI z7AH+sm&e8UiaAH2o7(Wtbci)Y&IoB_(rD@Kq%6svG+D|^`k^#6X|`0HR4X+MbxRNA zuakb1xLMkoxI_Biq!ZHb5H#5%uSC3Z86P zN7Yh4!3h25U(dPPQ?_W0HiFaT@`OT)Kj8PEcKmhY3$<2b=!0^qdQdLF&>WR%Lx(=w z^Zs+?U;JHB8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>GaB$ zUE7f`7%uGgU~_Rf!#FNuv9Q%&V8oVz+p*IR4$BE9!9W-j(Sfc(9u$^gT9%Qym==l@ zQlm*9_w0KMrYo!dXe3AwU)Uh^)W|d``X{p?xW(0!t8jai&*^S|EWNv7`-KM$zWSB6 z5MFiWtjbgZqx*o@*zGuSx3kMxj&^7gT|S z6zk5g9j86gvtTxhAkA?bx%-@cHnUFGn!m)&B~1Ei2X8`V?mJiCf%s3(~Fz&7@7_=ouMM2B8KJy&1I+#sE(l}KuZ{E0cv3=3>0Q)HTI&_1d^YG#LzLM`^V^2624l;{yoJD##}1@Z%O=- z{PO%p)Kz^GZyVDd_qOP9n$O}6uo3^$Gw|MeeLH*$ZW!p2Tx$!zP?YGvxFfS!8niVL zfnP+}E=y4d(T|}kF1|IOrQ{~F|9^Sysp_zw9p3PQST_i|53Rdl5q5-CP~}6g07mU or{W$>J5lq925p3>7gMDl&TbO?Zai8a$AS7d`wYv`Q=I+(11vOI00000 literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@__stddef_max_align_t.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@__stddef_max_align_t.h new file mode 100644 index 00000000..39ae8e0e --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@__stddef_max_align_t.h @@ -0,0 +1,25 @@ +/*===---- __stddef_max_align_t.h - Definition of max_align_t for modules ---=== + * + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + *===-----------------------------------------------------------------------=== + */ + +#ifndef __CLANG_MAX_ALIGN_T_DEFINED +#define __CLANG_MAX_ALIGN_T_DEFINED + +#if defined(_MSC_VER) +typedef double max_align_t; +#elif defined(__APPLE__) +typedef long double max_align_t; +#else +// Define 'max_align_t' to match the GCC definition. +typedef struct { + long long __clang_max_align_nonce1 __attribute__((__aligned__(__alignof__(long long)))); + long double __clang_max_align_nonce2 __attribute__((__aligned__(__alignof__(long double)))); +} max_align_t; +#endif + +#endif diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@__stddef_max_align_t.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@__stddef_max_align_t.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..a610f4ad36297c16a4226b5ca97a70e95161ca8f GIT binary patch literal 844 zcmbVJO=}ZD7@pniL84$tjN6t{20T;)*=gF6Lun5oY12T=K|FXHHnWr6A-gkWcT%mM zt04LhJoy&{DdZcytnZ?A287< ziBZV`PzNKeynJ+i_Uq?2ApMqmUU~5Tao^>F!$ig-B4Om-!EVTW zj-~2$K#L9-r*LuNei2Hc`XmXU3@B_jn^3u7oJl6Q1B_y!IB%+In+n04;2Wzt0S2&* zOj&wEetP%%;Gujt>P@ULw~ NzL4KCbp>gb!*`)I4XywH literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdarg.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdarg.h new file mode 100644 index 00000000..f97d3c32 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdarg.h @@ -0,0 +1,35 @@ +/*===---- stdarg.h - Variable argument handling ----------------------------=== + * + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + *===-----------------------------------------------------------------------=== + */ + +#ifndef __STDARG_H +#define __STDARG_H + +#ifndef _VA_LIST +typedef __builtin_va_list va_list; +#define _VA_LIST +#endif +#define va_start(ap, param) __builtin_va_start(ap, param) +#define va_end(ap) __builtin_va_end(ap) +#define va_arg(ap, type) __builtin_va_arg(ap, type) + +/* GCC always defines __va_copy, but does not define va_copy unless in c99 mode + * or -ansi is not specified, since it was not part of C90. + */ +#define __va_copy(d, s) __builtin_va_copy(d, s) + +#if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L || !defined(__STRICT_ANSI__) +#define va_copy(dest, src) __builtin_va_copy(dest, src) +#endif + +#ifndef __GNUC_VA_LIST +#define __GNUC_VA_LIST 1 +typedef __builtin_va_list __gnuc_va_list; +#endif + +#endif /* __STDARG_H */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdarg.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdarg.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..0f6196660ba0df87f570bdd2d070fb3f6093faa8 GIT binary patch literal 1372 zcmah|O-$2Z82(zK0pe!)F=Pa{ibe-%SAXhGE(#ct#3V=r#NsS%}7Z2V%8@!W9R^M(NYy-4u-t>Fk_kEt{ecKMB%BztdUl4<& zJh8BpR|}GkOOku3Ah~5%GHlH(>e!VEnA%c7bzMxoR306dh~r7raJ7<@HSF3`S{93T z!6r+#h|L8tr)fxpd*a{JNVHU{4Qqw7N$oMYRYLnOMkhnx> z!LW0pZcwawgqAb=JvfvsLeiD;*fdGCAGPf-Yg(^rdXhn4v6aooS2q4rTzeM|HEeI; z@RkE?NZ|@9+rs4ygixEG`~6})b5fvQ*}*zq;1wlXG)&L1m6EEMhU)>6vx{2&h-7&H zAtoUwCRrwd5|hA!{Pvaj()-?*Pj;B5V{mA`e1GMeuw49g|8Tuf7lfi96p>?AO`o=QDn=Nj0n zSe3z1scN-M)S3kWj^lVXh%^*x;(Hg#yUE6yY6Xl}dCWv9*>-BTIwq~{~%Jj_jk*RUzCOGP?58Q|{om}S` Jwi;`_e*xPzu5JJT literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdbool.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdbool.h new file mode 100644 index 00000000..ef176336 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdbool.h @@ -0,0 +1,31 @@ +/*===---- stdbool.h - Standard header for booleans -------------------------=== + * + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + *===-----------------------------------------------------------------------=== + */ + +#ifndef __STDBOOL_H +#define __STDBOOL_H + +/* Don't define bool, true, and false in C++, except as a GNU extension. */ +#ifndef __cplusplus +#define bool _Bool +#define true 1 +#define false 0 +#elif defined(__GNUC__) && !defined(__STRICT_ANSI__) +/* Define _Bool as a GNU extension. */ +#define _Bool bool +#if __cplusplus < 201103L +/* For C++98, define bool, false, true as a GNU extension. */ +#define bool bool +#define false false +#define true true +#endif +#endif + +#define __bool_true_false_are_defined 1 + +#endif /* __STDBOOL_H */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdbool.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdbool.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..a042acb48b4f2cf32eb0def1733659daec7f3430 GIT binary patch literal 1231 zcmb7DL2DC16n+~JBuKNph?GzQRS)81wALWS2$mjHq&ZmdIBsSq*-dt5)|uVJR0Z!! z!INk8BzpD-R75=3tA9Yec<|uGQ{v2KleQ%23d>{W?fc&M&G%-`!SL0?@FQ4&JrOeO zIbH0s9#)sSSPc|blHx9t98)K%QYc{&#aQ}^_HfhZ<5g`9CA`Z;pCcBuP@7Uf`nx&5 zqt9uOxJ&^G9Z9{q?A6x%(4l0uKmls7IWf6j)~{nH)lRLyBWjZ z=P&1#YNkN+oKzD1r%ZjtJ)bj7T-I`uASP3%j9{=9Vd(_GvC+<(AD`Q=_g=P~KrsL) zu4sS;R?Q>yuu8 zEv#JB9A&$Ft6<_*#{CR^E}be^I+ioU^Y3pvcNf2|8cl~0 zW?vy2Y1Ue>7c@%8(-~^-Y4P!s-Ibq&+}YmTXf$q<8yb9aLU$x>7472LLK?^DKN9M# A9RL6T literal 0 HcmV?d00001 diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stddef.h b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stddef.h new file mode 100644 index 00000000..64b96172 --- /dev/null +++ b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stddef.h @@ -0,0 +1,122 @@ +/*===---- stddef.h - Basic type definitions --------------------------------=== + * + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + *===-----------------------------------------------------------------------=== + */ + +#if !defined(__STDDEF_H) || defined(__need_ptrdiff_t) || defined(__need_size_t) || defined(__need_wchar_t) \ + || defined(__need_NULL) || defined(__need_wint_t) + +#if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && !defined(__need_wchar_t) && !defined(__need_NULL) \ + && !defined(__need_wint_t) +/* Always define miscellaneous pieces when modules are available. */ +#if !__has_feature(modules) +#define __STDDEF_H +#endif +#define __need_ptrdiff_t +#define __need_size_t +#define __need_wchar_t +#define __need_NULL +#define __need_STDDEF_H_misc +/* __need_wint_t is intentionally not defined here. */ +#endif + +#if defined(__need_ptrdiff_t) +#if !defined(_PTRDIFF_T) || __has_feature(modules) +/* Always define ptrdiff_t when modules are available. */ +#if !__has_feature(modules) +#define _PTRDIFF_T +#endif +typedef __PTRDIFF_TYPE__ ptrdiff_t; +#endif +#undef __need_ptrdiff_t +#endif /* defined(__need_ptrdiff_t) */ + +#if defined(__need_size_t) +#if !defined(_SIZE_T) || __has_feature(modules) +/* Always define size_t when modules are available. */ +#if !__has_feature(modules) +#define _SIZE_T +#endif +typedef __SIZE_TYPE__ size_t; +#endif +#undef __need_size_t +#endif /*defined(__need_size_t) */ + +#if defined(__need_STDDEF_H_misc) +/* ISO9899:2011 7.20 (C11 Annex K): Define rsize_t if __STDC_WANT_LIB_EXT1__ is + * enabled. */ +#if (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 && !defined(_RSIZE_T)) || __has_feature(modules) +/* Always define rsize_t when modules are available. */ +#if !__has_feature(modules) +#define _RSIZE_T +#endif +typedef __SIZE_TYPE__ rsize_t; +#endif +#endif /* defined(__need_STDDEF_H_misc) */ + +#if defined(__need_wchar_t) +#ifndef __cplusplus +/* Always define wchar_t when modules are available. */ +#if !defined(_WCHAR_T) || __has_feature(modules) +#if !__has_feature(modules) +#define _WCHAR_T +#if defined(_MSC_EXTENSIONS) +#define _WCHAR_T_DEFINED +#endif +#endif +typedef __WCHAR_TYPE__ wchar_t; +#endif +#endif +#undef __need_wchar_t +#endif /* defined(__need_wchar_t) */ + +#if defined(__need_NULL) +#undef NULL +#ifdef __cplusplus +#if !defined(__MINGW32__) && !defined(_MSC_VER) +#define NULL __null +#else +#define NULL 0 +#endif +#else +#define NULL ((void *)0) +#endif +#ifdef __cplusplus +#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED) +namespace std +{ +typedef decltype(nullptr) nullptr_t; +} + +using ::std::nullptr_t; +#endif +#endif +#undef __need_NULL +#endif /* defined(__need_NULL) */ + +#if defined(__need_STDDEF_H_misc) +#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L +#include "__stddef_max_align_t.h" +#endif +#define offsetof(t, d) __builtin_offsetof(t, d) +#undef __need_STDDEF_H_misc +#endif /* defined(__need_STDDEF_H_misc) */ + +/* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use +__WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */ +#if defined(__need_wint_t) +/* Always define wint_t when modules are available. */ +#if !defined(_WINT_T) || __has_feature(modules) +#if !__has_feature(modules) +#define _WINT_T +#endif +typedef __WINT_TYPE__ wint_t; +#endif +#undef __need_wint_t +#endif /* __need_wint_t */ + +#endif diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stddef.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stddef.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..07b162cc317e8b1f467249b518d28fdc5d4ffb4a GIT binary patch literal 1295 zcmb7@O-vI(6vtlfq0R`Bh=}3+fs}P&f%Z8?`3}PKW}E8 zVE5tm)EWQ)CDSPmC1bOQa(n}bsbBPJyZ`{3Jy@BByqs^j2P%>X!4GXf^`QGjbwAkz&1 zoxSsPae2ci-%ZEkGN+{DWZ-lQ@z0B#t&nplE*sls!+3h07ZhH^f=<||oL&N1 zND$eX5h3t(eJ4!f;?mXXYwdp6)Y~-bhgQ9n#Ewo!#1EZ%Cy9G{dq}>oyKmSJ`}O@K zlN~nKJs3|IeHe=z$Kv60kqDug3;xQ|&_Y{UDOFVuaLO>1V}!V>E$iBg0LEkE!Qj9k z4iSW@geYa9kv7^XRkc&xJ9OdY`lH7dtqn(Vllg0$iaNXxRVcuEy532tn&%(`auCk)bj$Y24X>hc3J1U`US^0h z$3EP?I&7dDdMQ=&)TANVL#Wd2jn>Z_mMA_uJ{k-U4&w2$Iqk_p8*L+V%BeOdYc*T> z>ay>mc0sy=gWR{x;mD+U*4gH5BM)WLG}%byv{Ty}`) + +// C99 7.18.3 Limits of other integer types +// +// Footnote 219, 220: C++ implementations should define these macros only when +// __STDC_LIMIT_MACROS is defined before is included. +// +// Footnote 222: C++ implementations should define these macros only when +// __STDC_CONSTANT_MACROS is defined before is included. +// +// C++11 [cstdint.syn]p2: +// +// The macros defined by are provided unconditionally. In particular, +// the symbols __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS (mentioned in +// footnotes 219, 220, and 222 in the C standard) play no role in C++. +// +// C11 removed the problematic footnotes. +// +// Work around this inconsistency by always defining those macros in C++ mode, +// so that a C library implementation which follows the C99 standard can be +// used in C++. +#ifdef __cplusplus +#if !defined(__STDC_LIMIT_MACROS) +#define __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS_DEFINED_BY_CLANG +#endif +#if !defined(__STDC_CONSTANT_MACROS) +#define __STDC_CONSTANT_MACROS +#define __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG +#endif +#endif + +#include_next + +#ifdef __STDC_LIMIT_MACROS_DEFINED_BY_CLANG +#undef __STDC_LIMIT_MACROS +#undef __STDC_LIMIT_MACROS_DEFINED_BY_CLANG +#endif +#ifdef __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG +#undef __STDC_CONSTANT_MACROS +#undef __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG +#endif + +#else + +/* C99 7.18.1.1 Exact-width integer types. + * C99 7.18.1.2 Minimum-width integer types. + * C99 7.18.1.3 Fastest minimum-width integer types. + * + * The standard requires that exact-width type be defined for 8-, 16-, 32-, and + * 64-bit types if they are implemented. Other exact width types are optional. + * This implementation defines an exact-width types for every integer width + * that is represented in the standard integer types. + * + * The standard also requires minimum-width types be defined for 8-, 16-, 32-, + * and 64-bit widths regardless of whether there are corresponding exact-width + * types. + * + * To accommodate targets that are missing types that are exactly 8, 16, 32, or + * 64 bits wide, this implementation takes an approach of cascading + * redefinitions, redefining __int_leastN_t to successively smaller exact-width + * types. It is therefore important that the types are defined in order of + * descending widths. + * + * We currently assume that the minimum-width types and the fastest + * minimum-width types are the same. This is allowed by the standard, but is + * suboptimal. + * + * In violation of the standard, some targets do not implement a type that is + * wide enough to represent all of the required widths (8-, 16-, 32-, 64-bit). + * To accommodate these targets, a required minimum-width type is only + * defined if there exists an exact-width type of equal or greater width. + */ + +#ifdef __INT64_TYPE__ +#ifndef __int8_t_defined /* glibc sys/types.h also defines int64_t*/ +typedef __INT64_TYPE__ int64_t; +#endif /* __int8_t_defined */ +typedef __UINT64_TYPE__ uint64_t; +#define __int_least64_t int64_t +#define __uint_least64_t uint64_t +#define __int_least32_t int64_t +#define __uint_least32_t uint64_t +#define __int_least16_t int64_t +#define __uint_least16_t uint64_t +#define __int_least8_t int64_t +#define __uint_least8_t uint64_t +#endif /* __INT64_TYPE__ */ + +#ifdef __int_least64_t +typedef __int_least64_t int_least64_t; +typedef __uint_least64_t uint_least64_t; +typedef __int_least64_t int_fast64_t; +typedef __uint_least64_t uint_fast64_t; +#endif /* __int_least64_t */ + +#ifdef __INT56_TYPE__ +typedef __INT56_TYPE__ int56_t; +typedef __UINT56_TYPE__ uint56_t; +typedef int56_t int_least56_t; +typedef uint56_t uint_least56_t; +typedef int56_t int_fast56_t; +typedef uint56_t uint_fast56_t; +#define __int_least32_t int56_t +#define __uint_least32_t uint56_t +#define __int_least16_t int56_t +#define __uint_least16_t uint56_t +#define __int_least8_t int56_t +#define __uint_least8_t uint56_t +#endif /* __INT56_TYPE__ */ + +#ifdef __INT48_TYPE__ +typedef __INT48_TYPE__ int48_t; +typedef __UINT48_TYPE__ uint48_t; +typedef int48_t int_least48_t; +typedef uint48_t uint_least48_t; +typedef int48_t int_fast48_t; +typedef uint48_t uint_fast48_t; +#define __int_least32_t int48_t +#define __uint_least32_t uint48_t +#define __int_least16_t int48_t +#define __uint_least16_t uint48_t +#define __int_least8_t int48_t +#define __uint_least8_t uint48_t +#endif /* __INT48_TYPE__ */ + +#ifdef __INT40_TYPE__ +typedef __INT40_TYPE__ int40_t; +typedef __UINT40_TYPE__ uint40_t; +typedef int40_t int_least40_t; +typedef uint40_t uint_least40_t; +typedef int40_t int_fast40_t; +typedef uint40_t uint_fast40_t; +#define __int_least32_t int40_t +#define __uint_least32_t uint40_t +#define __int_least16_t int40_t +#define __uint_least16_t uint40_t +#define __int_least8_t int40_t +#define __uint_least8_t uint40_t +#endif /* __INT40_TYPE__ */ + +#ifdef __INT32_TYPE__ + +#ifndef __int8_t_defined /* glibc sys/types.h also defines int32_t*/ +typedef __INT32_TYPE__ int32_t; +#endif /* __int8_t_defined */ + +#ifndef __uint32_t_defined /* more glibc compatibility */ +#define __uint32_t_defined +typedef __UINT32_TYPE__ uint32_t; +#endif /* __uint32_t_defined */ + +#define __int_least32_t int32_t +#define __uint_least32_t uint32_t +#define __int_least16_t int32_t +#define __uint_least16_t uint32_t +#define __int_least8_t int32_t +#define __uint_least8_t uint32_t +#endif /* __INT32_TYPE__ */ + +#ifdef __int_least32_t +typedef __int_least32_t int_least32_t; +typedef __uint_least32_t uint_least32_t; +typedef __int_least32_t int_fast32_t; +typedef __uint_least32_t uint_fast32_t; +#endif /* __int_least32_t */ + +#ifdef __INT24_TYPE__ +typedef __INT24_TYPE__ int24_t; +typedef __UINT24_TYPE__ uint24_t; +typedef int24_t int_least24_t; +typedef uint24_t uint_least24_t; +typedef int24_t int_fast24_t; +typedef uint24_t uint_fast24_t; +#define __int_least16_t int24_t +#define __uint_least16_t uint24_t +#define __int_least8_t int24_t +#define __uint_least8_t uint24_t +#endif /* __INT24_TYPE__ */ + +#ifdef __INT16_TYPE__ +#ifndef __int8_t_defined /* glibc sys/types.h also defines int16_t*/ +typedef __INT16_TYPE__ int16_t; +#endif /* __int8_t_defined */ +typedef __UINT16_TYPE__ uint16_t; +#define __int_least16_t int16_t +#define __uint_least16_t uint16_t +#define __int_least8_t int16_t +#define __uint_least8_t uint16_t +#endif /* __INT16_TYPE__ */ + +#ifdef __int_least16_t +typedef __int_least16_t int_least16_t; +typedef __uint_least16_t uint_least16_t; +typedef __int_least16_t int_fast16_t; +typedef __uint_least16_t uint_fast16_t; +#endif /* __int_least16_t */ + +#ifdef __INT8_TYPE__ +#ifndef __int8_t_defined /* glibc sys/types.h also defines int8_t*/ +typedef __INT8_TYPE__ int8_t; +#endif /* __int8_t_defined */ +typedef __UINT8_TYPE__ uint8_t; +#define __int_least8_t int8_t +#define __uint_least8_t uint8_t +#endif /* __INT8_TYPE__ */ + +#ifdef __int_least8_t +typedef __int_least8_t int_least8_t; +typedef __uint_least8_t uint_least8_t; +typedef __int_least8_t int_fast8_t; +typedef __uint_least8_t uint_fast8_t; +#endif /* __int_least8_t */ + +/* prevent glibc sys/types.h from defining conflicting types */ +#ifndef __int8_t_defined +#define __int8_t_defined +#endif /* __int8_t_defined */ + +/* C99 7.18.1.4 Integer types capable of holding object pointers. + */ +#define __stdint_join3(a, b, c) a##b##c + +#ifndef _INTPTR_T +#ifndef __intptr_t_defined +typedef __INTPTR_TYPE__ intptr_t; +#define __intptr_t_defined +#define _INTPTR_T +#endif +#endif + +#ifndef _UINTPTR_T +typedef __UINTPTR_TYPE__ uintptr_t; +#define _UINTPTR_T +#endif + +/* C99 7.18.1.5 Greatest-width integer types. + */ +typedef __INTMAX_TYPE__ intmax_t; +typedef __UINTMAX_TYPE__ uintmax_t; + +/* C99 7.18.4 Macros for minimum-width integer constants. + * + * The standard requires that integer constant macros be defined for all the + * minimum-width types defined above. As 8-, 16-, 32-, and 64-bit minimum-width + * types are required, the corresponding integer constant macros are defined + * here. This implementation also defines minimum-width types for every other + * integer width that the target implements, so corresponding macros are + * defined below, too. + * + * These macros are defined using the same successive-shrinking approach as + * the type definitions above. It is likewise important that macros are defined + * in order of decending width. + * + * Note that C++ should not check __STDC_CONSTANT_MACROS here, contrary to the + * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]). + */ + +#define __int_c_join(a, b) a##b +#define __int_c(v, suffix) __int_c_join(v, suffix) +#define __uint_c(v, suffix) __int_c_join(v##U, suffix) + +#ifdef __INT64_TYPE__ +#ifdef __INT64_C_SUFFIX__ +#define __int64_c_suffix __INT64_C_SUFFIX__ +#define __int32_c_suffix __INT64_C_SUFFIX__ +#define __int16_c_suffix __INT64_C_SUFFIX__ +#define __int8_c_suffix __INT64_C_SUFFIX__ +#else +#undef __int64_c_suffix +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#endif /* __INT64_C_SUFFIX__ */ +#endif /* __INT64_TYPE__ */ + +#ifdef __int_least64_t +#ifdef __int64_c_suffix +#define INT64_C(v) __int_c(v, __int64_c_suffix) +#define UINT64_C(v) __uint_c(v, __int64_c_suffix) +#else +#define INT64_C(v) v +#define UINT64_C(v) v##U +#endif /* __int64_c_suffix */ +#endif /* __int_least64_t */ + +#ifdef __INT56_TYPE__ +#ifdef __INT56_C_SUFFIX__ +#define INT56_C(v) __int_c(v, __INT56_C_SUFFIX__) +#define UINT56_C(v) __uint_c(v, __INT56_C_SUFFIX__) +#define __int32_c_suffix __INT56_C_SUFFIX__ +#define __int16_c_suffix __INT56_C_SUFFIX__ +#define __int8_c_suffix __INT56_C_SUFFIX__ +#else +#define INT56_C(v) v +#define UINT56_C(v) v##U +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#endif /* __INT56_C_SUFFIX__ */ +#endif /* __INT56_TYPE__ */ + +#ifdef __INT48_TYPE__ +#ifdef __INT48_C_SUFFIX__ +#define INT48_C(v) __int_c(v, __INT48_C_SUFFIX__) +#define UINT48_C(v) __uint_c(v, __INT48_C_SUFFIX__) +#define __int32_c_suffix __INT48_C_SUFFIX__ +#define __int16_c_suffix __INT48_C_SUFFIX__ +#define __int8_c_suffix __INT48_C_SUFFIX__ +#else +#define INT48_C(v) v +#define UINT48_C(v) v##U +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#endif /* __INT48_C_SUFFIX__ */ +#endif /* __INT48_TYPE__ */ + +#ifdef __INT40_TYPE__ +#ifdef __INT40_C_SUFFIX__ +#define INT40_C(v) __int_c(v, __INT40_C_SUFFIX__) +#define UINT40_C(v) __uint_c(v, __INT40_C_SUFFIX__) +#define __int32_c_suffix __INT40_C_SUFFIX__ +#define __int16_c_suffix __INT40_C_SUFFIX__ +#define __int8_c_suffix __INT40_C_SUFFIX__ +#else +#define INT40_C(v) v +#define UINT40_C(v) v##U +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#endif /* __INT40_C_SUFFIX__ */ +#endif /* __INT40_TYPE__ */ + +#ifdef __INT32_TYPE__ +#ifdef __INT32_C_SUFFIX__ +#define __int32_c_suffix __INT32_C_SUFFIX__ +#define __int16_c_suffix __INT32_C_SUFFIX__ +#define __int8_c_suffix __INT32_C_SUFFIX__ +#else +#undef __int32_c_suffix +#undef __int16_c_suffix +#undef __int8_c_suffix +#endif /* __INT32_C_SUFFIX__ */ +#endif /* __INT32_TYPE__ */ + +#ifdef __int_least32_t +#ifdef __int32_c_suffix +#define INT32_C(v) __int_c(v, __int32_c_suffix) +#define UINT32_C(v) __uint_c(v, __int32_c_suffix) +#else +#define INT32_C(v) v +#define UINT32_C(v) v##U +#endif /* __int32_c_suffix */ +#endif /* __int_least32_t */ + +#ifdef __INT24_TYPE__ +#ifdef __INT24_C_SUFFIX__ +#define INT24_C(v) __int_c(v, __INT24_C_SUFFIX__) +#define UINT24_C(v) __uint_c(v, __INT24_C_SUFFIX__) +#define __int16_c_suffix __INT24_C_SUFFIX__ +#define __int8_c_suffix __INT24_C_SUFFIX__ +#else +#define INT24_C(v) v +#define UINT24_C(v) v##U +#undef __int16_c_suffix +#undef __int8_c_suffix +#endif /* __INT24_C_SUFFIX__ */ +#endif /* __INT24_TYPE__ */ + +#ifdef __INT16_TYPE__ +#ifdef __INT16_C_SUFFIX__ +#define __int16_c_suffix __INT16_C_SUFFIX__ +#define __int8_c_suffix __INT16_C_SUFFIX__ +#else +#undef __int16_c_suffix +#undef __int8_c_suffix +#endif /* __INT16_C_SUFFIX__ */ +#endif /* __INT16_TYPE__ */ + +#ifdef __int_least16_t +#ifdef __int16_c_suffix +#define INT16_C(v) __int_c(v, __int16_c_suffix) +#define UINT16_C(v) __uint_c(v, __int16_c_suffix) +#else +#define INT16_C(v) v +#define UINT16_C(v) v##U +#endif /* __int16_c_suffix */ +#endif /* __int_least16_t */ + +#ifdef __INT8_TYPE__ +#ifdef __INT8_C_SUFFIX__ +#define __int8_c_suffix __INT8_C_SUFFIX__ +#else +#undef __int8_c_suffix +#endif /* __INT8_C_SUFFIX__ */ +#endif /* __INT8_TYPE__ */ + +#ifdef __int_least8_t +#ifdef __int8_c_suffix +#define INT8_C(v) __int_c(v, __int8_c_suffix) +#define UINT8_C(v) __uint_c(v, __int8_c_suffix) +#else +#define INT8_C(v) v +#define UINT8_C(v) v##U +#endif /* __int8_c_suffix */ +#endif /* __int_least8_t */ + +/* C99 7.18.2.1 Limits of exact-width integer types. + * C99 7.18.2.2 Limits of minimum-width integer types. + * C99 7.18.2.3 Limits of fastest minimum-width integer types. + * + * The presence of limit macros are completely optional in C99. This + * implementation defines limits for all of the types (exact- and + * minimum-width) that it defines above, using the limits of the minimum-width + * type for any types that do not have exact-width representations. + * + * As in the type definitions, this section takes an approach of + * successive-shrinking to determine which limits to use for the standard (8, + * 16, 32, 64) bit widths when they don't have exact representations. It is + * therefore important that the definitions be kept in order of decending + * widths. + * + * Note that C++ should not check __STDC_LIMIT_MACROS here, contrary to the + * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]). + */ + +#ifdef __INT64_TYPE__ +#define INT64_MAX INT64_C(9223372036854775807) +#define INT64_MIN (-INT64_C(9223372036854775807) - 1) +#define UINT64_MAX UINT64_C(18446744073709551615) +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define UINT64_WIDTH 64 +#define INT64_WIDTH UINT64_WIDTH + +#define __UINT_LEAST64_WIDTH UINT64_WIDTH +#define __UINT_LEAST32_WIDTH UINT64_WIDTH +#define __UINT_LEAST16_WIDTH UINT64_WIDTH +#define __UINT_LEAST8_MAX UINT64_MAX +#endif /* __STDC_VERSION__ */ + +#define __INT_LEAST64_MIN INT64_MIN +#define __INT_LEAST64_MAX INT64_MAX +#define __UINT_LEAST64_MAX UINT64_MAX +#define __INT_LEAST32_MIN INT64_MIN +#define __INT_LEAST32_MAX INT64_MAX +#define __UINT_LEAST32_MAX UINT64_MAX +#define __INT_LEAST16_MIN INT64_MIN +#define __INT_LEAST16_MAX INT64_MAX +#define __UINT_LEAST16_MAX UINT64_MAX +#define __INT_LEAST8_MIN INT64_MIN +#define __INT_LEAST8_MAX INT64_MAX +#define __UINT_LEAST8_MAX UINT64_MAX +#endif /* __INT64_TYPE__ */ + +#ifdef __INT_LEAST64_MIN +#define INT_LEAST64_MIN __INT_LEAST64_MIN +#define INT_LEAST64_MAX __INT_LEAST64_MAX +#define UINT_LEAST64_MAX __UINT_LEAST64_MAX +#define INT_FAST64_MIN __INT_LEAST64_MIN +#define INT_FAST64_MAX __INT_LEAST64_MAX +#define UINT_FAST64_MAX __UINT_LEAST64_MAX + +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define UINT_LEAST64_WIDTH __UINT_LEAST64_WIDTH +#define INT_LEAST64_WIDTH UINT_LEAST64_WIDTH +#define UINT_FAST64_WIDTH __UINT_LEAST64_WIDTH +#define INT_FAST64_WIDTH UINT_FAST64_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT_LEAST64_MIN */ + +#ifdef __INT56_TYPE__ +#define INT56_MAX INT56_C(36028797018963967) +#define INT56_MIN (-INT56_C(36028797018963967) - 1) +#define UINT56_MAX UINT56_C(72057594037927935) +#define INT_LEAST56_MIN INT56_MIN +#define INT_LEAST56_MAX INT56_MAX +#define UINT_LEAST56_MAX UINT56_MAX +#define INT_FAST56_MIN INT56_MIN +#define INT_FAST56_MAX INT56_MAX +#define UINT_FAST56_MAX UINT56_MAX + +#define __INT_LEAST32_MIN INT56_MIN +#define __INT_LEAST32_MAX INT56_MAX +#define __UINT_LEAST32_MAX UINT56_MAX +#define __INT_LEAST16_MIN INT56_MIN +#define __INT_LEAST16_MAX INT56_MAX +#define __UINT_LEAST16_MAX UINT56_MAX +#define __INT_LEAST8_MIN INT56_MIN +#define __INT_LEAST8_MAX INT56_MAX +#define __UINT_LEAST8_MAX UINT56_MAX + +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define UINT56_WIDTH 56 +#define INT56_WIDTH UINT56_WIDTH +#define UINT_LEAST56_WIDTH UINT56_WIDTH +#define INT_LEAST56_WIDTH UINT_LEAST56_WIDTH +#define UINT_FAST56_WIDTH UINT56_WIDTH +#define INT_FAST56_WIDTH UINT_FAST56_WIDTH +#define __UINT_LEAST32_WIDTH UINT56_WIDTH +#define __UINT_LEAST16_WIDTH UINT56_WIDTH +#define __UINT_LEAST8_WIDTH UINT56_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT56_TYPE__ */ + +#ifdef __INT48_TYPE__ +#define INT48_MAX INT48_C(140737488355327) +#define INT48_MIN (-INT48_C(140737488355327) - 1) +#define UINT48_MAX UINT48_C(281474976710655) +#define INT_LEAST48_MIN INT48_MIN +#define INT_LEAST48_MAX INT48_MAX +#define UINT_LEAST48_MAX UINT48_MAX +#define INT_FAST48_MIN INT48_MIN +#define INT_FAST48_MAX INT48_MAX +#define UINT_FAST48_MAX UINT48_MAX + +#define __INT_LEAST32_MIN INT48_MIN +#define __INT_LEAST32_MAX INT48_MAX +#define __UINT_LEAST32_MAX UINT48_MAX +#define __INT_LEAST16_MIN INT48_MIN +#define __INT_LEAST16_MAX INT48_MAX +#define __UINT_LEAST16_MAX UINT48_MAX +#define __INT_LEAST8_MIN INT48_MIN +#define __INT_LEAST8_MAX INT48_MAX +#define __UINT_LEAST8_MAX UINT48_MAX + +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define UINT48_WIDTH 48 +#define INT48_WIDTH UINT48_WIDTH +#define UINT_LEAST48_WIDTH UINT48_WIDTH +#define INT_LEAST48_WIDTH UINT_LEAST48_WIDTH +#define UINT_FAST48_WIDTH UINT48_WIDTH +#define INT_FAST48_WIDTH UINT_FAST48_WIDTH +#define __UINT_LEAST32_WIDTH UINT48_WIDTH +#define __UINT_LEAST16_WIDTH UINT48_WIDTH +#define __UINT_LEAST8_WIDTH UINT48_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT48_TYPE__ */ + +#ifdef __INT40_TYPE__ +#define INT40_MAX INT40_C(549755813887) +#define INT40_MIN (-INT40_C(549755813887) - 1) +#define UINT40_MAX UINT40_C(1099511627775) +#define INT_LEAST40_MIN INT40_MIN +#define INT_LEAST40_MAX INT40_MAX +#define UINT_LEAST40_MAX UINT40_MAX +#define INT_FAST40_MIN INT40_MIN +#define INT_FAST40_MAX INT40_MAX +#define UINT_FAST40_MAX UINT40_MAX + +#define __INT_LEAST32_MIN INT40_MIN +#define __INT_LEAST32_MAX INT40_MAX +#define __UINT_LEAST32_MAX UINT40_MAX +#define __INT_LEAST16_MIN INT40_MIN +#define __INT_LEAST16_MAX INT40_MAX +#define __UINT_LEAST16_MAX UINT40_MAX +#define __INT_LEAST8_MIN INT40_MIN +#define __INT_LEAST8_MAX INT40_MAX +#define __UINT_LEAST8_MAX UINT40_MAX + +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define UINT40_WIDTH 40 +#define INT40_WIDTH UINT40_WIDTH +#define UINT_LEAST40_WIDTH UINT40_WIDTH +#define INT_LEAST40_WIDTH UINT_LEAST40_WIDTH +#define UINT_FAST40_WIDTH UINT40_WIDTH +#define INT_FAST40_WIDTH UINT_FAST40_WIDTH +#define __UINT_LEAST32_WIDTH UINT40_WIDTH +#define __UINT_LEAST16_WIDTH UINT40_WIDTH +#define __UINT_LEAST8_WIDTH UINT40_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT40_TYPE__ */ + +#ifdef __INT32_TYPE__ +#define INT32_MAX INT32_C(2147483647) +#define INT32_MIN (-INT32_C(2147483647) - 1) +#define UINT32_MAX UINT32_C(4294967295) + +#define __INT_LEAST32_MIN INT32_MIN +#define __INT_LEAST32_MAX INT32_MAX +#define __UINT_LEAST32_MAX UINT32_MAX +#define __INT_LEAST16_MIN INT32_MIN +#define __INT_LEAST16_MAX INT32_MAX +#define __UINT_LEAST16_MAX UINT32_MAX +#define __INT_LEAST8_MIN INT32_MIN +#define __INT_LEAST8_MAX INT32_MAX +#define __UINT_LEAST8_MAX UINT32_MAX + +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define UINT32_WIDTH 32 +#define INT32_WIDTH UINT32_WIDTH +#define __UINT_LEAST32_WIDTH UINT32_WIDTH +#define __UINT_LEAST16_WIDTH UINT32_WIDTH +#define __UINT_LEAST8_WIDTH UINT32_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT32_TYPE__ */ + +#ifdef __INT_LEAST32_MIN +#define INT_LEAST32_MIN __INT_LEAST32_MIN +#define INT_LEAST32_MAX __INT_LEAST32_MAX +#define UINT_LEAST32_MAX __UINT_LEAST32_MAX +#define INT_FAST32_MIN __INT_LEAST32_MIN +#define INT_FAST32_MAX __INT_LEAST32_MAX +#define UINT_FAST32_MAX __UINT_LEAST32_MAX + +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define UINT_LEAST32_WIDTH __UINT_LEAST32_WIDTH +#define INT_LEAST32_WIDTH UINT_LEAST32_WIDTH +#define UINT_FAST32_WIDTH __UINT_LEAST32_WIDTH +#define INT_FAST32_WIDTH UINT_FAST32_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT_LEAST32_MIN */ + +#ifdef __INT24_TYPE__ +#define INT24_MAX INT24_C(8388607) +#define INT24_MIN (-INT24_C(8388607) - 1) +#define UINT24_MAX UINT24_C(16777215) +#define INT_LEAST24_MIN INT24_MIN +#define INT_LEAST24_MAX INT24_MAX +#define UINT_LEAST24_MAX UINT24_MAX +#define INT_FAST24_MIN INT24_MIN +#define INT_FAST24_MAX INT24_MAX +#define UINT_FAST24_MAX UINT24_MAX + +#define __INT_LEAST16_MIN INT24_MIN +#define __INT_LEAST16_MAX INT24_MAX +#define __UINT_LEAST16_MAX UINT24_MAX +#define __INT_LEAST8_MIN INT24_MIN +#define __INT_LEAST8_MAX INT24_MAX +#define __UINT_LEAST8_MAX UINT24_MAX + +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define UINT24_WIDTH 24 +#define INT24_WIDTH UINT24_WIDTH +#define UINT_LEAST24_WIDTH UINT24_WIDTH +#define INT_LEAST24_WIDTH UINT_LEAST24_WIDTH +#define UINT_FAST24_WIDTH UINT24_WIDTH +#define INT_FAST24_WIDTH UINT_FAST24_WIDTH +#define __UINT_LEAST16_WIDTH UINT24_WIDTH +#define __UINT_LEAST8_WIDTH UINT24_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT24_TYPE__ */ + +#ifdef __INT16_TYPE__ +#define INT16_MAX INT16_C(32767) +#define INT16_MIN (-INT16_C(32767) - 1) +#define UINT16_MAX UINT16_C(65535) + +#define __INT_LEAST16_MIN INT16_MIN +#define __INT_LEAST16_MAX INT16_MAX +#define __UINT_LEAST16_MAX UINT16_MAX +#define __INT_LEAST8_MIN INT16_MIN +#define __INT_LEAST8_MAX INT16_MAX +#define __UINT_LEAST8_MAX UINT16_MAX + +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define UINT16_WIDTH 16 +#define INT16_WIDTH UINT16_WIDTH +#define __UINT_LEAST16_WIDTH UINT16_WIDTH +#define __UINT_LEAST8_WIDTH UINT16_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT16_TYPE__ */ + +#ifdef __INT_LEAST16_MIN +#define INT_LEAST16_MIN __INT_LEAST16_MIN +#define INT_LEAST16_MAX __INT_LEAST16_MAX +#define UINT_LEAST16_MAX __UINT_LEAST16_MAX +#define INT_FAST16_MIN __INT_LEAST16_MIN +#define INT_FAST16_MAX __INT_LEAST16_MAX +#define UINT_FAST16_MAX __UINT_LEAST16_MAX + +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define UINT_LEAST16_WIDTH __UINT_LEAST16_WIDTH +#define INT_LEAST16_WIDTH UINT_LEAST16_WIDTH +#define UINT_FAST16_WIDTH __UINT_LEAST16_WIDTH +#define INT_FAST16_WIDTH UINT_FAST16_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT_LEAST16_MIN */ + +#ifdef __INT8_TYPE__ +#define INT8_MAX INT8_C(127) +#define INT8_MIN (-INT8_C(127) - 1) +#define UINT8_MAX UINT8_C(255) + +#define __INT_LEAST8_MIN INT8_MIN +#define __INT_LEAST8_MAX INT8_MAX +#define __UINT_LEAST8_MAX UINT8_MAX + +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define UINT8_WIDTH 8 +#define INT8_WIDTH UINT8_WIDTH +#define __UINT_LEAST8_WIDTH UINT8_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT8_TYPE__ */ + +#ifdef __INT_LEAST8_MIN +#define INT_LEAST8_MIN __INT_LEAST8_MIN +#define INT_LEAST8_MAX __INT_LEAST8_MAX +#define UINT_LEAST8_MAX __UINT_LEAST8_MAX +#define INT_FAST8_MIN __INT_LEAST8_MIN +#define INT_FAST8_MAX __INT_LEAST8_MAX +#define UINT_FAST8_MAX __UINT_LEAST8_MAX + +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define UINT_LEAST8_WIDTH __UINT_LEAST8_WIDTH +#define INT_LEAST8_WIDTH UINT_LEAST8_WIDTH +#define UINT_FAST8_WIDTH __UINT_LEAST8_WIDTH +#define INT_FAST8_WIDTH UINT_FAST8_WIDTH +#endif /* __STDC_VERSION__ */ +#endif /* __INT_LEAST8_MIN */ + +/* Some utility macros */ +#define __INTN_MIN(n) __stdint_join3(INT, n, _MIN) +#define __INTN_MAX(n) __stdint_join3(INT, n, _MAX) +#define __UINTN_MAX(n) __stdint_join3(UINT, n, _MAX) +#define __INTN_C(n, v) __stdint_join3(INT, n, _C(v)) +#define __UINTN_C(n, v) __stdint_join3(UINT, n, _C(v)) + +/* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */ +/* C99 7.18.3 Limits of other integer types. */ + +#define INTPTR_MIN (-__INTPTR_MAX__ - 1) +#define INTPTR_MAX __INTPTR_MAX__ +#define UINTPTR_MAX __UINTPTR_MAX__ +#define PTRDIFF_MIN (-__PTRDIFF_MAX__ - 1) +#define PTRDIFF_MAX __PTRDIFF_MAX__ +#define SIZE_MAX __SIZE_MAX__ + +/* C2x 7.20.2.4 Width of integer types capable of holding object pointers. */ +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +/* NB: The C standard requires that these be the same value, but the compiler + exposes separate internal width macros. */ +#define INTPTR_WIDTH __INTPTR_WIDTH__ +#define UINTPTR_WIDTH __UINTPTR_WIDTH__ +#endif + +/* ISO9899:2011 7.20 (C11 Annex K): Define RSIZE_MAX if __STDC_WANT_LIB_EXT1__ + * is enabled. */ +#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 +#define RSIZE_MAX (SIZE_MAX >> 1) +#endif + +/* C99 7.18.2.5 Limits of greatest-width integer types. */ +#define INTMAX_MIN (-__INTMAX_MAX__ - 1) +#define INTMAX_MAX __INTMAX_MAX__ +#define UINTMAX_MAX __UINTMAX_MAX__ + +/* C2x 7.20.2.5 Width of greatest-width integer types. */ +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +/* NB: The C standard requires that these be the same value, but the compiler + exposes separate internal width macros. */ +#define INTMAX_WIDTH __INTMAX_WIDTH__ +#define UINTMAX_WIDTH __UINTMAX_WIDTH__ +#endif + +/* C99 7.18.3 Limits of other integer types. */ +#define SIG_ATOMIC_MIN __INTN_MIN(__SIG_ATOMIC_WIDTH__) +#define SIG_ATOMIC_MAX __INTN_MAX(__SIG_ATOMIC_WIDTH__) +#ifdef __WINT_UNSIGNED__ +#define WINT_MIN __UINTN_C(__WINT_WIDTH__, 0) +#define WINT_MAX __UINTN_MAX(__WINT_WIDTH__) +#else +#define WINT_MIN __INTN_MIN(__WINT_WIDTH__) +#define WINT_MAX __INTN_MAX(__WINT_WIDTH__) +#endif + +#ifndef WCHAR_MAX +#define WCHAR_MAX __WCHAR_MAX__ +#endif +#ifndef WCHAR_MIN +#if __WCHAR_MAX__ == __INTN_MAX(__WCHAR_WIDTH__) +#define WCHAR_MIN __INTN_MIN(__WCHAR_WIDTH__) +#else +#define WCHAR_MIN __UINTN_C(__WCHAR_WIDTH__, 0) +#endif +#endif + +/* 7.18.4.2 Macros for greatest-width integer constants. */ +#define INTMAX_C(v) __int_c(v, __INTMAX_C_SUFFIX__) +#define UINTMAX_C(v) __int_c(v, __UINTMAX_C_SUFFIX__) + +/* C2x 7.20.3.x Width of other integer types. */ +/* FIXME: This is using the placeholder dates Clang produces for these macros + in C2x mode; switch to the correct values once they've been published. */ +#if __STDC_VERSION__ >= 202000L +#define PTRDIFF_WIDTH __PTRDIFF_WIDTH__ +#define SIG_ATOMIC_WIDTH __SIG_ATOMIC_WIDTH__ +#define SIZE_WIDTH __SIZE_WIDTH__ +#define WCHAR_WIDTH __WCHAR_WIDTH__ +#define WINT_WIDTH __WINT_WIDTH__ +#endif + +#endif /* __STDC_HOSTED__ */ +#endif /* __CLANG_STDINT_H */ diff --git a/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdint.h.blob b/.ccls-cache/@@home@hak@dev@s3k/@usr@lib@llvm-14@lib@clang@14.0.6@include@stdint.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..ebf363ecf13530b88fd661fd591dd33ab39beffb GIT binary patch literal 1315 zcmbVMF>ezw6!sAYmPSZnrw9p9h0hIyD3uCo)k=VbDg@m+SdQ)FOz!N+_O(g7F;*QJ z!$23rz{WqQkXS%n`5BB1G`zdgh$soVaMGQu``+{W{J!sb37vg<|MLVPL?V+&60r^u za+kRK9n!VtmE_*RkHl!_E%U|_Zu?ztNWzp3IV$m(>Gppn<2_?LO1H64777{Le>lkk zT_dTpBvwrl$GZux*79{;msD%va#$xy^EeffI4^{3g%LVCK1e?2c^6QxQK$79j+IV( zxUEytRB$ri?@E`&-#t3`S~Onm&&X*>=2JTZoIyY(vR*63!1W#BaK7n;FN$M7zU6$f zGU=-K8X2F{*Q?(ObYzc5%ogLHcN`>A+GBY2{8{OoX;~{A$ThVRFyXjsU+2>seAH4rKd-wvK1 ziXYbnTvDSasDzalYr*iwCb@mOGf*P{7D44o2VXu=y76p%>oI+~z4>%& cn?8Y%#hakI(sFSU3l^>}EMLmMXc$23Z;o@<(f|Me literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/common@inc@altc@altio.h b/.ccls-cache/@home@hak@dev@s3k/common@inc@altc@altio.h new file mode 100644 index 00000000..e4a668af --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/common@inc@altc@altio.h @@ -0,0 +1,12 @@ +#pragma once +#include +#include + +int alt_getchar(void); +int alt_putchar(char c); +int alt_putstr(const char *str); +int alt_puts(const char *str); +int alt_gets(char *str); +int alt_printf(const char *fmt, ...); +int alt_snprintf(char *restrict s, size_t n, const char *restrict fmt, ...); +int alt_vsnprintf(char *restrict s, size_t n, const char *restrict fmt, va_list ap); diff --git a/.ccls-cache/@home@hak@dev@s3k/common@inc@altc@altio.h.blob b/.ccls-cache/@home@hak@dev@s3k/common@inc@altc@altio.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..f932355ccb13ffac8ad6db123912325a89f607ad GIT binary patch literal 1375 zcmbW0-%Aux9L4Y5c4qF(>_djcA|`{S*t$ETrrQ>}SV~1ggs2b*%Q!o`JMH|?+1b^~ zD1s#FG3q5FC=3cJlKKbw0o6koSQ0&iJw-3|P(1{?-TAd_B%#g2Fc-e(bI-ZwP6Vtj zoa=rKAP{nfCJQ++FQny?P}r3hBtz2-T~KsM5LL^0DF&YdK}i+$EQn1RW5;F5Qc7}6 zYHf|>WHBw98{oty4KuIk*;raJF~=}Z^!#lCY!ZqEQ&5#LK~+myti99ub}R_(oqQV~ zw;ig*v@8^?bXv|}hpRVFY0uZMOQl?8N)xA2qN-%|lx0(9_q~6*ehOxYX4cmQ0{@{5 zZb;*11*m-B;_iOs?Zl#@TO4jGRVwJ?CSGJ(q?~AS5mPQ$rXpE80YY^EKd?MHILAHc zIr$ER@QOujBZMqqZv#-iAJ0F0`6g8KVgF!-UDo4Adk*L3x)KhHK@0~W1DLCr^`+zc zaIk5*#%E<^tKfOUj%+)dT|{YS;5?j}_~9TBLSYCIKs-iV`L%rS>!lkbK4QFRVQGtG z=mm>&<9VoB7nM14VPya1*(VN)L}WdLBp{O*bxR8^Egx-7RHN1cd7iTH^Y;2}AAUL@ z3Q^b-1*p9kbbY94SbbKrPzAD`xXC0t)>hX`-_o%GV)EJ@2SFgB0YU;0cC4-=-=?>` zsy$mlczspH%4k-U<9XiZdD%`c9(*y{|7pnK(TK*`Xh0vryyYZ!x9?-~pwGi6?O3Xq z0gfh!g4jb41S7cidD~?51Irb|RM~I!&npB%A$&ZL;hE%0APAX8CJ9#X9Rg*)!b&H2 zl*FT`8Aa_;REMJ8s2`)cM4T3c!?u8q)7`d!ZlJq8fnP +#include + +int alt_fputchar(FILE *f, char c); +int alt_fputuint(FILE *f, unsigned long long val); +int alt_fputhex(FILE *f, unsigned long long val); +int alt_fputstr(FILE *f, const char *s); +int alt_vfprintf(FILE *f, const char *fmt, va_list ap); +int alt_fprintf(FILE *f, const char *fmt, ...) + + int alt_putchar(char c); +int alt_putstr(const char *s); +int alt_putuint(unsigned long long val); +int alt_puthex(unsigned long long val); +int alt_vprintf(const char *fmt, va_list ap); +int alt_printf(const char *fmt, ...); + +int alt_snputuint(char *buf, int size, unsigned long long val); +int alt_snputhex(char *buf, int size, unsigned long long val); +int alt_snvprintf(char *buf, int size, const char *fmt, va_list ap); +int alt_snprintf(char *buf, int size, const char *fmt, ...); diff --git a/.ccls-cache/@home@hak@dev@s3k/common@src@altc@printf.c.blob b/.ccls-cache/@home@hak@dev@s3k/common@src@altc@printf.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..c66ec59441b9c0cd57a22aca032ae2a2a6b8033c GIT binary patch literal 1714 zcmbW1O=#0#7{}i@+rF*+NY@X?92x~jUAM;RoUlzqPeXJbgt3EKvovk9Ch17hI_G4% zfr{WRyU6gOD9AvV;sxjLY0moRh?q64wpN?IVk`8>aw+Q&U8@Y4d+5?NwrA=dZpzel5)qdU7zQ8|sMhq6yF@iZ4UhuniD4WIGCo2WzJux$ECf z69f=)@Epl08kj947%8iy3b#Bb8KiKj887y3rzkJ-_5f*M{L}8sKey3@WHe)afRgbRrJHs)Qj{CJ+d(<4uW?<6dVTr?DBkfZ|#e5!Z+g3bjxa3c14T-dJlNAfQ6A*!0R4${$AL?? z25u64arS?=V@aLHG?+;vx({&los$#olM81F&P?4rB~`|5@iBk{;9~#VPs)8C$E B^TGfC literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@time.c b/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@time.c new file mode 100644 index 00000000..f6ac5aae --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@time.c @@ -0,0 +1,24 @@ +#include "drivers/time.h" +#include "plat/config.h" +static volatile uint64_t *const MTIME = (uint64_t *)MTIME_BASE_ADDR; +static volatile uint64_t *const MTIMECMP = (uint64_t *)MTIMECMP_BASE_ADDR; + +uint64_t time_get(void) +{ + return MTIME[0]; +} + +void time_set(uint64_t time) +{ + MTIME[0] = time; +} + +uint64_t timeout_get(uint64_t hartid) +{ + return MTIMECMP[hartid]; +} + +void timeout_set(uint64_t hartid, uint64_t timeout) +{ + MTIMECMP[hartid] = timeout; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@time.c.blob b/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@time.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..e89c5611c9a59804f7f87519d35b78dcd5b97e90 GIT binary patch literal 525 zcmdO5_;;bn<{Se9gMLPSZmNDpVzz!tYMFkqakhSPer|4lo_=vrvVKZYW?5=cv3^Nr zZmM1~19NgtVqQ8)T6D|vi?TEG(sffZi&B$I@{1~MF>M4ogMsD0oX+)V1%aBVvi!^x z1(1#Tr6uvjsU;ejc_j)NiA5!uDLM)uHdIcNfs0FwQItzmfr(L+L4pZn3Ih)#i2Uy> z@2$SCuR0ZO7Th3^W{^$+Ms6-{DJDj420j#>=kK&>ZjH>Hgk({CI*KDS88|q^7zKm` zG?*9#7=%%D$ESCl$b59F9Htwr6{JCckxhtAiHVVoffHE+1Ji%)#FIDrpTs&Amn4>C zCM%TX=K$%PRIpFAlJoP5OB8%VJbhiAeFGTG%mf%17+D-x0+<+C7+3-rco~7F{r76A eTs!OED_=rJ0QGYL^)ov#doeLGGcbEW^aB79!<51R literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@ns16550a.c b/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@ns16550a.c new file mode 100644 index 00000000..78f8622b --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@ns16550a.c @@ -0,0 +1,47 @@ +#include "drivers/uart.h" + +// Line status register flags +#define LSR_RX_READY 0x1 // Receive data ready +#define LSR_TX_READY 0x60 // Transmit data ready + +struct uart { + union { + char rbr; // Receiver buffer register (read only) + char thr; // Transmitter holding register (write only) + }; + + char ier; // Interrupt enabler register + + union { + char iir; // Interrupt identification register (read only) + char fcr; // FIFO control register (write only) + }; + + char lcr; // Line control register + char __padding; + char lsr; // Line status register +}; + +void uart_init(void *base) +{ + volatile struct uart *uart = base; + uart->lcr = 0x3; + uart->fcr = 0x1; +} + +int uart_putc(void *base, char c) +{ + volatile struct uart *uart = base; + while (!(uart->lsr & LSR_TX_READY)) + ; + uart->thr = (unsigned char)c; + return (unsigned char)c; +} + +int uart_getc(void *base) +{ + volatile struct uart *uart = base; + while (!(uart->lsr & LSR_RX_READY)) + ; + return uart->rbr; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@ns16550a.c.blob b/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@ns16550a.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..40505f0c8720d9231d2477519ea160b2099b447a GIT binary patch literal 1557 zcmbW1UuYaf9LHz&Hpk}JZZ4P2ACfbfo}p|mN%vYwz))+8X(hB^I7|Of<=oqy%Z<6r zhS|MKN~^_!f{*H>)CUo1DZZp{BK5sO4L&HguPqcR_%7-?v)h~ORr}&S{O%a;_x*mp zzxnN!!QZ>rj@$zP*iC-}+f8TP_Hf4zURt+Ze`CX^cEDWQW2A#wV7DC>+B7({xUf)h z4!R)Ywj8?l|9a=Qe6~*L+Pp^?c0-?Cdgb2?91LWl>rSU{aNm;#p&=3owKW{NR>vnE zD%YI=&j3v;Kufd66=;Ejis%A56gArZ;QaEtpRcUQ-pzJT?;LWQ4nuCDF{Mp$jVW-T zM`PdB2UizAJC}_eV*o-)*aMKu72sHItf;^-@Itydvm-FlA1!+4qi!ZLey*m9kx_c|X`2JVRlhLoQ@1A;eVd2wg zV&v!FZq>i|9YnVu{_*{5-~4jQp*}@zN_@(VOaP#v82Vp|%D)FyexyoEAU%Qf0@4hC zzEOc1S+9Qga&ht)d zKoS7`7bqANSD6_vjh9upzqFs%a;eN~PHM$>C~jtHsTDAg8_9yxgkltgPS_3*!)qi6 zF#~W|A1;W&3@gKh9gT-oN~m-|hqGvwSILpmv-XBNv$WK3x%%NOIJt824dnVXWPVG^ zBWsJ15F?+qF3kX#H}aUEhqSsW+ z$(R$!S*E&Lf~K4GSsDO`^r1NHkTR5ng%iev0O)R6N~$*|AxX>?%BRNKn;{||rXgt% z*9rNWr6M!zc-_PU#z35SKpjXD1Gx(+E5a{AQ16Lj>eO49NmT%KU60XqMNiQ87B{8T z3mrBS=rhcr!3GIAI%@hYF;%Jj%oX(;{V{OA+W+*5rj2Paq3$F4Tr*Zr%&OSM;^m0y z?M5RN0a@w6XoeR1XsY(qXTCUJ;tN-t`NVkZ(e)>%->lZooUc_+9ACb`mwoI-5A)X@ zM(J}@*g%hAZ(} LNt9;iX1UTopXK6T literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@sifive.c b/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@sifive.c new file mode 100644 index 00000000..bea5516b --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@sifive.c @@ -0,0 +1,48 @@ +#include "drivers/uart.h" +// +// Bit masks for transmit and receive adata registers +#define TXDATA_FULL 0x80000000ul +#define RXDATA_EMPTY 0x80000000ul + +// Control register flags for enabling transmission and reception +#define TXCTRL_TXEN 0x1ul +#define RXCTRL_RXEN 0x1ul + +// Control register flags for setting stop bits +#define TXCTRL_NSTOP 0x2ul + +struct uart { + int txdata; // Transmit data register + int rxdata; // Receive data register + int txctrl; // Transmit control register + int rxctrl; // Receive control register + int ie; // UART interrupt enable + int ip; // UART interrupt pending + int div; // Baud rate divisor +}; + +void uart_init(void *base) +{ + volatile struct uart *uart = base; + uart->txctrl = TXCTRL_TXEN; // Enable transmit data + uart->rxctrl = RXCTRL_RXEN; // Enable receive data +} + +int uart_putc(void *base, char c) +{ + volatile struct uart *uart = base; + while (uart->txdata & TXDATA_FULL) { + } + uart->txdata = (unsigned char)c; + return (unsigned char)c; +} + +int uart_getc(void *base) +{ + volatile struct uart *uart = base; + int c; + do { + c = uart->rxdata; + } while (c & RXDATA_EMPTY); + return c; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@sifive.c.blob b/.ccls-cache/@home@hak@dev@s3k/common@src@drivers@uart@sifive.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..522d7bebb79ea0bd197a0ba66fbc9c7c5684e7d2 GIT binary patch literal 1482 zcmbVLO=uKX9Dnca)(qqBWcI_|xVwaxM9l|TN27=pi<_7PG^xhzh>0G;WahaUvpW;s z%&w6lu{}t!h0>NnOR)$ZG+u-rq!bTAdu&Cd2SM~C=HS6gON$W4H?zC5ljzAg{9*p^ z`+V;WfY%Q`KX@MiAkCW!PIve6fPBcFC8!=j*Kj=u55@ps%`i z34*j+X=rQr)`2j@-I&e(?tV5SKBC$3fdl#?;F4i*a=0jCwk4ES7j3*q42_*RfC)Y! ztf4SWpoDOTOEX?ysl}n`HAb=tj3`wNQ^h8jZFI||04DjQ=;D(oDK_xU>RNcZq}sI1 zC?cRpRKjj7R!zgEW*Jjb(kOL%;HRB$_x!Y@_J*Iqj=^ma=#Ym`M#ldg{a>CwEEgwd zk9{H^pJKgr^k{^=41$AuylZKwT4uLlv$(krxpOaY+|%>VzGca7wIox;uqwL!j+#VX z^lXVpY}m>O8MmfqH-EcgtzN!gtlKJ1j~!z=siv#Inwi?|nc_rl2ZC%4d8S|%XZNwI z_Qhd5e)Pgss}V%rz!X^fOl@KtV`8(xl))L7srkTyA^qO{kQ<5@c)?33AfcWRb>+JH zBCtp3adZC1|5MRUe|f$*JvuB8&yIaOCC>!w5AK=2{k!U)7dR}2*(tC&QV*QZ<@Yk1 osojTu`R1?dCAm&HesXd$SY2SfkuW5NSZ+28b;7QlU84o~2E}8wod5s; literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/common@src@s3k@s3k.c b/.ccls-cache/@home@hak@dev@s3k/common@src@s3k@s3k.c new file mode 100644 index 00000000..00a79375 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/common@src@s3k@s3k.c @@ -0,0 +1,317 @@ +#include "s3k/s3k.h" + +typedef union { + struct { + uint64_t a0, a1, a2, a3, a4, a5, a6, a7; + }; + + struct { + int info; + } get_info; + + struct { + s3k_reg_t reg; + uint64_t val; + } reg; + + struct { + bool full; + } sync; + + struct { + s3k_cidx_t idx; + s3k_cidx_t dst_idx; + s3k_cap_t cap; + } cap; + + struct { + s3k_cidx_t pmp_idx; + s3k_pmp_slot_t pmp_slot; + } pmp; + + struct { + s3k_cidx_t mon_idx; + s3k_pid_t pid; + } mon_state; + + struct { + s3k_cidx_t mon_idx; + s3k_pid_t pid; + s3k_reg_t reg; + uint64_t val; + } mon_reg; + + struct { + s3k_cidx_t mon_idx; + s3k_pid_t src_pid; + s3k_cidx_t src_idx; + s3k_pid_t dst_pid; + s3k_cidx_t dst_idx; + } mon_cap; + + struct { + s3k_cidx_t mon_idx; + s3k_pid_t pid; + s3k_cidx_t pmp_idx; + s3k_pmp_slot_t pmp_slot; + } mon_pmp; + + struct { + s3k_cidx_t sock_idx; + s3k_cidx_t cap_idx; + bool send_cap; + uint64_t data[4]; + } sock; +} sys_args_t; + +typedef struct { + s3k_err_t err; + uint64_t val; +} s3k_ret_t; + +_Static_assert(sizeof(sys_args_t) == 64, "sys_args_t has the wrong size"); + +s3k_cap_t s3k_mk_time(s3k_hart_t hart, s3k_time_slot_t bgn, s3k_time_slot_t end) +{ + return (s3k_cap_t){ + .time = { + .type = S3K_CAPTY_TIME, + .hart = hart, + .bgn = bgn, + .mrk = bgn, + .end = end, + } + }; +} + +s3k_cap_t s3k_mk_memory(s3k_addr_t bgn, s3k_addr_t end, s3k_rwx_t rwx) +{ + s3k_tag_t tag = bgn >> S3K_MAX_BLOCK_SIZE; + s3k_block_t bgn_block = (bgn - (tag << S3K_MAX_BLOCK_SIZE)) >> S3K_MIN_BLOCK_SIZE; + s3k_block_t end_block = (end - (tag << S3K_MAX_BLOCK_SIZE)) >> S3K_MIN_BLOCK_SIZE; + + return (s3k_cap_t){ + .mem = { + .type = S3K_CAPTY_MEMORY, + .tag = tag, + .bgn = bgn_block, + .end = end_block, + .mrk = bgn_block, + .rwx = rwx, + .lck = 0, + } + }; +} + +s3k_cap_t s3k_mk_pmp(s3k_napot_t addr, s3k_rwx_t rwx) +{ + return (s3k_cap_t){ + .pmp = { + .type = S3K_CAPTY_PMP, + .addr = addr & 0xFFFFFFFFFF, + .rwx = rwx & 0x7, + .used = 0, + .slot = 0, + } + }; +} + +s3k_cap_t s3k_mk_monitor(s3k_pid_t bgn, s3k_pid_t end) +{ + return (s3k_cap_t){ + .mon = { + .type = S3K_CAPTY_MONITOR, + .bgn = bgn, + .end = end, + .mrk = bgn, + } + }; +} + +s3k_cap_t s3k_mk_channel(s3k_chan_t bgn, s3k_chan_t end) +{ + return (s3k_cap_t){ + .chan = { + .type = S3K_CAPTY_CHANNEL, + .bgn = bgn, + .end = end, + .mrk = bgn, + } + }; +} + +s3k_cap_t s3k_mk_socket(s3k_chan_t chan, s3k_ipc_mode_t mode, s3k_ipc_perm_t perm, uint32_t tag) +{ + return (s3k_cap_t){ + .sock = { + .type = S3K_CAPTY_SOCKET, + .chan = chan, + .mode = mode, + .perm = perm, + .tag = tag, + } + }; +} + +void s3k_napot_decode(s3k_napot_t addr, uint64_t *base, size_t *size) +{ + *base = ((addr + 1) & addr) << 2; + *size = (((addr + 1) ^ addr) + 1) << 2; +} + +s3k_napot_t s3k_napot_encode(s3k_addr_t base, size_t size) +{ + return (base | (size / 2 - 1)) >> 2; +} + +static inline bool is_range_subset(uint64_t a_bgn, uint64_t a_end, uint64_t b_bgn, uint64_t b_end) +{ + return a_bgn <= b_bgn && b_end <= a_end; +} + +static inline bool is_range_prefix(uint64_t a_bgn, uint64_t a_end, uint64_t b_bgn, uint64_t b_end) +{ + return a_bgn == b_bgn && b_end <= a_end; +} + +static inline bool is_bit_subset(uint64_t a, uint64_t b) +{ + return (a & b) == a; +} + +s3k_addr_t s3k_tag_block_to_addr(s3k_tag_t tag, s3k_block_t block) +{ + return ((uint64_t)tag << S3K_MAX_BLOCK_SIZE) + ((uint64_t)block << S3K_MIN_BLOCK_SIZE); +} + +static bool s3k_cap_time_revokable(s3k_cap_t p, s3k_cap_t c) +{ + return (c.type == S3K_CAPTY_TIME) && (p.time.hart == c.time.hart) + && is_range_subset(p.time.bgn, p.time.end, c.time.bgn, c.time.end); +} + +static bool s3k_cap_mem_revokable(s3k_cap_t p, s3k_cap_t c) +{ + if (c.type == S3K_CAPTY_PMP) { + uint64_t p_bgn, p_end, c_bgn, c_end; + p_bgn = s3k_tag_block_to_addr(p.mem.tag, p.mem.bgn); + p_end = s3k_tag_block_to_addr(p.mem.tag, p.mem.end); + s3k_napot_decode(c.pmp.addr, &c_bgn, &c_end); + return is_range_subset(p_bgn, p_end, c_bgn, c_end); + } + return (c.type == S3K_CAPTY_MEMORY) && (p.mem.tag == c.mem.tag) + && is_range_subset(p.mem.bgn, p.mem.end, c.mem.bgn, c.mem.end); +} + +static bool s3k_cap_mon_revokable(s3k_cap_t p, s3k_cap_t c) +{ + return (c.type == S3K_CAPTY_MONITOR) && is_range_subset(p.mon.bgn, p.mon.end, c.mon.bgn, c.mon.end); +} + +static bool s3k_cap_chan_revokable(s3k_cap_t p, s3k_cap_t c) +{ + if (c.type == S3K_CAPTY_SOCKET) { + return is_range_subset(p.chan.bgn, p.chan.end, c.sock.chan, c.sock.chan + 1); + } + return (c.type == S3K_CAPTY_CHANNEL) && is_range_subset(p.chan.bgn, p.chan.end, c.chan.bgn, c.chan.end); +} + +static bool s3k_cap_sock_revokable(s3k_cap_t p, s3k_cap_t c) +{ + return (p.sock.tag == 0) && (c.sock.tag != 0) && (p.sock.chan == c.sock.chan); +} + +bool s3k_cap_is_revokable(s3k_cap_t p, s3k_cap_t c) +{ + switch (p.type) { + case S3K_CAPTY_TIME: + return s3k_cap_time_revokable(p, c); + case S3K_CAPTY_MEMORY: + return s3k_cap_mem_revokable(p, c); + case S3K_CAPTY_MONITOR: + return s3k_cap_mon_revokable(p, c); + case S3K_CAPTY_CHANNEL: + return s3k_cap_chan_revokable(p, c); + case S3K_CAPTY_SOCKET: + return s3k_cap_sock_revokable(p, c); + default: + return false; + } +} + +bool s3k_cap_is_valid(s3k_cap_t c) +{ + switch (c.type) { + case S3K_CAPTY_TIME: + return (c.time.bgn == c.time.mrk) && (c.time.bgn < c.time.end); + case S3K_CAPTY_MEMORY: + return (c.mem.bgn == c.mem.mrk) && (c.mem.bgn < c.mem.end); + case S3K_CAPTY_PMP: + return (c.pmp.used == 0) && (c.pmp.slot == 0); + case S3K_CAPTY_MONITOR: + return (c.mon.bgn == c.mon.mrk) && (c.mon.bgn < c.mon.end); + case S3K_CAPTY_CHANNEL: + return (c.chan.bgn == c.chan.mrk) && (c.chan.bgn < c.chan.end); + case S3K_CAPTY_SOCKET: + return is_bit_subset(c.sock.perm, S3K_IPC_SDATA | S3K_IPC_CDATA | S3K_IPC_SCAP | S3K_IPC_CCAP) + && is_bit_subset(c.sock.mode, S3K_IPC_YIELD | S3K_IPC_NOYIELD); + default: + return false; + } +} + +static bool s3k_cap_time_derivable(s3k_cap_t p, s3k_cap_t c) +{ + return (c.type == S3K_CAPTY_TIME) && (p.time.hart == c.time.hart) + && is_range_prefix(p.time.bgn, p.time.end, c.time.bgn, c.time.end); +} + +static bool s3k_cap_mem_derivable(s3k_cap_t p, s3k_cap_t c) +{ + if (c.type == S3K_CAPTY_PMP) { + uint64_t p_mrk, p_end, c_bgn, c_end; + p_mrk = s3k_tag_block_to_addr(p.mem.tag, p.mem.mrk); + p_end = s3k_tag_block_to_addr(p.mem.tag, p.mem.end); + s3k_napot_decode(c.pmp.addr, &c_bgn, &c_end); + return is_range_subset(p_mrk, p_end, c_bgn, c_end) && is_bit_subset(c.pmp.rwx, p.mem.rwx); + } + return (c.type == S3K_CAPTY_MEMORY) && (p.mem.tag == c.mem.tag) + && is_range_subset(p.mem.mrk, p.mem.end, c.mem.bgn, c.mem.end) && is_bit_subset(c.mem.rwx, p.mem.rwx); +} + +static bool s3k_cap_mon_derivable(s3k_cap_t p, s3k_cap_t c) +{ + return (c.type == S3K_CAPTY_MONITOR) && is_range_subset(p.mon.mrk, p.mon.end, c.mon.bgn, c.mon.end); +} + +static bool s3k_cap_chan_derivable(s3k_cap_t p, s3k_cap_t c) +{ + if (c.type == S3K_CAPTY_SOCKET) { + return (c.sock.tag == 0) && is_range_subset(p.chan.mrk, p.chan.end, c.sock.chan, c.sock.chan + 1); + } + return (c.type == S3K_CAPTY_CHANNEL) && is_range_subset(p.chan.mrk, p.chan.end, c.chan.bgn, c.chan.end); +} + +static bool s3k_cap_sock_derivable(s3k_cap_t p, s3k_cap_t c) +{ + return (c.type == S3K_CAPTY_SOCKET) && (p.sock.chan == c.sock.chan) && (p.sock.tag == 0) && (c.sock.tag != 0) + && (p.sock.mode == c.sock.mode) && (p.sock.perm == c.sock.perm); +} + +bool s3k_cap_is_derivable(s3k_cap_t p, s3k_cap_t c) +{ + switch (p.type) { + case S3K_CAPTY_TIME: + return s3k_cap_time_derivable(p, c); + case S3K_CAPTY_MEMORY: + return s3k_cap_mem_derivable(p, c); + case S3K_CAPTY_MONITOR: + return s3k_cap_mon_derivable(p, c); + case S3K_CAPTY_CHANNEL: + return s3k_cap_chan_derivable(p, c); + case S3K_CAPTY_SOCKET: + return s3k_cap_sock_derivable(p, c); + default: + return false; + } +} diff --git a/.ccls-cache/@home@hak@dev@s3k/common@src@s3k@s3k.c.blob b/.ccls-cache/@home@hak@dev@s3k/common@src@s3k@s3k.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..34d90b3f6f431f7826da4634ed431a6732f5b1a7 GIT binary patch literal 2218 zcma)-acCP=9LL|g)e>%{qK253S~F}zb7qTkD1}uJH*tmiHMD<}&EsJ4)t6{2&D#0oumeoY)T`Al)WpPQcYbqjg)Pv?w@dLhl;kSImO8Q z-~Zlz)U>kH$ZXfBMO4SMUV7rrbzpJSvi9BDujk4a-+G4{P7IckRV6P|Th@q03radi zy4V-_WQ_e%6DSnw!j&Wz;q$1#u27{13k-#tF#EZ-Z(H`SzrViTX*-HTRrk4du1@qo za3mt(N)wL4=P3XKta3jOKJ&n#OS}H)yt@uq9Z-x-$Vpsj2XZ^!3*>encktwIuQc~x z-FrGwhwM0hdvwfq(w+ zVC%{6#m?imJ#UeMnGHy1SzLx>meDGg%0u1prm2;E`8r#4%?lz%B1v3|mcY0Y`iUbp z%m2*GB|f@YhY0nRgMkt*MvIVf5iN4Sh5lEr+!em@O#m>ck#2EXAcPjTI4uxD8*k#t z2a{jET-vf)2W*>ab`z;dycAu6y)U6_oYX@L^i*j9J-r@_o|Rcq+(ZWy%kjn~oiV%% zVrXn~BDgo)3o-YiXE|DbDSi6W!Qu}-8cYfdt;_RMJe+m(7{j&VzHr|T0r#N{hdcb^ zT=ebE>GMI`4K@ujk!;E1G6;`we3nrdIfwU0&JKe6aDu8J{L7G=)?2jyzZlZMYCFJR;x%8ssqd zJwHEpb>aGAU0D_!=0wh0uGt`0Kfm_kXrvJU$LB7)PIQ>&<`u u^SwJiIJJ9SIz%F;bL^CJOqq?8>oeS~7L0wxGL!IBWD1613SIQ`5c(GoJg0{M literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/common@src@s3k@syscall.c b/.ccls-cache/@home@hak@dev@s3k/common@src@s3k@syscall.c new file mode 100644 index 00000000..65af4855 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/common@src@s3k@syscall.c @@ -0,0 +1,634 @@ +#include "s3k/s3k.h" + +typedef enum { + // Basic Info & Registers + S3K_SYS_GET_INFO, // Retrieve system information + S3K_SYS_REG_READ, // Read from a register + S3K_SYS_REG_WRITE, // Write to a register + S3K_SYS_SYNC, // Synchronize memory and time. + S3K_SYS_SLEEP, + + // Capability Management + S3K_SYS_CAP_READ, // Read the properties of a capability. + S3K_SYS_CAP_MOVE, // Move a capability to a different slot. + S3K_SYS_CAP_DELETE, // Delete a capability from the system. + S3K_SYS_CAP_REVOKE, // Deletes derived capabilities. + S3K_SYS_CAP_DERIVE, // Creates a new capability. + + // PMP calls + S3K_SYS_PMP_LOAD, + S3K_SYS_PMP_UNLOAD, + + // Monitor calls + S3K_SYS_MON_SUSPEND, + S3K_SYS_MON_RESUME, + S3K_SYS_MON_STATE_GET, + S3K_SYS_MON_YIELD, + S3K_SYS_MON_REG_READ, + S3K_SYS_MON_REG_WRITE, + S3K_SYS_MON_CAP_READ, + S3K_SYS_MON_CAP_MOVE, + S3K_SYS_MON_PMP_LOAD, + S3K_SYS_MON_PMP_UNLOAD, + + // Socket calls + S3K_SYS_SOCK_SEND, + S3K_SYS_SOCK_RECV, + S3K_SYS_SOCK_SENDRECV, +} s3k_syscall_t; + +typedef union { + struct { + uint64_t a0, a1, a2, a3, a4, a5, a6, a7; + }; + + struct { + uint64_t info; + } get_info; + + struct { + uint64_t reg; + } reg_read; + + struct { + uint64_t reg; + uint64_t val; + } reg_write; + + struct { + uint64_t full; + } sync; + + struct { + uint64_t time; + } sleep; + + struct { + uint64_t idx; + } cap_read; + + struct { + uint64_t src_idx; + uint64_t dst_idx; + } cap_move; + + struct { + uint64_t idx; + } cap_delete; + + struct { + uint64_t idx; + } cap_revoke; + + struct { + uint64_t src_idx; + uint64_t dst_idx; + uint64_t cap_raw; + } cap_derive; + + struct { + uint64_t idx; + uint64_t slot; + } pmp_load; + + struct { + uint64_t idx; + } pmp_unload; + + struct { + uint64_t mon_idx; + uint64_t pid; + } mon_state; + + struct { + uint64_t mon_idx; + uint64_t pid; + uint64_t reg; + } mon_reg_read; + + struct { + uint64_t mon_idx; + uint64_t pid; + uint64_t reg; + uint64_t val; + } mon_reg_write; + + struct { + uint64_t mon_idx; + uint64_t pid; + uint64_t idx; + } mon_cap_read; + + struct { + uint64_t mon_idx; + uint64_t src_pid; + uint64_t src_idx; + uint64_t dst_pid; + uint64_t dst_idx; + } mon_cap_move; + + struct { + uint64_t mon_idx; + uint64_t pid; + uint64_t idx; + uint64_t slot; + } mon_pmp_load; + + struct { + uint64_t mon_idx; + uint64_t pid; + uint64_t idx; + } mon_pmp_unload; + + struct { + uint64_t sock_idx; + uint64_t cap_idx; + uint64_t send_cap; + uint64_t data[4]; + } sock; +} sys_args_t; + +typedef struct { + s3k_err_t err; + uint64_t val; +} s3k_ret_t; + +_Static_assert(sizeof(sys_args_t) == 64, "sys_args_t has the wrong size"); + +#define DO_ECALL(call, args, width) \ + ({ \ + register uint64_t t0 __asm__("t0") = call; \ + register uint64_t a0 __asm__("a0") = args.a0; \ + register uint64_t a1 __asm__("a1") = args.a1; \ + register uint64_t a2 __asm__("a2") = args.a2; \ + register uint64_t a3 __asm__("a3") = args.a3; \ + register uint64_t a4 __asm__("a4") = args.a4; \ + register uint64_t a5 __asm__("a5") = args.a5; \ + register uint64_t a6 __asm__("a6") = args.a6; \ + register uint64_t a7 __asm__("a7") = args.a7; \ + switch ((width + 7) / 8) { \ + case 0: \ + __asm__ volatile("ecall" : "+r"(t0)); \ + break; \ + case 1: \ + __asm__ volatile("ecall" : "+r"(t0), "+r"(a0)); \ + break; \ + case 2: \ + __asm__ volatile("ecall" : "+r"(t0), "+r"(a0) : "r"(a1)); \ + break; \ + case 3: \ + __asm__ volatile("ecall" : "+r"(t0), "+r"(a0) : "r"(a1), "r"(a2)); \ + break; \ + case 4: \ + __asm__ volatile("ecall" : "+r"(t0), "+r"(a0) : "r"(a1), "r"(a2), "r"(a3)); \ + break; \ + case 5: \ + __asm__ volatile("ecall" : "+r"(t0), "+r"(a0) : "r"(a1), "r"(a2), "r"(a3), "r"(a4)); \ + break; \ + case 6: \ + __asm__ volatile("ecall" : "+r"(t0), "+r"(a0) : "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5)); \ + break; \ + case 7: \ + __asm__ volatile("ecall" \ + : "+r"(t0), "+r"(a0) \ + : "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a6)); \ + break; \ + case 8: \ + __asm__ volatile("ecall" \ + : "=r"(t0), "+r"(a0) \ + : "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a6), "r"(a7)); \ + break; \ + } \ + (s3k_ret_t){.err = t0, .val = a0}; \ + }) + +uint64_t s3k_get_pid(void) +{ + sys_args_t args = {.get_info = {0}}; + return DO_ECALL(S3K_SYS_GET_INFO, args, sizeof(args.get_info)).val; +} + +uint64_t s3k_get_time(void) +{ + sys_args_t args = {.get_info = {1}}; + return DO_ECALL(S3K_SYS_GET_INFO, args, sizeof(args.get_info)).val; +} + +uint64_t s3k_get_timeout(void) +{ + sys_args_t args = {.get_info = {2}}; + return DO_ECALL(S3K_SYS_GET_INFO, args, sizeof(args.get_info)).val; +} + +uint64_t s3k_reg_read(s3k_reg_t reg) +{ + sys_args_t args = {.reg_read = {reg}}; + return DO_ECALL(S3K_SYS_REG_READ, args, sizeof(args.reg_read)).val; +} + +uint64_t s3k_reg_write(s3k_reg_t reg, uint64_t val) +{ + sys_args_t args = { + .reg_write = {reg, val} + }; + return DO_ECALL(S3K_SYS_REG_WRITE, args, sizeof(args.reg_write)).val; +} + +void s3k_sync(void) +{ + sys_args_t args = {.sync = {true}}; + DO_ECALL(S3K_SYS_SYNC, args, sizeof(args.sync)); +} + +void s3k_sync_mem(void) +{ + sys_args_t args = {.sync = {false}}; + DO_ECALL(S3K_SYS_SYNC, args, sizeof(args.sync)); +} + +void s3k_sleep(uint64_t time) +{ + sys_args_t args = {.sleep = {time}}; + DO_ECALL(S3K_SYS_SLEEP, args, sizeof(args.sleep)); +} + +s3k_err_t s3k_cap_read(s3k_cidx_t idx, s3k_cap_t *cap) +{ + sys_args_t args = {.cap_read = {idx}}; + s3k_ret_t ret = DO_ECALL(S3K_SYS_CAP_READ, args, sizeof(args.cap_read)); + cap->raw = ret.val; + return ret.err; +} + +s3k_err_t s3k_cap_move(s3k_cidx_t src, s3k_cidx_t dst) +{ + s3k_err_t err; + do { + err = s3k_try_cap_move(src, dst); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_cap_delete(s3k_cidx_t idx) +{ + s3k_err_t err; + do { + err = s3k_try_cap_delete(idx); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_cap_revoke(s3k_cidx_t idx) +{ + s3k_err_t err; + do { + err = s3k_try_cap_revoke(idx); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_cap_derive(s3k_cidx_t src, s3k_cidx_t dst, s3k_cap_t ncap) +{ + s3k_err_t err; + do { + err = s3k_try_cap_derive(src, dst, ncap); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_pmp_load(s3k_cidx_t idx, s3k_pmp_slot_t slot) +{ + s3k_err_t err; + do { + err = s3k_try_pmp_load(idx, slot); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_pmp_unload(s3k_cidx_t idx) +{ + s3k_err_t err; + do { + err = s3k_try_pmp_unload(idx); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_mon_suspend(s3k_cidx_t mon_idx, s3k_pid_t pid) +{ + s3k_err_t err; + do { + err = s3k_try_mon_suspend(mon_idx, pid); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_mon_resume(s3k_cidx_t mon_idx, s3k_pid_t pid) +{ + s3k_err_t err; + do { + err = s3k_try_mon_resume(mon_idx, pid); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_mon_state_get(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_state_t *state) +{ + s3k_err_t err; + do { + err = s3k_try_mon_state_get(mon_idx, pid, state); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_mon_yield(s3k_cidx_t mon_idx, s3k_pid_t pid) +{ + s3k_err_t err; + do { + err = s3k_try_mon_yield(mon_idx, pid); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_mon_reg_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, uint64_t *val) +{ + s3k_err_t err; + do { + err = s3k_try_mon_reg_read(mon_idx, pid, reg, val); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_mon_reg_write(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, uint64_t val) +{ + s3k_err_t err; + do { + err = s3k_try_mon_reg_write(mon_idx, pid, reg, val); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_mon_cap_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx, s3k_cap_t *cap) +{ + s3k_err_t err; + do { + err = s3k_try_mon_cap_read(mon_idx, pid, idx, cap); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_mon_cap_move(s3k_cidx_t mon_idx, s3k_pid_t src_pid, s3k_cidx_t src_idx, s3k_pid_t dst_pid, + s3k_cidx_t dst_idx) +{ + s3k_err_t err; + do { + err = s3k_try_mon_cap_move(mon_idx, src_pid, src_idx, dst_pid, dst_idx); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_mon_pmp_load(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t pmp_idx, s3k_pmp_slot_t pmp_slot) +{ + s3k_err_t err; + do { + err = s3k_try_mon_pmp_load(mon_idx, pid, pmp_idx, pmp_slot); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_mon_pmp_unload(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t pmp_idx) +{ + s3k_err_t err; + do { + err = s3k_try_mon_pmp_unload(mon_idx, pid, pmp_idx); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_err_t s3k_sock_send(s3k_cidx_t sock_idx, const s3k_msg_t *msg) +{ + s3k_err_t err; + do { + err = s3k_try_sock_send(sock_idx, msg); + } while (err == S3K_ERR_PREEMPTED); + return err; +} + +s3k_reply_t s3k_sock_recv(s3k_cidx_t sock_idx, s3k_cidx_t cap_idx) +{ + s3k_reply_t reply; + do { + reply = s3k_try_sock_recv(sock_idx, cap_idx); + } while (reply.err == S3K_ERR_PREEMPTED); + return reply; +} + +s3k_reply_t s3k_sock_sendrecv(s3k_cidx_t sock_idx, const s3k_msg_t *msg) +{ + s3k_reply_t reply; + do { + reply = s3k_try_sock_sendrecv(sock_idx, msg); + } while (reply.err == S3K_ERR_PREEMPTED); + return reply; +} + +s3k_err_t s3k_try_cap_move(s3k_cidx_t src, s3k_cidx_t dst) +{ + sys_args_t args = { + .cap_move = {src, dst} + }; + return DO_ECALL(S3K_SYS_CAP_MOVE, args, sizeof(args.cap_move)).err; +} + +s3k_err_t s3k_try_cap_delete(s3k_cidx_t idx) +{ + const sys_args_t args = {.cap_delete = {idx}}; + return DO_ECALL(S3K_SYS_CAP_DELETE, args, sizeof(args.cap_delete)).err; +} + +s3k_err_t s3k_try_cap_revoke(s3k_cidx_t idx) +{ + sys_args_t args = {.cap_revoke = {idx}}; + return DO_ECALL(S3K_SYS_CAP_REVOKE, args, sizeof(args.cap_revoke)).err; +} + +s3k_err_t s3k_try_cap_derive(s3k_cidx_t src, s3k_cidx_t dst, s3k_cap_t ncap) +{ + sys_args_t args = { + .cap_derive = {src, dst, ncap.raw} + }; + return DO_ECALL(S3K_SYS_CAP_DERIVE, args, sizeof(args.cap_derive)).err; +} + +s3k_err_t s3k_try_pmp_load(s3k_cidx_t idx, s3k_pmp_slot_t slot) +{ + sys_args_t args = { + .pmp_load = {idx, slot} + }; + return DO_ECALL(S3K_SYS_PMP_LOAD, args, sizeof(args.pmp_load)).err; +} + +s3k_err_t s3k_try_pmp_unload(s3k_cidx_t idx) +{ + sys_args_t args = {.pmp_unload = {idx}}; + return DO_ECALL(S3K_SYS_PMP_UNLOAD, args, sizeof(args.pmp_unload)).err; +} + +s3k_err_t s3k_try_mon_suspend(s3k_cidx_t mon, s3k_pid_t pid) +{ + sys_args_t args = { + .mon_state = {mon, pid} + }; + return DO_ECALL(S3K_SYS_MON_SUSPEND, args, sizeof(args.mon_state)).err; +} + +s3k_err_t s3k_try_mon_resume(s3k_cidx_t mon, s3k_pid_t pid) +{ + sys_args_t args = { + .mon_state = {mon, pid} + }; + return DO_ECALL(S3K_SYS_MON_RESUME, args, sizeof(args.mon_state)).err; +} + +s3k_err_t s3k_try_mon_state_get(s3k_cidx_t mon, s3k_pid_t pid, s3k_state_t *state) +{ + sys_args_t args = { + .mon_state = {mon, pid} + }; + s3k_ret_t ret = DO_ECALL(S3K_SYS_MON_STATE_GET, args, sizeof(args.mon_state)); + *state = ret.val; + return ret.err; +} + +s3k_err_t s3k_try_mon_yield(s3k_cidx_t mon, s3k_pid_t pid) +{ + sys_args_t args = { + .mon_state = {mon, pid} + }; + return DO_ECALL(S3K_SYS_MON_YIELD, args, sizeof(args.mon_state)).err; +} + +s3k_err_t s3k_try_mon_reg_read(s3k_cidx_t mon, s3k_pid_t pid, s3k_reg_t reg, uint64_t *val) +{ + sys_args_t args = { + .mon_reg_read = {mon, pid, reg} + }; + s3k_ret_t ret = DO_ECALL(S3K_SYS_MON_REG_READ, args, sizeof(args.mon_reg_read)); + *val = ret.val; + return ret.err; +} + +s3k_err_t s3k_try_mon_reg_write(s3k_cidx_t mon, s3k_pid_t pid, s3k_reg_t reg, uint64_t val) +{ + sys_args_t args = { + .mon_reg_write = {mon, pid, reg, val} + }; + s3k_ret_t ret = DO_ECALL(S3K_SYS_MON_REG_WRITE, args, sizeof(args.mon_reg_write)); + return ret.err; +} + +s3k_err_t s3k_try_mon_cap_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx, s3k_cap_t *cap) +{ + sys_args_t args = { + .mon_cap_read = {mon_idx, pid, idx} + }; + s3k_ret_t ret = DO_ECALL(S3K_SYS_MON_CAP_READ, args, sizeof(args.mon_cap_read)); + if (!ret.err) + cap->raw = ret.val; + return ret.err; +} + +s3k_err_t s3k_try_mon_cap_move(s3k_cidx_t mon_idx, s3k_pid_t src_pid, s3k_cidx_t src_idx, s3k_pid_t dst_pid, + s3k_cidx_t dst_idx) +{ + sys_args_t args = { + .mon_cap_move = {mon_idx, src_pid, src_idx, dst_pid, dst_idx} + }; + return DO_ECALL(S3K_SYS_MON_CAP_MOVE, args, sizeof(args.mon_cap_move)).err; +} + +s3k_err_t s3k_try_mon_pmp_load(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx, s3k_pmp_slot_t slot) +{ + sys_args_t args = { + .mon_pmp_load = {mon_idx, pid, idx, slot} + }; + return DO_ECALL(S3K_SYS_MON_PMP_LOAD, args, sizeof(args.mon_pmp_load)).err; +} + +s3k_err_t s3k_try_mon_pmp_unload(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx) +{ + sys_args_t args = { + .mon_pmp_unload = {mon_idx, pid, idx} + }; + return DO_ECALL(S3K_SYS_MON_PMP_UNLOAD, args, sizeof(args.mon_pmp_unload)).err; +} + +s3k_err_t s3k_try_sock_send(s3k_cidx_t sock_idx, const s3k_msg_t *msg) +{ + sys_args_t args = { + .sock = {.sock_idx = sock_idx, + .cap_idx = msg->cap_idx, + .send_cap = msg->send_cap, + {msg->data[0], msg->data[1], msg->data[2], msg->data[3]}} + }; + return DO_ECALL(S3K_SYS_SOCK_SEND, args, sizeof(args.sock)).err; +} + +s3k_reply_t s3k_try_sock_recv(s3k_cidx_t sock_idx, s3k_cidx_t cap_idx) +{ + sys_args_t args = { + .sock = {.sock_idx = sock_idx, .cap_idx = cap_idx} + }; + register uint64_t t0 __asm__("t0") = S3K_SYS_SOCK_RECV; + register uint64_t a0 __asm__("a0") = args.a0; + register uint64_t a1 __asm__("a1") = args.a1; + register uint64_t a2 __asm__("a2") = args.a2; + register uint64_t a3 __asm__("a3") = args.a3; + register uint64_t a4 __asm__("a4") = args.a4; + register uint64_t a5 __asm__("a5") = args.a5; + register uint64_t a6 __asm__("a6") = args.a6; + register uint64_t a7 __asm__("a7") = args.a7; + __asm__ volatile("ecall" + : "+r"(t0), "+r"(a0), "+r"(a1), "+r"(a2), "+r"(a3), "+r"(a4), "+r"(a5) + : "r"(a6), "r"(a7)); + s3k_reply_t reply; + reply.err = t0; + reply.tag = a0; + reply.cap.raw = a1; + reply.data[0] = a2; + reply.data[1] = a3; + reply.data[2] = a4; + reply.data[3] = a5; + return reply; +} + +s3k_reply_t s3k_try_sock_sendrecv(s3k_cidx_t sock_idx, const s3k_msg_t *msg) +{ + sys_args_t args = { + .sock = {.sock_idx = sock_idx, + .cap_idx = msg->cap_idx, + .send_cap = msg->send_cap, + {msg->data[0], msg->data[1], msg->data[2], msg->data[3]}} + }; + register uint64_t t0 __asm__("t0") = S3K_SYS_SOCK_SENDRECV; + register uint64_t a0 __asm__("a0") = args.a0; + register uint64_t a1 __asm__("a1") = args.a1; + register uint64_t a2 __asm__("a2") = args.a2; + register uint64_t a3 __asm__("a3") = args.a3; + register uint64_t a4 __asm__("a4") = args.a4; + register uint64_t a5 __asm__("a5") = args.a5; + register uint64_t a6 __asm__("a6") = args.a6; + register uint64_t a7 __asm__("a7") = args.a7; + __asm__ volatile("ecall" + : "+r"(t0), "+r"(a0), "+r"(a1), "+r"(a2), "+r"(a3), "+r"(a4), "+r"(a5) + : "r"(a6), "r"(a7)); + s3k_reply_t reply; + reply.err = t0; + reply.tag = a0; + reply.cap.raw = a1; + reply.data[0] = a2; + reply.data[1] = a3; + reply.data[2] = a4; + reply.data[3] = a5; + return reply; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/common@src@s3k@syscall.c.blob b/.ccls-cache/@home@hak@dev@s3k/common@src@s3k@syscall.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..9080fa394bb906c17958a57518f9d9989fc7707f GIT binary patch literal 4596 zcmb7|4{Q`w9>?bmP)j|o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z{DbcvokEkqbwvC+p^q4I0=Fr{(j_m*C9P7W782Q>65=a(T@j^_XBK0eE{@-@pR?7 zca|?({PZ53K2h<})o9dvL~sy-gG_J`$ZvS$rd!viemRn56gQo-F;lQ9JDqf-bmWSp zLpaSf_`|_VTOYV@=e^M~xJ5N~yM{772oVR_$Q*=-cR3N__>F<;!3`_k`_SQ4ycWq@ z?+I@a!v8U_tN7|J5CkHcM6-x9J~ZiHQsi^|q~(Q<=C!ICsFPgMmN>7+z%nv20Lz}9 zoduYXokdxOf>8z~8b9VR9mcuG40 z>j<-s!8*pQ6R=J&>oZuNG3y+xbIj_8)z7Q}SOd%&1bL8=M{sY1-J2#_wP_;tHVf7) fW~IYQXO>koX;zUcu)(r1s|Z#RvzEYGLaqM;y)&%~ literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app0@main.c b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app0@main.c new file mode 100644 index 00000000..aa88d4e9 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app0@main.c @@ -0,0 +1,7 @@ +#include +char *output = (char *)0x80040800ull; + +void main(void) +{ + memcpy(output, "hello, world", 13); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app0@main.c.blob b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app0@main.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..59560d1ea32cc250c5840d00a616f7b8c3bb7b5c GIT binary patch literal 1110 zcmbVLKabNe6t@!B6NVVYQJfU2(S|j49ny;U8C59JloHbH9sa$2v_?>Vw?i8-cG=Irj=qO1l#m>t6 zcLko(iAIu~VaimZ4OXUwyH2&y)spGDVj2lauwc_>&K;mv)!5lp6cMuS4QXehS(Nr5 zNz1G3Ahyc;dZyE>RpgVBtnObV0{kYX0PhK`}p?9lH^#$18GfV4Tz%Xq8(4--q!A? ftHU(SQunb!I6REtod7}rpMX6_2|KqscO&=*PmzRX literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app1@main.c b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app1@main.c new file mode 100644 index 00000000..fa405d83 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app1@main.c @@ -0,0 +1,7 @@ +#include +char *output = (char *)0x80048800ull; + +void main(void) +{ + memcpy(output, "This is application 1", 22); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app1@main.c.blob b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@app1@main.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..f5d36717f011eaacdccfe0e80bb520cc4b69bb57 GIT binary patch literal 1110 zcmbVLy^a$x5Vm&}grYq_ROm#p1w|6YaUxbB1(E1L)bx?#^<_=G>y>{(!gbUL@d6ak z(eMa#l%SJ%1m1uWi3?um4&5ocLWhg>j>q3OGoNRA;Pm9x!*2ipoXMQwj4W}=R#@L( z;!?@yj2i6@a#?7jh>;4DvK--@@M1tgNChbt{{=-aq+0S~fl{tq5UDoP{S3fOY_-CI z&#@4z9E}qH@1x>TG8hiVm={#olwobslpPH+aQfjm|Kf4yt|LZ_RZLgT{_Eqfmz?X# zcs5Ru;DueIMPaetXiObd{q=J$WO&ZTNiC(5%2ig6-wQYAPT`77^OvlFE~Thc?5w%rpNIMtxqBI9V z4X?6?*eUPpna!?Nk%zhtPA@(h1eY3X*9A^m5NzSevrnJjzj@5ohN&W6NuI{NoaMCK zbaqBRrqzs{x%#m!G+z`fjVmF#;P5bVGwPP#U@K_d_q+1cIU fdNLd)6Zf$~I6REtod7}rpMV2L30t>XcO&=*SeS%x literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@boot@main.c b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@boot@main.c new file mode 100644 index 00000000..0c3790bd --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@boot@main.c @@ -0,0 +1,217 @@ +#include "../config.h" +#include "altc/altio.h" +#include "altc/string.h" +#include "s3k/s3k.h" + +#include + +// Defined in payload.S +extern char monitor_bin[]; +extern char crypto_bin[]; +extern char uart_bin[]; +extern size_t monitor_bin_len; +extern size_t crypto_bin_len; +extern size_t uart_bin_len; + +// From plat_conf.h +#define PMP_BOOT_CIDX 0 +#define MEMORY_RAM_CIDX 1 +#define MEMORY_UART_CIDX 2 +#define MEMORY_TIME_CIDX 3 +#define TIME_HART0_CIDX 4 +#define TIME_HART1_CIDX 5 +#define TIME_HART2_CIDX 6 +#define TIME_HART3_CIDX 7 +#define MONITOR_CIDX 8 +#define CHANNEL_CIDX 9 + +s3k_err_t mon_grant_cap(s3k_pid_t pid, s3k_cidx_t src, s3k_cidx_t dst) +{ + return s3k_mon_cap_move(MONITOR_CIDX, BOOT_PID, src, pid, dst); +} + +s3k_err_t mon_pmp_load(s3k_pid_t pid, s3k_cidx_t idx, s3k_pmp_slot_t slot) +{ + return s3k_mon_pmp_load(MONITOR_CIDX, pid, idx, slot); +} + +s3k_err_t mon_write_reg(s3k_pid_t pid, s3k_reg_t regnr, uint64_t val) +{ + return s3k_mon_reg_write(MONITOR_CIDX, pid, regnr, val); +} + +s3k_err_t mon_resume(s3k_pid_t pid) +{ + return s3k_mon_resume(MONITOR_CIDX, pid); +} + +s3k_err_t derive_ram(s3k_cidx_t dst, char *base, size_t len, s3k_mem_perm_t rwx) +{ + s3k_cap_t cap = s3k_mk_memory((uint64_t)base, (uint64_t)base + len, rwx); + return s3k_cap_derive(MEMORY_RAM_CIDX, dst, cap); +} + +s3k_err_t derive_pmp(s3k_cidx_t src, s3k_cidx_t dst, char *base, size_t len, s3k_mem_perm_t rwx) +{ + s3k_napot_t addr = s3k_napot_encode((s3k_addr_t)base, len); + s3k_cap_t cap = s3k_mk_pmp(addr, rwx); + return s3k_cap_derive(src, dst, cap); +} + +void setup_bin(s3k_pid_t pid, char *mem, size_t mem_len, char *bin, size_t bin_len) +{ + derive_ram(0x10, mem, mem_len, S3K_MEM_RWX); + derive_pmp(0x10, 0x11, mem, mem_len, S3K_MEM_RWX); + s3k_pmp_load(0x11, 2); + s3k_sync_mem(); + memcpy(mem, bin, bin_len); + mon_grant_cap(pid, 0x10, 1); + mon_grant_cap(pid, 0x11, 0); + mon_pmp_load(pid, 0, 0); + mon_write_reg(pid, S3K_REG_PC, (uint64_t)mem); + s3k_sync_mem(); +} + +void setup_shared_mem(void) +{ + derive_ram(0x10, SHARED0_MEM, SHARED0_MEM_LEN, S3K_MEM_RW); + derive_pmp(0x10, 0x11, SHARED0_MEM, SHARED0_MEM_LEN, S3K_MEM_RW); + derive_pmp(0x10, 0x12, SHARED0_MEM, SHARED0_MEM_LEN, S3K_MEM_RW); + s3k_cap_delete(0x10); + mon_grant_cap(MONITOR_PID, 0x11, 0x3); + mon_grant_cap(UART_PID, 0x12, 0x3); + mon_pmp_load(MONITOR_PID, 0x3, 0x1); + mon_pmp_load(UART_PID, 0x3, 0x1); + + derive_ram(0x10, SHARED1_MEM, SHARED1_MEM_LEN, S3K_MEM_RW); + derive_pmp(0x10, 0x11, SHARED1_MEM, SHARED1_MEM_LEN, S3K_MEM_RW); + derive_pmp(0x10, 0x12, SHARED1_MEM, SHARED1_MEM_LEN, S3K_MEM_RW); + s3k_cap_delete(0x10); + mon_grant_cap(MONITOR_PID, 0x11, 0x4); + mon_grant_cap(CRYPTO_PID, 0x12, 0x2); + mon_pmp_load(MONITOR_PID, 0x4, 0x1); + mon_pmp_load(CRYPTO_PID, 0x2, 0x1); +} + +void setup_uart_pmp(void) +{ + derive_pmp(MEMORY_UART_CIDX, 0x10, (void *)UART0_BASE_ADDR, 0x1000, S3K_MEM_RW); + mon_grant_cap(UART_PID, 0x10, 0x4); + mon_pmp_load(UART_PID, 0x4, 0x2); +} + +void setup_app_mem(void) +{ + derive_ram(0x10, APP0_MEM, APP0_MEM_LEN, S3K_MEM_RWX); + derive_ram(0x11, APP1_MEM, APP1_MEM_LEN, S3K_MEM_RWX); + mon_grant_cap(MONITOR_PID, 0x10, 0x5); + mon_grant_cap(MONITOR_PID, 0x11, 0x6); +} + +void setup_uart_ipc(s3k_chan_t chan, s3k_ipc_mode_t mode, s3k_ipc_perm_t perm) +{ + s3k_cap_derive(CHANNEL_CIDX, 0x10, s3k_mk_socket(chan, mode, perm, 0)); + s3k_cap_derive(0x10, 0x11, s3k_mk_socket(chan, mode, perm, 1)); + mon_grant_cap(MONITOR_PID, 0x10, 0x7); + mon_grant_cap(UART_PID, 0x11, 0x5); +} + +void setup_crypto_ipc(s3k_chan_t chan, s3k_ipc_mode_t mode, s3k_ipc_perm_t perm) +{ + s3k_cap_derive(CHANNEL_CIDX, 0x10, s3k_mk_socket(chan, mode, perm, 0)); + s3k_cap_derive(0x10, 0x11, s3k_mk_socket(chan, mode, perm, 1)); + mon_grant_cap(CRYPTO_PID, 0x10, 0x3); + mon_grant_cap(MONITOR_PID, 0x11, 0x8); +} + +void setup_app_channels(void) +{ + s3k_cap_derive(CHANNEL_CIDX, 0x10, s3k_mk_channel(2, 4)); + mon_grant_cap(MONITOR_PID, 0x10, 0x9); +} + +void setup_app_monitoring(void) +{ + // Monitor for boot, monitor, crypto, uart + s3k_cap_derive(MONITOR_CIDX, 0x10, s3k_mk_monitor(0, 4)); + // Monitor for app0, app1 + s3k_cap_derive(MONITOR_CIDX, 0x11, s3k_mk_monitor(4, 6)); + s3k_cap_delete(MONITOR_CIDX); + s3k_cap_move(0x10, MONITOR_CIDX); + mon_grant_cap(MONITOR_PID, 0x11, 0xa); +} + +void setup_time(void) +{ + s3k_cap_derive(TIME_HART0_CIDX, 0x10, s3k_mk_time(S3K_MIN_HART, 0, UART_TIME)); + s3k_cap_derive(TIME_HART0_CIDX, 0x11, s3k_mk_time(S3K_MIN_HART, UART_TIME, S3K_SLOT_CNT)); + s3k_cap_derive(0x10, 0x12, s3k_mk_time(S3K_MIN_HART, 0, UART_TIME - 2)); + s3k_cap_derive(0x11, 0x13, s3k_mk_time(S3K_MIN_HART, UART_TIME, S3K_SLOT_CNT - 2)); + + mon_grant_cap(UART_PID, 0x10, 0x2); + mon_grant_cap(MONITOR_PID, 0x11, 0x2); +} + +void start_proc(void) +{ + s3k_mon_resume(MONITOR_CIDX, CRYPTO_PID); + while (s3k_mon_yield(MONITOR_CIDX, CRYPTO_PID)) + ; + alt_puts("{crypto started}"); + + s3k_mon_resume(MONITOR_CIDX, MONITOR_PID); + while (s3k_mon_yield(MONITOR_CIDX, MONITOR_PID)) + ; + alt_puts("{monitor started}"); + + s3k_mon_resume(MONITOR_CIDX, UART_PID); + while (s3k_mon_yield(MONITOR_CIDX, UART_PID)) + ; + // UART outputs "uart started" + alt_puts("{error}"); + while (1) + ; +} + +void trap_handler(void) __attribute__((interrupt("machine"))); + +void trap_handler(void) +{ +} + +void main(void) +{ + s3k_reg_write(S3K_REG_TPC, (uint64_t)trap_handler); + s3k_cap_delete(TIME_HART1_CIDX); + s3k_cap_delete(TIME_HART2_CIDX); + s3k_cap_delete(TIME_HART3_CIDX); + derive_pmp(MEMORY_UART_CIDX, 0x5, (void *)UART0_BASE_ADDR, 0x1000, S3K_MEM_RW); + s3k_pmp_load(5, 1); + s3k_sync_mem(); + + alt_puts("{setting up memory ...}"); + /* Copy binary of monitor process, setup PMP and program counter. */ + setup_bin(MONITOR_PID, MONITOR_MEM, MONITOR_MEM_LEN, monitor_bin, monitor_bin_len); + /* Copy binary of crypto process, setup PMP and program counter. */ + setup_bin(CRYPTO_PID, CRYPTO_MEM, CRYPTO_MEM_LEN, crypto_bin, crypto_bin_len); + /* Copy binary of uart process, setup PMP and program counter. */ + setup_bin(UART_PID, UART_MEM, UART_MEM_LEN, uart_bin, uart_bin_len); + /* Give UART and Monitor processes shared memory */ + setup_shared_mem(); + /* Give UART process access to uart */ + setup_uart_pmp(); + /* Give monitor access to application memory */ + setup_app_mem(); + + alt_puts("{setting up ipc}"); + setup_uart_ipc(0, S3K_IPC_NOYIELD, S3K_IPC_CDATA | S3K_IPC_SDATA); + setup_crypto_ipc(1, S3K_IPC_NOYIELD, S3K_IPC_CDATA | S3K_IPC_SDATA); + setup_app_channels(); + setup_app_monitoring(); + + alt_puts("{setting up time}"); + setup_time(); + + alt_puts("{starting processes}"); + start_proc(); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@boot@main.c.blob b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@boot@main.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..d9d853d219b5b35accc6b5584fae09cd31853077 GIT binary patch literal 3921 zcmbVOdr(y875~0VM_~nBVS}qIx8EQjl4W;!DJsxK(IR0NLxJ1 z_S^5=^E>DK&f{)2dUSn9@gERE=4PLVH#a*rm|c8}Igr1>>=%9Od1o*H7apHC5ELCj zpJ;CI`GRJTL-3lMD8}h_c$>bHY0f5}xIyqX<+ub9ocP4eB~M0xV$2%@qS-ApnBDFc zPfl)ue3reMa|=us(=4;#b-FjYcyl1=a`BC(X7s3Mi)ZvntpA^l)8}mzny3|};px3` zT*x2iakO#{x6tI}f)u5@?A8eL)PzL5Yo6Y7Bu|tmt#Up5(XFAEtSvslMW8-@uG!&r zxp^^bCemp1cu+H##^6D8hJgYj6ps-e&bZ`ZNGf`~pG@PPKF)=s=u_{<35z}uo<1W3dSK#~}Kj-#2T+wKP zt2GSk_Q`O1OmxJ^V1lMc!L{|h9?z~Tx~$4^qeBdG04rx_z?_E5WH5(ZDm#3Yxys7f zO-eM3Tsl0vOl2PwJiKhH!=0K=mcgCq6}9aR=0>t?`_?&AXU)&QN>NhTBnm;E6Zxj- zT;RehhO%jKxI^4z=rVwt43wn;MpAF_?tAI^AAX?#ihN)r#6o`p&(urqGynXSudmQYUA!o?KpYN_Yzg%+5@)kRB-ss)0B7!6r2tEqY+$bNT>HCLEpG)XhRiQ!fDv2x5 z9^Mm)9?qPcK{zu3k_jgUmQ+P&BoP;DiVX}dMio*10{7o9nO*snNA^dzom}r&d{%Qd zk-=xt2lCV7$C$A+Y1<6T=dYdHnh*mur)?uCEk`e|G1m;znBmQbAJ^rN(u?cN^-QVe zXQ$a6r{% zVQRc6sKQ2(C_^CyKmzQT})Ma)m$sKS!}?T-D0Plm0nKXe$z0sVnIcj-M+9&2}iFGroJb0AeO1xsj%8W z8fCU({KQ{m#jT_j;@y6j*Vsp*GKoSF$VNyxOoD&gyCap!SEzWhcS0&M8*rv* zr$A*uhAVS{T%eU%+gXxf@*C1@)%L~9s%sUf2&?LQQUo}9tsYnf8De!}YF=uk6{qE; zft*n=qsoenCL`2qC)o)M?8l4d)Za6Xn1YISJ<;V-KABNFSX0 zjs0+zymuDc|Nc+uZjG&mn_peMObKh6LRFN4SRgK~Rtt*&q$$kPxOvQqwyIk(>e}K| zdn(igZK;$!RB}a(Q*R;MGO^j?MI6q-iOD zP%2{eu_llx7JMojIGX+ckwO100Qm+mmC27c#1~;4kK&7vbR%W@_|lax-=)DRpO~uB zsx`1JDs8ZL?Ui=AeU;@N?L#S3*n=JrWDg03gaV8cPy!6u(M^MMa`rxdQ$eTSaZA`G zCM#ZQSPHY;z&60yX>h_hzy{!aggpYXuec9r?62rwVa21#qnQxJt;7U&^@ICc!&O)g zn_j8V<5M5ekvyP1QJV-;4>C0Mj6?5$>A0xB2vYiB*ZoDYL%px6BaB&|z8nfwXQ_kP ztGCqCjd}b_+r@t^s6Q6{T z#cgaGoV$y=p?yzOoPbD1l1H+^@`e3N&OJE(D0*6jbb+Fd{jKIW*Ky^eD33ys02u!T DL>g=9 literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@config.h b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@config.h new file mode 100644 index 00000000..2f4c637e --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@config.h @@ -0,0 +1,39 @@ +#pragma once + +/* Boot process */ +#define BOOT_PID 0 +#define BOOT_MEM ((char *)0x80010000ull) +#define BOOT_LEN 0x10000 + +/* Monitor process */ +#define MONITOR_PID 1 +#define MONITOR_MEM ((char *)0x80020000ull) +#define MONITOR_MEM_LEN (0x8000ull) + +/* Crypto process */ +#define CRYPTO_PID 2 +#define CRYPTO_MEM ((char *)0x80028000ull) +#define CRYPTO_MEM_LEN (0x8000ull) + +/* UART process */ +#define UART_PID 3 +#define UART_TIME 10 /* number of time slots for uart */ +#define UART_MEM ((char *)0x80030000ull) +#define UART_MEM_LEN (0x8000ull) + +/* Shared memory between monitor and uart */ +#define SHARED0_MEM ((char *)0x80038000ull) +#define SHARED0_MEM_LEN (0x4000ull) +/* Shared memory between monitor and crypto */ +#define SHARED1_MEM ((char *)0x8003C000ull) +#define SHARED1_MEM_LEN (0x4000ull) + +/* Application 0 memory area */ +#define APP0_PID 4 +#define APP0_MEM ((char *)0x80040000ull) +#define APP0_MEM_LEN (0x8000ull) + +/* Application 1 memory area */ +#define APP1_PID 5 +#define APP1_MEM ((char *)0x80048000ull) +#define APP1_MEM_LEN (0x8000ull) diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@config.h.blob b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@config.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..8db8508be003f97045f3a45547bd0b02cb12d76b GIT binary patch literal 2554 zcmbVMU2NM_7qP$=j{(=xJ_ZV2$G z;_s|ljL3{%*0RO%|I6m5bYns-j`KOyfLH0p^sZ_jOoLD|4M9^!1x?#u;G=Q;j9)B7 z;}J2E5Y(cqm2!$;TDhDu7RfV<#}5`h$2@X0rev*>p_umJj$;SUtU4_3Oh}11uc^gS znIA8f1asOHWRUXyInm-RwV)*8o{|t4bmq;kdfliBIoo2UdO)cmmy`KPLvh;s?+&me zgeLQOC7V+W-n6oYRYTjh>UmVd>GY&x3YsowHAV8)tRmu6tw@1)lNj)9qj~+5GNesKo5{OnZ1(y`1ij1Uc2Y6-jRWR z+?+HtFbsxnA`MbUTv#l}R}|Y&TZHui?r|LcaOC2i!2DZpx@e%b*+Y%;8S7h74WeKN z>jS*kQ9T>nw(j2}pb@AHJQONu9mXrC9CLE6Ikzwz}-&zb@Nj%_CN5+{XlPP(OU2VC_4Pa+$-h4-~Y7l?H$QTnZe`$B;81iEEl<`9ZVByx|y{x?2vES z{MF&#mM(NBQ^SLq)QEHcmKVxZrsC;x#j_r*hd}|7L3Q7G`LADp`s^ukkv!sAwMwpd zwxX>N4^G8p;tetw7c!rImFBEk| zEy)J70WK6Exlq^qI5+%}7QE0mvM-%U*<*49+sLF>pHO-Ys9^`|1MGKFneS{m`SASd z9^40YAxMpyc+55NX4DKF1Ck4Iy7l#4hd#L6QQ}&wUKOL`nrXr z@7sq?tn>goOtZly<*3WGHyhDL&;-ml9WGpC-tQQiSs>leJLs-cX>CHAU + +static const uint32_t rc[10] = { + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36, +}; + +static const uint8_t SBOX[256] = { + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, + 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, + 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, + 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, + 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, + 0xcf, 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, + 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec, 0x5f, + 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, + 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, + 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, + 0xae, 0x08, 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 0x70, + 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, + 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, + 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16, +}; +static const uint8_t RSBOX[256] = { + 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, + 0x82, 0x9b, 0x2f, 0x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, 0xec, 0x5f, 0x60, + 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d, + 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, + 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d, +}; + +static const uint8_t GF2[256] = { + 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x22, 0x24, + 0x26, 0x28, 0x2a, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e, 0x40, 0x42, 0x44, 0x46, 0x48, 0x4a, + 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e, 0x60, 0x62, 0x64, 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, + 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7e, 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x96, + 0x98, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa4, 0xa6, 0xa8, 0xaa, 0xac, 0xae, 0xb0, 0xb2, 0xb4, 0xb6, 0xb8, 0xba, 0xbc, + 0xbe, 0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce, 0xd0, 0xd2, 0xd4, 0xd6, 0xd8, 0xda, 0xdc, 0xde, 0xe0, 0xe2, + 0xe4, 0xe6, 0xe8, 0xea, 0xec, 0xee, 0xf0, 0xf2, 0xf4, 0xf6, 0xf8, 0xfa, 0xfc, 0xfe, 0x1b, 0x19, 0x1f, 0x1d, 0x13, + 0x11, 0x17, 0x15, 0x0b, 0x09, 0x0f, 0x0d, 0x03, 0x01, 0x07, 0x05, 0x3b, 0x39, 0x3f, 0x3d, 0x33, 0x31, 0x37, 0x35, + 0x2b, 0x29, 0x2f, 0x2d, 0x23, 0x21, 0x27, 0x25, 0x5b, 0x59, 0x5f, 0x5d, 0x53, 0x51, 0x57, 0x55, 0x4b, 0x49, 0x4f, + 0x4d, 0x43, 0x41, 0x47, 0x45, 0x7b, 0x79, 0x7f, 0x7d, 0x73, 0x71, 0x77, 0x75, 0x6b, 0x69, 0x6f, 0x6d, 0x63, 0x61, + 0x67, 0x65, 0x9b, 0x99, 0x9f, 0x9d, 0x93, 0x91, 0x97, 0x95, 0x8b, 0x89, 0x8f, 0x8d, 0x83, 0x81, 0x87, 0x85, 0xbb, + 0xb9, 0xbf, 0xbd, 0xb3, 0xb1, 0xb7, 0xb5, 0xab, 0xa9, 0xaf, 0xad, 0xa3, 0xa1, 0xa7, 0xa5, 0xdb, 0xd9, 0xdf, 0xdd, + 0xd3, 0xd1, 0xd7, 0xd5, 0xcb, 0xc9, 0xcf, 0xcd, 0xc3, 0xc1, 0xc7, 0xc5, 0xfb, 0xf9, 0xff, 0xfd, 0xf3, 0xf1, 0xf7, + 0xf5, 0xeb, 0xe9, 0xef, 0xed, 0xe3, 0xe1, 0xe7, 0xe5, +}; + +static const uint8_t GF3[256] = { + 0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x18, 0x1b, 0x1e, 0x1d, 0x14, 0x17, 0x12, 0x11, 0x30, 0x33, 0x36, + 0x35, 0x3c, 0x3f, 0x3a, 0x39, 0x28, 0x2b, 0x2e, 0x2d, 0x24, 0x27, 0x22, 0x21, 0x60, 0x63, 0x66, 0x65, 0x6c, 0x6f, + 0x6a, 0x69, 0x78, 0x7b, 0x7e, 0x7d, 0x74, 0x77, 0x72, 0x71, 0x50, 0x53, 0x56, 0x55, 0x5c, 0x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, 0x25, 0x26, 0x2f, 0x2c, 0x29, 0x2a, 0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, + 0x02, 0x13, 0x10, 0x15, 0x16, 0x1f, 0x1c, 0x19, 0x1a, +}; + +static const uint8_t GF9[256] = { + 0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f, 0x48, 0x41, 0x5a, 0x53, 0x6c, 0x65, 0x7e, 0x77, 0x90, 0x99, 0x82, + 0x8b, 0xb4, 0xbd, 0xa6, 0xaf, 0xd8, 0xd1, 0xca, 0xc3, 0xfc, 0xf5, 0xee, 0xe7, 0x3b, 0x32, 0x29, 0x20, 0x1f, 0x16, + 0x0d, 0x04, 0x73, 0x7a, 0x61, 0x68, 0x57, 0x5e, 0x45, 0x4c, 0xab, 0xa2, 0xb9, 0xb0, 0x8f, 0x86, 0x9d, 0x94, 0xe3, + 0xea, 0xf1, 0xf8, 0xc7, 0xce, 0xd5, 0xdc, 0x76, 0x7f, 0x64, 0x6d, 0x52, 0x5b, 0x40, 0x49, 0x3e, 0x37, 0x2c, 0x25, + 0x1a, 0x13, 0x08, 0x01, 0xe6, 0xef, 0xf4, 0xfd, 0xc2, 0xcb, 0xd0, 0xd9, 0xae, 0xa7, 0xbc, 0xb5, 0x8a, 0x83, 0x98, + 0x91, 0x4d, 0x44, 0x5f, 0x56, 0x69, 0x60, 0x7b, 0x72, 0x05, 0x0c, 0x17, 0x1e, 0x21, 0x28, 0x33, 0x3a, 0xdd, 0xd4, + 0xcf, 0xc6, 0xf9, 0xf0, 0xeb, 0xe2, 0x95, 0x9c, 0x87, 0x8e, 0xb1, 0xb8, 0xa3, 0xaa, 0xec, 0xe5, 0xfe, 0xf7, 0xc8, + 0xc1, 0xda, 0xd3, 0xa4, 0xad, 0xb6, 0xbf, 0x80, 0x89, 0x92, 0x9b, 0x7c, 0x75, 0x6e, 0x67, 0x58, 0x51, 0x4a, 0x43, + 0x34, 0x3d, 0x26, 0x2f, 0x10, 0x19, 0x02, 0x0b, 0xd7, 0xde, 0xc5, 0xcc, 0xf3, 0xfa, 0xe1, 0xe8, 0x9f, 0x96, 0x8d, + 0x84, 0xbb, 0xb2, 0xa9, 0xa0, 0x47, 0x4e, 0x55, 0x5c, 0x63, 0x6a, 0x71, 0x78, 0x0f, 0x06, 0x1d, 0x14, 0x2b, 0x22, + 0x39, 0x30, 0x9a, 0x93, 0x88, 0x81, 0xbe, 0xb7, 0xac, 0xa5, 0xd2, 0xdb, 0xc0, 0xc9, 0xf6, 0xff, 0xe4, 0xed, 0x0a, + 0x03, 0x18, 0x11, 0x2e, 0x27, 0x3c, 0x35, 0x42, 0x4b, 0x50, 0x59, 0x66, 0x6f, 0x74, 0x7d, 0xa1, 0xa8, 0xb3, 0xba, + 0x85, 0x8c, 0x97, 0x9e, 0xe9, 0xe0, 0xfb, 0xf2, 0xcd, 0xc4, 0xdf, 0xd6, 0x31, 0x38, 0x23, 0x2a, 0x15, 0x1c, 0x07, + 0x0e, 0x79, 0x70, 0x6b, 0x62, 0x5d, 0x54, 0x4f, 0x46, +}; + +static const uint8_t GF11[256] = { + 0x00, 0x0b, 0x16, 0x1d, 0x2c, 0x27, 0x3a, 0x31, 0x58, 0x53, 0x4e, 0x45, 0x74, 0x7f, 0x62, 0x69, 0xb0, 0xbb, 0xa6, + 0xad, 0x9c, 0x97, 0x8a, 0x81, 0xe8, 0xe3, 0xfe, 0xf5, 0xc4, 0xcf, 0xd2, 0xd9, 0x7b, 0x70, 0x6d, 0x66, 0x57, 0x5c, + 0x41, 0x4a, 0x23, 0x28, 0x35, 0x3e, 0x0f, 0x04, 0x19, 0x12, 0xcb, 0xc0, 0xdd, 0xd6, 0xe7, 0xec, 0xf1, 0xfa, 0x93, + 0x98, 0x85, 0x8e, 0xbf, 0xb4, 0xa9, 0xa2, 0xf6, 0xfd, 0xe0, 0xeb, 0xda, 0xd1, 0xcc, 0xc7, 0xae, 0xa5, 0xb8, 0xb3, + 0x82, 0x89, 0x94, 0x9f, 0x46, 0x4d, 0x50, 0x5b, 0x6a, 0x61, 0x7c, 0x77, 0x1e, 0x15, 0x08, 0x03, 0x32, 0x39, 0x24, + 0x2f, 0x8d, 0x86, 0x9b, 0x90, 0xa1, 0xaa, 0xb7, 0xbc, 0xd5, 0xde, 0xc3, 0xc8, 0xf9, 0xf2, 0xef, 0xe4, 0x3d, 0x36, + 0x2b, 0x20, 0x11, 0x1a, 0x07, 0x0c, 0x65, 0x6e, 0x73, 0x78, 0x49, 0x42, 0x5f, 0x54, 0xf7, 0xfc, 0xe1, 0xea, 0xdb, + 0xd0, 0xcd, 0xc6, 0xaf, 0xa4, 0xb9, 0xb2, 0x83, 0x88, 0x95, 0x9e, 0x47, 0x4c, 0x51, 0x5a, 0x6b, 0x60, 0x7d, 0x76, + 0x1f, 0x14, 0x09, 0x02, 0x33, 0x38, 0x25, 0x2e, 0x8c, 0x87, 0x9a, 0x91, 0xa0, 0xab, 0xb6, 0xbd, 0xd4, 0xdf, 0xc2, + 0xc9, 0xf8, 0xf3, 0xee, 0xe5, 0x3c, 0x37, 0x2a, 0x21, 0x10, 0x1b, 0x06, 0x0d, 0x64, 0x6f, 0x72, 0x79, 0x48, 0x43, + 0x5e, 0x55, 0x01, 0x0a, 0x17, 0x1c, 0x2d, 0x26, 0x3b, 0x30, 0x59, 0x52, 0x4f, 0x44, 0x75, 0x7e, 0x63, 0x68, 0xb1, + 0xba, 0xa7, 0xac, 0x9d, 0x96, 0x8b, 0x80, 0xe9, 0xe2, 0xff, 0xf4, 0xc5, 0xce, 0xd3, 0xd8, 0x7a, 0x71, 0x6c, 0x67, + 0x56, 0x5d, 0x40, 0x4b, 0x22, 0x29, 0x34, 0x3f, 0x0e, 0x05, 0x18, 0x13, 0xca, 0xc1, 0xdc, 0xd7, 0xe6, 0xed, 0xf0, + 0xfb, 0x92, 0x99, 0x84, 0x8f, 0xbe, 0xb5, 0xa8, 0xa3, +}; + +static const uint8_t GF13[256] = { + 0x00, 0x0d, 0x1a, 0x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c3, 0xce, 0xed, 0xe0, + 0xf7, 0xfa, 0xb7, 0xba, 0xad, 0xa0, 0x83, 0x8e, 0x99, 0x94, 0xdf, 0xd2, 0xc5, 0xc8, 0xeb, 0xe6, 0xf1, 0xfc, 0x67, + 0x6a, 0x7d, 0x70, 0x53, 0x5e, 0x49, 0x44, 0x0f, 0x02, 0x15, 0x18, 0x3b, 0x36, 0x21, 0x2c, 0x0c, 0x01, 0x16, 0x1b, + 0x38, 0x35, 0x22, 0x2f, 0x64, 0x69, 0x7e, 0x73, 0x50, 0x5d, 0x4a, 0x47, 0xdc, 0xd1, 0xc6, 0xcb, 0xe8, 0xe5, 0xf2, + 0xff, 0xb4, 0xb9, 0xae, 0xa3, 0x80, 0x8d, 0x9a, 0x97, +}; + +static const uint8_t GF14[256] = { + 0x00, 0x0e, 0x1c, 0x12, 0x38, 0x36, 0x24, 0x2a, 0x70, 0x7e, 0x6c, 0x62, 0x48, 0x46, 0x54, 0x5a, 0xe0, 0xee, 0xfc, + 0xf2, 0xd8, 0xd6, 0xc4, 0xca, 0x90, 0x9e, 0x8c, 0x82, 0xa8, 0xa6, 0xb4, 0xba, 0xdb, 0xd5, 0xc7, 0xc9, 0xe3, 0xed, + 0xff, 0xf1, 0xab, 0xa5, 0xb7, 0xb9, 0x93, 0x9d, 0x8f, 0x81, 0x3b, 0x35, 0x27, 0x29, 0x03, 0x0d, 0x1f, 0x11, 0x4b, + 0x45, 0x57, 0x59, 0x73, 0x7d, 0x6f, 0x61, 0xad, 0xa3, 0xb1, 0xbf, 0x95, 0x9b, 0x89, 0x87, 0xdd, 0xd3, 0xc1, 0xcf, + 0xe5, 0xeb, 0xf9, 0xf7, 0x4d, 0x43, 0x51, 0x5f, 0x75, 0x7b, 0x69, 0x67, 0x3d, 0x33, 0x21, 0x2f, 0x05, 0x0b, 0x19, + 0x17, 0x76, 0x78, 0x6a, 0x64, 0x4e, 0x40, 0x52, 0x5c, 0x06, 0x08, 0x1a, 0x14, 0x3e, 0x30, 0x22, 0x2c, 0x96, 0x98, + 0x8a, 0x84, 0xae, 0xa0, 0xb2, 0xbc, 0xe6, 0xe8, 0xfa, 0xf4, 0xde, 0xd0, 0xc2, 0xcc, 0x41, 0x4f, 0x5d, 0x53, 0x79, + 0x77, 0x65, 0x6b, 0x31, 0x3f, 0x2d, 0x23, 0x09, 0x07, 0x15, 0x1b, 0xa1, 0xaf, 0xbd, 0xb3, 0x99, 0x97, 0x85, 0x8b, + 0xd1, 0xdf, 0xcd, 0xc3, 0xe9, 0xe7, 0xf5, 0xfb, 0x9a, 0x94, 0x86, 0x88, 0xa2, 0xac, 0xbe, 0xb0, 0xea, 0xe4, 0xf6, + 0xf8, 0xd2, 0xdc, 0xce, 0xc0, 0x7a, 0x74, 0x66, 0x68, 0x42, 0x4c, 0x5e, 0x50, 0x0a, 0x04, 0x16, 0x18, 0x32, 0x3c, + 0x2e, 0x20, 0xec, 0xe2, 0xf0, 0xfe, 0xd4, 0xda, 0xc8, 0xc6, 0x9c, 0x92, 0x80, 0x8e, 0xa4, 0xaa, 0xb8, 0xb6, 0x0c, + 0x02, 0x10, 0x1e, 0x34, 0x3a, 0x28, 0x26, 0x7c, 0x72, 0x60, 0x6e, 0x44, 0x4a, 0x58, 0x56, 0x37, 0x39, 0x2b, 0x25, + 0x0f, 0x01, 0x13, 0x1d, 0x47, 0x49, 0x5b, 0x55, 0x7f, 0x71, 0x63, 0x6d, 0xd7, 0xd9, 0xcb, 0xc5, 0xef, 0xe1, 0xf3, + 0xfd, 0xa7, 0xa9, 0xbb, 0xb5, 0x9f, 0x91, 0x83, 0x8d, +}; + +static uint32_t subword(uint32_t word) +{ + return (uint32_t)SBOX[word & 0xFF] | ((uint32_t)SBOX[(word >> 8) & 0xFF] << 8) + | ((uint32_t)SBOX[(word >> 16) & 0xFF] << 16) | ((uint32_t)SBOX[(word >> 24) & 0xFF] << 24); +} + +static uint32_t rotword(uint32_t word) +{ + return (word >> 8) | (word << 24); +} + +static void subshiftrows(uint8_t buf[16]) +{ + uint8_t tmp; + + // 1st row + buf[0] = SBOX[buf[0]]; + buf[4] = SBOX[buf[4]]; + buf[8] = SBOX[buf[8]]; + buf[12] = SBOX[buf[12]]; + + // 2nd row + tmp = SBOX[buf[1]]; + buf[1] = SBOX[buf[5]]; + buf[5] = SBOX[buf[9]]; + buf[9] = SBOX[buf[13]]; + buf[13] = tmp; + + // 3rd row + tmp = SBOX[buf[2]]; + buf[2] = SBOX[buf[10]]; + buf[10] = tmp; + tmp = SBOX[buf[6]]; + buf[6] = SBOX[buf[14]]; + buf[14] = tmp; + + // 4th row + tmp = SBOX[buf[15]]; + buf[15] = SBOX[buf[11]]; + buf[11] = SBOX[buf[7]]; + buf[7] = SBOX[buf[3]]; + buf[3] = tmp; +} + +static void subshiftrows_inv(uint8_t buf[16]) +{ + uint8_t tmp; + + // 1st row + buf[0] = RSBOX[buf[0]]; + buf[4] = RSBOX[buf[4]]; + buf[8] = RSBOX[buf[8]]; + buf[12] = RSBOX[buf[12]]; + + // 2nd row + tmp = RSBOX[buf[13]]; + buf[13] = RSBOX[buf[9]]; + buf[9] = RSBOX[buf[5]]; + buf[5] = RSBOX[buf[1]]; + buf[1] = tmp; + + // 3rd row + tmp = RSBOX[buf[10]]; + buf[10] = RSBOX[buf[2]]; + buf[2] = tmp; + tmp = RSBOX[buf[14]]; + buf[14] = RSBOX[buf[6]]; + buf[6] = tmp; + + // 4th row + tmp = RSBOX[buf[11]]; + buf[11] = RSBOX[buf[15]]; + buf[15] = RSBOX[buf[3]]; + buf[3] = RSBOX[buf[7]]; + buf[7] = tmp; +} + +static void mixcolumns(uint8_t buf[16]) +{ + uint8_t t[4]; + for (uint8_t i = 0; i < 16; i += 4) { + t[0] = buf[i + 0]; + t[1] = buf[i + 1]; + t[2] = buf[i + 2]; + t[3] = buf[i + 3]; + buf[i + 0] = GF2[t[0]] ^ GF3[t[1]] ^ t[2] ^ t[3]; + buf[i + 1] = GF2[t[1]] ^ GF3[t[2]] ^ t[3] ^ t[0]; + buf[i + 2] = GF2[t[2]] ^ GF3[t[3]] ^ t[0] ^ t[1]; + buf[i + 3] = GF2[t[3]] ^ GF3[t[0]] ^ t[1] ^ t[2]; + } +} + +static void mixcolumns_inv(uint8_t buf[16]) +{ + uint8_t t[4]; + for (uint8_t i = 0; i < 16; i += 4) { + t[0] = buf[i + 0]; + t[1] = buf[i + 1]; + t[2] = buf[i + 2]; + t[3] = buf[i + 3]; + buf[i + 0] = GF14[t[0]] ^ GF11[t[1]] ^ GF13[t[2]] ^ GF9[t[3]]; + buf[i + 1] = GF14[t[1]] ^ GF11[t[2]] ^ GF13[t[3]] ^ GF9[t[0]]; + buf[i + 2] = GF14[t[2]] ^ GF11[t[3]] ^ GF13[t[0]] ^ GF9[t[1]]; + buf[i + 3] = GF14[t[3]] ^ GF11[t[0]] ^ GF13[t[1]] ^ GF9[t[2]]; + } +} + +static void xorblock(uint8_t buf[16], const uint8_t key[16]) +{ + for (int i = 0; i < 16; ++i) + buf[i] ^= key[i]; +} + +void aes128_keyexpansion(const uint32_t key[4], uint32_t rk[44]) +{ + for (int i = 0; i < 4; ++i) + rk[i] = key[i]; + for (int i = 4; i < 44; i += 4) { + rk[i] = rk[i - 4] ^ subword(rotword(rk[i - 1])) ^ rc[i / 4 - 1]; + rk[i + 1] = rk[i - 3] ^ rk[i]; + rk[i + 2] = rk[i - 2] ^ rk[i + 1]; + rk[i + 3] = rk[i - 1] ^ rk[i + 2]; + } +} + +void aes128_enc(const uint32_t rk[44], uint8_t buf[16]) +{ + xorblock(buf, (uint8_t *)rk); + for (int i = 1; i <= 9; ++i) { + subshiftrows(buf); + mixcolumns(buf); + xorblock(buf, (uint8_t *)&rk[i * 4]); + } + subshiftrows(buf); + xorblock(buf, (uint8_t *)&rk[40]); +} + +void aes128_dec(const uint32_t rk[44], uint8_t buf[16]) +{ + xorblock(buf, (const uint8_t *)&rk[40]); + subshiftrows_inv(buf); + for (int i = 9; i >= 1; --i) { + xorblock(buf, (uint8_t *)&rk[i * 4]); + mixcolumns_inv(buf); + subshiftrows_inv(buf); + } + xorblock(buf, (const uint8_t *)rk); +} + +void aes128_cbc_mac(const uint32_t rk[44], uint8_t *buf, uint8_t mac[16], int len) +{ + // assert((len & 0xFF) == 0); + // assert(len >= 16); + // Copy first block + for (int i = 0; i < 16; ++i) + mac[i] = buf[i]; + aes128_enc(rk, mac); + for (int i = 16; i < len; i += 16) { + xorblock(mac, &buf[i - 16]); + aes128_enc(rk, mac); + } +} + +void aes128_cbc_enc(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, size_t len) +{ + // assert((len & 0xFF) == 0); + + // XOR with initialization vector, + // then encrypt block. + xorblock(buf, iv); + aes128_enc(rk, buf); + for (int i = 16; i < len; i += 16) { + // XOR with previous block, + // then encrypt block. + xorblock(&buf[i], &buf[i - 16]); + aes128_enc(rk, &buf[i]); + } +} + +void aes128_cbc_dec(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, size_t len) +{ + // assert((len & 0xFF) == 0); + for (int i = len - 16; i >= 16; i -= 16) { + // Decrypt block, then + // XOR with previous block. + aes128_dec(rk, &buf[i]); + xorblock(&buf[i], &buf[i - 16]); + } + // Decrypt block, then + // XOR with initialization vector. + aes128_dec(rk, buf); + xorblock(buf, iv); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@aes128.c.blob b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@aes128.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..70854b71bf2f809eeb375821838b0b32f8681d73 GIT binary patch literal 5000 zcmb_fe{56N6~5Pbjj}*3Ko9dq!MsKhCB}|p$8`-N48qzH7_AiAYAT65$9~{P{3Cj{ z6Q?j%Z4%la-B8$&DpaWj2~s*xTNQ#BQlYTXGKmN@HSH=i@dqT@GPECwt&YvSeedSk zd47$-MT_L4hDE0J;c$Y7Tq?2}U3dgmK^u2s8UeyzegJEc%Mqf~fUAptoq`F+)8kQz+6 z!{9e}!bNabx_rw=YAq_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hZ={R93AQz+Rf2}j)Pv<{Re-^(YN`xmvQtR{vFsO{1Morwxh`DnDv;AqsRHG_(9gv zO`J~dLC?iDaZkO7zm{x^$EjH_vp!}6n)S43*2}Dq*#NVib}ioOch>)y5Xw0@=!+w@ RmeK&#rkHlyMDdAn^nW`=n0o*K literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@aes128.h b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@aes128.h new file mode 100644 index 00000000..95d6ced7 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@aes128.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include + +// Generate round keys +void aes128_keyexpansion(const uint32_t key[4], uint32_t rk[44]); + +// Encryption provided round keys +void aes128_enc(const uint32_t rk[44], uint8_t buf[16]); + +// Decryption provided round keys +void aes128_dec(const uint32_t rk[44], uint8_t buf[16]); + +// CBC-MAC with AES. +void aes128_cbc_mac(const uint32_t rk[44], uint8_t *buf, uint8_t mac[16], int len); + +// Cipher block chaining encryption +void aes128_cbc_enc(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, size_t len); + +// Cipher block chaining decryption +void aes128_cbc_dec(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, size_t len); diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@aes128.h.blob b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@aes128.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..df58fe8b5b542caf22cc36c15a7382bede0c98e3 GIT binary patch literal 2039 zcmcIly>HV%6h9Y&A_ql^6qxw%RA^P_nl_3uP^1znSeS}fT4Wsi8ee0dqdPlI+66H& zFflVBL}5pj5Cam05yXT9e*g;`Oi0l3&S@$)B*m%3V9DpZcklOg=Sj5l@!q8m2qEnF z9>I>;z&2@NG26gR?ynLn5b(kCnFzQU_#9ij(+qsx-CyHmZJBlFD{k}(}gmo%yL7UU=i3hSt&SZ=kbR3E~@KI zwJT+#T+&_2!nR&#A+Awi7Id0K$n{eXHr^*)PuGXktPnE@`H;yW0H{aGrDO<1M_>#1 z4F=q6t_LG*8HuoFIVMjAAzBYAQx@p(u+gi+5z8bS0g4ao1V}8s$;qDS2~C73S-L|^ zn{ZtOCJ%<~4NwnECC%Vo-HXki+lOaL=1>G-ZLp(*6XW{w!1!U!J*Y_{aE8%6B8F$S z4b!D{W<(Sp&3{e`RZkk%Znk`G$L$*%JHlx`K2l9reRN`Xd*;W)%inM2T0XTklZfI> z#jt9YVH4}3B`-8hhH-Yr2sGYUDwS?eMIS0Krmdx7IX0fGg)38qX!qBb%JWy#Ti^R(5%zy! z!Tx=)a%v7>n0Tibu?qnA)f7* +#include + +typedef enum { ENCRYPT, DECRYPT } crypto_mode_t; + +static uint32_t enc_key[4] = { + 0x16157e2b, + 0xa6d2ae28, + 0x8815f7ab, + 0x3c4fcf09, +}; + +static uint32_t enc_round_key[44]; + +typedef struct { + uint8_t *data; + size_t len; +} frame_t; + +crypto_mode_t sendrecv_frame(frame_t *); + +void encrypt_data(frame_t *); +void decrypt_data(frame_t *); + +void main(void) +{ + aes128_keyexpansion(enc_key, enc_round_key); + frame_t frame; + s3k_reg_write(S3K_REG_SERVTIME, 500); + while (1) { + crypto_mode_t encrypt = sendrecv_frame(&frame); + switch (encrypt) { + case ENCRYPT: + encrypt_data(&frame); + break; + case DECRYPT: + decrypt_data(&frame); + break; + } + } +} + +/** + * Receives a data frame from monitor. + * Returns true if frame should be encrypted, + * otherwise false if frame should be decrypted. + */ +crypto_mode_t sendrecv_frame(frame_t *frame) +{ + // Receive a frame + s3k_msg_t msg; + msg.send_cap = false; + s3k_reply_t reply; + do { + reply = s3k_sock_sendrecv(0x3, &msg); + } while (reply.err); + frame->data = (uint8_t *)reply.data[0]; + frame->len = reply.data[1]; + return (reply.data[2] % 2 == 0) ? ENCRYPT : DECRYPT; +} + +void encrypt_data(frame_t *frame) +{ + // Encrypt the frame + for (int i = 0; i < frame->len; i += 16) + aes128_enc(enc_round_key, frame->data + i); +} + +void decrypt_data(frame_t *frame) +{ + // Receive the frame + for (int i = 0; i < frame->len; i += 16) + aes128_dec(enc_round_key, frame->data + i); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@main.c.blob b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@crypto@main.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..835db4b7a2dd4059473367c3126e25a83c3cc799 GIT binary patch literal 2845 zcmbVOOKclO7@pazT+4Fva2(fmY~xfGc0%lJTr0Ry5}Cv_C9X<&^^zvr_3kEFV(&)# zaFbR@v~91yQ&`DYw2PMTCsSMq3g zX6JkS|G)ou0B!wnb@Vnuh+EXEGPfu!agto)jN?n(vaY=>i>3h+RZTTaT`)DB6ZO?) zQ{$?FqGm+YCRPM>;So2dFKYUdqAsK*MF%2HUmbf;1?u4}L+2_=nX6Q4)$~w~-cw#~ zD3>{w8RisKtXPuF8Kxx3^O;4o_0i?(H*{ZPX(d0*59iVqMYUGa3#!GH6>w&*F3Sda zfAG!A-?#d{a%rDE^Ri%C`aX;M2vDl>aIQ54#;U=I;BRli4f3?P6Y^kb6=Y*5nE{P3x}tx8R|TI;k{pgl;<>1#V^pK+?$MMK$=OQ(mp545MAHgw4Tw07zI zq|4a-0UEo$is8lnx7dOp6y2-j~}`*TwXHZ z5?c!1PZY4-(|@7;h4DK#nsH_Ik#UP`v5p(~?dxRM8|PM%HSz< znjt9Exf9JcfbwF5L!Qu4j6*1tM>y$9#wdgF`%hy}PXAq{4CG)+5kNQY_4N7}+>4%| zfGkmDH|!F?zFgl~yXRKzOHcA{51B}~5;41Qy?pxT^)KEd6NJKU7}(YT+MIVNBV=J; zPX$i_JQdK>bx$PfPA0eUaL^M3PeBv}PecLr)R0v_ZuzPvkw_V`D#1}%<7w!c0~m=! za5j?7GdPRJDH$U13Pb{Vi~}fe24P~CU>{l|@om1ajlP|JDY^CITgcv=82J3eXyKFQ zb#jmG?|k>}y?sTzj_j-XjcM=m;Y~r+)HwVxutYPyolJNW$^dtDc10K%{X`1Ww6#I> zDmsD*tbNmZ@v-$kZvRRinlHwli?6w#i7sr|f4+Vq_0Mw`&LaC=JDU8U^R+9KSXQlS zd`Em>e+I~1ovt85#t91OsS|kvul(|C>9a|4=0nflrQ6XTi?suUpY=oObRoZwKsbi~ zB~XU~BY{&a4km(G7Kaic7-LMVlf~JQEX)@Y1(=yiOu=YZ)+c<|?u@ZA#w;*$lI|kL`;ACCb7*>*SBLOQ@4nQ)c={Mk=z3+6P?#+}+t7 zxX-Y-o9Pa$xsO0@Ci9cyUOb(jhSA9rX;Y*t4eSCUpDpqoa|4pk?~4#5ALENSMMDvb zCyQsixOB1vqmw&0D@{fGzyHBU!|R%*N<3{SxmgsC6XzZAju8fTppFTrG7e(~wM9px t=U7|}7jrBwg-b9x^|2Rpy-NXR`$JX{cE{Zr2D{N=W(OON4n*@T{tx$@l)nG~ literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@monitor@main.c b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@monitor@main.c new file mode 100644 index 00000000..8a37d803 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@monitor@main.c @@ -0,0 +1,203 @@ +#include "../config.h" +#include "s3k/s3k.h" +#include "string.h" + +#define MONITOR_CIDX 0xa + +typedef enum { + CMD_INVALID = 0, + CMD_SEEK = 0x1, + CMD_WRITE = 0x2, + CMD_READ = 0x3, + CMD_RUN = 0x4, + CMD_RESET = 0x5, +} cmd_t; + +typedef struct { + s3k_pid_t pid; + char *memory; + size_t seek; + size_t size; +} app_data_t; + +s3k_reply_t sendrecv(s3k_msg_t *msg); +void decrypt(void); +void encrypt(void); +cmd_t get_command(size_t len); + +void run_app(s3k_msg_t *msg, app_data_t *app); +void seek_app(s3k_msg_t *msg, app_data_t *app); +void write_app(s3k_msg_t *msg, app_data_t *app); +void read_app(s3k_msg_t *msg, app_data_t *app); +void reset_app(s3k_msg_t *msg, app_data_t *app); +void invalid(s3k_msg_t *msg); + +char *const uart_buffer = SHARED0_MEM; +char *const crypto_buffer = SHARED1_MEM; + +void setup_memory(void) +{ + s3k_cap_t pmp; + pmp = s3k_mk_pmp(s3k_napot_encode((uint64_t)APP0_MEM, APP0_MEM_LEN), S3K_MEM_RW); + s3k_cap_derive(0x5, 0x10, pmp); + s3k_pmp_load(0x10, 4); + s3k_sync_mem(); + + pmp = s3k_mk_pmp(s3k_napot_encode((uint64_t)APP0_MEM, APP0_MEM_LEN), S3K_MEM_RWX); + s3k_cap_derive(0x5, 0x12, pmp); + s3k_mon_cap_move(MONITOR_CIDX, MONITOR_PID, 0x12, APP0_PID, 0x0); + s3k_mon_pmp_load(MONITOR_CIDX, APP0_PID, 0x0, 0x0); + + pmp = s3k_mk_pmp(s3k_napot_encode((uint64_t)APP1_MEM, APP1_MEM_LEN), S3K_MEM_RW); + s3k_cap_derive(0x6, 0x11, pmp); + s3k_pmp_load(0x11, 5); + s3k_sync_mem(); + + pmp = s3k_mk_pmp(s3k_napot_encode((uint64_t)APP1_MEM, APP1_MEM_LEN), S3K_MEM_RWX); + s3k_cap_derive(0x6, 0x12, pmp); + s3k_mon_cap_move(MONITOR_CIDX, MONITOR_PID, 0x12, APP1_PID, 0x0); + s3k_mon_pmp_load(MONITOR_CIDX, APP1_PID, 0x0, 0x0); +} + +void main(void) +{ + // Revoke on time slice + s3k_cap_revoke(0x2); + setup_memory(); + + app_data_t apps[2]; + apps[0].pid = APP0_PID; + apps[0].memory = APP0_MEM; + apps[0].size = APP1_MEM_LEN; + apps[0].seek = 0; + apps[1].pid = APP0_PID; + apps[1].memory = APP1_MEM; + apps[1].size = APP1_MEM_LEN; + apps[1].seek = 0; + + s3k_reply_t reply; + s3k_msg_t msg; + while (1) { + reply = sendrecv(&msg); + cmd_t cmd = get_command(reply.data[0]); + int app = (uart_buffer[0] >> 4) % 0x2; + switch (cmd) { + case CMD_SEEK: + seek_app(&msg, &apps[app]); + break; + case CMD_RUN: + run_app(&msg, &apps[app]); + break; + case CMD_WRITE: + write_app(&msg, &apps[app]); + break; + case CMD_READ: + read_app(&msg, &apps[app]); + break; + case CMD_RESET: + reset_app(&msg, &apps[app]); + break; + default: + invalid(&msg); + } + } +} + +cmd_t get_command(size_t len) +{ + if (len < 4) + return CMD_INVALID; + switch (uart_buffer[0] & 0xF) { + case CMD_SEEK: + case CMD_RUN: + case CMD_WRITE: + case CMD_READ: + case CMD_RESET: + return uart_buffer[0] & 0xF; + default: + return CMD_INVALID; + } +} + +s3k_reply_t sendrecv(s3k_msg_t *msg) +{ + s3k_reply_t reply; + do { + reply = s3k_sock_sendrecv(0x7, msg); + } while (reply.err); + return reply; +} + +void decrypt(void) +{ + s3k_msg_t msg; + msg.send_cap = false; + msg.data[0] = 0; + msg.data[1] = 0; + msg.data[2] = 0x1; + while (s3k_sock_sendrecv(0x4, &msg).err) + ; +} + +void encrypt(void) +{ + s3k_msg_t msg; + msg.send_cap = false; + msg.data[0] = 0; + msg.data[1] = 0; + msg.data[2] = 0x0; + while (s3k_sock_sendrecv(0x4, &msg).err) + ; +} + +void run_app(s3k_msg_t *msg, app_data_t *app) +{ + s3k_mon_resume(MONITOR_CIDX, app->pid); + s3k_mon_yield(MONITOR_CIDX, app->pid); + s3k_mon_suspend(MONITOR_CIDX, app->pid); + msg->data[0] = 2; + memcpy(uart_buffer, "ok", 2); +} + +void seek_app(s3k_msg_t *msg, app_data_t *app) +{ + uint16_t val = uart_buffer[2] << 8 | uart_buffer[3]; + val = (val > app->size) ? app->size : val; + app->seek = val; + msg->data[0] = 2; + memcpy(uart_buffer, "ok", 2); +} + +void write_app(s3k_msg_t *msg, app_data_t *app) +{ + uint16_t len = uart_buffer[2] << 8 | uart_buffer[3]; + int i = 0; + while (i < len && i < SHARED0_MEM_LEN && app->seek < app->size) { + app->memory[app->seek++] = uart_buffer[(i++) + 4]; + } + msg->data[0] = 2; + memcpy(uart_buffer, "ok", 2); +} + +void read_app(s3k_msg_t *msg, app_data_t *app) +{ + uint16_t len = uart_buffer[2] << 8 | uart_buffer[3]; + int i = 0; + while (i < len && app->seek < app->size) { + uart_buffer[i++] = app->memory[app->seek++]; + } + msg->data[0] = i; +} + +void reset_app(s3k_msg_t *msg, app_data_t *app) +{ + s3k_mon_reg_write(MONITOR_CIDX, app->pid, S3K_REG_PC, (uint64_t)app->memory); + msg->data[0] = 2; + memcpy(uart_buffer, "ok", 2); +} + +void invalid(s3k_msg_t *msg) +{ + msg->data[0] = 3; + memcpy(uart_buffer, "inv", 3); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@monitor@main.c.blob b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@monitor@main.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..21b4ef719c3f9f5a742be6ff47fc8fcf0d6f9807 GIT binary patch literal 2926 zcmbVNZEO=|9Dkl$oy(;i%|2{hw{=I`k&djrZjQaVjUpR+2?I8e=uqpeck7O|cjfN7 zt)hlZLkO>;i6X--!w(}1f|(8tiA)@VBg2q@28|y;KNv86kSL-k^?%o`D|XAoe)vC6 z@A?0JzyI5Fw;bKS++Y1ALWu4XgB;z(bki)?L(7kK(;-RR%J~!-9t1@}RwPCdB^tK8 zwlcin@}U%8fD!!v7wzm7rEXsEJ6T==DN%~lB*%e_bXb-`c*TF+~ zR5F==fm?u%^*KWlH&YZX??k!zDWTLpXBWq?oaB@hMp72wRzsclXntBH65?b!Ao`d9 z=bfK338+<733oh9MFOHaQDV3wFn>`N7I7}nl_W&0@>)J#@55!JL1FIM#HJDd`3A+u zQTMBmYI%?g`a%&$>`xH|G_o>tR78aZnfD7E zOR1$RL}s%d-U#s1mPZDO!SuiF9y~&fXzLg;rmd62q_$2GQ`#DpZ(pe?Z~il=i3H&V z;V48TnTBh~nhXNhAU~m!;#I^dbF}Bm%C~E8?YNr)%zCUokKU_Z@%)z6r#{l)ywJl0 zc-FxS3Is1hR3w>>&y(j(1U`>0#+X#)c)Bx8m?9|?#uTC|fOBH?^e@v5OMlWh;r4Ti zmkEX9tVI<3^RkS>ctHmCs!Rr+ASZGOJb})|WYk2HWb(=UT#WNk{&OHx*Sqx7Tc*vk zG7P)8iV=^K<7NVnqfayy1XaKm(qhKgf-KJf=>_jLRC{gzOIqx`60dNJvu5B?aui}8 zMIXdsSDTd-dmfnwvFD*YHTJJ|AK3cV4L27nQCL`9Bpn|j4?!Oep`n zAqVBOgGlx3Kb$Sza&wO_$U>$4&<39v3^D@iP_F?z3UERp((5xZujj1<=27olRkHQj zR*bVzb`>zq4vrQs^fMgt!feB*LmM^|E+7j4Uw|Hu<7Y-r9pPxk__x=rsrKJAG$;6^ zNJ!Cu>3AQx4|3Xv-i!mWi8Mh9CSzj3bRG1bhrJiUrpQ|fT z*;(1+!Bw8B4d8L%#|;DCSHJi!(L+}vleY>(MvvBzhCHhu-YLm7Yql(a@zowv49Q4T&Bp zj&{dZ4|cXY!PeXBOTq8juG?$UK7My7(GS}yZ0q3c&c^Knft7on@O3c~wLJF54#U^j z+Y#>UI-vEf*8h(C(Eum!o;X!+4g( zGg;b9wh{u{kZqloC5mz%jE>L0&Fd{HiP!F2Wkpjp1vn{yBln!y%KDdy$bAM>M+dIfMuY} RgO6B`RC(~(WoK(W_#Z|Ld7uCQ literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@uartppp@main.c b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@uartppp@main.c new file mode 100644 index 00000000..c3e45ec7 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@uartppp@main.c @@ -0,0 +1,78 @@ +#include "../config.h" +#include "altc/altio.h" +#include "s3k/s3k.h" + +#define PPP_ESC 0x7C +#define PPP_BGN 0x7B +#define PPP_END 0x7D + +void ppp_send(char *buf, size_t len); +size_t ppp_recv(char *buf); + +void main(void) +{ + s3k_cap_revoke(0x2); + alt_puts("{uart started}"); + s3k_msg_t msg; + s3k_reply_t reply; + + char *buf = SHARED0_MEM; + + while (1) { + size_t len = ppp_recv(buf); + alt_puts("{received message}"); + msg.data[0] = len; + reply = s3k_sock_sendrecv(0x5, &msg); + if (reply.err != S3K_SUCCESS) { + char *s = "error0"; + if (reply.err < 10) + s[5] = '0' + reply.err; + else + s[5] = 'A' + reply.err - 10; + ppp_send(s, 6); + continue; + } + ppp_send(buf, reply.data[0]); + } +} + +void ppp_send(char *buf, size_t len) +{ + alt_putchar(PPP_BGN); + for (int i = 0; i < len; ++i) { + char c = buf[i]; + switch (c) { + case PPP_BGN: + case PPP_END: + case PPP_ESC: + alt_putchar(PPP_ESC); + c ^= 0x20; + /* fallthrough */ + default: + alt_putchar(c); + } + } + alt_putchar(PPP_END); +} + +size_t ppp_recv(char *buf) +{ + size_t i = 0; + while (alt_getchar() != PPP_BGN) + ; + while (1) { + char c = alt_getchar(); + switch (c) { + case PPP_BGN: + i = 0; + break; + case PPP_END: + return i; + case PPP_ESC: + c = alt_getchar() ^ 0x20; + /* fallthrough */ + default: + buf[i++] = c; + } + } +} diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@uartppp@main.c.blob b/.ccls-cache/@home@hak@dev@s3k/projects@demonstrator@uartppp@main.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..1a9834b3d8c815cae2e1461814960daa6abb997d GIT binary patch literal 732 zcmbV|K}#D!6vyW!Q8t@0EIDp#*rJ40HW{(S5Qwme(MmxZ@YIuRcQ?rzGrP=gqJ^Hc zhu-`Oz4Z%}_Cp9NRPfMauRWEXO6m5ES_SQ)bPkWybhd%2& z1LpZ-7C#!WNQB$Io5UClLmnr>NkYL!j!2>?VnZk3RhMMl9f$Y+x4W_%ib2486)zAt zDikl5?s^cooBiF*4S6@{Rr{Aq!9QDF_mONGfBUpld-`KI4g=4SOPaGpRTU_xg<=K@ zWF~{3MaVsnH9a5gzCE$tlmng^_$ynu#n^QFjxgq4jJmT#Q8cL2dMN{SvVPqOd73W) z{s zU9%Nhd0@k$zG&Lerfs~ZUklB%!w=h2va|JM<2DQ<32Py2LYqJs)=OB<)J?=#)Iv;S zp<&z5q)mzZ@-up+yk4UhGMme{kt>_a5{WtFv>YO_UinpN6#=ZoEE`toD&BtsFt*64 literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@hello@app0@main.c b/.ccls-cache/@home@hak@dev@s3k/projects@hello@app0@main.c new file mode 100644 index 00000000..0ecdf1ad --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/projects@hello@app0@main.c @@ -0,0 +1,72 @@ +#include "altc/altio.h" +#include "s3k/s3k.h" + +#define APP0_PID 0 +#define APP1_PID 1 + +// See plat_conf.h +#define BOOT_PMP 0 +#define RAM_MEM 1 +#define UART_MEM 2 +#define TIME_MEM 3 +#define HART0_TIME 4 +#define HART1_TIME 5 +#define HART2_TIME 6 +#define HART3_TIME 7 +#define MONITOR 8 +#define CHANNEL 9 + +void setup_uart(uint64_t uart_idx) +{ + uint64_t uart_addr = s3k_napot_encode(UART0_BASE_ADDR, 0x8); + // Derive a PMP capability for accessing UART + s3k_cap_derive(UART_MEM, uart_idx, s3k_mk_pmp(uart_addr, S3K_MEM_RW)); + // Load the derive PMP capability to PMP configuration + s3k_pmp_load(uart_idx, 1); + // Synchronize PMP unit (hardware) with PMP configuration + // false => not full synchronization. + s3k_sync_mem(); +} + +void setup_app1(uint64_t tmp) +{ + uint64_t uart_addr = s3k_napot_encode(UART0_BASE_ADDR, 0x8); + uint64_t app1_addr = s3k_napot_encode(0x80020000, 0x10000); + + // Derive a PMP capability for app1 main memory + s3k_cap_derive(RAM_MEM, tmp, s3k_mk_pmp(app1_addr, S3K_MEM_RWX)); + s3k_mon_cap_move(MONITOR, APP0_PID, tmp, APP1_PID, 0); + s3k_mon_pmp_load(MONITOR, APP1_PID, 0, 0); + + // Derive a PMP capability for uart + s3k_cap_derive(UART_MEM, tmp, s3k_mk_pmp(uart_addr, S3K_MEM_RW)); + s3k_mon_cap_move(MONITOR, APP0_PID, tmp, APP1_PID, 1); + s3k_mon_pmp_load(MONITOR, APP1_PID, 1, 1); + + // derive a time slice capability + s3k_mon_cap_move(MONITOR, APP0_PID, HART1_TIME, APP1_PID, 2); + + // Write start PC of app1 to PC + s3k_mon_reg_write(MONITOR, APP1_PID, S3K_REG_PC, 0x80020000); + + // Start app1 + s3k_mon_resume(MONITOR, APP1_PID); +} + +int main(void) +{ + // Setup UART access + setup_uart(10); + + // Setup app1 capabilities and PC + setup_app1(11); + + char buf[12]; + alt_snprintf(buf, 64, "hello, world from app%x", 0); + + // Write hello world. + alt_puts(buf); + + // BYE! + alt_puts("bye from app0"); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@hello@app0@main.c.blob b/.ccls-cache/@home@hak@dev@s3k/projects@hello@app0@main.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..cc2bd1afa7ecb67d7d6c63162f508547884f0f94 GIT binary patch literal 1151 zcmb7BOH30{6n!(rw3Grb2&fU87oAqxhM7(&Eyj?vAlef92^lnT!KBg=M*2%z@V9V5 zWI;^SxN*hG1mkC6Ob~G;3**X-QEN;{Sn0x*pM@+O@9T85YBz39UQXV*=bU@p=!cyQ zzC;KKGx@9{%%o<8v@$Q0`e%hgF@IK>Dwl*AC6mbusY1akWK(L6pF*aoOe#11f118? z`Qogao9;`iMHrheUKsk<6M`U<_Hg;@sZYuHrTM&?CMBgjSCGM7>{WARQqC4!$ZG9m z>{h#-W$b8xr6OcwC~Bq8uZDtS+gbXRhV6ABi^akOEkVpOL3Heo&%PJWZ|{+}cGUUI zrHbXM4}HjL`n+z|VeJ634%AbxM>g%`>yOc`p33}4Bpi>A9)|>N2hz$JHK&joMGhgv zV2nWyxF2aWrxv>NC9&`N!j(vPTeB|%WP;Wmz?*jrOCb}c@=yIQ#z zOT?p6V!Yn9Mv+0#wc~bh1=L;54$k2VF;312=;qvj9?k>Eb3CBv6#XH_PyBp{(THbc za{0uEgEWb+VLqKD0q|+Xt&k7U$hZDv=rRBP*(&WN$3|li5F6bLj`V}limimD$km#y zxp%HkuB{)Q0N=lr21k6LY{t!?1k{ymH|h3<7#DE?YTw>&uH0JMaE^y#wIRQ*Qlp3n zGc4Ew`vKJV!*GP7-M?SnZNIi6bdNVdd4?trBS0DKHvbKpg;bc;jlhGsfN`tGWZ^BKW1k{yghvZ1Z zbpy_$a9zm_Z%@DjZ~io2gzFB95xB0;KMd)1-Rs*BE6#1&(A%(~&JsT)Y{4zi5YV{p nyQR>L_Qm^ANaJmgu*y}tnXm~G0_q7(j(~$^3%F^j01x;Rz~~^e literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@hello@app1@main.c b/.ccls-cache/@home@hak@dev@s3k/projects@hello@app1@main.c new file mode 100644 index 00000000..a9112831 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/projects@hello@app1@main.c @@ -0,0 +1,8 @@ +#include "altc/altio.h" +#include "s3k/s3k.h" + +int main(void) +{ + alt_puts("hello, world from app1"); + alt_puts("bye from app1"); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@hello@app1@main.c.blob b/.ccls-cache/@home@hak@dev@s3k/projects@hello@app1@main.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..db4b12af3f1fdc7b58df866c7879883a764a2a7e GIT binary patch literal 196 zcmdO5_$Q}eagKq3K|douH&s6)FBQ+-{Uq7*+z)(Lo zF*8punSnVuCowObG(EcI`9;~8dFi?-nMFWj^NT8NG3^98gn{vY@u$nS=3c*YGxJIm fKsIVfFJq%%lGYW@A;UNGdvpX~o6NaMT(u7KObY}2|e z60<0lR27NvXSx#&TQ#d1agb;!Ox2UDmWUgcqRKZ6)nQ(?U?j~-A`VN{q8c%i7SR;D zfyCSd5=%(TcY<9?O{XdJI!hu5HXxVW!!*(Sd?M)|kw>t}X(+Isg7zrHT zBr`j`94CxX=JC%6Q#-vXYl*ttqbRpgA&yt&<-=63Rb-pgO`{;!2y+Z-w>&s_YyWbu zNEElqnuUG)st&_|#HLxZ#8}*4tEOU?a4arGr9@~Y2HOkpc)XfVZ(8qr^#z6@!?>Jk zzjg73)wr}Fx#<3Hv`Rwoza)x}(1UYyOs#^^b?19ye? zyby~|AoTP7 zAOT`XD8BpnW^41&D__EVD%*{a4)Q*skM9El#E|gkUTO5LvT)Ydu++7QwTT67VXB($<4_-=bm$)0sVY^ z+4Tw`#E)lEaeh3KuWv?+?VMJFQZ zvH#a~oz3Ku#4(o0fqf=-zW3kV5C|!XM_x|s*f6eqpUNa+I3F)eX2bbRG#M{+Cej5g zjr%Z}3#qIgDV1%MO=;_(DI3~P6APrG2o@jCeLeXp=)YKD1XV008(G>+X_OibO=*yI zi!}fFO|RqVW{PYf%{%poVHnEAxLBHUp;KEP3ooAE-Wgu6sn|0a$w_g^5KhF-k(|wx zTB(L*YSdn-N2=n9m5<)__SLC_o&mpq=oo}=*b|GNPNd^lrmzzss)=m^Iba7WLPg4f z9VRzbbl>?B*nNHaif3S0w1!2mZwL&U%Lac~>;O$8+sM%bJ0%Y{c6WovOv}vEy9=uq zd;z~#3=CH$kSW{)YL;ao0icwC(Q;bBP3brtpn)?08aX2%&+&kQP5^Hw=Y%Qgot+>_fru0}3Sp4>GZT{BmvTk_5 zC!75KEt$d=@Tg^L;Z}h1Z*iC-7x;0hO>=EtY#|r0RK0-2VjFnWv-NNRK=}fFxQ|?5 z;^uVPv-W8FU?3odgT7$p1 + +int main(void) +{ + alt_puts("starting app1"); + s3k_msg_t msg; + s3k_reply_t reply; + memcpy(msg.data, "ping", 5); + while (1) { + do { + reply = s3k_sock_sendrecv(3, &msg); + if (reply.err == S3K_ERR_TIMEOUT) + alt_puts("timeout"); + } while (reply.err); + alt_puts((char *)reply.data); + } +} diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@ping-pong@app1@main.c.blob b/.ccls-cache/@home@hak@dev@s3k/projects@ping-pong@app1@main.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..44f188007edd1c322c74c69c62a01064a2dd6866 GIT binary patch literal 1102 zcmb7EOHRWu6m&qUvS5J_2Ve;Z=TQ*_7W4vK0;RT_m^x16Pd~6@%{{mPH((7y;wJ21 zQE*aGsG3O0!iuHmc{83j&M{iN-Cw>Ugdoi`25CG7$|j)C#!#sIh7qHo;4;BQE)$50 zq7PZjWkAq25wT3Va4Cp5NQu@_J~0%l$bJ+VQFn`T;_0 Bkfs0t literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@trapped@app0@main.c b/.ccls-cache/@home@hak@dev@s3k/projects@trapped@app0@main.c new file mode 100644 index 00000000..91902561 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/projects@trapped@app0@main.c @@ -0,0 +1,83 @@ +#include "altc/altio.h" +#include "s3k/s3k.h" + +#define APP0_PID 0 +#define APP1_PID 1 + +// See plat_conf.h +#define BOOT_PMP 0 +#define RAM_MEM 1 +#define UART_MEM 2 +#define TIME_MEM 3 +#define HART0_TIME 4 +#define HART1_TIME 5 +#define HART2_TIME 6 +#define HART3_TIME 7 +#define MONITOR 8 +#define CHANNEL 9 + +void setup_uart(s3k_cidx_t uart_idx); +char trap_stack[1024]; +void trap_handler(void) __attribute__((interrupt("machine"))); + +void trap_handler(void) +{ + // We enter here on illegal instructions, for example writing to + // protected area (UART). + + // On an exception we do + // - tf.epc = tf.pc (save program counter) + // - tf.pc = tf.tpc (load trap handler address) + // - tf.esp = tf.sp (save stack pointer) + // - tf.sp = tf.tsp (load trap stack pointer) + // - tf.ecause = mcause (see RISC-V privileged spec) + // - tf.eval = mval (see RISC-V privileged spec) + // tf is the trap frame, all registers of our process + uint64_t epc = s3k_reg_read(S3K_REG_EPC); + uint64_t esp = s3k_reg_read(S3K_REG_ESP); + uint64_t ecause = s3k_reg_read(S3K_REG_ECAUSE); + uint64_t eval = s3k_reg_read(S3K_REG_EVAL); + + setup_uart(16); + alt_puts("uart is now setup!"); + alt_printf("error info:\n- epc: 0x%x\n- esp: 0x%x\n- ecause: 0x%x\n- eval: 0x%x\n", epc, esp, ecause, eval); + alt_printf("restoring pc and sp\n\n"); + // __attribute__((interrupt("machine"))) replaces `ret` with an `mret`. + // When mret is executed in user-mode, the kernel catches it setting the + // following: + // - tf.pc = tf.epc + // - tf.sp = tf.esp + // Restoring pc and sp to the previous values, unless epc and esp was + // overwritten. +} + +void setup_trap(void) +{ + // Sets the trap handler + s3k_reg_write(S3K_REG_TPC, (uint64_t)trap_handler); + // Set the trap stack + s3k_reg_write(S3K_REG_TSP, (uint64_t)trap_stack + 1024); +} + +void setup_uart(s3k_cidx_t uart_idx) +{ + uint64_t uart_addr = s3k_napot_encode(UART0_BASE_ADDR, 0x8); + // Derive a PMP capability for accessing UART + s3k_cap_derive(UART_MEM, uart_idx, s3k_mk_pmp(uart_addr, S3K_MEM_RW)); + // Load the derive PMP capability to PMP configuration + s3k_pmp_load(uart_idx, 1); + // Synchronize PMP unit (hardware) with PMP configuration + s3k_sync_mem(); +} + +int main(void) +{ + setup_trap(); + + // Write hello world. + // But we have not created a PMP capability! + alt_puts("hello, world from app0"); + + // BYE! + alt_puts("bye from app0"); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/projects@trapped@app0@main.c.blob b/.ccls-cache/@home@hak@dev@s3k/projects@trapped@app0@main.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..fd01cf5cd86473234a80a8cda09bf17cb6b9c24a GIT binary patch literal 1180 zcmb7@Z%7ki9LJyMW;oAHAGW!SN}f#2488qvX~dH@*3Ce7Vo_{eF+<+R<<3 zP|q8L5SPeIN?bxnaiTQM<=iPQD`zfB@qCWU%R)9Qi5#edn-r4i&Nwo}CxrC)|56>7 zGIA=J9`6v7G8~g)*p0SsC8id^>t~U^*dWqGwn+fl@_HtbCr2>xC6wG_c#l!djXzwjfIY7MYbZ@3(>*2Ue&10{)?){?p*q9Tuev z$+SdE7CiyW2_bM0XfsmOPoel8ehnYIHG4hakH*}5EEwts*QTSpF6{=oj?}d)RN4J1og%Bb2>>bux(T^L(j>K%sMze(MrE+A`24UnKk z68ov&0r%zG$MyMpbIYw!f2f4-eC3iwoj@Cj5%z-Wdw*PQY`QrgYf$$(EAB12)C07M zm|!oczIWozY&x+1tomd)9OEOQNcmpfqYfaeNj05PnE~%o;I_JR6!i59=G># y$Fg&^bz7b3s5rCe(k{rYCABaURG+yv=eu2BcoKvRM}=I?(`Fio0dhf0xqkp-pEF

+ +typedef struct file FILE; + +struct file { + int (*_putc)(struct file *, char c); + int (*_getc)(struct file *); + void (*_flush)(struct file *); +}; + +int alt_fputc(FILE *f, char c); +int alt_fgetc(FILE *f); +void alt_fflush(FILE *f); +int alt_fwrite(FILE *f, const char *buf, int size); +int alt_fread(FILE *f, char *buf, int size); +int alt_fgetstr(FILE *f, char *s); +int alt_fputstr(FILE *f, const char *s); +int alt_fputuint(FILE *f, unsigned long long val); +int alt_fputhex(FILE *f, unsigned long long val); +int alt_vfprintf(FILE *f, const char *fmt, va_list ap); +int alt_fprintf(FILE *f, const char *fmt, ...); + +int alt_putc(char c); +int alt_getc(void); +void alt_flush(void); +int alt_write(const char *buf, int size); +int alt_read(char *buf, int size); +int alt_getstr(char *buf); +int alt_putstr(const char *s); +int alt_putuint(unsigned long long val); +int alt_puthex(unsigned long long val); +int alt_vprintf(const char *fmt, va_list ap); +int alt_printf(const char *fmt, ...); + +int alt_sputuint(char *buf, unsigned long long val); +int alt_sputhex(char *buf, unsigned long long val); +int alt_vsprintf(char *buf, const char *fmt, va_list ap); +int alt_sprintf(char *buf, const char *fmt, ...); + +int alt_snputuint(char *buf, int size, unsigned long long val); +int alt_snputhex(char *buf, int size, unsigned long long val); +int alt_vsnprintf(char *buf, int size, const char *fmt, va_list ap); +int alt_snprintf(char *buf, int size, const char *fmt, ...); diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@alt@io.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@alt@io.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..f2ed60bc8946a04f645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+l=8l9G z+Pt=oi!udetG9K4i}2J1!~@RI0@>5DXCi^@^6Z&{0NKTaod+nDFh*2{J;Q-sgnBzf zeZ?3QvQVqq-h0yc3)Dt5L#8)HKorP$=CM5@u<4Kx}B1lRd>*iu+o z9by$H^dSLEB~h|U4rv43&q)j*V^eB?fisjL5rffCCKx~hpNg%qYp?+@gi-^@Ha@ib znM!5?Vqh3%g1|r$DV0I%&|+0!Vw6d=C##fHd#l4*fv~N`)(QceoIrB(dXK9logAhA?+ss_wZrfLwJLk37HgU+GD zodAvnX(u383sT3ctJISaw%VbdBw&*XmQF$JLv!&$kPDkrSHqRkOp4o0+-TOqv;4Ad~$`dQ*X`pb{xj zU@WKOQkd)}JgiNOi41FUB$Wg> zzcL?ZQ+`?gBq6}$3TRkmO!G~+hDnk(b*AmB_K83bf&PVIGB s_AI;)z(rWP50F!d#7wT1!)9_-95Itz7Yqt4x13vv^Q)U%nHt#t0{$MeVgLXD literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@time.h b/.ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@time.h new file mode 100644 index 00000000..6cbb62fe --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@time.h @@ -0,0 +1,6 @@ +#pragma once + +unsigned long long time_get(void); +void time_set(unsigned long long); +unsigned long long timeout_get(int); +void timeout_set(int, unsigned long long); diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@time.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@time.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..703e251732ddd0f0290337d813756f516b62bd91 GIT binary patch literal 695 zcma)(F-rq66o6ma>rw{3K*-x6ymVMb)! zSdxgC*COSnv@lKw%r; zZF6>G?&k7@f3k+4-x;MZM!uMzMko*YRmXUEIt^(!qHxsYytsvxq hx8^9V;Nn(1-}U~Wv<8Sl{WptTIoCia2RUZ}@DBU++LQnQ literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@uart@ns16550a.h b/.ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@uart@ns16550a.h new file mode 100644 index 00000000..06af7136 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@uart@ns16550a.h @@ -0,0 +1,20 @@ +#pragma once +#include "alt/io.h" + +#define UART_NS16550A(base) \ + (struct uart_ns16550a) \ + { \ + ._putc = uart_ns16550a_putc, ._getc = uart_ns16550a_getc, ._flush = uart_ns16550a_flush, \ + ._base = (char *)base, \ + } + +typedef struct uart_ns16550a { + int (*_putc)(FILE *f, char c); + int (*_getc)(FILE *f); + void (*_flush)(FILE *f); + char *_base; +} uart_ns16550a_t; + +int uart_ns16550a_putc(FILE *f, char c); +int uart_ns16550a_getc(FILE *f); +void uart_ns16550a_flush(FILE *f); diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@uart@ns16550a.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@drivers@uart@ns16550a.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..50f9336573f691cf448eed58e65d5dbeea9fe092 GIT binary patch literal 1779 zcmb7^O=uHA6vt<`6+%ANHWgZmNc=!d$YxSaLoKZszp$V!_;FEj+00I|+iZ5?%x+38 zejs@FCW?5_gBJzy;K7qn#goN@ph6E`ym;{9MUWb2HeYR1Xc|HoX5ah0|NFnUNq~Q! z?o2EJ0H8_A7@B$s8n_DCp%P^C3^Iyf2~!7FY~6*|aM?>CupN?$3#r9W73M9ce#&N4 z&nY=%&QY;lP>Towm4Bx;=2{N2Jp(hKmUW8ENm|Wjtg?=@>lR{E+~%!GyOPcDBPtUE z+mmH%=*~P)XAT0j2-FLmV3!b^)#dt1Z3C!{LcqT;fl2_$&o+Wq^^_u8F+iOov}8F& z)vzc=E}`?2ooXtS%<_i}n%K69FAGFE!-UICH=u62&>|_bK9yBA`)04TxS8e8Nn@^I zIj+b&lKuU0lQRB9kzNtuuknecZo)C8go=b+v9YCYm9<1obScW6uV5ysJinjowuRZN*hoR$aeCEd)u0@huR)(iXgd5l7igtlERt0NizjBMR0!jViWoyxYocMY8u zMaf6GZ;Nm%d3nCABJs&W`F-aAHrSr}>&G+xBuBgTMr@bH7lV2Ju>Iz`^M${RrsZI$ z8MvT(wyU*9BOsF8DS6{f20gXU%j%DxZ;tM+63d8rI(0RNjbukh)4Eo$J!T#_HFf4> zEK!JqU~oVGE8?Fp0MbBkAT3D)VBi=4wUG~pA0wmqocFR0QN%8469R#KZ9+5cPF?J$Jt^cM>XIn~;nlQ>QT$2Wv?EfqqWv2mRArSnX_R`RR*G3yitcL+kX! z7H$AV8RlWZUBNL~3ifT6xuV|M?3d`fhgahcsJ;C0^skb8d*ycRR`urN^t;ow6%Jke ze)-|ovE4gXZcAWL5>0Gt-T9glYpfd|*YY~UAe;#DT8g3!t;oHSA}d26FvyczY~S?* z9m&4)@rH46pd^Lmk-o@Ifr-eGbOX~AD{Ske2=m*Jx|XmK_O*oNaIyhu_P#Mh_}_%o z{f{@=3MnBU6_P^}4b-!lUoVco`r3CfckY5Vecs=r9Pf8{FJDx?u(5Ryq@KQ>gv@^f Jy`Uy+{STRLPt5=T literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@cap.h b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@cap.h new file mode 100644 index 00000000..9ecd3e5a --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@cap.h @@ -0,0 +1,148 @@ +#pragma once + +#include "kern/error.h" +#include "kern/types.h" + +// Min logarithmic size of a memory slice +#define MIN_BLOCK_SIZE 12 + +// Max logarithmic size of a memory slice +#define MAX_BLOCK_SIZE 27 + +enum mem_perm { + MEM_R = 0x1, + MEM_W = 0x2, + MEM_X = 0x4, + MEM_RW = MEM_R | MEM_W, + MEM_RX = MEM_R | MEM_X, + MEM_RWX = MEM_R | MEM_W | MEM_X, +}; + +// IPC Modes +enum ipc_mode { + IPC_NOYIELD = 0x0, // Non-Yielding Synchronous + IPC_YIELD = 0x1, // Yielding Synchronous +}; + +// IPC Permissions +enum ipc_perm { + IPC_SDATA = 0x1, // Server can send data + IPC_SCAP = 0x2, // Server can send capabilities + IPC_CDATA = 0x4, // Client can send data + IPC_CCAP = 0x8, // Client can send capabilities +}; + +// Capability types +enum capty { + CAPTY_NONE = 0, ///< No capability. + CAPTY_TIME = 1, ///< Time Slice capability. + CAPTY_MEMORY = 2, ///< Memory Slice capability. + CAPTY_PMP = 3, ///< PMP Frame capability. + CAPTY_MONITOR = 4, ///< Monitor capability. + CAPTY_CHANNEL = 5, ///< IPC Channel capability. + CAPTY_SERVER = 6, ///< IPC Socket capability. + CAPTY_CLIENT = 7, ///< IPC Socket capability. + CAPTY_COUNT ///< Number of capability types +}; + +typedef union { + uint64_t type : 4; + + uint64_t raw; + + struct { + uint64_t type : 4; + uint64_t _padding : 4; + uint64_t hart : 8; + uint64_t begin : 16; + uint64_t mark : 16; + uint64_t end : 16; + } time; + + struct { + uint64_t type : 4; + uint64_t rwx : 3; + uint64_t lock : 1; + uint64_t tag : 8; + uint64_t begin : 16; + uint64_t mark : 16; + uint64_t end : 16; + } mem; + + struct { + uint64_t type : 4; + uint64_t rwx : 3; + uint64_t _padding : 9; + uint64_t addr : 48; + } pmp; + + struct { + uint64_t type : 4; + uint64_t _padding : 12; + uint64_t begin : 16; + uint64_t mark : 16; + uint64_t end : 16; + } mon; + + struct { + uint64_t type : 4; + uint64_t _padding : 12; + uint64_t begin : 16; + uint64_t mark : 16; + uint64_t end : 16; + } chan; + + struct { + uint64_t type : 4; + uint64_t mode : 4; + uint64_t permission : 8; + uint64_t channel : 16; + uint64_t _padding : 32; + } server; + + struct { + uint64_t type : 4; + uint64_t mode : 4; + uint64_t permission : 8; + uint64_t channel : 16; + uint64_t tag : 32; + } client; +} Cap; + +/// Capability description + +_Static_assert(sizeof(Cap) == 8, "cap_t has the wrong size"); + +static inline Word CapIdx(Pid pid, Word reg) +{ + return pid * S3K_CAP_CNT + reg; +} + +static inline uint64_t pmp_napot_decode_end(uint64_t addr) +{ + return pmp_napot_decode_bgn(addr) + pmp_napot_decode_size(addr); +} + +static inline void pmp_napot_decode(uint64_t addr, uint64_t *bgn, uint64_t *end) +{ + *bgn = pmp_napot_decode_bgn(addr); + *end = pmp_napot_decode_end(addr); +} + +static inline uint64_t pmp_napot_encode(uint64_t bgn, uint64_t end) +{ + return (bgn | ((end - bgn) / 2 - 1)) >> 2; +} + +#define CAP_PMP(_addr, _rwx) 0 +#define CAP_MEMORY(_tag, _begin, _end, _rwx) 0 +#define CAP_MONITOR(_begin, _end) 0 +#define CAP_CHANNEL(_begin, _end) 0 +#define CAP_TIME(_begin, _end) 0 +#define CAP_NULL ((Cap){.raw = 0}) + +Word CapRead(Word i, Cap *cap); +Word CapMove(Word src, Word dst); +Word CapDelete(Word i); +Word CapRevoke(Word i); +Word CapDerive(Word src, Word dst, Cap cap); diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@cap.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@cap.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..b1167e3ccb8b480b5ce3b44d5fc397dd0b01a3d8 GIT binary patch literal 11077 zcmb6<33wD$ny)HF3^9aGCKMP#Q$h?$Ou9n|A+#if9FT^jbCO$|PIr-R(nstg5W!5s zWTQZkTq1ZNI-duuijK;vGvkGLAh>=iyQ1F+&ZoOOJB&Ln^C>!L?f+iYtL~)3(3_9% zf0atT|NZy%$V5NS8!Gz%F-ULsxJ13((xtbFJ$m1=F1@eUr}ufS`YzGy)>|#zIxCv3 z_jLR9UWd=xqwjFI<){3-?0~z=?b+(i7M+{3JFQlf4gZYOV|2K!&VWtyp=_7MYqb}8 zd-C%fE{oNChr{ag;`pqX+zn{L5RGtqihfIbZk*RBHZXakujaU)#L4QxI43L4zFnSd%V4c;S_XxJzL<9 zKD}LZIz5CG6dxijBD2Yo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}D*@j~SmOwlkPr?hVN(R%UYH$Y2Pbh}KLT>_8 z>i?nPJE7LZ;#Ca4m@g*MfYBh82E9;-3?DS_iXY)Tu!dhlObTXL}p??iDE)O(bVzs&(YidiUBEaRq8o^4VLTb9PBCTC(woc3 zNRzFWw9FW97vDu_gTXTuExq%K4Byo7U&q%GUBRTBhJQLqjSS%w-Bwu!nqN)q0dAhCyPsK_bLD8Y z>7-nEPwlmuLV7MdU`${WG&u9ZTC7y=^lCXWdZzkhE8j}=0QXZ=uk^ZiQVtkPA0yEd z{tpI?p7bg^vV*61MjPKoBmp;KRR8qK=vskKbSZ(aJi43&KDfY&Q}4Otz(;S_BcpAK PZJK#AkqO+>DYX3`vNr0D literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@csr.h b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@csr.h new file mode 100644 index 00000000..c6270616 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@csr.h @@ -0,0 +1,33 @@ +#pragma once +/** + * @file csr.h + * @brief Interact with control and status registers. + * @copyright MIT License + * @author Henrik Karlsson (henrik10@kth.se) + */ + +/* Machine CSR constants */ +#define MIP_MSIP 0x8 +#define MIE_MSIE 0x8 +#define MIP_MTIP 0x80 +#define MIE_MTIE 0x80 +#define MCAUSE_USER_ECALL 0x8 +#define MSTATUS_MIE 0x8 + +#ifndef __ASSEMBLER__ +#define CsrRead(__reg) \ + ({ \ + unsigned long __ret; \ + __asm__ volatile("csrr %0," #__reg : "=r"(__ret)); \ + __ret; \ + }) +#define CsrWrite(__reg, __val) ({ __asm__ volatile("csrw " #__reg ", %0" ::"r"(__val)); }) +#define CsrSwap(__reg, __val) \ + ({ \ + unsigned long __ret; \ + __asm__ volatile("csrrw %0," #__reg ",%1" : "=r"(__ret) : "r"(__val)); \ + __ret; \ + }) +#define CsrSet(__reg, __val) ({ __asm__ volatile("csrs " #__reg ", %0" ::"r"(__val)); }) +#define CsrClear(__reg, __val) ({ __asm__ volatile("csrc " #__reg ", %0" ::"r"(__val)); }) +#endif diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@csr.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@csr.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..05edbb7266116ad6973b96af1f460cf0899922c1 GIT binary patch literal 1992 zcmb7EO>7fK6dwCfDZgw)l^=;Fiz6TjSx*3CK}ZmhNux+u{5Xi-rt95_ck%3wGqYmtiRf(lAaFq%d8+t8kpgow^JS=Q!)N$E%o2PtE z^WCb;8?Hv#vQ{w+q``M__lmY_FyEvSX^t)oYgW|rIor_Cy(gw53q)vsjxf`%UlM`wL=a;GO`J&l4r20}|D2W-XJKB+4cs7{s zR`8Krb}E~XcZFfEWw@O|&!2BNk9Tfrmz#s5JG=FM@_3?M`JT-}QN*=&$8Nw$mkuFnoiiQAp<@~NKagrh9Su{}%%pl?Dx*$MXG8|r0d4%0`pq~(sbOV! zUpk0?pzRd&+CJ0&;QiXPbsu_N5w=GGQ`-86SV9GjL<$C!0X3b1_-CYG=+MT2&u_5@ z!L$v%1_FB91T>-4pfWg|hWN#25$o8rT1Vuh}o#`LRl(zp8fElSeUz9nkVqP zMCJ=~=gvW$OsmeP52I>5O3%@B3gUEB?Z?e;$?JvR{{|hTxD<+MxgTQzcM7C*E8Som z#EFRf$p2}5-^9J&!o<=pWWb`vok}NgA&y1dn~(1-9O`~`9_%YHstZuxY8+z;*KQFnkpJgNEZpxG-Q)fK@I6<+HAAgiMvT^ z3L?FD@E{btDu}cPQ7lqCC`j!eQ1#+52o@AUJcv+G8{cfFHBuB|*|%@@{pQW=>~XYn z=BT`h1SDl?o=DkrPRfw7WDVsct71u-q3Wd!v7{U^4T+d0HGNrhNTP+JWNMaLmZmjh z_bK2POGeJ1^M*+D8F5xskqB4h-xDJ-pElKO&@2c1T0X6&7Btl|+32(u)C&PWJgRw` zA$l-RGHIiN#EC&9&LS~!aN;7RI$!D)k}vu63=;VckUfw^B1Lq1ju&Z05w=t+6n(0X z{^bi;rnJm_IR9t-43@KFmk(Xwb$u~JxN_AF^s9IY0 z&QQ~9k}_4(MU5IraA8;HPwZf^_h~nqrndfe*>HWovna>osYGO4o=7HOxVtWeX-~pp z+HhMBvn+CZX>#;awej&QRve4V@_20D@)Ya{SSNPcmPKw)uetiSmqy2#jYKDvL?|Ic zY)clo ze7AM>!}&fvYWIZWxd5IpyUkapKB1!|# zoGQj=Of6PNQ^mq$q10!o?5bXj$nmrL-o_xueFlZP>(c&}KQnAby}gdh2&&kmX8BZA zdZ1#z!$+;?sY}0^3_f*a(DH$!KRQfpVhkAJ?QnAW+uQdmb9!@f6Bm;|`6Y|ll!)=p z?P#s?xtm4>L0|FQTkY0-(*?Xn-c`5`OJ6kW7ww5Eu8f(sH(ycRM=O}0O*b&I*N0T-? z(IEwA;kC2@??5MQgdd)~47aU^t4T@!GkkDpWqlRxzD{~eC48)MapdR?jEyCodu<{G zqn9(Kvy5t~0xYGCkzUvisE7^7WHM3k1*mpYu_v{*t5JYn);&;laZG6r&d0^GaK2ld YaP3b+GuPe>coxpYwFNlS%M%Oy2K06oB>(^b literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@interrupt.h b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@interrupt.h new file mode 100644 index 00000000..a838a8b2 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@interrupt.h @@ -0,0 +1,6 @@ +#pragma once + +#include "kern/proc.h" +#include "kern/types.h" + +Proc *InterruptHandler(Proc *proc, Word mcause, Word mtval); diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@interrupt.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@interrupt.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..8fc7bc9cb793840087a181cd49f24512b05b8572 GIT binary patch literal 1266 zcmb7EL5tHs6n-glqyzhJ8dzl@Wf6#|B0Kkz*D2{?L4rz|n z-WaQ?!b%c6rjp~BYbs@yYL~!eEK-eStVoUrF|RDIhcZ6qV!{z+Lo^};ka>^J&Kq;W zvXCl3Ngzqom$}!AlYsb-VxnZ>9mIW>dOc&3M1+*}6B-753h3?)KqEl+>xs1xOjUFr z(j;?P2xtier6U3)Kn#wTK^rx>;yePNiIC%%k5Cv(O0e4O!`FN>zdK?!`e<6ra-xiwAyArHTb#i|}{w{wLp%20D`!aH(IWBsM8AV|jvh zd!u>m;N@U}wRrXB literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@kassert.h b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@kassert.h new file mode 100644 index 00000000..0bcc7085 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@kassert.h @@ -0,0 +1,40 @@ +#pragma once + +#include "kprintf.h" + +/** + * @file kassert.h + * + * @brief Assertion support for the kernel. + * + * This header provides support for assertions in the kernel. When the NDEBUG + * symbol is not defined, the `kassert()` macro can be used to check whether a + * condition is true. If the condition is false, the `kassert_failure()` + * function will be called to report the failure. If NDEBUG is defined, then + * if the condition is false, we get a __builtin_unreachable, hinting to the + * compiler that the condition is assumed to be true. + * + * @copyright MIT License + */ +#ifndef NDEBUG + +#define KASSERT_FAILURE(FILE, LINE) kprintf(0, "Kernel assertion failed at %s:%d.\n", FILE, LINE); + +#define KASSERT(expr) \ + do { \ + if (expr) \ + break; \ + KASSERT_FAILURE(__FILE__, __LINE__); \ + while (1) \ + ; \ + } while (false) + +#else /* NDEBUG */ + +#define KASSERT(expr) \ + do { \ + if (!(expr)) \ + __builtin_unreachable(); \ + } while (false) + +#endif /* NDEBUG */ diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@kassert.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@kassert.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..0ea2225eb45e961345d7a59315997995b330bae3 GIT binary pat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P93CF< zLPZjkMnV$n^Yclu6a%>!hilW5x&8Dn%xnk(wy37vEWL(I6~50YA1Tx z^?m;ws8klsZa2Sq`*13y%89>cR-K(6N1oof`E6rcX{0H3DQ9LUxLrX*Hy#GG@lB1b zWp{sQ(?u;Q*6v=8YIVUWSIf1MQwB#%qdX&^GbZD_WA6?6SEuElEA>LKmTk~JeZy!L3Xd|P!A6SN=FNUSQMuMo|yU0imLb1a`MufMQwS$* z+~|kALs{E!DJPB$`JlYNiY^bY!$*NV;`?D-4m!O*OiebO0=9gKX;|>k*3WOwZ|oXx zJmmk6HqDB;F@4Vh}| z5Q$mtYc{aQW zD)H9q!FT(odB9!8$xE^I&)H|jN!8_4jRQ*>#L|;WdOL69*vkw05K(-O)F|NrM$_Am z-Ff%-KYk(W3)QCCSY2o=HNk!Q4BS+>vHFfTw{}(^%Gx0cuE^xPny*UM!cc6o#{ zv)b(AS!J)H?F;~He>VHcrd)p%*H-FF&DDAhd|C>c`gGH@q~z3&Br(lgj=_xr##oGa zN;{=zGhmwu;=-msXeS=dX24!bfIj^gy|ehx z?Kdv3)>TzgDURCjh3SGQW0d3C@!4z!?8O9Sv;X6*w{AZBK&4)GDtCG@5k)JCZgHTUC|`|0XP8@YCA#Ojg-KQp;aAU);EG c;gv7q7|0zBK26fktU=zCHU)DAJ2%Yx50&fE_y7O^ literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@macro.inc b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@macro.inc new file mode 100644 index 00000000..249ff679 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@macro.inc @@ -0,0 +1,16 @@ +#pragma once + +// See LICENSE file for copyright and license details. +.macro ld_sp tmp + la sp,(kernel_stack + 256) + csrr \tmp,mhartid + slli \tmp,\tmp,8 + add sp,sp,\tmp +.endm + +.macro ld_gp +.option push +.option norelax + la gp, __global_pointer$ +.option pop +.endm diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@macro.inc.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@macro.inc.blob new file mode 100644 index 0000000000000000000000000000000000000000..a4ff08a5eee65abb4cc624a28fd185bc76a55113 GIT binary patch literal 506 zcma)3F>b>!3?$G8^dCiO0;%iGTbE89n!T_k*-|Wtu4FrKpU}tUJ)MHuu`@YC01gCs zB=3$-aQ=IKJplk|c8YY-kW>T3mxkgPDF#7}3ZAqoWbz4*#BE2xL@`il{E}rU_P+6a z^r&owwGe<)yx(4Fys*7g5zrMu=sXNrYFr_{evF7=u9haZZI(`{a4eP0osxwg0Y7$t zHQ;``xMQ|)Vfw9HpI8aF9)e3j12S-VSV4=NgzuD%M-GkgHA)kd=s1k|mO~r(Fg4@k vm9=~!0}or+Z0ps7h4Cai(Qy9l-cI+xxvHY-;yg0{ZaZ>=2(2buzYXvYrCYJU literal 0 HcmV?d00001 diff --git a/kernel/inc/offsets.h b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@offsets.h similarity index 100% rename from kernel/inc/offsets.h rename to .ccls-cache/@home@hak@dev@s3k/sys@includes@kern@offsets.h diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@offsets.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@offsets.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..297f328c585b308690a37d444fdcc4b4f12ab6dc GIT binary patch literal 3943 zcma);du&rx9LMhp$~Fc&d$1P_I$*Dkw!61o$EE|WTQ`Z!J#HZ+pnJ64R@Sv!J2nQ3 zMtr~+G0~_20vHCUe@HS7G4c?>L_kGw7?g*P=+FQT(KrPnZvM_WJw5C0NJy4%mUG)r zzrW|XI$`9_g1obWAQ+pxEly)oU9-{Q>@fOG%|?Hh-{|+*jm=J<$Jpeoa~KpM+URX< zH~L(Ddxx>!<)Qys%=)#SW{nc)vX!Uv5z(YUe z%I)?NGr}bG$8cI%4ya=Y+t4J8Y-uk!`yd~OT=~2PK+xK$zcPUl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S)M=5_V9cLw_U z+j|FEm#b_IFJ#U{Ke!6)dSVfIy3RlsVhWvZLU=Lphp z0cTy(NJ5c1#OAb-008sQ0H90dxZLjWcGP2Kpd!}i#0C zZVWok8RDpnMb083BjBivbUZY~)lh!sA`)zXqrpbUO(R@5q2sKTRubH>4A9`FKOL3D#vhU!KKb0b_*q&9)&9?J_hp}wQzw-HXEJ}5R96Cc1bMSVc~^f;Ted)rBT zLEp`dFFM{E@}luoY%L}-0xv4#;U``n*u3*^SFPyl7-(79cd@WYmXTAhiU&tr};EPH!i%1WX;d zmY~ax5igNi-Db8CULYgoMVBrkoWdgCX(gEkGSW<=+aJCS5OP{^3Odx^vBAi_dOQeo+~WrP!HJGQmiNV4l{ufwJxWi(3JsWvR8OHeuS%{l!UCcCh(%C*h930+Zn1Q-4P9i zWm=XNml7>OSgIvmQSkj<4okS7L-}*Cb-X4oaX(z*Q1{bC)R19NOe+$E9KO>k6-wP$ zY2fMBElck+ShLLKoRq=}=!$2GbBfO?!*ICzC}YJ$Qwo5zPTC;AXS1E?#&co#r6Rw!q^wA$gIHh4NSWtFcgUty!&)^z`2)c7vCsej literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@sched.h b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@sched.h new file mode 100644 index 00000000..77f485f4 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@sched.h @@ -0,0 +1,35 @@ +#pragma once + +#include "kern/proc.h" + +/** + * @file sched.h + * @brief Scheduler. + * @copyright MIT License + * @author Henrik Karlsson (henrik10@kth.se) + * @bug QEMU mret does not work properly if all pmp registers are 0, so we have + * a temporary fix in sched_next. + */ + +/** + * @brief Initialize the scheduler. + * + * This function initializes the scheduler, which is responsible for managing + * the execution of processes on the system. It sets up the necessary data + * structures and configurations to support scheduling. + */ +void SchedInit(void); + +/** + * @brief Find the next process to schedule. + * + * This function finds the next process to schedule based on the current + * state of the system. + */ +Proc *SchedNext(void); + +/// Let pid run on hartid, begin-end. +void SchedUpdate(Word pid, Word hart, Word bgn, Word end); + +/// Delete scheduling at hartid, begin-end. +void SchedDelete(Word hartid, Word bgn, Word end); diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@sched.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@sched.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..f3f706b16c9bc501ec9e4ae75541d1b7f427d8d0 GIT binary patch literal 2501 zcmb7E-)kII6uzU22}}He1o2_XTt+Bq*x6}gvh*RTQ9@`Wv;kw4TG-6a+}*j!?7fpa zGn=F$N-4HV^+8+uV0{sU)*lpo@xg)tDN@iPD2jr4QU3t(#g-=Hxp!xFV>g6#S!VCv z`R+O2`Of+72-=>Br*9z*Ssrf?%d?j)mo%;L$z>~C53Nu*)-n;ya_pewpoc9UM3$hT z)3mCTwN~XZGiJ+-uQHSPHM8zG$b|3g?hz?-{MaQSG8?vVyh+h4kI{zhR8CPR6mqvp zC;gy221}>GUE)tRh-5D2~mFGI^CzRwjE^w18qlxF``%1Rk3p(|nJQWljw zw0*ez_jlb1WH&PHIxPYCIDuA9U1=DjftM{L{vC@H3IqQ@KU9G}w%A6m(+_=%*r(Nd8N+)*vpW=8=or)vsD^VVK zr+4Y0tO^WV7zh7T5b&x;8L=uZsoAj~RoXp~(rCHv8oNg~okf&O`d`{u`Do>v>rGBw z{G8(vcbfPlBEv6m;bPAg5p|1L{i)Vjx+2WokMjA)5Nd&OC=bRym=xPl`&50gOe=FlW2+$|XOKU;6T__UHNJFL816`cv9g@|ssT zvGCQEACu$bXUxjQl^+yAJ+A{n9q9rHUitpFv$vo9+L;Ga;}NCXQL+{d??(dzk0LZx z6_nKQ3}r5kJc1d#!%}n-hB)GxUZj-IFL*S>wU{{(cmvnq1R(Y}f~$5&Tv?7pIk6Cg zMforSbuh1~P3U(-8X!7S#0vw3Ax$fw!Uzz*dSK+-FN+_)+fjCwQOP@>@9>se)b{Bq z(u&vWE)iXHX&cxgoz4LfMZD@!$HPz?_%`4yq*b5b8W*@>GaKfjo|pW|8galrPz`WT z1tMWqU0Mj9jc`b!5XV6(jnvT=>lkLjhT28!sQUriptr+Wjn-pf%djoA;~?MyVzj5U zt<7M5u%Ky!XmA*z+%>7#&QD)2!?D+3C+NoA%@5Z$Uy&XKzv38#s59uF&%rCwR;XC) z&vM?Ci$2}ZM{=58)(^vTPG5lMqVDB1!!Tgqm@uZ{Id8m}(~@uByPDj#PhZXgbbgap zA3U>h+1mOv%iK~4tAUjdG&GduZHH0$<)rlIw7#}aGxNiUJRpraW6W*cr-;m5+XCyN zwgNlu3;-)v7mY&-Y#4`9aAqn6hRY!ht1sz+L_)1Wip+d?4*~tSeo`Ul^phzvyGibe xX`CC=O!U4l`~7 zGwf0QKRJz>B#kngbR~NhYqYQs7yrk>b|HIPp_0yF`)e@=s+3gD;mez16={;t*g4!S z*n(xJGkXMk3mJP)l3#^iKmaD@-QYtSOxGbkBRnHZ%oy`lpaqaE*-qGHb!-tmXwfdvUm3c1| zF{f%{vgsmUg=+P(y>jhS1@J1>%7*7vpmGbKG(LL&ar`@czMmg2e8$htzc|>(e?Pm7 lR<$*4R7OlK59~g$zP>i~n1}h}HcB@5TG^}AD_dm`{sCrUC+YwI literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@trap.h b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@trap.h new file mode 100644 index 00000000..ba72c170 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@trap.h @@ -0,0 +1,13 @@ +#pragma once +/** + * @file trap.h + * @brief Declares trap entry/exit functions. + * @copyright MIT License + * @author Henrik Karlsson (henrik10@kth.se) + */ +#include "kern/macro.h" +#include "kern/proc.h" + +void TrapHandler(void) NORETURN; +void TrapResume(Proc *) NORETURN; +void TrapReturn(Proc *) NORETURN; diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@trap.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@trap.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..c8c40304da693c8e2f98d9e36eaa692cc1c39ce5 GIT binary patch literal 1818 zcmb7FO=}ZD7@kc%$nN@aDB?j%jizrAB7DT*g@#4Xryr@4w5DVHkvq{sG1hQS0VVHfN_v3k=d3OrzRpP7L z008K-07KucLk~BgxKxLtC7|F4)-eyEKtA?z2%Lf}l8_UD8n8mb&aRMm;;=7+}v0Tfn(> z5jZvAEDk!Bj8V}^^$rf=9QAi1tZ{VcEk~H>R>ITM-sLCqq@x%QcaLDiUe?oh_Aa3VRiiC-u#4rUNvqMEjRY zm?Qj)Ac6u1ZsaqLHRkt&bRjzJSAc7ygCs>OWorMca%4`4c|GE)HB}8cN>_Ugoz)FZ z!EN0Y0`o)zNt_grUca9|o=+>ca)_IhRLTv^1!18s>j;w5a<5`n#=K8xvEWd-gp@V{ zXC|NQ5p}~FoXO{=bApOT9Tty894SaSlct6PIkjo0YqhjyRh0CL~ z=W(LxfRY4>^rV*F!EhXTdzC&!9PLw?IXRf%p)rxjYX2&oPGj7?r(mpId$jX?^X2+( zgAp&g$ld5RR?P?}7t~G8PMrs)Ij;Ty>ahVZY}1}F3>(-b0NV1y#>$U{>)-m2A`b9y zq-9zPX#qvfkcxm)APq z``7mU6DwP5@ZW~kubN$1A$g2sHmN}`U}EBU7tnL_S07}otTlPeu(P&WjrOavFMi6^ XbFkm}n3*%@N`^IUl}d&^ZL9S^KmmfR literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@types.h b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@types.h new file mode 100644 index 00000000..342e9175 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@types.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +typedef unsigned long Word; +typedef unsigned char Byte; +typedef unsigned long long Time; +typedef unsigned long Pid; + +#define NULL ((void *)0) diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@types.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@types.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..2af942b24ff74379609492ba0f313681f9c2eaca GIT binary patch literal 1335 zcmbVKL2J}N82z$zvr8|ECr>rtr7fGCZH>W$yP$XxiuF(tL2_P$BEb-b$z9Ap zao9%@86b6|kJL~hB{Av~$q^3ICWcE$q#2S_;Q{JWezNmDH|KpWwzx~!y4%ATT>aj^ zn2~bK@`xyKlThNgEeF0wlMn|lC|1&(c4?cXzNfc15fNeSghU}9g1fp5ZV%kGY2r)> zrcQ)zk|b}k2;6ZYC=Oz91&Hp(_)_7fDax64w}k9d-g6@=3C@HZwx<=OQf%m-3dMvm zQAmN=b7>Ws{hbsVD=dNzR2EU5HDfsL_=jJn3z%-4W_Q*Sef<-;w^!ymky1#*Kj+-q zE30fG>b4Pe*8G3j2{_qev>ObFR8;VZrE+NFbDe})E{U2zb0v|cM2rm*cgZXEn1#HD zmb_-G>7OQpbc$U)3kLZ9WwJY+%LRQx;|V$b-MCpg7_BnU{Ze^45n0Zk9`%@Vf`W*w zhdIlFY?z)ot<0eR@M@Rr%w)y@W=3=0pZ@ys@mp%@Yb{RB742~nIZW`L^N>c+XxIQ& zy-{DTSaql`gL#fDvyS$6w)fwDUERJIT~Msign;kYHAl^_bt+a3Y8?YU(_M(x-*XXcIM{?f=15bLTf=Y%wC?oS}|)2M#ldi3Vg~A literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@utils.h b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@utils.h new file mode 100644 index 00000000..db0da8ca --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@utils.h @@ -0,0 +1,50 @@ +#pragma once + +#include "kern/cap.h" +#include "kern/csr.h" +#include "kern/types.h" + +static inline bool BitSubset(Word a, Word b) +{ + return (a & ~b) == 0; +} + +static inline Word PmpNapotDecodeBase(Word addr) +{ + return ((addr + 1) & addr) << 2; +} + +static inline Word PmpNapotDecodeSize(Word addr) +{ + return (((addr + 1) ^ addr) + 1) << 2; +} + +static inline Word CapMemBegin(Cap cap) +{ + return (cap.mem.tag << 27) + (cap.mem.begin << 12); +} + +static inline Word CapMemEnd(Cap cap) +{ + return (cap.mem.tag << 27) + (cap.mem.end << 12); +} + +static inline Word CapMemMark(Cap cap) +{ + return (cap.mem.tag << 27) + (cap.mem.mark << 12); +} + +static inline Word CapPmpBegin(Cap cap) +{ + return PmpNapotDecodeBase(cap.pmp.addr); +} + +static inline Word CapPmpEnd(Cap cap) +{ + return PmpNapotDecodeBase(cap.pmp.addr) + PmpNapotDecodeSize(cap.pmp.addr); +} + +static inline Word Preempted(void) +{ + return CsrRead(mip) & CsrRead(mie); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@utils.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@utils.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..8fb6ea5229f6eb187124c0cafeb81ecf828b49fa GIT binary patch literal 3766 zcmb7He{37|75{!+_vF?|>Nzp)PS@H_t;4QkU(&jUd5IOW)Pg8Y8L5&^NSO28CAq}D z^X|?m?f4}MRq4>Cb}L0 zJ~yt@;#tYpUw`wy@AKa0ecroxBUAQ7KR)kVj zlyq)R(iBe6wbaaYEOkw&8S#~rfYxwo#o#nq7v{O5tk}CuI$2fb6m^%9luA>{X+c0q z__^c8*eF@%HDP8zo6n@>GA|VN$PfrQEy@F>N+u0kp{$BhX`n2Lys{f5w{JqpX_Va2 z?ATD%QZ1XGOXX^+B%)+3Nn{<&prne_;;fT0$tIb1bQC18n#9}UU@r`DHW$Fe=fce^e!{=Ht zhX@5?|L%YKTe6olO(nuuJn=+p0J<%jNKJU zCqe!7$Zf5n6clM!NiG)VB~6!Ah1|Ak(qfFzU{exrR5csex?0sW4qS4j(tJ7Dm$vpo ziC3n%zI3WLmAR?~Lo9-r3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b^tTU!|rqM ayx8;S);z&izB$JgDVklm$XH~e4Sxrf#g%^m literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@wfi.h b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@wfi.h new file mode 100644 index 00000000..a53659f5 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@wfi.h @@ -0,0 +1,13 @@ +#pragma once + +/** + * @file wfi.h + * @brief Declares wfi function. + * @copyright MIT License + * @author Henrik Karlsson (henrik10@kth.se) + */ + +static inline void Wfi(void) +{ + __asm__ volatile("wfi"); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@wfi.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@kern@wfi.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..d8116c8188798d531ab5ab8ad7138ee21555f1de GIT binary patch literal 1588 zcmb7F&ubJh6wdY_v=lw)A26rVN;7G7T?D&j3q>p{UJ4$UOyD#G}Ql{s*1~@l;LH?Y6Roox(7LH}88tzW2S%O>}JQ-6Mn$$yEs?rv*u2 zNX+emn6V*7Gg5$-#IPLFn4xP#RhDRO*pMV#o}4;uT+2eLk;EV}JYWoA_v~F9lS?M* z6b!;8)hzGoVW-VY%KFbaGum4d-W64+?T)NeDTry#J3+uDu5FU4=UEvGuVT;AECA!~OXcnX)1V zN?PSggRkoMt7b`@G`;(4+pOuL(rz}Hhg@c?(}`~Ri8dgspvHg>A_#dJK&AtK_hzT5 z-ue~tAGePBmY_{W#xO1j;n^HaS zDc|mV|4c4}OWdvCfrl^3FSBf3u&rcrR~-LYzcWv)spg&zVtE;qWWAEkZpXRn>-1sj zut}augj#kEv>``5?E^gEh!LYf}D{LMcSaUxJwA}J + +typedef struct semaphore { + uintptr_t released; + uintptr_t acquired; +} semaphore_t; + +/** + * Initialize the semaphore with n tickets. + */ +void semaphore_init(semaphore_t *sem, uintptr_t tickets); + +/** + * Acquire n tickets and wait for release. + */ +void semaphore_acquire_n(semaphore_t *sem, uintptr_t n); + +/** + * Release n tickets. + */ +void semaphore_release_n(semaphore_t *sem, uintptr_t n); + +/** + * Acquire 1 ticket and wait for release. + */ +void semaphore_acquire(semaphore_t *sem); + +/** + * Release 1 ticket. + */ +void semaphore_release(semaphore_t *sem); diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@includes@smp@semaphore.h.blob b/.ccls-cache/@home@hak@dev@s3k/sys@includes@smp@semaphore.h.blob new file mode 100644 index 0000000000000000000000000000000000000000..35fca4fa8812786e5b380bfbe5bbdab1e90ec71d GIT binary patch literal 2279 zcmb7EO=u)V82!50O~ygSWwY$&V5A)(Xh=^b?l^~#5rZP+p7H24;OUY8ol3+1rYhHOKM{H?T?0AEM2lf=nqijk zsgI>3BAb7vQvy=V`tx_U%0|s&WEjzoHy}b%&P-b;h?|Lemtd8OLm^A0K$;Ro(I9r$ zo7uA;Vb(+I&Bj`zHI2Cnu;>}dYg<2mjZT8==nKIBKe!ryGwbFt2NmVl#KE7dkKHY& zfuP0?q-acxh|+gx$@6Cn@pL|9njIozrBx}5on!<~kA8SU{2qPr={o~X14oh=Cm|Qa z6C@&7l82`&%30Abk3h9r2Y7z`*;#iK_4`CM^vw_V0$BBGebut+P=6L+^!JnBKDYnl zZ>NrMWB+ohFTele-Wq={xE;&_XNakCx?DJUVTIsQbx8{@!IBX~a~p5mdUf~hBZ4`` zV>6PgPO3djl<<_pOmEB6-dNt7EVLG@i))s(2#ZW>oqhik`}WSSUmelPn=7d`>9x?h zbF&N81zo@bESLheKl&+n;q=AVj}$-|Rd?)jJTYmyy&qs(Z>Kn-SBRrRGEIOpq$+fZ zx(W|!)!MRU)u5ID*w@Y25C7~@_1Z(XZoId)GkWX6(T6u*{ENWoW_$bNozE__putc(f, c); +} + +int alt_fgetc(FILE *f) +{ + return f->_getc(f); +} + +int alt_fwrite(FILE *f, const char *buf, int size) +{ + for (int i = 0; i < size; ++i) + alt_fputc(f, buf[i]); + return size; +} + +int alt_fread(FILE *f, char *buf, int size) +{ + for (int i = 0; i < size; ++i) + buf[i] = alt_fgetc(f); + return size; +} + +int alt_fputuint(FILE *f, unsigned long long val) +{ + int i = 0; + char buf[32]; + do { + int tmp = val % 10; + buf[i++] = '0' + tmp; + val /= 10; + } while (val); + + for (int j = i - 1; j >= 0; --j) + alt_fputc(f, buf[j]); + + return i; +} + +int alt_fputhex(FILE *f, unsigned long long val) +{ + int i = 0; + char buf[16]; + do { + int tmp = val % 16; + buf[i++] = tmp < 10 ? ('0' + tmp) : 'A' + (tmp - 10); + val /= 16; + } while (val); + + for (int j = i - 1; j >= 0; --j) + alt_fputc(f, buf[j]); + + return i; +} + +int alt_fputstr(FILE *f, const char *s) +{ + int i = 0; + while (s[i] != '\0') + alt_fputc(f, s[i++]); + return i; +} + +int alt_fgetstr(FILE *f, char *s) +{ + int i = 0; + while (1) { + s[i] = alt_fgetc(f); + if (s[i] == '\0') + break; + i++; + } + return i; +} + +int alt_vfprintf(FILE *f, const char *fmt, va_list ap) +{ + int i = 0; + int j = 0; + while (fmt[i] != '\0') { + if (fmt[i] != '%') { + alt_fputc(f, fmt[i]); + i++; + j++; + continue; + } + + switch (fmt[i + 1]) { + case '%': + alt_fputc(f, '%'); + j++; + break; + case 'c': + alt_fputc(f, va_arg(ap, int)); + j++; + break; + case 's': + j += alt_fputstr(f, va_arg(ap, char *)); + break; + case 'x': + j += alt_fputhex(f, va_arg(ap, unsigned int)); + break; + case 'X': + j += alt_fputhex(f, va_arg(ap, unsigned long)); + break; + case 'u': + j += alt_fputuint(f, va_arg(ap, unsigned int)); + break; + case 'U': + j += alt_fputuint(f, va_arg(ap, unsigned long)); + break; + default: + // Error: return negative number. + return -1; + } + fmt += 2; + } + return j; +} + +int alt_fprintf(FILE *f, const char *restrict fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int i = alt_vfprintf(f, fmt, ap); + va_end(ap); + return i; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@fprintf.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@fprintf.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..fb2d5177c80592b5a464454ee041dc4e037e09ee GIT binary patch literal 1941 zcma)6U2NM_6u$Pd#;qb6QWS+SA%oT`&1&C{r4fqSQYsN`Fl9(|(;hk{j_o*3{5Suk zWJPV&z3?<4`hq5e!~^gG5)XTV2_YsSBv6^e3%m>-Crv`UOd3DK++){ivIJ?Cb+3J{ z@ArM@obNi1{=L1sxQ`IRO;eX~Q)pvJ?qKIs8#`SGJGO`g&BYDNRt>koi)a#?mWyrG z5j(i98sSs1zZT-XOS&uxMi+7CUO=3JxV2$m*EBT;w`JSFmu21KH3@MCL?{R}5oaQ^ z-f{*L;?2iSo!c<&wrVJxq}sCRns#?-SchesEwbp~rmSgZAP5~9{tSv6)gch1ntU^C z2KF2qYib>9T1V$j7J_F{6AT5PEb#MuG1`b7R}yRm_Pzh|FSmwCMra9(Lv}ovTiB=m zC-q@rXu|*F#Kq6jdpF)DK46I@s+|K*775HNx~Oa(i#jTD58eiPHpGO zD&;SKdFTB4u}dFCi8d73bzHkI&mcnwa!OOH%<8i=wTjLLIZ@?Q`M7`it)FY3e{=JD zU<<%ePje5{@*V;0E8YQgi76525?TqNmt)K6fpUeqp(KIs6N}r|FTHC1b4U@K**@KU z6hVJ@o)44QWHt%YCfW^|pcK7+_azb4`H;bLoAR5744&briXls^W*SO3bObHr$TNAu zkw-6v91F395!uktPsj$^7-SW7uAkE*FONf-p|VVtI4+BFA?b8%dK4*G1jxV{0qH&C z+lB9TKd$shZCQ{G8AFTLJ>q%z!cnitkYkFPVy3b*HH9)ET{@l4jWR>zj~+a6m>9u_ zNO2}kkm6_}Kte&QX}|-0V6s5x2X{~X6yMvr*aO3G3G`$r zcQQ6PqB^MOxgHDgZci>Df#V>CvT24UvT1a*Pj(z|K`vAuW@tUkU}%`(KL9fvf0*Ia z!;Fsl?|FK$eC?Ad_+LcVSdFdCtxys#l~yQ)SIF4nTV&Md^+nRed5etx%)8awwej<> zN4sFAw&<-CS(|pveshbH~#wcT6q8(>h%b8ShhieSUMIE{0H9oRFVJy literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@printf.c b/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@printf.c new file mode 100644 index 00000000..b5c57eec --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@printf.c @@ -0,0 +1,58 @@ +#include "alt/io.h" + +extern FILE *const _altout; +extern FILE *const _altin; + +int alt_putc(char c) +{ + return alt_fputc(_altout, c); +} + +int alt_getc(void) +{ + return alt_fgetc(_altin); +} + +int alt_write(const char *buf, int size) +{ + return alt_fwrite(_altout, buf, size); +} + +int alt_read(char *buf, int size) +{ + return alt_fread(_altin, buf, size); +} + +int alt_putstr(const char *s) +{ + return alt_fputstr(_altout, s); +} + +int alt_getstr(char *s) +{ + return alt_fgetstr(_altin, s); +} + +int alt_putuint(unsigned long long u) +{ + return alt_fputuint(_altout, u); +} + +int alt_puthex(unsigned long long h) +{ + return alt_fputhex(_altout, h); +} + +int alt_vprintf(const char *restrict fmt, va_list ap) +{ + return alt_vfprintf(_altout, fmt, ap); +} + +int alt_printf(const char *restrict fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int i = alt_vprintf(fmt, ap); + va_end(ap); + return i; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@printf.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@printf.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..9c0d63bf37fc892cadb623ca6cd17c00df0c1145 GIT binary patch literal 2350 zcma)-ZD<@t7{_P!j9J6Bxm=I4c_D1`a%?ZzoAi3QYDs+gpfuRVVy*N;CEeTGyW8B} z?sa$X(v+&T{i1>h4M-I!_#q;SqF^j&DQZE2N?NI4`@!mm6cmdnC@P}s%ueQR&ugS` z40E$PzxhA^=b2{{;Gat;CRP9dsA!cnR8&eRr`3?Ny@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size) \ + (struct buffer) \ + { \ + ._putc = buffer_putc, ._getc = buffer_getc, ._flush = buffer_flush, ._buf = buf, ._size = size, \ + ._i = 0 \ + } + +struct buffer { + int (*_putc)(FILE *, char); + int (*_getc)(FILE *); + void (*_flush)(FILE *); + char *_buf; + int _size; + int _i; +}; + +int buffer_putc(FILE *f, char c) +{ + struct buffer *b = (struct buffer *)f; + if (b->_i >= b->_size) + return 0; + return b->_buf[b->_i++] = c; +} + +int buffer_getc(FILE *f) +{ + struct buffer *b = (struct buffer *)f; + if (b->_i >= b->_size) + return 0; + return b->_buf[b->_i++]; +} + +void buffer_flush(FILE *f) +{ + // NOP +} + +int alt_snputuint(char *buf, int size, unsigned long long val) +{ + struct buffer b = BUFFER(buf, size); + alt_fputuint((FILE *)&b, val); + if (b._i < b._size) + buf[b._i] = '\0'; + return b._i; +} + +int alt_snputhex(char *buf, int size, unsigned long long val) +{ + struct buffer b = BUFFER(buf, size); + alt_fputhex((FILE *)&b, val); + if (b._i < b._size) + buf[b._i] = '\0'; + return b._i; +} + +int alt_vsnprintf(char *buf, int size, const char *fmt, va_list ap) +{ + struct buffer b = BUFFER(buf, size); + alt_vfprintf((FILE *)&b, fmt, ap); + if (b._i < b._size) + buf[b._i] = '\0'; + return b._i; +} + +int alt_snprintf(char *buf, int size, const char *fmt, ...) +{ + struct buffer b = BUFFER(buf, size); + va_list ap; + va_start(ap, fmt); + alt_vfprintf((FILE *)&b, fmt, ap); + va_end(ap); + if (b._i < b._size) + buf[b._i] = '\0'; + return b._i; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@snprintf.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@snprintf.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..4aa42c42f536f603a75338b2aa4eeffee4183764 GIT binary patch literal 2810 zcmb7Fe`p(J82-LX(xvJ3dek%x*|m+;rA?a4bzPeMXuEZ#>)LH>A`XVaYI?aO*Iw@G zU6QU-VJO11;n4&l*PEn+u?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U-_u#>?QOK}ve8{Ei*!E%GIL*t|iVFkBf1#e*e4{K2wJpcdz literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@sprintf.c b/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@sprintf.c new file mode 100644 index 00000000..b0a4182f --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@sprintf.c @@ -0,0 +1,67 @@ +#include + +#define BUFFER(buf) \ + (struct buffer) \ + { \ + ._putc = buffer_putc, ._getc = buffer_getc, ._flush = buffer_flush, ._buf = buf, ._i = 0 \ + } + +struct buffer { + int (*_putc)(FILE *, char); + int (*_getc)(FILE *); + void (*_flush)(FILE *); + char *_buf; + int _i; +}; + +int buffer_putc(FILE *f, char c) +{ + struct buffer *b = (struct buffer *)f; + return b->_buf[b->_i++] = c; +} + +int buffer_getc(FILE *f) +{ + struct buffer *b = (struct buffer *)f; + return b->_buf[b->_i++]; +} + +void buffer_flush(FILE *f) +{ + // NOP +} + +int alt_sputuint(char *buf, unsigned long long val) +{ + struct buffer b = BUFFER(buf); + alt_fputuint((FILE *)&b, val); + buf[b._i] = '\0'; + return b._i; +} + +int alt_sputhex(char *buf, unsigned long long val) +{ + struct buffer b = BUFFER(buf); + alt_fputhex((FILE *)&b, val); + buf[b._i] = '\0'; + return b._i; +} + +int alt_vsprintf(char *buf, const char *fmt, va_list ap) +{ + struct buffer b = BUFFER(buf); + alt_vfprintf((FILE *)&b, fmt, ap); + buf[b._i] = '\0'; + return b._i; +} + +int alt_sprintf(char *buf, const char *fmt, ...) +{ + struct buffer b = BUFFER(buf); + va_list ap; + va_start(ap, fmt); + alt_vfprintf((FILE *)&b, fmt, ap); + va_end(ap); + buf[b._i] = '\0'; + return b._i; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@sprintf.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@alt@sprintf.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..03661d536417a6c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ccls-cache/@home@hak@dev@s3k/sys@src@drivers@time.c new file mode 100644 index 00000000..d656038f --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@time.c @@ -0,0 +1,24 @@ +#include "drivers/time.h" + +extern volatile uint64_t _mtime[]; // Set in linker script. +extern volatile uint64_t _mtimecmp[]; // Set in linker script. + +uint64_t time_get(void) +{ + return _mtime[0]; +} + +void time_set(uint64_t val) +{ + _mtime[0] = val; +} + +uint64_t timeout_get(uintptr_t hartid) +{ + return _mtimecmp[hartid]; +} + +void timeout_set(uintptr_t hartid, uint64_t val) +{ + _mtimecmp[hartid] = val; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@time.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@time.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..20ba7dcba1301709ff662b1f9917e151c86ceaef GIT binary patch literal 920 zcma))F^dyH6vy98420!ELI@{V=yHvTWHJzAs>@Z^h=_$Y-XUQ#J7(uHyOW!lY>Zk7 zS_oSBRm8&PDmg?j+Sy!X=_jy|i@UkYVT_T3VR*cm-~YY;%)181U!QGG0DuN6acxgdXcW7R=~0+ZAm&Xf>0Nh05o$9dh4`#z5{gfb@XeTNbuT zNkjWwM|7Wu!@Bf=oECyvA^@U5b@$9)j_T_C=E+FuzKD9n7n(Dx^tip;$v~^Un53MMTyOJZ*(vbJIBXWEC7|9hIH3i%}Ua;$&<9)=;`nZ(q4}_2Bgrex`FKataoa z<2aWvav;9|emQzkeRn^6lh&Bm?=94?LN2$C3Z+5?qXLu`=uYqDNAdmBXij%hGzE$% zTgq-=l!e@%0O0ANI5^zM^SAtwO@_sdmGrETd}gu}rY*2=u=@Zil@i?LHp#nEM9E;e vhG{Xd^~7!-5Xv+%+sO`@ZJ6$S{_x}1(fe1cHD`ir{}sdyyoC@3yam4j!bl^+ literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@ns16550a.c b/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@ns16550a.c new file mode 100644 index 00000000..b973209a --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@ns16550a.c @@ -0,0 +1,47 @@ +#include "drivers/uart/ns16550a.h" + +#define RBR 0 // Receiver buffer register +#define THR 0 // Transmitter holding register +#define IER 1 // Interrupt enable register +#define IIR 2 // Interrupt identification register +#define FCR 2 // FIFO control register +#define LCR 3 // Line control register +#define LSR 5 // Line status register + +#define LSR_RX_READY 0x1 // Receive data ready +#define LSR_TX_READY 0x60 // Transmit data ready + +void uart_ns16550a_init(FILE *f) +{ + // TODO: + // regs[LCR] = 0x3; + // regs[FCR] = 0x1; +} + +int uart_ns16550a_putc(FILE *f, char c) +{ + // regs = pointer to memory mapped registers + volatile char *regs = ((struct uart_ns16550a *)f)->_base; + // Wait until transmit register is empty. + while (!(regs[LSR] & LSR_TX_READY)) + ; + // Write char to transmit register + regs[THR] = c; + return c; +} + +int uart_ns16550a_getc(FILE *f) +{ + // regs = pointer to memory mapped registers + volatile char *regs = ((struct uart_ns16550a *)f)->_base; + // Wait until receive register is ready. + while (!(regs[LSR] & LSR_RX_READY)) + ; + // Read from receive register + return regs[RBR]; +} + +void uart_ns16550a_flush(FILE *f) +{ + // NOP +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@ns16550a.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@ns16550a.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..ce1b0d5e375789e393c8d0f50f6514494536696d GIT binary patch literal 1567 zcmbVKO>Em_82&yt>mv7O)|9QZiYkw^C{1I3Nt*+EkJMczI3e}G0a0;4(>C?6%Pvd^Auc;?^Ij*-S}*Md%X;*^ zpP%P>fBdGL`Z2q|_)y3cRI*?JbAeP2J!~X=sd^bF5X!Sq+U= z-nJ-b!EM!=vsVf^IMRlz8}?ko&^2cbDX-2TrG}KnUSrR7ZBFV2bI6-Uqp8|DQg#!e z_JxTQ7rE7CepqX&`#;8^th%gjIW+JuOdy(h;3DgZMPaqHrGB=TXSk8n^QAtp(`ZZ(=}ELbYGmgvDKU8fLb~O z1I68Re!Eu@D(m32*sT&DGQdYo9i~PR|IZ!e_Fq32Pqkc2mxHCNbeFEOWH-5)JXczn zms3kqNEDyK)8ceSz|%+-V2KeL!~y!*U!VPo>b37J$9v48W_WbZAsU^)a#T(WSVmJJ z2lcZL#-4od)=sa(N^{R4EmKotGMz$!Q!E+-rx+R!IrWWSk@DNmZynH&g7aP81V>qQ7

$#M*N|Gk`ftB^qm4@d(^A;1~r!wCv-A?60rhE8l!Sz7a^uhgfy* z!72+%Q4+xkFw=3GOiu<*cRo(dCebTFa;T+$UoCPTR8c8le3~3>hXF%I8^@A3$qecGpug@>XFTeYAsTATv*ybORjsPF9%m4e@ zx1VfY`E;{1ALh@O<)EX86ahY9mw(l0r2pI8_;K;25FbK0m}Q^T2YkQ|AIAsd$DxZ8 z;-z0w_kY`52zLRYJPWF$(os+WcC%ClF2{~}-_i05p)3%#vj~y^e8Al-$+4td#18?X Cr@>JG literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@sifive.c b/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@sifive.c new file mode 100644 index 00000000..dc16f41a --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@sifive.c @@ -0,0 +1,51 @@ +#include "drivers/uart/sifive.h" + +#define TXDATA 0 // Transmit data register +#define RXDATA 1 // Receive data register +#define TXCTRL 2 // Transmit control register +#define RXCTRL 3 // Receive control register +#define IE 4 // UART interrupt enable +#define IP 5 // UART interrupt pending +#define DIV 6 // Baud rate divisor + +// Bit masks for transmit and receive registers +#define TXDATA_FULL 0x80000000ul +#define RXDATA_EMPTY 0x80000000ul + +// Control register flags for enabling transmission and reception +#define TXCTRL_TXEN 0x1ul +#define RXCTRL_RXEN 0x1ul + +// Control register flags for setting stop bits +#define TXCTRL_NSTOP 0x2ul + +void uart_sifive_init(FILE *f) +{ + // TODO + // UART0->txctrl = TXCTRL_TXEN; // Enable transmit data + // UART0->rxctrl = RXCTRL_RXEN; // Enable receive data + // UART0->div = TLCLK / TARGET_BAUD_RATE; +} + +int uart_sifive_putc(FILE *, char c) +{ + volatile unsigned int *regs = ((struct uart_sifive *)f)->base_address; + while (regs[TXDATA] & TXDATA_FULL) { + } + regs[TXDATA] = c; + return (unsigned char)c; +} + +int uart_sifive_getc(FILE *f) +{ + volatile unsigned int *regs = ((struct uart_sifive *)f)->base_address; + int c; + while ((c = regs[RXDATA]) & RXDATA_EMPTY) + ; + return c; +} + +void uart_sifive_flush(FILE *f) +{ + // NOP +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@sifive.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@drivers@uart@sifive.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..2b94b70b612a25e82dd448e5cc77af8c08c49662 GIT binary patch literal 1163 zcmb7CPe>F|9DXyd>#`2`%GSgbA0~?q>a44VNZG2p8yjXajbTA8%gpTVu(}&FyPB6M z4;4y8RCK9BNDx5>y96GBf=;1CL`cvr=nozuv<#~4H~V&$QBTd`gZcPtzVxtN|63@r|S9WpADCt~Tuf6LmZ zGkQu(C)yQFSLJL*pEap~H1X7Bao&rf%3p{2EKsfF837?0b-vy2Dr zv+EI;SKoXX3~vNCrSTz29FC5hkdBYSdbRr%HLj&qV&{qPygxUA5L1n-p$uR*%A2Q= z|M+le&iHhBMWim`cxVLZ8q35+gGXn<17qxE89;y0qo(ullN-wm328hyAPq#rW5dIC z4;u|0y*~OCtSWIOSOEqKRt)JN!2pww&dol*7+w@3=0XmuOJtPvzzP+(Vh?L#Z86@1 zZ&$q&`)4DeEz=>=4bx8SglRx)x_0P`;Fs$os6D>j{c_GK*Iv#N-N%dn?VhIE3e43|L)AWdQTX5I(q{?ola zshpmlrjyaou~F$1IFz20o!@?y9OmF<0S?lu= cap.mon.begin && pid < cap.mon.end; +} + +Error CapMonitorSuspend(Word mon_idx, Word pid) +{ + Cap cap = ctable[mon_idx].cap; + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!cap_monitor_valid_pid(cap, pid)) + return ERR_INVCAP; + ProcSuspend(ProcGet(pid)); + return SUCCESS; +} + +Error CapMonitorResume(Word mon_idx, Word pid) +{ + Cap cap = ctable[mon_idx].cap; + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!cap_monitor_valid_pid(cap, pid)) + return ERR_INVCAP; + ProcResume(ProcGet(pid)); + return SUCCESS; +} + +Error CapMonitorGetState(Word mon_idx, Word pid, ProcState *state) +{ + Cap cap = ctable[mon_idx].cap; + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!cap_monitor_valid_pid(cap, pid)) + return ERR_INVCAP; + *state = ProcGetState(ProcGet(pid)); + return SUCCESS; +} + +Error CapMonitorRegRead(Word mon_idx, Word pid, Word regnr, Word *val) +{ + Cap cap = ctable[mon_idx].cap; + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!CapMonitorValidPid(cap, pid)) + return ERR_INVCAP; + if (regnr >= REG_COUNT) + return ERR_INVARG; + Proc *p = ProcGet(pid); + Word *regs = (Word *)&p->regs; + *val = regs[regnr]; + return SUCCESS; +} + +Error CapMonitorRegWrite(Word mon_idx, Word pid, Word regnr, Word val) +{ + Cap cap = ctable[mon_idx].cap; + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!cap_monitor_valid_pid(cap, pid)) + return ERR_INVCAP; + if (regnr >= REG_COUNT) + return ERR_INVARG; + Proc *p = ProcGet(pid); + Word *regs = (Word *)&p->regs; + regs[regnr] = val; + return SUCCESS; +} + +Error CapMonitorCapRead(Word mon_idx, Word read_idx, Cap *buf_cap) +{ + Cap cap = ctable[mon_idx].cap; + Word pid = CapIdxPid(read_idx); + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!cap_monitor_valid_pid(cap, pid)) + return ERR_INVCAP; + *buf_cap = ctable[read_idx].cap; + return SUCCESS; +} + +err_t cap_monitor_cap_move(cidx_t mon, cidx_t src, cidx_t dst) +{ + cap_t cap = ctable[mon_idx].cap; + pid_t mon_pid = cap_pid(mon); + pid_t src_pid = cap_pid(src); + pid_t dst_pid = cap_pid(dst); + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (src_pid != mon_pid && !cap_monitor_valid_pid(cap, src_pid)) + return ERR_INVCAP; + if (dst_pid != mon_pid && !cap_monitor_valid_pid(cap, dst_pid)) + return ERR_INVCAP; + return cap_move(src, dst); +} + +err_t cap_monitor_yield(cidx_t mon, pid_t pid) +{ + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!cap_monitor_valid_pid(cap, pid)) + return ERR_INVCAP; + proc_t *proc = proc_get(pid); + if (proc_acquire(proc)) { + proc_release(proc); + return SUCCESS; + } + return ERR_INVSTATE; +} + +err_t cap_server_send(cidx_t srv, uint64_t data[4]) +{ + if (cap.type != CAPTY_SERVER) + return ERR_INVCAP; + return SUCCESS; +} + +err_t cap_server_recv(cidx_t srv) +{ + if (cap.type != CAPTY_SERVER) + return ERR_INVCAP; + return SUCCESS; +} + +err_t cap_server_sendrecv(cidx_t srv, uint64_t data[4]) +{ + if (cap.type != CAPTY_SERVER) + return ERR_INVCAP; + return SUCCESS; +} + +err_t cap_client_send(cidx_t clt, uint64_t data[4]) +{ + if (cap.type != CAPTY_CLIENT) + return ERR_INVCAP; + return SUCCESS; +} + +err_t cap_client_recv(cidx_t clt) +{ + if (cap.type != CAPTY_CLIENT) + return ERR_INVCAP; + return SUCCESS; +} + +err_t cap_client_sendrecv(cidx_t clt, uint64_t data[4]) +{ + if (cap.type != CAPTY_CLIENT) + return ERR_INVCAP; + return SUCCESS; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@cap.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@cap.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..1701e5e68804163a602139f64612392f2bbef16f GIT binary patch literal 20169 zcmb7M30zZG*3XR*HH{D>#)yb9lco_75D_T?A__$aA%@7llK>G2m;^-Bjylw-iu*d< zEYs>(r>^7fjM`eQR_(Ov)cW=NtQ~8otD|F=ag@IAe{bFki?n6>>pS^#-+TAnd+yop zdFL4{`ti<~q<2Mxh{CGsYHeXvrPX0pTVt4Oe07*>t}D#$D6eU-+FW7PHm4)3ytF>F z>L;#rImbMu*OrzSH`~iyPTE>#kE^MViUcgLt+U!{;%aTyQpa4;*o+9#*h*{Lw+03@pHiXt#MPvC%idaLHXl$LRu54DPDVK-V^={H*=hQi??T*T^R=d+y z?yhsrjeB$i_0GCkIOz(jveneoF`jkd7UNl0P6^AvmZaF_w%Q$TEX0rTQTHxB`hcHW zw;xqYroG#n%Q3=o+Wr5WjP2F+Hm9@BNpFbNC-v$ES9z7qN^eMR=-r60-t_WiZd~3W zS3k=sFOy<>$t3sOdYg+r<@HTddi#`Ohiy)cy{x#==5*QX9Q1CsCcPXZ6s*El>TYm) z9?WiSa5=-!Wmrv3W9`^+kqnpDlsYQI#zlsPhembCg4V$ z_>cb%nb511YH-_Y7*phHd(V1Is~8gMYM|EQzhMZJyUOmcg%w+E6{QU|?qctnP}WF( zLJ51aQQ}A0@u*q|ax3Z0#e&TG^yXrLZK7XsZ%A9ef3R_P3mBq?{VaCboRAj$IIOS{ zje6SdayEvj8-SuBi`{B#sk<~kvT(Ghe}5fm&m}S(5n_r&?L|Z^5{bmz@Rf=M;vs&c zxXlT+$d3ZQFo|RYCq!KN+Xthk8f4mTkL&y>+HnwRH=|=S2}Z|ebezpPCS1!?cVp-6 z|K!&~e`OOg$B!8;&vm&=-S%>|-BE)DQfJpWt?H?z^`_eTB!^WGMCUeIq|+(rC`2L| zC4J0!=9+eG0rklxT_T5*WmcYJD!JZ;~b z+`zwwKlRipn7db^d1u!gk9 zL4@N-C`338B0QbfjUPw;G49sa)v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jPMVd{M7tQF#i&M{w3(4r2G8;AH0D2hX4Qo literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@exception.c b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@exception.c new file mode 100644 index 00000000..caa76659 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@exception.c @@ -0,0 +1,36 @@ +/* See LICENSE file for copyright and license details. */ +#include "kern/exception.h" +#include "kern/proc.h" + +#define ILLEGAL_INSTRUCTION 0x2 + +#define MRET 0x30200073 +#define SRET 0x10200073 +#define URET 0x00200073 + +static void HandleTrapReturn(Proc *p, Word mcause, Word mtval) +{ + p->regs.ecause = mcause; + p->regs.eval = mtval; + p->regs.epc = p->regs.pc; + p->regs.esp = p->regs.sp; + p->regs.pc = p->regs.tpc; + p->regs.sp = p->regs.tsp; +} + +static void HandleDelegate(Proc *p) +{ + p->regs.pc = p->regs.epc; + p->regs.sp = p->regs.esp; + p->regs.ecause = 0; + p->regs.eval = 0; + p->regs.epc = 0; + p->regs.esp = 0; +} + +Proc *ExceptionHandler(Proc *p, Word mcause, Word mtval) +{ + if (mcause == ILLEGAL_INSTRUCTION && (mtval == MRET || mtval == SRET || mtval == URET)) + return HandleTrapReturn(p); + return HandleDelegate(p, mcause, mtval); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@exception.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@exception.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..2c472b5fd6ae3841f03691d6f91779448f5afc77 GIT binary patch literal 2407 zcmb7ETWs586#joVTU~mIV_M=~Xww^Nt2j>65=OOFZD|D+rJK4=XyTH&&fmnXW2d&0 zu1tV5HVI98LgOMa1RDbhQG`I+3p}ipn*^m2FB2L(A@Ky#Kp^haoZn5-TQqf1^y&Dw zzwey$onv>Q^#h5KHH46qG*U!L%5zejWF@O-PO=s)$ubpbj+nYcPADX8tA-v@kXJI& zwq&Z7l9i@aeIttYiWz-QHx_h}Xft9$QIH7#vEsU_u4tJ!v5=UOO(ofHW~04oN>*Y| zsETFM(`mI|OGkSlR8mHqX#FV?m-R&?9*Q6_fyAlZ!nR>()<(JWB$WwiaU|vvA@?AO zL<1Sqv$==1^b|5~#Q<@^Fy~Y~A;wjcD7IlP_V2DHZ5p$1(~^=z(+syPRKCSI*T3zq zNx5oW>tmK3S9Lp-MC$|5U%%R&fX*lHUOJijbhnR1rYq%kZ2iyR-FtQts*J&utxWnB`-7Jy zsp>?E#mS7E(d<~kV%jOg>@NA{`?7y8gxs#666cr`e)8M*S56;>?Fn>^=D!XP$a-8O zX2-@ceLNU=*f8UPlp<#=lE1LCvetonSbelr@XIx*n?}LH3J^7 zu!#i>HAOwR(wRPMT>bH-U(UGRcgVV-=VUwk`m8j%t;0hFsB8%r;vyB8=lMITvA_#} zPVm^}*X}*P`du+Laq0Uv={zR@F(`mY1K$9#bMn>H{QS@D3&rSZWm|G@$O}9l?}M~{ z-cOVNJzVhjVNtrfzA%M~{0x~&zOu0z*YdT1&hRHU4j(W3?dzgk zcyEDO@R6zFtLmz89bX6N{2{-P`TnE9w~tPaPJuSt3fl~yr~thVginOSk#IPCPY*)4 zj4KluiXr5{JB^z!H!lrhM_hUEv&Vlrf8)pw0eTGr-J1d|$ASQ0Uf@*oSrCZ6oBg5Y z%Ejj%+95!%L7-<-pp+{G0l>V#@#Z85JoCYO-<#VVPWDx%kyav~f literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@head.S b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@head.S new file mode 100644 index 00000000..79995334 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@head.S @@ -0,0 +1,85 @@ +// See LICENSE file for copyright and license details. +#include "kern/macro.inc" +#include "kern/offsets.h" +#include "kern/csr.h" + +.extern init_kernel +.extern sched +.extern trap_entry +.extern trap_exit +.extern trap_resume + +.section .text.init,"ax",@progbits + +.globl _start +.type _start, @function +_start: +head_entry: + // Load global pointer. + ld_gp + ld_sp t1 + + // If hartid != MIN_HARTID, then jump to wait. + csrr t0,mhartid + li t1,S3K_MIN_HART + li t2,S3K_MAX_HART + bltu t0,t1,__hang + bgtu t0,t2,__hang + + // Set some CSRs to 0. + csrw mstatus,0 + csrw medeleg,0 + csrw mideleg,0 + csrw mscratch,0 + csrw mie,0 + csrw satp,0 + + // Set trap entry. + la t0,__hang + csrw mtvec,t0 + + csrr t0,mhartid + li t1,S3K_MIN_HART + bne t0,t1,wait + +zero_bss: + // Initialize the bss section. + la t0,_bss + la t1,_end + j 2f +1: sb zero,(t0) + addi t0,t0,1 +2: bne t0,t1,1b + + call cap_init + call sched_init + call proc_init + + la t0,kernel_ready + li t1,1 + sw t1,(t0) + +wait: // Wait for initilization to finish. + la t0,kernel_ready + lw t0,(t0) + beqz t0,wait + +head_exit: + // Enable timer interrupts. + li t0,MIE_MTIE + csrw mie,t0 + + // Start user processes. + la t0,trap_handler + csrw mtvec,t0 + csrw mscratch,0 + tail sched + +__hang: + csrw mie,0 + wfi + j __hang + +.section .data +kernel_ready: + .word 0 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@head.S.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@head.S.blob new file mode 100644 index 0000000000000000000000000000000000000000..d8bd00d9aab15dcc453b500d54f1e73c9938f35f GIT binary patch literal 784 zcmb7CzfZzI82td_SVx!~O)y?BQDm!eXf#X?I=GQ?z0#xCJG?6pTy$`9b#`;m$;8F~ zf!HS45gbt^ za7aDhK87_cy9riIlRj=Skwx_y>WN6mfk2c8s7(kU^EQ@`WP14xnW7|-YUnI-=qlMUpf+A{E~jK*Ww9)^_1lAtv5{?uFuqRQ zQJ!)c1ezu~ZAt%Ko)%-TlD66USIZLac;?%5NvZh1HMw;E2wBZDJ+sMN)zakl>7x05 z`1ouN^QYii?)rXV@^IIixI+RTbr9iNb1%resEJV~$MFfsR-cV2wiDFnKti39ioQTyKUttcW zi%tz8;OO7N{&fjMH1e?oPUr~~R76}ZkDK46o z!EPFYFX=xe3^1iUX$$20$R+&tQqzw4b+akZ9IM*-&5lgAfG>JLc1Bc6S=cV#*0@UM`xdAH`*Bs-A~ zB$MKKz~JxL-O~X~mecrjOv^|6r7Xv@CnO$e*3*O(lXKC2e9LE5L6l=zQQ(vXz#KgY zm=s`+)dTCQDx*TWcBZlbm}1?)evk%?3e?10aZy!GVRa`2F!QRGk(3l8NSes&s(mc60CJLBvmOFRdM=u5+p@VH?%4~45UE}31vB-Wg`9dJuh=g3P$?Fec@wqu$w*j7!( zwzXr6qqc2}a@1E?b9$<54V>nWYs~teEAg(pDhYn8+p(o?$0lV1rF%!m#t-|0$pCP< zdVu|Dw?>D1$gQ^!LMwfk6 zT0KV2s9=Qre45kzd;m1Y+Di_`aanKtHGZS@*OwOx(JG_E^mpDIT>s{S&rLOLPTYX| z$AJ0xJ!|JKO)ny(YX-lm0RQ3(fTs7A5bm{ZinX_RT0%JQ<>QB^?%ezvm6nvQgn8w) zgi_#iY0Atu*PMBgRCWQpjc}`-T-J1x-3u%|4L3H zNjGMjUU@6Frz12`9g?6Z%7?>rN0N`O-@ox?&D<_(*M2Jq=n+6AY8aG1KwG^ToTc;XoQ#MAbF zh~eJ8=OcZE&*b=c00(u4-BAbO2JWe{l{yFqaCnA1BPR*(A@Ar(!u(|Y+`shj7tb_i z&^lx#1{-o0Cy!w6KI-b3U0Nk>*YM+_Toyl*-~aK$O8D*H3)Zy4NQ$Jh`1OZoWa3ICkl4U0ZDbqv%Kz*UC076d literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@proc.c b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@proc.c new file mode 100644 index 00000000..a6b25f89 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@proc.c @@ -0,0 +1,125 @@ +/* See LICENSE file for copyright and license details. */ +#include "drivers/time.h" +#include "kern/cap.h" +#include "kern/csr.h" +#include "kern/kassert.h" +#include "kern/proc.h" + +extern Word _payload[]; +static Proc procs[S3K_PROC_CNT]; + +void ProcInit(void) +{ + for (uint64_t i = 0; i < S3K_PROC_CNT; i++) { + procs[i].pid = i; + procs[i].state = PSF_SUSPENDED; + } + procs[0].state = 0; + procs[0].regs.pc = (reg_t)_payload; + // KASSERT(cap_pmp_load(ctable_get(0, 0), 0) == SUCCESS); +} + +Proc *ProcGet(pid_t pid) +{ + KASSERT(pid < S3K_PROC_CNT); + KASSERT(procs[pid].pid == pid); + return &procs[pid]; +} + +ProcState ProcGetState(Proc *proc) +{ + Proc state = proc->state; + if ((state == PSF_BLOCKED) && time_get() >= proc->timeout) { + // TODO: Unblock state. + return 0; + } + return state; +} + +bool ProcAcquire(Proc *proc) +{ + ProcState expected = ProcGetState(proc); + proc_state_t desired = PSF_BUSY; + + if (expected & (PSF_BUSY | PSF_SUSPENDED)) + return false; + + if (time_get() < proc->timeout) + return false; +#ifdef SMP + return __atomic_compare_exchange(&proc->state, &expected, &desired, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); +#else + proc->state = desired; + return true; +#endif +} + +void ProcRelease(Proc *proc) +{ + KASSERT(proc->state & PSF_BUSY); +#ifdef SMP + __atomic_fetch_xor(&proc->state, PSF_BUSY, __ATOMIC_RELEASE); +#else + proc->state &= ~PSF_BUSY; +#endif +} + +void ProcSuspend(Proc *proc) +{ + ProcState prev = __atomic_fetch_or(&proc->state, PSF_SUSPENDED, __ATOMIC_RELAXED); + if (prev & PSF_BLOCKED) { + proc->state = PSF_SUSPENDED; + proc->regs.t0 = ERR_SUSPENDED; + } +} + +void ProcResume(Proc *proc) +{ + if (proc->state == PSF_SUSPENDED) + proc->timeout = 0; + __atomic_fetch_and(&proc->state, ~PSF_SUSPENDED, __ATOMIC_RELAXED); +} + +void ProcIpcWait(Proc *proc, Word chan) +{ + KASSERT(proc->state == PSF_BUSY); + proc->state = PSF_BLOCKED | ((uint64_t)chan << 48) | PSF_BUSY; +} + +bool ProcIpcAcquire(Proc *proc, chan_t chan) +{ + ProcState expected = PSF_BLOCKED | ((uint64_t)chan << 48); + ProcState desired = PSF_BUSY; + + if (proc->state != expected) + return false; + if (time_get() >= proc->timeout) + return false; +#ifdef SMP + return __atomic_compare_exchange_n(&proc->state, &expected, desired, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); +#else + proc->state = desired; + return true; +#endif +} + +bool ProcIsSuspended(proc_t *proc) +{ + return proc->state == PSF_SUSPENDED; +} + +bool proc_pmp_avail(proc_t *proc, pmp_slot_t slot) +{ + return proc->pmp.cfg[slot] == 0; +} + +void proc_pmp_load(proc_t *proc, pmp_slot_t slot, pmp_slot_t rwx, napot_t addr) +{ + proc->pmp.cfg[slot] = (uint8_t)(rwx | 0x18); + proc->pmp.addr[slot] = addr; +} + +void proc_pmp_unload(proc_t *proc, pmp_slot_t slot) +{ + proc->pmp.cfg[slot] = 0; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@proc.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@proc.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..589f8574e5b0dc2d40077bda38c405650b4b9d0b GIT binary patch literal 3943 zcmb7HZEO?g9eFmRCUgUWuB<7Z}#ExuVk_JN{1g8NJsuWT}h$2Lt%iUx9ob#P~ zcTPxHhlY}B>(*-3R26mfLz!Bs>Ncr-X+KO81*P2!W78zGtsmGrP1RIB7Nk-^ZvW@( z_$3L$SkeC;-~C^H|KI=R;x4qBln>rOh++7&mL+^znB^rh#~V-1^2UO}8@kBP5?$qU zx+X?Ngf>@`RZ+=H#3<;_3Wh;+Gn#&g_Ijrcyp}V0T{gryenwUcr&wPkugp#Jqk>$U;%Z{otn6wh3{#R- zTDaB0*q48LL>Rj-L?K7j{VyJ@H4s!KEvtl2NF*ub6*FNjRh9=%-g8yG`4+ zM1_r!=(?uU0GEFPC~Gi)mZ9n|nYF3U=5$~!NlhMy@DkSpHF8~^t3s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aqqQh_+?W5FuNLe z`Qtd*m;`BEcys06M~*joPQdEpf`UrdyUk2!?_RnNwY-VgpuJ})Jq|9(nQqK?^Mh`D ztnpaDi>G_1VINqpe*Ru&vgvQVdI!a&04frLf`X)U+0_s{*bGd~6|$aNTDGa_fl6VwmIhdn+|s~20JzB811`}C>E zagvhZO{N>`?R1hdkhj+^xotSoIO2ygtrffYezMzxcDiwD&uQfMvk=1NceOLvgcci_*L zzb(+fg+;y2i~=Ko9FP=JZfNi|a9-TxZ36op!5zI0yf3gX=(c5?Ip8?}c^x`=XnF}B zZam!L#YcTdIX51Qjm4MnL|_6msf;rxJtzHM{G9JOcuG73&K7r$PygU9{x6NS_NjC2 zbPdFDeP8`(9Qytimeout = (slot + si.len) * S3K_SLOT_LEN; + return proc; +} + +Proc *SchedNext(void) +{ + // Hart ID + Word hart = csrr(mhartid); + // Process to schedule + Proc *proc; + + timeout_set(hart, (uint64_t)-1); + + do { + uintptr_t slot = time_get() / S3K_SLOT_LEN; + while (time_get() < slot * S3K_SLOT_LEN) + ; + // Try schedule process + proc = sched_fetch(hart, slot); + } while (!proc); + timeout_set(hart, proc->timeout); + return proc; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@sched.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@sched.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..bac931fa36b5fa74b6416d2aefc13f7d16b7abe5 GIT binary patch literal 4001 zcmb7HZ)h9m8GrA5Ys{f&LbmM280*DbjI8N&w(AJj$e9un2RmgoX||4qOgr7Zk}f{o z$?x6SaW_^d``ZuuveAt$8?5w0+qD~GkPJ3hN+=y=3mK)1madFKzwOI57){q$d!AP( zS&6+_G3NC0>iPS7f6wndWy#KamrmUzgy?mz!SuSZu3KzV_a9o<{cT_Oxv8%+?&`i- zXI9=MpVYl(pmWMwoXj zqD6^_*r*fDBVOfFWEAz2_xf#I+w%Cj?bbBQ=FAK{zP+@!iYE6i!I!>XXO82Ea!6{g z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0=3es={2Zq8&bZn=z$8x>JUX@(RD YH6cregs.t0; + if (syscall_nr < ARRAY_SIZE(handlers)) + return handlers[syscall_nr](p); + return HandleInvArg(p); +} + +static Bool ValidCapIdx(Word i) +{ + return i < S3K_CAP_CNT; +} + +static Bool ValidPmpSlot(Word slot) +{ + return slot < S3K_PMP_CNT; +} + +static Bool ValidPid(Word pid) +{ + return pid < S3K_PROC_CNT; +} + +static Bool ValidReg(Word reg) +{ + return reg < REGISTER_COUNT; +} + +Proc *HandleInvArg(Proc *p) +{ + p->regs.t0 = ERR_INVARG; + return p; +} + +Proc *HandleGetPid(Proc *p) +{ + p->regs.t0 = SUCCESS; + p->regs.a0 = p->pid; + return p; +} + +Proc *HandleRegRead(Proc *p) +{ + if (!ValidReg(p->regs.a0)) + return HandleInvArg(p); + + Word reg = p->regs.a0; + Word *regs = (Word *)&p->regs; + p->regs.a0 = regs[reg]; + p->regs.t0 = SUCCESS; + return p; +} + +Proc *HandleRegWrite(Proc *p) +{ + if (!ValidReg(p->regs.a0)) + return HandleInvArg(p); + + Word reg = p->regs.a0; + Word value = p->regs.a1; + Word *regs = (Word *)&p->regs; + regs[reg] = value; + p->regs.t0 = SUCCESS; + return p; +} + +Proc *HandleSync(Proc *p) +{ + return NULL; +} + +Proc *HandleCapRead(Proc *p) +{ + if (!ValidCapIdx(p->regs.a0)) + return HandleInvArg(p); + + Word i = CapIdx(p->pid, p->regs.a0); + Cap *buf = (Cap *)&p->regs.a0; + p->regs.t0 = CapRead(i, buf); + return p; +} + +Proc *HandleCapMove(Proc *p) +{ + if (!ValidCapIdx(p->regs.a0) || !ValidCapIdx(p->regs.a0)) + return HandleInvArg(p); + Word src = CapIdx(p->pid, p->regs.a0); + Word dst = CapIdx(p->pid, p->regs.a1); + p->regs.t0 = CapMove(src, dst); + return p; +} + +Proc *HandleCapDelete(Proc *p) +{ + if (!ValidCapIdx(p->regs.a0)) + return HandleInvArg(p); + Word i = CapIdx(p->pid, p->regs.a0); + current->regs.t0 = CapDelete(i); + return p; +} + +Proc *HandleCapDerive(Proc *p) +{ + if (!ValidCapIdx(p->regs.a0) || !ValidCapIdx(p->regs.a0)) + return HandleInvArg(p); + Word src = CapIdx(p->pid, p->regs.a0); + Word dst = CapIdx(p->pid, p->regs.a1); + Cap cap = (Cap){.raw = p->regs.a2}; + current->regs.t0 = CapDerive(src, dst, cap); +} + +Proc *HandleCapRevoke(Proc *p) +{ + if (!ValidCapIdx(p->regs.a0)) + return HandleInvArg(p); + Word i = CapIdx(p->pid, p->regs.a0); + current->regs.t0 = CapRevoke(i); + return p; +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@syscall.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@syscall.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..424a3b74cbd49d87560cce92fad33e4b2704b2bc GIT binary patch literal 5585 zcmb7Hdu&tJ89&GIsF&P0&W!`cr0z{fGbi{FQe!gDK_&?aP#}zSJPI^%?2BJFwz>D( zfuP2t0rDv6NcNJ}N_|XaYSpTHbVJ%&QHI#6LaRw#rHO4)Cl#$z|L7#Pu3Krm@0@Ep zzKJ_LD>~=9-}%mWe&6$)w4ue9zQ6SygftpwI5EmQ!~U2v$fups12Ly`QgTM(0U;IS zC1;EmgI$M^g?Vi0rw85M_jsJ%JJ<(VS4hbVs6m+eW&(VK6*5gLy{bf#AOKI;uiPqw^tsp zGTZ@wl8Bqm^}bW)LE!FiB+fgBg8VUmN|1--lSy9sf6kOe<nz-PK{n$X<~^Aa^`Ay@l)HTyE!E&Mu=HXIWo$VL*%oN zK;;`Y1jQ$%Xh9K|=*nuiOJQ5J(jHa8E<>lgi#ToPN_|(BB}#LYDMvJ4F#2+Y^TlE) zM>y9T*s^4EjR)0de}8L-=GuDc>Vbq9K7)P&qsq3AUous|~o_)Na+_cJzQo0fNbt-8S^t`>({EPv`dUh0B*~+wPAC z1%5|7y;TfZ6;`qpnaw8bVLZ(m>_J-!N^q6AssrOHRMm@g>ka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Fa~@VIZJrq}%sHmTO^7CUjnU&r2j?#z5=g=(#_xv>-0 zhTG4be%0czs@6!OgSE$>xpFc5`rIE&<+fj)+dXU#^Gi93sdfGM(3hir%10aITJtefte GhVj3~9+Fr9 literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@trap.S b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@trap.S new file mode 100644 index 00000000..8b980605 --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@trap.S @@ -0,0 +1,136 @@ +// See LICENSE file for copyright and license details. +#include "kern/macro.inc" +#include "kern/offsets.h" +#include "kern/csr.h" + +.globl TrapHandler +.globl TrapResume +.globl TrapReturn + +.type TrapHandler,@function +.type TrapResume, @function +.type TrapReturn, @function + +.section .text.trap +.balign 16 +trap_handler: + // Save user tp to scratch, load PCB pointer + csrrw tp,mscratch,tp + + sd ra,PROC_RA(tp) + sd sp,PROC_SP(tp) + sd gp,PROC_GP(tp) + //sd tp,PROC_TP(tp) + sd t0,PROC_T0(tp) + sd t1,PROC_T1(tp) + sd t2,PROC_T2(tp) + sd s0,PROC_S0(tp) + sd s1,PROC_S1(tp) + sd a0,PROC_A0(tp) + sd a1,PROC_A1(tp) + sd a2,PROC_A2(tp) + sd a3,PROC_A3(tp) + sd a4,PROC_A4(tp) + sd a5,PROC_A5(tp) + sd a6,PROC_A6(tp) + sd a7,PROC_A7(tp) + sd s2,PROC_S2(tp) + sd s3,PROC_S3(tp) + sd s4,PROC_S4(tp) + sd s5,PROC_S5(tp) + sd s6,PROC_S6(tp) + sd s7,PROC_S7(tp) + sd s8,PROC_S8(tp) + sd s9,PROC_S9(tp) + sd s10,PROC_S10(tp) + sd s11,PROC_S11(tp) + sd t3,PROC_T3(tp) + sd t4,PROC_T4(tp) + sd t5,PROC_T5(tp) + sd t6,PROC_T6(tp) + + // Save the + csrr t1,mepc + csrr t2,mscratch + sd t1,PROC_PC(tp) + sd t2,PROC_TP(tp) + + + // Load the global and stack pointer of the kernel. + ld_gp + ld_sp t0 + + la ra, trap_return + + // call the trap handler + csrr t0,mcause + li t1,8 + beq t0,t1,syscall_handler + csrr a0,mcause + csrr a1,mtval + bltz t0,interrupt_handler + j exception_handler + +trap_resume: + mv tp,a0 + ld s0,PROC_PMPADDR0(tp) + ld s1,PROC_PMPADDR1(tp) + ld s2,PROC_PMPADDR2(tp) + ld s3,PROC_PMPADDR3(tp) + ld s4,PROC_PMPADDR4(tp) + ld s5,PROC_PMPADDR5(tp) + ld s6,PROC_PMPADDR6(tp) + ld s7,PROC_PMPADDR7(tp) + ld s8,PROC_PMPCFG0(tp) + csrw pmpaddr0,s0 + csrw pmpaddr1,s1 + csrw pmpaddr2,s2 + csrw pmpaddr3,s3 + csrw pmpaddr4,s4 + csrw pmpaddr5,s5 + csrw pmpaddr6,s6 + csrw pmpaddr7,s7 + csrw pmpcfg0,s8 + +trap_return: + ld t0,PROC_PC(tp) + ld t1,PROC_TP(tp) + csrw mepc,t0 + csrw mscratch,t1 + + ld ra,PROC_RA(tp) + ld sp,PROC_SP(tp) + ld gp,PROC_GP(tp) + //ld tp,PROC_TP(tp) + ld t0,PROC_T0(tp) + ld t1,PROC_T1(tp) + ld t2,PROC_T2(tp) + ld s0,PROC_S0(tp) + ld s1,PROC_S1(tp) + ld a0,PROC_A0(tp) + ld a1,PROC_A1(tp) + ld a2,PROC_A2(tp) + ld a3,PROC_A3(tp) + ld a4,PROC_A4(tp) + ld a5,PROC_A5(tp) + ld a6,PROC_A6(tp) + ld a7,PROC_A7(tp) + ld s2,PROC_S2(tp) + ld s3,PROC_S3(tp) + ld s4,PROC_S4(tp) + ld s5,PROC_S5(tp) + ld s6,PROC_S6(tp) + ld s7,PROC_S7(tp) + ld s8,PROC_S8(tp) + ld s9,PROC_S9(tp) + ld s10,PROC_S10(tp) + ld s11,PROC_S11(tp) + ld t3,PROC_T3(tp) + ld t4,PROC_T4(tp) + ld t5,PROC_T5(tp) + ld t6,PROC_T6(tp) + + // Save PCB pointer. + csrrw tp,mscratch,tp + + mret diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@trap.S.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@kern@trap.S.blob new file mode 100644 index 0000000000000000000000000000000000000000..c2bbc0f6da659ded2605f43ca08140472ccd0e89 GIT binary patch literal 2034 zcma)*e@q)?7{{-jE=4h|a`0BN;M-Zm2PeCT^l=#IVKL`n-T!-!PLl&E@TV zKF{}kpQm>QCKB=1TxJ-CbINXkb6Q=TO$c!6CKsoMR8CcR&Lt=w&aYU##%3molf8aU z5mi3GwTYgERYf`5;cr_TK@x(9}U4VJlAk zeD=yzKJu7t6GpVRKHk#sU_+Ms?x~JF};I zU#5%-s6f^Vt;9I;(NzA2x0sJ9VxO_$n3!^U$};vaWn@4GRy)B-GX9aw!^a-=K0p~pFe2-L9%9t7LvMvP zO*F+Cng(bf^ZvADY+yxdT1hO^>OqfnKJbxh?ZnLoeMd%KqKtgVM;3qpF{Xxg{n7L1 z)6rN%(+tf8$bOrS_}<^yXrWjWG?Bf}=`UKdw(05rdNr)ZOc`X7d?@h7r3<;8m9f>@ zT*yV{0S_@8Pqlm<9)FxRvLFjtJG2v{>%izL<4CTF%1DDWWC94pIKXwynw~kAMi~WA zfGh|>VjR?cdH;`FPXcA6LMk#F*og7^mJ=(>mj8W~GV&k~nF7juhGFE@mFbB;P{sz> zfNUS^BgWhphleL`UC)R$G>yJI228ArR1`pgOMUZ;#gC`7g!b`#^<+Ptd4Jnt&XD1stnAqWv8Wk<~`Qqk-ulwkk^ tvM%T%#%(+E*b|>sQtymb2RdXfa1rCup~Ua_^GP#QMhTQ43qu&M{{nkX3h)2` literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@mcslock.c b/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@mcslock.c new file mode 100644 index 00000000..e686297c --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@mcslock.c @@ -0,0 +1,53 @@ +// TODO: Replace with proper MCS Lock +#include "kassert.h" +#include "smp/mcslock.h" + +#include + +static void _release(qnode_t *const node) +{ + qnode_t *expected, *next, *prev; + prev = __atomic_exchange_n(&node->prev, NULL, __ATOMIC_RELAXED); + do { + expected = node; + next = node->next; + } while (!__atomic_compare_exchange_n(&next->prev, &expected, prev, false, __ATOMIC_RELEASE, __ATOMIC_RELAXED)); + if (prev) + prev->next = next; +} + +static bool _acquire(mcslock_t *lock, qnode_t *const node, bool preemptive) +{ + node->next = &lock->tail; + node->prev = __atomic_exchange_n(&lock->tail.prev, node, __ATOMIC_ACQUIRE); + if (node->prev == NULL) + return true; + node->prev->next = node; + while (__atomic_load_n(&node->prev, __ATOMIC_ACQUIRE)) { + if (preemptive && kernel_preempt()) { + _release(node); + return false; + } + } + return true; +} + +void mcslock_init(mcslock_t *lock) +{ + lock->tail.prev = lock->tail.next = NULL; +} + +void mcslock_acquire(mcslock_t *lock, qnode_t *node) +{ + _acquire(lock, node, false); +} + +bool mcslock_try_acquire(mcslock_t *lock, qnode_t *node) +{ + return _acquire(lock, node, true); +} + +void mcslock_release(mcslock_t *lock, qnode_t *node) +{ + _release(node); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@mcslock.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@mcslock.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..f88d00fbe9dd595e3de010ee30d333db97cdfc7f GIT binary patch literal 922 zcmdO5_;;bn<{Se9gMLPSZmNDpVzz!tYMFkqakhSOWwCy7QL=tPXC(l0G8($C3E($C2$%hfeB0kgq2 z=^L8p8R(hmXXYj6l%}NW7nh`@q^9X*F#KCooqLpceev-So$OSTJy<#;V}4nFW{Ltdh~kS7=Xey#A|V+mD3wc?V*lFVeV z`{QvrB{@H@xI_WuJBUXMic(W^3raG}fW8$I6JQjU5C%F>m_ZT6hG$Pt=0=8~buWb+UCBFiyx#c|a+F!Jr;y8~1q&z8cnztA=oSp_p!5Lc7~qqv&5o&%$* Jmuip$BLJq^3NZix literal 0 HcmV?d00001 diff --git a/kernel/src/smp/semaphore.c b/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@semaphore.c similarity index 100% rename from kernel/src/smp/semaphore.c rename to .ccls-cache/@home@hak@dev@s3k/sys@src@smp@semaphore.c diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@semaphore.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@semaphore.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..54c458d2a92d3992049c64a34045742d91b6a624 GIT binary patch literal 592 zcmdO5_;;bn<{Se9gMLPSZmNDpVzz!tYMFkqakhSOWwCy7QL=t2uiagJ@lYTSlqR%Tvi37V5iGLy4Y zONv1blVN1#VpU^eWM$w+HjIJ!zk&|a>9dt(Q$WE61B_CBQh5%H{}XpqmdSlDTLu#c c(Tu_w!W}?4bIH(SviXO6QRD>E1lt@K0eGLKr~m)} literal 0 HcmV?d00001 diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@taslock.c b/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@taslock.c new file mode 100644 index 00000000..3ec5383f --- /dev/null +++ b/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@taslock.c @@ -0,0 +1,25 @@ +#include "smp/taslock.h" + +#include + +void taslock_init(taslock_t *l) +{ + l->lock = 0; +} + +bool taslock_acquire(taslock_t *l) +{ + while (!taslock_try_acquire(l)) + return false; + return true; +} + +bool taslock_try_acquire(taslock_t *l) +{ + return __atomic_fetch_or(&l->lock, 1, __ATOMIC_ACQUIRE); +} + +void taslock_release(taslock_t *l) +{ + __atomic_store_n(&l->lock, 0, __ATOMIC_RELEASE); +} diff --git a/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@taslock.c.blob b/.ccls-cache/@home@hak@dev@s3k/sys@src@smp@taslock.c.blob new file mode 100644 index 0000000000000000000000000000000000000000..ea1efebd349474e5086be251bf770c49bc8f35a4 GIT binary patch literal 652 zcmdO5_;;bn<{Se9gMLPSZmNDpVzz!tYMFkqakhSOWwCy7QL=ta<*PF z19NgtVqQAY%5}^0i?TEG(sffZi&B$I@{1~MF>PXC)GsYA($C3E($C2$%hfeB0kgq2 z=^L8p8R(hmXXYj6l%}NW7nh_Y<>%+tsG4TE-pDnQ7%ypCPq;P2_|4DF);8jg2?||`a(@6o$uA+ zoq&#k>n|y)j89B1ECu=%ZUzsJ8lwQ0fB_Su0D~}!87IYMSFSu!Xpd?JrhYj_PA*QM z8#o#GQ1r{pay_JcH0LOa7c%oQOW<~MaY-<;aIq*cF|shQBkN^g{hzp_vP|xK*)ouK zV1QA`PbklU@xOu&)9JI7Wm90{AevF!PCO1MSGDr>$@ImC7NW@U2=T}O<@%odPqsRo jkc=Y7E5IuOl$-c$bym3Gbt7asCQb%U4hLYs2mna{K#a2V literal 0 HcmV?d00001 diff --git a/.ccls-root b/.ccls-root new file mode 100644 index 00000000..e69de29b diff --git a/.clang-format b/.clang-format index 7778d48e..a0d74593 100644 --- a/.clang-format +++ b/.clang-format @@ -4,7 +4,7 @@ UseTab: Always TabWidth: 8 IndentWidth: 8 ContinuationIndentWidth: 4 -ColumnLimit: 80 +ColumnLimit: 120 SortIncludes: true MaxEmptyLinesToKeep: 1 ReflowComments: false diff --git a/Makefile b/Makefile index e869980c..4f1db22c 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,5 @@ -.POSIX: -.SECONDARY: - -PROJECTS:=projects/hello \ - projects/trapped \ - projects/ping-pong \ - projects/demonstrator - -all: ${PROJECTS} - -${PROJECTS}: common - -common ${PROJECTS}: - @${MAKE} -C $@ all +all: + $(MAKE) -C projects/hello all clean: - @for i in common ${PROJECTS}; do \ - ${MAKE} -C $$i clean; \ - done - -format: - clang-format -i $$(find * -type f -name '*.[hc]') - -.PHONY: all clean format common ${PROJECTS} + $(MAKE) -C projects/hello clean diff --git a/common/inc/altc/altio.h b/common/inc/altc/altio.h index 64a4d3d7..e4a668af 100644 --- a/common/inc/altc/altio.h +++ b/common/inc/altc/altio.h @@ -9,5 +9,4 @@ int alt_puts(const char *str); int alt_gets(char *str); int alt_printf(const char *fmt, ...); int alt_snprintf(char *restrict s, size_t n, const char *restrict fmt, ...); -int alt_vsnprintf(char *restrict s, size_t n, const char *restrict fmt, - va_list ap); +int alt_vsnprintf(char *restrict s, size_t n, const char *restrict fmt, va_list ap); diff --git a/common/inc/plat/qemu_virt.h b/common/inc/plat/qemu_virt.h index ecf38508..1857729c 100644 --- a/common/inc/plat/qemu_virt.h +++ b/common/inc/plat/qemu_virt.h @@ -24,14 +24,3 @@ /// Stack size of 1024 KiB #define S3K_LOG_STACK_SIZE 10 - -#define INIT_CAPS \ - { \ - [0] = cap_mk_pmp(0x20005fff, MEM_RWX), \ - [1] = cap_mk_memory(0x80020000, 0x88000000, MEM_RWX), \ - [2] = cap_mk_memory(0x10000000, 0x10001000, MEM_RW), \ - [3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \ - [4] = cap_mk_time(0, 0, S3K_SLOT_CNT), \ - [8] = cap_mk_monitor(0, S3K_PROC_CNT), \ - [9] = cap_mk_channel(0, S3K_CHAN_CNT), \ - } diff --git a/common/inc/plat/qemu_virt4.h b/common/inc/plat/qemu_virt4.h index c2e3e510..e934506b 100644 --- a/common/inc/plat/qemu_virt4.h +++ b/common/inc/plat/qemu_virt4.h @@ -25,16 +25,11 @@ /// Stack size of 1024 KiB #define S3K_LOG_STACK_SIZE 10 -#define INIT_CAPS \ - { \ - [0] = cap_mk_pmp(0x20005fff, MEM_RWX), \ - [1] = cap_mk_memory(0x80020000, 0x88000000, MEM_RWX), \ - [2] = cap_mk_memory(0x10000000, 0x10001000, MEM_RW), \ - [3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \ - [4] = cap_mk_time(0, 0, S3K_SLOT_CNT), \ - [5] = cap_mk_time(1, 0, S3K_SLOT_CNT), \ - [6] = cap_mk_time(2, 0, S3K_SLOT_CNT), \ - [7] = cap_mk_time(3, 0, S3K_SLOT_CNT), \ - [8] = cap_mk_monitor(0, S3K_PROC_CNT), \ - [9] = cap_mk_channel(0, S3K_CHAN_CNT), \ +#define INIT_CAPS \ + { \ + [0] = cap_mk_pmp(0x20005fff, MEM_RWX), [1] = cap_mk_memory(0x80020000, 0x88000000, MEM_RWX), \ + [2] = cap_mk_memory(0x10000000, 0x10001000, MEM_RW), [3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \ + [4] = cap_mk_time(0, 0, S3K_SLOT_CNT), [5] = cap_mk_time(1, 0, S3K_SLOT_CNT), \ + [6] = cap_mk_time(2, 0, S3K_SLOT_CNT), [7] = cap_mk_time(3, 0, S3K_SLOT_CNT), \ + [8] = cap_mk_monitor(0, S3K_PROC_CNT), [9] = cap_mk_channel(0, S3K_CHAN_CNT), \ } diff --git a/common/inc/plat/sifive_unleashed.h b/common/inc/plat/sifive_unleashed.h index 38978405..115e93fe 100644 --- a/common/inc/plat/sifive_unleashed.h +++ b/common/inc/plat/sifive_unleashed.h @@ -24,13 +24,10 @@ #define UART_SIFIVE -#define INIT_CAPS \ - { \ - [0] = cap_mk_pmp(0x20005fff, MEM_RWX), \ - [1] = cap_mk_memory(0x80020000, 0x88000000, MEM_RWX), \ - [2] = cap_mk_memory(0x10010000, 0x10011000, MEM_RW), \ - [3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \ - [4] = cap_mk_time(1, 0, S3K_SLOT_CNT), \ - [8] = cap_mk_monitor(0, S3K_PROC_CNT), \ - [9] = cap_mk_channel(0, S3K_CHAN_CNT), \ +#define INIT_CAPS \ + { \ + [0] = cap_mk_pmp(0x20005fff, MEM_RWX), [1] = cap_mk_memory(0x80020000, 0x88000000, MEM_RWX), \ + [2] = cap_mk_memory(0x10010000, 0x10011000, MEM_RW), [3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \ + [4] = cap_mk_time(1, 0, S3K_SLOT_CNT), [8] = cap_mk_monitor(0, S3K_PROC_CNT), \ + [9] = cap_mk_channel(0, S3K_CHAN_CNT), \ } diff --git a/common/inc/plat/sifive_unleashed4.h b/common/inc/plat/sifive_unleashed4.h index a6dc7e11..0173bedc 100644 --- a/common/inc/plat/sifive_unleashed4.h +++ b/common/inc/plat/sifive_unleashed4.h @@ -24,16 +24,11 @@ #define UART_SIFIVE -#define INIT_CAPS \ - { \ - [0] = cap_mk_pmp(0x20005fff, MEM_RWX), \ - [1] = cap_mk_memory(0x80020000, 0x88000000, MEM_RWX), \ - [2] = cap_mk_memory(0x10010000, 0x10011000, MEM_RW), \ - [3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \ - [4] = cap_mk_time(1, 0, S3K_SLOT_CNT), \ - [5] = cap_mk_time(2, 0, S3K_SLOT_CNT), \ - [6] = cap_mk_time(3, 0, S3K_SLOT_CNT), \ - [7] = cap_mk_time(4, 0, S3K_SLOT_CNT), \ - [8] = cap_mk_monitor(0, S3K_PROC_CNT), \ - [9] = cap_mk_channel(0, S3K_CHAN_CNT), \ +#define INIT_CAPS \ + { \ + [0] = cap_mk_pmp(0x20005fff, MEM_RWX), [1] = cap_mk_memory(0x80020000, 0x88000000, MEM_RWX), \ + [2] = cap_mk_memory(0x10010000, 0x10011000, MEM_RW), [3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \ + [4] = cap_mk_time(1, 0, S3K_SLOT_CNT), [5] = cap_mk_time(2, 0, S3K_SLOT_CNT), \ + [6] = cap_mk_time(3, 0, S3K_SLOT_CNT), [7] = cap_mk_time(4, 0, S3K_SLOT_CNT), \ + [8] = cap_mk_monitor(0, S3K_PROC_CNT), [9] = cap_mk_channel(0, S3K_CHAN_CNT), \ } diff --git a/common/inc/s3k/syscall.h b/common/inc/s3k/syscall.h index 69f2e358..3ccc6163 100644 --- a/common/inc/s3k/syscall.h +++ b/common/inc/s3k/syscall.h @@ -18,22 +18,15 @@ s3k_err_t s3k_pmp_load(s3k_cidx_t pmp_idx, s3k_pmp_slot_t pmp_slot); s3k_err_t s3k_pmp_unload(s3k_cidx_t pmp_idx); s3k_err_t s3k_mon_suspend(s3k_cidx_t mon_idx, s3k_pid_t pid); s3k_err_t s3k_mon_resume(s3k_cidx_t mon_idx, s3k_pid_t pid); -s3k_err_t s3k_mon_state_get(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_state_t *state); +s3k_err_t s3k_mon_state_get(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_state_t *state); s3k_err_t s3k_mon_yield(s3k_cidx_t mon_idx, s3k_pid_t pid); -s3k_err_t s3k_mon_reg_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, - uint64_t *val); -s3k_err_t s3k_mon_reg_write(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, - uint64_t val); -s3k_err_t s3k_mon_cap_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx, - s3k_cap_t *cap); -s3k_err_t s3k_mon_cap_move(s3k_cidx_t mon_idx, s3k_pid_t src_pid, - s3k_cidx_t src_idx, s3k_pid_t dst_pid, +s3k_err_t s3k_mon_reg_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, uint64_t *val); +s3k_err_t s3k_mon_reg_write(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, uint64_t val); +s3k_err_t s3k_mon_cap_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx, s3k_cap_t *cap); +s3k_err_t s3k_mon_cap_move(s3k_cidx_t mon_idx, s3k_pid_t src_pid, s3k_cidx_t src_idx, s3k_pid_t dst_pid, s3k_cidx_t dst_idx); -s3k_err_t s3k_mon_pmp_load(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_cidx_t pmp_idx, s3k_pmp_slot_t pmp_slot); -s3k_err_t s3k_mon_pmp_unload(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_cidx_t pmp_idx); +s3k_err_t s3k_mon_pmp_load(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t pmp_idx, s3k_pmp_slot_t pmp_slot); +s3k_err_t s3k_mon_pmp_unload(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t pmp_idx); s3k_err_t s3k_sock_send(s3k_cidx_t sock_idx, const s3k_msg_t *msg); s3k_reply_t s3k_sock_recv(s3k_cidx_t sock_idx, s3k_cidx_t cap_cidx); s3k_reply_t s3k_sock_sendrecv(s3k_cidx_t sock_idx, const s3k_msg_t *msg); @@ -46,22 +39,15 @@ s3k_err_t s3k_try_pmp_load(s3k_cidx_t pmp_idx, s3k_pmp_slot_t pmp_slot); s3k_err_t s3k_try_pmp_unload(s3k_cidx_t pmp_idx); s3k_err_t s3k_try_mon_suspend(s3k_cidx_t mon_idx, s3k_pid_t pid); s3k_err_t s3k_try_mon_resume(s3k_cidx_t mon_idx, s3k_pid_t pid); -s3k_err_t s3k_try_mon_state_get(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_state_t *state); +s3k_err_t s3k_try_mon_state_get(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_state_t *state); s3k_err_t s3k_try_mon_yield(s3k_cidx_t mon_idx, s3k_pid_t pid); -s3k_err_t s3k_try_mon_reg_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, - uint64_t *val); -s3k_err_t s3k_try_mon_reg_write(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_reg_t reg, uint64_t val); -s3k_err_t s3k_try_mon_cap_read(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_cidx_t idx, s3k_cap_t *cap); -s3k_err_t s3k_try_mon_cap_move(s3k_cidx_t mon_idx, s3k_pid_t src_pid, - s3k_cidx_t src_idx, s3k_pid_t dst_pid, +s3k_err_t s3k_try_mon_reg_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, uint64_t *val); +s3k_err_t s3k_try_mon_reg_write(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, uint64_t val); +s3k_err_t s3k_try_mon_cap_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx, s3k_cap_t *cap); +s3k_err_t s3k_try_mon_cap_move(s3k_cidx_t mon_idx, s3k_pid_t src_pid, s3k_cidx_t src_idx, s3k_pid_t dst_pid, s3k_cidx_t dst_idx); -s3k_err_t s3k_try_mon_pmp_load(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_cidx_t pmp_idx, s3k_pmp_slot_t pmp_slot); -s3k_err_t s3k_try_mon_pmp_unload(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_cidx_t pmp_idx); +s3k_err_t s3k_try_mon_pmp_load(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t pmp_idx, s3k_pmp_slot_t pmp_slot); +s3k_err_t s3k_try_mon_pmp_unload(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t pmp_idx); s3k_err_t s3k_try_sock_send(s3k_cidx_t sock_idx, const s3k_msg_t *msg); s3k_reply_t s3k_try_sock_recv(s3k_cidx_t sock_idx, s3k_cidx_t cap_cidx); s3k_reply_t s3k_try_sock_sendrecv(s3k_cidx_t sock_idx, const s3k_msg_t *msg); diff --git a/common/inc/s3k/util.h b/common/inc/s3k/util.h index 65190928..2cd8213b 100644 --- a/common/inc/s3k/util.h +++ b/common/inc/s3k/util.h @@ -1,21 +1,18 @@ #pragma once #include "s3k/types.h" -s3k_cap_t s3k_mk_time(s3k_hart_t hart, s3k_time_slot_t bgn, - s3k_time_slot_t end); +s3k_cap_t s3k_mk_time(s3k_hart_t hart, s3k_time_slot_t bgn, s3k_time_slot_t end); s3k_cap_t s3k_mk_memory(s3k_addr_t bgn, s3k_addr_t end, s3k_rwx_t rwx); s3k_cap_t s3k_mk_pmp(s3k_napot_t napot_addr, s3k_rwx_t rwx); s3k_cap_t s3k_mk_monitor(s3k_pid_t bgn, s3k_pid_t end); s3k_cap_t s3k_mk_channel(s3k_chan_t bgn, s3k_chan_t end); -s3k_cap_t s3k_mk_socket(s3k_chan_t chan, s3k_ipc_mode_t mode, - s3k_ipc_perm_t perm, uint32_t tag); +s3k_cap_t s3k_mk_socket(s3k_chan_t chan, s3k_ipc_mode_t mode, s3k_ipc_perm_t perm, uint32_t tag); bool s3k_is_valid(s3k_cap_t a); bool s3k_is_parent(s3k_cap_t a, s3k_cap_t b); bool s3k_is_derivable(s3k_cap_t a, s3k_cap_t b); -void s3k_napot_decode(s3k_napot_t napot_addr, s3k_addr_t *base, - s3k_addr_t *size); +void s3k_napot_decode(s3k_napot_t napot_addr, s3k_addr_t *base, s3k_addr_t *size); s3k_napot_t s3k_napot_encode(s3k_addr_t base, s3k_addr_t size); static inline bool s3k_is_ready(s3k_state_t state) diff --git a/common/src/altc/gets.c b/common/src/altc/gets.c deleted file mode 100644 index f48a4716..00000000 --- a/common/src/altc/gets.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "altc/altio.h" -#include "drivers/uart.h" -#include "plat/config.h" - -#include - -int alt_getchar(void) -{ - return uart_getc((void *)UART0_BASE_ADDR); -} - -int alt_gets(char *src) -{ - int i = 0; - while (1) { - src[i] = alt_getchar(); - if (src[i] == '\n' || src[i] == '\0') - break; - i++; - } - src[i] = '\0'; - return i; -} diff --git a/common/src/altc/printf.c b/common/src/altc/printf.c index 25e3a978..26d7c7c4 100644 --- a/common/src/altc/printf.c +++ b/common/src/altc/printf.c @@ -3,116 +3,21 @@ #include #include -#define ALT_PRINTF_BUF_SIZE 128 - -static char *write_dec(char *restrict dst, const char *end, - unsigned long long val) -{ - if (!val && dst != end) { - *(dst++) = '0'; - } else if (dst != end) { - int i = 0; - char buf[24]; - while (val) { - int tmp = val % 10; - buf[i++] = '0' + tmp; - val /= 10; - } - while (i > 0 && dst != end) - *(dst++) = buf[--i]; - } - return dst; -} - -static char *write_hex(char *restrict dst, const char *end, - unsigned long long val) -{ - if (!val && dst != end) { - *(dst++) = '0'; - } else if (dst != end) { - int i = 0; - char buf[16]; - while (val) { - int tmp = val & 0xF; - buf[i++] = tmp < 10 ? ('0' + tmp) : 'A' + (tmp - 10); - val >>= 4; - } - while (i > 0 && dst != end) - *(dst++) = buf[--i]; - } - return dst; -} - -static char *write_str(char *restrict dst, const char *end, char *restrict src) -{ - while (dst != end && *src != '\0') - *(dst++) = *(src++); - return dst; -} - -static char *write_char(char *restrict dst, const char *end, char c) -{ - if (dst != end) - *(dst++) = c; - return dst; -} - -int alt_vsnprintf(char *restrict str, size_t size, const char *restrict fmt, - va_list ap) -{ - char *s = str; - const char *end = str + size - 1; - while (*fmt != '\0' && s != end) { - if (*(fmt++) != '%') { - s = write_char(s, end, *(fmt - 1)); - continue; - } - switch (*(fmt++)) { - case '%': - s = write_char(s, end, '%'); - break; - case 'c': - s = write_char(s, end, va_arg(ap, int)); - break; - case 's': - s = write_str(s, end, va_arg(ap, char *)); - break; - case 'x': - s = write_hex(s, end, va_arg(ap, unsigned int)); - break; - case 'X': - s = write_hex(s, end, va_arg(ap, unsigned long)); - break; - case 'd': - s = write_dec(s, end, va_arg(ap, unsigned int)); - break; - case 'D': - s = write_dec(s, end, va_arg(ap, unsigned long)); - break; - case '\0': - break; - } - } - *s = '\0'; - return s - str; -} - -int alt_snprintf(char *restrict str, size_t size, const char *restrict fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - int len = alt_vsnprintf(str, size, fmt, ap); - va_end(ap); - return len; -} - -int alt_printf(const char *restrict fmt, ...) -{ - char buf[ALT_PRINTF_BUF_SIZE]; - va_list ap; - va_start(ap, fmt); - int len = alt_vsnprintf(buf, ALT_PRINTF_BUF_SIZE, fmt, ap); - va_end(ap); - alt_putstr(buf); - return len; -} +int alt_fputchar(FILE *f, char c); +int alt_fputuint(FILE *f, unsigned long long val); +int alt_fputhex(FILE *f, unsigned long long val); +int alt_fputstr(FILE *f, const char *s); +int alt_vfprintf(FILE *f, const char *fmt, va_list ap); +int alt_fprintf(FILE *f, const char *fmt, ...) + + int alt_putchar(char c); +int alt_putstr(const char *s); +int alt_putuint(unsigned long long val); +int alt_puthex(unsigned long long val); +int alt_vprintf(const char *fmt, va_list ap); +int alt_printf(const char *fmt, ...); + +int alt_snputuint(char *buf, int size, unsigned long long val); +int alt_snputhex(char *buf, int size, unsigned long long val); +int alt_snvprintf(char *buf, int size, const char *fmt, va_list ap); +int alt_snprintf(char *buf, int size, const char *fmt, ...); diff --git a/common/src/altc/puts.c b/common/src/altc/puts.c deleted file mode 100644 index 2374e894..00000000 --- a/common/src/altc/puts.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "altc/altio.h" -#include "drivers/uart.h" -#include "plat/config.h" - -#include - -int alt_putchar(char c) -{ - uart_putc((void *)UART0_BASE_ADDR, c); - return c; -} - -int alt_putstr(const char *str) -{ - int i = 0; - while (str[i] != '\0') { - alt_putchar(str[i]); - i++; - } - return i; -} - -int alt_puts(const char *str) -{ - int i = alt_putstr(str); - alt_putchar('\r'); - alt_putchar('\n'); - return i; -} diff --git a/common/src/s3k/s3k.c b/common/src/s3k/s3k.c index 37440820..00a79375 100644 --- a/common/src/s3k/s3k.c +++ b/common/src/s3k/s3k.c @@ -87,10 +87,8 @@ s3k_cap_t s3k_mk_time(s3k_hart_t hart, s3k_time_slot_t bgn, s3k_time_slot_t end) s3k_cap_t s3k_mk_memory(s3k_addr_t bgn, s3k_addr_t end, s3k_rwx_t rwx) { s3k_tag_t tag = bgn >> S3K_MAX_BLOCK_SIZE; - s3k_block_t bgn_block = (bgn - (tag << S3K_MAX_BLOCK_SIZE)) - >> S3K_MIN_BLOCK_SIZE; - s3k_block_t end_block = (end - (tag << S3K_MAX_BLOCK_SIZE)) - >> S3K_MIN_BLOCK_SIZE; + s3k_block_t bgn_block = (bgn - (tag << S3K_MAX_BLOCK_SIZE)) >> S3K_MIN_BLOCK_SIZE; + s3k_block_t end_block = (end - (tag << S3K_MAX_BLOCK_SIZE)) >> S3K_MIN_BLOCK_SIZE; return (s3k_cap_t){ .mem = { @@ -142,8 +140,7 @@ s3k_cap_t s3k_mk_channel(s3k_chan_t bgn, s3k_chan_t end) }; } -s3k_cap_t s3k_mk_socket(s3k_chan_t chan, s3k_ipc_mode_t mode, - s3k_ipc_perm_t perm, uint32_t tag) +s3k_cap_t s3k_mk_socket(s3k_chan_t chan, s3k_ipc_mode_t mode, s3k_ipc_perm_t perm, uint32_t tag) { return (s3k_cap_t){ .sock = { @@ -167,14 +164,12 @@ s3k_napot_t s3k_napot_encode(s3k_addr_t base, size_t size) return (base | (size / 2 - 1)) >> 2; } -static inline bool is_range_subset(uint64_t a_bgn, uint64_t a_end, - uint64_t b_bgn, uint64_t b_end) +static inline bool is_range_subset(uint64_t a_bgn, uint64_t a_end, uint64_t b_bgn, uint64_t b_end) { return a_bgn <= b_bgn && b_end <= a_end; } -static inline bool is_range_prefix(uint64_t a_bgn, uint64_t a_end, - uint64_t b_bgn, uint64_t b_end) +static inline bool is_range_prefix(uint64_t a_bgn, uint64_t a_end, uint64_t b_bgn, uint64_t b_end) { return a_bgn == b_bgn && b_end <= a_end; } @@ -186,15 +181,13 @@ static inline bool is_bit_subset(uint64_t a, uint64_t b) s3k_addr_t s3k_tag_block_to_addr(s3k_tag_t tag, s3k_block_t block) { - return ((uint64_t)tag << S3K_MAX_BLOCK_SIZE) - + ((uint64_t)block << S3K_MIN_BLOCK_SIZE); + return ((uint64_t)tag << S3K_MAX_BLOCK_SIZE) + ((uint64_t)block << S3K_MIN_BLOCK_SIZE); } static bool s3k_cap_time_revokable(s3k_cap_t p, s3k_cap_t c) { return (c.type == S3K_CAPTY_TIME) && (p.time.hart == c.time.hart) - && is_range_subset(p.time.bgn, p.time.end, c.time.bgn, - c.time.end); + && is_range_subset(p.time.bgn, p.time.end, c.time.bgn, c.time.end); } static bool s3k_cap_mem_revokable(s3k_cap_t p, s3k_cap_t c) @@ -212,25 +205,20 @@ static bool s3k_cap_mem_revokable(s3k_cap_t p, s3k_cap_t c) static bool s3k_cap_mon_revokable(s3k_cap_t p, s3k_cap_t c) { - return (c.type == S3K_CAPTY_MONITOR) - && is_range_subset(p.mon.bgn, p.mon.end, c.mon.bgn, c.mon.end); + return (c.type == S3K_CAPTY_MONITOR) && is_range_subset(p.mon.bgn, p.mon.end, c.mon.bgn, c.mon.end); } static bool s3k_cap_chan_revokable(s3k_cap_t p, s3k_cap_t c) { if (c.type == S3K_CAPTY_SOCKET) { - return is_range_subset(p.chan.bgn, p.chan.end, c.sock.chan, - c.sock.chan + 1); + return is_range_subset(p.chan.bgn, p.chan.end, c.sock.chan, c.sock.chan + 1); } - return (c.type == S3K_CAPTY_CHANNEL) - && is_range_subset(p.chan.bgn, p.chan.end, c.chan.bgn, - c.chan.end); + return (c.type == S3K_CAPTY_CHANNEL) && is_range_subset(p.chan.bgn, p.chan.end, c.chan.bgn, c.chan.end); } static bool s3k_cap_sock_revokable(s3k_cap_t p, s3k_cap_t c) { - return (p.sock.tag == 0) && (c.sock.tag != 0) - && (p.sock.chan == c.sock.chan); + return (p.sock.tag == 0) && (c.sock.tag != 0) && (p.sock.chan == c.sock.chan); } bool s3k_cap_is_revokable(s3k_cap_t p, s3k_cap_t c) @@ -265,11 +253,8 @@ bool s3k_cap_is_valid(s3k_cap_t c) case S3K_CAPTY_CHANNEL: return (c.chan.bgn == c.chan.mrk) && (c.chan.bgn < c.chan.end); case S3K_CAPTY_SOCKET: - return is_bit_subset(c.sock.perm, S3K_IPC_SDATA | S3K_IPC_CDATA - | S3K_IPC_SCAP - | S3K_IPC_CCAP) - && is_bit_subset(c.sock.mode, - S3K_IPC_YIELD | S3K_IPC_NOYIELD); + return is_bit_subset(c.sock.perm, S3K_IPC_SDATA | S3K_IPC_CDATA | S3K_IPC_SCAP | S3K_IPC_CCAP) + && is_bit_subset(c.sock.mode, S3K_IPC_YIELD | S3K_IPC_NOYIELD); default: return false; } @@ -278,8 +263,7 @@ bool s3k_cap_is_valid(s3k_cap_t c) static bool s3k_cap_time_derivable(s3k_cap_t p, s3k_cap_t c) { return (c.type == S3K_CAPTY_TIME) && (p.time.hart == c.time.hart) - && is_range_prefix(p.time.bgn, p.time.end, c.time.bgn, - c.time.end); + && is_range_prefix(p.time.bgn, p.time.end, c.time.bgn, c.time.end); } static bool s3k_cap_mem_derivable(s3k_cap_t p, s3k_cap_t c) @@ -289,36 +273,28 @@ static bool s3k_cap_mem_derivable(s3k_cap_t p, s3k_cap_t c) p_mrk = s3k_tag_block_to_addr(p.mem.tag, p.mem.mrk); p_end = s3k_tag_block_to_addr(p.mem.tag, p.mem.end); s3k_napot_decode(c.pmp.addr, &c_bgn, &c_end); - return is_range_subset(p_mrk, p_end, c_bgn, c_end) - && is_bit_subset(c.pmp.rwx, p.mem.rwx); + return is_range_subset(p_mrk, p_end, c_bgn, c_end) && is_bit_subset(c.pmp.rwx, p.mem.rwx); } return (c.type == S3K_CAPTY_MEMORY) && (p.mem.tag == c.mem.tag) - && is_range_subset(p.mem.mrk, p.mem.end, c.mem.bgn, c.mem.end) - && is_bit_subset(c.mem.rwx, p.mem.rwx); + && is_range_subset(p.mem.mrk, p.mem.end, c.mem.bgn, c.mem.end) && is_bit_subset(c.mem.rwx, p.mem.rwx); } static bool s3k_cap_mon_derivable(s3k_cap_t p, s3k_cap_t c) { - return (c.type == S3K_CAPTY_MONITOR) - && is_range_subset(p.mon.mrk, p.mon.end, c.mon.bgn, c.mon.end); + return (c.type == S3K_CAPTY_MONITOR) && is_range_subset(p.mon.mrk, p.mon.end, c.mon.bgn, c.mon.end); } static bool s3k_cap_chan_derivable(s3k_cap_t p, s3k_cap_t c) { if (c.type == S3K_CAPTY_SOCKET) { - return (c.sock.tag == 0) - && is_range_subset(p.chan.mrk, p.chan.end, c.sock.chan, - c.sock.chan + 1); + return (c.sock.tag == 0) && is_range_subset(p.chan.mrk, p.chan.end, c.sock.chan, c.sock.chan + 1); } - return (c.type == S3K_CAPTY_CHANNEL) - && is_range_subset(p.chan.mrk, p.chan.end, c.chan.bgn, - c.chan.end); + return (c.type == S3K_CAPTY_CHANNEL) && is_range_subset(p.chan.mrk, p.chan.end, c.chan.bgn, c.chan.end); } static bool s3k_cap_sock_derivable(s3k_cap_t p, s3k_cap_t c) { - return (c.type == S3K_CAPTY_SOCKET) && (p.sock.chan == c.sock.chan) - && (p.sock.tag == 0) && (c.sock.tag != 0) + return (c.type == S3K_CAPTY_SOCKET) && (p.sock.chan == c.sock.chan) && (p.sock.tag == 0) && (c.sock.tag != 0) && (p.sock.mode == c.sock.mode) && (p.sock.perm == c.sock.perm); } diff --git a/common/src/s3k/syscall.c b/common/src/s3k/syscall.c index 28f71f03..65af4855 100644 --- a/common/src/s3k/syscall.c +++ b/common/src/s3k/syscall.c @@ -155,65 +155,51 @@ typedef struct { _Static_assert(sizeof(sys_args_t) == 64, "sys_args_t has the wrong size"); -#define DO_ECALL(call, args, width) \ - ({ \ - register uint64_t t0 __asm__("t0") = call; \ - register uint64_t a0 __asm__("a0") = args.a0; \ - register uint64_t a1 __asm__("a1") = args.a1; \ - register uint64_t a2 __asm__("a2") = args.a2; \ - register uint64_t a3 __asm__("a3") = args.a3; \ - register uint64_t a4 __asm__("a4") = args.a4; \ - register uint64_t a5 __asm__("a5") = args.a5; \ - register uint64_t a6 __asm__("a6") = args.a6; \ - register uint64_t a7 __asm__("a7") = args.a7; \ - switch ((width + 7) / 8) { \ - case 0: \ - __asm__ volatile("ecall" : "+r"(t0)); \ - break; \ - case 1: \ - __asm__ volatile("ecall" : "+r"(t0), "+r"(a0)); \ - break; \ - case 2: \ - __asm__ volatile("ecall" \ - : "+r"(t0), "+r"(a0) \ - : "r"(a1)); \ - break; \ - case 3: \ - __asm__ volatile("ecall" \ - : "+r"(t0), "+r"(a0) \ - : "r"(a1), "r"(a2)); \ - break; \ - case 4: \ - __asm__ volatile("ecall" \ - : "+r"(t0), "+r"(a0) \ - : "r"(a1), "r"(a2), "r"(a3)); \ - break; \ - case 5: \ - __asm__ volatile("ecall" \ - : "+r"(t0), "+r"(a0) \ - : "r"(a1), "r"(a2), "r"(a3), \ - "r"(a4)); \ - break; \ - case 6: \ - __asm__ volatile("ecall" \ - : "+r"(t0), "+r"(a0) \ - : "r"(a1), "r"(a2), "r"(a3), "r"(a4), \ - "r"(a5)); \ - break; \ - case 7: \ - __asm__ volatile("ecall" \ - : "+r"(t0), "+r"(a0) \ - : "r"(a1), "r"(a2), "r"(a3), "r"(a4), \ - "r"(a5), "r"(a6)); \ - break; \ - case 8: \ - __asm__ volatile("ecall" \ - : "=r"(t0), "+r"(a0) \ - : "r"(a1), "r"(a2), "r"(a3), "r"(a4), \ - "r"(a5), "r"(a6), "r"(a7)); \ - break; \ - } \ - (s3k_ret_t){.err = t0, .val = a0}; \ +#define DO_ECALL(call, args, width) \ + ({ \ + register uint64_t t0 __asm__("t0") = call; \ + register uint64_t a0 __asm__("a0") = args.a0; \ + register uint64_t a1 __asm__("a1") = args.a1; \ + register uint64_t a2 __asm__("a2") = args.a2; \ + register uint64_t a3 __asm__("a3") = args.a3; \ + register uint64_t a4 __asm__("a4") = args.a4; \ + register uint64_t a5 __asm__("a5") = args.a5; \ + register uint64_t a6 __asm__("a6") = args.a6; \ + register uint64_t a7 __asm__("a7") = args.a7; \ + switch ((width + 7) / 8) { \ + case 0: \ + __asm__ volatile("ecall" : "+r"(t0)); \ + break; \ + case 1: \ + __asm__ volatile("ecall" : "+r"(t0), "+r"(a0)); \ + break; \ + case 2: \ + __asm__ volatile("ecall" : "+r"(t0), "+r"(a0) : "r"(a1)); \ + break; \ + case 3: \ + __asm__ volatile("ecall" : "+r"(t0), "+r"(a0) : "r"(a1), "r"(a2)); \ + break; \ + case 4: \ + __asm__ volatile("ecall" : "+r"(t0), "+r"(a0) : "r"(a1), "r"(a2), "r"(a3)); \ + break; \ + case 5: \ + __asm__ volatile("ecall" : "+r"(t0), "+r"(a0) : "r"(a1), "r"(a2), "r"(a3), "r"(a4)); \ + break; \ + case 6: \ + __asm__ volatile("ecall" : "+r"(t0), "+r"(a0) : "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5)); \ + break; \ + case 7: \ + __asm__ volatile("ecall" \ + : "+r"(t0), "+r"(a0) \ + : "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a6)); \ + break; \ + case 8: \ + __asm__ volatile("ecall" \ + : "=r"(t0), "+r"(a0) \ + : "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a6), "r"(a7)); \ + break; \ + } \ + (s3k_ret_t){.err = t0, .val = a0}; \ }) uint64_t s3k_get_pid(void) @@ -346,8 +332,7 @@ s3k_err_t s3k_mon_resume(s3k_cidx_t mon_idx, s3k_pid_t pid) return err; } -s3k_err_t s3k_mon_state_get(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_state_t *state) +s3k_err_t s3k_mon_state_get(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_state_t *state) { s3k_err_t err; do { @@ -365,8 +350,7 @@ s3k_err_t s3k_mon_yield(s3k_cidx_t mon_idx, s3k_pid_t pid) return err; } -s3k_err_t s3k_mon_reg_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, - uint64_t *val) +s3k_err_t s3k_mon_reg_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, uint64_t *val) { s3k_err_t err; do { @@ -375,8 +359,7 @@ s3k_err_t s3k_mon_reg_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, return err; } -s3k_err_t s3k_mon_reg_write(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, - uint64_t val) +s3k_err_t s3k_mon_reg_write(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, uint64_t val) { s3k_err_t err; do { @@ -385,8 +368,7 @@ s3k_err_t s3k_mon_reg_write(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_reg_t reg, return err; } -s3k_err_t s3k_mon_cap_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx, - s3k_cap_t *cap) +s3k_err_t s3k_mon_cap_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx, s3k_cap_t *cap) { s3k_err_t err; do { @@ -395,20 +377,17 @@ s3k_err_t s3k_mon_cap_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx, return err; } -s3k_err_t s3k_mon_cap_move(s3k_cidx_t mon_idx, s3k_pid_t src_pid, - s3k_cidx_t src_idx, s3k_pid_t dst_pid, +s3k_err_t s3k_mon_cap_move(s3k_cidx_t mon_idx, s3k_pid_t src_pid, s3k_cidx_t src_idx, s3k_pid_t dst_pid, s3k_cidx_t dst_idx) { s3k_err_t err; do { - err = s3k_try_mon_cap_move(mon_idx, src_pid, src_idx, dst_pid, - dst_idx); + err = s3k_try_mon_cap_move(mon_idx, src_pid, src_idx, dst_pid, dst_idx); } while (err == S3K_ERR_PREEMPTED); return err; } -s3k_err_t s3k_mon_pmp_load(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_cidx_t pmp_idx, s3k_pmp_slot_t pmp_slot) +s3k_err_t s3k_mon_pmp_load(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t pmp_idx, s3k_pmp_slot_t pmp_slot) { s3k_err_t err; do { @@ -417,8 +396,7 @@ s3k_err_t s3k_mon_pmp_load(s3k_cidx_t mon_idx, s3k_pid_t pid, return err; } -s3k_err_t s3k_mon_pmp_unload(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_cidx_t pmp_idx) +s3k_err_t s3k_mon_pmp_unload(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t pmp_idx) { s3k_err_t err; do { @@ -512,14 +490,12 @@ s3k_err_t s3k_try_mon_resume(s3k_cidx_t mon, s3k_pid_t pid) return DO_ECALL(S3K_SYS_MON_RESUME, args, sizeof(args.mon_state)).err; } -s3k_err_t s3k_try_mon_state_get(s3k_cidx_t mon, s3k_pid_t pid, - s3k_state_t *state) +s3k_err_t s3k_try_mon_state_get(s3k_cidx_t mon, s3k_pid_t pid, s3k_state_t *state) { sys_args_t args = { .mon_state = {mon, pid} }; - s3k_ret_t ret - = DO_ECALL(S3K_SYS_MON_STATE_GET, args, sizeof(args.mon_state)); + s3k_ret_t ret = DO_ECALL(S3K_SYS_MON_STATE_GET, args, sizeof(args.mon_state)); *state = ret.val; return ret.err; } @@ -532,72 +508,59 @@ s3k_err_t s3k_try_mon_yield(s3k_cidx_t mon, s3k_pid_t pid) return DO_ECALL(S3K_SYS_MON_YIELD, args, sizeof(args.mon_state)).err; } -s3k_err_t s3k_try_mon_reg_read(s3k_cidx_t mon, s3k_pid_t pid, s3k_reg_t reg, - uint64_t *val) +s3k_err_t s3k_try_mon_reg_read(s3k_cidx_t mon, s3k_pid_t pid, s3k_reg_t reg, uint64_t *val) { sys_args_t args = { .mon_reg_read = {mon, pid, reg} }; - s3k_ret_t ret - = DO_ECALL(S3K_SYS_MON_REG_READ, args, sizeof(args.mon_reg_read)); + s3k_ret_t ret = DO_ECALL(S3K_SYS_MON_REG_READ, args, sizeof(args.mon_reg_read)); *val = ret.val; return ret.err; } -s3k_err_t s3k_try_mon_reg_write(s3k_cidx_t mon, s3k_pid_t pid, s3k_reg_t reg, - uint64_t val) +s3k_err_t s3k_try_mon_reg_write(s3k_cidx_t mon, s3k_pid_t pid, s3k_reg_t reg, uint64_t val) { sys_args_t args = { .mon_reg_write = {mon, pid, reg, val} }; - s3k_ret_t ret - = DO_ECALL(S3K_SYS_MON_REG_WRITE, args, sizeof(args.mon_reg_write)); + s3k_ret_t ret = DO_ECALL(S3K_SYS_MON_REG_WRITE, args, sizeof(args.mon_reg_write)); return ret.err; } -s3k_err_t s3k_try_mon_cap_read(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_cidx_t idx, s3k_cap_t *cap) +s3k_err_t s3k_try_mon_cap_read(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx, s3k_cap_t *cap) { sys_args_t args = { .mon_cap_read = {mon_idx, pid, idx} }; - s3k_ret_t ret - = DO_ECALL(S3K_SYS_MON_CAP_READ, args, sizeof(args.mon_cap_read)); + s3k_ret_t ret = DO_ECALL(S3K_SYS_MON_CAP_READ, args, sizeof(args.mon_cap_read)); if (!ret.err) cap->raw = ret.val; return ret.err; } -s3k_err_t s3k_try_mon_cap_move(s3k_cidx_t mon_idx, s3k_pid_t src_pid, - s3k_cidx_t src_idx, s3k_pid_t dst_pid, +s3k_err_t s3k_try_mon_cap_move(s3k_cidx_t mon_idx, s3k_pid_t src_pid, s3k_cidx_t src_idx, s3k_pid_t dst_pid, s3k_cidx_t dst_idx) { sys_args_t args = { .mon_cap_move = {mon_idx, src_pid, src_idx, dst_pid, dst_idx} }; - return DO_ECALL(S3K_SYS_MON_CAP_MOVE, args, sizeof(args.mon_cap_move)) - .err; + return DO_ECALL(S3K_SYS_MON_CAP_MOVE, args, sizeof(args.mon_cap_move)).err; } -s3k_err_t s3k_try_mon_pmp_load(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_cidx_t idx, s3k_pmp_slot_t slot) +s3k_err_t s3k_try_mon_pmp_load(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx, s3k_pmp_slot_t slot) { sys_args_t args = { .mon_pmp_load = {mon_idx, pid, idx, slot} }; - return DO_ECALL(S3K_SYS_MON_PMP_LOAD, args, sizeof(args.mon_pmp_load)) - .err; + return DO_ECALL(S3K_SYS_MON_PMP_LOAD, args, sizeof(args.mon_pmp_load)).err; } -s3k_err_t s3k_try_mon_pmp_unload(s3k_cidx_t mon_idx, s3k_pid_t pid, - s3k_cidx_t idx) +s3k_err_t s3k_try_mon_pmp_unload(s3k_cidx_t mon_idx, s3k_pid_t pid, s3k_cidx_t idx) { sys_args_t args = { .mon_pmp_unload = {mon_idx, pid, idx} }; - return DO_ECALL(S3K_SYS_MON_PMP_UNLOAD, args, - sizeof(args.mon_pmp_unload)) - .err; + return DO_ECALL(S3K_SYS_MON_PMP_UNLOAD, args, sizeof(args.mon_pmp_unload)).err; } s3k_err_t s3k_try_sock_send(s3k_cidx_t sock_idx, const s3k_msg_t *msg) @@ -626,8 +589,7 @@ s3k_reply_t s3k_try_sock_recv(s3k_cidx_t sock_idx, s3k_cidx_t cap_idx) register uint64_t a6 __asm__("a6") = args.a6; register uint64_t a7 __asm__("a7") = args.a7; __asm__ volatile("ecall" - : "+r"(t0), "+r"(a0), "+r"(a1), "+r"(a2), "+r"(a3), - "+r"(a4), "+r"(a5) + : "+r"(t0), "+r"(a0), "+r"(a1), "+r"(a2), "+r"(a3), "+r"(a4), "+r"(a5) : "r"(a6), "r"(a7)); s3k_reply_t reply; reply.err = t0; @@ -658,8 +620,7 @@ s3k_reply_t s3k_try_sock_sendrecv(s3k_cidx_t sock_idx, const s3k_msg_t *msg) register uint64_t a6 __asm__("a6") = args.a6; register uint64_t a7 __asm__("a7") = args.a7; __asm__ volatile("ecall" - : "+r"(t0), "+r"(a0), "+r"(a1), "+r"(a2), "+r"(a3), - "+r"(a4), "+r"(a5) + : "+r"(t0), "+r"(a0), "+r"(a1), "+r"(a2), "+r"(a3), "+r"(a4), "+r"(a5) : "r"(a6), "r"(a7)); s3k_reply_t reply; reply.err = t0; diff --git a/kernel/Makefile b/kernel/Makefile deleted file mode 100644 index 314fed20..00000000 --- a/kernel/Makefile +++ /dev/null @@ -1,91 +0,0 @@ -# See LICENSE file for copyright and license details. -.POSIX: -.SECONDARY: - -# Kernel basename -ROOT=.. -PROGRAM?=kernel -PLATFORM?=qemu_virt4 -BUILD?=build/${PLATFORM} -S3K_CONF_H?=s3k_conf.h - -include ${ROOT}/tools.mk -include ${ROOT}/common/plat/${PLATFORM}.mk - -# CC flags -CFLAGS:=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} \ - -DPLATFORM_${PLATFORM} \ - -std=c11 \ - -O2 -g3 \ - -Wall -Wextra -Werror \ - -Wno-unused-parameter \ - -Wshadow -fno-common \ - -fno-stack-protector \ - -flto \ - -include ${S3K_CONF_H} \ - -Iinc -I${COMMON_INC} \ - -# LD flags -LDFLAGS:=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} \ - -Tlinker.ld \ - -nostartfiles -ffreestanding \ - -flto \ - -Wl,--no-warn-rwx-segment \ - -Wl,--gc-sections \ - --specs=nosys.specs \ - -ffunction-sections -fdata-sections \ - -L${COMMON_LIB} \ - -laltc -lplat - -# Source files -S_SRCS:=${wildcard src/*.S} -C_SRCS:=${wildcard src/*.c} ${wildcard src/*/*.c} - -# Object files -OBJS:=${patsubst src/%.S, ${BUILD}/${PROGRAM}/%.S.o, ${S_SRCS}} \ - ${patsubst src/%.c, ${BUILD}/${PROGRAM}/%.c.o, ${C_SRCS}} - -# Dependency files -DEPS:=${OBJS:.o=.d} - -# Targets -ELF:=${BUILD}/${PROGRAM}.elf -BIN:=${ELF:.elf=.bin} -HEX:=${ELF:.elf=.hex} -DA :=${ELF:.elf=.da} - -all: ${ELF} ${BIN} ${HEX} ${DA} - -clean: - rm -f ${ELF} ${OBJS} ${DEPS} - -${BUILD}/${PROGRAM}/%.S.o: src/%.S - @mkdir -p ${@D} - @${CC} -o $@ $< -c -MMD ${CFLAGS} - @printf "CC\t$@\n" - -${BUILD}/${PROGRAM}/%.c.o: src/%.c - @mkdir -p ${@D} - @${CC} -o $@ $< -c -MMD ${CFLAGS} - @printf "CC\t$@\n" - -%.elf: ${OBJS} - @mkdir -p ${@D} - @${CC} -o $@ ${OBJS} ${LDFLAGS} - @printf "CC\t$@\n" - -%.bin: %.elf - @${OBJCOPY} -O binary $< $@ - @printf "OBJCOPY\t$@\n" - -%.hex: %.elf - @${OBJCOPY} -O ihex $< $@ - @printf "OBJCOPY\t$@\n" - -%.da: %.elf - @${OBJDUMP} -D $< > $@ - @printf "OBJDUMP\t$@\n" - -.PHONY: all da format clean - --include ${DEPS} diff --git a/kernel/inc/cap_ipc.h b/kernel/inc/cap_ipc.h deleted file mode 100644 index 1db9f44a..00000000 --- a/kernel/inc/cap_ipc.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "cap_table.h" -#include "error.h" -#include "proc.h" - -#include - -typedef struct ipc_msg { - cte_t cap_buf; - bool send_cap; - uint64_t data[4]; -} ipc_msg_t; - -err_t cap_sock_send(cte_t sock, const ipc_msg_t *msg, proc_t **next); -err_t cap_sock_recv(cte_t sock, const cte_t cap_buf, proc_t **next); -err_t cap_sock_sendrecv(cte_t sock, const ipc_msg_t *msg, proc_t **next); -void cap_sock_clear(cap_t cap, proc_t *next); diff --git a/kernel/inc/cap_lock.h b/kernel/inc/cap_lock.h deleted file mode 100644 index c8606ca9..00000000 --- a/kernel/inc/cap_lock.h +++ /dev/null @@ -1,5 +0,0 @@ -#include - -void cap_lock_init(void); -bool cap_lock_acquire(void); -void cap_lock_release(void); diff --git a/kernel/inc/cap_monitor.h b/kernel/inc/cap_monitor.h deleted file mode 100644 index 4808c91d..00000000 --- a/kernel/inc/cap_monitor.h +++ /dev/null @@ -1,174 +0,0 @@ -/** - * @file cap_monitor.h - * @brief Capability Monitor Interface - * - * This file provides the interface for monitoring and managing processes - * through capabilities. Functions include suspending and resuming - * processes, reading and writing to process registers, and managing - * process capabilities and PMP configurations. - * - * All functions require the processes to be in a suspended state for - * operations. Error codes indicate unauthorized, invalid, or inappropriate - * requests. - * - * @author Henrik Akira Karlsson - * - * @license - * - * Copyright (c) 2023 Henrik Akira Karlsson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once -#include "cap_table.h" -#include "error.h" -#include "proc.h" - -/** - * Suspends a specified process. - * - * @param mon The CTE of the monitor capability. - * @param pid The ID of the process to be suspended. - * @return SUCCESS if the process set to suspend. - * ERR_EMPTY if the CTE is empty. - * ERR_INVALID_MONITOR if the CTE has the wrong capability type or - * authorization. - */ -err_t cap_monitor_suspend(cte_t mon, pid_t pid); - -/** - * Resumes a specified suspended process. - * - * @param mon The CTE of the monitor capability. - * @param pid The ID of the process to be resumed. - * @return SUCCESS if the process is resumed. - * ERR_EMPTY if the CTE is empty. - * ERR_INVALID_MONITOR if the CTE has the wrong capability type or is - * unauthorized. - */ -err_t cap_monitor_resume(cte_t mon, pid_t pid); - -/** - * Yield remaining execution time to specified ready process. - * - * @param mon The CTE of the monitor capability. - * @param pid The ID of the process to be run. - * @param next - * @return YIELD if the yield is successful. - * ERR_EMPTY if the CTE is empty. - * ERR_INVALID_MONITOR if the CTE has the wrong capability type or is unauthorized. - * ERR_INVALID_STATE if the process is not ready. - */ -err_t cap_monitor_yield(cte_t mon, pid_t pid, proc_t **next); - -/** - * Get the current state of the process. - * - * @param mon The CTE of the monitor capability. - * @param pid The ID of the process to get state of. - * @return SUCCESS if the process state was retrieved. - * ERR_EMPTY if the CTE is empty. - * ERR_INVALID_MONITOR if the CTE has the wrong capability type or is unauthorized. - * ERR_INVALID_STATE if the process is not ready. - */ -err_t cap_monitor_state_get(cte_t mon, pid_t pid, proc_state_t *state); - -/** - * Reads a register value from a specified suspended process. - * - * @param mon The CTE of the monitor capability. - * @param pid The ID of the process whose register is to be read. - * @param reg The register to be read. - * @param val Pointer to store the read value. - * @return SUCCESS if the register is read. - * ERR_EMPTY if the CTE is empty. - * ERR_INVALID_MONITOR if unauthorized or wrong capability type. - * ERR_INVALID_STATE if the process is not suspended. - */ -err_t cap_monitor_reg_read(cte_t mon, pid_t pid, reg_t reg, uint64_t *val); - -/** - * Writes a value to a specified register of a suspended process. - * - * @param mon The CTE of the monitor capability. - * @param pid The ID of the process whose register is to be written. - * @param reg The register to be written to. - * @param val The value to write. - * @return SUCCESS if the value is written. - * ERR_EMPTY if the CTE is empty. - * ERR_INVALID_MONITOR if unauthorized or wrong capability type. - * ERR_INVALID_STATE if the process is not suspended. - */ -err_t cap_monitor_reg_write(cte_t mon, pid_t pid, reg_t reg, uint64_t val); - -/** - * Reads a capability from a specified source CTE of a suspended process. - * - * @param mon The CTE of the monitor capability. - * @param src The source CTE. - * @param cap Pointer to store the read capability. - * @return SUCCESS if the capability is read. - * ERR_EMPTY if the CTE is empty. - * ERR_INVALID_MONITOR if unauthorized or wrong capability type. - * ERR_INVALID_STATE if the process is not suspended. - */ -err_t cap_monitor_cap_read(cte_t mon, cte_t src, cap_t *cap); - -/** - * Moves a capability from a source to a destination CTE of a suspended process. - * - * @param mon The CTE of the monitor capability. - * @param src The source CTE. - * @param dst The destination CTE. - * @return SUCCESS if the capability is moved. - * ERR_EMPTY if the CTE is empty. - * ERR_INVALID_MONITOR if unauthorized or wrong capability type. - * ERR_INVALID_STATE if the process is not suspended. - */ -err_t cap_monitor_cap_move(cte_t mon, cte_t src, cte_t dst); - -/** - * Loads a PMP configuration into a specified slot of a suspended process. - * - * @param mon The CTE of the monitor capability. - * @param pmp The CTE of the PMP capability. - * @param pmp_slot The slot to load the PMP configuration into. - * @return SUCCESS if the configuration is loaded. - * ERR_EMPTY if the CTE is empty. - * ERR_INVALID_MONITOR if mon unauthorized or wrong capability type. - * ERR_INVALID_STATE if the process is not suspended. - * ERR_INVALID_PMP if the pmp is already in use or has the wrong - * capabilty type ERR_DST_OCCUPIED if the pmp slot is occupied - */ -err_t cap_monitor_pmp_load(cte_t mon, cte_t pmp, pmp_slot_t pmp_slot); - -/** - * Unloads a PMP configuration from a specified PMP CTE of a suspended process. - * - * @param mon The CTE of the monitor capability. - * @param pmp The CTE of the PMP capability to unload. - * @return SUCCESS if the configuration is unloaded. - * ERR_EMPTY if the CTE is empty. - * ERR_INVALID_MONITOR if unauthorized or wrong capability type. - * ERR_INVALID_STATE if the process is not suspended. - * ERR_INVALID_PMP if the pmp is not in use or has the wrong capabilty - * type - */ -err_t cap_monitor_pmp_unload(cte_t mon, cte_t pmp); diff --git a/kernel/inc/cap_ops.h b/kernel/inc/cap_ops.h deleted file mode 100644 index b1d15a2c..00000000 --- a/kernel/inc/cap_ops.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "cap_table.h" -#include "error.h" - -err_t cap_read(cte_t cte, cap_t *cap); -err_t cap_move(cte_t src, cte_t dst); -err_t cap_ipc_move(cte_t src, cte_t dst); -err_t cap_delete(cte_t cte); -err_t cap_revoke(cte_t parent); -err_t cap_derive(cte_t src, cte_t dst, cap_t new_cap); diff --git a/kernel/inc/cap_pmp.h b/kernel/inc/cap_pmp.h deleted file mode 100644 index 96777b45..00000000 --- a/kernel/inc/cap_pmp.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "cap_table.h" -#include "error.h" - -err_t cap_pmp_load(cte_t cidx, pmp_slot_t slot); -err_t cap_pmp_unload(cte_t cidx); diff --git a/kernel/inc/cap_table.h b/kernel/inc/cap_table.h deleted file mode 100644 index df066393..00000000 --- a/kernel/inc/cap_table.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "cap_types.h" -#include "kassert.h" - -#include -#include -#include - -typedef struct cte *cte_t; - -void ctable_init(void); -cte_t ctable_get(uint64_t pid, uint64_t index); -bool cte_is_empty(cte_t c); -void cte_set_next(cte_t c, cte_t next); -void cte_set_prev(cte_t c, cte_t prev); -void cte_set_cap(cte_t c, cap_t cap); -cte_t cte_next(cte_t c); -cte_t cte_prev(cte_t c); -cap_t cte_cap(cte_t c); -uint64_t cte_pid(cte_t c); -void cte_move(cte_t src, cte_t dst); -cap_t cte_delete(cte_t c); -void cte_insert(cte_t c, cap_t cap, cte_t prev); diff --git a/kernel/inc/cap_types.h b/kernel/inc/cap_types.h deleted file mode 100644 index b4d4095c..00000000 --- a/kernel/inc/cap_types.h +++ /dev/null @@ -1,120 +0,0 @@ -#pragma once - -#include -#include - -// Min logarithmic size of a memory slice -#define MIN_BLOCK_SIZE 12 - -// Max logarithmic size of a memory slice -#define MAX_BLOCK_SIZE 27 - -typedef uint64_t napot_t; -typedef uint64_t addr_t; -typedef uint16_t block_t; -typedef uint16_t chan_t; -typedef uint16_t time_slot_t; -typedef uint16_t pid_t; -typedef uint16_t cidx_t; -typedef uint8_t hart_t; -typedef uint8_t tag_t; -typedef uint8_t rwx_t; -typedef uint8_t pmp_slot_t; -/* register number */ -typedef int regnr_t; - -typedef enum { - MEM_NONE = 0, - MEM_R = 0x1, - MEM_W = 0x2, - MEM_X = 0x4, - MEM_RW = MEM_R | MEM_W, - MEM_RX = MEM_R | MEM_X, - MEM_RWX = MEM_R | MEM_W | MEM_X, -} mem_perm_t; - -// IPC Modes -typedef enum { - IPC_NOYIELD = 0x0, // Non-Yielding Synchronous - IPC_YIELD = 0x1, // Yielding Synchronous -} ipc_mode_t; - -// IPC Permissions -typedef enum { - IPC_SDATA = 0x1, // Server can send data - IPC_SCAP = 0x2, // Server can send capabilities - IPC_CDATA = 0x4, // Client can send data - IPC_CCAP = 0x8, // Client can send capabilities -} ipc_perm_t; - -// Capability types -typedef enum capty { - CAPTY_NONE = 0, ///< No capability. - CAPTY_TIME = 1, ///< Time Slice capability. - CAPTY_MEMORY = 2, ///< Memory Slice capability. - CAPTY_PMP = 3, ///< PMP Frame capability. - CAPTY_MONITOR = 4, ///< Monitor capability. - CAPTY_CHANNEL = 5, ///< IPC Channel capability. - CAPTY_SOCKET = 6, ///< IPC Socket capability. - CAPTY_COUNT ///< Number of capability types -} capty_t; - -/// Capability description -typedef union cap { - capty_t type : 4; - - uint64_t raw; - - struct { - capty_t type : 4; - uint16_t _padding : 4; - hart_t hart; - time_slot_t bgn; - time_slot_t mrk; - time_slot_t end; - } time; - - struct { - capty_t type : 4; - rwx_t rwx : 3; - bool lck : 1; - tag_t tag; - block_t bgn; - block_t mrk; - block_t end; - } mem; - - struct { - capty_t type : 4; - rwx_t rwx : 3; - bool used : 1; - pmp_slot_t slot; - napot_t addr : 48; - } pmp; - - struct { - capty_t type : 4; - uint16_t _padding : 12; - pid_t bgn; - pid_t mrk; - pid_t end; - } mon; - - struct { - capty_t type : 4; - uint16_t _padding : 12; - chan_t bgn; - chan_t mrk; - chan_t end; - } chan; - - struct { - capty_t type : 4; - ipc_mode_t mode : 4; - ipc_perm_t perm : 8; - chan_t chan; - uint32_t tag; - } sock; -} cap_t; - -_Static_assert(sizeof(cap_t) == 8, "cap_t has the wrong size"); diff --git a/kernel/inc/cap_util.h b/kernel/inc/cap_util.h deleted file mode 100644 index 0b377244..00000000 --- a/kernel/inc/cap_util.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once -#include "cap_types.h" - -#include - -cap_t cap_mk_time(hart_t hart, time_slot_t bgn, time_slot_t end); -cap_t cap_mk_memory(addr_t bgn, addr_t end, rwx_t rwx); -cap_t cap_mk_pmp(napot_t addr, rwx_t rwx); -cap_t cap_mk_monitor(pid_t bgn, pid_t end); -cap_t cap_mk_channel(chan_t bgn, chan_t end); -cap_t cap_mk_socket(chan_t chan, ipc_mode_t mode, ipc_perm_t perm, - uint32_t tag); - -static inline addr_t tag_block_to_addr(tag_t tag, block_t block) -{ - return ((uint64_t)tag << MAX_BLOCK_SIZE) - + ((uint64_t)block << MIN_BLOCK_SIZE); -} - -static inline void pmp_napot_decode(uint64_t addr, uint64_t *base, - uint64_t *size) -{ - *base = ((addr + 1) & addr) << 2; - *size = (((addr + 1) ^ addr) + 1) << 2; -} - -static inline uint64_t pmp_napot_encode(uint64_t base, uint64_t size) -{ - return (base | (size / 2 - 1)) >> 2; -} - -bool cap_is_valid(const cap_t cap); -void cap_snprint(char *restrict buf, size_t size, cap_t cap); diff --git a/kernel/inc/csr.h b/kernel/inc/csr.h deleted file mode 100644 index 7afa69af..00000000 --- a/kernel/inc/csr.h +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @file csr.h - * @brief Interact with control and status registers. - * @copyright MIT License - * @author Henrik Karlsson (henrik10@kth.se) - */ -#pragma once - -/* Machine CSR constants */ -#define MIP_MSIP 0x8 -#define MIE_MSIE 0x8 -#define MIP_MTIP 0x80 -#define MIE_MTIE 0x80 -#define MCAUSE_USER_ECALL 0x8 -#define MSTATUS_MIE 0x8 - -#ifndef __ASSEMBLER__ -#define csrr(__reg) \ - ({ \ - unsigned long __ret; \ - __asm__ volatile("csrr %0," #__reg : "=r"(__ret)); \ - __ret; \ - }) -#define csrw(__reg, __val) \ - ({ __asm__ volatile("csrw " #__reg ", %0" ::"r"(__val)); }) -#define csrrw(__reg, __val) \ - ({ \ - unsigned long __ret; \ - __asm__ volatile("csrrw %0," #__reg ",%1" \ - : "=r"(__ret) \ - : "r"(__val)); \ - __ret; \ - }) -#define csrs(__reg, __val) \ - ({ __asm__ volatile("csrs " #__reg ", %0" ::"r"(__val)); }) -#define csrc(__reg, __val) \ - ({ __asm__ volatile("csrc " #__reg ", %0" ::"r"(__val)); }) -#endif diff --git a/kernel/inc/error.h b/kernel/inc/error.h deleted file mode 100644 index 158914ae..00000000 --- a/kernel/inc/error.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -typedef enum { - SUCCESS = 0, - ERR_EMPTY, - ERR_SRC_EMPTY, - ERR_DST_OCCUPIED, - ERR_INVALID_INDEX, - ERR_INVALID_DERIVATION, - ERR_INVALID_MONITOR, - ERR_INVALID_PID, - ERR_INVALID_STATE, - ERR_INVALID_PMP, - ERR_INVALID_SLOT, - ERR_INVALID_SOCKET, - ERR_INVALID_SYSCALL, - ERR_INVALID_REGISTER, - ERR_INVALID_CAPABILITY, - ERR_NO_RECEIVER, - ERR_PREEMPTED, - ERR_TIMEOUT, - ERR_SUSPENDED, - CONTINUE = -1, // Special for revocation -} err_t; diff --git a/kernel/inc/init.h b/kernel/inc/init.h deleted file mode 100644 index fcea1f9b..00000000 --- a/kernel/inc/init.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -/** - * @file init.h - * @brief Declares the initialization function for the kernel. - * - * This file contains the declaration of the `init_kernel()` function, which - * initializes the kernel with the given payload and starts the boot process. - * The payload parameter should be a pointer to the boot process's code, which - * will be executed by the kernel. - * - * @copyright MIT License - * @author Henrik Karlsson (henrik10@kth.se) - */ -#include - -/** - * @brief Initializes the kernel with the given payload, which is a pointer to - * the boot process's code. - * - * This function sets up the kernel's and the boot processes' initial state. - * The payload parameter should be a pointer to the boot process's code, which - * will be the first process to execute. - * - * @param payload A pointer to the boot process's code. - */ -void init_kernel(uint64_t payload); diff --git a/kernel/inc/interrupt.h b/kernel/inc/interrupt.h deleted file mode 100644 index 8ee25c8f..00000000 --- a/kernel/inc/interrupt.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once -#include -#include - -proc_t *interrupt_handler(proc_t *proc, uint64_t mcause, uint64_t mtval); diff --git a/kernel/inc/kernel.h b/kernel/inc/kernel.h deleted file mode 100644 index c1ae85c6..00000000 --- a/kernel/inc/kernel.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "proc.h" - -#include -#include - -void kernel_init(void); -uint64_t kernel_wcet(void); -uint64_t kernel_wcet_reset(void); - -void kernel_syscall_entry(void); -void kernel_syscall_exit(void); -bool kernel_preempt(void); diff --git a/kernel/inc/kprintf.h b/kernel/inc/kprintf.h deleted file mode 100644 index a1b7ede8..00000000 --- a/kernel/inc/kprintf.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include - -void kprintf(int verb, const char *restrict fmt, ...); diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h deleted file mode 100644 index cc5f3bcf..00000000 --- a/kernel/inc/proc.h +++ /dev/null @@ -1,127 +0,0 @@ -#pragma once -/** - * @file proc.h - * @brief Defines the process control block and its associated functions. - * - * This file contains the definition of the `proc_t` data structure, which - * represents a process control block (PCB) in the operating system. It also - * contains the declarations of functions for manipulating the PCB. - * - * @copyright MIT License - */ - -#include "cap_table.h" -#include "cap_types.h" - -#include -#include - -typedef uint64_t proc_state_t; - -typedef enum { - PSF_BUSY = 1, - PSF_BLOCKED = 2, - PSF_SUSPENDED = 4, -} proc_state_flag_t; - -typedef enum { - REG_PC, - REG_RA, - REG_SP, - REG_GP, - REG_TP, - REG_T0, - REG_T1, - REG_T2, - REG_S0, - REG_S1, - REG_A0, - REG_A1, - REG_A2, - REG_A3, - REG_A4, - REG_A5, - REG_A6, - REG_A7, - REG_S2, - REG_S3, - REG_S4, - REG_S5, - REG_S6, - REG_S7, - REG_S8, - REG_S9, - REG_S10, - REG_S11, - REG_T3, - REG_T4, - REG_T5, - REG_T6, - REG_TPC, - REG_TSP, - REG_EPC, - REG_ESP, - REG_ECAUSE, - REG_EVAL, - REG_SERVTIME, - /* Special value for number of registers */ - REG_CNT, -} reg_t; - -/** - * @brief Process control block. - * - * Contains all information needed manage a process except the capabilities. - */ -typedef struct { - /** Process state. */ - proc_state_t state; - /** The registers of the process (RISC-V registers and virtual - * registers). */ - uint64_t regs[REG_CNT]; - /** PMP registers */ - uint8_t pmpcfg[S3K_PMP_CNT]; - uint64_t pmpaddr[S3K_PMP_CNT]; - /** Instrumentation registers */ - /** Process ID. */ - pid_t pid; - - /** Scheduling information */ - uint64_t timeout; - /** - * Minimum remaining time required for receiving messages. - * If a client does not have sufficient execution time, - * it is not allowed to send the message. - */ - uint64_t serv_time; -} proc_t; - -/** - * Initializes all processes in the system. - * - * @note This function should be called only once during system startup. - */ -void proc_init(void); - -/** - * @brief Gets the process corresponding to a given process ID. - * - * @param pid The process ID to look for. - * @return A pointer to the process corresponding to the given PID. - */ -proc_t *proc_get(pid_t pid); - -proc_state_t proc_get_state(proc_t *proc); - -bool proc_acquire(proc_t *proc); -void proc_release(proc_t *proc); -void proc_suspend(proc_t *proc); -void proc_resume(proc_t *proc); -void proc_ipc_wait(proc_t *proc, chan_t chan); -bool proc_ipc_acquire(proc_t *proc, chan_t chan); -bool proc_is_suspended(proc_t *proc); - -bool proc_pmp_avail(proc_t *proc, pmp_slot_t slot); -void proc_pmp_load(proc_t *proc, pmp_slot_t slot, rwx_t cfg, napot_t addr); -void proc_pmp_unload(proc_t *proc, pmp_slot_t slot); -void proc_pmp_sync(proc_t *proc); diff --git a/kernel/inc/smp/mcslock.h b/kernel/inc/smp/mcslock.h deleted file mode 100644 index 55f4a3e8..00000000 --- a/kernel/inc/smp/mcslock.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include -#include - -typedef struct qnode { - struct qnode *next; - struct qnode *prev; - uint64_t state; -} qnode_t; - -typedef struct mcslock { - struct qnode tail; -} mcslock_t; - -void mcslock_init(mcslock_t *lock); -bool mcslock_try_acquire(mcslock_t *lock, qnode_t *qnode); -void mcslock_acquire(mcslock_t *lock, qnode_t *qnode); -void mcslock_release(mcslock_t *lock, qnode_t *qnode); diff --git a/kernel/inc/syscall.h b/kernel/inc/syscall.h deleted file mode 100644 index dabafc6d..00000000 --- a/kernel/inc/syscall.h +++ /dev/null @@ -1,159 +0,0 @@ -#pragma once - -#include "cap_types.h" -#include "macro.h" -#include "proc.h" - -#include - -typedef enum { - // Basic Info & Registers - SYS_GET_INFO, // Retrieve basic system information - SYS_REG_READ, // Set the value of a specific register - SYS_REG_WRITE, // Get the value of a specific register - SYS_SYNC, // Synchronize with capabilities/scheduling - SYS_SLEEP, - - // Capability Management - SYS_CAP_READ, // Read the properties of a capability - SYS_CAP_MOVE, // Move a capability to a different slot - SYS_CAP_DELETE, // Remove a capability from the system - SYS_CAP_REVOKE, // Revoke a derived capabilities - SYS_CAP_DERIVE, // Derive a new capability from an existing one - - // PMP - SYS_PMP_LOAD, - SYS_PMP_UNLOAD, - - // Monitor - SYS_MON_SUSPEND, - SYS_MON_RESUME, - SYS_MON_STATE_GET, - SYS_MON_YIELD, - SYS_MON_REG_READ, - SYS_MON_REG_WRITE, - SYS_MON_CAP_READ, - SYS_MON_CAP_MOVE, - SYS_MON_PMP_LOAD, - SYS_MON_PMP_UNLOAD, - - // Socket - SYS_SOCK_SEND, - SYS_SOCK_RECV, - SYS_SOCK_SENDRECV, -} syscall_t; - -typedef union { - struct { - uint64_t a0, a1, a2, a3, a4, a5, a6, a7; - }; - - struct { - uint64_t info; - } get_info; - - struct { - uint64_t reg; - } reg_read; - - struct { - uint64_t reg; - uint64_t val; - } reg_write; - - struct { - uint64_t full; - } sync; - - struct { - uint64_t time; - } sleep; - - struct { - uint64_t idx; - } cap_read; - - struct { - uint64_t src_idx; - uint64_t dst_idx; - } cap_move; - - struct { - uint64_t idx; - } cap_delete; - - struct { - uint64_t idx; - } cap_revoke; - - struct { - uint64_t src_idx; - uint64_t dst_idx; - uint64_t cap_raw; - } cap_derive; - - struct { - uint64_t idx; - uint64_t slot; - } pmp_load; - - struct { - uint64_t idx; - } pmp_unload; - - struct { - uint64_t mon_idx; - uint64_t pid; - } mon_state; - - struct { - uint64_t mon_idx; - uint64_t pid; - uint64_t reg; - } mon_reg_read; - - struct { - uint64_t mon_idx; - uint64_t pid; - uint64_t reg; - uint64_t val; - } mon_reg_write; - - struct { - uint64_t mon_idx; - uint64_t pid; - uint64_t idx; - } mon_cap_read; - - struct { - uint64_t mon_idx; - uint64_t src_pid; - uint64_t src_idx; - uint64_t dst_pid; - uint64_t dst_idx; - } mon_cap_move; - - struct { - uint64_t mon_idx; - uint64_t pid; - uint64_t idx; - uint64_t slot; - } mon_pmp_load; - - struct { - uint64_t mon_idx; - uint64_t pid; - uint64_t idx; - } mon_pmp_unload; - - struct { - uint64_t sock_idx; - uint64_t cap_idx; - uint64_t send_cap; - uint64_t data[4]; - } sock; -} sys_args_t; - -_Static_assert(sizeof(sys_args_t) == 64, "sys_args_t has the wrong size"); - -proc_t *syscall_handler(proc_t *proc); diff --git a/kernel/inc/uart.h b/kernel/inc/uart.h deleted file mode 100644 index abdd46cd..00000000 --- a/kernel/inc/uart.h +++ /dev/null @@ -1,144 +0,0 @@ -#pragma once -#include - -/* Initializes UART */ -static inline void uart_init(void); -/* Puts one character in UART */ -static inline int uart_putc(char c); -/* Gets one character from UART */ -static inline int uart_getc(void); -/* Puts a string to UART */ -static inline int uart_write(const char *s, int size); -/* Gets a NUL terminated string */ -static inline int uart_read(char *s, int size); - -#if defined(UART_NS16550A) -/* Driver for ns16550a UART. */ -struct uart { - union { - char rbr; // Receiver buffer register (read only) - char thr; // Transmitter holding register (write only) - }; - - char ier; // Interrupt enabler register - - union { - char iir; // Interrupt identification register (read only) - char fcr; // FIFO control register (write only) - }; - - char lcr; // Line control register - char __padding; - char lsr; // Line status register -}; - -static volatile struct uart *UART0 = (volatile struct uart *)UART0_BASE_ADDR; - -// Line status register flags -#define LSR_RX_READY 0x1 // Receive data ready -#define LSR_TX_READY 0x60 // Transmit data ready - -void uart_init(void) -{ - UART0->lcr = 0x3; - UART0->fcr = 0x1; -} - -int uart_putc(char c) -{ - while (!(UART0->lsr & LSR_TX_READY)) - ; - UART0->thr = (unsigned char)c; - return (unsigned char)c; -} - -int uart_getc(void) -{ - while (!(UART0->lsr & LSR_RX_READY)) - ; - return UART0->rbr; -} - -#elif defined(UART_SIFIVE) - -/* Driver for SiFive's UART */ - -struct uart { - int txdata; // Transmit data register - int rxdata; // Receive data register - int txctrl; // Transmit control register - int rxctrl; // Receive control register - int ie; // UART interrupt enable - int ip; // UART interrupt pending - int div; // Baud rate divisor -}; - -static volatile struct uart *const UART0 - = (volatile struct uart *)UART0_BASE_ADDR; - -// Bit masks for transmit and receive adata registers -#define TXDATA_FULL 0x80000000ul -#define RXDATA_EMPTY 0x80000000ul - -// Control register flags for enabling transmission and reception -#define TXCTRL_TXEN 0x1ul -#define RXCTRL_RXEN 0x1ul - -// Control register flags for setting stop bits -#define TXCTRL_NSTOP 0x2ul - -#define TLCLK 500000000ull -#define TARGET_BAUD_RATE 115200ull - -void uart_init(void) -{ - UART0->txctrl = TXCTRL_TXEN; // Enable transmit data - UART0->rxctrl = RXCTRL_RXEN; // Enable receive data - UART0->div = TLCLK / TARGET_BAUD_RATE; -} - -int uart_putc(char c) -{ - while (UART0->txdata & TXDATA_FULL) { - } - UART0->txdata = (unsigned char)c; - return (unsigned char)c; -} - -int uart_getc(void) -{ - int c; - do { - c = UART0->rxdata; - } while (c & RXDATA_EMPTY); - return c; -} -#else -#error "Missing UART" -#endif - -int uart_write(const char *s, int size) -{ - if (s == NULL) - return 0; - - int i = 0; - for (i = 0; i < size && s[i] != '\0'; i++) - uart_putc(s[i]); - return i; -} - -int uart_read(char *s, int size) -{ - if (s == NULL || size <= 0) - return 0; - - int i; - for (i = 0; i < size - 1; ++i) { - s[i] = uart_getc(); - if (s[i] == '\n' || s[i] == '\r') - break; - } - s[i] = '\0'; - return i; -} diff --git a/kernel/src/cap_ipc.c b/kernel/src/cap_ipc.c deleted file mode 100644 index 5466b57d..00000000 --- a/kernel/src/cap_ipc.c +++ /dev/null @@ -1,239 +0,0 @@ -#include "cap_ipc.h" - -#include "altc/string.h" -#include "cap_ops.h" -#include "cap_table.h" -#include "csr.h" -#include "drivers/time.h" -#include "error.h" -#include "kassert.h" -#include "kernel.h" -#include "macro.h" -#include "proc.h" - -#include - -#define SERVER 0 -#define CLIENT 1 - -struct { - proc_t *server; - proc_t *client; - cte_t cap_buf; -} channels[S3K_CHAN_CNT]; - -static err_t do_send(cap_t cap, const ipc_msg_t *msg, proc_t **next) -{ - bool is_server = (cap.sock.tag == 0); - cte_t cap_buf = channels[cap.sock.chan].cap_buf; - - uint64_t curr_time = time_get(); - uint64_t timeout = timeout_get(csrr(mhartid)); - - if (curr_time >= timeout) { - return ERR_PREEMPTED; - } - - proc_t *recv; - - if (is_server) { - recv = channels[cap.sock.chan].client; - if (!recv) - return ERR_NO_RECEIVER; - channels[cap.sock.chan].client = NULL; - } else { - recv = channels[cap.sock.chan].server; - if (!recv) - return ERR_NO_RECEIVER; - if (cap.sock.mode == IPC_YIELD - && curr_time + recv->regs[REG_SERVTIME] >= timeout) - return ERR_NO_RECEIVER; - channels[cap.sock.chan].server = NULL; - } - - if (proc_ipc_acquire(recv, cap.sock.chan)) { - recv->regs[REG_T0] = SUCCESS; - recv->regs[REG_A0] = cap.sock.tag; - recv->regs[REG_A2] = msg->data[0]; - recv->regs[REG_A3] = msg->data[1]; - recv->regs[REG_A4] = msg->data[2]; - recv->regs[REG_A5] = msg->data[3]; - - if (msg->send_cap) { - recv->regs[REG_A1] = cte_cap(msg->cap_buf).raw; - cap_move(msg->cap_buf, cap_buf); - } else { - recv->regs[REG_A1] = 0; - } - - if (cap.sock.mode == IPC_YIELD) { - recv->timeout = (*next)->timeout; - *next = recv; - } else if (cap.sock.mode == IPC_NOYIELD) { - recv->timeout = 0; - proc_release(recv); - } else { - KASSERT(0); - } - return SUCCESS; - } - return ERR_NO_RECEIVER; -} - -static void do_recv(cap_t cap, cte_t cap_buf, proc_t *recv) -{ - bool is_server = (cap.sock.tag == 0); - if (is_server) { - channels[cap.sock.chan].server = recv; - channels[cap.sock.chan].cap_buf = cap_buf; - recv->timeout = UINT64_MAX; - proc_ipc_wait(recv, cap.sock.chan); - } else { - channels[cap.sock.chan].client = recv; - channels[cap.sock.chan].cap_buf = cap_buf; - if (cap.sock.mode == IPC_NOYIELD) - recv->timeout = UINT64_MAX; - proc_ipc_wait(recv, cap.sock.chan); - } -} - -static err_t reply(cte_t sock, cap_t cap, const ipc_msg_t *msg, proc_t **next) -{ - if (msg->send_cap && !(cap.sock.perm & IPC_SCAP)) - return ERR_INVALID_SOCKET; - return do_send(cap, msg, next); -} - -static err_t send(cte_t sock, cap_t cap, const ipc_msg_t *msg, proc_t **next) -{ - if (msg->send_cap && !(cap.sock.perm & IPC_CCAP)) - return ERR_INVALID_SOCKET; - return do_send(cap, msg, next); -} - -static err_t recv(cte_t sock, cap_t cap, cte_t cap_buf, proc_t **next) -{ - do_recv(cap, cap_buf, *next); - *next = NULL; - return ERR_TIMEOUT; -} - -static err_t replyrecv(cte_t sock, cap_t cap, const ipc_msg_t *msg, - proc_t **next) -{ - cte_t cap_buf = msg->cap_buf; - proc_t *server = *next; - KASSERT(server->state == PSF_BUSY); - - // Can send capability? - if (msg->send_cap && !(cap.sock.perm & IPC_SCAP)) - return ERR_INVALID_SOCKET; - - // Can receive capability? - if ((cap.sock.perm & IPC_CCAP) && !cte_is_empty(cap_buf) - && !msg->send_cap) - return ERR_DST_OCCUPIED; - - err_t err = do_send(cap, msg, next); - if (err == ERR_PREEMPTED) { - *next = NULL; - return err; - } else if (err == ERR_NO_RECEIVER && msg->send_cap) { - cap_delete(msg->cap_buf); - } - do_recv(cap, cap_buf, server); - if (*next == server) - *next = NULL; - return ERR_TIMEOUT; -} - -static err_t call(cte_t sock, cap_t cap, const ipc_msg_t *msg, proc_t **next) -{ - cte_t cap_buf = msg->cap_buf; - proc_t *client = *next; - - // Can send capability? - if (msg->send_cap && !(cap.sock.perm & IPC_CCAP)) - return ERR_INVALID_SOCKET; - - // Can receive capability? - if ((cap.sock.perm & IPC_SCAP) && !cte_is_empty(cap_buf) - && !msg->send_cap) - return ERR_DST_OCCUPIED; - - err_t err = do_send(cap, msg, next); - if (err) - return err; - do_recv(cap, cap_buf, client); - if (*next == client) - *next = NULL; - return ERR_TIMEOUT; -} - -/* Entry points */ -err_t cap_sock_send(cte_t sock, const ipc_msg_t *msg, proc_t **next) -{ - cap_t cap = cte_cap(sock); - if (cap.type == CAPTY_NONE) - return ERR_EMPTY; - if (cap.type != CAPTY_SOCKET) - return ERR_INVALID_SOCKET; - if ((*next)->state & PSF_SUSPENDED) { - *next = NULL; - return ERR_PREEMPTED; - } - if (cap.sock.tag == 0) { - return reply(sock, cap, msg, next); - } else { - return send(sock, cap, msg, next); - } -} - -err_t cap_sock_recv(cte_t sock, cte_t cap_buf, proc_t **next) -{ - cap_t cap = cte_cap(sock); - if (cap.type == CAPTY_NONE) - return ERR_EMPTY; - if (cap.type != CAPTY_SOCKET) - return ERR_INVALID_CAPABILITY; - if (cap.sock.tag != 0) - return ERR_INVALID_SOCKET; - if ((cap.sock.perm & IPC_CCAP) && !cte_is_empty(cap_buf)) - return ERR_DST_OCCUPIED; - if ((*next)->state & PSF_SUSPENDED) { - *next = NULL; - return ERR_PREEMPTED; - } - return recv(sock, cap, cap_buf, next); -} - -err_t cap_sock_sendrecv(cte_t sock, const ipc_msg_t *msg, proc_t **next) -{ - cap_t cap = cte_cap(sock); - if (cap.type == CAPTY_NONE) - return ERR_EMPTY; - if (cap.type != CAPTY_SOCKET) - return ERR_INVALID_CAPABILITY; - if ((*next)->state & PSF_SUSPENDED) { - *next = NULL; - return ERR_PREEMPTED; - } - KASSERT((*next)->state == PSF_BUSY); - - if (cap.sock.tag == 0) { - return replyrecv(sock, cap, msg, next); - } else { - return call(sock, cap, msg, next); - } -} - -void cap_sock_clear(cap_t cap, proc_t *p) -{ - if (cap.sock.tag == 0) { - channels[cap.sock.chan].server = NULL; - channels[cap.sock.chan].client = NULL; - channels[cap.sock.chan].cap_buf = NULL; - } else if (channels[cap.sock.chan].client == p) { - channels[cap.sock.chan].client = NULL; - } -} diff --git a/kernel/src/cap_lock.c b/kernel/src/cap_lock.c deleted file mode 100644 index 6df90292..00000000 --- a/kernel/src/cap_lock.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "cap_lock.h" - -#include "csr.h" -#include "smp/taslock.h" - -#ifdef SMP -static taslock_t lock; - -void cap_lock_init(void) -{ - taslock_init(&lock); -} - -bool cap_lock_acquire(void) -{ - return taslock_acquire(&lock); -} - -void cap_lock_release(void) -{ - taslock_release(&lock); -} -#endif diff --git a/kernel/src/cap_monitor.c b/kernel/src/cap_monitor.c deleted file mode 100644 index 17de2fc9..00000000 --- a/kernel/src/cap_monitor.c +++ /dev/null @@ -1,119 +0,0 @@ -#include "cap_monitor.h" - -#include "cap_ops.h" -#include "cap_pmp.h" -#include "proc.h" - -static err_t check_monitor(cte_t mon, pid_t pid, bool check_suspended) -{ - cap_t mon_cap = cte_cap(mon); - if (mon_cap.type != CAPTY_MONITOR || mon_cap.mon.mrk > pid - || pid >= mon_cap.mon.end) - return ERR_INVALID_MONITOR; - if (check_suspended && !proc_is_suspended(proc_get(pid))) - return ERR_INVALID_STATE; - return SUCCESS; -} - -static err_t check_monitor_move(cte_t mon, cte_t src, cte_t dst) -{ - uint64_t mon_pid = cte_pid(mon); - uint64_t src_pid = cte_pid(src); - uint64_t dst_pid = cte_pid(dst); - err_t err; - if (mon_pid != src_pid && (err = check_monitor(mon, src_pid, true))) - return err; - if (mon_pid != dst_pid && (err = check_monitor(mon, dst_pid, true))) - return err; - return SUCCESS; -} - -err_t cap_monitor_suspend(cte_t mon, pid_t pid) -{ - err_t err = check_monitor(mon, pid, false); - if (!err) - proc_suspend(proc_get(pid)); - return err; -} - -err_t cap_monitor_resume(cte_t mon, pid_t pid) -{ - err_t err = check_monitor(mon, pid, false); - if (!err) - proc_resume(proc_get(pid)); - return err; -} - -err_t cap_monitor_state_get(cte_t mon, pid_t pid, proc_state_t *state) -{ - err_t err = check_monitor(mon, pid, false); - if (!err) { - proc_t *proc = proc_get(pid); - *state = proc->state; - } - return err; -} - -err_t cap_monitor_yield(cte_t mon, pid_t pid, proc_t **next) -{ - err_t err = check_monitor(mon, pid, false); - if (!err) { - proc_t *monitor = *next; - proc_t *proc = proc_get(pid); - if (proc_acquire(proc)) { - *next = proc; - proc_release(monitor); - return SUCCESS; - } - return ERR_INVALID_STATE; - } - return err; -} - -err_t cap_monitor_reg_read(cte_t mon, pid_t pid, reg_t reg, uint64_t *val) -{ - err_t err = check_monitor(mon, pid, true); - if (!err) - *val = proc_get(pid)->regs[reg]; - return err; -} - -err_t cap_monitor_reg_write(cte_t mon, pid_t pid, reg_t reg, uint64_t val) -{ - err_t err = check_monitor(mon, pid, true); - if (!err) - proc_get(pid)->regs[reg] = val; - return err; -} - -err_t cap_monitor_cap_read(cte_t mon, cte_t src, cap_t *cap) -{ - err_t err = check_monitor(mon, cte_pid(src), true); - if (!err) - err = cap_read(src, cap); - return err; -} - -err_t cap_monitor_cap_move(cte_t mon, cte_t src, cte_t dst) -{ - err_t err = check_monitor_move(mon, src, dst); - if (!err) - err = cap_move(src, dst); - return err; -} - -err_t cap_monitor_pmp_load(cte_t mon, cte_t pmp, pmp_slot_t slot) -{ - err_t err = check_monitor(mon, cte_pid(pmp), true); - if (!err) - err = cap_pmp_load(pmp, slot); - return err; -} - -err_t cap_monitor_pmp_unload(cte_t mon, cte_t pmp) -{ - err_t err = check_monitor(mon, cte_pid(pmp), true); - if (!err) - err = cap_pmp_unload(pmp); - return err; -} diff --git a/kernel/src/cap_ops.c b/kernel/src/cap_ops.c deleted file mode 100644 index d9d392aa..00000000 --- a/kernel/src/cap_ops.c +++ /dev/null @@ -1,426 +0,0 @@ -#include "cap_ops.h" - -#include "cap_ipc.h" -#include "cap_util.h" -#include "kernel.h" -#include "sched.h" - -typedef err_t (*ipc_move_handler)(cte_t, cap_t, cte_t); -typedef err_t (*delete_handler)(cte_t, cap_t); -typedef err_t (*revoke_handler)(cte_t, cap_t); -typedef err_t (*derive_handler)(cte_t, cap_t, cte_t, cap_t); - -static err_t cap_delete_time(cte_t src, cap_t cap); -static err_t cap_delete_memory(cte_t src, cap_t cap); -static err_t cap_delete_pmp(cte_t src, cap_t cap); -static err_t cap_delete_monitor(cte_t src, cap_t cap); -static err_t cap_delete_channel(cte_t src, cap_t cap); -static err_t cap_delete_socket(cte_t src, cap_t cap); - -static err_t cap_revoke_time(cte_t src, cap_t cap); -static err_t cap_revoke_memory(cte_t src, cap_t cap); -static err_t cap_revoke_pmp(cte_t src, cap_t cap); -static err_t cap_revoke_monitor(cte_t src, cap_t cap); -static err_t cap_revoke_channel(cte_t src, cap_t cap); -static err_t cap_revoke_socket(cte_t src, cap_t cap); - -static err_t cap_derive_time(cte_t src, cap_t cap, cte_t dst, cap_t new_cap); -static err_t cap_derive_memory(cte_t src, cap_t cap, cte_t dst, cap_t new_cap); -static err_t cap_derive_pmp(cte_t src, cap_t cap, cte_t dst, cap_t new_cap); -static err_t cap_derive_monitor(cte_t src, cap_t cap, cte_t dst, cap_t new_cap); -static err_t cap_derive_channel(cte_t src, cap_t cap, cte_t dst, cap_t new_cap); -static err_t cap_derive_socket(cte_t src, cap_t cap, cte_t dst, cap_t new_cap); - -static const delete_handler delete_handlers[CAPTY_COUNT] = { - NULL, - cap_delete_time, - cap_delete_memory, - cap_delete_pmp, - cap_delete_monitor, - cap_delete_channel, - cap_delete_socket, -}; -static const revoke_handler revoke_handlers[CAPTY_COUNT] = { - NULL, - cap_revoke_time, - cap_revoke_memory, - cap_revoke_pmp, - cap_revoke_monitor, - cap_revoke_channel, - cap_revoke_socket, -}; -static const derive_handler derive_handlers[CAPTY_COUNT] = { - NULL, - cap_derive_time, - cap_derive_memory, - cap_derive_pmp, - cap_derive_monitor, - cap_derive_channel, - cap_derive_socket, -}; - -err_t cap_read(cte_t c, cap_t *cap) -{ - *cap = cte_cap(c); - return cap->raw ? SUCCESS : ERR_EMPTY; -} - -static void cap_ipc_move_hook(cte_t src, cte_t dst) -{ - cap_t cap = cte_cap(src); - switch (cap.type) { - case CAPTY_TIME: { - sched_update(cte_pid(dst), cap.time.end, cap.time.hart, - cap.time.mrk, cap.time.end); - } break; - case CAPTY_PMP: { - if (cap.pmp.used) { - proc_pmp_unload(proc_get(cte_pid(src)), cap.pmp.slot); - cap.pmp.used = 0; - cap.pmp.slot = 0; - cte_set_cap(src, cap); - } - } break; - default: - break; - } -} - -err_t cap_move(cte_t src, cte_t dst) -{ - if (cte_is_empty(src)) - return ERR_SRC_EMPTY; - if (!cte_is_empty(dst)) - return ERR_DST_OCCUPIED; - if (cte_pid(src) != cte_pid(dst)) - cap_ipc_move_hook(src, dst); - cte_move(src, dst); - return SUCCESS; -} - -err_t cap_delete(cte_t c) -{ - if (cte_is_empty(c)) - return ERR_EMPTY; - cap_t cap = cte_cap(c); - return delete_handlers[cap.type](c, cap); -} - -err_t cap_revoke(cte_t parent) -{ - cap_t pcap = cte_cap(parent); - if (pcap.type == CAPTY_NONE) - return ERR_EMPTY; - int err; - do { - err = revoke_handlers[pcap.type](parent, cte_cap(parent)); - } while (err < 0 && !kernel_preempt()); - return err < 0 ? ERR_PREEMPTED : SUCCESS; -} - -err_t cap_derive(cte_t src, cte_t dst, cap_t ncap) -{ - if (cte_is_empty(src)) - return ERR_SRC_EMPTY; - - if (!cte_is_empty(dst)) - return ERR_DST_OCCUPIED; - - cap_t scap = cte_cap(src); - return derive_handlers[scap.type](src, scap, dst, ncap); -} - -/********** HANDLERS ***********/ - -err_t cap_delete_time(cte_t c, cap_t cap) -{ - sched_delete(cap.time.hart, cap.time.mrk, cap.time.end); - cte_delete(c); - return SUCCESS; -} - -err_t cap_revoke_time(cte_t parent, cap_t pcap) -{ - cte_t child = cte_next(parent); - cap_t ccap = cte_cap(child); - if (ccap.type == CAPTY_TIME && pcap.time.hart == ccap.time.hart - && pcap.time.bgn <= ccap.time.bgn - && ccap.time.end <= pcap.time.end) { - // delete the child - cte_delete(child); - - // Update schedule. - uint64_t pid = cte_pid(parent); - uint64_t end = pcap.time.end; - uint64_t hartid = pcap.time.hart; - uint64_t from = ccap.time.mrk; - uint64_t to = pcap.time.mrk; - sched_update(pid, end, hartid, from, to); - - // Update parent. - pcap.time.mrk = ccap.time.mrk; - cte_set_cap(parent, pcap); - return pcap.time.mrk == pcap.time.bgn ? SUCCESS : CONTINUE; - } - - // Update schedule. - uint64_t pid = cte_pid(parent); - uint64_t end = pcap.time.end; - uint64_t hartid = pcap.time.hart; - uint64_t from = pcap.time.bgn; - uint64_t to = pcap.time.mrk; - sched_update(pid, end, hartid, from, to); - - // Update parent. - pcap.time.mrk = pcap.time.bgn; - cte_set_cap(parent, pcap); - return SUCCESS; -} - -err_t cap_derive_time(cte_t src, cap_t cap, cte_t dst, cap_t new_cap) -{ - if (new_cap.type == CAPTY_TIME && new_cap.time.hart == cap.time.hart - && new_cap.time.bgn == cap.time.mrk - && new_cap.time.end <= cap.time.end) { - sched_update(cte_pid(dst), new_cap.time.end, new_cap.time.hart, - new_cap.time.bgn, new_cap.time.end); - cap.time.mrk = new_cap.time.end; - cte_set_cap(src, cap); - cte_insert(dst, new_cap, src); - return SUCCESS; - } - return ERR_INVALID_DERIVATION; -} - -err_t cap_delete_memory(cte_t c, cap_t cap) -{ - cte_delete(c); - return SUCCESS; -} - -err_t cap_revoke_memory(cte_t parent, cap_t pcap) -{ - cte_t child = cte_next(parent); - cap_t ccap = cte_cap(child); - if (ccap.type == CAPTY_MEMORY && pcap.mem.tag == ccap.mem.tag - && pcap.mem.bgn <= ccap.mem.bgn) { - // delete the child - cte_delete(child); - - // Update parent. - pcap.mem.mrk = ccap.mem.mrk; - pcap.mem.lck = ccap.mem.lck; - cte_set_cap(parent, pcap); - - return (pcap.mem.mrk == pcap.mem.bgn && !pcap.mem.lck) ? - SUCCESS : - CONTINUE; - } - - uint64_t base, size; - pmp_napot_decode(ccap.pmp.addr, &base, &size); - - if (ccap.type == CAPTY_PMP - && tag_block_to_addr(pcap.mem.tag, pcap.mem.bgn) <= base) { - // delete the child - cte_delete(child); - - // Clear PMP config - if (ccap.pmp.used) { - proc_pmp_unload(proc_get(cte_pid(child)), - ccap.pmp.slot); - } - - return CONTINUE; - } - - pcap.mem.mrk = pcap.mem.bgn; - pcap.mem.lck = 0; - cte_set_cap(parent, pcap); - - return SUCCESS; -} - -err_t cap_derive_memory(cte_t src, cap_t cap, cte_t dst, cap_t new_cap) -{ - if (new_cap.type == CAPTY_MEMORY && cap.mem.tag == new_cap.mem.tag - && cap.mem.tag == new_cap.mem.tag && cap.mem.mrk <= new_cap.mem.bgn - && new_cap.mem.end <= cap.mem.end - && (new_cap.mem.rwx & cap.mem.rwx) == new_cap.mem.rwx - && !cap.mem.lck) { - cap.mem.mrk = new_cap.mem.end; - cte_set_cap(src, cap); - cte_insert(dst, new_cap, src); - return SUCCESS; - } - - uint64_t pmp_begin, pmp_end; - uint64_t mem_mrk, mem_end; - pmp_napot_decode(new_cap.pmp.addr, &pmp_begin, &pmp_end); - pmp_end += pmp_begin; - mem_mrk = tag_block_to_addr(cap.mem.tag, cap.mem.mrk); - mem_end = tag_block_to_addr(cap.mem.tag, cap.mem.end); - - if (new_cap.type == CAPTY_PMP && mem_mrk <= pmp_begin - && pmp_end <= mem_end - && (new_cap.pmp.rwx & cap.mem.rwx) == new_cap.pmp.rwx) { - cap.mem.lck = true; - cte_set_cap(src, cap); - cte_insert(dst, new_cap, src); - return SUCCESS; - } - return ERR_INVALID_DERIVATION; -} - -err_t cap_delete_pmp(cte_t c, cap_t cap) -{ - proc_t *proc = proc_get(cte_pid(c)); - if (cap.pmp.used) - proc_pmp_unload(proc, cap.pmp.slot); - cte_delete(c); - return SUCCESS; -} - -err_t cap_revoke_pmp(cte_t parent, cap_t pcap) -{ - return SUCCESS; -} - -err_t cap_derive_pmp(cte_t src, cap_t cap, cte_t dst, cap_t new_cap) -{ - return ERR_INVALID_DERIVATION; -} - -err_t cap_delete_monitor(cte_t c, cap_t cap) -{ - cte_delete(c); - return SUCCESS; -} - -err_t cap_revoke_monitor(cte_t parent, cap_t pcap) -{ - cte_t child = cte_next(parent); - cap_t ccap = cte_cap(child); - if (ccap.type == CAPTY_MONITOR && pcap.mon.bgn <= ccap.mon.bgn) { - // delete the child - cte_delete(child); - - // Update parent. - pcap.mon.mrk = ccap.mon.mrk; - cte_set_cap(parent, pcap); - - return (pcap.mon.mrk == pcap.mon.bgn) ? SUCCESS : CONTINUE; - } - - pcap.mon.mrk = pcap.mon.bgn; - cte_set_cap(parent, pcap); - - return SUCCESS; -} - -err_t cap_derive_monitor(cte_t src, cap_t cap, cte_t dst, cap_t new_cap) -{ - if (new_cap.type == CAPTY_MONITOR && cap.mon.mrk <= new_cap.mon.bgn - && new_cap.mon.end <= cap.mon.end) { - cap.mon.mrk = new_cap.mon.end; - cte_set_cap(src, cap); - cte_insert(dst, new_cap, src); - return SUCCESS; - } - return ERR_INVALID_DERIVATION; -} - -err_t cap_delete_channel(cte_t c, cap_t cap) -{ - cte_delete(c); - return SUCCESS; -} - -err_t cap_revoke_channel(cte_t parent, cap_t pcap) -{ - cte_t child = cte_next(parent); - cap_t ccap = cte_cap(child); - if (ccap.type == CAPTY_CHANNEL && pcap.chan.bgn <= ccap.chan.bgn) { - // delete the child - cte_delete(child); - - // Update parent. - pcap.chan.mrk = ccap.chan.mrk; - cte_set_cap(parent, pcap); - - return (pcap.chan.mrk == pcap.chan.bgn) ? SUCCESS : CONTINUE; - } - - if (ccap.type == CAPTY_SOCKET && pcap.chan.bgn <= ccap.sock.chan) { - // delete the child - cte_delete(child); - - // Clear socket - cap_sock_clear(ccap, proc_get(cte_pid(child))); - - return CONTINUE; - } - - pcap.chan.mrk = pcap.chan.bgn; - cte_set_cap(parent, pcap); - - return SUCCESS; -} - -err_t cap_derive_channel(cte_t src, cap_t cap, cte_t dst, cap_t new_cap) -{ - if (new_cap.type == CAPTY_CHANNEL && cap.chan.mrk <= new_cap.chan.bgn - && new_cap.chan.end <= cap.chan.end) { - cap.chan.mrk = new_cap.chan.end; - cte_set_cap(src, cap); - cte_insert(dst, new_cap, src); - return SUCCESS; - } - - if (new_cap.type == CAPTY_SOCKET && cap.chan.mrk <= new_cap.sock.chan - && new_cap.sock.chan < cap.chan.end) { - cap.chan.mrk = new_cap.sock.chan + 1; - cte_set_cap(src, cap); - cte_insert(dst, new_cap, src); - return SUCCESS; - } - return ERR_INVALID_DERIVATION; -} - -err_t cap_delete_socket(cte_t c, cap_t cap) -{ - proc_t *proc = proc_get(cte_pid(c)); - cap_sock_clear(cap, proc); - cte_delete(c); - return SUCCESS; -} - -err_t cap_revoke_socket(cte_t parent, cap_t pcap) -{ - cte_t child = cte_next(parent); - cap_t ccap = cte_cap(child); - if (ccap.type == CAPTY_SOCKET && pcap.sock.chan == ccap.sock.chan - && pcap.sock.tag == 0) { - // delete the child - cte_delete(child); - - // Clear socket - cap_sock_clear(ccap, proc_get(cte_pid(child))); - - return CONTINUE; - } - - return SUCCESS; -} - -err_t cap_derive_socket(cte_t src, cap_t cap, cte_t dst, cap_t new_cap) -{ - if (new_cap.type == CAPTY_SOCKET && new_cap.sock.chan == cap.sock.chan - && new_cap.sock.perm == cap.sock.perm - && new_cap.sock.mode == cap.sock.mode && cap.sock.tag == 0 - && new_cap.sock.tag != 0) { - cte_insert(dst, new_cap, src); - return SUCCESS; - } - return ERR_INVALID_DERIVATION; -} diff --git a/kernel/src/cap_pmp.c b/kernel/src/cap_pmp.c deleted file mode 100644 index 3b1d07aa..00000000 --- a/kernel/src/cap_pmp.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "cap_table.h" -#include "cap_types.h" -#include "error.h" -#include "kernel.h" - -err_t cap_pmp_load(cte_t pmp, pmp_slot_t slot) -{ - proc_t *proc = proc_get(cte_pid(pmp)); - cap_t cap = cte_cap(pmp); - if (cap.type == CAPTY_NONE) - return ERR_EMPTY; - if (cap.type != CAPTY_PMP || cap.pmp.used) - return ERR_INVALID_PMP; - if (!proc_pmp_avail(proc, slot)) - return ERR_DST_OCCUPIED; - - proc_pmp_load(proc, slot, cap.pmp.rwx, cap.pmp.addr); - cap.pmp.slot = slot; - cap.pmp.used = 1; - cte_set_cap(pmp, cap); - return SUCCESS; -} - -err_t cap_pmp_unload(cte_t pmp) -{ - proc_t *proc = proc_get(cte_pid(pmp)); - cap_t cap = cte_cap(pmp); - - if (cap.type == CAPTY_NONE) - return ERR_EMPTY; - if (cap.type != CAPTY_PMP || !cap.pmp.used) - return ERR_INVALID_PMP; - - proc_pmp_unload(proc, cap.pmp.slot); - cap.pmp.slot = 0; - cap.pmp.used = 0; - cte_set_cap(pmp, cap); - return SUCCESS; -} diff --git a/kernel/src/cap_table.c b/kernel/src/cap_table.c deleted file mode 100644 index 8662a4b8..00000000 --- a/kernel/src/cap_table.c +++ /dev/null @@ -1,111 +0,0 @@ -#include "cap_table.h" - -#include "cap_util.h" -#include "kassert.h" - -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) - -struct cte { - uint32_t prev, next; - cap_t cap; -}; - -static struct cte ctable[S3K_PROC_CNT * S3K_CAP_CNT]; - -static uint32_t offset(cte_t c) -{ - return (uint32_t)(c - ctable); -} - -void ctable_init(void) -{ - const cap_t init_caps[] = INIT_CAPS; - cte_t prev = ctable; - kprintf(0, "# Initial capabilities:\n"); - for (unsigned int i = 0; i < ARRAY_SIZE(init_caps); ++i) { - if (init_caps[i].type == CAPTY_NONE) - continue; - cte_insert(&ctable[i], init_caps[i], prev); - - char buf[128]; - cap_snprint(buf, 128, init_caps[i]); - kprintf(0, "#\t%d: %s\n", i, buf); - } -} - -cte_t ctable_get(uint64_t pid, uint64_t index) -{ - KASSERT(pid < S3K_PROC_CNT); - KASSERT(index < S3K_CAP_CNT); - return &ctable[pid * S3K_CAP_CNT + index]; -} - -bool cte_is_empty(cte_t c) -{ - return c->cap.type == 0; -} - -void cte_set_next(cte_t c, cte_t next) -{ - c->next = offset(next); -} - -void cte_set_prev(cte_t c, cte_t prev) -{ - c->prev = offset(prev); -} - -void cte_set_cap(cte_t c, cap_t cap) -{ - c->cap = cap; -} - -cte_t cte_next(cte_t c) -{ - return &ctable[c->next]; -} - -cte_t cte_prev(cte_t c) -{ - return &ctable[c->prev]; -} - -cap_t cte_cap(cte_t c) -{ - return c->cap; -} - -uint64_t cte_pid(cte_t c) -{ - return offset(c) / S3K_CAP_CNT; -} - -void cte_move(cte_t src, cte_t dst) -{ - if (src == dst) - return; - cte_set_cap(dst, cte_cap(src)); - cte_set_cap(src, (cap_t){0}); - cte_set_prev(dst, cte_prev(src)); - cte_set_next(dst, cte_next(src)); - cte_prev(dst)->next = offset(dst); - cte_next(dst)->prev = offset(dst); -} - -cap_t cte_delete(cte_t c) -{ - cap_t cap = cte_cap(c); - cte_set_cap(c, (cap_t){0}); - cte_set_next(cte_prev(c), cte_next(c)); - cte_set_prev(cte_next(c), cte_prev(c)); - return cap; -} - -void cte_insert(cte_t c, cap_t cap, cte_t prev) -{ - cte_set_prev(c, prev); - cte_set_next(c, cte_next(prev)); - cte_set_next(cte_prev(c), c); - cte_set_prev(cte_next(c), c); - cte_set_cap(c, cap); -} diff --git a/kernel/src/cap_util.c b/kernel/src/cap_util.c deleted file mode 100644 index dcaf0158..00000000 --- a/kernel/src/cap_util.c +++ /dev/null @@ -1,152 +0,0 @@ -#include "cap_util.h" - -#include "altc/altio.h" -#include "kassert.h" - -cap_t cap_mk_time(hart_t hart, time_slot_t bgn, time_slot_t end) -{ - KASSERT(bgn < end); -#if S3K_MIN_HART > 0 - KASSERT(hart >= S3K_MIN_HART); -#endif - KASSERT(hart <= S3K_MAX_HART); - KASSERT(end <= S3K_SLOT_CNT); - cap_t cap; - cap.type = CAPTY_TIME; - cap.time.hart = hart; - cap.time.bgn = bgn; - cap.time.mrk = bgn; - cap.time.end = end; - return cap; -} - -cap_t cap_mk_memory(addr_t bgn, addr_t end, rwx_t rwx) -{ - uint64_t tag = bgn >> MAX_BLOCK_SIZE; - KASSERT(bgn < end); - KASSERT(end <= (tag + 1) << MAX_BLOCK_SIZE); - cap_t cap; - cap.mem.type = CAPTY_MEMORY; - cap.mem.tag = tag; - cap.mem.bgn = (bgn - (tag << MAX_BLOCK_SIZE)) >> MIN_BLOCK_SIZE; - cap.mem.end = (end - (tag << MAX_BLOCK_SIZE)) >> MIN_BLOCK_SIZE; - cap.mem.mrk = cap.mem.bgn; - cap.mem.rwx = rwx; - cap.mem.lck = false; - return cap; -} - -cap_t cap_mk_pmp(napot_t addr, rwx_t rwx) -{ - cap_t cap; - cap.pmp.type = CAPTY_PMP; - cap.pmp.addr = addr; - cap.pmp.rwx = rwx; - cap.pmp.used = 0; - cap.pmp.slot = 0; - return cap; -} - -cap_t cap_mk_monitor(pid_t bgn, pid_t end) -{ - KASSERT(bgn < end); - KASSERT(end <= S3K_PROC_CNT); - cap_t cap; - cap.mon.type = CAPTY_MONITOR; - cap.mon.bgn = bgn; - cap.mon.end = end; - cap.mon.mrk = bgn; - return cap; -} - -cap_t cap_mk_channel(chan_t bgn, chan_t end) -{ - KASSERT(bgn < end); - KASSERT(end <= S3K_CHAN_CNT); - cap_t cap; - cap.chan.type = CAPTY_CHANNEL; - cap.chan.bgn = bgn; - cap.chan.end = end; - cap.chan.mrk = bgn; - return cap; -} - -cap_t cap_mk_socket(chan_t chan, ipc_mode_t mode, ipc_perm_t perm, uint32_t tag) -{ - cap_t cap; - cap.sock.type = CAPTY_SOCKET; - cap.sock.chan = chan; - cap.sock.mode = mode; - cap.sock.perm = perm; - cap.sock.tag = tag; - return cap; -} - -void cap_snprint(char *restrict buf, size_t size, cap_t cap) -{ - switch (cap.type) { - case CAPTY_NONE: - alt_snprintf(buf, size, "NONE{}"); - break; - case CAPTY_TIME: - alt_snprintf(buf, size, "TIME{hart=%d,bgn=%d,end=%d,mrk=%d}", - cap.time.hart, cap.time.bgn, cap.time.end, - cap.time.mrk); - break; - case CAPTY_MEMORY: { - uint64_t bgn = tag_block_to_addr(cap.mem.tag, cap.mem.bgn); - uint64_t end = tag_block_to_addr(cap.mem.tag, cap.mem.end); - uint64_t mrk = tag_block_to_addr(cap.mem.tag, cap.mem.mrk); - alt_snprintf(buf, size, - "MEMORY{bgn=0x%X,end=0x%X,mrk=0x%X,rwx=%d,lck=%x}", - bgn, end, mrk, cap.mem.rwx, cap.mem.lck); - } break; - case CAPTY_PMP: { - uint64_t base, _size; - pmp_napot_decode(cap.pmp.addr, &base, &_size); - alt_snprintf(buf, size, - "PMP{bgn=0x%X,end=0x%X,rwx=%d,used=%d,slot=%d}", - base, base + _size, cap.pmp.rwx, cap.pmp.used, - cap.pmp.slot); - } break; - case CAPTY_MONITOR: - alt_snprintf(buf, size, "MONITOR{bgn=%d,end=%d,mrk=%d}", - cap.mon.bgn, cap.mon.end, cap.mon.mrk); - break; - case CAPTY_CHANNEL: - alt_snprintf(buf, size, "CHANNEL{bgn=%d,end=%d,mrk=%d}", - cap.chan.bgn, cap.chan.end, cap.chan.mrk); - break; - case CAPTY_SOCKET: - alt_snprintf(buf, size, - "SOCKET{chan=%d,tag=%d,perm=%d,mode=%d}", - cap.sock.chan, cap.sock.tag, cap.sock.perm, - cap.sock.mode); - break; - default: - alt_snprintf(buf, size, "UNKNOWN{raw=0x%X}", cap.raw); - } -} - -bool cap_is_valid(const cap_t cap) -{ - switch (cap.type) { - case CAPTY_TIME: - return cap.time.bgn < cap.time.end - && cap.time.bgn == cap.time.mrk; - case CAPTY_MEMORY: - return cap.mem.lck == 0 && cap.mem.bgn < cap.mem.end - && cap.mem.mrk == cap.mem.bgn; - case CAPTY_PMP: - return cap.pmp.used == 0 && cap.pmp.slot == 0; - case CAPTY_MONITOR: - return cap.mon.bgn < cap.mon.end && cap.mon.bgn == cap.mon.mrk; - case CAPTY_CHANNEL: - return cap.mem.bgn < cap.mem.end && cap.mem.bgn == cap.mem.mrk; - case CAPTY_SOCKET: - return (cap.sock.mode == IPC_YIELD) - || (cap.sock.mode == IPC_NOYIELD); - default: - return false; - } -} diff --git a/kernel/src/exception.c b/kernel/src/exception.c deleted file mode 100644 index bdcfb914..00000000 --- a/kernel/src/exception.c +++ /dev/null @@ -1,41 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include "exception.h" - -#include "proc.h" - -#define ILLEGAL_INSTRUCTION 0x2 - -#define MRET 0x30200073 -#define SRET 0x10200073 -#define URET 0x00200073 - -static proc_t *_exception_delegate(proc_t *proc, uint64_t mcause, - uint64_t mtval) -{ - proc->regs[REG_ECAUSE] = mcause; - proc->regs[REG_EVAL] = mtval; - proc->regs[REG_EPC] = proc->regs[REG_PC]; - proc->regs[REG_ESP] = proc->regs[REG_SP]; - proc->regs[REG_PC] = proc->regs[REG_TPC]; - proc->regs[REG_SP] = proc->regs[REG_TSP]; - return proc; -} - -static proc_t *_exception_trap_return(proc_t *proc) -{ - proc->regs[REG_PC] = proc->regs[REG_EPC]; - proc->regs[REG_SP] = proc->regs[REG_ESP]; - proc->regs[REG_ECAUSE] = 0; - proc->regs[REG_EVAL] = 0; - proc->regs[REG_EPC] = 0; - proc->regs[REG_ESP] = 0; - return proc; -} - -proc_t *exception_handler(proc_t *proc, uint64_t mcause, uint64_t mtval) -{ - if (mcause == ILLEGAL_INSTRUCTION - && (mtval == MRET || mtval == SRET || mtval == URET)) - return _exception_trap_return(proc); - return _exception_delegate(proc, mcause, mtval); -} diff --git a/kernel/src/interrupt.c b/kernel/src/interrupt.c deleted file mode 100644 index cda176e5..00000000 --- a/kernel/src/interrupt.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include -#include - -proc_t *interrupt_handler(proc_t *proc, uint64_t mcause, uint64_t mtval) -{ - proc_release(proc); - return sched(); -} diff --git a/kernel/src/kernel.c b/kernel/src/kernel.c deleted file mode 100644 index 08fc5cf3..00000000 --- a/kernel/src/kernel.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "kernel.h" - -#include "altc/init.h" -#include "cap_lock.h" -#include "cap_table.h" -#include "csr.h" -#include "kassert.h" -#include "proc.h" -#include "sched.h" - -void kernel_init(void) -{ - alt_init(); - kprintf(0, "# uart initialized\n"); -#ifdef SMP - cap_lock_init(); - kprintf(0, "# capability lock initialized\n"); -#endif - ctable_init(); - kprintf(0, "# ctable initialized\n"); - sched_init(); - kprintf(0, "# scheduler initialized\n"); - proc_init(); - kprintf(0, "# processes initialized\n"); - kprintf(0, "# kernel initialization complete\n"); - kprintf(0, "# starting boot process\n"); -} - -bool kernel_preempt(void) -{ - return csrr(mip) & 0x80; -} diff --git a/kernel/src/kprintf.c b/kernel/src/kprintf.c deleted file mode 100644 index b68ba466..00000000 --- a/kernel/src/kprintf.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "kprintf.h" - -#include -#include - -#define BUF_SIZE 128 - -#if defined(NDEBUG) || !defined(VERBOSITY) -#undef VERBOSITY -#define VERBOSITY 0 -#endif - -#ifdef SMP -static int lock = 0; -#endif - -void kprintf(int verb, const char *restrict fmt, ...) -{ - if (verb > VERBOSITY) - return; - char buf[BUF_SIZE]; - va_list ap; - va_start(ap, fmt); - alt_vsnprintf(buf, BUF_SIZE, fmt, ap); - va_end(ap); - -#ifdef SMP - while (__atomic_fetch_or(&lock, 1, __ATOMIC_ACQUIRE)) - ; - alt_putstr(buf); - __atomic_store_n(&lock, 0, __ATOMIC_RELEASE); -#else - alt_putstr(buf); -#endif -} diff --git a/kernel/src/proc.c b/kernel/src/proc.c deleted file mode 100644 index acc0662a..00000000 --- a/kernel/src/proc.c +++ /dev/null @@ -1,142 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include "proc.h" - -#include "cap_pmp.h" -#include "csr.h" -#include "drivers/time.h" -#include "kassert.h" - -static proc_t procs[S3K_PROC_CNT]; -extern unsigned char _payload[]; - -void proc_init(void) -{ - for (uint64_t i = 0; i < S3K_PROC_CNT; i++) { - procs[i].pid = i; - procs[i].state = PSF_SUSPENDED; - } - procs[0].state = 0; - procs[0].regs[REG_PC] = (uint64_t)_payload; - KASSERT(cap_pmp_load(ctable_get(0, 0), 0) == SUCCESS); -} - -proc_t *proc_get(pid_t pid) -{ - KASSERT(pid < S3K_PROC_CNT); - KASSERT(procs[pid].pid == pid); - return &procs[pid]; -} - -proc_state_t proc_get_state(proc_t *proc) -{ - proc_state_t state = proc->state; - if ((state == PSF_BLOCKED) && time_get() >= proc->timeout) - return 0; - return state; -} - -bool proc_acquire(proc_t *proc) -{ - proc_state_t expected = proc->state; - proc_state_t desired = PSF_BUSY; - - if (expected & (PSF_BUSY | PSF_SUSPENDED)) - return false; - - if (time_get() < proc->timeout) - return false; -#ifdef SMP - return __atomic_compare_exchange(&proc->state, &expected, &desired, - false, __ATOMIC_ACQUIRE, - __ATOMIC_RELAXED); -#else - proc->state = desired; - return true; -#endif -} - -void proc_release(proc_t *proc) -{ - KASSERT(proc->state & PSF_BUSY); -#ifdef SMP - __atomic_fetch_xor(&proc->state, PSF_BUSY, __ATOMIC_RELEASE); -#else - proc->state &= ~PSF_BUSY; -#endif -} - -void proc_suspend(proc_t *proc) -{ - proc_state_t prev - = __atomic_fetch_or(&proc->state, PSF_SUSPENDED, __ATOMIC_RELAXED); - if (prev & PSF_BLOCKED) { - proc->state = PSF_SUSPENDED; - proc->regs[REG_T0] = ERR_SUSPENDED; - } -} - -void proc_resume(proc_t *proc) -{ - if (proc->state == PSF_SUSPENDED) - proc->timeout = 0; - __atomic_fetch_and(&proc->state, ~PSF_SUSPENDED, __ATOMIC_RELAXED); -} - -void proc_ipc_wait(proc_t *proc, chan_t chan) -{ - KASSERT(proc->state == PSF_BUSY); - proc->state = PSF_BLOCKED | ((uint64_t)chan << 48) | PSF_BUSY; -} - -bool proc_ipc_acquire(proc_t *proc, chan_t chan) -{ - proc_state_t expected = PSF_BLOCKED | ((uint64_t)chan << 48); - proc_state_t desired = PSF_BUSY; - - if (proc->state != expected) - return false; - if (time_get() >= proc->timeout) - return false; -#ifdef SMP - return __atomic_compare_exchange_n(&proc->state, &expected, desired, - false, __ATOMIC_ACQUIRE, - __ATOMIC_RELAXED); -#else - proc->state = desired; - return true; -#endif -} - -bool proc_is_suspended(proc_t *proc) -{ - return proc->state == PSF_SUSPENDED; -} - -bool proc_pmp_avail(proc_t *proc, pmp_slot_t slot) -{ - return proc->pmpcfg[slot] == 0; -} - -void proc_pmp_load(proc_t *proc, pmp_slot_t slot, pmp_slot_t rwx, napot_t addr) -{ - proc->pmpcfg[slot] = (uint8_t)(rwx | 0x18); - proc->pmpaddr[slot] = addr; -} - -void proc_pmp_unload(proc_t *proc, pmp_slot_t slot) -{ - proc->pmpcfg[slot] = 0; -} - -void proc_pmp_sync(proc_t *proc) -{ - csrw(pmpaddr0, proc->pmpaddr[0]); - csrw(pmpaddr1, proc->pmpaddr[1]); - csrw(pmpaddr2, proc->pmpaddr[2]); - csrw(pmpaddr3, proc->pmpaddr[3]); - csrw(pmpaddr4, proc->pmpaddr[4]); - csrw(pmpaddr5, proc->pmpaddr[5]); - csrw(pmpaddr6, proc->pmpaddr[6]); - csrw(pmpaddr7, proc->pmpaddr[7]); - csrw(pmpcfg0, *(uint64_t *)proc->pmpcfg); -} diff --git a/kernel/src/sched.c b/kernel/src/sched.c deleted file mode 100644 index 045bd871..00000000 --- a/kernel/src/sched.c +++ /dev/null @@ -1,162 +0,0 @@ -/* See LICENSE file for copyright and license details. */ - -#include "sched.h" - -#include "csr.h" -#include "drivers/time.h" -#include "kassert.h" -#include "kernel.h" -#include "kprintf.h" -#include "proc.h" -#include "smp/semaphore.h" -#include "trap.h" -#include "wfi.h" - -typedef struct slot_info { - // Owner of time slot. - uint8_t pid; - // Remaining length of corresponding slice. - uint8_t length; -} slot_info_t; - -struct sched_decision { - proc_t *proc; - uint64_t end_time; -}; - -static uint64_t slots[S3K_SLOT_CNT]; - -#ifdef SMP -static semaphore_t sched_semaphore; -#endif - -void sched_init(void) -{ - uint64_t pid = 0; - uint64_t end = S3K_SLOT_CNT; - uint64_t from = 0; - uint64_t to = S3K_SLOT_CNT; - -#ifdef SMP - semaphore_init(&sched_semaphore, S3K_HART_CNT); -#endif - - for (uint64_t hartid = S3K_MIN_HART; hartid <= S3K_MAX_HART; hartid++) - sched_update(pid, end, hartid, from, to); -} - -void sched_update(uint64_t pid, uint64_t end, uint64_t hart, uint64_t from, - uint64_t to) -{ - kprintf(1, "# sched_update(pid=%D,end=%D,hart=%D,from=%D,to=%D)\n", pid, - end, hart, from, to); -#ifdef SMP - semaphore_acquire_n(&sched_semaphore, S3K_HART_CNT); -#endif - hart -= S3K_MIN_HART; - int offset = hart * 16; - uint64_t mask = 0xFFFFull << offset; - for (uint64_t i = from; i < to; i++) { - slots[i] &= ~mask; - slots[i] |= ((pid << 8) | (end - i)) << offset; - } -#ifdef SMP - semaphore_release_n(&sched_semaphore, S3K_HART_CNT); -#endif -} - -void sched_delete(uint64_t hart, uint64_t from, uint64_t to) -{ - kprintf(1, "# sched_delete(hart=%D,from=%D,to=%D)\n", hart, from, to); -#ifdef SMP - semaphore_acquire_n(&sched_semaphore, S3K_HART_CNT); -#endif - hart -= S3K_MIN_HART; - int offset = hart * 16; - uint64_t mask = 0xFFFFull << offset; - for (uint64_t i = from; i < to; ++i) - slots[i] &= ~mask; -#ifdef SMP - semaphore_release_n(&sched_semaphore, S3K_HART_CNT); -#endif -} - -static slot_info_t slot_info_get(uint64_t hart, uint64_t slot) -{ - uint64_t entry = slots[slot % S3K_SLOT_CNT] - >> (hart - S3K_MIN_HART) * 16; - uint64_t pid = (entry >> 8) & 0xFF; - uint64_t length = entry & 0xFF; - return (slot_info_t){.pid = pid, .length = length}; -} - -static proc_t *sched_fetch(uint64_t hart, uint64_t slot) -{ - proc_t *proc = NULL; -#ifdef SMP - semaphore_acquire(&sched_semaphore); -#endif - // Get time slot information - slot_info_t si = slot_info_get(hart, slot); - - // If length = 0, then slice is deleted. - if (si.length == 0) - goto fail; - -#ifdef SMP - // Have priority over harts with lower ID when scheduling length is - // longer. - for (uint64_t i = S3K_MIN_HART; i < hart; i++) { - slot_info_t other_si = slot_info_get(i, slot); - if (si.pid == other_si.pid && si.length <= other_si.length) - goto fail; - } - - // Have priority over harts with higher ID when scheduling length is - // equal or longer. - for (uint64_t i = hart + 1; i < S3K_MAX_HART; i++) { - slot_info_t other_si = slot_info_get(i, slot); - if (si.pid == other_si.pid && si.length < other_si.length) - goto fail; - } -#endif - - proc = proc_get(si.pid); - - // Try to acquire the process. - if (!proc_acquire(proc)) { - proc = NULL; - goto fail; - } - - // Get the process. - kprintf(2, "# sched(hart=%d,pid=%d,slot=%D)\n", hart, si.pid, - slot % S3K_SLOT_CNT); - proc->timeout = (slot + si.length) * S3K_SLOT_LEN - S3K_SCHED_TIME; -fail: -#ifdef SMP - semaphore_release(&sched_semaphore); -#endif - return proc; -} - -proc_t *sched(void) -{ - // Hart ID - uint64_t hart = csrr(mhartid); - // Time slot - uint64_t slot; - // Process to schedule - proc_t *proc; - timeout_set(hart, (uint64_t)-1); - - do { - slot = (time_get() + S3K_SCHED_TIME) / S3K_SLOT_LEN; - while (time_get() < slot * S3K_SLOT_LEN) - ; - // Try schedule process - proc = sched_fetch(hart, slot); - } while (!proc); - timeout_set(hart, proc->timeout); - return proc; -} diff --git a/kernel/src/stack.S b/kernel/src/stack.S deleted file mode 100644 index 79fac71a..00000000 --- a/kernel/src/stack.S +++ /dev/null @@ -1,6 +0,0 @@ -.globl _sp - -.section .bss.stack -.balign 8 -.skip S3K_HART_CNT * (1 << S3K_LOG_STACK_SIZE) -_sp: diff --git a/kernel/src/syscall.c b/kernel/src/syscall.c deleted file mode 100644 index 97158aff..00000000 --- a/kernel/src/syscall.c +++ /dev/null @@ -1,620 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include "syscall.h" - -#include "cap_ipc.h" -#include "cap_lock.h" -#include "cap_monitor.h" -#include "cap_ops.h" -#include "cap_pmp.h" -#include "cap_table.h" -#include "cap_types.h" -#include "cap_util.h" -#include "csr.h" -#include "drivers/time.h" -#include "error.h" -#include "kernel.h" -#include "sched.h" -#include "trap.h" - -#include - -#define ARGS 8 - -static inline err_t validate_get_info(const sys_args_t *); -static inline err_t validate_reg_read(const sys_args_t *); -static inline err_t validate_reg_write(const sys_args_t *); -static inline err_t validate_sync(const sys_args_t *); -static inline err_t validate_sleep(const sys_args_t *); -static inline err_t validate_cap_read(const sys_args_t *); -static inline err_t validate_cap_move(const sys_args_t *); -static inline err_t validate_cap_delete(const sys_args_t *); -static inline err_t validate_cap_revoke(const sys_args_t *); -static inline err_t validate_cap_derive(const sys_args_t *); -static inline err_t validate_pmp_load(const sys_args_t *); -static inline err_t validate_pmp_unload(const sys_args_t *); -static inline err_t validate_mon_suspend(const sys_args_t *); -static inline err_t validate_mon_resume(const sys_args_t *); -static inline err_t validate_mon_state_get(const sys_args_t *); -static inline err_t validate_mon_yield(const sys_args_t *); -static inline err_t validate_mon_reg_read(const sys_args_t *); -static inline err_t validate_mon_reg_write(const sys_args_t *); -static inline err_t validate_mon_cap_read(const sys_args_t *); -static inline err_t validate_mon_cap_move(const sys_args_t *); -static inline err_t validate_mon_pmp_load(const sys_args_t *); -static inline err_t validate_mon_pmp_unload(const sys_args_t *); -static inline err_t validate_sock_send(const sys_args_t *); -static inline err_t validate_sock_recv(const sys_args_t *); -static inline err_t validate_sock_sendrecv(const sys_args_t *); - -static proc_t *handle_get_info(proc_t *const, const sys_args_t *); -static proc_t *handle_reg_read(proc_t *const, const sys_args_t *); -static proc_t *handle_reg_write(proc_t *const, const sys_args_t *); -static proc_t *handle_sync(proc_t *const, const sys_args_t *); -static proc_t *handle_sleep(proc_t *const, const sys_args_t *); -static proc_t *handle_cap_read(proc_t *const, const sys_args_t *); -static proc_t *handle_cap_move(proc_t *const, const sys_args_t *); -static proc_t *handle_cap_delete(proc_t *const, const sys_args_t *); -static proc_t *handle_cap_revoke(proc_t *const, const sys_args_t *); -static proc_t *handle_cap_derive(proc_t *const, const sys_args_t *); -static proc_t *handle_pmp_load(proc_t *const, const sys_args_t *); -static proc_t *handle_pmp_unload(proc_t *const, const sys_args_t *); -static proc_t *handle_mon_suspend(proc_t *const, const sys_args_t *); -static proc_t *handle_mon_resume(proc_t *const, const sys_args_t *); -static proc_t *handle_mon_state_get(proc_t *const, const sys_args_t *); -static proc_t *handle_mon_yield(proc_t *const, const sys_args_t *); -static proc_t *handle_mon_reg_read(proc_t *const, const sys_args_t *); -static proc_t *handle_mon_reg_write(proc_t *const, const sys_args_t *); -static proc_t *handle_mon_cap_read(proc_t *const, const sys_args_t *); -static proc_t *handle_mon_cap_move(proc_t *const, const sys_args_t *); -static proc_t *handle_mon_pmp_load(proc_t *const, const sys_args_t *); -static proc_t *handle_mon_pmp_unload(proc_t *const, const sys_args_t *); -static proc_t *handle_sock_send(proc_t *const, const sys_args_t *); -static proc_t *handle_sock_recv(proc_t *const, const sys_args_t *); -static proc_t *handle_sock_sendrecv(proc_t *const, const sys_args_t *); - -typedef proc_t *(*handler_t)(proc_t *const, const sys_args_t *); -typedef err_t (*validator_t)(const sys_args_t *); - -handler_t handlers[] = { - handle_get_info, handle_reg_read, handle_reg_write, - handle_sync, handle_sleep, handle_cap_read, - handle_cap_move, handle_cap_delete, handle_cap_revoke, - handle_cap_derive, handle_pmp_load, handle_pmp_unload, - handle_mon_suspend, handle_mon_resume, handle_mon_state_get, - handle_mon_yield, handle_mon_reg_read, handle_mon_reg_write, - handle_mon_cap_read, handle_mon_cap_move, handle_mon_pmp_load, - handle_mon_pmp_unload, handle_sock_send, handle_sock_recv, - handle_sock_sendrecv, -}; - -validator_t validators[] = { - validate_get_info, validate_reg_read, validate_reg_write, - validate_sync, validate_sleep, validate_cap_read, - validate_cap_move, validate_cap_delete, validate_cap_revoke, - validate_cap_derive, validate_pmp_load, validate_pmp_unload, - validate_mon_suspend, validate_mon_resume, validate_mon_state_get, - validate_mon_yield, validate_mon_reg_read, validate_mon_reg_write, - validate_mon_cap_read, validate_mon_cap_move, validate_mon_pmp_load, - validate_mon_pmp_unload, validate_sock_send, validate_sock_recv, - validate_sock_sendrecv, -}; - -proc_t *syscall_handler(proc_t *proc) -{ - // System call arguments. - const sys_args_t *args = (sys_args_t *)&proc->regs[REG_A0]; - uint64_t call = proc->regs[REG_T0]; - - // Validate system call arguments. - err_t err = ERR_INVALID_SYSCALL; - if (call < ARRAY_SIZE(validators)) - err = validators[call](args); - -#ifndef SMP /* Single core */ - if (err) { - // Increment PC - proc->regs[REG_PC] += 4; - proc->regs[REG_T0] = err; - } else if (kernel_preempt()) { - proc = NULL; - } else { - proc->regs[REG_PC] += 4; - proc = handlers[call](proc, args); - } -#else /* Multicore */ - if (err) { - // Invalid parameters - proc->regs[REG_PC] += 4; - proc->regs[REG_T0] = err; - } else if (kernel_preempt()) { - // Kernel preemption - proc = NULL; - } else if (call < SYS_CAP_MOVE) { - // These system calls do not require a lock - proc->regs[REG_PC] += 4; - proc = handlers[call](proc, args); - } else if (cap_lock_acquire()) { - // These system calls requires a lock - proc->regs[REG_PC] += 4; - proc = handlers[call](proc, args); - cap_lock_release(); - } else { - // Lock acquire failed due to preemption - proc->regs[REG_PC] += 4; - proc->regs[REG_T0] = ERR_PREEMPTED; - proc = NULL; - } -#endif - return proc; -} - -static bool valid_idx(cidx_t idx) -{ - return idx < S3K_CAP_CNT; -} - -static bool valid_slot(pmp_slot_t slot) -{ - return slot < S3K_PMP_CNT; -} - -static bool valid_pid(pid_t pid) -{ - return pid < S3K_PROC_CNT; -} - -static bool valid_reg(reg_t reg) -{ - return reg < REG_CNT; -} - -err_t validate_get_info(const sys_args_t *args) -{ - return SUCCESS; -} - -proc_t *handle_get_info(proc_t *const p, const sys_args_t *args) -{ - switch (args->get_info.info) { - case 0: - p->regs[REG_A0] = p->pid; - break; - case 1: - p->regs[REG_A0] = time_get(); - break; - case 2: - p->regs[REG_A0] = timeout_get(csrr(mhartid)); - break; - default: - p->regs[REG_A0] = 0; - } - p->regs[REG_T0] = SUCCESS; - return p; -} - -err_t validate_reg_read(const sys_args_t *args) -{ - if (!valid_reg(args->reg_read.reg)) - return ERR_INVALID_REGISTER; - return SUCCESS; -} - -proc_t *handle_reg_read(proc_t *const p, const sys_args_t *args) -{ - p->regs[REG_T0] = SUCCESS; - p->regs[REG_A0] = p->regs[args->reg_read.reg]; - return p; -} - -err_t validate_reg_write(const sys_args_t *args) -{ - if (!valid_reg(args->reg_write.reg)) - return ERR_INVALID_REGISTER; - return SUCCESS; -} - -proc_t *handle_reg_write(proc_t *const p, const sys_args_t *args) -{ - p->regs[REG_T0] = SUCCESS; - p->regs[args->reg_write.reg] = args->reg_write.val; - return p; -} - -err_t validate_sync(const sys_args_t *args) -{ - return SUCCESS; -} - -proc_t *handle_sync(proc_t *const p, const sys_args_t *args) -{ - // Full sync invokes scheduler, - // otherwise only update memory. - if (args->sync.full) { - proc_release(p); - return NULL; - } - proc_pmp_sync(p); - return p; -} - -err_t validate_sleep(const sys_args_t *args) -{ - return SUCCESS; -} - -proc_t *handle_sleep(proc_t *const p, const sys_args_t *args) -{ - p->regs[REG_T0] = SUCCESS; - if (args->sleep.time) - p->timeout = args->sleep.time; - return NULL; -} - -err_t validate_cap_read(const sys_args_t *args) -{ - if (!valid_idx(args->cap_read.idx)) - return ERR_INVALID_INDEX; - return SUCCESS; -} - -proc_t *handle_cap_read(proc_t *const p, const sys_args_t *args) -{ - cte_t c = ctable_get(p->pid, args->cap_read.idx); - p->regs[REG_T0] = cap_read(c, (cap_t *)&p->regs[REG_A0]); - return p; -} - -err_t validate_cap_move(const sys_args_t *args) -{ - if (!valid_idx(args->cap_move.src_idx)) - return ERR_INVALID_INDEX; - if (!valid_idx(args->cap_move.dst_idx)) - return ERR_INVALID_INDEX; - return SUCCESS; -} - -proc_t *handle_cap_move(proc_t *const p, const sys_args_t *args) -{ - cte_t src = ctable_get(p->pid, args->cap_move.src_idx); - cte_t dst = ctable_get(p->pid, args->cap_move.dst_idx); - p->regs[REG_T0] = cap_move(src, dst); - return p; -} - -err_t validate_cap_delete(const sys_args_t *args) -{ - if (!valid_idx(args->cap_delete.idx)) - return ERR_INVALID_INDEX; - return SUCCESS; -} - -proc_t *handle_cap_delete(proc_t *const p, const sys_args_t *args) -{ - cte_t c = ctable_get(p->pid, args->cap_delete.idx); - p->regs[REG_T0] = cap_delete(c); - return p; -} - -err_t validate_cap_revoke(const sys_args_t *args) -{ - if (!valid_idx(args->cap_revoke.idx)) - return ERR_INVALID_INDEX; - return SUCCESS; -} - -proc_t *handle_cap_revoke(proc_t *const p, const sys_args_t *args) -{ - cte_t c = ctable_get(p->pid, args->cap_revoke.idx); - - p->regs[REG_T0] = cap_revoke(c); - return p->regs[REG_T0] == ERR_PREEMPTED ? NULL : p; -} - -err_t validate_cap_derive(const sys_args_t *args) -{ - if (!valid_idx(args->cap_derive.src_idx)) - return ERR_INVALID_INDEX; - if (!valid_idx(args->cap_derive.dst_idx)) - return ERR_INVALID_INDEX; - cap_t cap = {.raw = args->cap_derive.cap_raw}; - if (!cap_is_valid(cap)) - return ERR_INVALID_DERIVATION; - return SUCCESS; -} - -proc_t *handle_cap_derive(proc_t *const p, const sys_args_t *args) -{ - cte_t src = ctable_get(p->pid, args->cap_derive.src_idx); - cte_t dst = ctable_get(p->pid, args->cap_derive.dst_idx); - cap_t cap = {.raw = args->cap_derive.cap_raw}; - p->regs[REG_T0] = cap_derive(src, dst, cap); - return p; -} - -err_t validate_pmp_load(const sys_args_t *args) -{ - if (!valid_idx(args->pmp_load.idx)) - return ERR_INVALID_INDEX; - if (!valid_slot(args->pmp_load.slot)) - return ERR_INVALID_SLOT; - return SUCCESS; -} - -proc_t *handle_pmp_load(proc_t *const p, const sys_args_t *args) -{ - cte_t pmp = ctable_get(p->pid, args->pmp_load.idx); - p->regs[REG_T0] = cap_pmp_load(pmp, args->pmp_load.slot); - return p; -} - -err_t validate_pmp_unload(const sys_args_t *args) -{ - if (!valid_idx(args->pmp_unload.idx)) - return ERR_INVALID_INDEX; - return SUCCESS; -} - -proc_t *handle_pmp_unload(proc_t *const p, const sys_args_t *args) -{ - cte_t pmp = ctable_get(p->pid, args->pmp_unload.idx); - p->regs[REG_T0] = cap_pmp_unload(pmp); - return p; -} - -err_t validate_mon_suspend(const sys_args_t *args) -{ - if (!valid_idx(args->mon_state.mon_idx)) - return ERR_INVALID_INDEX; - if (!valid_pid(args->mon_state.pid)) - return ERR_INVALID_PID; - return SUCCESS; -} - -proc_t *handle_mon_suspend(proc_t *const p, const sys_args_t *args) -{ - cte_t mon = ctable_get(p->pid, args->mon_state.mon_idx); - p->regs[REG_T0] = cap_monitor_suspend(mon, args->mon_state.pid); - return p; -} - -err_t validate_mon_resume(const sys_args_t *args) -{ - if (!valid_idx(args->mon_state.mon_idx)) - return ERR_INVALID_INDEX; - if (!valid_pid(args->mon_state.pid)) - return ERR_INVALID_PID; - return SUCCESS; -} - -proc_t *handle_mon_resume(proc_t *const p, const sys_args_t *args) -{ - cte_t mon = ctable_get(p->pid, args->mon_state.mon_idx); - p->regs[REG_T0] = cap_monitor_resume(mon, args->mon_state.pid); - return p; -} - -err_t validate_mon_state_get(const sys_args_t *args) -{ - if (!valid_idx(args->mon_state.mon_idx)) - return ERR_INVALID_INDEX; - if (!valid_pid(args->mon_state.pid)) - return ERR_INVALID_PID; - return SUCCESS; -} - -proc_t *handle_mon_state_get(proc_t *const p, const sys_args_t *args) -{ - cte_t mon = ctable_get(p->pid, args->mon_state.mon_idx); - p->regs[REG_T0] = cap_monitor_state_get( - mon, args->mon_state.pid, (proc_state_t *)&p->regs[REG_A0]); - return p; -} - -err_t validate_mon_yield(const sys_args_t *args) -{ - if (!valid_idx(args->mon_state.mon_idx)) - return ERR_INVALID_INDEX; - if (!valid_pid(args->mon_state.pid)) - return ERR_INVALID_PID; - return SUCCESS; -} - -proc_t *handle_mon_yield(proc_t *const p, const sys_args_t *args) -{ - cte_t mon = ctable_get(p->pid, args->mon_state.mon_idx); - proc_t *next = p; - p->regs[REG_T0] = cap_monitor_yield(mon, args->mon_state.pid, &next); - return next; -} - -err_t validate_mon_reg_read(const sys_args_t *args) -{ - if (!valid_idx(args->mon_reg_read.mon_idx)) - return ERR_INVALID_INDEX; - if (!valid_pid(args->mon_reg_read.pid)) - return ERR_INVALID_PID; - if (!valid_reg(args->mon_reg_read.reg)) - return ERR_INVALID_REGISTER; - return SUCCESS; -} - -proc_t *handle_mon_reg_read(proc_t *const p, const sys_args_t *args) -{ - cte_t mon = ctable_get(p->pid, args->mon_reg_read.mon_idx); - p->regs[REG_T0] = cap_monitor_reg_read(mon, args->mon_reg_read.pid, - args->mon_reg_read.reg, - &p->regs[REG_A0]); - return p; -} - -err_t validate_mon_reg_write(const sys_args_t *args) -{ - if (!valid_idx(args->mon_reg_write.mon_idx)) - return ERR_INVALID_INDEX; - if (!valid_pid(args->mon_reg_write.pid)) - return ERR_INVALID_PID; - if (!valid_reg(args->mon_reg_write.reg)) - return ERR_INVALID_REGISTER; - return SUCCESS; -} - -proc_t *handle_mon_reg_write(proc_t *const p, const sys_args_t *args) -{ - cte_t mon = ctable_get(p->pid, args->mon_reg_write.mon_idx); - p->regs[REG_T0] = cap_monitor_reg_write(mon, args->mon_reg_write.pid, - args->mon_reg_write.reg, - args->mon_reg_write.val); - return p; -} - -err_t validate_mon_cap_read(const sys_args_t *args) -{ - if (!valid_idx(args->mon_cap_read.mon_idx)) - return ERR_INVALID_INDEX; - if (!valid_pid(args->mon_cap_read.pid)) - return ERR_INVALID_PID; - if (!valid_idx(args->mon_cap_read.idx)) - return ERR_INVALID_INDEX; - return SUCCESS; -} - -proc_t *handle_mon_cap_read(proc_t *const p, const sys_args_t *args) -{ - cte_t mon = ctable_get(p->pid, args->mon_cap_read.mon_idx); - cte_t src = ctable_get(args->mon_cap_read.pid, args->mon_cap_read.idx); - p->regs[REG_T0] - = cap_monitor_cap_read(mon, src, (cap_t *)&p->regs[REG_A0]); - return p; -} - -err_t validate_mon_cap_move(const sys_args_t *args) -{ - if (!valid_idx(args->mon_cap_move.mon_idx)) - return ERR_INVALID_INDEX; - if (!valid_pid(args->mon_cap_move.src_pid)) - return ERR_INVALID_PID; - if (!valid_idx(args->mon_cap_move.src_idx)) - return ERR_INVALID_INDEX; - if (!valid_pid(args->mon_cap_move.dst_pid)) - return ERR_INVALID_PID; - if (!valid_idx(args->mon_cap_move.dst_idx)) - return ERR_INVALID_INDEX; - return SUCCESS; -} - -proc_t *handle_mon_cap_move(proc_t *const p, const sys_args_t *args) -{ - cte_t mon = ctable_get(p->pid, args->mon_cap_move.mon_idx); - cte_t src = ctable_get(args->mon_cap_move.src_pid, - args->mon_cap_move.src_idx); - cte_t dst = ctable_get(args->mon_cap_move.dst_pid, - args->mon_cap_move.dst_idx); - p->regs[REG_T0] = cap_monitor_cap_move(mon, src, dst); - return p; -} - -err_t validate_mon_pmp_load(const sys_args_t *args) -{ - if (!valid_idx(args->mon_pmp_load.mon_idx)) - return ERR_INVALID_INDEX; - if (!valid_pid(args->mon_pmp_load.pid)) - return ERR_INVALID_PID; - if (!valid_idx(args->mon_pmp_load.idx)) - return ERR_INVALID_INDEX; - if (!valid_pid(args->mon_pmp_load.slot)) - return ERR_INVALID_PID; - return SUCCESS; -} - -proc_t *handle_mon_pmp_load(proc_t *const p, const sys_args_t *args) -{ - cte_t mon = ctable_get(p->pid, args->mon_pmp_load.mon_idx); - cte_t pmp = ctable_get(args->mon_pmp_load.pid, args->mon_pmp_load.idx); - p->regs[REG_T0] - = cap_monitor_pmp_load(mon, pmp, args->mon_pmp_load.slot); - return p; -} - -err_t validate_mon_pmp_unload(const sys_args_t *args) -{ - if (!valid_idx(args->mon_pmp_unload.mon_idx)) - return ERR_INVALID_INDEX; - if (!valid_pid(args->mon_pmp_unload.pid)) - return ERR_INVALID_PID; - if (!valid_idx(args->mon_pmp_unload.idx)) - return ERR_INVALID_INDEX; - return SUCCESS; -} - -proc_t *handle_mon_pmp_unload(proc_t *const p, const sys_args_t *args) -{ - cte_t mon = ctable_get(p->pid, args->mon_pmp_unload.mon_idx); - cte_t pmp - = ctable_get(args->mon_pmp_unload.pid, args->mon_pmp_unload.idx); - p->regs[REG_T0] = cap_monitor_pmp_unload(mon, pmp); - return p; -} - -err_t validate_sock_send(const sys_args_t *args) -{ - if (!valid_idx(args->sock.sock_idx)) - return ERR_INVALID_INDEX; - if (!valid_idx(args->sock.cap_idx)) - return ERR_INVALID_INDEX; - return SUCCESS; -} - -proc_t *handle_sock_send(proc_t *const p, const sys_args_t *args) -{ - cte_t sock = ctable_get(p->pid, args->sock.sock_idx); - const ipc_msg_t msg = { - .cap_buf = ctable_get(p->pid, args->sock.cap_idx), - .send_cap = args->sock.send_cap, - .data = {args->sock.data[0], args->sock.data[1], args->sock.data[2], - args->sock.data[3]}, - }; - proc_t *next = p; - p->regs[REG_T0] = cap_sock_send(sock, &msg, &next); - return next; -} - -err_t validate_sock_recv(const sys_args_t *args) -{ - if (!valid_idx(args->sock.sock_idx)) - return ERR_INVALID_INDEX; - if (!valid_idx(args->sock.cap_idx)) - return ERR_INVALID_INDEX; - return SUCCESS; -} - -proc_t *handle_sock_recv(proc_t *const p, const sys_args_t *args) -{ - cte_t sock = ctable_get(p->pid, args->sock.sock_idx); - cte_t cap_buf = ctable_get(p->pid, args->sock.cap_idx); - proc_t *next = p; - p->regs[REG_T0] = cap_sock_recv(sock, cap_buf, &next); - return next; -} - -err_t validate_sock_sendrecv(const sys_args_t *args) -{ - if (!valid_idx(args->sock.sock_idx)) - return ERR_INVALID_INDEX; - if (!valid_idx(args->sock.cap_idx)) - return ERR_INVALID_INDEX; - return SUCCESS; -} - -proc_t *handle_sock_sendrecv(proc_t *const p, const sys_args_t *args) -{ - cte_t sock = ctable_get(p->pid, args->sock.sock_idx); - const ipc_msg_t msg = { - .cap_buf = ctable_get(p->pid, args->sock.cap_idx), - .send_cap = args->sock.send_cap, - .data = {args->sock.data[0], args->sock.data[1], args->sock.data[2], - args->sock.data[3]}, - }; - proc_t *next = p; - p->regs[REG_T0] = cap_sock_sendrecv(sock, &msg, &next); - return next; -} diff --git a/kernel/src/trap.S b/kernel/src/trap.S deleted file mode 100644 index ce5f6753..00000000 --- a/kernel/src/trap.S +++ /dev/null @@ -1,127 +0,0 @@ -// See LICENSE file for copyright and license details. -#include "macro.inc" -#include "offsets.h" -#include "csr.h" - -.globl trap_entry -.globl trap_exit - -.type trap_entry, @function -.type trap_exit, @function - -.section .text.trap -.balign 16 -trap_entry: - // Save user a0 to scratch, load PCB pointer - csrrw a0,mscratch,a0 - - sd ra,PROC_RA(a0) - sd sp,PROC_SP(a0) - sd gp,PROC_GP(a0) - sd tp,PROC_TP(a0) - sd t0,PROC_T0(a0) - sd t1,PROC_T1(a0) - sd t2,PROC_T2(a0) - sd s0,PROC_S0(a0) - sd s1,PROC_S1(a0) - /*sd a0,PROC_A0(a0)*/ - sd a1,PROC_A1(a0) - sd a2,PROC_A2(a0) - sd a3,PROC_A3(a0) - sd a4,PROC_A4(a0) - sd a5,PROC_A5(a0) - sd a6,PROC_A6(a0) - sd a7,PROC_A7(a0) - sd s2,PROC_S2(a0) - sd s3,PROC_S3(a0) - sd s4,PROC_S4(a0) - sd s5,PROC_S5(a0) - sd s6,PROC_S6(a0) - sd s7,PROC_S7(a0) - sd s8,PROC_S8(a0) - sd s9,PROC_S9(a0) - sd s10,PROC_S10(a0) - sd s11,PROC_S11(a0) - sd t3,PROC_T3(a0) - sd t4,PROC_T4(a0) - sd t5,PROC_T5(a0) - sd t6,PROC_T6(a0) - - // Save the - csrr t1,mepc - csrr t2,mscratch - sd t1,PROC_PC(a0) - sd t2,PROC_A0(a0) - - - // Load the global and stack pointer of the kernel. - ld_gp - ld_sp t0 - - // call the trap handler - csrr a1,mcause - csrr a2,mtval - call trap_handler - -trap_exit: - ld s0,PROC_PMPADDR0(a0) - ld s1,PROC_PMPADDR1(a0) - ld s2,PROC_PMPADDR2(a0) - ld s3,PROC_PMPADDR3(a0) - ld s4,PROC_PMPADDR4(a0) - ld s5,PROC_PMPADDR5(a0) - ld s6,PROC_PMPADDR6(a0) - ld s7,PROC_PMPADDR7(a0) - fence - ld s8,PROC_PMPCFG0(a0) - csrw pmpaddr0,s0 - csrw pmpaddr1,s1 - csrw pmpaddr2,s2 - csrw pmpaddr3,s3 - csrw pmpaddr4,s4 - csrw pmpaddr5,s5 - csrw pmpaddr6,s6 - csrw pmpaddr7,s7 - csrw pmpcfg0,s8 - - ld t0,PROC_PC(a0) - ld t1,PROC_A0(a0) - csrw mepc,t0 - csrw mscratch,t1 - - ld ra,PROC_RA(a0) - ld sp,PROC_SP(a0) - ld gp,PROC_GP(a0) - ld tp,PROC_TP(a0) - ld t0,PROC_T0(a0) - ld t1,PROC_T1(a0) - ld t2,PROC_T2(a0) - ld s0,PROC_S0(a0) - ld s1,PROC_S1(a0) - /*ld a0,PROC_A0(a0)*/ - ld a1,PROC_A1(a0) - ld a2,PROC_A2(a0) - ld a3,PROC_A3(a0) - ld a4,PROC_A4(a0) - ld a5,PROC_A5(a0) - ld a6,PROC_A6(a0) - ld a7,PROC_A7(a0) - ld s2,PROC_S2(a0) - ld s3,PROC_S3(a0) - ld s4,PROC_S4(a0) - ld s5,PROC_S5(a0) - ld s6,PROC_S6(a0) - ld s7,PROC_S7(a0) - ld s8,PROC_S8(a0) - ld s9,PROC_S9(a0) - ld s10,PROC_S10(a0) - ld s11,PROC_S11(a0) - ld t3,PROC_T3(a0) - ld t4,PROC_T4(a0) - ld t5,PROC_T5(a0) - ld t6,PROC_T6(a0) - - // Save PCB pointer. - csrrw a0,mscratch,a0 - - mret diff --git a/kernel/src/trap.c b/kernel/src/trap.c deleted file mode 100644 index eba41605..00000000 --- a/kernel/src/trap.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include -#include - -proc_t *trap_handler(proc_t *proc, uint64_t mcause, uint64_t mtval) -{ - if (mcause == 8) { - proc_t *next = syscall_handler(proc); - if (next != proc) - proc_release(proc); - if (next) - return next; - return sched(); - } else if ((int64_t)mcause < 0) { - return interrupt_handler(proc, mcause, mtval); - } else { - return exception_handler(proc, mcause, mtval); - } -} diff --git a/projects/demonstrator/boot/main.c b/projects/demonstrator/boot/main.c index c59cc2fb..0c3790bd 100644 --- a/projects/demonstrator/boot/main.c +++ b/projects/demonstrator/boot/main.c @@ -47,21 +47,18 @@ s3k_err_t mon_resume(s3k_pid_t pid) s3k_err_t derive_ram(s3k_cidx_t dst, char *base, size_t len, s3k_mem_perm_t rwx) { - s3k_cap_t cap - = s3k_mk_memory((uint64_t)base, (uint64_t)base + len, rwx); + s3k_cap_t cap = s3k_mk_memory((uint64_t)base, (uint64_t)base + len, rwx); return s3k_cap_derive(MEMORY_RAM_CIDX, dst, cap); } -s3k_err_t derive_pmp(s3k_cidx_t src, s3k_cidx_t dst, char *base, size_t len, - s3k_mem_perm_t rwx) +s3k_err_t derive_pmp(s3k_cidx_t src, s3k_cidx_t dst, char *base, size_t len, s3k_mem_perm_t rwx) { s3k_napot_t addr = s3k_napot_encode((s3k_addr_t)base, len); s3k_cap_t cap = s3k_mk_pmp(addr, rwx); return s3k_cap_derive(src, dst, cap); } -void setup_bin(s3k_pid_t pid, char *mem, size_t mem_len, char *bin, - size_t bin_len) +void setup_bin(s3k_pid_t pid, char *mem, size_t mem_len, char *bin, size_t bin_len) { derive_ram(0x10, mem, mem_len, S3K_MEM_RWX); derive_pmp(0x10, 0x11, mem, mem_len, S3K_MEM_RWX); @@ -98,8 +95,7 @@ void setup_shared_mem(void) void setup_uart_pmp(void) { - derive_pmp(MEMORY_UART_CIDX, 0x10, (void *)UART0_BASE_ADDR, 0x1000, - S3K_MEM_RW); + derive_pmp(MEMORY_UART_CIDX, 0x10, (void *)UART0_BASE_ADDR, 0x1000, S3K_MEM_RW); mon_grant_cap(UART_PID, 0x10, 0x4); mon_pmp_load(UART_PID, 0x4, 0x2); } @@ -147,13 +143,10 @@ void setup_app_monitoring(void) void setup_time(void) { - s3k_cap_derive(TIME_HART0_CIDX, 0x10, - s3k_mk_time(S3K_MIN_HART, 0, UART_TIME)); - s3k_cap_derive(TIME_HART0_CIDX, 0x11, - s3k_mk_time(S3K_MIN_HART, UART_TIME, S3K_SLOT_CNT)); + s3k_cap_derive(TIME_HART0_CIDX, 0x10, s3k_mk_time(S3K_MIN_HART, 0, UART_TIME)); + s3k_cap_derive(TIME_HART0_CIDX, 0x11, s3k_mk_time(S3K_MIN_HART, UART_TIME, S3K_SLOT_CNT)); s3k_cap_derive(0x10, 0x12, s3k_mk_time(S3K_MIN_HART, 0, UART_TIME - 2)); - s3k_cap_derive(0x11, 0x13, - s3k_mk_time(S3K_MIN_HART, UART_TIME, S3K_SLOT_CNT - 2)); + s3k_cap_derive(0x11, 0x13, s3k_mk_time(S3K_MIN_HART, UART_TIME, S3K_SLOT_CNT - 2)); mon_grant_cap(UART_PID, 0x10, 0x2); mon_grant_cap(MONITOR_PID, 0x11, 0x2); @@ -192,18 +185,15 @@ void main(void) s3k_cap_delete(TIME_HART1_CIDX); s3k_cap_delete(TIME_HART2_CIDX); s3k_cap_delete(TIME_HART3_CIDX); - derive_pmp(MEMORY_UART_CIDX, 0x5, (void *)UART0_BASE_ADDR, 0x1000, - S3K_MEM_RW); + derive_pmp(MEMORY_UART_CIDX, 0x5, (void *)UART0_BASE_ADDR, 0x1000, S3K_MEM_RW); s3k_pmp_load(5, 1); s3k_sync_mem(); alt_puts("{setting up memory ...}"); /* Copy binary of monitor process, setup PMP and program counter. */ - setup_bin(MONITOR_PID, MONITOR_MEM, MONITOR_MEM_LEN, monitor_bin, - monitor_bin_len); + setup_bin(MONITOR_PID, MONITOR_MEM, MONITOR_MEM_LEN, monitor_bin, monitor_bin_len); /* Copy binary of crypto process, setup PMP and program counter. */ - setup_bin(CRYPTO_PID, CRYPTO_MEM, CRYPTO_MEM_LEN, crypto_bin, - crypto_bin_len); + setup_bin(CRYPTO_PID, CRYPTO_MEM, CRYPTO_MEM_LEN, crypto_bin, crypto_bin_len); /* Copy binary of uart process, setup PMP and program counter. */ setup_bin(UART_PID, UART_MEM, UART_MEM_LEN, uart_bin, uart_bin_len); /* Give UART and Monitor processes shared memory */ diff --git a/projects/demonstrator/crypto/aes128.c b/projects/demonstrator/crypto/aes128.c index b5b5fee4..dd1001f0 100644 --- a/projects/demonstrator/crypto/aes128.c +++ b/projects/demonstrator/crypto/aes128.c @@ -7,210 +7,144 @@ static const uint32_t rc[10] = { }; static const uint8_t SBOX[256] = { - 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, - 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, - 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, - 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, - 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, - 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, - 0x52, 0x3b, 0xd6, 0xb3, 0x29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x56, 0xf4, 0xea, 0x65, 0x7a, + 0xae, 0x08, 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 0x70, + 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, + 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, + 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16, }; static const uint8_t RSBOX[256] = { - 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, - 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, - 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32, - 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, - 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, - 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, - 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50, - 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, - 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, - 0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d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d, + 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, + 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d, }; static const uint8_t GF2[256] = { - 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, - 0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e, - 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e, 0x40, 0x42, 0x44, 0x46, - 0x48, 0x4a, 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e, - 0x60, 0x62, 0x64, 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, 0x72, 0x74, 0x76, - 0x78, 0x7a, 0x7c, 0x7e, 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, - 0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa4, 0xa6, - 0xa8, 0xaa, 0xac, 0xae, 0xb0, 0xb2, 0xb4, 0xb6, 0xb8, 0xba, 0xbc, 0xbe, - 0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce, 0xd0, 0xd2, 0xd4, 0xd6, - 0xd8, 0xda, 0xdc, 0xde, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8, 0xea, 0xec, 0xee, - 0xf0, 0xf2, 0xf4, 0xf6, 0xf8, 0xfa, 0xfc, 0xfe, 0x1b, 0x19, 0x1f, 0x1d, - 0x13, 0x11, 0x17, 0x15, 0x0b, 0x09, 0x0f, 0x0d, 0x03, 0x01, 0x07, 0x05, - 0x3b, 0x39, 0x3f, 0x3d, 0x33, 0x31, 0x37, 0x35, 0x2b, 0x29, 0x2f, 0x2d, - 0x23, 0x21, 0x27, 0x25, 0x5b, 0x59, 0x5f, 0x5d, 0x53, 0x51, 0x57, 0x55, - 0x4b, 0x49, 0x4f, 0x4d, 0x43, 0x41, 0x47, 0x45, 0x7b, 0x79, 0x7f, 0x7d, - 0x73, 0x71, 0x77, 0x75, 0x6b, 0x69, 0x6f, 0x6d, 0x63, 0x61, 0x67, 0x65, - 0x9b, 0x99, 0x9f, 0x9d, 0x93, 0x91, 0x97, 0x95, 0x8b, 0x89, 0x8f, 0x8d, - 0x83, 0x81, 0x87, 0x85, 0xbb, 0xb9, 0xbf, 0xbd, 0xb3, 0xb1, 0xb7, 0xb5, - 0xab, 0xa9, 0xaf, 0xad, 0xa3, 0xa1, 0xa7, 0xa5, 0xdb, 0xd9, 0xdf, 0xdd, - 0xd3, 0xd1, 0xd7, 0xd5, 0xcb, 0xc9, 0xcf, 0xcd, 0xc3, 0xc1, 0xc7, 0xc5, - 0xfb, 0xf9, 0xff, 0xfd, 0xf3, 0xf1, 0xf7, 0xf5, 0xeb, 0xe9, 0xef, 0xed, - 0xe3, 0xe1, 0xe7, 0xe5, + 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x22, 0x24, + 0x26, 0x28, 0x2a, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e, 0x40, 0x42, 0x44, 0x46, 0x48, 0x4a, + 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e, 0x60, 0x62, 0x64, 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, + 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7e, 0x80, 0x82, 0x84, 0x86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xeb, 0xe9, 0xef, 0xed, 0xe3, 0xe1, 0xe7, 0xe5, }; static const uint8_t GF3[256] = { - 0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x18, 0x1b, 0x1e, 0x1d, - 0x14, 0x17, 0x12, 0x11, 0x30, 0x33, 0x36, 0x35, 0x3c, 0x3f, 0x3a, 0x39, - 0x28, 0x2b, 0x2e, 0x2d, 0x24, 0x27, 0x22, 0x21, 0x60, 0x63, 0x66, 0x65, - 0x6c, 0x6f, 0x6a, 0x69, 0x78, 0x7b, 0x7e, 0x7d, 0x74, 0x77, 0x72, 0x71, - 0x50, 0x53, 0x56, 0x55, 0x5c, 0x5f, 0x5a, 0x59, 0x48, 0x4b, 0x4e, 0x4d, - 0x44, 0x47, 0x42, 0x41, 0xc0, 0xc3, 0xc6, 0xc5, 0xcc, 0xcf, 0xca, 0xc9, - 0xd8, 0xdb, 0xde, 0xdd, 0xd4, 0xd7, 0xd2, 0xd1, 0xf0, 0xf3, 0xf6, 0xf5, - 0xfc, 0xff, 0xfa, 0xf9, 0xe8, 0xeb, 0xee, 0xed, 0xe4, 0xe7, 0xe2, 0xe1, - 0xa0, 0xa3, 0xa6, 0xa5, 0xac, 0xaf, 0xaa, 0xa9, 0xb8, 0xbb, 0xbe, 0xbd, - 0xb4, 0xb7, 0xb2, 0xb1, 0x90, 0x93, 0x96, 0x95, 0x9c, 0x9f, 0x9a, 0x99, - 0x88, 0x8b, 0x8e, 0x8d, 0x84, 0x87, 0x82, 0x81, 0x9b, 0x98, 0x9d, 0x9e, - 0x97, 0x94, 0x91, 0x92, 0x83, 0x80, 0x85, 0x86, 0x8f, 0x8c, 0x89, 0x8a, - 0xab, 0xa8, 0xad, 0xae, 0xa7, 0xa4, 0xa1, 0xa2, 0xb3, 0xb0, 0xb5, 0xb6, - 0xbf, 0xbc, 0xb9, 0xba, 0xfb, 0xf8, 0xfd, 0xfe, 0xf7, 0xf4, 0xf1, 0xf2, - 0xe3, 0xe0, 0xe5, 0xe6, 0xef, 0xec, 0xe9, 0xea, 0xcb, 0xc8, 0xcd, 0xce, - 0xc7, 0xc4, 0xc1, 0xc2, 0xd3, 0xd0, 0xd5, 0xd6, 0xdf, 0xdc, 0xd9, 0xda, - 0x5b, 0x58, 0x5d, 0x5e, 0x57, 0x54, 0x51, 0x52, 0x43, 0x40, 0x45, 0x46, - 0x4f, 0x4c, 0x49, 0x4a, 0x6b, 0x68, 0x6d, 0x6e, 0x67, 0x64, 0x61, 0x62, - 0x73, 0x70, 0x75, 0x76, 0x7f, 0x7c, 0x79, 0x7a, 0x3b, 0x38, 0x3d, 0x3e, - 0x37, 0x34, 0x31, 0x32, 0x23, 0x20, 0x25, 0x26, 0x2f, 0x2c, 0x29, 0x2a, - 0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16, - 0x1f, 0x1c, 0x19, 0x1a, + 0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x18, 0x1b, 0x1e, 0x1d, 0x14, 0x17, 0x12, 0x11, 0x30, 0x33, 0x36, + 0x35, 0x3c, 0x3f, 0x3a, 0x39, 0x28, 0x2b, 0x2e, 0x2d, 0x24, 0x27, 0x22, 0x21, 0x60, 0x63, 0x66, 0x65, 0x6c, 0x6f, + 0x6a, 0x69, 0x78, 0x7b, 0x7e, 0x7d, 0x74, 0x77, 0x72, 0x71, 0x50, 0x53, 0x56, 0x55, 0x5c, 0x5f, 0x5a, 0x59, 0x48, + 0x4b, 0x4e, 0x4d, 0x44, 0x47, 0x42, 0x41, 0xc0, 0xc3, 0xc6, 0xc5, 0xcc, 0xcf, 0xca, 0xc9, 0xd8, 0xdb, 0xde, 0xdd, + 0xd4, 0xd7, 0xd2, 0xd1, 0xf0, 0xf3, 0xf6, 0xf5, 0xfc, 0xff, 0xfa, 0xf9, 0xe8, 0xeb, 0xee, 0xed, 0xe4, 0xe7, 0xe2, + 0xe1, 0xa0, 0xa3, 0xa6, 0xa5, 0xac, 0xaf, 0xaa, 0xa9, 0xb8, 0xbb, 0xbe, 0xbd, 0xb4, 0xb7, 0xb2, 0xb1, 0x90, 0x93, + 0x96, 0x95, 0x9c, 0x9f, 0x9a, 0x99, 0x88, 0x8b, 0x8e, 0x8d, 0x84, 0x87, 0x82, 0x81, 0x9b, 0x98, 0x9d, 0x9e, 0x97, + 0x94, 0x91, 0x92, 0x83, 0x80, 0x85, 0x86, 0x8f, 0x8c, 0x89, 0x8a, 0xab, 0xa8, 0xad, 0xae, 0xa7, 0xa4, 0xa1, 0xa2, + 0xb3, 0xb0, 0xb5, 0xb6, 0xbf, 0xbc, 0xb9, 0xba, 0xfb, 0xf8, 0xfd, 0xfe, 0xf7, 0xf4, 0xf1, 0xf2, 0xe3, 0xe0, 0xe5, + 0xe6, 0xef, 0xec, 0xe9, 0xea, 0xcb, 0xc8, 0xcd, 0xce, 0xc7, 0xc4, 0xc1, 0xc2, 0xd3, 0xd0, 0xd5, 0xd6, 0xdf, 0xdc, + 0xd9, 0xda, 0x5b, 0x58, 0x5d, 0x5e, 0x57, 0x54, 0x51, 0x52, 0x43, 0x40, 0x45, 0x46, 0x4f, 0x4c, 0x49, 0x4a, 0x6b, + 0x68, 0x6d, 0x6e, 0x67, 0x64, 0x61, 0x62, 0x73, 0x70, 0x75, 0x76, 0x7f, 0x7c, 0x79, 0x7a, 0x3b, 0x38, 0x3d, 0x3e, + 0x37, 0x34, 0x31, 0x32, 0x23, 0x20, 0x25, 0x26, 0x2f, 0x2c, 0x29, 0x2a, 0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, + 0x02, 0x13, 0x10, 0x15, 0x16, 0x1f, 0x1c, 0x19, 0x1a, }; static const uint8_t GF9[256] = { - 0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f, 0x48, 0x41, 0x5a, 0x53, - 0x6c, 0x65, 0x7e, 0x77, 0x90, 0x99, 0x82, 0x8b, 0xb4, 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ec, 0xe5, 0xfe, 0xf7, 0xc8, + 0xc1, 0xda, 0xd3, 0xa4, 0xad, 0xb6, 0xbf, 0x80, 0x89, 0x92, 0x9b, 0x7c, 0x75, 0x6e, 0x67, 0x58, 0x51, 0x4a, 0x43, + 0x34, 0x3d, 0x26, 0x2f, 0x10, 0x19, 0x02, 0x0b, 0xd7, 0xde, 0xc5, 0xcc, 0xf3, 0xfa, 0xe1, 0xe8, 0x9f, 0x96, 0x8d, + 0x84, 0xbb, 0xb2, 0xa9, 0xa0, 0x47, 0x4e, 0x55, 0x5c, 0x63, 0x6a, 0x71, 0x78, 0x0f, 0x06, 0x1d, 0x14, 0x2b, 0x22, + 0x39, 0x30, 0x9a, 0x93, 0x88, 0x81, 0xbe, 0xb7, 0xac, 0xa5, 0xd2, 0xdb, 0xc0, 0xc9, 0xf6, 0xff, 0xe4, 0xed, 0x0a, + 0x03, 0x18, 0x11, 0x2e, 0x27, 0x3c, 0x35, 0x42, 0x4b, 0x50, 0x59, 0x66, 0x6f, 0x74, 0x7d, 0xa1, 0xa8, 0xb3, 0xba, + 0x85, 0x8c, 0x97, 0x9e, 0xe9, 0xe0, 0xfb, 0xf2, 0xcd, 0xc4, 0xdf, 0xd6, 0x31, 0x38, 0x23, 0x2a, 0x15, 0x1c, 0x07, + 0x0e, 0x79, 0x70, 0x6b, 0x62, 0x5d, 0x54, 0x4f, 0x46, }; static const uint8_t GF11[256] = { - 0x00, 0x0b, 0x16, 0x1d, 0x2c, 0x27, 0x3a, 0x31, 0x58, 0x53, 0x4e, 0x45, - 0x74, 0x7f, 0x62, 0x69, 0xb0, 0xbb, 0xa6, 0xad, 0x9c, 0x97, 0x8a, 0x81, - 0xe8, 0xe3, 0xfe, 0xf5, 0xc4, 0xcf, 0xd2, 0xd9, 0x7b, 0x70, 0x6d, 0x66, - 0x57, 0x5c, 0x41, 0x4a, 0x23, 0x28, 0x35, 0x3e, 0x0f, 0x04, 0x19, 0x12, - 0xcb, 0xc0, 0xdd, 0xd6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, 0x8c, 0x87, 0x9a, 0x91, 0xa0, 0xab, 0xb6, 0xbd, 0xd4, 0xdf, 0xc2, + 0xc9, 0xf8, 0xf3, 0xee, 0xe5, 0x3c, 0x37, 0x2a, 0x21, 0x10, 0x1b, 0x06, 0x0d, 0x64, 0x6f, 0x72, 0x79, 0x48, 0x43, + 0x5e, 0x55, 0x01, 0x0a, 0x17, 0x1c, 0x2d, 0x26, 0x3b, 0x30, 0x59, 0x52, 0x4f, 0x44, 0x75, 0x7e, 0x63, 0x68, 0xb1, + 0xba, 0xa7, 0xac, 0x9d, 0x96, 0x8b, 0x80, 0xe9, 0xe2, 0xff, 0xf4, 0xc5, 0xce, 0xd3, 0xd8, 0x7a, 0x71, 0x6c, 0x67, + 0x56, 0x5d, 0x40, 0x4b, 0x22, 0x29, 0x34, 0x3f, 0x0e, 0x05, 0x18, 0x13, 0xca, 0xc1, 0xdc, 0xd7, 0xe6, 0xed, 0xf0, + 0xfb, 0x92, 0x99, 0x84, 0x8f, 0xbe, 0xb5, 0xa8, 0xa3, }; static const uint8_t GF13[256] = { - 0x00, 0x0d, 0x1a, 0x17, 0x34, 0x39, 0x2e, 0x23, 0x68, 0x65, 0x72, 0x7f, - 0x5c, 0x51, 0x46, 0x4b, 0xd0, 0xdd, 0xca, 0xc7, 0xe4, 0xe9, 0xfe, 0xf3, - 0xb8, 0xb5, 0xa2, 0xaf, 0x8c, 0x81, 0x96, 0x9b, 0xbb, 0xb6, 0xa1, 0xac, - 0x8f, 0x82, 0x95, 0x98, 0xd3, 0xde, 0xc9, 0xc4, 0xe7, 0xea, 0xfd, 0xf0, - 0x6b, 0x66, 0x71, 0x7c, 0x5f, 0x52, 0x45, 0x48, 0x03, 0x0e, 0x19, 0x14, - 0x37, 0x3a, 0x2d, 0x20, 0x6d, 0x60, 0x77, 0x7a, 0x59, 0x54, 0x43, 0x4e, - 0x05, 0x08, 0x1f, 0x12, 0x31, 0x3c, 0x2b, 0x26, 0xbd, 0xb0, 0xa7, 0xa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a, 0xb7, 0xba, 0xad, 0xa0, 0x83, 0x8e, 0x99, 0x94, 0xdf, 0xd2, 0xc5, 0xc8, 0xeb, 0xe6, 0xf1, 0xfc, 0x67, + 0x6a, 0x7d, 0x70, 0x53, 0x5e, 0x49, 0x44, 0x0f, 0x02, 0x15, 0x18, 0x3b, 0x36, 0x21, 0x2c, 0x0c, 0x01, 0x16, 0x1b, + 0x38, 0x35, 0x22, 0x2f, 0x64, 0x69, 0x7e, 0x73, 0x50, 0x5d, 0x4a, 0x47, 0xdc, 0xd1, 0xc6, 0xcb, 0xe8, 0xe5, 0xf2, + 0xff, 0xb4, 0xb9, 0xae, 0xa3, 0x80, 0x8d, 0x9a, 0x97, }; static const uint8_t GF14[256] = { - 0x00, 0x0e, 0x1c, 0x12, 0x38, 0x36, 0x24, 0x2a, 0x70, 0x7e, 0x6c, 0x62, - 0x48, 0x46, 0x54, 0x5a, 0xe0, 0xee, 0xfc, 0xf2, 0xd8, 0xd6, 0xc4, 0xca, - 0x90, 0x9e, 0x8c, 0x82, 0xa8, 0xa6, 0xb4, 0xba, 0xdb, 0xd5, 0xc7, 0xc9, - 0xe3, 0xed, 0xff, 0xf1, 0xab, 0xa5, 0xb7, 0xb9, 0x93, 0x9d, 0x8f, 0x81, - 0x3b, 0x35, 0x27, 0x29, 0x03, 0x0d, 0x1f, 0x11, 0x4b, 0x45, 0x57, 0x59, - 0x73, 0x7d, 0x6f, 0x61, 0xad, 0xa3, 0xb1, 0xbf, 0x95, 0x9b, 0x89, 0x87, - 0xdd, 0xd3, 0xc1, 0xcf, 0xe5, 0xeb, 0xf9, 0xf7, 0x4d, 0x43, 0x51, 0x5f, - 0x75, 0x7b, 0x69, 0x67, 0x3d, 0x33, 0x21, 0x2f, 0x05, 0x0b, 0x19, 0x17, - 0x76, 0x78, 0x6a, 0x64, 0x4e, 0x40, 0x52, 0x5c, 0x06, 0x08, 0x1a, 0x14, - 0x3e, 0x30, 0x22, 0x2c, 0x96, 0x98, 0x8a, 0x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56, 0x37, 0x39, 0x2b, 0x25, + 0x0f, 0x01, 0x13, 0x1d, 0x47, 0x49, 0x5b, 0x55, 0x7f, 0x71, 0x63, 0x6d, 0xd7, 0xd9, 0xcb, 0xc5, 0xef, 0xe1, 0xf3, + 0xfd, 0xa7, 0xa9, 0xbb, 0xb5, 0x9f, 0x91, 0x83, 0x8d, }; static uint32_t subword(uint32_t word) { - return (uint32_t)SBOX[word & 0xFF] - | ((uint32_t)SBOX[(word >> 8) & 0xFF] << 8) - | ((uint32_t)SBOX[(word >> 16) & 0xFF] << 16) - | ((uint32_t)SBOX[(word >> 24) & 0xFF] << 24); + return (uint32_t)SBOX[word & 0xFF] | ((uint32_t)SBOX[(word >> 8) & 0xFF] << 8) + | ((uint32_t)SBOX[(word >> 16) & 0xFF] << 16) | ((uint32_t)SBOX[(word >> 24) & 0xFF] << 24); } static uint32_t rotword(uint32_t word) @@ -356,8 +290,7 @@ void aes128_dec(const uint32_t rk[44], uint8_t buf[16]) xorblock(buf, (const uint8_t *)rk); } -void aes128_cbc_mac(const uint32_t rk[44], uint8_t *buf, uint8_t mac[16], - int len) +void aes128_cbc_mac(const uint32_t rk[44], uint8_t *buf, uint8_t mac[16], int len) { // assert((len & 0xFF) == 0); // assert(len >= 16); @@ -371,8 +304,7 @@ void aes128_cbc_mac(const uint32_t rk[44], uint8_t *buf, uint8_t mac[16], } } -void aes128_cbc_enc(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, - size_t len) +void aes128_cbc_enc(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, size_t len) { // assert((len & 0xFF) == 0); @@ -388,8 +320,7 @@ void aes128_cbc_enc(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, } } -void aes128_cbc_dec(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, - size_t len) +void aes128_cbc_dec(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, size_t len) { // assert((len & 0xFF) == 0); for (int i = len - 16; i >= 16; i -= 16) { diff --git a/projects/demonstrator/crypto/aes128.h b/projects/demonstrator/crypto/aes128.h index 93aa87ae..95d6ced7 100644 --- a/projects/demonstrator/crypto/aes128.h +++ b/projects/demonstrator/crypto/aes128.h @@ -12,13 +12,10 @@ void aes128_enc(const uint32_t rk[44], uint8_t buf[16]); void aes128_dec(const uint32_t rk[44], uint8_t buf[16]); // CBC-MAC with AES. -void aes128_cbc_mac(const uint32_t rk[44], uint8_t *buf, uint8_t mac[16], - int len); +void aes128_cbc_mac(const uint32_t rk[44], uint8_t *buf, uint8_t mac[16], int len); // Cipher block chaining encryption -void aes128_cbc_enc(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, - size_t len); +void aes128_cbc_enc(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, size_t len); // Cipher block chaining decryption -void aes128_cbc_dec(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, - size_t len); +void aes128_cbc_dec(const uint32_t rk[44], uint8_t iv[16], uint8_t *buf, size_t len); diff --git a/projects/demonstrator/monitor/main.c b/projects/demonstrator/monitor/main.c index 635e8926..8a37d803 100644 --- a/projects/demonstrator/monitor/main.c +++ b/projects/demonstrator/monitor/main.c @@ -38,26 +38,22 @@ char *const crypto_buffer = SHARED1_MEM; void setup_memory(void) { s3k_cap_t pmp; - pmp = s3k_mk_pmp(s3k_napot_encode((uint64_t)APP0_MEM, APP0_MEM_LEN), - S3K_MEM_RW); + pmp = s3k_mk_pmp(s3k_napot_encode((uint64_t)APP0_MEM, APP0_MEM_LEN), S3K_MEM_RW); s3k_cap_derive(0x5, 0x10, pmp); s3k_pmp_load(0x10, 4); s3k_sync_mem(); - pmp = s3k_mk_pmp(s3k_napot_encode((uint64_t)APP0_MEM, APP0_MEM_LEN), - S3K_MEM_RWX); + pmp = s3k_mk_pmp(s3k_napot_encode((uint64_t)APP0_MEM, APP0_MEM_LEN), S3K_MEM_RWX); s3k_cap_derive(0x5, 0x12, pmp); s3k_mon_cap_move(MONITOR_CIDX, MONITOR_PID, 0x12, APP0_PID, 0x0); s3k_mon_pmp_load(MONITOR_CIDX, APP0_PID, 0x0, 0x0); - pmp = s3k_mk_pmp(s3k_napot_encode((uint64_t)APP1_MEM, APP1_MEM_LEN), - S3K_MEM_RW); + pmp = s3k_mk_pmp(s3k_napot_encode((uint64_t)APP1_MEM, APP1_MEM_LEN), S3K_MEM_RW); s3k_cap_derive(0x6, 0x11, pmp); s3k_pmp_load(0x11, 5); s3k_sync_mem(); - pmp = s3k_mk_pmp(s3k_napot_encode((uint64_t)APP1_MEM, APP1_MEM_LEN), - S3K_MEM_RWX); + pmp = s3k_mk_pmp(s3k_napot_encode((uint64_t)APP1_MEM, APP1_MEM_LEN), S3K_MEM_RWX); s3k_cap_derive(0x6, 0x12, pmp); s3k_mon_cap_move(MONITOR_CIDX, MONITOR_PID, 0x12, APP1_PID, 0x0); s3k_mon_pmp_load(MONITOR_CIDX, APP1_PID, 0x0, 0x0); @@ -195,8 +191,7 @@ void read_app(s3k_msg_t *msg, app_data_t *app) void reset_app(s3k_msg_t *msg, app_data_t *app) { - s3k_mon_reg_write(MONITOR_CIDX, app->pid, S3K_REG_PC, - (uint64_t)app->memory); + s3k_mon_reg_write(MONITOR_CIDX, app->pid, S3K_REG_PC, (uint64_t)app->memory); msg->data[0] = 2; memcpy(uart_buffer, "ok", 2); } diff --git a/projects/hello/Makefile b/projects/hello/Makefile index a2997c1d..78b0b443 100644 --- a/projects/hello/Makefile +++ b/projects/hello/Makefile @@ -1,43 +1,22 @@ .POSIX: -export PLATFORM ?=qemu_virt4 -export ROOT :=${abspath ../..} -export BUILD :=${abspath build/${PLATFORM}} -export S3K_CONF_H :=${abspath s3k_conf.h} +export S3K_ROOT:=${abspath ../..} -include ${ROOT}/tools.mk +include ${S3K_ROOT}/tools/tools.mk -APPS=app0 app1 +PROGRAMS=kern +#app0 app1 ELFS:=${patsubst %, ${BUILD}/%.elf, kernel ${APPS}} -all: kernel ${APPS} +all: ${PROGRAMS} clean: - rm -rf ${BUILD} + for i in $(PROGRAMS); do \ + ${MAKE} -C $$i clean; \ + done -common: - @${MAKE} -C ${ROOT}/common +${PROGRAMS}: + @${MAKE} -C $@ all -kernel: common - @${MAKE} -C ${ROOT}/kernel - -${APPS}: common - @${MAKE} -f ../build.mk PROGRAM=$@ - -qemu: kernel ${APPS} - @ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh - -qemu-gdb: kernel ${APPS} - @ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh -gdb tcp::3333 -S - -gdb: kernel ${APPS} - @ELFS="${ELFS}" ${ROOT}/scripts/gdb.sh - -gdb-openocd: kernel ${APPS} - @ELFS="${ELFS}" ${ROOT}/scripts/gdb-openocd.sh - -size: ${ELFS} - ${SIZE} ${ELFS} - -.PHONY: all clean size qemu qemu-gdb gdb kernel common ${APPS} +.PHONY: all clean ${PROGRAMS} diff --git a/projects/hello/app0/qemu.ld b/projects/hello/app0/qemu.ld new file mode 100644 index 00000000..b7a4d735 --- /dev/null +++ b/projects/hello/app0/qemu.ld @@ -0,0 +1,40 @@ +/* See LICENSE file for copyright and license details. */ +OUTPUT_ARCH(riscv) +ENTRY(_start) + +MEMORY { + RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x10000 +} + +__stack_size = 1024; +__global_pointer$ = MIN(_sdata + 0x800, MAX(_data + 0x800, _end - 0x800)); + +SECTIONS { + .text : { + *( .init ) + *( .text .text.* ) + } > RAM + + .data : { + _data = . ; + *( .data ) + *( .data.* ) + _sdata = . ; + *( .sdata ) + *( .sdata.* ) + } > RAM + + .bss : { + _bss = .; + _sbss = .; + *(.sbss .sbss.*) + *(.bss .bss.*) + _end = .; + } > RAM + + .stack : ALIGN(8) { + . += __stack_size; + __stack_pointer = .; + _end = .; + } +} diff --git a/projects/hello/app1/qemu.ld b/projects/hello/app1/qemu.ld new file mode 100644 index 00000000..a6f031ca --- /dev/null +++ b/projects/hello/app1/qemu.ld @@ -0,0 +1,40 @@ +/* See LICENSE file for copyright and license details. */ +OUTPUT_ARCH(riscv) +ENTRY(_start) + +MEMORY { + RAM (rwx) : ORIGIN = 0x80020000, LENGTH = 0x10000 +} + +__stack_size = 1024; +__global_pointer$ = MIN(_sdata + 0x800, MAX(_data + 0x800, _end - 0x800)); + +SECTIONS { + .text : { + *( .init ) + *( .text .text.* ) + } > RAM + + .data : { + _data = . ; + *( .data ) + *( .data.* ) + _sdata = . ; + *( .sdata ) + *( .sdata.* ) + } > RAM + + .bss : { + _bss = .; + _sbss = .; + *(.sbss .sbss.*) + *(.bss .bss.*) + _end = .; + } > RAM + + .stack : ALIGN(8) { + . += __stack_size; + __stack_pointer = .; + _end = .; + } +} diff --git a/projects/hello/kern/Makefile b/projects/hello/kern/Makefile new file mode 100644 index 00000000..a6162c80 --- /dev/null +++ b/projects/hello/kern/Makefile @@ -0,0 +1,6 @@ +ifeq ($(S3K_ROOT),) +$(error "S3K_ROOT not set") +endif + + +include $(S3K_ROOT)/tools/kern/qemu.mk diff --git a/projects/hello/kern/qemu.h b/projects/hello/kern/qemu.h new file mode 100644 index 00000000..70f63d62 --- /dev/null +++ b/projects/hello/kern/qemu.h @@ -0,0 +1,9 @@ +#define S3K_MIN_HART 0 +#define S3K_MAX_HART 0 +#define S3K_PMP_CNT 8 +#define S3K_CHAN_CNT 8 +#define S3K_PROC_CNT 8 +#define S3K_CAP_CNT 16 +#define S3K_SLOT_CNT 32 +#define S3K_SLOT_LEN 1000 +#define S3K_LOG_STACK_SIZE 8 diff --git a/projects/ping-pong/app0/main.c b/projects/ping-pong/app0/main.c index dbeb4821..ca4187b5 100644 --- a/projects/ping-pong/app0/main.c +++ b/projects/ping-pong/app0/main.c @@ -44,8 +44,7 @@ void setup_app1(uint64_t tmp) s3k_mon_pmp_load(MONITOR, APP1_PID, 1, 1); // derive a time slice capability - s3k_cap_derive(HART0_TIME, tmp, - s3k_mk_time(S3K_MIN_HART, 0, S3K_SLOT_CNT / 2)); + s3k_cap_derive(HART0_TIME, tmp, s3k_mk_time(S3K_MIN_HART, 0, S3K_SLOT_CNT / 2)); s3k_mon_cap_move(MONITOR, APP0_PID, tmp, APP1_PID, 2); // Write start PC of app1 to PC @@ -54,12 +53,8 @@ void setup_app1(uint64_t tmp) void setup_socket(uint64_t socket, uint64_t tmp) { - s3k_cap_derive(CHANNEL, socket, - s3k_mk_socket(0, S3K_IPC_YIELD, - S3K_IPC_SDATA | S3K_IPC_CDATA, 0)); - s3k_cap_derive(socket, tmp, - s3k_mk_socket(0, S3K_IPC_YIELD, - S3K_IPC_SDATA | S3K_IPC_CDATA, 1)); + s3k_cap_derive(CHANNEL, socket, s3k_mk_socket(0, S3K_IPC_YIELD, S3K_IPC_SDATA | S3K_IPC_CDATA, 0)); + s3k_cap_derive(socket, tmp, s3k_mk_socket(0, S3K_IPC_YIELD, S3K_IPC_SDATA | S3K_IPC_CDATA, 1)); s3k_mon_cap_move(MONITOR, APP0_PID, tmp, APP1_PID, 3); } diff --git a/projects/trapped/app0/main.c b/projects/trapped/app0/main.c index 608c91f2..91902561 100644 --- a/projects/trapped/app0/main.c +++ b/projects/trapped/app0/main.c @@ -40,9 +40,7 @@ void trap_handler(void) setup_uart(16); alt_puts("uart is now setup!"); - alt_printf( - "error info:\n- epc: 0x%x\n- esp: 0x%x\n- ecause: 0x%x\n- eval: 0x%x\n", - epc, esp, ecause, eval); + alt_printf("error info:\n- epc: 0x%x\n- esp: 0x%x\n- ecause: 0x%x\n- eval: 0x%x\n", epc, esp, ecause, eval); alt_printf("restoring pc and sp\n\n"); // __attribute__((interrupt("machine"))) replaces `ret` with an `mret`. // When mret is executed in user-mode, the kernel catches it setting the diff --git a/sys/includes/alt/io.h b/sys/includes/alt/io.h new file mode 100644 index 00000000..1377f1fc --- /dev/null +++ b/sys/includes/alt/io.h @@ -0,0 +1,44 @@ +#pragma once +#include + +typedef struct file FILE; + +struct file { + int (*_putc)(struct file *, char c); + int (*_getc)(struct file *); + void (*_flush)(struct file *); +}; + +int alt_fputc(FILE *f, char c); +int alt_fgetc(FILE *f); +void alt_fflush(FILE *f); +int alt_fwrite(FILE *f, const char *buf, int size); +int alt_fread(FILE *f, char *buf, int size); +int alt_fgetstr(FILE *f, char *s); +int alt_fputstr(FILE *f, const char *s); +int alt_fputuint(FILE *f, unsigned long long val); +int alt_fputhex(FILE *f, unsigned long long val); +int alt_vfprintf(FILE *f, const char *fmt, va_list ap); +int alt_fprintf(FILE *f, const char *fmt, ...); + +int alt_putc(char c); +int alt_getc(void); +void alt_flush(void); +int alt_write(const char *buf, int size); +int alt_read(char *buf, int size); +int alt_getstr(char *buf); +int alt_putstr(const char *s); +int alt_putuint(unsigned long long val); +int alt_puthex(unsigned long long val); +int alt_vprintf(const char *fmt, va_list ap); +int alt_printf(const char *fmt, ...); + +int alt_sputuint(char *buf, unsigned long long val); +int alt_sputhex(char *buf, unsigned long long val); +int alt_vsprintf(char *buf, const char *fmt, va_list ap); +int alt_sprintf(char *buf, const char *fmt, ...); + +int alt_snputuint(char *buf, int size, unsigned long long val); +int alt_snputhex(char *buf, int size, unsigned long long val); +int alt_vsnprintf(char *buf, int size, const char *fmt, va_list ap); +int alt_snprintf(char *buf, int size, const char *fmt, ...); diff --git a/sys/includes/drivers/time.h b/sys/includes/drivers/time.h new file mode 100644 index 00000000..6cbb62fe --- /dev/null +++ b/sys/includes/drivers/time.h @@ -0,0 +1,6 @@ +#pragma once + +unsigned long long time_get(void); +void time_set(unsigned long long); +unsigned long long timeout_get(int); +void timeout_set(int, unsigned long long); diff --git a/sys/includes/drivers/uart/ns16550a.h b/sys/includes/drivers/uart/ns16550a.h new file mode 100644 index 00000000..06af7136 --- /dev/null +++ b/sys/includes/drivers/uart/ns16550a.h @@ -0,0 +1,20 @@ +#pragma once +#include "alt/io.h" + +#define UART_NS16550A(base) \ + (struct uart_ns16550a) \ + { \ + ._putc = uart_ns16550a_putc, ._getc = uart_ns16550a_getc, ._flush = uart_ns16550a_flush, \ + ._base = (char *)base, \ + } + +typedef struct uart_ns16550a { + int (*_putc)(FILE *f, char c); + int (*_getc)(FILE *f); + void (*_flush)(FILE *f); + char *_base; +} uart_ns16550a_t; + +int uart_ns16550a_putc(FILE *f, char c); +int uart_ns16550a_getc(FILE *f); +void uart_ns16550a_flush(FILE *f); diff --git a/sys/includes/drivers/uart/sifive.h b/sys/includes/drivers/uart/sifive.h new file mode 100644 index 00000000..6065b0a6 --- /dev/null +++ b/sys/includes/drivers/uart/sifive.h @@ -0,0 +1,20 @@ +#pragma once +#include "alt/io.h" + +#define UART_SIFIVE(base_address) \ + (struct uart_sifive) \ + { \ + ._putc = uart_sifive_putc, ._getc = uart_sifive_getc, ._flush = uart_sifive_flush, \ + .base_address = (int *)base_address, \ + } + +struct uart_sifive { + int (*_putc)(FILE *f, char c); + int (*_getc)(FILE *f); + void (*_flush)(FILE *f); + int *base_address; +}; + +int uart_sifive_putc(FILE *f, char c); +int uart_sifive_getc(FILE *f); +void uart_sifive_flush(FILE *f); diff --git a/sys/includes/kern/cap.h b/sys/includes/kern/cap.h new file mode 100644 index 00000000..9ecd3e5a --- /dev/null +++ b/sys/includes/kern/cap.h @@ -0,0 +1,148 @@ +#pragma once + +#include "kern/error.h" +#include "kern/types.h" + +// Min logarithmic size of a memory slice +#define MIN_BLOCK_SIZE 12 + +// Max logarithmic size of a memory slice +#define MAX_BLOCK_SIZE 27 + +enum mem_perm { + MEM_R = 0x1, + MEM_W = 0x2, + MEM_X = 0x4, + MEM_RW = MEM_R | MEM_W, + MEM_RX = MEM_R | MEM_X, + MEM_RWX = MEM_R | MEM_W | MEM_X, +}; + +// IPC Modes +enum ipc_mode { + IPC_NOYIELD = 0x0, // Non-Yielding Synchronous + IPC_YIELD = 0x1, // Yielding Synchronous +}; + +// IPC Permissions +enum ipc_perm { + IPC_SDATA = 0x1, // Server can send data + IPC_SCAP = 0x2, // Server can send capabilities + IPC_CDATA = 0x4, // Client can send data + IPC_CCAP = 0x8, // Client can send capabilities +}; + +// Capability types +enum capty { + CAPTY_NONE = 0, ///< No capability. + CAPTY_TIME = 1, ///< Time Slice capability. + CAPTY_MEMORY = 2, ///< Memory Slice capability. + CAPTY_PMP = 3, ///< PMP Frame capability. + CAPTY_MONITOR = 4, ///< Monitor capability. + CAPTY_CHANNEL = 5, ///< IPC Channel capability. + CAPTY_SERVER = 6, ///< IPC Socket capability. + CAPTY_CLIENT = 7, ///< IPC Socket capability. + CAPTY_COUNT ///< Number of capability types +}; + +typedef union { + uint64_t type : 4; + + uint64_t raw; + + struct { + uint64_t type : 4; + uint64_t _padding : 4; + uint64_t hart : 8; + uint64_t begin : 16; + uint64_t mark : 16; + uint64_t end : 16; + } time; + + struct { + uint64_t type : 4; + uint64_t rwx : 3; + uint64_t lock : 1; + uint64_t tag : 8; + uint64_t begin : 16; + uint64_t mark : 16; + uint64_t end : 16; + } mem; + + struct { + uint64_t type : 4; + uint64_t rwx : 3; + uint64_t _padding : 9; + uint64_t addr : 48; + } pmp; + + struct { + uint64_t type : 4; + uint64_t _padding : 12; + uint64_t begin : 16; + uint64_t mark : 16; + uint64_t end : 16; + } mon; + + struct { + uint64_t type : 4; + uint64_t _padding : 12; + uint64_t begin : 16; + uint64_t mark : 16; + uint64_t end : 16; + } chan; + + struct { + uint64_t type : 4; + uint64_t mode : 4; + uint64_t permission : 8; + uint64_t channel : 16; + uint64_t _padding : 32; + } server; + + struct { + uint64_t type : 4; + uint64_t mode : 4; + uint64_t permission : 8; + uint64_t channel : 16; + uint64_t tag : 32; + } client; +} Cap; + +/// Capability description + +_Static_assert(sizeof(Cap) == 8, "cap_t has the wrong size"); + +static inline Word CapIdx(Pid pid, Word reg) +{ + return pid * S3K_CAP_CNT + reg; +} + +static inline uint64_t pmp_napot_decode_end(uint64_t addr) +{ + return pmp_napot_decode_bgn(addr) + pmp_napot_decode_size(addr); +} + +static inline void pmp_napot_decode(uint64_t addr, uint64_t *bgn, uint64_t *end) +{ + *bgn = pmp_napot_decode_bgn(addr); + *end = pmp_napot_decode_end(addr); +} + +static inline uint64_t pmp_napot_encode(uint64_t bgn, uint64_t end) +{ + return (bgn | ((end - bgn) / 2 - 1)) >> 2; +} + +#define CAP_PMP(_addr, _rwx) 0 +#define CAP_MEMORY(_tag, _begin, _end, _rwx) 0 +#define CAP_MONITOR(_begin, _end) 0 +#define CAP_CHANNEL(_begin, _end) 0 +#define CAP_TIME(_begin, _end) 0 +#define CAP_NULL ((Cap){.raw = 0}) + +Word CapRead(Word i, Cap *cap); +Word CapMove(Word src, Word dst); +Word CapDelete(Word i); +Word CapRevoke(Word i); +Word CapDerive(Word src, Word dst, Cap cap); diff --git a/sys/includes/kern/csr.h b/sys/includes/kern/csr.h new file mode 100644 index 00000000..c6270616 --- /dev/null +++ b/sys/includes/kern/csr.h @@ -0,0 +1,33 @@ +#pragma once +/** + * @file csr.h + * @brief Interact with control and status registers. + * @copyright MIT License + * @author Henrik Karlsson (henrik10@kth.se) + */ + +/* Machine CSR constants */ +#define MIP_MSIP 0x8 +#define MIE_MSIE 0x8 +#define MIP_MTIP 0x80 +#define MIE_MTIE 0x80 +#define MCAUSE_USER_ECALL 0x8 +#define MSTATUS_MIE 0x8 + +#ifndef __ASSEMBLER__ +#define CsrRead(__reg) \ + ({ \ + unsigned long __ret; \ + __asm__ volatile("csrr %0," #__reg : "=r"(__ret)); \ + __ret; \ + }) +#define CsrWrite(__reg, __val) ({ __asm__ volatile("csrw " #__reg ", %0" ::"r"(__val)); }) +#define CsrSwap(__reg, __val) \ + ({ \ + unsigned long __ret; \ + __asm__ volatile("csrrw %0," #__reg ",%1" : "=r"(__ret) : "r"(__val)); \ + __ret; \ + }) +#define CsrSet(__reg, __val) ({ __asm__ volatile("csrs " #__reg ", %0" ::"r"(__val)); }) +#define CsrClear(__reg, __val) ({ __asm__ volatile("csrc " #__reg ", %0" ::"r"(__val)); }) +#endif diff --git a/sys/includes/kern/error.h b/sys/includes/kern/error.h new file mode 100644 index 00000000..74d5b655 --- /dev/null +++ b/sys/includes/kern/error.h @@ -0,0 +1,15 @@ +#pragma once + +typedef enum { + SUCCESS = 0, + ERR_EMPTY, + ERR_EXISTS, + ERR_INVARG, + ERR_INVDRV, + ERR_INVCAP, + ERR_INVSTATE, + ERR_PREEMPT, + ERR_TIMEOUT, + ERR_SUSPENDED, + CONTINUE = -1, // Special for revocation +} Error; diff --git a/kernel/inc/exception.h b/sys/includes/kern/exception.h similarity index 56% rename from kernel/inc/exception.h rename to sys/includes/kern/exception.h index 53b37d3d..3042a1c3 100644 --- a/kernel/inc/exception.h +++ b/sys/includes/kern/exception.h @@ -6,8 +6,7 @@ * @author Henrik Karlsson (henrik10@kth.se) */ -#include "proc.h" +#include "kern/proc.h" +#include "kern/types.h" -#include - -proc_t *exception_handler(proc_t *proc, uint64_t mcause, uint64_t mtval); +Proc *ExceptionHandler(Proc *proc, Word mcause, Word mtval); diff --git a/sys/includes/kern/interrupt.h b/sys/includes/kern/interrupt.h new file mode 100644 index 00000000..a838a8b2 --- /dev/null +++ b/sys/includes/kern/interrupt.h @@ -0,0 +1,6 @@ +#pragma once + +#include "kern/proc.h" +#include "kern/types.h" + +Proc *InterruptHandler(Proc *proc, Word mcause, Word mtval); diff --git a/kernel/inc/kassert.h b/sys/includes/kern/kassert.h similarity index 91% rename from kernel/inc/kassert.h rename to sys/includes/kern/kassert.h index 369bbb2f..0bcc7085 100644 --- a/kernel/inc/kassert.h +++ b/sys/includes/kern/kassert.h @@ -1,4 +1,5 @@ #pragma once + #include "kprintf.h" /** @@ -17,8 +18,7 @@ */ #ifndef NDEBUG -#define KASSERT_FAILURE(FILE, LINE) \ - kprintf(0, "Kernel assertion failed at %s:%d.\n", FILE, LINE); +#define KASSERT_FAILURE(FILE, LINE) kprintf(0, "Kernel assertion failed at %s:%d.\n", FILE, LINE); #define KASSERT(expr) \ do { \ diff --git a/sys/includes/kern/kprintf.h b/sys/includes/kern/kprintf.h new file mode 100644 index 00000000..a332a93a --- /dev/null +++ b/sys/includes/kern/kprintf.h @@ -0,0 +1,11 @@ +#pragma once + +#include "alt/io.h" + +static inline void kprintf(int verb, const char *restrict fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + alt_printf(fmt, ap); + va_end(ap); +} diff --git a/kernel/inc/macro.h b/sys/includes/kern/macro.h similarity index 93% rename from kernel/inc/macro.h rename to sys/includes/kern/macro.h index ca5e087a..92aae97e 100644 --- a/kernel/inc/macro.h +++ b/sys/includes/kern/macro.h @@ -21,3 +21,5 @@ /* Returns the size of an array */ #define ARRAY_SIZE(x) (sizeof(x) / (sizeof((x)[0]))) + +#define BIT_SUBSET(x, y) (((x) & (y)) == (x)) diff --git a/kernel/inc/macro.inc b/sys/includes/kern/macro.inc similarity index 62% rename from kernel/inc/macro.inc rename to sys/includes/kern/macro.inc index fe0cf1f4..249ff679 100644 --- a/kernel/inc/macro.inc +++ b/sys/includes/kern/macro.inc @@ -2,13 +2,10 @@ // See LICENSE file for copyright and license details. .macro ld_sp tmp - la sp,_sp + la sp,(kernel_stack + 256) csrr \tmp,mhartid -#if S3K_MIN_HART != 0 - addi \tmp,\tmp,-S3K_MIN_HART -#endif - slli \tmp,\tmp,S3K_LOG_STACK_SIZE - sub sp,sp,\tmp + slli \tmp,\tmp,8 + add sp,sp,\tmp .endm .macro ld_gp diff --git a/sys/includes/kern/offsets.h b/sys/includes/kern/offsets.h new file mode 100644 index 00000000..87e25563 --- /dev/null +++ b/sys/includes/kern/offsets.h @@ -0,0 +1,55 @@ +#pragma once + +#define _OFFSET(x) (x * 8) + +#define PROC_STATE _OFFSET(0) + +/* Register offsets */ +#define PROC_PC _OFFSET(1) +#define PROC_RA _OFFSET(2) +#define PROC_SP _OFFSET(3) +#define PROC_GP _OFFSET(4) +#define PROC_TP _OFFSET(5) +#define PROC_T0 _OFFSET(6) +#define PROC_T1 _OFFSET(7) +#define PROC_T2 _OFFSET(8) +#define PROC_S0 _OFFSET(9) +#define PROC_S1 _OFFSET(10) +#define PROC_A0 _OFFSET(11) +#define PROC_A1 _OFFSET(12) +#define PROC_A2 _OFFSET(13) +#define PROC_A3 _OFFSET(14) +#define PROC_A4 _OFFSET(15) +#define PROC_A5 _OFFSET(16) +#define PROC_A6 _OFFSET(17) +#define PROC_A7 _OFFSET(18) +#define PROC_S2 _OFFSET(19) +#define PROC_S3 _OFFSET(20) +#define PROC_S4 _OFFSET(21) +#define PROC_S5 _OFFSET(22) +#define PROC_S6 _OFFSET(23) +#define PROC_S7 _OFFSET(24) +#define PROC_S8 _OFFSET(25) +#define PROC_S9 _OFFSET(26) +#define PROC_S10 _OFFSET(27) +#define PROC_S11 _OFFSET(28) +#define PROC_T3 _OFFSET(29) +#define PROC_T4 _OFFSET(30) +#define PROC_T5 _OFFSET(31) +#define PROC_T6 _OFFSET(32) +#define PROC_TPC _OFFSET(33) +#define PROC_TSP _OFFSET(34) +#define PROC_EPC _OFFSET(35) +#define PROC_ESP _OFFSET(36) +#define PROC_ECAUSE _OFFSET(37) +#define PROC_EVAL _OFFSET(38) +#define PROC_SERVTIME _OFFSET(39) +#define PROC_PMPCFG0 _OFFSET(40) +#define PROC_PMPADDR0 _OFFSET(41) +#define PROC_PMPADDR1 _OFFSET(42) +#define PROC_PMPADDR2 _OFFSET(43) +#define PROC_PMPADDR3 _OFFSET(44) +#define PROC_PMPADDR4 _OFFSET(45) +#define PROC_PMPADDR5 _OFFSET(46) +#define PROC_PMPADDR6 _OFFSET(47) +#define PROC_PMPADDR7 _OFFSET(48) diff --git a/sys/includes/kern/proc.h b/sys/includes/kern/proc.h new file mode 100644 index 00000000..fe55849f --- /dev/null +++ b/sys/includes/kern/proc.h @@ -0,0 +1,76 @@ +#pragma once +/** + * @file proc.h + * @brief Defines the process control block and its associated functions. + * + * This file contains the definition of the `proc_t` data structure, which + * represents a process control block (PCB) in the operating system. It also + * contains the declarations of functions for manipulating the PCB. + * + * @copyright MIT License + */ + +#include "kern/types.h" + +#define REGISTER_COUNT ((sizeof(Registers) / sizeof(Word))) + +typedef unsigned long Pid; +typedef unsigned long ProcState; + +typedef struct { + Word pc, ra, sp, gp, tp; + Word t0, t1, t2; + Word s0, s1; + Word a0, a1, a2, a3, a4, a5, a6, a7; + Word s2, s3, s4, s5, s6, s7, s8, s9, s10, s11; + Word t3, t4, t5, t6; + Word tpc, tsp; + Word epc, esp, ecause, eval; + Word servtime; +} Registers; + +typedef struct { + Word cfg; + Word addr[8]; +} PmpConf; + +typedef enum { + PSF_BUSY = 1, + PSF_BLOCKED = 2, + PSF_SUSPENDED = 4, +} ProcStateFlag; + +typedef struct { + Registers regs; + PmpConf pmp; + ProcState state; + Pid pid; + Time timeout; +} Proc; + +register Proc *const current __asm__("tp"); + +/** + * Initializes all processes in the system. + * + * @note This function should be called only once during system startup. + */ +void ProcInit(void); + +/** + * @brief Gets the process corresponding to a given process ID. + * + * @param pid The process ID to look for. + * @return A pointer to the process corresponding to the given PID. + */ +Proc *ProcGet(Pid pid); + +ProcState ProcGetState(Proc *proc); + +bool ProcAcquire(Proc *proc); +void ProcRelease(Proc *proc); +void ProcSuspend(Proc *proc); +void ProcResume(Proc *proc); +void ProcIpcWait(Proc *proc, Word chan); +bool ProcIpcAcquire(Proc *proc, Word chan); +bool ProcIsSuspended(Proc *proc); diff --git a/kernel/inc/sched.h b/sys/includes/kern/sched.h similarity index 72% rename from kernel/inc/sched.h rename to sys/includes/kern/sched.h index 482883c7..77f485f4 100644 --- a/kernel/inc/sched.h +++ b/sys/includes/kern/sched.h @@ -1,4 +1,7 @@ #pragma once + +#include "kern/proc.h" + /** * @file sched.h * @brief Scheduler. @@ -8,12 +11,6 @@ * a temporary fix in sched_next. */ -#include "macro.h" -#include "proc.h" - -#include -#include - /** * @brief Initialize the scheduler. * @@ -21,7 +18,7 @@ * the execution of processes on the system. It sets up the necessary data * structures and configurations to support scheduling. */ -void sched_init(void); +void SchedInit(void); /** * @brief Find the next process to schedule. @@ -29,11 +26,10 @@ void sched_init(void); * This function finds the next process to schedule based on the current * state of the system. */ -proc_t *sched(void); +Proc *SchedNext(void); /// Let pid run on hartid, begin-end. -void sched_update(uint64_t pid, uint64_t end, uint64_t hartid, uint64_t from, - uint64_t to); +void SchedUpdate(Word pid, Word hart, Word bgn, Word end); /// Delete scheduling at hartid, begin-end. -void sched_delete(uint64_t hartid, uint64_t from, uint64_t to); +void SchedDelete(Word hartid, Word bgn, Word end); diff --git a/sys/includes/kern/syscall.h b/sys/includes/kern/syscall.h new file mode 100644 index 00000000..c497c022 --- /dev/null +++ b/sys/includes/kern/syscall.h @@ -0,0 +1,6 @@ +#pragma once + +#include "kern/proc.h" +#include "kern/types.h" + +Proc *SyscallHandler(Proc *proc); diff --git a/kernel/inc/trap.h b/sys/includes/kern/trap.h similarity index 51% rename from kernel/inc/trap.h rename to sys/includes/kern/trap.h index 3b3edb06..ba72c170 100644 --- a/kernel/inc/trap.h +++ b/sys/includes/kern/trap.h @@ -5,10 +5,9 @@ * @copyright MIT License * @author Henrik Karlsson (henrik10@kth.se) */ -#include "macro.h" +#include "kern/macro.h" +#include "kern/proc.h" -#include - -void trap_handle(void); -void trap_entry(void) NORETURN; -void trap_exit(void) NORETURN; +void TrapHandler(void) NORETURN; +void TrapResume(Proc *) NORETURN; +void TrapReturn(Proc *) NORETURN; diff --git a/sys/includes/kern/types.h b/sys/includes/kern/types.h new file mode 100644 index 00000000..342e9175 --- /dev/null +++ b/sys/includes/kern/types.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +typedef unsigned long Word; +typedef unsigned char Byte; +typedef unsigned long long Time; +typedef unsigned long Pid; + +#define NULL ((void *)0) diff --git a/sys/includes/kern/utils.h b/sys/includes/kern/utils.h new file mode 100644 index 00000000..db0da8ca --- /dev/null +++ b/sys/includes/kern/utils.h @@ -0,0 +1,50 @@ +#pragma once + +#include "kern/cap.h" +#include "kern/csr.h" +#include "kern/types.h" + +static inline bool BitSubset(Word a, Word b) +{ + return (a & ~b) == 0; +} + +static inline Word PmpNapotDecodeBase(Word addr) +{ + return ((addr + 1) & addr) << 2; +} + +static inline Word PmpNapotDecodeSize(Word addr) +{ + return (((addr + 1) ^ addr) + 1) << 2; +} + +static inline Word CapMemBegin(Cap cap) +{ + return (cap.mem.tag << 27) + (cap.mem.begin << 12); +} + +static inline Word CapMemEnd(Cap cap) +{ + return (cap.mem.tag << 27) + (cap.mem.end << 12); +} + +static inline Word CapMemMark(Cap cap) +{ + return (cap.mem.tag << 27) + (cap.mem.mark << 12); +} + +static inline Word CapPmpBegin(Cap cap) +{ + return PmpNapotDecodeBase(cap.pmp.addr); +} + +static inline Word CapPmpEnd(Cap cap) +{ + return PmpNapotDecodeBase(cap.pmp.addr) + PmpNapotDecodeSize(cap.pmp.addr); +} + +static inline Word Preempted(void) +{ + return CsrRead(mip) & CsrRead(mie); +} diff --git a/kernel/inc/wfi.h b/sys/includes/kern/wfi.h similarity index 85% rename from kernel/inc/wfi.h rename to sys/includes/kern/wfi.h index 3880561b..a53659f5 100644 --- a/kernel/inc/wfi.h +++ b/sys/includes/kern/wfi.h @@ -7,7 +7,7 @@ * @author Henrik Karlsson (henrik10@kth.se) */ -static inline void wfi(void) +static inline void Wfi(void) { __asm__ volatile("wfi"); } diff --git a/kernel/inc/smp/semaphore.h b/sys/includes/smp/semaphore.h similarity index 66% rename from kernel/inc/smp/semaphore.h rename to sys/includes/smp/semaphore.h index c6e848c2..87b76709 100644 --- a/kernel/inc/smp/semaphore.h +++ b/sys/includes/smp/semaphore.h @@ -5,24 +5,24 @@ #include typedef struct semaphore { - uint64_t released; - uint64_t acquired; + uintptr_t released; + uintptr_t acquired; } semaphore_t; /** * Initialize the semaphore with n tickets. */ -void semaphore_init(semaphore_t *sem, uint64_t tickets); +void semaphore_init(semaphore_t *sem, uintptr_t tickets); /** * Acquire n tickets and wait for release. */ -void semaphore_acquire_n(semaphore_t *sem, uint64_t n); +void semaphore_acquire_n(semaphore_t *sem, uintptr_t n); /** * Release n tickets. */ -void semaphore_release_n(semaphore_t *sem, uint64_t n); +void semaphore_release_n(semaphore_t *sem, uintptr_t n); /** * Acquire 1 ticket and wait for release. diff --git a/kernel/inc/smp/taslock.h b/sys/includes/smp/taslock.h similarity index 100% rename from kernel/inc/smp/taslock.h rename to sys/includes/smp/taslock.h diff --git a/sys/src/alt/fprintf.c b/sys/src/alt/fprintf.c new file mode 100644 index 00000000..5e1abbc3 --- /dev/null +++ b/sys/src/alt/fprintf.c @@ -0,0 +1,131 @@ +#include "alt/io.h" + +int alt_fputc(FILE *f, char c) +{ + return f->_putc(f, c); +} + +int alt_fgetc(FILE *f) +{ + return f->_getc(f); +} + +int alt_fwrite(FILE *f, const char *buf, int size) +{ + for (int i = 0; i < size; ++i) + alt_fputc(f, buf[i]); + return size; +} + +int alt_fread(FILE *f, char *buf, int size) +{ + for (int i = 0; i < size; ++i) + buf[i] = alt_fgetc(f); + return size; +} + +int alt_fputuint(FILE *f, unsigned long long val) +{ + int i = 0; + char buf[32]; + do { + int tmp = val % 10; + buf[i++] = '0' + tmp; + val /= 10; + } while (val); + + for (int j = i - 1; j >= 0; --j) + alt_fputc(f, buf[j]); + + return i; +} + +int alt_fputhex(FILE *f, unsigned long long val) +{ + int i = 0; + char buf[16]; + do { + int tmp = val % 16; + buf[i++] = tmp < 10 ? ('0' + tmp) : 'A' + (tmp - 10); + val /= 16; + } while (val); + + for (int j = i - 1; j >= 0; --j) + alt_fputc(f, buf[j]); + + return i; +} + +int alt_fputstr(FILE *f, const char *s) +{ + int i = 0; + while (s[i] != '\0') + alt_fputc(f, s[i++]); + return i; +} + +int alt_fgetstr(FILE *f, char *s) +{ + int i = 0; + while (1) { + s[i] = alt_fgetc(f); + if (s[i] == '\0') + break; + i++; + } + return i; +} + +int alt_vfprintf(FILE *f, const char *fmt, va_list ap) +{ + int i = 0; + int j = 0; + while (fmt[i] != '\0') { + if (fmt[i] != '%') { + alt_fputc(f, fmt[i]); + i++; + j++; + continue; + } + + switch (fmt[i + 1]) { + case '%': + alt_fputc(f, '%'); + j++; + break; + case 'c': + alt_fputc(f, va_arg(ap, int)); + j++; + break; + case 's': + j += alt_fputstr(f, va_arg(ap, char *)); + break; + case 'x': + j += alt_fputhex(f, va_arg(ap, unsigned int)); + break; + case 'X': + j += alt_fputhex(f, va_arg(ap, unsigned long)); + break; + case 'u': + j += alt_fputuint(f, va_arg(ap, unsigned int)); + break; + case 'U': + j += alt_fputuint(f, va_arg(ap, unsigned long)); + break; + default: + // Error: return negative number. + return -1; + } + fmt += 2; + } + return j; +} + +int alt_fprintf(FILE *f, const char *restrict fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int i = alt_vfprintf(f, fmt, ap); + va_end(ap); + return i; +} diff --git a/sys/src/alt/printf.c b/sys/src/alt/printf.c new file mode 100644 index 00000000..b5c57eec --- /dev/null +++ b/sys/src/alt/printf.c @@ -0,0 +1,58 @@ +#include "alt/io.h" + +extern FILE *const _altout; +extern FILE *const _altin; + +int alt_putc(char c) +{ + return alt_fputc(_altout, c); +} + +int alt_getc(void) +{ + return alt_fgetc(_altin); +} + +int alt_write(const char *buf, int size) +{ + return alt_fwrite(_altout, buf, size); +} + +int alt_read(char *buf, int size) +{ + return alt_fread(_altin, buf, size); +} + +int alt_putstr(const char *s) +{ + return alt_fputstr(_altout, s); +} + +int alt_getstr(char *s) +{ + return alt_fgetstr(_altin, s); +} + +int alt_putuint(unsigned long long u) +{ + return alt_fputuint(_altout, u); +} + +int alt_puthex(unsigned long long h) +{ + return alt_fputhex(_altout, h); +} + +int alt_vprintf(const char *restrict fmt, va_list ap) +{ + return alt_vfprintf(_altout, fmt, ap); +} + +int alt_printf(const char *restrict fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int i = alt_vprintf(fmt, ap); + va_end(ap); + return i; +} diff --git a/sys/src/alt/snprintf.c b/sys/src/alt/snprintf.c new file mode 100644 index 00000000..c7d9a300 --- /dev/null +++ b/sys/src/alt/snprintf.c @@ -0,0 +1,77 @@ +#include + +#define BUFFER(buf, size) \ + (struct buffer) \ + { \ + ._putc = buffer_putc, ._getc = buffer_getc, ._flush = buffer_flush, ._buf = buf, ._size = size, \ + ._i = 0 \ + } + +struct buffer { + int (*_putc)(FILE *, char); + int (*_getc)(FILE *); + void (*_flush)(FILE *); + char *_buf; + int _size; + int _i; +}; + +int buffer_putc(FILE *f, char c) +{ + struct buffer *b = (struct buffer *)f; + if (b->_i >= b->_size) + return 0; + return b->_buf[b->_i++] = c; +} + +int buffer_getc(FILE *f) +{ + struct buffer *b = (struct buffer *)f; + if (b->_i >= b->_size) + return 0; + return b->_buf[b->_i++]; +} + +void buffer_flush(FILE *f) +{ + // NOP +} + +int alt_snputuint(char *buf, int size, unsigned long long val) +{ + struct buffer b = BUFFER(buf, size); + alt_fputuint((FILE *)&b, val); + if (b._i < b._size) + buf[b._i] = '\0'; + return b._i; +} + +int alt_snputhex(char *buf, int size, unsigned long long val) +{ + struct buffer b = BUFFER(buf, size); + alt_fputhex((FILE *)&b, val); + if (b._i < b._size) + buf[b._i] = '\0'; + return b._i; +} + +int alt_vsnprintf(char *buf, int size, const char *fmt, va_list ap) +{ + struct buffer b = BUFFER(buf, size); + alt_vfprintf((FILE *)&b, fmt, ap); + if (b._i < b._size) + buf[b._i] = '\0'; + return b._i; +} + +int alt_snprintf(char *buf, int size, const char *fmt, ...) +{ + struct buffer b = BUFFER(buf, size); + va_list ap; + va_start(ap, fmt); + alt_vfprintf((FILE *)&b, fmt, ap); + va_end(ap); + if (b._i < b._size) + buf[b._i] = '\0'; + return b._i; +} diff --git a/sys/src/alt/sprintf.c b/sys/src/alt/sprintf.c new file mode 100644 index 00000000..b0a4182f --- /dev/null +++ b/sys/src/alt/sprintf.c @@ -0,0 +1,67 @@ +#include + +#define BUFFER(buf) \ + (struct buffer) \ + { \ + ._putc = buffer_putc, ._getc = buffer_getc, ._flush = buffer_flush, ._buf = buf, ._i = 0 \ + } + +struct buffer { + int (*_putc)(FILE *, char); + int (*_getc)(FILE *); + void (*_flush)(FILE *); + char *_buf; + int _i; +}; + +int buffer_putc(FILE *f, char c) +{ + struct buffer *b = (struct buffer *)f; + return b->_buf[b->_i++] = c; +} + +int buffer_getc(FILE *f) +{ + struct buffer *b = (struct buffer *)f; + return b->_buf[b->_i++]; +} + +void buffer_flush(FILE *f) +{ + // NOP +} + +int alt_sputuint(char *buf, unsigned long long val) +{ + struct buffer b = BUFFER(buf); + alt_fputuint((FILE *)&b, val); + buf[b._i] = '\0'; + return b._i; +} + +int alt_sputhex(char *buf, unsigned long long val) +{ + struct buffer b = BUFFER(buf); + alt_fputhex((FILE *)&b, val); + buf[b._i] = '\0'; + return b._i; +} + +int alt_vsprintf(char *buf, const char *fmt, va_list ap) +{ + struct buffer b = BUFFER(buf); + alt_vfprintf((FILE *)&b, fmt, ap); + buf[b._i] = '\0'; + return b._i; +} + +int alt_sprintf(char *buf, const char *fmt, ...) +{ + struct buffer b = BUFFER(buf); + va_list ap; + va_start(ap, fmt); + alt_vfprintf((FILE *)&b, fmt, ap); + va_end(ap); + buf[b._i] = '\0'; + return b._i; +} diff --git a/sys/src/drivers/time.c b/sys/src/drivers/time.c new file mode 100644 index 00000000..d656038f --- /dev/null +++ b/sys/src/drivers/time.c @@ -0,0 +1,24 @@ +#include "drivers/time.h" + +extern volatile uint64_t _mtime[]; // Set in linker script. +extern volatile uint64_t _mtimecmp[]; // Set in linker script. + +uint64_t time_get(void) +{ + return _mtime[0]; +} + +void time_set(uint64_t val) +{ + _mtime[0] = val; +} + +uint64_t timeout_get(uintptr_t hartid) +{ + return _mtimecmp[hartid]; +} + +void timeout_set(uintptr_t hartid, uint64_t val) +{ + _mtimecmp[hartid] = val; +} diff --git a/sys/src/drivers/uart/ns16550a.c b/sys/src/drivers/uart/ns16550a.c new file mode 100644 index 00000000..b973209a --- /dev/null +++ b/sys/src/drivers/uart/ns16550a.c @@ -0,0 +1,47 @@ +#include "drivers/uart/ns16550a.h" + +#define RBR 0 // Receiver buffer register +#define THR 0 // Transmitter holding register +#define IER 1 // Interrupt enable register +#define IIR 2 // Interrupt identification register +#define FCR 2 // FIFO control register +#define LCR 3 // Line control register +#define LSR 5 // Line status register + +#define LSR_RX_READY 0x1 // Receive data ready +#define LSR_TX_READY 0x60 // Transmit data ready + +void uart_ns16550a_init(FILE *f) +{ + // TODO: + // regs[LCR] = 0x3; + // regs[FCR] = 0x1; +} + +int uart_ns16550a_putc(FILE *f, char c) +{ + // regs = pointer to memory mapped registers + volatile char *regs = ((struct uart_ns16550a *)f)->_base; + // Wait until transmit register is empty. + while (!(regs[LSR] & LSR_TX_READY)) + ; + // Write char to transmit register + regs[THR] = c; + return c; +} + +int uart_ns16550a_getc(FILE *f) +{ + // regs = pointer to memory mapped registers + volatile char *regs = ((struct uart_ns16550a *)f)->_base; + // Wait until receive register is ready. + while (!(regs[LSR] & LSR_RX_READY)) + ; + // Read from receive register + return regs[RBR]; +} + +void uart_ns16550a_flush(FILE *f) +{ + // NOP +} diff --git a/sys/src/drivers/uart/sifive.c b/sys/src/drivers/uart/sifive.c new file mode 100644 index 00000000..dc16f41a --- /dev/null +++ b/sys/src/drivers/uart/sifive.c @@ -0,0 +1,51 @@ +#include "drivers/uart/sifive.h" + +#define TXDATA 0 // Transmit data register +#define RXDATA 1 // Receive data register +#define TXCTRL 2 // Transmit control register +#define RXCTRL 3 // Receive control register +#define IE 4 // UART interrupt enable +#define IP 5 // UART interrupt pending +#define DIV 6 // Baud rate divisor + +// Bit masks for transmit and receive registers +#define TXDATA_FULL 0x80000000ul +#define RXDATA_EMPTY 0x80000000ul + +// Control register flags for enabling transmission and reception +#define TXCTRL_TXEN 0x1ul +#define RXCTRL_RXEN 0x1ul + +// Control register flags for setting stop bits +#define TXCTRL_NSTOP 0x2ul + +void uart_sifive_init(FILE *f) +{ + // TODO + // UART0->txctrl = TXCTRL_TXEN; // Enable transmit data + // UART0->rxctrl = RXCTRL_RXEN; // Enable receive data + // UART0->div = TLCLK / TARGET_BAUD_RATE; +} + +int uart_sifive_putc(FILE *, char c) +{ + volatile unsigned int *regs = ((struct uart_sifive *)f)->base_address; + while (regs[TXDATA] & TXDATA_FULL) { + } + regs[TXDATA] = c; + return (unsigned char)c; +} + +int uart_sifive_getc(FILE *f) +{ + volatile unsigned int *regs = ((struct uart_sifive *)f)->base_address; + int c; + while ((c = regs[RXDATA]) & RXDATA_EMPTY) + ; + return c; +} + +void uart_sifive_flush(FILE *f) +{ + // NOP +} diff --git a/sys/src/kern/cap.c b/sys/src/kern/cap.c new file mode 100644 index 00000000..d718e8f3 --- /dev/null +++ b/sys/src/kern/cap.c @@ -0,0 +1,375 @@ +#include "kern/cap.h" + +#include "kern/error.h" +#include "kern/sched.h" +#include "kern/utils.h" + +struct { + int prev, next; + Cap cap; +} ctable[]; + +static inline Word CapIdxPid(Word i) +{ + return i / S3K_CAP_CNT; +} + +Word CapRead(Word i, Cap *cap) +{ + *cap = ctable[i].cap; + return SUCCESS; +} + +Word CapMove(Word src, Word dst) +{ + Cap cap = ctable[src].cap; + Word prev = ctable[src].prev; + Word next = ctable[src].next; + + if (cap.type == CAPTY_NONE) + return ERR_INVCAP; + + ctable[dst].cap = cap; + ctable[dst].prev = prev; + ctable[dst].next = next; + ctable[next].prev = dst; + ctable[prev].next = dst; + + ctable[src].cap = CAP_NULL; + + if (CapIdxPid(src) != CapIdxPid(dst)) { + if (cap.type == CAPTY_TIME) { + SchedUpdate(CapIdxPid(dst), cap.time.hart, cap.time.mark, cap.time.end); + } + if (cap.type == CAPTY_SERVER) + IpcClear(cap.server.channel, cap.server.channel + 1); + } + + return SUCCESS; +} + +Word CapDelete(Word i) +{ + Cap cap = ctable[i].cap; + Word prev = ctable[i].prev; + Word next = ctable[i].next; + + if (cap.type == CAPTY_NONE) + return ERR_INVCAP; + + ctable[prev].next = next; + ctable[next].prev = prev; + + ctable[i].cap = CAP_NULL; + + if (cap.type == CAPTY_TIME) { + SchedDelete(cap.time.hart, cap.time.mark, cap.time.end); + } else if (cap.type == CAPTY_SERVER) { + IpcClear(cap.server.channel, cap.server.channel + 1); + } + + return SUCCESS; +} + +static Word CapDerivable(Cap p, Cap c) +{ + if (p.type == CAPTY_TIME && c.type == CAPTY_TIME) { + return c.time.mark == c.time.begin && c.time.begin < c.time.end && p.time.hart == c.time.hart + && p.time.mark <= c.time.begin && c.time.end <= p.time.end; + } else if (p.type == CAPTY_MEMORY && c.type == CAPTY_MEMORY) { + return c.mem.mark == c.mem.begin && c.mem.begin < c.mem.end && c.mem.lock == 0 && p.mem.lock == 0 + && p.mem.tag == c.mem.tag && p.mem.begin <= c.mem.begin && c.mem.end <= p.mem.end + && BitSubset(c.mem.rwx, p.mem.rwx); + } else if (p.type == CAPTY_MEMORY && c.type == CAPTY_PMP) { + return CapMemBegin(p) <= CapPmpBegin(c) && CapPmpEnd(c) <= CapMemEnd(p) + && BitSubset(c.pmp.rwx, p.mem.rwx); + } else if (p.type == CAPTY_PMP && c.type == CAPTY_PMP) { + return CapPmpBegin(p) <= CapPmpBegin(c) && CapPmpEnd(c) <= CapPmpEnd(p) + && BitSubset(c.pmp.rwx, p.pmp.rwx); + } else if (p.type == CAPTY_MONITOR && p.type == CAPTY_MONITOR) { + return c.mon.mark == c.mon.begin && c.mon.begin < c.mon.end && p.mon.mark <= c.mon.begin + && c.mon.end <= p.mon.end; + } else if (p.type == CAPTY_CHANNEL && c.type == CAPTY_CHANNEL) { + return c.chan.mark == c.chan.begin && c.chan.begin < c.chan.end && p.chan.mark <= c.chan.begin + && c.chan.end <= p.chan.end; + } else if (p.type == CAPTY_CHANNEL && c.type == CAPTY_SERVER) { + return p.chan.mark <= c.server.channel && c.server.channel < c.chan.end; + } else if (p.type == CAPTY_SERVER && c.type == CAPTY_CLIENT) { + return p.server.channel == c.client.channel && p.server.mode == c.client.mode + && p.server.permission == c.server.permission; + } + return 0; +} + +Word CapDerive(Word src, Word dst, Cap new_cap) +{ + Cap cap = ctable[src].cap; + Word next = ctable[src].next; + + if (cap.type == CAPTY_NONE || cap.type == CAPTY_PMP || cap.type == CAPTY_CLIENT) + return ERR_INVCAP; + if (ctable[dst].cap.type != CAPTY_NONE) + return ERR_EXISTS; + if (!CapDerivable(cap, new_cap)) + return ERR_INVDRV; + + // Update parent capability and associated resources. + if (cap.type == CAPTY_TIME && new_cap.type == CAPTY_TIME) { + cap.time.mark = new_cap.time.begin; + SchedUpdate(CapIdxPid(dst), new_cap.time.hart, new_cap.time.begin, new_cap.time.end); + } else if (cap.type == CAPTY_MEMORY && new_cap.type == CAPTY_MEMORY) { + cap.mem.mark = new_cap.mem.begin; + } else if (cap.type == CAPTY_MEMORY && new_cap.type == CAPTY_MEMORY) { + cap.mem.lock = 1; + } else if (cap.type == CAPTY_MONITOR && new_cap.type == CAPTY_MONITOR) { + cap.mon.mark = new_cap.mon.begin; + } else if (cap.type == CAPTY_CHANNEL && new_cap.type == CAPTY_CHANNEL) { + cap.chan.mark = new_cap.chan.begin; + } else if (cap.type == CAPTY_CHANNEL && new_cap.type == CAPTY_SERVER) { + cap.chan.mark = new_cap.server.channel + 1; + } + + ctable[src].next = dst; + ctable[src].cap = cap; + + // Insert new capability + ctable[dst].prev = src; + ctable[dst].next = next; + ctable[dst].cap = new_cap; +} + +Word CapRevokable(Cap p, Cap c) +{ + if (p.type == CAPTY_TIME && c.type == CAPTY_TIME) { + return p.time.hart == c.time.hart && c.time.end <= p.time.end; + } else if (p.type == CAPTY_MEMORY && c.type == CAPTY_MEMORY) { + return CapMemEnd(c) <= CapMemEnd(p); + } else if (p.type == CAPTY_MEMORY && c.type == CAPTY_PMP) { + return CapPmpBegin(c) <= CapMemEnd(p); + } else if (p.type == CAPTY_MONITOR && c.type == CAPTY_MONITOR) { + return c.mon.end <= p.mon.end; + } else if (p.type == CAPTY_CHANNEL && c.type == CAPTY_CHANNEL) { + return c.chan.end <= p.chan.end; + } else if (p.type == CAPTY_CHANNEL && c.type == CAPTY_SERVER) { + return c.server.channel < p.chan.end; + } else if (p.type == CAPTY_CHANNEL && c.type == CAPTY_CLIENT) { + return c.client.channel < p.chan.end; + } + return false; +} + +Word CapRevoke(Word i) +{ + Cap cap = ctable[i].cap; + + if (cap.type == CAPTY_NONE || cap.type == CAPTY_PMP || cap.type == CAPTY_CLIENT) + return ERR_INVCAP; + + bool done = false; + Word next = ctable[i].next; + Cap next_cap = ctable[next].cap; + + while (CapRevokable(cap, next_cap) && i != next) { + // If parent of next capability, delete it. + if (Preempted()) + goto preempted; + // Update parent. + if (cap.type == CAPTY_TIME && next_cap.type == CAPTY_TIME) { + cap.time.mark = next_cap.time.mark; + } else if (cap.type == CAPTY_MEMORY && next_cap.type == CAPTY_MEMORY) { + cap.mem.mark = next_cap.mem.mark; + cap.mem.lock = next_cap.mem.lock; + } else if (cap.type == CAPTY_MEMORY && next_cap.type == CAPTY_PMP) { + // nothing + } else if (cap.type == CAPTY_MONITOR && next_cap.type == CAPTY_MONITOR) { + cap.mon.mark = next_cap.mon.mark; + } else if (cap.type == CAPTY_CHANNEL && next_cap.type == CAPTY_CHANNEL) { + cap.chan.mark = next_cap.chan.mark; + } else if (cap.type == CAPTY_CHANNEL && next_cap.type == CAPTY_SERVER) { + cap.chan.mark = next_cap.server.channel + 1; + } else if (cap.type == CAPTY_CHANNEL && next_cap.type == CAPTY_CLIENT) { + cap.chan.mark = next_cap.client.channel + 1; + } + // Delete the capability + ctable[next].cap = CAP_NULL; + next = ctable[next].next; + next_cap = ctable[next].cap; + } + + done = true; + + if (cap.type == CAPTY_TIME) { + cap.time.mark = cap.time.begin; + } else if (cap.type == CAPTY_MEMORY) { + cap.mem.mark = cap.mem.begin; + cap.mem.lock = 0; + } else if (cap.type == CAPTY_MONITOR) { + cap.mon.mark = cap.mon.begin; + } else if (cap.type == CAPTY_CHANNEL) { + cap.chan.mark = cap.chan.begin; + } + +preempted: + // Interrupted. + ctable[i].cap = cap; + ctable[i].next = next; + ctable[next].prev = i; + + if (cap.type == CAPTY_TIME) + SchedUpdate(CapIdxPid(i), cap.time.hart, cap.time.mark, cap.time.end); + if (cap.type == CAPTY_CHANNEL) + IpcClear(cap.chan.mark, cap.chan.end); + + return done ? SUCCESS : ERR_PREEMPT; +} + +bool cap_monitor_valid_pid(Cap cap, Word pid) +{ + return pid >= cap.mon.begin && pid < cap.mon.end; +} + +Error CapMonitorSuspend(Word mon_idx, Word pid) +{ + Cap cap = ctable[mon_idx].cap; + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!cap_monitor_valid_pid(cap, pid)) + return ERR_INVCAP; + ProcSuspend(ProcGet(pid)); + return SUCCESS; +} + +Error CapMonitorResume(Word mon_idx, Word pid) +{ + Cap cap = ctable[mon_idx].cap; + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!cap_monitor_valid_pid(cap, pid)) + return ERR_INVCAP; + ProcResume(ProcGet(pid)); + return SUCCESS; +} + +Error CapMonitorGetState(Word mon_idx, Word pid, ProcState *state) +{ + Cap cap = ctable[mon_idx].cap; + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!cap_monitor_valid_pid(cap, pid)) + return ERR_INVCAP; + *state = ProcGetState(ProcGet(pid)); + return SUCCESS; +} + +Error CapMonitorRegRead(Word mon_idx, Word pid, Word regnr, Word *val) +{ + Cap cap = ctable[mon_idx].cap; + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!CapMonitorValidPid(cap, pid)) + return ERR_INVCAP; + if (regnr >= REG_COUNT) + return ERR_INVARG; + Proc *p = ProcGet(pid); + Word *regs = (Word *)&p->regs; + *val = regs[regnr]; + return SUCCESS; +} + +Error CapMonitorRegWrite(Word mon_idx, Word pid, Word regnr, Word val) +{ + Cap cap = ctable[mon_idx].cap; + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!cap_monitor_valid_pid(cap, pid)) + return ERR_INVCAP; + if (regnr >= REG_COUNT) + return ERR_INVARG; + Proc *p = ProcGet(pid); + Word *regs = (Word *)&p->regs; + regs[regnr] = val; + return SUCCESS; +} + +Error CapMonitorCapRead(Word mon_idx, Word read_idx, Cap *buf_cap) +{ + Cap cap = ctable[mon_idx].cap; + Word pid = CapIdxPid(read_idx); + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!cap_monitor_valid_pid(cap, pid)) + return ERR_INVCAP; + *buf_cap = ctable[read_idx].cap; + return SUCCESS; +} + +err_t cap_monitor_cap_move(cidx_t mon, cidx_t src, cidx_t dst) +{ + cap_t cap = ctable[mon_idx].cap; + pid_t mon_pid = cap_pid(mon); + pid_t src_pid = cap_pid(src); + pid_t dst_pid = cap_pid(dst); + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (src_pid != mon_pid && !cap_monitor_valid_pid(cap, src_pid)) + return ERR_INVCAP; + if (dst_pid != mon_pid && !cap_monitor_valid_pid(cap, dst_pid)) + return ERR_INVCAP; + return cap_move(src, dst); +} + +err_t cap_monitor_yield(cidx_t mon, pid_t pid) +{ + if (cap.type != CAPTY_MONITOR) + return ERR_INVCAP; + if (!cap_monitor_valid_pid(cap, pid)) + return ERR_INVCAP; + proc_t *proc = proc_get(pid); + if (proc_acquire(proc)) { + proc_release(proc); + return SUCCESS; + } + return ERR_INVSTATE; +} + +err_t cap_server_send(cidx_t srv, uint64_t data[4]) +{ + if (cap.type != CAPTY_SERVER) + return ERR_INVCAP; + return SUCCESS; +} + +err_t cap_server_recv(cidx_t srv) +{ + if (cap.type != CAPTY_SERVER) + return ERR_INVCAP; + return SUCCESS; +} + +err_t cap_server_sendrecv(cidx_t srv, uint64_t data[4]) +{ + if (cap.type != CAPTY_SERVER) + return ERR_INVCAP; + return SUCCESS; +} + +err_t cap_client_send(cidx_t clt, uint64_t data[4]) +{ + if (cap.type != CAPTY_CLIENT) + return ERR_INVCAP; + return SUCCESS; +} + +err_t cap_client_recv(cidx_t clt) +{ + if (cap.type != CAPTY_CLIENT) + return ERR_INVCAP; + return SUCCESS; +} + +err_t cap_client_sendrecv(cidx_t clt, uint64_t data[4]) +{ + if (cap.type != CAPTY_CLIENT) + return ERR_INVCAP; + return SUCCESS; +} diff --git a/sys/src/kern/exception.c b/sys/src/kern/exception.c new file mode 100644 index 00000000..6911857e --- /dev/null +++ b/sys/src/kern/exception.c @@ -0,0 +1,37 @@ +/* See LICENSE file for copyright and license details. */ +#include "kern/exception.h" + +#include "kern/proc.h" + +#define ILLEGAL_INSTRUCTION 0x2 + +#define MRET 0x30200073 +#define SRET 0x10200073 +#define URET 0x00200073 + +static void HandleTrapReturn(Proc *p, Word mcause, Word mtval) +{ + p->regs.ecause = mcause; + p->regs.eval = mtval; + p->regs.epc = p->regs.pc; + p->regs.esp = p->regs.sp; + p->regs.pc = p->regs.tpc; + p->regs.sp = p->regs.tsp; +} + +static void HandleDelegate(Proc *p) +{ + p->regs.pc = p->regs.epc; + p->regs.sp = p->regs.esp; + p->regs.ecause = 0; + p->regs.eval = 0; + p->regs.epc = 0; + p->regs.esp = 0; +} + +Proc *ExceptionHandler(Proc *p, Word mcause, Word mtval) +{ + if (mcause == ILLEGAL_INSTRUCTION && (mtval == MRET || mtval == SRET || mtval == URET)) + return HandleTrapReturn(p); + return HandleDelegate(p, mcause, mtval); +} diff --git a/kernel/src/head.S b/sys/src/kern/head.S similarity index 88% rename from kernel/src/head.S rename to sys/src/kern/head.S index 4938b234..79995334 100644 --- a/kernel/src/head.S +++ b/sys/src/kern/head.S @@ -1,7 +1,7 @@ // See LICENSE file for copyright and license details. -#include "macro.inc" -#include "offsets.h" -#include "csr.h" +#include "kern/macro.inc" +#include "kern/offsets.h" +#include "kern/csr.h" .extern init_kernel .extern sched @@ -51,7 +51,9 @@ zero_bss: addi t0,t0,1 2: bne t0,t1,1b - call kernel_init + call cap_init + call sched_init + call proc_init la t0,kernel_ready li t1,1 @@ -68,10 +70,9 @@ head_exit: csrw mie,t0 // Start user processes. - la t0,trap_entry + la t0,trap_handler csrw mtvec,t0 csrw mscratch,0 - la ra,trap_exit tail sched __hang: diff --git a/sys/src/kern/interrupt.c b/sys/src/kern/interrupt.c new file mode 100644 index 00000000..378cac8f --- /dev/null +++ b/sys/src/kern/interrupt.c @@ -0,0 +1,10 @@ +#include "kern/interrupt.h" + +#include "kern/proc.h" +#include "kern/sched.h" + +Proc *InterruptHandler(Proc *proc, Word mcause, Word mtval) +{ + ProcRelease(proc); + return SchedNext(); +} diff --git a/sys/src/kern/plat/qemu.c b/sys/src/kern/plat/qemu.c new file mode 100644 index 00000000..a0094216 --- /dev/null +++ b/sys/src/kern/plat/qemu.c @@ -0,0 +1,20 @@ +#include "drivers/uart/ns16550a.h" +#include "kern/cap.h" + +const cap_t init_caps[] = { + CAP_PMP(0X20005fff, MEM_RWX), + CAP_MEMORY(0, 0x80020000, 0x88000000, MEM_RWX), + CAP_MEMORY(0, 0x10000000, 0x10001000, MEM_RW), + CAP_MEMORY(0, 0x200b000, 0x200c000, MEM_R), + CAP_TIME(0, S3K_SLOT_CNT), + CAP_MONITOR(0, S3K_PROC_CNT), + CAP_CHANNEL(0, S3K_CHAN_CNT), + 0, +}; + +char kernel_stack[256]; + +static uart_ns16550a_t uart = UART_NS16550A(0x10000000ULL); + +FILE *const _altin = (FILE *)&uart; +FILE *const _altout = (FILE *)&uart; diff --git a/sys/src/kern/proc.c b/sys/src/kern/proc.c new file mode 100644 index 00000000..bd51ae95 --- /dev/null +++ b/sys/src/kern/proc.c @@ -0,0 +1,126 @@ +/* See LICENSE file for copyright and license details. */ +#include "kern/proc.h" + +#include "drivers/time.h" +#include "kern/cap.h" +#include "kern/csr.h" +#include "kern/kassert.h" + +extern Word _payload[]; +static Proc procs[S3K_PROC_CNT]; + +void ProcInit(void) +{ + for (uint64_t i = 0; i < S3K_PROC_CNT; i++) { + procs[i].pid = i; + procs[i].state = PSF_SUSPENDED; + } + procs[0].state = 0; + procs[0].regs.pc = (reg_t)_payload; + // KASSERT(cap_pmp_load(ctable_get(0, 0), 0) == SUCCESS); +} + +Proc *ProcGet(pid_t pid) +{ + KASSERT(pid < S3K_PROC_CNT); + KASSERT(procs[pid].pid == pid); + return &procs[pid]; +} + +ProcState ProcGetState(Proc *proc) +{ + Proc state = proc->state; + if ((state == PSF_BLOCKED) && time_get() >= proc->timeout) { + // TODO: Unblock state. + return 0; + } + return state; +} + +bool ProcAcquire(Proc *proc) +{ + ProcState expected = ProcGetState(proc); + proc_state_t desired = PSF_BUSY; + + if (expected & (PSF_BUSY | PSF_SUSPENDED)) + return false; + + if (time_get() < proc->timeout) + return false; +#ifdef SMP + return __atomic_compare_exchange(&proc->state, &expected, &desired, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); +#else + proc->state = desired; + return true; +#endif +} + +void ProcRelease(Proc *proc) +{ + KASSERT(proc->state & PSF_BUSY); +#ifdef SMP + __atomic_fetch_xor(&proc->state, PSF_BUSY, __ATOMIC_RELEASE); +#else + proc->state &= ~PSF_BUSY; +#endif +} + +void ProcSuspend(Proc *proc) +{ + ProcState prev = __atomic_fetch_or(&proc->state, PSF_SUSPENDED, __ATOMIC_RELAXED); + if (prev & PSF_BLOCKED) { + proc->state = PSF_SUSPENDED; + proc->regs.t0 = ERR_SUSPENDED; + } +} + +void ProcResume(Proc *proc) +{ + if (proc->state == PSF_SUSPENDED) + proc->timeout = 0; + __atomic_fetch_and(&proc->state, ~PSF_SUSPENDED, __ATOMIC_RELAXED); +} + +void ProcIpcWait(Proc *proc, Word chan) +{ + KASSERT(proc->state == PSF_BUSY); + proc->state = PSF_BLOCKED | ((uint64_t)chan << 48) | PSF_BUSY; +} + +bool ProcIpcAcquire(Proc *proc, chan_t chan) +{ + ProcState expected = PSF_BLOCKED | ((uint64_t)chan << 48); + ProcState desired = PSF_BUSY; + + if (proc->state != expected) + return false; + if (time_get() >= proc->timeout) + return false; +#ifdef SMP + return __atomic_compare_exchange_n(&proc->state, &expected, desired, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); +#else + proc->state = desired; + return true; +#endif +} + +bool ProcIsSuspended(proc_t *proc) +{ + return proc->state == PSF_SUSPENDED; +} + +bool proc_pmp_avail(proc_t *proc, pmp_slot_t slot) +{ + return proc->pmp.cfg[slot] == 0; +} + +void proc_pmp_load(proc_t *proc, pmp_slot_t slot, pmp_slot_t rwx, napot_t addr) +{ + proc->pmp.cfg[slot] = (uint8_t)(rwx | 0x18); + proc->pmp.addr[slot] = addr; +} + +void proc_pmp_unload(proc_t *proc, pmp_slot_t slot) +{ + proc->pmp.cfg[slot] = 0; +} diff --git a/sys/src/kern/sched.c b/sys/src/kern/sched.c new file mode 100644 index 00000000..9d8cab27 --- /dev/null +++ b/sys/src/kern/sched.c @@ -0,0 +1,83 @@ +/* See LICENSE file for copyright and license details. */ + +#include "kern/sched.h" + +#include "drivers/time.h" +#include "kern/csr.h" +#include "kern/kassert.h" +#include "kern/kprintf.h" +#include "kern/proc.h" +#include "kern/trap.h" +#include "kern/types.h" +#include "kern/wfi.h" +#include "smp/semaphore.h" + +typedef struct { + // Owner of time slot. + int pid; + // Remaining length of corresponding slice. + int len; +} SlotInfo; + +static SlotInfo slots[S3K_SLOT_CNT]; + +void SchedInit(void) +{ + sched_update(0, 0, 0, S3K_SLOT_CNT); +} + +void SchedUpdate(Word pid, Word hart, Word bgn, Word end) +{ + for (int i = bgn; i < end; i++) + slots[i] = (SlotInfo){.pid = pid, .len = end - i}; +} + +void SchedDelete(Word hart, Word bgn, Word end) +{ + for (int i = bgn; i < end; ++i) + slots[i].len = 0; +} + +static SlotInfo slot_info_get(Word hart, Word slot) +{ + return slots[slot % S3K_SLOT_CNT]; +} + +static Proc *SchedFetch(Word hart, Word slot) +{ + // Get time slot information + SlotInfo si = slot_info_get(hart, slot); + Proc *proc = ProcGet(si.pid); + + // If length = 0, then slice is deleted. + if (si.len == 0) + return NULL; + + // Try to acquire the process. + if (!ProcAcquire(proc)) + return NULL; + + // Get the process. + proc->timeout = (slot + si.len) * S3K_SLOT_LEN; + return proc; +} + +Proc *SchedNext(void) +{ + // Hart ID + Word hart = csrr(mhartid); + // Process to schedule + Proc *proc; + + timeout_set(hart, (uint64_t)-1); + + do { + uintptr_t slot = time_get() / S3K_SLOT_LEN; + while (time_get() < slot * S3K_SLOT_LEN) + ; + // Try schedule process + proc = sched_fetch(hart, slot); + } while (!proc); + timeout_set(hart, proc->timeout); + return proc; +} diff --git a/sys/src/kern/syscall.c b/sys/src/kern/syscall.c new file mode 100644 index 00000000..e667a325 --- /dev/null +++ b/sys/src/kern/syscall.c @@ -0,0 +1,149 @@ +/* See LICENSE file for copyright and license details. */ +#include "kern/syscall.h" + +#include "drivers/time.h" +#include "kern/cap.h" +#include "kern/csr.h" +#include "kern/error.h" +#include "kern/sched.h" +#include "kern/trap.h" +#include "kern/types.h" + +static Proc *HandleInvArg(Proc *p); + +static Proc *HandleGetPid(Proc *p); +static Proc *HandleRegRead(Proc *p); +static Proc *HandleRegWrite(Proc *p); +static Proc *HandleSync(Proc *p); +static Proc *HandleCapRead(Proc *p); +static Proc *HandleCapMove(Proc *p); +static Proc *HandleCapDelete(Proc *p); +static Proc *HandleCapDerive(Proc *p); +static Proc *HandleCapRevoke(Proc *p); + +typedef Proc *(*Handler)(Proc *p); + +static const Handler handlers[] = { + HandleGetPid, HandleRegRead, HandleRegWrite, HandleSync, HandleCapRead, + HandleCapMove, HandleCapDelete, HandleCapDerive, HandleCapRevoke, +}; + +Proc *SyscallHandler(Proc *p) +{ + Word syscall_nr = p->regs.t0; + if (syscall_nr < ARRAY_SIZE(handlers)) + return handlers[syscall_nr](p); + return HandleInvArg(p); +} + +static Bool ValidCapIdx(Word i) +{ + return i < S3K_CAP_CNT; +} + +static Bool ValidPmpSlot(Word slot) +{ + return slot < S3K_PMP_CNT; +} + +static Bool ValidPid(Word pid) +{ + return pid < S3K_PROC_CNT; +} + +static Bool ValidReg(Word reg) +{ + return reg < REGISTER_COUNT; +} + +Proc *HandleInvArg(Proc *p) +{ + p->regs.t0 = ERR_INVARG; + return p; +} + +Proc *HandleGetPid(Proc *p) +{ + p->regs.t0 = SUCCESS; + p->regs.a0 = p->pid; + return p; +} + +Proc *HandleRegRead(Proc *p) +{ + if (!ValidReg(p->regs.a0)) + return HandleInvArg(p); + + Word reg = p->regs.a0; + Word *regs = (Word *)&p->regs; + p->regs.a0 = regs[reg]; + p->regs.t0 = SUCCESS; + return p; +} + +Proc *HandleRegWrite(Proc *p) +{ + if (!ValidReg(p->regs.a0)) + return HandleInvArg(p); + + Word reg = p->regs.a0; + Word value = p->regs.a1; + Word *regs = (Word *)&p->regs; + regs[reg] = value; + p->regs.t0 = SUCCESS; + return p; +} + +Proc *HandleSync(Proc *p) +{ + return NULL; +} + +Proc *HandleCapRead(Proc *p) +{ + if (!ValidCapIdx(p->regs.a0)) + return HandleInvArg(p); + + Word i = CapIdx(p->pid, p->regs.a0); + Cap *buf = (Cap *)&p->regs.a0; + p->regs.t0 = CapRead(i, buf); + return p; +} + +Proc *HandleCapMove(Proc *p) +{ + if (!ValidCapIdx(p->regs.a0) || !ValidCapIdx(p->regs.a0)) + return HandleInvArg(p); + Word src = CapIdx(p->pid, p->regs.a0); + Word dst = CapIdx(p->pid, p->regs.a1); + p->regs.t0 = CapMove(src, dst); + return p; +} + +Proc *HandleCapDelete(Proc *p) +{ + if (!ValidCapIdx(p->regs.a0)) + return HandleInvArg(p); + Word i = CapIdx(p->pid, p->regs.a0); + current->regs.t0 = CapDelete(i); + return p; +} + +Proc *HandleCapDerive(Proc *p) +{ + if (!ValidCapIdx(p->regs.a0) || !ValidCapIdx(p->regs.a0)) + return HandleInvArg(p); + Word src = CapIdx(p->pid, p->regs.a0); + Word dst = CapIdx(p->pid, p->regs.a1); + Cap cap = (Cap){.raw = p->regs.a2}; + current->regs.t0 = CapDerive(src, dst, cap); +} + +Proc *HandleCapRevoke(Proc *p) +{ + if (!ValidCapIdx(p->regs.a0)) + return HandleInvArg(p); + Word i = CapIdx(p->pid, p->regs.a0); + current->regs.t0 = CapRevoke(i); + return p; +} diff --git a/sys/src/kern/trap.S b/sys/src/kern/trap.S new file mode 100644 index 00000000..8b980605 --- /dev/null +++ b/sys/src/kern/trap.S @@ -0,0 +1,136 @@ +// See LICENSE file for copyright and license details. +#include "kern/macro.inc" +#include "kern/offsets.h" +#include "kern/csr.h" + +.globl TrapHandler +.globl TrapResume +.globl TrapReturn + +.type TrapHandler,@function +.type TrapResume, @function +.type TrapReturn, @function + +.section .text.trap +.balign 16 +trap_handler: + // Save user tp to scratch, load PCB pointer + csrrw tp,mscratch,tp + + sd ra,PROC_RA(tp) + sd sp,PROC_SP(tp) + sd gp,PROC_GP(tp) + //sd tp,PROC_TP(tp) + sd t0,PROC_T0(tp) + sd t1,PROC_T1(tp) + sd t2,PROC_T2(tp) + sd s0,PROC_S0(tp) + sd s1,PROC_S1(tp) + sd a0,PROC_A0(tp) + sd a1,PROC_A1(tp) + sd a2,PROC_A2(tp) + sd a3,PROC_A3(tp) + sd a4,PROC_A4(tp) + sd a5,PROC_A5(tp) + sd a6,PROC_A6(tp) + sd a7,PROC_A7(tp) + sd s2,PROC_S2(tp) + sd s3,PROC_S3(tp) + sd s4,PROC_S4(tp) + sd s5,PROC_S5(tp) + sd s6,PROC_S6(tp) + sd s7,PROC_S7(tp) + sd s8,PROC_S8(tp) + sd s9,PROC_S9(tp) + sd s10,PROC_S10(tp) + sd s11,PROC_S11(tp) + sd t3,PROC_T3(tp) + sd t4,PROC_T4(tp) + sd t5,PROC_T5(tp) + sd t6,PROC_T6(tp) + + // Save the + csrr t1,mepc + csrr t2,mscratch + sd t1,PROC_PC(tp) + sd t2,PROC_TP(tp) + + + // Load the global and stack pointer of the kernel. + ld_gp + ld_sp t0 + + la ra, trap_return + + // call the trap handler + csrr t0,mcause + li t1,8 + beq t0,t1,syscall_handler + csrr a0,mcause + csrr a1,mtval + bltz t0,interrupt_handler + j exception_handler + +trap_resume: + mv tp,a0 + ld s0,PROC_PMPADDR0(tp) + ld s1,PROC_PMPADDR1(tp) + ld s2,PROC_PMPADDR2(tp) + ld s3,PROC_PMPADDR3(tp) + ld s4,PROC_PMPADDR4(tp) + ld s5,PROC_PMPADDR5(tp) + ld s6,PROC_PMPADDR6(tp) + ld s7,PROC_PMPADDR7(tp) + ld s8,PROC_PMPCFG0(tp) + csrw pmpaddr0,s0 + csrw pmpaddr1,s1 + csrw pmpaddr2,s2 + csrw pmpaddr3,s3 + csrw pmpaddr4,s4 + csrw pmpaddr5,s5 + csrw pmpaddr6,s6 + csrw pmpaddr7,s7 + csrw pmpcfg0,s8 + +trap_return: + ld t0,PROC_PC(tp) + ld t1,PROC_TP(tp) + csrw mepc,t0 + csrw mscratch,t1 + + ld ra,PROC_RA(tp) + ld sp,PROC_SP(tp) + ld gp,PROC_GP(tp) + //ld tp,PROC_TP(tp) + ld t0,PROC_T0(tp) + ld t1,PROC_T1(tp) + ld t2,PROC_T2(tp) + ld s0,PROC_S0(tp) + ld s1,PROC_S1(tp) + ld a0,PROC_A0(tp) + ld a1,PROC_A1(tp) + ld a2,PROC_A2(tp) + ld a3,PROC_A3(tp) + ld a4,PROC_A4(tp) + ld a5,PROC_A5(tp) + ld a6,PROC_A6(tp) + ld a7,PROC_A7(tp) + ld s2,PROC_S2(tp) + ld s3,PROC_S3(tp) + ld s4,PROC_S4(tp) + ld s5,PROC_S5(tp) + ld s6,PROC_S6(tp) + ld s7,PROC_S7(tp) + ld s8,PROC_S8(tp) + ld s9,PROC_S9(tp) + ld s10,PROC_S10(tp) + ld s11,PROC_S11(tp) + ld t3,PROC_T3(tp) + ld t4,PROC_T4(tp) + ld t5,PROC_T5(tp) + ld t6,PROC_T6(tp) + + // Save PCB pointer. + csrrw tp,mscratch,tp + + mret diff --git a/kernel/src/smp/mcslock.c b/sys/src/smp/mcslock.c similarity index 82% rename from kernel/src/smp/mcslock.c rename to sys/src/smp/mcslock.c index caed50ed..e5393440 100644 --- a/kernel/src/smp/mcslock.c +++ b/sys/src/smp/mcslock.c @@ -2,7 +2,6 @@ #include "smp/mcslock.h" #include "kassert.h" -#include "kernel.h" #include @@ -13,9 +12,7 @@ static void _release(qnode_t *const node) do { expected = node; next = node->next; - } while (!__atomic_compare_exchange_n(&next->prev, &expected, prev, - false, __ATOMIC_RELEASE, - __ATOMIC_RELAXED)); + } while (!__atomic_compare_exchange_n(&next->prev, &expected, prev, false, __ATOMIC_RELEASE, __ATOMIC_RELAXED)); if (prev) prev->next = next; } @@ -23,8 +20,7 @@ static void _release(qnode_t *const node) static bool _acquire(mcslock_t *lock, qnode_t *const node, bool preemptive) { node->next = &lock->tail; - node->prev - = __atomic_exchange_n(&lock->tail.prev, node, __ATOMIC_ACQUIRE); + node->prev = __atomic_exchange_n(&lock->tail.prev, node, __ATOMIC_ACQUIRE); if (node->prev == NULL) return true; node->prev->next = node; @@ -39,7 +35,6 @@ static bool _acquire(mcslock_t *lock, qnode_t *const node, bool preemptive) void mcslock_init(mcslock_t *lock) { - // lock->tail.prev = lock->tail.next = NULL; lock->tail.prev = lock->tail.next = NULL; } diff --git a/sys/src/smp/semaphore.c b/sys/src/smp/semaphore.c new file mode 100644 index 00000000..03fa4040 --- /dev/null +++ b/sys/src/smp/semaphore.c @@ -0,0 +1,38 @@ +/** + * A counting semaphore based on a ticket lock. + */ +#include "smp/semaphore.h" + +void semaphore_init(semaphore_t *sem, uint64_t tickets) +{ + // Initial number of served tickets. + sem->released = tickets; + // Initiallly, 0 tickets are released. + sem->acquired = 0; +} + +void semaphore_acquire_n(semaphore_t *sem, uint64_t n) +{ + uint64_t my_ticket; + // Acquire n tickets. + my_ticket = __atomic_add_fetch(&sem->acquired, n, __ATOMIC_RELAXED); + // Wait until the tickets are released. + while (my_ticket > __atomic_load_n(&sem->released, __ATOMIC_ACQUIRE)) + ; +} + +void semaphore_release_n(semaphore_t *sem, uint64_t n) +{ + // Release n tickets. + __atomic_fetch_add(&sem->released, n, __ATOMIC_RELEASE); +} + +void semaphore_acquire(semaphore_t *sem) +{ + semaphore_acquire_n(sem, 1); +} + +void semaphore_release(semaphore_t *sem) +{ + semaphore_release_n(sem, 1); +} diff --git a/kernel/src/smp/taslock.c b/sys/src/smp/taslock.c similarity index 85% rename from kernel/src/smp/taslock.c rename to sys/src/smp/taslock.c index 08cc30c6..3ec5383f 100644 --- a/kernel/src/smp/taslock.c +++ b/sys/src/smp/taslock.c @@ -1,7 +1,5 @@ #include "smp/taslock.h" -#include "kernel.h" - #include void taslock_init(taslock_t *l) @@ -12,8 +10,7 @@ void taslock_init(taslock_t *l) bool taslock_acquire(taslock_t *l) { while (!taslock_try_acquire(l)) - if (kernel_preempt()) - return false; + return false; return true; } diff --git a/kernel/s3k_conf.h b/tools/kern/default.h similarity index 100% rename from kernel/s3k_conf.h rename to tools/kern/default.h diff --git a/kernel/linker.ld b/tools/kern/linker.ld similarity index 100% rename from kernel/linker.ld rename to tools/kern/linker.ld diff --git a/tools/kern/qemu.ld b/tools/kern/qemu.ld new file mode 100644 index 00000000..f001ad37 --- /dev/null +++ b/tools/kern/qemu.ld @@ -0,0 +1,39 @@ +/* See LICENSE file for copyright and license details. */ +OUTPUT_ARCH(riscv) +ENTRY(_start) + +_payload = ORIGIN(RAM) + LENGTH(RAM); + +_mtime = 0x2000; +_mtimecmp = 0x2000ff8; + +__global_pointer$ = MIN(_sdata + 0x800, MAX(_data + 0x800, _end - 0x800)); + +MEMORY { + RAM (rwx) : ORIGIN = 0x80000000, LENGTH = 64K +} + +SECTIONS { + .text : { + *( .text.init ) + *( .text .text.* ) + } > RAM + + .data : ALIGN(4K) { + _data = . ; + *( .data ) + *( .data.* ) + _sdata = . ; + *( .sdata ) + *( .sdata.* ) + } > RAM + + .bss : ALIGN(4K) { + _bss = .; + _sbss = .; + *(.sbss .sbss.*) + *(.bss .bss.*) + _end = ALIGN(8); + } > RAM +} + diff --git a/tools/kern/qemu.mk b/tools/kern/qemu.mk new file mode 100644 index 00000000..f1367c8b --- /dev/null +++ b/tools/kern/qemu.mk @@ -0,0 +1,53 @@ +.SECONDARY: +.POSIX: + +ifeq ($(S3K_ROOT),) +$(error "S3K_ROOT not set") +endif + +VPATH=$(S3K_ROOT)/sys/src +INCLUDES=-I$(S3K_ROOT)/sys/includes +LINKER_SCRIPT=$(S3K_ROOT)/tools/kern/qemu.ld + +CFLAGS=$(CONFIG) $(INCLUDES) +CFLAGS+=-march=rv64imac_zicsr -mabi=lp64 -mcmodel=medany +CFLAGS+=-nostdlib -nostartfiles +CFLAGS+=-O2 -g +CFLAGS+=-T$(LINKER_SCRIPT) +CFLAGS+=-include qemu.h + +# Core kernel files +SRCS:=kern/trap.S kern/head.S +SRCS+=kern/proc.c kern/sched.c +# Exception handling +SRCS+=kern/interrupt.c kern/exception.c kern/syscall.c +# Capabilities +SRCS+=kern/cap.c +# ALT lib +SRCS+=alt/fprintf.c alt/printf.c alt/snprintf.c +# Platform specific files +SRCS+=kern/plat/qemu.c drivers/time.c drivers/uart/ns16550a.c + +OBJS=$(patsubst %, objs/%.o, $(SRCS)) +ELF=kernel.elf +HEX=kernel.hex + + +all: $(ELF) $(HEX) + +clean: + rm -f $(OBJS) $(ELF) $(HEX) + +objs/%.c.o: %.c + @mkdir -p $(@D) + $(CC) -o $@ $< -c $(CFLAGS) + +objs/%.S.o: %.S + @mkdir -p $(@D) + $(CC) -o $@ $< -c $(CFLAGS) + +$(ELF): $(OBJS) + $(CC) -o $@ $(OBJS) $(CFLAGS) + +$(HEX): $(ELF) + $(OBJCOPY) -O ihex $< $@ diff --git a/tools/scripts/clang-format.sh b/tools/scripts/clang-format.sh new file mode 100755 index 00000000..1bf012f9 --- /dev/null +++ b/tools/scripts/clang-format.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +FILES=$(find -name *.[hc]) +clang-format -i $FILES diff --git a/scripts/gdb-openocd.sh b/tools/scripts/gdb-openocd.sh similarity index 100% rename from scripts/gdb-openocd.sh rename to tools/scripts/gdb-openocd.sh diff --git a/scripts/gdb.sh b/tools/scripts/gdb.sh similarity index 100% rename from scripts/gdb.sh rename to tools/scripts/gdb.sh diff --git a/scripts/qemu.sh b/tools/scripts/qemu.sh similarity index 100% rename from scripts/qemu.sh rename to tools/scripts/qemu.sh diff --git a/tools.mk b/tools/tools.mk similarity index 100% rename from tools.mk rename to tools/tools.mk