完善了irq & shell能够启动起来
This commit is contained in:
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
@@ -46,9 +46,9 @@
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
// "miDebuggerPath": "/opt/homebrew/bin/arm-none-eabi-gdb",
|
||||
// "miDebuggerPath": "/home/zhangzheng/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gdb",
|
||||
"miDebuggerPath": "/home/mkrtos-smart/toolchains/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/aarch64-none-elf-gdb",
|
||||
"miDebuggerServerAddress": "127.0.0.1:33333",
|
||||
"miDebuggerPath": "/home/zhangzheng/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gdb",
|
||||
// "miDebuggerPath": "/home/mkrtos-smart/toolchains/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/aarch64-none-elf-gdb",
|
||||
"miDebuggerServerAddress": "127.0.0.1:3333",
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
|
||||
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -64,7 +64,10 @@
|
||||
"u_vmam.h": "c",
|
||||
"u_arch_hard.h": "c",
|
||||
"arm_gicv2.h": "c",
|
||||
"sche_arch.h": "c"
|
||||
"sche_arch.h": "c",
|
||||
"irq_sender.h": "c",
|
||||
"timer.h": "c",
|
||||
"arm_local_reg.h": "c"
|
||||
},
|
||||
"cortex-debug.showRTOS": false,
|
||||
"cortex-debug.variableUseNaturalFormat": false,
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "mk_sys.h"
|
||||
#include <psci.h>
|
||||
#include <arm_gicv2.h>
|
||||
#include <timer/timer.h>
|
||||
#include <timer.h>
|
||||
#include <hyp.h>
|
||||
#include <sche_arch.h>
|
||||
__ALIGN__(THREAD_BLOCK_SIZE)
|
||||
@@ -29,7 +29,8 @@ void *_estack = thread_knl_stack + THREAD_BLOCK_SIZE;
|
||||
*/
|
||||
void to_sche(void)
|
||||
{
|
||||
sche_arch_sw_context();
|
||||
gic2_set_pending(arm_gicv2_get_global(), SYSTICK_INTR_NO);
|
||||
// sche_arch_sw_context();
|
||||
}
|
||||
/**
|
||||
* 进行一些系统的初始化
|
||||
@@ -108,6 +109,6 @@ void arch_init(void)
|
||||
print_mem();
|
||||
psci_init();
|
||||
gic_init(arm_gicv2_get_global(),
|
||||
0x08000000, 0x08010000); /*TODO:*/
|
||||
0x08000000, 0x8010000); /*TODO:*/
|
||||
}
|
||||
INIT_LOW_HARD(arch_init);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
#define ARCH_WORD_SIZE 64
|
||||
#define SYSTICK_INTR_NO 30
|
||||
#define LOG_INTR_NO 37 // USART1_IRQn
|
||||
#define LOG_INTR_NO 33
|
||||
|
||||
/// @brief 线程信息
|
||||
typedef struct
|
||||
|
||||
@@ -190,7 +190,6 @@ el1_irq:
|
||||
el2_irq:
|
||||
kernel_entry 2
|
||||
bl entry_handler
|
||||
bl SysTick_Handler
|
||||
kernel_exit 2
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
* ID1024-ID8191,reserved
|
||||
* 8192及其以上,LPI
|
||||
*/
|
||||
typedef struct gic {
|
||||
typedef struct gic
|
||||
{
|
||||
uint16_t irqs_number; //!< 支持的irq数量
|
||||
|
||||
addr_t disp_base_addr; //!< 分发器起始地址
|
||||
@@ -24,33 +25,33 @@ typedef struct gic {
|
||||
// #define GIC2_BASE (0xFF840000)
|
||||
// #define GIC2_GICD_BASE (GIC2_BASE + 0x1000)
|
||||
|
||||
#define GICD_CTLR(GIC2_GICD_BASE) (0x0 + GIC2_GICD_BASE)
|
||||
#define GICD_TYPER(GIC2_GICD_BASE) (0x4 + GIC2_GICD_BASE)
|
||||
#define GICD_IIDR(GIC2_GICD_BASE) (0x8 + GIC2_GICD_BASE)
|
||||
#define GICD_IGROUPRn(GIC2_GICD_BASE) (0x80 + GIC2_GICD_BASE)
|
||||
#define GICD_ISENABLERn(GIC2_GICD_BASE) (0x100 + GIC2_GICD_BASE)
|
||||
#define GICD_ICENABLERn(GIC2_GICD_BASE) (0x180 + GIC2_GICD_BASE)
|
||||
#define GICD_ISPENDRn(GIC2_GICD_BASE) (0x200 + GIC2_GICD_BASE)
|
||||
#define GICD_ICPENDRn(GIC2_GICD_BASE) (0x280 + GIC2_GICD_BASE)
|
||||
#define GICD_ISACTIVERn(GIC2_GICD_BASE) (0x300 + GIC2_GICD_BASE)
|
||||
#define GICD_ICACTIVERn(GIC2_GICD_BASE) (0x380 + GIC2_GICD_BASE)
|
||||
#define GICD_CTLR(GIC2_GICD_BASE) (0x0 + GIC2_GICD_BASE)
|
||||
#define GICD_TYPER(GIC2_GICD_BASE) (0x4 + GIC2_GICD_BASE)
|
||||
#define GICD_IIDR(GIC2_GICD_BASE) (0x8 + GIC2_GICD_BASE)
|
||||
#define GICD_IGROUPRn(GIC2_GICD_BASE) (0x80 + GIC2_GICD_BASE)
|
||||
#define GICD_ISENABLERn(GIC2_GICD_BASE) (0x100 + GIC2_GICD_BASE)
|
||||
#define GICD_ICENABLERn(GIC2_GICD_BASE) (0x180 + GIC2_GICD_BASE)
|
||||
#define GICD_ISPENDRn(GIC2_GICD_BASE) (0x200 + GIC2_GICD_BASE)
|
||||
#define GICD_ICPENDRn(GIC2_GICD_BASE) (0x280 + GIC2_GICD_BASE)
|
||||
#define GICD_ISACTIVERn(GIC2_GICD_BASE) (0x300 + GIC2_GICD_BASE)
|
||||
#define GICD_ICACTIVERn(GIC2_GICD_BASE) (0x380 + GIC2_GICD_BASE)
|
||||
#define GICD_IPRIORITYRn(GIC2_GICD_BASE) (0x400 + GIC2_GICD_BASE)
|
||||
#define GICD_ITARGETSRn(GIC2_GICD_BASE) (0x800 + GIC2_GICD_BASE)
|
||||
#define GICD_ICFGRn(GIC2_GICD_BASE) (0xC00 + GIC2_GICD_BASE)
|
||||
#define GICD_SGIR(GIC2_GICD_BASE) (0xf00 + GIC2_GICD_BASE)
|
||||
#define GICD_CPENDSGIRn(GIC2_GICD_BASE) (0xf10 + GIC2_GICD_BASE)
|
||||
#define GICD_SPENDSGIRn(GIC2_GICD_BASE) (0xf20 + GIC2_GICD_BASE)
|
||||
#define GICD_ITARGETSRn(GIC2_GICD_BASE) (0x800 + GIC2_GICD_BASE)
|
||||
#define GICD_ICFGRn(GIC2_GICD_BASE) (0xC00 + GIC2_GICD_BASE)
|
||||
#define GICD_SGIR(GIC2_GICD_BASE) (0xf00 + GIC2_GICD_BASE)
|
||||
#define GICD_CPENDSGIRn(GIC2_GICD_BASE) (0xf10 + GIC2_GICD_BASE)
|
||||
#define GICD_SPENDSGIRn(GIC2_GICD_BASE) (0xf20 + GIC2_GICD_BASE)
|
||||
|
||||
// #define (GIC2_GICC_BASE) (GIC2_BASE + 0x2000)
|
||||
#define GICC_CTLR(GIC2_GICC_BASE) (0x0 + GIC2_GICC_BASE)
|
||||
#define GICC_PMR(GIC2_GICC_BASE) (0x4 + GIC2_GICC_BASE)
|
||||
#define GICC_BPR(GIC2_GICC_BASE) (0x8 + GIC2_GICC_BASE)
|
||||
#define GICC_IAR(GIC2_GICC_BASE) (0xc + GIC2_GICC_BASE)
|
||||
#define GICC_EOIR(GIC2_GICC_BASE) (0x10 + GIC2_GICC_BASE)
|
||||
#define GICC_RPR(GIC2_GICC_BASE) (0x14 + GIC2_GICC_BASE)
|
||||
#define GICC_CTLR(GIC2_GICC_BASE) (0x0 + GIC2_GICC_BASE)
|
||||
#define GICC_PMR(GIC2_GICC_BASE) (0x4 + GIC2_GICC_BASE)
|
||||
#define GICC_BPR(GIC2_GICC_BASE) (0x8 + GIC2_GICC_BASE)
|
||||
#define GICC_IAR(GIC2_GICC_BASE) (0xc + GIC2_GICC_BASE)
|
||||
#define GICC_EOIR(GIC2_GICC_BASE) (0x10 + GIC2_GICC_BASE)
|
||||
#define GICC_RPR(GIC2_GICC_BASE) (0x14 + GIC2_GICC_BASE)
|
||||
#define GICC_HPPIR(GIC2_GICC_BASE) (0x18 + GIC2_GICC_BASE)
|
||||
#define GICC_APRn(GIC2_GICC_BASE) (0xd0 + GIC2_GICC_BASE)
|
||||
#define GICC_IIDR(GIC2_GICC_BASE) (0x00FC + GIC2_GICC_BASE)
|
||||
#define GICC_APRn(GIC2_GICC_BASE) (0xd0 + GIC2_GICC_BASE)
|
||||
#define GICC_IIDR(GIC2_GICC_BASE) (0x00FC + GIC2_GICC_BASE)
|
||||
|
||||
#define MAX_INTR_NO 1020
|
||||
|
||||
@@ -226,12 +227,14 @@ static inline void gic_dist_init(gic_t *irq)
|
||||
{
|
||||
gic_disable(irq);
|
||||
|
||||
for (int i = 32; i < irq->irqs_number; i++) {
|
||||
for (int i = 32; i < irq->irqs_number; i++)
|
||||
{
|
||||
gic2_set_unmask(irq, i);
|
||||
gic2_set_edge_mode(irq, i, 0);
|
||||
gic2_clear_active(irq, i);
|
||||
}
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
gic2_set_unmask(irq, i);
|
||||
}
|
||||
|
||||
@@ -240,7 +243,8 @@ static inline void gic_dist_init(gic_t *irq)
|
||||
static inline void gic_inter_init(gic_t *irq)
|
||||
{
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
gic2_set_prio(irq, i, 0xa0);
|
||||
}
|
||||
|
||||
@@ -254,7 +258,8 @@ static inline void gic2_eoi_irq(gic_t *irq, int inx)
|
||||
static inline void gic_init(gic_t *irq, addr_t disp_addr, addr_t inter_addr)
|
||||
{
|
||||
irq->irqs_number = ((read_reg32(GICD_TYPER(disp_addr)) & 0x1ful) + 1) * 32;
|
||||
if (irq->irqs_number > MAX_INTR_NO) {
|
||||
if (irq->irqs_number > MAX_INTR_NO)
|
||||
{
|
||||
irq->irqs_number = MAX_INTR_NO;
|
||||
}
|
||||
irq->disp_base_addr = disp_addr;
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
#include <asm/arm_local_reg.h>
|
||||
#include <asm/timer.h>
|
||||
#include <arm_gicv2.h>
|
||||
|
||||
#define GENERIC_TIMER_IRQ 30
|
||||
#include <irq.h>
|
||||
#include <assert.h>
|
||||
#include "timer.h"
|
||||
#define GENERIC_TIMER_IRQ SYSTICK_INTR_NO
|
||||
|
||||
static unsigned int arch_timer_rate;
|
||||
|
||||
@@ -61,9 +63,10 @@ static void enable_timer_interrupt(int inx)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void timer_init(int cpu)
|
||||
{
|
||||
assert(irq_alloc(GENERIC_TIMER_IRQ, NULL, systick_handler));
|
||||
|
||||
arch_timer_rate = generic_timer_get_freq();
|
||||
arch_timer_rate /= CONFIG_SYS_SCHE_HZ;
|
||||
|
||||
@@ -74,10 +77,6 @@ void timer_init(int cpu)
|
||||
gic2_set_target_cpu(arm_gicv2_get_global(), GENERIC_TIMER_IRQ, 1 << cpu);
|
||||
printk("cpu:%d timer dis:0x%x\n", arch_get_current_cpu_id(),
|
||||
gic2_get_target_cpu(arm_gicv2_get_global(), GENERIC_TIMER_IRQ));
|
||||
|
||||
// enable_timer_interrupt(cpu);
|
||||
// write_sysreg(0x3UL, cntkctl_el1);
|
||||
// write_sysreg(0x1UL, cnthctl_el2);
|
||||
}
|
||||
void handle_timer_irq(void)
|
||||
{
|
||||
@@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <irq.h>
|
||||
void timer_init(int cpu);
|
||||
void handle_timer_irq(void);
|
||||
|
||||
extern void systick_handler(irq_entry_t *irq);
|
||||
@@ -2,22 +2,27 @@
|
||||
#include "arch.h"
|
||||
#include "thread.h"
|
||||
#include "futex.h"
|
||||
#include <asm/arm_local_reg.h>
|
||||
#include <arm_gicv2.h>
|
||||
#include <sche_arch.h>
|
||||
#include <timer.h>
|
||||
static umword_t sys_tick_cnt;
|
||||
|
||||
umword_t sys_tick_cnt_get(void)
|
||||
{
|
||||
return sys_tick_cnt;
|
||||
}
|
||||
#include <asm/arm_local_reg.h>
|
||||
#include <arm_gicv2.h>
|
||||
extern void handle_timer_irq(void);
|
||||
void SysTick_Handler(void)
|
||||
|
||||
void systick_handler(irq_entry_t *irq)
|
||||
{
|
||||
handle_timer_irq(); // TODO:定时器的处理应该被分流,这里处理还有点问题,而且最好采用通用定时器
|
||||
gic2_eoi_irq(arm_gicv2_get_global(), arch_get_isr_no());
|
||||
handle_timer_irq();
|
||||
gic2_eoi_irq(arm_gicv2_get_global(), SYSTICK_INTR_NO);
|
||||
// 进行上下文切换
|
||||
sys_tick_cnt++;
|
||||
thread_timeout_check(1);
|
||||
futex_timeout_times_tick();
|
||||
thread_sched();
|
||||
if (thread_sched(FALSE))
|
||||
{
|
||||
sche_arch_sw_context();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "init.h"
|
||||
#include "queue.h"
|
||||
#include <irq.h>
|
||||
#include <arm_gicv2.h>
|
||||
|
||||
#define UART01x_DR 0x00 /* Data read or written from the interface. */
|
||||
#define UART01x_RSR 0x04 /* Receive status register (Read). */
|
||||
@@ -129,8 +130,25 @@ static queue_t queue;
|
||||
static uint8_t queue_data[QUEUE_LEN];
|
||||
void uart_tigger(irq_entry_t *irq)
|
||||
{
|
||||
// q_enqueue(&queue, USART_ReceiveData(USART1));
|
||||
/*TODO:*/
|
||||
int ch;
|
||||
|
||||
ch = read_reg32(UART011_BASE_ADDR + UART01x_DR);
|
||||
if (ch & 0x0f00)
|
||||
{
|
||||
write_reg32(UART011_BASE_ADDR + UART01x_ECR, 0);
|
||||
goto end;
|
||||
}
|
||||
ch &= 0xff;
|
||||
q_enqueue(&queue, ch);
|
||||
mword_t status = cpulock_lock();
|
||||
|
||||
if (irq->irq->wait_thread && thread_get_status(irq->irq->wait_thread) == THREAD_SUSPEND)
|
||||
{
|
||||
thread_ready(irq->irq->wait_thread, TRUE);
|
||||
}
|
||||
cpulock_set(status);
|
||||
end:
|
||||
gic2_eoi_irq(arm_gicv2_get_global(), LOG_INTR_NO);
|
||||
}
|
||||
|
||||
void uart_init(void)
|
||||
@@ -153,10 +171,18 @@ void uart_init(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
unsigned long mask = UART011_RXIM | UART011_RTIM;
|
||||
|
||||
write_reg32(UART011_BASE_ADDR + UART011_ICR, 0xffff & ~mask);
|
||||
write_reg32(UART011_BASE_ADDR + UART01x_ECR, 0xff);
|
||||
write_reg32(UART011_BASE_ADDR + UART011_IMSC, read_reg32(UART011_BASE_ADDR + UART011_IMSC) | mask);
|
||||
// write_reg32(UART011_BASE_ADDR + UART011 IMSC, read_reg32(UART011_BASE_ADDR + UART011_IMSC) & ~mask);
|
||||
|
||||
gic2_set_unmask(arm_gicv2_get_global(), LOG_INTR_NO);
|
||||
gic2_set_target_cpu(arm_gicv2_get_global(), LOG_INTR_NO, 1 << arch_get_current_cpu_id());
|
||||
}
|
||||
INIT_HIGH_HAD(uart_init);
|
||||
|
||||
|
||||
void uart_set(uart_t *uart)
|
||||
{
|
||||
uart_set_baud(uart->baud);
|
||||
|
||||
@@ -12,7 +12,7 @@ umword_t sys_tick_cnt_get(void)
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
// 进行上下文切换
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
sys_tick_cnt++;
|
||||
thread_timeout_check(1);
|
||||
futex_timeout_times_tick();
|
||||
|
||||
@@ -12,7 +12,7 @@ umword_t sys_tick_cnt_get(void)
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
// 进行上下文切换
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
sys_tick_cnt++;
|
||||
thread_timeout_check(1);
|
||||
futex_timeout_times_tick();
|
||||
|
||||
@@ -12,7 +12,7 @@ umword_t sys_tick_cnt_get(void)
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
// 进行上下文切换
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
sys_tick_cnt++;
|
||||
thread_timeout_check(1);
|
||||
futex_timeout_times_tick();
|
||||
|
||||
@@ -12,7 +12,7 @@ umword_t sys_tick_cnt_get(void)
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
// 进行上下文切换
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
sys_tick_cnt++;
|
||||
thread_timeout_check(1);
|
||||
futex_timeout_times_tick();
|
||||
|
||||
@@ -123,7 +123,7 @@ typedef struct thread
|
||||
umword_t magic; //!< maigc
|
||||
} thread_t;
|
||||
|
||||
static inline void thread_set_msg_bug(thread_t *th, void *msg, void *umsg)
|
||||
static inline void thread_set_msg_buf(thread_t *th, void *msg, void *umsg)
|
||||
{
|
||||
th->msg.msg = msg;
|
||||
th->msg.umsg = umsg;
|
||||
@@ -168,7 +168,7 @@ void thread_bind(thread_t *th, kobject_t *tk);
|
||||
void thread_unbind(thread_t *th);
|
||||
|
||||
void thread_send_wait(thread_t *th);
|
||||
void thread_sched(void);
|
||||
bool_t thread_sched(bool_t is_sche);
|
||||
void thread_suspend(thread_t *th);
|
||||
void thread_dead(thread_t *th);
|
||||
void thread_todead(thread_t *th, bool_t is_sche);
|
||||
|
||||
@@ -90,7 +90,10 @@ void entry_handler(void)
|
||||
isr_no -= CONFIG_USER_ISR_START_NO; //!< 系统用的irq偏移
|
||||
|
||||
assert(isr_no < CONFIG_IRQ_REG_TAB_SIZE);
|
||||
// printk("%d.\n", isr_no);
|
||||
// if (isr_no != 30)
|
||||
// {
|
||||
// printk("%d.\n", isr_no);
|
||||
// }
|
||||
if (!irq_check_usability(isr_no))
|
||||
{
|
||||
if (irqs[isr_no].irq_tigger_func)
|
||||
|
||||
@@ -386,7 +386,8 @@ static void task_release_stage2(kobject_t *kobj)
|
||||
#endif
|
||||
// if (cur_tk == tk)
|
||||
// {
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
to_sche();
|
||||
// }
|
||||
// mm_trace();
|
||||
printk("release tk %x\n", tk);
|
||||
@@ -397,7 +398,8 @@ void task_kill(task_t *tk)
|
||||
kobj_del_list_init(&kobj_list);
|
||||
obj_unmap(&tk->obj_space, vpage_create3(KOBJ_DELETE_RIGHT, 0, TASK_PROT), &kobj_list);
|
||||
kobj_del_list_to_do(&kobj_list);
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
to_sche();
|
||||
}
|
||||
task_t *task_create(ram_limit_t *lim, int is_knl)
|
||||
{
|
||||
|
||||
@@ -187,7 +187,7 @@ static void thread_release_stage2(kobject_t *kobj)
|
||||
if (cur_th == th)
|
||||
{
|
||||
scheduler_reset();
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
}
|
||||
#if IS_ENABLED(CONFIG_BUDDY_SLAB)
|
||||
mm_limit_free_buddy(th->lim, kobj, THREAD_BLOCK_SIZE);
|
||||
@@ -249,7 +249,7 @@ void thread_suspend(thread_t *th)
|
||||
// }
|
||||
scheduler_del(&th->sche);
|
||||
th->status = THREAD_SUSPEND;
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
}
|
||||
/**
|
||||
* @brief 线程死亡
|
||||
@@ -264,7 +264,7 @@ void thread_dead(thread_t *th)
|
||||
}
|
||||
scheduler_del(&th->sche);
|
||||
th->status = THREAD_DEAD;
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,7 +272,7 @@ void thread_dead(thread_t *th)
|
||||
*
|
||||
* @param th
|
||||
*/
|
||||
void thread_sched(void)
|
||||
bool_t thread_sched(bool_t is_sche)
|
||||
{
|
||||
umword_t status = cpulock_lock();
|
||||
sched_t *next_sche = scheduler_next();
|
||||
@@ -283,10 +283,14 @@ void thread_sched(void)
|
||||
{
|
||||
cpulock_set(status);
|
||||
|
||||
return;
|
||||
return FALSE;
|
||||
}
|
||||
if (is_sche)
|
||||
{
|
||||
to_sche();
|
||||
}
|
||||
to_sche();
|
||||
cpulock_set(status);
|
||||
return TRUE;
|
||||
}
|
||||
/**
|
||||
* @brief 线程进入就绪态
|
||||
@@ -305,7 +309,7 @@ void thread_ready(thread_t *th, bool_t is_sche)
|
||||
th->status = THREAD_READY;
|
||||
if (is_sche)
|
||||
{
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
}
|
||||
cpulock_set(status);
|
||||
}
|
||||
@@ -319,7 +323,7 @@ void thread_todead(thread_t *th, bool_t is_sche)
|
||||
th->status = THREAD_TODEAD;
|
||||
if (is_sche)
|
||||
{
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -590,7 +594,7 @@ static int thread_ipc_reply(msg_tag_t in_tag)
|
||||
return ret;
|
||||
}
|
||||
|
||||
__attribute__((optimize(1))) int thread_ipc_call(thread_t *to_th, msg_tag_t in_tag, msg_tag_t *ret_tag,
|
||||
__attribute__((optimize(0))) int thread_ipc_call(thread_t *to_th, msg_tag_t in_tag, msg_tag_t *ret_tag,
|
||||
ipc_timeout_t timout, umword_t *ret_user_id, bool_t is_call)
|
||||
{
|
||||
int ret = -EINVAL;
|
||||
@@ -643,6 +647,7 @@ again_check:
|
||||
//!< 拷贝失败
|
||||
goto end;
|
||||
}
|
||||
thread_ready(recv_kobj, TRUE); //!< 直接唤醒接受者
|
||||
|
||||
if (is_call)
|
||||
{
|
||||
@@ -667,7 +672,6 @@ again_check:
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
thread_ready(recv_kobj, TRUE); //!< 直接唤醒接受者
|
||||
preemption();
|
||||
}
|
||||
ret = 0;
|
||||
@@ -770,7 +774,7 @@ static void thread_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_t
|
||||
|
||||
if (f->regs[4]) //!< cp_stack
|
||||
{
|
||||
stack_bottom = (umword_t)(cur_th->msg.msg);
|
||||
stack_bottom = (umword_t)(thread_get_msg_buf(cur_th));
|
||||
}
|
||||
thread_set_exc_regs(tag_th, f->regs[1], f->regs[2], f->regs[3], stack_bottom);
|
||||
tag = msg_tag_init4(0, 0, 0, 0);
|
||||
@@ -778,9 +782,10 @@ static void thread_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_t
|
||||
break;
|
||||
case MSG_BUG_SET:
|
||||
{
|
||||
if (is_rw_access(thread_get_bind_task(tag_th), (void *)(f->regs[1]), THREAD_MSG_BUG_LEN, FALSE))
|
||||
task_t *tag_tk = thread_get_bind_task(tag_th);
|
||||
if (is_rw_access(tag_tk, (void *)(f->regs[1]), THREAD_MSG_BUG_LEN, FALSE))
|
||||
{
|
||||
thread_set_msg_buf(tag_th, (void *)mm_get_paddr(mm_space_get_pdir(&task->mm_space), f->regs[1], PAGE_SHIFT),
|
||||
thread_set_msg_buf(tag_th, (void *)mm_get_paddr(mm_space_get_pdir(&tag_tk->mm_space), f->regs[1], PAGE_SHIFT),
|
||||
(void *)(f->regs[1]));
|
||||
tag = msg_tag_init4(0, 0, 0, 0);
|
||||
}
|
||||
@@ -849,7 +854,7 @@ static void thread_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_t
|
||||
break;
|
||||
case YIELD:
|
||||
{
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
tag = msg_tag_init4(0, 0, 0, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -101,7 +101,7 @@ static void knl_init_1(void)
|
||||
task_knl_init(&knl_task);
|
||||
thread_knl_pf_set(knl_thread, knl_main);
|
||||
thread_bind(knl_thread, &knl_task.kobj);
|
||||
thread_set_msg_bug(knl_thread, knl_msg_buf, knl_msg_buf);
|
||||
thread_set_msg_buf(knl_thread, knl_msg_buf, knl_msg_buf);
|
||||
thread_ready(knl_thread, FALSE);
|
||||
|
||||
slist_init(&del_task_head);
|
||||
@@ -146,7 +146,7 @@ static void knl_init_2(void)
|
||||
assert(task_vma_alloc(&init_task->mm_space.mem_vma,
|
||||
vma_addr_create(VPAGE_PROT_RO, VMA_ADDR_RESV, CONFIG_BOOT_FS_VADDR),
|
||||
cpio_get_size(cpio_images), (paddr_t)cpio_images, 0) >= 0);
|
||||
thread_set_msg_bug(init_thread, (void *)init_msg_buf, (void *)CONFIG_MSG_BUF_VADDR);
|
||||
thread_set_msg_buf(init_thread, (void *)init_msg_buf, (void *)CONFIG_MSG_BUF_VADDR);
|
||||
thread_user_pf_set(init_thread, (void *)(entry), (void *)0xdeaddead,
|
||||
NULL, 0);
|
||||
#else
|
||||
@@ -156,7 +156,7 @@ static void knl_init_2(void)
|
||||
void *sp_addr = (char *)init_task->mm_space.mm_block + app->i.stack_offset - app->i.data_offset;
|
||||
void *sp_addr_top = (char *)sp_addr + app->i.stack_size;
|
||||
|
||||
thread_set_msg_bug(init_thread, (char *)(init_task->mm_space.mm_block) + app->i.ram_size, (char *)(init_task->mm_space.mm_block) + app->i.ram_size);
|
||||
thread_set_msg_buf(init_thread, (char *)(init_task->mm_space.mm_block) + app->i.ram_size, (char *)(init_task->mm_space.mm_block) + app->i.ram_size);
|
||||
thread_user_pf_set(init_thread, (void *)(CONFIG_KNL_TEXT_ADDR + CONFIG_INIT_TASK_OFFSET), (void *)((umword_t)sp_addr_top - 8),
|
||||
init_task->mm_space.mm_block, 0);
|
||||
#endif
|
||||
@@ -228,7 +228,8 @@ void start_kernel(void)
|
||||
print_mkrtos_info();
|
||||
cli();
|
||||
sys_startup(); //!< 开始调度
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
to_sche();
|
||||
sti();
|
||||
|
||||
while (1)
|
||||
|
||||
@@ -18,7 +18,7 @@ static void th_test(void *arg)
|
||||
printk("%d ", a[i]);
|
||||
}
|
||||
printk("\n");
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
}
|
||||
}
|
||||
static void th_test2(void *arg)
|
||||
@@ -35,7 +35,7 @@ static void th_test2(void *arg)
|
||||
printk("%d,", a[i]);
|
||||
}
|
||||
printk("\n");
|
||||
thread_sched();
|
||||
thread_sched(TRUE);
|
||||
}
|
||||
}
|
||||
void kthread_test_init(void)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
# export TOOLCHAIN=/home/zhangzheng/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/
|
||||
# export TOOLCHAIN_LIB=/home/zhangzheng/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/lib/gcc/aarch64-none-elf/10.3.1
|
||||
export TOOLCHAIN=/home/mkrtos-smart/toolchains/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/
|
||||
export TOOLCHAIN_LIB=/home/mkrtos-smart/toolchains/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/lib/gcc/aarch64-none-elf/10.3.1
|
||||
export TOOLCHAIN=/home/zhangzheng/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/
|
||||
export TOOLCHAIN_LIB=/home/zhangzheng/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/lib/gcc/aarch64-none-elf/10.3.1
|
||||
# export TOOLCHAIN=/home/mkrtos-smart/toolchains/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/
|
||||
# export TOOLCHAIN_LIB=/home/mkrtos-smart/toolchains/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/lib/gcc/aarch64-none-elf/10.3.1
|
||||
|
||||
export BOARD=aarch64_qemu
|
||||
export CROSS_COMPILE_NAME=aarch64-none-elf-
|
||||
|
||||
Submodule mkrtos_user/lib/mkrtos-musl updated: d7d8a3c1b1...e271ed124f
@@ -1,53 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#define NS_PROT 0x0001 //!< namespace的协议
|
||||
#define NS_REGISTER_OP ((uint16_t)0) //!< ns注册
|
||||
#define NS_QUERY_OP ((uint16_t)1) //!< ns请求
|
||||
#define NS_REGISTER_OP ((umword_t)0) //!< ns注册
|
||||
#define NS_QUERY_OP ((umword_t)1) //!< ns请求
|
||||
|
||||
#define FS_PROT 0x0002
|
||||
#define FS_OPEN ((uint16_t)0) //!< 打开文件
|
||||
#define FS_CLOSE ((uint16_t)1) //!< 关闭文件
|
||||
#define FS_READ ((uint16_t)2) //!< 读取文件
|
||||
#define FS_WRITE ((uint16_t)3) //!< 写入文件
|
||||
#define FS_LSEEK ((uint16_t)4) //!< 写入文件位置
|
||||
#define FS_FTRUNCATE ((uint16_t)5) //!< 文件截断
|
||||
#define FS_SYNC ((uint16_t)6) //!< 文件同步
|
||||
#define FS_OPENDIR ((uint16_t)7) //!< 打开目录,应该使用open打开,保留该接口*
|
||||
#define FS_CLOSEDIR ((uint16_t)8) //!< 关闭目录,应该使用closedir,保留该接口*
|
||||
#define FS_READDIR ((uint16_t)9) //!< 读取目录
|
||||
#define FS_MKDIR ((uint16_t)10) //!< 新建目录
|
||||
#define FS_UNLINK ((uint16_t)11) //!< 删除目录或者文件
|
||||
#define FS_RENAME ((uint16_t)12) //!< 重命名
|
||||
#define FS_STAT ((uint16_t)13) //!< 获取文件状态
|
||||
#define FS_CHMOD ((uint16_t)14) //!< 改变权限 暂不实现*
|
||||
#define FS_UTIME ((uint16_t)15) //!< 修改时间 暂不实现*
|
||||
#define FS_CHDIR ((uint16_t)16) //!< 进入某个目录,可在客户端实现 暂不实现*
|
||||
#define FS_CWDIR ((uint16_t)17) //!< 获取当前目录,可在客户端实现 暂不实现*
|
||||
#define FS_MOUNT ((uint16_t)18) //!< 挂载节点 暂不实现*
|
||||
#define FS_SYMLINK ((uint16_t)19) //!< 软链接
|
||||
#define FS_OPEN ((umword_t)0) //!< 打开文件
|
||||
#define FS_CLOSE ((umword_t)1) //!< 关闭文件
|
||||
#define FS_READ ((umword_t)2) //!< 读取文件
|
||||
#define FS_WRITE ((umword_t)3) //!< 写入文件
|
||||
#define FS_LSEEK ((umword_t)4) //!< 写入文件位置
|
||||
#define FS_FTRUNCATE ((umword_t)5) //!< 文件截断
|
||||
#define FS_SYNC ((umword_t)6) //!< 文件同步
|
||||
#define FS_OPENDIR ((umword_t)7) //!< 打开目录,应该使用open打开,保留该接口*
|
||||
#define FS_CLOSEDIR ((umword_t)8) //!< 关闭目录,应该使用closedir,保留该接口*
|
||||
#define FS_READDIR ((umword_t)9) //!< 读取目录
|
||||
#define FS_MKDIR ((umword_t)10) //!< 新建目录
|
||||
#define FS_UNLINK ((umword_t)11) //!< 删除目录或者文件
|
||||
#define FS_RENAME ((umword_t)12) //!< 重命名
|
||||
#define FS_STAT ((umword_t)13) //!< 获取文件状态
|
||||
#define FS_CHMOD ((umword_t)14) //!< 改变权限 暂不实现*
|
||||
#define FS_UTIME ((umword_t)15) //!< 修改时间 暂不实现*
|
||||
#define FS_CHDIR ((umword_t)16) //!< 进入某个目录,可在客户端实现 暂不实现*
|
||||
#define FS_CWDIR ((umword_t)17) //!< 获取当前目录,可在客户端实现 暂不实现*
|
||||
#define FS_MOUNT ((umword_t)18) //!< 挂载节点 暂不实现*
|
||||
#define FS_SYMLINK ((umword_t)19) //!< 软链接
|
||||
|
||||
#define DRV_PROT 0x0003
|
||||
#define DRV_OPEN ((uint16_t)0) //!< 打开设备
|
||||
#define DRV_READ ((uint16_t)1) //!< 读取设备
|
||||
#define DRV_WRITE ((uint16_t)2) //!< 写入设备
|
||||
#define DRV_CLOSE ((uint16_t)3) //!< 关闭设备
|
||||
#define DRV_IOCTL ((uint16_t)4) //!< 控制设备
|
||||
#define DRV_OPEN ((umword_t)0) //!< 打开设备
|
||||
#define DRV_READ ((umword_t)1) //!< 读取设备
|
||||
#define DRV_WRITE ((umword_t)2) //!< 写入设备
|
||||
#define DRV_CLOSE ((umword_t)3) //!< 关闭设备
|
||||
#define DRV_IOCTL ((umword_t)4) //!< 控制设备
|
||||
|
||||
#define META_PROT 0x0004 //!< 元协议
|
||||
|
||||
#define PM_PROT 0x0005 //!< 进程管理协议
|
||||
#define PM_RUN_APP ((uint16_t)0) //!< 启动应用程序
|
||||
#define PM_KILL_TASK ((uint16_t)1) //!< 删除进程
|
||||
#define PM_WATCH_PID ((uint16_t)2) //!< watch pid
|
||||
#define PM_RUN_APP ((umword_t)0) //!< 启动应用程序
|
||||
#define PM_KILL_TASK ((umword_t)1) //!< 删除进程
|
||||
#define PM_WATCH_PID ((umword_t)2) //!< watch pid
|
||||
|
||||
#define CONS_PROT 0x0006 //!< console协议
|
||||
#define CONS_WRITE ((uint16_t)0) //!< console删除
|
||||
#define CONS_READ ((uint16_t)1) //!< console读
|
||||
#define CONS_ACTIVE ((uint16_t)2) //!< console激活
|
||||
#define CONS_WRITE ((umword_t)0) //!< console删除
|
||||
#define CONS_READ ((umword_t)1) //!< console读
|
||||
#define CONS_ACTIVE ((umword_t)2) //!< console激活
|
||||
|
||||
#define PM_SIG_PROT 0x0007 //!< pm信号协议
|
||||
#define PM_SIG_NOTIFY ((uint16_t)0) //!< 通知消息
|
||||
#define PM_SIG_NOTIFY ((umword_t)0) //!< 通知消息
|
||||
|
||||
#define NET_DRV_PROT 0x0008
|
||||
#define NET_DRV_WRITE ((uint16_t)0) //!< 网络驱动写
|
||||
#define NET_DRV_READ ((uint16_t)1) //!< 网络驱动读
|
||||
#define NET_DRV_WRITE ((umword_t)0) //!< 网络驱动写
|
||||
#define NET_DRV_READ ((umword_t)1) //!< 网络驱动读
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
int off = 0; \
|
||||
int off_map = 0; \
|
||||
int ret = -1; \
|
||||
int op_val = op; \
|
||||
umword_t op_val = op; \
|
||||
/*拷贝op*/ \
|
||||
rpc_memcpy(msg_ipc->msg_buf, &op_val, sizeof(op_val)); \
|
||||
off += rpc_align(sizeof(op_val), __alignof(op)); \
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
int off = 0; \
|
||||
int off_buf = 0; \
|
||||
int ret = -1; \
|
||||
size_t op_val = op; \
|
||||
umword_t op_val = op; \
|
||||
/*拷贝op*/ \
|
||||
rpc_memcpy(msg_ipc->msg_buf, &op_val, sizeof(op_val)); \
|
||||
off += rpc_align(sizeof(op_val), __alignof(op)); \
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
int off = 0; \
|
||||
int off_buf = 0; \
|
||||
int ret = -1; \
|
||||
size_t op_val = op; \
|
||||
umword_t op_val = op; \
|
||||
/*拷贝op*/ \
|
||||
rpc_memcpy(msg_ipc->msg_buf, &op_val, __alignof(op_val)); \
|
||||
off += rpc_align(sizeof(op_val), __alignof(op)); \
|
||||
|
||||
@@ -108,7 +108,7 @@ static int thread_set_msg_buf(obj_handler_t hd_task, obj_handler_t hd_thread)
|
||||
{
|
||||
return msg_tag_get_val(tag);
|
||||
}
|
||||
// 设置msgbuff,TODO:内核需要获取到对应的物理地址
|
||||
// 设置msgbuff
|
||||
tag = thread_msg_buf_set(hd_thread, (void *)(CONFIG_MSG_BUF_VADDR));
|
||||
if (msg_tag_get_val(tag) < 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user