phoenix-rtos / phoenix-rtos-kernel Goto Github PK
View Code? Open in Web Editor NEWPhoenix-RTOS microkernel repository
Home Page: http://phoenix-rtos.com
License: BSD 3-Clause "New" or "Revised" License
Phoenix-RTOS microkernel repository
Home Page: http://phoenix-rtos.com
License: BSD 3-Clause "New" or "Revised" License
Some hints:
Maps should be defined by loader before kernel is started. SYSPAGE should be used to pass map description during kernel bootstrap.
Processes should be assigned to particular maps and MPU registers should be used to provide separation between maps.
Message passing should be modified to be aware on passing data between separated maps (copying should be used instead of passing pointer when source map is unavailable for destination process.
phoenix-rtos-kernel/src/hal/armv7/stm32l1.c
Line 388 in 2a6d794
Need to fix with caution (perform power consuption measurements)
Missing break in switch-case:
phoenix-rtos-kernel/hal/armv7m/imxrt/10xx/imxrt10xx.c
Lines 214 to 218 in f84dea0
Found while toying with sonarscanner software (https://sonarcloud.io/project/issues?id=nalajcie_phoenix-rtos-project&issues=AXcHQntzk8qWjK72eCGK&open=AXcHQntzk8qWjK72eCGK).
Might affect also other archs.
Currently, it is assumed that PLIC is always present what can cause an exception on platforms without it (like spike). PLIC should be detected by parsing DTB during kernel startup and used only when it is present."
_init-imxrt.S:61 gcc assumes 0 after this trailing comma, which changes offsets. Should there be a zero, or should there be no comma?
Currently memory passing optimizes passing of large data by loaning pages between processes. This mechanisms assumes that pages exists in memory, so lazy binding is not supported.
I checked what effect the use of __attribute__((packed))
at structure has on code size for the ARM.
I considered two structures with and without attribute packed set:
platformctl_t
and syspage_t
.
To check the code size, I used the program size
column text
.
pack no pack diff
imx6ull.elf 58126 57858 268
stm32l152xd.elf 62860 62708 152
stm32l152xe.elf 62860 62708 152
stm32l4x6.elf 62688 62536 152
imxrt105x.elf 63104 62832 272
imxrt106x.elf 63104 62832 272
imxrt117x.elf 60436 60108 328
pack no pack diff
imx6ull.elf 58126 58126 0
stm32l152xd.elf 62860 62540 320
stm32l152xe.elf 62860 62540 320
stm32l4x6.elf 62688 62360 328
imxrt105x.elf 63104 61884 1220
imxrt106x.elf 63104 61884 1220
imxrt117x.elf 60436 59216 1220
pack no pack diff
imxrt105x.elf 28542 27922 620
imxrt106x.elf 28542 27922 620
imxrt117x.elf 24778 24158 620
The size of the structures increases very little without packed.
An example of a simple function from a file hal/armv7m/imxrt/pmap.c
:
int pmap_getMapsCnt(void)
{
return syspage->mapssz;
}
struct syspage_t
with attribute pack set:
00000000 <pmap_getMapsCnt>:
0: 4b08 ldr r3, [pc, #32] ; (24 <pmap_getMapsCnt+0x24>)
2: 681a ldr r2, [r3, #0]
4: f892 0029 ldrb.w r0, [r2, #41] ; 0x29
8: f892 3028 ldrb.w r3, [r2, #40] ; 0x28
c: f892 102a ldrb.w r1, [r2, #42] ; 0x2a
10: ea43 2300 orr.w r3, r3, r0, lsl #8
14: f892 002b ldrb.w r0, [r2, #43] ; 0x2b
18: ea43 4301 orr.w r3, r3, r1, lsl #16
1c: ea43 6000 orr.w r0, r3, r0, lsl #24
20: 4770 bx lr
22: bf00 nop
24: 00000000 .word 0x00000000 24: R_ARM_ABS32 syspage
struct syspage_t
without attribute pack set:
00000000 <pmap_getMapsCnt>:
0: 4b01 ldr r3, [pc, #4] ; (8 <pmap_getMapsCnt+0x8>)
2: 681b ldr r3, [r3, #0]
4: 6a98 ldr r0, [r3, #40] ; 0x28
6: 4770 bx lr
8: 00000000 .word 0x00000000 8: R_ARM_ABS32 syspage
An explanation of this is in the GCC
documentation:
-munaligned-access
-mno-unaligned-access
Enables (or disables) reading and writing of 16- and 32- bit values from addresses that are not 16- or 32- bit aligned. By default unaligned access is disabled for all pre-ARMv6, all ARMv6-M and for ARMv8-M Baseline architectures, and enabled for all other architectures. If unaligned access is not enabled then words in packed data structures are accessed a byte at a time.
The ARM attribute Tag_CPU_unaligned_access is set in the generated object file to either true or false, depending upon the setting of this option. If unaligned access is enabled then the preprocessor symbol __ARM_FEATURE_UNALIGNED is also defined.
Conclusion:
Using __attribute__((pack))
with structures and GCC
flag -mno-unaligned-access
on ARM causes in a large in increase code and performance degradation.
Is it necessary to use attribute pack for these two structures (in imx6ull
at syspage_t
does not have it)?
An interrupt coming after _hal_cpuSetKernelStack() in proc_fork() could potentially corrupt kernel stack. Consider disabling interrupts in proc_fork().
@Maxez Think this through
Steps to reproduce:
Problem detected on ia32 and confirmed on arm-imx6ull.
Why is offs_t type ( 64 bit ) used in structures, if the buffer size is only 2 * SIZE_PAGE.
Using 64 bit variables increases code size and decreases performance.
Comparison of code size for 32 bit and 64 bit:
armv7a7 64:
_klog_msgRespond 00000048 72
_klog_readln.isra.0 000000d4 212
msgthr 00000230 560
klog_write 000001d0 464
_klog_init 00000038 56
_klog_initSrv 00000034 52
armv7a7 32:
_klog_msgRespond 00000048 72
_klog_readln.isra.0 00000080 128
msgthr 0000021c 540
klog_write 000000f0 240
_klog_init 00000038 56
_klog_initSrv 00000034 52
i386 64:
_klog_readln 0000010a 266
_klog_msgRespond 0000007b 123
msgthr 000003a5 933
klog_write 000002e9 745
_klog_init 00000050 80
_klog_initSrv 00000036 54
i386 32:
_klog_msgRespond 0000007b 123
_klog_readln.isra.0 00000080 128
msgthr 000003b5 949
klog_write 0000012b 299
_klog_init 00000050 80
_klog_initSrv 00000036 54
When no CPIO is linked the following instructions:
/* Happens in QEMU when programs are not page aligned. What the hell? */
cpio = (void *)(programs - 0x1000);
if (hal_strncmp(cpio->c_magic, "070701", 6)) {
lib_printf("programs: valid cpio archive not found\n");
return -EINVAL;
}
lib_printf("programs: cpio archive found dislocated\n");
can cause access to unauthorized memory. For example when on armv7m7-imxrt106x there is no CPIO
under programs symbol (which is set to 0x20000000), programs-0x1000 will point to reserved memory.
Allocates new memory instead of given address.
Function hal_cpuPushSignal
is not implemented on this architecture. I tried to use signals on imxrt1064 CPU.
phoenix-rtos-kernel/hal/armv7m/cpu.h
Line 333 in f84dea0
When sending a long message, we should either use sender's page attributes when remapping or do cache maintenance to handle mismatched attributes.
Is it really necessary to check namelen < 0
in posix_gethostname()
and posix_sethostname()
functions, if namelen
is of type size_t
and will never be < 0
.
The compiler skips this condition.
threads.c: In function 'threads_schedule':
threads.c:641:3: warning: implicit declaration of function 'cpu_sendIPI' [-Wimplicit-function-declaration]
641 | cpu_sendIPI(0, 32);
phoenix-rtos-kernel/src/proc/threads.c:641: undefined reference to `cpu_sendIPI'
Messages:
warning: listing the stack pointer register 'esp' in a clobber list is deprecated [-Wdeprecated]
note: the value of the stack pointer after an 'asm' statement must be the same as it was before the statement
files:
vm/page-nommu.c: In function '_page_init':
./hal/armv7/pmap.h:24:41: error: 'RAM_SIZE' undeclared (first use in this function)
24 | #define VADDR_MAX (VADDR_KERNEL + RAM_SIZE * 1024)
| ^~~~~~~~
hal/armv7/_init-stm32.S: Assembler messages:
hal/armv7/_init-stm32.S:63: Error: invalid operands (*ABS* and *UND* sections) for `*'
For example:
lib_printf("%-16s", "TEST")
There is a compilation error for TARGET=ia32-generic:
proc/process.c: In function 'process_load64':
proc/process.c:427:11: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
427 | vaddr = (void *)((unsigned long)phdr->p_vaddr & ~(phdr->p_align - 1));
| ^
proc/process.c: In function 'proc_syspageSpawnName':
proc/process.c:879:25: error: 'syspage_t' {aka 'struct _syspage_t'} has no member named 'mapssz'
879 | for (i = 0; i < syspage->mapssz; ++i) {
| ^~
proc/process.c:882:31: error: 'syspage_t' {aka 'struct _syspage_t'} has no member named 'maps'
882 | if (!hal_strcmp(map, syspage->maps[i].name)) {
| ^~
proc/process.c:885:10: error: 'syspage_program_t' {aka 'struct syspage_program_t'} has no member named 'dmap'
885 | prog->dmap = i;
| ^~
For TARGET=arm*
is the same.
Spawning multiple processes through syspage
fails, leading to the number of instances being multiplied to the power of two (see the attached screen shots). I've checked syspage
content forwarded from plo
to the kernel
and it looks ok, thus it seems an issue of kernel
process spawn. I have verified this only on armv7m7-imxrt106x
target so it may be NOMMU
specific and may be observed on armv7m7-imxrt117x
too.
This issue may be linked with Jira tasks ([RTOS-1] multiple sysexec usage fails) and [NIL-20], although I've not verified psh
sysexec
behavior, but it looks similar.
Simple program which may be used to reproduce:
#include <stdio.h>
#include <unistd.h>
#include <sys/msg.h>
int main(int argc, char *argv[])
{
oid_t oid;
/* wait for dummyfs & imxrt-multi */
while (lookup("/dev", NULL, &oid) < 0)
sleep(1);
printf("spawn test id %s\n", argc == 2 ? argv[1] : "(no id)");
for (;;)
sleep(1);
return 0;
}
Aliases are common to all of the cases below, and they are the following:
alias phoenix-armv7m7-imxrt106x.elf 0x11000 0xf600
alias dummyfs 0x20600 0x8c00
alias spawn_test 0x29200 0x4000
alias imxrt-multi 0x2d200 0x7e00
alias psh 0x35000 0x19800
app flash1 -x dummyfs xip1 dtcm
app flash1 -x imxrt-multi xip1 dtcm
app flash1 -x psh xip1 ocram2
app flash1 -x spawn_test;1 xip1 ocram2
app flash1 -x dummyfs xip1 dtcm
app flash1 -x imxrt-multi xip1 dtcm
app flash1 -x psh xip1 ocram2
app flash1 -x spawn_test;1 xip1 ocram2
app flash1 -x spawn_test;2 xip1 ocram2
app flash1 -x dummyfs xip1 dtcm
app flash1 -x imxrt-multi xip1 dtcm
app flash1 -x psh xip1 ocram2
app flash1 -x spawn_test;1 xip1 ocram2
app flash1 -x spawn_test;2 xip1 ocram2
app flash1 -x spawn_test;3 xip1 ocram2
app flash1 -x dummyfs xip1 dtcm
app flash1 -x imxrt-multi xip1 dtcm
app flash1 -x psh xip1 ocram2
app flash1 -x spawn_test;1 xip1 ocram2
app flash1 -x spawn_test;2 xip1 ocram2
app flash1 -x spawn_test;3 xip1 ocram2
app flash1 -x spawn_test;4 xip1 ocram2
app flash1 -x dummyfs xip1 dtcm
app flash1 -x imxrt-multi xip1 dtcm
app flash1 -x psh xip1 ocram2
app flash1 -x spawn_test;1 xip1 ocram2
app flash1 -x spawn_test;2 xip1 ocram2
app flash1 -x spawn_test;3 xip1 ocram2
app flash1 -x spawn_test;4 xip1 ocram2
app flash1 -x spawn_test;5 xip1 ocram2
Above and including four spawned instances system stopped responding nether psh
was working nor imxrt-multi
console input. I tried different combination of maps although using (imap=ocram2, dmap=ocram2) any time it looked the same.
we need real rename functionality in order to make link work as it should (and it should be able to fail)
test_malloc from libphoenix fails on malloc((size_t) 0x7fffffff)) test. map_pageFault gets called after out of range access to amap->anons array in amap.c:173.
Problem specific to ia32. The test passes on arm-imx6ull.
On NOMMU architectures _map_remove() and _map_add() both take process' lock to protect it's list of map_entries. Currently it will cause deadlock e.g. when killing the process.
Unfortunately, on the newest qemu-system-riscv64 system is unable to boot. It can be caused by adding to qemu support for OpenSBI. Some investigation should be done.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.