📄 bootloader.s
字号:
add r3, r3, r0 ;-Add coffset to get address of
; first word of config data
add r0, r3, r4 ;-Add csize to get address of
; last word of config data
ldr r2, =(EXC_REGISTERS_BASE + 0x148) ;-Load address of CONFIG_DATA
; register
ldr r4, =(EXC_REGISTERS_BASE + 0x140) ;-Load address of CONFIG_CONTROL
; register
ldr r5, =0x04 ;-Load Busy Bit mask
CONFIGURE_LOOP
ldr r1, [r3], #4 ;-Load a word of data
str r1, [r2] ;-Write data to CONFIG_DATA
BUSY_BIT_LOOP
ldr r6, [r4] ;-Load CONFIG_CONTROL
and r7, r6, r5 ;-Mask Busy Bit
cmp r7, #0x4 ;-Check if Busy Bit is set
beq BUSY_BIT_LOOP ;-If not, load more data
cmp r3, r0 ;-Loop until end of SBI file
bne CONFIGURE_LOOP
WAIT_FOR_CO_TO_BE_CLEARED ;-Wait for CO bit to be cleared
ldr r6, [r4] ;-Load CONFIG_CONTROL reg
and r6, r6, #0x2 ;-Mask CO bit
cmp r6, #0x2 ;-Loop until CO is '0'
beq WAIT_FOR_CO_TO_BE_CLEARED
CHECK_ERROR_BIT ;-Check E bit
and r7, r6, #0x010 ;-Mask E Bit
cmp r7, #0x010 ;-Take error vector if '1'
beq CONFIG_ERROR
;-PLD should now be in
; user mode.
PLD_CONFIG_DONE
;***************************************************************************
;* Branch to Reset_Handler
;***************************************************************************
b Reset_Handler
;***************************************************************************
; WAIT_FUNCTION
;
; This function waits for a specified number of AHB1 cycles by reading the
; register AHB1_COUNT.
;
; r9 - Parameter that contains number of AHB1 cycles to wait
;
;***************************************************************************
CACHE_THIS_CODE2_START
WAIT_FUNCTION
ldr r7, [r6] ;-Load value of AHB1_COUNT
add r7, r7, r9 ;-r9 contains cycles to wait
; Load r7 with terminal count
WAIT_LOOP
ldr r8, [r6] ;-Load value of AHB1_COUNT
cmp r7, r8 ;-Compare to terminal count
bhi WAIT_LOOP ;-Loop until we get there
mov pc, lr ;-Return from function
CACHE_THIS_CODE2_END
;***************************************************************************
; Error Vectors
;
; These are the error vectors taken when errors are encountered in the boot
; process. These handlers simply trap the execution of code with an
; infinite loop. It is the users responsibility to design meaningful error
; handlers.
;
;***************************************************************************
PLD_LOCKED ;-Error vector if PLD is locked
b PLD_LOCKED
CONFIG_ERROR ;-Error vector if PLD config
b CONFIG_ERROR ; sets error flag
ID_Error ;-Error vector if IDCODE does
b ID_Error ; not match expected value
SBI_IDCODE_ERROR ;-Error vector if IDCODE does
b SBI_IDCODE_ERROR ; not match SBI file
;***************************************************************************
; Branch to EBI1
;
; The new image that is downloaded to the board via the TCP/IP is stored in
; EBI1. The last thing the function that writes the image to flash does is
; write a value in the last block of EBI0 to indicate that there is a new
; image in EBI1 that should be booted on reset.
;
;***************************************************************************
BRANCH_TO_EBI1
ldr pc, =EXC_EBI_BLOCK1_BASE ;-Branch to where EBI0
nop ;-NOP is not executed as
; pipeline is flushed
;***************************************************************************
; Uart Routines
; useful routines for exception handlers...
;***************************************************************************
inituart
; messes r0, r1
; set up stripe uart
ldr r0,=EXC_UART_MC
ldr r1,=0x3
str r1,[r0]
ldr r0,=EXC_UART_DIV_LO
ldr r1,=(EXC_AHB2_CLK_FREQUENCY / (38400 * 16)) ; 38400 baud
str r1,[r0]
ldr r0,=EXC_UART_DIV_HI
ldr r1,=0
str r1,[r0]
mov pc, lr
waittx
; messes r1, r2, r3
ldr r3,=EXC_UART_TSR
ldr r1, =0x1f
waittx1
; wait for tx clear
ldr r2,[r3]
ands r2,r2,r1
bne waittx1
mov pc, lr
print
; enter with r0->null terminated string
; messes r0, r1, r2, r3, r4, r5
mov r5, lr ; save lr
ldr r4,=EXC_UART_TD
print1
bl waittx
ldr r1,[r0, #1]!
ands r1,r1,#0xff
beq endprint
str r1,[r4]
b print1
endprint
mov pc, r5 ; org. lr
str_undefined DCB "\n*** undefined instructions ***",0
str_swi DCB "\n*** swi interrupt ***",0
str_prefetch DCB "\n*** prefetch abort ***",0
str_abort DCB "\n*** data abort ***",0
str_fiq DCB "\n*** fiq ***",0
str_irq DCB "\n*** irq ***",0
str_deviceid DCB "\n*** invalid device id ***",0
;***************************************************************************
; Exception Handlers
;***************************************************************************
AREA |handlers|, CODE, READONLY
Undefined_Handler
bl inituart
; printf("undefined instructions");
ldr r0, =str_undefined
bl print
Undefined_Handler2
B Undefined_Handler2
SWI_Handler
bl inituart
; printf("swi interrupt");
ldr r0, =str_swi
bl print
SWI_Handler2
B SWI_Handler2
Prefetch_Handler
bl inituart
; printf("prefetch abort");
ldr r0, =str_prefetch
bl print
Prefetch_Handler2
B Prefetch_Handler2
Abort_Handler
bl inituart
; printf("data abort");
ldr r0, =str_abort
bl print
Abort_Handler2
B Abort_Handler2
FIQ_Handler
bl inituart
; printf("fiq");
ldr r0, =str_fiq
bl print
FIQ_Handler2
B FIQ_Handler2
IRQ_Handler
;; r13 == sp
;; r14 == lr
;save the lr on the stack
str r14,[r13,#-4]!
;; save the reqisters ...
;; the C does a stmfd r13!,{r4-r11,r14}
;; so we only need to save r0-r3, r12 ...
stmfd r13!,{r0-r3,r12}
IMPORT irq
BL irq ; --- Now call the C code
;; restore the reqisters ...
;; the C does a ldmfd r13!,{r4-r11,pc}
;; so we only need to restore r0-r3, r12
ldmfd r13!,{r0-r3,r12}
; get the lr from the stack
ldr r14,[r13],#4
;; rti
subs pc, r14, #4
;***************************************************************************
; Include SBI file
;
; In this section, a new data section named sbi_data is declared. The
; INCBIN directive tells the assembler to insert the file .sbi
; in pure binary form. The file is not interpreted in any way. During
; the PLD configuration portion of the boot process, this file is read
; using the sbi_start label. The SBI file is written to the PLD
; configuration peripheral to configure the PLD portion of the device.
;
;***************************************************************************
AREA sbi_data, DATA, READONLY
sbi_start
INCBIN remote_reconfiguration.sbi
sbi_end
;***************************************************************************
; End of assembly source file
;***************************************************************************
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -