Skip to content

Commit

Permalink
Merge pull request #245 from VisorFolks/feature/akashkollipara/87-rp2…
Browse files Browse the repository at this point in the history
…040-port
  • Loading branch information
akashkollipara authored Nov 22, 2023
2 parents 3aea7cf + deb4215 commit ea9b716
Show file tree
Hide file tree
Showing 88 changed files with 1,450 additions and 596 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<body>
<div align="center">
<i>An unified software platform for embedded system projects ...</i><br>
<i>From India with Pride!</i><br><br>
<i>From Bharat with Pride!</i><br><br>
</div>
</body>

Expand Down
7 changes: 4 additions & 3 deletions mk/tc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

include mk/path.mk

ifeq ($(findstring arm-v7,$(ARCH)),arm)
ifeq ($(findstring arm,$(ARCH)),arm)
TC ?= $(TOOLS_ROOT)/arm-toolchain/bin/arm-none-eabi
TI := $(TOOLS_ROOT)/arm-toolchain/arm-none-eabi/include
TL := $(TOOLS_ROOT)/arm-toolchain/arm-none-eabi/lib
TI := $(TOOLS_ROOT)/arm-toolchain/lib/gcc/arm-none-eabi/$(TC_VER)/include-fixed/
TI += $(TOOLS_ROOT)/arm-toolchain/arm-none-eabi/include/
TL := $(TOOLS_ROOT)/arm-toolchain/lib/gcc/arm-none-eabi/$(TC_VER)/$(TL_TYPE)/
endif

ifeq ($(findstring riscv,$(ARCH)),riscv)
Expand Down
6 changes: 3 additions & 3 deletions mk/tc_get.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ T_ALLOWLIST += get_all_tc get_avr_tc get_arm_tc get_riscv_tc
# GIT REPO RECOMMENDED
# Provide git repo path for toolchains for better experience
ESIZE_REPO := https://github.com/VisorFolks/cc_elf_size.git
AVR_TC_REPO ?=
RISC_V_TC_REPO ?=
ARM_TC_REPO ?=
AVR_TC_REPO ?= https://github.com/VisorFolks/avr-toolchain
RISC_V_TC_REPO ?= https://github.com/VisorFolks/risc-v-toolchain
ARM_TC_REPO ?= https://github.com/VisorFolks/arm-toolchain

get_all_tc: --tc_clear get_avr_tc get_arm_tc get_riscv_tc

Expand Down
File renamed without changes.
134 changes: 134 additions & 0 deletions src/arch/arm-m/32/common_v6_v7/supervisor/arch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2019, Cyancore Team
*
* File Name : arch.c
* Description : This file consists of architecture specific function that
* cannot be inlined. Hence, present in c file.
* Primary Author : Mayuri Lokhande [[email protected]]
* Organisation : Cyancore Core-Team
*/

#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include <status.h>
#include <syslog.h>
#include <mmio.h>
#include <arch.h>
#include <visor/workers.h>

static void arch_ecall_handler()
{
context_frame_t *frame = get_context_frame();
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;
}

/**
*arch_early_setup - This function is called in the early stages of boot
*
* @brief This function is respinsible to clean reset cpu status/control registers.
*
*/
void arch_early_setup()
{
arch_di();

}

/**
* arch_setup - This function is called after initial setup is done
*
* @brief This function is called after initial setup is done.
*/
void arch_setup()
{
return;
}

void arch_di_save_state(istate_t *sreg_i_backup)
{
*
}

void arch_ei_restore_state(istate_t *sreg_i_backup)
{

}

/**
* arch_core_index - Returns code index
*/

_WEAK unsigned int arch_core_index()
{
return 0;
}

void _NORETURN arch_panic_handler_callback()
{
context_frame_t *frame;
frame = get_context_frame();
if(!frame)
goto panic;
syslog_stdout_enable();
sysdbg("r0=%p\tr1=%p\tr2=%p\tr3=%p\tr4=%p\tr5=%p\n",
frame->r0, frame->r1, frame->r2, frame->r3, frame->r4, frame->r5);
sysdbg("r6=%p\tr7=%p\tr8=%p\tr9=%p\tr10=%p\tr11=%p\n",
frame->r6, frame->r7, frame->r8, frame->r9, frame->r10, frame->r11);
sysdbg("r12=%p\tr13=%p\tr14=%p\tr15=%p\tAPSR=%p\n",
frame->r12, frame->r13, frame->r14, frame->r15, frame->apsr);
#if DEBUG==0
syslog(info, "APSR=%p\n", frame->apsr);
#endif
panic:
while(1) arch_wfi();
}

static cpu_sleep_t sleep_flag;

/**
* arch_suspended_state_was
*
* @brief This function checks for the suspended state
* and returns true or flase based on arg.
*
* @param[in] state: suspended state
* @return bool: True/False
*/

bool arch_suspended_state_was(cpu_sleep_t state)
{
assert(state != resume);
if(!sleep_flag)
return false;
return (sleep_flag == state);
}

/**
* arch_signal_suspend
*
* @brief This function is intended to be called before cpu enters
* suspend state. By passing the state, we store and use to check while
* exiting resume routine.
*
* @param[in] state: Suspend state of cpu
*/
void arch_signal_suspend(cpu_sleep_t state)
{
sleep_flag = state;
}

/**
* @brief This function signals resume of cpu. It is intended
* to be called after exiting resume routine.
*/
void arch_signal_resume(void)
{
sleep_flag = resume;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
*/

#include <status.h>
#include <stdint.h>

extern uint8_t _start_start;
extern void _stack_start();
extern void init(void);
#define proto_irq_func(x) extern void int_##x(void)
proto_irq_func(1);
Expand All @@ -37,8 +38,8 @@ proto_irq_func(14);
* deref based on irq id and call respective handler.
*/

const void (*arch_vectors[N_IRQ+1](void)) _SECTION(".archvectors") =
[
void (*arch_vectors[N_IRQ+1])(void) _SECTION(".archvectors") =
{
&_stack_start, // Stack start value has higher address of stack
// with as assumption that stack grows towards
// lower address
Expand All @@ -58,4 +59,4 @@ const void (*arch_vectors[N_IRQ+1](void)) _SECTION(".archvectors") =
&int_12, // IRQ 12 -> N/A
&int_13, // IRQ 13 -> PendSV
&int_14, // IRQ 14 -> SysTick
];
};
53 changes: 53 additions & 0 deletions src/arch/arm-m/32/common_v6_v7/supervisor/asm.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2022-2023, Cyancore Team
*
* File Name : asm.S
* Description : This file consists of all the function written in asm
* like ISR, context management and panic handler
* Primary Author : Mayuri Lokhande [[email protected]]
* Organisation : Cyancore Core-Team
*/

#include <asm.inc>

.altmacro
.macro INT id

function int_\id
push {r0}
mov r0, #\id
b isr
.endm

/**
* isr - interrupt service routine function
* @brief This function is called from interrupt router.
* It is responsible to do context management before and after
* calling the interrupt handler function.
*/

.weak isr
function isr
push {r1-r7, lr}
mrs r1, msp
bl exception_handler
pop {r1-r7}
pop {r0}
mov lr, r0
pop {r0}
mov pc, lr

/**
* Interrupt Router Declaration Table
* 1-14 Interrupt routers are define as of now. If possible more can
* be added. But during compile time only necessary interrupt router
* functions will be retained and others are cleaned up.
*/
/*==========< Interrupt router functions >==========*/
.set i, 1
.rept 14
INT %i
.set i, i+1
.endr

16 changes: 16 additions & 0 deletions src/arch/arm-m/32/common_v6_v7/supervisor/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2023, Cyancore Team
#
# File Name : build.mk
# Description : Build script for this directory.
# Primary Authod : Akash Kollipara [[email protected]]
# Organisation : Cyancore Core-Team
#

ARM32_M_S_ARCH_DIR := $(GET_PATH)

$(eval $(call add_include,$(ARM32_M_S_ARCH_DIR)/include/))

DIR := $(ARM32_M_S_ARCH_DIR)
include mk/obj.mk
109 changes: 109 additions & 0 deletions src/arch/arm-m/32/common_v6_v7/supervisor/exception_handler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2019, Cyancore Team
*
* File Name : interrupt_handler.c
* Description : This file consists of arch interrupt handler sources.
* Primary Author : Mayuri Lokhande [[email protected]]
* Organisation : Cyancore Core-Team
*/

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <status.h>
#include <string.h>
#include <assert.h>
#include <arch.h>
#include <assert.h>

static context_frame_t *local_frame;

static void set_context_frame(*frame)
{
local_frame = frame;
}

bool in_isr(void)
{
return (local_frame != NULL) ? true : false ;
}

/**
* int_handler - Array of Interrupt handler pointers
*
* @brief This is a function pointer array which consists of addresses of corresponding
* interrupt handler functions. This is by default assigned as arch_panic_handler.
*/
static void (* exhandler[N_EXCEP])(void) = {{[0 ... N_EXCEP-1] = arch_panic_handler}};

/**
* arch_register_interrupt_handlers - Registers arch interrupt handlers
* @brief This function is responsible to registers all architectural level
* Interrupt handling functions.
*
* @param[in] id: Interrupt ID
* @param[in] *handler - function pointer of interrupt handling function.
*/

void arch_register_interrupt_handler(unsigned int id, void(* handler)(void))
{
/*Check if Interrupt ID is valid*/
assert((id > 0) && (id <= N_EXCEP));

/*
* Decrement ID as array indexing starts from 0.
* ID = 0 is CPU entry address.
*/
id --;

/*Store interrupt handler*/
exhandler[id] = handler;
}

/**
* Exception handler - Executes Interrupt handler corresponding to int ID
*
* @brief This function is called by ISR. It executes function pointed by int_handler.
* It accepts int ID as argument, which indexes the interrupt handling function.
*
* @param[in] id: Interrupt ID
*/

void exception_handler(unsigned int id, context_frame_t *frame)
{
set_context_frame(frame);

/*Check if Interrupt ID is valid*/
if((id > 0) && (id <= N_EXCEP))
{
/*
* Decrement ID as array indexing starts from 0.
* ID = 0 is CPU entry address.
*/
id --;

/* Get corresponding interrupt handling function */
void (*handler)(void) = exhandler[id]

/* Check if the handler is valid*/
assert(handler)

/* Execute exception handler */
handler();
}
else if(id == 65535)
plat_panic_handler_callback();
else if(id == 65536)
arch_panic_handler_callback();
else{}
set_context_frame(NULL);
return;
}

context_frame_t *get_context_frame()
{
if(local_frame)
return local_frame;
return NULL;
}
Loading

0 comments on commit ea9b716

Please sign in to comment.