• 上电的第一行代码是硬件复位中断的入口,也就是RAM零地址的代码,属于boot代码的一部分

  • 芯片启动流程 - 内核概述

  • 内核代码具体的细节,ARM Cortex-M可以参考LiteOS-M,ARM Cortex-A可以参考LiteOS-A或者Linux内核

  • 本来芯片上电后的第一行代码应该是能在源码中看到的,但是OpenHarmony中使用了ARM的CMSIS官方库,也就是说上电时的第一行代码已经融合进编译器里面去了,所以你看不到,只能看到第二行代码,那就是 Reset_Handler() 复位中断函数

    • RAM的0地址就是第一行代码,同时也是reset复位中断的入口,在这里的代码只有一个目的,那就是复位中断进来后立马调用 Reset_Handler() 函数,这里既可以调用汇编的reset函数,也可以调用C语言函数。
  • 搜索 Reset_Handler 这个函数,这是上电后执行的第二行代码

    • arm/cortex-m4/gcc/los_interrupt.c: hwiForm[1] = (HWI_PROC_FUNC)Reset_Handler; /* [1] reset */
    • arm/cortex-m3/keil/los_startup.s:Reset_Handler
  • ARM官方CMSIS的API一般都是NVIC_开头的函数,和上电后先调用的函数有:

    • HalHwiInit ArchInit LOS_KernelInit kal/cmsis/cmsis_liteos2.c osKernelInitialize
jim@ubuntu:~/openHarmony/kernel/liteos_m/arch/arm/cortex-m3/keil$ ls
los_arch_atomic.h   los_arch_interrupt.h  los_atomic.S   los_dispatch.S  los_interrupt.c  los_timer.c
los_arch_context.h  los_arch_timer.h      los_context.c  los_exc.S       los_startup.s

jim@ubuntu:~/openHarmony$ cat kernel/liteos_m/arch/arm/cortex-m4/gcc/los_interrupt.c 

#include <stdarg.h>
#include "securec.h"
#include "los_context.h"
#include "los_arch_interrupt.h"
#include "los_hook.h"
#include "los_task.h"
#include "los_sched.h"
#include "los_memory.h"
#include "los_membox.h"
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
#include "los_cpup.h"
#endif

/* ****************************************************************************
 Function    : HalHwiInit
 Description : initialization of the hardware interrupt
 Input       : None
 Output      : None
 Return      : None
 **************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
{
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
    UINT32 index;
    HWI_PROC_FUNC *hwiForm = (HWI_PROC_FUNC *)ArchGetHwiFrom();
    hwiForm[0] = 0; /* [0] Top of Stack */
    hwiForm[1] = (HWI_PROC_FUNC)Reset_Handler; /* [1] reset */
    for (index = 2; index < OS_VECTOR_CNT; index++) { /* 2: The starting position of the interrupt */
        hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
    }

    /* Interrupt vector table location */
    SCB->VTOR = (UINT32)(UINTPTR)hwiForm;
#endif
#if (__CORTEX_M >= 0x03U) /* only for Cortex-M3 and above */
    NVIC_SetPriorityGrouping(OS_NVIC_AIRCR_PRIGROUP);
#endif

    return;
}

/* ======== */

jim@ubuntu:~/openHarmony/third_party$ cat cmsis/Device/ARM/ARMCM55/Source/startup_ARMCM55.c

/*----------------------------------------------------------------------------
  Reset Handler called on controller reset
 *----------------------------------------------------------------------------*/
__NO_RETURN void Reset_Handler(void)
{
  __set_PSP((uint32_t)(&__INITIAL_SP));

  __set_MSPLIM((uint32_t)(&__STACK_LIMIT));
  __set_PSPLIM((uint32_t)(&__STACK_LIMIT));

#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  __TZ_set_STACKSEAL_S((uint32_t *)(&__STACK_SEAL));
#endif

  SystemInit();                             /* CMSIS System Initialization */
  __PROGRAM_START();                        /* Enter PreMain (C library entry point) */
}

  • 这个复位中断里会一级一级往后调用,你建个工程在代码里面一步步跳转就可以溯源了。

为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:https://qr21.cn/FV7h05

《鸿蒙开发学习手册》:

如何快速入门:https://qr21.cn/FV7h05

  1. 基本概念
  2. 构建第一个ArkTS应用
  3. ……

开发基础知识:https://qr21.cn/FV7h05

  1. 应用基础知识
  2. 配置文件
  3. 应用数据管理
  4. 应用安全管理
  5. 应用隐私保护
  6. 三方应用调用管控机制
  7. 资源分类与访问
  8. 学习ArkTS语言
  9. ……

基于ArkTS 开发:https://qr21.cn/FV7h05

  1. Ability开发
  2. UI开发
  3. 公共事件与通知
  4. 窗口管理
  5. 媒体
  6. 安全
  7. 网络与链接
  8. 电话服务
  9. 数据管理
  10. 后台任务(Background Task)管理
  11. 设备管理
  12. 设备使用信息统计
  13. DFX
  14. 国际化开发
  15. 折叠屏系列
  16. ……

鸿蒙开发面试真题(含参考答案):https://qr18.cn/F781PH

鸿蒙开发面试大盘集篇(共计319页):https://qr18.cn/F781PH

1.项目开发必备面试题
2.性能优化方向
3.架构方向
4.鸿蒙开发系统底层方向
5.鸿蒙音视频开发方向
6.鸿蒙车载开发方向
7.鸿蒙南向开发方向

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐