]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc64 / sysdep.h
CommitLineData
a334319f
UD
1/* Copyright (C) 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
2 Free Software Foundation, Inc.
cfc91acd
RM
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
1e2f8718 19
cfc91acd
RM
20/* Alan Modra <amodra@bigpond.net.au> rewrote the INLINE_SYSCALL macro */
21
22#ifndef _LINUX_POWERPC_SYSDEP_H
23#define _LINUX_POWERPC_SYSDEP_H 1
24
25#include <sysdeps/unix/powerpc/sysdep.h>
26
27/* Define __set_errno() for INLINE_SYSCALL macro below. */
28#ifndef __ASSEMBLER__
29#include <errno.h>
30#endif
31
5bfed16d
UD
32/* Some systen calls got renamed over time, but retained the same semantics.
33 Handle them here so they can be catched by both C and assembler stubs in
34 glibc. */
35
36#ifdef __NR_pread64
37# ifdef __NR_pread
38# error "__NR_pread and __NR_pread64 both defined???"
39# endif
40# define __NR_pread __NR_pread64
41#endif
42
43#ifdef __NR_pwrite64
44# ifdef __NR_pwrite
45# error "__NR_pwrite and __NR_pwrite64 both defined???"
46# endif
47# define __NR_pwrite __NR_pwrite64
48#endif
49
cfc91acd
RM
50/* For Linux we can use the system call table in the header file
51 /usr/include/asm/unistd.h
52 of the kernel. But these symbols do not follow the SYS_* syntax
53 so we have to redefine the `SYS_ify' macro here. */
54#undef SYS_ify
55#ifdef __STDC__
56# define SYS_ify(syscall_name) __NR_##syscall_name
57#else
58# define SYS_ify(syscall_name) __NR_/**/syscall_name
59#endif
60
61#ifdef __ASSEMBLER__
62
63/* This seems to always be the case on PPC. */
a334319f 64#define ALIGNARG(log2) log2
cfc91acd 65/* For ELF we need the `.type' directive to make shared libs work right. */
a334319f
UD
66#define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
67#define ASM_SIZE_DIRECTIVE(name) .size name,.-name
cfc91acd 68
a334319f 69#endif /* __ASSEMBLER__ */
cfc91acd
RM
70
71#undef INLINE_SYSCALL
cfc91acd 72
cfc91acd
RM
73/* This version is for kernels that implement system calls that
74 behave like function calls as far as register saving. */
1e2f8718
UD
75#define INLINE_SYSCALL(name, nr, args...) \
76 ({ \
574b892e 77 INTERNAL_SYSCALL_DECL (sc_err); \
c67a469f 78 long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); \
574b892e
UD
79 if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
80 { \
81 __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
82 sc_ret = -1L; \
83 } \
84 sc_ret; \
cfc91acd
RM
85 })
86
aff4519d
UD
87/* Define a macro which expands inline into the wrapper code for a system
88 call. This use is for internal calls that do not need to handle errors
89 normally. It will never touch errno. This returns just what the kernel
90 gave back in the non-error (CR0.SO cleared) case, otherwise (CR0.SO set)
91 the negation of the return value in the kernel gets reverted. */
92
1e2f8718 93#undef INTERNAL_SYSCALL
2edb61e3 94#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
aff4519d 95 ({ \
c67a469f
UD
96 register long int r0 __asm__ ("r0"); \
97 register long int r3 __asm__ ("r3"); \
98 register long int r4 __asm__ ("r4"); \
99 register long int r5 __asm__ ("r5"); \
100 register long int r6 __asm__ ("r6"); \
101 register long int r7 __asm__ ("r7"); \
102 register long int r8 __asm__ ("r8"); \
a334319f 103 LOADARGS_##nr(name, args); \
aff4519d
UD
104 __asm__ __volatile__ \
105 ("sc\n\t" \
574b892e 106 "mfcr %0\n\t" \
aff4519d
UD
107 "0:" \
108 : "=&r" (r0), \
1e2f8718
UD
109 "=&r" (r3), "=&r" (r4), "=&r" (r5), \
110 "=&r" (r6), "=&r" (r7), "=&r" (r8) \
aff4519d 111 : ASM_INPUT_##nr \
1e2f8718 112 : "r9", "r10", "r11", "r12", \
aff4519d 113 "cr0", "ctr", "memory"); \
574b892e
UD
114 err = r0; \
115 (int) r3; \
aff4519d 116 })
2edb61e3 117#define INTERNAL_SYSCALL(name, err, nr, args...) \
a334319f 118 INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
574b892e 119
1e2f8718 120#undef INTERNAL_SYSCALL_DECL
c67a469f 121#define INTERNAL_SYSCALL_DECL(err) long int err
1e2f8718
UD
122
123#undef INTERNAL_SYSCALL_ERROR_P
124#define INTERNAL_SYSCALL_ERROR_P(val, err) \
a334319f 125 (__builtin_expect (err & (1 << 28), 0))
574b892e 126
1e2f8718
UD
127#undef INTERNAL_SYSCALL_ERRNO
128#define INTERNAL_SYSCALL_ERRNO(val, err) (val)
aff4519d
UD
129
130#define LOADARGS_0(name, dummy) \
2edb61e3 131 r0 = name
c67a469f
UD
132#define LOADARGS_1(name, __arg1) \
133 long int arg1 = (long int) (__arg1); \
aff4519d 134 LOADARGS_0(name, 0); \
2edb61e3 135 extern void __illegally_sized_syscall_arg1 (void); \
c67a469f 136 if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 8) \
2edb61e3 137 __illegally_sized_syscall_arg1 (); \
c67a469f
UD
138 r3 = arg1
139#define LOADARGS_2(name, __arg1, __arg2) \
140 long int arg2 = (long int) (__arg2); \
141 LOADARGS_1(name, __arg1); \
2edb61e3 142 extern void __illegally_sized_syscall_arg2 (void); \
c67a469f 143 if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 8) \
2edb61e3 144 __illegally_sized_syscall_arg2 (); \
c67a469f
UD
145 r4 = arg2
146#define LOADARGS_3(name, __arg1, __arg2, __arg3) \
147 long int arg3 = (long int) (__arg3); \
148 LOADARGS_2(name, __arg1, __arg2); \
2edb61e3 149 extern void __illegally_sized_syscall_arg3 (void); \
c67a469f 150 if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 8) \
2edb61e3 151 __illegally_sized_syscall_arg3 (); \
c67a469f
UD
152 r5 = arg3
153#define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \
154 long int arg4 = (long int) (__arg4); \
155 LOADARGS_3(name, __arg1, __arg2, __arg3); \
2edb61e3 156 extern void __illegally_sized_syscall_arg4 (void); \
c67a469f 157 if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 8) \
2edb61e3 158 __illegally_sized_syscall_arg4 (); \
c67a469f
UD
159 r6 = arg4
160#define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
161 long int arg5 = (long int) (__arg5); \
162 LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
2edb61e3 163 extern void __illegally_sized_syscall_arg5 (void); \
c67a469f 164 if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 8) \
2edb61e3 165 __illegally_sized_syscall_arg5 (); \
c67a469f
UD
166 r7 = arg5
167#define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
168 long int arg6 = (long int) (__arg6); \
169 LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
2edb61e3 170 extern void __illegally_sized_syscall_arg6 (void); \
c67a469f 171 if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 8) \
2edb61e3 172 __illegally_sized_syscall_arg6 (); \
c67a469f 173 r8 = arg6
cfc91acd
RM
174
175#define ASM_INPUT_0 "0" (r0)
176#define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
177#define ASM_INPUT_2 ASM_INPUT_1, "2" (r4)
178#define ASM_INPUT_3 ASM_INPUT_2, "3" (r5)
179#define ASM_INPUT_4 ASM_INPUT_3, "4" (r6)
180#define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
181#define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
182
cfc91acd 183#endif /* linux/powerpc/powerpc64/sysdep.h */