lpc2124 啟動(dòng)代碼詳解
;/* 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種定義的常量參數(shù)由來(lái):
; 這7個(gè)常量定義為處理器 7種運(yùn)行模式的參數(shù),為7種“當(dāng)前程序狀態(tài)寄存器” CPSR 模式設(shè)置位 M[4:0]的值。
; 比如這里的用戶模式,CPSR的M[4:0], 設(shè)置為10000就是0x10.
; 同理其他.詳見(jiàn)<<嵌入式系統(tǒng)開(kāi)發(fā)與應(yīng)用>>P71. CPSR設(shè)置很關(guān)鍵!
;
; ARM 有7種工作模式:
; User: 非特權(quán)模式,大部分任務(wù)執(zhí)行在這種模式 正常程序執(zhí)行的模式
; FIQ: 當(dāng)一個(gè)高優(yōu)先級(jí)(fast)中斷產(chǎn)生時(shí)將會(huì)進(jìn)入這種模式 高速數(shù)據(jù)傳輸和通道處理
; IRQ: 當(dāng)一個(gè)低優(yōu)先級(jí)(normal)中斷產(chǎn)生時(shí)將會(huì)進(jìn)入這種模式 通常的中斷處理
; SVC: 用于操作系統(tǒng)的保護(hù)模式
; Abort: 當(dāng)存取異常時(shí)將會(huì)進(jìn)入這種模式 虛擬存儲(chǔ)及存儲(chǔ)保護(hù)
; Undef: 當(dāng)執(zhí)行未定義指令時(shí)會(huì)進(jìn)入這種模式 軟件仿真硬件協(xié)處理器
; System: 使用和User模式相同寄存器集的特權(quán)模式
;
; 這個(gè)7個(gè)值,將根據(jù)運(yùn)行狀態(tài)需要寫到CPSR寄存器的第0,1,2,3,4,5位。
;
; ARM有7種運(yùn)行狀態(tài),每一種狀態(tài)的堆棧指針寄存器(SP)都是獨(dú)立的。
; 所以,對(duì)于程序中需要用的每一種處理器模式,
; 都要給SP定義一個(gè)堆棧地址。
; 流程為:修改狀態(tài)寄存器內(nèi)的狀態(tài)位,使處理器切換到需要的模式,然后給SP賦值。
; 需要注意的是:不要切換到User模式, 進(jìn)行該模式下的堆棧設(shè)置,因?yàn)檫M(jìn)入U(xiǎn)ser模式后就不能
; 再操作CPSR 返回到其他模式了。
; 先定義各種模式對(duì)應(yīng)的CPSR寄存器M[4:0]的值,該值決定了進(jìn)入何種模式。
; asm 中的 EQU 就是 C 語(yǔ)言中的 #define
Mode_USR EQU 0x10;用戶模式
Mode_FIQ EQU 0x11;FIQ模式
Mode_IRQ EQU 0x12;IRQ模式
Mode_SVC EQU 0x13;超級(jí)用戶模式
Mode_ABT EQU 0x17;終止模式
Mode_UND EQU 0x1B;未定義模式
Mode_SYS EQU 0x1F;系統(tǒng)模式
;中斷屏蔽位 :也和CPSR寄存器的設(shè)置有關(guān),這里兩位是禁止/開(kāi)啟快速中斷和一般中斷的設(shè)置.
; 設(shè)置IRQ和FIQ中斷禁止位,這兩個(gè)值將被寫到CPSR寄存器的第6位(FIQ)和第7位(IRQ).1是禁止,0是允許。
I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled .IRQ中斷控制位,當(dāng)被置位時(shí),IRQ中斷被禁止
F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled.FIQ中斷控制位,當(dāng)被置位時(shí),F(xiàn)IQ中斷被禁止
; 狀態(tài)屏蔽位
; EQU T_bit, 0x20 ;T位,置位時(shí)在Thumb模式下運(yùn)行,清零時(shí)在ARM下運(yùn)行
;//
;//
;//
;//
;//
;//
;//
;//
UND_Stack_Size EQU 0x00000000;未定義模式棧
SVC_Stack_Size EQU 0x00000008;超級(jí)用戶模式棧
ABT_Stack_Size EQU 0x00000000;終止模式棧
FIQ_Stack_Size EQU 0x00000000;快速中斷棧
IRQ_Stack_Size EQU 0x00000080;普通中斷堆棧
USR_Stack_Size EQU 0x00000400;用戶模式定義棧
;//設(shè)置堆棧大小,
ISR_Stack_Size EQU (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size +
FIQ_Stack_Size + IRQ_Stack_Size);//總堆棧長(zhǎng)度
; 初始化??臻g
;//開(kāi)辟堆棧段,定義為可讀可寫,不初始化內(nèi)存單元或?qū)?nèi)存寫0,字節(jié)對(duì)齊 ,arm 字為32位
; 定義一個(gè)數(shù)據(jù)段,名為STACK,NOINIT - 僅僅保留內(nèi)存單元,還沒(méi)有寫入值,可讀寫,ALIGN=3 - 按字節(jié)對(duì)齊。
AREA STACK, NOINIT, READWRITE, ALIGN=3
;//堆棧大小的設(shè)置,各公司寫的啟動(dòng)代碼有所不同,但是不影響大局,可以借鑒一些你認(rèn)為比較簡(jiǎn)單的啟動(dòng)代碼
;//,然后寫自己的堆棧地址和大小設(shè)置程序.
; 分配內(nèi)存,用戶模式棧名為Stack_Mem,大小為1024字節(jié);分配 ISR_Stack_Size的內(nèi)存空間,在USR_Stack之上?。
Stack_Mem SPACE USR_Stack_Size ;分配 0x00000400 長(zhǎng)度空間,并置初始化為 0
__initial_sp SPACE ISR_Stack_Size ;申請(qǐng)堆棧內(nèi)存空間. SPACE 為偽指令
Stack_Top;//堆棧段內(nèi)容結(jié)束, 在這里放個(gè)標(biāo)號(hào),用來(lái)獲得堆棧頂部地址
; 下面一段轉(zhuǎn)來(lái)的對(duì)話
; 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 - thats 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 dont consume a l
; ot of stack space - especially if you dont allow them to nest.
; Have you spent some time reading up on the ARM architecture?
評(píng)論