From 354254c64d687d4f8b07589c47f898edf0c7a13b Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Fri, 18 Feb 2022 00:31:15 +0530 Subject: [PATCH 1/6] Pthread --- src/include/call_type.h | 24 ++++ src/include/machine_call.h | 5 +- src/include/supervisor_call.h | 14 +-- src/lib/libposix/include/posix/sys/types.h | 118 +++++++++--------- src/lib/libposix/src/posix_pthread.c | 88 +++++++++++-- .../workers/scall/supervisory_call.c | 2 +- .../terravisor/workers/mcall/machine_call.c | 2 +- 7 files changed, 170 insertions(+), 83 deletions(-) create mode 100644 src/include/call_type.h diff --git a/src/include/call_type.h b/src/include/call_type.h new file mode 100644 index 00000000..ae364dc0 --- /dev/null +++ b/src/include/call_type.h @@ -0,0 +1,24 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2019, Cyancore Team + * + * File Name : call_type.c + * Description : This file consists of call_typedef + * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#pragma once + +#if defined(ARCH_ARM_32) +#define __CALL_ARG_TYPE__ unsigned long + +#elif defined(ARCH_RISCV_64) || defined(ARCH_ARM_64) +#define __CALL_ARG_TYPE__ unsigned long + +#else +#define __CALL_ARG_TYPE__ unsigned int + +#endif + +typedef __CALL_ARG_TYPE__ call_args; diff --git a/src/include/machine_call.h b/src/include/machine_call.h index b3638963..a5a4f4cc 100644 --- a/src/include/machine_call.h +++ b/src/include/machine_call.h @@ -13,6 +13,7 @@ #include #include +#include // Machine call IDs typedef enum mcall_id @@ -22,8 +23,6 @@ typedef enum mcall_id set_sleep_mode = 0x0003, } mcall_id_t; - - typedef struct mret { uintptr_t p; @@ -34,7 +33,7 @@ typedef struct mret typedef struct mcall { mcall_id_t id; - mret_t (*callback)(unsigned int a0, unsigned int a1, unsigned int a2); + mret_t (*callback)(call_args a0, call_args a1, call_args a2); } mcall_t; #define INCLUDE_MCALL(_name, _id , _callback) \ diff --git a/src/include/supervisor_call.h b/src/include/supervisor_call.h index 7bbb54b1..8d955f0a 100644 --- a/src/include/supervisor_call.h +++ b/src/include/supervisor_call.h @@ -13,6 +13,7 @@ #include #include +#include // Supervisor call IDs typedef enum scall_id @@ -20,16 +21,7 @@ typedef enum scall_id scall_id_generic = 0x0000, scall_id_is_irq, /* pthread related */ - scall_id_pthread_attr_destroy = 0x1000, - scall_id_pthread_attr_getdetachstate, - scall_id_pthread_attr_getschedparam, - scall_id_pthread_attr_getstacksize, - scall_id_pthread_attr_init, - scall_id_pthread_attr_setdetachstate, - scall_id_pthread_attr_setschedparam, - scall_id_pthread_attr_setschedpolicy, - scall_id_pthread_attr_setstacksize, - scall_id_pthread_barrier_destroy, + scall_id_pthread_barrier_destroy = 0x1000, scall_id_pthread_barrier_init, scall_id_pthread_barrier_wait, scall_id_pthread_create, @@ -84,7 +76,7 @@ typedef struct sret typedef struct scall { scall_id_t id; - sret_t (*callback)(unsigned int a0, unsigned int a1, unsigned int a2); + sret_t (*callback)(call_args a0, call_args a1, call_args a2); } scall_t; #define INCLUDE_SCALL(_name, _id , _callback) \ diff --git a/src/lib/libposix/include/posix/sys/types.h b/src/lib/libposix/include/posix/sys/types.h index 11ed4c4e..84d3755c 100644 --- a/src/lib/libposix/include/posix/sys/types.h +++ b/src/lib/libposix/include/posix/sys/types.h @@ -25,8 +25,8 @@ * * Enabled/disabled by posixconfigENABLE_CLOCK_T. */ -#if !defined( posixconfigENABLE_CLOCK_T ) || ( posixconfigENABLE_CLOCK_T == 1 ) - typedef uint32_t clock_t; +#if !defined(posixconfigENABLE_CLOCK_T) || (posixconfigENABLE_CLOCK_T == 1) +typedef uint32_t clock_t; #endif /** @@ -34,8 +34,8 @@ * * Enabled/disabled by posixconfigENABLE_CLOCKID_T. */ -#if !defined( posixconfigENABLE_CLOCKID_T ) || ( posixconfigENABLE_CLOCKID_T == 1 ) - typedef int clockid_t; +#if !defined(posixconfigENABLE_CLOCKID_T) || (posixconfigENABLE_CLOCKID_T == 1) +typedef int clockid_t; #endif /** @@ -43,8 +43,8 @@ * * Enabled/disabled by posixconfigENABLE_MODE_T. */ -#if !defined( posixconfigENABLE_MODE_T ) || ( posixconfigENABLE_MODE_T == 1 ) - typedef int mode_t; +#if !defined(posixconfigENABLE_MODE_T) || (posixconfigENABLE_MODE_T == 1) +typedef int mode_t; #endif /** @@ -52,8 +52,8 @@ * * Enabled/disabled by posixconfigENABLE_PID_T. */ -#if !defined( posixconfigENABLE_PID_T ) || ( posixconfigENABLE_PID_T == 1 ) - typedef int pid_t; +#if !defined(posixconfigENABLE_PID_T) || (posixconfigENABLE_PID_T == 1) +typedef int pid_t; #endif /** @@ -61,14 +61,14 @@ * * Enabled/disabled by posixconfigENABLE_PTHREAD_ATTR_T. */ -#if !defined( posixconfigENABLE_PTHREAD_ATTR_T ) || ( posixconfigENABLE_PTHREAD_ATTR_T == 1 ) - typedef struct pthread_attr - { - int detach_state; - int policy; - sched_param_t sched_param; - size_t stacksize; - }pthread_attr_t; +#if !defined(posixconfigENABLE_PTHREAD_ATTR_T) || (posixconfigENABLE_PTHREAD_ATTR_T == 1) +typedef struct pthread_attr +{ + int detach_state; + int policy; + sched_param_t sched_param; + size_t stacksize; +} pthread_attr_t; #endif /** @@ -76,28 +76,28 @@ * * Enabled/disabled by posixconfigENABLE_PTHREAD_BARRIER_T. */ -#if !defined( posixconfigENABLE_PTHREAD_BARRIER_T ) || ( posixconfigENABLE_PTHREAD_BARRIER_T == 1 ) - typedef struct pthread_barrier - { - /* pthread_barrier structure place holder */ - }pthread_barrier_t; +#if !defined(posixconfigENABLE_PTHREAD_BARRIER_T) || (posixconfigENABLE_PTHREAD_BARRIER_T == 1) +typedef struct pthread_barrier +{ + /* pthread_barrier structure place holder */ +} pthread_barrier_t; #endif /** * @brief Used to define a barrier attributes object. */ - typedef void * pthread_barrierattr_t; +typedef void *pthread_barrierattr_t; /** * @brief Used for condition variables. * * Enabled/disabled by posixconfigENABLE_PTHREAD_COND_T. */ -#if !defined( posixconfigENABLE_PTHREAD_COND_T ) || ( posixconfigENABLE_PTHREAD_COND_T == 1 ) - typedef struct pthread_cond - { - /* pthread_cond structure place holder */ - }pthread_cond_t; +#if !defined(posixconfigENABLE_PTHREAD_COND_T) || (posixconfigENABLE_PTHREAD_COND_T == 1) +typedef struct pthread_cond +{ + /* pthread_cond structure place holder */ +} pthread_cond_t; #endif /** @@ -105,8 +105,8 @@ * * Enabled/disabled by posixconfigENABLE_PTHREAD_CONDATTR_T. */ -#if !defined( posixconfigENABLE_PTHREAD_CONDATTR_T ) || ( posixconfigENABLE_PTHREAD_CONDATTR_T == 1 ) - typedef void * pthread_condattr_t; +#if !defined(posixconfigENABLE_PTHREAD_CONDATTR_T) || (posixconfigENABLE_PTHREAD_CONDATTR_T == 1) +typedef void *pthread_condattr_t; #endif /** @@ -114,11 +114,11 @@ * * Enabled/disabled by posixconfigENABLE_PTHREAD_MUTEX_T. */ -#if !defined( posixconfigENABLE_PTHREAD_MUTEX_T ) || ( posixconfigENABLE_PTHREAD_MUTEX_T == 1 ) - typedef struct pthread_mutex - { - /* pthread_mutex structure place holder */ - }pthread_mutex_t; +#if !defined(posixconfigENABLE_PTHREAD_MUTEX_T) || (posixconfigENABLE_PTHREAD_MUTEX_T == 1) +typedef struct pthread_mutex +{ + /* pthread_mutex structure place holder */ +} pthread_mutex_t; #endif /** @@ -126,11 +126,11 @@ * * Enabled/disabled by posixconfigENABLE_PTHREAD_MUTEXATTR_T. */ -#if !defined( posixconfigENABLE_PTHREAD_MUTEXATTR_T ) || ( posixconfigENABLE_PTHREAD_MUTEXATTR_T == 1 ) - typedef struct pthread_mutexattr - { - /* pthread_mutexattr structure place holder */ - }pthread_mutexattr_t; +#if !defined(posixconfigENABLE_PTHREAD_MUTEXATTR_T) || (posixconfigENABLE_PTHREAD_MUTEXATTR_T == 1) +typedef struct pthread_mutexattr +{ + /* pthread_mutexattr structure place holder */ +} pthread_mutexattr_t; #endif /** @@ -138,11 +138,13 @@ * * Enabled/disabled by posixconfigENABLE_PTHREAD_T. */ -#if !defined( posixconfigENABLE_PTHREAD_T ) || ( posixconfigENABLE_PTHREAD_T == 1 ) - typedef struct pthread - { - /* pthread structure place holder */ - }pthread_t; +#if !defined(posixconfigENABLE_PTHREAD_T) || (posixconfigENABLE_PTHREAD_T == 1) +typedef struct pthread +{ + pthread_attr_t *attr; + void *(*fn)(void *); + int pid; +} pthread_t; #endif /** @@ -150,8 +152,8 @@ * * Enabled/disabled by posixconfigENABLE_SSIZE_T. */ -#if !defined( posixconfigENABLE_SSIZE_T ) || ( posixconfigENABLE_SSIZE_T == 1 ) - typedef size_t ssize_t; +#if !defined(posixconfigENABLE_SSIZE_T) || (posixconfigENABLE_SSIZE_T == 1) +typedef size_t ssize_t; #endif /** @@ -159,8 +161,8 @@ * * Enabled/disabled by posixconfigENABLE_TIME_T. */ -#if !defined( posixconfigENABLE_TIME_T ) || ( posixconfigENABLE_TIME_T == 1 ) - typedef int64_t time_t; +#if !defined(posixconfigENABLE_TIME_T) || (posixconfigENABLE_TIME_T == 1) +typedef int64_t time_t; #endif /** @@ -168,8 +170,8 @@ * * Enabled/disabled by posixconfigENABLE_TIMER_T. */ -#if !defined( posixconfigENABLE_TIMER_T ) || ( posixconfigENABLE_TIMER_T == 1 ) - typedef void * timer_t; +#if !defined(posixconfigENABLE_TIMER_T) || (posixconfigENABLE_TIMER_T == 1) +typedef void *timer_t; #endif /** @@ -177,8 +179,8 @@ * * Enabled/disabled by posixconfigENABLE_USECONDS_T. */ -#if !defined( posixconfigENABLE_USECONDS_T ) || ( posixconfigENABLE_USECONDS_T == 1 ) - typedef unsigned long useconds_t; +#if !defined(posixconfigENABLE_USECONDS_T) || (posixconfigENABLE_USECONDS_T == 1) +typedef unsigned long useconds_t; #endif /** @@ -186,13 +188,13 @@ * * Enabled/disabled by posixconfigENABLE_OFF_T. */ -#if !defined( posixconfigENABLE_OFF_T ) || ( posixconfigENABLE_OFF_T == 1 ) - typedef long int off_t; +#if !defined(posixconfigENABLE_OFF_T) || (posixconfigENABLE_OFF_T == 1) +typedef long int off_t; #endif -#if( posixconfigUSE_16_BIT_TICKS == 1 ) - typedef uint16_t TickType_t; +#if (posixconfigUSE_16_BIT_TICKS == 1) +typedef uint16_t TickType_t; #else - typedef size_t TickType_t; +typedef size_t TickType_t; #endif -#define posixconfigMAX_DELAY (TickType_t)(~0) +#define posixconfigMAX_DELAY (TickType_t)(~0) diff --git a/src/lib/libposix/src/posix_pthread.c b/src/lib/libposix/src/posix_pthread.c index 0da03cda..f07d30d3 100644 --- a/src/lib/libposix/src/posix_pthread.c +++ b/src/lib/libposix/src/posix_pthread.c @@ -15,14 +15,26 @@ #include #include +pthread_mutex_t g_pthread_mutex; +pthread_mutexattr_t g_pthread_mutex_attr; + /********************* * Static Functions ********************/ +static int s_pthread_acquire_lock(void) +{ + return pthread_mutex_lock(&g_pthread_mutex); +} + +static int s_pthread_release_lock(void) +{ + return pthread_mutex_unlock(&g_pthread_mutex); +} /********************* * POSIX Functions ********************/ -int pthread_attr_destroy( pthread_attr_t * attr ) +int pthread_attr_destroy(pthread_attr_t *attr) { ASSERT_IF_FALSE(attr != NULL, int); @@ -31,7 +43,7 @@ int pthread_attr_destroy( pthread_attr_t * attr ) return SUCCESS; } -int pthread_attr_getdetachstate( const pthread_attr_t * attr, int * detachstate ) +int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate) { ASSERT_IF_FALSE(attr != NULL, int); ASSERT_IF_FALSE(detachstate != NULL, int); @@ -40,7 +52,7 @@ int pthread_attr_getdetachstate( const pthread_attr_t * attr, int * detachstate return SUCCESS; } -int pthread_attr_getschedparam( const pthread_attr_t * attr, sched_param_t * param ) +int pthread_attr_getschedparam(const pthread_attr_t *attr, sched_param_t *param) { ASSERT_IF_FALSE(attr != NULL, int); ASSERT_IF_FALSE(param != NULL, int); @@ -49,7 +61,7 @@ int pthread_attr_getschedparam( const pthread_attr_t * attr, sched_param_t * par return SUCCESS; } -int pthread_attr_getstacksize( const pthread_attr_t * attr , size_t * stacksize ) +int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize) { ASSERT_IF_FALSE(attr != NULL, int); ASSERT_IF_FALSE(stacksize != NULL, int); @@ -58,7 +70,7 @@ int pthread_attr_getstacksize( const pthread_attr_t * attr , size_t * stacksize return SUCCESS; } -int pthread_attr_init( pthread_attr_t * attr ) +int pthread_attr_init(pthread_attr_t *attr) { ASSERT_IF_FALSE(attr != NULL, int); @@ -68,7 +80,7 @@ int pthread_attr_init( pthread_attr_t * attr ) return SUCCESS; } -int pthread_attr_setdetachstate( pthread_attr_t * attr, int detachstate ) +int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) { ASSERT_IF_FALSE(attr != NULL, int); @@ -76,7 +88,7 @@ int pthread_attr_setdetachstate( pthread_attr_t * attr, int detachstate ) return SUCCESS; } -int pthread_attr_setschedparam( pthread_attr_t * attr, const sched_param_t * param ) +int pthread_attr_setschedparam(pthread_attr_t *attr, const sched_param_t *param) { ASSERT_IF_FALSE(attr != NULL, int); ASSERT_IF_FALSE(param != NULL, int); @@ -85,7 +97,7 @@ int pthread_attr_setschedparam( pthread_attr_t * attr, const sched_param_t * par return SUCCESS; } -int pthread_attr_setschedpolicy( pthread_attr_t * attr, int policy) +int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy) { ASSERT_IF_FALSE(attr != NULL, int); @@ -93,7 +105,7 @@ int pthread_attr_setschedpolicy( pthread_attr_t * attr, int policy) return SUCCESS; } -int pthread_attr_setstacksize( pthread_attr_t * attr, size_t stacksize) +int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) { ASSERT_IF_FALSE(attr != NULL, int); ASSERT_IF_FALSE(stacksize >= posixconfigPTHREAD_MIN_STACK_SIZE, int); @@ -101,3 +113,61 @@ int pthread_attr_setstacksize( pthread_attr_t * attr, size_t stacksize) attr->stacksize = stacksize; return SUCCESS; } + +int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*startroutine)(void *), void *arg) +{ + sret_t pthread_sys_ret = + { + .status = SUCCESS + }; + + int err = SUCCESS; + + ASSERT_IF_FALSE(thread != NULL, int); + ASSERT_IF_FALSE(attr != NULL, int); + ASSERT_IF_FALSE(attr->stacksize >= posixconfigPTHREAD_MIN_STACK_SIZE, int); + + thread->attr = (pthread_attr_t *)attr; + + /* Grab resource access else return EBUSY */ + RET_ERR_IF_FALSE(s_pthread_acquire_lock() == SUCCESS, -EBUSY, int); + + super_call(scall_id_pthread_create, (call_args) startroutine, (call_args) arg, thread->attr->stacksize, &pthread_sys_ret); + if (pthread_sys_ret.status != SUCCESS) + { + err = -EAGAIN; + } + else + { + thread->fn = startroutine; + + /* Get the PID */ + thread->pid = pthread_sys_ret.size; + } + + /* Release resource access else return EBUSY */ + RET_ERR_IF_FALSE(s_pthread_release_lock() == SUCCESS, -EBUSY, int); + + return err; +} + +int pthread_equal(pthread_t t1, pthread_t t2) +{ + return memcmp(&t1, &t2, sizeof(pthread_t)); +} + +void pthread_exit(void *value_ptr _UNUSED) +{ + sret_t pthread_sys_ret = + { + .status = SUCCESS + }; + + /* Grab resource access else return EBUSY */ + s_pthread_acquire_lock(); + + super_call(scall_id_pthread_exit, RST_VAL, RST_VAL, RST_VAL, &pthread_sys_ret); + + /* Release resource access else return EBUSY */ + s_pthread_release_lock(); +} diff --git a/src/visor/supervisor/workers/scall/supervisory_call.c b/src/visor/supervisor/workers/scall/supervisory_call.c index c53bfa2d..cf939447 100644 --- a/src/visor/supervisor/workers/scall/supervisory_call.c +++ b/src/visor/supervisor/workers/scall/supervisory_call.c @@ -19,7 +19,7 @@ extern scall_t _scall_table_start; extern scall_t _scall_table_end; -void super_call(scall_id_t id, unsigned int a0, unsigned int a1, unsigned int a2, sret_t *ret) +void super_call(scall_id_t id, call_args a0, call_args a1, call_args a2, sret_t *ret) { /* mcall Table pointer */ scall_t *ptr; diff --git a/src/visor/terravisor/workers/mcall/machine_call.c b/src/visor/terravisor/workers/mcall/machine_call.c index a374a10f..7531dd8a 100644 --- a/src/visor/terravisor/workers/mcall/machine_call.c +++ b/src/visor/terravisor/workers/mcall/machine_call.c @@ -19,7 +19,7 @@ extern mcall_t _mcall_table_start; extern mcall_t _mcall_table_end; -void machine_call(mcall_id_t id, unsigned int a0, unsigned int a1, unsigned int a2, mret_t *ret) +void machine_call(mcall_id_t id, call_args a0, call_args a1, call_args a2, mret_t *ret) { /* mcall Table pointer */ mcall_t *ptr; From 116e3da59736ac19e389ded45de2c9abab03fa47 Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Sat, 19 Feb 2022 11:28:52 +0530 Subject: [PATCH 2/6] Updated Git_CI for dev-cc-kernel --- .github/workflows/github_ci.yml | 6 +++--- .github/workflows/sonarcloud.yml | 2 ++ .vscode/settings.json | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/github_ci.yml b/.github/workflows/github_ci.yml index 597e93c4..5ad97b98 100644 --- a/.github/workflows/github_ci.yml +++ b/.github/workflows/github_ci.yml @@ -2,10 +2,10 @@ name: GitHub CI on: push: - branches: [ stable, development ] + branches: [ stable, development, dev-cc-kernel ] pull_request: - branches: [ stable, development ] + branches: [ stable, development, dev-cc-kernel ] jobs: build: @@ -15,7 +15,7 @@ jobs: contents: read security-events: write statuses: write - + strategy: fail-fast: true matrix: diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index e50d16ff..c3fc2c61 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -5,10 +5,12 @@ on: branches: - stable - development + - dev-cc-kernel pull_request: branches: - stable - development + - dev-cc-kernel jobs: build: diff --git a/.vscode/settings.json b/.vscode/settings.json index 34ba3b67..76570ddf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -34,6 +34,7 @@ "diffEditor.codeLens": true, "diffEditor.wordWrap": "on", "editor.suggest.showStatusBar": true, + "editor.formatOnSave": false, "files.associations": { "*.sx": "c", "*.{c,c.dev.c.temp,c.tmp,c.old,h,h.dev,h.old,h.temp,h.tmp)": "C", @@ -41,7 +42,7 @@ "*.{S,S.old,S.dev.S.temp,S.tmp,s.old,s.temp,s.tmp,s.dev,asm,asm.old,asm.dev.asm.temp,asm.tmp,inc,inc.old,inc.temp,inc.tmp,ld,ld.old,ld.temp,ld.tmp,ld.sx,ld.sx.old,ld.sx.temp,ld.sx.tmp,lst}": "coffeescript", }, "files.autoSave": "afterDelay", - "files.autoSaveDelay": 5000, + "files.autoSaveDelay": 100, "files.defaultLanguage": "C", "files.insertFinalNewline": true, "files.trimTrailingWhitespace": true, From cf642e606b1b57a719240a8c5efad6a96fb55b44 Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Sat, 19 Feb 2022 11:31:25 +0530 Subject: [PATCH 3/6] Revert " Updated Git_CI for dev-cc-kernel" This reverts commit 116e3da59736ac19e389ded45de2c9abab03fa47. --- .github/workflows/github_ci.yml | 6 +++--- .github/workflows/sonarcloud.yml | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/github_ci.yml b/.github/workflows/github_ci.yml index 5ad97b98..597e93c4 100644 --- a/.github/workflows/github_ci.yml +++ b/.github/workflows/github_ci.yml @@ -2,10 +2,10 @@ name: GitHub CI on: push: - branches: [ stable, development, dev-cc-kernel ] + branches: [ stable, development ] pull_request: - branches: [ stable, development, dev-cc-kernel ] + branches: [ stable, development ] jobs: build: @@ -15,7 +15,7 @@ jobs: contents: read security-events: write statuses: write - + strategy: fail-fast: true matrix: diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index c3fc2c61..e50d16ff 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -5,12 +5,10 @@ on: branches: - stable - development - - dev-cc-kernel pull_request: branches: - stable - development - - dev-cc-kernel jobs: build: From becaea5155277185884ce3affe169b317ce331e1 Mon Sep 17 00:00:00 2001 From: Pranjal Chanda Date: Sat, 19 Feb 2022 13:50:16 +0530 Subject: [PATCH 4/6] code_smell fix --- src/include/call_type.h | 9 +++------ src/lib/libposix/include/posix/pthread.h | 2 +- src/lib/libposix/src/posix_pthread.c | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/include/call_type.h b/src/include/call_type.h index ae364dc0..f38f3f4f 100644 --- a/src/include/call_type.h +++ b/src/include/call_type.h @@ -11,14 +11,11 @@ #pragma once #if defined(ARCH_ARM_32) -#define __CALL_ARG_TYPE__ unsigned long +typedef unsigned long call_args; #elif defined(ARCH_RISCV_64) || defined(ARCH_ARM_64) -#define __CALL_ARG_TYPE__ unsigned long +typedef unsigned long long call_args; #else -#define __CALL_ARG_TYPE__ unsigned int - +typedef unsigned int call_args; #endif - -typedef __CALL_ARG_TYPE__ call_args; diff --git a/src/lib/libposix/include/posix/pthread.h b/src/lib/libposix/include/posix/pthread.h index 8769ec39..0d475cea 100644 --- a/src/lib/libposix/include/posix/pthread.h +++ b/src/lib/libposix/include/posix/pthread.h @@ -310,7 +310,7 @@ int pthread_equal( pthread_t t1, * * @retval void - this function cannot return to its caller. */ -void pthread_exit( void * value_ptr ); +void pthread_exit( const void * value_ptr ); /** * @brief Dynamic thread scheduling parameters access. diff --git a/src/lib/libposix/src/posix_pthread.c b/src/lib/libposix/src/posix_pthread.c index f07d30d3..c77ef9cf 100644 --- a/src/lib/libposix/src/posix_pthread.c +++ b/src/lib/libposix/src/posix_pthread.c @@ -156,7 +156,7 @@ int pthread_equal(pthread_t t1, pthread_t t2) return memcmp(&t1, &t2, sizeof(pthread_t)); } -void pthread_exit(void *value_ptr _UNUSED) +void pthread_exit( const void *value_ptr _UNUSED) { sret_t pthread_sys_ret = { From bd74b8dae58ca4a09435a242093963637cba415e Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Sat, 19 Feb 2022 15:05:46 +0530 Subject: [PATCH 5/6] Updtaed call args --- .../8/common_5x_6/terravisor/include/avr.h | 2 ++ .../riscv/32/i/terravisor/include/riscv.h | 2 ++ src/include/call_type.h | 21 ------------------- src/include/machine_call.h | 4 ++-- src/include/supervisor_call.h | 4 ++-- src/lib/libposix/src/posix_pthread.c | 2 +- .../workers/scall/supervisory_call.c | 2 +- .../terravisor/workers/mcall/machine_call.c | 2 +- 8 files changed, 11 insertions(+), 28 deletions(-) delete mode 100644 src/include/call_type.h diff --git a/src/arch/avr/8/common_5x_6/terravisor/include/avr.h b/src/arch/avr/8/common_5x_6/terravisor/include/avr.h index 42e68540..936a96e9 100644 --- a/src/arch/avr/8/common_5x_6/terravisor/include/avr.h +++ b/src/arch/avr/8/common_5x_6/terravisor/include/avr.h @@ -23,5 +23,7 @@ typedef struct context_frame r6, r5, r4, r3, r2, sreg, r0, r1, r24; } context_frame_t; +typedef uint16_t call_arg_t; + context_frame_t *get_context_frame(); void arch_panic_handler_callback(); diff --git a/src/arch/riscv/32/i/terravisor/include/riscv.h b/src/arch/riscv/32/i/terravisor/include/riscv.h index a16ce3c9..33806c71 100644 --- a/src/arch/riscv/32/i/terravisor/include/riscv.h +++ b/src/arch/riscv/32/i/terravisor/include/riscv.h @@ -24,6 +24,8 @@ typedef struct context_frame /* Padding is necessary for alignment */ } context_frame_t; +typedef uint32_t call_arg_t; + static inline unsigned int arch_core_isa() { unsigned int ret; diff --git a/src/include/call_type.h b/src/include/call_type.h deleted file mode 100644 index f38f3f4f..00000000 --- a/src/include/call_type.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team - * - * File Name : call_type.c - * Description : This file consists of call_typedef - * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] - * Organisation : Cyancore Core-Team - */ - -#pragma once - -#if defined(ARCH_ARM_32) -typedef unsigned long call_args; - -#elif defined(ARCH_RISCV_64) || defined(ARCH_ARM_64) -typedef unsigned long long call_args; - -#else -typedef unsigned int call_args; -#endif diff --git a/src/include/machine_call.h b/src/include/machine_call.h index a5a4f4cc..b630e05f 100644 --- a/src/include/machine_call.h +++ b/src/include/machine_call.h @@ -13,7 +13,7 @@ #include #include -#include +#include // Machine call IDs typedef enum mcall_id @@ -33,7 +33,7 @@ typedef struct mret typedef struct mcall { mcall_id_t id; - mret_t (*callback)(call_args a0, call_args a1, call_args a2); + mret_t (*callback)(call_arg_t a0, call_arg_t a1, call_arg_t a2); } mcall_t; #define INCLUDE_MCALL(_name, _id , _callback) \ diff --git a/src/include/supervisor_call.h b/src/include/supervisor_call.h index 8d955f0a..678a5da6 100644 --- a/src/include/supervisor_call.h +++ b/src/include/supervisor_call.h @@ -13,7 +13,7 @@ #include #include -#include +#include // Supervisor call IDs typedef enum scall_id @@ -76,7 +76,7 @@ typedef struct sret typedef struct scall { scall_id_t id; - sret_t (*callback)(call_args a0, call_args a1, call_args a2); + sret_t (*callback)(call_arg_t a0, call_arg_t a1, call_arg_t a2); } scall_t; #define INCLUDE_SCALL(_name, _id , _callback) \ diff --git a/src/lib/libposix/src/posix_pthread.c b/src/lib/libposix/src/posix_pthread.c index c77ef9cf..c70d79e7 100644 --- a/src/lib/libposix/src/posix_pthread.c +++ b/src/lib/libposix/src/posix_pthread.c @@ -132,7 +132,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*startr /* Grab resource access else return EBUSY */ RET_ERR_IF_FALSE(s_pthread_acquire_lock() == SUCCESS, -EBUSY, int); - super_call(scall_id_pthread_create, (call_args) startroutine, (call_args) arg, thread->attr->stacksize, &pthread_sys_ret); + super_call(scall_id_pthread_create, (call_arg_t) startroutine, (call_arg_t) arg, thread->attr->stacksize, &pthread_sys_ret); if (pthread_sys_ret.status != SUCCESS) { err = -EAGAIN; diff --git a/src/visor/supervisor/workers/scall/supervisory_call.c b/src/visor/supervisor/workers/scall/supervisory_call.c index cf939447..da6a44ff 100644 --- a/src/visor/supervisor/workers/scall/supervisory_call.c +++ b/src/visor/supervisor/workers/scall/supervisory_call.c @@ -19,7 +19,7 @@ extern scall_t _scall_table_start; extern scall_t _scall_table_end; -void super_call(scall_id_t id, call_args a0, call_args a1, call_args a2, sret_t *ret) +void super_call(scall_id_t id, call_arg_t a0, call_arg_t a1, call_arg_t a2, sret_t *ret) { /* mcall Table pointer */ scall_t *ptr; diff --git a/src/visor/terravisor/workers/mcall/machine_call.c b/src/visor/terravisor/workers/mcall/machine_call.c index 7531dd8a..25a94116 100644 --- a/src/visor/terravisor/workers/mcall/machine_call.c +++ b/src/visor/terravisor/workers/mcall/machine_call.c @@ -19,7 +19,7 @@ extern mcall_t _mcall_table_start; extern mcall_t _mcall_table_end; -void machine_call(mcall_id_t id, call_args a0, call_args a1, call_args a2, mret_t *ret) +void machine_call(mcall_id_t id, call_arg_t a0, call_arg_t a1, call_arg_t a2, mret_t *ret) { /* mcall Table pointer */ mcall_t *ptr; From 04bdd61db8123a04df07ee3389d09f8bcf86ba32 Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Sat, 19 Feb 2022 15:43:51 +0530 Subject: [PATCH 6/6] procedure call update --- src/arch/avr/8/common_5x_6/terravisor/include/arch.h | 2 +- src/arch/riscv/32/i/terravisor/include/arch.h | 2 +- src/include/machine_call.h | 3 ++- src/include/supervisor_call.h | 3 ++- src/platform/mega_avr/atmega328p/include/plat_arch.h | 4 ---- src/platform/mega_avr/common/platform/platform_resource.c | 4 ++-- src/platform/sifive/common_fe310/platform/platform_resource.c | 4 ++-- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/arch/avr/8/common_5x_6/terravisor/include/arch.h b/src/arch/avr/8/common_5x_6/terravisor/include/arch.h index d92c022d..62d1cf34 100644 --- a/src/arch/avr/8/common_5x_6/terravisor/include/arch.h +++ b/src/arch/avr/8/common_5x_6/terravisor/include/arch.h @@ -44,7 +44,7 @@ void arch_panic_handler(); * * Refer arch.c for more details. */ -void arch_machine_call(unsigned int, unsigned int, unsigned int, unsigned int, mret_t *); +void arch_machine_call(call_arg_t, call_arg_t, call_arg_t, call_arg_t, mret_t *); #endif /** diff --git a/src/arch/riscv/32/i/terravisor/include/arch.h b/src/arch/riscv/32/i/terravisor/include/arch.h index 202b6e4f..f25b9a55 100644 --- a/src/arch/riscv/32/i/terravisor/include/arch.h +++ b/src/arch/riscv/32/i/terravisor/include/arch.h @@ -11,8 +11,8 @@ #pragma once #define _ARCH_H_ -#include #include +#include /** * arch_early_setup - This needs to be called in early stages of boot diff --git a/src/include/machine_call.h b/src/include/machine_call.h index b630e05f..24f1ef6a 100644 --- a/src/include/machine_call.h +++ b/src/include/machine_call.h @@ -13,7 +13,6 @@ #include #include -#include // Machine call IDs typedef enum mcall_id @@ -30,6 +29,8 @@ typedef struct mret status_t status; } mret_t; +#include + typedef struct mcall { mcall_id_t id; diff --git a/src/include/supervisor_call.h b/src/include/supervisor_call.h index 678a5da6..8916719e 100644 --- a/src/include/supervisor_call.h +++ b/src/include/supervisor_call.h @@ -13,7 +13,6 @@ #include #include -#include // Supervisor call IDs typedef enum scall_id @@ -73,6 +72,8 @@ typedef struct sret status_t status; } sret_t; +#include + typedef struct scall { scall_id_t id; diff --git a/src/platform/mega_avr/atmega328p/include/plat_arch.h b/src/platform/mega_avr/atmega328p/include/plat_arch.h index d7388530..21707f1b 100644 --- a/src/platform/mega_avr/atmega328p/include/plat_arch.h +++ b/src/platform/mega_avr/atmega328p/include/plat_arch.h @@ -32,7 +32,3 @@ #define CLKPR 0x61 #define PRR 0x64 #define OSCCAL 0x66 - -#ifdef _MACHINE_CALL_H_ -extern void (*mcall)(unsigned int, unsigned int, unsigned int, unsigned int, mret_t *); -#endif diff --git a/src/platform/mega_avr/common/platform/platform_resource.c b/src/platform/mega_avr/common/platform/platform_resource.c index 5c1afa31..93d36c35 100644 --- a/src/platform/mega_avr/common/platform/platform_resource.c +++ b/src/platform/mega_avr/common/platform/platform_resource.c @@ -48,7 +48,7 @@ status_t platform_resources_setup() * * @return status: return the function execution status */ -mret_t platform_fetch_sp(unsigned int a0, unsigned int a1 _UNUSED, unsigned int a2 _UNUSED) +mret_t platform_fetch_sp(call_arg_t a0, call_arg_t a1 _UNUSED, call_arg_t a2 _UNUSED) { mret_t ret; ret.p = (uintptr_t) sp_terravisor_dev_info(a0); @@ -72,7 +72,7 @@ INCLUDE_MCALL(atmega328p_fetch_sp, fetch_sp, platform_fetch_sp); * * @return status: return the function execution status */ -mret_t platform_fetch_dp(unsigned int a0, unsigned int a1 _UNUSED, unsigned int a2 _UNUSED) +mret_t platform_fetch_dp(call_arg_t a0, call_arg_t a1 _UNUSED, call_arg_t a2 _UNUSED) { mret_t ret; switch(a0) diff --git a/src/platform/sifive/common_fe310/platform/platform_resource.c b/src/platform/sifive/common_fe310/platform/platform_resource.c index e7c2e11e..d1c23c88 100644 --- a/src/platform/sifive/common_fe310/platform/platform_resource.c +++ b/src/platform/sifive/common_fe310/platform/platform_resource.c @@ -48,7 +48,7 @@ status_t platform_resources_setup() * * @return status: return the function execution status */ -mret_t platform_fetch_sp(unsigned int a0, unsigned int a1 _UNUSED, unsigned int a2 _UNUSED) +mret_t platform_fetch_sp(call_arg_t a0, call_arg_t a1 _UNUSED, call_arg_t a2 _UNUSED) { mret_t ret; ret.p = (uintptr_t) sp_terravisor_dev_info(a0); @@ -72,7 +72,7 @@ INCLUDE_MCALL(sifive_fe310_fetch_sp, fetch_sp, platform_fetch_sp); * * @return status: return the function execution status */ -mret_t platform_fetch_dp(unsigned int a0, unsigned int a1 _UNUSED, unsigned int a2 _UNUSED) +mret_t platform_fetch_dp(call_arg_t a0, call_arg_t a1 _UNUSED, call_arg_t a2 _UNUSED) { mret_t ret; switch(a0)