OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [libgloss/] [mips/] [crt0_cfe.S] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
/*
/*
 * crt0_cfe.S -- Runtime startup for MIPS targets running CFE.
 * crt0_cfe.S -- Runtime startup for MIPS targets running CFE.
 *
 *
 * Copyright 2003
 * Copyright 2003
 * Broadcom Corporation. All rights reserved.
 * Broadcom Corporation. All rights reserved.
 *
 *
 * This software is furnished under license and may be used and copied only
 * This software is furnished under license and may be used and copied only
 * in accordance with the following terms and conditions.  Subject to these
 * in accordance with the following terms and conditions.  Subject to these
 * conditions, you may download, copy, install, use, modify and distribute
 * conditions, you may download, copy, install, use, modify and distribute
 * modified or unmodified copies of this software in source and/or binary
 * modified or unmodified copies of this software in source and/or binary
 * form. No title or ownership is transferred hereby.
 * form. No title or ownership is transferred hereby.
 *
 *
 * 1) Any source code used, modified or distributed must reproduce and
 * 1) Any source code used, modified or distributed must reproduce and
 *    retain this copyright notice and list of conditions as they appear in
 *    retain this copyright notice and list of conditions as they appear in
 *    the source file.
 *    the source file.
 *
 *
 * 2) No right is granted to use any trade name, trademark, or logo of
 * 2) No right is granted to use any trade name, trademark, or logo of
 *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
 *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
 *    used to endorse or promote products derived from this software
 *    used to endorse or promote products derived from this software
 *    without the prior written permission of Broadcom Corporation.
 *    without the prior written permission of Broadcom Corporation.
 *
 *
 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
 *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
 *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
 *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
 *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
 *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
 *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
 *    LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *    LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 */
/*
/*
 * Derived from crt0_cygmon.S:
 * Derived from crt0_cygmon.S:
 *
 *
 * Copyright (c) 1995, 1996, 1997, 2000 Red Hat, Inc.
 * Copyright (c) 1995, 1996, 1997, 2000 Red Hat, Inc.
 *
 *
 * The authors hereby grant permission to use, copy, modify, distribute,
 * The authors hereby grant permission to use, copy, modify, distribute,
 * and license this software and its documentation for any purpose, provided
 * and license this software and its documentation for any purpose, provided
 * that existing copyright notices are retained in all copies and that this
 * that existing copyright notices are retained in all copies and that this
 * notice is included verbatim in any distributions. No written agreement,
 * notice is included verbatim in any distributions. No written agreement,
 * license, or royalty fee is required for any of the authorized uses.
 * license, or royalty fee is required for any of the authorized uses.
 * Modifications to this software may be copyrighted by their authors
 * Modifications to this software may be copyrighted by their authors
 * and need not follow the licensing terms described here, provided that
 * and need not follow the licensing terms described here, provided that
 * the new terms are clearly indicated on the first page of each file where
 * the new terms are clearly indicated on the first page of each file where
 * they apply.
 * they apply.
 */
 */
/*
/*
 * This file does minimal runtime startup for code running under
 * This file does minimal runtime startup for code running under
 * CFE firmware.
 * CFE firmware.
 *
 *
 * It does minimal hardware initialization.  In particular
 * It does minimal hardware initialization.  In particular
 * it sets Status:FR to match the requested floating point
 * it sets Status:FR to match the requested floating point
 * mode.
 * mode.
 *
 *
 * It is meant to be linked with the other files provided by libcfe.a,
 * It is meant to be linked with the other files provided by libcfe.a,
 * and calls routines in those files.
 * and calls routines in those files.
 */
 */
#ifdef __mips16
#ifdef __mips16
/* This file contains 32 bit assembly code.  */
/* This file contains 32 bit assembly code.  */
        .set nomips16
        .set nomips16
#endif
#endif
#ifdef __mips_embedded_pic
#ifdef __mips_embedded_pic
# error -membedded-pic is not supported.
# error -membedded-pic is not supported.
#endif
#endif
#include "regs.S"
#include "regs.S"
/*
/*
 * Set up some room for a stack. We just grab a chunk of memory.
 * Set up some room for a stack. We just grab a chunk of memory.
 */
 */
#define STARTUP_STACK_SIZE      (1 * 1024)
#define STARTUP_STACK_SIZE      (1 * 1024)
        .comm   _lstack, STARTUP_STACK_SIZE
        .comm   _lstack, STARTUP_STACK_SIZE
        .text
        .text
        .align  4
        .align  4
    /*
    /*
     * Without the following nop, GDB thinks _start is a data variable.
     * Without the following nop, GDB thinks _start is a data variable.
     * This is probably a bug in GDB in handling a symbol that is at the
     * This is probably a bug in GDB in handling a symbol that is at the
     * start of the .text section.
     * start of the .text section.
     */
     */
        nop
        nop
    /*
    /*
     * On entry, the following values have been passed in registers
     * On entry, the following values have been passed in registers
     * by the firmware:
     * by the firmware:
     *
     *
     * a0: firmware handle
     * a0: firmware handle
     * a1: zero (unused)
     * a1: zero (unused)
     * a2: firmware callback entrypoint
     * a2: firmware callback entrypoint
     * a3: CFE entrypoint seal (unused)
     * a3: CFE entrypoint seal (unused)
     *
     *
     * They must be preserved until the CFE entrypoint and handle
     * They must be preserved until the CFE entrypoint and handle
     * are passed to __libcfe_init().
     * are passed to __libcfe_init().
     */
     */
        .globl  _start
        .globl  _start
        .ent    _start
        .ent    _start
_start:
_start:
        .set    noreorder
        .set    noreorder
    /* Set the global data pointer, defined in the linker script.  */
    /* Set the global data pointer, defined in the linker script.  */
        la              gp, _gp
        la              gp, _gp
#ifndef __mips_soft_float
#ifndef __mips_soft_float
    /* If compiled for hard float, set the FPU mode based on the
    /* If compiled for hard float, set the FPU mode based on the
       compilation flags.  Note that this assumes that enough code
       compilation flags.  Note that this assumes that enough code
       will run after the mtc0 to clear any hazards.  */
       will run after the mtc0 to clear any hazards.  */
        mfc0    t0, C0_SR
        mfc0    t0, C0_SR
        or      t0, t0, (SR_CU1 | SR_FR)
        or      t0, t0, (SR_CU1 | SR_FR)
#if (__mips_fpr == 32)
#if (__mips_fpr == 32)
        xor     t0, t0, SR_FR           /* If 32-bit FP mode, clear FR.  */
        xor     t0, t0, SR_FR           /* If 32-bit FP mode, clear FR.  */
#endif
#endif
        mtc0    t0, C0_SR
        mtc0    t0, C0_SR
#endif
#endif
        .end    _start
        .end    _start
    /*
    /*
     * zero out the bss section.
     * zero out the bss section.
     */
     */
        .globl  _zerobss
        .globl  _zerobss
        .ent    _zerobss
        .ent    _zerobss
_zerobss:
_zerobss:
    /* These variables are defined in the linker script.  */
    /* These variables are defined in the linker script.  */
        la              v0, _fbss
        la              v0, _fbss
        la              v1, _end
        la              v1, _end
3:
3:
        sw              zero, 0(v0)
        sw              zero, 0(v0)
        bltu    v0, v1, 3b
        bltu    v0, v1, 3b
        addiu   v0, v0, 4               /* Delay slot.  */
        addiu   v0, v0, 4               /* Delay slot.  */
        .end    _zerobss
        .end    _zerobss
    /*
    /*
     * Setup a small stack so we can run some C code, and do
     * Setup a small stack so we can run some C code, and do
     * the library initialization.  (32 bytes are saved for
     * the library initialization.  (32 bytes are saved for
     * the argument registers' stack slots.)
     * the argument registers' stack slots.)
     */
     */
        .globl  _stackinit
        .globl  _stackinit
        .ent    _stackinit
        .ent    _stackinit
_stackinit:
_stackinit:
        la      t0, _lstack
        la      t0, _lstack
        addiu   sp, t0, (STARTUP_STACK_SIZE - 32)
        addiu   sp, t0, (STARTUP_STACK_SIZE - 32)
        jal     __libcfe_init
        jal     __libcfe_init
        nop
        nop
    /*
    /*
     * Setup the stack pointer --
     * Setup the stack pointer --
     *    __libcfe_init() returns the value to be used as the top of
     *    __libcfe_init() returns the value to be used as the top of
     *    the program's stack.
     *    the program's stack.
     *
     *
     *    We subtract 32 bytes for the 4 argument registers, in case
     *    We subtract 32 bytes for the 4 argument registers, in case
     *    main() wants to write them back to the stack.  The caller
     *    main() wants to write them back to the stack.  The caller
     *    allocates stack space for parameters in the old MIPS ABIs.
     *    allocates stack space for parameters in the old MIPS ABIs.
     *    We must do this even though we aren't passing arguments,
     *    We must do this even though we aren't passing arguments,
     *    because main might be declared to have them.)
     *    because main might be declared to have them.)
     *
     *
     *    We subtract 32 more bytes for the argv/envp setup for the
     *    We subtract 32 more bytes for the argv/envp setup for the
     *    call to main().
     *    call to main().
     */
     */
        subu    v0, v0, 64
        subu    v0, v0, 64
        move    sp, v0
        move    sp, v0
        .end    _stackinit
        .end    _stackinit
    /*
    /*
     * initialize target specific stuff. Only execute these
     * initialize target specific stuff. Only execute these
     * functions it they exist.
     * functions it they exist.
     */
     */
        .globl  hardware_init_hook .text
        .globl  hardware_init_hook .text
        .globl  software_init_hook .text
        .globl  software_init_hook .text
        .type   _fini,@function
        .type   _fini,@function
        .type   _init,@function
        .type   _init,@function
        .globl  atexit .text
        .globl  atexit .text
        .globl  exit .text
        .globl  exit .text
        .globl  _crt0init
        .globl  _crt0init
        .ent    _crt0init
        .ent    _crt0init
_crt0init:
_crt0init:
        la              t9, hardware_init_hook  # init the hardware if needed
        la              t9, hardware_init_hook  # init the hardware if needed
        beq             t9, zero, 6f
        beq             t9, zero, 6f
        nop
        nop
        jal             t9
        jal             t9
        nop
        nop
6:
6:
        la              t9, software_init_hook  # init the software if needed
        la              t9, software_init_hook  # init the software if needed
        beq             t9, zero, 7f
        beq             t9, zero, 7f
        nop
        nop
        jal             t9
        jal             t9
        nop
        nop
7:
7:
        la              a0, _fini
        la              a0, _fini
        jal             atexit
        jal             atexit
        nop
        nop
#ifdef GCRT0
#ifdef GCRT0
        .globl  _ftext
        .globl  _ftext
        .globl  _extext
        .globl  _extext
        la              a0, _ftext
        la              a0, _ftext
        la              a1, _etext
        la              a1, _etext
        jal             monstartup
        jal             monstartup
        nop
        nop
#endif
#endif
        jal     _init                   # run global constructors
        jal     _init                   # run global constructors
        nop
        nop
        addiu   a1,sp,32                        # argv = sp + 32
        addiu   a1,sp,32                        # argv = sp + 32
        addiu   a2,sp,40                        # envp = sp + 40
        addiu   a2,sp,40                        # envp = sp + 40
#if __mips64
#if __mips64
        sd      zero,(a1)                       # argv[argc] = 0
        sd      zero,(a1)                       # argv[argc] = 0
        sd      zero,(a2)                       # envp[0] = 0
        sd      zero,(a2)                       # envp[0] = 0
#else
#else
        sw      zero,(a1)
        sw      zero,(a1)
        sw      zero,(a2)
        sw      zero,(a2)
#endif
#endif
        jal     main                    # call the program start function
        jal     main                    # call the program start function
        move    a0,zero                 # set argc to 0; delay slot.
        move    a0,zero                 # set argc to 0; delay slot.
        # fall through to the "exit" routine
        # fall through to the "exit" routine
        jal     exit                    # call libc exit to run the G++
        jal     exit                    # call libc exit to run the G++
                                        # destructors
                                        # destructors
        move    a0, v0                  # pass through the exit code
        move    a0, v0                  # pass through the exit code
        .end    _crt0init
        .end    _crt0init
/*
/*
 * _exit -- Exit from the application.  This is provided in this file because
 * _exit -- Exit from the application.  This is provided in this file because
 *          program exit should shut down profiling (if GCRT0 is defined),
 *          program exit should shut down profiling (if GCRT0 is defined),
 *          and only this file is compiled with GCRT0 defined.
 *          and only this file is compiled with GCRT0 defined.
 */
 */
        .globl  _exit
        .globl  _exit
        .ent    _exit
        .ent    _exit
_exit:
_exit:
7:
7:
        move    s0, a0                  /* Save in case we loop.  */
        move    s0, a0                  /* Save in case we loop.  */
#ifdef GCRT0
#ifdef GCRT0
        jal     _mcleanup
        jal     _mcleanup
        nop
        nop
#endif
#endif
        la      t0, hardware_exit_hook
        la      t0, hardware_exit_hook
        beq     t0,zero,1f
        beq     t0,zero,1f
        nop
        nop
        jal     t0
        jal     t0
        nop
        nop
1:
1:
        /* Call into the library to do the heavy lifting.  */
        /* Call into the library to do the heavy lifting.  */
        jal     __libcfe_exit
        jal     __libcfe_exit
        move    a0, s0                  /* Delay slot.  */
        move    a0, s0                  /* Delay slot.  */
        b       7b                      /* Loop back just in case.  */
        b       7b                      /* Loop back just in case.  */
        nop
        nop
        .end    _exit
        .end    _exit
/* EOF crt0_cfe.S */
/* EOF crt0_cfe.S */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.