AALLeeXXX

armstub7.S

Oct 24th, 2017
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 4.92 KB | None | 0 0
  1. /*
  2. This file is tools/armstubs/armstub7.S
  3. and comes from https://github.com/raspberrypi/tools/blob/master/armstubs/armstub7.S
  4.  
  5. Copyright (c) 2016 Raspberry Pi (Trading) Ltd.
  6. All rights reserved.
  7.  
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions are met:
  10.     * Redistributions of source code must retain the above copyright
  11.       notice, this list of conditions and the following disclaimer.
  12.     * Redistributions in binary form must reproduce the above copyright
  13.       notice, this list of conditions and the following disclaimer in the
  14.       documentation and/or other materials provided with the distribution.
  15.     * Neither the name of the copyright holder nor the
  16.       names of its contributors may be used to endorse or promote products
  17.       derived from this software without specific prior written permission.
  18.  
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  23. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30.  
  31. .arch_extension sec
  32. .arch_extension virt
  33.  
  34. .section .init
  35. .section .bootarm
  36. .global jmp_loader
  37. .global _secure_monitor
  38. .globl _start
  39. /* the vector table for secure state and HYP mode */
  40. _start:
  41.     b jmp_loader    /* reset */
  42. osc:    .word 19200000
  43.  
  44. /*
  45.  * secure monitor handler
  46.  * U-boot calls this "software interrupt" in start.S
  47.  * This is executed on a "smc" instruction, we use a "smc #0" to switch
  48.  * to non-secure state.
  49.  * We use only r0 and r1 here, due to constraints in the caller.
  50.  * AB, 2017-10-15: Change SCR to keep in secure mode and SPSR to return to
  51.  * (secure)-SVC mode.
  52.  */
  53. _secure_monitor:
  54.   //movw  r1, #0x131            @ set NS, AW, FW, HVC
  55.   movw  r1, #0x130            @ reset NS, AW, FW, HVC
  56.   mcr   p15, 0, r1, c1, c1, 0       @ write SCR (with NS bit set)
  57.  
  58.   //movw  r0, #0x1da            @ Set HYP_MODE | F_BIT | I_BIT | A_BIT
  59.   movw  r0, #0x1D3            @ Set SVC_MODE | F_BIT | I_BIT | A_BIT
  60.   msr     spsr_cxfs, r0       @ Set full SPSR
  61.   movs  pc, lr                      @ return to secure SVC
  62.  
  63. value:  .word 0x63fff
  64. machid: .word 3138
  65. mbox:   .word 0x4000008C
  66.  
  67. jmp_loader:
  68. @ Check which proc we are and run proc 0 only
  69.  
  70.     mrc p15, 0, r0, c1, c0, 0 @ Read System Control Register
  71.     orr r0, r0, #(1<<2)       @ cache enable
  72.     orr r0, r0, #(1<<12)      @ icache enable
  73.     mcr p15, 0, r0, c1, c0, 0 @ Write System Control Register
  74. /*.if !BCM2710
  75.     mrc p15, 0, r0, c1, c0, 1 @ Read Auxiliary Control Register
  76.     orr r0, r0, #(1<<6)       @ SMP
  77.     mcr p15, 0, r0, c1, c0, 1 @ Write Auxiliary Control Register
  78. .else*/
  79.     mrrc p15, 1, r0, r1, c15  @ CPU Extended Control Register
  80.     orr r0, r0, #(1<<6)       @ SMP
  81.     mcrr p15, 1, r0, r1, c15  @ CPU Extended Control Register
  82. /*.endif
  83. */
  84.     mov r0, #1
  85.     mcr p15, 0, r0, c14, c3, 1 @ CNTV_CTL (enable=1, imask=0)
  86.  
  87. @ set to non-sec
  88.     ldr r1, value               @ value = 0x63fff
  89.     mcr p15, 0, r1, c1, c1, 2       @ NSACR = all copros to non-sec
  90. @ timer frequency
  91.     ldr r1, osc             @ osc = 19200000
  92.     mcr p15, 0, r1, c14, c0, 0      @ write CNTFRQ
  93.  
  94.     adr r1, _start
  95.     mcr p15, 0, r1, c12, c0, 1      @ set MVBAR to secure vectors
  96.     mrc p15, 0, ip, c12, c0, 0      @ save secure copy of VBAR
  97.  
  98.     isb
  99.     smc #0              @ call into MONITOR mode
  100.  
  101.   /* Skip this since still in Secure mode after SMC...
  102.   Will be set later ...
  103.     mcr p15, 0, ip, c12, c0, 0      @ write non-secure copy of VBAR
  104.   */
  105.  
  106.     ldr r4, kernel          @ kernel address to execute from
  107.     mrc     p15, 0, r0, c0, c0, 5     @ R0 = MPIDR
  108.     ubfx    r0, r0, #0, #2            @ R0 = R0 & 0x03 (2 LSB from bit 0)
  109.     cmp     r0, #0                    @ primary core
  110.     beq     9f
  111.  
  112.     mov r5, #1
  113.     lsl r5, r0                         @ R0 is the core number/index
  114. @ modify the 0xff for force_core mode
  115.     tst r5, #0xff                       @ enabled cores
  116.     beq 10f
  117.  
  118.     ldr r5, mbox        @ mbox
  119.     mov r3, #0          @ magic
  120.  
  121.     add r5, #(0x400000CC-0x4000008C)    @ mbox
  122. 1:
  123.     wfe
  124.     ldr r4, [r5, r0, lsl #4]
  125.     cmp r4, r3
  126.     beq 1b
  127. @ clear mailbox
  128.     str r4, [r5, r0, lsl #4]
  129. 9:
  130.     mov r0, #0
  131.     ldr r1, machid      @ BCM2708 machine id
  132.     ldr r2, atags       @ ATAGS
  133.     bx  r4
  134. 10:
  135.     wfi
  136.     b   10b
  137.  
  138. startSingle:
  139.   b skip
  140.  
  141. .org 0xf0
  142. .word 0x5afe570b    @ magic value to indicate firmware should overwrite atags and kernel
  143. .word 0         @ version
  144. atags:  .word 0x0   @ device tree address
  145. kernel2:    .word 0x0   @ kernel start address
  146. kernel: .word startSingle
Advertisement
Add Comment
Please, Sign In to add comment