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