├── .clang-format ├── .codespell_ignore ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── ci.yml │ └── lint.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── hal ├── Makefile ├── aarch64 │ ├── Makefile │ ├── _exceptions.S │ ├── _init.S │ ├── _memcpy.S │ ├── _memset.S │ ├── aarch64.h │ ├── arch │ │ ├── cpu.h │ │ ├── exceptions.h │ │ ├── interrupts.h │ │ ├── pmap.h │ │ ├── spinlock.h │ │ └── types.h │ ├── cache.c │ ├── cpu.c │ ├── dtb.c │ ├── dtb.h │ ├── exceptions.c │ ├── hal.c │ ├── halsyspage.h │ ├── interrupts_gicv2.c │ ├── interrupts_gicv2.h │ ├── pmap.c │ ├── spinlock.c │ ├── string.c │ └── zynqmp │ │ ├── Makefile │ │ ├── config.h │ │ ├── console.c │ │ ├── timer.c │ │ ├── zynqmp.c │ │ ├── zynqmp.h │ │ └── zynqmp_regs.h ├── arm │ ├── Makefile │ ├── barriers.h │ ├── rtt.c │ ├── rtt.h │ ├── scs.c │ └── scs.h ├── armv7a │ ├── Makefile │ ├── _armv7a.S │ ├── _interrupts.S │ ├── _memcpy.S │ ├── _memset.S │ ├── arch │ │ ├── cpu.h │ │ ├── exceptions.h │ │ ├── interrupts.h │ │ ├── pmap.h │ │ ├── spinlock.h │ │ └── types.h │ ├── armv7a.h │ ├── cpu.c │ ├── exceptions.c │ ├── hal.c │ ├── halsyspage.h │ ├── imx6ull │ │ ├── Makefile │ │ ├── _init.S │ │ ├── _memtest.S │ │ ├── config.h │ │ ├── console.c │ │ ├── imx6ull.c │ │ ├── interrupts.c │ │ ├── memtest.c │ │ └── timer.c │ ├── pmap.c │ ├── spinlock.c │ ├── string.c │ └── zynq7000 │ │ ├── Makefile │ │ ├── _init.S │ │ ├── config.h │ │ ├── console.c │ │ ├── interrupts.c │ │ ├── timer.c │ │ ├── zynq.c │ │ └── zynq.h ├── armv7m │ ├── Makefile │ ├── _memcpy.S │ ├── _memset.S │ ├── arch │ │ ├── cpu.h │ │ ├── elf.h │ │ ├── exceptions.h │ │ ├── interrupts.h │ │ ├── pmap.h │ │ ├── spinlock.h │ │ └── types.h │ ├── cpu.c │ ├── exceptions.c │ ├── hal.c │ ├── imxrt │ │ ├── 10xx │ │ │ ├── Makefile │ │ │ ├── config.h │ │ │ ├── console.c │ │ │ ├── imxrt10xx.c │ │ │ └── imxrt10xx.h │ │ ├── 117x │ │ │ ├── Makefile │ │ │ ├── config.h │ │ │ ├── console.c │ │ │ ├── imxrt117x.c │ │ │ └── imxrt117x.h │ │ ├── Makefile │ │ ├── _init.S │ │ ├── halsyspage.h │ │ ├── interrupts.c │ │ └── timer.c │ ├── pmap.c │ ├── spinlock.c │ ├── stm32 │ │ ├── Makefile │ │ ├── _init.S │ │ ├── config.h │ │ ├── halsyspage.h │ │ ├── interrupts.c │ │ ├── l1 │ │ │ ├── Makefile │ │ │ ├── console.c │ │ │ ├── stm32l1.c │ │ │ └── timer.c │ │ ├── l4 │ │ │ ├── Makefile │ │ │ ├── console.c │ │ │ ├── stm32l4.c │ │ │ └── timer.c │ │ ├── stm32-timer.h │ │ └── stm32.h │ └── string.c ├── armv7r │ ├── Makefile │ ├── _armv7r.S │ ├── _interrupts.S │ ├── _memcpy.S │ ├── _memset.S │ ├── arch │ │ ├── cpu.h │ │ ├── elf.h │ │ ├── exceptions.h │ │ ├── interrupts.h │ │ ├── pmap.h │ │ ├── spinlock.h │ │ └── types.h │ ├── armv7r.h │ ├── cpu.c │ ├── exceptions.c │ ├── hal.c │ ├── halsyspage.h │ ├── pmap.c │ ├── spinlock.c │ ├── string.c │ └── zynqmp │ │ ├── Makefile │ │ ├── _init.S │ │ ├── config.h │ │ ├── console.c │ │ ├── interrupts.c │ │ ├── timer.c │ │ ├── zynqmp.c │ │ ├── zynqmp.h │ │ └── zynqmp_regs.h ├── armv8m │ ├── Makefile │ ├── _memcpy.S │ ├── _memset.S │ ├── arch │ │ ├── cpu.h │ │ ├── elf.h │ │ ├── exceptions.h │ │ ├── interrupts.h │ │ ├── pmap.h │ │ ├── spinlock.h │ │ └── types.h │ ├── cpu.c │ ├── exceptions.c │ ├── hal.c │ ├── interrupts.c │ ├── mcx │ │ ├── Makefile │ │ ├── _init.S │ │ └── n94x │ │ │ ├── Makefile │ │ │ ├── config.h │ │ │ ├── console.c │ │ │ ├── mcxn94x.c │ │ │ ├── mcxn94x.h │ │ │ └── timer.c │ ├── nrf │ │ ├── 91 │ │ │ ├── Makefile │ │ │ ├── config.h │ │ │ ├── console.c │ │ │ ├── nrf91.c │ │ │ ├── nrf91.h │ │ │ └── timer.c │ │ ├── Makefile │ │ └── _init.S │ ├── pmap.c │ ├── spinlock.c │ └── string.c ├── armv8r │ ├── Makefile │ ├── _armv8r.S │ ├── _interrupts.S │ ├── _memcpy.S │ ├── _memset.S │ ├── arch │ │ ├── cpu.h │ │ ├── elf.h │ │ ├── exceptions.h │ │ ├── interrupts.h │ │ ├── pmap.h │ │ ├── spinlock.h │ │ └── types.h │ ├── armv8r.h │ ├── cpu.c │ ├── exceptions.c │ ├── hal.c │ ├── halsyspage.h │ ├── mps3an536 │ │ ├── Makefile │ │ ├── _init.S │ │ ├── config.h │ │ ├── console.c │ │ ├── interrupts.c │ │ ├── mps3an536.c │ │ └── timer.c │ ├── pmap.c │ ├── spinlock.c │ └── string.c ├── common.c ├── console.h ├── cpu.h ├── elf.h ├── exceptions.h ├── gaisler │ ├── Makefile │ ├── ambapp.c │ └── ambapp.h ├── hal.h ├── ia32 │ ├── Makefile │ ├── _exceptions.S │ ├── _init.S │ ├── _interrupts.S │ ├── arch │ │ ├── cpu.h │ │ ├── exceptions.h │ │ ├── interrupts.h │ │ ├── pmap.h │ │ ├── spinlock.h │ │ ├── tlb.h │ │ └── types.h │ ├── config.h │ ├── console-serial.c │ ├── console-vga.c │ ├── console.c │ ├── console.h │ ├── cpu.c │ ├── exceptions.c │ ├── hal.c │ ├── halsyspage.h │ ├── ia32.h │ ├── init.c │ ├── init.h │ ├── interrupts.c │ ├── pci.c │ ├── pci.h │ ├── pmap.c │ ├── spinlock.c │ ├── string.c │ └── timer.c ├── interrupts.h ├── list.h ├── pmap.h ├── riscv64 │ ├── Makefile │ ├── _cache.S │ ├── _init.S │ ├── _interrupts.S │ ├── _string.S │ ├── arch │ │ ├── cpu.h │ │ ├── exceptions.h │ │ ├── interrupts.h │ │ ├── pmap.h │ │ ├── spinlock.h │ │ └── types.h │ ├── asm-macros.h │ ├── cpu.c │ ├── dtb.c │ ├── dtb.h │ ├── exceptions.c │ ├── generic │ │ ├── Makefile │ │ ├── config.h │ │ ├── console.c │ │ └── generic.c │ ├── hal.c │ ├── halsyspage.h │ ├── interrupts.c │ ├── noelv │ │ ├── Makefile │ │ ├── config.h │ │ ├── console.c │ │ └── noelv.c │ ├── plic.c │ ├── plic.h │ ├── pmap.c │ ├── riscv64.h │ ├── sbi.c │ ├── sbi.h │ ├── spinlock.c │ ├── string.c │ └── timer.c ├── sparcv8leon │ ├── Makefile │ ├── _interrupts-nommu.S │ ├── _interrupts.S │ ├── _traps.S │ ├── arch │ │ ├── cpu.h │ │ ├── elf.h │ │ ├── exceptions.h │ │ ├── interrupts.h │ │ ├── pmap.h │ │ ├── spinlock.h │ │ ├── tlb.h │ │ └── types.h │ ├── cpu.c │ ├── exceptions-nommu.c │ ├── exceptions.c │ ├── gaisler │ │ ├── Makefile │ │ ├── console.c │ │ ├── gaisler.h │ │ ├── generic │ │ │ ├── Makefile │ │ │ ├── _init.S │ │ │ ├── config.h │ │ │ ├── generic.c │ │ │ └── generic.h │ │ ├── gr712rc │ │ │ ├── Makefile │ │ │ ├── _init.S │ │ │ ├── config.h │ │ │ ├── gr712rc.c │ │ │ └── gr712rc.h │ │ ├── gr716 │ │ │ ├── Makefile │ │ │ ├── _init.S │ │ │ ├── config.h │ │ │ ├── gr716.c │ │ │ └── gr716.h │ │ ├── gr740 │ │ │ ├── Makefile │ │ │ ├── _init.S │ │ │ ├── config.h │ │ │ ├── gr740.c │ │ │ └── gr740.h │ │ ├── grlib-tn-0018.h │ │ ├── irqamp.c │ │ ├── irqmp.c │ │ ├── l2cache.c │ │ ├── l2cache.h │ │ └── timer.c │ ├── hal.c │ ├── halsyspage.h │ ├── pmap-nommu.c │ ├── pmap.c │ ├── sparcv8leon.h │ ├── spinlock.c │ ├── srmmu.c │ ├── srmmu.h │ ├── string.c │ └── tlb.c ├── spinlock.h ├── string.h ├── timer.h ├── tlb │ ├── Makefile │ ├── tlb.c │ └── tlb.h └── types.h ├── include ├── arch │ ├── aarch64 │ │ ├── stdtypes.h │ │ ├── types.h │ │ └── zynqmp │ │ │ ├── syspage.h │ │ │ └── zynqmp.h │ ├── armv7a │ │ ├── imx6ull │ │ │ ├── imx6ull.h │ │ │ └── syspage.h │ │ ├── stdtypes.h │ │ ├── types.h │ │ └── zynq7000 │ │ │ ├── syspage.h │ │ │ └── zynq7000.h │ ├── armv7m │ │ ├── imxrt │ │ │ ├── 10xx │ │ │ │ └── imxrt10xx.h │ │ │ ├── 11xx │ │ │ │ └── imxrt1170.h │ │ │ └── syspage.h │ │ ├── stdtypes.h │ │ ├── stm32 │ │ │ ├── l1 │ │ │ │ └── stm32l1.h │ │ │ ├── l4 │ │ │ │ └── stm32l4.h │ │ │ └── syspage.h │ │ └── types.h │ ├── armv7r │ │ ├── stdtypes.h │ │ ├── types.h │ │ └── zynqmp │ │ │ ├── syspage.h │ │ │ └── zynqmp.h │ ├── armv8m │ │ ├── mcx │ │ │ ├── n94x │ │ │ │ └── mcxn94x.h │ │ │ └── syspage.h │ │ ├── nrf │ │ │ ├── 91 │ │ │ │ └── nrf9160.h │ │ │ └── syspage.h │ │ ├── stdtypes.h │ │ └── types.h │ ├── armv8r │ │ ├── mps3an536 │ │ │ ├── mps3an536.h │ │ │ └── syspage.h │ │ ├── stdtypes.h │ │ └── types.h │ ├── ia32 │ │ ├── ia32.h │ │ ├── stdtypes.h │ │ ├── syspage.h │ │ └── types.h │ ├── riscv64 │ │ ├── riscv64.h │ │ ├── stdtypes.h │ │ ├── syspage.h │ │ └── types.h │ └── sparcv8leon │ │ ├── generic │ │ └── generic.h │ │ ├── gr712rc │ │ └── gr712rc.h │ │ ├── gr716 │ │ └── gr716.h │ │ ├── gr740 │ │ └── gr740.h │ │ ├── sparcv8leon.h │ │ ├── stdtypes.h │ │ ├── syspage.h │ │ └── types.h ├── errno.h ├── events.h ├── file.h ├── gaisler │ └── ambapp.h ├── ioctl.h ├── limits.h ├── mman.h ├── msg.h ├── posix-fcntl.h ├── posix-poll.h ├── posix-socket.h ├── posix-stat.h ├── posix-statvfs.h ├── posix-stdio.h ├── posix-timespec.h ├── posix-types.h ├── posix-uio.h ├── signal.h ├── syscalls.h ├── sysinfo.h ├── syspage.h ├── threads.h ├── time.h ├── types.h └── utsname.h ├── lib ├── Makefile ├── assert.c ├── assert.h ├── bsearch.c ├── bsearch.h ├── cbuffer.c ├── cbuffer.h ├── helpers.h ├── idtree.c ├── idtree.h ├── lib.h ├── list.c ├── list.h ├── printf.c ├── printf.h ├── rand.c ├── rand.h ├── rb.c ├── rb.h ├── strtoul.c ├── strtoul.h ├── strutil.c └── strutil.h ├── log ├── Makefile ├── log.c └── log.h ├── main.c ├── posix ├── Makefile ├── fdpass.c ├── fdpass.h ├── inet.c ├── posix.c ├── posix.h ├── posix_private.h ├── sockdefs.h ├── sockport.h └── unix.c ├── proc ├── Makefile ├── cond.c ├── cond.h ├── elf.h ├── lock.h ├── msg-nommu.c ├── msg.c ├── msg.h ├── mutex.c ├── mutex.h ├── name.c ├── name.h ├── ports.c ├── ports.h ├── proc.c ├── proc.h ├── process.c ├── process.h ├── resource.c ├── resource.h ├── threads.c ├── threads.h ├── userintr.c └── userintr.h ├── syscalls.c ├── syscalls.h ├── syspage.c ├── syspage.h ├── test ├── Makefile ├── hw-ddr.c ├── hw-ddr.h ├── msg.c ├── msg.h ├── proc-fpu.c ├── proc-fpu.h ├── proc.c ├── proc.h ├── rb.c ├── rb.h ├── test.c ├── test.h ├── vm.c └── vm.h ├── usrv.c ├── usrv.h └── vm ├── Makefile ├── amap.c ├── amap.h ├── kmalloc.c ├── kmalloc.h ├── map.c ├── map.h ├── object.c ├── object.h ├── page-nommu.c ├── page.c ├── page.h ├── vm.c ├── vm.h ├── zone.c └── zone.h /.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 | -------------------------------------------------------------------------------- /.codespell_ignore: -------------------------------------------------------------------------------- 1 | PTD 2 | ptd 3 | mapp 4 | pmapp 5 | HSI 6 | sie 7 | hart 8 | SME 9 | spOffs 10 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # phoenix-rtos-kernel 2 | This repository contains the source for the Phoenix-RTOS microkernel. 3 | 4 | Supported targets: 5 | 6 | * armv7m4-stm32l4x6 7 | * armv7m7-imxrt105x 8 | * armv7m7-imxrt106x 9 | * armv7m7-imxrt117x 10 | * armv7a7-imx6ull 11 | * armv7a9-zynq7000 12 | * ia32-generic 13 | * riscv64-generic 14 | * sparcv8leon-gr716 15 | * sparcv8leon-gr712rc 16 | * sparcv8leon-generic 17 | 18 | ## Building kernel 19 | 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. 20 | 21 | ## License 22 | This work is licensed under a BSD license. See the LICENSE file for details. 23 | -------------------------------------------------------------------------------- /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/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/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 _HAL_AARCH64_INTERRUPTS_H_ 17 | #define _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 | int (*f)(unsigned int, cpu_context_t *, void *); 26 | void *data; 27 | } intr_handler_t; 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /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 _HAL_AARCH64_SPINLOCK_H_ 17 | #define _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/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 _HAL_AARCH64_TYPES_H_ 17 | #define _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/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 _HAL_DTB_H_ 17 | 18 | #include "hal/types.h" 19 | 20 | #define ntoh16(x) (((x << 8) & 0xff00) | ((x >> 8) & 0xff)) 21 | #define ntoh32(x) ((ntoh16(x) << 16) | ntoh16(x >> 16)) 22 | #define ntoh64(x) ((ntoh32(x) << 32) | ntoh32(x >> 32)) 23 | 24 | typedef struct { 25 | addr_t start; 26 | addr_t end; 27 | } dtb_memBank_t; 28 | 29 | 30 | typedef struct { 31 | addr_t base; 32 | int intr; 33 | } dtb_serial_t; 34 | 35 | 36 | void dtb_getSystem(char **model, char **compatible); 37 | 38 | 39 | int dtb_getCPU(unsigned int n, char **compatible, u32 *clock); 40 | 41 | 42 | void dtb_getMemory(dtb_memBank_t **banks, size_t *nBanks); 43 | 44 | 45 | void dtb_getGIC(addr_t *gicc, addr_t *gicd); 46 | 47 | 48 | void dtb_getSerials(dtb_serial_t **serials, size_t *nSerials); 49 | 50 | 51 | void _dtb_init(addr_t dtbPhys); 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /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 _HAL_SYSPAGE_H_ 17 | #define _HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /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 _INTERRUPTS_GICV2_H_ 17 | #define _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/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 | -------------------------------------------------------------------------------- /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 _HAL_CONFIG_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_ZYNQ_H_ 17 | #define _HAL_ZYNQ_H_ 18 | 19 | #include "hal/cpu.h" 20 | #include "include/arch/aarch64/zynqmp/zynqmp.h" 21 | 22 | 23 | extern int _zynqmp_setMIO(unsigned pin, char l0, char l1, char l2, char l3, char config); 24 | 25 | 26 | extern int _zynq_setDevRst(int dev, unsigned int state); 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /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/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 HAL_ARM_BARRIERS_H_ 17 | #define 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/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 HAL_ARM_RTT_H_ 15 | #define 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/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/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 _HAL_ARMV7A_EXCEPTIONS_H_ 17 | #define _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/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 _HAL_ARMV7A_INTERRUPTS_H_ 17 | #define _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 | int (*f)(unsigned int, cpu_context_t *, void *); 26 | void *data; 27 | } intr_handler_t; 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /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 _HAL_ARMV7A_SPINLOCK_H_ 17 | #define _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/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 _HAL_ARMV7A_TYPES_H_ 17 | #define _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/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 _HAL_SYSPAGE_H_ 17 | #define _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/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 | -------------------------------------------------------------------------------- /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 _HAL_CONFIG_H_ 17 | #define _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/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/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 _HAL_CONFIG_H_ 17 | #define _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/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 _HAL_ZYNQ_H_ 17 | #define _HAL_ZYNQ_H_ 18 | 19 | #include "hal/cpu.h" 20 | 21 | 22 | extern 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 | extern int _zynq_setAmbaClk(u32 dev, u32 state); 26 | 27 | 28 | extern void _zynq_interrupts_setCPU(unsigned int irqn, u32 cpuID); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /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/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 _HAL_ARMV7M_ELF_H_ 17 | #define _HAL_ARMV7M_ELF_H_ 18 | 19 | 20 | #define R_ARM_ABS32 2 21 | #define R_ARM_TARGET1 38 22 | 23 | 24 | static inline int hal_isRelReloc(int relType) 25 | { 26 | return ((relType == R_ARM_ABS32) || (relType == R_ARM_TARGET1)) ? 1 : 0; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /hal/armv7m/arch/exceptions.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _HAL_ARMV7M_EXCEPTIONS_H_ 3 | #define _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/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 _HAL_ARMV7M_INTERRUPTS_H_ 18 | #define _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 | int (*f)(unsigned int, cpu_context_t *, void *); 32 | void *data; 33 | void *got; 34 | } intr_handler_t; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /hal/armv7m/arch/pmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * pmap interface - machine dependent part of VM subsystem (ARMv7 with MPU) 7 | * 8 | * Copyright 2017, 2020 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Aleksander Kaminski, Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _HAL_PMAP_ARMV7M_H_ 17 | #define _HAL_PMAP_ARMV7M_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | /* Architecure dependent page attributes - used for mapping */ 22 | #define PGHD_PRESENT 0x01 23 | #define PGHD_USER 0x04 24 | #define PGHD_WRITE 0x02 25 | #define PGHD_EXEC 0x00 26 | #define PGHD_DEV 0x00 27 | #define PGHD_NOT_CACHED 0x00 28 | #define PGHD_READ 0x00 29 | 30 | /* Page flags */ 31 | #define PAGE_FREE 0x00000001 32 | 33 | #define PAGE_OWNER_BOOT (0 << 1) 34 | #define PAGE_OWNER_KERNEL (1 << 1) 35 | #define PAGE_OWNER_APP (2 << 1) 36 | 37 | #define PAGE_KERNEL_SYSPAGE (1 << 4) 38 | #define PAGE_KERNEL_CPU (2 << 4) 39 | #define PAGE_KERNEL_PTABLE (3 << 4) 40 | #define PAGE_KERNEL_PMAP (4 << 4) 41 | #define PAGE_KERNEL_STACK (5 << 4) 42 | #define PAGE_KERNEL_HEAP (6 << 4) 43 | 44 | 45 | #ifndef __ASSEMBLY__ 46 | 47 | typedef struct _page_t { 48 | addr_t addr; 49 | u8 idx; 50 | u16 flags; 51 | struct _page_t *next; 52 | } page_t; 53 | 54 | 55 | typedef struct _pmap_t { 56 | void *start; 57 | void *end; 58 | u32 regions; 59 | } pmap_t; 60 | 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /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 _HAL_ARMV7M_SPINLOCK_H_ 17 | #define _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/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 _HAL_ARMV7M_TYPES_H_ 17 | #define _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/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 | extern void _hal_cpuInit(void); 26 | 27 | 28 | void *hal_syspageRelocate(void *data) 29 | { 30 | return data; 31 | } 32 | 33 | 34 | ptr_t hal_syspageAddr(void) 35 | { 36 | return (ptr_t)syspage; 37 | } 38 | 39 | 40 | int hal_started(void) 41 | { 42 | return hal_common.started; 43 | } 44 | 45 | 46 | void _hal_start(void) 47 | { 48 | hal_common.started = 1; 49 | } 50 | 51 | 52 | void hal_lockScheduler(void) 53 | { 54 | } 55 | 56 | 57 | void _hal_init(void) 58 | { 59 | hal_common.started = 0; 60 | 61 | _hal_spinlockInit(); 62 | _hal_exceptionsInit(); 63 | _hal_interruptsInit(); 64 | _hal_cpuInit(); 65 | _hal_consoleInit(); 66 | _hal_timerInit(SYSTICK_INTERVAL); 67 | 68 | return; 69 | } 70 | -------------------------------------------------------------------------------- /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/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 _HAL_CONFIG_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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/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 _HAL_CONFIG_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_IMXRT1170_H_ 17 | #define _HAL_IMXRT1170_H_ 18 | 19 | 20 | #include "hal/types.h" 21 | 22 | 23 | extern int hal_platformctl(void *ptr); 24 | 25 | 26 | extern void _imxrt_wdgReload(void); 27 | 28 | 29 | extern int _imxrt_setIOmux(int mux, char sion, char mode); 30 | 31 | 32 | extern int _imxrt_setIOpad(int pad, char sre, char dse, char pue, char pus, char ode, char apc); 33 | 34 | 35 | extern int _imxrt_setIOisel(int isel, char daisy); 36 | 37 | 38 | extern int _imxrt_setDevClock(int clock, int div, int mux, int mfd, int mfn, int state); 39 | 40 | 41 | extern int _imxrt_setDirectLPCG(int clock, int state); 42 | 43 | 44 | extern int _imxrt_getDirectLPCG(int clock, int *state); 45 | 46 | 47 | extern int _imxrt_setLevelLPCG(int clock, int level); 48 | 49 | 50 | extern void _imxrt_platformInit(void); 51 | 52 | 53 | extern void _imxrt_init(void); 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /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/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 _HAL_SYSPAGE_H_ 17 | #define _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/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 l1, $(TARGET_SUBFAMILY))) 9 | include hal/armv7m/stm32/l1/Makefile 10 | else ifneq (, $(findstring l4, $(TARGET_SUBFAMILY))) 11 | include hal/armv7m/stm32/l4/Makefile 12 | endif 13 | 14 | OBJS += $(addprefix $(PREFIX_O)hal/armv7m/stm32/, _init.o interrupts.o) 15 | -------------------------------------------------------------------------------- /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 _HAL_CONFIG_H_ 17 | #define _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/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 _HAL_SYSPAGE_H_ 17 | #define _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/l1/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Phoenix-RTOS kernel (ARMv7-M HAL STM32L1) 3 | # 4 | # Copyright 2016-2017, 2019-2020 Phoenix Systems 5 | # 6 | 7 | OBJS += $(addprefix $(PREFIX_O)hal/armv7m/stm32/l1/, stm32l1.o console.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/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 _HAL_STM32TIMER_H_ 17 | #define _HAL_STM32TIMER_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | extern void timer_jiffiesAdd(time_t t); 22 | 23 | 24 | extern void timer_setAlarm(time_t us); 25 | 26 | 27 | #endif -------------------------------------------------------------------------------- /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 11 | $(error Unsupported TARGET) 12 | endif 13 | 14 | CFLAGS += -Ihal/armv7r 15 | 16 | OBJS += $(addprefix $(PREFIX_O)hal/armv7r/, _armv7r.o _interrupts.o _memcpy.o _memset.o \ 17 | cpu.o exceptions.o hal.o pmap.o spinlock.o string.o) 18 | -------------------------------------------------------------------------------- /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 _HAL_ARMV7R_ELF_H_ 17 | #define _HAL_ARMV7R_ELF_H_ 18 | 19 | 20 | #define R_ARM_ABS32 2 21 | #define R_ARM_TARGET1 38 22 | 23 | 24 | static inline int hal_isRelReloc(int relType) 25 | { 26 | return ((relType == R_ARM_ABS32) || (relType == R_ARM_TARGET1)) ? 1 : 0; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /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 _HAL_ARMV7R_EXCEPTIONS_H_ 17 | #define _HAL_ARMV7R_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 | -------------------------------------------------------------------------------- /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 _HAL_ARMV7R_INTERRUPTS_H_ 17 | #define _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 | int (*f)(unsigned int, cpu_context_t *, void *); 26 | void *data; 27 | void *got; 28 | } intr_handler_t; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /hal/armv7r/arch/pmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * pmap interface - machine dependent part of VM subsystem (ARMv7r) 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 _HAL_PMAP_ARMV7R_H_ 17 | #define _HAL_PMAP_ARMV7R_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/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 _HAL_ARMV7R_SPINLOCK_H_ 17 | #define _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 | 26 | u8 lock; 27 | } __attribute__((packed)) spinlock_t; 28 | 29 | 30 | typedef u32 spinlock_ctx_t; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /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 _HAL_ARMV7R_TYPES_H_ 17 | #define _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 | 32 | #endif 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /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 _HAL_SYSPAGE_H_ 17 | #define _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/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/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 _HAL_CONFIG_H_ 17 | #define _HAL_CONFIG_H_ 18 | 19 | 20 | #define NUM_CPUS 1 21 | #define SIZE_INTERRUPTS 188 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 | -------------------------------------------------------------------------------- /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 _HAL_ZYNQ_H_ 17 | #define _HAL_ZYNQ_H_ 18 | 19 | #include "hal/cpu.h" 20 | #include "include/arch/armv7r/zynqmp/zynqmp.h" 21 | 22 | 23 | extern int _zynqmp_setMIO(unsigned pin, char l0, char l1, char l2, char l3, char config); 24 | 25 | 26 | extern int _zynq_setDevRst(int dev, unsigned int state); 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /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 | endif 15 | 16 | include hal/arm/Makefile 17 | CFLAGS += -Ihal/arm 18 | 19 | OBJS += $(addprefix $(PREFIX_O)hal/armv8m/, string.o spinlock.o cpu.o hal.o \ 20 | pmap.o exceptions.o _memcpy.o _memset.o interrupts.o) 21 | -------------------------------------------------------------------------------- /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 _HAL_ARMV8M_ELF_H_ 18 | #define _HAL_ARMV8M_ELF_H_ 19 | 20 | 21 | #define R_ARM_ABS32 2 22 | #define R_ARM_TARGET1 38 23 | 24 | 25 | static inline int hal_isRelReloc(int relType) 26 | { 27 | return ((relType == R_ARM_ABS32) || (relType == R_ARM_TARGET1)) ? 1 : 0; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /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 _HAL_ARMV8M_EXCEPTIONS_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_ARMV8M_INTERRUPTS_H_ 18 | #define _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 | int (*f)(unsigned int, cpu_context_t *, void *); 35 | void *data; 36 | void *got; 37 | } intr_handler_t; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /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 _HAL_PMAP_ARMV8M_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_ARMV8M_SPINLOCK_H_ 17 | #define _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/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 _HAL_ARMV8M_TYPES_H_ 18 | #define _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 | -------------------------------------------------------------------------------- /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 | extern void _hal_cpuInit(void); 26 | 27 | 28 | void *hal_syspageRelocate(void *data) 29 | { 30 | return data; 31 | } 32 | 33 | 34 | ptr_t hal_syspageAddr(void) 35 | { 36 | return (ptr_t)syspage; 37 | } 38 | 39 | 40 | int hal_started(void) 41 | { 42 | return hal_common.started; 43 | } 44 | 45 | 46 | void _hal_start(void) 47 | { 48 | hal_common.started = 1; 49 | } 50 | 51 | 52 | void hal_lockScheduler(void) 53 | { 54 | } 55 | 56 | 57 | void _hal_init(void) 58 | { 59 | hal_common.started = 0; 60 | 61 | _hal_spinlockInit(); 62 | _hal_exceptionsInit(); 63 | _hal_interruptsInit(); 64 | _hal_cpuInit(); 65 | _hal_consoleInit(); 66 | _hal_timerInit(SYSTICK_INTERVAL); 67 | } 68 | -------------------------------------------------------------------------------- /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/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/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 _HAL_CONFIG_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_MCXN94X_H_ 17 | #define _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 | extern int _mcxn94x_portPinConfig(int pin, int mux, int options); 26 | 27 | 28 | extern u64 _mcxn94x_sysconGray2Bin(u64 gray); 29 | 30 | 31 | extern int _mcxn94x_sysconSetDevClk(int dev, unsigned int sel, unsigned int div, int enable); 32 | 33 | 34 | extern int _mcxn94x_sysconDevReset(int dev, int state); 35 | 36 | 37 | extern int hal_platformctl(void *ptr); 38 | 39 | 40 | extern void _hal_platformInit(void); 41 | 42 | 43 | extern void _mcxn94x_scbSetPriorityGrouping(u32 group); 44 | 45 | 46 | extern void _mcxn94x_scbSetPriority(s8 excpn, u32 priority); 47 | 48 | 49 | extern unsigned int _mcxn94x_cpuid(void); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /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/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 _HAL_CONFIG_H_ 17 | #define _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/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/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/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 _HAL_ARMV8R_ELF_H_ 17 | #define _HAL_ARMV8R_ELF_H_ 18 | 19 | 20 | #define R_ARM_ABS32 2 21 | #define R_ARM_TARGET1 38 22 | 23 | 24 | static inline int hal_isRelReloc(int relType) 25 | { 26 | return ((relType == R_ARM_ABS32) || (relType == R_ARM_TARGET1)) ? 1 : 0; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /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 _HAL_ARMV8R_EXCEPTIONS_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_ARMV8R_INTERRUPTS_H_ 17 | #define _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 | int (*f)(unsigned int, cpu_context_t *, void *); 26 | void *data; 27 | void *got; 28 | } intr_handler_t; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /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 _HAL_PMAP_ARMV8M_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_ARMV8R_SPINLOCK_H_ 17 | #define _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/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 _HAL_ARMV8R_TYPES_H_ 17 | #define _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/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 _HAL_SYSPAGE_H_ 17 | #define _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/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/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 _HAL_CONFIG_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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/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 16 24 | 25 | 26 | void hal_stackPutArgs(void **stackp, size_t argc, const struct stackArg *argv) 27 | { 28 | size_t i, misalign, argsz = 0; 29 | ptr_t stack = (ptr_t)*stackp; 30 | 31 | for (i = 0; i < argc; i++) { 32 | argsz += SIZE_STACK_ARG(argv[i].sz); 33 | } 34 | 35 | misalign = (stack - argsz) & (STACK_ALIGN - 1); 36 | stack -= misalign; 37 | 38 | for (i = 0; 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 | -------------------------------------------------------------------------------- /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 _HAL_CONSOLE_H_ 18 | #define _HAL_CONSOLE_H_ 19 | 20 | /* Console attributes */ 21 | #define ATTR_NORMAL 0x03 22 | #define ATTR_BOLD 0x0f 23 | #define ATTR_USER 0x07 24 | 25 | #define CONSOLE_CYAN "\033[36m" 26 | #define CONSOLE_NORMAL "\033[0m" 27 | #define CONSOLE_BOLD "\033[1m" 28 | 29 | 30 | extern void hal_consolePrint(int attr, const char *s); 31 | 32 | 33 | extern void hal_consolePutch(char c); 34 | 35 | 36 | extern void _hal_consoleInit(void); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /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 _HAL_ELF_H_ 17 | #define _HAL_ELF_H_ 18 | 19 | 20 | #ifdef NOMMU 21 | 22 | 23 | #include 24 | 25 | 26 | static int hal_isRelReloc(int relType); 27 | 28 | 29 | #endif 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /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 _HAL_EXCEPTIONS_H_ 17 | #define _HAL_EXCEPTIONS_H_ 18 | 19 | #include 20 | 21 | 22 | extern int hal_exceptionsFaultType(unsigned int n, exc_context_t *ctx); 23 | 24 | 25 | extern void *hal_exceptionsFaultAddr(unsigned int n, exc_context_t *ctx); 26 | 27 | 28 | extern ptr_t hal_exceptionsPC(exc_context_t *ctx); 29 | 30 | 31 | extern void hal_exceptionsDumpContext(char *buff, exc_context_t *ctx, int n); 32 | 33 | 34 | extern int hal_exceptionsSetHandler(unsigned int n, void (*handler)(unsigned int, exc_context_t *)); 35 | 36 | 37 | extern void _hal_exceptionsInit(void); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 _HAL_AMBAPP_H_ 17 | #define _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/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 _HAL_HAL_H_ 17 | #define _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 | extern void *hal_syspageRelocate(void *data); 42 | 43 | 44 | extern ptr_t hal_syspageAddr(void); 45 | 46 | 47 | extern void hal_wdgReload(void); 48 | 49 | 50 | extern int hal_platformctl(void *ptr); 51 | 52 | 53 | extern int hal_started(void); 54 | 55 | 56 | extern void _hal_start(void); 57 | 58 | 59 | extern void _hal_init(void); 60 | 61 | 62 | extern void hal_lockScheduler(void); 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /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/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 _HAL_IA32_EXCEPTIONS_H_ 18 | #define _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/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 _HAL_IA32_SPINLOCK_H_ 18 | #define _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/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 _HAL_IA32_TLB_H_ 18 | #define _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/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 _HAL_IA32_TYPES_H_ 18 | #define _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/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 _HAL_CONFIG_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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/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 _HAL_IA32_CONSOLE_H_ 17 | #define _HAL_IA32_CONSOLE_H_ 18 | 19 | 20 | #ifdef HAL_CONSOLE_VGA 21 | 22 | 23 | extern void hal_consoleVGAPrint(int, const char *); 24 | 25 | 26 | extern void hal_consoleVGAPutch(char); 27 | 28 | 29 | extern void _hal_consoleVGAInit(void); 30 | 31 | 32 | #endif 33 | 34 | 35 | #ifdef HAL_CONSOLE_SERIAL 36 | 37 | 38 | extern void hal_consoleSerialPrint(int, const char *); 39 | 40 | 41 | extern void hal_consoleSerialPutch(char); 42 | 43 | 44 | extern void _hal_consoleSerialInit(void); 45 | 46 | 47 | #endif 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /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/spinlock.h" 18 | #include "hal/console.h" 19 | #include "hal/exceptions.h" 20 | #include "hal/interrupts.h" 21 | #include "hal/cpu.h" 22 | #include "hal/pmap.h" 23 | #include "hal/timer.h" 24 | #include "pci.h" 25 | #include "halsyspage.h" 26 | 27 | 28 | struct { 29 | int started; 30 | } hal_common; 31 | 32 | 33 | syspage_t *syspage; 34 | 35 | 36 | extern void _hal_cpuInit(void); 37 | 38 | 39 | void *hal_syspageRelocate(void *data) 40 | { 41 | return ((u8 *)data + VADDR_KERNEL); 42 | } 43 | 44 | 45 | ptr_t hal_syspageAddr(void) 46 | { 47 | return (ptr_t)syspage; 48 | } 49 | 50 | 51 | int hal_started(void) 52 | { 53 | return hal_common.started; 54 | } 55 | 56 | 57 | void _hal_start(void) 58 | { 59 | hal_common.started = 1; 60 | } 61 | 62 | 63 | void hal_wdgReload(void) 64 | { 65 | } 66 | 67 | 68 | void _hal_init(void) 69 | { 70 | 71 | _hal_spinlockInit(); 72 | _hal_consoleInit(); 73 | 74 | 75 | _hal_exceptionsInit(); 76 | _hal_interruptsInit(); 77 | 78 | _hal_cpuInit(); 79 | _hal_pciInit(); 80 | 81 | hal_common.started = 0; 82 | return; 83 | } 84 | -------------------------------------------------------------------------------- /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 _HAL_SYSPAGE_H_ 17 | #define _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/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 _HAL_PCI_H_ 17 | #define _HAL_PCI_H_ 18 | 19 | #include "include/arch/ia32/ia32.h" 20 | 21 | 22 | extern int hal_pciSetUsbOwnership(pci_usbownership_t *usbownership); 23 | 24 | 25 | extern int hal_pciGetDevice(pci_id_t *id, pci_dev_t *dev, void *caps); 26 | 27 | 28 | extern int hal_pciSetConfigOption(pci_pcicfg_t *pcicfg); 29 | 30 | 31 | extern void _hal_pciInit(void); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /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 _HAL_INTERRUPTS_H_ 17 | #define _HAL_INTERRUPTS_H_ 18 | 19 | #include 20 | 21 | 22 | extern int hal_interruptsSetHandler(intr_handler_t *h); 23 | 24 | 25 | extern int hal_interruptsDeleteHandler(intr_handler_t *h); 26 | 27 | 28 | extern char *hal_interruptsFeatures(char *features, unsigned int len); 29 | 30 | 31 | extern void _hal_interruptsInit(void); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /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 _HAL_LIST_H_ 18 | #define _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 | if (*(list) == NULL) { \ 29 | (t)->next = (t); \ 30 | (t)->prev = (t); \ 31 | (*(list)) = (t); \ 32 | break; \ 33 | } \ 34 | (t)->prev = (*(list))->prev; \ 35 | (*(list))->prev->next = (t); \ 36 | (t)->next = (*(list)); \ 37 | (*(list))->prev = (t); \ 38 | } while (0) 39 | 40 | 41 | #define HAL_LIST_REMOVE(list, t) \ 42 | do { \ 43 | if ((t) == NULL) \ 44 | break; \ 45 | if (((t)->next == (t)) && ((t)->prev == (t))) \ 46 | (*(list)) = NULL; \ 47 | else { \ 48 | (t)->prev->next = (t)->next; \ 49 | (t)->next->prev = (t)->prev; \ 50 | if ((t) == (*(list))) \ 51 | (*(list)) = (t)->next; \ 52 | } \ 53 | (t)->next = NULL; \ 54 | (t)->prev = NULL; \ 55 | } while (0) 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /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 | include hal/$(TARGET_SUFF)/$(TARGET_SUBFAMILY)/Makefile 11 | 12 | CFLAGS += -Ihal/$(TARGET_SUFF) -Ihal/$(TARGET_SUFF)/$(TARGET_SUBFAMILY) 13 | 14 | # binutils 2.41 silently introduced gp relaxations which for some reason make kernel impossible to build 15 | # TODO: investigate further 16 | ifeq ($(shell expr $(LD_VERSION_MINOR) ">=" 41), 1) 17 | LDFLAGS += $(LDFLAGS_PREFIX)--no-relax-gp 18 | endif 19 | -------------------------------------------------------------------------------- /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 _HAL_RISCV64_EXCEPTIONS_H_ 17 | #define _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/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 _HAL_RISCV64_INTERRUPTS_H_ 18 | #define _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 | int (*f)(unsigned int, cpu_context_t *, void *); 32 | void *data; 33 | } intr_handler_t; 34 | 35 | 36 | void hal_interruptsInitCore(void); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /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 _HAL_RISCV64_SPINLOCK_H_ 17 | #define _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/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 _HAL_RISCV64_TYPES_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_DTB_H_ 17 | 18 | #include "hal/cpu.h" 19 | 20 | #define ntoh16(x) (((x << 8) & 0xff00) | ((x >> 8) & 0xff)) 21 | #define ntoh32(x) ((ntoh16(x) << 16) | ntoh16(x >> 16)) 22 | #define ntoh64(x) ((ntoh32(x) << 32) | ntoh32(x >> 32)) 23 | 24 | 25 | void dtb_save(void *dtb); 26 | 27 | 28 | void dtb_parse(void); 29 | 30 | 31 | void dtb_getSystem(char **model, char **compatible); 32 | 33 | 34 | int dtb_getCPU(unsigned int n, char **compatible, u32 *clock, char **isa, char **mmu); 35 | 36 | 37 | void dtb_getMemory(u8 **reg, size_t *nreg); 38 | 39 | 40 | int dtb_getPLIC(void); 41 | 42 | 43 | void dtb_getReservedMemory(u64 **reg); 44 | 45 | 46 | void dtb_getDTBArea(u64 *dtb, u32 *dtbsz); 47 | 48 | 49 | void _dtb_init(void); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 _HAL_CONFIG_H_ 17 | #define _HAL_CONFIG_H_ 18 | 19 | #ifndef __ASSEMBLY__ 20 | 21 | #include "include/arch/riscv64/syspage.h" 22 | #include "include/syspage.h" 23 | 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 _HAL_SYSPAGE_H_ 17 | #define _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/riscv64/noelv/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for riscv64-noelv 3 | # 4 | # Copyright 2024 Phoenix Systems 5 | # 6 | 7 | include hal/gaisler/Makefile 8 | 9 | OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/$(TARGET_SUBFAMILY)/, console.o noelv.o) 10 | -------------------------------------------------------------------------------- /hal/riscv64/noelv/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 _HAL_CONFIG_H_ 17 | #define _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 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /hal/riscv64/noelv/noelv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL internal functions for riscv64-noelv 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 | } noelv_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(&noelv_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(&noelv_common.lock, &sc); 55 | 56 | return ret; 57 | } 58 | 59 | 60 | void _hal_platformInit(void) 61 | { 62 | hal_spinlockCreate(&noelv_common.lock, "noelv_common.lock"); 63 | ambapp_init(); 64 | } 65 | -------------------------------------------------------------------------------- /hal/riscv64/plic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * RISCV64 PLIC interrupt controler 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 _HAL_PLIC_H_ 17 | #define _HAL_PLIC_H_ 18 | 19 | #include "hal/types.h" 20 | 21 | 22 | /* PLIC Supervisor Context number */ 23 | #define PLIC_SCONTEXT(hartId) (2 * (hartId) + 1) 24 | 25 | 26 | void plic_priority(unsigned int n, unsigned int priority); 27 | 28 | 29 | u32 plic_priorityGet(unsigned int n); 30 | 31 | 32 | int plic_isPending(unsigned int n); 33 | 34 | 35 | void plic_tresholdSet(unsigned int context, unsigned int priority); 36 | 37 | 38 | u32 plic_tresholdGet(unsigned int context); 39 | 40 | 41 | unsigned int plic_claim(unsigned int context); 42 | 43 | 44 | void plic_complete(unsigned int context, unsigned int n); 45 | 46 | 47 | int plic_enableInterrupt(unsigned int context, unsigned int n); 48 | 49 | 50 | int plic_disableInterrupt(unsigned int context, unsigned int n); 51 | 52 | 53 | void plic_initCore(void); 54 | 55 | 56 | void plic_init(void); 57 | 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /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/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 | #define R_SPARC_32 3 17 | 18 | 19 | static inline int hal_isRelReloc(int relType) 20 | { 21 | return (relType == R_SPARC_32) ? 1 : 0; 22 | } 23 | -------------------------------------------------------------------------------- /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 _HAL_LEON3_EXCEPTIONS_H_ 17 | #define _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/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 _HAL_LEON3_INTERRUPTS_H_ 17 | #define _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 | int (*f)(unsigned int, cpu_context_t *, void *); 26 | void *data; 27 | #ifdef NOMMU 28 | void *got; 29 | #endif 30 | } intr_handler_t; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /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 _HAL_LEON3_SPINLOCK_H_ 17 | #define _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/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 _HAL_LEON3_TLB_H_ 18 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_LEON3_TYPES_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 _GAISLER_H_ 17 | #define _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 | void hal_timerWdogReboot(void); 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /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/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 _HAL_CONFIG_H_ 17 | #define _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/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 _HAL_GENERIC_H_ 17 | #define _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 | void _hal_platformInit(void); 38 | 39 | 40 | #endif /* __ASSEMBLY__ */ 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /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/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 _HAL_CONFIG_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_GR716_H_ 17 | #define _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 | 47 | void _hal_platformInit(void); 48 | 49 | 50 | #endif /* __ASSEMBLY__ */ 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 _HAL_CONFIG_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_GR716_H_ 17 | #define _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 | extern int _gr716_getIomuxCfg(u8 pin, u8 *opt, u8 *pullup, u8 *pulldn); 36 | 37 | 38 | extern void _gr716_cguClkEnable(u32 cgu, u32 device); 39 | 40 | 41 | extern void _gr716_cguClkDisable(u32 cgu, u32 device); 42 | 43 | 44 | extern int _gr716_cguClkStatus(u32 cgu, u32 device); 45 | 46 | 47 | extern int hal_platformctl(void *ptr); 48 | 49 | 50 | extern void _hal_platformInit(void); 51 | 52 | 53 | #endif /* __ASSEMBLY__ */ 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /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/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 _HAL_CONFIG_H_ 17 | #define _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/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 _HAL_GR740_H_ 17 | #define _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 | void _hal_platformInit(void); 48 | 49 | 50 | #endif /* __ASSEMBLY__ */ 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /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 _L2CACHE_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_SYSPAGE_H_ 17 | #define _HAL_SYSPAGE_H_ 18 | 19 | #include "hal/types.h" 20 | #include "config.h" 21 | 22 | extern syspage_t *syspage; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 _HAL_SPINLOCK_H_ 17 | #define _HAL_SPINLOCK_H_ 18 | 19 | #include 20 | 21 | 22 | extern void hal_spinlockSet(spinlock_t *spinlock, spinlock_ctx_t *sc); 23 | 24 | 25 | extern void hal_spinlockClear(spinlock_t *spinlock, spinlock_ctx_t *sc); 26 | 27 | 28 | extern void hal_spinlockCreate(spinlock_t *spinlock, const char *name); 29 | 30 | 31 | extern void hal_spinlockDestroy(spinlock_t *spinlock); 32 | 33 | 34 | extern void _hal_spinlockInit(void); 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /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 _HAL_STRING_H_ 18 | #define _HAL_STRING_H_ 19 | 20 | #include "hal/types.h" 21 | 22 | 23 | extern void hal_memcpy(void *dst, const void *src, size_t l); 24 | 25 | 26 | extern int hal_memcmp(const void *ptr1, const void *ptr2, size_t num); 27 | 28 | 29 | extern void hal_memset(void *dst, int v, size_t l); 30 | 31 | 32 | extern size_t hal_strlen(const char *s); 33 | 34 | 35 | extern int hal_strcmp(const char *s1, const char *s2); 36 | 37 | 38 | extern int hal_strncmp(const char *s1, const char *s2, size_t count); 39 | 40 | 41 | extern char *hal_strcpy(char *dest, const char *src); 42 | 43 | 44 | extern char *hal_strncpy(char *dest, const char *src, size_t n); 45 | 46 | 47 | extern unsigned long hal_i2s(const char *prefix, char *s, unsigned long i, unsigned char b, char zero); 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /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 _HAL_TIMER_H_ 17 | #define _HAL_TIMER_H_ 18 | 19 | 20 | #include "cpu.h" 21 | #include "interrupts.h" 22 | 23 | extern time_t hal_timerGetUs(void); 24 | 25 | 26 | extern void hal_timerSetWakeup(u32 waitUs); 27 | 28 | 29 | extern int hal_timerRegister(int (*f)(unsigned int, cpu_context_t *, void *), void *data, intr_handler_t *h); 30 | 31 | 32 | extern void _hal_timerInit(u32 interval); 33 | 34 | 35 | extern char *hal_timerFeatures(char *features, unsigned int len); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /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/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 _HAL_TLB_H_ 17 | #define _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 | -------------------------------------------------------------------------------- /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 _HAL_TYPES_H_ 17 | #define _HAL_TYPES_H_ 18 | 19 | 20 | #define NULL 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 | 40 | #endif 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_AARCH64_STDTYPES_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_AARCH64_TYPES_H_ 17 | #define _PHOENIX_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 | typedef unsigned long long time_t; 30 | 31 | typedef __u64 id_t; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /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 _PHOENIX_SYSPAGE_ZYNQMP_H_ 17 | #define _PHOENIX_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/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 _PHOENIX_SYSPAGE_IMX6ULL_H_ 17 | #define _PHOENIX_SYSPAGE_IMX6ULL_H_ 18 | 19 | 20 | typedef struct { 21 | int dummy; 22 | } __attribute__((packed)) hal_syspage_t; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_ARMV7A_STDTYPES_H_ 17 | #define _PHOENIX_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/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 _PHOENIX_ARCH_ARMV7A_TYPES_H_ 17 | #define _PHOENIX_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 | typedef unsigned long long time_t; 30 | 31 | typedef __u64 id_t; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /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 _PHOENIX_SYSPAGE_ZYNQ7000_H_ 17 | #define _PHOENIX_SYSPAGE_ZYNQ7000_H_ 18 | 19 | typedef struct { 20 | int dummy; 21 | } __attribute__((packed)) hal_syspage_t; 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /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 _PHOENIX_SYSPAGE_IMXRT_H_ 18 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_ARMV7M_STDTYPES_H_ 17 | #define _PHOENIX_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/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 _PHOENIX_SYSPAGE_STM32_H_ 18 | #define _PHOENIX_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/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 _PHOENIX_ARCH_ARMV7M_TYPES_H_ 17 | #define _PHOENIX_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 | typedef unsigned long long time_t; 30 | 31 | typedef __u32 id_t; 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 _PHOENIX_ARCH_ARMV7R_STDTYPES_H_ 17 | #define _PHOENIX_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/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 _PHOENIX_ARCH_ARMV7R_TYPES_H_ 17 | #define _PHOENIX_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 | typedef unsigned long long time_t; 30 | 31 | typedef __u32 id_t; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /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 _PHOENIX_SYSPAGE_ARMV7R_ZYNQMP_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_SYSPAGE_MCXN94X_H_ 18 | #define _PHOENIX_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/armv8m/nrf/91/nrf9160.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Macros and enums for NRF9160 related code 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 _PHOENIX_ARCH_NRF9160_H_ 17 | #define _PHOENIX_ARCH_NRF9160_H_ 18 | 19 | 20 | #define PCTL_REBOOT_MAGIC 0xaa55aa55UL 21 | 22 | /* clang-format off */ 23 | /* nRF9160 peripheral id's - same as irq numbers */ 24 | enum { spu_irq = 3, regulators_irq, clock_irq = 5, power_irq = 5, ctrlapperi_irq, spi0_irq = 8, twi0_irq = 8, uarte0_irq = 8, 25 | spi1_irq = 9, twi1_irq = 9, uarte1_irq = 9, spi2_irq = 10, twi2_irq = 10, uarte2_irq = 10, spi3_irq = 11, twi3_irq = 11, uarte3_irq = 11, 26 | gpiote0_irq = 13, saadc_irq, timer0_irq, timer1_irq, timer2_irq, rtc0_irq = 20, rtc1_irq, ddpic_irq = 23, wdt_irq, 27 | egu0_irq = 27, egu1_irq, egu2_irq, egu3_irq, egu4_irq, egu5_irq, pwm0_irq, pwm1_irq, pwm2_irq, pwm3_irq, pdm_irq = 38, 28 | i2s_irq = 40, ipc_irq = 42, fpu_irq = 44, gpiote1_irq = 49, kmu_irq = 57, nvmc_irq = 57, vmc_irq, cc_host_rgf_irq = 64, 29 | cryptocell_irq = 64, gpio_irq = 66 }; 30 | /* clang-format on */ 31 | 32 | 33 | typedef struct { 34 | enum { pctl_set = 0, 35 | pctl_get } action; 36 | enum { pctl_reboot = 0 } type; 37 | 38 | struct { 39 | unsigned int magic; 40 | unsigned int reason; 41 | } reboot; 42 | 43 | } __attribute__((packed)) platformctl_t; 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /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 _PHOENIX_SYSPAGE_NRF91_H_ 18 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_ARMV8M_STDTYPES_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_ARMV8M_TYPES_H_ 17 | #define _PHOENIX_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 | typedef unsigned long long time_t; 30 | 31 | typedef __u32 id_t; 32 | 33 | 34 | #endif 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 _PHOENIX_ARCH_MPS3AN536_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_SYSPAGE_MPS3AN536_H_ 17 | #define _PHOENIX_SYSPAGE_MPS3AN536_H_ 18 | 19 | 20 | typedef struct { 21 | int dummy; 22 | } __attribute__((packed)) hal_syspage_t; 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_ARMV8R_STDTYPES_H_ 17 | #define _PHOENIX_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/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 _PHOENIX_ARCH_ARMV7A_TYPES_H_ 17 | #define _PHOENIX_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 | typedef unsigned long long time_t; 30 | 31 | typedef __u32 id_t; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_IA32_STDTYPES_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /include/arch/ia32/syspage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * HAL syspage for ia32 7 | * 8 | * Copyright 2021 Phoenix Systems 9 | * Authors: Lukasz Kosinski, Hubert Buczynski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _PHOENIX_SYSPAGE_IA32_H_ 17 | #define _PHOENIX_SYSPAGE_IA32_H_ 18 | 19 | #define ACPI_NONE 0 20 | #define ACPI_RSDP 1 21 | #define ACPI_XSDP 2 22 | 23 | typedef struct { 24 | struct { 25 | unsigned short size; 26 | unsigned int addr; 27 | } __attribute__((packed)) gdtr; 28 | unsigned short pad1; 29 | struct { 30 | unsigned short size; 31 | unsigned int addr; 32 | } __attribute__((packed)) idtr; 33 | unsigned short pad2; 34 | unsigned int pdir; 35 | unsigned int ptable; 36 | unsigned int stack; 37 | unsigned int stacksz; 38 | 39 | unsigned int ebda; 40 | unsigned int acpi_version; 41 | unsigned int localApicAddr; 42 | unsigned long madt; /* addr_t */ 43 | unsigned int madtLength; 44 | unsigned long fadt; /* addr_t */ 45 | unsigned int fadtLength; 46 | unsigned long hpet; /* addr_t */ 47 | unsigned int hpetLength; 48 | unsigned long mcfg; /* addr_t */ 49 | unsigned int mcfgLength; 50 | 51 | struct { 52 | unsigned short width; 53 | unsigned short height; 54 | unsigned short bpp; 55 | unsigned short pitch; 56 | unsigned long framebuffer; /* addr_t */ 57 | } __attribute__((packed)) graphmode; /* Graphics mode info */ 58 | } __attribute__((packed)) hal_syspage_t; 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_IA32_TYPES_H_ 18 | #define _PHOENIX_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 | typedef unsigned long long time_t; 31 | 32 | typedef __u64 id_t; 33 | 34 | 35 | #endif 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_RISCV64_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_RISCV64_STDTYPES_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_SYSPAGE_RISCV64_H_ 17 | #define _PHOENIX_SYSPAGE_RISCV64_H_ 18 | 19 | 20 | typedef struct { 21 | unsigned int boothartId; 22 | } __attribute__((packed)) hal_syspage_t; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_RISCV64_TYPES_H_ 17 | #define _PHOENIX_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 | typedef unsigned long long time_t; 30 | 31 | typedef __u64 id_t; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_GENERIC_H_ 17 | #define _PHOENIX_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/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 _PHOENIX_ARCH_GR712RC_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_SPARCV8LEON_H_ 17 | #define _PHOENIX_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 _PHOENIX_ARCH_LEON3_STDTYPES_H_ 17 | #define _PHOENIX_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/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 _PHOENIX_SYSPAGE_LEON3_H_ 17 | #define _PHOENIX_SYSPAGE_LEON3_H_ 18 | 19 | 20 | typedef struct { 21 | int dummy; 22 | } __attribute__((packed)) hal_syspage_t; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /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 _PHOENIX_ARCH_LEON3_TYPES_H_ 17 | #define _PHOENIX_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 | typedef unsigned long long time_t; 30 | 31 | typedef __u32 id_t; 32 | 33 | 34 | #endif 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /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 _PHOENIX_EVENTS_H_ 17 | #define _PHOENIX_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/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 _PHOENIX_FILE_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_IOCTL_H_ 17 | #define _PHOENIX_IOCTL_H_ 18 | 19 | 20 | typedef struct { 21 | unsigned long request; 22 | char data[]; 23 | } ioctl_in_t; 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /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 _PHOENIX_LIMITS_H_ 17 | #define _PHOENIX_LIMITS_H_ 18 | 19 | 20 | #define HOST_NAME_MAX 255 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /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 _PHOENIX_MMAN_H_ 17 | #define _PHOENIX_MMAN_H_ 18 | 19 | 20 | #define MAP_NONE 0x0 21 | #define MAP_NEEDSCOPY (1 << 0) 22 | #define MAP_UNCACHED (1 << 1) 23 | #define MAP_DEVICE (1 << 2) 24 | #define MAP_NOINHERIT (1 << 3) 25 | #define MAP_PHYSMEM (1 << 4) 26 | #define MAP_CONTIGUOUS (1 << 5) 27 | #define MAP_ANONYMOUS (1 << 6) 28 | #define MAP_FIXED (1 << 7) 29 | /* NOTE: vm uses u8 to store flags, if more flags are needed this type needs to be changed. */ 30 | #define MAP_SHARED 0x0 31 | #define MAP_PRIVATE 0x0 32 | 33 | 34 | #define PROT_NONE 0x0 35 | #define PROT_READ 0x1 36 | #define PROT_WRITE 0x2 37 | #define PROT_EXEC 0x4 38 | #define PROT_USER 0x8 39 | 40 | 41 | #define MAP_FAILED (void *)-1 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /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 _PHOENIX_POSIX_FCNTL_H_ 17 | #define _PHOENIX_POSIX_FCNTL_H_ 18 | 19 | 20 | #define FD_CLOEXEC 1 21 | 22 | #define O_RDONLY 0x0001 23 | #define O_WRONLY 0x0002 24 | #define O_RDWR 0x0004 25 | #define O_APPEND 0x0008 26 | #define O_CREAT 0x0100 27 | #define O_TRUNC 0x0200 28 | #define O_EXCL 0x0400 29 | #define O_SYNC 0x0800 30 | #define O_NONBLOCK 0x1000 31 | #define O_NDELAY O_NONBLOCK 32 | #define O_NOCTTY 0x2000 33 | #define O_CLOEXEC 0x4000 34 | 35 | /* clang-format off */ 36 | 37 | /* fcntl() operations */ 38 | enum { F_DUPFD = 0, F_DUPFD_CLOEXEC, F_GETFD, F_SETFD, F_GETFL, F_SETFL, 39 | F_GETOWN, F_SETOWN, F_GETLK, F_SETLK, F_SETLKW }; 40 | 41 | /* clang-format on */ 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /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 _PHOENIX_POSIX_POLL_H_ 17 | #define _PHOENIX_POSIX_POLL_H_ 18 | 19 | 20 | #define POLLIN 0x1 21 | #define POLLRDNORM 0x2 22 | #define POLLRDBAND 0x4 23 | #define POLLPRI 0x8 24 | #define POLLOUT 0x10 25 | #define POLLWRNORM 0x20 26 | #define POLLWRBAND 0x40 27 | #define POLLERR 0x80 28 | #define POLLHUP 0x100 29 | #define POLLNVAL 0x200 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 | -------------------------------------------------------------------------------- /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 _PHOENIX_POSIX_STATVFS_H_ 18 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_POSIX_STDIO_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_POSIX_TIMESPEC_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_POSIX_TYPES_H_ 17 | #define _PHOENIX_POSIX_TYPES_H_ 18 | 19 | 20 | typedef int pid_t; 21 | typedef int mode_t; 22 | typedef int gid_t; 23 | typedef int uid_t; 24 | 25 | typedef int dev_t; 26 | typedef int ino_t; /* FIXME: should be unsigned long long to encode id_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_POSIX_UIO_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_SIGNAL_H_ 18 | #define _PHOENIX_SIGNAL_H_ 19 | 20 | enum { signal_kill = 1, signal_segv, signal_illegal, signal_cancel = 32 }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /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 _PHOENIX_THREADS_H_ 17 | #define _PHOENIX_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 | -------------------------------------------------------------------------------- /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 _PHOENIX_TIME_H_ 17 | #define _PHOENIX_TIME_H_ 18 | 19 | 20 | #define PH_CLOCK_RELATIVE 0 21 | #define PH_CLOCK_REALTIME 1 22 | #define PH_CLOCK_MONOTONIC 2 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /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 _PHOENIX_UTSNAME_H_ 17 | #define _PHOENIX_UTSNAME_H_ 18 | 19 | 20 | #include "limits.h" 21 | 22 | 23 | struct utsname { 24 | char sysname[16]; 25 | char nodename[HOST_NAME_MAX + 1]; 26 | char release[16]; 27 | char version[32]; 28 | char machine[16]; 29 | }; 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /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 strtoul.o rb.o list.o cbuffer.o strutil.o idtree.o) 9 | 10 | -------------------------------------------------------------------------------- /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 | #include 17 | #include "assert.h" 18 | #include "printf.h" 19 | #include "log/log.h" 20 | #include "hal/hal.h" 21 | 22 | 23 | void lib_assertPanic(const char *func, int line, const char *fmt, ...) 24 | { 25 | va_list ap; 26 | 27 | log_disable(); 28 | hal_cpuDisableInterrupts(); 29 | lib_printf("kernel (%s:%d): ", func, line); 30 | va_start(ap, fmt); 31 | lib_vprintf(fmt, ap); 32 | va_end(ap); 33 | lib_putch('\n'); 34 | 35 | #ifdef NDEBUG 36 | hal_cpuReboot(); 37 | #endif 38 | 39 | for (;;) { 40 | hal_cpuHalt(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /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 LIB_ASSERT_H_ 17 | #define 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 | #ifndef NDEBUG 29 | 30 | #define LIB_ASSERT(condition, fmt, ...) LIB_ASSERT_ALWAYS(condition, fmt, ##__VA_ARGS__) 31 | 32 | #else 33 | 34 | #define LIB_ASSERT(condition, fmt, ...) 35 | 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /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 *, void *)) 22 | { 23 | int l = 0, r = nmemb - 1, m; 24 | int cmp; 25 | 26 | if (nmemb == 0) 27 | return NULL; 28 | 29 | while (l <= r) { 30 | m = (l + r) / 2; 31 | 32 | cmp = compar(key, base + m * size); 33 | 34 | if (cmp == 0) 35 | return base + m * size; 36 | 37 | if (cmp > 0) 38 | l = m + 1; 39 | else 40 | r = m - 1; 41 | } 42 | return NULL; 43 | } 44 | -------------------------------------------------------------------------------- /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 LIB_BSEARCH_H_ 18 | #define LIB_BSEARCH_H_ 19 | 20 | 21 | extern void *lib_bsearch(void *key, void *base, size_t nmemb, size_t size, int (*compar)(void *, void *)); 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /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 _LIB_CBUFFER_H_ 17 | #define _LIB_CBUFFER_H_ 18 | 19 | typedef struct { 20 | size_t sz, r, w; 21 | char full, mark; 22 | void *data; 23 | page_t *pages; 24 | } cbuffer_t; 25 | 26 | 27 | static inline size_t _cbuffer_free(cbuffer_t *buf) 28 | { 29 | if (buf->w == buf->r) 30 | return buf->full ? 0 : buf->sz; 31 | 32 | return (buf->r - buf->w + buf->sz) & (buf->sz - 1); 33 | } 34 | 35 | 36 | static inline size_t _cbuffer_avail(cbuffer_t *buf) 37 | { 38 | return buf->sz - _cbuffer_free(buf); 39 | } 40 | 41 | 42 | static inline int _cbuffer_discard(cbuffer_t *buf, size_t sz) 43 | { 44 | int cnt = min(_cbuffer_free(buf), sz); 45 | buf->r = (buf->r + cnt) & (buf->sz - 1); 46 | return cnt; 47 | } 48 | 49 | 50 | extern int _cbuffer_init(cbuffer_t *buf, void *data, size_t sz); 51 | 52 | 53 | extern int _cbuffer_read(cbuffer_t *buf, void *data, size_t sz); 54 | 55 | 56 | extern int _cbuffer_write(cbuffer_t *buf, const void *data, size_t sz); 57 | 58 | 59 | extern int _cbuffer_peek(const cbuffer_t *buf, void *data, size_t sz); 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /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 _LIB_HELPERS_H_ 13 | #define _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 | -------------------------------------------------------------------------------- /lib/idtree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * id allocating tree 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 _PHOENIX_IDTREE_H_ 17 | #define _PHOENIX_IDTREE_H_ 18 | 19 | #include "rb.h" 20 | 21 | 22 | #define MAX_ID ((1LL << (__CHAR_BIT__ * (sizeof(int)) - 1)) - 1) 23 | 24 | 25 | typedef rbtree_t idtree_t; 26 | 27 | 28 | typedef struct { 29 | rbnode_t linkage; 30 | int lmaxgap, rmaxgap; 31 | int id; 32 | } idnode_t; 33 | 34 | 35 | #define lib_idtreeof(type, node_field, node) ({ \ 36 | long _off = (long)&(((type *)0)->node_field); \ 37 | idnode_t *tmpnode = (node); \ 38 | (type *)((tmpnode == NULL) ? NULL : ((void *)tmpnode - _off)); \ 39 | }) 40 | 41 | 42 | idnode_t *lib_idtreeFind(idtree_t *tree, int id); 43 | 44 | 45 | idnode_t *lib_idtreeMinimum(rbnode_t *node); 46 | 47 | 48 | idnode_t *lib_idtreeNext(rbnode_t *node); 49 | 50 | 51 | int lib_idtreeInsert(idtree_t *tree, idnode_t *z); 52 | 53 | 54 | void lib_idtreeRemove(idtree_t *tree, idnode_t *node); 55 | 56 | 57 | int lib_idtreeId(idnode_t *node); 58 | 59 | 60 | int lib_idtreeAlloc(idtree_t *tree, idnode_t *n, int min); 61 | 62 | 63 | void lib_idtreeDump(rbnode_t *node); 64 | 65 | 66 | void lib_idtreeInit(idtree_t *tree); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /lib/lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Library routines 7 | * 8 | * Copyright 2012, 2014, 2016 Phoenix Systems 9 | * Copyright 2001, 2006 Pawel Pisarczyk 10 | * Author: Pawel Pisarczyk, Pawel Kolodziej 11 | * 12 | * This file is part of Phoenix-RTOS. 13 | * 14 | * %LICENSE% 15 | */ 16 | 17 | #ifndef _LIB_LIB_H_ 18 | #define _LIB_LIB_H_ 19 | 20 | #include "hal/hal.h" 21 | #include "printf.h" 22 | #include "bsearch.h" 23 | #include "rand.h" 24 | #include "strtoul.h" 25 | #include "rb.h" 26 | #include "list.h" 27 | #include "assert.h" 28 | #include "strutil.h" 29 | #include "idtree.h" 30 | 31 | 32 | #define lib_atomicIncrement(ptr) __atomic_add_fetch(ptr, 1, __ATOMIC_RELAXED) 33 | 34 | 35 | #define lib_atomicDecrement(ptr) __atomic_add_fetch(ptr, -1, __ATOMIC_ACQ_REL) 36 | 37 | 38 | #define max(a, b) ({ \ 39 | __typeof__ (a) _a = (a); \ 40 | __typeof__ (b) _b = (b); \ 41 | _a > _b ? _a : _b; \ 42 | }) 43 | 44 | 45 | #define min(a, b) ({ \ 46 | __typeof__ (a) _a = (a); \ 47 | __typeof__ (b) _b = (b); \ 48 | _a > _b ? _b : _a; \ 49 | }) 50 | 51 | 52 | #include "cbuffer.h" 53 | 54 | 55 | #define swap(a, b) ({ \ 56 | __typeof__ (a) tmp = (a); \ 57 | (a) = (b); \ 58 | (b) = (tmp); \ 59 | }) 60 | 61 | 62 | static inline int abs(int val) 63 | { 64 | return (val < 0 ? -val : val); 65 | } 66 | 67 | 68 | #define round_page(x) (((x) + SIZE_PAGE - 1) & ~(SIZE_PAGE - 1)) 69 | 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /lib/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Standard routines - doubly-linked list 7 | * 8 | * Copyright 2017, 2018 Phoenix Systems 9 | * Author: Pawel Pisarczyk, Jan Sikorski, Aleksander Kaminski 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _LIB_LIST_H_ 17 | #define _LIB_LIST_H_ 18 | 19 | #include "hal/hal.h" 20 | 21 | 22 | extern void lib_listAdd(void **list, void *t, size_t noff, size_t poff); 23 | 24 | 25 | extern void lib_listRemove(void **list, void *t, size_t noff, size_t poff); 26 | 27 | 28 | extern int lib_listBelongs(void **list, void *t, size_t noff, size_t poff); 29 | 30 | 31 | #define LIST_ADD_EX(list, t, next, prev) \ 32 | lib_listAdd((void **)(list), (void *)(t), (size_t)&(((typeof(t))0)->next), (size_t)&(((typeof(t))0)->prev)) 33 | 34 | 35 | #define LIST_ADD(list, t) LIST_ADD_EX(list, t, next, prev) 36 | 37 | 38 | #define LIST_REMOVE_EX(list, t, next, prev) \ 39 | lib_listRemove((void **)(list), (void *)(t), (size_t)&(((typeof(t))0)->next), (size_t)&(((typeof(t))0)->prev)) 40 | 41 | 42 | #define LIST_REMOVE(list, t) LIST_REMOVE_EX(list, t, next, prev) 43 | 44 | 45 | #define LIST_BELONGS_EX(list, t, next, prev) \ 46 | lib_listBelongs((void **)(list), (void *)t, (size_t)&(((typeof(t))0)->next), (size_t)&(((typeof(t))0)->prev)) 47 | 48 | 49 | #define LIST_BELONGS(list, t) LIST_BELONGS_EX(list, t, next, prev) 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /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 | #ifndef _LIB_PRINTF_H_ 18 | #define _LIB_PRINTF_H_ 19 | 20 | #include 21 | 22 | extern int lib_sprintf(char *out, const char *format, ...); 23 | 24 | 25 | extern int lib_vsprintf(char *out, const char *format, va_list args); 26 | 27 | 28 | extern int lib_printf(const char *fmt, ...); 29 | 30 | 31 | extern int lib_vprintf(const char *format, va_list ap); 32 | 33 | 34 | extern void lib_putch(char c); 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /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 "hal/hal.h" 17 | 18 | 19 | int lib_rand(unsigned int *seedp) 20 | { 21 | *seedp = (*seedp * 1103515245 + 12345); 22 | return((unsigned)(*seedp / 2)); 23 | } 24 | -------------------------------------------------------------------------------- /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 _LIB_RAND_H_ 17 | #define _LIB_RAND_H_ 18 | 19 | 20 | extern int lib_rand(unsigned int *seedp); 21 | 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/strtoul.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Standard routines - ASCII to integer conversion 7 | * 8 | * Copyright 2017, 2024 Phoenix Systems 9 | * Author: Jakub Sejdak, Aleksander Kaminski, Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #include "hal/hal.h" 17 | #include "lib.h" 18 | 19 | 20 | static int strtoul_isalnum(char c) 21 | { 22 | if ((c >= '0') && (c <= '9')) { 23 | return 1; 24 | } 25 | 26 | /* test letter */ 27 | c &= ~0x20; 28 | if ((c >= 'A') && (c <= 'Z')) { 29 | return 1; 30 | } 31 | 32 | return 0; 33 | } 34 | 35 | 36 | unsigned long lib_strtoul(char *nptr, char **endptr, int base) 37 | { 38 | unsigned long t, v = 0; 39 | 40 | if ((base == 16) && (nptr[0] == '0') && (nptr[1] == 'x')) { 41 | nptr += 2; 42 | } 43 | 44 | while (strtoul_isalnum(*nptr)) { 45 | t = *nptr - '0'; 46 | if (t > 9) { 47 | t = (*nptr | 0x20) - 'a' + 10; 48 | } 49 | 50 | if (t >= base) { 51 | break; 52 | } 53 | 54 | v = (v * base) + t; 55 | 56 | ++nptr; 57 | } 58 | 59 | if (endptr != NULL) { 60 | *endptr = nptr; 61 | } 62 | 63 | return v; 64 | } 65 | 66 | 67 | long lib_strtol(char *nptr, char **endptr, int base) 68 | { 69 | int sign = 1; 70 | 71 | if (*nptr == '-') { 72 | sign = -1; 73 | ++nptr; 74 | } 75 | 76 | return sign * (long)lib_strtoul(nptr, endptr, base); 77 | } 78 | -------------------------------------------------------------------------------- /lib/strtoul.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Phoenix-RTOS 3 | * 4 | * Operating system kernel 5 | * 6 | * Standard routines - ASCII to unsigned integer conversion 7 | * 8 | * Copyright 2017 Phoenix Systems 9 | * Author: Jakub Sejdak, Pawel Pisarczyk 10 | * 11 | * This file is part of Phoenix-RTOS. 12 | * 13 | * %LICENSE% 14 | */ 15 | 16 | #ifndef _LIB_STROUL_H_ 17 | #define _LIB_STROUL_H_ 18 | 19 | 20 | extern unsigned long lib_strtoul(char *nptr, char **endptr, int base); 21 | 22 | 23 | extern long lib_strtol(char *nptr, char **endptr, int base); 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /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 | 19 | 20 | static char *lib_strrchr(char *s, int 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) + 1; 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, 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 | -------------------------------------------------------------------------------- /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 _LIB_STRUTIL_H_ 17 | #define _LIB_STRUTIL_H_ 18 | 19 | 20 | char *lib_strdup(const char *str); 21 | 22 | 23 | void lib_splitname(char *path, char **base, char **dir); 24 | 25 | 26 | #endif /* _LIB_STRUTIL_H_ */ 27 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 _LOG_H_ 16 | #define _LOG_H_ 17 | 18 | #include "proc/msg.h" 19 | 20 | 21 | extern int 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 | extern void log_scrub(void); 27 | 28 | 29 | /* Same as log_scrub, but give up if lock is taken */ 30 | extern 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 | extern void log_disable(void); 36 | 37 | 38 | extern void log_msgHandler(msg_t *msg, oid_t oid, unsigned long int rid); 39 | 40 | 41 | extern void _log_init(void); 42 | 43 | 44 | #endif /* _LOG_H_ */ 45 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 _POSIX_FDPASS_H_ 17 | #define _POSIX_FDPASS_H_ 18 | 19 | #include "posix_private.h" 20 | 21 | 22 | #define MAX_MSG_CONTROLLEN 256 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 | extern int fdpass_pack(fdpack_t **packs, const void *control, socklen_t controllen); 34 | 35 | 36 | extern int fdpass_unpack(fdpack_t **packs, void *control, socklen_t *controllen); 37 | 38 | 39 | extern int fdpass_discard(fdpack_t **packs); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /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 _SYS_SOCKDEFS_H_ 17 | #define _SYS_SOCKDEFS_H_ 18 | 19 | #define SOCK_NONBLOCK 0x8000 20 | #define SOCK_CLOEXEC 0x4000 21 | #define SOCK_LARGEBUF 0x2000 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 _PROC_COND_H_ 17 | #define _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 | extern void cond_put(cond_t *cond); 31 | 32 | 33 | extern cond_t *cond_get(int c); 34 | 35 | 36 | extern int proc_condCreate(const struct condAttr *attr); 37 | 38 | 39 | extern int proc_condWait(int c, int m, time_t timeout); 40 | 41 | 42 | extern int proc_condSignal(int c); 43 | 44 | 45 | extern int proc_condBroadcast(int c); 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /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 _PROC_LOCK_H_ 17 | #define _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 | extern int proc_lockSet(lock_t *lock); 38 | 39 | 40 | extern int proc_lockSet2(lock_t *lock1, lock_t *lock2); 41 | 42 | 43 | extern int proc_lockTry(lock_t *lock); 44 | 45 | 46 | /* `timeout` - in microseconds, absolute time relative to monotonic clock */ 47 | extern int proc_lockWait(struct _thread_t **queue, lock_t *lock, time_t timeout); 48 | 49 | 50 | extern int proc_lockClear(lock_t *lock); 51 | 52 | 53 | extern int proc_lockSetInterruptible(lock_t *lock); 54 | 55 | 56 | extern int proc_lockInit(lock_t *lock, const struct lockAttr *attr, const char *name); 57 | 58 | 59 | extern int proc_lockDone(lock_t *lock); 60 | 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /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 _PROC_MSG_H_ 17 | #define _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 | extern int proc_send(u32 port, msg_t *msg); 66 | 67 | 68 | extern int proc_recv(u32 port, msg_t *msg, msg_rid_t *rid); 69 | 70 | 71 | extern int proc_respond(u32 port, msg_t *msg, msg_rid_t rid); 72 | 73 | 74 | extern void _msg_init(vm_map_t *kmap, vm_object_t *kernel); 75 | 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /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 _PROC_MUTEX_H_ 17 | #define _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 | extern mutex_t *mutex_get(int h); 30 | 31 | 32 | extern void mutex_put(mutex_t *mutex); 33 | 34 | 35 | extern int proc_mutexLock(int h); 36 | 37 | 38 | extern int proc_mutexTry(int h); 39 | 40 | 41 | extern int proc_mutexUnlock(int h); 42 | 43 | 44 | extern int proc_mutexCreate(const struct lockAttr *attr); 45 | 46 | 47 | extern int proc_mutexDestroy(int h); 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /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 _PROC_PORT_H_ 17 | #define _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 *port); 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 | -------------------------------------------------------------------------------- /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 | _threads_init(kmap, kernel); 25 | _process_init(kmap, kernel); 26 | _port_init(); 27 | _msg_init(kmap, kernel); 28 | _name_init(); 29 | _userintr_init(); 30 | 31 | return EOK; 32 | } 33 | -------------------------------------------------------------------------------- /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 _PROC_PROC_H_ 18 | #define _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 | extern int _proc_init(vm_map_t *kmap, vm_object_t *kernel); 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /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 _PROC_RESOURCE_H_ 17 | #define _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 | unsigned 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 | extern int resource_alloc(process_t *process, resource_t *r); 45 | 46 | 47 | extern resource_t *resource_get(process_t *process, int id); 48 | 49 | 50 | extern int resource_put(process_t *process, resource_t *r); 51 | 52 | 53 | extern int proc_resourceDestroy(process_t *process, int id); 54 | 55 | 56 | extern void proc_resourcesDestroy(process_t *process); 57 | 58 | 59 | extern int proc_resourcesCopy(process_t *source); 60 | 61 | 62 | extern void _resource_init(process_t *process); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /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 _PROC_USERINTR_H_ 17 | #define _PROC_USERINTR_H_ 18 | 19 | #include "hal/hal.h" 20 | #include "cond.h" 21 | #include "resource.h" 22 | 23 | 24 | typedef struct _userintr_t { 25 | resource_t resource; 26 | intr_handler_t handler; 27 | process_t *process; 28 | int (*f)(unsigned int, void *); 29 | void *arg; 30 | cond_t *cond; 31 | } userintr_t; 32 | 33 | 34 | extern void userintr_put(userintr_t *ui); 35 | 36 | 37 | extern int userintr_setHandler(unsigned int n, int (*f)(unsigned int, void *), void *arg, handle_t c); 38 | 39 | 40 | extern userintr_t *userintr_active(void); 41 | 42 | 43 | extern void _userintr_init(void); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /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 _SYSCALLS_H_ 18 | #define _SYSCALLS_H_ 19 | 20 | 21 | extern const void * const syscalls[]; 22 | 23 | 24 | extern void _syscalls_init(void); 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /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 _SYSPAGE_H_ 17 | #define _SYSPAGE_H_ 18 | 19 | #include "hal/hal.h" 20 | #include "include/syspage.h" 21 | 22 | 23 | /* Map's functions */ 24 | 25 | extern size_t syspage_mapSize(void); 26 | 27 | 28 | extern const syspage_map_t *syspage_mapList(void); 29 | 30 | 31 | extern const syspage_map_t *syspage_mapIdResolve(unsigned int id); 32 | 33 | 34 | extern const syspage_map_t *syspage_mapAddrResolve(addr_t addr); 35 | 36 | 37 | extern const syspage_map_t *syspage_mapNameResolve(const char *name); 38 | 39 | 40 | /* Prog's functions */ 41 | 42 | extern size_t syspage_progSize(void); 43 | 44 | 45 | extern syspage_prog_t *syspage_progList(void); 46 | 47 | 48 | extern const syspage_prog_t *syspage_progIdResolve(unsigned int id); 49 | 50 | 51 | extern const syspage_prog_t *syspage_progNameResolve(const char *name); 52 | 53 | 54 | /* General functions */ 55 | 56 | extern void syspage_progShow(void); 57 | 58 | 59 | extern void syspage_init(void); 60 | 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | extern int test_ddrAccessibility(uint32_t address, int size); 20 | 21 | extern int test_ddrBitCrossTalk(uint32_t address, int size); 22 | 23 | extern int test_ddrBitChargeLeakage(uint32_t address, int size); 24 | 25 | extern int test_ddrFullMemtest(uint32_t address, int size, int iterations); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /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 | extern void test_msg(void); 21 | 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /test/proc-fpu.h: -------------------------------------------------------------------------------- 1 | #ifndef _TEST_FPU_H_ 2 | #define _TEST_FPU_H_ 3 | 4 | 5 | /* Function testing fpu context switching */ 6 | extern void test_fpuContextSwitching(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /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 | extern void test_proc_threads1(void); 21 | 22 | 23 | extern void test_proc_threads2(void); 24 | 25 | 26 | extern void test_proc_conditional(void); 27 | 28 | 29 | extern void test_proc_exit(void); 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /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 | extern void test_rb(void); 21 | 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /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 | #include "test.h" 17 | 18 | #include "vm.h" 19 | #include "proc.h" 20 | #include "rb.h" 21 | #include "msg.h" 22 | 23 | 24 | void test_run(void) 25 | { 26 | test_proc_threads1(); 27 | // test_vm_alloc(); 28 | // test_vm_kmalloc(); 29 | // test_rb(); 30 | // test_msg(); 31 | } 32 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | extern void test_vm_alloc(void); 27 | 28 | 29 | extern void test_vm_anons(struct _vm_map_t *kmap, struct _vm_object_t *kernel); 30 | 31 | 32 | extern void test_vm_mmap(void); 33 | 34 | 35 | extern void test_vm_zalloc(void); 36 | 37 | 38 | extern void test_vm_kmalloc(void); 39 | 40 | 41 | extern void test_vm_kmallocsim(void); 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /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 | 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 | proc_threadCreate(NULL, usrv_msgthr, NULL, 4, SIZE_KSTACK, NULL, 0, NULL); 70 | } 71 | 72 | 73 | void _usrv_init(void) 74 | { 75 | _log_init(); 76 | } 77 | -------------------------------------------------------------------------------- /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 _USRV_H_ 17 | #define _USRV_H_ 18 | 19 | 20 | extern void _usrv_init(void); 21 | 22 | 23 | extern void _usrv_start(void); 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 _VM_AMAP_H_ 17 | #define _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 | unsigned int refs; 29 | page_t *page; 30 | } anon_t; 31 | 32 | 33 | typedef struct _amap_t { 34 | lock_t lock; 35 | unsigned int refs, size; 36 | anon_t *anons[]; 37 | } amap_t; 38 | 39 | 40 | extern page_t *amap_page(struct _vm_map_t *map, amap_t *amap, struct _vm_object_t *o, void *vaddr, int aoffs, off_t offs, int prot); 41 | 42 | 43 | extern void amap_clear(amap_t *amap, size_t offset, size_t size); 44 | 45 | 46 | extern void amap_putanons(amap_t *amap, int offs, int size); 47 | 48 | 49 | extern void amap_getanons(amap_t *amap, int offs, int size); 50 | 51 | 52 | extern amap_t *amap_create(amap_t *amap, int *offset, size_t size); 53 | 54 | 55 | extern void amap_put(amap_t *amap); 56 | 57 | 58 | extern amap_t *amap_ref(amap_t *amap); 59 | 60 | 61 | extern void _amap_init(struct _vm_map_t *kmap, struct _vm_object_t *kernel); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /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 _VM_KMALLOC_H_ 17 | #define _VM_KMALLOC_H_ 18 | 19 | #include "hal/hal.h" 20 | 21 | 22 | extern void *vm_kmalloc(size_t size); 23 | 24 | 25 | extern void vm_kfree(void *p); 26 | 27 | 28 | extern void vm_kmallocGetStats(size_t *allocsz); 29 | 30 | 31 | extern void vm_kmallocDump(void); 32 | 33 | 34 | extern int _kmalloc_init(void); 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /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 _VM_OBJECT_H_ 17 | #define _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 | unsigned 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 | extern vm_object_t *vm_objectRef(vm_object_t *o); 40 | 41 | 42 | extern int vm_objectGet(vm_object_t **o, oid_t oid); 43 | 44 | 45 | extern int vm_objectPut(vm_object_t *o); 46 | 47 | 48 | extern page_t *vm_objectPage(struct _vm_map_t *map, amap_t **amap, vm_object_t *o, void *vaddr, off_t offs); 49 | 50 | 51 | extern vm_object_t *vm_objectContiguous(size_t size); 52 | 53 | 54 | extern int _object_init(struct _vm_map_t *kmap, vm_object_t *kernel); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /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 _VM_PAGE_H_ 18 | #define _VM_PAGE_H_ 19 | 20 | #include "hal/hal.h" 21 | #include "include/sysinfo.h" 22 | 23 | 24 | extern page_t *vm_pageAlloc(size_t size, u8 flags); 25 | 26 | 27 | extern void vm_pageFree(page_t *lh); 28 | 29 | 30 | extern page_t *_page_get(addr_t addr); 31 | 32 | 33 | extern void _page_showPages(void); 34 | 35 | 36 | extern int page_map(pmap_t *pmap, void *vaddr, addr_t pa, int attr); 37 | 38 | 39 | extern int _page_sbrk(pmap_t *pmap, void **bss, void **top); 40 | 41 | 42 | extern void vm_pageGetStats(size_t *freesz); 43 | 44 | 45 | extern void vm_pageinfo(meminfo_t *info); 46 | 47 | 48 | extern void _page_init(pmap_t *pmap, void **bss, void **top); 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /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 | 26 | 27 | struct { 28 | void *bss; 29 | void *top; 30 | } vm; 31 | 32 | 33 | void vm_meminfo(meminfo_t *info) 34 | { 35 | vm_pageinfo(info); 36 | vm_mapinfo(info); 37 | } 38 | 39 | 40 | void _vm_init(vm_map_t *kmap, vm_object_t *kernel) 41 | { 42 | _pmap_init(&kmap->pmap, &vm.bss, &vm.top); 43 | _page_init(&kmap->pmap, &vm.bss, &vm.top); 44 | 45 | _map_init(kmap, kernel, &vm.bss, &vm.top); 46 | 47 | _zone_init(kmap, kernel, &vm.bss, &vm.top); 48 | _kmalloc_init(); 49 | 50 | _object_init(kmap, kernel); 51 | _amap_init(kmap, kernel); 52 | 53 | return; 54 | } 55 | -------------------------------------------------------------------------------- /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 _VM_VM_H_ 17 | #define _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 | extern void vm_meminfo(meminfo_t *info); 30 | 31 | 32 | /* Function initializes virtual memory manager */ 33 | extern void _vm_init(vm_map_t *kmap, vm_object_t *kernel); 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /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 _VM_ZALLOC_H_ 17 | #define _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 | volatile unsigned int blocks; 30 | volatile 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 | extern int _vm_zoneCreate(vm_zone_t *zone, size_t blocksz, unsigned int blocks); 40 | 41 | 42 | extern int _vm_zoneDestroy(vm_zone_t *zone); 43 | 44 | 45 | extern void *_vm_zalloc(vm_zone_t *zone, addr_t *addr); 46 | 47 | 48 | extern void _vm_zfree(vm_zone_t *zone, void *vaddr); 49 | 50 | 51 | extern void _zone_init(vm_map_t *map, vm_object_t *kernel, void **bss, void **top); 52 | 53 | 54 | #endif 55 | --------------------------------------------------------------------------------