-
Notifications
You must be signed in to change notification settings - Fork 47
/
acpi64.asm
139 lines (111 loc) · 2 KB
/
acpi64.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
; --------------------------------------- 64 bit APIC functions ---------------------------------------
USE64
include 'mutex64.asm'
;-------------------------------------------------------------------------------------------
; Function SendSIPI64 : Sends SIPI. RBX = CPU Index, EAX = linear
;-------------------------------------------------------------------------------------------
SendSIPI64:
PUSH RAX
PUSH RBX
PUSH RCX
PUSH RDX
PUSH RSI
PUSH RDI
linear edi,LocalApic
mov ecx,[edi]
; Spurious
MOV EDI,[RCX]
ADD EDI,0x0F0
MOV EDX,[EDI]
OR EDX,0x1FF
MOV [EDI],EDX
; Vector
.L1:
MOV ECX,EAX
TEST EAX,0xFFF
JZ .L2
INC EAX
JMP .L1
.L2:
MOV ESI,EAX
SHR ESI,12
; Init
MOV ECX,0x04500
OR ECX,ESI
call SendIPI64
; SIPI 1
MOV ECX,0x05600
OR ECX,ESI
call SendIPI64
; SIPI 2
MOV ECX,0x05600
OR ECX,ESI
call SendIPI64
POP RDI
POP RSI
POP RDX
POP RCX
POP RBX
POP RAX
RET
;-------------------------------------------------------------------------------------------
; Function SendIPI64 : Sends IPI. EBX = CPU Index, ECX = IPI
;-------------------------------------------------------------------------------------------
SendIPI64: ; EBX = CPU INDEX, ECX = IPI
PUSH RAX
PUSH RBX
PUSH RCX
PUSH RDX
PUSH RSI
PUSH RDI
; Lock Mutex
xor rax,rax
mov ax,mut_ipi
call qwaitlock64
; Write it to 0x310
; EBX is CPU INDEX
; MAKE IT APIC ID
xor eax,eax
mov ax,cpusstructize
mul bx
add ax,cpus
xor rdi,rdi
mov di,ax
add di,4
linear esi,edi
mov bl,[esi]
linear edi,LocalApic
mov edi,[edi]
ADD EDI,0x310
MOV EDX,[EDI]
AND EDX,0xFFFFFF
XOR EAX,EAX
MOV AL,BL
SHL EAX,24
OR EDX,EAX
MOV [EDI],EDX
; Write it to 0x300
linear edi,LocalApic
mov edi,[edi]
ADD EDI,0x300
MOV [EDI],ECX
; Verify it got delivered
.Verify:
PAUSE
MOV EAX,[EDI];
SHR EAX,12
TEST EAX,1
JNZ .Verify
; Write it to 0xB0 (EOI)
; MOV EDI,[ecx]
; ADD EDI,0xB0
; MOV dword [EDI],0
; Release Mutex
qunlock64 mut_ipi
POP RDI
POP RSI
POP RDX
POP RCX
POP RBX
POP RAX
RET