blob: 8c097b87fca7be4b3ea209feff41aa4fa2adc3d6 [file] [log] [blame]
Jeff Diked67b5692005-07-07 17:56:49 -07001/*
2 * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_STUB_H
7#define __SYSDEP_STUB_H
8
Jeff Dike5b7b15a2005-12-18 17:50:39 +01009#include <sys/mman.h>
Jeff Diked67b5692005-07-07 17:56:49 -070010#include <asm/ptrace.h>
11#include <asm/unistd.h>
Jeff Dike54ae36f2007-10-16 01:27:33 -070012#include "as-layout.h"
Jeff Dike5b7b15a2005-12-18 17:50:39 +010013#include "stub-data.h"
14#include "kern_constants.h"
15#include "uml-config.h"
Jeff Diked67b5692005-07-07 17:56:49 -070016
17extern void stub_segv_handler(int sig);
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070018extern void stub_clone_handler(void);
Jeff Diked67b5692005-07-07 17:56:49 -070019
20#define STUB_SYSCALL_RET EAX
21#define STUB_MMAP_NR __NR_mmap2
Jeff Dike71f926f2007-10-16 01:26:44 -070022#define MMAP_OFFSET(o) ((o) >> UM_KERN_PAGE_SHIFT)
Jeff Diked67b5692005-07-07 17:56:49 -070023
Jeff Dike17d46972005-11-21 21:32:09 -080024static inline long stub_syscall0(long syscall)
25{
26 long ret;
27
28 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall));
29
30 return ret;
31}
32
Paolo 'Blaisorblade' Giarrusso4f027242005-11-07 00:58:46 -080033static inline long stub_syscall1(long syscall, long arg1)
34{
35 long ret;
36
37 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1));
38
39 return ret;
40}
41
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070042static inline long stub_syscall2(long syscall, long arg1, long arg2)
43{
44 long ret;
45
Paolo 'Blaisorblade' Giarrusso4f027242005-11-07 00:58:46 -080046 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
47 "c" (arg2));
48
49 return ret;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070050}
51
52static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
53{
Paolo 'Blaisorblade' Giarrusso4f027242005-11-07 00:58:46 -080054 long ret;
55
56 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
57 "c" (arg2), "d" (arg3));
58
59 return ret;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070060}
61
62static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
63 long arg4)
64{
Paolo 'Blaisorblade' Giarrusso4f027242005-11-07 00:58:46 -080065 long ret;
66
67 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
68 "c" (arg2), "d" (arg3), "S" (arg4));
69
70 return ret;
71}
72
73static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
74 long arg4, long arg5)
75{
76 long ret;
77
78 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
79 "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5));
80
81 return ret;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070082}
83
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070084static inline void trap_myself(void)
85{
86 __asm("int3");
87}
88
Jeff Dike5b7b15a2005-12-18 17:50:39 +010089static inline void remap_stack(int fd, unsigned long offset)
90{
91 __asm__ volatile ("movl %%eax,%%ebp ; movl %0,%%eax ; int $0x80 ;"
92 "movl %7, %%ebx ; movl %%eax, (%%ebx)"
Jeff Dike54ae36f2007-10-16 01:27:33 -070093 : : "g" (STUB_MMAP_NR), "b" (STUB_DATA),
94 "c" (UM_KERN_PAGE_SIZE),
Jeff Dike5b7b15a2005-12-18 17:50:39 +010095 "d" (PROT_READ | PROT_WRITE),
Jeff Dike54ae36f2007-10-16 01:27:33 -070096 "S" (MAP_FIXED | MAP_SHARED), "D" (fd),
97 "a" (offset),
98 "i" (&((struct stub_data *) STUB_DATA)->err)
Jeff Dike5b7b15a2005-12-18 17:50:39 +010099 : "memory");
100}
101
Jeff Diked67b5692005-07-07 17:56:49 -0700102#endif