Change Service dir structure, erase uncessary hardkernel functions.

This commit is contained in:
TXuian
2024-05-08 15:22:08 +08:00
parent 18eff4334c
commit 3b011500f1
24 changed files with 121 additions and 314 deletions
@@ -15,10 +15,12 @@ c_useropts = -O0
INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \
-I$(KERNEL_ROOT)/services/lib/ipc \
-I$(KERNEL_ROOT)/services/lib/memory \
-I$(KERNEL_ROOT)/services/lib/serial \
-I$(KERNEL_ROOT)/services/lib/usyscall \
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
-I$(KERNEL_ROOT)/services/app
board: libserial.o usyscall.o test_irq_sender.o
board: libserial.o arch_usyscall.o test_irq_sender.o
@mv $^ ../../app
%.o: %.c
@@ -9,10 +9,25 @@
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#include "usyscall.h"
/// this file is only used for debug
#pragma once
int syscall(int sys_num, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4)
{
int ret = -1;
void printf(char* fmt, ...);
__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");
char getc();
return ret;
}
@@ -1,124 +0,0 @@
/*
* 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"
#include "libmem.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, ipc_fsize_fn ipc_fsize, char* name, char** argv)
{
int file_size = ipc_fsize(session, fd);
void* img = malloc(file_size);
int read_len = 0, cur_read_len = 0;
while (read_len < file_size) {
cur_read_len = file_size - read_len < 4096 ? file_size - read_len : 4096;
read_len += ipc_read(session, fd, img + read_len, read_len, cur_read_len);
}
int ret = syscall(SYSCALL_SPAWN, (intptr_t)img, (intptr_t)name, (intptr_t)argv, 0);
free(img);
return ret;
}
int exit()
{
return syscall(SYSCALL_EXIT, 0, 0, 0, 0);
}
int yield(task_yield_reason reason)
{
return syscall(SYSCALL_YIELD, (uintptr_t)reason, 0, 0, 0);
}
int kill(int pid)
{
return syscall(SYSCALL_KILL, (intptr_t)pid, 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);
}
@@ -1,80 +0,0 @@
/*
* 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 <stdint.h>
#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 //
#define SYSCALL_KILL 12 // kill the task by id
// 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 enum {
SYS_TASK_YIELD_NO_REASON = 0x0,
SYS_TASK_YIELD_FOREVER = 0x1,
SYS_TASK_YIELD_BLOCK_IPC = 0x2,
} task_yield_reason;
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_fsize_fn)(struct Session* session, int fd);
typedef int (*ipc_write_fn)(struct Session* session, int fd, char* src, int offset, int len);
int spawn(struct Session* session, int fd, ipc_read_fn ipc_read, ipc_fsize_fn ipc_fsize, char* name, char** argv);
int exit();
int yield(task_yield_reason reason);
int kill(int pid);
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);
@@ -19,10 +19,12 @@ INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \
-I$(KERNEL_ROOT)/services/fs/fs_server/include \
-I$(KERNEL_ROOT)/services/lib/ipc \
-I$(KERNEL_ROOT)/services/lib/memory \
-I$(KERNEL_ROOT)/services/lib/serial \
-I$(KERNEL_ROOT)/services/lib/usyscall \
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
-I$(KERNEL_ROOT)/services/app
board: libserial.o stub.o usyscall.o
board: libserial.o stub.o arch_usyscall.o
@mv $^ ../../app
%.o: %.c
@@ -9,10 +9,25 @@
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#include "usyscall.h"
/// this file is only used for debug
#pragma once
int syscall(int sys_num, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4)
{
int ret = -1;
void printf(char* fmt, ...);
__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");
char getc();
return ret;
}
@@ -1,124 +0,0 @@
/*
* 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"
#include "libmem.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, ipc_fsize_fn ipc_fsize, char* name, char** argv)
{
int file_size = ipc_fsize(session, fd);
void* img = malloc(file_size);
int read_len = 0, cur_read_len = 0;
while (read_len < file_size) {
cur_read_len = file_size - read_len < 4096 ? file_size - read_len : 4096;
read_len += ipc_read(session, fd, img + read_len, read_len, cur_read_len);
}
int ret = syscall(SYSCALL_SPAWN, (intptr_t)img, (intptr_t)name, (intptr_t)argv, 0);
free(img);
return ret;
}
int exit()
{
return syscall(SYSCALL_EXIT, 0, 0, 0, 0);
}
int yield(task_yield_reason reason)
{
return syscall(SYSCALL_YIELD, (uintptr_t)reason, 0, 0, 0);
}
int kill(int pid)
{
return syscall(SYSCALL_KILL, (intptr_t)pid, 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);
}
@@ -1,80 +0,0 @@
/*
* 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 <stdint.h>
#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 //
#define SYSCALL_KILL 12 // kill the task by id
// 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 enum {
SYS_TASK_YIELD_NO_REASON = 0x0,
SYS_TASK_YIELD_FOREVER = 0x1,
SYS_TASK_YIELD_BLOCK_IPC = 0x2,
} task_yield_reason;
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_fsize_fn)(struct Session* session, int fd);
typedef int (*ipc_write_fn)(struct Session* session, int fd, char* src, int offset, int len);
int spawn(struct Session* session, int fd, ipc_read_fn ipc_read, ipc_fsize_fn ipc_fsize, char* name, char** argv);
int exit();
int yield(task_yield_reason reason);
int kill(int pid);
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);