Browse Source

[linux] Add linux_syscall

Add linux_syscall for both i386 and x86_64.

Signed-off-by: Piotr Jaroszyński <p.jaroszynski@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Piotr Jaroszyński 14 years ago
parent
commit
e743910cf9

+ 45
- 0
src/arch/i386/core/linux/linux_syscall.S View File

@@ -0,0 +1,45 @@
1
+
2
+	.section ".data"
3
+	.globl linux_errno
4
+
5
+linux_errno:	.int 0
6
+
7
+	.section ".text"
8
+	.code32
9
+	.globl linux_syscall
10
+	.type  linux_syscall, @function
11
+
12
+linux_syscall:
13
+	/* Save registers */
14
+	pushl	%ebx
15
+	pushl	%esi
16
+	pushl	%edi
17
+	pushl	%ebp
18
+
19
+	movl	20(%esp), %eax  // C arg1 -> syscall number
20
+	movl	24(%esp), %ebx  // C arg2 -> syscall arg1
21
+	movl	28(%esp), %ecx  // C arg3 -> syscall arg2
22
+	movl	32(%esp), %edx  // C arg4 -> syscall arg3
23
+	movl	36(%esp), %esi  // C arg5 -> syscall arg4
24
+	movl	40(%esp), %edi  // C arg6 -> syscall arg5
25
+	movl	44(%esp), %ebp  // C arg7 -> syscall arg6
26
+
27
+	int	$0x80
28
+
29
+	/* Restore registers */
30
+	popl	%ebp
31
+	popl	%edi
32
+	popl	%esi
33
+	popl	%ebx
34
+
35
+	cmpl	$-4095, %eax
36
+	jae	1f
37
+	ret
38
+
39
+1:
40
+	negl	%eax
41
+	movl	%eax, linux_errno
42
+	movl	$-1, %eax
43
+	ret
44
+
45
+	.size linux_syscall, . - linux_syscall

+ 33
- 0
src/arch/x86_64/core/linux/linux_syscall.S View File

@@ -0,0 +1,33 @@
1
+
2
+	.section ".data"
3
+	.globl linux_errno
4
+
5
+linux_errno:	.int 0
6
+
7
+	.section ".text"
8
+	.code64
9
+	.globl linux_syscall
10
+	.type  linux_syscall, @function
11
+
12
+linux_syscall:
13
+	movq	%rdi, %rax    // C arg1 -> syscall number
14
+	movq	%rsi, %rdi    // C arg2 -> syscall arg1
15
+	movq	%rdx, %rsi    // C arg3 -> syscall arg2
16
+	movq	%rcx, %rdx    // C arg4 -> syscall arg3
17
+	movq	%r8, %r10     // C arg5 -> syscall arg4
18
+	movq	%r9, %r8      // C arg6 -> syscall arg5
19
+	movq	8(%rsp), %r9  // C arg7 -> syscall arg6
20
+
21
+	syscall
22
+
23
+	cmpq	$-4095, %rax
24
+	jae	1f
25
+	ret
26
+
27
+1:
28
+	negq	%rax
29
+	movl	%eax, linux_errno
30
+	movq	$-1, %rax
31
+	ret
32
+
33
+	.size linux_syscall, . - linux_syscall

Loading…
Cancel
Save