17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7257d1b4Sraf * Common Development and Distribution License (the "License"). 6*7257d1b4Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*7257d1b4Sraf 227c478bd9Sstevel@tonic-gate /* 23*7257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _LIBC_SPARCV9_INC_SYS_H 287c478bd9Sstevel@tonic-gate #define _LIBC_SPARCV9_INC_SYS_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* 337c478bd9Sstevel@tonic-gate * This file defines common code sequences for system calls. Note that 347c478bd9Sstevel@tonic-gate * it is assumed that __cerror is within the short branch distance from 357c478bd9Sstevel@tonic-gate * all the traps (so that a simple bcs can follow the trap, rather than 367c478bd9Sstevel@tonic-gate * a position independent code sequence.) 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <sys/asm_linkage.h> 407c478bd9Sstevel@tonic-gate #include <sys/syscall.h> 417c478bd9Sstevel@tonic-gate #include <sys/errno.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * While it's tempting to imagine we could use 'rd %pc' here, 457c478bd9Sstevel@tonic-gate * in fact it's a rather slow operation that consumes many 467c478bd9Sstevel@tonic-gate * cycles, so we use the usual side-effect of 'call' instead. 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate #define PIC_SETUP(r) \ 497c478bd9Sstevel@tonic-gate mov %o7, %g1; \ 507c478bd9Sstevel@tonic-gate 9: call 8f; \ 517c478bd9Sstevel@tonic-gate sethi %hi(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r; \ 527c478bd9Sstevel@tonic-gate 8: or %r, %lo(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r; \ 537c478bd9Sstevel@tonic-gate add %r, %o7, %r; \ 547c478bd9Sstevel@tonic-gate mov %g1, %o7 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate /* 577c478bd9Sstevel@tonic-gate * Trap number for system calls 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate #define SYSCALL_TRAPNUM 64 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* 627c478bd9Sstevel@tonic-gate * Define the external symbol __cerror for all files. 637c478bd9Sstevel@tonic-gate */ 647c478bd9Sstevel@tonic-gate .global __cerror 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * __SYSTRAP provides the basic trap sequence. It assumes that an entry 687c478bd9Sstevel@tonic-gate * of the form SYS_name exists (probably from sys/syscall.h). 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate #define __SYSTRAP(name) \ 717c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 727c478bd9Sstevel@tonic-gate mov SYS_/**/name, %g1; \ 737c478bd9Sstevel@tonic-gate ta SYSCALL_TRAPNUM 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #define SYSTRAP_RVAL1(name) __SYSTRAP(name) 767c478bd9Sstevel@tonic-gate #define SYSTRAP_RVAL2(name) __SYSTRAP(name) 777c478bd9Sstevel@tonic-gate #define SYSTRAP_2RVALS(name) __SYSTRAP(name) 787c478bd9Sstevel@tonic-gate #define SYSTRAP_64RVAL(name) __SYSTRAP(name) 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * SYSFASTTRAP provides the fast system call trap sequence. It assumes 827c478bd9Sstevel@tonic-gate * that an entry of the form ST_name exists (probably from sys/trap.h). 837c478bd9Sstevel@tonic-gate */ 847c478bd9Sstevel@tonic-gate #define SYSFASTTRAP(name) \ 857c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 867c478bd9Sstevel@tonic-gate ta ST_/**/name 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* 897c478bd9Sstevel@tonic-gate * SYSCERROR provides the sequence to branch to __cerror if an error is 907c478bd9Sstevel@tonic-gate * indicated by the carry-bit being set upon return from a trap. 917c478bd9Sstevel@tonic-gate */ 927c478bd9Sstevel@tonic-gate #define SYSCERROR \ 937c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 947c478bd9Sstevel@tonic-gate bcs __cerror; \ 957c478bd9Sstevel@tonic-gate nop 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate /* 987c478bd9Sstevel@tonic-gate * SYSLWPERR provides the sequence to return 0 on a successful trap 997c478bd9Sstevel@tonic-gate * and the error code if unsuccessful. 1007c478bd9Sstevel@tonic-gate * Error is indicated by the carry-bit being set upon return from a trap. 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate #define SYSLWPERR \ 1037c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 1047c478bd9Sstevel@tonic-gate bcc,a,pt %icc, 1f; \ 1057c478bd9Sstevel@tonic-gate clr %o0; \ 1067c478bd9Sstevel@tonic-gate cmp %o0, ERESTART; \ 1077c478bd9Sstevel@tonic-gate move %icc, EINTR, %o0; \ 1087c478bd9Sstevel@tonic-gate 1: 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #define SAVE_OFFSET (STACK_BIAS + 8 * 16) 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * SYSREENTRY provides the entry sequence for restartable system calls. 1147c478bd9Sstevel@tonic-gate */ 1157c478bd9Sstevel@tonic-gate #define SYSREENTRY(name) \ 1167c478bd9Sstevel@tonic-gate ENTRY(name); \ 1177c478bd9Sstevel@tonic-gate stn %o0, [%sp + SAVE_OFFSET]; \ 1187c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 1197c478bd9Sstevel@tonic-gate .restart_/**/name: 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate /* 1227c478bd9Sstevel@tonic-gate * SYSRESTART provides the error handling sequence for restartable 1237c478bd9Sstevel@tonic-gate * system calls. 1247c478bd9Sstevel@tonic-gate */ 1257c478bd9Sstevel@tonic-gate #define SYSRESTART(name) \ 1267c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 1277c478bd9Sstevel@tonic-gate bcc,pt %icc, 1f; \ 1287c478bd9Sstevel@tonic-gate cmp %o0, ERESTART; \ 1297c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 1307c478bd9Sstevel@tonic-gate be,a,pn %icc, name; \ 1317c478bd9Sstevel@tonic-gate ldn [%sp + SAVE_OFFSET], %o0; \ 1327c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 1337c478bd9Sstevel@tonic-gate ba,a __cerror; \ 1347c478bd9Sstevel@tonic-gate 1: 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * SYSINTR_RESTART provides the error handling sequence for restartable 1387c478bd9Sstevel@tonic-gate * system calls in case of EINTR or ERESTART. 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate #define SYSINTR_RESTART(name) \ 1417c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 1427c478bd9Sstevel@tonic-gate bcc,a,pt %icc, 1f; \ 1437c478bd9Sstevel@tonic-gate clr %o0; \ 1447c478bd9Sstevel@tonic-gate cmp %o0, ERESTART; \ 1457c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 1467c478bd9Sstevel@tonic-gate be,a,pn %icc, name; \ 1477c478bd9Sstevel@tonic-gate ldn [%sp + SAVE_OFFSET], %o0; \ 1487c478bd9Sstevel@tonic-gate cmp %o0, EINTR; \ 1497c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 1507c478bd9Sstevel@tonic-gate be,a,pn %icc, name; \ 1517c478bd9Sstevel@tonic-gate ldn [%sp + SAVE_OFFSET], %o0; \ 1527c478bd9Sstevel@tonic-gate 1: 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate /* 1557c478bd9Sstevel@tonic-gate * SYSCALL provides the standard (i.e.: most common) system call sequence. 1567c478bd9Sstevel@tonic-gate */ 1577c478bd9Sstevel@tonic-gate #define SYSCALL(name) \ 1587c478bd9Sstevel@tonic-gate ENTRY(name); \ 1597c478bd9Sstevel@tonic-gate SYSTRAP_2RVALS(name); \ 1607c478bd9Sstevel@tonic-gate SYSCERROR 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate #define SYSCALL_RVAL1(name) \ 1637c478bd9Sstevel@tonic-gate ENTRY(name); \ 1647c478bd9Sstevel@tonic-gate SYSTRAP_RVAL1(name); \ 1657c478bd9Sstevel@tonic-gate SYSCERROR 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate /* 1687c478bd9Sstevel@tonic-gate * SYSCALL_RESTART provides the most common restartable system call sequence. 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate #define SYSCALL_RESTART(name) \ 1717c478bd9Sstevel@tonic-gate SYSREENTRY(name); \ 1727c478bd9Sstevel@tonic-gate SYSTRAP_2RVALS(name); \ 1737c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 1747c478bd9Sstevel@tonic-gate SYSRESTART(.restart_/**/name) 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate #define SYSCALL_RESTART_RVAL1(name) \ 1777c478bd9Sstevel@tonic-gate SYSREENTRY(name); \ 1787c478bd9Sstevel@tonic-gate SYSTRAP_RVAL1(name); \ 1797c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 1807c478bd9Sstevel@tonic-gate SYSRESTART(.restart_/**/name) 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate /* 1837c478bd9Sstevel@tonic-gate * SYSCALL2 provides a common system call sequence when the entry name 1847c478bd9Sstevel@tonic-gate * is different than the trap name. 1857c478bd9Sstevel@tonic-gate */ 1867c478bd9Sstevel@tonic-gate #define SYSCALL2(entryname, trapname) \ 1877c478bd9Sstevel@tonic-gate ENTRY(entryname); \ 1887c478bd9Sstevel@tonic-gate SYSTRAP_2RVALS(trapname); \ 1897c478bd9Sstevel@tonic-gate SYSCERROR 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate #define SYSCALL2_RVAL1(entryname, trapname) \ 1927c478bd9Sstevel@tonic-gate ENTRY(entryname); \ 1937c478bd9Sstevel@tonic-gate SYSTRAP_RVAL1(trapname); \ 1947c478bd9Sstevel@tonic-gate SYSCERROR 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate /* 1977c478bd9Sstevel@tonic-gate * SYSCALL2_RESTART provides a common restartable system call sequence when the 1987c478bd9Sstevel@tonic-gate * entry name is different than the trap name. 1997c478bd9Sstevel@tonic-gate */ 2007c478bd9Sstevel@tonic-gate #define SYSCALL2_RESTART(entryname, trapname) \ 2017c478bd9Sstevel@tonic-gate SYSREENTRY(entryname); \ 2027c478bd9Sstevel@tonic-gate SYSTRAP_2RVALS(trapname); \ 2037c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 2047c478bd9Sstevel@tonic-gate SYSRESTART(.restart_/**/entryname) 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate #define SYSCALL2_RESTART_RVAL1(entryname, trapname) \ 2077c478bd9Sstevel@tonic-gate SYSREENTRY(entryname); \ 2087c478bd9Sstevel@tonic-gate SYSTRAP_RVAL1(trapname); \ 2097c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 2107c478bd9Sstevel@tonic-gate SYSRESTART(.restart_/**/entryname) 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate /* 2137c478bd9Sstevel@tonic-gate * SYSCALL_NOERROR provides the most common system call sequence for those 2147c478bd9Sstevel@tonic-gate * system calls which don't check the error return (carry bit). 2157c478bd9Sstevel@tonic-gate */ 2167c478bd9Sstevel@tonic-gate #define SYSCALL_NOERROR(name) \ 2177c478bd9Sstevel@tonic-gate ENTRY(name); \ 2187c478bd9Sstevel@tonic-gate SYSTRAP_2RVALS(name) 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate #define SYSCALL_NOERROR_RVAL1(name) \ 2217c478bd9Sstevel@tonic-gate ENTRY(name); \ 2227c478bd9Sstevel@tonic-gate SYSTRAP_RVAL1(name) 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* 2257c478bd9Sstevel@tonic-gate * Standard syscall return sequence, return code equal to rval1. 2267c478bd9Sstevel@tonic-gate */ 2277c478bd9Sstevel@tonic-gate #define RET \ 2287c478bd9Sstevel@tonic-gate retl; \ 2297c478bd9Sstevel@tonic-gate nop 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate /* 2327c478bd9Sstevel@tonic-gate * Syscall return sequence, return code equal to rval2. 2337c478bd9Sstevel@tonic-gate */ 2347c478bd9Sstevel@tonic-gate #define RET2 \ 2357c478bd9Sstevel@tonic-gate retl; \ 2367c478bd9Sstevel@tonic-gate mov %o1, %o0 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate /* 2397c478bd9Sstevel@tonic-gate * Syscall return sequence with return code forced to zero. 2407c478bd9Sstevel@tonic-gate */ 2417c478bd9Sstevel@tonic-gate #define RETC \ 2427c478bd9Sstevel@tonic-gate retl; \ 2437c478bd9Sstevel@tonic-gate clr %o0 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate #endif /* _LIBC_SPARCV9_INC_SYS_H */ 246