更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_user_init.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_user_init.h"
33#include "los_syscall.h"
34
35#ifdef LOSCFG_KERNEL_SYSCALL
36
37#define SYS_CALL_VALUE 0x900001
38
39//加载init进程
40
41#ifdef LOSCFG_QUICK_START
42LITE_USER_SEC_RODATA STATIC CHAR *g_initPath = "/dev/shm/init";
43#else
44LITE_USER_SEC_RODATA STATIC CHAR *g_initPath = "/bin/init";//由Init_lite在编译后,生成
45#endif
46///将 sys_call3 链接在 section(".user.text")段
47LITE_USER_SEC_TEXT STATIC UINT32 sys_call3(UINT32 nbr, UINT32 parm1, UINT32 parm2, UINT32 parm3)
48{
49 register UINT32 reg7 __asm__("r7") = (UINT32)(nbr); //系统调用号给了R7寄存器
50 register UINT32 reg2 __asm__("r2") = (UINT32)(parm3);//R2 = 参数3
51 register UINT32 reg1 __asm__("r1") = (UINT32)(parm2);//R1 = 参数2
52 register UINT32 reg0 __asm__("r0") = (UINT32)(parm1);//R0 = 参数1
53
54 //SVC指令会触发一个特权调用异常。这为非特权软件调用操作系统或其他只能在PL1级别访问的系统组件提供了一种机制。
55 __asm__ __volatile__
56 (
57 "svc %1" //管理模式(svc) [10011]:操作系统使用的保护模式
58 : "=r"(reg0) //输出寄存器为R0
59 : "i"(SYS_CALL_VALUE), "r"(reg7), "r"(reg0), "r"(reg1), "r"(reg2)
60 : "memory", "r14"
61 );
62 //相当于执行了 reset_vector_mp.S 中的 向量表0x08对应的 _osExceptSwiHdl
63 return reg0;//reg0的值将在汇编中改变.
64}
65
66LITE_USER_SEC_ENTRY VOID OsUserInit(VOID *args)
67{
68#ifdef LOSCFG_KERNEL_DYNLOAD
69 sys_call3(__NR_execve, (UINTPTR)g_initPath, 0, 0);//发起系统调用,陷入内核态,对应 SysExecve ,加载elf运行
70#endif
71 while (true) {
72 }
73}
74#endif
macro EXC_SP_SET reg0
Definition: asm.h:50
macro EXC_SP_SET reg1 mrc 获取CPU信息 and mov reg1
Definition: asm.h:53
unsigned long UINTPTR
Definition: los_typedef.h:68
unsigned int UINT32
Definition: los_typedef.h:57
char CHAR
Definition: los_typedef.h:63
LITE_USER_SEC_RODATA STATIC CHAR * g_initPath
Definition: los_user_init.c:42
LITE_USER_SEC_ENTRY VOID OsUserInit(VOID *args)
Definition: los_user_init.c:66
LITE_USER_SEC_TEXT STATIC UINT32 sys_call3(UINT32 nbr, UINT32 parm1, UINT32 parm2, UINT32 parm3)
将 sys_call3 链接在 section(".user.text")段
Definition: los_user_init.c:47