1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _LIBC_SPARC_INC_SYS_H 28 #define _LIBC_SPARC_INC_SYS_H 29 30 /* 31 * This file defines common code sequences for system calls. Note that 32 * it is assumed that __cerror is within the short branch distance from 33 * all the traps (so that a simple bcs can follow the trap, rather than 34 * a position independent code sequence.) Ditto for __cerror64. 35 */ 36 37 #include <sys/asm_linkage.h> 38 #include <sys/syscall.h> 39 #include <sys/errno.h> 40 41 /* 42 * While it's tempting to imagine we could use 'rd %pc' here, 43 * in fact it's a rather slow operation that consumes many 44 * cycles, so we use the usual side-effect of 'call' instead. 45 */ 46 #define PIC_SETUP(r) \ 47 mov %o7, %g1; \ 48 9: call 8f; \ 49 sethi %hi(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r; \ 50 8: or %r, %lo(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r; \ 51 add %r, %o7, %r; \ 52 mov %g1, %o7 53 54 /* 55 * Trap number for system calls 56 */ 57 #define SYSCALL_TRAPNUM 8 58 #define FASTSCALL_TRAPNUM 9 59 60 /* 61 * Define the external symbols __cerror and __cerror64 for all files. 62 */ 63 .global __cerror 64 .global __cerror64 65 66 /* 67 * __SYSTRAP provides the basic trap sequence. It assumes that an entry 68 * of the form SYS_name exists (probably from sys/syscall.h). 69 */ 70 #define __SYSTRAP(name) \ 71 /* CSTYLED */ \ 72 mov SYS_##name, %g1; \ 73 ta SYSCALL_TRAPNUM 74 75 #define SYSTRAP_RVAL1(name) __SYSTRAP(name) 76 #define SYSTRAP_RVAL2(name) __SYSTRAP(name) 77 #define SYSTRAP_2RVALS(name) __SYSTRAP(name) 78 #define SYSTRAP_64RVAL(name) __SYSTRAP(name) 79 80 /* 81 * SYSFASTTRAP provides the fast system call trap sequence. It assumes 82 * that an entry of the form ST_name exists (probably from sys/trap.h). 83 */ 84 #define SYSFASTTRAP(name) \ 85 /* CSTYLED */ \ 86 ta ST_##name 87 88 /* 89 * SYSCERROR provides the sequence to branch to __cerror if an error is 90 * indicated by the carry-bit being set upon return from a trap. 91 */ 92 #define SYSCERROR \ 93 bcs __cerror; \ 94 nop 95 96 /* 97 * SYSCERROR64 provides the sequence to branch to __cerror64 if an error is 98 * indicated by the carry-bit being set upon return from a trap. 99 */ 100 #define SYSCERROR64 \ 101 bcs __cerror64; \ 102 nop 103 104 /* 105 * SYSLWPERR provides the sequence to return 0 on a successful trap 106 * and the error code if unsuccessful. 107 * Error is indicated by the carry-bit being set upon return from a trap. 108 */ 109 #define SYSLWPERR \ 110 /* CSTYLED */ \ 111 bcc,a,pt %icc, 1f; \ 112 clr %o0; \ 113 cmp %o0, ERESTART; \ 114 move %icc, EINTR, %o0; \ 115 1: 116 117 #define SAVE_OFFSET 68 118 119 /* 120 * SYSREENTRY provides the entry sequence for restartable system calls. 121 */ 122 #define SYSREENTRY(name) \ 123 ENTRY(name); \ 124 stn %o0, [%sp + SAVE_OFFSET]; \ 125 /* CSTYLED */ \ 126 .restart_##name: 127 128 /* 129 * SYSRESTART provides the error handling sequence for restartable 130 * system calls. 131 */ 132 #define SYSRESTART(name) \ 133 /* CSTYLED */ \ 134 bcc,pt %icc, 1f; \ 135 cmp %o0, ERESTART; \ 136 /* CSTYLED */ \ 137 be,a,pn %icc, name; \ 138 ldn [%sp + SAVE_OFFSET], %o0; \ 139 /* CSTYLED */ \ 140 ba,a __cerror; \ 141 1: 142 143 /* 144 * SYSINTR_RESTART provides the error handling sequence for restartable 145 * system calls in case of EINTR or ERESTART. 146 */ 147 #define SYSINTR_RESTART(name) \ 148 /* CSTYLED */ \ 149 bcc,a,pt %icc, 1f; \ 150 clr %o0; \ 151 cmp %o0, ERESTART; \ 152 /* CSTYLED */ \ 153 be,a,pn %icc, name; \ 154 ldn [%sp + SAVE_OFFSET], %o0; \ 155 cmp %o0, EINTR; \ 156 /* CSTYLED */ \ 157 be,a,pn %icc, name; \ 158 ldn [%sp + SAVE_OFFSET], %o0; \ 159 1: 160 161 /* 162 * SYSCALL provides the standard (i.e.: most common) system call sequence. 163 */ 164 #define SYSCALL(name) \ 165 ENTRY(name); \ 166 SYSTRAP_2RVALS(name); \ 167 SYSCERROR 168 169 #define SYSCALL_RVAL1(name) \ 170 ENTRY(name); \ 171 SYSTRAP_RVAL1(name); \ 172 SYSCERROR 173 174 /* 175 * SYSCALL64 provides the standard (i.e.: most common) system call sequence 176 * for system calls that return 64-bit values. 177 */ 178 #define SYSCALL64(name) \ 179 ENTRY(name); \ 180 SYSTRAP_64RVAL(name); \ 181 SYSCERROR64 182 183 /* 184 * SYSCALL_RESTART provides the most common restartable system call sequence. 185 */ 186 #define SYSCALL_RESTART(name) \ 187 SYSREENTRY(name); \ 188 SYSTRAP_2RVALS(name); \ 189 /* CSTYLED */ \ 190 SYSRESTART(.restart_##name) 191 192 #define SYSCALL_RESTART_RVAL1(name) \ 193 SYSREENTRY(name); \ 194 SYSTRAP_RVAL1(name); \ 195 /* CSTYLED */ \ 196 SYSRESTART(.restart_##name) 197 198 /* 199 * SYSCALL2 provides a common system call sequence when the entry name 200 * is different than the trap name. 201 */ 202 #define SYSCALL2(entryname, trapname) \ 203 ENTRY(entryname); \ 204 SYSTRAP_2RVALS(trapname); \ 205 SYSCERROR 206 207 #define SYSCALL2_RVAL1(entryname, trapname) \ 208 ENTRY(entryname); \ 209 SYSTRAP_RVAL1(trapname); \ 210 SYSCERROR 211 212 /* 213 * SYSCALL2_RESTART provides a common restartable system call sequence when the 214 * entry name is different than the trap name. 215 */ 216 #define SYSCALL2_RESTART(entryname, trapname) \ 217 SYSREENTRY(entryname); \ 218 SYSTRAP_2RVALS(trapname); \ 219 /* CSTYLED */ \ 220 SYSRESTART(.restart_##entryname) 221 222 #define SYSCALL2_RESTART_RVAL1(entryname, trapname) \ 223 SYSREENTRY(entryname); \ 224 SYSTRAP_RVAL1(trapname); \ 225 /* CSTYLED */ \ 226 SYSRESTART(.restart_##entryname) 227 228 /* 229 * SYSCALL_NOERROR provides the most common system call sequence for those 230 * system calls which don't check the error return (carry bit). 231 */ 232 #define SYSCALL_NOERROR(name) \ 233 ENTRY(name); \ 234 SYSTRAP_2RVALS(name) 235 236 #define SYSCALL_NOERROR_RVAL1(name) \ 237 ENTRY(name); \ 238 SYSTRAP_RVAL1(name) 239 240 /* 241 * Standard syscall return sequence, return code equal to rval1. 242 */ 243 #define RET \ 244 retl; \ 245 nop 246 247 /* 248 * Syscall return sequence, return code equal to rval2. 249 */ 250 #define RET2 \ 251 retl; \ 252 mov %o1, %o0 253 254 /* 255 * Syscall return sequence with return code forced to zero. 256 */ 257 #define RETC \ 258 retl; \ 259 clr %o0 260 261 #endif /* _LIBC_SPARC_INC_SYS_H */ 262