Support XiZi_AIoT
This commit is contained in:
43
Ubiquitous/XiZi_AIoT/softkernel/include/assert.h
Normal file
43
Ubiquitous/XiZi_AIoT/softkernel/include/assert.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file assert.h
|
||||
* @brief provide macro assert
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: assert.h
|
||||
Description: provide macro assert
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
#include "log.h"
|
||||
|
||||
extern void panic(char*);
|
||||
#define assert(condition) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
ERROR("(%s) failed\n", #condition); \
|
||||
panic("\n"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LIKELY(exp) __builtin_expect(exp, 1)
|
||||
#define UNLIKELY(exp) __builtin_expect(exp, 0)
|
||||
111
Ubiquitous/XiZi_AIoT/softkernel/include/buddy.h
Normal file
111
Ubiquitous/XiZi_AIoT/softkernel/include/buddy.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file buddy.h
|
||||
* @brief buddy algorithm header
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: buddy.h
|
||||
Description: buddy algorithm header
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "list.h"
|
||||
#include "memlayout.h"
|
||||
#include "spinlock.h"
|
||||
#include "pagetable.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define MAX_BUDDY_ORDER (10)
|
||||
|
||||
#define FREE_LIST_INDEX(order) \
|
||||
(1 << order)
|
||||
|
||||
#define IS_BUDDY_PAGE(buddy, order) \
|
||||
(buddy->order == order && buddy->node.next != &buddy->node)
|
||||
|
||||
#define BUDDY_PAGE_INDEX(page_idx, order) \
|
||||
(page_idx ^ (FREE_LIST_INDEX(order)))
|
||||
|
||||
#define COMBINED_PAGE_INDEX(page_idx, order) \
|
||||
(page_idx & ~(FREE_LIST_INDEX(order)))
|
||||
|
||||
#define CALCULATE_NPAGES(size) \
|
||||
(ALIGNUP(size, PAGE_SIZE) >> LEVEL4_PTE_SHIFT)
|
||||
|
||||
struct KPage {
|
||||
struct double_list_node node;
|
||||
union {
|
||||
uint32_t order;
|
||||
struct KPage* page_node;
|
||||
};
|
||||
uintptr_t mapped_addr;
|
||||
};
|
||||
|
||||
struct KFreeList {
|
||||
uint32_t n_free_pages;
|
||||
struct double_list_node list_head;
|
||||
};
|
||||
|
||||
#define MAX_NR_PAGES MAX_NR_FREE_PAGES
|
||||
struct KBuddy {
|
||||
uint32_t n_pages;
|
||||
uint32_t use_lock;
|
||||
struct spinlock lock;
|
||||
struct KFreeList free_list[MAX_BUDDY_ORDER];
|
||||
struct KPage* first_page;
|
||||
uint32_t mem_start;
|
||||
uint32_t mem_end;
|
||||
struct KPage pages[MAX_NR_PAGES];
|
||||
};
|
||||
|
||||
/*********************************************
|
||||
* Buddy system public functions
|
||||
*********************************************/
|
||||
/*
|
||||
* Buddy system init function
|
||||
* @param mem_start free memory region start
|
||||
* @param mem_end free memory region end
|
||||
* @return void
|
||||
*/
|
||||
void KBuddySysInit(struct KBuddy* pbuddy, uint32_t mem_start, uint32_t mem_end);
|
||||
|
||||
/*
|
||||
* Continuous pages alloc by size
|
||||
* @param size(uint32_t) size of need alloc
|
||||
* @return NULL or v_addr (char*) return NULL if alloc failed, or return virtual page's addr
|
||||
*/
|
||||
char* KBuddyAlloc(struct KBuddy* pbuddy, uint32_t size);
|
||||
|
||||
/*
|
||||
* Continuous pages free from vaddr
|
||||
* @param vaddr(char*) virtual addr
|
||||
* @param isFreeSuccess(bool) return false if free failed, or return true
|
||||
*/
|
||||
bool KBuddyFree(struct KBuddy* pbuddy, char* vaddr);
|
||||
|
||||
/*
|
||||
* Print current free pages for debug.
|
||||
*/
|
||||
void KFreePagesInfo(struct KBuddy* pbuddy);
|
||||
84
Ubiquitous/XiZi_AIoT/softkernel/include/execelf.h
Executable file
84
Ubiquitous/XiZi_AIoT/softkernel/include/execelf.h
Executable file
@@ -0,0 +1,84 @@
|
||||
/* Copyright (c) 2006-2018 Frans Kaashoek, Robert Morris, Russ Cox,
|
||||
* Massachusetts Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/**
|
||||
* @file execelf.h
|
||||
* @brief Format of an ELF executable file
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2024.11.23
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: execelf.h
|
||||
Description: Format of an ELF executable file
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2024-11-23
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. reserve only necessary elfhdr structs
|
||||
*************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define ELF_MAGIC 0x464C457FU // "\x7FELF" in little endian
|
||||
|
||||
// File header
|
||||
struct elfhdr {
|
||||
uint32_t magic; // must equal ELF_MAGIC
|
||||
uint8_t elf[12];
|
||||
uint16_t type;
|
||||
uint16_t machine;
|
||||
uint32_t version;
|
||||
uint32_t entry;
|
||||
uint32_t phoff;
|
||||
uint32_t shoff;
|
||||
uint32_t flags;
|
||||
uint16_t ehsize;
|
||||
uint16_t phentsize;
|
||||
uint16_t phnum;
|
||||
uint16_t shentsize;
|
||||
uint16_t shnum;
|
||||
uint16_t shstrndx;
|
||||
};
|
||||
|
||||
// Program section header
|
||||
struct proghdr {
|
||||
uint32_t type;
|
||||
uint32_t off;
|
||||
uint32_t vaddr;
|
||||
uint32_t paddr;
|
||||
uint32_t filesz;
|
||||
uint32_t memsz;
|
||||
uint32_t flags;
|
||||
uint32_t align;
|
||||
};
|
||||
|
||||
// Values for Proghdr type
|
||||
#define ELF_PROG_LOAD 1
|
||||
|
||||
// Flag bits for Proghdr flags
|
||||
#define ELF_PROG_FLAG_EXEC 1
|
||||
#define ELF_PROG_FLAG_WRITE 2
|
||||
#define ELF_PROG_FLAG_READ 4
|
||||
66
Ubiquitous/XiZi_AIoT/softkernel/include/ipc.h
Normal file
66
Ubiquitous/XiZi_AIoT/softkernel/include/ipc.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file ipc.h
|
||||
* @brief use share memory page to support inter process communication
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: ipc.h
|
||||
Description: use share memory page to support inter process communication
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
/* the content of this file must be the same with libipc.h */
|
||||
|
||||
#define IPC_MSG_MAGIC 0xABCDDCBA
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
uint64_t header;
|
||||
struct {
|
||||
uint64_t valid : 1; // for server to peek new msg
|
||||
uint64_t done : 1; // for client to check request done
|
||||
uint64_t init : 1; // for client to check request done
|
||||
uint64_t reserved : 1;
|
||||
uint64_t nr_args : 4;
|
||||
uint64_t opcode : 8;
|
||||
uint64_t len : 16;
|
||||
uint64_t magic : 32;
|
||||
};
|
||||
};
|
||||
int32_t ret_val;
|
||||
} __attribute__((packed)) ipc_msg_header;
|
||||
|
||||
struct IpcArgInfo {
|
||||
uint16_t offset;
|
||||
uint16_t len;
|
||||
};
|
||||
|
||||
/* [header, ipc_arg_buffer_len[], ipc_arg_buffer[]] */
|
||||
struct IpcMsg {
|
||||
ipc_msg_header header;
|
||||
uintptr_t buf[];
|
||||
};
|
||||
enum {
|
||||
IPC_ARG_INFO_BASE_OFFSET = sizeof(ipc_msg_header),
|
||||
};
|
||||
44
Ubiquitous/XiZi_AIoT/softkernel/include/kalloc.h
Normal file
44
Ubiquitous/XiZi_AIoT/softkernel/include/kalloc.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file kalloc.c
|
||||
* @brief kalloc, kfree kind of memory allocation support
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: kalloc.c
|
||||
Description: kalloc, kfree kind of memory allocation support
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "pagetable.h"
|
||||
|
||||
bool module_phymem_init();
|
||||
char* kalloc(uint32_t size);
|
||||
bool kfree(char* vaddr);
|
||||
|
||||
char* raw_alloc(uint32_t size);
|
||||
bool raw_free(char* paddr);
|
||||
|
||||
void show_phymem_info();
|
||||
|
||||
extern struct KBuddy user_phy_freemem_buddy;
|
||||
extern struct KBuddy kern_virtmem_buddy;
|
||||
41
Ubiquitous/XiZi_AIoT/softkernel/include/kern_init.h
Normal file
41
Ubiquitous/XiZi_AIoT/softkernel/include/kern_init.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file kern_init.h
|
||||
* @brief init function header
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: kern_init.h
|
||||
Description: init function header
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
#include "actracer.h"
|
||||
|
||||
struct XiziBootNode {
|
||||
char* name;
|
||||
char* bootinfo;
|
||||
bool (*init)();
|
||||
};
|
||||
|
||||
bool hardkernel_init(struct TraceTag*);
|
||||
bool softkernel_init(struct TraceTag* _hardkernel_tag, struct TraceTag* _softkernel_tag);
|
||||
void show_xizi_bar(void);
|
||||
103
Ubiquitous/XiZi_AIoT/softkernel/include/list.h
Normal file
103
Ubiquitous/XiZi_AIoT/softkernel/include/list.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file list.h
|
||||
* @brief double list support
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: list.h
|
||||
Description: double list support
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
|
||||
struct list_node {
|
||||
struct list_node* next;
|
||||
};
|
||||
|
||||
struct double_list_node {
|
||||
struct double_list_node *next;
|
||||
struct double_list_node *prev;
|
||||
};
|
||||
|
||||
#define CONTAINER_OF(item, type, member) \
|
||||
((type*)((char*)(item) - (unsigned long)(&((type*)0)->member)))
|
||||
|
||||
#define IS_DOUBLE_LIST_EMPTY(head) \
|
||||
((head)->next == (head))
|
||||
|
||||
/*********************************************
|
||||
*
|
||||
* Double linked list operation functions
|
||||
*
|
||||
*********************************************/
|
||||
#define DOUBLE_LIST_ENTRY(item, type, member) \
|
||||
CONTAINER_OF(item, type, member)
|
||||
|
||||
#define DOUBLE_LIST_FOR_EACH_ENTRY(item, head, member) \
|
||||
for (item = DOUBLE_LIST_ENTRY((head)->next, typeof(*item), member); \
|
||||
&item->member != (head); \
|
||||
item = DOUBLE_LIST_ENTRY(item->member.next, typeof(*item), member))
|
||||
|
||||
#define DOUBLE_LIST_FOR_EACH_ENTRY_REVERSE(item, head, member) \
|
||||
for (item = DOUBLE_LIST_ENTRY((head)->prev, typeof(*item), member); \
|
||||
&item->member != (head); \
|
||||
item = DOUBLE_LIST_ENTRY(item->member.prev, typeof(*item), member))
|
||||
|
||||
__attribute__((always_inline))
|
||||
static void inline doubleListNodeInit(struct double_list_node *list)
|
||||
{
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static void inline _double_list_add(struct double_list_node* new_node, struct double_list_node* prev, struct double_list_node* next)
|
||||
{
|
||||
next->prev = new_node;
|
||||
new_node->next = next;
|
||||
new_node->prev = prev;
|
||||
prev->next = new_node;
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
static void inline _double_list_del(struct double_list_node *prev, struct double_list_node *next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static void inline doubleListAddOnHead(struct double_list_node* new_node, struct double_list_node* head)
|
||||
{
|
||||
_double_list_add(new_node, head, head->next);
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static void inline doubleListAddOnBack(struct double_list_node* new_node, struct double_list_node* head)
|
||||
{
|
||||
_double_list_add(new_node, head->prev, head);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
static void inline doubleListDel(struct double_list_node *entry)
|
||||
{
|
||||
_double_list_del(entry->prev, entry->next);
|
||||
entry->next = entry;
|
||||
entry->prev = entry;
|
||||
}
|
||||
64
Ubiquitous/XiZi_AIoT/softkernel/include/log.h
Normal file
64
Ubiquitous/XiZi_AIoT/softkernel/include/log.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file log.h
|
||||
* @brief log support
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: log.h
|
||||
Description: log support
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
|
||||
#define OUTPUT_LEVLE_LOG 0
|
||||
#define OUTPUT_LEVLE_DEBUG 1
|
||||
#define OUTPUT_LEVLE_ERROR 2
|
||||
|
||||
#define OUTPUT_LEVLE OUTPUT_LEVLE_DEBUG
|
||||
|
||||
extern void KPrintf(char* fmt, ...);
|
||||
|
||||
#if (OUTPUT_LEVLE >= OUTPUT_LEVLE_LOG)
|
||||
#define LOG_PRINTF(f, args...) \
|
||||
KPrintf(f, ##args)
|
||||
#else
|
||||
#define LOG_PRINTF(f, args...)
|
||||
#endif
|
||||
|
||||
#define LOG(f, args...) \
|
||||
LOG_PRINTF("LOG: [%s] ", __func__); \
|
||||
LOG_PRINTF(f, ##args)
|
||||
|
||||
#if (OUTPUT_LEVLE >= OUTPUT_LEVLE_DEBUG)
|
||||
#define DEBUG_PRINTF(f, args...) \
|
||||
KPrintf(f, ##args)
|
||||
#else
|
||||
#define DEBUG_PRINTF(f, args...)
|
||||
#endif
|
||||
|
||||
#define DEBUG(f, args...) \
|
||||
DEBUG_PRINTF("DEBUG: [%s] ", __func__); \
|
||||
DEBUG_PRINTF(f, ##args)
|
||||
|
||||
#define ERROR(f, args...) \
|
||||
KPrintf("ERROR: [%s %d] ", __func__, __LINE__); \
|
||||
KPrintf(f, ##args)
|
||||
54
Ubiquitous/XiZi_AIoT/softkernel/include/mmio_access.h
Normal file
54
Ubiquitous/XiZi_AIoT/softkernel/include/mmio_access.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file mmio_access.h
|
||||
* @brief map phy mmio address t virt mmio address
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: mmio_access.h
|
||||
Description: map phy mmio address t virt mmio address
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include "memlayout.h"
|
||||
|
||||
#define MMIO_P2V_WO(paddr) ((DEV_VRTMEM_BASE - DEV_PHYMEM_BASE) + (paddr))
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
typedef uintptr_t mmio_reg_t;
|
||||
__attribute__((unused, always_inline)) static inline uintptr_t MMIO_P2V(uintptr_t paddr)
|
||||
{
|
||||
/// @todo use dtb rather than just mapping.
|
||||
return (DEV_VRTMEM_BASE - DEV_PHYMEM_BASE) + paddr;
|
||||
}
|
||||
|
||||
__attribute__((unused, always_inline)) static inline void mmio_write(uintptr_t paddr, mmio_reg_t value)
|
||||
{
|
||||
*(volatile mmio_reg_t*)(MMIO_P2V(paddr)) = (value);
|
||||
}
|
||||
|
||||
__attribute__((unused, always_inline)) static inline mmio_reg_t mmio_read(uintptr_t paddr)
|
||||
{
|
||||
return *(volatile mmio_reg_t*)(MMIO_P2V(paddr));
|
||||
}
|
||||
#endif
|
||||
47
Ubiquitous/XiZi_AIoT/softkernel/include/multicores.h
Normal file
47
Ubiquitous/XiZi_AIoT/softkernel/include/multicores.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file multicores.h
|
||||
* @brief cpu header
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: multicores.h
|
||||
Description: cpu header
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "core.h"
|
||||
#include "trap_common.h"
|
||||
|
||||
struct CPU {
|
||||
int cpuid;
|
||||
|
||||
struct TaskMicroDescriptor* task;
|
||||
struct context* scheduler;
|
||||
};
|
||||
|
||||
extern struct CPU global_cpus[NR_CPU];
|
||||
|
||||
static inline struct CPU* cur_cpu(void)
|
||||
{
|
||||
return &global_cpus[cur_cpuid()];
|
||||
}
|
||||
53
Ubiquitous/XiZi_AIoT/softkernel/include/object_allocator.h
Normal file
53
Ubiquitous/XiZi_AIoT/softkernel/include/object_allocator.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file object_allocator.h
|
||||
* @brief slab algorithm declaration
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: object_allocator.h
|
||||
Description: slab algorithm declaration
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct slab_state {
|
||||
struct slab_state *prev, *next;
|
||||
uint64_t bitmap;
|
||||
uintptr_t refcount;
|
||||
uint8_t data[] __attribute__((aligned(sizeof(void*))));
|
||||
};
|
||||
|
||||
struct slab_allocator {
|
||||
size_t element_size;
|
||||
size_t nr_elements;
|
||||
size_t slabsize;
|
||||
uint64_t bitmap_empty;
|
||||
struct slab_state *partial, *empty, *full;
|
||||
};
|
||||
|
||||
void slab_init(struct slab_allocator*, size_t);
|
||||
void slab_destroy(const struct slab_allocator*);
|
||||
|
||||
void* slab_alloc(struct slab_allocator*);
|
||||
void slab_free(struct slab_allocator*, const void*);
|
||||
77
Ubiquitous/XiZi_AIoT/softkernel/include/pagetable.h
Normal file
77
Ubiquitous/XiZi_AIoT/softkernel/include/pagetable.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file pagetable.h
|
||||
* @brief page table header
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: pagetable.h
|
||||
Description: page table header
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "memlayout.h"
|
||||
|
||||
#include "actracer.h"
|
||||
#include "mmu.h"
|
||||
#include "mmu_common.h"
|
||||
|
||||
// clang-format off
|
||||
#define ALIGNUP(sz, al) (((uint32_t)(sz) + (uint32_t)(al) - 1) & ~((uint32_t)(al) - 1))
|
||||
#define ALIGNDOWN(sz, al) ((uint32_t)(sz) & ~((uint32_t)(al) - 1))
|
||||
|
||||
#define LEVEL4_PTE_IDX(v) (((uintptr_t)(v) >> LEVEL4_PTE_SHIFT) & (NUM_LEVEL4_PTE - 1))
|
||||
#define LEVEL4_PTE_ADDR(v) ALIGNDOWN(v, LEVEL4_PTE_SIZE)
|
||||
|
||||
#define TOPLEVLE_PAGEDIR_SIZE sizeof(uintptr_t) * NUM_TOPLEVEL_PDE
|
||||
// clang-format on
|
||||
|
||||
struct TopLevelPageDirectory {
|
||||
uintptr_t* pd_addr;
|
||||
};
|
||||
|
||||
struct PagerRightGroup {
|
||||
struct TraceTag mmu_driver_tag;
|
||||
};
|
||||
|
||||
struct XiziPageManager {
|
||||
bool (*new_pgdir)(struct TopLevelPageDirectory* pgdir);
|
||||
void (*free_user_pgdir)(struct TopLevelPageDirectory* pgdir);
|
||||
bool (*map_pages)(uintptr_t* pgdir, uintptr_t vaddr, uintptr_t paddr, uintptr_t len, bool is_dev);
|
||||
bool (*unmap_pages)(uintptr_t* pgdir, uintptr_t vaddr, uintptr_t len);
|
||||
|
||||
uintptr_t (*resize_user_pgdir)(struct TopLevelPageDirectory* pgdir, uintptr_t old_size, uintptr_t new_size);
|
||||
uintptr_t (*address_translate)(struct TopLevelPageDirectory* pgdir, uintptr_t vaddr);
|
||||
uintptr_t (*cross_vspace_data_copy)(struct TopLevelPageDirectory* pgdir, uintptr_t cross_dest, uintptr_t src, uintptr_t len);
|
||||
};
|
||||
|
||||
extern struct MmuCommonDone* _p_pgtbl_mmu_access;
|
||||
uintptr_t* _page_walk(uintptr_t* pgdir, uintptr_t vaddr, bool alloc);
|
||||
|
||||
extern struct TopLevelPageDirectory kern_pgdir;
|
||||
void load_kern_pgdir(struct TraceTag* mmu_driver_tag);
|
||||
|
||||
extern struct XiziPageManager xizi_pager;
|
||||
bool module_pager_init(struct PagerRightGroup*);
|
||||
36
Ubiquitous/XiZi_AIoT/softkernel/include/scheduler.h
Normal file
36
Ubiquitous/XiZi_AIoT/softkernel/include/scheduler.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file scheduler.h
|
||||
* @brief scheduler algorithm declaration
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: scheduler.h
|
||||
Description: scheduler algorithm declaration
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "task.h"
|
||||
|
||||
struct TaskMicroDescriptor* max_priority_runnable_task(void);
|
||||
struct TaskMicroDescriptor* round_robin_runnable_task(uint32_t priority);
|
||||
void recover_priority(void);
|
||||
92
Ubiquitous/XiZi_AIoT/softkernel/include/share_page.h
Normal file
92
Ubiquitous/XiZi_AIoT/softkernel/include/share_page.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file share_page.h
|
||||
* @brief support share page for tasks
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: share_page.h
|
||||
Description: support share page for tasks
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "actracer.h"
|
||||
#include "list.h"
|
||||
#include "task.h"
|
||||
|
||||
/// @brief userland session info copy
|
||||
struct Session {
|
||||
int id;
|
||||
int capacity;
|
||||
int head;
|
||||
int tail;
|
||||
void* buf;
|
||||
};
|
||||
|
||||
#define SERVER_SESSION_BACKEND(session) CONTAINER_OF(session, struct session_backend, server_side)
|
||||
#define CLIENT_SESSION_BACKEND(session) CONTAINER_OF(session, struct session_backend, client_side)
|
||||
|
||||
struct server_session {
|
||||
struct double_list_node node; // list_head of server task's ipc pipes
|
||||
uintptr_t buf_addr;
|
||||
int capacity;
|
||||
int head;
|
||||
int tail;
|
||||
bool closed;
|
||||
};
|
||||
|
||||
struct client_session {
|
||||
struct double_list_node node; // list_head of client task's ipc pipes
|
||||
uintptr_t buf_addr;
|
||||
int capacity;
|
||||
bool closed;
|
||||
};
|
||||
|
||||
/// @brief kernel data struct to represent a ipc pipe, listed in client's task
|
||||
struct session_backend {
|
||||
struct server_session server_side;
|
||||
struct client_session client_side;
|
||||
int session_id; // id of this session
|
||||
int nr_pages; // pages used by this pipe
|
||||
struct TaskMicroDescriptor* client; // client of this pipe
|
||||
struct TaskMicroDescriptor* server; // server of this pipe
|
||||
|
||||
uintptr_t buf_kernel_addr;
|
||||
};
|
||||
|
||||
struct SharePageRightGroup {
|
||||
struct TraceTag dcache_driver_tag;
|
||||
struct TraceTag mmu_driver_tag;
|
||||
};
|
||||
|
||||
struct XiziSharePageManager {
|
||||
struct session_backend* (*create_share_pages)(struct TaskMicroDescriptor* client, struct TaskMicroDescriptor* server, const int capacity);
|
||||
void (*unmap_task_share_pages)(struct TaskMicroDescriptor* task, const uintptr_t task_vaddr, const int nr_pages);
|
||||
int (*delete_share_pages)(struct session_backend* session_backend);
|
||||
|
||||
uintptr_t (*task_map_pages)(struct TaskMicroDescriptor* task, const uintptr_t vaddr, const uintptr_t paddr, const int nr_pages, const int is_dev);
|
||||
};
|
||||
extern struct XiziSharePageManager xizi_share_page_manager;
|
||||
|
||||
int module_share_page_init(struct SharePageRightGroup* right_group);
|
||||
98
Ubiquitous/XiZi_AIoT/softkernel/include/syscall.h
Normal file
98
Ubiquitous/XiZi_AIoT/softkernel/include/syscall.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file syscall.h
|
||||
* @brief syscall header
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: syscall.h
|
||||
Description: syscall header
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
|
||||
// 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
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
#include <stdint.h>
|
||||
|
||||
#include "share_page.h"
|
||||
#include "task.h"
|
||||
|
||||
typedef enum {
|
||||
SYS_STATE_TEST = 0,
|
||||
SYS_STATE_MEMBLOCK_INFO,
|
||||
SYS_STATE_SET_TASK_PRIORITY,
|
||||
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;
|
||||
|
||||
/* fn pointer to access user server */
|
||||
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 syscall(int sys_num, uintptr_t param1, uintptr_t param2, uintptr_t param3, uintptr_t param4);
|
||||
|
||||
int sys_spawn(struct KernReadTool* read_tool, char* name, char** argv);
|
||||
int sys_exit();
|
||||
int sys_yield();
|
||||
|
||||
int sys_register_as_server(char* name);
|
||||
int sys_connect_session(char* path, int capacity, struct Session* user_session);
|
||||
int sys_poll_session(struct Session* userland_session_arr, int arr_capacity);
|
||||
int sys_close_session(struct Session* session);
|
||||
|
||||
int sys_exec(struct KernReadTool* read_tool, char* name, char** argv);
|
||||
int sys_state(sys_state_option option, sys_state_info* info);
|
||||
int sys_mmap(uintptr_t vaddr, uintptr_t paddr, int len, int is_dev);
|
||||
|
||||
int sys_register_irq(int irq_num, int irq_opcode);
|
||||
#endif
|
||||
132
Ubiquitous/XiZi_AIoT/softkernel/include/task.h
Normal file
132
Ubiquitous/XiZi_AIoT/softkernel/include/task.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* @file task.h
|
||||
* @brief task header
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.08.25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: task.h
|
||||
Description: task header
|
||||
Others:
|
||||
History:
|
||||
1. Date: 2023-08-28
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. first version
|
||||
*************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "core.h"
|
||||
|
||||
#include "list.h"
|
||||
#include "object_allocator.h"
|
||||
#include "pagetable.h"
|
||||
#include "share_page.h"
|
||||
#include "spinlock.h"
|
||||
|
||||
#define TASK_CLOCK_TICK 50
|
||||
#define TASK_MAX_PRIORITY 32
|
||||
#define TASK_DEFAULT_PRIORITY 1
|
||||
#define TASK_NAME_MAX_LEN 16
|
||||
|
||||
enum ProcState {
|
||||
INIT = 0,
|
||||
READY,
|
||||
RUNNING,
|
||||
DEAD,
|
||||
};
|
||||
|
||||
/* Thread Control Block */
|
||||
struct Thread {
|
||||
struct TaskMicroDescriptor* task; // process of current thread
|
||||
uintptr_t stack_addr; // [virt] stack base address
|
||||
struct context* context;
|
||||
struct trapframe* trapframe;
|
||||
};
|
||||
|
||||
/* Process Control Block */
|
||||
struct TaskMicroDescriptor {
|
||||
struct double_list_node node;
|
||||
|
||||
struct spinlock lock;
|
||||
/* task->lock needed */
|
||||
int pid;
|
||||
/// @todo support parent
|
||||
struct TaskMicroDescriptor* parent;
|
||||
enum ProcState state;
|
||||
/// @todo support ret value
|
||||
int ret; // state val that be returned to parent
|
||||
struct TopLevelPageDirectory pgdir; // [phy] vm pgtbl base address
|
||||
struct double_list_node cli_sess_listhead;
|
||||
struct double_list_node svr_sess_listhead;
|
||||
struct TraceTag server_identifier;
|
||||
|
||||
/* task->lock not necessary */
|
||||
struct Thread main_thread; // will only access by task itself
|
||||
int remain_tick;
|
||||
int maxium_tick;
|
||||
|
||||
struct TraceTag cwd; // current directory
|
||||
|
||||
int priority; // priority
|
||||
|
||||
/// @todo support mem_size
|
||||
uintptr_t mem_size; // mem size of proc used(allocated by kernel)
|
||||
char name[TASK_NAME_MAX_LEN];
|
||||
};
|
||||
|
||||
struct SchedulerRightGroup {
|
||||
struct TraceTag intr_driver_tag;
|
||||
struct TraceTag mmu_driver_tag;
|
||||
};
|
||||
|
||||
struct XiziTaskManager {
|
||||
struct spinlock lock; // lock to organize free and used task list
|
||||
struct double_list_node task_list_head[TASK_MAX_PRIORITY]; /* list of task control blocks that are allocated */
|
||||
int nr_pcb_used; // for debug
|
||||
struct slab_allocator task_allocator;
|
||||
|
||||
/// @todo Add pid to task
|
||||
uint32_t next_pid;
|
||||
|
||||
/* number of tcbs in which one page contains */
|
||||
int nr_tcb_per_page;
|
||||
|
||||
/* init task manager */
|
||||
void (*init)();
|
||||
/* new a task control block, checkout #sys_spawn for usage */
|
||||
struct TaskMicroDescriptor* (*new_task_cb)();
|
||||
/* free a task control block, this calls #free_user_pgdir to free all vitual spaces */
|
||||
void (*free_pcb)(struct TaskMicroDescriptor*);
|
||||
/* init a task control block, set name, remain_tick, state, cwd, priority, etc. */
|
||||
void (*task_set_default_schedule_attr)(struct TaskMicroDescriptor*, struct TraceTag* cwd);
|
||||
|
||||
/* use by task_scheduler, find next READY task, should be in locked */
|
||||
struct TaskMicroDescriptor* (*next_runnable_task)(void);
|
||||
/* function that's runing by kernel thread context, schedule use tasks */
|
||||
void (*task_scheduler)(struct SchedulerRightGroup);
|
||||
/* call to yield current use task */
|
||||
void (*cur_task_yield_noschedule)(void);
|
||||
/* set task priority */
|
||||
void (*set_cur_task_priority)(int priority);
|
||||
};
|
||||
|
||||
extern uint32_t ready_task_priority;
|
||||
extern struct TaskMicroDescriptor* next_task_emergency;
|
||||
extern struct XiziTaskManager xizi_task_manager;
|
||||
|
||||
int spawn_embedded_task(char* img_start, char* name, char** argv);
|
||||
bool module_task_manager_init(void);
|
||||
Reference in New Issue
Block a user