Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #272

Merged
merged 20 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b54bcff
Add support for strcpy
akashkollipara Dec 19, 2023
5f9c8a3
Merge pull request #260 from VisorFolks/dev/akashkollipara/libc
akashkollipara Dec 20, 2023
d571a37
<libc> strcpy is now a macro which uses strlcpy
akashkollipara Dec 21, 2023
d2ac8e3
Update sonarcloud.yml
pranjalchanda08 Dec 23, 2023
b894e72
Update sonarcloud.yml
pranjalchanda08 Dec 23, 2023
a237aca
Merge pull request #264 from VisorFolks/dev/pranjalchanda08/263-chang…
akashkollipara Dec 24, 2023
0cc5bd9
<Status> Updated status codes to use +ve values.
akashkollipara Dec 24, 2023
7813dc1
<Err> Updated error handling
akashkollipara Dec 24, 2023
4ca5849
<RV32I> Fix for arch_ei_restore_state
akashkollipara Jan 1, 2024
ce87773
Additional fixes and cosmetic updates for status codes
akashkollipara Jan 1, 2024
c33f791
<SiFive> Fixed error handling in platform timer
akashkollipara Jan 1, 2024
23db466
<Mega AVR> Updated status code on HAL
akashkollipara Jan 1, 2024
6038f34
<SiFive> Add use_prng guard for bootloader limitations
akashkollipara Jan 1, 2024
e725432
Merge pull request #266 from VisorFolks/bugfix/akashkollipara/status_…
akashkollipara Jan 3, 2024
66f7eb9
Pseudo Random number generation update
shubhangi47 Jan 3, 2024
b7ec522
Merge pull request #270 from VisorFolks/dev/akashkollipara/236-sifive…
shubhangi47 Jan 3, 2024
a4dfdae
Merge pull request #269 from VisorFolks/dev/shubhangi47/236-arch_rand…
akashkollipara Jan 3, 2024
3fe5b81
Added support for true random number generation for avr platform
shubhangi47 Jan 3, 2024
fc0ca77
Merge pull request #271 from VisorFolks/dev/shubhangi47/236-arch_rand…
akashkollipara Jan 3, 2024
22922b1
Cosmetic Fix
akashkollipara Jan 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
run: |
make get_avr_tc AVR_TC_REPO=https://github.com/VisorFolks/avr-toolchain.git
make get_riscv_tc RISC_V_TC_REPO=https://github.com/VisorFolks/risc-v-toolchain.git
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Download and set up sonar-scanner
env:
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
Expand Down
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
"*.sx": "c",
"*.{c,c.dev.c.temp,c.tmp,c.old,h,h.dev,h.old,h.temp,h.tmp)": "C",
"*.{cpp,cpp.dev,cpp.temp,cpp.tmp,cpp.old}": "C++",
"*.{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",
"cc_os_sched.h": "c",
"cc_os.h": "c"
"*.{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": 100,
Expand Down
12 changes: 12 additions & 0 deletions src/arch/avr/8/common_5x_6/terravisor/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <mmio.h>
#include <arch.h>
#include <visor/workers.h>
#include <rand.h>

/**
* arch_early_setup - This function is called in the early stages of boot
Expand Down Expand Up @@ -139,3 +140,14 @@ void arch_signal_resume(void)
{
sleep_flag = resume;
}

/**
* arch_rseed_capture
*
* @brief This function is intended to capture unique seed value
*/
void arch_rseed_capture()
{
extern uintptr_t *_bss_start;
srand(*_bss_start);
}
3 changes: 3 additions & 0 deletions src/arch/avr/8/common_5x_6/terravisor/include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,6 @@ bool arch_suspended_state_was(cpu_sleep_t);
void arch_signal_suspend(cpu_sleep_t);
void arch_signal_resume(void);
#endif

void arch_rseed_capture();

4 changes: 3 additions & 1 deletion src/arch/avr/8/common_5x_6/terravisor/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <mmio.h>
#include <plat_arch.h>
#include <engine.h>
#include <arch.h>

extern uint16_t stack_start;

Expand All @@ -33,7 +34,8 @@ void _NAKED init()
{
/* Set resisters to architecturally defined reset */
zero_reg();

/* Capture unique seed value before memory initialization */
arch_rseed_capture();
/* Boot framework */
engine();

Expand Down
13 changes: 13 additions & 0 deletions src/arch/riscv/32/i/terravisor/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <lock/lock.h>
#include <visor/workers.h>
#include <interrupt.h>
#include <rand.h>

static void arch_vcall_handler()
{
Expand Down Expand Up @@ -93,6 +94,7 @@ void arch_di_save_state(istate_t *istate)
void arch_ei_restore_state(istate_t *istate)
{
asm volatile("csrs mie, %0" : : "r" (*istate));
arch_ei();
}

static cpu_sleep_t sleep_flag[N_CORES];
Expand Down Expand Up @@ -159,3 +161,14 @@ _WEAK void arch_unhandled_irq()
while(1)
arch_wfi();
}

/**
* arch_rseed_capture
*
* @brief This function is intended to capture unique seed value
*/
void arch_rseed_capture()
{
extern uintptr_t *_bss_start;
srand(*_bss_start);
}
1 change: 1 addition & 0 deletions src/arch/riscv/32/i/terravisor/include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,4 @@ static inline void arch_dmb()
bool arch_suspended_state_was(cpu_sleep_t);
void arch_signal_suspend(cpu_sleep_t);
void arch_signal_resume(void);
void arch_rseed_capture();
5 changes: 4 additions & 1 deletion src/arch/riscv/32/i/terravisor/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ void _NAKED init()
{
arch_di();
asm volatile("la tp, _tls_start");
#if USE_PRNG
/* Capture unique seed value before memory initialization */
arch_rseed_capture();
#endif
/* Boot framework */

#if CCSMP == 0
engine();
#else
Expand Down
2 changes: 1 addition & 1 deletion src/driver/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ status_t driver_register(device_t *dev _UNUSED)

ret = dev->driver_setup();
(ret == success) ? syslog(pass, "Started %s\n", dev->name) :
syslog(fail, "Couldn't start %s (Err: -%p)\n", dev->name, -ret);
syslog(fail, "Couldn't start %s (Err: %p)\n", dev->name, ret);
exit:
return ret;
}
Expand Down
3 changes: 1 addition & 2 deletions src/driver/interrupt/plic/plic.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ static bool plic_get_pending(uint32_t irq_id)

static void plic_register_irq_handler(uint32_t id, void (* handler)(void))
{
assert(id);
assert(handler);
RET_ON_FAIL(id && handler,);
plic_irq_handler[id] = handler;
arch_dsb();
}
Expand Down
32 changes: 11 additions & 21 deletions src/driver/sysclk/sysclk_prci/sysclk_prci.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ static status_t sysclk_setup()
istate_t ist;

sysclk = (sysclk_port_t *)malloc(sizeof(sysclk_port_t));
if(!sysclk)
return error_memory_low;

RET_ON_FAIL(sysclk, error_memory_low);

port = sysclk;

arch_visor_call(fetch_dp, clock, 0, 0, &vres);
Expand Down Expand Up @@ -84,10 +85,8 @@ static status_t sysclk_disable()
istate_t ist;
sysclk_port_t *port = sysclk;

if(!port)
return error_driver_init_failed;

assert(port->baddr && port->base_clk);
RET_ON_FAIL(port && port->baddr && port->base_clk,
error_driver_data);

lock_acquire(&sysclk_key);
arch_di_save_state(&ist);
Expand All @@ -111,10 +110,9 @@ status_t sysclk_reset()
status_t ret;
sysclk_port_t *port = sysclk;
istate_t ist;
if(!port)
return error_driver_init_failed;

assert(port->baddr && port->base_clk);
RET_ON_FAIL(port && port->baddr && port->base_clk,
error_driver_data);

lock_acquire(&sysclk_key);
arch_di_save_state(&ist);
Expand All @@ -136,8 +134,6 @@ static inline void sysclk_set_internal(unsigned int clk _UNUSED)
{
status_t ret;
sysclk_port_t *port = sysclk;
if(!port)
return;
ret = prci_hfxocs_enable(port);
prci_pll_bypass(port);
ret |= prci_hfosc_enable(port);
Expand All @@ -155,8 +151,6 @@ static inline void sysclk_set_external(void)
{
status_t ret;
sysclk_port_t *port = sysclk;
if(!port)
return;
ret = prci_hfosc_enable(port);
ret |= prci_hfxocs_enable(port);
prci_pll_select_xosc(port);
Expand All @@ -172,8 +166,6 @@ static inline void sysclk_set_pll(unsigned int clk)
{
status_t ret;
sysclk_port_t *port = sysclk;
if(!port)
return;
ret = prci_hfosc_enable(port);
ret |= prci_hfxocs_enable(port);
prci_pll_bypass(port);
Expand All @@ -193,10 +185,9 @@ static void sysclk_configure_clk(call_arg_t a0, call_arg_t a1, call_arg_t a2 _UN
istate_t ist;
clock_type_t type = (clock_type_t) a0;
unsigned int clk = (unsigned int) a1;
if(!port)
return;

assert(port->baddr && port->base_clk);
ret->status = error_inval_pointer;
RET_ON_FAIL(port && port->baddr && port->base_clk,);

ret->p = 0;
ret->size = 0;
Expand Down Expand Up @@ -239,10 +230,9 @@ static void sysclk_get_freq(call_arg_t a0 _UNUSED, call_arg_t a1 _UNUSED,
sysclk_port_t *port = sysclk;
istate_t ist;
unsigned int getclk;
if(!port)
return;

assert(port->baddr && port->base_clk);
ret->status = error_inval_pointer;
RET_ON_FAIL(port && port->baddr && port->base_clk,);

lock_acquire(&sysclk_key);
arch_di_save_state(&ist);
Expand Down
113 changes: 59 additions & 54 deletions src/include/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,74 +16,79 @@

typedef enum status
{
success = 0x0000,
success = 0x0000,
/* Generic error */
error_generic = -0x0001,
error_func_inval = -0x0002,
error_func_inval_arg = -0x0003,
error_overflow = -0x0004,
error_generic = 0x0001,
error_func_inval = 0x0002,
error_func_inval_arg = 0x0003,
error_overflow = 0x0004,
error_inval_pointer = 0x0005,
/* Driver related error */
error_driver = -0x0100,
error_driver_init_done = -0x0101,
error_driver_init_failed = -0x0102,
error_driver_busy = -0x0103,
error_driver_data = -0x0104,
error_driver = 0x0100,
error_driver_init_done = 0x0101,
error_driver_init_failed = 0x0102,
error_driver_busy = 0x0103,
error_driver_data = 0x0104,
/* Device related error */
error_device = -0x0200,
error_device_id_inval = -0x0201,
error_device_inval = -0x0202,
error_device_busy = -0x0203,
error_device = 0x0200,
error_device_id_inval = 0x0201,
error_device_inval = 0x0202,
error_device_busy = 0x0203,
/* Visor Call related error */
error_vcall = -0x0300,
error_vcall_code_inval = -0x0301,
error_vcall = 0x0300,
error_vcall_code_inval = 0x0301,
/* Memory related error */
error_memory = -0x0600,
error_memory_low = -0x0601,
error_memory = 0x0600,
error_memory_low = 0x0601,
/* File related error */
error_file = -0x0700,
error_file_desc = -0x0701,
error_file_exist = -0x0702,
error_file_not_found = -0x0703,
error_file_no_space = -0x0704,
error_file_long_name = -0x0705,
error_file_io = -0x0706,
error_file = 0x0700,
error_file_desc = 0x0701,
error_file_exist = 0x0702,
error_file_not_found = 0x0703,
error_file_no_space = 0x0704,
error_file_long_name = 0x0705,
error_file_io = 0x0706,
/* String related error */
error_string = -0x0800,
error_string = 0x0800,
/* Math related error */
error_math = -0x0900,
error_math_inval_arg = -0x0901,
error_math_large_val = -0x0902,
error_math = 0x0900,
error_math_inval_arg = 0x0901,
error_math_large_val = 0x0902,
/* Access related error */
error_access = -0x0a00,
error_access = 0x0a00,
/* System related error */
error_system = -0x0b00,
error_system_irq_link_fail = -0x0b01,
error_system_irq_unlink_fail = -0x0b02,
error_system_clk_caliberation = -0x0b03,
error_system_prog_fail = -0x0b04,
error_system = 0x0b00,
error_system_irq_link_fail = 0x0b01,
error_system_irq_unlink_fail = 0x0b02,
error_system_clk_caliberation = 0x0b03,
error_system_prog_fail = 0x0b04,
error_system_inval_cpu = 0x0b05,
/* Network related error */
error_net = -0x0c00,
error_net_con_timeout = -0x0c01,
error_net = 0x0c00,
error_net_con_timeout = 0x0c01,
/* User space related error */
error_user = -0x0d00,
error_user = 0x0d00,
/* IO related error */
error_io = -0x0e00,
error_io = 0x0e00,
/* OS related error */
error_os = -0x0f00,
error_os_task_overfow = -0x0f01,
error_os_deadlock = -0x0f02,
error_os_invalid_op = -0x0f03,
error_os_sem_get = -0x0f04,
error_os_panic_presched_cb_null = -0x0f05,
error_os_panic_sched_algo_null = -0x0f06,
error_os_panic_os_start_fail = -0x0f07,
error_os_mutex_lock = -0x0f08,
error_os_mutex_unlock = -0x0f09,
error_os = 0x0f00,
error_os_task_overfow = 0x0f01,
error_os_deadlock = 0x0f02,
error_os_invalid_op = 0x0f03,
error_os_sem_get = 0x0f04,
error_os_panic_presched_cb_null = 0x0f05,
error_os_panic_sched_algo_null = 0x0f06,
error_os_panic_os_start_fail = 0x0f07,
error_os_mutex_lock = 0x0f08,
error_os_mutex_unlock = 0x0f09,
/* Mesg related error */
error_mesg = -0x1000,
error_mesg_long = -0x1001,
error_mesg = 0x1000,
error_mesg_long = 0x1001,
/* List related error */
error_list = -0x1100,
error_list_node_exists = -0x1101,
error_list_node_not_found = -0x1102,
error_list = 0x1100,
error_list_node_exists = 0x1101,
error_list_node_not_found = 0x1102,
} status_t;

#define STATUS_CHECK_POINTER(x) RET_ON_FAIL(x, error_inval_pointer)
#define STATUS_CHECK_COREID(x) RET_ON_FAIL((x < N_CORES), error_system_inval_cpu)
7 changes: 7 additions & 0 deletions src/lib/libc/include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,10 @@ size_t strnlen(const char *i, size_t size);
* ret = pointer to first occurance
*/
char *strchr_rev(const char *i, int r);

/*
* Strcpy
* i = destination address
* j = source address
*/
#define strcpy(i, j) strlcpy(i, j, strlen(j));
1 change: 1 addition & 0 deletions src/lib/libc/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,4 @@ char *strchr_rev(const char *i, int r)
}
return ret;
}

Loading
Loading