Giter VIP home page Giter VIP logo

phoenix-rtos-kernel's Introduction

phoenix-rtos-kernel

This repository contains the source for the Phoenix-RTOS microkernel.

Supported targets:

  • armv7m4-stm32l4x6
  • armv7m7-imxrt105x
  • armv7m7-imxrt106x
  • armv7m7-imxrt117x
  • armv7a7-imx6ull
  • armv7a9-zynq7000
  • ia32-generic
  • riscv64-generic
  • sparcv8leon3-gr716

Building kernel

To compile the kernel and build the operating system image phoenix-rtos-project repository should be used. Please read the instruction in this repository.

License

This work is licensed under a BSD license. See the LICENSE file for details.

phoenix-rtos-kernel's People

Contributors

adamdebek avatar agkaminski avatar anglov avatar astalke avatar badochov avatar cinek28 avatar damianloew avatar darchiv avatar gerard5 avatar ignorek avatar jmaksymowicz avatar js6i avatar kaman avatar kemonats avatar kwasik avatar lukileczo avatar maciejpurski avatar maxez avatar michalslomczynski avatar nalajcie avatar niewim19 avatar osctobe avatar pawelpisarczyk avatar xvuko avatar youki0 avatar ziemleszcz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phoenix-rtos-kernel's Issues

link can't fail

we need real rename functionality in order to make link work as it should (and it should be able to fail)

programs_decode: fix for QEMU cpio parsing can cause unathorized access

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.

riscv64: Adding support for latest qemu.

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.

Error compiling kernel TARGET=ia32-generic

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.

Adding full suport of multiple memory maps on NOMMU arcthitectures.

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.

test_malloc fails on ia32

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.

armv7: Compilation error, missing RAM_SIZE

armv7m7-imx:

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)
      |                                         ^~~~~~~~

armv7m3-stm armv7m4-stm:

hal/armv7/_init-stm32.S: Assembler messages:
hal/armv7/_init-stm32.S:63: Error: invalid operands (*ABS* and *UND* sections) for `*'

arm: Compilation error, missing cpu_sendIPI

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'

imxrt: Lone comma in _init-imxrt.S

_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?

Spawn of multiple processes through `syspage` fails.

Description

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      

One instance:

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

one

Two instances:

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

two

Three instances:

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

three

Four instances:

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

four

Five instance:

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

five

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.

Deadlock in NOMMU memory management

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.

Structure with __attribute__((packed)) in ARM

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.

The results:

platformctl_t

                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

syspage_t

kernel

                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

plo

                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)?

Disabling interrupts in proc_fork()?

An interrupt coming after _hal_cpuSetKernelStack() in proc_fork() could potentially corrupt kernel stack. Consider disabling interrupts in proc_fork().
@Maxez Think this through

Many warnings when creating the ia32 kernel with gcc 9.3.0

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:

  • cpu.c:277
  • spinlock.h:72

klog: offs_t type in structures

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.