Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:09

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  *  Common start code for SPARC.
0005  *
0006  *  This is based on the file srt0.s provided with the binary
0007  *  distribution of the SPARC Instruction Simulator (SIS) found
0008  *  at ftp://ftp.estec.esa.nl/pub/ws/wsd/erc32.
0009  */
0010 
0011 /*
0012  *  COPYRIGHT (c) 1989-2011.
0013  *  On-Line Applications Research Corporation (OAR).
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #include <rtems/asm.h>
0038 #include <rtems/score/percpu.h>
0039 #include <bspopts.h>
0040 
0041 #if defined(RTEMS_SMP) && defined(BSP_LEON3_SMP)
0042   #define START_LEON3_ENABLE_SMP
0043 #endif
0044 
0045 #define TRAP_SYM(_vector) SYM(trap_##_vector)
0046 
0047 /*
0048  *  Unexpected trap will lead to an RTEMS fatal error.
0049  */
0050 #define BAD_TRAP(_vector) \
0051   TRAP_SYM(_vector):; \
0052   TRAP(_vector, _SPARC_Bad_trap)
0053 
0054 /*
0055  * External interrupt trap
0056  */
0057 #define ISR_TRAP(_vector) \
0058   TRAP_SYM(_vector):; \
0059   TRAP(_vector - 0x10, _SPARC_Interrupt_trap)
0060 
0061 /*
0062  * System call optimized trap table entry
0063  */
0064 #define FPDIS_TRAP(_handler)  \
0065   mov   %psr, %l0 ; \
0066   sethi %hi(_handler), %l4 ; \
0067   jmp   %l4+%lo(_handler); \
0068    sethi %hi(SPARC_PSR_EF_MASK), %l3
0069 
0070 /*
0071  * System call optimized trap table entry
0072  */
0073 #define IRQDIS_TRAP(_handler)  \
0074   mov   %psr, %l0 ; \
0075   sethi %hi(_handler), %l4 ; \
0076   jmp   %l4+%lo(_handler); \
0077    or   %l0, 0x0f00, %l3; ! Set PIL=0xf to disable IRQ
0078 
0079 /*
0080  * System call optimized trap table entry
0081  */
0082 #define IRQEN_TRAP(_handler)  \
0083   mov   %psr, %l0 ; \
0084   sethi %hi(_handler), %l4 ; \
0085   jmp   %l4+%lo(_handler); \
0086    andn %l0, 0xf00, %l3; ! Set PIL=0 to Enable IRQ
0087 
0088 /*
0089  * Window Overflow optimized trap table entry
0090  */
0091 #define WOTRAP(_vector, _handler)  \
0092   sethi %hi(_handler), %l4; \
0093   jmp   %l4+%lo(_handler); \
0094     save; \
0095   nop
0096 
0097 /*
0098  * Window Underflow optimized trap table entry
0099  */
0100 #define WUTRAP(_vector, _handler)  \
0101   mov   %wim, %l3 ; \
0102   sethi %hi(_handler), %l4 ; \
0103   jmp   %l4+%lo(_handler); \
0104    sll  %l3, 1, %l4 ! l4 = WIM << 1
0105 
0106 /*
0107  *  Software trap. Treat as BAD_TRAP for the time being...
0108  */
0109 
0110 #define SOFT_TRAP(_vector) BAD_TRAP(_vector)
0111 
0112   .section    ".text"
0113   PUBLIC(start)
0114   .global start
0115 
0116 SYM(start):
0117 #if SYM(start) != start
0118 start:
0119 #endif 
0120 
0121 /*
0122  *  The trap table has to be the first code in a boot PROM.  But because
0123  *  the Memory Configuration comes up thinking we only have 4K of PROM, we
0124  *  cannot have a full trap table and still have room left over to
0125  *  reprogram the Memory Configuration register correctly.  This file
0126  *  uses an abbreviated trap which has every entry which might be used
0127  *  before RTEMS installs its own trap table.
0128  */
0129 
0130   PUBLIC(trap_table)
0131 SYM(trap_table):
0132 
0133   RTRAP( 0, SYM(hard_reset) );                  ! 00 reset trap
0134   BAD_TRAP(0x01)                                ! 01 instruction access
0135                                                 !    exception
0136   BAD_TRAP(0x02)                                ! 02 illegal instruction
0137   BAD_TRAP(0x03)                                ! 03 privileged instruction
0138 #if defined(SPARC_USE_LAZY_FP_SWITCH)
0139 TRAP_SYM(0x04):
0140   FPDIS_TRAP(SYM(syscall_lazy_fp_switch));      ! 04 fp disabled
0141 #else
0142   BAD_TRAP(0x04)                                ! 04 fp disabled
0143 #endif
0144 TRAP_SYM(0x05):
0145   WOTRAP(5, SYM(window_overflow_trap_handler)); ! 05 window overflow
0146 TRAP_SYM(0x06):
0147   WUTRAP(6, SYM(window_underflow_trap_handler));! 06 window underflow
0148   BAD_TRAP(0x07)                                ! 07 memory address not aligned
0149   BAD_TRAP(0x08)                                ! 08 fp exception
0150   BAD_TRAP(0x09)                                ! 09 data access exception
0151   BAD_TRAP(0x0a)                                ! 0A tag overflow
0152   BAD_TRAP(0x0b)                                ! 0B undefined
0153   BAD_TRAP(0x0c)                                ! 0C undefined
0154   BAD_TRAP(0x0d)                                ! 0D undefined
0155   BAD_TRAP(0x0e)                                ! 0E undefined
0156   BAD_TRAP(0x0f)                                ! 0F undefined
0157 
0158   /*
0159    *  External interrupt traps
0160    */
0161 
0162   ISR_TRAP(0x10)                                ! 10 undefined
0163   ISR_TRAP(0x11)                                ! 11 external interrupt 1
0164   ISR_TRAP(0x12)                                ! 12 external interrupt 2
0165   ISR_TRAP(0x13)                                ! 13 external interrupt 3
0166   ISR_TRAP(0x14)                                ! 14 external interrupt 4
0167   ISR_TRAP(0x15)                                ! 15 external interrupt 5
0168   ISR_TRAP(0x16)                                ! 16 external interrupt 6
0169   ISR_TRAP(0x17)                                ! 17 external interrupt 7
0170   ISR_TRAP(0x18)                                ! 18 external interrupt 8
0171   ISR_TRAP(0x19)                                ! 19 external interrupt 9
0172   ISR_TRAP(0x1a)                                ! 1A external interrupt 10
0173   ISR_TRAP(0x1b)                                ! 1B external interrupt 11
0174   ISR_TRAP(0x1c)                                ! 1C external interrupt 12
0175   ISR_TRAP(0x1d)                                ! 1D external interrupt 13
0176   ISR_TRAP(0x1e)                                ! 1E external interrupt 14
0177   ISR_TRAP(0x1f)                                ! 1F external interrupt 15
0178 
0179   BAD_TRAP(0x20)                                ! 20 undefined
0180   BAD_TRAP(0x21)                                ! 21 undefined
0181   BAD_TRAP(0x22)                                ! 22 undefined
0182   BAD_TRAP(0x23)                                ! 23 undefined
0183   BAD_TRAP(0x24)                                ! 24 cp_disabled
0184   BAD_TRAP(0x25)                                ! 25 undefined
0185   BAD_TRAP(0x26)                                ! 26 undefined
0186   BAD_TRAP(0x27)                                ! 27 undefined
0187   BAD_TRAP(0x28)                                ! 28 cp_exception
0188   BAD_TRAP(0x29)                                ! 29 undefined
0189   BAD_TRAP(0x2a)                                ! 2A undefined
0190   BAD_TRAP(0x2b)                                ! 2B undefined
0191   BAD_TRAP(0x2c)                                ! 2C undefined
0192   BAD_TRAP(0x2d)                                ! 2D undefined
0193   BAD_TRAP(0x2e)                                ! 2E undefined
0194   BAD_TRAP(0x2f)                                ! 2F undefined
0195   BAD_TRAP(0x30)                                ! 30 undefined
0196   BAD_TRAP(0x31)                                ! 31 undefined
0197   BAD_TRAP(0x32)                                ! 32 undefined
0198   BAD_TRAP(0x33)                                ! 33 undefined
0199   BAD_TRAP(0x34)                                ! 34 undefined
0200   BAD_TRAP(0x35)                                ! 35 undefined
0201   BAD_TRAP(0x36)                                ! 36 undefined
0202   BAD_TRAP(0x37)                                ! 37 undefined
0203   BAD_TRAP(0x38)                                ! 38 undefined
0204   BAD_TRAP(0x39)                                ! 39 undefined
0205   BAD_TRAP(0x3a)                                ! 3A undefined
0206   BAD_TRAP(0x3b)                                ! 3B undefined
0207   BAD_TRAP(0x3c)                                ! 3C undefined
0208   BAD_TRAP(0x3d)                                ! 3D undefined
0209   BAD_TRAP(0x3e)                                ! 3E undefined
0210   BAD_TRAP(0x3f)                                ! 3F undefined
0211   BAD_TRAP(0x40)                                ! 40 undefined
0212   BAD_TRAP(0x41)                                ! 41 undefined
0213   BAD_TRAP(0x42)                                ! 42 undefined
0214   BAD_TRAP(0x43)                                ! 43 undefined
0215   BAD_TRAP(0x44)                                ! 44 undefined
0216   BAD_TRAP(0x45)                                ! 45 undefined
0217   BAD_TRAP(0x46)                                ! 46 undefined
0218   BAD_TRAP(0x47)                                ! 47 undefined
0219   BAD_TRAP(0x48)                                ! 48 undefined
0220   BAD_TRAP(0x49)                                ! 49 undefined
0221   BAD_TRAP(0x4a)                                ! 4A undefined
0222   BAD_TRAP(0x4b)                                ! 4B undefined
0223   BAD_TRAP(0x4c)                                ! 4C undefined
0224   BAD_TRAP(0x4d)                                ! 4D undefined
0225   BAD_TRAP(0x4e)                                ! 4E undefined
0226   BAD_TRAP(0x4f)                                ! 4F undefined
0227   BAD_TRAP(0x50)                                ! 50 undefined
0228   BAD_TRAP(0x51)                                ! 51 undefined
0229   BAD_TRAP(0x52)                                ! 52 undefined
0230   BAD_TRAP(0x53)                                ! 53 undefined
0231   BAD_TRAP(0x54)                                ! 54 undefined
0232   BAD_TRAP(0x55)                                ! 55 undefined
0233   BAD_TRAP(0x56)                                ! 56 undefined
0234   BAD_TRAP(0x57)                                ! 57 undefined
0235   BAD_TRAP(0x58)                                ! 58 undefined
0236   BAD_TRAP(0x59)                                ! 59 undefined
0237   BAD_TRAP(0x5a)                                ! 5A undefined
0238   BAD_TRAP(0x5b)                                ! 5B undefined
0239   BAD_TRAP(0x5c)                                ! 5C undefined
0240   BAD_TRAP(0x5d)                                ! 5D undefined
0241   BAD_TRAP(0x5e)                                ! 5E undefined
0242   BAD_TRAP(0x5f)                                ! 5F undefined
0243   BAD_TRAP(0x60)                                ! 60 undefined
0244   BAD_TRAP(0x61)                                ! 61 undefined
0245   BAD_TRAP(0x62)                                ! 62 undefined
0246   BAD_TRAP(0x63)                                ! 63 undefined
0247   BAD_TRAP(0x64)                                ! 64 undefined
0248   BAD_TRAP(0x65)                                ! 65 undefined
0249   BAD_TRAP(0x66)                                ! 66 undefined
0250   BAD_TRAP(0x67)                                ! 67 undefined
0251   BAD_TRAP(0x68)                                ! 68 undefined
0252   BAD_TRAP(0x69)                                ! 69 undefined
0253   BAD_TRAP(0x6a)                                ! 6A undefined
0254   BAD_TRAP(0x6b)                                ! 6B undefined
0255   BAD_TRAP(0x6c)                                ! 6C undefined
0256   BAD_TRAP(0x6d)                                ! 6D undefined
0257   BAD_TRAP(0x6e)                                ! 6E undefined
0258   BAD_TRAP(0x6f)                                ! 6F undefined
0259   BAD_TRAP(0x70)                                ! 70 undefined
0260   BAD_TRAP(0x71)                                ! 71 undefined
0261   BAD_TRAP(0x72)                                ! 72 undefined
0262   BAD_TRAP(0x73)                                ! 73 undefined
0263   BAD_TRAP(0x74)                                ! 74 undefined
0264   BAD_TRAP(0x75)                                ! 75 undefined
0265   BAD_TRAP(0x76)                                ! 76 undefined
0266   BAD_TRAP(0x77)                                ! 77 undefined
0267   BAD_TRAP(0x78)                                ! 78 undefined
0268   BAD_TRAP(0x79)                                ! 79 undefined
0269   BAD_TRAP(0x7a)                                ! 7A undefined
0270   BAD_TRAP(0x7b)                                ! 7B undefined
0271 
0272 /*
0273    This is a sad patch to make sure that we know where the
0274    MEC timer control register mirror is so we can stop the timers
0275    from an external debugger. It is needed because the control
0276    register is write-only. Trap 0x7C cannot occure in ERC32...
0277 */
0278 
0279     .global SYM(_ERC32_MEC_Timer_Control_Mirror), SYM(CLOCK_SPEED)
0280 
0281 SYM(_ERC32_MEC_Timer_Control_Mirror):
0282 
0283   BAD_TRAP(0x7C)                                ! 7C undefined
0284   BAD_TRAP(0x7D)                                ! 7D undefined
0285 
0286 SYM(CLOCK_SPEED):
0287 TRAP_SYM(0x7e):
0288 
0289   .word 0x0a, 0, 0, 0               ! 7E (10 MHz default)
0290 
0291   BAD_TRAP(0x7F)                                ! 7F undefined
0292 
0293   /*
0294    *  Software traps
0295    *
0296    *  NOTE: At the risk of being redundant... this is not a full
0297    *        table.  The setjmp on the SPARC requires a window flush trap
0298    *        handler and RTEMS will preserve the entries that were
0299    *        installed before.
0300    */
0301 
0302 TRAP_SYM(0x80):
0303   TRAP( 0x80, SYM(syscall) );                   ! 80 halt syscall SW trap
0304   SOFT_TRAP(0x81)                               ! 81
0305   SOFT_TRAP(0x82)                               ! 82
0306 TRAP_SYM(0x83):
0307   TRAP( 0x83, SYM(window_flush_trap_handler) ); ! 83 flush windows SW trap
0308   SOFT_TRAP(0x84)                               ! 84
0309   SOFT_TRAP(0x85)                               ! 85
0310   SOFT_TRAP(0x86)                               ! 86
0311   SOFT_TRAP(0x87)                               ! 87
0312   SOFT_TRAP(0x88)                               ! 88
0313 
0314   /*
0315    *  SW Trap 9-15 Reserved for Operating System
0316    *  
0317    *  SPARC_SWTRAP_IRQDIS
0318    *  SPARC_SWTRAP_IRQEN
0319    */
0320 TRAP_SYM(0x89):
0321   IRQDIS_TRAP(SYM(syscall_irqdis));             ! 89 IRQ Disable syscall trap
0322 TRAP_SYM(0x8a):
0323   IRQEN_TRAP(SYM(syscall_irqen));               ! 8A IRQ Enable syscall trap
0324 #if defined(SPARC_USE_SYNCHRONOUS_FP_SWITCH)
0325 TRAP_SYM(0x8b):
0326   IRQDIS_TRAP(SYM(syscall_irqdis_fp));          ! 8B IRQ disable
0327                                                 ! and set PSR[EF] syscall trap
0328 #else
0329   SOFT_TRAP(0x8b)                               ! 8B
0330 #endif
0331   SOFT_TRAP(0x8c)                               ! 8C
0332   SOFT_TRAP(0x8d)                               ! 8D
0333   SOFT_TRAP(0x8e)                               ! 8E
0334   SOFT_TRAP(0x8f)                               ! 8F
0335   SOFT_TRAP(0x90)                               ! 90
0336   SOFT_TRAP(0x91)                               ! 91
0337   SOFT_TRAP(0x92)                               ! 92
0338   SOFT_TRAP(0x93)                               ! 93
0339   SOFT_TRAP(0x94)                               ! 94
0340   SOFT_TRAP(0x95)                               ! 95
0341   SOFT_TRAP(0x96)                               ! 96
0342   SOFT_TRAP(0x97)                               ! 97
0343   SOFT_TRAP(0x98)                               ! 98
0344   SOFT_TRAP(0x99)                               ! 99
0345   SOFT_TRAP(0x9a)                               ! 9A
0346   SOFT_TRAP(0x9b)                               ! 9B
0347   SOFT_TRAP(0x9c)                               ! 9C
0348   SOFT_TRAP(0x9d)                               ! 9D
0349   SOFT_TRAP(0x9e)                               ! 9E
0350   SOFT_TRAP(0x9f)                               ! 9F
0351   SOFT_TRAP(0xa0)                               ! a0
0352   SOFT_TRAP(0xa1)                               ! a1
0353   SOFT_TRAP(0xa2)                               ! a2
0354   SOFT_TRAP(0xa3)                               ! a3
0355   SOFT_TRAP(0xa4)                               ! a4
0356   SOFT_TRAP(0xa5)                               ! a5
0357   SOFT_TRAP(0xa6)                               ! a6
0358   SOFT_TRAP(0xa7)                               ! a7
0359   SOFT_TRAP(0xa8)                               ! a8
0360   SOFT_TRAP(0xa9)                               ! a9
0361   SOFT_TRAP(0xaa)                               ! aA
0362   SOFT_TRAP(0xab)                               ! aB
0363   SOFT_TRAP(0xac)                               ! aC
0364   SOFT_TRAP(0xad)                               ! aD
0365   SOFT_TRAP(0xae)                               ! aE
0366   SOFT_TRAP(0xaf)                               ! aF
0367   SOFT_TRAP(0xb0)                               ! b0
0368   SOFT_TRAP(0xb1)                               ! b1
0369   SOFT_TRAP(0xb2)                               ! b2
0370   SOFT_TRAP(0xb3)                               ! b3
0371   SOFT_TRAP(0xb4)                               ! b4
0372   SOFT_TRAP(0xb5)                               ! b5
0373   SOFT_TRAP(0xb6)                               ! b6
0374   SOFT_TRAP(0xb7)                               ! b7
0375   SOFT_TRAP(0xb8)                               ! b8
0376   SOFT_TRAP(0xb9)                               ! b9
0377   SOFT_TRAP(0xba)                               ! bA
0378   SOFT_TRAP(0xbb)                               ! bB
0379   SOFT_TRAP(0xbc)                               ! bC
0380   SOFT_TRAP(0xbd)                               ! bD
0381   SOFT_TRAP(0xbe)                               ! bE
0382   SOFT_TRAP(0xbf)                               ! bF
0383   SOFT_TRAP(0xc0)                               ! c0
0384   SOFT_TRAP(0xc1)                               ! c1
0385   SOFT_TRAP(0xc2)                               ! c2
0386   SOFT_TRAP(0xc3)                               ! c3
0387   SOFT_TRAP(0xc4)                               ! c4
0388   SOFT_TRAP(0xc5)                               ! c5
0389   SOFT_TRAP(0xc6)                               ! c6
0390   SOFT_TRAP(0xc7)                               ! c7
0391   SOFT_TRAP(0xc8)                               ! c8
0392   SOFT_TRAP(0xc9)                               ! c9
0393   SOFT_TRAP(0xca)                               ! cA
0394   SOFT_TRAP(0xcb)                               ! cB
0395   SOFT_TRAP(0xcc)                               ! cC
0396   SOFT_TRAP(0xcd)                               ! cD
0397   SOFT_TRAP(0xce)                               ! cE
0398   SOFT_TRAP(0xcf)                               ! cF
0399   SOFT_TRAP(0xd0)                               ! d0
0400   SOFT_TRAP(0xd1)                               ! d1
0401   SOFT_TRAP(0xd2)                               ! d2
0402   SOFT_TRAP(0xd3)                               ! d3
0403   SOFT_TRAP(0xd4)                               ! d4
0404   SOFT_TRAP(0xd5)                               ! d5
0405   SOFT_TRAP(0xd6)                               ! d6
0406   SOFT_TRAP(0xd7)                               ! d7
0407   SOFT_TRAP(0xd8)                               ! d8
0408   SOFT_TRAP(0xd9)                               ! d9
0409   SOFT_TRAP(0xda)                               ! dA
0410   SOFT_TRAP(0xdb)                               ! dB
0411   SOFT_TRAP(0xdc)                               ! dC
0412   SOFT_TRAP(0xdd)                               ! dD
0413   SOFT_TRAP(0xde)                               ! dE
0414   SOFT_TRAP(0xdf)                               ! dF
0415   SOFT_TRAP(0xe0)                               ! e0
0416   SOFT_TRAP(0xe1)                               ! e1
0417   SOFT_TRAP(0xe2)                               ! e2
0418   SOFT_TRAP(0xe3)                               ! e3
0419   SOFT_TRAP(0xe4)                               ! e4
0420   SOFT_TRAP(0xe5)                               ! e5
0421   SOFT_TRAP(0xe6)                               ! e6
0422   SOFT_TRAP(0xe7)                               ! e7
0423   SOFT_TRAP(0xe8)                               ! e8
0424   SOFT_TRAP(0xe9)                               ! e9
0425   SOFT_TRAP(0xea)                               ! eA
0426   SOFT_TRAP(0xeb)                               ! eB
0427   SOFT_TRAP(0xec)                               ! eC
0428   SOFT_TRAP(0xed)                               ! eD
0429   SOFT_TRAP(0xee)                               ! eE
0430   SOFT_TRAP(0xef)                               ! eF
0431   SOFT_TRAP(0xf0)                               ! f0
0432   SOFT_TRAP(0xf1)                               ! f1
0433   SOFT_TRAP(0xf2)                               ! f2
0434   SOFT_TRAP(0xf3)                               ! f3
0435   SOFT_TRAP(0xf4)                               ! f4
0436   SOFT_TRAP(0xf5)                               ! f5
0437   SOFT_TRAP(0xf6)                               ! f6
0438   SOFT_TRAP(0xf7)                               ! f7
0439   SOFT_TRAP(0xf8)                               ! f8
0440   SOFT_TRAP(0xf9)                               ! f9
0441   SOFT_TRAP(0xfa)                               ! fA
0442   SOFT_TRAP(0xfb)                               ! fB
0443   SOFT_TRAP(0xfc)                               ! fC
0444   SOFT_TRAP(0xfd)                               ! fD
0445   SOFT_TRAP(0xfe)                               ! fE
0446   SOFT_TRAP(0xff)                               ! fF
0447 
0448 /*
0449  *  This is the hard reset code.
0450  */
0451 
0452 #define PSR_INIT   0x10c0       /* Disable traps, set s and ps */
0453 #define WIM_INIT   2
0454 
0455         PUBLIC(hard_reset)
0456 SYM(hard_reset):
0457 
0458 /* Common initialisation */
0459 
0460         set     SYM(trap_table), %g1    ! Initialize TBR
0461         mov     %g1, %tbr
0462 
0463         mov %psr, %g1           ! Initialize WIM
0464     add %g1, 1, %g2
0465     and %g2, 0x7, %g2
0466     set 1, %g3
0467     sll %g3, %g2, %g3
0468         mov     %g3, %wim
0469 
0470     or  %g1, 0xf20, %g1
0471         wr      %g1, %psr       ! enable traps and disable ints
0472 
0473         nop
0474         nop
0475         nop
0476 
0477         mov     %sp, %o0 ! save end of usable RAM provided by the boot loader
0478         set     SYM(_Per_CPU_Information), %g6 ! set per-CPU control
0479         set     SYM(_ISR_Stack_size), %l0 ! get ISR stack size
0480 
0481 #if defined(START_LEON3_ENABLE_SMP)
0482         rd      %asr17, %l7 ! get CPU identifier
0483         srl     %l7, LEON3_ASR17_PROCESSOR_INDEX_SHIFT, %l7
0484         add     %l7, 1, %l1 ! get ISR stack offset for this CPU
0485         smul    %l1, %l0, %l0
0486         sll     %l7, PER_CPU_CONTROL_SIZE_LOG2, %l2 ! per-CPU for this CPU
0487         add     %g6, %l2, %g6
0488 #endif
0489         set     SYM(_ISR_Stack_area_begin), %sp ! set stack pointer
0490         add     %sp, %l0, %sp
0491         andn    %sp, CPU_STACK_ALIGNMENT - 1, %sp
0492         sub     %sp, SPARC_MINIMUM_STACK_FRAME_SIZE, %sp
0493         mov     %sp, %fp ! set frame pointer
0494 
0495 #if defined(START_LEON3_ENABLE_SMP)
0496         /* If .Lbootcpuindex < 0 then assign us as boot CPU and continue. */
0497         set     SYM(.Lbootcpuindex), %l0
0498         mov     -1, %l1
0499         casa    [%l0] (10), %l1, %l7
0500         cmp     %l1, %l7
0501         bne     .Lbootsecondarycpu
0502          nop
0503 #endif
0504 
0505         /* clear the bss */
0506 
0507         sethi %hi(__bss_start), %g2     ! g2 = start of bss
0508         or    %g2,%lo(__bss_start),%g2
0509 
0510         sethi %hi(_end),%g3
0511         or    %g3,%lo(_end),%g3         ! g3 = end of bss
0512         mov   %g0,%g1                   ! so std has two zeros
0513 .Lzerobss:
0514         std    %g0,[%g2]
0515         add    %g2,8,%g2
0516         cmp    %g2,%g3
0517         bleu,a .Lzerobss
0518         nop
0519 
0520         call    SYM(_SPARC_Memory_initialize)
0521          nop ! o0 = end of usable RAM provided by the boot loader
0522 
0523         call    SYM(boot_card)          ! does not return
0524          mov    %g0, %o0                ! command line
0525 
0526 #if defined(START_LEON3_ENABLE_SMP)
0527 .Lbootsecondarycpu:
0528         call    SYM(bsp_start_on_secondary_processor) ! does not return
0529          mov    %g6, %o0
0530 
0531         /*
0532          * This is the index of the boot CPU.  Set by the first CPU at boot to
0533          * its CPU index.
0534          */
0535         .section .data, "aw"
0536         .align  4
0537         .type   .Lbootcpuindex, #object
0538         .size   .Lbootcpuindex, 4
0539 .Lbootcpuindex:
0540         .long   -1
0541 #endif
0542 
0543 /* end of file */