-/* $OpenBSD: SYS.h,v 1.15 2023/12/11 22:24:16 kettenis Exp $ */
+/* $OpenBSD: SYS.h,v 1.16 2024/03/27 20:03:29 miod Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
#define SYSENTRY_HIDDEN(x) \
ENTRY(_thread_sys_ ## x)
-#define __END_HIDDEN(x) \
- SET_ENTRY_SIZE(_thread_sys_ ## x); \
- _HIDDEN_FALIAS(x,_thread_sys_ ## x); \
- SET_ENTRY_SIZE(_HIDDEN(x))
-#define __END(x) \
- __END_HIDDEN(x); SET_ENTRY_SIZE(x)
-
#define PINSYSCALL(sysno, label) \
.pushsection .openbsd.syscalls,"",@progbits; \
.p2align 2; \
#ifdef __ASSEMBLER__
/*
* If the system call number fits in a 8-bit signed value (i.e. fits in 7 bits),
- * then we can use the #imm8 addressing mode.
+ * then we can use the #imm8 addressing mode. Otherwise, we'll load the number
+ * from memory at the end of the system call wrapper.
*/
.macro systrap num
mov.l 903f, r0
97: trapa #0x80
PINSYSCALL(\num, 97b)
- bra 904f
- nop
+.endif
+.endm
+
+.macro systrap_data num
+.iflt \num - 128
+.else
+ .text
.align 2
903: .long \num
- 904:
.endif
.endm
+
+.macro syscall_error num
+.ifeq \num - SYS_lseek
+ mov #-1, r1
+.endif
+ rts
+ mov #-1, r0
+.endm
+
#endif
#define SYSTRAP(x) \
SYSENTRY_HIDDEN(x); \
SYSTRAP(y)
-#define SET_ERRNO_AND_RETURN \
+#define SET_ERRNO_AND_RETURN(y) \
stc gbr,r1; \
mov #TCB_OFFSET_ERRNO_NEG,r2; \
sub r2,r1; \
mov.l r0,@r1; \
- mov #-1, r1; /* for lseek */ \
- rts; \
- mov #-1, r0
+ syscall_error SYS_ ## y
#define _SYSCALL(x,y) \
.text; \
- 911: SET_ERRNO_AND_RETURN; \
+ 911: SET_ERRNO_AND_RETURN(y); \
_SYSCALL_NOERROR(x,y); \
bf 911b
#define _SYSCALL_HIDDEN(x,y) \
.text; \
- 911: SET_ERRNO_AND_RETURN; \
+ 911: SET_ERRNO_AND_RETURN(y); \
_SYSCALL_HIDDEN_NOERROR(x,y); \
bf 911b
+#define __END_HIDDEN(x,y) \
+ systrap_data SYS_ ## y; \
+ SET_ENTRY_SIZE(_thread_sys_ ## x); \
+ _HIDDEN_FALIAS(x,_thread_sys_ ## x); \
+ SET_ENTRY_SIZE(_HIDDEN(x))
+#define __END(x,y) \
+ __END_HIDDEN(x,y); SET_ENTRY_SIZE(x)
+
#define SYSCALL_NOERROR(x) \
_SYSCALL_NOERROR(x,x)
_SYSCALL_NOERROR(x,y); \
rts; \
nop; \
- __END(x)
+ __END(x,y)
#define PSEUDO(x,y) \
_SYSCALL(x,y); \
rts; \
nop; \
- __END(x)
+ __END(x,y)
#define PSEUDO_HIDDEN(x,y) \
_SYSCALL_HIDDEN(x,y); \
rts; \
nop; \
- __END_HIDDEN(x)
+ __END_HIDDEN(x,y)
#define RSYSCALL_NOERROR(x) PSEUDO_NOERROR(x,x)
#define RSYSCALL(x) PSEUDO(x,x)
#define RSYSCALL_HIDDEN(x) PSEUDO_HIDDEN(x,x)
-#define SYSCALL_END(x) __END(x)
-#define SYSCALL_END_HIDDEN(x) __END_HIDDEN(x)
+#define SYSCALL_END(x) __END(x,x)
+#define SYSCALL_END_HIDDEN(x) __END_HIDDEN(x,x)
-/* $OpenBSD: brk.S,v 1.9 2023/12/10 16:45:52 deraadt Exp $ */
+/* $OpenBSD: brk.S,v 1.10 2024/03/27 20:03:29 miod Exp $ */
/* $NetBSD: brk.S,v 1.10 2006/01/06 03:58:31 uwe Exp $ */
/*-
bf 1f
mov r0, r4
1:
-#if SYS_break >= 128
- mov.l LSYS_break, r0
-#else
- mov #SYS_break, r0
-#endif
-99: trapa #0x80
- PINSYSCALL(SYS_break, 99b)
+ systrap SYS_break
bf 2f
#ifdef __PIC__
mov.l Lcurbrk, r0
rts
mov.l r4, @r1
2:
- SET_ERRNO_AND_RETURN
+ SET_ERRNO_AND_RETURN(break)
.align 2
-#if SYS_break >= 128
-LSYS_break: .long SYS_break
-#endif
+ systrap_data SYS_break
#ifdef __PIC__
L_GOT: .long _GLOBAL_OFFSET_TABLE_
Lminbrk: .long __minbrk@GOT
-/* $OpenBSD: sbrk.S,v 1.9 2023/12/10 16:45:52 deraadt Exp $ */
+/* $OpenBSD: sbrk.S,v 1.10 2024/03/27 20:03:29 miod Exp $ */
/* $NetBSD: sbrk.S,v 1.9 2006/01/06 03:58:31 uwe Exp $ */
/*-
#endif
mov.l @r0, r0
add r0, r4
-#if SYS_break >= 128
- mov.l LSYS_break, r0
-#else
- mov #SYS_break, r0
-#endif
-99: trapa #0x80
- PINSYSCALL(SYS_break, 99b)
+ systrap SYS_break
bf 1f
#ifdef __PIC__
mov.l Lcurbrk, r0
rts
mov.l r2, @r1
1:
- SET_ERRNO_AND_RETURN
+ SET_ERRNO_AND_RETURN(break)
.align 2
-#if SYS_break >= 128
-LSYS_break: .long SYS_break
-#endif
+ systrap_data SYS_break
#ifdef __PIC__
L_GOT: .long _GLOBAL_OFFSET_TABLE_
Lcurbrk: .long __curbrk@GOT
-/* $OpenBSD: sigprocmask.S,v 1.7 2023/12/10 16:45:52 deraadt Exp $ */
+/* $OpenBSD: sigprocmask.S,v 1.8 2024/03/27 20:03:29 miod Exp $ */
/* $NetBSD: sigprocmask.S,v 1.6 2003/08/07 16:42:21 agc Exp $ */
/*-
1: mov.l @r2, r2 /* fetch indirect ... */
mov r2, r5 /* to new mask arg */
2:
-#if SYS_sigprocmask >= 128
- mov.l LSYS_sigprocmask, r0
-#else
- mov #SYS_sigprocmask, r0
-#endif
-99: trapa #0x80
- PINSYSCALL(SYS_sigprocmask, 99b)
+ systrap SYS_sigprocmask
bf 4f
mov r6, r2 /* fetch old mask requested */
tst r2, r2 /* test if old mask requested */
rts
nop
4:
- SET_ERRNO_AND_RETURN
-
- .align 2
-#if SYS_sigprocmask >= 128
-LSYS_sigprocmask:
- .long SYS_sigprocmask
-#endif
+ SET_ERRNO_AND_RETURN(sigprocmask)
+ systrap_data(SYS_sigprocmask)
SYSCALL_END_HIDDEN(sigprocmask)
-/* $OpenBSD: sigsuspend.S,v 1.6 2023/12/10 16:45:52 deraadt Exp $ */
+/* $OpenBSD: sigsuspend.S,v 1.7 2024/03/27 20:03:29 miod Exp $ */
/* $NetBSD: sigsuspend.S,v 1.5 2003/08/07 16:42:21 agc Exp $ */
/*-
mov r4, r0 /* fetch mask arg */
mov.l @r0, r0 /* indirect to mask arg */
mov r0, r4
-#if SYS_sigsuspend >= 128
- mov.l LSYS_sigsuspend, r0
-#else
- mov #SYS_sigsuspend, r0
-#endif
-99: trapa #0x80
- PINSYSCALL(SYS_sigsuspend, 99b)
- SET_ERRNO_AND_RETURN
-
- .align 2
-#if SYS_sigsuspend >= 128
-LSYS_sigsuspend:
- .long SYS_sigsuspend
-#endif
+ systrap SYS_sigsuspend
+ SET_ERRNO_AND_RETURN(sigsuspend)
+ systrap_data SYS_sigsuspend
SYSCALL_END_HIDDEN(sigsuspend)
-/* $OpenBSD: tfork_thread.S,v 1.5 2023/12/10 16:45:52 deraadt Exp $ */
+/* $OpenBSD: tfork_thread.S,v 1.6 2024/03/27 20:03:29 miod Exp $ */
/*
* Copyright (c) 2007 Miodrag Vallat.
* r4 r5 r6 r7
*/
ENTRY(__tfork_thread)
-#if SYS___tfork >= 128
- mov.l .LSYS___tfork, r0
-#else
- mov #SYS___tfork, r0
-#endif
-99: trapa #0x80
- PINSYSCALL(SYS___tfork, 99b)
+ systrap SYS___tfork
bf 9f
tst r0, r0
rts
nop
+ systrap_data SYS___tfork
+
1:
/*
* In child process: invoke function, then exit.
jsr @r6
mov r7, r4
-#if SYS___threxit >= 128
- mov.l .LSYS___threxit, r0
-#else
- mov #SYS___threxit, r0
-#endif
-98: trapa #0x80
- PINSYSCALL(SYS___threxit, 98b)
+ systrap SYS___threxit
+ systrap_data SYS___threxit
9:
/*
* System call failure.
*/
- SET_ERRNO_AND_RETURN
-
- .align 2
-#if SYS___tfork >= 128
-.LSYS___tfork: .long SYS___tfork
-#endif
-#if SYS___threxit >= 128
-.LSYS___threxit: .long SYS___threxit
-#endif
+ SET_ERRNO_AND_RETURN(__tfork)
SET_ENTRY_SIZE(__tfork_thread)