-
Notifications
You must be signed in to change notification settings - Fork 1
/
ea.c
92 lines (83 loc) · 1.76 KB
/
ea.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* linux/kernel/math/ea.c
*
* (C) 1991 Linus Torvalds
*/
/*
* Calculate the effective address.
*/
#include <stddef.h>
#include <linux/math_emu.h>
#include <asm/segment.h>
static int __regoffset[] = {
offsetof(struct info,___eax),
offsetof(struct info,___ecx),
offsetof(struct info,___edx),
offsetof(struct info,___ebx),
offsetof(struct info,___esp),
offsetof(struct info,___ebp),
offsetof(struct info,___esi),
offsetof(struct info,___edi)
};
#define REG(x) (*(long *)(__regoffset[(x)]+(char *) info))
static char * sib(struct info * info, int mod)
{
unsigned char ss,index,base;
long offset = 0;
base = get_fs_byte((char *) EIP);
EIP++;
ss = base >> 6;
index = (base >> 3) & 7;
base &= 7;
if (index == 4)
offset = 0;
else
offset = REG(index);
offset <<= ss;
if (mod || base != 5)
offset += REG(base);
if (mod == 1) {
offset += (signed char) get_fs_byte((char *) EIP);
EIP++;
} else if (mod == 2 || base == 5) {
offset += (signed) get_fs_long((unsigned long *) EIP);
EIP += 4;
}
I387.foo = offset;
I387.fos = 0x17;
return (char *) offset;
}
char * ea(struct info * info, unsigned short code)
{
unsigned char mod,rm;
long * tmp = &EAX;
int offset = 0;
mod = (code >> 6) & 3;
rm = code & 7;
if (rm == 4 && mod != 3)
return sib(info,mod);
if (rm == 5 && !mod) {
offset = get_fs_long((unsigned long *) EIP);
EIP += 4;
I387.foo = offset;
I387.fos = 0x17;
return (char *) offset;
}
tmp = & REG(rm);
switch (mod) {
case 0: offset = 0; break;
case 1:
offset = (signed char) get_fs_byte((char *) EIP);
EIP++;
break;
case 2:
offset = (signed) get_fs_long((unsigned long *) EIP);
EIP += 4;
break;
case 3:
math_abort(info,1<<(SIGILL-1));
}
I387.foo = offset;
I387.fos = 0x17;
return offset + (char *) *tmp;
}