/************************************************************************* * * Filename: * * crt1.S * * Description: * * This is the start-up code for Ada, C and C++ programs running on the * the XGC monitor, or other software that provides a system call * interface and supports the XGC standard traps (See the file crt0.S * for details). * * Credits: * * Copyright (c) 1998-2000 XGC.Com Software * * This file is part of the XGC/ERC32 library. It was developed under * European Space Agency contract 11935/96/NL/JG. * * License: * * Permission to use copy, modify, and distribute this software for any * purpose without fee is hereby granted. This software is provided "as * is", without any express or implied warranty. In particular, neither * the author nor the European Space Agency makes any representation or * warranty of any kind concerning the merchantability of this software * or its fitness for any particular purpose. * * Revision: * * $Id: crt1.S,v 1.8 2000/12/03 18:39:08 cvs Exp $ * *************************************************************************/ .text .globl start start: /* * Zeroize the bss area. */ sethi %hi(__bss_start), %g1 or %g1, %lo(__bss_start), %g1 sethi %hi(_end), %g2 or %g2, %lo(_end), %g2 .L2: st %g0, [%g1] add %g1, 4, %g1 cmp %g1, %g2 bleu,a .L2 nop /* * Copy the initial values of the .data section from the .idata * section. */ sethi %hi(_sidata),%g2 or %g2,%lo(_sidata),%o1 sethi %hi(_sdata),%g2 or %g2,%lo(_sdata),%o0 sethi %hi(_edata),%g2 or %g2,%lo(_edata),%g2 sub %g2,%o0,%g2 sra %g2,2,%g3 cmp %g3,0 ble .L3 nop .L4: ld [%o1],%g2 st %g2,[%o0] add %o1,4,%o1 add %g3,-1,%g3 cmp %g3,0 bg .L4 add %o0,4,%o0 .L3: /* * Create the first stack frame. We load the lowest stack address * into global register %g7, where is can be checked against %sp. */ sethi %hi(_sstack), %g1 or %g1, %lo(_sstack), %g7 sethi %hi(_estack), %g1 or %g1, %lo(_estack), %sp mov %sp, %fp sub %sp, 104, %sp /* * Call any static contructors. */ sethi %hi(__CTOR_LIST__ + 4), %o0 or %o0, %lo(__CTOR_LIST__ + 4), %l0 ld [%o0 + %lo(__CTOR_LIST__ + 4)], %o0 cmp %o0, 0 be .L12 mov 0, %o0 .L5: ld [%l0], %o0 call %o0, 0 add %l0, 4, %l0 ld [%l0], %o0 cmp %o0, 0 bne .L5 mov 0, %o0 .L12: /* * Call main (0, 0). Return with exit code in register %o0. */ mov %g0, %o0 call main, 0 mov %g0, %o1 .globl _exit _exit: /* * Call any static destructors. */ mov %o0, %l1 sethi %hi(__DTOR_LIST__ + 4), %g2 or %g2, %lo(__DTOR_LIST__ + 4), %l0 ld [%g2 + %lo(__DTOR_LIST__ + 4)], %g2 cmp %g2, 0 be .L8 nop .L10: ld [%l0], %g2 call %g2, 0 add %l0, 4, %l0 ld [%l0], %g2 cmp %g2, 0 bne .L10 nop .L8: /* * Program finished, return to monitor. */ mov %l1, %o0 mov %l1, %i0 ta 15 ba . .end