source: trunk/libs/newlib/src/libgloss/sparc_leon/rtrap.S @ 621

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

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

File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2011 Aeroflex Gaisler
3 *
4 * BSD license:
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25
26#include <asm-leon/leonstack.h>
27#include <asm-leon/winmacros.h>
28                       
29/* Registers to not touch at all. */
30#define t_psr     l0
31#define t_pc      l1
32#define t_npc     l2
33#define t_wim     l3
34#define twin_tmp1 l4
35#define glob_tmp  g4
36#define curptr    g6
37
38        /* Number of register windows */
39        .global _nwindows_min1, _nwindows
40
41        .text
42        .align 4
43        .globl  leonbare_trapreturn, schedule_callback
44
45leonbare_trapreturn:
46
47        /* a optional scheduler can be called here */
48        set schedule_callback, %g2
49        ld [%g2], %g2
50        cmp %g2,%g0
51        beq 3f
52         nop
53                 
54        jmpl %g2,%o7
55#ifndef _SOFT_FLOAT
56         add    %sp, FW_REGS_SZ + 8 + SF_REGS_SZ , %o1  ! pt_regs ptr
57#else
58         add    %sp, SF_REGS_SZ , %o1              ! pt_regs ptr
59#endif
60       
613:
62       
63#ifndef _SOFT_FLOAT
64        ld [%sp + (SF_REGS_SZ + PT_REGS_SZ + FW_REGS_SZ - 4)],%g2
65        sethi %hi(fpustate_current), %g3
66        st %g2, [%g3+%lo(fpustate_current)]
67#endif
68               
69        wr      %t_psr, 0x0, %psr       ! enable nesting again, clear ET
70       
71#ifndef _FLAT
72        /* Will the rett land us in the invalid window? */
73        mov     2, %g1
74        sll     %g1, %t_psr, %g1
75
76        sethi %hi(_nwindows), %g2       !NWINDOWS
77        ld [%g2+%lo(_nwindows)], %g2
78       
79        srl     %g1, %g2, %g2
80        or      %g1, %g2, %g1
81        rd      %wim, %g2
82        andcc   %g2, %g1, %g0
83        be      1f              ! Nope, just return from the trap
84         sll    %g2, 0x1, %g1
85
86                /* We have to grab a window before returning. */
87                sethi %hi(_nwindows_min1), %g3  !NWINDOWS-1
88                ld [%g3+%lo(_nwindows_min1)], %g3
89
90                srl     %g2, %g3,  %g2
91                or      %g1, %g2, %g1
92                and     %g1, 0xff, %g1
93
94                wr      %g1, 0x0, %wim
95
96                /* Grrr, make sure we load from the right %sp... */
97                PT_LOAD_ALL(sp, t_psr, t_pc, t_npc, g1)
98       
99                restore %g0, %g0, %g0
100                RW_LOAD(sp)
101                b       2f
102                 save   %g0, %g0, %g0
103
104        /* Reload the entire frame in case this is from a
105         * kernel system call or whatever...
106         */
1071:
108#endif
109        PT_LOAD_ALL(sp, t_psr, t_pc, t_npc, g1)
1102:
111
112#ifdef _FLAT
113        restore
114        RW_LOAD(sp)
115        save
116#endif
117       
118        wr      %t_psr, 0x0, %psr
119        nop; nop; nop 
120
121        jmp     %t_pc
122        rett    %t_npc
123
124
125
126
127       
128#ifdef _FLAT
129#warning _FLAT not implemented
130#endif
131       
132
Note: See TracBrowser for help on using the repository browser.