├── .codespell_ignore ├── hal ├── tlb │ ├── Makefile │ └── tlb.h ├── gaisler │ ├── Makefile │ └── ambapp.h ├── riscv64 │ ├── generic │ │ ├── Makefile │ │ ├── config.h │ │ ├── generic.c │ │ └── console.c │ ├── gaisler │ │ ├── gr765 │ │ │ ├── Makefile │ │ │ ├── config.h │ │ │ └── gr765.c │ │ ├── grfpga │ │ │ ├── Makefile │ │ │ ├── config.h │ │ │ └── grfpga.c │ │ └── Makefile │ ├── halsyspage.h │ ├── arch │ │ ├── types.h │ │ ├── exceptions.h │ │ ├── spinlock.h │ │ └── interrupts.h │ ├── Makefile │ ├── dtb.h │ └── plic.h ├── aarch64 │ ├── zynqmp │ │ ├── Makefile │ │ ├── zynqmp.h │ │ └── config.h │ ├── halsyspage.h │ ├── arch │ │ ├── types.h │ │ ├── interrupts.h │ │ └── spinlock.h │ ├── Makefile │ ├── interrupts_gicv2.h │ └── dtb.h ├── Makefile ├── armv7r │ ├── tda4vm │ │ ├── Makefile │ │ └── config.h │ ├── zynqmp │ │ ├── Makefile │ │ ├── zynqmp.h │ │ └── config.h │ ├── halsyspage.h │ ├── arch │ │ ├── elf.h │ │ ├── types.h │ │ ├── interrupts.h │ │ ├── spinlock.h │ │ └── exceptions.h │ └── Makefile ├── armv7m │ ├── stm32 │ │ ├── l4 │ │ │ └── Makefile │ │ ├── Makefile │ │ ├── halsyspage.h │ │ ├── stm32-timer.h │ │ └── config.h │ ├── imxrt │ │ ├── 10xx │ │ │ ├── Makefile │ │ │ └── config.h │ │ ├── 117x │ │ │ ├── Makefile │ │ │ ├── imxrt117x.h │ │ │ └── config.h │ │ ├── halsyspage.h │ │ └── Makefile │ ├── arch │ │ ├── types.h │ │ ├── exceptions.h │ │ ├── elf.h │ │ ├── spinlock.h │ │ └── interrupts.h │ ├── Makefile │ └── hal.c ├── sparcv8leon │ ├── gaisler │ │ ├── gr716 │ │ │ ├── Makefile │ │ │ ├── config.h │ │ │ ├── gr716.h │ │ │ └── _init.S │ │ ├── gr740 │ │ │ ├── Makefile │ │ │ ├── config.h │ │ │ └── gr740.h │ │ ├── generic │ │ │ ├── Makefile │ │ │ ├── generic.h │ │ │ └── config.h │ │ ├── gr712rc │ │ │ ├── Makefile │ │ │ ├── config.h │ │ │ └── gr712rc.h │ │ ├── gaisler.h │ │ ├── l2cache.h │ │ └── Makefile │ ├── halsyspage.h │ ├── arch │ │ ├── elf.h │ │ ├── types.h │ │ ├── spinlock.h │ │ ├── interrupts.h │ │ ├── tlb.h │ │ └── exceptions.h │ ├── Makefile │ ├── srmmu.c │ └── tlb.c ├── armv8r │ ├── mps3an536 │ │ ├── Makefile │ │ ├── config.h │ │ └── mps3an536.c │ ├── halsyspage.h │ ├── Makefile │ └── arch │ │ ├── elf.h │ │ ├── types.h │ │ ├── interrupts.h │ │ ├── spinlock.h │ │ ├── exceptions.h │ │ └── pmap.h ├── arm │ ├── Makefile │ ├── barriers.h │ └── rtt.h ├── armv8m │ ├── nrf │ │ ├── 91 │ │ │ ├── Makefile │ │ │ ├── config.h │ │ │ └── nrf91.h │ │ └── Makefile │ ├── mcx │ │ ├── n94x │ │ │ ├── Makefile │ │ │ ├── config.h │ │ │ └── mcxn94x.h │ │ └── Makefile │ ├── stm32 │ │ ├── n6 │ │ │ ├── Makefile │ │ │ └── config.h │ │ ├── Makefile │ │ ├── stm32-timer.h │ │ └── halsyspage.h │ ├── halsyspage.h │ ├── arch │ │ ├── types.h │ │ ├── elf.h │ │ ├── spinlock.h │ │ ├── exceptions.h │ │ ├── interrupts.h │ │ └── pmap.h │ ├── Makefile │ └── hal.c ├── armv7a │ ├── zynq7000 │ │ ├── Makefile │ │ ├── zynq.h │ │ └── config.h │ ├── halsyspage.h │ ├── Makefile │ ├── arch │ │ ├── types.h │ │ ├── interrupts.h │ │ ├── spinlock.h │ │ └── exceptions.h │ └── imx6ull │ │ ├── config.h │ │ └── Makefile ├── ia32 │ ├── halsyspage.h │ ├── config.h │ ├── pci.h │ ├── Makefile │ ├── arch │ │ ├── types.h │ │ ├── spinlock.h │ │ ├── exceptions.h │ │ └── tlb.h │ ├── console.h │ ├── console.c │ └── hal.c ├── elf.h ├── interrupts.h ├── timer.h ├── spinlock.h ├── console.h ├── types.h ├── exceptions.h ├── common.c ├── hal.h ├── list.h └── string.h ├── test ├── proc-fpu.h ├── Makefile ├── msg.h ├── rb.h ├── test.h ├── proc.h ├── hw-ddr.h ├── vm.h ├── test.c └── proc-fpu.c ├── log ├── Makefile └── log.h ├── .gitignore ├── posix ├── Makefile ├── sockdefs.h └── fdpass.h ├── lib ├── Makefile ├── rand.h ├── bsearch.h ├── rand.c ├── strutil.h ├── bsearch.c ├── assert.h ├── printf.h ├── assert.c ├── strutil.c ├── helpers.h └── cbuffer.h ├── .github └── workflows │ ├── lint.yml │ └── ci.yml ├── vm ├── Makefile ├── types.h ├── kmalloc.h ├── vm.h ├── page.h ├── zone.h ├── vm.c ├── object.h └── amap.h ├── include ├── limits.h ├── signal.h ├── ioctl.h ├── time.h ├── arch │ ├── sparcv8leon │ │ ├── syspage.h │ │ ├── types.h │ │ ├── sparcv8leon.h │ │ ├── stdtypes.h │ │ ├── generic │ │ │ └── generic.h │ │ └── gr712rc │ │ │ └── gr712rc.h │ ├── armv7a │ │ ├── imx6ull │ │ │ └── syspage.h │ │ ├── zynq7000 │ │ │ └── syspage.h │ │ ├── types.h │ │ └── stdtypes.h │ ├── riscv64 │ │ ├── syspage.h │ │ ├── types.h │ │ ├── stdtypes.h │ │ └── riscv64.h │ ├── aarch64 │ │ ├── zynqmp │ │ │ └── syspage.h │ │ ├── types.h │ │ └── stdtypes.h │ ├── armv8r │ │ ├── mps3an536 │ │ │ ├── syspage.h │ │ │ └── mps3an536.h │ │ ├── types.h │ │ └── stdtypes.h │ ├── armv7m │ │ ├── types.h │ │ ├── stdtypes.h │ │ ├── stm32 │ │ │ └── syspage.h │ │ └── imxrt │ │ │ └── syspage.h │ ├── armv8m │ │ ├── types.h │ │ ├── stdtypes.h │ │ ├── nrf │ │ │ └── syspage.h │ │ ├── mcx │ │ │ └── syspage.h │ │ └── stm32 │ │ │ └── syspage.h │ ├── armv7r │ │ ├── types.h │ │ ├── stdtypes.h │ │ ├── tda4vm │ │ │ └── syspage.h │ │ └── zynqmp │ │ │ └── syspage.h │ └── ia32 │ │ ├── types.h │ │ └── stdtypes.h ├── posix-uio.h ├── posix-timespec.h ├── utsname.h ├── events.h ├── file.h ├── threads.h ├── posix-stdio.h ├── posix-types.h ├── posix-poll.h ├── mman.h ├── posix-fcntl.h └── posix-statvfs.h ├── usrv.h ├── proc ├── Makefile ├── proc.c ├── proc.h ├── mutex.h ├── cond.h ├── userintr.h ├── name.h ├── resource.h ├── ports.h ├── msg.h └── lock.h ├── syscalls.h ├── .clang-format ├── README.md ├── syspage.h └── usrv.c /.codespell_ignore: -------------------------------------------------------------------------------- 1 | PTD 2 | ptd 3 | mapp 4 | pmapp 5 | HSI 6 | sie 7 | hart 8 | SME 9 | ded 10 | hsi 11 | spOffs 12 | DED 13 | inout 14 | fo 15 | ba 16 | -------------------------------------------------------------------------------- /hal/tlb/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for HAL TLB functions 3 | # 4 | # Copyright 2023 Phoenix Systems 5 | # 6 | 7 | OBJS += $(addprefix $(PREFIX_O)hal/tlb/, tlb.o) 8 | -------------------------------------------------------------------------------- /hal/gaisler/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for HAL Gaisler functions 3 | # 4 | # Copyright 2024 Phoenix Systems 5 | # 6 | 7 | OBJS += $(addprefix $(PREFIX_O)hal/gaisler/, ambapp.o) 8 | -------------------------------------------------------------------------------- /test/proc-fpu.h: -------------------------------------------------------------------------------- 1 | #ifndef _TEST_FPU_H_ 2 | #define _TEST_FPU_H_ 3 | 4 | 5 | /* Function testing fpu context switching */ 6 | void test_fpuContextSwitching(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /log/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for phoenix-rtos-kernel/log 3 | # 4 | # Copyright 2021 Phoenix Systems 5 | # Author: Maciej Purski 6 | # 7 | 8 | OBJS += $(addprefix $(PREFIX_O)log/, log.o) 9 | -------------------------------------------------------------------------------- /hal/riscv64/generic/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for riscv64-generic 3 | # 4 | # Copyright 2024 Phoenix Systems 5 | # 6 | 7 | OBJS += $(addprefix $(PREFIX_O)hal/riscv64/generic/, console.o generic.o) 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | *.elf 4 | *.img 5 | *.flash 6 | *.cmd 7 | *.hex 8 | *~ 9 | .depend 10 | .DS_Store 11 | CMakeLists.txt 12 | .idea/ 13 | cmake-build-debug/ 14 | .vscode/* 15 | .cpptest 16 | -------------------------------------------------------------------------------- /hal/aarch64/zynqmp/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (AArch64 HAL ZynqMP) 3 | # 4 | # Copyright 2024 Phoenix Systems 5 | # 6 | 7 | OBJS += $(addprefix $(PREFIX_O)hal/aarch64/zynqmp/, console.o zynqmp.o timer.o) 8 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for phoenix-rtos-kernel/test 3 | # 4 | # Copyright 2020 Phoenix Systems 5 | # Author: Pawel Pisarczyk 6 | # 7 | 8 | OBJS += $(addprefix $(PREFIX_O)test/, test.o vm.o rb.o proc.o msg.o) 9 | 10 | -------------------------------------------------------------------------------- /posix/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for phoenix-rtos-kernel/posix 3 | # 4 | # Copyright 2020 Phoenix Systems 5 | # Author: Pawel Pisarczyk 6 | # 7 | 8 | OBJS += $(addprefix $(PREFIX_O)posix/, posix.o inet.o unix.o fdpass.o) 9 | 10 | -------------------------------------------------------------------------------- /hal/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for phoenix-rtos-kernel/hal 3 | # 4 | # Copyright 2023 Phoenix Systems 5 | # Author: Hubert Badocha 6 | # 7 | 8 | OBJS += $(addprefix $(PREFIX_O)hal/, common.o) 9 | 10 | include hal/$(TARGET_SUFF)/Makefile 11 | -------------------------------------------------------------------------------- /hal/armv7r/tda4vm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-R HAL TDA4VM) 3 | # 4 | # Copyright 2025 Phoenix Systems 5 | # 6 | 7 | OBJS += $(addprefix $(PREFIX_O)hal/armv7r/tda4vm/, _init.o console.o interrupts.o tda4vm.o timer.o) 8 | -------------------------------------------------------------------------------- /hal/armv7r/zynqmp/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-R HAL ZynqMP) 3 | # 4 | # Copyright 2025 Phoenix Systems 5 | # 6 | 7 | OBJS += $(addprefix $(PREFIX_O)hal/armv7r/zynqmp/, _init.o console.o interrupts.o zynqmp.o timer.o) 8 | -------------------------------------------------------------------------------- /hal/armv7m/stm32/l4/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-M HAL STM32L4) 3 | # 4 | # Copyright 2016-2017, 2019-2020 Phoenix Systems 5 | # 6 | 7 | 8 | OBJS += $(addprefix $(PREFIX_O)hal/armv7m/stm32/l4/, stm32l4.o console.o timer.o) 9 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/gr716/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (sparcv8leon-gr716 HAL) 3 | # 4 | # Copyright 2022 Phoenix Systems 5 | # 6 | 7 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/$(TARGET_SUBFAMILY)/, gr716.o _init.o) 8 | -------------------------------------------------------------------------------- /hal/armv8r/mps3an536/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv8-R HAL MPS3 AN536) 3 | # 4 | # Copyright 2024 Phoenix Systems 5 | # 6 | 7 | OBJS += $(addprefix $(PREFIX_O)hal/armv8r/mps3an536/, _init.o console.o interrupts.o mps3an536.o timer.o) 8 | 9 | -------------------------------------------------------------------------------- /hal/riscv64/gaisler/gr765/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for riscv64-gr765 3 | # 4 | # Copyright 2024 Phoenix Systems 5 | # 6 | 7 | include hal/gaisler/Makefile 8 | 9 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/$(TARGET_SUBFAMILY)/, gr765.o) 10 | -------------------------------------------------------------------------------- /hal/riscv64/gaisler/grfpga/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for riscv64-grfpga 3 | # 4 | # Copyright 2024 Phoenix Systems 5 | # 6 | 7 | include hal/gaisler/Makefile 8 | 9 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/$(TARGET_SUBFAMILY)/, grfpga.o) 10 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for phoenix-rtos-kernel/lib 3 | # 4 | # Copyright 2020 Phoenix Systems 5 | # Author: Pawel Pisarczyk 6 | # 7 | 8 | OBJS += $(addprefix $(PREFIX_O)lib/, assert.o printf.o bsearch.o rand.o rb.o list.o cbuffer.o strutil.o idtree.o) 9 | 10 | -------------------------------------------------------------------------------- /hal/arm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for HAL ARM common functions 3 | # 4 | # Copyright 2023 Phoenix Systems 5 | # 6 | 7 | # TODO handle other common ARM stuff (e.g GIC) and 8 | # select relevant components here 9 | 10 | OBJS += $(addprefix $(PREFIX_O)hal/arm/, scs.o rtt.o) 11 | -------------------------------------------------------------------------------- /hal/armv8m/nrf/91/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv8 HAL) 3 | # 4 | # Copyright 2016-2017, 2019-2020, 2022 Phoenix Systems 5 | # 6 | 7 | CFLAGS += -Ihal/armv8m/nrf/91 8 | 9 | OBJS += $(addprefix $(PREFIX_O)hal/armv8m/nrf/91/, nrf91.o console.o timer.o) 10 | -------------------------------------------------------------------------------- /hal/armv7m/imxrt/10xx/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-M HAL i.MX RT10xx) 3 | # 4 | # Copyright 2016-2017, 2019-2020 Phoenix Systems 5 | # 6 | 7 | CFLAGS += -Ihal/armv7m/imxrt/10xx 8 | 9 | OBJS += $(addprefix $(PREFIX_O)hal/armv7m/imxrt/10xx/, console.o imxrt10xx.o) 10 | -------------------------------------------------------------------------------- /hal/armv7m/imxrt/117x/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-M HAL i.MX RT117x) 3 | # 4 | # Copyright 2016-2017, 2019-2020 Phoenix Systems 5 | # 6 | 7 | CFLAGS += -Ihal/armv7m/imxrt/117x 8 | 9 | OBJS += $(addprefix $(PREFIX_O)hal/armv7m/imxrt/117x/, console.o imxrt117x.o) 10 | -------------------------------------------------------------------------------- /hal/armv8m/mcx/n94x/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv8 HAL) 3 | # 4 | # Copyright 2016-2017, 2019-2020, 2022, 2024 Phoenix Systems 5 | # 6 | 7 | CFLAGS += -Ihal/armv8m/mcx/n94x 8 | 9 | OBJS += $(addprefix $(PREFIX_O)hal/armv8m/mcx/n94x/, mcxn94x.o console.o timer.o) 10 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/gr740/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (sparcv8leon-gr740 HAL) 3 | # 4 | # Copyright 2025 Phoenix Systems 5 | # 6 | 7 | include hal/tlb/Makefile 8 | 9 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/$(TARGET_SUBFAMILY)/, _init.o gr740.o) 10 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/generic/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (sparcv8leon-generic HAL) 3 | # 4 | # Copyright 2024 Phoenix Systems 5 | # 6 | 7 | include hal/tlb/Makefile 8 | 9 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/$(TARGET_SUBFAMILY)/, generic.o _init.o) 10 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/gr712rc/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (sparcv8leon-gr712rc HAL) 3 | # 4 | # Copyright 2023 Phoenix Systems 5 | # 6 | 7 | include hal/tlb/Makefile 8 | 9 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/$(TARGET_SUBFAMILY)/, gr712rc.o _init.o) 10 | -------------------------------------------------------------------------------- /hal/armv8m/stm32/n6/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv8-M HAL STM32N6) 3 | # 4 | # Copyright 2016-2017, 2019-2025 Phoenix Systems 5 | # 6 | 7 | CFLAGS += -Ihal/armv8m/stm32/n6 8 | 9 | OBJS += $(addprefix $(PREFIX_O)hal/armv8m/stm32/n6/, bsec.o console.o risaf.o stm32n6.o timer.o) 10 | -------------------------------------------------------------------------------- /hal/armv8m/stm32/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv8-M HAL STM32) 3 | # 4 | # Copyright 2016-2025 Phoenix Systems 5 | # 6 | 7 | 8 | ifneq (, $(findstring n6, $(TARGET_SUBFAMILY))) 9 | include hal/armv8m/stm32/n6/Makefile 10 | endif 11 | 12 | OBJS += $(addprefix $(PREFIX_O)hal/armv8m/stm32/, _init.o) 13 | -------------------------------------------------------------------------------- /hal/armv8m/nrf/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv8 HAL) 3 | # 4 | # Copyright 2016-2017, 2019-2020, 2022 Phoenix Systems 5 | # 6 | 7 | 8 | ifneq (, $(findstring nrf91, $(TARGET_SUBFAMILY))) 9 | include hal/armv8m/nrf/91/Makefile 10 | endif 11 | 12 | OBJS += $(addprefix $(PREFIX_O)hal/armv8m/nrf/, _init.o) 13 | -------------------------------------------------------------------------------- /hal/armv8m/mcx/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv8 HAL) 3 | # 4 | # Copyright 2016-2017, 2019-2020, 2022, 2024 Phoenix Systems 5 | # 6 | 7 | 8 | ifneq (, $(findstring mcxn94x, $(TARGET_SUBFAMILY))) 9 | include hal/armv8m/mcx/n94x/Makefile 10 | endif 11 | 12 | OBJS += $(addprefix $(PREFIX_O)hal/armv8m/mcx/, _init.o) 13 | -------------------------------------------------------------------------------- /hal/armv7a/zynq7000/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-A HAL Zynq-7000) 3 | # 4 | # Copyright 2021 Phoenix Systems 5 | # 6 | 7 | OBJS += $(addprefix $(PREFIX_O)hal/armv7a/zynq7000/, _init.o console.o zynq.o timer.o interrupts.o) 8 | 9 | $(PREFIX_O)hal/armv7a/zynq7000/_init.o: hal/armv7a/_armv7a.S hal/armv7a/_interrupts.S 10 | -------------------------------------------------------------------------------- /hal/armv7m/stm32/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-M HAL STM32) 3 | # 4 | # Copyright 2016-2017, 2019-2020 Phoenix Systems 5 | # 6 | 7 | 8 | ifneq (, $(findstring l4, $(TARGET_SUBFAMILY))) 9 | include hal/armv7m/stm32/l4/Makefile 10 | endif 11 | 12 | OBJS += $(addprefix $(PREFIX_O)hal/armv7m/stm32/, _init.o interrupts.o) 13 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | # vim:sw=2:ts=2 2 | name: lint 3 | 4 | # on events 5 | on: 6 | push: 7 | branches: 8 | - master 9 | - 'feature/*' 10 | pull_request: 11 | branches: 12 | - master 13 | - 'feature/*' 14 | 15 | jobs: 16 | call-lint: 17 | uses: phoenix-rtos/phoenix-rtos-project/.github/workflows/lint.yml@master 18 | -------------------------------------------------------------------------------- /test/msg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Tests for messages 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Author: Jakub Sejdak 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _TEST_MSG_H_ 17 | #define _TEST_MSG_H_ 18 | 19 | 20 | void test_msg(void); 21 | 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /vm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for phoenix-rtos-kernel/vm 3 | # 4 | # Copyright 2017, 2020 Phoenix Systems 5 | # Author: Pawel Pisarczyk 6 | # 7 | 8 | OBJS += $(addprefix $(PREFIX_O)vm/, vm.o map.o zone.o kmalloc.o object.o amap.o) 9 | 10 | ifneq (, $(findstring NOMMU, $(CPPFLAGS))) 11 | OBJS += $(PREFIX_O)vm/page-nommu.o 12 | else 13 | OBJS += $(PREFIX_O)vm/page.o 14 | endif 15 | -------------------------------------------------------------------------------- /include/limits.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Limits 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Ziemowit Leszczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_LIMITS_H_ 17 | #define _PH_LIMITS_H_ 18 | 19 | 20 | #define HOST_NAME_MAX 255U 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /test/rb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Tests for red-black tree 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Author: Jakub Sejdak 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _TEST_RB_H_ 17 | #define _TEST_RB_H_ 18 | 19 | 20 | void test_rb(void); 21 | 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # vim:sw=2:ts=2 2 | name: ci 3 | 4 | # on events 5 | on: 6 | push: 7 | branches: 8 | - master 9 | - 'feature/*' 10 | pull_request: 11 | branches: 12 | - master 13 | - 'feature/*' 14 | 15 | jobs: 16 | call-ci: 17 | uses: phoenix-rtos/phoenix-rtos-project/.github/workflows/ci-submodule.yml@master 18 | secrets: inherit 19 | -------------------------------------------------------------------------------- /hal/riscv64/gaisler/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (SPARCV8 LEON3 HAL) 3 | # 4 | # Copyright 2023-2025 Phoenix Systems 5 | # 6 | # %LICENSE% 7 | # 8 | 9 | include hal/$(TARGET_SUFF)/gaisler/$(TARGET_SUBFAMILY)/Makefile 10 | 11 | CFLAGS += -Ihal/$(TARGET_SUFF)/gaisler/$(TARGET_SUBFAMILY) 12 | 13 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/, console.o) 14 | -------------------------------------------------------------------------------- /lib/rand.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Standard routines 7 | * 8 | * Copyright 2012, 2016 Phoenix Systems 9 | * Author: Pawel Kolodziej 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_LIB_RAND_H_ 17 | #define _PH_LIB_RAND_H_ 18 | 19 | 20 | int lib_rand(unsigned int *seedp); 21 | 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /usrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * User server 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Authors: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_USRV_H_ 17 | #define _PH_USRV_H_ 18 | 19 | 20 | void _usrv_init(void); 21 | 22 | 23 | void _usrv_start(void); 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/signal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Signals 7 | * 8 | * Copyright 2018 Phoenix Systems 9 | * Author: Jan Sikorski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #ifndef _PH_SIGNAL_H_ 18 | #define _PH_SIGNAL_H_ 19 | 20 | enum { signal_kill = 1, signal_segv, signal_illegal, signal_cancel = 32 }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /proc/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for phoenix-rtos-kernel/proc 3 | # 4 | # Copyright 2020 Phoenix Systems 5 | # Author: Pawel Pisarczyk 6 | # 7 | 8 | OBJS += $(addprefix $(PREFIX_O)proc/, proc.o threads.o process.o name.o resource.o mutex.o cond.o userintr.o ports.o) 9 | 10 | ifneq (, $(findstring NOMMU, $(CPPFLAGS))) 11 | OBJS += $(PREFIX_O)proc/msg-nommu.o 12 | else 13 | OBJS += $(PREFIX_O)proc/msg.o 14 | endif 15 | -------------------------------------------------------------------------------- /include/ioctl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * ioctl 7 | * 8 | * Copyright 2018 Phoenix Systems 9 | * Author: Jan Sikorski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_IOCTL_H_ 17 | #define _PH_IOCTL_H_ 18 | 19 | 20 | typedef struct { 21 | unsigned long request; 22 | char data[]; 23 | } ioctl_in_t; 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /test/test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Test subsystem 7 | * 8 | * Copyright 2012, 2016, 2017 Phoenix Systems 9 | * Copyright 2001, 2005 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _TEST_TEST_H_ 18 | #define _TEST_TEST_H_ 19 | 20 | #include "vm.h" 21 | #include "proc.h" 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /vm/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Virtual memory manager - common types 7 | * 8 | * Copyright 2025 Phoenix Systems 9 | * Author: Adam Greloch 10 | * 11 | * %LICENSE% 12 | */ 13 | 14 | #ifndef _PH_VM_TYPES_H_ 15 | #define _PH_VM_TYPES_H_ 16 | 17 | #include "hal/types.h" 18 | 19 | typedef u8 vm_flags_t; 20 | 21 | typedef u32 vm_attr_t; 22 | 23 | typedef u8 vm_prot_t; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /posix/sockdefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * libphoenix 5 | * 6 | * sys/socket.h 7 | * 8 | * Copyright 2018 Phoenix Systems 9 | * Author: Michał Mirosław 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_SYS_SOCKDEFS_H_ 17 | #define _PH_SYS_SOCKDEFS_H_ 18 | 19 | #define SOCK_NONBLOCK 0x8000U 20 | #define SOCK_CLOEXEC 0x4000U 21 | #define SOCK_LARGEBUF 0x2000U 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /hal/armv8m/stm32/stm32-timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Extra timer interface for stm32 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_STM32TIMER_H_ 17 | #define _PH_HAL_STM32TIMER_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | 22 | void timer_jiffiesAdd(time_t t); 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/bsearch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Binary search 7 | * 8 | * Copyright 2012 Phoenix Systems 9 | * Author: Paweł Kołodziej 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | * 15 | */ 16 | 17 | #ifndef _PH_LIB_BSEARCH_H_ 18 | #define _PH_LIB_BSEARCH_H_ 19 | 20 | 21 | void *lib_bsearch(void *key, void *base, size_t nmemb, size_t size, int (*compar)(void *n1, void *n2)); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /include/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Time 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_TIME_H_ 17 | #define _PH_TIME_H_ 18 | 19 | 20 | #define PH_CLOCK_RELATIVE 0 21 | #define PH_CLOCK_REALTIME 1 22 | #define PH_CLOCK_MONOTONIC 2 23 | 24 | #define TIMER_ABSTIME 1U 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /lib/rand.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Standard library - random number generator 7 | * 8 | * Copyright 2012, 2016 Phoenix Systems 9 | * Author: Pawel Kolodziej 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #include "lib/rand.h" 17 | 18 | 19 | int lib_rand(unsigned int *seedp) 20 | { 21 | *seedp = (*seedp * 1103515245U + 12345U); 22 | return (int)(unsigned int)(*seedp / 2U); 23 | } 24 | -------------------------------------------------------------------------------- /include/arch/sparcv8leon/syspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL syspage for sparcv8leon 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_SYSPAGE_LEON3_H_ 17 | #define _PH_SYSPAGE_LEON3_H_ 18 | 19 | 20 | typedef struct { 21 | int dummy; 22 | } __attribute__((packed)) hal_syspage_t; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /syscalls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System calls 7 | * 8 | * Copyright 2012, 2017 Phoenix Systems 9 | * Copyright 2007 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_SYSCALLS_H_ 18 | #define _PH_SYSCALLS_H_ 19 | 20 | 21 | extern const void *const syscalls[]; 22 | 23 | 24 | void _syscalls_init(void); 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /hal/aarch64/halsyspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System information page (prepared by kernel loader) 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_SYSPAGE_H_ 17 | #define _PH_HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /hal/armv7a/halsyspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System information page (prepared by kernel loader) 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_SYSPAGE_H_ 17 | #define _PH_HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /hal/ia32/halsyspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System information page (prepared by kernel loader) 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_SYSPAGE_H_ 17 | #define _PH_HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/arch/armv7a/imx6ull/syspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL syspage for i.MX 6ULL 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Authors: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_SYSPAGE_IMX6ULL_H_ 17 | #define _PH_SYSPAGE_IMX6ULL_H_ 18 | 19 | 20 | typedef struct { 21 | int dummy; 22 | } __attribute__((packed)) hal_syspage_t; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/arch/armv7a/zynq7000/syspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL syspage for Zynq-7000 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Authors: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_SYSPAGE_ZYNQ7000_H_ 17 | #define _PH_SYSPAGE_ZYNQ7000_H_ 18 | 19 | typedef struct { 20 | int dummy; 21 | } __attribute__((packed)) hal_syspage_t; 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /test/proc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Tests for proc subsystem 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _TEST_PROC_H_ 17 | #define _TEST_PROC_H_ 18 | 19 | 20 | void test_proc_threads1(void); 21 | 22 | 23 | void test_proc_threads2(void); 24 | 25 | 26 | void test_proc_exit(void); 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /hal/armv7m/imxrt/halsyspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System information page (prepared by kernel loader) 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_SYSPAGE_H_ 17 | #define _PH_HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /hal/armv7m/stm32/halsyspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System information page (prepared by kernel loader) 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_SYSPAGE_H_ 17 | #define _PH_HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /hal/armv7r/halsyspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System information page (prepared by kernel loader) 7 | * 8 | * Copyright 2022, 2024 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_SYSPAGE_H_ 17 | #define _PH_HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /hal/armv8m/stm32/halsyspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System information page (prepared by kernel loader) 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_SYSPAGE_H_ 17 | #define _PH_HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /hal/armv8r/halsyspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System information page (prepared by kernel loader) 7 | * 8 | * Copyright 2022, 2024 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_SYSPAGE_H_ 17 | #define _PH_HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /hal/riscv64/halsyspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System information page (prepared by kernel loader) 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_SYSPAGE_H_ 17 | #define _PH_HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *hal_syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /hal/sparcv8leon/halsyspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System information page (prepared by kernel loader) 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_SYSPAGE_H_ 17 | #define _PH_HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/arch/riscv64/syspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL syspage for riscv64 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Authors: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_SYSPAGE_RISCV64_H_ 17 | #define _PH_SYSPAGE_RISCV64_H_ 18 | 19 | 20 | typedef struct { 21 | unsigned int boothartId; 22 | } __attribute__((packed)) hal_syspage_t; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /hal/ia32/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for ia2 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | #ifndef __ASSEMBLY__ 20 | 21 | #include "include/arch/ia32/syspage.h" 22 | #include "include/syspage.h" 23 | 24 | #endif 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/arch/aarch64/zynqmp/syspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL syspage for ZynqMP 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Authors: Jacek Maksymowicz 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_SYSPAGE_ZYNQMP_H_ 17 | #define _PH_SYSPAGE_ZYNQMP_H_ 18 | 19 | typedef struct { 20 | long long int resetReason; 21 | } __attribute__((packed)) hal_syspage_t; 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/arch/armv8r/mps3an536/syspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL syspage for MPS3-AN536 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Authors: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_SYSPAGE_MPS3AN536_H_ 17 | #define _PH_SYSPAGE_MPS3AN536_H_ 18 | 19 | 20 | typedef struct { 21 | int dummy; 22 | } __attribute__((packed)) hal_syspage_t; 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /hal/armv8m/halsyspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System information page (prepared by kernel loader) 7 | * 8 | * Copyright 2022, 2024, 2025 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_SYSPAGE_H_ 17 | #define _PH_HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /hal/armv8r/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv8-R HAL) 3 | # 4 | # Copyright 2024 Phoenix Systems 5 | # 6 | 7 | ifneq (, $(findstring mps3an536, $(TARGET_SUBFAMILY))) 8 | include hal/armv8r/mps3an536/Makefile 9 | CFLAGS += -Ihal/armv8r/mps3an536 10 | else 11 | $(error Unsupported TARGET) 12 | endif 13 | 14 | CFLAGS += -Ihal/armv8r 15 | 16 | OBJS += $(addprefix $(PREFIX_O)hal/armv8r/, _armv8r.o _interrupts.o _memcpy.o _memset.o \ 17 | cpu.o exceptions.o hal.o pmap.o spinlock.o string.o) 18 | -------------------------------------------------------------------------------- /hal/armv7m/stm32/stm32-timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Extra timer interface for stm32 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_STM32TIMER_H_ 17 | #define _PH_HAL_STM32TIMER_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | 22 | void timer_jiffiesAdd(time_t t); 23 | 24 | 25 | void timer_setAlarm(time_t us); 26 | 27 | 28 | #endif -------------------------------------------------------------------------------- /include/posix-uio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * POSIX-compatibility definitions - uio 7 | * 8 | * Copyright 2018, 2024 Phoenix Systems 9 | * Author: Jan Sikorski, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_POSIX_UIO_H_ 17 | #define _PH_POSIX_UIO_H_ 18 | 19 | 20 | #include "types.h" 21 | 22 | 23 | struct iovec { 24 | void *iov_base; 25 | size_t iov_len; 26 | }; 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /hal/elf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Hardware Abstraction Layer ELF support 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Hubert Badocha 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ELF_H_ 17 | #define _PH_HAL_ELF_H_ 18 | 19 | 20 | #ifdef NOMMU 21 | 22 | 23 | #include 24 | 25 | 26 | static int hal_isRelReloc(unsigned char relType); 27 | 28 | 29 | #endif 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/posix-timespec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * POSIX-compatibility definitions - timespec 7 | * 8 | * Copyright 2018, 2024 Phoenix Systems 9 | * Author: Jan Sikorski, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_POSIX_TIMESPEC_H_ 17 | #define _PH_POSIX_TIMESPEC_H_ 18 | 19 | 20 | #include "types.h" 21 | 22 | 23 | struct timespec { 24 | time_t tv_sec; 25 | long tv_nsec; 26 | }; 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/strutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * String helper routines 7 | * 8 | * Copyright 2018, 2023 Phoenix Systems 9 | * Author: Jan Sikorski, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_LIB_STRUTIL_H_ 17 | #define _PH_LIB_STRUTIL_H_ 18 | 19 | 20 | char *lib_strdup(const char *str); 21 | 22 | 23 | void lib_splitname(char *path, char **base, const char **dir); 24 | 25 | 26 | #endif /* _LIB_STRUTIL_H_ */ 27 | -------------------------------------------------------------------------------- /include/utsname.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * utsname 7 | * 8 | * Copyright 2025 Phoenix Systems 9 | * Author: Hubert Badocha 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_UTSNAME_H_ 17 | #define _PH_UTSNAME_H_ 18 | 19 | 20 | #include "limits.h" 21 | 22 | 23 | struct utsname { 24 | char sysname[16]; 25 | char nodename[HOST_NAME_MAX + 1U]; 26 | char release[16]; 27 | char version[32]; 28 | char machine[16]; 29 | }; 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /hal/riscv64/generic/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for riscv64 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | #ifndef __ASSEMBLY__ 20 | 21 | #include "include/arch/riscv64/syspage.h" 22 | #include "include/syspage.h" 23 | 24 | #define PLIC_CONTEXTS_PER_HART 2 25 | 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /hal/sparcv8leon/arch/elf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Hardware Abstraction Layer ELF support 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Hubert Badocha 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_LEON3_ELF_H_ 17 | #define _PH_HAL_LEON3_ELF_H_ 18 | 19 | #define R_SPARC_32 3U 20 | 21 | 22 | static inline int hal_isRelReloc(unsigned char relType) 23 | { 24 | return (relType == R_SPARC_32) ? 1 : 0; 25 | } 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/events.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * posixsrv's events 7 | * 8 | * Copyright 2018, 2024 Phoenix Systems 9 | * Author: Jan Sikorski, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_EVENTS_H_ 17 | #define _PH_EVENTS_H_ 18 | 19 | /* clang-format off */ 20 | 21 | enum { evAdd = 0x1, evDelete = 0x2, evEnable = 0x4, evDisable = 0x8, evOneshot = 0x10, evClear = 0x20, evDispatch = 0x40 }; 22 | 23 | /* clang-format on */ 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/arch/armv7m/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_ARMV7M_TYPES_H_ 17 | #define _PH_ARCH_ARMV7M_TYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "stdtypes.h" 24 | 25 | 26 | typedef __u32 addr_t; 27 | 28 | typedef int ssize_t; 29 | 30 | typedef __u32 id_t; 31 | 32 | 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /hal/armv7m/arch/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV7M_TYPES_H_ 17 | #define _PH_HAL_ARMV7M_TYPES_H_ 18 | 19 | 20 | #include "include/types.h" 21 | 22 | 23 | #ifndef __ASSEMBLY__ 24 | 25 | 26 | typedef __u32 cycles_t; 27 | typedef __u32 ptr_t; 28 | 29 | typedef unsigned int size_t; 30 | 31 | 32 | #endif 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /hal/armv8m/arch/types.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Phoenix-RTOS 4 | * 5 | * Operating system kernel 6 | * 7 | * Types 8 | * 9 | * Copyright 2023 Phoenix Systems 10 | * Author: Damian Loewnau 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_HAL_ARMV8M_TYPES_H_ 18 | #define _PH_HAL_ARMV8M_TYPES_H_ 19 | 20 | 21 | #include "include/types.h" 22 | 23 | 24 | #ifndef __ASSEMBLY__ 25 | 26 | 27 | typedef __u32 cycles_t; 28 | typedef __u32 ptr_t; 29 | 30 | typedef unsigned int size_t; 31 | 32 | 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/arch/aarch64/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Jacek Maksymowicz 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_AARCH64_TYPES_H_ 17 | #define _PH_ARCH_AARCH64_TYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "stdtypes.h" 24 | 25 | 26 | typedef __u64 addr_t; 27 | 28 | typedef __s64 ssize_t; 29 | 30 | typedef __u64 id_t; 31 | 32 | 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /hal/sparcv8leon/arch/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2022, 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_LEON3_TYPES_H_ 17 | #define _PH_HAL_LEON3_TYPES_H_ 18 | 19 | 20 | #include "include/types.h" 21 | 22 | 23 | #ifndef __ASSEMBLY__ 24 | 25 | 26 | typedef __u64 cycles_t; 27 | typedef __u32 ptr_t; 28 | 29 | typedef unsigned int size_t; 30 | 31 | 32 | #endif 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /include/arch/sparcv8leon/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2022, 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_LEON3_TYPES_H_ 17 | #define _PH_ARCH_LEON3_TYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "stdtypes.h" 24 | 25 | 26 | typedef __u32 addr_t; 27 | 28 | typedef int ssize_t; 29 | 30 | typedef __u32 id_t; 31 | 32 | 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /hal/armv7a/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-A HAL) 3 | # 4 | # Copyright 2018, 2020, 2021 Phoenix Systems 5 | # 6 | 7 | ifneq (, $(findstring zynq7000, $(TARGET_SUBFAMILY))) 8 | include hal/armv7a/zynq7000/Makefile 9 | CFLAGS += -Ihal/armv7a/zynq7000 -Ihal/armv7a 10 | else ifneq (, $(findstring imx6ull, $(TARGET_SUBFAMILY))) 11 | include hal/armv7a/imx6ull/Makefile 12 | CFLAGS += -Ihal/armv7a/imx6ull -Ihal/armv7a 13 | endif 14 | 15 | OBJS += $(addprefix $(PREFIX_O)hal/armv7a/, string.o spinlock.o cpu.o hal.o pmap.o exceptions.o _memcpy.o _memset.o) 16 | -------------------------------------------------------------------------------- /hal/armv7m/arch/exceptions.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _PH_HAL_ARMV7M_EXCEPTIONS_H_ 3 | #define _PH_HAL_ARMV7M_EXCEPTIONS_H_ 4 | 5 | #include "cpu.h" 6 | 7 | #define EXC_DEFAULT 128 8 | 9 | #define EXC_UNDEFINED 3 10 | 11 | #define SIZE_CTXDUMP 320 /* Size of dumped context */ 12 | 13 | 14 | typedef struct _exc_context_t { 15 | /* Saved by ISR */ 16 | u32 psp; 17 | u32 r4; 18 | u32 r5; 19 | u32 r6; 20 | u32 r7; 21 | u32 r8; 22 | u32 r9; 23 | u32 r10; 24 | u32 r11; 25 | u32 excret; 26 | 27 | /* Saved by hardware */ 28 | cpu_hwContext_t mspctx; 29 | } exc_context_t; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /hal/armv7m/imxrt/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-M HAL i.MX RT) 3 | # 4 | # Copyright 2016-2017, 2019-2020 Phoenix Systems 5 | # 6 | 7 | 8 | ifneq (, $(findstring imxrt117x, $(TARGET_SUBFAMILY))) 9 | include hal/armv7m/imxrt/117x/Makefile 10 | else ifneq (, $(findstring imxrt106x, $(TARGET_SUBFAMILY))) 11 | include hal/armv7m/imxrt/10xx/Makefile 12 | else ifneq (, $(findstring imxrt105x, $(TARGET_SUBFAMILY))) 13 | include hal/armv7m/imxrt/10xx/Makefile 14 | endif 15 | 16 | OBJS += $(addprefix $(PREFIX_O)hal/armv7m/imxrt/, _init.o interrupts.o timer.o) 17 | -------------------------------------------------------------------------------- /hal/riscv64/arch/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types RISCV64 7 | * 8 | * Copyright 2018, 2024 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_RISCV64_TYPES_H_ 17 | #define _PH_HAL_RISCV64_TYPES_H_ 18 | 19 | #include "include/types.h" 20 | 21 | #ifndef __ASSEMBLY__ 22 | 23 | typedef __u64 cycles_t; 24 | typedef __u64 ptr_t; 25 | 26 | typedef unsigned long size_t; 27 | 28 | 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/arch/armv8m/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2023, 2024 Phoenix Systems 9 | * Author: Damian Loewnau, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_ARMV8M_TYPES_H_ 17 | #define _PH_ARCH_ARMV8M_TYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "stdtypes.h" 24 | 25 | 26 | typedef __u32 addr_t; 27 | 28 | typedef int ssize_t; 29 | 30 | typedef __u32 id_t; 31 | 32 | 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /hal/riscv64/gaisler/gr765/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for riscv64 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | #ifndef __ASSEMBLY__ 20 | 21 | #include "include/arch/riscv64/syspage.h" 22 | #include "include/syspage.h" 23 | 24 | 25 | #define AHB_IOAREA 0xfff00000U 26 | 27 | #define PLIC_CONTEXTS_PER_HART 4 28 | 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/arch/riscv64/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types RISCV64 7 | * 8 | * Copyright 2018, 2024 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_RISCV64_TYPES_H_ 17 | #define _PH_ARCH_RISCV64_TYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "stdtypes.h" 24 | 25 | 26 | typedef __u64 addr_t; 27 | 28 | typedef long ssize_t; 29 | 30 | typedef __u64 id_t; 31 | 32 | 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /hal/riscv64/gaisler/grfpga/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for riscv64 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | #ifndef __ASSEMBLY__ 20 | 21 | #include "include/arch/riscv64/syspage.h" 22 | #include "include/syspage.h" 23 | 24 | 25 | #define AHB_IOAREA 0xfff00000U 26 | 27 | #define PLIC_CONTEXTS_PER_HART 4 28 | 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /test/hw-ddr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Tests for DDR RAM 7 | * 8 | * Copyright 2015 Phoenix Systems 9 | * Author: Jakub Sejdak 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _TEST_DDR_H_ 17 | #define _TEST_DDR_H_ 18 | 19 | int test_ddrAccessibility(uint32_t address, int size); 20 | 21 | int test_ddrBitCrossTalk(uint32_t address, int size); 22 | 23 | int test_ddrBitChargeLeakage(uint32_t address, int size); 24 | 25 | int test_ddrFullMemtest(uint32_t address, int size, int iterations); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /hal/armv7a/arch/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2014, 2017, 2018 Phoenix Systems 9 | * Author: Jacek Popko, Aleksander Kaminski, Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV7A_TYPES_H_ 17 | #define _PH_HAL_ARMV7A_TYPES_H_ 18 | 19 | 20 | #include "include/types.h" 21 | 22 | 23 | #ifndef __ASSEMBLY__ 24 | 25 | 26 | typedef __u32 cycles_t; 27 | typedef __u32 ptr_t; 28 | 29 | typedef unsigned int size_t; 30 | 31 | 32 | #endif 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /hal/armv7m/arch/elf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Hardware Abstraction Layer ELF support 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Hubert Badocha 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV7M_ELF_H_ 17 | #define _PH_HAL_ARMV7M_ELF_H_ 18 | 19 | 20 | #define R_ARM_ABS32 2U 21 | #define R_ARM_TARGET1 38U 22 | 23 | 24 | static inline int hal_isRelReloc(unsigned char relType) 25 | { 26 | return ((relType == R_ARM_ABS32) || (relType == R_ARM_TARGET1)) ? 1 : 0; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /hal/armv7r/arch/elf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Hardware Abstraction Layer ELF support 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Hubert Badocha 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV7R_ELF_H_ 17 | #define _PH_HAL_ARMV7R_ELF_H_ 18 | 19 | 20 | #define R_ARM_ABS32 2U 21 | #define R_ARM_TARGET1 38U 22 | 23 | 24 | static inline int hal_isRelReloc(unsigned char relType) 25 | { 26 | return ((relType == R_ARM_ABS32) || (relType == R_ARM_TARGET1)) ? 1 : 0; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /hal/armv7r/arch/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2014, 2017, 2018, 2024 Phoenix Systems 9 | * Author: Jacek Popko, Aleksander Kaminski, Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV7R_TYPES_H_ 17 | #define _PH_HAL_ARMV7R_TYPES_H_ 18 | 19 | 20 | #include "include/types.h" 21 | 22 | 23 | #ifndef __ASSEMBLY__ 24 | 25 | 26 | typedef __u32 cycles_t; 27 | typedef __u32 ptr_t; 28 | 29 | typedef unsigned int size_t; 30 | 31 | #endif 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /hal/armv8r/arch/elf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Hardware Abstraction Layer ELF support 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Hubert Badocha 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV8R_ELF_H_ 17 | #define _PH_HAL_ARMV8R_ELF_H_ 18 | 19 | 20 | #define R_ARM_ABS32 2U 21 | #define R_ARM_TARGET1 38U 22 | 23 | 24 | static inline int hal_isRelReloc(unsigned char relType) 25 | { 26 | return ((relType == R_ARM_ABS32) || (relType == R_ARM_TARGET1)) ? 1 : 0; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /hal/armv8r/mps3an536/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for ARMv8-R MPS3 AN536 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | #define NUM_CPUS 1 20 | 21 | #ifndef __ASSEMBLY__ 22 | 23 | #define HAL_NAME_PLATFORM "MPS3 AN536 " 24 | 25 | #include "include/arch/armv8r/mps3an536/syspage.h" 26 | #include "include/syspage.h" 27 | 28 | #endif 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/arch/armv7a/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2014, 2017, 2018 Phoenix Systems 9 | * Author: Jacek Popko, Aleksander Kaminski, Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_ARMV7A_TYPES_H_ 17 | #define _PH_ARCH_ARMV7A_TYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "stdtypes.h" 24 | 25 | 26 | typedef __u32 addr_t; 27 | 28 | typedef int ssize_t; 29 | 30 | typedef __u64 id_t; 31 | 32 | 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/arch/armv7r/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2014, 2017, 2018 Phoenix Systems 9 | * Author: Jacek Popko, Aleksander Kaminski, Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_ARMV7R_TYPES_H_ 17 | #define _PH_ARCH_ARMV7R_TYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "stdtypes.h" 24 | 25 | 26 | typedef __u32 addr_t; 27 | 28 | typedef int ssize_t; 29 | 30 | typedef __u32 id_t; 31 | 32 | 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/arch/armv8r/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2014, 2017, 2018 Phoenix Systems 9 | * Author: Jacek Popko, Aleksander Kaminski, Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_ARMV7A_TYPES_H_ 17 | #define _PH_ARCH_ARMV7A_TYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "stdtypes.h" 24 | 25 | 26 | typedef __u32 addr_t; 27 | 28 | typedef int ssize_t; 29 | 30 | typedef __u32 id_t; 31 | 32 | 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * file attributes 7 | * 8 | * Copyright 2017-2018, 2024 Phoenix Systems 9 | * Author: Aleksander Kaminski, Pawel Pisarczyk, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_FILE_H_ 17 | #define _PH_FILE_H_ 18 | 19 | /* clang-format off */ 20 | 21 | enum { atMode = 0, atUid, atGid, atSize, atBlocks, atIOBlock, atType, atPort, atPollStatus, atEventMask, atCTime, 22 | atMTime, atATime, atLinks, atDev }; 23 | 24 | /* clang-format on */ 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /hal/aarch64/arch/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * CPU-specific types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Jacek Maksymowicz 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_AARCH64_TYPES_H_ 17 | #define _PH_HAL_AARCH64_TYPES_H_ 18 | 19 | 20 | #include "include/types.h" 21 | 22 | 23 | #ifndef __ASSEMBLY__ 24 | 25 | 26 | typedef __u64 cycles_t; 27 | typedef __u64 ptr_t; 28 | typedef __u16 asid_t; 29 | 30 | typedef unsigned long int size_t; 31 | 32 | 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /hal/gaisler/ambapp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * AMBA Plug'n'Play 7 | * 8 | * Copyright 2023, 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_AMBAPP_H_ 17 | #define _PH_HAL_AMBAPP_H_ 18 | 19 | 20 | #include "include/gaisler/ambapp.h" 21 | 22 | 23 | int ambapp_findMaster(ambapp_dev_t *dev, unsigned int *instance); 24 | 25 | 26 | int ambapp_findSlave(ambapp_dev_t *dev, unsigned int *instance); 27 | 28 | 29 | void ambapp_init(void); 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /hal/armv8m/arch/elf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Hardware Abstraction Layer ELF support 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Hubert Badocha 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #ifndef _PH_HAL_ARMV8M_ELF_H_ 18 | #define _PH_HAL_ARMV8M_ELF_H_ 19 | 20 | 21 | #define R_ARM_ABS32 2U 22 | #define R_ARM_TARGET1 38U 23 | 24 | 25 | static inline int hal_isRelReloc(unsigned char relType) 26 | { 27 | return ((relType == R_ARM_ABS32) || (relType == R_ARM_TARGET1)) ? 1 : 0; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /hal/armv8r/arch/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2014, 2017, 2018, 2024 Phoenix Systems 9 | * Author: Jacek Popko, Aleksander Kaminski, Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV8R_TYPES_H_ 17 | #define _PH_HAL_ARMV8R_TYPES_H_ 18 | 19 | 20 | #include "include/types.h" 21 | 22 | 23 | #ifndef __ASSEMBLY__ 24 | 25 | 26 | typedef __u32 cycles_t; 27 | typedef __u32 ptr_t; 28 | 29 | typedef unsigned int size_t; 30 | 31 | 32 | #endif 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /hal/armv7m/stm32/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for STM32 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | #include "hal/types.h" 22 | #include "include/arch/armv7m/stm32/syspage.h" 23 | #include "include/syspage.h" 24 | #include "stm32.h" 25 | #include "stm32-timer.h" 26 | 27 | #define HAL_NAME_PLATFORM "STM32 " 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /hal/armv7r/tda4vm/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for TDA4VM 7 | * 8 | * Copyright 2021, 2025 Phoenix Systems 9 | * Author: Hubert Buczynski, Jacek Maksymowicz 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | 20 | #define NUM_CPUS 1 21 | 22 | #ifndef __ASSEMBLY__ 23 | 24 | #define HAL_NAME_PLATFORM "TI K3 J721e SoC " 25 | 26 | #include "include/arch/armv7r/tda4vm/syspage.h" 27 | #include "include/syspage.h" 28 | 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /hal/riscv64/arch/exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception handling 7 | * 8 | * Copyright 2018 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_RISCV64_EXCEPTIONS_H_ 17 | #define _PH_HAL_RISCV64_EXCEPTIONS_H_ 18 | 19 | #include "cpu.h" 20 | 21 | 22 | #define EXC_DEFAULT 128 23 | #define EXC_UNDEFINED 2 24 | #define EXC_PAGEFAULT 127 25 | 26 | #define SIZE_CTXDUMP 1024 /* Size of dumped context */ 27 | 28 | typedef cpu_context_t exc_context_t; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /hal/armv7a/arch/interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception and interrupt handling 7 | * 8 | * Copyright 2016, 2018, 2020 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV7A_INTERRUPTS_H_ 17 | #define _PH_HAL_ARMV7A_INTERRUPTS_H_ 18 | 19 | #include "cpu.h" 20 | 21 | typedef struct _intr_handler_t { 22 | struct _intr_handler_t *next; 23 | struct _intr_handler_t *prev; 24 | unsigned int n; 25 | intrFn_t f; 26 | void *data; 27 | } intr_handler_t; 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /hal/armv7m/arch/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Spinlock 7 | * 8 | * Copyright 2014, 2017 Phoenix Systems 9 | * Author: Jacek Popko, Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV7M_SPINLOCK_H_ 17 | #define _PH_HAL_ARMV7M_SPINLOCK_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | typedef struct _spinlock_t { 22 | const char *name; 23 | struct _spinlock_t *next; 24 | struct _spinlock_t *prev; 25 | 26 | u8 lock; 27 | } spinlock_t; 28 | 29 | 30 | typedef u32 spinlock_ctx_t; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /hal/armv7m/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-M HAL) 3 | # 4 | # Copyright 2016-2017, 2019-2020 Phoenix Systems 5 | # 6 | 7 | 8 | ifneq (, $(findstring stm32, $(TARGET_SUBFAMILY))) 9 | include hal/armv7m/stm32/Makefile 10 | CFLAGS += -Ihal/armv7m/stm32 -Ihal/armv7m 11 | else ifneq (, $(findstring imxrt, $(TARGET_SUBFAMILY))) 12 | include hal/armv7m/imxrt/Makefile 13 | CFLAGS += -Ihal/armv7m/imxrt -Ihal/armv7m 14 | endif 15 | 16 | include hal/arm/Makefile 17 | CFLAGS += -Ihal/arm 18 | 19 | OBJS += $(addprefix $(PREFIX_O)hal/armv7m/, string.o spinlock.o cpu.o hal.o pmap.o exceptions.o _memcpy.o _memset.o) 20 | -------------------------------------------------------------------------------- /hal/armv7r/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-R HAL) 3 | # 4 | # Copyright 2025 Phoenix Systems 5 | # 6 | 7 | ifneq (, $(findstring zynqmp, $(TARGET_SUBFAMILY))) 8 | include hal/armv7r/zynqmp/Makefile 9 | CFLAGS += -Ihal/armv7r/zynqmp 10 | else ifneq (, $(findstring tda4vm, $(TARGET_SUBFAMILY))) 11 | include hal/armv7r/tda4vm/Makefile 12 | CFLAGS += -Ihal/armv7r/tda4vm 13 | else 14 | $(error Unsupported TARGET) 15 | endif 16 | 17 | CFLAGS += -Ihal/armv7r 18 | 19 | OBJS += $(addprefix $(PREFIX_O)hal/armv7r/, _armv7r.o _interrupts.o _memcpy.o _memset.o \ 20 | cpu.o exceptions.o hal.o pmap.o spinlock.o string.o) 21 | -------------------------------------------------------------------------------- /hal/armv7r/zynqmp/zynqmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL internal functions for ZynqMP 7 | * 8 | * Copyright 2022, 2025 Phoenix Systems 9 | * Author: Maciej Purski, Jacek Maksymowicz 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ZYNQ_H_ 17 | #define _PH_HAL_ZYNQ_H_ 18 | 19 | #include "hal/cpu.h" 20 | #include "include/arch/armv7r/zynqmp/zynqmp.h" 21 | 22 | 23 | int _zynqmp_setMIO(unsigned int pin, u8 l0, u8 l1, u8 l2, u8 l3, u8 config); 24 | 25 | 26 | int _zynq_setDevRst(int dev, unsigned int state); 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /hal/armv8m/mcx/n94x/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for MCXN94x 7 | * 8 | * Copyright 2021, 2022, 2024 Phoenix Systems 9 | * Author: Hubert Buczynski, Damian Loewnau, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | #define SIZE_INTERRUPTS (171 + 16) 20 | 21 | #ifndef __ASSEMBLY__ 22 | 23 | #include "include/arch/armv8m/mcx/syspage.h" 24 | #include "mcxn94x.h" 25 | 26 | #define HAL_NAME_PLATFORM "MCX N94x " 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/arch/ia32/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Types 7 | * 8 | * Copyright 2012, 2017, 2024 Phoenix Systems 9 | * Copyright 2001, 2006 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk, Lukasz Leczkowski 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_ARCH_IA32_TYPES_H_ 18 | #define _PH_ARCH_IA32_TYPES_H_ 19 | 20 | 21 | #ifndef __ASSEMBLY__ 22 | 23 | 24 | #include "stdtypes.h" 25 | 26 | 27 | typedef __u32 addr_t; 28 | 29 | typedef long ssize_t; 30 | 31 | typedef __u64 id_t; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /hal/aarch64/zynqmp/zynqmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL internal functions for ZynqMP 7 | * 8 | * Copyright 2022, 2024 Phoenix Systems 9 | * Author: Maciej Purski, Jacek Maksymowicz 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ZYNQ_H_ 17 | #define _PH_HAL_ZYNQ_H_ 18 | 19 | #include "hal/cpu.h" 20 | #include "include/arch/aarch64/zynqmp/zynqmp.h" 21 | 22 | 23 | int _zynqmp_setMIO(unsigned int pin, u8 l0, u8 l1, u8 l2, u8 l3, u8 config); 24 | 25 | 26 | int _zynq_setDevRst(int dev, unsigned int state); 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /vm/kmalloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Fine-grained memory allocator 7 | * 8 | * Copyright 2012, 2017 Phoenix Systems 9 | * Copyright 2001, 2005 Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_VM_KMALLOC_H_ 17 | #define _PH_VM_KMALLOC_H_ 18 | 19 | #include "hal/hal.h" 20 | 21 | 22 | void *vm_kmalloc(size_t size); 23 | 24 | 25 | void vm_kfree(void *p); 26 | 27 | 28 | void vm_kmallocGetStats(size_t *allocsz); 29 | 30 | 31 | void vm_kmallocDump(void); 32 | 33 | 34 | int _kmalloc_init(void); 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /hal/sparcv8leon/arch/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Spinlock 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_LEON3_SPINLOCK_H_ 17 | #define _PH_HAL_LEON3_SPINLOCK_H_ 18 | 19 | 20 | #include "hal/types.h" 21 | 22 | 23 | typedef u32 spinlock_ctx_t; 24 | 25 | 26 | typedef struct _spinlock_t { 27 | const char *name; 28 | struct _spinlock_t *next; 29 | struct _spinlock_t *prev; 30 | u8 lock; 31 | } __attribute__((packed)) spinlock_t; 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /hal/armv7r/arch/interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception and interrupt handling 7 | * 8 | * Copyright 2016, 2018, 2020, 2024 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV7R_INTERRUPTS_H_ 17 | #define _PH_HAL_ARMV7R_INTERRUPTS_H_ 18 | 19 | #include "cpu.h" 20 | 21 | typedef struct _intr_handler_t { 22 | struct _intr_handler_t *next; 23 | struct _intr_handler_t *prev; 24 | unsigned int n; 25 | intrFn_t f; 26 | void *data; 27 | void *got; 28 | } intr_handler_t; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /hal/armv8m/arch/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Spinlock 7 | * 8 | * Copyright 2014, 2017, 2022 Phoenix Systems 9 | * Author: Jacek Popko, Pawel Pisarczyk, Damian Loewnau 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV8M_SPINLOCK_H_ 17 | #define _PH_HAL_ARMV8M_SPINLOCK_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | typedef struct _spinlock_t { 22 | const char *name; 23 | struct _spinlock_t *next; 24 | struct _spinlock_t *prev; 25 | 26 | u8 lock; 27 | } spinlock_t; 28 | 29 | 30 | typedef u32 spinlock_ctx_t; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /hal/armv8r/arch/interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception and interrupt handling 7 | * 8 | * Copyright 2016, 2018, 2020, 2024 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV8R_INTERRUPTS_H_ 17 | #define _PH_HAL_ARMV8R_INTERRUPTS_H_ 18 | 19 | #include "cpu.h" 20 | 21 | typedef struct _intr_handler_t { 22 | struct _intr_handler_t *next; 23 | struct _intr_handler_t *prev; 24 | unsigned int n; 25 | intrFn_t f; 26 | void *data; 27 | void *got; 28 | } intr_handler_t; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/threads.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Mutexes/Condvars 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_THREADS_H_ 17 | #define _PH_THREADS_H_ 18 | 19 | 20 | /* Mutex attributes */ 21 | 22 | 23 | #define PH_LOCK_NORMAL 0 24 | #define PH_LOCK_RECURSIVE 1 25 | #define PH_LOCK_ERRORCHECK 2 26 | 27 | 28 | struct lockAttr { 29 | int type; 30 | }; 31 | 32 | 33 | /* Condvar attributes */ 34 | 35 | 36 | struct condAttr { 37 | int clock; 38 | }; 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /hal/aarch64/arch/interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception and interrupt handling 7 | * 8 | * Copyright 2016, 2018, 2020, 2024 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Jacek Maksymowicz 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_AARCH64_INTERRUPTS_H_ 17 | #define _PH_HAL_AARCH64_INTERRUPTS_H_ 18 | 19 | #include "cpu.h" 20 | 21 | typedef struct _intr_handler_t { 22 | struct _intr_handler_t *next; 23 | struct _intr_handler_t *prev; 24 | unsigned int n; 25 | intrFn_t f; 26 | void *data; 27 | } intr_handler_t; 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /hal/armv8m/nrf/91/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for nRF9160 7 | * 8 | * Copyright 2021, 2022 Phoenix Systems 9 | * Author: Hubert Buczynski, Damian Loewnau 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | #include "include/arch/armv8m/nrf/syspage.h" 23 | #include "nrf91.h" 24 | 25 | /* Based on INTLINESNUM value (ICTR cpu register) */ 26 | #define SIZE_INTERRUPTS 256 27 | 28 | #define HAL_NAME_PLATFORM "NRF91 " 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /hal/sparcv8leon/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (sparcv8leon HAL) 3 | # 4 | # Copyright 2022 Phoenix Systems 5 | # 6 | 7 | include hal/$(TARGET_SUFF)/gaisler/Makefile 8 | include hal/gaisler/Makefile 9 | 10 | CFLAGS := -Ihal/$(TARGET_SUFF) $(CFLAGS) 11 | 12 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/, cpu.o hal.o spinlock.o string.o _traps.o) 13 | 14 | ifeq ($(findstring -DNOMMU,$(CPPFLAGS)),-DNOMMU) 15 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/, exceptions-nommu.o pmap-nommu.o _interrupts-nommu.o) 16 | else 17 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/, exceptions.o pmap.o srmmu.o tlb.o _interrupts.o) 18 | endif 19 | -------------------------------------------------------------------------------- /hal/sparcv8leon/arch/interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Interrupt handling 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_LEON3_INTERRUPTS_H_ 17 | #define _PH_HAL_LEON3_INTERRUPTS_H_ 18 | 19 | #include "cpu.h" 20 | 21 | typedef struct _intr_handler_t { 22 | struct _intr_handler_t *next; 23 | struct _intr_handler_t *prev; 24 | unsigned int n; 25 | intrFn_t f; 26 | void *data; 27 | #ifdef NOMMU 28 | void *got; 29 | #endif 30 | } intr_handler_t; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /hal/armv7a/imx6ull/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for i.MX 6ULL 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | #define ADDR_DDR 0x80000000 20 | #define SIZE_DDR 0x7ffffff 21 | 22 | #define NUM_CPUS 1 23 | 24 | #ifndef __ASSEMBLY__ 25 | 26 | #define HAL_NAME_PLATFORM "NXP i.MX 6ULL " 27 | 28 | #include "include/arch/armv7a/imx6ull/syspage.h" 29 | #include "include/syspage.h" 30 | 31 | #endif 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /hal/armv7r/zynqmp/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for ZynqMP 7 | * 8 | * Copyright 2021, 2025 Phoenix Systems 9 | * Author: Hubert Buczynski, Jacek Maksymowicz 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | 20 | #define NUM_CPUS 1 21 | #define SIZE_INTERRUPTS 188U 22 | 23 | #ifndef __ASSEMBLY__ 24 | 25 | #define HAL_NAME_PLATFORM "Xilinx Zynq Ultrascale+ " 26 | 27 | #include "include/arch/armv7r/zynqmp/syspage.h" 28 | #include "include/syspage.h" 29 | 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /test/vm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Tests for VM subsystem 7 | * 8 | * Copyright 2012, 2016 Phoenix Systems 9 | * Copyright 2005-2006 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _TEST_VM_H_ 18 | #define _TEST_VM_H_ 19 | 20 | struct _vm_map_t; 21 | 22 | 23 | struct _vm_object_t; 24 | 25 | 26 | void test_vm_alloc(void); 27 | 28 | 29 | void test_vm_mmap(void); 30 | 31 | 32 | void test_vm_zalloc(void); 33 | 34 | 35 | void test_vm_kmalloc(void); 36 | 37 | 38 | void test_vm_kmallocsim(void); 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /hal/aarch64/arch/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Spinlock 7 | * 8 | * Copyright 2014, 2017, 2024 Phoenix Systems 9 | * Author: Jacek Popko, Pawel Pisarczyk, Aleksander Kaminski, Jacek Maksymowicz 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_AARCH64_SPINLOCK_H_ 17 | #define _PH_HAL_AARCH64_SPINLOCK_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | typedef struct _spinlock_t { 22 | u8 lock; 23 | const char *name; 24 | struct _spinlock_t *next; 25 | struct _spinlock_t *prev; 26 | } spinlock_t; 27 | 28 | 29 | typedef u32 spinlock_ctx_t; 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /hal/armv7a/arch/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Spinlock 7 | * 8 | * Copyright 2014, 2017 Phoenix Systems 9 | * Author: Jacek Popko, Pawel Pisarczyk, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV7A_SPINLOCK_H_ 17 | #define _PH_HAL_ARMV7A_SPINLOCK_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | typedef struct _spinlock_t { 22 | const char *name; 23 | struct _spinlock_t *next; 24 | struct _spinlock_t *prev; 25 | 26 | u8 lock; 27 | } __attribute__((packed)) spinlock_t; 28 | 29 | 30 | typedef u32 spinlock_ctx_t; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /hal/armv7r/arch/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Spinlock 7 | * 8 | * Copyright 2014, 2017, 2024 Phoenix Systems 9 | * Author: Jacek Popko, Pawel Pisarczyk, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV7R_SPINLOCK_H_ 17 | #define _PH_HAL_ARMV7R_SPINLOCK_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | typedef struct _spinlock_t { 22 | const char *name; 23 | struct _spinlock_t *next; 24 | struct _spinlock_t *prev; 25 | u8 lock; 26 | } __attribute__((packed)) spinlock_t; 27 | 28 | 29 | typedef u32 spinlock_ctx_t; 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /hal/armv8r/arch/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Spinlock 7 | * 8 | * Copyright 2014, 2017, 2024 Phoenix Systems 9 | * Author: Jacek Popko, Pawel Pisarczyk, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV8R_SPINLOCK_H_ 17 | #define _PH_HAL_ARMV8R_SPINLOCK_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | typedef struct _spinlock_t { 22 | const char *name; 23 | struct _spinlock_t *next; 24 | struct _spinlock_t *prev; 25 | 26 | u8 lock; 27 | } __attribute__((packed)) spinlock_t; 28 | 29 | 30 | typedef u32 spinlock_ctx_t; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/gaisler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Gaisler CPU specific functions 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_GAISLER_H_ 17 | #define _PH_GAISLER_H_ 18 | 19 | #include 20 | #include "hal/types.h" 21 | 22 | 23 | int gaisler_setIomuxCfg(u8 pin, u8 opt, u8 pullup, u8 pulldn); 24 | 25 | 26 | void gaisler_cpuHalt(void); 27 | 28 | 29 | void hal_cpuStartCores(void); 30 | 31 | 32 | __attribute__((noreturn)) void hal_timerWdogReboot(void); 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /hal/interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception and interrupt handling 7 | * 8 | * Copyright 2016, 2018, 2020 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_INTERRUPTS_H_ 17 | #define _PH_HAL_INTERRUPTS_H_ 18 | 19 | #include 20 | 21 | 22 | int hal_interruptsSetHandler(intr_handler_t *h); 23 | 24 | 25 | int hal_interruptsDeleteHandler(intr_handler_t *h); 26 | 27 | 28 | char *hal_interruptsFeatures(char *features, unsigned int len); 29 | 30 | 31 | void _hal_interruptsInit(void); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /proc/proc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Processes management 7 | * 8 | * Copyright 2012-2015, 2017 Phoenix Systems 9 | * Copyright 2001, 2006-2007 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #include "hal/hal.h" 18 | #include "include/errno.h" 19 | #include "proc.h" 20 | 21 | 22 | int _proc_init(vm_map_t *kmap, vm_object_t *kernel) 23 | { 24 | (void)_threads_init(kmap, kernel); 25 | (void)_process_init(kmap, kernel); 26 | _port_init(); 27 | _msg_init(kmap, kernel); 28 | _name_init(); 29 | _userintr_init(); 30 | 31 | return EOK; 32 | } 33 | -------------------------------------------------------------------------------- /hal/aarch64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (AArch64 HAL) 3 | # 4 | # Copyright 2018, 2020, 2021, 2024 Phoenix Systems 5 | # 6 | 7 | # Note: _init.o must be first in the list 8 | OBJS += $(addprefix $(PREFIX_O)hal/aarch64/, _init.o cache.o cpu.o dtb.o hal.o exceptions.o pmap.o spinlock.o string.o _memcpy.o _memset.o) 9 | 10 | CFLAGS += -mcpu=$(cpu)+nofp -Ihal/aarch64 11 | ifneq (, $(findstring zynqmp, $(TARGET_SUBFAMILY))) 12 | include hal/aarch64/zynqmp/Makefile 13 | CFLAGS += -Ihal/aarch64/zynqmp 14 | OBJS += $(addprefix $(PREFIX_O)hal/aarch64/, interrupts_gicv2.o) 15 | endif 16 | 17 | $(PREFIX_O)hal/aarch64/_init.o: hal/aarch64/_exceptions.S hal/aarch64/_init.S 18 | -------------------------------------------------------------------------------- /hal/arm/barriers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * ARM barriers 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARM_BARRIERS_H_ 17 | #define _PH_HAL_ARM_BARRIERS_H_ 18 | 19 | 20 | static inline void hal_cpuDataMemoryBarrier(void) 21 | { 22 | __asm__ volatile ("dmb"); 23 | } 24 | 25 | 26 | static inline void hal_cpuDataSyncBarrier(void) 27 | { 28 | __asm__ volatile ("dsb"); 29 | } 30 | 31 | 32 | static inline void hal_cpuInstrBarrier(void) 33 | { 34 | __asm__ volatile ("isb"); 35 | } 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /hal/ia32/pci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * PCI driver 7 | * 8 | * Copyright 2019, 2020, 2024 Phoenix Systems 9 | * Author: Kamil Amanowicz, Lukasz Kosinski, Adam Greloch 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_PCI_H_ 17 | #define _PH_HAL_PCI_H_ 18 | 19 | #include "include/arch/ia32/ia32.h" 20 | 21 | 22 | int hal_pciSetUsbOwnership(pci_usbownership_t *usbownership); 23 | 24 | 25 | int hal_pciGetDevice(pci_id_t *id, pci_dev_t *dev, void *caps); 26 | 27 | 28 | int hal_pciSetConfigOption(pci_pcicfg_t *pcicfg); 29 | 30 | 31 | void _hal_pciInit(void); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /hal/riscv64/arch/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Spinlock 7 | * 8 | * Copyright 2012, 2018, 2020, 2024 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_RISCV64_SPINLOCK_H_ 17 | #define _PH_HAL_RISCV64_SPINLOCK_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | 22 | typedef u64 spinlock_ctx_t; 23 | 24 | typedef struct _spinlock_t { 25 | const char *name; 26 | struct _spinlock_t *next; 27 | struct _spinlock_t *prev; 28 | 29 | u32 lock; 30 | } __attribute__((packed, aligned(8))) spinlock_t; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /hal/armv7a/zynq7000/zynq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL internal functions for zynq7000 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Maciej Purski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ZYNQ_H_ 17 | #define _PH_HAL_ZYNQ_H_ 18 | 19 | #include "hal/cpu.h" 20 | 21 | 22 | int _zynq_setMIO(unsigned int pin, char disableRcvr, char pullup, char ioType, char speed, char l0, char l1, char l2, char l3, char triEnable); 23 | 24 | 25 | int _zynq_setAmbaClk(u32 dev, u32 state); 26 | 27 | 28 | void _zynq_interrupts_setCPU(unsigned int irqn, u32 cpuID); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /hal/ia32/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for phoenix-rtos-kernel/hal/ia32 3 | # 4 | # Copyright 2017, 2020 Phoenix Systems 5 | # Author: Pawel Pisarczyk 6 | # 7 | 8 | include hal/tlb/Makefile 9 | 10 | OBJS += $(addprefix $(PREFIX_O)hal/ia32/, _init.o _exceptions.o _interrupts.o spinlock.o exceptions.o interrupts.o cpu.o pmap.o timer.o hal.o string.o pci.o init.o console.o) 11 | CFLAGS += -Ihal/ia32 12 | 13 | ifneq ($(findstring serial,$(CONSOLE)),) 14 | OBJS += $(PREFIX_O)hal/$(TARGET_SUFF)/console-serial.o 15 | CPPFLAGS += -DHAL_CONSOLE_SERIAL 16 | endif 17 | 18 | ifneq ($(findstring vga,$(CONSOLE)),) 19 | OBJS += $(PREFIX_O)hal/$(TARGET_SUFF)/console-vga.o 20 | CPPFLAGS += -DHAL_CONSOLE_VGA 21 | endif 22 | -------------------------------------------------------------------------------- /hal/sparcv8leon/arch/tlb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * TLB handling 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Andrzej Stalke, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #ifndef _PH_HAL_LEON3_TLB_H_ 18 | #define _PH_HAL_LEON3_TLB_H_ 19 | 20 | #include "cpu.h" 21 | #include "pmap.h" 22 | #include "hal/tlb/tlb.h" 23 | 24 | 25 | void hal_tlbFlushLocal(const pmap_t *pmap); 26 | 27 | 28 | void hal_tlbInvalidateLocalEntry(const pmap_t *pmap, const void *vaddr); 29 | 30 | 31 | int hal_tlbIrqHandler(unsigned int n, cpu_context_t *ctx, void *arg); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/posix-stdio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * POSIX-compatibility definitions - stdio 7 | * 8 | * Copyright 2018, 2024 Phoenix Systems 9 | * Author: Jan Sikorski, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_POSIX_STDIO_H_ 17 | #define _PH_POSIX_STDIO_H_ 18 | 19 | 20 | #ifndef SEEK_SET 21 | #define SEEK_SET 0 /* Seek relative to start of file */ 22 | #endif 23 | 24 | #ifndef SEEK_CUR 25 | #define SEEK_CUR 1 /* Seek relative to current position */ 26 | #endif 27 | 28 | #ifndef SEEK_END 29 | #define SEEK_END 2 /* Seek relative to end of file */ 30 | #endif 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /test/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Test subsystem 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Author: Adrian Kepka 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | /* parasoft-begin-suppress ALL "tests don't need to comply with MISRA" */ 17 | 18 | #include "test.h" 19 | 20 | #include "vm.h" 21 | #include "proc.h" 22 | #include "rb.h" 23 | #include "msg.h" 24 | 25 | 26 | void test_run(void) 27 | { 28 | test_proc_threads1(); 29 | // test_vm_alloc(); 30 | // test_vm_kmalloc(); 31 | // test_rb(); 32 | // test_msg(); 33 | } 34 | 35 | /* parasoft-end-suppress ALL "tests don't need to comply with MISRA" */ 36 | -------------------------------------------------------------------------------- /hal/armv8r/arch/exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception handling (ARMv8r) 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV8R_EXCEPTIONS_H_ 17 | #define _PH_HAL_ARMV8R_EXCEPTIONS_H_ 18 | 19 | #include "cpu.h" 20 | 21 | #define EXC_DEFAULT 128 22 | 23 | #define EXC_UNDEFINED 3 24 | 25 | #define SIZE_CTXDUMP 512 /* Size of dumped context */ 26 | 27 | typedef struct _exc_context_t { 28 | u32 dfsr; 29 | u32 dfar; 30 | u32 ifsr; 31 | u32 ifar; 32 | 33 | cpu_context_t cpuCtx; 34 | } exc_context_t; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/arch/ia32/stdtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exact-width integer types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_IA32_STDTYPES_H_ 17 | #define _PH_ARCH_IA32_STDTYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | typedef unsigned char __u8; 24 | typedef unsigned short __u16; 25 | typedef unsigned int __u32; 26 | typedef unsigned long long __u64; 27 | 28 | typedef char __s8; 29 | typedef short __s16; 30 | typedef int __s32; 31 | typedef long long __s64; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /hal/armv7r/arch/exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception handling (ARMv7r) 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV7R_EXCEPTIONS_H_ 17 | #define _PH_HAL_ARMV7R_EXCEPTIONS_H_ 18 | 19 | #include "cpu.h" 20 | 21 | #define EXC_DEFAULT 128U 22 | 23 | #define EXC_UNDEFINED 3U 24 | 25 | #define SIZE_CTXDUMP 512U /* Size of dumped context */ 26 | 27 | typedef struct _exc_context_t { 28 | u32 dfsr; 29 | u32 dfar; 30 | u32 ifsr; 31 | u32 ifar; 32 | 33 | cpu_context_t cpuCtx; 34 | } exc_context_t; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /hal/ia32/arch/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * CPU related routines 7 | * 8 | * Copyright 2012, 2017, 2024 Phoenix Systems 9 | * Copyright 2001, 2006 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk, Lukasz Leczkowski 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_HAL_IA32_TYPES_H_ 18 | #define _PH_HAL_IA32_TYPES_H_ 19 | 20 | 21 | #include "include/types.h" 22 | 23 | 24 | #ifndef __ASSEMBLY__ 25 | 26 | 27 | typedef __u8 ld80[10]; /* Long double as bytes */ 28 | 29 | typedef __u64 cycles_t; 30 | typedef __u32 ptr_t; 31 | 32 | typedef unsigned long size_t; 33 | 34 | 35 | #endif 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/l2cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system loader 5 | * 6 | * L2 cache management 7 | * 8 | * Copyright 2025 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_L2CACHE_H_ 17 | #define _PH_L2CACHE_H_ 18 | 19 | 20 | #include 21 | 22 | 23 | /* clang-format off */ 24 | enum { l2c_inv_line = 1, l2c_flush_line, l2c_flush_inv_line, l2c_inv_all = 5, l2c_flush_all, l2c_flush_inv_all }; 25 | /* clang-format on */ 26 | 27 | 28 | void l2c_flushRange(unsigned int mode, addr_t start, size_t size); 29 | 30 | 31 | void l2c_init(addr_t base); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/arch/riscv64/stdtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exact-width integer types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_RISCV64_STDTYPES_H_ 17 | #define _PH_ARCH_RISCV64_STDTYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | typedef unsigned char __u8; 24 | typedef unsigned short __u16; 25 | typedef unsigned int __u32; 26 | typedef unsigned long __u64; 27 | 28 | typedef signed char __s8; 29 | typedef short __s16; 30 | typedef int __s32; 31 | typedef long __s64; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /hal/ia32/arch/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Spinlock 7 | * 8 | * Copyright 2012 Phoenix Systems 9 | * Copyright 2001, 2005 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_HAL_IA32_SPINLOCK_H_ 18 | #define _PH_HAL_IA32_SPINLOCK_H_ 19 | 20 | #include "hal/types.h" 21 | 22 | typedef u32 spinlock_ctx_t; 23 | 24 | typedef struct _spinlock_t { 25 | const char *name; 26 | cycles_t b; 27 | cycles_t e; 28 | cycles_t dmin; 29 | cycles_t dmax; 30 | struct _spinlock_t *next; 31 | struct _spinlock_t *prev; 32 | 33 | u32 lock; 34 | } spinlock_t; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/gr716/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for sparcv8leon-gr716 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "gr716.h" 24 | 25 | #include "include/arch/sparcv8leon/syspage.h" 26 | #include "include/syspage.h" 27 | 28 | #define HAL_NAME_PLATFORM "SPARCv8 LEON3-GR716" 29 | 30 | 31 | #endif /* __ASSEMBLY__ */ 32 | 33 | 34 | #define NWINDOWS 31 35 | #define NUM_CPUS 1 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/arch/armv7m/stdtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exact-width integer types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_ARMV7M_STDTYPES_H_ 17 | #define _PH_ARCH_ARMV7M_STDTYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | typedef unsigned char __u8; 24 | typedef unsigned short __u16; 25 | typedef unsigned int __u32; 26 | typedef unsigned long long __u64; 27 | 28 | typedef signed char __s8; 29 | typedef short __s16; 30 | typedef int __s32; 31 | typedef long long __s64; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/arch/armv8m/stdtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exact-width integer types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_ARMV8M_STDTYPES_H_ 17 | #define _PH_ARCH_ARMV8M_STDTYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | typedef unsigned char __u8; 24 | typedef unsigned short __u16; 25 | typedef unsigned int __u32; 26 | typedef unsigned long long __u64; 27 | 28 | typedef signed char __s8; 29 | typedef short __s16; 30 | typedef int __s32; 31 | typedef long long __s64; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /hal/armv8m/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv8M HAL) 3 | # 4 | # Copyright 2022 Phoenix Systems 5 | # 6 | 7 | 8 | ifneq (, $(findstring nrf, $(TARGET_SUBFAMILY))) 9 | include hal/armv8m/nrf/Makefile 10 | CFLAGS += -Ihal/armv8m 11 | else ifneq (, $(findstring mcx, $(TARGET_SUBFAMILY))) 12 | include hal/armv8m/mcx/Makefile 13 | CFLAGS += -Ihal/armv8m 14 | else ifneq (, $(findstring stm32, $(TARGET_SUBFAMILY))) 15 | include hal/armv8m/stm32/Makefile 16 | CFLAGS += -Ihal/armv8m 17 | endif 18 | 19 | include hal/arm/Makefile 20 | CFLAGS += -Ihal/arm 21 | 22 | OBJS += $(addprefix $(PREFIX_O)hal/armv8m/, string.o spinlock.o cpu.o hal.o \ 23 | pmap.o exceptions.o _memcpy.o _memset.o interrupts.o) 24 | -------------------------------------------------------------------------------- /hal/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * System timer driver 7 | * 8 | * Copyright 2018, 2021 Phoenix Systems 9 | * Author: Aleksander Kaminski, Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_TIMER_H_ 17 | #define _PH_HAL_TIMER_H_ 18 | 19 | 20 | #include "cpu.h" 21 | #include "interrupts.h" 22 | 23 | time_t hal_timerGetUs(void); 24 | 25 | 26 | void hal_timerSetWakeup(u32 waitUs); 27 | 28 | 29 | int hal_timerRegister(intrFn_t f, void *data, intr_handler_t *h); 30 | 31 | 32 | void _hal_timerInit(u32 interval); 33 | 34 | 35 | char *hal_timerFeatures(char *features, unsigned int len); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/arch/aarch64/stdtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exact-width integer types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_AARCH64_STDTYPES_H_ 17 | #define _PH_ARCH_AARCH64_STDTYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | typedef unsigned char __u8; 24 | typedef unsigned short int __u16; 25 | typedef unsigned int __u32; 26 | typedef unsigned long int __u64; 27 | 28 | typedef signed char __s8; 29 | typedef short int __s16; 30 | typedef int __s32; 31 | typedef long int __s64; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /vm/vm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Virtual memory manager 7 | * 8 | * Copyright 2012 Phoenix Systems 9 | * Copyright 2001, 2005 Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_VM_VM_H_ 17 | #define _PH_VM_VM_H_ 18 | 19 | #include "hal/hal.h" 20 | #include "include/sysinfo.h" 21 | #include "page.h" 22 | #include "map.h" 23 | #include "zone.h" 24 | #include "kmalloc.h" 25 | #include "object.h" 26 | #include "amap.h" 27 | 28 | 29 | void vm_meminfo(meminfo_t *info); 30 | 31 | 32 | /* Function initializes virtual memory manager */ 33 | void _vm_init(vm_map_t *kmap, vm_object_t *kernel); 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/arch/armv7a/stdtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exact-width integer types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_ARMV7A_STDTYPES_H_ 17 | #define _PH_ARCH_ARMV7A_STDTYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | typedef unsigned char __u8; 24 | typedef unsigned short int __u16; 25 | typedef unsigned int __u32; 26 | typedef unsigned long long int __u64; 27 | 28 | typedef signed char __s8; 29 | typedef short int __s16; 30 | typedef int __s32; 31 | typedef long long int __s64; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/arch/armv7r/stdtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exact-width integer types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_ARMV7R_STDTYPES_H_ 17 | #define _PH_ARCH_ARMV7R_STDTYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | typedef unsigned char __u8; 24 | typedef unsigned short int __u16; 25 | typedef unsigned int __u32; 26 | typedef unsigned long long int __u64; 27 | 28 | typedef signed char __s8; 29 | typedef short int __s16; 30 | typedef int __s32; 31 | typedef long long int __s64; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/arch/armv8r/stdtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exact-width integer types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_ARMV8R_STDTYPES_H_ 17 | #define _PH_ARCH_ARMV8R_STDTYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | typedef unsigned char __u8; 24 | typedef unsigned short int __u16; 25 | typedef unsigned int __u32; 26 | typedef unsigned long long int __u64; 27 | 28 | typedef signed char __s8; 29 | typedef short int __s16; 30 | typedef int __s32; 31 | typedef long long int __s64; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/arch/sparcv8leon/sparcv8leon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * SPARC V8 LEON basic peripherals control functions 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_SPARCV8LEON_H_ 17 | #define _PH_ARCH_SPARCV8LEON_H_ 18 | 19 | 20 | #if defined(__CPU_GR716) 21 | #include "gr716/gr716.h" 22 | #elif defined(__CPU_GR712RC) 23 | #include "gr712rc/gr712rc.h" 24 | #elif defined(__CPU_GENERIC) 25 | #include "generic/generic.h" 26 | #elif defined(__CPU_GR740) 27 | #include "gr740/gr740.h" 28 | #else 29 | #error "Unsupported TARGET" 30 | #endif 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/arch/sparcv8leon/stdtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exact-width integer types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_LEON3_STDTYPES_H_ 17 | #define _PH_ARCH_LEON3_STDTYPES_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | typedef unsigned char __u8; 24 | typedef unsigned short __u16; 25 | typedef unsigned int __u32; 26 | typedef unsigned long long __u64; 27 | 28 | typedef signed char __s8; 29 | typedef signed short __s16; 30 | typedef signed int __s32; 31 | typedef signed long long __s64; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/posix-types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * POSIX-compatibility definitions - types 7 | * 8 | * Copyright 2018, 2024 Phoenix Systems 9 | * Author: Jan Sikorski, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_POSIX_TYPES_H_ 17 | #define _PH_POSIX_TYPES_H_ 18 | 19 | 20 | typedef int pid_t; 21 | typedef unsigned int mode_t; 22 | typedef int gid_t; 23 | typedef int uid_t; 24 | 25 | typedef int dev_t; 26 | typedef unsigned long long ino_t; 27 | typedef int nlink_t; 28 | typedef int blksize_t; 29 | typedef long long blkcnt_t; 30 | typedef unsigned long long fsblkcnt_t; 31 | typedef unsigned long long fsfilcnt_t; 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /hal/armv7a/arch/exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception handling 7 | * 8 | * Copyright 2017, 2018 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Jakub Sejdak, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV7A_EXCEPTIONS_H_ 17 | #define _PH_HAL_ARMV7A_EXCEPTIONS_H_ 18 | 19 | #include "cpu.h" 20 | 21 | #define EXC_DEFAULT 128 22 | 23 | #define EXC_UNDEFINED 1 24 | #define EXC_PAGEFAULT 4 25 | 26 | #define SIZE_CTXDUMP 512 /* Size of dumped context */ 27 | 28 | 29 | typedef struct _exc_context_t { 30 | u32 dfsr; 31 | u32 dfar; 32 | u32 ifsr; 33 | u32 ifar; 34 | 35 | cpu_context_t cpuCtx; 36 | } exc_context_t; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /hal/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Spinlock 7 | * 8 | * Copyright 2014, 2017 Phoenix Systems 9 | * Author: Jacek Popko, Pawel Pisarczyk, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_SPINLOCK_H_ 17 | #define _PH_HAL_SPINLOCK_H_ 18 | 19 | #include 20 | 21 | 22 | void hal_spinlockSet(spinlock_t *spinlock, spinlock_ctx_t *sc); 23 | 24 | 25 | void hal_spinlockClear(spinlock_t *spinlock, spinlock_ctx_t *sc); 26 | 27 | 28 | void hal_spinlockCreate(spinlock_t *spinlock, const char *name); 29 | 30 | 31 | void hal_spinlockDestroy(spinlock_t *spinlock); 32 | 33 | 34 | void _hal_spinlockInit(void); 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/arch/armv8r/mps3an536/mps3an536.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * MPS3 AN536 basic peripherals control functions 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_MPS3AN536_H_ 17 | #define _PH_ARCH_MPS3AN536_H_ 18 | 19 | 20 | #define PCTL_REBOOT_MAGIC 0xaa55aa55UL 21 | 22 | 23 | typedef struct { 24 | /* clang-format off */ 25 | enum { pctl_set = 0, pctl_get } action; 26 | enum { pctl_reboot = 0 } type; 27 | /* clang-format on */ 28 | 29 | union { 30 | struct { 31 | unsigned int magic; 32 | } reboot; 33 | } task; 34 | } __attribute__((packed)) platformctl_t; 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /proc/proc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Processes management 7 | * 8 | * Copyright 2012-2015, 2017 Phoenix Systems 9 | * Copyright 2001, 2006-2007 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk, Pawel Kolodziej, Jacek Popko 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_PROC_PROC_H_ 18 | #define _PH_PROC_PROC_H_ 19 | 20 | #include "hal/hal.h" 21 | #include "threads.h" 22 | #include "process.h" 23 | #include "lock.h" 24 | #include "msg.h" 25 | #include "name.h" 26 | #include "resource.h" 27 | #include "mutex.h" 28 | #include "cond.h" 29 | #include "userintr.h" 30 | #include "ports.h" 31 | 32 | 33 | int _proc_init(vm_map_t *kmap, vm_object_t *kernel); 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/arch/armv8m/nrf/syspage.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Phoenix-RTOS 4 | * 5 | * Operating system kernel 6 | * 7 | * HAL syspage for NRF91 boards 8 | * 9 | * Copyright 2021, 2022 Phoenix Systems 10 | * Authors: Hubert Buczynski, Damian Loewnau 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_SYSPAGE_NRF91_H_ 18 | #define _PH_SYSPAGE_NRF91_H_ 19 | 20 | 21 | typedef struct { 22 | struct { 23 | unsigned int type; 24 | unsigned int allocCnt; 25 | struct { 26 | unsigned int rbar; 27 | unsigned int rlar; 28 | } table[16] __attribute__((aligned(8))); 29 | unsigned int map[16]; /* ((unsigned int)-1) = map is not assigned */ 30 | } __attribute__((packed)) mpu; 31 | } __attribute__((packed)) hal_syspage_t; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /hal/armv7m/arch/interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Interrupt handling 7 | * 8 | * Copyright 2016, 2017, 2020 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Artur Wodejko, Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #ifndef _PH_HAL_ARMV7M_INTERRUPTS_H_ 18 | #define _PH_HAL_ARMV7M_INTERRUPTS_H_ 19 | 20 | #include "cpu.h" 21 | #include "hal/arm/scs.h" 22 | 23 | #define SVC_IRQ 11 24 | #define PENDSV_IRQ 14 25 | #define SYSTICK_IRQ 15 26 | 27 | typedef struct _intr_handler_t { 28 | struct _intr_handler_t *next; 29 | struct _intr_handler_t *prev; 30 | unsigned int n; 31 | intrFn_t f; 32 | void *data; 33 | void *got; 34 | } intr_handler_t; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/generic/generic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL internal functions for sparcv8leon-generic 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_GENERIC_H_ 17 | #define _PH_HAL_GENERIC_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "hal/types.h" 24 | #include 25 | 26 | #include "hal/gaisler/ambapp.h" 27 | 28 | #include "include/arch/sparcv8leon/generic/generic.h" 29 | 30 | 31 | int gaisler_setIomuxCfg(u8 pin, u8 opt, u8 pullup, u8 pulldn); 32 | 33 | 34 | int hal_platformctl(void *ptr); 35 | 36 | 37 | #endif /* __ASSEMBLY__ */ 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /include/arch/armv7m/stm32/syspage.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Phoenix-RTOS 4 | * 5 | * Operating system kernel 6 | * 7 | * HAL syspage for STM32 boards 8 | * 9 | * Copyright 2021 Phoenix Systems 10 | * Authors: Hubert Buczynski 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_SYSPAGE_STM32_H_ 18 | #define _PH_SYSPAGE_STM32_H_ 19 | 20 | 21 | typedef struct { 22 | struct { 23 | unsigned int type; 24 | unsigned int allocCnt; 25 | struct { 26 | unsigned int rbar; 27 | unsigned int rasr; 28 | } table[16] __attribute__((aligned(8))); 29 | unsigned int map[16]; /* ((unsigned int)-1) = map is not assigned */ 30 | } __attribute__((packed)) mpu; 31 | unsigned int bootReason; 32 | } __attribute__((packed)) hal_syspage_t; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/arch/armv7r/tda4vm/syspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL syspage for TDA4VM 7 | * 8 | * Copyright 2025 Phoenix Systems 9 | * Authors: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_SYSPAGE_ARMV7R_TDA4VM_H_ 17 | #define _PH_SYSPAGE_ARMV7R_TDA4VM_H_ 18 | 19 | 20 | typedef struct { 21 | int resetReason; 22 | struct { 23 | unsigned int type; 24 | unsigned int allocCnt; 25 | struct { 26 | unsigned int rbar; 27 | unsigned int rasr; 28 | } table[16] __attribute__((aligned(8))); 29 | unsigned int map[16]; /* ((unsigned int)-1) = map is not assigned */ 30 | } __attribute__((packed)) mpu; 31 | } __attribute__((packed)) hal_syspage_t; 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/arch/armv7r/zynqmp/syspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL syspage for ZynqMP 7 | * 8 | * Copyright 2025 Phoenix Systems 9 | * Authors: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_SYSPAGE_ARMV7R_ZYNQMP_H_ 17 | #define _PH_SYSPAGE_ARMV7R_ZYNQMP_H_ 18 | 19 | 20 | typedef struct { 21 | int resetReason; 22 | struct { 23 | unsigned int type; 24 | unsigned int allocCnt; 25 | struct { 26 | unsigned int rbar; 27 | unsigned int rasr; 28 | } table[16] __attribute__((aligned(8))); 29 | unsigned int map[16]; /* ((unsigned int)-1) = map is not assigned */ 30 | } __attribute__((packed)) mpu; 31 | } __attribute__((packed)) hal_syspage_t; 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /proc/mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Mutexes 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_PROC_MUTEX_H_ 17 | #define _PH_PROC_MUTEX_H_ 18 | 19 | #include "include/threads.h" 20 | #include "resource.h" 21 | 22 | 23 | typedef struct _mutex_t { 24 | resource_t resource; 25 | lock_t lock; 26 | } mutex_t; 27 | 28 | 29 | mutex_t *mutex_get(int h); 30 | 31 | 32 | void mutex_put(mutex_t *mutex); 33 | 34 | 35 | int proc_mutexLock(int h); 36 | 37 | 38 | int proc_mutexTry(int h); 39 | 40 | 41 | int proc_mutexUnlock(int h); 42 | 43 | 44 | int proc_mutexCreate(const struct lockAttr *attr); 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /hal/aarch64/zynqmp/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for ZynqMP 7 | * 8 | * Copyright 2021, 2024 Phoenix Systems 9 | * Author: Hubert Buczynski, Jacek Maksymowicz 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | 20 | /* On-Chip memory */ 21 | #define ADDR_OCRAM 0xfffc0000 22 | #define SIZE_OCRAM (256 * 1024) 23 | 24 | #define ASID_BITS 16 25 | #define NUM_CPUS 4 26 | #define SIZE_INTERRUPTS 188 27 | 28 | #ifndef __ASSEMBLY__ 29 | 30 | #define HAL_NAME_PLATFORM "Xilinx Zynq Ultrascale+ " 31 | 32 | #include "include/arch/aarch64/zynqmp/syspage.h" 33 | #include "include/syspage.h" 34 | 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/arch/armv8m/mcx/syspage.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Phoenix-RTOS 4 | * 5 | * Operating system kernel 6 | * 7 | * HAL syspage for MCXN94x 8 | * 9 | * Copyright 2021, 2022, 204 Phoenix Systems 10 | * Authors: Hubert Buczynski, Damian Loewnau, Aleksander Kaminski 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_SYSPAGE_MCXN94X_H_ 18 | #define _PH_SYSPAGE_MCXN94X_H_ 19 | 20 | 21 | typedef struct { 22 | struct { 23 | unsigned int type; 24 | unsigned int allocCnt; 25 | struct { 26 | unsigned int rbar; 27 | unsigned int rlar; 28 | } table[16] __attribute__((aligned(8))); 29 | unsigned int map[16]; /* ((unsigned int)-1) = map is not assigned */ 30 | } __attribute__((packed)) mpu; 31 | } __attribute__((packed)) hal_syspage_t; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/arch/armv7m/imxrt/syspage.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Phoenix-RTOS 4 | * 5 | * Operating system kernel 6 | * 7 | * HAL syspage for i.MX RT boards 8 | * 9 | * Copyright 2021 Phoenix Systems 10 | * Authors: Hubert Buczynski, Gerard Swiderski 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_SYSPAGE_IMXRT_H_ 18 | #define _PH_SYSPAGE_IMXRT_H_ 19 | 20 | 21 | typedef struct { 22 | struct { 23 | unsigned int type; 24 | unsigned int allocCnt; 25 | struct { 26 | unsigned int rbar; 27 | unsigned int rasr; 28 | } table[16] __attribute__((aligned(8))); 29 | unsigned int map[16]; /* ((unsigned int)-1) = map is not assigned */ 30 | } __attribute__((packed)) mpu; 31 | unsigned int bootReason; 32 | } __attribute__((packed)) hal_syspage_t; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /hal/ia32/console.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Consoles for ia32. 7 | * 8 | * Copyright 2025 Phoenix Systems 9 | * Author: Hubert Badocha 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_IA32_CONSOLE_H_ 17 | #define _PH_HAL_IA32_CONSOLE_H_ 18 | 19 | 20 | #ifdef HAL_CONSOLE_VGA 21 | 22 | 23 | void hal_consoleVGAPrint(int, const char *); 24 | 25 | 26 | void hal_consoleVGAPutch(char); 27 | 28 | 29 | void _hal_consoleVGAInit(void); 30 | 31 | 32 | #endif 33 | 34 | 35 | #ifdef HAL_CONSOLE_SERIAL 36 | 37 | 38 | void hal_consoleSerialPrint(int, const char *); 39 | 40 | 41 | void hal_consoleSerialPutch(char); 42 | 43 | 44 | void _hal_consoleSerialInit(void); 45 | 46 | 47 | #endif 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/generic/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for sparcv8leon-generic 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "generic.h" 24 | 25 | #include "include/arch/sparcv8leon/syspage.h" 26 | #include "include/syspage.h" 27 | 28 | #define HAL_NAME_PLATFORM "SPARCv8 LEON3-Generic" 29 | 30 | #define ADDR_RAM 0x40000000 31 | #define SIZE_RAM (128 * 1024 * 1024) /* 128 MB */ 32 | 33 | 34 | #endif /* __ASSEMBLY__ */ 35 | 36 | 37 | #define NWINDOWS 8 38 | #define NUM_CPUS 1 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/gr712rc/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for sparcv8leon-gr712rc 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "gr712rc.h" 24 | 25 | #include "include/arch/sparcv8leon/syspage.h" 26 | #include "include/syspage.h" 27 | 28 | #define HAL_NAME_PLATFORM "SPARCv8 LEON3-GR712RC" 29 | 30 | #define ADDR_RAM 0x40000000 31 | #define SIZE_RAM (128 * 1024 * 1024) /* 128 MB */ 32 | 33 | 34 | #endif /* __ASSEMBLY__ */ 35 | 36 | 37 | #define NWINDOWS 8 38 | #define NUM_CPUS 2 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/arch/armv8m/stm32/syspage.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Phoenix-RTOS 4 | * 5 | * Operating system kernel 6 | * 7 | * HAL syspage for STM32 boards 8 | * 9 | * Copyright 2021 Phoenix Systems 10 | * Authors: Hubert Buczynski 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_SYSPAGE_STM32_H_ 18 | #define _PH_SYSPAGE_STM32_H_ 19 | 20 | 21 | typedef struct { 22 | struct { 23 | unsigned int type; 24 | unsigned int allocCnt; 25 | unsigned int mair[2]; 26 | struct { 27 | unsigned int rbar; 28 | unsigned int rlar; 29 | } table[16] __attribute__((aligned(8))); 30 | unsigned int map[16]; /* ((unsigned int)-1) = map is not assigned */ 31 | } __attribute__((packed)) mpu; 32 | unsigned int bootReason; 33 | } __attribute__((packed)) hal_syspage_t; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /hal/sparcv8leon/arch/exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception handling 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_LEON3_EXCEPTIONS_H_ 17 | #define _PH_HAL_LEON3_EXCEPTIONS_H_ 18 | 19 | #include 20 | 21 | #define EXC_DEFAULT 128 22 | 23 | #define EXC_UNDEFINED 2 24 | 25 | #ifndef NOMMU 26 | #define EXC_PAGEFAULT 1 27 | #define EXC_PAGEFAULT_DATA 9 28 | #endif 29 | 30 | #define SIZE_CTXDUMP 550 31 | 32 | #pragma pack(push, 1) 33 | 34 | typedef struct _exc_context_t { 35 | /* special */ 36 | u32 wim; 37 | u32 tbr; 38 | 39 | cpu_context_t cpuCtx; 40 | } exc_context_t; 41 | 42 | #pragma pack(pop) 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /hal/tlb/tlb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * TLB handling 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Andrzej Stalke, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_TLB_H_ 17 | #define _PH_HAL_TLB_H_ 18 | 19 | 20 | #include 21 | 22 | 23 | /* To invalidate entire TLB set vaddr = NULL & count = 0. 24 | * Must be protected by pmap_common.lock */ 25 | void hal_tlbInvalidateEntry(const pmap_t *pmap, const void *vaddr, size_t count); 26 | 27 | 28 | /* Must be protected by pmap_common.lock */ 29 | void hal_tlbCommit(spinlock_t *spinlock, spinlock_ctx_t *ctx); 30 | 31 | 32 | void hal_tlbShootdown(void); 33 | 34 | 35 | void hal_tlbInitCore(const unsigned int id); 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /proc/cond.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Conditionals 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_PROC_COND_H_ 17 | #define _PH_PROC_COND_H_ 18 | 19 | #include "threads.h" 20 | #include "resource.h" 21 | 22 | 23 | typedef struct _cond_t { 24 | resource_t resource; 25 | thread_t *queue; 26 | struct condAttr attr; 27 | } cond_t; 28 | 29 | 30 | void cond_put(cond_t *cond); 31 | 32 | 33 | cond_t *cond_get(int c); 34 | 35 | 36 | int proc_condCreate(const struct condAttr *attr); 37 | 38 | 39 | int proc_condWait(int c, int m, time_t timeout); 40 | 41 | 42 | int proc_condSignal(int c); 43 | 44 | 45 | int proc_condBroadcast(int c); 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /hal/armv8m/arch/exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exceptions handling 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Damian Loewnau 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_ARMV8M_EXCEPTIONS_H_ 17 | #define _PH_HAL_ARMV8M_EXCEPTIONS_H_ 18 | 19 | #include "cpu.h" 20 | 21 | #define EXC_DEFAULT 128 22 | 23 | #define EXC_UNDEFINED 3 24 | 25 | #define SIZE_CTXDUMP 512 /* Size of dumped context */ 26 | 27 | 28 | typedef struct _exc_context_t { 29 | /* Saved by ISR */ 30 | u32 psp; 31 | u32 r4; 32 | u32 r5; 33 | u32 r6; 34 | u32 r7; 35 | u32 r8; 36 | u32 r9; 37 | u32 r10; 38 | u32 r11; 39 | u32 excret; 40 | 41 | /* Saved by hardware */ 42 | cpu_hwContext_t mspctx; 43 | } exc_context_t; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/posix-poll.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * POSIX-compatibility definitions - poll 7 | * 8 | * Copyright 2018, 2024 Phoenix Systems 9 | * Author: Jan Sikorski, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_POSIX_POLL_H_ 17 | #define _PH_POSIX_POLL_H_ 18 | 19 | 20 | #define POLLIN 0x1U 21 | #define POLLRDNORM 0x2U 22 | #define POLLRDBAND 0x4U 23 | #define POLLPRI 0x8U 24 | #define POLLOUT 0x10U 25 | #define POLLWRNORM 0x20U 26 | #define POLLWRBAND 0x40U 27 | #define POLLERR 0x80U 28 | #define POLLHUP 0x100U 29 | #define POLLNVAL 0x200U 30 | 31 | 32 | typedef unsigned int nfds_t; 33 | 34 | 35 | struct pollfd { 36 | int fd; 37 | short events; 38 | short revents; 39 | }; 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /hal/console.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL console 7 | * 8 | * Copyright 2012, 2016 Phoenix Systems 9 | * Copyright 2001, 2005 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_HAL_CONSOLE_H_ 18 | #define _PH_HAL_CONSOLE_H_ 19 | 20 | /* Console attributes */ 21 | #define ATTR_NORMAL 0x03 22 | #define ATTR_BOLD 0x0f 23 | #define ATTR_USER 0x07 24 | 25 | /* clang-format off */ 26 | #define CONSOLE_CYAN "\033" "[36m" 27 | #define CONSOLE_NORMAL "\033" "[0m" 28 | #define CONSOLE_BOLD "\033" "[1m" 29 | /* clang-format on */ 30 | 31 | 32 | void hal_consolePrint(int attr, const char *s); 33 | 34 | 35 | void hal_consolePutch(char c); 36 | 37 | 38 | void _hal_consoleInit(void); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /hal/aarch64/interrupts_gicv2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Interrupt handling for ARM GIC v1 or v2 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Jacek Maksymowicz 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_INTERRUPTS_GICV2_H_ 17 | #define _PH_INTERRUPTS_GICV2_H_ 18 | 19 | 20 | /* Type of interrupt's configuration */ 21 | enum { 22 | gicv2_cfg_reserved = 0, 23 | gicv2_cfg_high_level = 1, 24 | gicv2_cfg_rising_edge = 3, 25 | }; 26 | 27 | 28 | /* Returns one of gicv2_cfg_* for a given interrupt number. Must be implemented in platform-specific code. */ 29 | int _interrupts_gicv2_classify(unsigned int irqn); 30 | 31 | 32 | void interrupts_setCPU(unsigned int irqn, unsigned int cpuID); 33 | 34 | 35 | #endif /* _INTERRUPTS_GICV2_H_ */ 36 | -------------------------------------------------------------------------------- /hal/armv8m/arch/interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Interrupt handling 7 | * 8 | * Copyright 2016, 2017, 2020, 2022 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Artur Wodejko, Hubert Buczynski, Damian Loewnau 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #ifndef _PH_HAL_ARMV8M_INTERRUPTS_H_ 18 | #define _PH_HAL_ARMV8M_INTERRUPTS_H_ 19 | 20 | #include "cpu.h" 21 | #include "hal/arm/scs.h" 22 | 23 | #define SVC_IRQ 11 24 | #define PENDSV_IRQ 14 25 | #define SYSTICK_IRQ 15 26 | 27 | 28 | typedef struct _intr_handler_t { 29 | struct _intr_handler_t *next; 30 | struct _intr_handler_t *prev; 31 | /* irq */ 32 | unsigned int n; 33 | /* handler function */ 34 | intrFn_t f; 35 | void *data; 36 | void *got; 37 | } intr_handler_t; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/gr740/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for sparcv8leon-gr740 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "gr740.h" 24 | 25 | #include "include/arch/sparcv8leon/syspage.h" 26 | #include "include/syspage.h" 27 | 28 | #define HAL_NAME_PLATFORM "SPARCv8 LEON3-GR740" 29 | 30 | #define ADDR_RAM 0x00000000 31 | #define SIZE_RAM (128 * 1024 * 1024) /* 128 MB */ 32 | 33 | #define L2CACHE_CTRL_BASE ((void *)0xf0000000) 34 | 35 | #endif /* __ASSEMBLY__ */ 36 | 37 | 38 | #define NWINDOWS 8 39 | #define NUM_CPUS 4 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /hal/ia32/arch/exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception handling 7 | * 8 | * Copyright 2012 Phoenix Systems 9 | * Copyright 2001, 2005 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk, Jan Sikorski 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_HAL_IA32_EXCEPTIONS_H_ 18 | #define _PH_HAL_IA32_EXCEPTIONS_H_ 19 | 20 | #include "cpu.h" 21 | 22 | #define EXC_DEFAULT 128 23 | 24 | #define EXC_UNDEFINED 6 25 | #define EXC_PAGEFAULT 14 26 | 27 | #define SIZE_CTXDUMP 512 /* Size of dumped context */ 28 | 29 | 30 | #pragma pack(push, 1) 31 | 32 | typedef struct { 33 | u32 err; 34 | u32 dr0; 35 | u32 dr1; 36 | u32 dr2; 37 | u32 dr3; 38 | u32 dr6; 39 | u32 dr7; 40 | cpu_context_t cpuCtx; 41 | } exc_context_t; 42 | 43 | #pragma pack(pop) 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /hal/riscv64/arch/interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception and interrupt handling 7 | * 8 | * Copyright 2016, 2012, 2020, 2024 Phoenix Systems 9 | * Copyright 2001, 2005, 2006 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk, Lukasz Leczkowski 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_HAL_RISCV64_INTERRUPTS_H_ 18 | #define _PH_HAL_RISCV64_INTERRUPTS_H_ 19 | 20 | #include "cpu.h" 21 | 22 | 23 | #define TLB_IRQ (1U | CLINT_IRQ_FLG) 24 | #define SYSTICK_IRQ (5U | CLINT_IRQ_FLG) 25 | 26 | 27 | typedef struct _intr_handler_t { 28 | struct _intr_handler_t *next; 29 | struct _intr_handler_t *prev; 30 | unsigned int n; 31 | intrFn_t f; 32 | void *data; 33 | } intr_handler_t; 34 | 35 | 36 | void hal_interruptsInitCore(void); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /hal/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL - Basic types 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_TYPES_H_ 17 | #define _PH_HAL_TYPES_H_ 18 | 19 | 20 | #define NULL ((void *)0) 21 | 22 | 23 | #ifndef __ASSEMBLY__ 24 | 25 | 26 | #include "include/types.h" 27 | #include 28 | 29 | typedef __u8 u8; 30 | typedef __u16 u16; 31 | typedef __u32 u32; 32 | typedef __u64 u64; 33 | 34 | typedef __s8 s8; 35 | typedef __s16 s16; 36 | typedef __s32 s32; 37 | typedef __s64 s64; 38 | 39 | typedef void (*startFn_t)(void *arg); 40 | 41 | struct _cpu_context_t; 42 | 43 | typedef int (*intrFn_t)(unsigned int n, struct _cpu_context_t *ctx, void *arg); 44 | 45 | #endif 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lib/bsearch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Binary search 7 | * 8 | * Copyright 2012 Phoenix Systems 9 | * Author: Paweł Kołodziej 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | * 15 | */ 16 | 17 | #include "hal/hal.h" 18 | #include "bsearch.h" 19 | 20 | 21 | void *lib_bsearch(void *key, void *base, size_t nmemb, size_t size, int (*compar)(void *n1, void *n2)) 22 | { 23 | ssize_t l = 0, r = (ssize_t)nmemb - 1, m; 24 | int cmp; 25 | 26 | if (nmemb == 0U) { 27 | return NULL; 28 | } 29 | 30 | while (l <= r) { 31 | m = (l + r) / 2; 32 | 33 | cmp = compar(key, base + m * (ssize_t)size); 34 | 35 | if (cmp == 0) { 36 | return base + m * (ssize_t)size; 37 | } 38 | 39 | if (cmp > 0) { 40 | l = m + 1; 41 | } 42 | else { 43 | r = m - 1; 44 | } 45 | } 46 | return NULL; 47 | } 48 | -------------------------------------------------------------------------------- /posix/fdpass.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * File descriptor passing 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Ziemowit Leszczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_POSIX_FDPASS_H_ 17 | #define _PH_POSIX_FDPASS_H_ 18 | 19 | #include "posix_private.h" 20 | 21 | 22 | #define MAX_MSG_CONTROLLEN 256U 23 | 24 | 25 | /* NOTE: file descriptors are added & removed FIFO style */ 26 | typedef struct fdpack_s { 27 | struct fdpack_s *next, *prev; 28 | unsigned int first, cnt; 29 | fildes_t fd[]; 30 | } fdpack_t; 31 | 32 | 33 | int fdpass_pack(fdpack_t **packs, const void *control, socklen_t controllen); 34 | 35 | 36 | int fdpass_unpack(fdpack_t **packs, void *control, socklen_t *controllen); 37 | 38 | 39 | int fdpass_discard(fdpack_t **packs); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (SPARCV8 LEON3 HAL) 3 | # 4 | # Copyright 2023-2025 Phoenix Systems 5 | # 6 | # %LICENSE% 7 | # 8 | 9 | include hal/$(TARGET_SUFF)/gaisler/$(TARGET_SUBFAMILY)/Makefile 10 | 11 | CFLAGS := -Ihal/$(TARGET_SUFF)/gaisler/$(TARGET_SUBFAMILY) $(CFLAGS) 12 | 13 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/, console.o timer.o) 14 | 15 | ifeq ($(TARGET_SUBFAMILY), gr712rc) 16 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/, irqmp.o) 17 | else ifeq ($(TARGET_SUBFAMILY), gr716) 18 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/, irqamp.o) 19 | else ifeq ($(TARGET_SUBFAMILY), gr740) 20 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/, irqamp.o l2cache.o) 21 | else ifeq ($(TARGET_SUBFAMILY), generic) 22 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/, irqmp.o) 23 | endif 24 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: WebKit 3 | 4 | ColumnLimit: 0 5 | AlignAfterOpenBracket: DontAlign 6 | UseTab: ForContinuationAndIndentation 7 | IndentWidth: 4 8 | ContinuationIndentWidth: 8 9 | BracedInitializerIndentWidth: 4 10 | TabWidth: 4 11 | 12 | PointerAlignment: Right 13 | SpaceAfterCStyleCast: false 14 | BreakBeforeBraces: Stroustrup 15 | 16 | AlignConsecutiveMacros: 17 | Enabled: true 18 | AlignEscapedNewlines: DontAlign 19 | AlignTrailingComments: 20 | Kind: Always 21 | OverEmptyLines: 0 22 | AllowShortBlocksOnASingleLine: true 23 | AllowShortCaseLabelsOnASingleLine: true 24 | AllowShortLoopsOnASingleLine: false 25 | IndentCaseLabels: true 26 | MaxEmptyLinesToKeep: 2 27 | SortIncludes: false 28 | SpacesBeforeTrailingComments: 2 29 | 30 | BreakBeforeBinaryOperators: None 31 | BreakBeforeTernaryOperators: false 32 | BreakConstructorInitializers: AfterColon 33 | 34 | InsertNewlineAtEOF: true 35 | ... 36 | -------------------------------------------------------------------------------- /hal/armv7a/zynq7000/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for Zynq 7000 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | 20 | /* On-Chip memory */ 21 | #define ADDR_OCRAM_LOW 0x00000000 22 | #define SIZE_OCRAM_LOW 192 * 1024 23 | #define ADDR_OCRAM_HIGH 0xffff0000 24 | #define SIZE_OCRAM_HIGH 64 * 1024 25 | 26 | /* TODO: temp solution, defines describe specific platform */ 27 | #define ADDR_DDR 0x00100000 28 | #define SIZE_DDR 0x7ffffff 29 | 30 | #define NUM_CPUS 2 31 | 32 | #ifndef __ASSEMBLY__ 33 | 34 | #define HAL_NAME_PLATFORM "Xilinx Zynq-7000 " 35 | 36 | #include "include/arch/armv7a/zynq7000/syspage.h" 37 | #include "include/syspage.h" 38 | 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /hal/riscv64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (RISCV64 HAL) 3 | # 4 | # Copyright 2018, 2020, 2024 Phoenix Systems 5 | # 6 | 7 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/, _init.o _cache.o _string.o _interrupts.o hal.o spinlock.o interrupts.o \ 8 | cpu.o pmap.o dtb.o timer.o string.o exceptions.o plic.o sbi.o) 9 | 10 | CFLAGS += -Ihal/$(TARGET_SUFF) 11 | 12 | ifneq ($(filter $(TARGET_SUBFAMILY),grfpga gr765),) 13 | include hal/$(TARGET_SUFF)/gaisler/Makefile 14 | CFLAGS += -Ihal/$(TARGET_SUFF)/gaisler/$(TARGET_SUBFAMILY) 15 | else 16 | include hal/$(TARGET_SUFF)/$(TARGET_SUBFAMILY)/Makefile 17 | CFLAGS += -Ihal/$(TARGET_SUFF)/$(TARGET_SUBFAMILY) 18 | endif 19 | 20 | # binutils 2.41 silently introduced gp relaxations which for some reason make kernel impossible to build 21 | # TODO: investigate further 22 | ifeq ($(shell expr $(LD_VERSION_MINOR) ">=" 41), 1) 23 | LDFLAGS += $(LDFLAGS_PREFIX)--no-relax-gp 24 | endif 25 | -------------------------------------------------------------------------------- /lib/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Debug assert 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_LIB_ASSERT_H_ 17 | #define _PH_LIB_ASSERT_H_ 18 | 19 | 20 | void lib_assertPanic(const char *func, int line, const char *fmt, ...); 21 | 22 | 23 | #define LIB_ASSERT_ALWAYS(condition, fmt, ...) \ 24 | if (!(condition)) { \ 25 | lib_assertPanic(__FUNCTION__, __LINE__, (fmt), ##__VA_ARGS__); \ 26 | } 27 | 28 | #define LIB_STATIC_ASSERT_SAME_TYPE(t1, t2) _Static_assert(__builtin_types_compatible_p(typeof(t1), typeof(t2)), "type mismatch") 29 | 30 | #ifndef NDEBUG 31 | 32 | #define LIB_ASSERT(condition, fmt, ...) LIB_ASSERT_ALWAYS((condition), (fmt), ##__VA_ARGS__) 33 | 34 | #else 35 | 36 | #define LIB_ASSERT(condition, fmt, ...) 37 | 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /proc/userintr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Userspace interrupts handling 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Author: Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_PROC_USERINTR_H_ 17 | #define _PH_PROC_USERINTR_H_ 18 | 19 | #include "hal/hal.h" 20 | #include "cond.h" 21 | #include "resource.h" 22 | 23 | 24 | typedef int (*userintrFn_t)(unsigned int n, void *arg); 25 | 26 | typedef struct _userintr_t { 27 | resource_t resource; 28 | intr_handler_t handler; 29 | process_t *process; 30 | userintrFn_t f; 31 | void *arg; 32 | cond_t *cond; 33 | } userintr_t; 34 | 35 | 36 | void userintr_put(userintr_t *ui); 37 | 38 | 39 | int userintr_setHandler(unsigned int n, userintrFn_t f, void *arg, handle_t c); 40 | 41 | 42 | userintr_t *userintr_active(void); 43 | 44 | 45 | void _userintr_init(void); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # phoenix-rtos-kernel 2 | This repository contains the source for the Phoenix-RTOS microkernel. 3 | 4 | Supported targets: 5 | 6 | * aarch64a53-zynqmp 7 | * armv7m4-stm32l4x6 8 | * armv7m7-imxrt105x 9 | * armv7m7-imxrt106x 10 | * armv7m7-imxrt117x 11 | * armv7a7-imx6ull 12 | * armv7a9-zynq7000 13 | * armv7r5f-zynqmp 14 | * armv8m33-nrf9160 15 | * armv8m33-mcxn94x 16 | * armv8m55-stm32n6 17 | * armv8r52-mps3an536 18 | * ia32-generic 19 | * riscv64-generic 20 | * riscv64-grfpga 21 | * riscv64-gr765 22 | * sparcv8leon-gr716 23 | * sparcv8leon-gr712rc 24 | * sparcv8leon-generic 25 | * sparcv8leon-gr740 26 | 27 | ## Building kernel 28 | To compile the kernel and build the operating system image [phoenix-rtos-project](https://github.com/phoenix-rtos/phoenix-rtos-project) repository should be used. Please read the instruction in this repository. 29 | 30 | ## License 31 | This work is licensed under a BSD license. See the LICENSE file for details. 32 | -------------------------------------------------------------------------------- /lib/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Standard routines - printf 7 | * 8 | * Copyright 2012, 2014, 2016 Phoenix Systems 9 | * Copyright 2001, 2005-2006 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk, Pawel Kolodziej, Pawel Krezolek 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | /* parasoft-begin-suppress MISRAC2012-RULE_17_1 "stdarg.h required for custom functions that are like printf" */ 18 | 19 | #ifndef _PH_LIB_PRINTF_H_ 20 | #define _PH_LIB_PRINTF_H_ 21 | 22 | #include 23 | 24 | int lib_sprintf(char *out, const char *format, ...); 25 | 26 | 27 | int lib_vsprintf(char *out, const char *format, va_list args); 28 | 29 | 30 | void lib_printf(const char *format, ...); 31 | 32 | 33 | int lib_vprintf(const char *format, va_list ap); 34 | 35 | 36 | void lib_putch(char s); 37 | 38 | 39 | #endif 40 | 41 | /* parasoft-end-suppress MISRAC2012-RULE_17_1 */ 42 | -------------------------------------------------------------------------------- /log/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Kernel log buffer 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Maciej Purski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | #ifndef _PH_LOG_H_ 16 | #define _PH_LOG_H_ 17 | 18 | #include "proc/msg.h" 19 | 20 | 21 | size_t log_write(const char *data, size_t len); 22 | 23 | 24 | /* Has to be called after log_write to wakeup klog readers. 25 | * Not safe - performs i.a. proc_respond! */ 26 | void log_scrub(void); 27 | 28 | 29 | /* Same as log_scrub, but give up if lock is taken */ 30 | void log_scrubTry(void); 31 | 32 | 33 | /* Bypass log, change log_write mode to writing directly to the console 34 | * Debug feature, allows direct and instant message printing */ 35 | void log_disable(void); 36 | 37 | 38 | void log_msgHandler(msg_t *msg, oid_t oid, msg_rid_t rid); 39 | 40 | 41 | void _log_init(void); 42 | 43 | 44 | #endif /* _LOG_H_ */ 45 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/gr740/gr740.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL internal functions for sparcv8leon-gr740 7 | * 8 | * Copyright 2025 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_GR740_H_ 17 | #define _PH_HAL_GR740_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "hal/types.h" 24 | #include 25 | 26 | #include "hal/gaisler/ambapp.h" 27 | #include "hal/sparcv8leon/gaisler/gaisler.h" 28 | 29 | #include "include/arch/sparcv8leon/gr740/gr740.h" 30 | 31 | 32 | int gaisler_setIomuxCfg(u8 pin, u8 opt, u8 pullup, u8 pulldn); 33 | 34 | 35 | void _gr740_cguClkEnable(u32 device); 36 | 37 | 38 | void _gr740_cguClkDisable(u32 device); 39 | 40 | 41 | int _gr740_cguClkStatus(u32 device); 42 | 43 | 44 | int hal_platformctl(void *ptr); 45 | 46 | 47 | #endif /* __ASSEMBLY__ */ 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /hal/ia32/console.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL console 7 | * 8 | * Copyright 2025 Phoenix Systems 9 | * Author: Hubert Badocha 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #include "hal/console.h" 18 | #include "hal/ia32/console.h" 19 | 20 | 21 | void hal_consolePrint(int attr, const char *s) 22 | { 23 | #ifdef HAL_CONSOLE_VGA 24 | hal_consoleVGAPrint(attr, s); 25 | #endif 26 | #ifdef HAL_CONSOLE_SERIAL 27 | hal_consoleSerialPrint(attr, s); 28 | #endif 29 | } 30 | 31 | 32 | void hal_consolePutch(char c) 33 | { 34 | #ifdef HAL_CONSOLE_VGA 35 | hal_consoleVGAPutch(c); 36 | #endif 37 | #ifdef HAL_CONSOLE_SERIAL 38 | hal_consoleSerialPutch(c); 39 | #endif 40 | } 41 | 42 | 43 | __attribute__((section(".init"))) void _hal_consoleInit(void) 44 | { 45 | #ifdef HAL_CONSOLE_VGA 46 | _hal_consoleVGAInit(); 47 | #endif 48 | #ifdef HAL_CONSOLE_SERIAL 49 | _hal_consoleSerialInit(); 50 | #endif 51 | } 52 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/gr712rc/gr712rc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL internal functions for sparcv8leon-gr712rc 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_GR716_H_ 17 | #define _PH_HAL_GR716_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "hal/types.h" 24 | #include 25 | 26 | #include "hal/gaisler/ambapp.h" 27 | #include "hal/sparcv8leon/gaisler/gaisler.h" 28 | 29 | #include "include/arch/sparcv8leon/gr712rc/gr712rc.h" 30 | 31 | 32 | int gaisler_setIomuxCfg(u8 pin, u8 opt, u8 pullup, u8 pulldn); 33 | 34 | 35 | void _gr712rc_cguClkEnable(u32 device); 36 | 37 | 38 | void _gr712rc_cguClkDisable(u32 device); 39 | 40 | 41 | int _gr712rc_cguClkStatus(u32 device); 42 | 43 | 44 | int hal_platformctl(void *ptr); 45 | 46 | #endif /* __ASSEMBLY__ */ 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /lib/assert.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Debug assert 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | /* parasoft-begin-suppress MISRAC2012-RULE_17_1 "stdarg.h required for custom functions that are like printf" */ 17 | #include 18 | #include "assert.h" 19 | #include "printf.h" 20 | #include "log/log.h" 21 | #include "hal/hal.h" 22 | 23 | 24 | void lib_assertPanic(const char *func, int line, const char *fmt, ...) 25 | { 26 | va_list ap; 27 | 28 | log_disable(); 29 | hal_cpuDisableInterrupts(); 30 | lib_printf("kernel (%s:%d): ", func, line); 31 | va_start(ap, fmt); 32 | (void)lib_vprintf(fmt, ap); 33 | va_end(ap); 34 | lib_putch('\n'); 35 | 36 | /* parasoft-end-suppress MISRAC2012-RULE_17_1 */ 37 | 38 | #ifdef NDEBUG 39 | hal_cpuReboot(); 40 | #else 41 | for (;;) { 42 | hal_cpuHalt(); 43 | } 44 | #endif 45 | } 46 | -------------------------------------------------------------------------------- /hal/exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Exception handling 7 | * 8 | * Copyright 2017, 2018 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Jakub Sejdak, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_EXCEPTIONS_H_ 17 | #define _PH_HAL_EXCEPTIONS_H_ 18 | 19 | #include "vm/types.h" 20 | 21 | #include 22 | 23 | 24 | typedef void (*excHandlerFn_t)(unsigned int n, exc_context_t *ctx); 25 | 26 | 27 | vm_prot_t hal_exceptionsFaultType(unsigned int n, exc_context_t *ctx); 28 | 29 | 30 | void *hal_exceptionsFaultAddr(unsigned int n, exc_context_t *ctx); 31 | 32 | 33 | ptr_t hal_exceptionsPC(exc_context_t *ctx); 34 | 35 | 36 | void hal_exceptionsDumpContext(char *buff, exc_context_t *ctx, unsigned int n); 37 | 38 | 39 | int hal_exceptionsSetHandler(unsigned int n, excHandlerFn_t handler); 40 | 41 | 42 | void _hal_exceptionsInit(void); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /hal/armv8m/mcx/n94x/mcxn94x.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * MCXN94X basic peripherals control functions 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_MCXN94X_H_ 17 | #define _PH_HAL_MCXN94X_H_ 18 | 19 | #include "hal/types.h" 20 | #include "hal/pmap.h" 21 | 22 | #include "include/arch/armv8m/mcx/n94x/mcxn94x.h" 23 | 24 | 25 | int _mcxn94x_portPinConfig(int pin, int mux, int options); 26 | 27 | 28 | u64 _mcxn94x_sysconGray2Bin(u64 gray); 29 | 30 | 31 | int _mcxn94x_sysconSetDevClk(int dev, unsigned int sel, unsigned int div, int enable); 32 | 33 | 34 | int _mcxn94x_sysconDevReset(int dev, int state); 35 | 36 | 37 | int hal_platformctl(void *ptr); 38 | 39 | 40 | void _mcxn94x_scbSetPriorityGrouping(u32 group); 41 | 42 | 43 | void _mcxn94x_scbSetPriority(s8 excpn, u32 priority); 44 | 45 | 46 | unsigned int _mcxn94x_cpuid(void); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /hal/common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Common hal functions 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Hubert Badocha 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #include "hal/cpu.h" 18 | #include "hal/string.h" 19 | 20 | #include "hal/types.h" 21 | 22 | /* STACK_ALIGN is most strict stack alignment constraint across all supported architectures. */ 23 | #define STACK_ALIGN 16U 24 | 25 | 26 | void hal_stackPutArgs(void **stackp, size_t argc, const struct stackArg *argv) 27 | { 28 | size_t i, misalign, argsz = 0U; 29 | ptr_t stack = (ptr_t)*stackp; 30 | 31 | for (i = 0U; i < argc; i++) { 32 | argsz += SIZE_STACK_ARG(argv[i].sz); 33 | } 34 | 35 | misalign = (stack - argsz) & (STACK_ALIGN - 1U); 36 | stack -= misalign; 37 | 38 | for (i = 0U; i < argc; i++) { 39 | stack -= SIZE_STACK_ARG(argv[i].sz); 40 | hal_memcpy((void *)stack, argv[i].argp, argv[i].sz); 41 | } 42 | 43 | *stackp = (void *)stack; 44 | } 45 | -------------------------------------------------------------------------------- /include/arch/riscv64/riscv64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * RISCV64 basic peripherals control functions 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_RISCV64_H_ 17 | #define _PH_ARCH_RISCV64_H_ 18 | 19 | #define PCTL_REBOOT_MAGIC 0xaa55aa55UL 20 | 21 | /* clang-format off */ 22 | 23 | typedef struct { 24 | enum { pctl_set = 0, pctl_get } action; 25 | enum { pctl_reboot = 0, pctl_iomux, pctl_ambapp } type; 26 | 27 | union { 28 | struct { 29 | unsigned int magic; 30 | } reboot; 31 | 32 | struct { 33 | unsigned char pin; 34 | unsigned char opt; 35 | unsigned char pullup; 36 | unsigned char pulldn; 37 | } iocfg; 38 | 39 | struct { 40 | struct _ambapp_dev_t *dev; 41 | unsigned int *instance; 42 | } ambapp; 43 | } task; 44 | } __attribute__((packed)) platformctl_t; 45 | 46 | /* clang-format on */ 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /vm/page.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Virtual memory manager - page allocator 7 | * 8 | * Copyright 2012, 2016 Phoenix Systems 9 | * Copyright 2001, 2005 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_VM_PAGE_H_ 18 | #define _PH_VM_PAGE_H_ 19 | 20 | #include "hal/hal.h" 21 | #include "include/sysinfo.h" 22 | #include "types.h" 23 | 24 | 25 | page_t *vm_pageAlloc(size_t size, vm_flags_t flags); 26 | 27 | 28 | void vm_pageFree(page_t *lh); 29 | 30 | 31 | page_t *_page_get(addr_t addr); 32 | 33 | 34 | void _page_showPages(void); 35 | 36 | 37 | int page_map(pmap_t *pmap, void *vaddr, addr_t pa, vm_attr_t attr); 38 | 39 | 40 | int _page_sbrk(pmap_t *pmap, void **start, void **end); 41 | 42 | 43 | void vm_pageGetStats(size_t *freesz); 44 | 45 | 46 | void vm_pageinfo(meminfo_t *info); 47 | 48 | 49 | void _page_init(pmap_t *pmap, void **bss, void **top); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /hal/armv8m/stm32/n6/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for STM32N6 7 | * 8 | * Copyright 2021, 2025 Phoenix Systems 9 | * Author: Hubert Buczynski, Jacek Maksymowicz 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | #include "hal/types.h" 22 | #include "include/arch/armv8m/stm32/syspage.h" 23 | #include "include/syspage.h" 24 | #include "hal/armv8m/stm32/stm32.h" 25 | #include "hal/armv8m/stm32/stm32-timer.h" 26 | 27 | #define SIZE_INTERRUPTS 211 28 | 29 | /* Constants for configuring which TIM peripheral is used as system timer */ 30 | #define TIM_SYSTEM_BASE ((void *)0x52003c00) /* TIM18 base address */ 31 | #define TIM_SYSTEM_PCTL pctl_tim18 32 | #define TIM_SYSTEM_IRQ tim18_irq 33 | #define TIM_SYSTEM_FREQ (400UL * 1000000UL) /* Frequency in Hz */ 34 | 35 | #define HAL_NAME_PLATFORM "STM32N6 " 36 | 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/gr716/gr716.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL internal functions for sparcv8leon-gr716 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_GR716_H_ 17 | #define _PH_HAL_GR716_H_ 18 | 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | 23 | #include "hal/types.h" 24 | #include 25 | 26 | #include "hal/gaisler/ambapp.h" 27 | #include "hal/sparcv8leon/gaisler/gaisler.h" 28 | 29 | #include "include/arch/sparcv8leon/gr716/gr716.h" 30 | 31 | 32 | #define TIMER_IRQ 9 33 | 34 | 35 | int _gr716_getIomuxCfg(u8 pin, u8 *opt, u8 *pullup, u8 *pulldn); 36 | 37 | 38 | void _gr716_cguClkEnable(u32 cgu, u32 device); 39 | 40 | 41 | void _gr716_cguClkDisable(u32 cgu, u32 device); 42 | 43 | 44 | int _gr716_cguClkStatus(u32 cgu, u32 device); 45 | 46 | 47 | int hal_platformctl(void *ptr); 48 | 49 | 50 | #endif /* __ASSEMBLY__ */ 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /include/arch/sparcv8leon/generic/generic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * LEON3 Generic basic peripherals control functions 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_GENERIC_H_ 17 | #define _PH_ARCH_GENERIC_H_ 18 | 19 | #define PCTL_REBOOT_MAGIC 0xaa55aa55UL 20 | 21 | /* clang-format off */ 22 | 23 | typedef struct { 24 | enum { pctl_set = 0, pctl_get } action; 25 | enum { pctl_iomux = 0, pctl_ambapp, pctl_reboot } type; 26 | 27 | union { 28 | struct { 29 | unsigned char pin; 30 | unsigned char opt; 31 | unsigned char pullup; 32 | unsigned char pulldn; 33 | } iocfg; 34 | 35 | struct { 36 | struct _ambapp_dev_t *dev; 37 | unsigned int *instance; 38 | } ambapp; 39 | 40 | struct { 41 | unsigned int magic; 42 | } reboot; 43 | } task; 44 | } __attribute__((packed)) platformctl_t; 45 | 46 | /* clang-format on */ 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /include/mman.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Memory management 7 | * 8 | * Copyright 2018 Phoenix Systems 9 | * Author: Jan Sikorski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_MMAN_H_ 17 | #define _PH_MMAN_H_ 18 | 19 | 20 | #define MAP_NONE 0x0U 21 | #define MAP_NEEDSCOPY (0x1U << 0) 22 | #define MAP_UNCACHED (0x1U << 1) 23 | #define MAP_DEVICE (0x1U << 2) 24 | #define MAP_NOINHERIT (0x1U << 3) 25 | #define MAP_PHYSMEM (0x1U << 4) 26 | #define MAP_CONTIGUOUS (0x1U << 5) 27 | #define MAP_ANONYMOUS (0x1U << 6) 28 | #define MAP_FIXED (0x1U << 7) 29 | /* NOTE: vm uses u8 to store flags, if more flags are needed this type needs to be changed. */ 30 | #define MAP_SHARED 0x0U 31 | #define MAP_PRIVATE 0x0U 32 | 33 | 34 | #define PROT_NONE 0x0U 35 | #define PROT_READ 0x1U 36 | #define PROT_WRITE 0x2U 37 | #define PROT_EXEC 0x4U 38 | #define PROT_USER 0x8U 39 | 40 | 41 | #define MAP_FAILED (void *)-1 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /hal/sparcv8leon/srmmu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * SPARC reference MMU routines 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #include "srmmu.h" 18 | #include "hal/sparcv8leon/sparcv8leon.h" 19 | 20 | 21 | void hal_srmmuFlushTLB(const void *vaddr, u8 type) 22 | { 23 | addr_t addr = (addr_t)(((u32)vaddr & ~(0xfff)) | ((type & 0xf) << 8)); 24 | hal_cpuStoreAlternate(addr, ASI_FLUSH_ALL, 0); 25 | } 26 | 27 | 28 | u32 hal_srmmuGetFaultSts(void) 29 | { 30 | return hal_cpuLoadAlternate(MMU_FAULT_STS, ASI_MMU_REGS); 31 | } 32 | 33 | 34 | u32 hal_srmmuGetFaultAddr(void) 35 | { 36 | return hal_cpuLoadAlternate(MMU_FAULT_ADDR, ASI_MMU_REGS); 37 | } 38 | 39 | 40 | void hal_srmmuSetContext(u32 ctx) 41 | { 42 | hal_cpuStoreAlternate(MMU_CTX, ASI_MMU_REGS, ctx); 43 | } 44 | 45 | 46 | u32 hal_srmmuGetContext(void) 47 | { 48 | return hal_cpuLoadAlternate(MMU_CTX, ASI_MMU_REGS); 49 | } 50 | -------------------------------------------------------------------------------- /hal/ia32/arch/tlb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * TLB handling 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Andrzej Stalke, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #ifndef _PH_HAL_IA32_TLB_H_ 18 | #define _PH_HAL_IA32_TLB_H_ 19 | 20 | 21 | #include "pmap.h" 22 | #include "hal/tlb/tlb.h" 23 | 24 | 25 | static inline void hal_tlbFlushLocal(const pmap_t *pmap) 26 | { 27 | u32 tmpreg; 28 | (void)pmap; 29 | 30 | /* clang-format off */ 31 | __asm__ volatile ( 32 | "movl %%cr3, %0\n\t" 33 | "movl %0, %%cr3" 34 | : "=r" (tmpreg) 35 | : 36 | : "memory"); 37 | /* clang-format on */ 38 | 39 | return; 40 | } 41 | 42 | 43 | static inline void hal_tlbInvalidateLocalEntry(const pmap_t *pmap, const void *vaddr) 44 | { 45 | (void)pmap; 46 | 47 | /* clang-format off */ 48 | __asm__ volatile ( 49 | "invlpg (%0)" 50 | : 51 | : "r" (vaddr) 52 | : "memory" ); 53 | /* clang-format on */ 54 | 55 | return; 56 | } 57 | 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /hal/riscv64/dtb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * DTB parser 7 | * 8 | * Copyright 2018, 2024 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_DTB_H_ 17 | #define _PH_HAL_DTB_H_ 18 | 19 | #include "hal/cpu.h" 20 | 21 | #define ntoh16(x) (((x << 8) & 0xff00) | ((x >> 8) & 0xff)) 22 | #define ntoh32(x) ((ntoh16(x) << 16) | ntoh16(x >> 16)) 23 | #define ntoh64(x) ((ntoh32(x) << 32) | ntoh32(x >> 32)) 24 | 25 | 26 | void dtb_save(void *dtb); 27 | 28 | 29 | void dtb_parse(void); 30 | 31 | 32 | void dtb_getSystem(char **model, char **compatible); 33 | 34 | 35 | int dtb_getCPU(unsigned int n, char **compatible, u32 *clock, char **isa, char **mmu); 36 | 37 | 38 | void dtb_getMemory(u8 **reg, size_t *nreg); 39 | 40 | 41 | int dtb_getPLIC(void); 42 | 43 | 44 | void dtb_getReservedMemory(u64 **reg); 45 | 46 | 47 | void dtb_getDTBArea(u64 *dtb, u32 *dtbsz); 48 | 49 | 50 | void _dtb_init(void); 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /vm/zone.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Virtual memory manager - zone allocator 7 | * 8 | * Copyright 2014, 2016-2017 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_VM_ZALLOC_H_ 17 | #define _PH_VM_ZALLOC_H_ 18 | 19 | #include "lib/lib.h" 20 | 21 | 22 | typedef struct _vm_zone_t { 23 | struct _vm_zone_t *next; 24 | struct _vm_zone_t *prev; 25 | 26 | rbnode_t linkage; 27 | 28 | size_t blocksz; 29 | unsigned int blocks; 30 | unsigned int used; 31 | void *vaddr; 32 | void *first; 33 | page_t *pages; 34 | 35 | /* u8 padd[1024]; */ 36 | } vm_zone_t; 37 | 38 | 39 | int _vm_zoneCreate(vm_zone_t *zone, size_t blocksz, unsigned int blocks); 40 | 41 | 42 | int _vm_zoneDestroy(vm_zone_t *zone); 43 | 44 | 45 | void *_vm_zalloc(vm_zone_t *zone, addr_t *addr); 46 | 47 | 48 | void _vm_zfree(vm_zone_t *zone, void *block); 49 | 50 | 51 | void _zone_init(vm_map_t *map, vm_object_t *kernel, void **bss, void **top); 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /hal/armv8m/hal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Hardware Abstraction Layer (ARMv8M) 7 | * 8 | * Copyright 2016-2017, 2022 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Artur Wodejko, Damian Loewnau 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #include "hal/hal.h" 17 | struct { 18 | int started; 19 | } hal_common; 20 | 21 | 22 | hal_syspage_t *syspage; 23 | 24 | 25 | void *hal_syspageRelocate(void *data) 26 | { 27 | return data; 28 | } 29 | 30 | 31 | ptr_t hal_syspageAddr(void) 32 | { 33 | return (ptr_t)syspage; 34 | } 35 | 36 | 37 | int hal_started(void) 38 | { 39 | return hal_common.started; 40 | } 41 | 42 | 43 | void _hal_start(void) 44 | { 45 | hal_common.started = 1; 46 | } 47 | 48 | 49 | void hal_lockScheduler(void) 50 | { 51 | } 52 | 53 | 54 | void _hal_init(void) 55 | { 56 | hal_common.started = 0; 57 | 58 | _hal_spinlockInit(); 59 | _hal_exceptionsInit(); 60 | _hal_interruptsInit(); 61 | _hal_cpuInit(); 62 | _hal_consoleInit(); 63 | _hal_timerInit(SYSTICK_INTERVAL); 64 | } 65 | -------------------------------------------------------------------------------- /hal/armv7m/hal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Hardware Abstraction Layer (ARMv7 Cortex-M3) 7 | * 8 | * Copyright 2016-2017 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Artur Wodejko 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #include "hal/hal.h" 17 | struct { 18 | int started; 19 | } hal_common; 20 | 21 | 22 | hal_syspage_t *syspage; 23 | 24 | 25 | void *hal_syspageRelocate(void *data) 26 | { 27 | return data; 28 | } 29 | 30 | 31 | ptr_t hal_syspageAddr(void) 32 | { 33 | return (ptr_t)syspage; 34 | } 35 | 36 | 37 | int hal_started(void) 38 | { 39 | return hal_common.started; 40 | } 41 | 42 | 43 | void _hal_start(void) 44 | { 45 | hal_common.started = 1; 46 | } 47 | 48 | 49 | void hal_lockScheduler(void) 50 | { 51 | } 52 | 53 | 54 | void _hal_init(void) 55 | { 56 | hal_common.started = 0; 57 | 58 | _hal_spinlockInit(); 59 | _hal_exceptionsInit(); 60 | _hal_interruptsInit(); 61 | _hal_cpuInit(); 62 | _hal_consoleInit(); 63 | _hal_timerInit(SYSTICK_INTERVAL); 64 | 65 | return; 66 | } 67 | -------------------------------------------------------------------------------- /hal/armv7a/imx6ull/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-A HAL i.MX 6ULL) 3 | # 4 | # Copyright 2021 Phoenix Systems 5 | # 6 | 7 | OBJS += $(addprefix $(PREFIX_O)hal/armv7a/imx6ull/, _init.o console.o imx6ull.o timer.o interrupts.o) 8 | 9 | $(PREFIX_O)hal/armv7a/imx6ull/_init.o: hal/armv7a/_armv7a.S hal/armv7a/_interrupts.S 10 | 11 | ifdef MEMTEST_SHORT 12 | CPPFLAGS += -DMEMTEST_SHORT 13 | endif 14 | 15 | ifeq ($(KERNEL_PLO_BOOT), y) 16 | CPPFLAGS += -DKERNEL_PLO_BOOT 17 | endif 18 | 19 | # TODO: remove after introducing plo 20 | # HACKISH: different OBJS for memtest target 21 | .PHONY: memtest 22 | memtest: $(PREFIX_PROG)/memtest.elf $(PREFIX_PROG)/memtest.img 23 | memtest: OBJS:=$(addprefix $(PREFIX_O)hal/armv7a/imx6ull/, _memtest.o memtest.o) 24 | 25 | $(PREFIX_PROG)/memtest.elf: $(PREFIX_O)hal/armv7a/imx6ull/_memtest.o $(PREFIX_O)hal/armv7a/imx6ull/memtest.o 26 | $(SIL)$(LD) $(CFLAGS) $(LDFLAGS) -o $@ -nostdlib -e _start -Wl,--section-start,.init=0x907000 -z max-page-size=0x1000 $^ -lgcc 27 | 28 | $(PREFIX_PROG)/memtest.img: $(PREFIX_PROG)/memtest.elf 29 | $(SIL)$(OBJCOPY) $< -Obinary $@ 30 | -------------------------------------------------------------------------------- /vm/vm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Virtual memory manager 7 | * 8 | * Copyright 2012, 2016-2017 Phoenix Systems 9 | * Copyright 2001, 2005 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #include "hal/hal.h" 18 | #include "lib/lib.h" 19 | #include "include/sysinfo.h" 20 | #include "page.h" 21 | #include "map.h" 22 | #include "amap.h" 23 | #include "zone.h" 24 | #include "kmalloc.h" 25 | #include "vm/vm.h" 26 | 27 | 28 | static struct { 29 | void *bss; 30 | void *top; 31 | } vm; 32 | 33 | 34 | void vm_meminfo(meminfo_t *info) 35 | { 36 | vm_pageinfo(info); 37 | vm_mapinfo(info); 38 | } 39 | 40 | 41 | void _vm_init(vm_map_t *kmap, vm_object_t *kernel) 42 | { 43 | _pmap_init(&kmap->pmap, &vm.bss, &vm.top); 44 | _page_init(&kmap->pmap, &vm.bss, &vm.top); 45 | 46 | (void)_map_init(kmap, kernel, &vm.bss, &vm.top); 47 | 48 | _zone_init(kmap, kernel, &vm.bss, &vm.top); 49 | (void)_kmalloc_init(); 50 | 51 | (void)_object_init(kmap, kernel); 52 | _amap_init(kmap, kernel); 53 | 54 | return; 55 | } 56 | -------------------------------------------------------------------------------- /hal/armv7m/imxrt/117x/imxrt117x.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * iMXRT basic peripherals control functions 7 | * 8 | * Copyright 2019-2022 Phoenix Systems 9 | * Author: Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_IMXRT1170_H_ 17 | #define _PH_HAL_IMXRT1170_H_ 18 | 19 | 20 | #include "hal/types.h" 21 | 22 | 23 | int hal_platformctl(void *ptr); 24 | 25 | 26 | void _imxrt_wdgReload(void); 27 | 28 | 29 | int _imxrt_setIOmux(int mux, char sion, char mode); 30 | 31 | 32 | int _imxrt_setIOpad(int pad, char sre, char dse, char pue, char pus, char ode, char apc); 33 | 34 | 35 | int _imxrt_setIOisel(int isel, char daisy); 36 | 37 | 38 | int _imxrt_setDevClock(int clock, int div, int mux, int mfd, int mfn, int state); 39 | 40 | 41 | int _imxrt_setDirectLPCG(int clock, int state); 42 | 43 | 44 | int _imxrt_getDirectLPCG(int clock, int *state); 45 | 46 | 47 | int _imxrt_setLevelLPCG(int clock, int level); 48 | 49 | 50 | void _imxrt_platformInit(void); 51 | 52 | 53 | void _imxrt_init(void); 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /hal/riscv64/generic/generic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL internal functions for riscv64-generic 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #include "hal/hal.h" 18 | #include "include/arch/riscv64/riscv64.h" 19 | 20 | static struct { 21 | spinlock_t lock; 22 | } generic_common; 23 | 24 | 25 | int hal_platformctl(void *ptr) 26 | { 27 | platformctl_t *pctl = ptr; 28 | spinlock_ctx_t sc; 29 | int ret = -1; 30 | 31 | hal_spinlockSet(&generic_common.lock, &sc); 32 | 33 | switch (pctl->type) { 34 | case pctl_reboot: 35 | if ((pctl->action == pctl_set) && (pctl->task.reboot.magic == PCTL_REBOOT_MAGIC)) { 36 | hal_cpuReboot(); 37 | } 38 | break; 39 | 40 | case pctl_iomux: 41 | ret = 0; 42 | break; 43 | 44 | default: 45 | break; 46 | } 47 | hal_spinlockClear(&generic_common.lock, &sc); 48 | 49 | return ret; 50 | } 51 | 52 | 53 | void _hal_platformInit(void) 54 | { 55 | hal_spinlockCreate(&generic_common.lock, "generic_common.lock"); 56 | } 57 | -------------------------------------------------------------------------------- /vm/object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Virtual memory manager - memory object abstraction 7 | * 8 | * Copyright 2016-2017 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_VM_OBJECT_H_ 17 | #define _PH_VM_OBJECT_H_ 18 | 19 | #include "hal/hal.h" 20 | #include "lib/lib.h" 21 | #include "proc/lock.h" 22 | #include "amap.h" 23 | 24 | 25 | struct _vm_map_t; 26 | 27 | typedef struct _vm_object_t { 28 | rbnode_t linkage; 29 | oid_t oid; 30 | int refs; 31 | size_t size; 32 | page_t *pages[]; 33 | } vm_object_t; 34 | 35 | 36 | #define VM_OBJ_PHYSMEM ((vm_object_t *)-1) 37 | 38 | 39 | vm_object_t *vm_objectRef(vm_object_t *o); 40 | 41 | 42 | int vm_objectGet(vm_object_t **o, oid_t oid); 43 | 44 | 45 | int vm_objectPut(vm_object_t *o); 46 | 47 | 48 | page_t *vm_objectPage(struct _vm_map_t *map, amap_t **amap, vm_object_t *o, void *vaddr, u64 offs); 49 | 50 | 51 | vm_object_t *vm_objectContiguous(size_t size); 52 | 53 | 54 | int _object_init(struct _vm_map_t *kmap, vm_object_t *kernel); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /hal/aarch64/dtb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system loader 5 | * 6 | * DTB parser 7 | * 8 | * Copyright 2018, 2024 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_DTB_H_ 17 | #define _PH_HAL_DTB_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | #define ntoh16(x) (((x << 8) & 0xff00) | ((x >> 8) & 0xff)) 22 | #define ntoh32(x) ((ntoh16(x) << 16) | ntoh16(x >> 16)) 23 | #define ntoh64(x) ((ntoh32(x) << 32) | ntoh32(x >> 32)) 24 | 25 | typedef struct { 26 | addr_t start; 27 | addr_t end; 28 | } dtb_memBank_t; 29 | 30 | 31 | typedef struct { 32 | addr_t base; 33 | int intr; 34 | } dtb_serial_t; 35 | 36 | 37 | void dtb_getSystem(char **model, char **compatible); 38 | 39 | 40 | int dtb_getCPU(unsigned int n, char **compatible, u32 *clock); 41 | 42 | 43 | void dtb_getMemory(dtb_memBank_t **banks, size_t *nBanks); 44 | 45 | 46 | void dtb_getGIC(addr_t *gicc, addr_t *gicd); 47 | 48 | 49 | void dtb_getSerials(dtb_serial_t **serials, size_t *nSerials); 50 | 51 | 52 | void _dtb_init(addr_t dtbPhys); 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /hal/armv7m/imxrt/10xx/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for i.MX RT10xx 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | #define SIZE_INTERRUPTS 167 20 | 21 | #define TIMER_US2CYC(x) (x) 22 | #define TIMER_CYC2US(x) (x) 23 | 24 | #ifndef __ASSEMBLY__ 25 | #include "hal/types.h" 26 | #include "include/arch/armv7m/imxrt/syspage.h" 27 | #include "include/syspage.h" 28 | #include "include/arch/armv7m/imxrt/10xx/imxrt10xx.h" 29 | #include "imxrt10xx.h" 30 | 31 | #define HAL_NAME_PLATFORM "NXP i.MX RT10xx " 32 | 33 | #define GPT1_BASE 0x401ec000 34 | #define GPT2_BASE 0x401f0000 35 | #define GPT_BASE GPT2_BASE 36 | 37 | #define GPT1_IRQ gpt1_irq 38 | #define GPT2_IRQ gpt2_irq 39 | #define GPT_IRQ GPT2_IRQ 40 | 41 | #define GPT_BUS_CLK pctl_clk_gpt2_bus 42 | #define GPT_FREQ_MHZ 24 43 | #define GPT_OSC_PRESCALER 8 44 | #define GPT_PRESCALER (GPT_FREQ_MHZ / GPT_OSC_PRESCALER) 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/posix-fcntl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * POSIX-compatibility definitions - fcntl 7 | * 8 | * Copyright 2018, 2024 Phoenix Systems 9 | * Author: Jan Sikorski, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_POSIX_FCNTL_H_ 17 | #define _PH_POSIX_FCNTL_H_ 18 | 19 | 20 | #define FD_CLOEXEC 0x1U 21 | 22 | #define O_RDONLY 0x00001U 23 | #define O_WRONLY 0x00002U 24 | #define O_RDWR 0x00004U 25 | #define O_APPEND 0x00008U 26 | #define O_CREAT 0x00100U 27 | #define O_TRUNC 0x00200U 28 | #define O_EXCL 0x00400U 29 | #define O_SYNC 0x00800U 30 | #define O_NONBLOCK 0x01000U 31 | #define O_NDELAY O_NONBLOCK 32 | #define O_NOCTTY 0x02000U 33 | #define O_CLOEXEC 0x04000U 34 | #define O_RSYNC 0x08000U 35 | #define O_DSYNC 0x10000U 36 | 37 | #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) 38 | 39 | /* clang-format off */ 40 | 41 | /* fcntl() operations */ 42 | enum { F_DUPFD = 0, F_DUPFD_CLOEXEC, F_GETFD, F_SETFD, F_GETFL, F_SETFL, 43 | F_GETOWN, F_SETOWN, F_GETLK, F_SETLK, F_SETLKW }; 44 | 45 | /* clang-format on */ 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /syspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Syspage 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Authors: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_SYSPAGE_INTERNAL_H_ 17 | #define _PH_SYSPAGE_INTERNAL_H_ 18 | 19 | #include "hal/hal.h" 20 | #include "include/syspage.h" 21 | 22 | 23 | /* Map's functions */ 24 | 25 | size_t syspage_mapSize(void); 26 | 27 | 28 | const syspage_map_t *syspage_mapList(void); 29 | 30 | 31 | const syspage_map_t *syspage_mapIdResolve(unsigned int id); 32 | 33 | 34 | const syspage_map_t *syspage_mapAddrResolve(addr_t addr); 35 | 36 | 37 | const syspage_map_t *syspage_mapNameResolve(const char *name); 38 | 39 | 40 | /* Prog's functions */ 41 | 42 | size_t syspage_progSize(void); 43 | 44 | 45 | syspage_prog_t *syspage_progList(void); 46 | 47 | 48 | const syspage_prog_t *syspage_progIdResolve(unsigned int id); 49 | 50 | 51 | const syspage_prog_t *syspage_progNameResolve(const char *name); 52 | 53 | 54 | /* General functions */ 55 | 56 | void syspage_progShow(void); 57 | 58 | 59 | void syspage_init(void); 60 | 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /include/posix-statvfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * POSIX-compatibility definitions - statvfs 7 | * 8 | * Copyright 2025 Phoenix Systems 9 | * Author: Hubert Badocha 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #ifndef _PH_POSIX_STATVFS_H_ 18 | #define _PH_POSIX_STATVFS_H_ 19 | 20 | #include "posix-types.h" 21 | 22 | 23 | struct statvfs { 24 | unsigned long f_bsize; /* Filesystem block size */ 25 | unsigned long f_frsize; /* Fundamental filesystem block size */ 26 | fsblkcnt_t f_blocks; /* Number of blocks on filesystem (in f_frsize units) */ 27 | fsblkcnt_t f_bfree; /* Number of free blocks */ 28 | fsblkcnt_t f_bavail; /* Number of free blocks available to non-privileged process */ 29 | fsfilcnt_t f_files; /* Number of inodes */ 30 | fsfilcnt_t f_ffree; /* Number of free inodes */ 31 | fsfilcnt_t f_favail; /* Number of free inodes available to non-privileged process */ 32 | unsigned long f_fsid; /* Filesystem ID */ 33 | unsigned long f_flag; /* Filesystem flags */ 34 | unsigned long f_namemax; /* Maximum filename length */ 35 | }; 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/strutil.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * String helper routines 7 | * 8 | * Copyright 2018, 2023 Phoenix Systems 9 | * Author: Jan Sikorski, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #include "hal/hal.h" 17 | #include "vm/kmalloc.h" 18 | #include "lib/strutil.h" 19 | 20 | static char *lib_strrchr(char *s, char c) 21 | { 22 | char *p = NULL; 23 | char *i; 24 | 25 | for (i = s; *i != '\0'; ++i) { 26 | if (*i == c) { 27 | p = i; 28 | } 29 | } 30 | 31 | return p; 32 | } 33 | 34 | 35 | char *lib_strdup(const char *str) 36 | { 37 | size_t len = hal_strlen(str) + 1U; 38 | char *ptr = vm_kmalloc(len); 39 | 40 | if (ptr != NULL) { 41 | hal_memcpy(ptr, str, len); 42 | } 43 | 44 | return ptr; 45 | } 46 | 47 | 48 | void lib_splitname(char *path, char **base, const char **dir) 49 | { 50 | char *slash; 51 | 52 | slash = lib_strrchr(path, '/'); 53 | 54 | if (slash == NULL) { 55 | *dir = "."; 56 | *base = path; 57 | } 58 | else if (slash == path) { 59 | *base = path + 1; 60 | *dir = "/"; 61 | } 62 | else { 63 | *dir = path; 64 | *base = slash + 1; 65 | *slash = '\0'; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /hal/armv8r/mps3an536/mps3an536.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Cortex R52 MPS3 AN536 functions 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #include "hal/cpu.h" 18 | #include "hal/spinlock.h" 19 | #include "include/arch/armv8r/mps3an536/mps3an536.h" 20 | 21 | 22 | static struct { 23 | spinlock_t lock; 24 | } mps3an536_common; 25 | 26 | 27 | int hal_platformctl(void *ptr) 28 | { 29 | spinlock_ctx_t sc; 30 | platformctl_t *data = ptr; 31 | int ret = -1; 32 | 33 | hal_spinlockSet(&mps3an536_common.lock, &sc); 34 | 35 | switch (data->type) { 36 | case pctl_reboot: 37 | if (data->action == pctl_set) { 38 | if (data->task.reboot.magic == PCTL_REBOOT_MAGIC) { 39 | hal_cpuReboot(); 40 | } 41 | } 42 | break; 43 | 44 | default: 45 | break; 46 | } 47 | 48 | hal_spinlockClear(&mps3an536_common.lock, &sc); 49 | 50 | return ret; 51 | } 52 | 53 | 54 | unsigned int hal_cpuGetCount(void) 55 | { 56 | return 1; 57 | } 58 | 59 | 60 | void _hal_platformInit(void) 61 | { 62 | hal_spinlockCreate(&mps3an536_common.lock, "mps3an536_common.lock"); 63 | } 64 | -------------------------------------------------------------------------------- /hal/sparcv8leon/tlb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * TLB handling 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Andrzej Stalke, Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | #include "srmmu.h" 20 | 21 | 22 | void hal_tlbFlushLocal(const pmap_t *pmap) 23 | { 24 | if ((pmap != NULL) && (hal_srmmuGetContext() == pmap->context)) { 25 | hal_srmmuFlushTLB(NULL, TLB_FLUSH_CTX); 26 | } 27 | else { 28 | hal_srmmuFlushTLB(NULL, TLB_FLUSH_ALL); 29 | } 30 | } 31 | 32 | 33 | void hal_tlbInvalidateLocalEntry(const pmap_t *pmap, const void *vaddr) 34 | { 35 | if ((pmap != NULL) && (hal_srmmuGetContext() == pmap->context)) { 36 | if ((ptr_t)vaddr < VADDR_USR_MAX) { 37 | hal_srmmuFlushTLB(vaddr, TLB_FLUSH_L3); 38 | } 39 | else { 40 | hal_srmmuFlushTLB(vaddr, TLB_FLUSH_CTX); 41 | } 42 | } 43 | else { 44 | hal_srmmuFlushTLB(vaddr, TLB_FLUSH_ALL); 45 | } 46 | } 47 | 48 | 49 | int hal_tlbIrqHandler(unsigned int n, cpu_context_t *ctx, void *arg) 50 | { 51 | (void)n; 52 | (void)ctx; 53 | (void)arg; 54 | 55 | hal_tlbShootdown(); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /lib/helpers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Generic useful macros 5 | * 6 | * Copyright 2024 Phoenix Systems 7 | * Author: Daniel Sawka 8 | * 9 | * %LICENSE% 10 | */ 11 | 12 | #ifndef _PH_LIB_HELPERS_H_ 13 | #define _PH_LIB_HELPERS_H_ 14 | 15 | /* 16 | These macros should only be used in `#if` and `#elif` directives, because undefined identifiers expand to 0 there. 17 | Otherwise there will be "use of undefined identifier" errors (an exception: identifier is first checked for 18 | existence with e.g. `#ifdef`). 19 | 20 | Anything that expands to a numerical expression (or to an empty value) is fine. String literals don't work. 21 | */ 22 | 23 | /* 24 | These macros produce a logically correct result only if X is defined. You may use `#ifdef` or `defined()` 25 | for this purpose. Unfortunately, `defined()` cannot be conveniently put inside a macro as this is undefined 26 | behavior (see -Wexpansion-to-defined for details), so you have to use it directly on the spot, for example: 27 | `#if defined(PERIPH1) && !ISEMPTY(PERIPH1) 28 | // Use PERIPH1 29 | #endif` 30 | */ 31 | 32 | /* True if X is empty (has no value). The result in #if is valid only if defined(X) is true */ 33 | #define ISEMPTY(X) ((0 - X - 1) == 1 && (X + 0) != -2) 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /hal/riscv64/plic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * RISCV64 PLIC interrupt controller driver 7 | * 8 | * Copyright 2020 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_PLIC_H_ 17 | #define _PH_HAL_PLIC_H_ 18 | 19 | #include "hal/types.h" 20 | #include 21 | 22 | 23 | /* PLIC Supervisor Context number */ 24 | #define PLIC_SCONTEXT(hartId) (PLIC_CONTEXTS_PER_HART * (hartId) + 1) 25 | 26 | 27 | void plic_priority(unsigned int n, unsigned int priority); 28 | 29 | 30 | u32 plic_priorityGet(unsigned int n); 31 | 32 | 33 | int plic_isPending(unsigned int n); 34 | 35 | 36 | void plic_tresholdSet(unsigned int context, unsigned int priority); 37 | 38 | 39 | u32 plic_tresholdGet(unsigned int context); 40 | 41 | 42 | unsigned int plic_claim(unsigned int context); 43 | 44 | 45 | void plic_complete(unsigned int context, unsigned int n); 46 | 47 | 48 | int plic_enableInterrupt(unsigned int context, unsigned int n); 49 | 50 | 51 | int plic_disableInterrupt(unsigned int context, unsigned int n); 52 | 53 | 54 | void plic_initCore(void); 55 | 56 | 57 | void plic_init(void); 58 | 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /hal/arm/rtt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * SEGGER's Real Time Transfer - simplified driver 5 | * 6 | * Copyright 2023-2024 Phoenix Systems 7 | * Author: Gerard Swiderski, Daniel Sawka 8 | * 9 | * This file is part of Phoenix-RTOS. 10 | * 11 | * %LICENSE% 12 | */ 13 | 14 | #ifndef _PH_HAL_ARM_RTT_H_ 15 | #define _PH_HAL_ARM_RTT_H_ 16 | 17 | 18 | typedef enum { 19 | rtt_dir_up, /* tx: target -> host */ 20 | rtt_dir_down, /* rx: host -> target */ 21 | } rtt_dir_t; 22 | 23 | 24 | typedef enum { 25 | rtt_mode_skip = 0, /* write if the whole message can be written at once; discard the message otherwise */ 26 | rtt_mode_trim = 1, /* write anything if possible; discard the remaining unwritten data otherwise */ 27 | rtt_mode_blocking = 2, /* wait until writable */ 28 | } rtt_mode_t; 29 | 30 | 31 | /* Initialize rtt internal structures */ 32 | int _hal_rttInit(void); 33 | 34 | 35 | /* Non-blocking write to channel */ 36 | int _hal_rttWrite(unsigned int chan, const void *buf, unsigned int count); 37 | 38 | 39 | /* Check for available space in tx */ 40 | int _hal_rttTxAvail(unsigned int chan); 41 | 42 | 43 | /* Reset fifo pointers */ 44 | int _hal_rttReset(unsigned int chan, rtt_dir_t dir); 45 | 46 | 47 | #endif /* end of HAL_ARM_RTT_H_ */ 48 | -------------------------------------------------------------------------------- /hal/riscv64/generic/console.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL console (via SBI) 7 | * 8 | * Copyright 2018, 2020 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #include "hal/console.h" 17 | #include "hal/spinlock.h" 18 | #include "hal/riscv64/sbi.h" 19 | 20 | 21 | static struct { 22 | spinlock_t spinlock; 23 | } console_common; 24 | 25 | 26 | void _hal_consolePrint(const char *s) 27 | { 28 | while (*s != '\0') { 29 | hal_consolePutch(*s++); 30 | } 31 | } 32 | 33 | 34 | void hal_consolePrint(int attr, const char *s) 35 | { 36 | if (attr == ATTR_BOLD) { 37 | _hal_consolePrint(CONSOLE_BOLD); 38 | } 39 | else if (attr != ATTR_USER) { 40 | _hal_consolePrint(CONSOLE_CYAN); 41 | } 42 | 43 | _hal_consolePrint(s); 44 | _hal_consolePrint(CONSOLE_NORMAL); 45 | } 46 | 47 | 48 | void hal_consolePutch(char c) 49 | { 50 | spinlock_ctx_t sc; 51 | 52 | hal_spinlockSet(&console_common.spinlock, &sc); 53 | hal_sbiPutchar(c); 54 | hal_spinlockClear(&console_common.spinlock, &sc); 55 | } 56 | 57 | 58 | __attribute__((section(".init"))) void _hal_consoleInit(void) 59 | { 60 | hal_spinlockCreate(&console_common.spinlock, "console.spinlock"); 61 | } 62 | -------------------------------------------------------------------------------- /hal/hal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Hardware Abstraction Layer (ARMv7) 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_HAL_H_ 17 | #define _PH_HAL_HAL_H_ 18 | 19 | #include "cpu.h" 20 | /* TODO: remove config file after cleaning up 'includes' directory */ 21 | #include "config.h" 22 | #include "string.h" 23 | #include "console.h" 24 | #include "pmap.h" 25 | #include "spinlock.h" 26 | #include "interrupts.h" 27 | #include "exceptions.h" 28 | #include "timer.h" 29 | #include "types.h" 30 | 31 | 32 | typedef struct _hal_tls_t { 33 | ptr_t tls_base; 34 | ptr_t arm_m_tls; 35 | size_t tdata_sz; 36 | size_t tbss_sz; 37 | size_t tls_sz; 38 | } hal_tls_t; 39 | 40 | 41 | void *hal_syspageRelocate(void *data); 42 | 43 | 44 | ptr_t hal_syspageAddr(void); 45 | 46 | 47 | void hal_wdgReload(void); 48 | 49 | 50 | int hal_platformctl(void *ptr); 51 | 52 | 53 | int hal_started(void); 54 | 55 | 56 | void _hal_start(void); 57 | 58 | 59 | void _hal_init(void); 60 | 61 | 62 | void hal_lockScheduler(void); 63 | 64 | 65 | void _hal_cpuInit(void); 66 | 67 | 68 | void _hal_platformInit(void); 69 | 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /hal/sparcv8leon/gaisler/gr716/_init.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Low level initialization 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #define __ASSEMBLY__ 17 | 18 | #include "config.h" 19 | #include 20 | 21 | .extern syspage 22 | 23 | .section ".text" 24 | .align 4 25 | .global _init 26 | _init: 27 | /* Set up trap table */ 28 | sethi %hi(_trap_table), %g1 29 | wr %g1, %tbr 30 | 31 | wr %g0, 0x2, %wim 32 | 33 | /* Point to syspage */ 34 | sethi %hi(syspage), %g1 35 | st %g2, [%g1 + %lo(syspage)] 36 | 37 | sethi %hi(relOffs), %g1 38 | st %g0, [%g1 + %lo(relOffs)] 39 | 40 | /* Set PSR to "supervisor", enable traps, disable interrupts, set CWP to 0 */ 41 | mov %psr, %g1 42 | or %g1, (PSR_ET | PSR_S | PSR_PIL), %g1 43 | andn %g1, (PSR_CWP), %g1 44 | wr %g1, %psr 45 | nop 46 | nop 47 | nop 48 | 49 | /* Set stack pointer */ 50 | clr %fp 51 | sethi %hi(_init_stack), %g1 52 | ld [%g1 + %lo(_init_stack)], %sp 53 | sub %sp, 0x60, %sp 54 | 55 | call main 56 | mov %g0, %g1 57 | .size _init, . - _init 58 | 59 | .align 8 60 | .global _init_stack 61 | _init_stack: 62 | .word _end + SIZE_KSTACK 63 | -------------------------------------------------------------------------------- /proc/name.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Names resolving 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Author: Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_PROC_NAME_H_ 17 | #define _PH_PROC_NAME_H_ 18 | 19 | #include "hal/hal.h" 20 | 21 | 22 | int proc_portRegister(u32 port, const char *name, oid_t *oid); 23 | 24 | 25 | void proc_portUnregister(const char *name); 26 | 27 | 28 | int proc_portLookup(const char *name, oid_t *file, oid_t *dev); 29 | 30 | 31 | int proc_lookup(const char *name, oid_t *file, oid_t *dev); 32 | 33 | 34 | int proc_read(oid_t oid, off_t offs, void *buf, size_t sz, unsigned int mode); 35 | 36 | 37 | int proc_link(oid_t dir, oid_t oid, const char *name); 38 | 39 | 40 | int proc_unlink(oid_t dir, oid_t oid, const char *name); 41 | 42 | 43 | int proc_create(u32 port, int type, unsigned int mode, oid_t dev, oid_t dir, char *name, oid_t *oid); 44 | 45 | 46 | int proc_close(oid_t oid, unsigned int mode); 47 | 48 | 49 | int proc_open(oid_t oid, unsigned int mode); 50 | 51 | 52 | off_t proc_size(oid_t oid); 53 | 54 | 55 | int proc_write(oid_t oid, off_t offs, void *buf, size_t sz, unsigned int mode); 56 | 57 | 58 | void _name_init(void); 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /hal/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * List 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Jacek Popko, Pawel Pisarczyk, Hubert Badocha 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | 17 | #ifndef _PH_HAL_LIST_H_ 18 | #define _PH_HAL_LIST_H_ 19 | 20 | 21 | /* list has to be a struct with pointer fields prev and next to another list */ 22 | 23 | 24 | #define HAL_LIST_ADD(list, t) \ 25 | do { \ 26 | if ((t) == NULL) { \ 27 | break; \ 28 | } \ 29 | if (*(list) == NULL) { \ 30 | (t)->next = (t); \ 31 | (t)->prev = (t); \ 32 | (*(list)) = (t); \ 33 | break; \ 34 | } \ 35 | (t)->prev = (*(list))->prev; \ 36 | (*(list))->prev->next = (t); \ 37 | (t)->next = (*(list)); \ 38 | (*(list))->prev = (t); \ 39 | } while (0) 40 | 41 | 42 | #define HAL_LIST_REMOVE(list, t) \ 43 | do { \ 44 | if ((t) == NULL) { \ 45 | break; \ 46 | } \ 47 | if (((t)->next == (t)) && ((t)->prev == (t))) { \ 48 | (*(list)) = NULL; \ 49 | } \ 50 | else { \ 51 | (t)->prev->next = (t)->next; \ 52 | (t)->next->prev = (t)->prev; \ 53 | if ((t) == (*(list))) { \ 54 | (*(list)) = (t)->next; \ 55 | } \ 56 | } \ 57 | (t)->next = NULL; \ 58 | (t)->prev = NULL; \ 59 | } while (0) 60 | 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /proc/resource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Process resources 7 | * 8 | * Copyright 2017, 2018, 2023 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_PROC_RESOURCE_H_ 17 | #define _PH_PROC_RESOURCE_H_ 18 | 19 | #include "hal/hal.h" 20 | #include "threads.h" 21 | #include "lib/idtree.h" 22 | 23 | 24 | struct _mutex_t; 25 | struct _cond_t; 26 | struct _usrintr_t; 27 | 28 | 29 | typedef struct _resource_t { 30 | idnode_t linkage; 31 | int refs; 32 | /* clang-format off */ 33 | enum { rtLock = 0, rtCond, rtInth } type; 34 | /* clang-format on */ 35 | 36 | union { 37 | struct _cond_t *cond; 38 | struct _mutex_t *mutex; 39 | struct _userintr_t *userintr; 40 | } payload; 41 | } resource_t; 42 | 43 | 44 | int resource_alloc(process_t *process, resource_t *r); 45 | 46 | 47 | resource_t *resource_get(process_t *process, int id); 48 | 49 | 50 | int resource_put(process_t *process, resource_t *r); 51 | 52 | 53 | int proc_resourceDestroy(process_t *process, int id); 54 | 55 | 56 | void proc_resourcesDestroy(process_t *process); 57 | 58 | 59 | int proc_resourcesCopy(process_t *source); 60 | 61 | 62 | void _resource_init(process_t *process); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /vm/amap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Virtual memory manager - amap abstraction 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_VM_AMAP_H_ 17 | #define _PH_VM_AMAP_H_ 18 | 19 | #include "hal/hal.h" 20 | #include "map.h" 21 | 22 | struct _vm_map_t; 23 | struct _vm_object_t; 24 | 25 | 26 | typedef struct _anon_t { 27 | lock_t lock; 28 | int refs; 29 | page_t *page; 30 | } anon_t; 31 | 32 | 33 | typedef struct _amap_t { 34 | lock_t lock; 35 | size_t size; 36 | int refs; 37 | anon_t *anons[]; 38 | } amap_t; 39 | 40 | 41 | page_t *amap_page(struct _vm_map_t *map, amap_t *amap, struct _vm_object_t *o, void *vaddr, size_t aoffs, u64 offs, vm_prot_t prot); 42 | 43 | 44 | void amap_clear(amap_t *amap, size_t offset, size_t size); 45 | 46 | 47 | void amap_putanons(amap_t *amap, size_t offset, size_t size); 48 | 49 | 50 | void amap_getanons(amap_t *amap, size_t offset, size_t size); 51 | 52 | 53 | amap_t *amap_create(amap_t *amap, size_t *offset, size_t size); 54 | 55 | 56 | void amap_put(amap_t *amap); 57 | 58 | 59 | amap_t *amap_ref(amap_t *amap); 60 | 61 | 62 | void _amap_init(struct _vm_map_t *kmap, struct _vm_object_t *kernel); 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /proc/ports.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Ports 7 | * 8 | * Copyright 2017, 2018, 2023 Phoenix Systems 9 | * Author: Jakub Sejdak, Pawel Pisarczyk, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_PROC_PORT_H_ 17 | #define _PH_PROC_PORT_H_ 18 | 19 | #include "hal/hal.h" 20 | #include "lib/lib.h" 21 | #include "msg.h" 22 | #include "process.h" 23 | #include "threads.h" 24 | 25 | 26 | typedef struct _port_t { 27 | idnode_t linkage; 28 | struct _port_t *next; 29 | struct _port_t *prev; 30 | 31 | idtree_t rid; 32 | 33 | kmsg_t *kmessages; 34 | process_t *owner; 35 | int refs, closed; 36 | 37 | spinlock_t spinlock; 38 | lock_t lock; 39 | thread_t *threads; 40 | msg_t *current; 41 | } port_t; 42 | 43 | /* FIXME - use int for port handle. 44 | * Or even better, use dedicated type. */ 45 | 46 | int proc_portCreate(u32 *id); 47 | 48 | 49 | void proc_portDestroy(u32 port); 50 | 51 | 52 | void proc_portsDestroy(process_t *proc); 53 | 54 | 55 | port_t *proc_portGet(u32 id); 56 | 57 | 58 | void port_put(port_t *p, int destroy); 59 | 60 | 61 | msg_rid_t proc_portRidAlloc(port_t *p, kmsg_t *kmsg); 62 | 63 | 64 | kmsg_t *proc_portRidGet(port_t *p, msg_rid_t rid); 65 | 66 | 67 | void _port_init(void); 68 | 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /hal/riscv64/gaisler/gr765/gr765.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL internal functions for riscv64-gr765 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #include "hal/gaisler/ambapp.h" 17 | 18 | #include "hal/hal.h" 19 | #include "include/arch/riscv64/riscv64.h" 20 | 21 | static struct { 22 | spinlock_t lock; 23 | } gr765_common; 24 | 25 | 26 | int hal_platformctl(void *ptr) 27 | { 28 | platformctl_t *pctl = ptr; 29 | spinlock_ctx_t sc; 30 | int ret = -1; 31 | 32 | hal_spinlockSet(&gr765_common.lock, &sc); 33 | 34 | switch (pctl->type) { 35 | case pctl_reboot: 36 | if ((pctl->action == pctl_set) && (pctl->task.reboot.magic == PCTL_REBOOT_MAGIC)) { 37 | hal_cpuReboot(); 38 | } 39 | break; 40 | 41 | case pctl_iomux: 42 | ret = 0; 43 | break; 44 | 45 | case pctl_ambapp: 46 | if (pctl->action == pctl_get) { 47 | ret = ambapp_findSlave(pctl->task.ambapp.dev, pctl->task.ambapp.instance); 48 | } 49 | break; 50 | 51 | default: 52 | break; 53 | } 54 | hal_spinlockClear(&gr765_common.lock, &sc); 55 | 56 | return ret; 57 | } 58 | 59 | 60 | void _hal_platformInit(void) 61 | { 62 | hal_spinlockCreate(&gr765_common.lock, "gr765_common.lock"); 63 | ambapp_init(); 64 | } 65 | -------------------------------------------------------------------------------- /hal/riscv64/gaisler/grfpga/grfpga.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL internal functions for riscv64-grfpga 7 | * 8 | * Copyright 2024 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #include "hal/gaisler/ambapp.h" 17 | 18 | #include "hal/hal.h" 19 | #include "include/arch/riscv64/riscv64.h" 20 | 21 | static struct { 22 | spinlock_t lock; 23 | } grfpga_common; 24 | 25 | 26 | int hal_platformctl(void *ptr) 27 | { 28 | platformctl_t *pctl = ptr; 29 | spinlock_ctx_t sc; 30 | int ret = -1; 31 | 32 | hal_spinlockSet(&grfpga_common.lock, &sc); 33 | 34 | switch (pctl->type) { 35 | case pctl_reboot: 36 | if ((pctl->action == pctl_set) && (pctl->task.reboot.magic == PCTL_REBOOT_MAGIC)) { 37 | hal_cpuReboot(); 38 | } 39 | break; 40 | 41 | case pctl_iomux: 42 | ret = 0; 43 | break; 44 | 45 | case pctl_ambapp: 46 | if (pctl->action == pctl_get) { 47 | ret = ambapp_findSlave(pctl->task.ambapp.dev, pctl->task.ambapp.instance); 48 | } 49 | break; 50 | 51 | default: 52 | break; 53 | } 54 | hal_spinlockClear(&grfpga_common.lock, &sc); 55 | 56 | return ret; 57 | } 58 | 59 | 60 | void _hal_platformInit(void) 61 | { 62 | hal_spinlockCreate(&grfpga_common.lock, "grfpga_common.lock"); 63 | ambapp_init(); 64 | } 65 | -------------------------------------------------------------------------------- /proc/msg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Messages 7 | * 8 | * Copyright 2017, 2018 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Jakub Sejdak, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_PROC_MSG_H_ 17 | #define _PH_PROC_MSG_H_ 18 | 19 | #include "hal/hal.h" 20 | #include "include/errno.h" 21 | #include "include/msg.h" 22 | #include "lib/lib.h" 23 | #include "threads.h" 24 | 25 | 26 | typedef struct _kmsg_t { 27 | #ifndef NOMMU 28 | msg_t msg; 29 | #else 30 | msg_t *msg; 31 | #endif 32 | 33 | struct _kmsg_t *next; 34 | struct _kmsg_t *prev; 35 | 36 | idnode_t idlinkage; 37 | 38 | thread_t *threads; 39 | process_t *src; 40 | volatile int state; 41 | 42 | #ifndef NOMMU 43 | struct _kmsg_layout_t { 44 | void *bvaddr; 45 | u64 boffs; 46 | void *w; 47 | page_t *bp; 48 | 49 | void *evaddr; 50 | u64 eoffs; 51 | page_t *ep; 52 | } i, o; 53 | #else 54 | void *imapped; 55 | void *omapped; 56 | #endif 57 | } kmsg_t; 58 | 59 | 60 | /* 61 | * Message passing 62 | */ 63 | 64 | 65 | int proc_send(u32 port, msg_t *msg); 66 | 67 | 68 | int proc_recv(u32 port, msg_t *msg, msg_rid_t *rid); 69 | 70 | 71 | int proc_respond(u32 port, msg_t *msg, msg_rid_t rid); 72 | 73 | 74 | void _msg_init(vm_map_t *kmap, vm_object_t *kernel); 75 | 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /hal/ia32/hal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Hardware Abstraction Layer (IA32 PC) 7 | * 8 | * Copyright 2012, 2016 Phoenix Systems 9 | * Copyright 2006 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #include "hal/hal.h" 18 | #include "hal/spinlock.h" 19 | #include "hal/console.h" 20 | #include "hal/exceptions.h" 21 | #include "hal/interrupts.h" 22 | #include "hal/cpu.h" 23 | #include "hal/pmap.h" 24 | #include "hal/timer.h" 25 | #include "pci.h" 26 | #include "halsyspage.h" 27 | 28 | 29 | struct { 30 | int started; 31 | } hal_common; 32 | 33 | 34 | syspage_t *syspage; 35 | 36 | 37 | void *hal_syspageRelocate(void *data) 38 | { 39 | return ((u8 *)data + VADDR_KERNEL); 40 | } 41 | 42 | 43 | ptr_t hal_syspageAddr(void) 44 | { 45 | return (ptr_t)syspage; 46 | } 47 | 48 | 49 | int hal_started(void) 50 | { 51 | return hal_common.started; 52 | } 53 | 54 | 55 | void _hal_start(void) 56 | { 57 | hal_common.started = 1; 58 | } 59 | 60 | 61 | void hal_wdgReload(void) 62 | { 63 | } 64 | 65 | 66 | void _hal_init(void) 67 | { 68 | 69 | _hal_spinlockInit(); 70 | _hal_consoleInit(); 71 | 72 | 73 | _hal_exceptionsInit(); 74 | _hal_interruptsInit(); 75 | 76 | _hal_cpuInit(); 77 | _hal_pciInit(); 78 | 79 | hal_common.started = 0; 80 | return; 81 | } 82 | -------------------------------------------------------------------------------- /lib/cbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Circular buffer 7 | * 8 | * Copyright 2019 Phoenix Systems 9 | * Author: Jan Sikorski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_LIB_CBUFFER_H_ 17 | #define _PH_LIB_CBUFFER_H_ 18 | 19 | typedef struct { 20 | size_t sz, r, w; 21 | unsigned char full, mark; 22 | void *data; 23 | } cbuffer_t; 24 | 25 | 26 | static inline size_t _cbuffer_free(cbuffer_t *buf) 27 | { 28 | if (buf->w == buf->r) { 29 | return (buf->full != 0U) ? 0U : buf->sz; 30 | } 31 | return (buf->r - buf->w + buf->sz) & (buf->sz - 1U); 32 | } 33 | 34 | 35 | static inline size_t _cbuffer_avail(cbuffer_t *buf) 36 | { 37 | return buf->sz - _cbuffer_free(buf); 38 | } 39 | 40 | 41 | static inline size_t _cbuffer_discard(cbuffer_t *buf, size_t sz) 42 | { 43 | size_t cnt = min(_cbuffer_avail(buf), sz); 44 | buf->r = (buf->r + cnt) & (buf->sz - 1U); 45 | if (cnt > 0U) { 46 | buf->full = 0; 47 | } 48 | return cnt; 49 | } 50 | 51 | 52 | void _cbuffer_init(cbuffer_t *buf, void *data, size_t sz); 53 | 54 | 55 | unsigned int _cbuffer_read(cbuffer_t *buf, void *data, size_t sz); 56 | 57 | 58 | unsigned int _cbuffer_write(cbuffer_t *buf, const void *data, size_t sz); 59 | 60 | 61 | unsigned int _cbuffer_peek(const cbuffer_t *buf, void *data, size_t sz); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /hal/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL basic routines 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Copyright 2001, 2005-2006 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk, Artur Wodejko, Aleksander Kaminski 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _PH_HAL_STRING_H_ 18 | #define _PH_HAL_STRING_H_ 19 | 20 | #include "hal/types.h" 21 | 22 | 23 | /* parasoft-suppress-next-line MISRAC2012-RULE_8_6 "Definition in assembly code" */ 24 | void hal_memcpy(void *dst, const void *src, size_t l); 25 | 26 | 27 | int hal_memcmp(const void *ptr1, const void *ptr2, size_t num); 28 | 29 | 30 | /* parasoft-suppress-next-line MISRAC2012-RULE_8_6 "Definition in assembly code" */ 31 | void hal_memset(void *dst, int v, size_t l); 32 | 33 | 34 | size_t hal_strlen(const char *s); 35 | 36 | 37 | int hal_strcmp(const char *s1, const char *s2); 38 | 39 | 40 | int hal_strncmp(const char *s1, const char *s2, size_t n); 41 | 42 | 43 | char *hal_strcpy(char *dest, const char *src); 44 | 45 | 46 | char *hal_strncpy(char *dest, const char *src, size_t n); 47 | 48 | 49 | /* TODO: meaningful naming of signature and implementation (hal_i2s -> hal_ul2str(?), i -> val, b -> base, l -> length, etc.) */ 50 | unsigned long hal_i2s(const char *prefix, char *s, unsigned long i, u8 b, u8 zero); 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /usrv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * User server 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Authors: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #include "hal/hal.h" 17 | 18 | #include "usrv.h" 19 | #include "log/log.h" 20 | #include "include/ioctl.h" 21 | 22 | #include "proc/threads.h" 23 | #include "proc/msg.h" 24 | #include "proc/ports.h" 25 | 26 | 27 | #define USRV_ID_LOG 0 28 | 29 | 30 | static struct { 31 | oid_t oid; 32 | } usrv_common; 33 | 34 | 35 | static void usrv_msgthr(void *arg) 36 | { 37 | msg_t msg; 38 | msg_rid_t rid; 39 | oid_t oid = usrv_common.oid; 40 | 41 | for (;;) { 42 | if (proc_recv(oid.port, &msg, &rid) != 0) { 43 | continue; 44 | } 45 | 46 | oid.id = msg.oid.id; 47 | 48 | switch (oid.id) { 49 | case USRV_ID_LOG: 50 | log_msgHandler(&msg, oid, rid); 51 | break; 52 | 53 | default: 54 | msg.o.err = -ENOSYS; 55 | (void)proc_respond(oid.port, &msg, rid); 56 | break; 57 | } 58 | } 59 | } 60 | 61 | 62 | void _usrv_start(void) 63 | { 64 | /* Create port 0 for /dev/kmsg */ 65 | if (proc_portCreate(&usrv_common.oid.port) != 0) { 66 | return; 67 | } 68 | 69 | (void)proc_threadCreate(NULL, usrv_msgthr, NULL, 1, (size_t)SIZE_KSTACK, NULL, 0, NULL); 70 | } 71 | 72 | 73 | void _usrv_init(void) 74 | { 75 | _log_init(); 76 | } 77 | -------------------------------------------------------------------------------- /hal/armv7m/imxrt/117x/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Configuration file for i.MX RT117x 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Author: Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_CONFIG_H_ 17 | #define _PH_HAL_CONFIG_H_ 18 | 19 | #define SIZE_INTERRUPTS 217 20 | 21 | #define TIMER_US2CYC(x) (x) 22 | #define TIMER_CYC2US(x) (x) 23 | 24 | #ifndef __ASSEMBLY__ 25 | #include "hal/types.h" 26 | #include "include/arch/armv7m/imxrt/syspage.h" 27 | #include "include/syspage.h" 28 | #include "include/arch/armv7m/imxrt/11xx/imxrt1170.h" 29 | #include "imxrt117x.h" 30 | 31 | #define HAL_NAME_PLATFORM "NXP i.MX RT117x " 32 | 33 | #define GPT1_BASE 0x400ec000 34 | #define GPT2_BASE 0x400f0000 35 | #define GPT3_BASE 0x400f4000 36 | #define GPT4_BASE 0x400f8000 37 | #define GPT5_BASE 0x400fc000 38 | #define GPT6_BASE 0x40100000 39 | #define GPT_BASE GPT1_BASE 40 | 41 | #define GPT1_IRQ gpt1_irq 42 | #define GPT2_IRQ gpt2_irq 43 | #define GPT3_IRQ gpt3_irq 44 | #define GPT4_IRQ gpt4_irq 45 | #define GPT5_IRQ gpt5_irq 46 | #define GPT6_IRQ gpt6_irq 47 | #define GPT_IRQ GPT1_IRQ 48 | 49 | #define GPT_BUS_CLK pctl_clk_gpt1 50 | #define GPT_FREQ_MHZ 24 51 | #define GPT_OSC_PRESCALER 8 52 | #define GPT_PRESCALER (GPT_FREQ_MHZ / GPT_OSC_PRESCALER) 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /proc/lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Lock definition 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Author: Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_PROC_LOCK_H_ 17 | #define _PH_PROC_LOCK_H_ 18 | 19 | #include "hal/hal.h" 20 | #include "include/threads.h" 21 | 22 | 23 | typedef struct _lock_t { 24 | spinlock_t spinlock; /* Spinlock */ 25 | struct _thread_t *owner; /* Owner thread */ 26 | struct _thread_t *queue; /* Waiting threads */ 27 | struct _lock_t *prev, *next; /* Doubly linked list */ 28 | const char *name; 29 | struct lockAttr attr; 30 | unsigned int depth; /* Used with recursive locks */ 31 | } lock_t; 32 | 33 | 34 | extern const struct lockAttr proc_lockAttrDefault; 35 | 36 | 37 | int proc_lockSet(lock_t *lock); 38 | 39 | 40 | int proc_lockSet2(lock_t *l1, lock_t *l2); 41 | 42 | 43 | int proc_lockTry(lock_t *lock); 44 | 45 | 46 | /* `timeout` - in microseconds, absolute time relative to monotonic clock */ 47 | int proc_lockWait(struct _thread_t **queue, lock_t *lock, time_t timeout); 48 | 49 | 50 | int proc_lockClear(lock_t *lock); 51 | 52 | 53 | int proc_lockSetInterruptible(lock_t *lock); 54 | 55 | 56 | int proc_lockInit(lock_t *lock, const struct lockAttr *attr, const char *name); 57 | 58 | 59 | int proc_lockDone(lock_t *lock); 60 | 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /hal/armv8m/nrf/91/nrf91.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * nRF91 basic peripherals control functions 7 | * 8 | * Copyright 2022 Phoenix Systems 9 | * Author: Damian Loewnau 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_NRF91_H_ 17 | #define _PH_HAL_NRF91_H_ 18 | 19 | #include "hal/types.h" 20 | #include "hal/pmap.h" 21 | 22 | #include "include/arch/armv8m/nrf/91/nrf9160.h" 23 | 24 | 25 | /* clang-format off */ 26 | enum { gpio_input = 0, gpio_output }; 27 | enum { gpio_low = 0, gpio_high }; 28 | enum { gpio_nopull = 0, gpio_pulldown, gpio_pullup = 3}; 29 | 30 | 31 | enum { scb_actlr = 2, scb_cpuid = 832, scb_icsr, scb_vtor, scb_aircr, scb_scr, scb_ccr, scb_shp1, scb_shp2, 32 | scb_shp3, scb_shcsr, scb_cfsr, scb_mmsr, scb_bfsr, scb_ufsr, scb_hfsr, scb_mmar, scb_bfar, scb_afsr }; 33 | /* clang-format on */ 34 | 35 | 36 | int hal_platformctl(void *); 37 | 38 | 39 | int _nrf91_systickInit(u32 interval); 40 | 41 | 42 | int _nrf91_gpioConfig(u8 pin, u8 dir, u8 pull); 43 | 44 | 45 | int _nrf91_gpioSet(u8 pin, u8 val); 46 | 47 | 48 | void _nrf91_scbSetPriorityGrouping(u32 group); 49 | 50 | 51 | u32 _nrf91_scbGetPriorityGrouping(void); 52 | 53 | 54 | void _nrf91_scbSetPriority(s8 excpn, u32 priority); 55 | 56 | 57 | u32 _nrf91_scbGetPriority(s8 excpn); 58 | 59 | 60 | unsigned int _nrf91_cpuid(void); 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /include/arch/sparcv8leon/gr712rc/gr712rc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * GR712RC basic peripherals control functions 7 | * 8 | * Copyright 2023 Phoenix Systems 9 | * Author: Lukasz Leczkowski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_ARCH_GR712RC_H_ 17 | #define _PH_ARCH_GR712RC_H_ 18 | 19 | #define PCTL_REBOOT_MAGIC 0xaa55aa55UL 20 | 21 | /* clang-format off */ 22 | 23 | /* Clock gating unit devices */ 24 | 25 | enum { cgudev_eth = 0, cgudev_spw0, cgudev_spw1, cgudev_spw2, cgudev_spw3, cgudev_spw4, cgudev_spw5, cgudev_can, 26 | cgudev_ccsdsEnc = 9, cgudev_ccsdsDec, cgudev_milStd1553 }; 27 | 28 | 29 | typedef struct { 30 | enum { pctl_set = 0, pctl_get } action; 31 | enum { pctl_iomux = 0, pctl_cguctrl, pctl_ambapp, pctl_reboot } type; 32 | 33 | union { 34 | struct { 35 | unsigned char pin; 36 | unsigned char opt; 37 | unsigned char pullup; 38 | unsigned char pulldn; 39 | } iocfg; 40 | 41 | struct { 42 | union { 43 | enum { disable = 0, enable } state; 44 | int stateVal; 45 | } v; 46 | unsigned int cgudev; 47 | } cguctrl; 48 | 49 | struct { 50 | struct _ambapp_dev_t *dev; 51 | unsigned int *instance; 52 | } ambapp; 53 | 54 | struct { 55 | unsigned int magic; 56 | } reboot; 57 | } task; 58 | } __attribute__((packed)) platformctl_t; 59 | 60 | /* clang-format on */ 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /test/proc-fpu.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include
3 | #include 4 | 5 | 6 | #define LEN 128 7 | 8 | 9 | int test_fpuThread1(void *arg) 10 | { 11 | int i; 12 | double f[LEN]; 13 | main_printf(ATTR_INFO, "test: [fpuThread1] start\n"); 14 | 15 | f[0] = 1 - 0.0123456789; 16 | for (;;) { 17 | for (i = 1; i < LEN; i++) { 18 | f[i] = f[i - 1] * (1 - 0.00123456789); 19 | } 20 | for (i = 0; i < LEN; i++) { 21 | if (f[i] >= 1 || f[i] <= 0) { 22 | main_printf(ATTR_ERROR, "test: [fpuThread1] invalid result f[%d] = %f\n", i, f[i]); 23 | } 24 | } 25 | f[0] = f[LEN - 1]; 26 | if (f[0] < 0.005) { 27 | f[0] = 1 - 0.0123456789; 28 | } 29 | } 30 | return 0; 31 | } 32 | 33 | int test_fpuThread2(void *arg) 34 | { 35 | int i; 36 | double f[LEN]; 37 | main_printf(ATTR_INFO, "test: [fpuThread2] start\n"); 38 | f[0] = -1 + 0.0123456789; 39 | for (;;) { 40 | for (i = 1; i < LEN; i++) { 41 | f[i] = -1 * f[i - 1] * (-1 + 0.00123456789); 42 | } 43 | for (i = 0; i < LEN; i++) { 44 | if (f[i] <= -1 || f[i] >= 0) { 45 | main_printf(ATTR_ERROR, "test: [fpuThread2] invalid result f[%d] = %f\n", i, f[i]); 46 | } 47 | } 48 | f[0] = f[LEN - 1]; 49 | if (f[0] > -0.005) { 50 | f[0] = -1 + 0.0123456789; 51 | } 52 | } 53 | return 0; 54 | } 55 | 56 | void test_fpuContextSwitching(void) 57 | { 58 | proc_thread(NULL, test_fpuThread1, NULL, 0, NULL, ttRegular); 59 | proc_thread(NULL, test_fpuThread2, NULL, 0, NULL, ttRegular); 60 | } 61 | -------------------------------------------------------------------------------- /hal/armv8m/arch/pmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * pmap interface - machine dependent part of VM subsystem (ARMv8) 7 | * 8 | * Copyright 2017, 2020, 2022 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Aleksander Kaminski, Hubert Buczynski, Damian Loewnau 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_PMAP_ARMV8M_H_ 17 | #define _PH_HAL_PMAP_ARMV8M_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | #define PGHD_PRESENT 0x01U 22 | #define PGHD_USER 0x04U 23 | #define PGHD_WRITE 0x02U 24 | #define PGHD_EXEC 0x00U 25 | #define PGHD_DEV 0x00U 26 | #define PGHD_NOT_CACHED 0x00U 27 | #define PGHD_READ 0x00U 28 | 29 | /* Page flags */ 30 | #define PAGE_FREE 0x00000001U 31 | 32 | #define PAGE_OWNER_BOOT (0U << 1) 33 | #define PAGE_OWNER_KERNEL (1U << 1) 34 | #define PAGE_OWNER_APP (2U << 1) 35 | 36 | #define PAGE_KERNEL_SYSPAGE (1U << 4) 37 | #define PAGE_KERNEL_CPU (2U << 4) 38 | #define PAGE_KERNEL_PTABLE (3U << 4) 39 | #define PAGE_KERNEL_PMAP (4U << 4) 40 | #define PAGE_KERNEL_STACK (5U << 4) 41 | #define PAGE_KERNEL_HEAP (6U << 4) 42 | 43 | 44 | #ifndef __ASSEMBLY__ 45 | 46 | typedef struct _page_t { 47 | addr_t addr; 48 | u8 idx; 49 | u16 flags; 50 | struct _page_t *next; 51 | } page_t; 52 | 53 | 54 | typedef struct _pmap_t { 55 | void *start; 56 | void *end; 57 | u32 regions; 58 | } pmap_t; 59 | 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /hal/armv8r/arch/pmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * pmap interface - machine dependent part of VM subsystem (ARMv8r) 7 | * 8 | * Copyright 2017, 2020, 2022, 2024 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Aleksander Kaminski, Hubert Buczynski, Damian Loewnau 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PH_HAL_PMAP_ARMV8M_H_ 17 | #define _PH_HAL_PMAP_ARMV8M_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | #define PGHD_PRESENT 0x01U 22 | #define PGHD_USER 0x04U 23 | #define PGHD_WRITE 0x02U 24 | #define PGHD_EXEC 0x00U 25 | #define PGHD_DEV 0x00U 26 | #define PGHD_NOT_CACHED 0x00U 27 | #define PGHD_READ 0x00U 28 | 29 | /* Page flags */ 30 | #define PAGE_FREE 0x00000001U 31 | 32 | #define PAGE_OWNER_BOOT (0U << 1) 33 | #define PAGE_OWNER_KERNEL (1U << 1) 34 | #define PAGE_OWNER_APP (2U << 1) 35 | 36 | #define PAGE_KERNEL_SYSPAGE (1U << 4) 37 | #define PAGE_KERNEL_CPU (2U << 4) 38 | #define PAGE_KERNEL_PTABLE (3U << 4) 39 | #define PAGE_KERNEL_PMAP (4U << 4) 40 | #define PAGE_KERNEL_STACK (5U << 4) 41 | #define PAGE_KERNEL_HEAP (6U << 4) 42 | 43 | 44 | #ifndef __ASSEMBLY__ 45 | 46 | typedef struct _page_t { 47 | addr_t addr; 48 | u8 idx; 49 | u16 flags; 50 | struct _page_t *next; 51 | } page_t; 52 | 53 | 54 | typedef struct _pmap_t { 55 | u32 mpr; 56 | void *start; 57 | void *end; 58 | } pmap_t; 59 | 60 | #endif 61 | 62 | #endif 63 | --------------------------------------------------------------------------------