ARM-S3C2440启动文件init.s解析(3)
 
- UID
- 1029342
- 性别
- 男
|

ARM-S3C2440启动文件init.s解析(3)
;从这里开始就是正真的代码入口了!
AREA Init,CODE,READONLY ;这表明下面的是一个名为Init的代码段
ENTRY ;定义程序的入口(调试用)
EXPORT __ENTRY ;导出符号_ENTRY,但在那用到就还没查明
__ENTRY
ResetEntry
;1)The code, which converts to Big-endian, should be in little endian code.
;2)The following little endian code will be compiled in Big-Endian mode.
; The code byte order should be changed as the memory bus width.
;3)The pseudo instruction,DCD can not be used here because the linker generates error.
;条件编译,在编译成机器码前就设定好
ASSERT EF:ENDIAN_CHANGE ;判断ENDIAN_CHANGE是否已定义
[ ENDIAN_CHANGE ;如果已经定义了ENDIAN_CHANGE,则(在Option.inc里已经设为FALSE )
ASSERT EF:ENTRY_BUS_WIDTH ;判断ENTRY_BUS_WIDTH是否已定义
[ ENTRY_BUS_WIDTH=32 ;如果已经定义了ENTRY_BUS_WIDTH,则判断是不是为32
b ChangeBigEndian ;DCD 0xea000007
]
;在bigendian中,地址为A的字单元包括字节单元A,A+1,A+2,A+3,字节单元由高位到低位为A,A+1,A+2,A+3
; 地址为A的字单元包括半字单元A,A+2,半字单元由高位到低位为A,A+2
[ ENTRY_BUS_WIDTH=16
andeq r14,r7,r0,lsl #20 ;DCD 0x0007ea00 也是b ChangeBigEndian指令,只是由于总线不一样而取机器码
] ;的顺序不一样,先取低位->高位 上述指令是通过机器码装换而来的
[ ENTRY_BUS_WIDTH=8
streq r0,[r0,-r10,ror #1] ;DCD 0x070000ea 也是b ChangeBigEndian指令,只是由于总线不一样而取机器码
] ;的顺序不一样
|
b ResetHandler ;我们的程序由于ENDIAN_CHANGE设成FALSE就到这儿了,转跳到复位程序入口
]
b HandlerUndef ;handler for Undefined mode ;0x04
b HandlerSWI ;handler for SWI interrupt ;0x08
b HandlerPabort ;handler for PAbort ;0x0c
b HandlerDabort ;handler for DAbort ;0x10
b . ;reserved 注意小圆点 ;0x14
b HandlerIRQ ;handler for IRQ interrupt ;0x18
b HandlerFIQ ;handler for FIQ interrupt ;0x1c
;@0x20
b EnterPWDN ; Must be @0x20.
;==================================================================================
;下面是改变大小端的程序,这里采用直接定义机器码的方式,至说为什么这么做就得问三星了
;反正我们程序里这段代码也不会去执行,不用去管它
;==================================================================================
;通过设置CP15的C1的位7,设置存储格式为Bigendian,三种总线方式
ChangeBigEndian ;//here ENTRY_BUS_WIDTH=16
;@0x24
[ ENTRY_BUS_WIDTH=32
DCD 0xee110f10 ;0xee110f10 => mrc p15,0,r0,c1,c0,0
DCD 0xe3800080 ;0xe3800080 => orr r0,r0,#0x80; //Big-endian
DCD 0xee010f10 ;0xee010f10 => mcr p15,0,r0,c1,c0,0
;对存储器控制寄存器操作,指定内存模式为Big-endian
;因为刚开始CPU都是按照32位总线的指令格式运行的,如果采用其他的话,CPU别不了,必须转化
;但当系统初始化好以后,则CPU能自动识别
]
[ ENTRY_BUS_WIDTH=16
DCD 0x0f10ee11
DCD 0x0080e380
DCD 0x0f10ee01
;因为采用Big-endian模式,采用16位总线时,物理地址的高位和数据的地位对应
;所以指令的机器码也相应的高低对调
]
[ ENTRY_BUS_WIDTH=8
DCD 0x100f11ee
DCD 0x800080e3
DCD 0x100f01ee
]
DCD 0xffffffff ;swinv 0xffffff is similar with NOP and run well in both endian mode.
DCD 0xffffffff
DCD 0xffffffff
DCD 0xffffffff
DCD 0xffffffff
b ResetHandler
;====================================================================================
; Function for entering power down mode
; 1. SDRAM should be in self-refresh mode.
; 2. All interrupt should be maksked for SDRAM/DRAM self-refresh.
; 3. LCD controller should be disabled for SDRAM/DRAM self-refresh.
; 4. The I-cache may have to be turned on.
; 5. The location of the following code may have not to be changed.
;void EnterPWDN(int CLKCON);
EnterPWDN
mov r2,r0 ;r2=rCLKCON 保存原始数据 0x4c00000c 使能各模块的时钟输入
tst r0,#0x8 ;测试bit[3] SLEEP mode? 1=>sleep
bne ENTER_SLEEP ;C=0,即TST结果非0,bit[3]=1
;//进入PWDN后如果不是sleep则进入stop
;//进入Stop mode
ENTER_STOP
ldr r0,=REFRESH ;0x48000024 DRAM/SDRAM refresh config
ldr r3,[r0] ;r3=rREFRESH
mov r1, r3
orr r1, r1, #BIT_SELFREFRESH ;Enable SDRAM self-refresh
str r1, [r0] ;Enable SDRAM self-refresh
mov r1,#16 ;wait until self-refresh is issued. may not be needed.
0
subs r1,r1,#1
bne %B0
;//wait 16 fclks for self-refresh
ldr r0,=CLKCON ;enter STOP mode.
str r2,[r0]
mov r1,#32
0
subs r1,r1,#1 ;1) wait until the STOP mode is in effect.
bne %B0 ;2) Or wait here until the CPU& eripherals will be turned-off
;Entering SLEEP mode, only the reset by wake-up is available.
ldr r0,=REFRESH ;exit from SDRAM self refresh mode.
str r3,[r0]
MOV_PC_LR ;back to main process |
|
|
|
|
|