mcu能够启动到init

This commit is contained in:
zhangzheng
2024-04-10 17:08:21 +00:00
parent f3de8b8869
commit 5b2ac390ab
16 changed files with 55 additions and 20 deletions

4
.vscode/launch.json vendored
View File

@@ -46,7 +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/zhangzheng/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/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:3333",
"MIMode": "gdb",

View File

@@ -70,7 +70,8 @@
"arm_local_reg.h": "c",
"thread_task_arch.h": "c",
"mm_space.h": "c",
"spinlock_arch.h": "c"
"spinlock_arch.h": "c",
"app.h": "c"
},
"cortex-debug.showRTOS": false,
"cortex-debug.variableUseNaturalFormat": false,

View File

@@ -10,7 +10,7 @@ add_custom_target(
srec_cat -output ${CMAKE_SOURCE_DIR}/build/output/kernel.img -binary
${CMAKE_SOURCE_DIR}/build/output/bootstrap -binary -offset 0x0
${CMAKE_SOURCE_DIR}/build/output/mkrtos -binary -offset ${CONFIG_KNL_OFFSET}
# ${CMAKE_SOURCE_DIR}/build/output/init -binary -offset ${CONFIG_INIT_TASK_OFFSET}
${CMAKE_SOURCE_DIR}/build/output/init -binary -offset ${CONFIG_INIT_TASK_OFFSET}
${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio -binary -offset ${CONFIG_BOOTFS_OFFSET}
COMMAND
cp ${CMAKE_SOURCE_DIR}/build/output/kernel.img ${CMAKE_SOURCE_DIR}/build/output/kernel.bin

View File

@@ -79,7 +79,7 @@ if ((DEFINED CONFIG_ELF_LAUNCH) AND (CONFIG_ELF_LAUNCH STREQUAL "y"))
add_custom_target(
mkrtos_dump_elf ALL
COMMAND
cp init.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/mkrtos.elf
cp mkrtos.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/mkrtos.elf
)
add_dependencies(mkrtos_dump_elf mkrtos_dump)
endif()

View File

@@ -17,9 +17,20 @@
#include "mm_wrap.h"
#include "arch.h"
#include "string.h"
typedef struct entry_frame_tmp
{
umword_t r[6];
} entry_frame_tmp_t;
static void syscall_entry_raw(entry_frame_tmp_t entry);
syscall_entry_func syscall_handler_get(void)
{
return syscall_entry;
return (void *)syscall_entry_raw;
}
static void syscall_entry_raw(entry_frame_tmp_t entry)
{
syscall_entry((entry_frame_t *)&entry);
}
void thread_knl_pf_set(thread_t *cur_th, void *pc)
{

View File

@@ -38,12 +38,12 @@ void syscall_entry(entry_frame_t *entry)
goto end;
}
}
sti(); //开启中断
// sti(); //开启中断
if (kobj->invoke_func)
{
kobj->invoke_func(kobj, sys_p, msg_tag_init(entry->regs[0]), entry);
}
cli(); //关闭中断
// cli(); //关闭中断
end:;
#if !IS_ENABLED(CONFIG_MMU)
addr_t u_sp = arch_get_user_sp();

View File

@@ -127,13 +127,13 @@ static void knl_init_2(void)
init_thread = thread_create(&root_factory_get()->limit);
assert(init_thread);
init_task = task_create(&root_factory_get()->limit, FALSE);
init_task = task_create(&root_factory_get()->limit, FALSE);
assert(init_task);
#if IS_ENABLED(CONFIG_ELF_LAUNCH)
addr_t entry;
ret_addr = cpio_find_file(cpio_images, (umword_t)(-1), "init.elf", &size);
ret_addr = cpio_find_file(cpio_images, (umword_t)(-1), "init", &size);
assert(ret_addr);
elf_load(init_task, ret_addr, size, &entry);
void *init_msg_buf = mm_buddy_alloc_one_page();
@@ -149,6 +149,7 @@ static void knl_init_2(void)
NULL, 0);
#else
app_info_t *app = app_info_get((void *)(CONFIG_KNL_TEXT_ADDR + CONFIG_INIT_TASK_OFFSET));
assert(app);
// 申请init的ram内存
assert(task_alloc_base_ram(init_task, &root_factory_get()->limit, app->i.ram_size + THREAD_MSG_BUG_LEN) >= 0);
void *sp_addr = (char *)init_task->mm_space.mm_block + app->i.stack_offset - app->i.data_offset;
@@ -227,7 +228,7 @@ void start_kernel(void)
cli();
sys_startup(); //!< 开始调度
thread_sched(TRUE);
to_sche();
// to_sche();
sti();
while (1)

View File

@@ -16,4 +16,17 @@
((type *)(((umword_t)(ptr)) - ((umword_t)(&(((type *)0)->member)))))
#define ATTR_ALIGN(a) __attribute__((aligned(a)))
#define AUTO_CALL(prio) __attribute__((constructor(prio)))
#define AUTO_CALL(prio) __attribute__((constructor(prio)))
#define __ARG_PLACEHOLDER_1 0,
#define __take_second_arg(__ignored, val, ...) val
#define __is_defined(x) ___is_defined(x)
#define ___is_defined(val) ____is_defined(__ARG_PLACEHOLDER_##val)
#define ____is_defined(arg1_or_junk) __take_second_arg(arg1_or_junk 1, 0)
#define __or(x, y) ___or(x, y)
#define ___or(x, y) ____or(__ARG_PLACEHOLDER_##x, y)
#define ____or(arg1_or_junk, y) __take_second_arg(arg1_or_junk 1, y)
#define IS_BUILTIN(option) __is_defined(option)
#define IS_MODULE(option) __is_defined(option##_MODULE)
#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))

View File

@@ -5,6 +5,7 @@ include_directories(
)
if (${ARCH_NAME} STREQUAL "armv7_8m")
set(START_LIB start)
set(START_INIT_LIB start_init)
# add_subdirectory(app)
add_subdirectory(hello)
@@ -17,6 +18,8 @@ elseif(${CONFIG_ARCH} STREQUAL "aarch64" )
START_LIB
""
)
set(START_INIT_LIB "")
set(
START_SRC
${CMAKE_SOURCE_DIR}/build/libc/output/lib/crt1.o

View File

@@ -64,7 +64,7 @@ if ((DEFINED CONFIG_ELF_LAUNCH) AND (CONFIG_ELF_LAUNCH STREQUAL "y"))
add_custom_target(
cpiofs_dump_elf ALL
COMMAND
cp cpiofs.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/cpiofs.elf
cp cpiofs.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/cpiofs
)
add_dependencies(cpiofs_dump_elf cpiofs_dump)
endif()

View File

@@ -1,4 +1,5 @@
#include <u_util.h>
#if !IS_ENABLED(CONFIG_MMU)
#define HEAP_SIZE 512
#define STACK_SIZE (2048)
@@ -15,3 +16,4 @@
__attribute__((used)) HEAP_ATTR static char _____heap_____[HEAP_SIZE];
__attribute__((used)) STACK_ATTR static char _____stack_____[STACK_SIZE];
#endif

View File

@@ -10,7 +10,7 @@ target_link_libraries(init.elf
PUBLIC
-Bstatic
${LIBC_NAME}
${START_LIB}
${START_INIT_LIB}
--whole-archive
libc_be
sys
@@ -59,7 +59,7 @@ if ((DEFINED CONFIG_ELF_LAUNCH) AND (CONFIG_ELF_LAUNCH STREQUAL "y"))
add_custom_target(
init_dump_elf ALL
COMMAND
cp init.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/init.elf
cp init.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/init
)
add_dependencies(init_dump_elf init_dump)
endif()

View File

@@ -1,4 +1,5 @@
#ifndef CONFIG_MMU
#include <u_util.h>
#if !IS_ENABLED(CONFIG_MMU)
/**
* @file heap_stack.c
* @author ATShining (1358745329@qq.com)

View File

@@ -1,8 +1,8 @@
#一次读取一行,每行代表启动的应用程序,暂时不支持参数
# fatfs
cpiofs.elf
cpiofs
# dm9000_drv
# net
sh.elf
sh
# lcd_drv

View File

@@ -53,7 +53,7 @@ if ((DEFINED CONFIG_ELF_LAUNCH) AND (CONFIG_ELF_LAUNCH STREQUAL "y"))
add_custom_target(
sh_dump_elf ALL
COMMAND
cp sh.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/sh.elf
cp sh.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/sh
)
add_dependencies(sh_dump_elf shell_dump)
endif()

View File

@@ -1,4 +1,5 @@
#ifndef CONFIG_MMU
#include <u_util.h>
#if !IS_ENABLED(CONFIG_MMU)
#define HEAP_SIZE 2048
#define STACK_SIZE (1024 + 512)