From 604c29571901f3578048e7a93087c3e4999dae4f Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Mon, 23 Oct 2023 14:47:23 +0530 Subject: [PATCH] Moving all exception calls to visor call - Updated source to use visor call and common interface - Each layer will be taking up responsibility to handle the requested call or forward it to relevant layer. - RISC-V and AVR core is tested, ARM implementation is still pending Issue: #155 #87 --- .../arm-m/32/common_v6_v7/supervisor/arch.c | 12 +-- .../32/common_v6_v7/supervisor/include/arch.h | 6 +- src/arch/avr/8/common_5x_6/terravisor/arch.c | 4 +- .../8/common_5x_6/terravisor/include/arch.h | 10 +-- src/arch/riscv/32/i/terravisor/arch.c | 18 ++-- src/arch/riscv/32/i/terravisor/include/arch.h | 6 +- .../con_serial_mega_avr/console_serial.c | 20 ++--- .../con_serial_mega_avr/earlycon_serial.c | 20 ++--- .../con_serial_sifive/console_serial.c | 2 +- .../con_serial_sifive/earlycon_serial.c | 2 +- src/driver/interrupt/plic/plic.c | 12 +-- src/driver/onboardled/onboardled.c | 14 +-- src/driver/sysclk/sysclk_prci/sysclk_prci.c | 28 +++--- src/include/driver/sysclk.h | 16 ++-- src/include/linker_macros.h | 8 +- src/include/machine_call.h | 47 ---------- src/include/status.h | 11 +-- src/include/supervisor_call.h | 87 ------------------- src/include/vcall_id.h | 65 ++++++++++++++ src/include/visor/supervisor/workers.h | 16 ---- src/include/visor/terravisor/workers.h | 14 --- src/include/visor/visor/workers.h | 13 +++ src/include/visor_call.h | 39 +++++++++ src/lib/libposix/src/posix_mqueue.c | 10 +-- src/lib/libposix/src/posix_pthread.c | 6 +- src/lib/libposix/src/posix_semaphore.c | 12 +-- src/lib/libposix/src/posix_utils.c | 4 +- .../mega_avr/atmega2560/include/plat_arch.h | 4 +- src/platform/mega_avr/common/hal/gpio/gpio.c | 22 ++--- src/platform/mega_avr/common/hal/pwm/pwm.c | 20 ++--- .../mega_avr/common/hal/timer/timer.c | 2 +- src/platform/mega_avr/common/hal/uart/uart.c | 12 +-- .../mega_avr/common/include/platform.h | 2 +- .../mega_avr/common/platform/platform.c | 4 +- .../common/platform/platform_resource.c | 14 +-- .../mega_avr/common/platform/platform_timer.c | 20 ++--- .../mega_avr/common/platform/platform_wdt.c | 12 +-- src/platform/mega_avr/common/sections.ld.sx | 2 +- .../common_rp2/platform/platform_resource.c | 2 +- .../sifive/common_fe310/hal/clint/clint.c | 12 +-- .../sifive/common_fe310/hal/gpio/gpio.c | 10 +-- .../sifive/common_fe310/hal/uart/uart.c | 20 ++--- .../sifive/common_fe310/platform/plat_timer.c | 20 ++--- .../sifive/common_fe310/platform/platform.c | 2 +- .../common_fe310/platform/platform_reset.c | 8 +- .../common_fe310/platform/platform_resource.c | 14 +-- .../sifive/common_fe310/sections.ld.sx | 2 +- src/visor/build.mk | 1 + src/visor/common/build.mk | 14 +++ .../workers/scall => common/workers}/build.mk | 8 +- .../mcall => common/workers/vcall}/build.mk | 6 +- .../workers/vcall/visor_call.c} | 28 +++--- .../supervisor/workers/scall/scall.ld.sx | 22 ----- .../workers/scall/supervisory_call.c | 55 ------------ src/visor/terravisor/build.mk | 1 - src/visor/terravisor/workers/build.mk | 17 ---- 56 files changed, 363 insertions(+), 495 deletions(-) delete mode 100644 src/include/machine_call.h delete mode 100644 src/include/supervisor_call.h create mode 100644 src/include/vcall_id.h delete mode 100644 src/include/visor/supervisor/workers.h delete mode 100644 src/include/visor/terravisor/workers.h create mode 100644 src/include/visor/visor/workers.h create mode 100644 src/include/visor_call.h create mode 100644 src/visor/common/build.mk rename src/visor/{supervisor/workers/scall => common/workers}/build.mk (63%) rename src/visor/{terravisor/workers/mcall => common/workers/vcall}/build.mk (72%) rename src/visor/{terravisor/workers/mcall/machine_call.c => common/workers/vcall/visor_call.c} (50%) delete mode 100644 src/visor/supervisor/workers/scall/scall.ld.sx delete mode 100644 src/visor/supervisor/workers/scall/supervisory_call.c delete mode 100644 src/visor/terravisor/workers/build.mk diff --git a/src/arch/arm-m/32/common_v6_v7/supervisor/arch.c b/src/arch/arm-m/32/common_v6_v7/supervisor/arch.c index 8acf8e7e..c74180b5 100644 --- a/src/arch/arm-m/32/common_v6_v7/supervisor/arch.c +++ b/src/arch/arm-m/32/common_v6_v7/supervisor/arch.c @@ -16,16 +16,16 @@ #include #include #include -#include +#include static void arch_ecall_handler() { context_frame_t *frame = get_context_frame(); - mret_t mres; - machine_call(frame->r0, frame->r1, frame->r3, &mres); - frame->r0 = mres.p; - frame->r1 = mres.size; - frame->r2 = mres.status; + vret_t vres; + machine_call(frame->r0, frame->r1, frame->r3, &vres); + frame->r0 = vres.p; + frame->r1 = vres.size; + frame->r2 = vres.status; return; } diff --git a/src/arch/arm-m/32/common_v6_v7/supervisor/include/arch.h b/src/arch/arm-m/32/common_v6_v7/supervisor/include/arch.h index f42cec65..7e48edf3 100644 --- a/src/arch/arm-m/32/common_v6_v7/supervisor/include/arch.h +++ b/src/arch/arm-m/32/common_v6_v7/supervisor/include/arch.h @@ -13,7 +13,7 @@ #define _ARCH_H_ #include -#include +#include /** * arch_early_setup - This needs to be called in early stages of boot @@ -53,8 +53,8 @@ void arch_register_interrupt_handler(unsigned int, void(*)(void)); * @param[in] r2: third argument * @param[in] *ret: return struct */ -#define arch_machine_call arch_super_call -static inline void arch_super_call(unsigned int code, unsigned int arg0, unsigned int arg1, unsigned int arg2, mret_t *ret) +#define arch_visor_call arch_super_call +static inline void arch_super_call(unsigned int code, unsigned int arg0, unsigned int arg1, unsigned int arg2, vret_t *ret) { if(ret == NULL) return; diff --git a/src/arch/avr/8/common_5x_6/terravisor/arch.c b/src/arch/avr/8/common_5x_6/terravisor/arch.c index 0ed970f4..b1db93e9 100644 --- a/src/arch/avr/8/common_5x_6/terravisor/arch.c +++ b/src/arch/avr/8/common_5x_6/terravisor/arch.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include /** * arch_early_setup - This function is called in the early stages of boot @@ -25,7 +25,7 @@ * @brief This function is responsible to clean reset cpu status/control registers. * */ -void (* const p_mcall)(unsigned int, unsigned int, unsigned int, unsigned int, mret_t *) = &machine_call; +void (* const p_vcall)(unsigned int, unsigned int, unsigned int, unsigned int, vret_t *) = &vcall_handler; void arch_early_setup() { arch_di(); 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 1b311713..5c7f212b 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 @@ -16,7 +16,7 @@ #include #include #include -#include +#include /** * arch_early_setup - This needs to be called in early stages of boot @@ -56,7 +56,7 @@ static inline unsigned int arch_core_index() } /** - * arch_machine_call - perform machine call + * arch_visor_call - perform machine call * * @brief This function emulates the machine * call to maintain consistency. @@ -67,12 +67,12 @@ static inline unsigned int arch_core_index() * @param[in] a2: third argument * @param[in] *ret: return value */ -static inline void arch_machine_call(unsigned int code, unsigned int a0, unsigned int a1, unsigned int a2, mret_t *ret) +static inline void arch_visor_call(unsigned int code, unsigned int a0, unsigned int a1, unsigned int a2, vret_t *ret) { - extern void (*const p_mcall)(unsigned int, unsigned int, unsigned int, unsigned int, mret_t*); + extern void (*const p_vcall)(unsigned int, unsigned int, unsigned int, unsigned int, vret_t*); if(ret == NULL) return; - p_mcall(code, a0, a1, a2, ret); + p_vcall(code, a0, a1, a2, ret); return; } diff --git a/src/arch/riscv/32/i/terravisor/arch.c b/src/arch/riscv/32/i/terravisor/arch.c index a0becfe5..5f0c286c 100644 --- a/src/arch/riscv/32/i/terravisor/arch.c +++ b/src/arch/riscv/32/i/terravisor/arch.c @@ -14,18 +14,18 @@ #include #include #include -#include +#include #include -static void arch_mcall_handler() +static void arch_vcall_handler() { context_frame_t *frame = get_context_frame(); - mret_t mres; - machine_call(frame->a0, frame->a1, frame->a2, frame->a3, &mres); + vret_t vres; + vcall_handler(frame->a0, frame->a1, frame->a2, frame->a3, &vres); fence(w, w); - frame->a0 = mres.p; - frame->a1 = mres.size; - frame->a2 = mres.status; + frame->a0 = vres.p; + frame->a1 = vres.size; + frame->a2 = vres.status; return; } @@ -72,13 +72,13 @@ void arch_early_setup() */ void arch_setup() { - link_interrupt(int_arch, 11, &arch_mcall_handler); + link_interrupt(int_arch, 11, &arch_vcall_handler); return; } void arch_setup2() { - link_interrupt(int_arch, 11, &arch_mcall_handler); + link_interrupt(int_arch, 11, &arch_vcall_handler); return; } diff --git a/src/arch/riscv/32/i/terravisor/include/arch.h b/src/arch/riscv/32/i/terravisor/include/arch.h index ad957d51..c60066f7 100644 --- a/src/arch/riscv/32/i/terravisor/include/arch.h +++ b/src/arch/riscv/32/i/terravisor/include/arch.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include /** * arch_early_setup - This needs to be called in early stages of boot @@ -63,7 +63,7 @@ static inline unsigned int arch_core_index() } /** - * arch_machine_call - perform machine call + * arch_visor_call - perform machine call * * @brief This function performs environment call * in m mode @@ -74,7 +74,7 @@ static inline unsigned int arch_core_index() * @param[in] a2: third argument * @param[in] *ret: return struct */ -static inline void arch_machine_call(unsigned int code, unsigned int arg0, unsigned int arg1, unsigned int arg2, mret_t *ret) +static inline void arch_visor_call(unsigned int code, unsigned int arg0, unsigned int arg1, unsigned int arg2, vret_t *ret) { if(ret == NULL) return; diff --git a/src/driver/console/con_serial_mega_avr/console_serial.c b/src/driver/console/con_serial_mega_avr/console_serial.c index 5a839077..6a713907 100644 --- a/src/driver/console/con_serial_mega_avr/console_serial.c +++ b/src/driver/console/con_serial_mega_avr/console_serial.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -30,25 +30,25 @@ static void console_serial_read_irq_handler(void); static status_t console_serial_setup() { - mret_t mres; + vret_t vres; const swdev_t *sp; const module_t *dp; hw_devid_t devid; - arch_machine_call(fetch_sp, console_uart, 0, 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_sp, console_uart, 0, 0, &vres); + if(vres.status != success) { sysdbg3("Console could not found!\n"); - return mres.status; + return vres.status; } - sp = (swdev_t *) mres.p; + sp = (swdev_t *) vres.p; devid = sp->hwdev_id; - arch_machine_call(fetch_dp, (devid & 0xff00), (devid & 0x00ff), 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_dp, (devid & 0xff00), (devid & 0x00ff), 0, &vres); + if(vres.status != success) { sysdbg3("UART Device %d not found!\n", devid); - return mres.status; + return vres.status; } - dp = (module_t *)mres.p; + dp = (module_t *)vres.p; console_port = (uart_port_t *)malloc(sizeof(uart_port_t)); if(!console_port) return error_memory_low; diff --git a/src/driver/console/con_serial_mega_avr/earlycon_serial.c b/src/driver/console/con_serial_mega_avr/earlycon_serial.c index 05d8a527..35ce138b 100644 --- a/src/driver/console/con_serial_mega_avr/earlycon_serial.c +++ b/src/driver/console/con_serial_mega_avr/earlycon_serial.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -27,25 +27,25 @@ static uart_port_t *earlycon_port; static status_t earlycon_serial_setup() { - mret_t mres; + vret_t vres; swdev_t *sp; module_t *dp; hw_devid_t devid; - arch_machine_call(fetch_sp, console_uart, 0, 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_sp, console_uart, 0, 0, &vres); + if(vres.status != success) { sysdbg3("Console could not found!\n"); - return mres.status; + return vres.status; } - sp = (swdev_t *) mres.p; + sp = (swdev_t *) vres.p; devid = sp->hwdev_id; - arch_machine_call(fetch_dp, (devid & 0xff00), (devid & 0x00ff), 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_dp, (devid & 0xff00), (devid & 0x00ff), 0, &vres); + if(vres.status != success) { sysdbg3("UART Device %d not found!\n", devid); - return mres.status; + return vres.status; } - dp = (module_t *)mres.p; + dp = (module_t *)vres.p; earlycon_port = (uart_port_t *)malloc(sizeof(uart_port_t)); if(!earlycon_port) return error_memory_low; diff --git a/src/driver/console/con_serial_sifive/console_serial.c b/src/driver/console/con_serial_sifive/console_serial.c index 4bd9c194..0d1f55b5 100644 --- a/src/driver/console/con_serial_sifive/console_serial.c +++ b/src/driver/console/con_serial_sifive/console_serial.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/driver/console/con_serial_sifive/earlycon_serial.c b/src/driver/console/con_serial_sifive/earlycon_serial.c index bb71d828..12792cb1 100644 --- a/src/driver/console/con_serial_sifive/earlycon_serial.c +++ b/src/driver/console/con_serial_sifive/earlycon_serial.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/driver/interrupt/plic/plic.c b/src/driver/interrupt/plic/plic.c index 96df39bc..16a17b8c 100644 --- a/src/driver/interrupt/plic/plic.c +++ b/src/driver/interrupt/plic/plic.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -33,14 +33,14 @@ static plic_port_t *port; static status_t plic_setup() { - mret_t mres; + vret_t vres; const module_t *dp; - arch_machine_call(fetch_dp, plic, 0, 0, &mres); + arch_visor_call(fetch_dp, plic, 0, 0, &vres); - if(mres.status != success) - return mres.status; - dp = (module_t *)mres.p; + if(vres.status != success) + return vres.status; + dp = (module_t *)vres.p; port = (plic_port_t *)malloc(sizeof(plic_port_t)); if(!port) return error_memory_low; diff --git a/src/driver/onboardled/onboardled.c b/src/driver/onboardled/onboardled.c index 0f619b3c..a0966ad7 100644 --- a/src/driver/onboardled/onboardled.c +++ b/src/driver/onboardled/onboardled.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -73,19 +73,19 @@ status_t onboardled_off(void) static status_t onboardled_setup(void) { - mret_t mres; + vret_t vres; status_t ret; lock_acquire(&obledlock); - arch_machine_call(fetch_sp, onboard_led, 0, 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_sp, onboard_led, 0, 0, &vres); + if(vres.status != success) { sysdbg3("%p - sp node could not be found!\n", onboard_led); - ret = mres.status; + ret = vres.status; goto exit; } - obled_sp = (swdev_t *) mres.p; - ret = mres.status; + obled_sp = (swdev_t *) vres.p; + ret = vres.status; obledPort = (gpio_port_t *)malloc(sizeof(gpio_port_t) * obled_sp->pmux->npins); diff --git a/src/driver/sysclk/sysclk_prci/sysclk_prci.c b/src/driver/sysclk/sysclk_prci/sysclk_prci.c index 4d3ab45d..dfa61634 100644 --- a/src/driver/sysclk/sysclk_prci/sysclk_prci.c +++ b/src/driver/sysclk/sysclk_prci/sysclk_prci.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -31,7 +31,7 @@ static status_t sysclk_disable(); static status_t sysclk_setup() { status_t ret = success; - mret_t mres; + vret_t vres; module_t *dp; sysclk_port_t *port; istate_t ist; @@ -41,30 +41,30 @@ static status_t sysclk_setup() return error_memory_low; port = sysclk; - arch_machine_call(fetch_dp, clock, 0, 0, &mres); + arch_visor_call(fetch_dp, clock, 0, 0, &vres); - if(mres.status != success) + if(vres.status != success) { sysdbg2("Clock not found in DP!\n"); port->base_clk = 0; - ret = mres.status; + ret = vres.status; goto cleanup_exit; } - port->base_clk = *((unsigned int *)mres.p); + port->base_clk = *((unsigned int *)vres.p); - arch_machine_call(fetch_dp, prci, 0, 0, &mres); + arch_visor_call(fetch_dp, prci, 0, 0, &vres); - if(mres.status != success) + if(vres.status != success) { sysdbg2("PRCI not found in DP!\n"); - ret = mres.status; + ret = vres.status; goto cleanup_exit; } lock_acquire(&sysclk_key); arch_di_save_state(&ist); - dp = (module_t *) mres.p; + dp = (module_t *) vres.p; port->port_id = dp->id; port->baddr = dp->baddr; port->stride = dp->stride; @@ -187,7 +187,7 @@ static inline void sysclk_set_pll(unsigned int clk) return; } -static void sysclk_configure_clk(call_arg_t a0, call_arg_t a1, call_arg_t a2 _UNUSED, mret_t *ret) +static void sysclk_configure_clk(call_arg_t a0, call_arg_t a1, call_arg_t a2 _UNUSED, vret_t *ret) { sysclk_port_t *port = sysclk; istate_t ist; @@ -231,10 +231,10 @@ static void sysclk_configure_clk(call_arg_t a0, call_arg_t a1, call_arg_t a2 _UN return; } -INCLUDE_MCALL(sysclk_set, config_clk, sysclk_configure_clk); +INCLUDE_VCALL(sysclk_set, config_clk, sysclk_configure_clk); static void sysclk_get_freq(call_arg_t a0 _UNUSED, call_arg_t a1 _UNUSED, - call_arg_t a2 _UNUSED, mret_t *ret) + call_arg_t a2 _UNUSED, vret_t *ret) { sysclk_port_t *port = sysclk; istate_t ist; @@ -276,4 +276,4 @@ static void sysclk_get_freq(call_arg_t a0 _UNUSED, call_arg_t a1 _UNUSED, return; } -INCLUDE_MCALL(sysclk_get, fetch_clk, sysclk_get_freq); +INCLUDE_VCALL(sysclk_get, fetch_clk, sysclk_get_freq); diff --git a/src/include/driver/sysclk.h b/src/include/driver/sysclk.h index dc75356a..7adf4064 100644 --- a/src/include/driver/sysclk.h +++ b/src/include/driver/sysclk.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include typedef struct sysclk_config_clk_callback { @@ -28,17 +28,17 @@ status_t sysclk_reset(void); static inline status_t sysclk_set_clk(clock_type_t type, unsigned int clk) { - mret_t mres; - arch_machine_call(config_clk, type, clk, 0, &mres); - return mres.status; + vret_t vres; + arch_visor_call(config_clk, type, clk, 0, &vres); + return vres.status; } static inline status_t sysclk_get_clk(unsigned int *clk) { - mret_t mres; - arch_machine_call(fetch_clk, 0, 0, 0, &mres); - *clk = (mres.status == success) ? (unsigned int) mres.p : 0; - return mres.status; + vret_t vres; + arch_visor_call(fetch_clk, 0, 0, 0, &vres); + *clk = (vres.status == success) ? (unsigned int) vres.p : 0; + return vres.status; } status_t sysclk_register_config_clk_callback(sysclk_config_clk_callback_t *); diff --git a/src/include/linker_macros.h b/src/include/linker_macros.h index a14f50b1..40fe7546 100644 --- a/src/include/linker_macros.h +++ b/src/include/linker_macros.h @@ -15,7 +15,7 @@ KEEP(*(.driver)) \ PROVIDE(_driver_table_end = .); -#define ECALL_TABLE \ - PROVIDE(_ecall_table_start = .); \ - KEEP(*(.ecall)) \ - PROVIDE(_ecall_table_end = .); +#define VCALL_TABLE \ + PROVIDE(_vcall_table_start = .); \ + KEEP(*(.vcall)) \ + PROVIDE(_vcall_table_end = .); diff --git a/src/include/machine_call.h b/src/include/machine_call.h deleted file mode 100644 index e39c3fb0..00000000 --- a/src/include/machine_call.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * CYANCORE LICENSE - * Copyrights (C) 2019-2022, Cyancore Team - * - * File Name : machine_call.h - * Description : This file consists of machine call IDs and prototypes - * Primary Author : Akash Kollipara [akashkollipara@gmail.com] - * Organisation : Cyancore Core-Team - */ - -#pragma once -#define _MACHINE_CALL_H_ - -#include -#include - -// Machine call IDs -typedef enum mcall_id -{ - fetch_sp = 0x0001, - fetch_dp = 0x0002, - set_sleep_mode = 0x0003, - fetch_clk = 0x0004, - config_clk = 0x0005, -} mcall_id_t; - -typedef struct mret -{ - uintptr_t p; - size_t size; - status_t status; -} mret_t; - -#include - -typedef struct mcall -{ - mcall_id_t id; - void (*callback)(call_arg_t a0, call_arg_t a1, call_arg_t a2, mret_t *ret); -} mcall_t; - -#define INCLUDE_MCALL(_name, _id , _callback) \ - const mcall_t _name _SECTION(".ecall") = \ - { \ - .id = _id, \ - .callback = _callback \ - } diff --git a/src/include/status.h b/src/include/status.h index 6182f784..0a334037 100644 --- a/src/include/status.h +++ b/src/include/status.h @@ -33,14 +33,9 @@ typedef enum status error_device_id_inval = -0x0201, error_device_inval = -0x0202, error_device_busy = -0x0203, -/* Machine Call related error */ - error_mcall = -0x0300, - error_mcall_code_inval = -0x0301, -/* hcall related error */ - error_hcall = -0x0400, -/* Syscall related error */ - error_scall = -0x0500, - error_scall_code_inval = -0x0501, +/* Visor Call related error */ + error_vcall = -0x0300, + error_vcall_code_inval = -0x0301, /* Memory related error */ error_memory = -0x0600, error_memory_low = -0x0601, diff --git a/src/include/supervisor_call.h b/src/include/supervisor_call.h deleted file mode 100644 index 678a5da6..00000000 --- a/src/include/supervisor_call.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team - * - * File Name : supervisor_call.h - * Description : This file consists of supervisor call IDs and prototypes - * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] - * Organisation : Cyancore Core-Team - */ - -#pragma once -#define _SUPER_CALL_H_ - -#include -#include -#include - -// Supervisor call IDs -typedef enum scall_id -{ - scall_id_generic = 0x0000, - scall_id_is_irq, -/* pthread related */ - scall_id_pthread_barrier_destroy = 0x1000, - scall_id_pthread_barrier_init, - scall_id_pthread_barrier_wait, - scall_id_pthread_create, - scall_id_pthread_cond_broadcast, - scall_id_pthread_cond_destroy, - scall_id_pthread_cond_init, - scall_id_pthread_cond_signal, - scall_id_pthread_cond_timedwait, - scall_id_pthread_equal, - scall_id_pthread_exit, - scall_id_pthread_getschedparam, - scall_id_pthread_join, - scall_id_pthread_mutex_destroy, - scall_id_pthread_mutex_init, - scall_id_pthread_mutex_timedlock, - scall_id_pthread_mutex_unlock, - scall_id_pthread_mutexattr_destroy, - scall_id_pthread_mutexattr_gettype, - scall_id_pthread_mutexattr_init, - scall_id_pthread_mutexattr_settype, - scall_id_pthread_self, - scall_id_pthread_setschedparam, - scall_id_pthread_delay_ticks, -/* mqueue related */ - scall_id_mq_close, - scall_id_mq_setattr, - scall_id_mq_getattr, - scall_id_mq_open, - scall_id_mq_receive, - scall_id_mq_send, - scall_id_mq_unlink, -/* semaphore related */ - scall_id_sem_init, - scall_id_sem_destroy, - scall_id_sem_getvalue, - scall_id_sem_post, - scall_id_sem_wait, -/* scheduler related */ - scall_id_sched_get_max_priority, - scall_id_sched_get_min_priority, - scall_id_sched_yield, - -} scall_id_t; - -typedef struct sret -{ - uintptr_t p; - size_t size; - status_t status; -} sret_t; - -typedef struct scall -{ - scall_id_t id; - sret_t (*callback)(call_arg_t a0, call_arg_t a1, call_arg_t a2); -} scall_t; - -#define INCLUDE_SCALL(_name, _id , _callback) \ - const scall_t _name _SECTION(".scall") = \ - { \ - .id = _id, \ - .callback = _callback \ - } diff --git a/src/include/vcall_id.h b/src/include/vcall_id.h new file mode 100644 index 00000000..f7fa6c6c --- /dev/null +++ b/src/include/vcall_id.h @@ -0,0 +1,65 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2023, Cyancore Team + * + * File Name : vcall_id.h + * Description : This file consists of visor call IDs + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#pragma once +#define _VCALL_ID_H_ + +// Visor call IDs +typedef enum vcall_id +{ + fetch_sp = 0x0001, + fetch_dp = 0x0002, + set_sleep_mode = 0x0003, + fetch_clk = 0x0004, + config_clk = 0x0005, +/* pthread related */ + pthread_barrier_destroy = 0x1001, + pthread_barrier_init, + pthread_barrier_wait, + pthread_create, + pthread_cond_broadcast, + pthread_cond_destroy, + pthread_cond_init, + pthread_cond_signal, + pthread_cond_timedwait, + pthread_equal, + pthread_exit, + pthread_getschedparam, + pthread_join, + pthread_mutex_destroy, + pthread_mutex_init, + pthread_mutex_timedlock, + pthread_mutex_unlock, + pthread_mutexattr_destroy, + pthread_mutexattr_gettype, + pthread_mutexattr_init, + pthread_mutexattr_settype, + pthread_self, + pthread_setschedparam, + pthread_delay_ticks, +/* mqueue related */ + mq_close = 0x2001, + mq_setattr, + mq_getattr, + mq_open, + mq_receive, + mq_send, + mq_unlink, +/* semaphore related */ + sem_init, + sem_destroy, + sem_getvalue, + sem_post, + sem_wait, +/* scheduler related */ + sched_get_max_priority, + sched_get_min_priority, + sched_yield, +} vcall_id_t; diff --git a/src/include/visor/supervisor/workers.h b/src/include/visor/supervisor/workers.h deleted file mode 100644 index e966d14d..00000000 --- a/src/include/visor/supervisor/workers.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team - * - * File Name : worker.h - * Description : This file consists of supervisor-workers - * and related prototypes - * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] - * Organisation : Cyancore Core-Team - */ - -#pragma once - -#include - -void super_call(scall_id_t id, unsigned int a0, unsigned int a1, unsigned int a2, sret_t *ret); diff --git a/src/include/visor/terravisor/workers.h b/src/include/visor/terravisor/workers.h deleted file mode 100644 index ab9697ed..00000000 --- a/src/include/visor/terravisor/workers.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team - * - * File Name : worker.h - * Description : This file consists of terravisor-workers - * and related prototypes - * Primary Author : Akash Kollipara [akashkollipara@gmail.com] - * Organisation : Cyancore Core-Team - */ - -#pragma once - -void machine_call(unsigned int, unsigned int, unsigned int, unsigned int, mret_t *); diff --git a/src/include/visor/visor/workers.h b/src/include/visor/visor/workers.h new file mode 100644 index 00000000..dfa184b7 --- /dev/null +++ b/src/include/visor/visor/workers.h @@ -0,0 +1,13 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2023, Cyancore Team + * + * File Name : worker.h + * Description : This file consists of visor workers prototype + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#pragma once + +void vcall_handler(unsigned int, unsigned int, unsigned int, unsigned int, vret_t *); diff --git a/src/include/visor_call.h b/src/include/visor_call.h new file mode 100644 index 00000000..300fe539 --- /dev/null +++ b/src/include/visor_call.h @@ -0,0 +1,39 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2019-2023, Cyancore Team + * + * File Name : visor_call.h + * Description : This file consists of visor call utils and + * data types + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#pragma once +#define _VISOR_CALL_H_ + +#include +#include +#include + +typedef struct mret +{ + uintptr_t p; + size_t size; + status_t status; +} vret_t; + +#include + +typedef struct vcall +{ + vcall_id_t id; + void (*callback)(call_arg_t a0, call_arg_t a1, call_arg_t a2, vret_t *ret); +} vcall_t; + +#define INCLUDE_VCALL(_name, _id , _callback) \ + const vcall_t _name _SECTION(".vcall") = \ + { \ + .id = _id, \ + .callback = _callback \ + } diff --git a/src/lib/libposix/src/posix_mqueue.c b/src/lib/libposix/src/posix_mqueue.c index caaba26e..af0238d6 100644 --- a/src/lib/libposix/src/posix_mqueue.c +++ b/src/lib/libposix/src/posix_mqueue.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include @@ -44,7 +44,7 @@ static int s_queue_write(mqd_t mqdes, const void * buff, size_t size, unsigned m memcpy((void *)p_mqd_section->kernel_buff, buff, size); - super_call(scall_id_mq_send, p_mqd_section->id, size, msg_prio, &mq_sys_ret); + super_call(mq_send, p_mqd_section->id, size, msg_prio, &mq_sys_ret); RET_ERR_IF_FALSE(mq_sys_ret.status == SUCCESS, -EBADF, int); return SUCCESS; @@ -57,7 +57,7 @@ static int s_queue_read(mqd_t mqdes, void * buff, size_t size) RET_ERR_IF_FALSE((p_mqd_section->attr.mq_flags & O_WRONLY), -ENOTSUP, int); - super_call(scall_id_mq_receive, p_mqd_section->id, size, RST_VAL, &mq_sys_ret); + super_call(mq_receive, p_mqd_section->id, size, RST_VAL, &mq_sys_ret); RET_ERR_IF_FALSE(mq_sys_ret.status == SUCCESS, -EBADF, int); memcpy(buff, (void *) (p_mqd_section->kernel_buff), size); @@ -131,7 +131,7 @@ mqd_t mq_open( const char * name, p_mqd_section->attr.mq_flags = oflag; /* Perform super_call */ - super_call(scall_id_mq_open, + super_call(mq_open, (p_mqd_section->attr.mq_maxmsg * p_mqd_section->attr.mq_msgsize), RST_VAL, RST_VAL, @@ -175,7 +175,7 @@ int mq_close( mqd_t mqdes ) memset(&((mqd_section_t *) mqdes)->attr, RST_VAL, sizeof(mq_attr_t)); /* Perform Super Call */ - super_call(scall_id_mq_close, ((mqd_section_t *) mqdes)->id, RST_VAL, RST_VAL, &mq_sys_ret); + super_call(mq_close, ((mqd_section_t *) mqdes)->id, RST_VAL, RST_VAL, &mq_sys_ret); if (mq_sys_ret.status != SUCCESS) { err = -ENOTSUP; diff --git a/src/lib/libposix/src/posix_pthread.c b/src/lib/libposix/src/posix_pthread.c index 2d78dc61..b3f560a6 100644 --- a/src/lib/libposix/src/posix_pthread.c +++ b/src/lib/libposix/src/posix_pthread.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include @@ -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_arg_t) startroutine, (call_arg_t) arg, thread->attr->stacksize, &pthread_sys_ret); + super_call(pthread_create, (call_arg_t) startroutine, (call_arg_t) arg, thread->attr->stacksize, &pthread_sys_ret); if (pthread_sys_ret.status != SUCCESS) { err = -EAGAIN; @@ -166,7 +166,7 @@ void pthread_exit( const void *value_ptr _UNUSED) /* 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); + super_call(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/lib/libposix/src/posix_semaphore.c b/src/lib/libposix/src/posix_semaphore.c index cc0fd6fc..1b667ca0 100644 --- a/src/lib/libposix/src/posix_semaphore.c +++ b/src/lib/libposix/src/posix_semaphore.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include @@ -29,7 +29,7 @@ static int s_sem_wait( const sem_t * sem ) ASSERT_IF_FALSE(sem->id != RST_VAL, int); /* Perform super_call */ - super_call(scall_id_sem_wait, sem->id, RST_VAL, RST_VAL, &sem_sys_ret); + super_call(sem_wait, sem->id, RST_VAL, RST_VAL, &sem_sys_ret); return sem_sys_ret.status; } @@ -48,7 +48,7 @@ int sem_destroy( sem_t * sem ) ASSERT_IF_FALSE(sem->id != RST_VAL, int); /* Perform super_call */ - super_call(scall_id_sem_destroy, sem->id, RST_VAL, RST_VAL, &sem_sys_ret); + super_call(sem_destroy, sem->id, RST_VAL, RST_VAL, &sem_sys_ret); RET_ERR_IF_FALSE(sem_sys_ret.status == SUCCESS, sem_sys_ret.status, int); /* Reset semaphore ID */ @@ -67,7 +67,7 @@ int sem_getvalue( sem_t * sem, int * sval ) ASSERT_IF_FALSE(sem != NULL, int); /* Perform super_call */ - super_call(scall_id_sem_getvalue, sem->id, RST_VAL, RST_VAL, &sem_sys_ret); + super_call(sem_getvalue, sem->id, RST_VAL, RST_VAL, &sem_sys_ret); RET_ERR_IF_FALSE(sem_sys_ret.status == SUCCESS, sem_sys_ret.status, int); /* Copy sem value */ @@ -88,7 +88,7 @@ int sem_init( sem_t * sem, int pshared _UNUSED, unsigned value ) ASSERT_IF_FALSE(sem->id == RST_VAL, int); /* Perform super_call */ - super_call(scall_id_sem_init, value, RST_VAL, RST_VAL, &sem_sys_ret); + super_call(sem_init, value, RST_VAL, RST_VAL, &sem_sys_ret); if (sem_sys_ret.status != SUCCESS) { return sem_sys_ret.status; @@ -111,7 +111,7 @@ int sem_post( const sem_t * sem ) ASSERT_IF_FALSE(sem->id != RST_VAL, int); /* Perform super_call */ - super_call(scall_id_sem_post, sem->id, RST_VAL, RST_VAL, &sem_sys_ret); + super_call(sem_post, sem->id, RST_VAL, RST_VAL, &sem_sys_ret); return sem_sys_ret.status; } diff --git a/src/lib/libposix/src/posix_utils.c b/src/lib/libposix/src/posix_utils.c index f5f71710..5f2932b4 100644 --- a/src/lib/libposix/src/posix_utils.c +++ b/src/lib/libposix/src/posix_utils.c @@ -9,7 +9,7 @@ */ #include -#include +#include #include #include #include @@ -336,6 +336,6 @@ void os_delay_ticks( const TickType_t ticks ) { sret_t sys_ret; - super_call(scall_id_pthread_delay_ticks, ticks, RST_VAL, RST_VAL, &sys_ret); + super_call(pthread_delay_ticks, ticks, RST_VAL, RST_VAL, &sys_ret); RET_ERR_IF_FALSE(sys_ret.status == SUCCESS, EAGAIN, void); } diff --git a/src/platform/mega_avr/atmega2560/include/plat_arch.h b/src/platform/mega_avr/atmega2560/include/plat_arch.h index 542ab0c8..fe84e736 100644 --- a/src/platform/mega_avr/atmega2560/include/plat_arch.h +++ b/src/platform/mega_avr/atmega2560/include/plat_arch.h @@ -34,6 +34,6 @@ #define PRR1 0x65 #define OSCCAL 0x66 -#ifdef _MACHINE_CALL_H_ -extern void (*mcall)(unsigned int, unsigned int, unsigned int, unsigned int, mret_t *); +#ifdef _VISOR_CALL_H_ +extern void (*vcall)(unsigned int, unsigned int, unsigned int, unsigned int, vret_t *); #endif diff --git a/src/platform/mega_avr/common/hal/gpio/gpio.c b/src/platform/mega_avr/common/hal/gpio/gpio.c index 1efedb32..63906a37 100644 --- a/src/platform/mega_avr/common/hal/gpio/gpio.c +++ b/src/platform/mega_avr/common/hal/gpio/gpio.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -24,7 +24,7 @@ status_t gpio_pin_alloc(gpio_port_t *port, uint8_t portID, uint8_t pinID) { - mret_t mres; + vret_t vres; gpio_module_t *dp; unsigned char flag; @@ -46,13 +46,13 @@ status_t gpio_pin_alloc(gpio_port_t *port, uint8_t portID, uint8_t pinID) port->pin = pinID; port->port = portID; - arch_machine_call(fetch_dp, gpio, portID, 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_dp, gpio, portID, 0, &vres); + if(vres.status != success) { sysdbg4("GPIO Port %d not found in DP\n", portID); - return mres.status; + return vres.status; } - dp = (gpio_module_t *)mres.p; + dp = (gpio_module_t *)vres.p; port->pbaddr = dp->baddr; sysdbg4("GPIO engine @ %p\n", dp->baddr); sysdbg4("Using GPIO Pin %d on Port %d\n", port->pin, port->port); @@ -124,7 +124,7 @@ bool gpio_pin_read(const gpio_port_t *port) status_t gpio_port_alloc(gpio_port_t *port, uint8_t portID) { - mret_t mres; + vret_t vres; gpio_module_t *dp; unsigned char flag = 0; @@ -145,13 +145,13 @@ status_t gpio_port_alloc(gpio_port_t *port, uint8_t portID) port->pin = (uint8_t)((uint16_t)(1 << BIT) - 1); port->port = portID; - arch_machine_call(fetch_dp, gpio, portID, 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_dp, gpio, portID, 0, &vres); + if(vres.status != success) { sysdbg4("GPIO Port %d not found in DP\n", portID); - return mres.status; + return vres.status; } - dp = (gpio_module_t *)mres.p; + dp = (gpio_module_t *)vres.p; port->pbaddr = dp->baddr; sysdbg4("GPIO engine @ %p\n", dp->baddr); return success; diff --git a/src/platform/mega_avr/common/hal/pwm/pwm.c b/src/platform/mega_avr/common/hal/pwm/pwm.c index dc56e09a..11f18c66 100644 --- a/src/platform/mega_avr/common/hal/pwm/pwm.c +++ b/src/platform/mega_avr/common/hal/pwm/pwm.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -31,29 +31,29 @@ static void pwm_to_timer(const pwm_port_t *p, timer_port_t *t) status_t pwm_get_properties(pwm_port_t *port, sw_devid_t dev) { - mret_t mres; + vret_t vres; swdev_t *sp; module_t *dp; hw_devid_t devid; - arch_machine_call(fetch_sp, dev, 0, 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_sp, dev, 0, 0, &vres); + if(vres.status != success) { sysdbg3("%p - sp node could not be found!\n", dev); - return mres.status; + return vres.status; } - sp = (swdev_t *) mres.p; + sp = (swdev_t *) vres.p; devid = sp->hwdev_id; port->pmux = sp->pmux; - arch_machine_call(fetch_dp, (devid & 0xff00), (devid & 0xf0), 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_dp, (devid & 0xff00), (devid & 0xf0), 0, &vres); + if(vres.status != success) { sysdbg3("PWM (timer) Device %d not found!\n", devid); - return mres.status; + return vres.status; } - dp = (module_t *) mres.p; + dp = (module_t *) vres.p; port->port_id = dp->id; port->clk_id = dp->clk_id; port->baddr = dp->baddr; diff --git a/src/platform/mega_avr/common/hal/timer/timer.c b/src/platform/mega_avr/common/hal/timer/timer.c index 6a030ec0..9bf7892c 100644 --- a/src/platform/mega_avr/common/hal/timer/timer.c +++ b/src/platform/mega_avr/common/hal/timer/timer.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include "timer8.h" diff --git a/src/platform/mega_avr/common/hal/uart/uart.c b/src/platform/mega_avr/common/hal/uart/uart.c index f92e2f7d..7b734aab 100644 --- a/src/platform/mega_avr/common/hal/uart/uart.c +++ b/src/platform/mega_avr/common/hal/uart/uart.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include "uart_private.h" @@ -30,11 +30,11 @@ status_t uart_setup(uart_port_t *port, direction_t d, parity_t p) assert(port); MMIO8(port->baddr + UCSRA_OFFSET) = 0x00; platform_clk_en(port->clk_id); - mret_t mres; - arch_machine_call(fetch_dp, clock, 0, 0, &mres); - if(mres.status != success) - return mres.status; - unsigned long *clk = (unsigned long *)mres.p; + vret_t vres; + arch_visor_call(fetch_dp, clock, 0, 0, &vres); + if(vres.status != success) + return vres.status; + unsigned long *clk = (unsigned long *)vres.p; // Enable module based on direction diff --git a/src/platform/mega_avr/common/include/platform.h b/src/platform/mega_avr/common/include/platform.h index 1d71d867..f6388cf3 100644 --- a/src/platform/mega_avr/common/include/platform.h +++ b/src/platform/mega_avr/common/include/platform.h @@ -21,6 +21,6 @@ status_t platform_resources_setup(void); status_t platform_clk_reset(void); status_t platform_clk_en(unsigned int); status_t platform_clk_dis(unsigned int); -status_t platform_mcall_update(void *); +status_t platform_vcall_update(void *); status_t platform_wdt_reset(void); void plat_panic_handler_callback(void); diff --git a/src/platform/mega_avr/common/platform/platform.c b/src/platform/mega_avr/common/platform/platform.c index 6fefeae8..6af19823 100644 --- a/src/platform/mega_avr/common/platform/platform.c +++ b/src/platform/mega_avr/common/platform/platform.c @@ -13,9 +13,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include #include diff --git a/src/platform/mega_avr/common/platform/platform_resource.c b/src/platform/mega_avr/common/platform/platform_resource.c index 4fd3d28f..23fb30db 100644 --- a/src/platform/mega_avr/common/platform/platform_resource.c +++ b/src/platform/mega_avr/common/platform/platform_resource.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include /** @@ -38,7 +38,7 @@ status_t platform_resources_setup() } /** - * platform_fetch_sp - mcall handler for fetch_sp + * platform_fetch_sp - vcall handler for fetch_sp * * @brief This function is a machine call hander for fetch_sp * access code. It is responsible to respond with hardware ID @@ -51,7 +51,7 @@ status_t platform_resources_setup() * @return status: return the function execution status */ static void platform_fetch_sp(call_arg_t a0, call_arg_t a1 _UNUSED, - call_arg_t a2 _UNUSED, mret_t *ret) + call_arg_t a2 _UNUSED, vret_t *ret) { sysdbg2("Fetch SP: Got request for %x\n", a0); ret->p = (uintptr_t) sp_terravisor_dev_info(a0); @@ -60,10 +60,10 @@ static void platform_fetch_sp(call_arg_t a0, call_arg_t a1 _UNUSED, return; } -INCLUDE_MCALL(atmega328p_fetch_sp, fetch_sp, platform_fetch_sp); +INCLUDE_VCALL(atmega328p_fetch_sp, fetch_sp, platform_fetch_sp); /** - * platform_fetch_dp - mcall handler for fetch_dp + * platform_fetch_dp - vcall handler for fetch_dp * * @brief This function is a machine call hander for fetch_dp * access code. It is responsible to respond with pointer to @@ -76,7 +76,7 @@ INCLUDE_MCALL(atmega328p_fetch_sp, fetch_sp, platform_fetch_sp); * @return status: return the function execution status */ static void platform_fetch_dp(call_arg_t a0, call_arg_t a1 _UNUSED, - call_arg_t a2 _UNUSED, mret_t *ret) + call_arg_t a2 _UNUSED, vret_t *ret) { sysdbg2("Fetch DP: Got request for %x\n", a0); switch(a0) @@ -98,4 +98,4 @@ static void platform_fetch_dp(call_arg_t a0, call_arg_t a1 _UNUSED, return; } -INCLUDE_MCALL(atmega328p_fetch_dp, fetch_dp, platform_fetch_dp); +INCLUDE_VCALL(atmega328p_fetch_dp, fetch_dp, platform_fetch_dp); diff --git a/src/platform/mega_avr/common/platform/platform_timer.c b/src/platform/mega_avr/common/platform/platform_timer.c index 84391b30..0ed3a228 100644 --- a/src/platform/mega_avr/common/platform/platform_timer.c +++ b/src/platform/mega_avr/common/platform/platform_timer.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -76,26 +76,26 @@ static void plat_timer_reg_cb(void *cb) */ static status_t plat_get_timer_prop(void) { - mret_t mres; + vret_t vres; swdev_t *sp; hw_devid_t devid; - arch_machine_call(fetch_sp, sched_timer, 0, 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_sp, sched_timer, 0, 0, &vres); + if(vres.status != success) { sysdbg3("%p - sp node could not be found!\n", sched_timer); - return mres.status; + return vres.status; } - sp = (swdev_t *) mres.p; + sp = (swdev_t *) vres.p; devid = sp->hwdev_id; - arch_machine_call(fetch_dp, (devid & 0xff00), (devid & 0xff), 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_dp, (devid & 0xff00), (devid & 0xff), 0, &vres); + if(vres.status != success) { sysdbg3("Timer Device %d not found!\n", devid); - return mres.status; + return vres.status; } - tm = (module_t *) mres.p; + tm = (module_t *) vres.p; return success; } diff --git a/src/platform/mega_avr/common/platform/platform_wdt.c b/src/platform/mega_avr/common/platform/platform_wdt.c index c2211611..4136e0bc 100644 --- a/src/platform/mega_avr/common/platform/platform_wdt.c +++ b/src/platform/mega_avr/common/platform/platform_wdt.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -45,16 +45,16 @@ void platform_wdt_handler(); */ static status_t platform_wdt_setup() { - mret_t mres; + vret_t vres; module_t *dp; - arch_machine_call(fetch_dp, wdt, 0, 0, &mres); + arch_visor_call(fetch_dp, wdt, 0, 0, &vres); - if(mres.status != success) + if(vres.status != success) { sysdbg2("WDT not found in DP\n"); - return mres.status; + return vres.status; } - dp = (module_t *) mres.p; + dp = (module_t *) vres.p; plat_wdt = (wdt_port_t *)malloc(sizeof(wdt_port_t)); if(!plat_wdt) return error_memory_low; diff --git a/src/platform/mega_avr/common/sections.ld.sx b/src/platform/mega_avr/common/sections.ld.sx index b8177686..7d8b3be5 100644 --- a/src/platform/mega_avr/common/sections.ld.sx +++ b/src/platform/mega_avr/common/sections.ld.sx @@ -65,7 +65,7 @@ SECTIONS *(.data.*) KEEP(*(.data)) DRIVER_TABLE - ECALL_TABLE + VCALL_TABLE } > vma_dmem AT > lma_mem .heap : diff --git a/src/platform/rpi/common_rp2/platform/platform_resource.c b/src/platform/rpi/common_rp2/platform/platform_resource.c index c725c3b2..5ebce2bf 100644 --- a/src/platform/rpi/common_rp2/platform/platform_resource.c +++ b/src/platform/rpi/common_rp2/platform/platform_resource.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include /** diff --git a/src/platform/sifive/common_fe310/hal/clint/clint.c b/src/platform/sifive/common_fe310/hal/clint/clint.c index 6ca26ecd..bd1adf56 100644 --- a/src/platform/sifive/common_fe310/hal/clint/clint.c +++ b/src/platform/sifive/common_fe310/hal/clint/clint.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -30,19 +30,19 @@ static clint_port_t *port; static status_t clint_setup() { - mret_t mres; + vret_t vres; const module_t *dp; - arch_machine_call(fetch_dp, clint, 0, 0, &mres); + arch_visor_call(fetch_dp, clint, 0, 0, &vres); - if(mres.status != success) - return mres.status; + if(vres.status != success) + return vres.status; port = (clint_port_t *)malloc(sizeof(clint_port_t)); if(!port) return error_memory_low; - dp = (module_t *)mres.p; + dp = (module_t *)vres.p; port->baddr = dp->baddr; port->stride = dp->stride; port->port_id = clint; diff --git a/src/platform/sifive/common_fe310/hal/gpio/gpio.c b/src/platform/sifive/common_fe310/hal/gpio/gpio.c index 70dd8041..f00138ec 100644 --- a/src/platform/sifive/common_fe310/hal/gpio/gpio.c +++ b/src/platform/sifive/common_fe310/hal/gpio/gpio.c @@ -22,7 +22,7 @@ status_t gpio_pin_alloc(gpio_port_t *port, uint8_t portID, uint8_t pinID) { - mret_t mres; + vret_t vres; const gpio_module_t *dp; unsigned char flag; @@ -42,13 +42,13 @@ status_t gpio_pin_alloc(gpio_port_t *port, uint8_t portID, uint8_t pinID) port->pin = pinID; port->port = portID; - arch_machine_call(fetch_dp, gpio, portID, 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_dp, gpio, portID, 0, &vres); + if(vres.status != success) { sysdbg("GPIO Port %d not found in DP\n", portID); - return mres.status; + return vres.status; } - dp = (gpio_module_t *)mres.p; + dp = (gpio_module_t *)vres.p; port->pbaddr = dp->baddr; sysdbg("GPIO engine @ %p\n", dp->baddr); sysdbg("Using GPIO Pin %d on Port %d\n", port->pin, port->port); diff --git a/src/platform/sifive/common_fe310/hal/uart/uart.c b/src/platform/sifive/common_fe310/hal/uart/uart.c index ee29c1b0..99089347 100644 --- a/src/platform/sifive/common_fe310/hal/uart/uart.c +++ b/src/platform/sifive/common_fe310/hal/uart/uart.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -26,28 +26,28 @@ status_t uart_get_properties(uart_port_t *port, sw_devid_t dev) { - mret_t mres; + vret_t vres; swdev_t *sp; module_t *dp; hw_devid_t devid; - arch_machine_call(fetch_sp, dev, 0, 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_sp, dev, 0, 0, &vres); + if(vres.status != success) { sysdbg3("%p - sp node could not be found!\n", dev); - return mres.status; + return vres.status; } - sp = (swdev_t *) mres.p; + sp = (swdev_t *) vres.p; devid = sp->hwdev_id; port->pmux = sp->pmux; - arch_machine_call(fetch_dp, (devid & 0xff00), (devid & 0xff), 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_dp, (devid & 0xff00), (devid & 0xff), 0, &vres); + if(vres.status != success) { sysdbg3("UART Device %d not found!\n", devid); - return mres.status; + return vres.status; } - dp = (module_t *) mres.p; + dp = (module_t *) vres.p; port->port_id = dp->id; port->clk_id = dp->clk_id; port->baddr = dp->baddr; diff --git a/src/platform/sifive/common_fe310/platform/plat_timer.c b/src/platform/sifive/common_fe310/platform/plat_timer.c index 096a752a..0e6f9ab2 100644 --- a/src/platform/sifive/common_fe310/platform/plat_timer.c +++ b/src/platform/sifive/common_fe310/platform/plat_timer.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include @@ -72,26 +72,26 @@ static void plat_timer_reg_cb(void *cb) */ static status_t plat_get_timer_prop(void) { - mret_t mres; + vret_t vres; swdev_t *sp; hw_devid_t devid; - arch_machine_call(fetch_sp, sched_timer, 0, 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_sp, sched_timer, 0, 0, &vres); + if(vres.status != success) { sysdbg3("%p - sp node could not be found!\n", sched_timer); - return mres.status; + return vres.status; } - sp = (swdev_t *) mres.p; + sp = (swdev_t *) vres.p; devid = sp->hwdev_id; - arch_machine_call(fetch_dp, (devid & 0xff00), (devid & 0xff), 0, &mres); - if(mres.status != success) + arch_visor_call(fetch_dp, (devid & 0xff00), (devid & 0xff), 0, &vres); + if(vres.status != success) { sysdbg3("Timer Device %d not found!\n", devid); - return mres.status; + return vres.status; } - tm = (module_t *) mres.p; + tm = (module_t *) vres.p; return success; } diff --git a/src/platform/sifive/common_fe310/platform/platform.c b/src/platform/sifive/common_fe310/platform/platform.c index b2bd834d..db5f52b6 100644 --- a/src/platform/sifive/common_fe310/platform/platform.c +++ b/src/platform/sifive/common_fe310/platform/platform.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include void platform_early_setup() diff --git a/src/platform/sifive/common_fe310/platform/platform_reset.c b/src/platform/sifive/common_fe310/platform/platform_reset.c index 2f676eaa..41e9dd0d 100644 --- a/src/platform/sifive/common_fe310/platform/platform_reset.c +++ b/src/platform/sifive/common_fe310/platform/platform_reset.c @@ -31,15 +31,15 @@ */ reset_t platform_get_reset_syndrome() { - mret_t mres; + vret_t vres; const module_t *dp; uint32_t pmucause_val; aon_port_t aonport; - arch_machine_call(fetch_dp, aon, 0, 0, &mres); - assert(mres.status == success); + arch_visor_call(fetch_dp, aon, 0, 0, &vres); + assert(vres.status == success); - dp = (module_t *)mres.p; + dp = (module_t *)vres.p; aonport.baddr = dp->baddr; aon_pmucause(&aonport, &pmucause_val); diff --git a/src/platform/sifive/common_fe310/platform/platform_resource.c b/src/platform/sifive/common_fe310/platform/platform_resource.c index a8ad09f0..fc89e673 100644 --- a/src/platform/sifive/common_fe310/platform/platform_resource.c +++ b/src/platform/sifive/common_fe310/platform/platform_resource.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include /** @@ -37,7 +37,7 @@ status_t platform_resources_setup() } /** - * platform_fetch_sp - mcall handler for fetch_sp + * platform_fetch_sp - vcall handler for fetch_sp * * @brief This function is a machine call hander for fetch_sp * access code. It is responsible to respond with hardware ID @@ -50,7 +50,7 @@ status_t platform_resources_setup() * @return status: return the function execution status */ static void platform_fetch_sp(call_arg_t a0, call_arg_t a1 _UNUSED, - call_arg_t a2 _UNUSED, mret_t *ret) + call_arg_t a2 _UNUSED, vret_t *ret) { sysdbg5("Fetch SP: Got request for %x\n", a0); ret->p = (uintptr_t) sp_terravisor_dev_info(a0); @@ -59,10 +59,10 @@ static void platform_fetch_sp(call_arg_t a0, call_arg_t a1 _UNUSED, return; } -INCLUDE_MCALL(sifive_fe310_fetch_sp, fetch_sp, platform_fetch_sp); +INCLUDE_VCALL(sifive_fe310_fetch_sp, fetch_sp, platform_fetch_sp); /** - * platform_fetch_dp - mcall handler for fetch_dp + * platform_fetch_dp - vcall handler for fetch_dp * * @brief This function is a machine call hander for fetch_dp * access code. It is responsible to respond with pointer to @@ -75,7 +75,7 @@ INCLUDE_MCALL(sifive_fe310_fetch_sp, fetch_sp, platform_fetch_sp); * @return status: return the function execution status */ static void platform_fetch_dp(call_arg_t a0, call_arg_t a1 _UNUSED, - call_arg_t a2 _UNUSED, mret_t *ret) + call_arg_t a2 _UNUSED, vret_t *ret) { sysdbg5("Fetch DP: Got request for %x\n", a0); switch(a0) @@ -97,4 +97,4 @@ static void platform_fetch_dp(call_arg_t a0, call_arg_t a1 _UNUSED, return; } -INCLUDE_MCALL(sifive_fe310_fetch_dp, fetch_dp, platform_fetch_dp); +INCLUDE_VCALL(sifive_fe310_fetch_dp, fetch_dp, platform_fetch_dp); diff --git a/src/platform/sifive/common_fe310/sections.ld.sx b/src/platform/sifive/common_fe310/sections.ld.sx index f5650e3a..2c9c75d7 100644 --- a/src/platform/sifive/common_fe310/sections.ld.sx +++ b/src/platform/sifive/common_fe310/sections.ld.sx @@ -91,7 +91,7 @@ SECTIONS *(.data.*) KEEP(*(.data)) DRIVER_TABLE - ECALL_TABLE + VCALL_TABLE } > vma_dmem AT > lma_mem .tdata : ALIGN(4) diff --git a/src/visor/build.mk b/src/visor/build.mk index 47130f58..40820c16 100644 --- a/src/visor/build.mk +++ b/src/visor/build.mk @@ -13,6 +13,7 @@ VISOR_DIR := $(GET_PATH) INCLUDE += $(SRC)/include/visor/ +include $(VISOR_DIR)/common/build.mk ifneq ($(EXE_MODE),) include $(VISOR_DIR)/$(EXE_MODE)/build.mk endif diff --git a/src/visor/common/build.mk b/src/visor/common/build.mk new file mode 100644 index 00000000..e47070a4 --- /dev/null +++ b/src/visor/common/build.mk @@ -0,0 +1,14 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2023, Cyancore Team +# +# File Name : build.mk +# Description : This file accumulates the build scripts +# from terravisor directories +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +V_COM_PATH := $(GET_PATH) + +include $(V_COM_PATH)/workers/build.mk diff --git a/src/visor/supervisor/workers/scall/build.mk b/src/visor/common/workers/build.mk similarity index 63% rename from src/visor/supervisor/workers/scall/build.mk rename to src/visor/common/workers/build.mk index c07c5394..4029ffdd 100644 --- a/src/visor/supervisor/workers/scall/build.mk +++ b/src/visor/common/workers/build.mk @@ -1,6 +1,6 @@ # # CYANCORE LICENSE -# Copyrights (C) 2019, Cyancore Team +# Copyrights (C) 2023, Cyancore Team # # File Name : build.mk # Description : This file builds worker sources @@ -8,10 +8,10 @@ # Organisation : Cyancore Core-Team # -MCALL_DIR := $(GET_PATH) +VWORKER_DIR := $(GET_PATH) -LD_SUPPLEMENT += $(MCALL_DIR)/scall.ld.sx +include $(VWORKER_DIR)/vcall/build.mk -DIR := $(MCALL_DIR) +DIR := $(VWORKER_DIR) include mk/obj.mk diff --git a/src/visor/terravisor/workers/mcall/build.mk b/src/visor/common/workers/vcall/build.mk similarity index 72% rename from src/visor/terravisor/workers/mcall/build.mk rename to src/visor/common/workers/vcall/build.mk index 9e20c5e8..7cb37a68 100644 --- a/src/visor/terravisor/workers/mcall/build.mk +++ b/src/visor/common/workers/vcall/build.mk @@ -1,6 +1,6 @@ # # CYANCORE LICENSE -# Copyrights (C) 2019, Cyancore Team +# Copyrights (C) 2023, Cyancore Team # # File Name : build.mk # Description : This file builds worker sources @@ -8,8 +8,8 @@ # Organisation : Cyancore Core-Team # -MCALL_DIR := $(GET_PATH) +VCALL_DIR := $(GET_PATH) -DIR := $(MCALL_DIR) +DIR := $(VCALL_DIR) include mk/obj.mk diff --git a/src/visor/terravisor/workers/mcall/machine_call.c b/src/visor/common/workers/vcall/visor_call.c similarity index 50% rename from src/visor/terravisor/workers/mcall/machine_call.c rename to src/visor/common/workers/vcall/visor_call.c index 4d1572bd..d23ee3c4 100644 --- a/src/visor/terravisor/workers/mcall/machine_call.c +++ b/src/visor/common/workers/vcall/visor_call.c @@ -1,6 +1,6 @@ /* * CYANCORE LICENSE - * Copyrights (C) 2019-2022, Cyancore Team + * Copyrights (C) 2019-2023, Cyancore Team * * File Name : machine_call.c * Description : This file contains sources of machine call handler @@ -11,41 +11,41 @@ #include #include #include -#include +#include #include #include -/* mcall Table start and end defined in linker script mcall.ld.sx */ -extern mcall_t _ecall_table_start; -extern mcall_t _ecall_table_end; +/* vcall Table start and end defined in linker script using VCALL_TABLE */ +extern vcall_t _vcall_table_start; +extern vcall_t _vcall_table_end; -typedef void (*mcb_t)(call_arg_t, call_arg_t, call_arg_t, mret_t *); -static mcb_t get_callback_from_table(const mcall_t *start, const mcall_t *end, mcall_id_t id) +typedef void (*vcb_t)(call_arg_t, call_arg_t, call_arg_t, vret_t *); +static vcb_t get_callback_from_table(const vcall_t *start, const vcall_t *end, vcall_id_t id) { - mcall_t *ptr = (mcall_t *)start; + vcall_t *ptr = (vcall_t *)start; while(ptr < end) { if(ptr->id == id) return (ptr->callback != NULL) ? ptr->callback : NULL; ptr++; } - return (mcb_t) 0; + return (vcb_t) 0; } -void machine_call(mcall_id_t id, call_arg_t a0, call_arg_t a1, call_arg_t a2, mret_t *ret) +void vcall_handler(vcall_id_t id, call_arg_t a0, call_arg_t a1, call_arg_t a2, vret_t *ret) { - sysdbg4("MCall: id=%p, a0=%p, a1=%p, a2=%p\n", id, a0, a1, a2); + sysdbg4("VCall: id=%p, a0=%p, a1=%p, a2=%p\n", id, a0, a1, a2); /* Callback function pointer */ - mcb_t cb; + vcb_t cb; /* Assign "ret" parameters to default error case, * on execution of the call, the ret will updated. */ ret->p = (uintptr_t) 0; ret->size = 0; - ret->status = error_mcall_code_inval; + ret->status = error_vcall_code_inval; - cb = get_callback_from_table(&_ecall_table_start, &_ecall_table_end, id); + cb = get_callback_from_table(&_vcall_table_start, &_vcall_table_end, id); if(cb != 0) cb(a0, a1, a2, ret); return; diff --git a/src/visor/supervisor/workers/scall/scall.ld.sx b/src/visor/supervisor/workers/scall/scall.ld.sx deleted file mode 100644 index 8771727f..00000000 --- a/src/visor/supervisor/workers/scall/scall.ld.sx +++ /dev/null @@ -1,22 +0,0 @@ -/* - * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team - * - * File Name : scall.ld.sx - * Description : This file contains memory layout for the - * cyancore scall framework - * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] - * Organisation : Cyancore Core-Team - */ - -SECTIONS -{ - .scall_table : - { - PROVIDE(_scall_table_start = .); - KEEP(*(.scall)) - PROVIDE(_scall_table_end = .); - } -} - -INSERT BEFORE .stack; diff --git a/src/visor/supervisor/workers/scall/supervisory_call.c b/src/visor/supervisor/workers/scall/supervisory_call.c deleted file mode 100644 index da6a44ff..00000000 --- a/src/visor/supervisor/workers/scall/supervisory_call.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team - * - * File Name : supervisory_call.c - * Description : This file contains sources of supervisory call handler - * Primary Author : Pranjal Chanda [pranjalchanda08@gmail.com] - * Organisation : Cyancore Core-Team - */ - -#include -#include -#include -#include -#include -#include - -/* mcall Table start and end defined in linker script mcall.ld.sx */ -extern scall_t _scall_table_start; -extern scall_t _scall_table_end; - -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; - - /* Assign "ret" parameters to default error case, - * on execution of the call, the ret will updated. - */ - ret->p = (uintptr_t) NULL; - ret->size = 0; - ret->status = error_scall_code_inval; - - /* Assign the pointer to start of table */ - ptr = &_scall_table_start; - - /* Run through the table till the end */ - while(ptr <= & _scall_table_end) - { - /* Check if the mcall ID matches */ - if(ptr->id == id) - { - /* Execute the callback function and update the "ret" */ - if (ptr->callback != NULL) - { - *ret = ptr->callback(a0, a1, a2); - } - /* Stop parsing the table and return */ - break; - } - /* Increament location pointer */ - ptr++; - } - return; -} diff --git a/src/visor/terravisor/build.mk b/src/visor/terravisor/build.mk index acdb3874..54b1c29f 100644 --- a/src/visor/terravisor/build.mk +++ b/src/visor/terravisor/build.mk @@ -15,4 +15,3 @@ TERRAVISOR := 1 $(eval $(call add_define,TERRAVISOR)) include $(TERRA_PATH)/services/build.mk -include $(TERRA_PATH)/workers/build.mk diff --git a/src/visor/terravisor/workers/build.mk b/src/visor/terravisor/workers/build.mk deleted file mode 100644 index 232b8f52..00000000 --- a/src/visor/terravisor/workers/build.mk +++ /dev/null @@ -1,17 +0,0 @@ -# -# CYANCORE LICENSE -# Copyrights (C) 2019, Cyancore Team -# -# File Name : build.mk -# Description : This file builds worker sources -# Primary Author : Akash Kollipara [akashkollipara@gmail.com] -# Organisation : Cyancore Core-Team -# - -TWORKER_DIR := $(GET_PATH) - -include $(TWORKER_DIR)/mcall/build.mk - -DIR := $(TWORKER_DIR) - -include mk/obj.mk