source: trunk/libs/newlib/src/libgloss/sparc/crt0.S @ 612

Last change on this file since 612 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 4.3 KB
Line 
1/*
2 * C startup code for the Fujitsu SPARClite demo board
3 *
4 * Copyright (c) 1995, 1996 Cygnus Support
5 *
6 * The authors hereby grant permission to use, copy, modify, distribute,
7 * and license this software and its documentation for any purpose, provided
8 * that existing copyright notices are retained in all copies and that this
9 * notice is included verbatim in any distributions. No written agreement,
10 * license, or royalty fee is required for any of the authorized uses.
11 * Modifications to this software may be copyrighted by their authors
12 * and need not follow the licensing terms described here, provided that
13 * the new terms are clearly indicated on the first page of each file where
14 * they apply.
15 */
16#include "asm.h"
17
18.register %g2, #scratch
19.register %g3, #scratch
20       
21.data
22        .align  8
23        .ascii  "DaTa"          ! this is the first address in the data section
24        .long   SYM(sdata)
25SYM(environ):
26        .long   0
27
28        .text
29        .align 8
30
31        .globl SYM(_start)
32SYM(_start):
33        .globl SYM(start)
34SYM(start):
35        /* see if the stack is already setup. if not, then default
36         *  to using the value of %sp as set by the ROM monitor
37         */
38        sethi   %hi(__stack), %g1
39        or      %g1,%lo(__stack),%g1
40        cmp     %g0,%g1
41        be      1f
42        mov     %g1, %sp                                ! set the stack pointer
43        mov     %sp, %fp
441:     
45
46        /* zero the bss section */
47        sethi %hi(__bss_start),%g2
48        or    %g2,%lo(__bss_start),%g2          ! start of bss
49        sethi %hi(_end),%g3
50        or    %g3,%lo(_end),%g3                 ! end of bss
51        mov   %g0,%g1                           ! so std has two zeros
52zerobss:
53        std    %g0,[%g2]
54        add    %g2,8,%g2
55        cmp    %g2,%g3
56        bleu,a zerobss
57        nop
58       
59/*
60 * copy prom & trap vectors to sram.
61 */
62        set 0x30000000, %l0
63        set 0xfff8, %l1
64        tst %l1                                 ! Set condition codes
65
66copyloop:
67        ldd [%l1], %l2
68        std %l2, [%l0 + %l1]
69        bg copyloop
70        deccc 8, %l1
71
72        set 0x30000000, %l0                     ! Base of new trap vector
73        mov %l0, %tbr                           ! Install the new tbr
74
75        set SYM(win_ovf_trap), %l1              ! Setup window overflow trap
76        ldd [%l1], %l2
77        std %l2, [%l0 + 5 * 16]
78        ldd [%l1 + 8], %l2
79        std %l2, [%l0 + 5 * 16 + 8]
80
81        set SYM(win_unf_trap), %l1              ! Setup window underflow trap
82        ldd [%l1], %l2
83        std %l2, [%l0 + 6 * 16]
84        ldd [%l1 + 8], %l2
85        std %l2, [%l0 + 6 * 16 + 8]
86
87/*
88 * Try enabling the FPU by setting EF.  If that causes a trap, then we probably
89 * don't have an FPU.
90 */
91
92        ldd [%l0 + 2 * 16], %l4                 ! Save original trap routine
93        set SYM(no_fpu_trap), %l1               ! Install new one
94        ldd [%l1], %l2
95        std %l2, [%l0 + 2 * 16]
96
97        mov %psr, %l0
98        sethi %hi(0x1000), %l1
99        bset %l1, %l0
100!       mov %l0, %psr
101
102        std %l4, [2 * 16]                       ! Restore original trap routine
103
104
105/*
106 * Move the data segment from it's ROM address to RAM where it
107 * belongs.
108 */
109
110relocd:
111#if 0   /* This code is broken.  FIXME */
112        set (_sdata),%g2                        ! %g2 = start of data in aout file
113        set SYM(environ),%g4                    ! %g4 = actual data base address
114        set (_edata),%g3                        ! %g3 = end of where data should go
115        subcc   %g3, %g4, %g5                   ! %g5 = length of data
116
117        subcc   %g4, %g2, %g0                   ! need to relocate data ?
118        ble     init
119        ld      [%g4], %g6
120        subcc   %g6, 1, %g0
121        be      init
122mvdata:
123        subcc   %g5, 8, %g5
124        ldd     [%g2 + %g5], %g6
125        bg      mvdata
126#endif
127
128/*
129 * initialize target specific stuff. Only execute these
130 * functions it they exist.
131 */
132init:
133        sethi   %hi(SYM(hardware_init_hook)), %g1
134        or      %g1,%lo(SYM(hardware_init_hook)),%g1
135        cmp     %g0,%g1
136        be      1f
137        nop
138        call    SYM(hardware_init_hook)
139        nop
140
1411:     
142        sethi   %hi(SYM(software_init_hook)), %g1
143        or      %g1,%lo(SYM(software_init_hook)),%g1
144        cmp     %g0,%g1
145        be      2f
146        nop
147        call    SYM(software_init_hook)
148        nop
1492:
150        call SYM(main)
151        nop
152
153        /* call exit from the C library so atexit gets called, and the
154         * C++ destructors get run. This calls our exit routine below   
155         * when it's done.
156         */
157        call    SYM(exit)
158        nop
159
160/*
161 * This should drop control back to the ROM monitor, if there is
162 * one.
163 */
164        .globl  SYM(_exit)
165SYM(_exit):
166        call    0
167        nop
168
169/*
170 * Trap handlers.
171 */
172
173        .align 8
174
175SYM(win_ovf_trap):
176        sethi %hi(SYM(win_ovf)), %l3
177        jmpl %lo(SYM(win_ovf))+%l3, %g0
178        mov %wim, %l0
179        nop
180
181SYM(win_unf_trap):
182        sethi %hi(SYM(win_unf)), %l3
183        jmpl %lo(SYM(win_unf))+%l3, %g0
184        mov %wim, %l0
185        nop
186       
187SYM(no_fpu_trap):                       ! Come here when no fpu exists.
188        jmpl %l2, %g0                   ! This just skips the
189        rett %l2+4                      ! offending instruction.
Note: See TracBrowser for help on using the repository browser.