source: trunk/libs/newlib/src/libgloss/sparc_leon/etrap.S @ 684

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

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

File size: 3.7 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 /* Set by caller */
31#define t_pc         l1 /* Set by caller */
32#define t_npc        l2 /* Set by caller */
33#define t_wim        l3 /* Set by caller */
34#define t_twinmask   l4 /* Set at beginning of this entry routine. */
35#define t_kstack     l5 /* Set right before pt_regs frame is built */
36#define t_retpc      l6 /* If you change this, change winmacro.h header file */
37#define t_systable   l7 /* Never touch this, could be the syscall table ptr. */
38#define curptr       g6 /* Set after pt_regs frame is built */
39
40        /* Number of register windows */
41        .global _nwindows_min1, _nwindows
42
43        .text
44        .align 4
45        .globl  leonbare_trapsetup
46
47leonbare_trapsetup:
48
49#ifdef  _FLAT
50        restore
51        RW_STORE(sp)
52        save
53#endif
54
55#ifndef _SOFT_FLOAT
56        /* build a pt_regs trap frame. */
57        sub     %fp, (SF_REGS_SZ + PT_REGS_SZ + FW_REGS_SZ), %t_kstack
58        PT_STORE_ALL(t_kstack, t_psr, t_pc, t_npc, g2)
59       
60        /* build a fp_regs trap frame. */
61        sethi %hi(fpustate_current), %g2
62        ld [%g2+%lo(fpustate_current)], %g3
63        st %g3,[%t_kstack + (SF_REGS_SZ + PT_REGS_SZ + FW_REGS_SZ - 4)]
64        add %t_kstack,SF_REGS_SZ + PT_REGS_SZ,%g3
65        st %g3, [%g2+%lo(fpustate_current)]
66       
67#else   
68        /* build a pt_regs trap frame.
69         */
70        sub     %fp, (SF_REGS_SZ + PT_REGS_SZ), %t_kstack
71        PT_STORE_ALL(t_kstack, t_psr, t_pc, t_npc, g2)
72#endif
73       
74
75#ifndef _FLAT
76        /* See if we are in the trap window. */
77        mov     1, %t_twinmask
78        sll     %t_twinmask, %t_psr, %t_twinmask ! t_twinmask = (1 << psr)
79        andcc   %t_twinmask, %t_wim, %g0
80        beq     1f              ! in trap window, clean up
81         nop
82
83                /*-------------------------------------------------*/
84                /* Spill , adjust %wim and go. */
85                srl     %t_wim, 0x1, %g2        ! begin computation of new %wim
86               
87                sethi %hi(_nwindows_min1), %g3
88                ld [%g3+%lo(_nwindows_min1)], %g3
89
90                sll     %t_wim, %g3, %t_wim     ! NWINDOWS-1
91                or      %t_wim, %g2, %g2
92                and     %g2, 0xff, %g2         
93       
94                save    %g0, %g0, %g0           ! get in window to be saved
95       
96                /* Set new %wim value */
97                wr      %g2, 0x0, %wim
98
99                /* Save the kernel window onto the corresponding stack. */
100                RW_STORE(sp)
101       
102                restore %g0, %g0, %g0
103                /*-------------------------------------------------*/
104       
1051:               
106#endif
107        /* Trap from kernel with a window available.
108         * Just do it...
109         */
110        jmpl    %t_retpc + 0x8, %g0     ! return to caller
111         mov    %t_kstack, %sp          ! jump onto new stack
112       
113       
Note: See TracBrowser for help on using the repository browser.