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