forked from xuos/xiuos
Change Service dir structure, erase uncessary hardkernel functions.
This commit is contained in:
parent
18eff4334c
commit
3b011500f1
|
@ -77,6 +77,10 @@ BOOT_STACK_SIZE = 0x4000;
|
||||||
RAM_VECTORS_SIZE = 72;
|
RAM_VECTORS_SIZE = 72;
|
||||||
|
|
||||||
/* Specify the memory areas */
|
/* Specify the memory areas */
|
||||||
|
/*
|
||||||
|
ddr3: physical area: [0x10000000, 0x50000000);
|
||||||
|
virt_ddr3: virt area exclude boot(start_sec), that will be [0x90000000 + 0x11000, 0xD0000000)
|
||||||
|
*/
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
ocram (rwx) : ORIGIN = 0x00900000, LENGTH = 256K
|
ocram (rwx) : ORIGIN = 0x00900000, LENGTH = 256K
|
||||||
|
@ -154,7 +158,7 @@ SECTIONS
|
||||||
PROVIDE(boot_end_addr = .);
|
PROVIDE(boot_end_addr = .);
|
||||||
} > ddr3
|
} > ddr3
|
||||||
|
|
||||||
/* Other Kernel code is placed over 0x80000000 + 128KB. */
|
/* Other Kernel code is placed over 0x10011000(phy) and 0x90011000(virt). */
|
||||||
.text : AT(0x10011000) {
|
.text : AT(0x10011000) {
|
||||||
*(.vectors)
|
*(.vectors)
|
||||||
. = ALIGN(0x1000);
|
. = ALIGN(0x1000);
|
||||||
|
|
|
@ -156,29 +156,11 @@ static uint32_t _hw_cur_int_num(uint32_t int_info)
|
||||||
return int_info & 0x1FF;
|
return int_info & 0x1FF;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t _hw_cur_int_cpu(uint32_t int_info)
|
|
||||||
{
|
|
||||||
return (int_info >> 10) & 0x7;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _hw_after_irq(uint32_t int_info)
|
static void _hw_after_irq(uint32_t int_info)
|
||||||
{
|
{
|
||||||
gic_write_end_of_irq(int_info);
|
gic_write_end_of_irq(int_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _is_interruptable(void)
|
|
||||||
{
|
|
||||||
uint32_t val;
|
|
||||||
|
|
||||||
__asm__ __volatile__(
|
|
||||||
"mrs %0, cpsr"
|
|
||||||
: "=r"(val)
|
|
||||||
:
|
|
||||||
:);
|
|
||||||
|
|
||||||
return !(val & DIS_INT);
|
|
||||||
}
|
|
||||||
|
|
||||||
int _cur_cpu_id()
|
int _cur_cpu_id()
|
||||||
{
|
{
|
||||||
return cpu_get_current();
|
return cpu_get_current();
|
||||||
|
@ -196,10 +178,8 @@ static struct XiziTrapDriver xizi_trap_driver = {
|
||||||
|
|
||||||
.bind_irq_handler = _bind_irq_handler,
|
.bind_irq_handler = _bind_irq_handler,
|
||||||
|
|
||||||
.is_interruptable = _is_interruptable,
|
|
||||||
.hw_before_irq = _hw_before_irq,
|
.hw_before_irq = _hw_before_irq,
|
||||||
.hw_cur_int_num = _hw_cur_int_num,
|
.hw_cur_int_num = _hw_cur_int_num,
|
||||||
.hw_cur_int_cpu = _hw_cur_int_cpu,
|
|
||||||
.hw_after_irq = _hw_after_irq,
|
.hw_after_irq = _hw_after_irq,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -163,29 +163,11 @@ static uint32_t _hw_cur_int_num(uint32_t int_info)
|
||||||
return int_info & XSCUGIC_ACK_INTID_MASK;
|
return int_info & XSCUGIC_ACK_INTID_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t _hw_cur_int_cpu(uint32_t int_info)
|
|
||||||
{
|
|
||||||
return (int_info >> 5) & 0x3;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _hw_after_irq(uint32_t int_info)
|
static void _hw_after_irq(uint32_t int_info)
|
||||||
{
|
{
|
||||||
XScuGic_CPUWriteReg(&IntcInstance, XSCUGIC_EOI_OFFSET, int_info);
|
XScuGic_CPUWriteReg(&IntcInstance, XSCUGIC_EOI_OFFSET, int_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _is_interruptable(void)
|
|
||||||
{
|
|
||||||
uint32_t val;
|
|
||||||
|
|
||||||
__asm__ __volatile__(
|
|
||||||
"mrs %0, cpsr"
|
|
||||||
: "=r"(val)
|
|
||||||
:
|
|
||||||
:);
|
|
||||||
|
|
||||||
return !(val & DIS_INT);
|
|
||||||
}
|
|
||||||
|
|
||||||
int _cur_cpu_id()
|
int _cur_cpu_id()
|
||||||
{
|
{
|
||||||
return cpu_get_current();
|
return cpu_get_current();
|
||||||
|
@ -203,10 +185,8 @@ static struct XiziTrapDriver xizi_trap_driver = {
|
||||||
|
|
||||||
.bind_irq_handler = _bind_irq_handler,
|
.bind_irq_handler = _bind_irq_handler,
|
||||||
|
|
||||||
.is_interruptable = _is_interruptable,
|
|
||||||
.hw_before_irq = _hw_before_irq,
|
.hw_before_irq = _hw_before_irq,
|
||||||
.hw_cur_int_num = _hw_cur_int_num,
|
.hw_cur_int_num = _hw_cur_int_num,
|
||||||
.hw_cur_int_cpu = _hw_cur_int_cpu,
|
|
||||||
.hw_after_irq = _hw_after_irq,
|
.hw_after_irq = _hw_after_irq,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,6 @@ struct irq_table_entry {
|
||||||
struct XiziTrapDriver {
|
struct XiziTrapDriver {
|
||||||
/* irq number table*/
|
/* irq number table*/
|
||||||
struct irq_table_entry sw_irqtbl[NR_IRQS];
|
struct irq_table_entry sw_irqtbl[NR_IRQS];
|
||||||
/* current irq number happening in cpu*/
|
|
||||||
uint32_t curr_int[NR_CPU];
|
|
||||||
|
|
||||||
void (*sys_irq_init)(int);
|
void (*sys_irq_init)(int);
|
||||||
int (*cur_cpu_id)();
|
int (*cur_cpu_id)();
|
||||||
|
@ -71,11 +69,9 @@ struct XiziTrapDriver {
|
||||||
void (*bind_irq_handler)(int, irq_handler_t);
|
void (*bind_irq_handler)(int, irq_handler_t);
|
||||||
|
|
||||||
/* check if no if interruptable */
|
/* check if no if interruptable */
|
||||||
int (*is_interruptable)();
|
|
||||||
/* code runs before irq handling */
|
/* code runs before irq handling */
|
||||||
uint32_t (*hw_before_irq)();
|
uint32_t (*hw_before_irq)();
|
||||||
uint32_t (*hw_cur_int_num)(uint32_t int_info);
|
uint32_t (*hw_cur_int_num)(uint32_t int_info);
|
||||||
uint32_t (*hw_cur_int_cpu)(uint32_t int_info);
|
|
||||||
/* code runs after irq handling */
|
/* code runs after irq handling */
|
||||||
void (*hw_after_irq)(uint32_t int_info);
|
void (*hw_after_irq)(uint32_t int_info);
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,24 +38,6 @@ Modification:
|
||||||
// extern struct MmuCommonDone mmu_common_done;
|
// extern struct MmuCommonDone mmu_common_done;
|
||||||
static struct MmuDriverRightGroup right_group;
|
static struct MmuDriverRightGroup right_group;
|
||||||
|
|
||||||
void load_pgdir_critical(uintptr_t pgdir_paddr, struct TraceTag* intr_driver_tag)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* get cache driver */
|
|
||||||
struct ICacheDone* p_icache_done = AchieveResource(&right_group.icache_driver_tag);
|
|
||||||
struct DCacheDone* p_dcache_done = AchieveResource(&right_group.dcache_driver_tag);
|
|
||||||
|
|
||||||
/* get intr driver */
|
|
||||||
struct XiziTrapDriver* p_intr_driver = AchieveResource(intr_driver_tag);
|
|
||||||
|
|
||||||
p_intr_driver->cpu_irq_disable();
|
|
||||||
TTBR0_W((uint32_t)pgdir_paddr);
|
|
||||||
CLEARTLB(0);
|
|
||||||
p_icache_done->invalidateall();
|
|
||||||
p_dcache_done->flushall();
|
|
||||||
p_intr_driver->cpu_irq_enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
void load_pgdir(uintptr_t pgdir_paddr)
|
void load_pgdir(uintptr_t pgdir_paddr)
|
||||||
{
|
{
|
||||||
/* get cache driver */
|
/* get cache driver */
|
||||||
|
@ -94,7 +76,6 @@ static struct MmuCommonDone mmu_common_done = {
|
||||||
.MmuUsrDevPteAttr = GetUsrDevPteAttr,
|
.MmuUsrDevPteAttr = GetUsrDevPteAttr,
|
||||||
.MmuKernPteAttr = GetKernPteAttr,
|
.MmuKernPteAttr = GetKernPteAttr,
|
||||||
|
|
||||||
.LoadPgdirCrit = load_pgdir_critical,
|
|
||||||
.LoadPgdir = load_pgdir,
|
.LoadPgdir = load_pgdir,
|
||||||
.TlbFlushAll = tlb_flush_all,
|
.TlbFlushAll = tlb_flush_all,
|
||||||
.TlbFlush = tlb_flush_range,
|
.TlbFlush = tlb_flush_range,
|
||||||
|
|
|
@ -27,7 +27,6 @@ struct MmuCommonDone
|
||||||
void (*MmuUsrDevPteAttr)(uintptr_t* attr);
|
void (*MmuUsrDevPteAttr)(uintptr_t* attr);
|
||||||
void (*MmuKernPteAttr)(uintptr_t* attr);
|
void (*MmuKernPteAttr)(uintptr_t* attr);
|
||||||
|
|
||||||
void (*LoadPgdirCrit)(uintptr_t pgdir_paddr, struct TraceTag*);
|
|
||||||
void (*LoadPgdir)(uintptr_t pgdir_paddr);
|
void (*LoadPgdir)(uintptr_t pgdir_paddr);
|
||||||
void (*TlbFlushAll)();
|
void (*TlbFlushAll)();
|
||||||
void (*TlbFlush)(uintptr_t vaddr, int len);
|
void (*TlbFlush)(uintptr_t vaddr, int len);
|
||||||
|
|
|
@ -19,6 +19,8 @@ c_useropts = -O0
|
||||||
INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \
|
INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \
|
||||||
-I$(KERNEL_ROOT)/services/lib/ipc \
|
-I$(KERNEL_ROOT)/services/lib/ipc \
|
||||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
-I$(KERNEL_ROOT)/services/lib/memory \
|
||||||
|
-I$(KERNEL_ROOT)/services/lib/serial \
|
||||||
|
-I$(KERNEL_ROOT)/services/lib/usyscall \
|
||||||
-I$(KERNEL_ROOT)/services/fs/libfs \
|
-I$(KERNEL_ROOT)/services/fs/libfs \
|
||||||
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
||||||
-I$(KERNEL_ROOT)/services/app
|
-I$(KERNEL_ROOT)/services/app
|
||||||
|
@ -37,44 +39,44 @@ bin:
|
||||||
@mkdir -p bin
|
@mkdir -p bin
|
||||||
|
|
||||||
ifeq ($(BOARD), imx6q-sabrelite)
|
ifeq ($(BOARD), imx6q-sabrelite)
|
||||||
test_irq_send: test_irq_sender.o usyscall.o libserial.o
|
test_irq_send: test_irq_sender.o usyscall.o arch_usyscall.o libserial.o
|
||||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||||
@${objdump} -S $@ > $@.asm
|
@${objdump} -S $@ > $@.asm
|
||||||
endif
|
endif
|
||||||
|
|
||||||
test_irq_block: test_irq_block.o libserial.o libipc.o session.o usyscall.o libmem.o
|
test_irq_block: test_irq_block.o libserial.o libipc.o session.o usyscall.o arch_usyscall.o libmem.o
|
||||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||||
@${objdump} -S $@ > $@.asm
|
@${objdump} -S $@ > $@.asm
|
||||||
|
|
||||||
test_irq_hdlr: test_irq_handler.o libserial.o libipc.o session.o usyscall.o libmem.o
|
test_irq_hdlr: test_irq_handler.o libserial.o libipc.o session.o usyscall.o arch_usyscall.o libmem.o
|
||||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||||
@${objdump} -S $@ > $@.asm
|
@${objdump} -S $@ > $@.asm
|
||||||
|
|
||||||
shell: shell_port.o libserial.o shell_cmd_list.o shell.o shell_ext.o libfs_to_client.o libipc.o session.o usyscall.o libmem.o
|
shell: shell_port.o libserial.o shell_cmd_list.o shell.o shell_ext.o libfs_to_client.o libipc.o session.o usyscall.o arch_usyscall.o libmem.o
|
||||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||||
@${objdump} -S $@ > $@.asm
|
@${objdump} -S $@ > $@.asm
|
||||||
|
|
||||||
init: init.o libfs_to_client.o libipc.o session.o libserial.o usyscall.o libmem.o
|
init: init.o libfs_to_client.o libipc.o session.o libserial.o usyscall.o arch_usyscall.o libmem.o
|
||||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||||
@${objdump} -S $@ > $@.asm
|
@${objdump} -S $@ > $@.asm
|
||||||
|
|
||||||
test_fs: test_fs.o libfs_to_client.o libipc.o session.o libserial.o usyscall.o libmem.o
|
test_fs: test_fs.o libfs_to_client.o libipc.o session.o libserial.o usyscall.o arch_usyscall.o libmem.o
|
||||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||||
@${objdump} -S $@ > $@.asm
|
@${objdump} -S $@ > $@.asm
|
||||||
|
|
||||||
simple_client: simple_client.o libserial.o libipc.o session.o simple_service.o libfs_to_client.o usyscall.o libmem.o
|
simple_client: simple_client.o libserial.o libipc.o session.o simple_service.o libfs_to_client.o usyscall.o arch_usyscall.o libmem.o
|
||||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||||
@${objdump} -S $@ > $@.asm
|
@${objdump} -S $@ > $@.asm
|
||||||
|
|
||||||
simple_server: simple_server.o libserial.o libipc.o session.o simple_service.o usyscall.o libmem.o
|
simple_server: simple_server.o libserial.o libipc.o session.o simple_service.o usyscall.o arch_usyscall.o libmem.o
|
||||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||||
@${objdump} -S $@ > $@.asm
|
@${objdump} -S $@ > $@.asm
|
||||||
|
|
||||||
fs_server: fs_server.o libfs_to_client.o fs.o libserial.o libipc.o session.o block_io.o usyscall.o libmem.o
|
fs_server: fs_server.o libfs_to_client.o fs.o libserial.o libipc.o session.o block_io.o usyscall.o arch_usyscall.o libmem.o
|
||||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||||
@${objdump} -S $@ > $@.asm
|
@${objdump} -S $@ > $@.asm
|
||||||
|
|
||||||
test_priority: test_priority.o libserial.o usyscall.o libmem.o
|
test_priority: test_priority.o libserial.o usyscall.o arch_usyscall.o libmem.o
|
||||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||||
@${objdump} -S $@ > $@.asm
|
@${objdump} -S $@ > $@.asm
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,12 @@ c_useropts = -O0
|
||||||
INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \
|
INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \
|
||||||
-I$(KERNEL_ROOT)/services/lib/ipc \
|
-I$(KERNEL_ROOT)/services/lib/ipc \
|
||||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
-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/boards/$(BOARD) \
|
||||||
-I$(KERNEL_ROOT)/services/app
|
-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
|
@mv $^ ../../app
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
|
|
|
@ -9,10 +9,25 @@
|
||||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
* See the Mulan PSL v2 for more details.
|
* See the Mulan PSL v2 for more details.
|
||||||
*/
|
*/
|
||||||
|
#include "usyscall.h"
|
||||||
|
|
||||||
/// this file is only used for debug
|
int syscall(int sys_num, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4)
|
||||||
#pragma once
|
{
|
||||||
|
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;
|
||||||
|
}
|
|
@ -19,10 +19,12 @@ INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \
|
||||||
-I$(KERNEL_ROOT)/services/fs/fs_server/include \
|
-I$(KERNEL_ROOT)/services/fs/fs_server/include \
|
||||||
-I$(KERNEL_ROOT)/services/lib/ipc \
|
-I$(KERNEL_ROOT)/services/lib/ipc \
|
||||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
-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/boards/$(BOARD) \
|
||||||
-I$(KERNEL_ROOT)/services/app
|
-I$(KERNEL_ROOT)/services/app
|
||||||
|
|
||||||
board: libserial.o stub.o usyscall.o
|
board: libserial.o stub.o arch_usyscall.o
|
||||||
@mv $^ ../../app
|
@mv $^ ../../app
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
|
@ -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,6 +19,8 @@ INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \
|
||||||
-I$(KERNEL_ROOT)/services/fs/fs_server/include \
|
-I$(KERNEL_ROOT)/services/fs/fs_server/include \
|
||||||
-I$(KERNEL_ROOT)/services/lib/ipc \
|
-I$(KERNEL_ROOT)/services/lib/ipc \
|
||||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
-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/boards/$(BOARD) \
|
||||||
-I$(KERNEL_ROOT)/services/app
|
-I$(KERNEL_ROOT)/services/app
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ c_useropts = -O0
|
||||||
INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \
|
INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \
|
||||||
-I$(KERNEL_ROOT)/services/lib/ipc \
|
-I$(KERNEL_ROOT)/services/lib/ipc \
|
||||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
-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/boards/$(BOARD) \
|
||||||
-I$(KERNEL_ROOT)/services/app
|
-I$(KERNEL_ROOT)/services/app
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
SRC_DIR := ipc memory
|
SRC_DIR := ipc memory usyscall
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ c_useropts = -O0
|
||||||
|
|
||||||
INC_DIR = -I$(KERNEL_ROOT)/services/lib/ipc \
|
INC_DIR = -I$(KERNEL_ROOT)/services/lib/ipc \
|
||||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
-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/boards/$(BOARD) \
|
||||||
-I$(KERNEL_ROOT)/services/app
|
-I$(KERNEL_ROOT)/services/app
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@ INC_DIR = -I$(KERNEL_ROOT)/services/app \
|
||||||
-I$(KERNEL_ROOT)/services/fs/libfs \
|
-I$(KERNEL_ROOT)/services/fs/libfs \
|
||||||
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
||||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
-I$(KERNEL_ROOT)/services/lib/memory \
|
||||||
|
-I$(KERNEL_ROOT)/services/lib/serial \
|
||||||
|
-I$(KERNEL_ROOT)/services/lib/usyscall \
|
||||||
-I$(KERNEL_ROOT)/services/lib/ipc
|
-I$(KERNEL_ROOT)/services/lib/ipc
|
||||||
|
|
||||||
all: libmem.o
|
all: libmem.o
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
ifeq ($(BOARD), imx6q-sabrelite)
|
||||||
|
toolchain ?= arm-none-eabi-
|
||||||
|
endif
|
||||||
|
ifeq ($(BOARD), zynq7000-zc702)
|
||||||
|
toolchain ?= arm-xilinx-eabi-
|
||||||
|
endif
|
||||||
|
cc = ${toolchain}gcc
|
||||||
|
ld = ${toolchain}g++
|
||||||
|
objdump = ${toolchain}objdump
|
||||||
|
user_ldflags = -N -Ttext 0
|
||||||
|
|
||||||
|
cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie
|
||||||
|
c_useropts = -O0
|
||||||
|
|
||||||
|
INC_DIR = -I$(KERNEL_ROOT)/services/app \
|
||||||
|
-I$(KERNEL_ROOT)/services/fs/libfs \
|
||||||
|
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
||||||
|
-I$(KERNEL_ROOT)/services/lib/memory \
|
||||||
|
-I$(KERNEL_ROOT)/services/lib/serial \
|
||||||
|
-I$(KERNEL_ROOT)/services/lib/usyscall \
|
||||||
|
-I$(KERNEL_ROOT)/services/lib/ipc
|
||||||
|
|
||||||
|
all: usyscall.o
|
||||||
|
@mv $^ ../../app
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
@echo "cc $^"
|
||||||
|
@${cc} ${cflags} ${c_useropts} ${INC_DIR} -o $@ -c $^
|
|
@ -12,28 +12,6 @@
|
||||||
#include "usyscall.h"
|
#include "usyscall.h"
|
||||||
#include "libmem.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 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);
|
int file_size = ipc_fsize(session, fd);
|
|
@ -62,6 +62,8 @@ typedef int (*ipc_read_fn)(struct Session* session, int fd, char* dst, int offse
|
||||||
typedef int (*ipc_fsize_fn)(struct Session* session, int fd);
|
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);
|
typedef int (*ipc_write_fn)(struct Session* session, int fd, char* src, int offset, int len);
|
||||||
|
|
||||||
|
int syscall(int sys_num, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4);
|
||||||
|
|
||||||
int spawn(struct Session* session, int fd, ipc_read_fn ipc_read, ipc_fsize_fn ipc_fsize, char* name, char** argv);
|
int spawn(struct Session* session, int fd, ipc_read_fn ipc_read, ipc_fsize_fn ipc_fsize, char* name, char** argv);
|
||||||
int exit();
|
int exit();
|
||||||
int yield(task_yield_reason reason);
|
int yield(task_yield_reason reason);
|
|
@ -18,6 +18,8 @@ c_useropts = -O0
|
||||||
INC_DIR = -I$(KERNEL_ROOT)/services/app \
|
INC_DIR = -I$(KERNEL_ROOT)/services/app \
|
||||||
-I$(KERNEL_ROOT)/services/fs/libfs \
|
-I$(KERNEL_ROOT)/services/fs/libfs \
|
||||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
-I$(KERNEL_ROOT)/services/lib/memory \
|
||||||
|
-I$(KERNEL_ROOT)/services/lib/serial \
|
||||||
|
-I$(KERNEL_ROOT)/services/lib/usyscall \
|
||||||
-I$(KERNEL_ROOT)/services/lib/ipc \
|
-I$(KERNEL_ROOT)/services/lib/ipc \
|
||||||
-I$(KERNEL_ROOT)/services/boards/$(BOARD)
|
-I$(KERNEL_ROOT)/services/boards/$(BOARD)
|
||||||
|
|
||||||
|
|
|
@ -46,11 +46,11 @@ bool intr_distributer_init(struct IrqDispatcherRightGroup* _right_group)
|
||||||
return p_intr_driver != NULL;
|
return p_intr_driver != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void default_interrupt_routine(void)
|
void default_interrupt_routine(int irq)
|
||||||
{
|
{
|
||||||
/* default handler borrow the rights of dispatcher */
|
/* default handler borrow the rights of dispatcher */
|
||||||
///@todo Support other cores. (currently assume that CPU_0 is used)
|
///@todo Support other cores. (currently assume that CPU_0 is used)
|
||||||
ERROR("Interrupt %d has been asserted\n", p_intr_driver->curr_int[0]);
|
ERROR("Interrupt %d has been asserted\n", irq);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void context_switch(struct context**, struct context*);
|
extern void context_switch(struct context**, struct context*);
|
||||||
|
@ -69,20 +69,19 @@ void intr_irq_dispatch(struct trapframe* tf)
|
||||||
assert(current_task != NULL);
|
assert(current_task != NULL);
|
||||||
current_task->main_thread.trapframe = tf;
|
current_task->main_thread.trapframe = tf;
|
||||||
|
|
||||||
unsigned cpu = p_intr_driver->hw_cur_int_cpu(int_info);
|
int cpu = cur_cpuid();
|
||||||
|
assert(cpu >= 0 && cpu < NR_CPU);
|
||||||
unsigned irq = p_intr_driver->hw_cur_int_num(int_info);
|
unsigned irq = p_intr_driver->hw_cur_int_num(int_info);
|
||||||
p_intr_driver->curr_int[cpu] = irq;
|
|
||||||
|
|
||||||
// distribute irq
|
// distribute irq
|
||||||
irq_handler_t isr = p_intr_driver->sw_irqtbl[irq].handler;
|
irq_handler_t isr = p_intr_driver->sw_irqtbl[irq].handler;
|
||||||
if (isr != NULL) {
|
if (isr != NULL) {
|
||||||
isr(irq, tf, NULL);
|
isr(irq, tf, NULL);
|
||||||
} else {
|
} else {
|
||||||
default_interrupt_routine();
|
default_interrupt_routine(irq);
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish irq.
|
// finish irq.
|
||||||
p_intr_driver->curr_int[cpu] = 0;
|
|
||||||
p_intr_driver->hw_after_irq(int_info);
|
p_intr_driver->hw_after_irq(int_info);
|
||||||
|
|
||||||
if (cur_cpu()->task == NULL || current_task->state != RUNNING) {
|
if (cur_cpu()->task == NULL || current_task->state != RUNNING) {
|
||||||
|
|
Loading…
Reference in New Issue