Skip to content

Commit 28d3b5a

Browse files
committed
arch/xtensa: Add call0-based syscall interface
There was a system call handler added as part of the call0 ABI integration. Wire it up to the standard Zephyr userspace system call API. Signed-off-by: Andy Ross <andyross@google.com>
1 parent d909e24 commit 28d3b5a

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

arch/xtensa/core/xtensa-win0.S

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,3 +474,47 @@ xtensa_switch:
474474
s32i a4, a3, 0 /* store switch handle */
475475
mov a3, a2
476476
j restore
477+
478+
/* This file also contains the system call stubs, though those are
479+
* used only by ring 3 code and live in the regular .text section.
480+
* The system calls work just like CALL0 ABI functions, with arguments
481+
* marshalled for us by the compiler. All we need to do is put the ID
482+
* number in A11.
483+
*/
484+
.section .text.asm_syscall_stubs, "ax"
485+
486+
.global xtensa_syscall6
487+
xtensa_syscall6:
488+
mov a11, a8
489+
syscall
490+
ret
491+
492+
.global xtensa_syscall5
493+
xtensa_syscall5:
494+
mov a11, a7
495+
syscall
496+
ret
497+
498+
.global xtensa_syscall4
499+
xtensa_syscall4:
500+
mov a11, a6
501+
syscall
502+
ret
503+
504+
.global xtensa_syscall3
505+
xtensa_syscall3:
506+
mov a11, a5
507+
syscall
508+
ret
509+
510+
.global xtensa_syscall2
511+
xtensa_syscall2:
512+
mov a11, a4
513+
syscall
514+
ret
515+
516+
.global xtensa_syscall1
517+
xtensa_syscall1:
518+
mov a11, a3
519+
syscall
520+
ret

include/zephyr/arch/syscall.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <zephyr/arch/arc/syscall.h>
2424
#elif defined(CONFIG_RISCV)
2525
#include <zephyr/arch/riscv/syscall.h>
26+
#elif defined(CONFIG_XTENSA)
27+
#include <zephyr/arch/xtensa/syscall.h>
2628
#endif
2729

2830
#endif /* ZEPHYR_INCLUDE_ARCH_SYSCALL_H_ */

include/zephyr/arch/xtensa/syscall.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Copyright 2023 Google LLC
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
#ifndef ZEPHYR_INCLUDE_ARCH_XTENSA_SYSCALL_H_
5+
#define ZEPHYR_INCLUDE_ARCH_XTENSA_SYSCALL_H_
6+
7+
/* The Xtensa syscall interface is a straightforward extension of the
8+
* CALL0 function ABI convention, the only difference being placement
9+
* of the system call ID (the C declarations for Zephyr put it in the
10+
* last argument, which is variable, where the handler wants to see it
11+
* in A11 always. Therefore the system calls are expressed as tiny
12+
* linkable functions in xtensa-call0.S.
13+
*
14+
* Alas the declarations for the Zephyr API have these functions
15+
* tagged inline, so we need to do a little preprocessor work to avoid
16+
* redeclaration warnings.
17+
*/
18+
19+
uintptr_t xtensa_syscall6(uintptr_t a1, uintptr_t a2, uintptr_t a3,
20+
uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t id);
21+
uintptr_t xtensa_syscall5(uintptr_t a1, uintptr_t a2, uintptr_t a3,
22+
uintptr_t a4, uintptr_t a5, uintptr_t id);
23+
uintptr_t xtensa_syscall4(uintptr_t a1, uintptr_t a2, uintptr_t a3,
24+
uintptr_t a4, uintptr_t id);
25+
uintptr_t xtensa_syscall3(uintptr_t a1, uintptr_t a2, uintptr_t a3,
26+
uintptr_t id);
27+
uintptr_t xtensa_syscall2(uintptr_t a1, uintptr_t a2, uintptr_t id);
28+
uintptr_t xtensa_syscall1(uintptr_t a1, uintptr_t id);
29+
30+
#define arch_syscall_invoke6 xtensa_syscall6
31+
#define arch_syscall_invoke5 xtensa_syscall5
32+
#define arch_syscall_invoke4 xtensa_syscall4
33+
#define arch_syscall_invoke3 xtensa_syscall3
34+
#define arch_syscall_invoke2 xtensa_syscall2
35+
#define arch_syscall_invoke1 xtensa_syscall1
36+
37+
#endif /* ZEPHYR_INCLUDE_ARCH_XTENSA_SYSCALL_H_ */

0 commit comments

Comments
 (0)