/*
* sheevaplug machine assist
* arm926ej-s processor at 1.2GHz
*
* loader uses R11 as scratch.
* R9 and R10 are used for `extern register' variables.
*
* ARM v7 arch. ref. man. (I know, this is v5) §B1.3.3 that
* we don't need barriers around moves to CPSR. The ARM v6 manual
* seems to be silent on the subject.
*/
#include "arm.s"
/*
* MCR and MRC are counter-intuitively named.
* MCR coproc, opcode1, Rd, CRn, CRm[, opcode2] # arm -> coproc
* MRC coproc, opcode1, Rd, CRn, CRm[, opcode2] # coproc -> arm
*/
/*
* Entered here from Das U-Boot with MMU disabled.
* Until the MMU is enabled it is OK to call functions provided
* they are within ±32MiB relative and do not require any
* local variables or more than one argument (i.e. there is
* no stack).
*/
TEXT _start(SB), 1, $-4
MOVW $setR12(SB), R12 /* load the SB */
_main:
/* SVC mode, interrupts disabled */
MOVW $(PsrDirq|PsrDfiq|PsrMsvc), R1
MOVW R1, CPSR
BARRIERS
/*
* disable the MMU & caches,
* switch to system permission & 32-bit addresses.
*/
MOVW $(CpCsystem|CpCd32|CpCi32), R1
MCR CpSC, 0, R1, C(CpCONTROL), C(0)
ISB
/*
* disable the Sheevaplug's L2 cache, invalidate all caches
*/
/* flush caches. 926ejs manual says we have to do it iteratively. */
_dwbinv0:
MRC CpSC, 0, PC, C(CpCACHE), C(CpCACHEwbi), CpCACHEtest
BNE _dwbinv0
/* drain L1 write buffer, also drains L2 eviction buffer on sheeva */
BARRIERS
/* disable l2 cache. do this while l1 caches are off */
MRC CpSC, CpL2, R1, C(CpTESTCFG), C(CpTCl2cfg), CpTCl2conf
/* disabling write allocation is probably for cortex-a8 errata 460075 */
/* l2 off, no wr alloc, no streaming */
BIC $(CpTCl2ena | CpTCl2wralloc | CpTCldcstream), R1
MCR CpSC, CpL2, R1, C(CpTESTCFG), C(CpTCl2cfg), CpTCl2conf
BARRIERS
/* flush caches. 926ejs manual says we have to do it iteratively. */
_dwbinv1:
MRC CpSC, 0, PC, C(CpCACHE), C(CpCACHEwbi), CpCACHEtest
BNE _dwbinv1
BARRIERS
/* clear all PTEs first, to provide a default */
WAVE('\n')
MOVW $PADDR(L1+L1X(0)), R4 /* address of PTE for 0 */
_ptenv0:
ZEROPTE()
CMP.S $PADDR(L1+16*KiB), R4
BNE _ptenv0
/* double map of PHYSDRAM, KZERO to PHYSDRAM for first few MBs */
MOVW $PTEDRAM, R2 /* PTE bits */
MOVW $PHYSDRAM, R3 /* pa */
MOVW $PADDR(L1+L1X(PHYSDRAM)), R4 /* address of PTE for PHYSDRAM */
MOVW $16, R5
_ptdbl:
FILLPTE()
SUB.S $1, R5
BNE _ptdbl
/*
* back up and fill in PTEs for memory at KZERO
* there is 1 bank of 512MB of SDRAM at PHYSDRAM
*/
MOVW $PTEDRAM, R2 /* PTE bits */
MOVW $PHYSDRAM, R3
MOVW $PADDR(L1+L1X(KZERO)), R4 /* start with PTE for KZERO */
MOVW $512, R5 /* inner loop count */
_ptekrw: /* set PTEs for 512MiB */
FILLPTE()
SUB.S $1, R5
BNE _ptekrw
/*
* back up and fill in PTE for MMIO
*/
MOVW $PTEIO, R2 /* PTE bits */
MOVW $PHYSIO, R3
MOVW $PADDR(L1+L1X(VIRTIO)), R4 /* start with PTE for VIRTIO */
FILLPTE()
/* mmu.c sets up the vectors later */
/*
* set up a temporary stack; avoid data & bss segments
*/
MOVW $(PHYSDRAM | (128*1024*1024)), R13
WAVE('P')
/* set the domain access control */
MOVW $Client, R0
BL dacput(SB)
/* set the translation table base */
MOVW $PADDR(L1), R0
BL ttbput(SB)
MOVW $0, R0
BL pidput(SB) /* paranoia */
/* the little dance to turn the MMU & caches on */
WAVE('l')
BL cacheuwbinv(SB)
BL mmuinvalidate(SB)
BL mmuenable(SB)
WAVE('a')
/* warp the PC into the virtual map */
MOVW $KZERO, R0
BL _r15warp(SB)
/*
* now running at KZERO+something!
*/
MOVW $setR12(SB), R12 /* reload the SB */
/*
* set up temporary stack again, in case we've just switched
* to a new register set.
*/
MOVW $(KZERO|(128*1024*1024)), R13
WAVE(' ')
/* pass Mach to main and set up the stack */
MOVW $(MACHADDR), R0 /* Mach */
MOVW R0, R13
ADD $(MACHSIZE), R13 /* stack pointer */
SUB $4, R13 /* space for link register */
BL main(SB) /* void main(Mach*) */
/* fall through */
/* not used */
TEXT _reset(SB), 1, $-4
/* turn the caches off */
MOVW $(PsrDirq|PsrDfiq|PsrMsvc), R0
MOVW R0, CPSR
BARRIERS
BL cacheuwbinv(SB)
MRC CpSC, 0, R0, C(CpCONTROL), C(0)
BIC $(CpCwb|CpCicache|CpCdcache|CpCalign), R0
MCR CpSC, 0, R0, C(CpCONTROL), C(0)
BARRIERS
WAVE('R')
/* redo double map of 0, KZERO */
MOVW $(L1+L1X(0)), R4 /* address of PTE for 0 */
MOVW $PTEDRAM, R2 /* PTE bits */
MOVW $0, R3
MOVW $16, R5
_ptrdbl:
ORR R3, R2, R1 /* first identity-map 0 to 0, etc. */
MOVW R1, (R4)
ADD $4, R4 /* bump PTE address */
ADD $MiB, R3 /* bump pa */
SUB.S $1, R5
BNE _ptrdbl
MOVW $PHYSBOOTROM, R3
MOVW R3, 0x20(R2) /* where $0xe59ff018 jumps to */
BARRIERS
WAVE('t')
WAVE('\r')
WAVE('\n')
/* ...and jump to it */
MOVW R2, R15 /* software reboot */
_limbo: /* should not get here... */
B _limbo /* ... and can't get out */
BL _div(SB) /* hack to load _div, etc. */
TEXT _r15warp(SB), 1, $-4
BIC $KSEGM, R14
ORR R0, R14
BIC $KSEGM, R13
ORR R0, R13
RET
BARRIERS /* force outstanding stores to cache */
/* keep writing back dirty cache lines until no more exist */
_uwbinv: /* D writeback+invalidate */
MRC CpSC, 0, PC, C(CpCACHE), C(CpCACHEwbi), CpCACHEtest
BNE _uwbinv
/* drain L1 write buffer, also drains L2 eviction buffer on sheeva */
BARRIERS
MOVW $0, R0 /* I invalidate */
MCR CpSC, 0, R0, C(CpCACHE), C(CpCACHEinvi), CpCACHEall
/* drain L1 write buffer, also drains L2 eviction buffer on sheeva */
BARRIERS
MOVW R3, CPSR /* splx */
RET
TEXT cacheiinv(SB), 1, $-4 /* I invalidate */
BARRIERS
MCR CpSC, 0, R0, C(CpCACHE), C(CpCACHEinvi), CpCACHEall
/* drain L1 write buffer, also drains L2 eviction buffer on sheeva */
BARRIERS
RET
TEXT cachedinv(SB), 1, $-4 /* D invalidate */
_dinv:
BARRIERS
MCR CpSC, 0, R0, C(CpCACHE), C(CpCACHEinvd), CpCACHEall
/* drain L1 write buffer, also drains L2 eviction buffer on sheeva */
BARRIERS
RET
/*
* l2 cache
*
* these functions assume that the necessary l1 cache operations have been
* or will be done explicitly by the caller.
*/
/* enable l2 cache in config coproc. reg. do this while l1 caches are off. */
TEXT l2cachecfgon(SB), 1, $-4
BARRIERS
MCR CpSC, CpL2, R0, C(CpTESTCFG), C(CpTCl2inv), CpTCl2all
BARRIERS
MRC CpSC, CpL2, R1, C(CpTESTCFG), C(CpTCl2cfg), CpTCl2conf
ORR $(CpTCl2ena | CpTCl2prefdis), R1 /* l2 on, prefetch off */
MCR CpSC, CpL2, R1, C(CpTESTCFG), C(CpTCl2cfg), CpTCl2conf
BARRIERS
RET
/* disable l2 cache in config coproc. reg. do this while l1 caches are off. */
TEXT l2cachecfgoff(SB), 1, $-4
BARRIERS
MRC CpSC, CpL2, R1, C(CpTESTCFG), C(CpTCl2cfg), CpTCl2conf
BIC $CpTCl2ena, R1
MCR CpSC, CpL2, R1, C(CpTESTCFG), C(CpTCl2cfg), CpTCl2conf
BARRIERS
MCR CpSC, CpL2, R0, C(CpTESTCFG), C(CpTCl2inv), CpTCl2all
BARRIERS
RET
TEXT l2cacheuwb(SB), 1, $-4 /* L2 unified writeback */
MCR CpSC, CpL2, R0, C(CpTESTCFG), C(CpTCl2flush), CpTCl2all
ISB
RET
TEXT l2cacheuwbse(SB), 1, $-4 /* L2 unified writeback SE */
MOVW R0, R2 /* first arg: address */