diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/clock/arm/armv7-a/cortex-a9/zynq7000-zc702/clock.c b/Ubiquitous/XiZi_AIoT/hardkernel/clock/arm/armv7-a/cortex-a9/zynq7000-zc702/clock.c index 9f2665c12..f65fd7cd3 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/clock/arm/armv7-a/cortex-a9/zynq7000-zc702/clock.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/clock/arm/armv7-a/cortex-a9/zynq7000-zc702/clock.c @@ -35,7 +35,7 @@ Modification: #include "log.h" XScuTimer global_timer; -#define TIMER_LOAD_VALUE 0xFFFF +#define TIMER_LOAD_VALUE 0x514C7 static void _sys_clock_init() { diff --git a/Ubiquitous/XiZi_AIoT/kernel_actracer/Readme.txt b/Ubiquitous/XiZi_AIoT/kernel_actracer/Readme.txt new file mode 100644 index 000000000..d8d0f55fb --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/kernel_actracer/Readme.txt @@ -0,0 +1,13 @@ +Actracer接口: + +bool AchieveResourceTag(struct TraceTag* target, struct TraceTag* owner, char* name): + 将owner资源(以tag标识)下属名为name的资源标识(tag)的值赋给传入的target。(调用者自行创建target并负责其生命周期) + +void* AchieveResource(struct TraceTag* target): + 若资源给定存储的形式为指针,则根据给入的target标识,返回资源的指针。 + +bool CreateResourceTag(struct TraceTag* new_tag, struct TraceTag* owner, char* name, tracemeta_ac_type type, void* p_resource): + 在owner资源下,创建一个名为name的资源,并将该资源的标识赋值给new_tag。(调用者自行创建target并负责其生命周期) + +bool DeleteResource(struct TraceTag* target, struct TraceTag* owner): + 删除owner资源下属以target标识的资源。 diff --git a/Ubiquitous/XiZi_AIoT/kernel_actracer/actracer.c b/Ubiquitous/XiZi_AIoT/kernel_actracer/actracer.c index eedfe2b61..32dcbf651 100644 --- a/Ubiquitous/XiZi_AIoT/kernel_actracer/actracer.c +++ b/Ubiquitous/XiZi_AIoT/kernel_actracer/actracer.c @@ -495,7 +495,7 @@ void tracer_find_tag(struct TraceTag* target, struct TraceTag* const source, cha bool AchieveResourceTag(struct TraceTag* target, struct TraceTag* owner, char* name) { tracer_find_tag(target, owner, name); - if (target == NULL) { + if (target->meta == NULL) { return false; } return true; diff --git a/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/Makefile b/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/Makefile index 5502b38e2..71ddf042c 100644 --- a/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/Makefile @@ -18,7 +18,7 @@ INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \ -I$(KERNEL_ROOT)/services/boards/$(BOARD) \ -I$(KERNEL_ROOT)/services/app -libserial: libserial.o +board: libserial.o usyscall.o @mv $^ ../../app %.o: %.c diff --git a/Ubiquitous/XiZi_AIoT/services/app/usyscall.c b/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/usyscall.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/app/usyscall.c rename to Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/usyscall.c diff --git a/Ubiquitous/XiZi_AIoT/services/app/usyscall.h b/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/usyscall.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/app/usyscall.h rename to Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/usyscall.h diff --git a/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/Makefile b/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/Makefile index a579b284e..f312ba643 100644 --- a/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/Makefile @@ -21,7 +21,7 @@ INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \ -I$(KERNEL_ROOT)/services/boards/$(BOARD) \ -I$(KERNEL_ROOT)/services/app -libserial: libserial.o stub.o +board: libserial.o stub.o usyscall.o @mv $^ ../../app %.o: %.c diff --git a/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/usyscall.c b/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/usyscall.c new file mode 100644 index 000000000..c03893a43 --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/usyscall.c @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2020 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#include "usyscall.h" + +static int +syscall(int sys_num, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4) +{ + int ret = -1; + + __asm__ volatile( + "mov r0, %1;\ + mov r1, %2;\ + mov r2, %3;\ + mov r3, %4;\ + mov r4, %5;\ + swi 0;\ + dsb;\ + isb;\ + mov %0, r0" + : "=r"(ret) + : "r"(sys_num), "r"(a1), "r"(a2), "r"(a3), "r"(a4) + : "memory", "r0", "r1", "r2", "r3", "r4"); + + return ret; +} + +int spawn(struct Session* session, int fd, ipc_read_fn ipc_read, char* name, char** argv) +{ + struct KernReadTool read_tool = { + .session = session, + .fd = fd, + .ipc_read = ipc_read, + }; + return syscall(SYSCALL_SPAWN, (intptr_t)&read_tool, (intptr_t)name, (intptr_t)argv, 0); +} + +int exit() +{ + return syscall(SYSCALL_EXIT, 0, 0, 0, 0); +} + +int yield() +{ + return syscall(SYSCALL_YIELD, 0, 0, 0, 0); +} + +int register_server(char* name) +{ + return syscall(SYSCALL_SERVER, (intptr_t)name, 0, 0, 0); +} + +int session(char* path, int capacity, struct Session* user_session) +{ + return syscall(SYSCALL_SESSION, (intptr_t)path, (intptr_t)capacity, (intptr_t)user_session, 0); +} + +int poll_session(struct Session* userland_session_arr, int arr_capacity) +{ + return syscall(SYSCALL_POLL_SESSION, (intptr_t)userland_session_arr, (intptr_t)arr_capacity, 0, 0); +} + +int close_session(struct Session* session) +{ + return syscall(SYSCALL_CLOSE_SESSION, (intptr_t)session, 0, 0, 0); +} + +int get_memblock_info(sys_state_info* info) +{ + return syscall(SYSCALL_SYS_STATE, SYS_STATE_MEMBLOCK_INFO, (intptr_t)info, 0, 0); +} + +int set_priority(sys_state_info* info) +{ + return syscall(SYSCALL_SYS_STATE, SYS_STATE_SET_TASK_PRIORITY, (intptr_t)info, 0, 0); +} + +int task_heap_base() +{ + return syscall(SYSCALL_SYS_STATE, SYS_STATE_GET_HEAP_BASE, 0, 0, 0); +} + +int show_task() +{ + return syscall(SYSCALL_SYS_STATE, SYS_STATE_SHOW_TASKS, 0, 0, 0); +} + +int show_mem() +{ + return syscall(SYSCALL_SYS_STATE, SYS_STATE_SHOW_MEM_INFO, 0, 0, 0); +} + +int show_cpu() +{ + return syscall(SYSCALL_SYS_STATE, SYS_STATE_SHOW_CPU_INFO, 0, 0, 0); +} + +int mmap(uintptr_t vaddr, uintptr_t paddr, int len, bool is_dev) +{ + return syscall(SYSCALL_MMAP, vaddr, paddr, (intptr_t)len, (intptr_t)is_dev); +} + +int register_irq(int irq, int opcode) +{ + return syscall(SYSCALL_REGISTER_IRQ, (intptr_t)irq, (intptr_t)opcode, 0, 0); +} \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/usyscall.h b/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/usyscall.h new file mode 100644 index 000000000..65ab3cd6f --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/usyscall.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2020 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#pragma once +#include + +#include "libserial.h" +#include "session.h" + +// clang-format off +#define SYSCALL_TEST 0 +#define SYSCALL_SPAWN 1 // generate a brand new task to run elf +#define SYSCALL_EXIT 2 // exit task, delete the task cb +#define SYSCALL_YIELD 3 // yield task, go to scheduler + +#define SYSCALL_MMAP 4 // map a virt page to phy page +#define SYSCALL_SERVER 5 // register current task as a server +#define SYSCALL_SESSION 6 // create a session to a server +#define SYSCALL_POLL_SESSION 7 // server poll for it's server sessions +#define SYSCALL_CLOSE_SESSION 8 // client close it's client sessions + +#define SYSCALL_EXEC 9 // run elf using current task +#define SYSCALL_SYS_STATE 10 // run system state +#define SYSCALL_REGISTER_IRQ 11 // +// clang-format on + +typedef enum { + SYS_STATE_TEST = 0, + SYS_STATE_SET_TASK_PRIORITY, + SYS_STATE_GET_HEAP_BASE, + SYS_STATE_MEMBLOCK_INFO, + SYS_STATE_SHOW_TASKS, + SYS_STATE_SHOW_MEM_INFO, + SYS_STATE_SHOW_CPU_INFO, +} sys_state_option; + +typedef union { + struct { + uintptr_t memblock_start; + uintptr_t memblock_end; + } memblock_info; + int priority; +} sys_state_info; + +typedef int (*ipc_read_fn)(struct Session* session, int fd, char* dst, int offset, int len); +typedef int (*ipc_write_fn)(struct Session* session, int fd, char* src, int offset, int len); + +struct KernReadTool { + struct Session* session; + int fd; + ipc_read_fn ipc_read; +}; + +int spawn(struct Session* session, int fd, ipc_read_fn ipc_read, char* name, char** argv); +int exit(); +int yield(); +int register_server(char* name); +int session(char* path, int capacity, struct Session* user_session); +int poll_session(struct Session* userland_session_arr, int arr_capacity); +int close_session(struct Session* session); +int task_heap_base(); +int get_memblock_info(sys_state_info* info); +int set_priority(sys_state_info* info); +int show_task(); +int show_mem(); +int show_cpu(); +int mmap(uintptr_t vaddr, uintptr_t paddr, int len, bool is_dev); +int register_irq(int irq, int opcode); \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/lib/ipc/Readme.txt b/Ubiquitous/XiZi_AIoT/services/lib/ipc/Readme.txt new file mode 100644 index 000000000..9dca77ff0 --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/lib/ipc/Readme.txt @@ -0,0 +1,31 @@ +libipc接口说明: + +libipc使用共享内存在两个进程之间实现进程间函数调用。 + +server的实现参考simple_server。 +1. 在server程序和client库函数共用的头文件(参考simple_service.h)中定义IPC_SERVICES, + I. 包含(1)服务名称,(2)服务提供的接口名。 + II. simple_service.h中还包含了client库函数提供的接口(add(), hello_string(),...),这些接口可以单独为一个头文件提供给用户。 + +2. 在client库中使用提供给用户的接口, + I. 使用默认形式的接口需要依照: + IPC_INTERFACE(1.I中定义的接口名,参数的个数,[函数中使用的参数名...],[各个参数占用的内存大小]); + II. 默认接口要求传入的“参数的实际内容”在共享内存中存在一份拷贝,因此在IPC_INTERFACE中需要给出“参数占用的内存大小”。 + III. 使用IPC_CALL(接口名)()调用IPC_INTERFACE中生成的消息发送函数,IPC_CALL(接口名)()中只接受指针参数(需传入IPC_INTERFACE中定义的参数名),指针指向“存储实际参数”的地址。 + 如hello_string()函数,IPC_CALL(Ipc_hello_string)传入(buf, &len),指针buf指向缓存数组的真正位置,指针&len指向存储(int)len的真正位置。 + IV. hello_string_nowait()给出了消息传输的真正逻辑: + (1) 在Session中创建Message; + (2) 使用ipc_msg_get_nth_arg_buf()和ipc_msg_set_nth_arg()为参数赋值。 + (3) 设置Message的操作码(此处为Ipc_hello_string); + (4) 调用ipc_msg_send_nowait()或ipc_msg_send()发送消息。 + +3. 定义server程序: + I. 在server的c文件(此处为simple_server.c)中定义IPC_DO_SERVE_FUNC(接口名)()中实现函数逻辑。(传入参数均为指针); + II. 为server定义在message中解析接口的函数,使用宏IPC_SERVER_INTERFACE(接口名,参数个数); + III. 向server处理表注册接口,使用IPC_SERVER_REGISTER_INTERFACES(服务名,接口个数,[接口名, ...]) ; + IV. 定义main函数: + (1) 初始化server所需的数据结构; + (2) 向操作系统注册服务:register_server(“用来访问服务的名称”); + (3) 调用ipc_server_loop():该函数单线程得处理传入到server的调用请求。 + +注:创建session时传入的大小必须大于后续在 使用session发起的调用中 参数实际所占的大小。 \ No newline at end of file