⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 startrom.s

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 S
📖 第 1 页 / 共 2 页
字号:
        TTL     Generic ARM start-of-day (initialisation) code     > startrom.s        ; ---------------------------------------------------------------------        ; This file provides the Angel initialisation and startup code        ; for ROM systems. After performing all the necessary ARM and        ; target initialisation the "__main" function is called to        ; start the Angel library and application code present.        ;        ; $Revision: 1.14.6.4 $        ;   $Author: dbrooke $        ;     $Date: 1998/03/26 16:47:57 $        ;        ; Copyright Advanced RISC Machines Limited, 1995.        ; All Rights Reserved        ;        ; Notes:        ; To make it simpler for the developer to understand, the ROM        ; specific and generic Angel workspace are provided as        ; standard RW data AREAs.        ;        ; However, this means that care must be taken when        ; constructing ROM based versions of Angel. In fact there are        ; two types of ROM based Angel: boot ROMs and application        ; ROMs. For application ROMs we do not need to worry about the        ; size of RW data, since *NO* programs will be downloaded, and        ; the application can use as much RAM as required. However,        ; for boot ROMs we need to ensure that the RAM usage of the        ; ROM system does not exceed 0x8000. This will ensure that        ; default AIF applications can be downloaded.        ;        ; For non-ROM based applications the linker can be left to        ; place data AREAs as it sees fit. For ROM based code we force        ; the linker to reference the data at a fixed address. The        ; only problem then becomes finding the initialised data in        ; the ROM image, and ensuring that it is copied to the correct        ; RAM address. This can be achieved as follows:        ;        ; 1) We know that the linker places identical area types        ;    contiguously.        ;        ; 2) We explicitly force the RO (code areas) to be at the        ;    start of the ROM image.        ;        ; 3) We can use Image$$RO$$Base and Limit to find the end of        ;    the RO section in the ROM image. This will give us the start        ;    location in the ROM of the RW data.        ;        ; 4) We can use the corresponding RW and ZI Base and Limit        ;    values to find out how big the areas are, and initialise the        ;    RAM accordingly.        ;        ; 5) Since we now know how large the RW data is, we can find        ;    the end of the ROM image and any post-armlink information        ;    that has been appended to the binary image (e.g. CRCs, MMU        ;    tables, etc.).        ;        ; 6) We know that the linker places R/W code areas before R/W        ;    data areas, which in turn appear before the BSS areas.        ;        ; We cannot use the "-last" feature of the ARM linker to place        ; a RO area at the end, since this will break point 1) where        ; the linker wants to make AREAs of the same type contiguous.        ;        ; ---------------------------------------------------------------------        GET     listopts.s              ; standard listing control        GET     lolevel.s               ; generic ARM definitions        GET     macros.s                ; standard assembler support        GET     target.s                ; target specific definitions            ; ---------------------------------------------------------------------        IMPORT  |__main|                ; Hi-level Angel init entry point        IMPORT  |__entry|,WEAK          ; main need not exist (no application)        IMPORT  __rt_asm_fatalerror     ; error reporting via suppasm.s                IMPORT  angel_StartupStatus     ; Variable describing type of reset.        IMPORT  angel_MMUtype           ; Variable holding ARM MMU type.        ;        ; The following linker generated symbols are used to control        ; the ROM-to-RAM copy loop:        ;        IMPORT  |Image$$RO$$Base|        IMPORT  |Image$$RO$$Limit|        IMPORT  |Image$$RW$$Base|        IMPORT  |Image$$ZI$$Base|        IMPORT  |Image$$ZI$$Limit|        IMPORT  |Image$$RW$$Limit|        ;        ; These are used to copy the vector table to zero when necessary        ;        IMPORT  |__Vectors$$Base|        IMPORT  |__Vectors$$Limit|        KEEP                            ; Keep local symbols in the object.        ; ---------------------------------------------------------------------        ;        ; This AREA is marked as NOINIT, to ensure that it appears as BSS:        AREA    |AngelROM$$Data|,DATA,NOINIT        EXPORT  angel_ROMEnd        EXPORT  angel_GhostCountangel_ROMWorkspaceStart %       0       ; start of this workspace section        ;angel_ROMEnd            %       4       ; true ROM end address        ; When constructing the ROM, it may be necessary to append        ; information to the image produced by the linker. This        ; variable is initialised to the address after all of the        ; linker placed AREAs. This allows the run-time code to find        ; such private, appended, information. e.g. hard-wired MMU        ; tables, ROM CRC values, etc.        ;angel_GhostCount        %       4       ; count of ghost interruptsangel_ROMWorkspaceEnd   %       0       ; allows size of area to be calculated        ; ---------------------------------------------------------------------        ; -- ROM Startup code -------------------------------------------------        ; ---------------------------------------------------------------------        AREA    |ROMStartup|,CODE,PIC,READONLY		ENTRY|__romBase|     ; Symbol for the first location in the ROM.        EXPORT  |__rom|         ; NOTE: This is not an APCS function|__rom| ; This is the only symbol exported from this area. It is the        ; main ENTRY point into a ROM Angel world from an ARM hardware        ; reset. It can also be used as an emergency re-start when        ; called directly from software control.        ;        ; We treat the call to this code as a branch, and will *NOT*        ; return to the caller. This code corrupts the r14 value        ; present at the instance of the entry to this routine. NOTE:        ; At this point we cannot rely on the state of the ARM        ; hardware exception vectors, so the code should not generate        ; aborts or events until handlers have been put in place.;- First we must get the actual start address        SUB     r4, pc, #8;- Switch in Supervisor Mode and disable interrupt and fast interrupt        MRS     r14,CPSR		BIC     r14,r14,#ModeMask        ORR     r14,r14,#(SVCmode :OR: InterruptMask)        MSR     CPSR_cxsf,r14		;- Get the Area Base and Limit        LDR     r0, =|Image$$RO$$Base|		LDR     r1, =|Image$$RO$$Limit|        LDR     r2, =|Image$$RW$$Base|		LDR     r3, =|Image$$RW$$Limit|		;- If Link Address <> Start Address		TEQ		r0, r4		        BEQ     NoCodeCopy;- If Size RW + Size RO + Start Address > Link Address		SUB		r5, r1, r0	; RO size		SUB		r6, r3, r2	; RW size		ADD		r7, r5, r6	; RW size + RO size		ADD		r8, r7, r4	; Start Address + RW size + RO size		CMP		r8, r0		; - Link Address		BHS		InverseCopy;- | Copy from start address up to end of image		MOV		r9, r4CopyLoop		LDR     r10, [r9], #4        STR     r10, [r0], #4		SUBS	r7, r7, #4        BHS     CopyLoop;- | Jump in relocated area		        LDR     pc, =gotoRelocated;- Else;- | Copy from end of image down to start addressInverseCopy		ADD		r0, r0, r7		ADD		r9, r4, r7InverseCopyLoop		LDR     r10, [r9], #-4        STR     r10, [r0], #-4		SUBS	r7, r7, #4        BHS     InverseCopyLoop;- | Jump in relocated area		        LDR     pc, =gotoRelocated;- EndIfgotoRelocated;- Initialize Read-Write DatasNoCodeCopy		LDR		r0, =|Image$$RO$$Limit|		LDR		r1, =|Image$$RW$$Base|		LDR		r3, =|Image$$ZI$$Base|		CMP		r0, r1		BEQ		ZeroInitRWInitLoop		CMP		r1, r3		LDRCC	r2, [r0], #4		STRCC	r2, [r1], #4		BCC		RWInitLoop;- Clear Zero Initialized DatasZeroInit		LDR		r1, =|Image$$ZI$$Limit|		MOV		r2, #0ZeroInitLoop		CMP		r3, r1		STRCC	r2, [r3], #4		BCC		ZeroInitLoop        ; r1 points to top of image, save this to r7 for now        MOV     r7, r4        ; Now we have set everything up, we can jump to (possibly)        ; re-located code and continue running from there.        ; The following instruction forces the PC to be loaded from        ; a literal pool. The value loaded is the address of the        ; gotoRelocated symbol, suitably relocated. This means when        ; we "armlink" the object created we can specify the image        ; address, and the code will then be correct.                        ; We have just initialised the RAM, so we can now start using        ; Angel variables:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -