vma interface fix.

This commit is contained in:
zhangzheng
2024-09-19 23:30:54 +08:00
parent abb63b2e80
commit 6b38424e91
64 changed files with 456 additions and 642 deletions

6
.vscode/launch.json vendored
View File

@@ -50,12 +50,12 @@
// "miDebuggerPath": "/home/zhangzheng/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/aarch64-none-elf-gdb",
// "miDebuggerPath": "/Applications/ArmGNUToolchain/11.3.rel1/aarch64-none-elf/bin/aarch64-none-elf-gdb",
// "miDebuggerPath": "/home/zhangzheng/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gdb",
// "miDebuggerPath": "/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gdb",
"miDebuggerPath": "/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gdb",
// "miDebuggerPath": "/home/zhangzheng/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gdb",
// "miDebuggerPath": "/home/mkrtos-smart/toolchains/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/aarch64-none-elf-gdb",
// "miDebuggerPath": "/home/toolchains/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/aarch64-none-elf-gdb",
"miDebuggerPath": "/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gdb",
"miDebuggerServerAddress": "127.0.0.1:3333",
// "miDebuggerPath": "/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gdb",
"miDebuggerServerAddress": "127.0.0.1:33333",
"MIMode": "gdb",
"setupCommands": [
{

View File

@@ -25,14 +25,3 @@ int mm_space_init(mm_space_t *mm_space, int is_knl)
return ret;
}
bool_t mm_space_add(mm_space_t *m_space,
umword_t addr,
umword_t size,
uint8_t attrs)
{
return 0;
}
void mm_space_del(mm_space_t *m_space, umword_t addr)
{
/*TODO:*/
}

View File

@@ -68,6 +68,9 @@ void NMI_Handler(void)
void HardFault_Handler(void)
{
bool_t is_knl = is_run_knl();
addr_t fault_addr = (addr_t)(SCB->MMFAR);
printk("data 0x%x access is error.\n", fault_addr);
printk("%s\n", __FUNCTION__);
task_knl_kill(thread_get_current(), is_knl);

View File

@@ -13,3 +13,12 @@
#include "mm_space.h"
#include "mpu.h"
#include "assert.h"
int mm_space_init(mm_space_t *mm_space, int is_knl)
{
int ret = 0;
ret = task_vma_init(&mm_space->mem_vma);
return ret;
}

View File

@@ -48,3 +48,4 @@ static inline page_entry_t *mm_space_get_pdir(mm_space_t *sp)
return &sp->mem_dir;
}
#endif
int mm_space_init(mm_space_t *mm_space, int is_knl);

View File

@@ -22,9 +22,13 @@ static inline umword_t vpage_attrs_to_page_attrs(enum vpage_prot_attrs attrs)
if (attrs & VPAGE_PROT_RO)
{
to_attrs == REGION_RO;
to_attrs = REGION_RO;
}
else if ((attrs & VPAGE_PROT_RWX) == VPAGE_PROT_RWX)
if ((attrs & VPAGE_PROT_RW) == VPAGE_PROT_RW)
{
to_attrs = REGION_RWX;
}
if ((attrs & VPAGE_PROT_RWX) == VPAGE_PROT_RWX)
{
to_attrs = REGION_RWX;
}

View File

@@ -20,7 +20,6 @@ enum kobj_prot
TASK_PROT,
LOG_PROT,
IPC_PROT,
MM_PROT,
SYS_PROT,
FUTEX_PROT,
IRQ_PROT,

View File

@@ -27,8 +27,13 @@ typedef union vma_addr
umword_t raw;
struct
{
#if IS_ENABLED(CONFIG_MMU)
umword_t prot : 8;
umword_t flags : 4;
#else
umword_t prot : 6;
umword_t flags : 3;
#endif
// umword_t resv : 2;
umword_t addr : (sizeof(void *) * 8 - PAGE_SHIFT);
};
@@ -119,9 +124,9 @@ typedef struct task_vma
typedef struct region_info
{
umword_t start_addr; //!< 内存申请的开始地址
umword_t size; //!< 实际申请的内存大小
umword_t block_start_addr; //!< 块申请的开始地址
umword_t block_size; //!< 保护的块大小
umword_t size; //!< 实际申请的内存大小
umword_t rbar; //!< mpu保护寄存器信息
umword_t rasr; //!< mpu保护寄存器信息
int16_t region_inx; //!< 区域索引

View File

@@ -26,12 +26,16 @@ else()
endif()
endif()
file(GLOB mm_src mm/*.c mm/*.S)
list(APPEND deps ${mm_src})
if (DEFINED CONFIG_MMU)
if (CONFIG_MMU STREQUAL "y")
file(GLOB mm_src mm/*.c mm/*.S)
file(GLOB mm_mmu_src mm/mmu/*.c mm/mmu/*.S)
list(APPEND deps ${mm_src} ${mm_mmu_src})
list(APPEND deps ${mm_mmu_src})
endif()
else()
file(GLOB mm_mpu_src mm/mpu/*.c mm/mpu/*.S)
list(APPEND deps ${mm_mpu_src})
endif()
add_library(knl STATIC ${deps})

View File

@@ -1,216 +0,0 @@
/**
* @file misc.c
* @author ATShining (1358745329@qq.com)
* @brief
* @version 0.1
* @date 2023-09-29
*
* @copyright Copyright (c) 2023
*
*/
#include "types.h"
#include "mm_wrap.h"
#include "mm.h"
#include "mm_space.h"
#include "util.h"
#include "printk.h"
#if CONFIG_MK_MPU_CFG
#include "mpu.h"
static bool_t mpu_calc(
mm_space_t *ms,
umword_t mem_start_addr,
int size,
umword_t *ret_align_size,
umword_t *alloc_addr)
{
#if CONFIG_MPU_VERSION == 1
int ffs_t_;
int ffs_t;
region_info_t *region[2];
region[0] = mm_space_alloc_pt_region(ms);
region[1] = mm_space_alloc_pt_region(ms);
if (!region[0] || !region[1])
{
if (!region[0])
{
mm_space_free_pt_region(ms, region[0]);
}
if (!region[1])
{
mm_space_free_pt_region(ms, region[1]);
}
return FALSE;
}
ffs_t_ = ffs(size);
if (!is_power_of_2(size))
{
ffs_t_++;
}
ffs_t = 1 << ffs_t_;
int sub_region_t = ffs_t >> 3;
int align_sub_size = ALIGN(size, sub_region_t);
umword_t mem_align_sub_mem_addr = ALIGN((umword_t)mem_start_addr, sub_region_t);
umword_t mem_align_up_mem_addr = ALIGN((umword_t)mem_start_addr, ffs_t);
umword_t mem_align_down_mem_addr = ALIGN_DOWN((umword_t)mem_start_addr, ffs_t);
region[0]->start_addr = mem_align_sub_mem_addr;
region[0]->size = mem_align_up_mem_addr - mem_align_sub_mem_addr;
region[0]->block_size = ffs_t;
region[0]->block_start_addr = mem_align_down_mem_addr;
if (alloc_addr)
{
*alloc_addr = region[0]->start_addr;
}
region[0]->region = 0xff;
for (umword_t i = mem_align_down_mem_addr; i < mem_align_up_mem_addr; i += sub_region_t)
{
if (i < mem_align_sub_mem_addr)
{
region[0]->region |= 1 << ((i - mem_align_down_mem_addr) / sub_region_t);
}
else
{
region[0]->region &= ~(1 << ((i - mem_align_down_mem_addr) / sub_region_t));
}
}
region[1]->region = 0x00;
for (umword_t i = mem_align_up_mem_addr; i < mem_align_up_mem_addr + ffs_t; i += sub_region_t)
{
if (i < mem_align_sub_mem_addr + align_sub_size)
{
region[1]->region &= ~(1 << ((i - mem_align_up_mem_addr) / sub_region_t));
}
else
{
region[1]->region |= (1 << ((i - mem_align_up_mem_addr) / sub_region_t));
}
}
region[1]->start_addr = mem_align_up_mem_addr;
region[1]->size = (mem_align_sub_mem_addr + align_sub_size) - mem_align_up_mem_addr;
region[1]->block_size = ffs_t;
region[1]->block_start_addr = mem_align_up_mem_addr;
*ret_align_size = sub_region_t;
#if 0
printk("st:0x%x re:0x%x sub:0x%x\n region:[", region[0]->block_start_addr, region[0]->region, sub_region_t);
for (int i = 0; i < 8; i++)
{
if (region[0]->region & (1 << i))
{
printk("x");
}
else
{
printk("o");
}
}
printk("]\n");
printk("st:0x%x re:0x%x sub:0x%x\n region:[", region[1]->block_start_addr, region[1]->region, sub_region_t);
for (int i = 0; i < 8; i++)
{
if (region[1]->region & (1 << i))
{
printk("x");
}
else
{
printk("o");
}
}
printk("]\n");
#endif
mpu_calc_regs(region[0], region[0]->block_start_addr, 1 << ffs_t_, REGION_RWX, region[0]->region);
mpu_calc_regs(region[1], region[1]->block_start_addr, 1 << ffs_t_, REGION_RWX, region[1]->region);
#elif CONFIG_MPU_VERSION == 2
#endif
return TRUE;
}
void *mpu_ram_alloc(mm_space_t *ms, ram_limit_t *r_limit, size_t ram_size)
{
#if CONFIG_MPU_VERSION == 1
umword_t pre_alloc_addr;
struct mem_heap *heap = NULL;
umword_t status = cpulock_lock();
again_alloc:
heap = mm_get_free(heap, ram_size, &pre_alloc_addr);
if (!heap)
{
cpulock_set(status);
printk("The system is low on memory.\n");
// mm_trace();
return NULL;
}
umword_t need_align;
umword_t alloc_addr;
if (mpu_calc(ms, pre_alloc_addr, ram_size,
&need_align, &alloc_addr) == FALSE)
{
cpulock_set(status);
printk("The MPU area is exhausted.");
return NULL;
}
void *ram = mm_limit_alloc_align(r_limit, ram_size, need_align);
if (!ram)
{
cpulock_set(status);
printk("The system is low on memory.\n");
return NULL;
}
//!< 申请的地址与预分配的地址不同
if (ram != (void *)alloc_addr)
{
cpulock_set(status);
printk("Again.\n");
mm_limit_free_align(r_limit, ram, need_align);
heap = heap->next;
goto again_alloc;
}
cpulock_set(status);
return ram;
#elif CONFIG_MPU_VERSION == 2
region_info_t *region;
void *ram = mm_limit_alloc_align(r_limit, ram_size + MPU_ALIGN_SIZE, MPU_ALIGN_SIZE);
if (!ram)
{
printk("The system is low on memory.\n");
return NULL;
}
region = mm_space_alloc_pt_region(ms);
if (!region)
{
mm_limit_free_align(r_limit, ram, ram_size);
return NULL;
}
region->block_start_addr = (umword_t)ram;
region->start_addr = (umword_t)ram;
region->block_size = 0;
region->size = ram_size + MPU_ALIGN_SIZE;
mpu_calc_regs(region, region->block_start_addr, ram_size & (~(MPU_ALIGN_SIZE - 1)), REGION_RWX, region->region);
return ram;
#endif
}
#else
void *mpu_ram_alloc(mm_space_t *ms, ram_limit_t *r_limit, size_t ram_size)
{
void *ram = mm_limit_alloc(r_limit, ram_size);
return ram;
}
#endif

View File

@@ -6,6 +6,11 @@
#include <assert.h>
#include <err.h>
#include <mpu.h>
#include <mm.h>
#include <mm_wrap.h>
#include <task.h>
#include <thread.h>
#include <string.h>
static region_info_t *vma_alloc_pt_region(task_vma_t *vma)
{
assert(vma != NULL);
@@ -38,6 +43,7 @@ static region_info_t *vma_find_pt_region(task_vma_t *vma, addr_t addr, size_t si
}
static void vma_free_pt_region(task_vma_t *vma, region_info_t *ri)
{
memset(ri, 0, sizeof(*ri));
ri->region_inx = -1;
}
@@ -80,10 +86,6 @@ int task_vma_alloc(task_vma_t *task_vma, vma_addr_t vaddr, size_t size,
mm_space);
assert(task_vma != NULL);
if (!ret_vaddr)
{
return -EINVAL;
}
#if CONFIG_MPU_VERSION == 1
if (!is_power_of_2(size))
{
@@ -105,7 +107,16 @@ int task_vma_alloc(task_vma_t *task_vma, vma_addr_t vaddr, size_t size,
}
#if CONFIG_MPU_VERSION == 1
vma_addr = (addr_t)mm_limit_alloc_align(pt_task, size, size);
if (paddr == 0)
{
// 未设置物理内存,则自动申请一个
vma_addr = (addr_t)mm_limit_alloc_align(pt_task->lim, size, size);
}
else
{
// 设置了物理内存,就用设置的物理内存
vma_addr = paddr;
}
if (vma_addr == 0)
{
return -ENOMEM;
@@ -152,14 +163,23 @@ int task_vma_alloc(task_vma_t *task_vma, vma_addr_t vaddr, size_t size,
0 /*TODO:支持每一个region bit位*/);
ri->start_addr = vma_addr;
ri->size = size;
mpu_switch_to_task(
pt_task);
if (pt_task == thread_get_current_task())
{
// 只有是当前线程的时候发生切换
mpu_switch_to_task(pt_task);
}
if (ret_vaddr)
{
*ret_vaddr = vma_addr;
}
goto end;
err_end:
#if CONFIG_MPU_VERSION == 1
mm_limit_free_align(pt_task, vma_addr, size);
mm_limit_free_align(pt_task->lim, (void *)vma_addr, size);
#elif CONFIG_MPU_VERSION == 2
mm_limit_free_align(pt_task, vma_addr, MPU_ALIGN_SIZE);
mm_limit_free_align(pt_task->lim, (void *)vma_addr, MPU_ALIGN_SIZE);
#endif
end:
return ret;
}
/**
@@ -179,6 +199,37 @@ int task_vma_grant(task_vma_t *src_task_vma, task_vma_t *dst_task_vma,
{
return -ENOSYS;
}
static int task_vma_free_inner(task_vma_t *task_vma, vaddr_t vaddr, size_t size, bool_t is_free_mem)
{
region_info_t *ri = NULL;
addr_t vma_addr;
task_t *pt_task;
pt_task = container_of(
container_of(task_vma, mm_space_t, mem_vma),
task_t,
mm_space);
assert(task_vma);
vma_addr = vaddr; // vma_addr_get_addr(vaddr);
ri = vma_find_pt_region(task_vma, vma_addr, size);
if (!ri)
{
return -ENOENT;
}
vma_free_pt_region(task_vma, ri);
if (is_free_mem)
{
#if CONFIG_MPU_VERSION == 1
mm_limit_free_align(pt_task->lim, (void *)vma_addr, size);
#elif CONFIG_MPU_VERSION == 2
mm_limit_free_align(pt_task->lim, (void *)vma_addr, MPU_ALIGN_SIZE);
#endif
}
if (pt_task==thread_get_current_task()){
mpu_switch_to_task(pt_task);
}
return 0;
}
/**
* @brief 释放申请的虚拟内存,并释放已经申请的物理内存
* 1.从分配树中找到需要的节点
@@ -191,34 +242,7 @@ int task_vma_grant(task_vma_t *src_task_vma, task_vma_t *dst_task_vma,
*/
int task_vma_free(task_vma_t *task_vma, vaddr_t vaddr, size_t size)
{
region_info_t *ri = NULL;
addr_t vma_addr;
task_t *pt_task;
pt_task = container_of(
container_of(task_vma, mm_space_t, mem_vma),
task_t,
mm_space);
assert(task_vma);
vma_addr = vma_addr_get_addr(vaddr);
ri = vma_find_pt_region(task_vma, vma_addr, size);
if (!ri)
{
return -ENOENT;
}
vma_free_pt_region(task_vma, ri);
#if CONFIG_MPU_VERSION == 1
mm_limit_free_align(pt_task, vma_addr, size);
#elif CONFIG_MPU_VERSION == 2
mm_limit_free_align(pt_task, vma_addr, MPU_ALIGN_SIZE);
#endif
mpu_switch_to_task(
container_of(
container_of(task_vma, mm_space_t, mem_vma),
task_t,
mm_space));
return 0;
return task_vma_free_inner(task_vma, vaddr, size, TRUE);
}
/**
@@ -232,7 +256,7 @@ int task_vma_free(task_vma_t *task_vma, vaddr_t vaddr, size_t size)
*/
int task_vma_free_pmem(task_vma_t *task_vma, vaddr_t addr, size_t size, bool_t is_free_mem)
{
return -ENOSYS;
return task_vma_free_inner(task_vma, addr, size, is_free_mem);
}
/**
* @brief 缺页的处理流程
@@ -268,11 +292,213 @@ int task_vma_clean(task_vma_t *task_vma)
{
task_vma->pt_regions[i].region_inx = -1;
#if CONFIG_MPU_VERSION == 1
mm_limit_free_align(pt_task, task_vma->pt_regions[i].start_addr, task_vma->pt_regions[i].size);
mm_limit_free_align(pt_task->lim, (void *)(task_vma->pt_regions[i].start_addr),
task_vma->pt_regions[i].size);
#elif CONFIG_MPU_VERSION == 2
mm_limit_free_align(pt_task, task_vma->pt_regions[i].start_addr, MPU_ALIGN_SIZE);
mm_limit_free_align(pt_task->lim, (void *)(task_vma->pt_regions[i].start_addr),
MPU_ALIGN_SIZE);
#endif
}
}
return 0;
}
#if CONFIG_MK_MPU_CFG
#include "mpu.h"
static bool_t mpu_calc(
mm_space_t *ms,
umword_t mem_start_addr,
int size,
umword_t *ret_align_size,
umword_t *alloc_addr)
{
#if CONFIG_MPU_VERSION == 1
int ffs_t_;
int ffs_t;
region_info_t *region[2];
region[0] = vma_alloc_pt_region(&ms->mem_vma);
region[1] = vma_alloc_pt_region(&ms->mem_vma);
if (!region[0] || !region[1])
{
if (!region[0])
{
vma_free_pt_region(&ms->mem_vma, region[0]);
}
if (!region[1])
{
vma_free_pt_region(&ms->mem_vma, region[1]);
}
return FALSE;
}
ffs_t_ = ffs(size);
if (!is_power_of_2(size))
{
ffs_t_++;
}
ffs_t = 1 << ffs_t_;
int sub_region_t = ffs_t >> 3;
int align_sub_size = ALIGN(size, sub_region_t);
umword_t mem_align_sub_mem_addr = ALIGN((umword_t)mem_start_addr, sub_region_t);
umword_t mem_align_up_mem_addr = ALIGN((umword_t)mem_start_addr, ffs_t);
umword_t mem_align_down_mem_addr = ALIGN_DOWN((umword_t)mem_start_addr, ffs_t);
region[0]->start_addr = mem_align_sub_mem_addr;
region[0]->size = mem_align_up_mem_addr - mem_align_sub_mem_addr;
region[0]->block_size = ffs_t;
region[0]->block_start_addr = mem_align_down_mem_addr;
if (alloc_addr)
{
*alloc_addr = region[0]->start_addr;
}
region[0]->region = 0xff;
for (umword_t i = mem_align_down_mem_addr; i < mem_align_up_mem_addr; i += sub_region_t)
{
if (i < mem_align_sub_mem_addr)
{
region[0]->region |= 1 << ((i - mem_align_down_mem_addr) / sub_region_t);
}
else
{
region[0]->region &= ~(1 << ((i - mem_align_down_mem_addr) / sub_region_t));
}
}
region[1]->region = 0x00;
for (umword_t i = mem_align_up_mem_addr; i < mem_align_up_mem_addr + ffs_t; i += sub_region_t)
{
if (i < mem_align_sub_mem_addr + align_sub_size)
{
region[1]->region &= ~(1 << ((i - mem_align_up_mem_addr) / sub_region_t));
}
else
{
region[1]->region |= (1 << ((i - mem_align_up_mem_addr) / sub_region_t));
}
}
region[1]->start_addr = mem_align_up_mem_addr;
region[1]->size = (mem_align_sub_mem_addr + align_sub_size) - mem_align_up_mem_addr;
region[1]->block_size = ffs_t;
region[1]->block_start_addr = mem_align_up_mem_addr;
*ret_align_size = sub_region_t;
#if 0
printk("st:0x%x re:0x%x sub:0x%x\n region:[", region[0]->block_start_addr, region[0]->region, sub_region_t);
for (int i = 0; i < 8; i++)
{
if (region[0]->region & (1 << i))
{
printk("x");
}
else
{
printk("o");
}
}
printk("]\n");
printk("st:0x%x re:0x%x sub:0x%x\n region:[", region[1]->block_start_addr, region[1]->region, sub_region_t);
for (int i = 0; i < 8; i++)
{
if (region[1]->region & (1 << i))
{
printk("x");
}
else
{
printk("o");
}
}
printk("]\n");
#endif
mpu_calc_regs(region[0], region[0]->block_start_addr, 1 << ffs_t_, REGION_RWX, region[0]->region);
mpu_calc_regs(region[1], region[1]->block_start_addr, 1 << ffs_t_, REGION_RWX, region[1]->region);
#elif CONFIG_MPU_VERSION == 2
#endif
return TRUE;
}
void *mpu_ram_alloc(mm_space_t *ms, ram_limit_t *r_limit, size_t ram_size)
{
#if CONFIG_MPU_VERSION == 1
umword_t pre_alloc_addr;
struct mem_heap *heap = NULL;
umword_t status = cpulock_lock();
again_alloc:
heap = mm_get_free(heap, ram_size, &pre_alloc_addr);
if (!heap)
{
cpulock_set(status);
printk("The system is low on memory.\n");
// mm_trace();
return NULL;
}
umword_t need_align;
umword_t alloc_addr;
if (mpu_calc(ms, pre_alloc_addr, ram_size,
&need_align, &alloc_addr) == FALSE)
{
cpulock_set(status);
printk("The MPU area is exhausted.");
return NULL;
}
void *ram = mm_limit_alloc_align(r_limit, ram_size, need_align);
if (!ram)
{
cpulock_set(status);
printk("The system is low on memory.\n");
return NULL;
}
//!< 申请的地址与预分配的地址不同
if (ram != (void *)alloc_addr)
{
cpulock_set(status);
printk("Again.\n");
mm_limit_free_align(r_limit, ram, need_align);
heap = heap->next;
goto again_alloc;
}
cpulock_set(status);
return ram;
#elif CONFIG_MPU_VERSION == 2
region_info_t *region;
void *ram = mm_limit_alloc_align(r_limit, ram_size + MPU_ALIGN_SIZE, MPU_ALIGN_SIZE);
if (!ram)
{
printk("The system is low on memory.\n");
return NULL;
}
region = mm_space_alloc_pt_region(ms);
if (!region)
{
mm_limit_free_align(r_limit, ram, ram_size);
return NULL;
}
region->block_start_addr = (umword_t)ram;
region->start_addr = (umword_t)ram;
region->block_size = 0;
region->size = ram_size + MPU_ALIGN_SIZE;
mpu_calc_regs(region, region->block_start_addr, ram_size & (~(MPU_ALIGN_SIZE - 1)), REGION_RWX, region->region);
return ram;
#endif
}
#else
void *mpu_ram_alloc(mm_space_t *ms, ram_limit_t *r_limit, size_t ram_size)
{
void *ram = mm_limit_alloc(r_limit, ram_size);
return ram;
}
#endif

View File

@@ -1,145 +0,0 @@
/**
* @file mm_man.c
* @author ATShining (1358745329@qq.com)
* @brief
* @version 0.1
* @date 2023-09-29
*
* @copyright Copyright (c) 2023
*
*/
#include "types.h"
#include "kobject.h"
#include "init.h"
// #include "mm_page.h"
#include "thread.h"
#include "task.h"
#include "globals.h"
#include "mpu.h"
typedef struct mm_man
{
kobject_t kobj;
} mm_man_t;
static mm_man_t mm_man;
static void mm_man_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag, entry_frame_t *f);
static void mm_man_reg(void)
{
kobject_init(&mm_man.kobj, MM_TYPE);
mm_man.kobj.invoke_func = mm_man_syscall;
global_reg_kobj(&mm_man.kobj, MM_PROT);
}
INIT_KOBJ(mm_man_reg);
enum mm_op
{
MM_ALLOC,
MM_FREE,
MM_ALIGN_ALLOC, //!< 直接暂用一个region
MM_ALIGN_FREE,
MM_MOD_ATTRS,
};
static void mm_man_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag, entry_frame_t *f)
{
task_t *cur_task = thread_get_current_task();
msg_tag_t tag = msg_tag_init4(0, 0, 0, -EINVAL);
if (sys_p.prot != MM_PROT)
{
f->regs[0] = msg_tag_init4(0, 0, 0, -EPROTO).raw;
return;
}
switch (sys_p.op)
{
case MM_ALLOC:
{
#if 0
addr_t ret_addr;
int ret = mm_pages_alloc_page(&cur_task->mm_space.mm_pages, cur_task->lim, f->regs[1], &ret_addr, f->regs[2]);
if (ret < 0)
{
tag = msg_tag_init4(0, 0, 0, ret);
}
else
{
tag = msg_tag_init4(0, 0, 0, 0);
f->regs[1] = ret_addr;
}
#else
void *ret_mem = mm_limit_alloc(cur_task->lim, f->regs[1]);
if (!ret_mem)
{
tag = msg_tag_init4(0, 0, 0, -ENOMEM);
}
else
{
f->regs[1] = (umword_t)ret_mem;
tag = msg_tag_init4(0, 0, 0, 0);
}
#endif
}
break;
case MM_FREE:
{
#if 0
mm_pages_free_page(&cur_task->mm_space.mm_pages, cur_task->lim, f->regs[1], f->regs[2]);
tag = msg_tag_init4(0, 0, 0, 0);
#else
mm_limit_free(cur_task->lim, (void *)(f->regs[1]));
tag = msg_tag_init4(0, 0, 0, 0);
#endif
}
break;
case MM_ALIGN_ALLOC:
{
#if CONFIG_MK_MPU_CFG
region_info_t *regi_info = mm_space_alloc_pt_region(&cur_task->mm_space);
if (regi_info)
{
umword_t size = f->regs[2];
umword_t addr = f->regs[1];
#if CONFIG_MPU_VERSION == 1
if ((!is_power_of_2(size)) && ((addr & (~(size - 1))) != 0))
{
tag = msg_tag_init4(0, 0, 0, -EINVAL);
break;
}
#elif CONFIG_MPU_VERSION == 2
if ((size & (MPU_ALIGN_SIZE - 1)) == 0 && (addr & (MPU_ALIGN_SIZE - 1)) == 0)
{
tag = msg_tag_init4(0, 0, 0, -EINVAL);
break;
}
#endif
mpu_calc_regs(regi_info, addr, size, REGION_RWX, 0);
mpu_switch_to_task(cur_task);
tag = msg_tag_init4(0, 0, 0, 0);
}
else
{
tag = msg_tag_init4(0, 0, 0, -ENOMEM);
}
#else
tag = msg_tag_init4(0, 0, 0, -ENOSYS);
#endif
}
break;
case MM_MOD_ATTRS:
{
tag = msg_tag_init4(0, 0, 0, -ENOSYS); // TODO:
}
break;
default:
tag = msg_tag_init4(0, 0, 0, -ENOSYS);
break;
}
f->regs[0] = tag.raw;
}
void mm_man_dump(void)
{
}

View File

@@ -356,14 +356,13 @@ static ssize_t share_mem_map(share_mem_t *obj, vma_addr_t addr, vaddr_t *ret_vad
return ret;
}
#else
bool_t _ret = mm_space_add(&task->mm_space, (umword_t)(obj->mem), obj->size, REGION_RWX /*TODO:这里写死了*/);
if (_ret)
ret = task_vma_alloc(&task->mm_space.mem_vma, addr, obj->size, (vaddr_t)(obj->mem), ret_vaddr);
if (ret < 0)
{
mpu_switch_to_task(task);
return ret;
}
map_size = _ret == TRUE ? 0 : -ENOMEM;
*ret_vaddr = (vaddr_t)(obj->mem);
map_size = obj->size;
// *ret_vaddr = (vaddr_t)(obj->mem);
#endif
return map_size;
}
@@ -371,13 +370,7 @@ static int share_mem_unmap(share_mem_t *obj, vaddr_t vaddr)
{
task_t *task = thread_get_current_task();
#if IS_ENABLED(CONFIG_MMU)
task_vma_free_pmem(&task->mm_space.mem_vma, vaddr, obj->size, FALSE);
#else
// 共享内存解除映射
mm_space_del(&task->mm_space, (umword_t)obj->mem);
mpu_switch_to_task(task);
#endif
return 0;
}
static void share_mem_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag, entry_frame_t *f)

View File

@@ -28,7 +28,8 @@
* @brief 任务的操作码
*
*/
enum task_op_code {
enum task_op_code
{
TASK_OBJ_MAP, //!< 进行映射操作
TASK_OBJ_UNMAP, //!< 进行解除映射操作
TASK_ALLOC_RAM_BASE, //!< 分配task的基础内存
@@ -70,12 +71,14 @@ INIT_KOBJ_MEM(task_mem_init);
*/
int task_alloc_base_ram(task_t *tk, ram_limit_t *lim, size_t size)
{
if (tk->mm_space.mm_block) {
if (tk->mm_space.mm_block)
{
return -EACCES;
}
// 申请init的ram内存
void *ram = mpu_ram_alloc(&tk->mm_space, lim, size + THREAD_MSG_BUG_LEN);
if (!ram) {
if (!ram)
{
printk("Failed to request process memory.\n");
return -ENOMEM;
}
@@ -105,10 +108,13 @@ task_t *thread_get_bind_task(thread_t *th)
*/
static void task_unlock_2(spinlock_t *sp0, spinlock_t *sp1, int status0, int status1)
{
if (sp0 < sp1) {
if (sp0 < sp1)
{
spinlock_set(sp1, status1);
spinlock_set(sp0, status0);
} else {
}
else
{
spinlock_set(sp0, status0);
spinlock_set(sp1, status1);
}
@@ -126,25 +132,32 @@ static int task_lock_2(spinlock_t *sp0, spinlock_t *sp1, int *st0, int *st1)
{
int status0;
int status1;
if (sp0 < sp1) {
if (sp0 < sp1)
{
status0 = spinlock_lock(sp0);
if (status0 < 0) {
if (status0 < 0)
{
return FALSE;
}
status1 = spinlock_lock(sp1);
if (status1 < 0) {
if (status1 < 0)
{
spinlock_set(sp0, status0);
return FALSE;
}
*st0 = status0;
*st1 = status1;
} else {
}
else
{
status0 = spinlock_lock(sp1);
if (status0 < 0) {
if (status0 < 0)
{
return FALSE;
}
status1 = spinlock_lock(sp0);
if (status1 < 0) {
if (status1 < 0)
{
spinlock_set(sp1, status0);
return FALSE;
}
@@ -164,10 +177,13 @@ int task_set_pid(task_t *task, pid_t pid)
{
task_t *cur_task = thread_get_current_task();
if (cur_task->pid == 0) {
if (cur_task->pid == 0)
{
task->pid = pid;
return 0;
} else {
}
else
{
return -EACCES;
}
}
@@ -185,21 +201,26 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
task_t *tag_task = container_of(kobj, task_t, kobj);
msg_tag_t tag = msg_tag_init4(0, 0, 0, -EINVAL);
if (sys_p.prot != TASK_PROT) {
if (sys_p.prot != TASK_PROT)
{
f->regs[0] = msg_tag_init4(0, 0, 0, -EINVAL).raw;
return;
}
switch (sys_p.op) {
case TASK_SET_OBJ_NAME: {
switch (sys_p.op)
{
case TASK_SET_OBJ_NAME:
{
mword_t status = spinlock_lock(&tag_task->kobj.lock);
if (status < 0) {
if (status < 0)
{
tag = msg_tag_init4(0, 0, 0, -EINVAL);
break;
}
kobject_t *source_kobj = obj_space_lookup_kobj(&cur_task->obj_space, f->regs[0]);
if (!source_kobj) {
if (!source_kobj)
{
spinlock_set(&tag_task->kobj.lock, status);
tag = msg_tag_init4(0, 0, 0, -EINVAL);
break;
@@ -207,17 +228,20 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
kobject_set_name(source_kobj, (char *)(&f->regs[1]));
spinlock_set(&tag_task->kobj.lock, status);
tag = msg_tag_init4(0, 0, 0, 1);
} break;
}
break;
case TASK_OBJ_VALID: //!< 查看某个obj在task中是否存在
{
mword_t status = spinlock_lock(&tag_task->kobj.lock);
if (status < 0) {
if (status < 0)
{
tag = msg_tag_init4(0, 0, 0, -EINVAL);
break;
}
kobject_t *source_kobj = obj_space_lookup_kobj(&cur_task->obj_space, f->regs[1]);
if (!source_kobj) {
if (!source_kobj)
{
spinlock_set(&tag_task->kobj.lock, status);
tag = msg_tag_init4(0, 0, 0, 0);
break;
@@ -225,7 +249,8 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
f->regs[1] = source_kobj->kobj_type;
spinlock_set(&tag_task->kobj.lock, status);
tag = msg_tag_init4(0, 0, 0, 1);
} break;
}
break;
case TASK_OBJ_MAP: //!< 从一个task中映射一个对象到目标进程
{
kobj_del_list_t del;
@@ -233,7 +258,8 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
kobj_del_list_init(&del);
int suc = task_lock_2(&tag_task->kobj.lock, &cur_task->kobj.lock, &st0, &st1);
if (!suc) {
if (!suc)
{
tag = msg_tag_init4(0, 0, 0, -EINVAL);
break;
}
@@ -243,14 +269,16 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
kobj_del_list_to_do(&del);
task_unlock_2(&tag_task->kobj.lock, &cur_task->kobj.lock, st0, st1);
tag = msg_tag_init4(0, 0, 0, ret);
} break;
}
break;
case TASK_OBJ_UNMAP: //!< 解除task中一个进程的创建
{
kobject_t *del_kobj;
kobj_del_list_t kobj_list;
mword_t status = spinlock_lock(&tag_task->kobj.lock);
if (status < 0) {
if (status < 0)
{
tag = msg_tag_init4(0, 0, 0, -EINVAL);
break;
}
@@ -261,12 +289,14 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
kobj_del_list_to_do(&kobj_list);
cpulock_set(status);
tag = msg_tag_init4(0, 0, 0, 0);
} break;
}
break;
#if !IS_ENABLED(CONFIG_MMU)
case TASK_ALLOC_RAM_BASE: //!< 分配task所拥有的内存空间
{
mword_t status = spinlock_lock(&tag_task->kobj.lock);
if (status < 0) {
if (status < 0)
{
tag = msg_tag_init4(0, 0, 0, -EINVAL);
break;
}
@@ -274,7 +304,8 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
tag = msg_tag_init4(0, 0, 0, ret);
f->regs[1] = (umword_t)(tag_task->mm_space.mm_block);
spinlock_set(&tag_task->kobj.lock, status);
} break;
}
break;
#endif
case TASK_COPY_DATA: //!< 拷贝数据到task的内存区域
{
@@ -284,11 +315,13 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
umword_t st_addr = f->regs[0];
size_t cp_size = f->regs[1];
if (cp_size > THREAD_MSG_BUG_LEN) {
if (cp_size > THREAD_MSG_BUG_LEN)
{
tag = msg_tag_init4(0, 0, 0, -EINVAL);
break;
}
if (!is_rw_access(tag_task, (void *)st_addr, cp_size, FALSE)) {
if (!is_rw_access(tag_task, (void *)st_addr, cp_size, FALSE))
{
tag = msg_tag_init4(0, 0, 0, -EPERM);
break;
}
@@ -302,12 +335,14 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
case TASK_SET_PID: //!< 设置pid
{
tag = msg_tag_init4(0, 0, 0, task_set_pid(tag_task, f->regs[0]));
} break;
}
break;
case TASK_GET_PID: //!< 获取pid
{
f->regs[1] = tag_task->pid;
tag = msg_tag_init4(0, 0, 0, 0);
} break;
}
break;
default:
break;
}
@@ -335,7 +370,8 @@ void task_init(task_t *task, ram_limit_t *ram, int is_knl)
#if IS_ENABLED(CONFIG_MMU)
knl_pdir_init(&task->mm_space.mem_dir, task->mm_space.mem_dir.dir, 3 /*TODO:*/);
#else
mm_space_add(&task->mm_space, CONFIG_KNL_TEXT_ADDR, CONFIG_KNL_TEXT_SIZE, REGION_RO);
task_vma_alloc(&task->mm_space.mem_vma, vma_addr_create(VPAGE_PROT_RO, 0, 0),
CONFIG_KNL_TEXT_SIZE, CONFIG_KNL_TEXT_ADDR, NULL);
#endif
}
@@ -366,7 +402,8 @@ static void task_release_stage2(kobject_t *kobj)
obj_space_release(&tk->obj_space, tk->lim);
#if !IS_ENABLED(CONFIG_MMU)
if (tk->mm_space.mm_block) {
if (tk->mm_space.mm_block)
{
#if CONFIG_MK_MPU_CFG
mm_limit_free_align(tk->lim, tk->mm_space.mm_block, tk->mm_space.mm_block_size);
#else
@@ -405,7 +442,8 @@ task_t *task_create(ram_limit_t *lim, int is_knl)
tk = mm_limit_alloc(lim, sizeof(task_t));
#endif
if (!tk) {
if (!tk)
{
return NULL;
}
task_init(tk, lim, is_knl);

View File

@@ -1,9 +1,9 @@
#!/bin/bash
export TOOLCHAIN=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/bin/
export TOOLCHAIN_LIB=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/lib/gcc/arm-none-eabi/10.3.1/thumb/v7-m/nofp
# export TOOLCHAIN=/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/bin/
# export TOOLCHAIN_LIB=/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/lib/gcc/arm-none-eabi/5.4.1/armv7-m/
# export TOOLCHAIN=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/bin/
# export TOOLCHAIN_LIB=/Users/zhangzheng/gcc-arm-none-eabi-10.3-2021.10/lib/gcc/arm-none-eabi/10.3.1/thumb/v7-m/nofp
export TOOLCHAIN=/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/bin/
export TOOLCHAIN_LIB=/home/zhangzheng/gcc-arm-none-eabi-5_4-2016q3/lib/gcc/arm-none-eabi/5.4.1/armv7-m/
export BOARD=STM32F205
export CROSS_COMPILE_NAME=arm-none-eabi-

View File

@@ -1,9 +1,9 @@
#!/bin/bash
export TOOLCHAIN=/Applications/ArmGNUToolchain/11.3.rel1/aarch64-none-elf/bin/
export TOOLCHAIN_LIB=/Applications/ArmGNUToolchain/11.3.rel1/aarch64-none-elf/lib/gcc/aarch64-none-elf/11.3.1
# export TOOLCHAIN=/home/toolchains/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/
# export TOOLCHAIN_LIB=/home/toolchains/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/lib/gcc/aarch64-none-elf/10.3.1
# export TOOLCHAIN=/Applications/ArmGNUToolchain/11.3.rel1/aarch64-none-elf/bin/
# export TOOLCHAIN_LIB=/Applications/ArmGNUToolchain/11.3.rel1/aarch64-none-elf/lib/gcc/aarch64-none-elf/11.3.1
export TOOLCHAIN=/home/toolchains/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin/
export TOOLCHAIN_LIB=/home/toolchains/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/lib/gcc/aarch64-none-elf/10.3.1
export BOARD=aarch64_qemu
export CROSS_COMPILE_NAME=aarch64-none-elf-
if [ -z "$1" ]; then

View File

@@ -2,7 +2,7 @@
#include "syscall_backend.h"
#include "u_prot.h"
#include "u_ipc.h"
#include "u_mm.h"
#include "u_app.h"
#include "cons_cli.h"
#include "u_arch.h"

View File

@@ -2,7 +2,7 @@
#include "syscall_backend.h"
#include "u_prot.h"
#include "u_ipc.h"
#include "u_mm.h"
#include "u_app.h"
#include "cons_cli.h"
#include "u_arch.h"

View File

@@ -1,14 +0,0 @@
#pragma once
#include "u_types.h"
#include "u_prot.h"
#include "u_arch.h"
enum region_rights
{
REGION_PRIV = 1,
REGION_RO = 2,
REGION_RWX = 3,
};
void *mm_alloc_page(obj_handler_t obj_inx, umword_t pnf_nr, uint8_t attrs);
void mm_free_page(obj_handler_t obj_inx, void *addr, umword_t pfn_nr);
msg_tag_t mm_align_alloc(obj_handler_t obj_inx, void *addr, umword_t size);

View File

@@ -9,7 +9,6 @@ enum kobj_prot
TASK_PROT,
LOG_PROT,
IPC_PROT,
MM_PROT,
SYS_PROT,
FUTEX_PROT,
IRQ_PROT,

View File

@@ -23,8 +23,13 @@ typedef union vma_addr
umword_t raw;
struct
{
#if IS_ENABLED(CONFIG_MMU)
umword_t prot : 8;
umword_t flags : 4;
#else
umword_t prot : 6;
umword_t flags : 3;
#endif
// umword_t resv : 2;
umword_t addr : (sizeof(void *) * 8 - CONFIG_PAGE_SHIFT);
};

View File

@@ -1,65 +0,0 @@
#include "u_mm.h"
#include "u_types.h"
#include "u_prot.h"
#include "u_arch.h"
enum mm_op
{
MM_ALLOC,
MM_FREE,
MM_ALIGN_ALLOC, //!< 直接暂用一个region
MM_ALIGN_FREE,
MM_MOD_ATTRS,
};
void *mm_alloc_page(obj_handler_t obj_inx, umword_t pnf_nr, uint8_t attrs)
{
register volatile umword_t r0 asm(ARCH_REG_0);
register volatile umword_t r1 asm(ARCH_REG_1);
register volatile umword_t r2 asm(ARCH_REG_2);
register volatile umword_t r3 asm(ARCH_REG_3);
mk_syscall(syscall_prot_create(MM_ALLOC, MM_PROT, obj_inx).raw,
0,
pnf_nr,
attrs,
0,
0,
0);
asm __volatile__(""
:
:
: ARCH_REG_0, ARCH_REG_1, ARCH_REG_2, ARCH_REG_3);
{
msg_tag_t tag = msg_tag_init(r0);
if (msg_tag_get_prot(tag) < 0)
{
return NULL;
}
return (void *)r1;
}
return NULL; /*TODO:*/
}
void mm_free_page(obj_handler_t obj_inx, void *addr, umword_t pfn_nr)
{
mk_syscall(syscall_prot_create(MM_FREE, MM_PROT, obj_inx).raw,
0,
addr,
pfn_nr,
0,
0,
0);
}
msg_tag_t mm_align_alloc(obj_handler_t obj_inx, void *addr, umword_t size)
{
register volatile umword_t r0 asm(ARCH_REG_0);
mk_syscall(syscall_prot_create(MM_ALIGN_ALLOC, MM_PROT, obj_inx).raw,
0,
addr,
size,
0,
0,
0);
return msg_tag_init(r0);
}

View File

@@ -12,7 +12,6 @@
#include "u_prot.h"
#include "u_app.h"
#include "u_factory.h"
#include "u_mm.h"
#include "u_task.h"
#include "u_hd_man.h"
#include "u_thread.h"
@@ -196,7 +195,7 @@ int app_load(const char *name, uenv_t *cur_env, pid_t *pid, char *argv[], int ar
{
goto end_del_obj;
}
tag = task_map(hd_task, MM_PROT, MM_PROT, KOBJ_DELETE_RIGHT);
tag = task_map(hd_task, VMA_PROT, VMA_PROT, KOBJ_DELETE_RIGHT);
if (msg_tag_get_prot(tag) < 0)
{
goto end_del_obj;

View File

@@ -2,19 +2,19 @@
#include "u_types.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_sleep.h"
// AUTO_CALL(101)
int u_drv_init(void)
{
msg_tag_t tag;
// msg_tag_t tag;
tag = mm_align_alloc(MM_PROT, (void *)0x40000000, 0x50000000 - 0x40000000);
if (msg_tag_get_val(tag) < 0)
{
return msg_tag_get_val(tag);
}
// tag = mm_align_alloc(MM_PROT, (void *)0x40000000, 0x50000000 - 0x40000000);
// if (msg_tag_get_val(tag) < 0)
// {
// return msg_tag_get_val(tag);
// }
return 0;
}

View File

@@ -13,7 +13,7 @@
#include "u_app.h"
#include "u_arch.h"
#include "u_factory.h"
#include "u_mm.h"
#include "u_task.h"
#include "u_hd_man.h"
#include "u_thread.h"
@@ -209,11 +209,6 @@ int app_load(const char *name, uenv_t *cur_env, pid_t *pid, char *argv[], int ar
{
goto end_del_obj;
}
tag = task_map(hd_task, MM_PROT, MM_PROT, KOBJ_DELETE_RIGHT);
if (msg_tag_get_prot(tag) < 0)
{
goto end_del_obj;
}
tag = task_map(hd_task, VMA_PROT, VMA_PROT, KOBJ_DELETE_RIGHT);
if (msg_tag_get_prot(tag) < 0)
{

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -29,7 +29,7 @@ elseif(${CONFIG_ARCH} STREQUAL "aarch64" )
)
add_subdirectory(uvmm)
add_subdirectory(test)
# add_subdirectory(test)
endif()
add_subdirectory(init)
add_subdirectory(shell)

View File

@@ -1,7 +1,7 @@
#include "u_types.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_sleep.h"
#include "u_drv.h"

View File

@@ -4,7 +4,7 @@
#include "u_factory.h"
#include "u_hd_man.h"
#include "u_irq_sender.h"
#include "u_mm.h"
#include "u_log.h"
#include "u_local_thread.h"
#include <assert.h>

View File

@@ -1,7 +1,7 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -11,7 +11,7 @@
#include "x_malloc.h"
#include <stdlib.h>
#include <stdio.h>
#include "u_mm.h"
void *XMalloc(uint32_t size)
{
void *mem = mm_alloc_page(MM_PROT, size, 0);

View File

@@ -10,7 +10,6 @@
*/
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,6 +1,5 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,6 +1,5 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -3,7 +3,6 @@
#include "u_hd_man.h"
#include "u_ipc.h"
#include "u_log.h"
#include "u_mm.h"
#include "u_prot.h"
#include "u_sleep.h"
#include "u_task.h"

View File

@@ -3,7 +3,6 @@
#include <pthread.h>
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -10,6 +10,11 @@
#include <CuTest.h>
static void sharea_mem_test(CuTest *cu)
{
#if IS_ENABLED(CONFIG_MMU)
#define TEST_MEM_SIZE (PAGE_SIZE * 100)
#else
#define TEST_MEM_SIZE (PAGE_SIZE)
#endif
addr_t addr;
umword_t size;
obj_handler_t hd = handler_alloc();
@@ -17,7 +22,7 @@ static void sharea_mem_test(CuTest *cu)
msg_tag_t tag = facotry_create_share_mem(FACTORY_PROT,
vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, hd),
SHARE_MEM_CNT_BUDDY_CNT,
PAGE_SIZE * 100);
TEST_MEM_SIZE);
assert(msg_tag_get_prot(tag) >= 0);
tag = share_mem_map(hd, vma_addr_create(VPAGE_PROT_RW, VMA_ADDR_RESV, 0), &addr, &size);
assert(msg_tag_get_prot(tag) >= 0);
@@ -29,12 +34,13 @@ static void sharea_mem_test(CuTest *cu)
share_mem_unmap(hd);
handler_free_umap(hd);
#if IS_ENABLED(CONFIG_MMU)
hd = handler_alloc();
assert(hd != HANDLER_INVALID);
tag = facotry_create_share_mem(FACTORY_PROT,
vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, hd),
SHARE_MEM_CNT_DPD,
PAGE_SIZE * 100);
TEST_MEM_SIZE);
assert(msg_tag_get_prot(tag) >= 0);
tag = share_mem_map(hd, vma_addr_create(VPAGE_PROT_RW, VMA_ADDR_RESV, 0), &addr, &size);
assert(msg_tag_get_prot(tag) >= 0);
@@ -45,6 +51,8 @@ static void sharea_mem_test(CuTest *cu)
memset((void *)addr, 0, size);
share_mem_unmap(hd);
handler_free_umap(hd);
#endif
#undef TEST_MEM_SIZE
}
static CuSuite suite;
CuSuite *sharem_mem_test_suite(void)

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,7 +1,7 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,6 +1,6 @@
#include "u_types.h"
#include "u_prot.h"
#include "u_mm.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>

View File

@@ -1,23 +0,0 @@
#include "u_types.h"
#include "u_prot.h"
#include "u_factory.h"
#include "u_task.h"
#include "u_hd_man.h"
#include "u_share_mem.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
void sharea_mem_test(void)
{
addr_t addr;
umword_t size;
obj_handler_t hd = handler_alloc();
assert(hd != HANDLER_INVALID);
msg_tag_t tag = facotry_create_share_mem(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, hd), 1024);
assert(msg_tag_get_prot(tag) >= 0);
tag = share_mem_map(hd, 3, &addr, &size);
assert(msg_tag_get_prot(tag) >= 0);
memset((void *)addr, 0, size);
// share_mem_unmap(hd);
handler_free_umap(hd);
}

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -19,10 +19,8 @@ static void RunAllTests(void)
CuSuiteAddSuite(&suite, ipc_test_suite());
CuSuiteAddSuite(&suite, ulog_test_suite());
CuSuiteAddSuite(&suite, printf_test_suite());
#if IS_ENABLED(CONFIG_MMU)
CuSuiteAddSuite(&suite, vmm_test_suite());
CuSuiteAddSuite(&suite, sharem_mem_test_suite());
#endif
CuSuiteAddSuite(&suite, map_test_suite());
CuSuiteAddSuite(&suite, thread_base_test_suite());
CuSuiteAddSuite(&suite, sema_test_suite());

View File

@@ -5,7 +5,6 @@
#include "u_hd_man.h"
#include "u_ipc.h"
#include "u_log.h"
#include "u_mm.h"
#include "u_prot.h"
#include "u_sleep.h"
#include "u_task.h"

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -6,6 +6,8 @@
#include <u_hd_man.h>
#include <u_vmam.h>
#include <stdio.h>
#if IS_ENABLED(CONFIG_MMU)
static void vmm_large_block_test(CuTest *cu)
{
addr_t addr;
@@ -22,6 +24,7 @@ static void vmm_large_block_test(CuTest *cu)
#undef TEST_MM_SIZE
#undef TEST_CN
}
#endif
static void vmm_small_block_test(CuTest *cu)
{
addr_t addr;
@@ -42,29 +45,33 @@ static void vmm_small_block_test(CuTest *cu)
static void *test_main[TEST_MEM_CN];
static void vmm_press_block_test(CuTest *cu)
{
int i;
int m;
addr_t addr;
msg_tag_t tag;
#define TEST_MM_SIZE (PAGE_SIZE)
for (int i = 0; i < TEST_MEM_CN; i++)
for (i = 0; i < TEST_MEM_CN; i++)
{
tag = u_vmam_alloc(VMA_PROT, vma_addr_create(VPAGE_PROT_RWX, 0, 0), TEST_MM_SIZE, 0, &addr);
CuAssert(cu, "vmam alloc faile.\n", msg_tag_get_val(tag) >= 0);
if (msg_tag_get_val(tag) < 0) {
break;
}
memset((void *)addr, 0x55, TEST_MM_SIZE);
// printf("alloc umem:0x%lx\n", addr);
test_main[i] = (void *)addr;
}
for (int i = 0; i < TEST_MEM_CN; i++)
for (m = 0; m < i; m++)
{
for (int j = 0; j < TEST_MM_SIZE; j++)
{
uint8_t *tmp_mm = test_main[i];
uint8_t *tmp_mm = test_main[m];
if (tmp_mm[j] != 0x55)
{
printf("mem test fail. i:%d j:%d\n", i, j);
printf("mem test fail. i:%d j:%d\n", m, j);
}
assert(tmp_mm[j] == 0x55);
}
u_vmam_free(VMA_PROT, (addr_t)(test_main[i]), TEST_MM_SIZE);
u_vmam_free(VMA_PROT, (addr_t)(test_main[m]), TEST_MM_SIZE);
}
#undef TEST_MM_SIZE
@@ -75,7 +82,9 @@ CuSuite *vmm_test_suite(void)
{
CuSuiteInit(&suite);
#if IS_ENABLED(CONFIG_MMU)
SUITE_ADD_TEST(&suite, vmm_large_block_test);
#endif
SUITE_ADD_TEST(&suite, vmm_small_block_test);
SUITE_ADD_TEST(&suite, vmm_press_block_test);

View File

@@ -9,7 +9,7 @@
// #include "libc.h"
#include "lwiperf.h"
#include "u_prot.h"
#include "u_mm.h"
#include <u_hd_man.h>
#include <u_task.h>
#include <u_factory.h>

View File

@@ -1,7 +1,7 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -3,7 +3,6 @@
#include <pthread.h>
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -2,7 +2,7 @@
#include "u_prot.h"
#include "u_app.h"
#include "u_factory.h"
#include "u_mm.h"
#include "u_task.h"
#include "u_hd_man.h"
#include "u_thread.h"

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -5,7 +5,7 @@
#include "u_factory.h"
#include "u_hd_man.h"
#include "u_irq_sender.h"
#include "u_mm.h"
#include "u_log.h"
#include <assert.h>
#include <stm32f2xx.h>

View File

@@ -1,7 +1,7 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,6 +1,6 @@
#include "u_types.h"
#include "u_prot.h"
#include "u_mm.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>

View File

@@ -1,7 +1,7 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -1,6 +1,6 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"

View File

@@ -47,5 +47,5 @@ int main(int argc, char *args[])
}
IMPORT_BIN(".rodata", "/Users/zhangzheng/mkrtos-real/mkrtos_user/server/uvmm/src/benos.bin", benos_bin);
IMPORT_BIN(".rodata", "/Users/zhangzheng/mkrtos-real/mkrtos_user/server/uvmm/src/vm_benos.json", benos_json);
IMPORT_BIN(".rodata", "/home/mkrtos-real/mkrtos_user/server/uvmm/src/benos.bin", benos_bin);
IMPORT_BIN(".rodata", "/home/mkrtos-real/mkrtos_user/server/uvmm/src/vm_benos.json", benos_json);