增加用户态

This commit is contained in:
zhangzheng
2024-04-03 16:08:09 +00:00
parent c73c35c5b2
commit 436c88f8ca
22 changed files with 392 additions and 408 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "mkrtos_user/lib/mkrtos-musl"]
path = mkrtos_user/lib/mkrtos-musl
url = https://gitee.com/IsYourGod/mkrtos-musl.git

347
.vscode/settings.json vendored
View File

@@ -1,351 +1,10 @@
{
"files.associations": {
".*": ".cc",
"debug.h": "c",
"mpu_armv7.h": "c",
"core_cm3.h": "c",
"mpu.h": "c",
"gd32f10x.h": "c",
"mkrtos.h": "c",
"config.h": "c",
"assert.h": "c",
"dev_object.h": "c",
"sys.h": "c",
"gd32f10x_libopt.h": "c",
"delay.h": "c",
"gd32_sys.h": "c",
"stm32_sys.h": "c",
"stm32f2xx_conf.h": "c",
"sched.h": "c",
"stdio.h": "c",
"stm32f2xx.h": "c",
"tty.h": "c",
"fs.h": "c",
"system_stm32f2xx.h": "c",
"cpio.h": "c",
"dev.h": "c",
"knl_service.h": "c",
"sp.h": "c",
"fcntl.h": "c",
"stat.h": "c",
"types.h": "c",
"paths.h": "c",
"endian.h": "c",
"dietfeatures.h": "c",
"stackgap-common.h": "c",
"string.h": "c",
"features.h": "c",
"typeinfo": "c",
"embfeatures.h": "c",
"unistd.h": "c",
"fp_lib.h": "c",
"stdint.h": "c",
"int_math.h": "c",
"int_endianness.h": "c",
"cstdio": "c",
"math.h": "c",
"ieeefp.h": "c",
"int_lib.h": "c",
"cdefs.h": "c",
"softfloat.h": "c",
"sfp-machine.h": "c",
"soft-fp.h": "c",
"quad.h": "c",
"double.h": "c",
"*.inc": "c",
"half.h": "c",
"softfloat-for-gcc.h": "c",
"mkrtos_su.h": "c",
"array": "c",
"functional": "c",
"istream": "c",
"ostream": "c",
"tuple": "c",
"type_traits": "c",
"utility": "c",
"arch.h": "c",
"list.h": "c",
"typeindex": "c",
"mm.h": "c",
"atomic.h": "c",
"slist.h": "c",
"exec.h": "c",
"bitset": "c",
"knl_mutex.h": "c",
"knl_msg.h": "c",
"msg.h": "c",
"reboot.h": "c",
"random": "cpp",
"util.h": "c",
"factory.h": "c",
"prot.h": "c",
"ram_limit.h": "c",
"task.h": "c",
"mm_wrap.h": "c",
"ctype.h": "c",
"kobject.h": "c",
"misc.h": "c",
"cpulock.h": "c",
"init.h": "c",
"uart.h": "c",
"stdarg.h": "c",
"xprintf.h": "c",
"globals.h": "c",
"thread.h": "c",
"chrono": "c",
"ratio": "c",
"log.h": "c",
"syscall.h": "c",
"scheduler.h": "c",
"thread_armv7m.h": "c",
"printk.h": "c",
"obj_space.h": "c",
"u_types.h": "c",
"u_log.h": "c",
"u_prot.h": "c",
"u_arch.h": "c",
"errno.h": "c",
"crt_arch.h": "c",
"stdio_impl.h": "c",
"uio.h": "c",
"fs_backend.h": "c",
"mm_space.h": "c",
"mm_page.h": "c",
"u_task.h": "c",
"cpiofs.h": "c",
"u_factory.h": "c",
"u_thread.h": "c",
"u_app.h": "c",
"u_util.h": "c",
"u_mm.h": "c",
"u_ipc.h": "c",
"ref.h": "c",
"map.h": "c",
"ipc.h": "c",
"err.h": "c",
"diskio.h": "c",
"ff.h": "c",
"u_hd_man.h": "c",
"pthread.h": "c",
"*.in": "cpp",
"syscall_backend.h": "c",
"misc_backend.h": "c",
"queue.h": "c",
"irq.h": "c",
"irq_sender.h": "c",
"u_irq_sender.h": "c",
"u_env.h": "c",
"stddef.h": "c",
"u_rpc.h": "c",
"namespace.h": "c",
"u_rpc_svr.h": "c",
"rpc_prot.h": "c",
"ns_types.h": "c",
"ns_svr.h": "c",
"u_rpc_2.h": "c",
"ns_cli.h": "c",
"fs_cli.h": "c",
"u_rpc_1.h": "c",
"__config": "c",
"stm32f10x.h": "c",
"variant": "c",
"soft_iic.h": "c",
"sysinfo.h": "c",
"u_sleep.h": "c",
"hmi_user_uart.h": "c",
"usart3.h": "c",
"u_local_thread.h": "c",
"string": "c",
"string_view": "c",
"vector": "c",
"cstddef": "c",
"usart2.h": "c",
"hmi_lcd_process.h": "c",
"stdlib.h": "c",
"auto_close.h": "c",
"u_sys.h": "c",
"relay.h": "c",
"spi1.h": "c",
"led.h": "c",
"adc.h": "c",
"w25q64.h": "c",
"__bit_reference": "c",
"unordered_map": "c",
"__strerror.h": "c",
"sstream": "c",
"u_drv.h": "c",
"__node_handle": "c",
"__hash_table": "c",
"__tuple": "c",
"limits": "c",
"compare": "c",
"algorithm": "c",
"music_control.h": "c",
"__split_buffer": "c",
"initializer_list": "c",
"spi2.h": "c",
"wk2xx.h": "c",
"cwchar": "c",
"test.h": "c",
"uart5.h": "c",
"wk2xx_hw.h": "c",
"cstdlib": "c",
"locale": "c",
"uart4.h": "c",
"u_queue.h": "c",
"dirent.h": "c",
"iosfwd": "c",
"drv_adc.h": "c",
"mrboard.h": "c",
"mrapi.h": "c",
"device_port.h": "c",
"spi.h": "c",
"mr_board.h": "c",
"mr_config.h": "c",
"drv_svr.h": "c",
"drv_types.h": "c",
"ios": "c",
"mr_def.h": "c",
"drv_rpc.h": "c",
"rtdbg.h": "c",
"rtdevice.h": "c",
"rtthread.h": "c",
"driver.h": "c",
"char.h": "c",
"block.h": "c",
"graphic.h": "c",
"mtd.h": "c",
"net.h": "c",
"ringbuffer.h": "c",
"completion.h": "c",
"dataqueue.h": "c",
"workqueue.h": "c",
"waitqueue.h": "c",
"pipe.h": "c",
"ringblk_buf.h": "c",
"poll.h": "c",
"pin.h": "c",
"rtconfig.h": "c",
"bus.h": "c",
"dm.h": "c",
"platform.h": "c",
"rtdef.h": "c",
"rtc.h": "c",
"board.h": "c",
"drv_common.h": "c",
"drv_can.h": "c",
"drv_gpio.h": "c",
"drv_config.h": "c",
"dma_config.h": "c",
"drv_lptim.h": "c",
"uart_config.h": "c",
"drv_crypto.h": "c",
"drv_log.h": "c",
"drv_usart.h": "c",
"__locale": "c",
"__string": "c",
"limits.h": "c",
"ctime": "c",
"pthread_impl.h": "c",
"time.h": "c",
"u_thread_util.h": "c",
"__mutex_base": "c",
"mutex": "c",
"__threading_support": "c",
"spinlock.h": "c",
"mr_api.h": "c",
"u_app_loader.h": "c",
"process_manager.h": "c",
"fs_svr.h": "c",
"pm_svr.h": "c",
"cons_cli.h": "c",
"access.h": "c",
"shell.h": "c",
"shell_cfg.h": "c",
"__memory": "c",
"optional": "c",
"system_error": "c",
"__dirent.h": "c",
"shell_fs.h": "c",
"shell_passthrough.h": "c",
"u_slist.h": "c",
"atomic": "c",
"futex.h": "c",
"u_rpc_buf.h": "c",
"pm_cli.h": "c",
"u_sig.h": "c",
"u_err.h": "c",
"core_cmfunc.h": "c",
"stm32f4xx.h": "c",
"malloc.h": "c",
"ethernetif.h": "c",
"netif.h": "c",
"netconf.h": "c",
"dhcp.h": "c",
"u_intr.h": "c",
"etharp.h": "c",
"pbuf.h": "c",
"stm32f4x7_eth.h": "c",
"lan8270.h": "c",
"dm9000.h": "c",
"mk_sys.h": "c",
"sram.h": "c",
"semaphore.h": "c",
"libc.h": "c",
"printf.h": "c",
"printf_config.h": "c",
"net_drv_svr.h": "c",
"net_drv_types.h": "c",
"__tree": "c",
"filesystem": "c",
"u_share_mem.h": "c",
"fs_rpc.h": "c",
"net_drv_cli.h": "c",
"deque": "c",
"map": "c",
"regex": "c",
"set": "c",
"stack": "c",
"stm32f10x_conf.h": "c",
"system_swm341.h": "c",
"swm341.h": "c",
"mpu_armv8.h": "c",
"stm32f4xx_conf.h": "c",
"knl_misc.h": "c",
"dev_touch.h": "c",
"version.h": "c",
"tp_ft5206.h": "c",
"radio_button_widge.h": "c",
"x_types.h": "c",
"mem_dev.h": "c",
"group_widge.h": "c",
"xwindows.h": "c",
"color.h": "c",
"arm_math.h": "c",
"arm_const_structs.h": "c",
"arm_common_tables.h": "c",
"widget_define.h": "c",
"paint.h": "c",
"gui_interface_extern.h": "c",
"gui.h": "c",
"gui_timeout.h": "c",
"bitmap.h": "c",
"early_boot.h": "c",
"sysregs.h": "c",
"types_asm.h": "c",
"pager.h": "c",
"thread_arch.h": "c",
"aarch64_ptregs.h": "c",
"psci.h": "c",
"buddy.h": "c",
"atomics.h": "c",
"asm_config.h": "c",
"slab.h": "c",
"arm_local_reg.h": "c",
"timer.h": "c",
"arm_gicv2.h": "c",
"sched_arch.h": "c",
"thread_task_arch.h": "c"
"cpio.h": "c",
"elf64.h": "c",
"aarch64_ptregs.h": "c"
},
"cortex-debug.showRTOS": false,
"cortex-debug.variableUseNaturalFormat": false,

View File

@@ -33,6 +33,6 @@ set(compile_time "${DATE}\" \"${TIME}" CACHE STRING " " FORCE)
add_subdirectory(mkrtos_bootstrap)
add_subdirectory(mkrtos_knl)
# add_subdirectory(mkrtos_img)
# add_subdirectory(mkrtos_user)
add_subdirectory(mkrtos_user)

View File

@@ -117,4 +117,4 @@ CONFIG_CPU=4
CONFIG_THREAD_BLOCK_SIZE=0x1000
CONFIG_PAGE_SHIFT=12
CONFIG_MMU=y
CONFIG_KNL_TEST=y
CONFIG_KNL_TEST=n

View File

@@ -11,9 +11,10 @@
#pragma once
#include "types.h"
#include "arch.h"
#include <thread_arch.h>
#include <aarch64_ptregs.h>
#define ARCH_WORD_SIZE 64
#define LOG_INTR_NO 37 // USART1_IRQn
/// @brief 线程信息

View File

@@ -0,0 +1,4 @@
#pragma once
#include <types.h>
int elf_load(umword_t elf_data);

34
mkrtos_knl/inc/lib/cpio.h Normal file
View File

@@ -0,0 +1,34 @@
#pragma once
#include <types.h>
//! 26bytes
#pragma pack(1)
typedef struct cpio_fs
{
char c_magic[6];
char c_ino[8];
char c_mode[8];
char c_uid[8];
char c_gid[8];
char c_nlink[8];
char c_mtime[8];
char c_filesize[8];
char c_devmajor[8];
char c_devminor[8];
char c_rdevmajor[8];
char c_rdevminor[8];
char c_namesize[8];
char c_check[8];
} cpio_fs_t;
static inline int64_t check_magic(char *magic)
{
if (magic[0] == '0' && magic[1] == '7' && magic[2] == '0' &&
magic[3] == '7' && magic[4] == '0' && magic[5] == '1')
{
return 0;
}
return -1;
}
int htoi(char *str, int len);
umword_t cpio_find_file(umword_t st, umword_t en, const char *name);

View File

@@ -2,6 +2,7 @@
#include "types.h"
int memcmp(const void *vl, const void *vr, size_t n);
void *memccpy(void *dst, const void *src, int c, size_t count);
void memcpy(void *dst, void *src, size_t len);
void *memset(void *dst, char s, size_t count);

118
mkrtos_knl/knl/elf64.c Normal file
View File

@@ -0,0 +1,118 @@
#include <types.h>
typedef uint16_t Elf64_Half;
typedef uint32_t Elf64_Word;
typedef uint64_t Elf64_Addr;
typedef uint64_t Elf64_Off;
typedef uint64_t Elf64_Xword;
#define EI_NIDENT (16)
#pragma pack(1)
typedef struct
{
unsigned char e_ident[EI_NIDENT]; /* 一个字节数组用来确认文件是否是一个ELF文件 */
Elf64_Half e_type; /* 描述文件是,可执行文件elf=2,重定位so=3 */
Elf64_Half e_machine; /* 目标主机架构 */
Elf64_Word e_version; /* ELF文件格式的版本 */
Elf64_Addr e_entry; /* 入口点虚拟地址 */
Elf64_Off e_phoff; /* 程序头文件偏移 */
Elf64_Off e_shoff; /* 节头表文件偏移 */
Elf64_Word e_flags; /* ELF文件标志 */
Elf64_Half e_ehsize; /* ELF头大小 */
Elf64_Half e_phentsize; /* 程序头大小 */
Elf64_Half e_phnum; /* 程序头表计数 */
Elf64_Half e_shentsize; /* 节头表大小 */
Elf64_Half e_shnum; /* 节头表计数 */
Elf64_Half e_shstrndx; /* 字符串表索引节头 */
} Elf64_Ehdr;
#pragma pack(1)
typedef struct
{
Elf64_Word p_type; /* Segment type */
Elf64_Word p_flags; /* Segment flags */
Elf64_Off p_offset; /* Segment file offset */
Elf64_Addr p_vaddr; /* Segment virtual address */
Elf64_Addr p_paddr; /* Segment physical address */
Elf64_Xword p_filesz; /* Segment size in file */
Elf64_Xword p_memsz; /* Segment size in memory */
Elf64_Xword p_align; /* Segment alignment */
} Elf64_Phdr;
#define PT_NULL 0 /* Program header table entry unused */
#define PT_LOAD 1 /* Loadable program segment */
#define PT_DYNAMIC 2 /* Dynamic linking information */
#define PT_INTERP 3 /* Program interpreter */
#define PT_NOTE 4 /* Auxiliary information */
#define PT_SHLIB 5 /* Reserved */
#define PT_PHDR 6 /* Entry for header table itself */
#define PT_TLS 7 /* Thread-local storage segment */
#define PT_NUM 8 /* Number of defined types */
#define PT_LOOS 0x60000000 /* Start of OS-specific */
#define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */
#define PT_GNU_STACK 0x6474e551 /* Indicates stack executability */
#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */
#define PT_LOSUNW 0x6ffffffa
#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */
#define PT_SUNWSTACK 0x6ffffffb /* Stack segment */
#define PT_HISUNW 0x6fffffff
#define PT_HIOS 0x6fffffff /* End of OS-specific */
#define PT_LOPROC 0x70000000 /* Start of processor-specific */
#define PT_HIPROC 0x7fffffff /* End of processor-specific */
#define ET_NONE 0
#define ET_REL 1
#define ET_EXEC 2
#define ET_DYN 3
#define ET_CORE 4
#define ET_NUM 5
#define ET_LOOS 0xfe00
#define ET_HIOS 0xfeff
#define ET_LOPROC 0xff00
#define ET_HIPROC 0xffff
#define ELFMAG "\177ELF"
#define SELFMAG 4
#include <string.h>
#include <printk.h>
int elf_check(Elf64_Ehdr *ehdr)
{
if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0)
{
return -1;
}
if (ehdr->e_type != ET_EXEC)
{
return -1;
}
/*TODO:check arch.*/
return 0;
}
int elf_load(umword_t elf_data)
{
int ret;
Elf64_Ehdr *elf_header;
elf_header = (Elf64_Ehdr *)elf_data;
ret = elf_check(elf_header);
if (ret != 0)
{
return ret;
}
int size = elf_header->e_phentsize;
Elf64_Phdr *elf_phdr = (Elf64_Phdr *)(elf_header->e_phoff + elf_data);
for (int i = 0; i < elf_header->e_phnum; i++, elf_phdr++)
{
if (elf_phdr->p_type == PT_LOAD)
{
printk("[] paddr:0x%x vaddr:0x%x memsize:%d filesize:%d\n",
elf_phdr->p_vaddr, elf_phdr->p_paddr, elf_phdr->p_memsz, elf_phdr->p_filesz);
// 申请内存拷贝数据然后转移给ini_task
// memcpy((char *)elf_phdr->p_paddr, (char *)(elf_data + elf_phdr->p_offset),
// elf_phdr->p_filesz);
}
}
}

View File

@@ -22,10 +22,14 @@
#include "mm_wrap.h"
#include "thread_task_arch.h"
#include "knl_misc.h"
#include <assert.h>
#if IS_ENABLED(CONFIG_KNL_TEST)
#include <knl_test.h>
#endif
#if ARCH_WORD_SIZE == 64
#include <elf64.h>
#endif
#include <cpio.h>
static uint8_t knl_msg_buf[THREAD_MSG_BUG_LEN];
static thread_t *knl_thread;
@@ -101,7 +105,6 @@ static void knl_init_1(void)
}
INIT_STAGE1(knl_init_1);
/**
* 初始化init线程
* 初始化用户态任务
@@ -115,33 +118,41 @@ static void knl_init_2(void)
#if IS_ENABLED(CONFIG_KNL_TEST)
knl_test();
#else
init_thread = thread_create(&root_factory_get()->limit);
assert(init_thread);
init_task = task_create(&root_factory_get()->limit, FALSE);
assert(init_task);
app_info_t *app = app_info_get((void *)(CONFIG_KNL_TEXT_ADDR + CONFIG_INIT_TASK_OFFSET));
// 申请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;
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);
thread_bind(init_thread, &init_task->kobj);
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);
assert(obj_map_root(&init_thread->kobj, &init_task->obj_space, &root_factory_get()->limit, vpage_create3(KOBJ_ALL_RIGHTS, 0, THREAD_PROT)));
assert(obj_map_root(&init_task->kobj, &init_task->obj_space, &root_factory_get()->limit, vpage_create3(KOBJ_ALL_RIGHTS, 0, TASK_PROT)));
for (int i = FACTORY_PORT_START; i < FACTORY_PORT_END; i++)
{
kobject_t *kobj = global_get_kobj(i);
if (kobj)
{
assert(obj_map_root(kobj, &init_task->obj_space, &root_factory_get()->limit, vpage_create3(KOBJ_ALL_RIGHTS, 0, i)));
}
}
init_thread->sche.prio = 2;
init_task->pid = 0;
thread_ready(init_thread, FALSE);
extern mword_t cpio_images;
umword_t ret_addr;
ret_addr = cpio_find_file(cpio_images, (umword_t)(-1), "init.elf");
assert(ret_addr);
elf_load(ret_addr);
// init_thread = thread_create(&root_factory_get()->limit);
// assert(init_thread);
// init_task = task_create(&root_factory_get()->limit, FALSE);
// assert(init_task);
// app_info_t *app = app_info_get((void *)(CONFIG_KNL_TEXT_ADDR + CONFIG_INIT_TASK_OFFSET));
// // 申请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;
// 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);
// thread_bind(init_thread, &init_task->kobj);
// 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);
// assert(obj_map_root(&init_thread->kobj, &init_task->obj_space, &root_factory_get()->limit, vpage_create3(KOBJ_ALL_RIGHTS, 0, THREAD_PROT)));
// assert(obj_map_root(&init_task->kobj, &init_task->obj_space, &root_factory_get()->limit, vpage_create3(KOBJ_ALL_RIGHTS, 0, TASK_PROT)));
// for (int i = FACTORY_PORT_START; i < FACTORY_PORT_END; i++)
// {
// kobject_t *kobj = global_get_kobj(i);
// if (kobj)
// {
// assert(obj_map_root(kobj, &init_task->obj_space, &root_factory_get()->limit, vpage_create3(KOBJ_ALL_RIGHTS, 0, i)));
// }
// }
// init_thread->sche.prio = 2;
// init_task->pid = 0;
// thread_ready(init_thread, FALSE);
#endif
}
INIT_STAGE2(knl_init_2);

82
mkrtos_knl/lib/cpio.c Normal file
View File

@@ -0,0 +1,82 @@
#include "mk_sys.h"
#include "cpio.h"
#include <string.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b)) //!< 最小值
#define ALIGN(mem, align) (((mem) + ((align) - 1)) & (~((align) - 1))) //!< 向上对齐
umword_t cpio_find_file(umword_t st, umword_t en, const char *name)
{
uint8_t rByte;
int32_t bk_inx;
cpio_fs_t *file_info;
for (umword_t i = st; st < en;)
{
file_info = (cpio_fs_t *)i;
if (check_magic((char *)file_info) < 0)
{
return 0;
}
int name_size = htoi(file_info->c_namesize, 8);
const char *f_name = (char *)(i + sizeof(cpio_fs_t));
if (strcmp(f_name, name) == 0)
{
return (mword_t)(ALIGN(i + sizeof(cpio_fs_t) + name_size, 4));
}
if (strcmp("TRAILER!!!", f_name) == 0)
{
return 0;
}
int file_size = htoi(file_info->c_filesize, 8);
i = ALIGN(ALIGN(i + sizeof(cpio_fs_t) + name_size, 4) +
file_size,
4);
}
return 0;
}
int htoi(char *str, int len)
{
int n = 0;
int i = 0;
if (str == NULL || len <= 0)
return -1;
for (i = 0; i < len; i++)
{
if (str[i] != '0')
{
break;
}
}
str += i;
while (1)
{
if (*str >= '0' && *str <= '9')
{
n = 16 * n + (*str - '0');
}
else if (*str >= 'A' && *str <= 'F') // 十六进制还要判断字符是不是在A-F或者a-f之间
{
n = 16 * n + (*str - 'A' + 10);
}
else if (*str >= 'a' && *str <= 'f')
{
n = 16 * n + (*str - 'a' + 10);
}
else
{
break;
}
str++;
i++;
if (i >= len)
{
break;
}
}
return n;
}

View File

@@ -1,6 +1,13 @@
#include "types.h"
#include "string.h"
int memcmp(const void *vl, const void *vr, size_t n)
{
const unsigned char *l=vl, *r=vr;
for (; n && *l == *r; n--, l++, r++);
return n ? *l-*r : 0;
}
void *memccpy(void *dst, const void *src, int c, size_t count)
{
char *a = dst;

View File

@@ -1,22 +1,32 @@
cmake_minimum_required(VERSION 3.13)
# -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-fPIC -fPIE -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
-D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
" )
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
# add_subdirectory(dietlibc)
add_subdirectory(sys)
add_subdirectory(sys_util)
add_subdirectory(sys_svr)
add_subdirectory(modbus)
add_subdirectory(stm32f1_bsp)
add_subdirectory(libc_backend)
add_subdirectory(mlibc)
add_subdirectory(cpio)
add_subdirectory(util)
add_subdirectory(mr)
add_subdirectory(lwip)
add_subdirectory(printf)
add_subdirectory(letter-shell/demo/mkrtos)
# add_subdirectory(at_device)
if (${CONFIG_ARCH} STREQUAL "cortex-m3" OR
${CONFIG_ARCH} STREQUAL "cortex-m4" OR
${CONFIG_ARCH} STREQUAL "cortex-m33"
)
# -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-fPIC -fPIE -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-fPIC -fPIE -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
" )
# add_subdirectory(dietlibc)
add_subdirectory(sys_util)
add_subdirectory(sys_svr)
add_subdirectory(modbus)
add_subdirectory(stm32f1_bsp)
add_subdirectory(libc_backend)
add_subdirectory(mlibc)
add_subdirectory(cpio)
add_subdirectory(util)
add_subdirectory(mr)
add_subdirectory(lwip)
add_subdirectory(printf)
add_subdirectory(letter-shell/demo/mkrtos)
# add_subdirectory(at_device)
elseif(${CONFIG_ARCH} STREQUAL "aarch64")
#TODO:
endif()

View File

@@ -1,14 +1,9 @@
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-fPIC -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
-D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
" )
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
file(GLOB_RECURSE deps *.c *.S)
file(GLOB deps src/*.c src/*.S)
file(GLOB deps_arch ${CONFIG_ARCH}/*.c ${CONFIG_ARCH}/*.S)
file(APPEND deps deps_arch)
add_library(
sys
STATIC

1
mkrtos_user/lib/sys/deps Normal file
View File

@@ -0,0 +1 @@
deps_archdeps_archdeps_archdeps_arch

View File

@@ -0,0 +1,10 @@
.text
/*
int mk_syscall(int nr, ...)
*/
.global mk_syscall
.type mk_syscall, %function
mk_syscall:
hvc 0
ret

View File

@@ -0,0 +1,19 @@
.syntax unified
.text
/*
int mk_syscall(int nr, ...)
*/
.global mk_syscall
.type mk_syscall, %function
mk_syscall:
push {r4-r7}
mov r7, r0
mov r0, r1
mov r1, r2
mov r2, r3
add r6, sp,#16
ldmia r6,{r3-r5}
svc 128
pop {r4-r7}
bx lr

View File

@@ -0,0 +1,19 @@
.syntax unified
.text
/*
int mk_syscall(int nr, ...)
*/
.global mk_syscall
.type mk_syscall, %function
mk_syscall:
push {r4-r7}
mov r7, r0
mov r0, r1
mov r1, r2
mov r2, r3
add r6, sp,#16
ldmia r6,{r3-r5}
svc 128
pop {r4-r7}
bx lr

View File

@@ -1,13 +1,16 @@
cmake_minimum_required(VERSION 3.13)
if (${CONFIG_ARCH} STREQUAL "cortex-m3" OR
${CONFIG_ARCH} STREQUAL "cortex-m4" OR
${CONFIG_ARCH} STREQUAL "cortex-m33"
)
# -n -pie -fpie -fpic
# -msingle-pic-base -mno-pic-data-is-text-relative
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-fPIC -fPIE -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
-D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
")
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-fPIC -fPIE -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
" )
include_directories(
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/libc_backend/inc
)
@@ -22,3 +25,6 @@ add_subdirectory(test)
# add_subdirectory(net)
# add_subdirectory(tcc-0.9.27)
add_subdirectory(tinycc-arm-thumb)
elseif(${CONFIG_ARCH} STREQUAL "aarch64" )
#TODO:
endif()

View File

@@ -27,7 +27,10 @@ message(======="CPU_TYPE=${CONFIG_CPU_TYPE}")
# -mfloat-abi=soft -u _printf_float -lc -lrdimon
#-mfpu=fpv5-sp-d16
if (${CONFIG_ARCH} STREQUAL "cortex-m3" OR ${CONFIG_ARCH} STREQUAL "cortex-m4")
if (${CONFIG_ARCH} STREQUAL "cortex-m3" OR
${CONFIG_ARCH} STREQUAL "cortex-m4" OR
${CONFIG_ARCH} STREQUAL "cortex-m33"
)
include(armv7_8.cmake)
elseif(${CONFIG_ARCH} STREQUAL "aarch64" )
include(aarch64.cmake)