-
Notifications
You must be signed in to change notification settings - Fork 47
/
int32.asm
224 lines (183 loc) · 3.06 KB
/
int32.asm
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
; --------------------------------------- int 0xF0 protected ---------------------------------------
int32_21:
mov bp,ax
mov ax,0x0421
int32:
jmp .ibegin
db 'dmmi'
.ibegin:
; AX 0, find interface
cmp ax,0
jnz .n0
dh_virtualization;
push ds
mov ax,data16_idx
mov ds,ax
mov dl,[numcpus]
pop ds
mov ax,0xFACE
IRETD
.n0:
; AH 4, call real mode interrupt
; AL = INT NUM
; BP = AX VALUE
; CX,DX,SI,DI = Normal values
; Upper ESI,EDI => DS and ES
cmp ah,4
jnz nn4
push ds
push eax
mov ax,data32_idx
mov ds,ax
; Mutex Lock
mov ax,mut_i21
call far code32_idx:qwaitlock32
; Save: AX,BX,CD,DX,SI,DI,DS,ES
mov word [From32To16Regs],bp
mov word [From32To16Regs + 2],bx
mov word [From32To16Regs + 4],cx
mov word [From32To16Regs + 6],dx
mov word [From32To16Regs + 8],si
mov word [From32To16Regs + 10],di
mov eax,esi
shr eax,16
mov word [From32To16Regs + 12],ax
mov eax,edi
shr eax,16
mov word [From32To16Regs + 14],ax
pop eax
mov byte [From32To16Regs + 16],al ; #intr
mov word [From32To16Regs + 18],ss ; save for later
mov dword [From32To16Regs + 20],esp ; save for later
; back to real mode
db 066h
db 0eah
dw TempBackRM
dw code16_idx
i4BackFromRM:
mov ax,stack32_idx
mov ss,ax
mov ax,data32_idx
mov ds,ax
mov ax,word [From32To16Regs + 18]
mov ss,ax
mov esp,dword [From32To16Regs + 20]
pop ds
qunlock32 mut_i21
iretd
nn4:
; AH 5, mutex functions
cmp ah,5
jnz .n5
; Initialize mutex
cmp al,0
jnz .n50
push fs
mov bx,page32_idx
mov fs,bx
mov byte [fs:edi],0xFF
pop fs
iretd
.n50:
; lock mutex
cmp al,2
jnz .n52
push fs
mov bx,page32_idx
mov fs,bx
dec byte [fs:edi]
pop fs
iretd
.n52:
; unlock mutex
cmp al,3
jnz .n53
push fs
mov bx,page32_idx
mov fs,bx
cmp byte [fs:edi],0xFF
jz .okl
inc byte [fs:edi]
.okl:
pop fs
iretd
.n53:
; wait mutex
cmp al,4
jnz .n54
push fs
mov bx,page32_idx
mov fs,bx
.Loop1:
CMP byte [fs:edi],0xff
JZ .OutLoop1
pause
JMP .Loop1
.OutLoop1:
pop fs
iretd
.n54:
IRETd
.n5:
; AX 9, switch to mode
cmp ah,9
jnz nn9
; AL 0, unreal
cmp al,0
jnz .nn90
; Back to real mode, ecx = seg:ofs
mov ax,page32_idx
mov ds,ax
linear eax,ofsnnn0,CODE16
mov word [eax],cx
shr ecx,16
linear eax,ofsnnn0,CODE16
mov word [eax],cx
push code32_idx
mov ecx,nnn90Back
push ecx
retf
IRETD
.nn90:
IRETD
nn9:
nop
iretd
CompatFromLongIntF0:
; Disable Paging to get out of Long Mode
mov eax, cr0
and eax,7fffffffh
mov cr0, eax
; Deactivate Long Mode
mov ecx, 0c0000080h
rdmsr
btc eax, 8
wrmsr
; Disable PAE
mov eax, cr4
btc eax, 5
mov cr4, eax
; Go Real
db 066h
db 0eah
dw TempBackLM
dw code16_idx
nnn90Back:
; Disable Paging to get out of Long Mode
mov eax, cr0
and eax,7fffffffh
mov cr0, eax
; Deactivate Long Mode
mov ecx, 0c0000080h
rdmsr
btc eax, 8
wrmsr
; Disable PAE
mov eax, cr4
btc eax, 5
mov cr4, eax
; Go Real
db 066h
db 0eah
dw TempBackLMnnn0
dw code16_idx