更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_vm_boot.c
浏览该文件的文档.
1/*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include "los_vm_boot.h"
33#include "los_config.h"
34#include "los_base.h"
35#include "los_vm_zone.h"
36#include "los_vm_map.h"
37#include "los_memory_pri.h"
38#include "los_vm_page.h"
39#include "los_arch_mmu.h"
40
41/**
42 * @brief 虚拟内存区间检查, 需理解 los_vm_zone.h 中画出的鸿蒙虚拟内存全景图
43 */
44
45UINTPTR g_vmBootMemBase = (UINTPTR)&__bss_end; ///< 内核空间可用于分配的区域,紧挨着.bss区
46BOOL g_kHeapInited = FALSE; ///< 内核堆区初始化变量
47
48
49///< 开机引导分配器分配内存,只有开机时采用的分配方式
50VOID *OsVmBootMemAlloc(size_t len)
51{
52 UINTPTR ptr;
53
54 if (g_kHeapInited) {
55 VM_ERR("kernel heap has been initialized, do not to use boot memory allocation!");
56 return NULL;
57 }
58
59 ptr = LOS_Align(g_vmBootMemBase, sizeof(UINTPTR));//对齐
60 g_vmBootMemBase = ptr + LOS_Align(len, sizeof(UINTPTR));//通过改变 g_vmBootMemBase来获取内存
61 //这样也行,g_vmBootMemBase 真是野蛮粗暴
62 return (VOID *)ptr;
63}
64///整个系统内存初始化
66{
67 STATUS_T ret;
68
69#ifdef LOSCFG_KERNEL_VM
70 OsKSpaceInit();//内核空间初始化
71#endif
72
73 ret = OsKHeapInit(OS_KHEAP_BLOCK_SIZE);// 内核堆空间初始化 512K
74 if (ret != LOS_OK) {
75 VM_ERR("OsKHeapInit fail\n");
76 return LOS_NOK;
77 }
78
79#ifdef LOSCFG_KERNEL_VM
80 OsVmPageStartup();// 物理内存初始化
81 g_kHeapInited = TRUE; //内核堆区初始化完成
82 OsInitMappingStartUp();//映射初始化
83#else
84 g_kHeapInited = TRUE;//内核堆区完成初始化
85#endif
86 return LOS_OK;
87}
88
LITE_OS_SEC_TEXT UINTPTR LOS_Align(UINTPTR addr, UINT32 boundary)
Align the value (addr) by some bytes (boundary) you specify.
Definition: los_misc.c:35
VOID OsInitMappingStartUp(VOID)
OsInitMappingStartUp 开始初始化mmu
https://blog.csdn.net/qq_38410730/article/details/81036768
CHAR __bss_end
bss结束地址 attribute((section(".__bss_end")));
STATUS_T OsKHeapInit(size_t size)
内核空间动态内存(堆内存)初始化 , 争取系统动态内存池
Definition: los_memory.c:2095
int STATUS_T
Definition: los_typedef.h:215
unsigned long UINTPTR
Definition: los_typedef.h:68
unsigned int UINT32
Definition: los_typedef.h:57
size_t BOOL
Definition: los_typedef.h:88
VOID * OsVmBootMemAlloc(size_t len)
Definition: los_vm_boot.c:50
BOOL g_kHeapInited
内核堆区初始化变量
Definition: los_vm_boot.c:46
UINT32 OsSysMemInit(VOID)
整个系统内存初始化
Definition: los_vm_boot.c:65
UINTPTR g_vmBootMemBase
虚拟内存区间检查, 需理解 los_vm_zone.h 中画出的鸿蒙虚拟内存全景图
Definition: los_vm_boot.c:45
VOID OsKSpaceInit(VOID)
内核虚拟空间初始化
Definition: los_vm_map.c:250
VOID OsVmPageStartup(VOID)
Definition: los_vm_page.c:72