Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:50

0001 /*
0002  * start.S -- startup file for JMR3904 BSP based upon crt0.S from
0003  * newlib-1.8.2/libgloss/mips and adapted for RTEMS.
0004  *
0005  * crt0.S -- startup file for MIPS.
0006  *
0007  * Copyright (c) 1995, 1996, 1997 Cygnus Support
0008  *
0009  * The authors hereby grant permission to use, copy, modify, distribute,
0010  * and license this software and its documentation for any purpose, provided
0011  * that existing copyright notices are retained in all copies and that this
0012  * notice is included verbatim in any distributions. No written agreement,
0013  * license, or royalty fee is required for any of the authorized uses.
0014  * Modifications to this software may be copyrighted by their authors
0015  * and need not follow the licensing terms described here, provided that
0016  * the new terms are clearly indicated on the first page of each file where
0017  * they apply.
0018  */
0019 
0020 #include <rtems/asm.h>
0021 #include <bsp/regs.h>
0022 
0023 #include <bsp.h>
0024 
0025 #ifdef __mips16
0026 /* This file contains 32 bit assembly code.  */
0027     .set nomips16
0028 #endif
0029 
0030 /* This is for referencing addresses that are not in the .sdata or
0031    .sbss section under embedded-pic, or before we've set up gp.  */
0032 #ifdef __mips_embedded_pic
0033 # ifdef __mips64
0034 #  define LA(t,x) la t,x-PICBASE ; daddu t,s0,t
0035 # else
0036 #  define LA(t,x) la t,x-PICBASE ; addu t,s0,t
0037 # endif
0038 #else /* __mips_embedded_pic */
0039 # define LA(t,x) la t,x
0040 #endif /* __mips_embedded_pic */
0041 
0042     .text
0043     .align  2
0044 
0045 /* Without the following nop, GDB thinks _start is a data variable.
0046  * This is probably a bug in GDB in handling a symbol that is at the
0047  * start of the .text section.
0048  */
0049     nop
0050     nop
0051     nop
0052     nop
0053     nop
0054     nop
0055     nop
0056     nop
0057     nop
0058     .globl  _start
0059     .ent    _start
0060 _start:
0061     nop
0062     nop
0063     nop
0064     nop
0065     nop
0066     nop
0067     nop
0068     nop
0069     .set    noreorder
0070     /* Get the address of start into $5 in a position independent fashion.
0071     ** This lets us know whether we have been relocated or not.
0072     */
0073     $LF1 = . + 8
0074     bal     $LF1
0075     nop
0076 _branch:
0077 #if 0
0078     move    $5, $31             # $5 == where are we
0079     li  $6, 0x8800000c          # $6 == where we want to be
0080 /*  #la      $6,_branch */
0081     beq $5, $6, _start_in_ram
0082     nop
0083     /* relocate the code from EEPROM to RAM */
0084         la  $7, _edata
0085 relocate:
0086         nop
0087     lw  $8, ($5)            # $8 = *EEPROM
0088     addu    $5, $5, 4           # EEPROM++
0089         sw      $8, ($6)            # *RAM = $8
0090     addu    $6, $6, 4           # RAM++
0091     bne $6, $7, relocate        # copied all the way to edata?
0092     nop
0093     la  $6, _start_in_ram
0094     jr  $6
0095     nop
0096     .end _start
0097 
0098     .globl  _start_in_ram
0099     .ent _start_in_ram
0100 #endif
0101 _start_in_ram:
0102     nop
0103 #if 0
0104 #ifdef __mips_embedded_pic
0105     PICBASE = .+8
0106         bal PICBASE
0107     nop
0108     move    s0,$31
0109 #endif
0110 #endif
0111     li  v0, SR_CU1|SR_PE|SR_FR|SR_KX|SR_SX|SR_UX
0112     mtc0    v0, C0_SR
0113     mtc0    zero, C0_CAUSE
0114 
0115 #if 0
0116 /* Check for FPU presence */
0117 #ifndef __mips_soft_float
0118 /* This doesn't work if there is no FPU.  We get illegal instruction
0119    exceptions.  */
0120     li  t2,0xAAAA5555
0121     mtc1    t2,fp0      /* write to FPR 0 */
0122     mtc1    zero,fp1    /* write to FPR 1 */
0123     mfc1    t0,fp0
0124     mfc1    t1,fp1
0125     nop
0126     bne t0,t2,1f    /* check for match */
0127     nop
0128     bne t1,zero,1f  /* double check */
0129     nop
0130 #ifndef __mips64  /* Clear the FR bit */
0131     li  v0, SR_CU1|SR_PE|SR_KX|SR_SX|SR_UX
0132     mtc0    v0, C0_SR
0133 #endif
0134     j   2f
0135     nop
0136 #endif
0137 #endif
0138 
0139 1:
0140     li  v0, SR_PE|SR_FR|SR_KX|SR_SX|SR_UX
0141     mtc0    v0, C0_SR
0142 2:
0143 /* Fix high bits, if any, of the PC so that exception handling
0144    doesn't get confused.  */
0145     LA (v0, 3f)
0146     jr  v0
0147     nop
0148 3:
0149     LA (gp, _gp)                # set the global data pointer
0150 #if 0
0151     .end _start_in_ram
0152 #else
0153     .end _start
0154 #endif
0155 
0156 /*
0157  * zero out the bss section.
0158  */
0159     .globl  zerobss
0160     .ent    zerobss
0161 zerobss:
0162     LA (v0, _fbss)
0163     LA (v1, _end)
0164 3:
0165     sw  zero,0(v0)
0166     bltu    v0,v1,3b
0167     addiu   v0,v0,4             # executed in delay slot
0168 
0169     la  t0, _ISR_Stack_area_end # initialize stack so we
0170     /* We must subtract 24 bytes for the 3 8 byte arguments to main, in
0171        case main wants to write them back to the stack.  The caller is
0172        supposed to allocate stack space for parameters in registers in
0173        the old MIPS ABIs.  We must do this even though we aren't passing
0174        arguments, because main might be declared to have them.
0175 
0176        Some ports need a larger alignment for the stack, so we subtract
0177        32, which satisifes the stack for the arguments and keeps the
0178        stack pointer better aligned.  */
0179     subu    t0,t0,32
0180     move    sp,t0               # set stack pointer
0181     .end    zerobss
0182 
0183     .globl  exit .text
0184     .globl  init
0185     .ent    init
0186 init:
0187         nop
0188     jal init_tlb        /* clear the tlb */
0189     move    a0,zero             # set command line to 0
0190     jal boot_card           # call the program start function
0191     nop
0192 
0193 dead:
0194     b   dead
0195     nop
0196     .end    init
0197 
0198 /*
0199  * _sys_exit -- Exit from the application. Normally we cause a user trap
0200  *          to return to the ROM monitor for another run. NOTE: This is
0201  *      the only other routine we provide in the crt0.o object, since
0202  *          it may be tied to the "_start" routine. It also allows
0203  *          executables that contain a complete world to be linked with
0204  *          just the crt0.o object.
0205  */
0206     .globl  _sys_exit
0207     .ent _sys_exit
0208 _sys_exit:
0209 7:
0210 #ifdef GCRT0
0211     jal _mcleanup
0212     nop
0213 #endif
0214     /* break instruction can cope with 0xfffff, but GAS limits the range: */
0215     break   1023
0216     nop
0217     b   7b              # but loop back just in-case
0218     nop
0219     .end _sys_exit
0220 
0221 /* EOF crt0.S */