1/* System call interface.  C-SKY ABIV2 version.
2   Copyright (C) 2018-2021 Free Software Foundation, Inc.
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, see
17   <https://www.gnu.org/licenses/>.  */
18
19#include <sysdep.h>
20
21/* long syscall(long sysnum, long a, long b, long c, long d, long e, long f) */
22
23ENTRY (syscall)
24	subi	sp, 8
25	stw	r4, (sp, 0)
26	stw	r5, (sp, 4)
27	mov	t0, r7
28
29	/* Put system call number in r7, adjust shift for arguments
30           and load extra arguments from stack. */
31	mov	r7, a0
32	mov	a0, a1
33	mov	a1, a2
34	mov	a2, a3
35	ldw	a3, (sp, 8)
36	ldw	r4, (sp, 12)
37	ldw	r5, (sp, 16)
38	trap	0
39
40	/* Restore temp registers.  */
41	mov	r7, t0
42	ldw	r4, (sp, 0)
43	ldw	r5, (sp, 4)
44	addi	sp, 8
45
46	/* Check return value.  */
47	lrw	t0, 0xfffff000
48	cmphs	a0, t0
49	bf	1f
50#ifdef __PIC__
51	subi	sp, 8
52	stw	gb, (sp, 0)
53	stw	lr, (sp, 4)
54	grs	gb, .Lgetpc
55.Lgetpc:
56	lrw	t0, .Lgetpc@GOTPC
57	addu	gb, gb, t0
58	lrw	t0, __syscall_error@PLT
59	ldr.w	t0, (gb, t0 << 0)
60	jsr	t0
61	ldw	gb, (sp, 0)
62	ldw	lr, (sp, 4)
63	addi	sp, 8
64#else
65	jmpi	__syscall_error
66#endif /* __PIC__ */
671:
68	rts
69PSEUDO_END (syscall)
70