10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*6812Sraf * Common Development and Distribution License (the "License"). 6*6812Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*6812Sraf 220Sstevel@tonic-gate /* 23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _LIBC_SPARCV9_INC_SYS_H 280Sstevel@tonic-gate #define _LIBC_SPARCV9_INC_SYS_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate /* 330Sstevel@tonic-gate * This file defines common code sequences for system calls. Note that 340Sstevel@tonic-gate * it is assumed that __cerror is within the short branch distance from 350Sstevel@tonic-gate * all the traps (so that a simple bcs can follow the trap, rather than 360Sstevel@tonic-gate * a position independent code sequence.) 370Sstevel@tonic-gate */ 380Sstevel@tonic-gate 390Sstevel@tonic-gate #include <sys/asm_linkage.h> 400Sstevel@tonic-gate #include <sys/syscall.h> 410Sstevel@tonic-gate #include <sys/errno.h> 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * While it's tempting to imagine we could use 'rd %pc' here, 450Sstevel@tonic-gate * in fact it's a rather slow operation that consumes many 460Sstevel@tonic-gate * cycles, so we use the usual side-effect of 'call' instead. 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate #define PIC_SETUP(r) \ 490Sstevel@tonic-gate mov %o7, %g1; \ 500Sstevel@tonic-gate 9: call 8f; \ 510Sstevel@tonic-gate sethi %hi(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r; \ 520Sstevel@tonic-gate 8: or %r, %lo(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r; \ 530Sstevel@tonic-gate add %r, %o7, %r; \ 540Sstevel@tonic-gate mov %g1, %o7 550Sstevel@tonic-gate 560Sstevel@tonic-gate /* 570Sstevel@tonic-gate * Trap number for system calls 580Sstevel@tonic-gate */ 590Sstevel@tonic-gate #define SYSCALL_TRAPNUM 64 600Sstevel@tonic-gate 610Sstevel@tonic-gate /* 620Sstevel@tonic-gate * Define the external symbol __cerror for all files. 630Sstevel@tonic-gate */ 640Sstevel@tonic-gate .global __cerror 650Sstevel@tonic-gate 660Sstevel@tonic-gate /* 670Sstevel@tonic-gate * __SYSTRAP provides the basic trap sequence. It assumes that an entry 680Sstevel@tonic-gate * of the form SYS_name exists (probably from sys/syscall.h). 690Sstevel@tonic-gate */ 700Sstevel@tonic-gate #define __SYSTRAP(name) \ 710Sstevel@tonic-gate /* CSTYLED */ \ 720Sstevel@tonic-gate mov SYS_/**/name, %g1; \ 730Sstevel@tonic-gate ta SYSCALL_TRAPNUM 740Sstevel@tonic-gate 750Sstevel@tonic-gate #define SYSTRAP_RVAL1(name) __SYSTRAP(name) 760Sstevel@tonic-gate #define SYSTRAP_RVAL2(name) __SYSTRAP(name) 770Sstevel@tonic-gate #define SYSTRAP_2RVALS(name) __SYSTRAP(name) 780Sstevel@tonic-gate #define SYSTRAP_64RVAL(name) __SYSTRAP(name) 790Sstevel@tonic-gate 800Sstevel@tonic-gate /* 810Sstevel@tonic-gate * SYSFASTTRAP provides the fast system call trap sequence. It assumes 820Sstevel@tonic-gate * that an entry of the form ST_name exists (probably from sys/trap.h). 830Sstevel@tonic-gate */ 840Sstevel@tonic-gate #define SYSFASTTRAP(name) \ 850Sstevel@tonic-gate /* CSTYLED */ \ 860Sstevel@tonic-gate ta ST_/**/name 870Sstevel@tonic-gate 880Sstevel@tonic-gate /* 890Sstevel@tonic-gate * SYSCERROR provides the sequence to branch to __cerror if an error is 900Sstevel@tonic-gate * indicated by the carry-bit being set upon return from a trap. 910Sstevel@tonic-gate */ 920Sstevel@tonic-gate #define SYSCERROR \ 930Sstevel@tonic-gate /* CSTYLED */ \ 940Sstevel@tonic-gate bcs __cerror; \ 950Sstevel@tonic-gate nop 960Sstevel@tonic-gate 970Sstevel@tonic-gate /* 980Sstevel@tonic-gate * SYSLWPERR provides the sequence to return 0 on a successful trap 990Sstevel@tonic-gate * and the error code if unsuccessful. 1000Sstevel@tonic-gate * Error is indicated by the carry-bit being set upon return from a trap. 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate #define SYSLWPERR \ 1030Sstevel@tonic-gate /* CSTYLED */ \ 1040Sstevel@tonic-gate bcc,a,pt %icc, 1f; \ 1050Sstevel@tonic-gate clr %o0; \ 1060Sstevel@tonic-gate cmp %o0, ERESTART; \ 1070Sstevel@tonic-gate move %icc, EINTR, %o0; \ 1080Sstevel@tonic-gate 1: 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate #define SAVE_OFFSET (STACK_BIAS + 8 * 16) 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate /* 1130Sstevel@tonic-gate * SYSREENTRY provides the entry sequence for restartable system calls. 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate #define SYSREENTRY(name) \ 1160Sstevel@tonic-gate ENTRY(name); \ 1170Sstevel@tonic-gate stn %o0, [%sp + SAVE_OFFSET]; \ 1180Sstevel@tonic-gate /* CSTYLED */ \ 1190Sstevel@tonic-gate .restart_/**/name: 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate /* 1220Sstevel@tonic-gate * SYSRESTART provides the error handling sequence for restartable 1230Sstevel@tonic-gate * system calls. 1240Sstevel@tonic-gate */ 1250Sstevel@tonic-gate #define SYSRESTART(name) \ 1260Sstevel@tonic-gate /* CSTYLED */ \ 1270Sstevel@tonic-gate bcc,pt %icc, 1f; \ 1280Sstevel@tonic-gate cmp %o0, ERESTART; \ 1290Sstevel@tonic-gate /* CSTYLED */ \ 1300Sstevel@tonic-gate be,a,pn %icc, name; \ 1310Sstevel@tonic-gate ldn [%sp + SAVE_OFFSET], %o0; \ 1320Sstevel@tonic-gate /* CSTYLED */ \ 1330Sstevel@tonic-gate ba,a __cerror; \ 1340Sstevel@tonic-gate 1: 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* 1370Sstevel@tonic-gate * SYSINTR_RESTART provides the error handling sequence for restartable 1380Sstevel@tonic-gate * system calls in case of EINTR or ERESTART. 1390Sstevel@tonic-gate */ 1400Sstevel@tonic-gate #define SYSINTR_RESTART(name) \ 1410Sstevel@tonic-gate /* CSTYLED */ \ 1420Sstevel@tonic-gate bcc,a,pt %icc, 1f; \ 1430Sstevel@tonic-gate clr %o0; \ 1440Sstevel@tonic-gate cmp %o0, ERESTART; \ 1450Sstevel@tonic-gate /* CSTYLED */ \ 1460Sstevel@tonic-gate be,a,pn %icc, name; \ 1470Sstevel@tonic-gate ldn [%sp + SAVE_OFFSET], %o0; \ 1480Sstevel@tonic-gate cmp %o0, EINTR; \ 1490Sstevel@tonic-gate /* CSTYLED */ \ 1500Sstevel@tonic-gate be,a,pn %icc, name; \ 1510Sstevel@tonic-gate ldn [%sp + SAVE_OFFSET], %o0; \ 1520Sstevel@tonic-gate 1: 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate /* 1550Sstevel@tonic-gate * SYSCALL provides the standard (i.e.: most common) system call sequence. 1560Sstevel@tonic-gate */ 1570Sstevel@tonic-gate #define SYSCALL(name) \ 1580Sstevel@tonic-gate ENTRY(name); \ 1590Sstevel@tonic-gate SYSTRAP_2RVALS(name); \ 1600Sstevel@tonic-gate SYSCERROR 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate #define SYSCALL_RVAL1(name) \ 1630Sstevel@tonic-gate ENTRY(name); \ 1640Sstevel@tonic-gate SYSTRAP_RVAL1(name); \ 1650Sstevel@tonic-gate SYSCERROR 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate /* 1680Sstevel@tonic-gate * SYSCALL_RESTART provides the most common restartable system call sequence. 1690Sstevel@tonic-gate */ 1700Sstevel@tonic-gate #define SYSCALL_RESTART(name) \ 1710Sstevel@tonic-gate SYSREENTRY(name); \ 1720Sstevel@tonic-gate SYSTRAP_2RVALS(name); \ 1730Sstevel@tonic-gate /* CSTYLED */ \ 1740Sstevel@tonic-gate SYSRESTART(.restart_/**/name) 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate #define SYSCALL_RESTART_RVAL1(name) \ 1770Sstevel@tonic-gate SYSREENTRY(name); \ 1780Sstevel@tonic-gate SYSTRAP_RVAL1(name); \ 1790Sstevel@tonic-gate /* CSTYLED */ \ 1800Sstevel@tonic-gate SYSRESTART(.restart_/**/name) 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate /* 1830Sstevel@tonic-gate * SYSCALL2 provides a common system call sequence when the entry name 1840Sstevel@tonic-gate * is different than the trap name. 1850Sstevel@tonic-gate */ 1860Sstevel@tonic-gate #define SYSCALL2(entryname, trapname) \ 1870Sstevel@tonic-gate ENTRY(entryname); \ 1880Sstevel@tonic-gate SYSTRAP_2RVALS(trapname); \ 1890Sstevel@tonic-gate SYSCERROR 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate #define SYSCALL2_RVAL1(entryname, trapname) \ 1920Sstevel@tonic-gate ENTRY(entryname); \ 1930Sstevel@tonic-gate SYSTRAP_RVAL1(trapname); \ 1940Sstevel@tonic-gate SYSCERROR 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate /* 1970Sstevel@tonic-gate * SYSCALL2_RESTART provides a common restartable system call sequence when the 1980Sstevel@tonic-gate * entry name is different than the trap name. 1990Sstevel@tonic-gate */ 2000Sstevel@tonic-gate #define SYSCALL2_RESTART(entryname, trapname) \ 2010Sstevel@tonic-gate SYSREENTRY(entryname); \ 2020Sstevel@tonic-gate SYSTRAP_2RVALS(trapname); \ 2030Sstevel@tonic-gate /* CSTYLED */ \ 2040Sstevel@tonic-gate SYSRESTART(.restart_/**/entryname) 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate #define SYSCALL2_RESTART_RVAL1(entryname, trapname) \ 2070Sstevel@tonic-gate SYSREENTRY(entryname); \ 2080Sstevel@tonic-gate SYSTRAP_RVAL1(trapname); \ 2090Sstevel@tonic-gate /* CSTYLED */ \ 2100Sstevel@tonic-gate SYSRESTART(.restart_/**/entryname) 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate /* 2130Sstevel@tonic-gate * SYSCALL_NOERROR provides the most common system call sequence for those 2140Sstevel@tonic-gate * system calls which don't check the error return (carry bit). 2150Sstevel@tonic-gate */ 2160Sstevel@tonic-gate #define SYSCALL_NOERROR(name) \ 2170Sstevel@tonic-gate ENTRY(name); \ 2180Sstevel@tonic-gate SYSTRAP_2RVALS(name) 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate #define SYSCALL_NOERROR_RVAL1(name) \ 2210Sstevel@tonic-gate ENTRY(name); \ 2220Sstevel@tonic-gate SYSTRAP_RVAL1(name) 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate /* 2250Sstevel@tonic-gate * Standard syscall return sequence, return code equal to rval1. 2260Sstevel@tonic-gate */ 2270Sstevel@tonic-gate #define RET \ 2280Sstevel@tonic-gate retl; \ 2290Sstevel@tonic-gate nop 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate /* 2320Sstevel@tonic-gate * Syscall return sequence, return code equal to rval2. 2330Sstevel@tonic-gate */ 2340Sstevel@tonic-gate #define RET2 \ 2350Sstevel@tonic-gate retl; \ 2360Sstevel@tonic-gate mov %o1, %o0 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate /* 2390Sstevel@tonic-gate * Syscall return sequence with return code forced to zero. 2400Sstevel@tonic-gate */ 2410Sstevel@tonic-gate #define RETC \ 2420Sstevel@tonic-gate retl; \ 2430Sstevel@tonic-gate clr %o0 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate #endif /* _LIBC_SPARCV9_INC_SYS_H */ 246