XIZI_AIoT: Add modifications for all SDK files. Add libmalloc interfaces(not functional)

This commit is contained in:
TXuian 2024-02-02 11:10:55 +08:00
parent c7529f1702
commit 6942ad6d1d
51 changed files with 2010 additions and 1665 deletions

View File

@ -9,6 +9,24 @@
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file context_switch.S
* @brief task context switch functions
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.08.15
*/
/*************************************************
File name: context_switch.S
Description: task context switch functions
Others:
History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. first version
*************************************************/
.global context_switch
context_switch:

View File

@ -33,6 +33,16 @@
* @brief This file contains cortexA9 functions
*
*/
/*************************************************
File name: cortexA9.S
Description: This file contains cortexA9 functions
Others:
History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. Not modifications
*************************************************/
.code 32
.section ".text","ax"

View File

@ -39,12 +39,12 @@
/*************************************************
File name: dcd.c
Description: imx6q device configuration data
Others:
Others:
History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. first version
1. Not modifications
*************************************************/
#include <hab_defines.h>

View File

@ -33,7 +33,7 @@ History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. first version
1. Not modifications
*************************************************/
#include <soc_memory_map.h>

View File

@ -27,6 +27,24 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file cortex_a9.h
* @brief some cortex A9 core functions
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.08.25
*/
/*************************************************
File name: cortex_a9.h
Description: some cortex A9 core functions
Others:
History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. Not modification
*************************************************/
#if !defined(__CORTEX_A9_H__)
#define __CORTEX_A9_H__

View File

@ -34,6 +34,16 @@
*
* @ingroup diag_init
*/
/*************************************************
File name: hab_defines.h
Description: defines for data structures and macros used for enabling secure boot
Others:
History:
1. Date: 2023-11-23
Author: AIIT XUOS Lab
Modification:
1. Not modifications
*************************************************/
#ifndef HAB_DEFINES_H
#define HAB_DEFINES_H
/*===========================================================================
@ -46,7 +56,7 @@
CONSTANTS
=============================================================================*/
/** @addtogroup struct
* @{
* @{
*/
#define HDR_BYTES 4 /* cannot use sizeof(hab_hdr_t) in preprocessor */

View File

@ -27,7 +27,24 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file iomux_register.h
* @brief iomux registers addresses
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.08.25
*/
/*************************************************
File name: iomux_register.h
Description: iomux registers addresses
Others:
History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. Comment unnecessary macros
*************************************************/
// File: iomux_register.h
#ifndef _IOMUX_REGISTER_H_

View File

@ -27,6 +27,24 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file registers.h
* @brief imx6q sabrelite registers
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.08.25
*/
/*************************************************
File name: registers.h
Description: imx6q sabrelite registers
Others:
History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. Comment unnecessary macros
*************************************************/
#include "regs.h"
//#################################################

View File

@ -13,7 +13,24 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*/
/**
* @file regs.h
* @brief imx6q sabrelite register operation macros
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.08.25
*/
/*************************************************
File name: regs.h
Description: imx6q sabrelite register operation macros
Others:
History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. Comment unnecessary macros
*************************************************/
#ifndef _REGS_H
#define _REGS_H 1

View File

@ -23,6 +23,16 @@
* @author AIIT XUOS Lab
* @date 2023.09.08
*/
/*************************************************
File name: soc_memory_map.h
Description: support imx6q soc memory map define, reference from u-boot-2009-08/include/asm-arm/arch-mx6/mx6.h
Others:
History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. Comment unnecessary macros
*************************************************/
#ifndef SOC_MEMORY_MAP_H
#define SOC_MEMORY_MAP_H

View File

@ -40,12 +40,13 @@
/*************************************************
File name: l1_cache.c
Description: the general management of L1 cache
Others:
History:
Others:
History:
1. Date: 2023-04-27
Author: AIIT XUOS Lab
Modification:
1implement the l1 cache operations
Modification:
1. implement the l1 cache operations
2. functions are modifications of imx6 SDK package
*************************************************/
#include "l1_cache.h"

View File

@ -34,12 +34,13 @@
/*************************************************
File name: l2_cache.c
Description: the general management of L2 cache
Others:
History:
Others:
History:
1. Date: 2023-04-27
Author: AIIT XUOS Lab
Modification:
1support xiuos cache interface
Modification:
1. support xiuos cache interface
2. implementations are modifications of imx6 SDK package
*************************************************/
#include "l2_cache.h"

View File

@ -27,6 +27,24 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file ccm_pll.c
* @brief support imx6q soc ccm pll functions
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.09.08
*/
/*************************************************
File name: ccm_pll.c
Description: support imx6q soc ccm pll functions
Others:
History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. Delete unnecessary functions;
2. Slim clock_gating_config to fit only uart and gpt(clock)
*************************************************/
#include "soc_memory_map.h"
#include <stdbool.h>
#include <stdint.h>

View File

@ -34,6 +34,16 @@
*
* @ingroup diag_timer
*/
/*************************************************
File name: soc_memory_map.h
Description: GPT driver source file.
Others:
History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. Delete a commented out function
*************************************************/
#include <stdint.h>
#include "soc_memory_map.h"

View File

@ -27,7 +27,24 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file ccm_pll.h
* @brief ccm pll source file
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.11.23
*/
/*************************************************
File name: ccm_pll.h
Description: ccm pll source file
Others:
History:
1. Date: 2023-11-23
Author: AIIT XUOS Lab
Modification:
1. Not modification
*************************************************/
#ifndef _CCM_PLL_H_
#define _CCM_PLL_H_

View File

@ -35,6 +35,16 @@
* @file gpt.h
* @brief GPT driver public interface.
*/
/*************************************************
File name: gpt.h
Description: GPT driver public interface.
Others:
History:
1. Date: 2023-11-23
Author: AIIT XUOS Lab
Modification:
1. Not modifications
*************************************************/
#ifndef __GPT_H__
#define __GPT_H__

View File

@ -18,6 +18,16 @@
*
* This file was generated automatically and any changes may be lost.
*/
/*************************************************
File name: regsccm.h
Description: ccm registers
Others:
History:
1. Date: 2023-11-23
Author: AIIT XUOS Lab
Modification:
1. Not modifications
*************************************************/
#ifndef __HW_CCM_REGISTERS_H__
#define __HW_CCM_REGISTERS_H__

View File

@ -18,6 +18,16 @@
*
* This file was generated automatically and any changes may be lost.
*/
/*************************************************
File name: regsccmanalog.h
Description:
Others:
History:
1. Date: 2023-11-23
Author: AIIT XUOS Lab
Modification:
1. Comment unnecessary macros
*************************************************/
#ifndef __HW_CCM_ANALOG_REGISTERS_H__
#define __HW_CCM_ANALOG_REGISTERS_H__

View File

@ -18,6 +18,16 @@
*
* This file was generated automatically and any changes may be lost.
*/
/*************************************************
File name: regsgpc.h
Description:
Others:
History:
1. Date: 2023-11-23
Author: AIIT XUOS Lab
Modification:
1. Comment unnecessary macros
*************************************************/
#ifndef __HW_GPC_REGISTERS_H__
#define __HW_GPC_REGISTERS_H__

View File

@ -18,6 +18,16 @@
*
* This file was generated automatically and any changes may be lost.
*/
/*************************************************
File name: regsgpt.h
Description:
Others:
History:
1. Date: 2023-11-23
Author: AIIT XUOS Lab
Modification:
1. Comment unnecessary macros
*************************************************/
#ifndef __HW_GPT_REGISTERS_H__
#define __HW_GPT_REGISTERS_H__

View File

@ -35,6 +35,16 @@
* @file timer.h
* @brief various defines used by the timer driver.
*/
/*************************************************
File name: timer.h
Description: various defines used by the timer driver.
Others:
History:
1. Date: 2023-11-23
Author: AIIT XUOS Lab
Modification:
1. Not modifications
*************************************************/
#ifndef __TIMER_H__
#define __TIMER_H__

View File

@ -25,7 +25,7 @@
* @brief handle program abort
* @version 3.0
* @author AIIT XUOS Lab
* @date 2024.11.23
* @date 2023.11.23
*/
/*************************************************
@ -33,10 +33,11 @@ File name: error_debug.c
Description: handle program abort
Others:
History:
1. Date: 2024-11-23
1. Date: 2023-11-23
Author: AIIT XUOS Lab
Modification:
1. first version
1. Take only armv7 abort reason part.
2. Modify iabort and dabort handler
*************************************************/
#include "core.h"
#include "memlayout.h"

View File

@ -27,6 +27,17 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* 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 gicv2_common_opa.c
* @brief gicv2 operation
@ -43,6 +54,7 @@ History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. Rename file
*************************************************/
#pragma once

View File

@ -43,7 +43,7 @@ History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. take only gicd part
1. take only gicd part of functions
*************************************************/
#include "gicv2_common_opa.h"
#include "gicv2_registers.h"

View File

@ -43,7 +43,7 @@ History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. take only gicc part
1. take only gicc part of functions
*************************************************/
#include "gicv2_common_opa.h"
#include "gicv2_registers.h"

View File

@ -43,6 +43,7 @@ History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. Rename the file
*************************************************/
#include <stdint.h>

View File

@ -11,22 +11,11 @@
*/
/**
* @file spinlock.c
* @brief spinlock c interfaces
* @brief spinlock interfaces
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.08.25
* @date 2023.11.23
*/
/*************************************************
File name: spinlock.c
Description: spinlock c interfaces
Others:
History:
1. Date: 2023-08-28
Author: AIIT XUOS Lab
Modification:
1. add return of _spinlock_lock
*************************************************/
#include <stdint.h>
#include <string.h>

View File

@ -36,7 +36,7 @@ Modification:
/* A9 physical memory layout */
#define PHY_MEM_BASE (0x10000000)
#define PHY_USER_FREEMEM_BASE (0x40000000)
#define PHY_USER_FREEMEM_BASE (0x30000000)
#define PHY_USER_FREEMEM_TOP (0x50000000)
#define PHY_MEM_STOP (0x50000000)

View File

@ -39,12 +39,12 @@
/*************************************************
File name: imx_uart.c
Description: imx6q board uart function
Others:
Others:
History:
1. Date: 2023-08-28
1. Date: 2023-09-28
Author: AIIT XUOS Lab
Modification:
1. first version
1. Get init and read/write functions
*************************************************/
#include "crm_regs.h"
#include "regs_pins.h"

View File

@ -23,6 +23,16 @@
* @author AIIT XUOS Lab
* @date 2023.09.08
*/
/*************************************************
File name: crm_regs.h
Description: support imx6q clock control module define, reference from u-boot-2009-08/cpu/arm_cortexa8/mx6/crm_regs.h
Others:
History:
1. Date: 2023-09-08
Author: AIIT XUOS Lab
Modification:
1. Comment unnecessary macros.
*************************************************/
#ifndef __ARCH_ARM_MACH_MX6_CRM_REGS_H__
#define __ARCH_ARM_MACH_MX6_CRM_REGS_H__

View File

@ -21,12 +21,12 @@
/*************************************************
File name: imx_uart.h
Description: imx6q board uart function
Others:
Others:
History:
1. Date: 2023-08-28
1. Date: 2023-09-08
Author: AIIT XUOS Lab
Modification:
1. first version
1. Not modifications
*************************************************/
#ifndef __IMX_UART_H__

View File

@ -26,7 +26,16 @@
* @author AIIT XUOS Lab
* @date 2023.09.08
*/
/*************************************************
File name: iomux_v3.h
Description: support imx6q iomux function define, reference from u-boot-2009-08/include/asm-arm/arch-mx6/iomux_v3.h
Others:
History:
1. Date: 2023-09-08
Author: AIIT XUOS Lab
Modification:
1. Not modifications
*************************************************/
#ifndef __MACH_IOMUX_V3_H__
#define __MACH_IOMUX_V3_H__

View File

@ -18,6 +18,16 @@
*
* This file was generated automatically and any changes may be lost.
*/
/*************************************************
File name: regsuart.h
Description: uart regs
Others:
History:
1. Date: 2023-11-23
Author: AIIT XUOS Lab
Modification:
1. Comment unnecessary macros
*************************************************/
#ifndef __HW_UART_REGISTERS_H__
#define __HW_UART_REGISTERS_H__

View File

@ -26,6 +26,16 @@
* @author AIIT XUOS Lab
* @date 2023.09.08
*/
/*************************************************
File name: iomux_v3.c
Description: support imx6q iomux function, reference from u-boot-2009-08/cpu/arm_cortexa8/mx6/iomux-v3.c
Others:
History:
1. Date: 2023-11-23
Author: AIIT XUOS Lab
Modification:
1. Not modifications
*************************************************/
#include <iomux_v3.h>

View File

@ -7,7 +7,11 @@ user_ldflags = --specs=nosys.specs -Wl,-Map=user.map,-cref -N
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 -no-pie
c_useropts = -O0
INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell -I$(KERNEL_ROOT)/services/lib/ipc -I$(KERNEL_ROOT)/services/boards/imx6q-sabrelite -I$(KERNEL_ROOT)/services/fs/include
INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \
-I$(KERNEL_ROOT)/services/lib/ipc \
-I$(KERNEL_ROOT)/services/lib/memory \
-I$(KERNEL_ROOT)/services/boards/imx6q-sabrelite \
-I$(KERNEL_ROOT)/services/fs/include
all: init simple_client simple_server shell fs_server test_priority test_fs readme.txt | bin
../../tools/mkfs/mkfs ./fs.img $^
@ -26,7 +30,7 @@ init: init.o fs_service.o libipc.o session.o libserial.o usyscall.o
@${ld} ${user_ldflags} -e main -o $@ $^
@${objdump} -S $@ > $@.asm
simple_client: simple_client.o libserial.o libipc.o session.o simple_service.o fs_service.o usyscall.o
simple_client: simple_client.o libserial.o libipc.o session.o simple_service.o fs_service.o usyscall.o
@${ld} ${user_ldflags} -e main -o $@ $^
@${objdump} -S $@ > $@.asm

View File

@ -84,7 +84,7 @@ int main(int argc, char** argv)
if (argc >= 2) {
id = string_to_integer(argv[1]);
}
printf("This is Simple Client %d\n", id);
printf("This is Simple Client %d, size is 0x%x\n", id, task_heap_base());
struct Session session_wait;
struct Session session_nowait;

View File

@ -83,6 +83,11 @@ 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);
@ -98,7 +103,7 @@ int show_cpu()
return syscall(SYSCALL_SYS_STATE, SYS_STATE_SHOW_CPU_INFO, 0, 0, 0);
}
int mmap(int vaddr, int paddr, int len, bool is_dev)
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);
}

View File

@ -34,8 +34,9 @@
typedef enum {
SYS_STATE_TEST = 0,
SYS_STATE_MEMBLOCK_INFO,
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,
@ -65,10 +66,11 @@ 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(int vaddr, int paddr, int len, bool is_dev);
int mmap(uintptr_t vaddr, uintptr_t paddr, int len, bool is_dev);
int register_irq(int irq, int opcode);

View File

@ -1,4 +1,4 @@
SRC_DIR := ipc
SRC_DIR := ipc memory
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,17 @@
toolchain ?= arm-none-eabi-
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 -no-pie
c_useropts = -O0
INC_DIR = -I$(KERNEL_ROOT)/services/boards/imx6q-sabrelite \
-I$(KERNEL_ROOT)/services/lib/ipc
all:
%.o: %.c
@echo "cc $^"
@${cc} ${cflags} ${c_useropts} ${INC_DIR} -o $@ -c $^

View File

@ -9,4 +9,27 @@
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file libmalloc.h
* @brief support malloc and free in userland
* @version 3.0
* @author AIIT XUOS Lab
* @date 2024.01.31
*/
/*************************************************
File name: libmalloc.h
Description: support malloc and free in userland
Others:
History:
1. Date: 2024-01-31
Author: AIIT XUOS Lab
Modification:
1. first version
*************************************************/
#pragma once
#include <stddef.h>
void* malloc(size_t size);
void free(void* ptr);

View File

@ -25,7 +25,7 @@
* @brief Format of an ELF executable file
* @version 3.0
* @author AIIT XUOS Lab
* @date 2024.11.23
* @date 2023.11.23
*/
/*************************************************
@ -33,7 +33,7 @@ File name: execelf.h
Description: Format of an ELF executable file
Others:
History:
1. Date: 2024-11-23
1. Date: 2023-11-23
Author: AIIT XUOS Lab
Modification:
1. reserve only necessary elfhdr structs

View File

@ -54,8 +54,9 @@ Modification:
typedef enum {
SYS_STATE_TEST = 0,
SYS_STATE_MEMBLOCK_INFO,
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,

View File

@ -39,7 +39,7 @@ Modification:
#define TASK_CLOCK_TICK 50
#define TASK_MAX_PRIORITY 32
#define TASK_DEFAULT_PRIORITY 1
#define TASK_DEFAULT_PRIORITY 2
#define TASK_NAME_MAX_LEN 16
enum ProcState {

View File

@ -33,8 +33,8 @@ Modification:
#include "actracer.h"
#include "buddy.h"
struct KBuddy user_phy_freemem_buddy;
struct KBuddy kern_virtmem_buddy;
struct KBuddy user_phy_freemem_buddy;
extern uint32_t kernel_data_end[];
bool module_phymem_init()

View File

@ -143,6 +143,7 @@ static bool _map_user_pages(uintptr_t* pgdir, uintptr_t vaddr, uintptr_t paddr,
static void _free_user_pgdir(struct TopLevelPageDirectory* pgdir)
{
uintptr_t low_bound = kern_virtmem_buddy.mem_start, high_bound = kern_virtmem_buddy.mem_end;
uintptr_t user_low_bound = user_phy_freemem_buddy.mem_start, user_high_bound = user_phy_freemem_buddy.mem_end;
uintptr_t end_idx = USER_MEM_TOP >> LEVEL3_PDE_SHIFT;
for (uintptr_t i = 0; i < end_idx; i++) {
@ -152,8 +153,12 @@ static void _free_user_pgdir(struct TopLevelPageDirectory* pgdir)
// free each page
for (uintptr_t j = 0; j < NUM_LEVEL4_PTE; j++) {
uintptr_t* page_paddr = (uintptr_t*)ALIGNDOWN(((uintptr_t*)P2V(pgtbl_paddr))[j], PAGE_SIZE);
if (page_paddr != NULL && (uintptr_t)page_paddr >= low_bound && (uintptr_t)page_paddr < high_bound) {
kfree(P2V(page_paddr));
if (page_paddr != NULL) {
if (LIKELY((uintptr_t)page_paddr >= low_bound && (uintptr_t)page_paddr < high_bound)) {
kfree(P2V(page_paddr));
} else if (LIKELY((uintptr_t)page_paddr >= user_low_bound && (uintptr_t)page_paddr < user_high_bound)) {
raw_free((char*)page_paddr);
}
}
}
kfree(P2V(pgtbl_paddr));

View File

@ -180,7 +180,7 @@ int task_exec(struct TaskMicroDescriptor* task, struct Session* session, int fd,
task->pgdir = pgdir;
/// @todo record mem size used b task
task->mem_size = load_size;
task->mem_size = ALIGNUP(load_size, PAGE_SIZE);
xizi_pager.free_user_pgdir(&old_pgdir);
return 0;

View File

@ -41,19 +41,27 @@ int sys_mmap(uintptr_t vaddr, uintptr_t paddr, int len, int is_dev)
struct TaskMicroDescriptor* cur_task = cur_cpu()->task;
assert(cur_task != NULL);
int true_len = ALIGNUP(len, PAGE_SIZE);
if (paddr != (uintptr_t)NULL) {
if (xizi_share_page_manager.task_map_pages(cur_task, vaddr, paddr, ALIGNUP(len, PAGE_SIZE) / PAGE_SIZE, is_dev) == (uintptr_t)NULL) {
if (xizi_share_page_manager.task_map_pages(cur_task, vaddr, paddr, true_len / PAGE_SIZE, is_dev) == (uintptr_t)NULL) {
return -1;
}
} else {
char* kern_vaddr = kalloc(len);
if (kern_vaddr == NULL) {
return -1;
}
if (xizi_share_page_manager.task_map_pages(cur_task, vaddr, V2P(kern_vaddr), ALIGNUP(len, PAGE_SIZE) / PAGE_SIZE, is_dev) == (uintptr_t)NULL) {
kfree(kern_vaddr);
return -1;
int load_len = 0;
uintptr_t load_vaddr = vaddr;
while (load_len < true_len) {
char* paddr = raw_alloc(PAGE_SIZE);
if (paddr == NULL) {
return -1;
}
if (xizi_share_page_manager.task_map_pages(cur_task, load_vaddr, (uintptr_t)paddr, 1, false) == (uintptr_t)NULL) {
raw_free(paddr);
return -1;
}
load_vaddr += PAGE_SIZE;
load_len += PAGE_SIZE;
}
}
return 0;
return vaddr + true_len;
}

View File

@ -128,6 +128,8 @@ int sys_state(sys_state_option option, sys_state_info* info)
if (option == SYS_STATE_MEMBLOCK_INFO) {
info->memblock_info.memblock_start = (uintptr_t)V2P(_binary_fs_img_start);
info->memblock_info.memblock_end = (uintptr_t)V2P(_binary_fs_img_end);
} else if (option == SYS_STATE_GET_HEAP_BASE) {
return cur_cpu()->task->mem_size;
} else if (option == SYS_STATE_SET_TASK_PRIORITY) {
xizi_task_manager.set_cur_task_priority(info->priority);
} else if (option == SYS_STATE_SHOW_TASKS) {

View File

@ -136,6 +136,7 @@ int spawn_embedded_task(char* img_start, char* name, char** argv)
new_task_cb->pgdir = pgdir;
/// @todo record mem size used b task
new_task_cb->mem_size = ALIGNUP(load_size, PAGE_SIZE);
xizi_pager.free_user_pgdir(&old_pgdir);