Skip to content

Commit

Permalink
<VisorCall> Moving all exception calls to visor call
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
akashkollipara committed Nov 22, 2023
1 parent 93ace41 commit 604c295
Show file tree
Hide file tree
Showing 56 changed files with 363 additions and 495 deletions.
12 changes: 6 additions & 6 deletions src/arch/arm-m/32/common_v6_v7/supervisor/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
#include <syslog.h>
#include <mmio.h>
#include <arch.h>
#include <terravisor/workers.h>
#include <visor/workers.h>

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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/arch/arm-m/32/common_v6_v7/supervisor/include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define _ARCH_H_

#include <arm.h>
#include <machine_call.h>
#include <visor_call.h>

/**
* arch_early_setup - This needs to be called in early stages of boot
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/arch/avr/8/common_5x_6/terravisor/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
#include <plat_arch.h>
#include <mmio.h>
#include <arch.h>
#include <terravisor/workers.h>
#include <visor/workers.h>

/**
* arch_early_setup - This function is called in the early stages of boot
*
* @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();
Expand Down
10 changes: 5 additions & 5 deletions src/arch/avr/8/common_5x_6/terravisor/include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <avr.h>
#include <mmio.h>
#include <resource.h>
#include <machine_call.h>
#include <visor_call.h>

/**
* arch_early_setup - This needs to be called in early stages of boot
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}

Expand Down
18 changes: 9 additions & 9 deletions src/arch/riscv/32/i/terravisor/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
#include <syslog.h>
#include <arch.h>
#include <lock/lock.h>
#include <terravisor/workers.h>
#include <visor/workers.h>
#include <interrupt.h>

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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/arch/riscv/32/i/terravisor/include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <stdbool.h>
#include <resource.h>
#include <riscv.h>
#include <machine_call.h>
#include <visor_call.h>

/**
* arch_early_setup - This needs to be called in early stages of boot
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/driver/console/con_serial_mega_avr/console_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <stdlib.h>
#include <lock/spinlock.h>
#include <resource.h>
#include <machine_call.h>
#include <visor_call.h>
#include <arch.h>
#include <driver.h>
#include <interrupt.h>
Expand All @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/driver/console/con_serial_mega_avr/earlycon_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <stdlib.h>
#include <lock/spinlock.h>
#include <resource.h>
#include <machine_call.h>
#include <visor_call.h>
#include <arch.h>
#include <driver.h>
#include <interrupt.h>
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/driver/console/con_serial_sifive/console_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <stdlib.h>
#include <lock/spinlock.h>
#include <resource.h>
#include <machine_call.h>
#include <visor_call.h>
#include <arch.h>
#include <driver.h>
#include <interrupt.h>
Expand Down
2 changes: 1 addition & 1 deletion src/driver/console/con_serial_sifive/earlycon_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <syslog.h>
#include <lock/spinlock.h>
#include <resource.h>
#include <machine_call.h>
#include <visor_call.h>
#include <arch.h>
#include <driver.h>
#include <interrupt.h>
Expand Down
12 changes: 6 additions & 6 deletions src/driver/interrupt/plic/plic.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <stdbool.h>
#include <assert.h>
#include <arch.h>
#include <machine_call.h>
#include <visor_call.h>
#include <interrupt.h>
#include <resource.h>
#include <driver.h>
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/driver/onboardled/onboardled.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <syslog.h>
#include <stdlib.h>
#include <resource.h>
#include <machine_call.h>
#include <visor_call.h>
#include <lock/lock.h>
#include <driver.h>
#include <driver/onboardled.h>
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 604c295

Please sign in to comment.