尝试多核启动

This commit is contained in:
zhangzheng
2024-04-11 16:08:25 +00:00
parent db81692be4
commit f0aff5bd3f
40 changed files with 897 additions and 278 deletions

6
.vscode/launch.json vendored
View File

@@ -48,10 +48,10 @@
// "miDebuggerPath": "/opt/homebrew/bin/arm-none-eabi-gdb",
// "miDebuggerPath": "/home/zhangzheng/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gdb",
"miDebuggerPath": "/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/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/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/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",
"miDebuggerServerAddress": "127.0.0.1:3333",
"MIMode": "gdb",
"setupCommands": [
{

View File

@@ -71,7 +71,9 @@
"thread_task_arch.h": "c",
"mm_space.h": "c",
"spinlock_arch.h": "c",
"app.h": "c"
"app.h": "c",
"config.h": "c",
"u_sleep.h": "c"
},
"cortex-debug.showRTOS": false,
"cortex-debug.variableUseNaturalFormat": false,

View File

@@ -21,9 +21,12 @@ void jump2kernel(addr_t cpio_start, addr_t cpio_end)
while (1)
;
}
Elf64_Addr entry;
Elf64_Addr entry = 0;
elf_load_knl(knl_st_addr, &entry);
if (entry == 0) {
uart_write_str("not find knl image...\n");
}
main_func entry_fun = (main_func)entry;
knl_entry = entry;
entry_fun((mword_t)cpio_start);

View File

@@ -20,10 +20,13 @@
#include <timer.h>
#include <hyp.h>
#include <sche_arch.h>
#include <spin_table.h>
#include <thread_knl.h>
__ALIGN__(THREAD_BLOCK_SIZE)
static uint8_t thread_knl_stack[THREAD_BLOCK_SIZE] = {0};
void *_estack = thread_knl_stack + THREAD_BLOCK_SIZE;
static uint8_t thread_knl_stack[CONFIG_CPU][THREAD_BLOCK_SIZE] = {0};
void *_estack = &thread_knl_stack[0] + THREAD_BLOCK_SIZE;
static void other_cpu_boot(void);
extern void _start(void);
/**
* 进行调度
*/
@@ -37,13 +40,16 @@ void to_sche(void)
*/
void sys_startup(void)
{
/*TODO:*/
init_arm_hyp();
timer_init(arch_get_current_cpu_id());
for (int i = 1; i < CONFIG_CPU; i++)
{
cpu_start_to(i, thread_knl_stack[i], other_cpu_boot);
psci_cpu_on(i, (umword_t)_start);
}
}
void sys_reset(void)
{
/*TODO:*/
psci_system_reset();
}
umword_t arch_get_isr_no(void)
{
@@ -51,12 +57,10 @@ umword_t arch_get_isr_no(void)
}
void arch_disable_irq(int inx)
{
/*TODO:*/
gic2_set_mask(arm_gicv2_get_global(), inx);
}
void arch_enable_irq(int inx)
{
/*TODO:*/
gic2_set_unmask(arm_gicv2_get_global(), inx);
}
uint32_t arch_get_sys_clk(void)
@@ -66,7 +70,6 @@ uint32_t arch_get_sys_clk(void)
}
void arch_set_enable_irq_prio(int inx, int sub_prio, int pre_prio)
{
/*TODO:*/
gic2_set_prio(arm_gicv2_get_global(), inx, pre_prio);
}
extern char _data_boot[], _edata_boot[];
@@ -105,10 +108,32 @@ static void print_mem(void)
void arch_init(void)
{
printk("MKRTOS running on EL:%d\n", arch_get_currentel() >> 2);
printk("MKRTOS running on EL:%d\n", arch_get_currentel());
print_mem();
init_arm_hyp();
psci_init();
gic_init(arm_gicv2_get_global(),
0x08000000, 0x8010000); /*TODO:*/
}
INIT_LOW_HARD(arch_init);
static void arch_cpu_knl_init(void)
{
init_arm_hyp();
scheduler_init(); //!< 初始化其他cpu的调度队列
gic_init(arm_gicv2_get_global(), 0x08000000, 0x8010000);
knl_init_1();
timer_init(arch_get_current_cpu_id());
}
static void other_cpu_boot(void)
{
cli();
per_cpu_boot_mapping(FALSE);
mword_t elx = arch_get_currentel();
printk("cpuid %d run el%d.\n", arch_get_current_cpu_id(), elx);
arch_cpu_knl_init();
sti();
while (1)
;
}

View File

@@ -31,37 +31,37 @@ typedef struct
typedef struct pf {
struct
{
mword_t regs[31]; //!< 基础寄存器
mword_t sp; //!< sp
mword_t pc; //!< pc
mword_t pstate; //!< pstate
umword_t regs[31]; //!< 基础寄存器
umword_t sp; //!< sp
umword_t pc; //!< pc
umword_t pstate; //!< pstate
};
mword_t orig_x0;
umword_t orig_x0;
uint32_t syscallno;
uint32_t unused2;
mword_t orig_addr_limit;
mword_t unused;
mword_t stackframe[2];
umword_t orig_addr_limit;
umword_t unused;
umword_t stackframe[2];
} pf_t;
typedef struct sp_info {
mword_t x19;
mword_t x20;
mword_t x21;
mword_t x22;
mword_t x23;
mword_t x24;
mword_t x25;
mword_t x26;
mword_t x27;
mword_t x28;
mword_t fp; // x29
mword_t sp;
mword_t pc;
mword_t u_sp; // user_sp
mword_t tpidr_el0;
umword_t x19;
umword_t x20;
umword_t x21;
umword_t x22;
umword_t x23;
umword_t x24;
umword_t x25;
umword_t x26;
umword_t x27;
umword_t x28;
umword_t fp; // x29
umword_t sp;
umword_t pc;
umword_t u_sp; // user_sp
umword_t tpidr_el0;
} sp_info_t;
#define _barrier() __asm__ __volatile__("" : : : "memory")
@@ -115,7 +115,7 @@ static inline uint64_t arch_get_currentel(void)
asm volatile("mrs %0, CurrentEL"
: "=r"(_val));
return _val;
return _val >> 2;
}
static inline int arch_get_current_cpu_id(void)
{

View File

@@ -1,5 +1,7 @@
#include <asm/sysregs.h>
#include <asm_config.h>
#include <complier.h>
.section .rodata
.align 3
.globl string1
@@ -35,10 +37,6 @@ per_cpu_stack_addr:
_start:
msr daifset, #0xf //
mov x9, x0
#ifdef CONFIG_DEBUG_ON_EARLY_ASM
/* init uart and print the string*/
bl __init_uart
#endif
mrs x5, CurrentEL
cmp x5, #CurrentEL_EL3
@@ -46,9 +44,6 @@ _start:
b el2_entry
el3_entry:
#ifdef CONFIG_DEBUG_ON_EARLY_ASM
bl print_el
#endif
ldr x0, =SCTLR_EL2_VALUE_MMU_DISABLED
msr sctlr_el2, x0
@@ -116,3 +111,25 @@ jump_kenel_main:
ldr x1, = start_kernel
br x1
b .
.section ".text"
BEGIN_FUNC(per_cpu_boot_func)
//
mrs x0, mpidr_el1 // id
and x0, x0,#0xFF // Check processor id
cbz x0, percpu_spin_loop // Hang for all non-primary CPU
//spin table
ldr x1, = cpu_jump_addr
lsl x2, x0, MWORD_SHIFT
percpu_spin_jump:
ldr x3, [x1, x2]
cbz x3, percpu_spin_jump
ldr x4, = per_cpu_stack_addr
ldr x4, [x4, x2] //sp
mov sp, x4 //cpusp
br x3
percpu_spin_loop:
b .
END_FUNC(per_cpu_boot_func)

View File

@@ -1,50 +0,0 @@
#include <pre_cpu.h>
#include <types.h>
#include <buddy.h>
#include <config.h>
#include <string.h>
#include <arch.h>
#include <assert.h>
#include <asm_config.h>
#if CONFIG_SMP
extern char _pre_cpu_data_start[];
extern char _pre_cpu_data_end[];
static void *pre_cpu_data;
static mword_t pre_cpu_data_size;
void pre_cpu_init(void)
{
mword_t data_size = (addr_t)_pre_cpu_data_end - (addr_t)_pre_cpu_data_start;
pre_cpu_data_size = ALIGN(data_size, MWORD_BYTES);
printk("pre_cpu data's size is %d bytes.\n", data_size);\
printk("pre_cpu data's alloc size is %d bytes.\n", pre_cpu_data_size);
pre_cpu_data = buddy_alloc(buddy_get_alloter(),
pre_cpu_data_size * SYS_CPU_NUM);
assert(pre_cpu_data);
memset(pre_cpu_data, 0, pre_cpu_data_size * SYS_CPU_NUM);
}
#else
void pre_cpu_init(void)
{
}
#endif
void *pre_cpu_get_var_cpu(int cpu_inx, void *mem_addr)
{
#if CONFIG_SMP
mword_t offset = (addr_t)mem_addr - (addr_t)_pre_cpu_data_start;
return (void *)((addr_t)pre_cpu_data +
offset + cpu_inx * pre_cpu_data_size);
#else
return mem_addr;
#endif
}
void *pre_cpu_get_current_cpu_var(void *mem_addr)
{
return pre_cpu_get_var_cpu(arch_get_current_cpu_id(), mem_addr);
}

View File

@@ -1,12 +0,0 @@
#pragma once
#include <util.h>
#define PER_CPU(type, name) \
__attribute__((used)) \
SECTION(".data.per_cpu") type name
void pre_cpu_init(void);
void *pre_get_current_cpu_var(void *mem_addr);
void *pre_get_var_cpu(int cpu_inx, void *mem_addr);

View File

@@ -21,38 +21,8 @@ void *get_cpu_stack(int cpu_inx)
return (void *)per_cpu_stack[cpu_inx];
}
static inline SECTION(TEXT_BOOT_SECTION) uint64_t get_st_currentel(void)
void SECTION(TEXT_BOOT_SECTION) cpu_start_to(int cpu_id, void *stack, void *(fn)(void))
{
unsigned long _val;
asm volatile("mrs %0, CurrentEL"
: "=r"(_val));
return _val;
}
static SECTION(TEXT_BOOT_SECTION) inline int boot_get_current_cpu_id(void)
{
return read_sysreg(mpidr_el1) & 0XFFUL;
}
extern void cpu_kernel_init(void);
void SECTION(TEXT_BOOT_SECTION) other_cpu_boot(void)
{
// int cpu_id;
// cpu_id = boot_get_current_cpu_id();
// per_cpu_boot_mapping(&per_cpu_pkdir[cpu_id - 1]);
per_cpu_boot_mapping(FALSE);
mword_t elx = get_st_currentel();
// kprint("cpuid %d run el%d.\n", cpu_id, elx);
cpu_kernel_init();
while (1)
;
}
void SECTION(TEXT_BOOT_SECTION) cpu_start_to(int cpu_id)
{
// knl_pdir_init(&per_cpu_pkdir[cpu_id - 1], per_cpu_boot_kpdir[cpu_id - 1]);
per_cpu_stack_addr[cpu_id] = ((addr_t)per_cpu_stack[cpu_id]) + THREAD_BLOCK_SIZE - MWORD_BYTES - PT_REGS_SIZE;
cpu_jump_addr[cpu_id] = (mword_t)other_cpu_boot;
per_cpu_stack_addr[cpu_id] = ((addr_t)stack) + THREAD_BLOCK_SIZE - MWORD_BYTES - PT_REGS_SIZE;
cpu_jump_addr[cpu_id] = (mword_t)fn;
}

View File

@@ -1,4 +1,4 @@
#pragma once
void cpu_start_to(int cpu_id);
void cpu_start_to(int cpu_id, void *stack, void (*fn)(void));
void *get_cpu_stack(int cpu_inx);

View File

@@ -65,7 +65,7 @@ static void enable_timer_interrupt(int inx)
}
void timer_init(int cpu)
{
assert(irq_alloc(GENERIC_TIMER_IRQ, NULL, systick_handler));
irq_alloc(GENERIC_TIMER_IRQ, NULL, systick_handler);
arch_timer_rate = generic_timer_get_freq();
arch_timer_rate /= CONFIG_SYS_SCHE_HZ;
@@ -75,7 +75,7 @@ void timer_init(int cpu)
gic2_set_unmask(arm_gicv2_get_global(), GENERIC_TIMER_IRQ);
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(),
printk("cpu:%d timer dis:0x%x\n", cpu,
gic2_get_target_cpu(arm_gicv2_get_global(), GENERIC_TIMER_IRQ));
}
void handle_timer_irq(void)

View File

@@ -0,0 +1,17 @@
#pragma once
#include <util.h>
#if IS_ENABLED(CONFIG_SMP)
#define PER_CPU(type, name) \
__attribute__((used)) \
SECTION(".data.per_cpu") type name
#else
#define PER_CPU(type, name) \
__attribute__((used)) \
SECTION(".data") type name
#endif
void pre_cpu_init(void);
void *pre_get_current_cpu_var(void *mem_addr);
void *pre_cpu_get_var_cpu(uint32_t cpu_inx, void *mem_addr);
void *pre_cpu_get_current_cpu_var(void *mem_addr);

View File

@@ -36,5 +36,7 @@ scheduler_t *scheduler_get_current(void);
void scheduler_init(void);
sched_t *scheduler_next(void);
void scheduler_add(sched_t *node);
void scheduler_add_to_cpu(sched_t *node, int cpu);
sched_t *scheduler_next_cpu(int cpu);
void scheduler_del(sched_t *node);
void scheduler_reset(void);

View File

@@ -2,3 +2,4 @@
#include <task.h>
void task_knl_kill(thread_t *kill_thread, bool_t is_knl);
void knl_init_1(void);

View File

@@ -27,7 +27,7 @@
#include "access.h"
#include "limits.h"
#include "futex.h"
#include <pre_cpu.h>
/**
* @brief 以下是futex的操作码
*
@@ -93,7 +93,7 @@ typedef struct futex_wait_item
mword_t sleep_times;
} futex_wait_item_t;
static slist_head_t wait_list; //!< futex的等待队列
static PER_CPU(slist_head_t, wait_list); //!< futex的等待队列
/**
* @brief 初始化一个超时等待队列
@@ -101,7 +101,10 @@ static slist_head_t wait_list; //!< futex的等待队列
*/
static void futex_wait_list_init(void)
{
slist_init(&wait_list);
for (int i = 0; i < CONFIG_CPU; i++)
{
slist_init(pre_cpu_get_var_cpu(i, &wait_list));
}
}
INIT_KOBJ(futex_wait_list_init);
/**
@@ -112,9 +115,9 @@ void futex_timeout_times_tick(void)
{
futex_wait_item_t *item;
slist_foreach_not_next(item, &wait_list, node) //!< 第一次循环等待的ipc
slist_foreach_not_next(item, (slist_head_t *)pre_cpu_get_current_cpu_var(&wait_list), node) //!< 第一次循环等待的ipc
{
futex_wait_item_t *next = slist_next_entry(item, &wait_list, node);
futex_wait_item_t *next = slist_next_entry(item, (slist_head_t *)pre_cpu_get_current_cpu_var(&wait_list), node);
if (item->sleep_times > 0)
{
if ((--item->sleep_times) == 0)
@@ -366,7 +369,7 @@ static int futex_dispose(futex_t *fst, uint32_t *uaddr, int futex_op, uint32_t v
};
slist_init(&item.node);
slist_add_append(&wait_list, &item.node);
slist_add_append((slist_head_t *)pre_cpu_get_current_cpu_var(&wait_list), &item.node);
thread_suspend(cur_th);
preemption();
if (item.sleep_times <= 0)

View File

@@ -89,10 +89,13 @@ void entry_handler(void)
}
isr_no -= CONFIG_USER_ISR_START_NO; //!< 系统用的irq偏移
assert(isr_no < CONFIG_IRQ_REG_TAB_SIZE);
if (isr_no >= CONFIG_IRQ_REG_TAB_SIZE)
{
assert(isr_no < CONFIG_IRQ_REG_TAB_SIZE);
}
// if (isr_no != 30)
// {
// printk("%d.\n", isr_no);
// printk("==============%d.\n", isr_no);
// }
if (!irq_check_usability(isr_no))
{

59
mkrtos_knl/knl/pre_cpu.c Normal file
View File

@@ -0,0 +1,59 @@
#include <pre_cpu.h>
#include <types.h>
#include <buddy.h>
#include <string.h>
#include <assert.h>
#include <arch.h>
#if IS_ENABLED(CONFIG_SMP)
#include <init.h>
extern char _pre_cpu_data_start[];
extern char _pre_cpu_data_end[];
static void *pre_cpu_data;
static mword_t pre_cpu_data_size;
void pre_cpu_init(void)
{
mword_t data_size = (addr_t)_pre_cpu_data_end - (addr_t)_pre_cpu_data_start;
pre_cpu_data_size = ALIGN(data_size, PAGE_SIZE);
printk("pre_cpu data's size is %d bytes.\n", data_size);
printk("pre_cpu data's alloc size is %d bytes.\n", pre_cpu_data_size);
if (pre_cpu_data_size)
{
pre_cpu_data = buddy_alloc(buddy_get_alloter(),
pre_cpu_data_size * CONFIG_CPU);
assert(pre_cpu_data);
memset(pre_cpu_data, 0, pre_cpu_data_size * CONFIG_CPU);
}
}
INIT_KOBJ_MEM(pre_cpu_init);
#else
void pre_cpu_init(void)
{
}
#endif
void *pre_cpu_get_var_cpu(uint32_t cpu_inx, void *mem_addr)
{
#if IS_ENABLED(CONFIG_SMP)
mword_t offset = (addr_t)mem_addr - (addr_t)_pre_cpu_data_start;
return (void *)((addr_t)pre_cpu_data +
offset + cpu_inx * pre_cpu_data_size);
#else
return mem_addr;
#endif
}
void *pre_cpu_get_cpu_var(uint32_t cpu_inx, void *mem_addr)
{
assert(cpu_inx < CONFIG_CPU);
return pre_cpu_get_var_cpu(cpu_inx, mem_addr);
}
void *pre_cpu_get_current_cpu_var(void *mem_addr)
{
return pre_cpu_get_var_cpu(arch_get_current_cpu_id(), mem_addr);
}

View File

@@ -14,7 +14,8 @@
#include "thread.h"
#include "init.h"
#include <arch.h>
static scheduler_t scheduler;
#include <pre_cpu.h>
static PER_CPU(scheduler_t, scheduler);
umword_t sched_reset = 0;
void scheduler_reset(void)
@@ -27,24 +28,31 @@ void scheduler_reset(void)
scheduler_t *scheduler_get_current(void)
{
return &scheduler;
return pre_cpu_get_current_cpu_var(&scheduler);
}
scheduler_t *scheduler_get_cpu(int inx)
{
return pre_cpu_get_var_cpu(inx, &scheduler);
}
void scheduler_init(void)
{
for (int i = 0; i < PRIO_MAX; i++)
{
slist_init(&(scheduler.prio_list[i]));
slist_init(&(scheduler_get_current()->prio_list[i]));
}
}
INIT_HIGH_HAD(scheduler_init);
INIT_KOBJ(scheduler_init);
void scheduler_add(sched_t *node)
{
scheduler_add_to_cpu(node, arch_get_current_cpu_id());
}
void scheduler_add_to_cpu(sched_t *node, int cpu)
{
thread_t *node_th = container_of(node, thread_t, sche);
assert(node_th->magic == THREAD_MAGIC);
scheduler_t *sched = scheduler_get_current();
scheduler_t *sched = scheduler_get_cpu(cpu);
assert(node->prio >= 0);
assert(node->prio < PRIO_MAX);
@@ -88,9 +96,9 @@ void scheduler_del(sched_t *node)
sched->cur_sche = NULL;
}
}
sched_t *scheduler_next(void)
sched_t *scheduler_next_cpu(int cpu)
{
scheduler_t *sche = scheduler_get_current();
scheduler_t *sche = scheduler_get_cpu(cpu);
sched_t *next_sch = NULL;
slist_head_t *next = NULL;
@@ -111,6 +119,10 @@ sched_t *scheduler_next(void)
sche->cur_sche = next_sch;
return next_sch;
}
sched_t *scheduler_next(void)
{
return scheduler_next_cpu(arch_get_current_cpu_id());
}
void sched_tail(void)
{

View File

@@ -27,6 +27,8 @@
#include "access.h"
#include "ipc.h"
#include "arch.h"
#include <pre_cpu.h>
enum thread_op
{
SET_EXEC_REGS,
@@ -66,13 +68,16 @@ static inline void thread_wait_entry_init(thread_wait_entry_t *entry, thread_t *
entry->times = times;
}
static slist_head_t wait_send_queue;
static slist_head_t wait_recv_queue;
static PER_CPU(slist_head_t, wait_send_queue);
static PER_CPU(slist_head_t, wait_recv_queue);
static void thread_timeout_init(void)
{
slist_init(&wait_send_queue);
slist_init(&wait_recv_queue);
for (int i = 0; i < CONFIG_CPU; i++)
{
slist_init(pre_cpu_get_var_cpu(i, &wait_send_queue));
slist_init(pre_cpu_get_var_cpu(i, &wait_recv_queue));
}
}
INIT_KOBJ(thread_timeout_init);
@@ -142,10 +147,10 @@ static void thread_release_stage1(kobject_t *kobj)
}
thread_wait_entry_t *pos;
slist_foreach_not_next(pos, &wait_send_queue, node_timeout)
slist_foreach_not_next(pos, (slist_head_t *)pre_cpu_get_current_cpu_var(&wait_send_queue), node_timeout)
{
assert(pos->th->status == THREAD_SUSPEND);
thread_wait_entry_t *next = slist_next_entry(pos, &wait_send_queue, node_timeout);
thread_wait_entry_t *next = slist_next_entry(pos, (slist_head_t *)pre_cpu_get_current_cpu_var(&wait_send_queue), node_timeout);
if (pos->th != th)
{
@@ -162,10 +167,10 @@ static void thread_release_stage1(kobject_t *kobj)
}
thread_wait_entry_t *pos2;
slist_foreach_not_next(pos2, &wait_recv_queue, node)
slist_foreach_not_next(pos2, (slist_head_t *)pre_cpu_get_current_cpu_var(&wait_recv_queue), node)
{
assert(pos2->th->status == THREAD_SUSPEND);
thread_wait_entry_t *next = slist_next_entry(pos2, &wait_recv_queue, node);
thread_wait_entry_t *next = slist_next_entry(pos2, (slist_head_t *)pre_cpu_get_current_cpu_var(&wait_recv_queue), node);
if (pos2->th != th)
{
@@ -297,22 +302,32 @@ bool_t thread_sched(bool_t is_sche)
*
* @param th
*/
void thread_ready(thread_t *th, bool_t is_sche)
void thread_ready_to_cpu(thread_t *th, int cpu, bool_t is_sche)
{
assert(cpu < CONFIG_CPU);
umword_t status = cpulock_lock();
// if (!!slist_in_list(&th->sche.node))
// {
assert(!slist_in_list(&th->sche.node));
// }
scheduler_add(&th->sche);
scheduler_add_to_cpu(&th->sche, cpu);
th->status = THREAD_READY;
if (is_sche)
{
thread_sched(TRUE);
umword_t status = cpulock_lock();
sched_t *next_sche = scheduler_next_cpu(cpu);
assert(th->magic == THREAD_MAGIC);
}
cpulock_set(status);
}
/**
* @brief 线程进入就绪态
*
* @param th
*/
void thread_ready(thread_t *th, bool_t is_sche)
{
thread_ready_to_cpu(th, arch_get_current_cpu_id(), is_sche);
}
void thread_todead(thread_t *th, bool_t is_sche)
{
// if (!!slist_in_list(&th->sche.node))
@@ -360,10 +375,10 @@ void thread_timeout_check(ssize_t tick)
{
thread_wait_entry_t *pos;
slist_foreach_not_next(pos, &wait_send_queue, node_timeout)
slist_foreach_not_next(pos, (slist_head_t *)pre_cpu_get_current_cpu_var(&wait_send_queue), node_timeout)
{
assert(pos->th->status == THREAD_SUSPEND);
thread_wait_entry_t *next = slist_next_entry(pos, &wait_send_queue, node_timeout);
thread_wait_entry_t *next = slist_next_entry(pos, (slist_head_t *)pre_cpu_get_current_cpu_var(&wait_send_queue), node_timeout);
if (pos->times > 0)
{
pos->times -= tick;
@@ -381,10 +396,12 @@ void thread_timeout_check(ssize_t tick)
pos = next;
}
thread_wait_entry_t *pos2;
slist_foreach_not_next(pos2, &wait_recv_queue, node)
slist_foreach_not_next(pos2,
(slist_head_t *)pre_cpu_get_current_cpu_var(&wait_recv_queue), node)
{
assert(pos2->th->status == THREAD_SUSPEND);
thread_wait_entry_t *next = slist_next_entry(pos2, &wait_recv_queue, node);
thread_wait_entry_t *next = slist_next_entry(pos2,
(slist_head_t *)pre_cpu_get_current_cpu_var(&wait_recv_queue), node);
if (pos2->times > 0)
{
@@ -402,9 +419,9 @@ void thread_timeout_check(ssize_t tick)
static void thread_timeout_del_recv(thread_t *th)
{
thread_wait_entry_t *pos2;
slist_foreach_not_next(pos2, &wait_recv_queue, node)
slist_foreach_not_next(pos2, (slist_head_t *)pre_cpu_get_current_cpu_var(&wait_recv_queue), node)
{
thread_wait_entry_t *next = slist_next_entry(pos2, &wait_recv_queue, node);
thread_wait_entry_t *next = slist_next_entry(pos2, (slist_head_t *)pre_cpu_get_current_cpu_var(&wait_recv_queue), node);
if (pos2->th == th)
{
@@ -516,7 +533,7 @@ static int thread_ipc_recv(msg_tag_t *ret_msg, ipc_timeout_t timeout,
if (timeout.recv_timeout)
{
thread_wait_entry_init(&wait, cur_th, timeout.recv_timeout);
slist_add_append(&wait_recv_queue, &wait.node); //!< 放到等待队列中
slist_add_append(pre_cpu_get_current_cpu_var(&wait_recv_queue), &wait.node); //!< 放到等待队列中
}
}
thread_suspend(cur_th); //!< 挂起
@@ -620,7 +637,7 @@ again_check:
thread_wait_entry_init(&wait, cur_th, timout.send_timeout);
slist_add_append(&recv_kobj->wait_send_head, &wait.node); //!< 放到线程的等待队列中
slist_add_append(&wait_send_queue, &wait.node_timeout);
slist_add_append(pre_cpu_get_current_cpu_var(&wait_send_queue), &wait.node_timeout);
thread_suspend(cur_th); //!< 挂起
preemption();
if (cur_th->ipc_status == THREAD_IPC_ABORT)
@@ -832,7 +849,14 @@ static void thread_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_t
if (!slist_in_list(&tag_th->sche.node))
{
tag_th->sche.prio = (f->regs[1] >= PRIO_MAX ? PRIO_MAX - 1 : f->regs[1]);
thread_ready(tag_th, TRUE);
if (f->regs[2] >= CONFIG_CPU)
{
thread_ready(tag_th, TRUE);
}
else
{
thread_ready_to_cpu(tag_th, f->regs[2], TRUE);
}
}
else
{

View File

@@ -92,7 +92,7 @@ static void knl_main(void)
* 初始化内核线程
* 初始化内核任务
*/
static void knl_init_1(void)
void knl_init_1(void)
{
knl_thread = thread_get_current();
@@ -104,7 +104,6 @@ static void knl_init_1(void)
thread_set_msg_buf(knl_thread, knl_msg_buf, knl_msg_buf);
thread_ready(knl_thread, FALSE);
slist_init(&del_task_head);
}
INIT_STAGE1(knl_init_1);
@@ -117,7 +116,7 @@ INIT_STAGE1(knl_init_1);
static void knl_init_2(void)
{
mm_trace();
slist_init(&del_task_head);
#if IS_ENABLED(CONFIG_KNL_TEST)
knl_test();
#else

View File

@@ -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-

View File

@@ -8,9 +8,9 @@ fi
# -machine virt,virtualization=on,gic-version=2,highmem=off,secure=off,dumpdtb=virt.dtb
qemu-system-aarch64 \
-machine virt,virtualization=on,gic-version=2,highmem=off,secure=off\
-cpu cortex-a53 \
-cpu cortex-a57 \
-nographic \
-m size=512 \
-smp 4\
-smp 4,cores=4 \
-kernel $PWD/build/output/bootstrap.elf \
-S -gdb tcp::$1

View File

@@ -8,7 +8,6 @@ if (${ARCH_NAME} STREQUAL "armv7_8m")
add_subdirectory(mlibc)
add_subdirectory(mr)
add_subdirectory(lwip)
add_subdirectory(printf)
# add_subdirectory(at_device)
elseif(${CONFIG_ARCH} STREQUAL "aarch64")
add_subdirectory(mkrtos-musl)
@@ -20,4 +19,5 @@ add_subdirectory(sys_svr)
add_subdirectory(libc_backend)
add_subdirectory(cpio)
add_subdirectory(letter-shell/demo/mkrtos)
add_subdirectory(printf)

View File

@@ -0,0 +1,8 @@
.text
.global __pthread_new_thread_entry__
.type __pthread_new_thread_entry__,%function
__pthread_new_thread_entry__:
ldr x0, [sp, #12]
ldr x1, [sp, #4]
br x1

View File

@@ -75,13 +75,8 @@ src/printf/printf.h)
target_compile_definitions(printf PRIVATE PRINTF_INCLUDE_CONFIG_H)
target_include_directories(printf PRIVATE
"$<BUILD_INTERFACE:${GENERATED_INCLUDE_DIR}>"
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/arm/
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/generic
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/obj/src/internal
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/src/include
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/src/internal
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/obj/include
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/include
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_svr/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys/inc/
)
# set_property(TARGET printf PROPERTY C_STANDARD 99)
@@ -143,7 +138,8 @@ if (UNIX)
endif()
target_link_libraries(
printf
muslc
${LIBC_NAME}
sys
)
# -------------------------

View File

@@ -55,7 +55,11 @@ msg_tag_t thread_yield(obj_handler_t obj);
msg_tag_t thread_msg_buf_set(obj_handler_t obj, void *msg);
msg_tag_t thread_msg_buf_get(obj_handler_t obj, umword_t *msg, umword_t *len);
msg_tag_t thread_exec_regs(obj_handler_t obj, umword_t pc, umword_t sp, umword_t ram, umword_t cp_stack);
msg_tag_t thread_run(obj_handler_t obj, uint8_t prio);
msg_tag_t thread_run_cpu(obj_handler_t obj, uint8_t prio, umword_t cpu);
static inline msg_tag_t thread_run(obj_handler_t obj, uint8_t prio)
{
return thread_run_cpu(obj, prio, -1);
}
msg_tag_t thread_bind_task(obj_handler_t obj, obj_handler_t tk_obj);
msg_tag_t thread_ipc_wait(ipc_timeout_t timeout, umword_t *obj, obj_handler_t ipc_obj);

View File

@@ -172,14 +172,14 @@ msg_tag_t thread_exec_regs(obj_handler_t obj, umword_t pc, umword_t sp, umword_t
return tag;
}
msg_tag_t thread_run(obj_handler_t obj, uint8_t prio)
msg_tag_t thread_run_cpu(obj_handler_t obj, uint8_t prio, umword_t cpu)
{
register volatile umword_t r0 asm(ARCH_REG_0);
mk_syscall(syscall_prot_create4(RUN_THREAD, THREAD_PROT, obj, TRUE).raw,
0,
prio,
0,
cpu,
0,
0,
0);

View File

@@ -8,9 +8,7 @@ if (${ARCH_NAME} STREQUAL "armv7_8m")
set(START_INIT_LIB start_init)
# add_subdirectory(app)
add_subdirectory(hello)
add_subdirectory(drv)
add_subdirectory(test)
# add_subdirectory(net)
# add_subdirectory(tcc-0.9.27)
elseif(${CONFIG_ARCH} STREQUAL "aarch64" )
@@ -37,4 +35,6 @@ add_subdirectory(init)
add_subdirectory(shell)
add_subdirectory(tinycc-arm-thumb)
add_subdirectory(fs)
add_subdirectory(hello)
add_subdirectory(test)

View File

@@ -2,18 +2,16 @@ cmake_minimum_required(VERSION 3.13)
file(GLOB_RECURSE deps *.c *.S)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_STDPERIPH_DRIVER=1 \
")
add_executable(hello.elf
${deps}
${START_SRC}
)
target_link_libraries(hello.elf
PUBLIC
start_tiny
-Bstatic
${LIBC_NAME}
${START_LIB}
printf
muslc
sys
sys_util
sys_svr
@@ -27,26 +25,13 @@ target_include_directories(
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_svr/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/server/hello/src/test
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/arm/
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/generic
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/obj/src/internal
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/src/include
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/src/internal
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/obj/include
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/include
${CMAKE_SOURCE_DIR}/mkrtos_user/server/hello/bsp/core_inc
${CMAKE_SOURCE_DIR}/mkrtos_user/server/hello/bsp/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/printf/src/printf
)
add_dependencies(hello.elf
muslc
printf
)
set_target_properties(hello.elf PROPERTIES LINK_FLAGS
"-T ${CMAKE_CURRENT_LIST_DIR}/link.lds -pie --gc-section -no-dynamic-linker "
#--no-warn-rwx-segments
set_target_properties(sh.elf PROPERTIES LINK_FLAGS
"-T ${CMAKE_CURRENT_LIST_DIR}/${ARCH_NAME}/link.lds ${CORTEX_M_LINK_FLAGS} --gc-section -no-dynamic-linker "
)
add_custom_target(
hello_dump ALL
@@ -65,12 +50,16 @@ add_custom_target(
COMMAND
cp hello.elf ${CMAKE_SOURCE_DIR}/build/output/hello.elf
)
if ((DEFINED CONFIG_ELF_LAUNCH) AND (CONFIG_ELF_LAUNCH STREQUAL "y"))
add_custom_target(
hello_dump_elf ALL
COMMAND
cp hello.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/hello.elf
)
add_dependencies(hello_dump_elf hello_dump)
endif()
add_dependencies(hello_dump hello.elf)
add_dependencies(hello_dump sys)
add_dependencies(hello_dump sys_util)
add_dependencies(hello_dump mr)
add_dependencies(hello_dump sys_svr)
add_dependencies(hello_dump start)
add_dependencies(hello_dump muslc)

View File

@@ -0,0 +1,233 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2021 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64",
"elf64-littleaarch64")
OUTPUT_ARCH(aarch64)
ENTRY(_start)
SEARCH_DIR("//aarch64-none-elf/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x01400000)); . = SEGMENT_START("text-segment", 0x01400000);
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
.init :
{
KEEP (*(SORT_NONE(.init)))
} =0x1f2003d5
.plt : { *(.plt) *(.iplt) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(SORT(.text.sorted.*))
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
. = ALIGN(4);
_shell_command_start = .;
KEEP(*(shellCommand))
_shell_command_end = .;
} =0x1f2003d5
.fini :
{
KEEP (*(SORT_NONE(.fini)))
} =0x1f2003d5
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
.tdata :
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
}
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
__data_start = .;
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
__bss_start__ = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
_bss_end__ = .; __bss_end__ = .;
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
. = ALIGN(64 / 8);
__end__ = .;
_end = .; PROVIDE (end = .);
.stack 0x80000 :
{
_stack = .;
*(.stack)
}
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1. */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions. */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2. */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2. */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions. */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3. */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF 5. */
.debug_addr 0 : { *(.debug_addr) }
.debug_line_str 0 : { *(.debug_line_str) }
.debug_loclists 0 : { *(.debug_loclists) }
.debug_macro 0 : { *(.debug_macro) }
.debug_names 0 : { *(.debug_names) }
.debug_rnglists 0 : { *(.debug_rnglists) }
.debug_str_offsets 0 : { *(.debug_str_offsets) }
.debug_sup 0 : { *(.debug_sup) }
.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }
.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
}

View File

@@ -35,6 +35,7 @@
static void test(void)
{
// thread_cpu_test();
#if 0
malloc_test();
printf_test();

View File

@@ -19,3 +19,4 @@ int pthread_cond_lock_test(void);
void sharea_mem_test(void);
void ns_test(void);
void malloc_test(void);
void thread_cpu_test(void);

View File

@@ -0,0 +1,78 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"
#include "u_ipc.h"
#include "u_hd_man.h"
#include <assert.h>
#include <stdio.h>
#include "u_sleep.h"
#include "u_vmam.h"
#include <string.h>
static umword_t th1_hd = 0;
static umword_t th2_hd = 0;
#define STACK_SIZE 4096
static __attribute__((aligned(8))) uint8_t stack0[STACK_SIZE];
static __attribute__((aligned(8))) uint8_t stack1[STACK_SIZE];
//! 读取系统寄存器
#define read_sysreg(reg) ({ \
unsigned long _val; \
asm volatile("mrs %0, " #reg \
: "=r"(_val)); \
_val; \
})
static inline int arch_get_current_cpu_id(void)
{
return read_sysreg(mpidr_el1) & 0XFFUL;
}
static void thread_test_func(void)
{
printf("[u]thread run %d cpu.\n", arch_get_current_cpu_id());
handler_free_umap(th1_hd);
printf("Error\n");
}
void thread_cpu_test(void)
{
th1_hd = handler_alloc();
assert(th1_hd != HANDLER_INVALID);
msg_tag_t tag;
void *mem;
u_sleep_ms(500);
tag = factory_create_thread(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, th1_hd));
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_bind_task(th1_hd, TASK_THIS);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_exec_regs(th1_hd, (umword_t)thread_test_func, (umword_t)stack0 + STACK_SIZE - 8, TASK_RAM_BASE(), 0);
assert(msg_tag_get_prot(tag) >= 0);
tag = u_vmam_alloc(VMA_PROT, vma_addr_create(VPAGE_PROT_RW, 0, 0), PAGE_SIZE, 0, (addr_t *)(&mem));
assert(msg_tag_get_prot(tag) >= 0);
memset((void *)mem, 0, PAGE_SIZE);
// 设置msgbuff
tag = thread_msg_buf_set(th1_hd, mem);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_run_cpu(th1_hd, 2, 1);
th2_hd = handler_alloc();
assert(th2_hd != HANDLER_INVALID);
tag = factory_create_thread(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, th2_hd));
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_bind_task(th2_hd, TASK_THIS);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_exec_regs(th2_hd, (umword_t)thread_test_func, (umword_t)stack1 + STACK_SIZE - 8, TASK_RAM_BASE(), 0);
assert(msg_tag_get_prot(tag) >= 0);
tag = u_vmam_alloc(VMA_PROT, vma_addr_create(VPAGE_PROT_RW, 0, 0), PAGE_SIZE, 0, (addr_t *)(&mem));
assert(msg_tag_get_prot(tag) >= 0);
memset((void *)mem, 0, PAGE_SIZE);
// 设置msgbuff
tag = thread_msg_buf_set(th2_hd, mem);
assert(msg_tag_get_prot(tag) >= 0);
tag = thread_run_cpu(th2_hd, 2, 3);
u_sleep_ms(500);
}

View File

@@ -2,21 +2,22 @@ cmake_minimum_required(VERSION 3.13)
file(GLOB_RECURSE deps *.c *.S)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_STDPERIPH_DRIVER=1 \
")
add_executable(test.elf
${deps}
${START_SRC}
)
target_link_libraries(test.elf
PUBLIC
start
muslc
-Bstatic
${LIBC_NAME}
${START_LIB}
--whole-archive
libc_be
--no-whole-archive
printf
sys
sys_util
sys_svr
mr
${GCC_LIB_PATH}/libgcc.a
)
target_include_directories(
@@ -25,25 +26,16 @@ target_include_directories(
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_util/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_svr/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/arm/
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/generic
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/obj/src/internal
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/src/include
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/src/internal
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/obj/include
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/include
${CMAKE_SOURCE_DIR}/mkrtos_user/server/test/src/test
${CMAKE_SOURCE_DIR}/mkrtos_user/server/test/bsp/core_inc
${CMAKE_SOURCE_DIR}/mkrtos_user/server/test/bsp/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/printf/src/printf
)
add_dependencies(test.elf
muslc
set_target_properties(sh.elf PROPERTIES LINK_FLAGS
"-T ${CMAKE_CURRENT_LIST_DIR}/${ARCH_NAME}/link.lds ${CORTEX_M_LINK_FLAGS} --gc-section -no-dynamic-linker "
)
set_target_properties(test.elf PROPERTIES LINK_FLAGS
"-T ${CMAKE_CURRENT_LIST_DIR}/link.lds -pie --gc-section -no-dynamic-linker "
)
#--no-warn-rwx-segments
add_custom_target(
test_dump ALL
COMMAND
@@ -61,8 +53,16 @@ add_custom_target(
COMMAND
cp test.elf ${CMAKE_SOURCE_DIR}/build/output/test.elf
)
if ((DEFINED CONFIG_ELF_LAUNCH) AND (CONFIG_ELF_LAUNCH STREQUAL "y"))
add_custom_target(
test_dump_elf ALL
COMMAND
cp test.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/test.elf
)
add_dependencies(test_dump_elf test_dump)
endif()
add_dependencies(test_dump test.elf)
add_dependencies(test_dump sys)
add_dependencies(test_dump sys_util)
add_dependencies(test_dump sys_svr)

View File

@@ -0,0 +1,233 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2021 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64",
"elf64-littleaarch64")
OUTPUT_ARCH(aarch64)
ENTRY(_start)
SEARCH_DIR("//aarch64-none-elf/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x01400000)); . = SEGMENT_START("text-segment", 0x01400000);
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
.init :
{
KEEP (*(SORT_NONE(.init)))
} =0x1f2003d5
.plt : { *(.plt) *(.iplt) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(SORT(.text.sorted.*))
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
. = ALIGN(4);
_shell_command_start = .;
KEEP(*(shellCommand))
_shell_command_end = .;
} =0x1f2003d5
.fini :
{
KEEP (*(SORT_NONE(.fini)))
} =0x1f2003d5
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
.tdata :
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
}
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
__data_start = .;
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
__bss_start__ = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
_bss_end__ = .; __bss_end__ = .;
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
. = ALIGN(64 / 8);
__end__ = .;
_end = .; PROVIDE (end = .);
.stack 0x80000 :
{
_stack = .;
*(.stack)
}
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1. */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions. */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2. */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2. */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions. */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3. */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF 5. */
.debug_addr 0 : { *(.debug_addr) }
.debug_line_str 0 : { *(.debug_line_str) }
.debug_loclists 0 : { *(.debug_loclists) }
.debug_macro 0 : { *(.debug_macro) }
.debug_names 0 : { *(.debug_names) }
.debug_rnglists 0 : { *(.debug_rnglists) }
.debug_str_offsets 0 : { *(.debug_str_offsets) }
.debug_sup 0 : { *(.debug_sup) }
.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }
.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
}

View File

@@ -19,15 +19,15 @@ int main(int argc, char *args[])
{
printf("argc:%d args[0]:%s\n", argc, args[0]);
#if 0
malloc_test();
rpc_test();
ns_test();
irq_test();
printf("%s: please input str.\n", args[0]);
scanf("%s", data);
printf("%s\n", data);
fs_test();
#if 1
// malloc_test();
// rpc_test();
// ns_test();
// irq_test();
// printf("%s: please input str.\n", args[0]);
// scanf("%s", data);
// printf("%s\n", data);
// fs_test();
#endif
return 0;
}

View File

@@ -5,6 +5,7 @@
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <u_util.h>
static pthread_cond_t cond;
static pthread_mutex_t mutex;
static int cond_value;

View File

@@ -1,17 +1,17 @@
#include "drv_cli.h"
#include <mr_api.h>
#include <assert.h>
#include <stdio.h>
void mr_drv_test(void)
{
char data[10] = "mkrtos..\n";
// #include "drv_cli.h"
// #include <mr_api.h>
// #include <assert.h>
// #include <stdio.h>
// void mr_drv_test(void)
// {
// char data[10] = "mkrtos..\n";
int fd = dev_fs_open("/dev/uart1", MR_OFLAG_RDWR);
assert(fd > 0);
int ret = dev_fs_read(fd, data, sizeof(data));
assert(ret >= 0);
printf("%s:%d data:%s.\n", __func__, __LINE__, data);
ret = dev_fs_write(fd, data, sizeof(data));
assert(ret >= 0);
dev_fs_close(fd);
}
// int fd = dev_fs_open("/dev/uart1", MR_OFLAG_RDWR);
// assert(fd > 0);
// int ret = dev_fs_read(fd, data, sizeof(data));
// assert(ret >= 0);
// printf("%s:%d data:%s.\n", __func__, __LINE__, data);
// ret = dev_fs_write(fd, data, sizeof(data));
// assert(ret >= 0);
// dev_fs_close(fd);
// }