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

📄 pxa255_macros.inc

📁 老外的一个开源项目
💻 INC
字号:
;Copyright (c) David Vescovi.  All rights reserved.
;Part of Project DrumStix
;Windows Embedded Developers Interest Group (WE-DIG) community project.
;http://www.we-dig.org
;Copyright (c) Microsoft Corporation.  All rights reserved.
;------------------------------------------------------------------------------
;
;  File:  pxa255_macros.inc
;
;  Intel pxa255 assembly macros
;
;------------------------------------------------------------------------------
	IF  !:DEF: _pxa255macros_inc_
_pxa255macros_inc_			EQU		1


;
; **** Macro DisableInts *********************************************
; * Params: $gp1 (scratch reg)
; *
; * Returns: nothing
; *
; *  This macro disables both IRQ and FIQ nondestructively
; ********************************************************************
;
	MACRO
	DisableInts $gp1
	MRS $gp1, cpsr						; Get value of CPSR
	ORR $gp1, $gp1, #CSPR_DeIrqFiq		; Set IRQ and FIQ-disabling bits
	MSR cpsr_c, $gp1					; Disable the IRQ/FIQ
	MEND


;
; **** Macro EnableInts *********************************************
; * Params: $gp1 (scratch reg)
; *
; * Returns: nothing
; *
; *  This macro enables both IRQ and FIQ nondestructively
; ********************************************************************
;
	MACRO
	EnableInts $gp1
	MRS $gp1, cpsr						; Get value of CPSR
	AND $gp1, $gp1, #CSPR_EnIrqFiq		; Set enable/disable bits
	MSR cpsr_c, $gp1					; Control the IRQ/FIQ
	MEND


;
; **** Macro Zero_SDRAM *********************************************
; * Params: $StartAdx: 32-bit aligned start address.
; *         $NumMB   : Number of MB to clear.
; *         $gp1,2   : general purpose scratch
; *
; * Returns: nothing
; *
; * Effects: corrupts $gp1,2
; *
; *  This macro simply zeros out RAM, ending at $StartAdx, and
; *  starting at ($StartAdx + ($NumMB*0x100000)), inclusive.  It is the resposibility of the
; *  caller to ensure that the addresses are valid!  Ensure $StartAdx
; *  is 32-bit aligned, or the math will be wrong.
; *
; Ex:
;    ldr r0, =0xA0000000     ; start Adx
;    mov r1, #64             ; #MB
;
;    Zero_SDRAM r0, r1, r2, r3
;
; ********************************************************************
;
	MACRO
	Zero_SDRAM $StartAdx, $NumMB, $gp1, $gp2
	;
	; Determine ending address: endAdx = (($NumMB * 0x0010 0000) + $StartAdx)
	;
	mov		$gp1, #0x100000
	mla		$gp2, $NumMB, $gp1, $StartAdx

	ldr		$gp1, =0x00000000			; source data
10
	sub		$gp2, $gp2, #4				; word pre-decrement

	str		$gp1, [$gp2]				; 32-bit zero fill
	cmp		$gp2, $StartAdx
	bne		%BT10
	MEND


;
; **** Macro Zero_SDRAM_Tuned_64MB ***********************************
; * Params: $StartAdx: 32-bit aligned start address.
; *         $gp1,2   : general purpose scratch
; *
; * Returns: nothing
; *
; * Effects: corrupts $gp1-6
; *
; *  This macro simply zeros out 64MB of RAM starting at $StartAdx.
; *  It is the resposibility of the caller to ensure that the addresses 
; *  are valid!  Ensure $StartAdx is 32-bit aligned, or the math will be
; *  wrong.
; *
; Ex:
;    ldr r0, =0xA0000000     ; start Adx
;
;    Zero_SDRAM_Tuned_64MB r0, r1, r2, r3, r4, r5, r6
;
; ********************************************************************
;
	MACRO
	SCRUB_SDRAM_TUNED_64 $StartAdx, $gp1, $gp2, $gp3, $gp4, $gp5, $gp6

	mov		$gp6, #0				; data
	mov		$gp1, $StartAdx
	add		$gp2, $StartAdx, #4
	add		$gp3, $StartAdx, #8
	add		$gp4, $StartAdx, #C

	mov		$gp5, #0x04000000		; loop counter = 64 MB

10
	str		$gp6, [$gp1], #+16
	str		$gp6, [$gp2], #+16
	str		$gp6, [$gp3], #+16
	str		$gp6, [$gp4], #+16

	subs	$gp5, $gp5, #16
	bne		%BT10

	str		$gp6, [$gp1]			; get last word
	MEND


;
; **** CPWAIT ********************************************************
; * Params: $Rd      : temporary read register
; *
; * Returns: nothing
; *
; * Effects: corrupts $Rd
; *
; *  This macro is used to wait for coprocessor operations to complete.
; *
; Ex:
;
;    CPWAIT r0
;
; ********************************************************************
;
	MACRO
	CPWAIT  $Rd

	mrc		p15, 0, $Rd, c2, c0, 0		; arbitrary read of CP15
	mov		$Rd, $Rd					; wait for it (foward dependency)
	sub		pc, pc, #4					; branch to next instruction
	MEND


;
; **** Macro InitUART *********************************************
; * Params: $FBA (Uart Base Address )$gp2, $gp3 (scratch regs)
; *
; * Returns: nothing
; *
; * Registers:  Preserves $FBA, corrupts the rest
; *
; *  This macro inits the UART in non-polled, non-FIFO mode at 38400 baud.
; *  It assumes the IO pins (alternate function) are already set up.
; ********************************************************************
;
	MACRO
	InitUART $FBA, $gp2, $gp3

	; Disable UART and disable interrupts
	ldr $gp2, =0x0
	str $gp2, [$FBA, #0x0c] ; (DLAB OFF)
	str $gp2, [$FBA, #0x04] ; IER_DLH = 0x0

	; Set baud rate divisor (38400 baud)
	ldr $gp2, =0x80         
	str $gp2, [$FBA, #0x0c] ; (DLAB ON)
	ldr $gp2, =0x18         
	str $gp2, [$FBA]        ; THR_RBR_DLL = 0x18
	ldr $gp2, =0x0
	str $gp2, [$FBA, #0x04] ; IER_DLH = 0x0

	; Set communications parameters to 8,N,1
	ldr $gp2, =0x0
	str $gp2, [$FBA, #0x0c] ; (DLAB OFF)
	ldr $gp2, =0x3
	str $gp2, [$FBA, #0x0c] ; LCR = 0x3

	; Clear and enable fifos
	ldr $gp2, =0x7
	str $gp2, [$FBA, #0x08] ; IIR_FCR = 0x8

	; Set polled mode
	ldr $gp2, =0x0
	str $gp2, [$FBA, #0x04] ; IER_DLH = 0x0

	; Set normal UART mode
	ldr $gp2, =0x0
	str $gp2, [$FBA, #0x10] ; MCR = 0


	; Enable UART
	ldr $gp2, [$FBA, #0x04] ; $gp2 = IER_DLH
	orr $gp2, $gp2, #0x40   ; Set the enable uart bit
	str $gp2, [$FBA, #0x04] ;

	MEND


;
; **** Macro PrintStr *********************************************
; * Params: $FBA (UART Base Address), $pStr (pointer to string), $gp1
; *
; * Returns: nothing
; *
; * Effects: Corrupts $pStr & $gp1, preserves $FBA
; *
; *  This macro writes the string pointed to by $pSTr until a '0' is reached.
; *
; ********************************************************************
;
	MACRO
	PrintStr $FBA, $pStr, $gp1

10
	ldrb    $gp1, [$pStr]        ; load the first byte
	cmp     $gp1, #0             ; is it NULL?
	beq     %FT20                ; if so, let's end now (search forward, this macro only)

	IsTBE   $FBA, $gp1           ; ensure TBE
	ldrb    $gp1, [$pStr]        ; load the first byte (agin, for now... really need another register)

	strb    $gp1, [$FBA]         ; transmit a byte
	add     $pStr, $pStr, #1     ;  and increment the byte pointer
	b       %BT10                ; otherwise, keep looping (search backwards, this macro only)
20

	MEND


;
; **** Macro PrintReg *********************************************
; * Params: $FBA (UART Base Address), $Reg (register to dump), rest gp
; *
; * Returns: nothing
; *
; * Prints a 32-bit register to UART.  Does ASCII conversion.
; *
; ********************************************************************
;
	MACRO
	PrintReg $FBA, $Reg, $gp1, $gp2, $gp3

	; First, must convert register to ASCII
	;
	mov     $gp1, #28                       ; n = 28
99
	mov     $gp2, $Reg LSR $gp1             ; $gp2 = $Reg >> n
	and     $gp2, $gp2, #0xF                ; mask off irrelevant bits
	cmp     $gp2, #0x0000000A               ; if r1 < 0xA
	addlt   $gp3, $gp2, #0x30               ; $gp3 = ($gp2 + 0x30)  {0x0 -> 0x9}
	addge   $gp3, $gp2, #0x37               ; $gp3 = ($gp2 + 0x37)  {0xA -> 0xF)

	; Now just dump the char i just converted
	;
	IsTBE   $FBA, $gp2						; ensure TBE
	strb    $gp3, [$FBA]					; transmit

	subs    $gp1, $gp1, #4					; n=n-4
	bne     %BT99

	; 0th Iteration
	;
	mov     $gp2, $Reg                      ; $gp2 = $reg (no need to shift for the LSN)
	and     $gp2, $gp2, #0xF                ; mask off irrelevant bits
	cmp     $gp2, #0x0000000A               ; if r1 < 0xA
	addlt   $gp3, $gp2, #0x30               ; $gp3 = ($gp2 + 0x30)  {0x0 -> 0x9}
	addge   $gp3, $gp2, #0x37               ; $gp3 = ($gp2 + 0x37)  [0xA -> 0xF)

	; dump the char i just converted
	;
	IsTBE   $FBA, $gp2         ; ensure TBE
	strb    $gp3, [$FBA]       ; transmit

	; Add cr/lf
	;
	mov     $gp1, #0x0A
	IsTBE   $FBA, $gp2         ; ensure TBE
	strb    $gp1, [$FBA]       ; transmit  (LF)

    MEND


;
; **** Macro IsTBE ***************************************************
; * Params: $FBA (UART Base Address), $gp1 (scratch reg)
; *
; * Returns: nothing
; *
; * Effects: Corrupts $gp1, preserves $FBA
; *
; *  This macro spins until UART.LSR.TEMT gets set, indicating it
; *    is ready for data.
; ********************************************************************
;
	MACRO
	IsTBE $FBA, $gp1

10
	ldr		$gp1, [$FBA, #LSR_OFFSET]
	ands	$gp1, $gp1, #0x40			; mask all but bit 6, and set Z if result=0 (i.e. if bit not set)
	beq		%BT10

	MEND


; This macro will read the CCCR and return its value in $retval
; $Base should contain the base address of the CCCR (virtual or phy)
;      
	MACRO
	GET_CCCR $retval, $Base, $gp1
		
	ldr     $retval, [$Base]            ; read S24's value
	ldr     $gp1, =CCCR_VALID_MASK      ; mask out irrelevant bits
	and     $retval, $retval, $gp1
	MEND

;
; **** Macro GET_CLKCFG *********************************************
; * Params: $retval (return value register)
; *
; * Returns: Reads the clock configuration register (cp14 reg 6).
; *
; ********************************************************************
;
	MACRO
	GET_CLKCFG $retval
		
	mrc p14, 0, $retval, c6, c0, 0      ; read CLKCFG's value
	and     $retval, $retval, #0x3      ; mask out irrelevant bits
	MEND


    ENDIF ; !:DEF: _pxa255macros_inc_
    
    END 

⌨️ 快捷键说明

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