分享

lpc2124 启动代码详解

 弓道自然_改名 2014-07-24

lpc2124 启动代码详解  

2010-07-08 11:37:49|  分类: 默认分类|举报|字号 订阅

;/*****************************************************************************/
;/* STARTUP.S: Startup file for Philips LPC2000                               */
;/*****************************************************************************/
;/* <<< Use Configuration Wizard in Context Menu >>>                          */ 
;/*****************************************************************************/
;/* This file is part of the uVision/ARM development tools.                   */
;/* Copyright (c) 2005-2007 Keil Software. All rights reserved.               */
;/* This software may only be used under the terms of a valid, current,       */
;/* end user licence from KEIL for a compatible version of KEIL software      */
;/* development tools. Nothing else gives you the right to use this software. */
;/*****************************************************************************/


;/*
; *  The STARTUP.S code is executed after CPU Reset. This file may be 
; *  translated with the following SET symbols. In uVision these SET 
; *  symbols are entered under Options - ASM - Define.
; *
; *  REMAP: when set the startup code initializes the register MEMMAP 
; *  which overwrites the settings of the CPU configuration pins. The 
; *  startup and interrupt vectors are remapped from:
; *     0x00000000  default setting (not remapped)
; *     0x80000000  when EXTMEM_MODE is used
; *     0x40000000  when RAM_MODE is used
; *
; *  EXTMEM_MODE: when set the device is configured for code execution
; *  from external memory starting at address 0x80000000.
; *
; *  RAM_MODE: when set the device is configured for code execution
; *  from on-chip RAM starting at address 0x40000000.
; *
; *  EXTERNAL_MODE: when set the PIN2SEL values are written that enable
; *  the external BUS at startup.
; */

;
; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs.
; 处理器需定义七种工作方式
; 如下 7种定义的常量参数由来:
; 这7个常量定义为处理器 7种运行模式的参数,为7种“当前程序状态寄存器” CPSR 模式设置位 M[4:0]的值。
; 比如这里的用户模式,CPSR的M[4:0], 设置为10000就是0x10.
; 同理其他.详见<<嵌入式系统开发与应用>>P71. CPSR设置很关键! 
;  
; ARM 有7种工作模式:
; User: 非特权模式,大部分任务执行在这种模式   正常程序执行的模式
; FIQ: 当一个高优先级(fast)中断产生时将会进入这种模式 高速数据传输和通道处理
; IRQ: 当一个低优先级(normal)中断产生时将会进入这种模式 通常的中断处理
; SVC: 用于操作系统的保护模式 
; Abort: 当存取异常时将会进入这种模式   虚拟存储及存储保护
; Undef: 当执行未定义指令时会进入这种模式 软件仿真硬件协处理器
; System: 使用和User模式相同寄存器集的特权模式

; 这个7个值,将根据运行状态需要写到CPSR寄存器的第0,1,2,3,4,5位。
;
; ARM有7种运行状态,每一种状态的堆栈指针寄存器(SP)都是独立的。

; 所以,对于程序中需要用的每一种处理器模式,
; 都要给SP定义一个堆栈地址。
; 流程为:修改状态寄存器内的状态位,使处理器切换到需要的模式,然后给SP赋值。
; 需要注意的是:不要切换到User模式, 进行该模式下的堆栈设置,因为进入User模式后就不能

; 再操作CPSR 返回到其他模式了。
; 先定义各种模式对应的CPSR寄存器M[4:0]的值,该值决定了进入何种模式。
; asm 中的 EQU 就是 C 语言中的 #define

Mode_USR        EQU     0x10 ;用户模式
Mode_FIQ        EQU     0x11 ;FIQ模式
Mode_IRQ        EQU     0x12 ;IRQ模式
Mode_SVC        EQU     0x13 ;超级用户模式
Mode_ABT        EQU     0x17 ;终止模式
Mode_UND        EQU     0x1B ;未定义模式
Mode_SYS        EQU     0x1F ;系统模式

;中断屏蔽位 :也和CPSR寄存器的设置有关,这里两位是禁止/开启快速中断和一般中断的设置.
; 设置IRQ和FIQ中断禁止位,这两个值将被写到CPSR寄存器的第6位(FIQ)和第7位(IRQ).1是禁止,0是允许。

I_Bit           EQU     0x80            ; when I bit is set, IRQ is disabled .IRQ中断控制位,当被置位时,IRQ中断被禁止

F_Bit           EQU     0x40            ; when F bit is set, FIQ is disabled.FIQ中断控制位,当被置位时,FIQ中断被禁止

; 状态屏蔽位
; EQU         T_bit,             0x20    ;T位,置位时在Thumb模式下运行,清零时在ARM下运行


;// <h> Stack Configuration (Stack Sizes in Bytes)
;//   <o0> Undefined Mode      <0x0-0xFFFFFFFF:8>
;//   <o1> Supervisor Mode     <0x0-0xFFFFFFFF:8>
;//   <o2> Abort Mode          <0x0-0xFFFFFFFF:8>
;//   <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
;//   <o4> Interrupt Mode      <0x0-0xFFFFFFFF:8>
;//   <o5> User/System Mode    <0x0-0xFFFFFFFF:8>
;// </h>各模式下定义的堆栈地址. 本段将完成堆栈相关的常量

UND_Stack_Size  EQU     0x00000000 ;未定义模式栈
SVC_Stack_Size  EQU     0x00000008 ;超级用户模式栈
ABT_Stack_Size  EQU     0x00000000 ;终止模式栈
FIQ_Stack_Size  EQU     0x00000000 ;快速中断栈
IRQ_Stack_Size  EQU     0x00000080 ;普通中断堆栈
USR_Stack_Size  EQU     0x00000400 ;用户模式定义栈

;//设置堆栈大小,
ISR_Stack_Size  EQU     (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size + \
                         FIQ_Stack_Size + IRQ_Stack_Size) ;//总堆栈长度

; 初始化栈空间
;//开辟堆栈段,定义为可读可写,不初始化内存单元或将内存写0,字节对齐 ,arm 字为32位
; 定义一个数据段,名为STACK,NOINIT - 仅仅保留内存单元,还没有写入值,可读写,ALIGN=3 - 按字节对齐。
                AREA    STACK, NOINIT, READWRITE, ALIGN=3

;//堆栈大小的设置,各公司写的启动代码有所不同,但是不影响大局,可以借鉴一些你认为比较简单的启动代码
;//,然后写自己的堆栈地址和大小设置程序.
; 分配内存,用户模式栈名为Stack_Mem,大小为1024字节;分配 ISR_Stack_Size的内存空间,在USR_Stack之上?。

Stack_Mem       SPACE   USR_Stack_Size ;分配 0x00000400 长度空间,并置初始化为 0
__initial_sp    SPACE   ISR_Stack_Size ;申请堆栈内存空间. SPACE 为伪指令

Stack_Top ;//堆栈段内容结束, 在这里放个标号,用来获得堆栈顶部地址
; 下面一段转来的对话
; Hello,

; could anybody tell me the information of this code line

; Stack_Mem SPACE USR_Stack_Size
; __initial_sp SPACE ISR_Stack_Size

; Stack_Top

; __initial_sp is the whole stack size - that's clear. But which information has the last code line Stack_Top? 
; And why is the ; USR_Stack_Size in comparison to the other Stack_Sizes so big?


; The user-stack is for your application, with all calls and auto variables.

; The ISR stack is just for interrupt service routines, and they normally don't consume a l
; ot of stack space - especially if  you don't allow them to nest.

; Have you spent some time reading up on the ARM architecture?

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多