📄 main.s
字号:
;
ldr r2, =0x55555555
50 cmp r3, r10 ; Mem init
strcc r2, [r3], #4
bcc %B50
mov r5, #0x00000007 ; Display pattern: 0x00000007
setHexLED r5, r6
ldr r5, =PlatformMain
setHexLED r5, r6
;
; Now jump the the Diangostic Manager initialization code:
; VOID PlatformMain(PVOID memTop);
;
ldr r0, =|Image$$ZI$$Limit| ; Top of zero init segment
bl PlatformMain
;
; In a real application we wouldn't normally expect to return, however
; in case we do the debug monitor swi is used to halt the application.
;
mov r0, #0x18 ; angel_SWIreason_ReportException
ldr r1, =0x20026 ; ADP_Stopped_ApplicationExit
swi 0x123456 ; Angel semihosting ARM SWI
LTORG ; Place a literal pool here
;===hzh
;LedSet
; mov r0, r0, lsl #3
; and r0, r0, #(3<<3)
; ldr r1, =xlli_GPIOREGS_PHYSICAL_BASE
; str r0, [r1, #xlli_GPCR0_offset]
; eor r0, r0, #(3<<3)
; str r0, [r1, #xlli_GPSR0_offset]
; mov pc, lr
;===
;------------------------------------------------------------------------------
;
; FUNCTION:
; CopyROM
;
; DESCRIPTION:
; This routine relocates the POST to SDRAM.
;
; INPUT PARAMETERS:
; None.
;
; RETURNS:
; None.
;
; GLOBAL EFFECTS:
; The contents of POST stored in Flash is copied to SDRAM.
;
; ASSUMPTIONS:
; The memory controller has been initialized.
;
; CALLS:
; None.
;
; CALLED BY:
; POST.
;
; PROTOTYPE:
; VOID CopyROM(VOID);
;
;------------------------------------------------------------------------------
;
; Copy the ROM image to RAM and prepare for remap
;
; WARNING: Don't add any instruction between the label CopyROM
; and the SUB instructions below. This code is attempting to calculate
; the delta offset of this routine to cover the case when DM is stored
; in high flash.
;
CopyROM
sub r0, pc, #8 ; Get the current program counter
ldr r1, =ROM_BASE ; Get the beginning of flash
sub r0, r0, r1 ; Calculate the current offset
ldr r1, =CopyROM ; Get the compile time offset
sub r4, r0, r1 ; Calculate the program offset
;
; Now setup the registers as follows:
; R1 = Destination Address
; R2 = Source Starting Address
; R3 = Source Ending Address
; R4 = Relative program offset in ROM
;
ldr r1, =RAM_BASE ; Destination Address
ldr r2, =ROM_BASE ; Source Starting Address
add r2, r2, r4 ; Take into account our program offset
; ldr r3, =ROM_SIZE ; Size of Source
ldr r3,=0x100000
add r3, r3, r2 ; Calculate Source Ending Address
;
; Copy Source to Destination
;
100 ldr r0,[r2],#4
str r0,[r1],#4
;
; Check for end of copy
;
cmp r2,r3
bls %B100
;
; Verify the copy, setup the registers as follows:
; R1 = Destination Address
; R2 = Source Starting Address
; R3 = Source Ending Address
; R4 = Relative program offset in ROM
;
ldr r1, =RAM_BASE ; Destination Address
ldr r2, =ROM_BASE ; Source Starting Address
add r2, r2, r4 ; Take into account our program offset
;
; Verify that source equals destination
;
200 ldr r0,[r2],#4
ldr r4,[r1],#4
cmp r0,r4
bne CopyFail
;
; Check for end if verify
;
cmp r2,r3
bls %B200
mov pc,lr
CopyFail
ldr r2, =0xFFFF0004 ; Display pattern: 0xFFFF0004
setHexLED r2, r3
210
ldr r1, =0xFFFF
maskHexLED r1, r2, r3
pauseMilliSecs #250, r1, r2, r3
ldr r1, =0
maskHexLED r1, r2, r3
pauseMilliSecs #500, r1, r2, r3
b %B210
;------------------------------------------------------------------------------
;
; FUNCTION:
; StartAtRAM
;
; DESCRIPTION:
; This routine determines the address in RAM we should jump to.
;
; INPUT PARAMETERS:
; None.
;
; RETURNS:
; None.
;
; GLOBAL EFFECTS:
; Once this routine is executed, we're running from RAM.
;
; ASSUMPTIONS:
; The POST has been copied from Flash to RAM.
;
; CALLS:
; None.
;
; CALLED BY:
; POST.
;
; PROTOTYPE:
; VOID StartAtRAM(VOID);
;
;------------------------------------------------------------------------------
;
; Jump to the same address in RAM. Nothing to do in particular
; here because we are jumping back to the same address, just executing from
; RAM. At this point we are running from ROM that has been remapped to ROM_BASE.
;
; WARNING: Don't add any instruction between the label StartAtRAM
; and the SUB instructions below. This code is attempting to calculate
; the delta offset of this routine to cover the case when DM is stored
; in high flash.
;
StartAtRAM
sub r0, pc, #8 ; Get the current program counter
ldr r1, =ROM_BASE ; Get the beginning of flash
sub r0, r0, r1 ; Calculate the current offset
ldr r1, =StartAtRAM ; Get the compile time offset
sub r2, r0, r1 ; Calculate the program offset
;
; Calculate the new address in RAM by taking the current address and subtract
; ROM_BASE. On return, we should be running from RAM.
;
ldr r0, =ROM_BASE ; Get Destination Address
add r0, r0, r2 ; Take into account our program offset
sub pc,lr,r0 ; Back plus our load offset
;------------------------------------------------------------------------------
;
; FUNCTION:
; VirtualToPhysical
;
; DESCRIPTION:
; This routine will return the physical address of the specified virtual
; address.
;
; INPUT PARAMETERS:
; r0 - Virtual address of interest
; r1 - Address of variable to hold resultant physical address
;
; RETURNS:
; r0 - 0 = Success, -1 = Failure
; [r1] - Physical address of the specified virtual address
;
; GLOBAL EFFECTS:
; None
;
; ASSUMPTIONS:
; None
;
; CALLS:
; None
;
; CALLED BY:
; This routine can be called by "C" code.
;
; PROTOTYPE:
; UINT VirtualToPhysical(PVOID VA, PVOID PA);
;
;------------------------------------------------------------------------------
VirtualToPhysical
stmfd sp!, {r2 - r5, lr} ; Save registers
VirtToPhys v_cbSDRAM,s_cbSDRAM,p_cbSDRAM,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F390 ; If zero, exit
VirtToPhys i_xxSDRAM,s_xxSDRAM,i_xxSDRAM,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F390 ; If zero, exit
VirtToPhys v_cxSDRAM,s_cxSDRAM,p_cxSDRAM,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F390 ; If zero, exit
VirtToPhys i_xxPCMCIA,s_xxPCMCIA,i_xxPCMCIA,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F390 ; If zero, exit
VirtToPhys i_xxProcessorReg,s_xxProcessorReg,i_xxProcessorReg,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F390 ; If zero, exit
VirtToPhys i_xxPlatformReg,s_xxPlatformReg,i_xxPlatformReg,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F390 ; If zero, exit
VirtToPhys v_xxBOOTROM,s_xxBOOTROM,p_xxBOOTROM,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F390 ; If zero, exit
VirtToPhys v_xxALTROM,s_xxALTROM,p_xxALTROM,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F390 ; If zero, exit
VirtToPhys i_xxETHERNET,s_xxETHERNET,i_xxETHERNET,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
390 mov r0, r5 ; Return the status
ldmfd sp!, {r2 - r5, pc} ; Restore registers and return
LTORG ; Place a literal pool here
;------------------------------------------------------------------------------
;
; FUNCTION:
; PhysicalToVirtual
;
; DESCRIPTION:
; This routine will return the virtual address of the specified physical
; address.
;
; INPUT PARAMETERS:
; r0 - Physical address of interest
; r1 - 1 (Cache/Buffered), 2 (Cache/Non-Buffered) or 0 (Non-Cached/Non-Buffered)
; r2 - Address of location in which to store resultant virtual address
; (pointer to pointer)
;
; RETURNS:
; r0 - 0 = Success, -1 = Failure
; [r2] - Virtual address of the specified physical address
;
; GLOBAL EFFECTS:
; None
;
; ASSUMPTIONS:
; None
;
; CALLS:
; None
;
; CALLED BY:
; This routine can be called by "C" code.
;
; PROTOTYPE:
; UINT PhysicalToVirtual(PVOID VA, BOOL Flag, PVOID PA);
;
;------------------------------------------------------------------------------
PhysicalToVirtual
stmfd sp!, {r1, r3 - r6, lr} ; Save registers
mov r6, r1 ; Save copy of flag
mov r1, r2 ; Save the pointer for return va
cmp r6, #01 ; Check for cached/buffered address desired
beq %F400 ; If not cached/buffered, check address range
PhysToVirt p_cbSDRAM,s_cbSDRAM,v_cbSDRAM,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F490 ; If zero, exit
400
cmp r6, #02 ; Check for cached address desired
beq %F410 ; If not cached, check address range
PhysToVirt p_cxSDRAM,s_cxSDRAM,v_cxSDRAM,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F490 ; If zero, exit
410
PhysToVirt i_xxSDRAM,s_xxSDRAM,i_xxSDRAM,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F490 ; If zero, exit
PhysToVirt i_xxPCMCIA,s_xxPCMCIA,i_xxPCMCIA,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F490 ; If zero, exit
PhysToVirt i_xxProcessorReg,s_xxProcessorReg,i_xxProcessorReg,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F490 ; If zero, exit
PhysToVirt i_xxPlatformReg,s_xxPlatformReg,i_xxPlatformReg,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F490 ; If zero, exit
PhysToVirt p_xxBOOTROM,s_xxBOOTROM,v_xxBOOTROM,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F490 ; If zero, exit
PhysToVirt p_xxALTROM,s_xxALTROM,v_xxALTROM,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
beq %F490 ; If zero, exit
PhysToVirt i_xxETHERNET,s_xxETHERNET,i_xxETHERNET,r0,r1,r2,r3,r4,r5
cmp r5, #0 ; Check result
490 mov r0, r5 ; Return the status
ldmfd sp!, {r1, r3 - r6, pc} ; Restore registers and return
;------------------------------------------------------------------------------
;
; FUNCTION:
; GetCpuVersion()
;
; DESCRIPTION:
; This routine is called by "C" to retrieve the CPU version.
;
; INPUT PARAMETERS:
; None.
;
; RETURNS:
; R0 - The CPU version information.
;
; GLOBAL EFFECTS:
; None.
;
; ASSUMPTIONS:
; None.
;
; CALLS:
; None.
;
; CALLED BY:
; "C" code.
;
; PROTOTYPE:
; UINT GetCpuVersion(VOID);
;
;------------------------------------------------------------------------------
;GetCpuVersion
; stmfd sp!, {lr} ; Save registers
; bl XsGetProcessorVersion ; Get CPU ID
; ldmfd sp!, {pc} ; Restore registers and return
;------------------------------------------------------------------------------
;
; FUNCTION:
; IsMMUEnabled()
;
; DESCRIPTION:
; This routine is called by "C" to determine if the MMU is enabled.
;
; INPUT PARAMETERS:
; None.
;
; RETURNS:
; R0 - zero if MMU not enabled, non-zero of MMU enabled.
;
; GLOBAL EFFECTS:
; None.
;
; ASSUMPTIONS:
; None.
;
; CALLS:
; None.
;
; CALLED BY:
; "C" code.
;
; PROTOTYPE:
; UINT IsMMUEnabled(VOID);
;
;------------------------------------------------------------------------------
IsMMUEnabled
stmfd sp!, {r1, lr} ; Save registers
getARMControl r0 ; Get co-processor 15 register 1
tst r0, #CONTROL_MMU ; Check MMU enable bit
bne %F500 ; If set, return MMU enabled
mov r0, #0 ; MMU not enabled
b %F510 ; Exit
500 mov r0, #1 ; MMU enabled
510
ldmfd sp!, {r1, pc} ; Restore registers and return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -