summaryrefslogtreecommitdiffstats
path: root/libc/sysdeps/linux/powerpc/_mmap.c
blob: 350f4c49eec3b62bdb8d3a7af4e113e9ac84eb85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <sys/syscall.h>

#define __syscall_clobbers \
	"r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12"
#define __syscall_return(type) \
	return (__sc_err & 0x10000000 ? errno = __sc_ret, __sc_ret = -1 : 0), \
	       (type) __sc_ret

void * mmap(void *start, size_t length, int prot, int flags, int fd,
	off_t offset)
{
	unsigned long __sc_ret, __sc_err;
	register unsigned long __sc_0 __asm__ ("r0");
	register unsigned long __sc_3 __asm__ ("r3");
	register unsigned long __sc_4 __asm__ ("r4");
	register unsigned long __sc_5 __asm__ ("r5");
	register unsigned long __sc_6 __asm__ ("r6");
	register unsigned long __sc_7 __asm__ ("r7");
	register unsigned long __sc_8 __asm__ ("r8");

	__sc_3 = (unsigned long) start;
	__sc_4 = (unsigned long) length;
	__sc_5 = (unsigned long) prot;
	__sc_6 = (unsigned long) flags;
	__sc_7 = (unsigned long) fd;
	__sc_8 = (unsigned long) offset;
	__sc_0 = __NR_mmap;
	__asm__ __volatile__
		("sc		\n\t"
		 "mfcr %1	"
		: "=&r" (__sc_3), "=&r" (__sc_0)
		: "0"   (__sc_3), "1"   (__sc_0),
		  "r"   (__sc_4),
		  "r"   (__sc_5),
		  "r"   (__sc_6),
		  "r"   (__sc_7),
		  "r"   (__sc_8)
		: __syscall_clobbers);
	__sc_ret = __sc_3;
	__sc_err = __sc_0;

	__syscall_return (void *);
}