blob: ccd3a50c0995edec74134b56a705ad1f85902b2d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Linux/PARISC Project (http://www.parisc-linux.org/)
3 *
4 * HP-UX System Call Wrapper routines and System Call Return Path
5 *
6 * Copyright (C) 2000 Hewlett-Packard (John Marvin)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
Helge Deller79793452007-01-28 16:43:32 +010023#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#warning PA64 support needs more work...did first cut
25#endif
26
Sam Ravnborg0013a852005-09-09 20:57:26 +020027#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/assembly.h>
29#include <asm/signal.h>
Helge Deller79793452007-01-28 16:43:32 +010030#include <linux/linkage.h>
Helge Dellerbd3bb8c2008-05-02 22:02:48 +020031#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Helge Deller79793452007-01-28 16:43:32 +010033 .level LEVEL
Helge Dellerbd3bb8c2008-05-02 22:02:48 +020034 __HEAD
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36 /* These should probably go in a header file somewhere.
37 * They are duplicated in kernel/wrappers.S
38 * Possibly we should consider consolidating these
39 * register save/restore macros.
40 */
41 .macro reg_save regs
Helge Deller79793452007-01-28 16:43:32 +010042#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#warning NEEDS WORK for 64-bit
44#endif
45 STREG %r3, PT_GR3(\regs)
46 STREG %r4, PT_GR4(\regs)
47 STREG %r5, PT_GR5(\regs)
48 STREG %r6, PT_GR6(\regs)
49 STREG %r7, PT_GR7(\regs)
50 STREG %r8, PT_GR8(\regs)
51 STREG %r9, PT_GR9(\regs)
52 STREG %r10,PT_GR10(\regs)
53 STREG %r11,PT_GR11(\regs)
54 STREG %r12,PT_GR12(\regs)
55 STREG %r13,PT_GR13(\regs)
56 STREG %r14,PT_GR14(\regs)
57 STREG %r15,PT_GR15(\regs)
58 STREG %r16,PT_GR16(\regs)
59 STREG %r17,PT_GR17(\regs)
60 STREG %r18,PT_GR18(\regs)
61 .endm
62
63 .macro reg_restore regs
64 LDREG PT_GR3(\regs), %r3
65 LDREG PT_GR4(\regs), %r4
66 LDREG PT_GR5(\regs), %r5
67 LDREG PT_GR6(\regs), %r6
68 LDREG PT_GR7(\regs), %r7
69 LDREG PT_GR8(\regs), %r8
70 LDREG PT_GR9(\regs), %r9
71 LDREG PT_GR10(\regs),%r10
72 LDREG PT_GR11(\regs),%r11
73 LDREG PT_GR12(\regs),%r12
74 LDREG PT_GR13(\regs),%r13
75 LDREG PT_GR14(\regs),%r14
76 LDREG PT_GR15(\regs),%r15
77 LDREG PT_GR16(\regs),%r16
78 LDREG PT_GR17(\regs),%r17
79 LDREG PT_GR18(\regs),%r18
80 .endm
81
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 .import sys_fork
84
Helge Deller79793452007-01-28 16:43:32 +010085ENTRY(hpux_fork_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 ldo TASK_REGS-TASK_SZ_ALGN-64(%r30),%r1 ;! get pt regs
87 ;! pointer in task
88 reg_save %r1
89
90 STREG %r2,-20(%r30)
91 ldo 64(%r30),%r30
92 STREG %r2,PT_GR19(%r1) ;! save for child
93 STREG %r30,PT_GR21(%r1) ;! save for child
94
95 LDREG PT_GR30(%r1),%r25
96 mtctl %r25,%cr29
97 copy %r1,%r24
98 bl sys_clone,%r2
99 ldi SIGCHLD,%r26
100
101 LDREG -84(%r30),%r2
102fork_return:
103 ldo -64(%r30),%r30
104 ldo TASK_REGS-TASK_SZ_ALGN-64(%r30),%r1 ;! get pt regs
105
106 reg_restore %r1
107
108 /*
109 * HP-UX wants pid (child gets parent pid, parent gets child pid)
110 * in r28 and a flag in r29 (r29 == 1 for child, 0 for parent).
111 * Linux fork returns 0 for child, pid for parent. Since HP-UX
112 * libc stub throws away parent pid and returns 0 for child,
113 * we'll just return 0 for parent pid now. Only applications
114 * that jump directly to the gateway page (not supported) will
115 * know the difference. We can fix this later if necessary.
116 */
117
118 ldo -1024(%r0),%r1
119 comb,>>=,n %r28,%r1,fork_exit /* just let the syscall exit handle it */
120 or,= %r28,%r0,%r0
121 or,tr %r0,%r0,%r29 /* r28 <> 0, we are parent, set r29 to 0 */
122 ldo 1(%r0),%r29 /* r28 == 0, we are child, set r29 to 1 */
123
124fork_exit:
125 bv %r0(%r2)
126 nop
Helge Deller79793452007-01-28 16:43:32 +0100127ENDPROC(hpux_fork_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129 /* Set the return value for the child */
130
Helge Deller79793452007-01-28 16:43:32 +0100131ENTRY(hpux_child_return)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
Helge Deller79793452007-01-28 16:43:32 +0100133 bl,n schedule_tail, %r2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif
135
136 LDREG TASK_PT_GR19-TASK_SZ_ALGN-128(%r30),%r2
137 b fork_return
138 copy %r0,%r28
Helge Deller79793452007-01-28 16:43:32 +0100139ENDPROC(hpux_child_return)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 .import hpux_execve
142
Helge Deller79793452007-01-28 16:43:32 +0100143ENTRY(hpux_execv_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 copy %r0,%r24 /* NULL environment */
145
Helge Deller79793452007-01-28 16:43:32 +0100146ENTRY(hpux_execve_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 ldo TASK_REGS-TASK_SZ_ALGN-64(%r30),%r1 ;! get pt regs
149
150 /*
151 * Do we need to save/restore r3-r18 here?
152 * I don't think so. why would new thread need old
153 * threads registers?
154 */
155
156 /* Store arg0, arg1 and arg2 so that hpux_execve will find them */
157
158 STREG %r26,PT_GR26(%r1)
159 STREG %r25,PT_GR25(%r1)
160 STREG %r24,PT_GR24(%r1)
161
162 STREG %r2,-20(%r30)
163 ldo 64(%r30),%r30
164 bl hpux_execve,%r2
165 copy %r1,%arg0
166
167 ldo -64(%r30),%r30
168 LDREG -20(%r30),%r2
169
170 /* If exec succeeded we need to load the args */
171
172 ldo -1024(%r0),%r1
173 comb,>>= %r28,%r1,exec_error
174 copy %r2,%r19
175 ldo -TASK_SZ_ALGN-64(%r30),%r1 ;! get task ptr
176 LDREG TASK_PT_GR26(%r1),%r26
177 LDREG TASK_PT_GR25(%r1),%r25
178 LDREG TASK_PT_GR24(%r1),%r24
179 LDREG TASK_PT_GR23(%r1),%r23
180 copy %r0,%r2 /* Flag to syscall_exit not to clear args */
181
182exec_error:
183 bv %r0(%r19)
184 nop
Helge Deller79793452007-01-28 16:43:32 +0100185ENDPROC(hpux_execv_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 .import hpux_pipe
188
189 /* HP-UX expects pipefd's returned in r28 & r29 */
190
Helge Deller79793452007-01-28 16:43:32 +0100191ENTRY(hpux_pipe_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 STREG %r2,-20(%r30)
193 ldo 64(%r30),%r30
194 bl hpux_pipe,%r2
195 ldo -56(%r30),%r26 /* pass local array to hpux_pipe */
196
197
198 ldo -1024(%r0),%r1
199 comb,>>= %r28,%r1,pipe_exit /* let syscall exit handle it */
200 LDREG -84(%r30),%r2
201
202 /* if success, load fd's from stack array */
203
204 LDREG -56(%r30),%r28
205 LDREG -52(%r30),%r29
206
207pipe_exit:
208 bv %r0(%r2)
209 ldo -64(%r30),%r30
Helge Deller79793452007-01-28 16:43:32 +0100210ENDPROC(hpux_pipe_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 .import syscall_exit
213
Helge Deller79793452007-01-28 16:43:32 +0100214ENTRY(hpux_syscall_exit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 /*
216 *
217 * HP-UX call return conventions:
218 *
219 * if error:
220 * r22 = 1
221 * r28 = errno value
222 * r29 = secondary return value
223 * else
224 * r22 = 0
225 * r28 = return value
226 * r29 = secondary return value
227 *
228 * For now, we'll just check to see if r28 is < (unsigned long)-1024
229 * (to handle addresses > 2 Gb) and if so set r22 to zero. If not,
230 * we'll complement r28 and set r22 to 1. Wrappers will be
231 * needed for syscalls that care about the secondary return value.
232 * The wrapper may also need a way of avoiding the following code,
233 * but we'll deal with that when it becomes necessary.
234 */
235
236 ldo -1024(%r0),%r1
237 comb,<< %r28,%r1,no_error
238 copy %r0,%r22
239 subi 0,%r28,%r28
240 ldo 1(%r0),%r22
241
242no_error:
Helge Deller79793452007-01-28 16:43:32 +0100243 b,n syscall_exit
244ENDPROC(hpux_syscall_exit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 .import hpux_unimplemented
247
Helge Deller79793452007-01-28 16:43:32 +0100248ENTRY(hpux_unimplemented_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 b hpux_unimplemented
250 STREG %r22,-64(%r30) /* overwrite arg8 with syscall number */
Helge Deller79793452007-01-28 16:43:32 +0100251ENDPROC(hpux_unimplemented_wrapper)