📄 init.s
字号:
;********************************************************************************
;* *
;* Copyright (C) 2002 Oki Electric Industry Co., LTD. *
;* *
;* System Name : ML674001 series *
;* Module Name : Startup routine *
;* File Name : init.s *
;* Revision : 01.00 *
;* Date : 2002/12/02 initial version *
;* *
;********************************************************************************
; the AREA must have the attribute READONLY, otherwise the linker will not
; place it in ROM.
;
; the AREA must have the attribute CODE, otherwise the assembler will not
; allow any code in this AREA
AREA Init, CODE, READONLY
INCLUDE define.s ; common definitions
; locations of various things in our memory system
IRQ_Stack EQU RAM_Limit ; top of IRQ stack
SVC_Stack EQU IRQ_Stack-1024 ; top of SVC stack
USR_Stack EQU SVC_Stack-1024 ; top of USR stack
IMPORT IRQ, WEAK ; IRQ handler
IMPORT SWI, WEAK ; SWI handler
; --- Define entry point
EXPORT __main ; defined to ensure that C runtime system
__main ; is not linked in
EXPORT _main ; defined to ensure that C runtime system
_main ; is not linked in
ENTRY
; --- setup interrupt / exception vectors
B Reset
Undef B Undef
B SWI
Pref B Pref
Abort B Abort
NOP ; reserved vector
B IRQ
FIQ B FIQ
;********************************
;* Reset Handler *
;********************************
; the RESET entry point
Reset
; --- initialize stack pointer registers
; enter IRQ mode and set up the IRQ stack pointer
MOV R0, #Mode_IRQ:OR:I_Bit:OR:F_Bit ; no interrupts
MSR CPSR_c, R0
LDR R13, =IRQ_Stack ; set IRQ mode stack.
; set up the SVC stack pointer last and return to SVC mode
MOV R0, #Mode_SVC:OR:I_Bit:OR:F_Bit ; no interrupts
MSR CPSR_c, R0
LDR R13, =SVC_Stack ; set SVC mode STACK.
; --- initialize memory required by C code
IF :DEF:SCATTER
IMPORT InitRegions
BL InitRegions
ELSE
IMPORT |Image$$RO$$Limit| ; end of ROM code (=start of ROM data)
IMPORT |Image$$RW$$Base| ; base of RAM to initialize
IMPORT |Image$$ZI$$Base| ; base and limit of area
IMPORT |Image$$ZI$$Limit| ; to zero initialize
LDR r0, =|Image$$RO$$Limit| ; get pointer to ROM data
LDR r1, =|Image$$RW$$Base| ; and RAM copy
LDR r3, =|Image$$ZI$$Base| ; zero init base => top of initialized data
CMP r0, r1 ; check that they are different
BEQ %F1
0 CMP r1, r3 ; copy init data
LDRCC r2, [r0], #4
STRCC r2, [r1], #4
BCC %B0
1 LDR r1, =|Image$$ZI$$Limit| ; top of zero init segment
MOV r2, #0
2 CMP r3, r1 ; zero init
STRCC r2, [r3], #4
BCC %B2
ENDIF
; --- now change to user mode and set up user mode stack.
MOV R0, #Mode_USR:OR:F_Bit:OR:I_Bit
MSR CPSR_c, R0
LDR sp, =USR_Stack ; set USR mode stack.
; --- now enable external bus function(second function of PIOC[6:2]).
LDR R0, =GPCTL
LDRH R1, [R0]
ORR R1, R1, #0x4
STRH R1, [R0]
; --- now enter the C code
IMPORT main
LDR r0, =main
MOV lr, pc
BX r0 ; branch to main function.
END_LOOP
B END_LOOP
IF :DEF:SCATTER
; --- copy and zi_init subroutines
; these subroutines are only used by sample programs which use scatter loading
; copy is a subroutine which copies a region, from an address given by
; r0 to an address given by r1. The address of the word beyond the end
; of this region is held in r2. r3 is used to hold the word being copied.
EXPORT copy
copy
CMP r1, r2 ; loop whilst r1 < r2
LDRLO r3, [r0], #4
STRLO r3, [r1], #4
BLO copy
MOV pc, lr ; return from subroutine copy
; zi_init is a subroutine which zero-initialises a region,
; starting at the address in r0. The address of the word
; beyond the end of this region is held in r1.
EXPORT zi_init
zi_init
MOV r2, #0
CMP r0, r1 ; loop whilst r0 < r1
STRLO r2, [r0], #4
BLO zi_init
MOV pc, lr ; return from subroutine zi_init
ENDIF
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -