VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / arch / parisc / kernel / real2.S
1 /*
2  *
3  * This file is subject to the terms and conditions of the GNU General Public
4  * License.  See the file "COPYING" in the main directory of this archive
5  * for more details.
6  *
7  * Copyright (C) 2000 Hewlett Packard (Paul Bame bame@puffin.external.hp.com)
8  *
9  */
10 #include <asm/assembly.h>
11 #include <asm/psw.h>
12
13         .section        .bss
14         .export real_stack
15         .export real32_stack
16         .export real64_stack
17         .align  64
18 real_stack:
19 real32_stack:
20 real64_stack:
21         .block  8192
22
23 #ifdef __LP64__
24 #  define REG_SZ 8
25 #else
26 #  define REG_SZ 4
27 #endif
28
29 #define N_SAVED_REGS 9
30
31 save_cr_space:
32         .block  REG_SZ * N_SAVED_REGS
33 save_cr_end:
34
35
36 /************************ 32-bit real-mode calls ***********************/
37 /* This can be called in both narrow and wide kernels */
38
39         .text
40
41         .export real32_call_asm
42
43         /* unsigned long real32_call_asm(unsigned int *sp,
44          *              unsigned int *arg0p,
45          *              unsigned int iodc_fn)
46          *      sp is value of stack pointer to adopt before calling PDC (virt)
47          *      arg0p points to where saved arg values may be found
48          *      iodc_fn is the IODC function to call
49          */
50
51 real32_call_asm:
52         STREG   %rp, -RP_OFFSET(%sp)    /* save RP */
53 #ifdef __LP64__
54         callee_save
55         ldo     2*REG_SZ(%sp), %sp      /* room for a couple more saves */
56         STREG   %r27, -1*REG_SZ(%sp)
57         STREG   %r29, -2*REG_SZ(%sp)
58 #endif
59         STREG   %sp, -REG_SZ(%arg0)     /* save SP on real-mode stack */
60         copy    %arg0, %sp              /* adopt the real-mode SP */
61
62         /* save iodc_fn */
63         copy    %arg2, %r31
64
65         /* load up the arg registers from the saved arg area */
66         /* 32-bit calling convention passes first 4 args in registers */
67         ldw     0(%arg1), %arg0         /* note overwriting arg0 */
68         ldw     -8(%arg1), %arg2
69         ldw     -12(%arg1), %arg3
70         ldw     -4(%arg1), %arg1        /* obviously must do this one last! */
71
72         tophys_r1  %sp
73
74         b,l     rfi_virt2real,%r2
75         nop
76
77         b,l     save_control_regs,%r2           /* modifies r1, r2, r28 */
78         nop
79
80 #ifdef __LP64__
81         rsm     PSW_SM_W, %r0           /* go narrow */
82 #endif
83
84         ldil    L%PA(ric_ret), %r2
85         ldo     R%PA(ric_ret)(%r2), %r2
86         bv      0(%r31)
87         nop
88 ric_ret:
89 #ifdef __LP64__
90         ssm     PSW_SM_W, %r0           /* go wide */
91 #endif
92         /* restore CRs before going virtual in case we page fault */
93         b,l     restore_control_regs, %r2       /* modifies r1, r2, r26 */
94         nop
95
96         b,l     rfi_real2virt,%r2
97         nop
98
99         tovirt_r1 %sp
100         LDREG   -REG_SZ(%sp), %sp       /* restore SP */
101 #ifdef __LP64__
102         LDREG   -1*REG_SZ(%sp), %r27
103         LDREG   -2*REG_SZ(%sp), %r29
104         ldo     -2*REG_SZ(%sp), %sp
105         callee_rest
106 #endif
107         LDREG   -RP_OFFSET(%sp), %rp    /* restore RP */
108         bv      0(%rp)
109         nop
110
111
112 #  define PUSH_CR(r, where) mfctl r, %r1 ! STREG,ma %r1, REG_SZ(where)
113 #  define POP_CR(r, where) LDREG,mb -REG_SZ(where), %r1 ! mtctl %r1, r
114
115         .text
116 save_control_regs:
117         load32  PA(save_cr_space), %r28
118         PUSH_CR(%cr24, %r28)
119         PUSH_CR(%cr25, %r28)
120         PUSH_CR(%cr26, %r28)
121         PUSH_CR(%cr27, %r28)
122         PUSH_CR(%cr28, %r28)
123         PUSH_CR(%cr29, %r28)
124         PUSH_CR(%cr30, %r28)
125         PUSH_CR(%cr31, %r28)
126         PUSH_CR(%cr15, %r28)
127         bv 0(%r2)
128         nop
129
130 restore_control_regs:
131         load32  PA(save_cr_end), %r26
132         POP_CR(%cr15, %r26)
133         POP_CR(%cr31, %r26)
134         POP_CR(%cr30, %r26)
135         POP_CR(%cr29, %r26)
136         POP_CR(%cr28, %r26)
137         POP_CR(%cr27, %r26)
138         POP_CR(%cr26, %r26)
139         POP_CR(%cr25, %r26)
140         POP_CR(%cr24, %r26)
141         bv 0(%r2)
142         nop
143
144 /* rfi_virt2real() and rfi_real2virt() could perhaps be adapted for
145  * more general-purpose use by the several places which need RFIs
146  */
147         .align 128
148         .text
149 rfi_virt2real:
150         /* switch to real mode... */
151         ssm             0,0             /* See "relied upon translation" */
152         nop                             /* comment in interruption.S */
153         nop
154         nop
155         nop
156         nop
157         nop
158         nop
159         nop
160         
161         rsm             (PSW_SM_Q|PSW_SM_I),%r0  /* disable Q & I bits to load iia queue */
162         mtctl           %r0, %cr17      /* Clear IIASQ tail */
163         mtctl           %r0, %cr17      /* Clear IIASQ head */
164         load32          PA(rfi_v2r_1), %r1
165         mtctl           %r1, %cr18      /* IIAOQ head */
166         ldo             4(%r1), %r1
167         mtctl           %r1, %cr18      /* IIAOQ tail */
168         load32          REAL_MODE_PSW, %r1
169         mtctl           %r1, %cr22
170         rfi
171         
172         nop
173         nop
174         nop
175         nop
176         nop
177         nop
178         nop
179         nop
180 rfi_v2r_1:
181         tophys_r1 %r2
182         bv      0(%r2)
183         nop
184
185         .text
186         .align 128
187 rfi_real2virt:
188         ssm             0,0             /* See "relied upon translation" */
189         nop                             /* comment in interruption.S */
190         nop
191         nop
192         nop
193         nop
194         nop
195         nop
196         nop
197         
198         rsm             PSW_SM_Q,%r0    /* disable Q bit to load iia queue */
199         mtctl           %r0, %cr17      /* Clear IIASQ tail */
200         mtctl           %r0, %cr17      /* Clear IIASQ head */
201         load32          (rfi_r2v_1), %r1
202         mtctl           %r1, %cr18      /* IIAOQ head */
203         ldo             4(%r1), %r1
204         mtctl           %r1, %cr18      /* IIAOQ tail */
205         load32          KERNEL_PSW, %r1
206         mtctl           %r1, %cr22
207         rfi
208         
209         nop
210         nop
211         nop
212         nop
213         nop
214         nop
215         nop
216         nop
217 rfi_r2v_1:
218         tovirt_r1 %r2
219         bv      0(%r2)
220         nop
221
222 #ifdef __LP64__
223
224 /************************ 64-bit real-mode calls ***********************/
225 /* This is only usable in wide kernels right now and will probably stay so */
226         .text
227         .export real64_call_asm
228         /* unsigned long real64_call_asm(unsigned long *sp,
229          *              unsigned long *arg0p,
230          *              unsigned long fn)
231          *      sp is value of stack pointer to adopt before calling PDC (virt)
232          *      arg0p points to where saved arg values may be found
233          *      iodc_fn is the IODC function to call
234          */
235 real64_call_asm:
236         std     %rp, -0x10(%sp)         /* save RP */
237         std     %sp, -8(%arg0)          /* save SP on real-mode stack */
238         copy    %arg0, %sp              /* adopt the real-mode SP */
239
240         /* save fn */
241         copy    %arg2, %r31
242
243         /* set up the new ap */
244         ldo     64(%arg1), %r29
245
246         /* load up the arg registers from the saved arg area */
247         /* 32-bit calling convention passes first 4 args in registers */
248         ldd     0*REG_SZ(%arg1), %arg0          /* note overwriting arg0 */
249         ldd     2*REG_SZ(%arg1), %arg2
250         ldd     3*REG_SZ(%arg1), %arg3
251         ldd     4*REG_SZ(%arg1), %r22
252         ldd     5*REG_SZ(%arg1), %r21
253         ldd     6*REG_SZ(%arg1), %r20
254         ldd     7*REG_SZ(%arg1), %r19
255         ldd     1*REG_SZ(%arg1), %arg1          /* do this one last! */
256
257         tophys_r1 %sp
258
259         b,l     rfi_virt2real,%r2
260         nop
261
262         b,l     save_control_regs,%r2           /* modifies r1, r2, r28 */
263         nop
264
265         load32  PA(r64_ret), %r2
266         bv      0(%r31)
267         nop
268 r64_ret:
269         /* restore CRs before going virtual in case we page fault */
270         b,l     restore_control_regs, %r2       /* modifies r1, r2, r26 */
271         nop
272
273         b,l     rfi_real2virt,%r2
274         nop
275
276         tovirt_r1 %sp
277         ldd     -8(%sp), %sp            /* restore SP */
278         ldd     -0x10(%sp), %rp         /* restore RP */
279         bv      0(%rp)
280         nop
281
282 #endif
283
284         .export pc_in_user_space
285         .text
286         /* Doesn't belong here but I couldn't find a nicer spot. */
287         /* Should never get called, only used by profile stuff in time.c */
288 pc_in_user_space:
289         bv,n    0(%rp)
290         nop
291
292
293         .export __canonicalize_funcptr_for_compare
294         .text
295         /* http://lists.parisc-linux.org/hypermail/parisc-linux/10916.html
296         **      GCC 3.3 and later has a new function in libgcc.a for
297         **      comparing function pointers.
298         */
299 __canonicalize_funcptr_for_compare:
300 #ifdef __LP64__
301         bve (%r2)
302 #else
303         bv %r0(%r2)
304 #endif
305         copy %r26,%r28