C Microkernel Realtime eXecutive
Realtime Operating System for Cortex-M based microcontrollers
 
Loading...
Searching...
No Matches

Linux port provides the ability to run CMRX-based environment hosted on ordinary Linux machine as a ordinary userspace process. More...

Modules

 Implementation details
 This group contains platform-specific routines that implement internal behavior of this port.
 
 Linux timing provider
 This is the default (and the only) timing provider for the Linux target platform.
 

Macros

#define CMRX_VTABLE_SECTION_STR3(section_symbol)   # section_symbol
 Linux port specifier for vtables.
 
#define CMRX_VTABLE_SECTION_STR2(application_name)   CMRX_VTABLE_SECTION_STR3(vtable_ ## application_name)
 
#define CMRX_VTABLE_SECTION_STR(application_name)   CMRX_VTABLE_SECTION_STR2(application_name)
 
#define CMRX_VTABLE_SECTION_START2(application_name)   __start_vtable_ ## application_name
 
#define CMRX_VTABLE_SECTION_START(application_name)   CMRX_VTABLE_SECTION_START2(application_name)
 
#define CMRX_VTABLE_SECTION_STOP2(application_name)   __stop_vtable_ ## application_name
 
#define CMRX_VTABLE_SECTION_STOP(application_name)   CMRX_VTABLE_SECTION_STOP2(application_name)
 
#define CMRX_VTABLE_SECTION   CMRX_VTABLE_SECTION_STR(APPLICATION_NAME)
 
#define CMRX_VTABLE_SPECIFIER   __attribute__((section(CMRX_VTABLE_SECTION))) const
 
#define CMRX_APPLICATION_INSTANCE_CONSTRUCTOR(application)
 Linux port implementation of application creation macro.
 
#define CMRX_THREAD_AUTOCREATE_CONSTRUCTOR(application, entrypoint, data, priority, core)
 Linux port implementation of thread autostart.
 

Functions

long CMRX_VTABLE_SECTION_START (APPLICATION_NAME)
 
long CMRX_VTABLE_SECTION_STOP (APPLICATION_NAME)
 

Detailed Description

Linux port provides the ability to run CMRX-based environment hosted on ordinary Linux machine as a ordinary userspace process.

Linux architecture support is an environment where CMRX scheduler and kernel API runs hosted as ordinary Linux process. Here CMRX uses Linux' own syscalls to implement functionality of the abstract machine.

The environment which Linux-based environment creates encapsulates whole system into one process. All CMRX processes share common address space. This is similar to other architectures which CMRX currently supports.

Macro Definition Documentation

◆ CMRX_APPLICATION_INSTANCE_CONSTRUCTOR

#define CMRX_APPLICATION_INSTANCE_CONSTRUCTOR (   application)
Value:
void * __APPL_SYMBOL(application, data_start) = (void *) 1;\
void * __APPL_SYMBOL(application, data_end) = (void *) 1;\
void * __APPL_SYMBOL(application, bss_start) = (void *) 1;\
void * __APPL_SYMBOL(application, bss_end) = (void *) 1;\
void * __APPL_SYMBOL(application, shared_start) = (void *) 1;\
void * __APPL_SYMBOL(application, shared_end) = (void *) 1;\
void * __APPL_SYMBOL(application, vtable_start) = (void *) 1;\
void * __APPL_SYMBOL(application, vtable_end) = (void *) 1;\
\
const struct OS_process_definition_t __APPL_SYMBOL(application, instance) = {\
{\
{ &__APPL_SYMBOL(application, data_start), &__APPL_SYMBOL(application, data_end) },\
{ &__APPL_SYMBOL(application, bss_start), &__APPL_SYMBOL(application, bss_end) },\
{ __APPL_SYMBOL(application, mmio_start), __APPL_SYMBOL(application, mmio_end) },\
{ __APPL_SYMBOL(application, mmio_2_start), __APPL_SYMBOL(application, mmio_2_end) },\
{ &__APPL_SYMBOL(application, shared_start), &__APPL_SYMBOL(application, shared_end) }\
},\
{ &CMRX_VTABLE_SECTION_START(application), &CMRX_VTABLE_SECTION_STOP(application) }\
};\
__attribute__((constructor)) void __APPL_SYMBOL(application, inst_construct)(void)\
{\
cmrx_posix_register_application(&__APPL_SYMBOL(application, instance));\
}
#define CMRX_VTABLE_SECTION_START(application_name)
Definition application.h:58
#define CMRX_VTABLE_SECTION_STOP(application_name)
Definition application.h:61
Static definition of process in firmware image.
Definition runtime.h:31

Linux port implementation of application creation macro.

As of now this macro does nothing. It is here just to make this port conformal to the API.

◆ CMRX_THREAD_AUTOCREATE_CONSTRUCTOR

#define CMRX_THREAD_AUTOCREATE_CONSTRUCTOR (   application,
  entrypoint,
  data,
  priority,
  core 
)
Value:
const struct OS_thread_create_t __APPL_SYMBOL(application, thread_create_ ## entrypoint) = {\
&__APPL_SYMBOL(application, instance),\
data,\
}; \
__attribute__((constructor)) void __APPL_SYMBOL(application, thread_create_ ## entrypoint ## _construct)(void)\
{\
cmrx_posix_register_thread(&__APPL_SYMBOL(application, thread_create_ ## entrypoint));\
}
struct OS_core_state_t core[OS_NUM_CORES]
CPU scheduling thread IDs.
Definition sched.c:37
Structure describing auto-spawned thread.
Definition runtime.h:46
void * data
User data passed to entrypoint function.
Definition runtime.h:54
uint8_t priority
Thread priority.
Definition runtime.h:57
entrypoint_t * entrypoint
Entrypoint address.
Definition runtime.h:51

Linux port implementation of thread autostart.

Thread autostart is implemented by creating instance of structure describing thread to be created and creating a function that calls cmrx_posix_register_thread. This function is marked as constructor which ensures it is called before the main is started.

See OS_THREAD_CREATE for more details in arguments.

◆ CMRX_VTABLE_SECTION

#define CMRX_VTABLE_SECTION   CMRX_VTABLE_SECTION_STR(APPLICATION_NAME)

◆ CMRX_VTABLE_SECTION_START

#define CMRX_VTABLE_SECTION_START (   application_name)    CMRX_VTABLE_SECTION_START2(application_name)

◆ CMRX_VTABLE_SECTION_START2

#define CMRX_VTABLE_SECTION_START2 (   application_name)    __start_vtable_ ## application_name

◆ CMRX_VTABLE_SECTION_STOP

#define CMRX_VTABLE_SECTION_STOP (   application_name)    CMRX_VTABLE_SECTION_STOP2(application_name)

◆ CMRX_VTABLE_SECTION_STOP2

#define CMRX_VTABLE_SECTION_STOP2 (   application_name)    __stop_vtable_ ## application_name

◆ CMRX_VTABLE_SECTION_STR

#define CMRX_VTABLE_SECTION_STR (   application_name)    CMRX_VTABLE_SECTION_STR2(application_name)

◆ CMRX_VTABLE_SECTION_STR2

#define CMRX_VTABLE_SECTION_STR2 (   application_name)    CMRX_VTABLE_SECTION_STR3(vtable_ ## application_name)

◆ CMRX_VTABLE_SECTION_STR3

#define CMRX_VTABLE_SECTION_STR3 (   section_symbol)    # section_symbol

Linux port specifier for vtables.

◆ CMRX_VTABLE_SPECIFIER

#define CMRX_VTABLE_SPECIFIER   __attribute__((section(CMRX_VTABLE_SECTION))) const

Function Documentation

◆ CMRX_VTABLE_SECTION_START()

long CMRX_VTABLE_SECTION_START ( APPLICATION_NAME  )
extern

◆ CMRX_VTABLE_SECTION_STOP()

long CMRX_VTABLE_SECTION_STOP ( APPLICATION_NAME  )
extern

◆ mpu_init_stack()

int mpu_init_stack ( int  thread_id)

Initialize MPU for stack of thread.

Performs initialization of the MPU to enable the given thread to use the stack.

Parameters
thread_idThread stack has to be initialized for

◆ mpu_restore()

int mpu_restore ( const MPU_State hosted_state,
const MPU_State parent_state 
)

Load MPU settings.

Loads MPU settings for default amount of regions from off-CPU buffer. This is suitable for store-resume during task switching.

Parameters
hosted_stateMPU state buffer for the current host process
parent_stateMPU state buffer for the parent process

◆ os_boot_thread()

void os_boot_thread ( Thread_t  boot_thread)

Will unblock the boot thread.

Start executing thread.

Unblock the boot thread. Then this function continues listening for signals for timer and thread switching requests.

◆ os_core_sleep()

void os_core_sleep ( void  )

Park current core This function is free to park current core in whatever way that will still allow the core to be woken up by external interrupts.

◆ os_init_arch()

void os_init_arch ( void  )

Configure Linux architecture behavior.

Perform architecture-specific initialization during kernel startup.

We will use SIGUSR1 handler as a machinery to actually switch threads. This routine will find the next thread, pause current one and then restart the other.

The SIGUSR2 handler serves the purpose of forcing the thread to cooperate on thread switching. Whenever a thread is commanded SIGUSR2, it will enter waiting and will remain waiting until there is a command to resume execution.

This is the next best thing that can be done in order to simulate thread scheduling.

◆ os_kernel_shutdown()

void os_kernel_shutdown ( )

Stop running the kernel.

Return to bare metal execution mode similar to one after CPU reset. This function should configure the CPU to continue execution in privileged mode not distinguishing between thread and kernel space. Once this mode is configured the function cmrx_shutdown_handler() should be executed.

This is a point of no return. Code here is free to destroy any previous context.

Stop running the kernel.

This is platform-specific way of how to shutdown the kernel. In this case an interrupt frame is forged on stack that will resemble a frame returning back to the cmrx_shutdown_handler function. The result of running this function will be that the processor leaves the handler mode, enters privileged thread mode and will be using MSP.

◆ os_memory_protection_start()

void os_memory_protection_start ( )

Start memory protection.

Initialize hardware memory protection unit so that following conditions are met:

  • RAM is not executable
  • kernel can execute all the flash and read/write all the RAM
  • FLASH can optionally be executable from userspace, if hardware is not capable enough to allow for fine-grained execution access. Kernel must be able to continue execution past this point.

◆ os_memory_protection_stop()

void os_memory_protection_stop ( )

Disable memory protection.

Disables memory protection unit so that no rules are enforced by the hardware. The CPU state after this call should resemble MPU state after reset.

◆ os_process_create()

int os_process_create ( Process_t  process_id,
const struct OS_process_definition_t definition 
)

Platform-specific way of initializing threads.

Create process using process definition.

Nothing is done here. No special facilities for processes in this port.

◆ os_request_context_switch()

void os_request_context_switch ( bool  activate)
inline

Set/clear thread switch request flag.

Request context switch.

Parameters
activatenew value of the flag

◆ os_rpc_call()

int os_rpc_call ( unsigned long  arg0,
unsigned long  arg1,
unsigned long  arg2,
unsigned long  arg3 
)

Kernel implementation of rpc_call syscall.

This routine performs remote procedure call. It digs for 5th and 6th argument passed to _rpc_call() on thread stack. Retrieves address of called method from service VMT and synthesizes stack frame for jumping into this method. Arguments used to call _rpc_call() are passed to callee.

◆ os_rpc_return()

int os_rpc_return ( uint32_t  arg0,
uint32_t  arg1,
uint32_t  arg2,
uint32_t  arg3 
)

Kernel implementation of rpc_return syscall.

This syscall has to return the control back to the code which called rpc_call. This has to be done in a way that the calling code will be able to access the return value of the RPC method.

◆ os_set_syscall_return_value()

int os_set_syscall_return_value ( Thread_t  thread_id,
int32_t  retval 
)

Set return value of syscall for given thread.

Parameters
thread_idId of the thread whose exception handler is being modified
retvalvalue to store on the stack

◆ os_syscalls_end()

struct Syscall_Entry_t * os_syscalls_end ( void  )

◆ os_syscalls_start()

struct Syscall_Entry_t * os_syscalls_start ( void  )

◆ os_thread_initialize_arch()

void os_thread_initialize_arch ( struct OS_thread_t thread,
unsigned  stack_size,
entrypoint_t *  entrypoint,
void *  data 
)

Perform platform-specific initialization of thread.

Perform architecture-specific thread initialization This function should perform the following actions:

This will initialize facilities for thread synchronization. Here we will create pipe pair used to block the thread on external request and the Linux thread is created for the CMRX thread.

◆ static_init_process_count()

unsigned static_init_process_count ( )

Provides count of statically initialized processes.

Returns
amount of processes that have to be statically initialized

◆ static_init_process_table()

const struct OS_process_definition_t * static_init_process_table ( )

Provides address of statically intialized process table.

Returns
address of table containins details of statically initialized processes

◆ static_init_thread_count()

unsigned static_init_thread_count ( )

Provides count of statically initialized threads.

Returns
amount of threads that have to be statically initialized

◆ static_init_thread_table()

const struct OS_thread_create_t * static_init_thread_table ( )

Provides address of statically initialized thread table.

Returns
address of table containing details of statically initialized threads