forked from xuos/xiuos
Support XiZi_AIoT
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
|
||||
SRC_FILES := default_irq_handler.c \
|
||||
clock_irq_handler.c \
|
||||
software_irq_handler.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
/**
|
||||
* @file clock_irq_handler.c
|
||||
* @brief clock interrupt handler
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: clock_irq_handler.c
|
||||
Description: clock interrupt handler
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#include "clock_common_op.h"
|
||||
|
||||
#include "actracer.h"
|
||||
#include "assert.h"
|
||||
#include "multicores.h"
|
||||
#include "task.h"
|
||||
|
||||
static struct TraceTag clock_driver_tag;
|
||||
static struct XiziClockDriver* p_clock_driver = NULL;
|
||||
|
||||
bool clock_intr_handler_init(struct TraceTag* p_clock_driver_tag)
|
||||
{
|
||||
clock_driver_tag = *p_clock_driver_tag;
|
||||
p_clock_driver = AchieveResource(p_clock_driver_tag);
|
||||
return p_clock_driver != NULL;
|
||||
}
|
||||
|
||||
uint64_t global_tick = 0;
|
||||
int xizi_clock_handler(int irq, void* tf, void* arg)
|
||||
{
|
||||
/* handle clock interrupt using driver */
|
||||
p_clock_driver->clear_clock_intr();
|
||||
global_tick++;
|
||||
struct TaskMicroDescriptor* current_task = cur_cpu()->task;
|
||||
if (current_task) {
|
||||
current_task->remain_tick--;
|
||||
current_task->maxium_tick--;
|
||||
if (current_task->remain_tick == 0) {
|
||||
xizi_task_manager.cur_task_yield_noschedule();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
/**
|
||||
* @file default_irq_handler.c
|
||||
* @brief irq distributor
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: default_irq_handler.c
|
||||
Description: irq distributor
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#include <stddef.h>
|
||||
|
||||
#include "core.h"
|
||||
#include "trap_common.h"
|
||||
|
||||
#include "assert.h"
|
||||
#include "log.h"
|
||||
#include "multicores.h"
|
||||
#include "task.h"
|
||||
|
||||
static struct IrqDispatcherRightGroup right_group;
|
||||
static struct XiziTrapDriver* p_intr_driver = NULL;
|
||||
bool intr_distributer_init(struct IrqDispatcherRightGroup* _right_group)
|
||||
{
|
||||
right_group = *_right_group;
|
||||
p_intr_driver = AchieveResource(&_right_group->intr_driver_tag);
|
||||
return p_intr_driver != NULL;
|
||||
}
|
||||
|
||||
void default_interrupt_routine(void)
|
||||
{
|
||||
/* default handler borrow the rights of dispatcher */
|
||||
///@todo Support other cores. (currently assume that CPU_0 is used)
|
||||
ERROR("Interrupt %d has been asserted\n", p_intr_driver->curr_int[0]);
|
||||
}
|
||||
|
||||
extern void context_switch(struct context**, struct context*);
|
||||
void intr_irq_dispatch(struct trapframe* tf)
|
||||
{
|
||||
assert(p_intr_driver != NULL);
|
||||
|
||||
p_intr_driver->cpu_irq_disable();
|
||||
// enter irq
|
||||
uint32_t int_info = 0;
|
||||
if ((int_info = p_intr_driver->hw_before_irq()) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct TaskMicroDescriptor* current_task = cur_cpu()->task;
|
||||
if (LIKELY(current_task != NULL)) {
|
||||
current_task->main_thread.trapframe = tf;
|
||||
}
|
||||
|
||||
unsigned cpu = p_intr_driver->hw_cur_int_cpu(int_info);
|
||||
unsigned irq = p_intr_driver->hw_cur_int_num(int_info);
|
||||
p_intr_driver->curr_int[cpu] = irq;
|
||||
|
||||
// distribute irq
|
||||
irq_handler_t isr = p_intr_driver->sw_irqtbl[irq].handler;
|
||||
if (isr) {
|
||||
isr(irq, tf, NULL);
|
||||
} else {
|
||||
default_interrupt_routine();
|
||||
}
|
||||
|
||||
// finish irq.
|
||||
p_intr_driver->curr_int[cpu] = 0;
|
||||
p_intr_driver->hw_after_irq(int_info);
|
||||
|
||||
if (UNLIKELY(cur_cpu()->task == NULL && current_task != NULL)) {
|
||||
context_switch(¤t_task->main_thread.context, cur_cpu()->scheduler);
|
||||
}
|
||||
assert(current_task == cur_cpu()->task);
|
||||
|
||||
p_intr_driver->cpu_irq_enable();
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
/**
|
||||
* @file software_irq_handler.c
|
||||
* @brief syscall distributor
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: software_irq_handler.c
|
||||
Description: syscall distributor
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#include "core.h"
|
||||
#include "trap_common.h"
|
||||
|
||||
#include "assert.h"
|
||||
#include "multicores.h"
|
||||
#include "syscall.h"
|
||||
#include "task.h"
|
||||
|
||||
static struct SwiDispatcherRightGroup right_group;
|
||||
static struct XiziTrapDriver* p_intr_driver = NULL;
|
||||
|
||||
bool swi_distributer_init(struct SwiDispatcherRightGroup* _right_group)
|
||||
{
|
||||
right_group = *_right_group;
|
||||
p_intr_driver = AchieveResource(&_right_group->intr_driver_tag);
|
||||
return p_intr_driver != NULL;
|
||||
}
|
||||
|
||||
extern void context_switch(struct context**, struct context*);
|
||||
void software_irq_dispatch(struct trapframe* tf)
|
||||
{
|
||||
assert(p_intr_driver != NULL);
|
||||
|
||||
p_intr_driver->cpu_irq_disable();
|
||||
// get current task
|
||||
struct TaskMicroDescriptor* cur_task = cur_cpu()->task;
|
||||
/// @todo: Handle dead task
|
||||
|
||||
int syscall_num = -1;
|
||||
if (cur_task && cur_task->state != DEAD) {
|
||||
cur_task->main_thread.trapframe = tf;
|
||||
// call syscall
|
||||
int ret = arch_syscall(cur_task->main_thread.trapframe, &syscall_num);
|
||||
|
||||
if (syscall_num != SYSCALL_EXEC) {
|
||||
arch_set_return(tf, ret);
|
||||
}
|
||||
} else {
|
||||
ERROR("syscall by killed task.\n");
|
||||
}
|
||||
|
||||
if (cur_cpu()->task == NULL && cur_task != NULL) {
|
||||
context_switch(&cur_task->main_thread.context, cur_cpu()->scheduler);
|
||||
}
|
||||
assert(cur_task == cur_cpu()->task);
|
||||
if (syscall_num == SYSCALL_EXIT) {
|
||||
ERROR("Exit reaches");
|
||||
}
|
||||
p_intr_driver->cpu_irq_enable();
|
||||
}
|
||||
Reference in New Issue
Block a user