NAME=list syscalls
FILE=-
CMDS=<<EOF
-a arm
-b 32
-e asm.os=linux
asl~?
-e asm.os=android
asl~?
-b 16
asl~?
EOF
EXPECT=<<EOF
44
44
44
EOF
EXPECT_ERR=
RUN

NAME=list ppc syscalls
FILE=-
CMDS=<<EOF
-a ppc
-b 32
-e asm.os=linux
asl~?
-b 64
asl~?
EOF
EXPECT=<<EOF
35
34
EOF
EXPECT_ERR=
RUN

NAME=as <num> honors user argument
FILE=-
CMDS=<<EOF
-a x86
-b 64
-e asm.os=linux
as 0
as 1
as 2
as 4
as write
EOF
EXPECT=<<EOF
0 = read (0, 0x00000000, 0)
1 = write (0, "", 0)
2 = open ("", 0x00000000, 0x00000000)
4 = stat ("", 0x00000000)
1 = write (0, "", 0)
EOF
EXPECT_ERR=
RUN

NAME=syscall names resolve x86_64 numbers
FILE=-
CMDS=<<EOF
-a x86
-b 64
-e asm.os=linux
asl read
asl nanosleep
asl clock_nanosleep
EOF
EXPECT=<<EOF
0
35
230
EOF
EXPECT_ERR=
RUN

NAME=syscall JSON exposes arity and argument formats
FILE=-
CMDS=<<EOF
-a x86
-b 64
-e asm.os=linux
asj 41
asj 39
asj 99999
EOF
EXPECT=<<EOF
[{"name":"socket","swi":128,"num":41,"args":3,"sargs":"ixx domain type protocol"}]
[{"name":"getpid","swi":128,"num":39,"args":0,"sargs":""}]
[]
EOF
EXPECT_ERR=
RUN

NAME=Linux x86 32 syscall register convention
FILE=-
CMDS=<<EOF
-a x86
-b 32
-e asm.os=linux
tcc x86syscall
EOF
EXPECT=<<EOF
eax x86syscall (ebx, ecx, edx, esi, edi, ebp);
EOF
EXPECT_ERR=
RUN

NAME=Linux arm 32 syscall register convention
FILE=-
CMDS=<<EOF
-a arm
-b 32
-e asm.os=linux
tcc armsyscall
EOF
EXPECT=<<EOF
r0 armsyscall (r0, r1, r2, r3, r4, r5, r6);
EOF
EXPECT_ERR=
RUN

NAME=Linux arm 64 syscall register convention
FILE=-
CMDS=<<EOF
-a arm
-b 64
-e asm.os=linux
tcc arm64syscall
EOF
EXPECT=<<EOF
x0 arm64syscall (x0, x1, x2, x3, x4, x5);
EOF
EXPECT_ERR=
RUN

NAME=Linux mips 32 syscall register convention
FILE=-
CMDS=<<EOF
-a mips
-b 32
-e asm.os=linux
tcc o32syscall
EOF
EXPECT=<<EOF
v0 o32syscall (a0, a1, a2, a3, stack) a3;
EOF
EXPECT_ERR=
RUN

NAME=MIPS o32 syscall numbers and networking metadata
FILE=-
CMDS=<<EOF
-a mips
-b 32
-e asm.os=linux
asj 4183
asj 4170
asl mmap2
asl rt_sigaction
asl rt_sigprocmask
asl sysctl
asl fstat64
asl fcntl64
asl gettid
asl set_thread_area
asl exit_group
EOF
EXPECT=<<EOF
[{"name":"socket","swi":4000,"num":4183,"args":3,"sargs":"ixx domain type protocol"}]
[{"name":"connect","swi":4000,"num":4170,"args":3,"sargs":"ipi fd addr addrlen"}]
0x1072
0x1062
0x1063
0x1039
0x1077
0x107c
0x107e
0x10bb
0x1096
EOF
EXPECT_ERR=
RUN

NAME=Linux syscall clobbers differ from C caller-saved registers
FILE=-
CMDS=<<EOF
-a x86
-b 64
-e asm.os=linux
tcck~cc.amd64syscall.clobber
-a mips
-b 32
tcck~cc.o32syscall.clobber
tcck~cc.o32syscall.error
EOF
EXPECT=<<EOF
cc.amd64syscall.clobber=rax,rcx,r11
cc.o32syscall.clobber=v0,v1,a3
cc.o32syscall.error=a3
EOF
EXPECT_ERR=
RUN

NAME=i386 old mmap takes an argument-structure pointer
FILE=-
CMDS=<<EOF
-a x86
-b 32
-e asm.os=linux
asj 90
asj 192
EOF
EXPECT=<<EOF
[{"name":"mmap","swi":128,"num":90,"args":1,"sargs":"p args"}]
[{"name":"mmap2","swi":128,"num":192,"args":6,"sargs":"xixxii addr len prot flags fd pgoff"}]
EOF
EXPECT_ERR=
RUN
