Skip to content

Commit 11275b0

Browse files
author
Michael Chourdakis
committed
Begin ACPI64
1 parent 736d3fd commit 11275b0

13 files changed

+258
-5
lines changed

acpi32.asm

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SendSIPI32f:
1313
PUSHAD
1414
PUSH DS
1515
PUSH ES
16-
mov cx,page32_idx
16+
mov cx,page32_idx ; This is a base-0 segment, so "linear" for EDI positioning
1717
mov es,cx
1818
mov cx,data16_idx
1919
mov ds,cx

acpi64.asm

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
; --------------------------------------- 64 bit APIC functions ---------------------------------------
2+
USE64
3+
4+
5+
include 'mutex64.asm'
6+
7+
8+
9+
10+
;-------------------------------------------------------------------------------------------
11+
; Function SendSIPI64 : Sends SIPI. EBX = CPU Index, EAX = linear
12+
;-------------------------------------------------------------------------------------------
13+
SendSIPI64:
14+
PUSH RAX
15+
PUSH RBX
16+
PUSH RCX
17+
PUSH RDX
18+
PUSH RSI
19+
PUSH RDI
20+
21+
break64
22+
linear ECX,LocalApic
23+
; Spurious
24+
MOV EDI,[ECX]
25+
ADD EDI,0x0F0
26+
MOV EDX,[EDI]
27+
OR EDX,0x1FF
28+
MOV [EDI],EDX
29+
30+
; Vector
31+
.L1:
32+
MOV ECX,EAX
33+
TEST EAX,0xFFF
34+
JZ .L2
35+
INC EAX
36+
JMP .L1
37+
.L2:
38+
MOV ESI,EAX
39+
SHR ESI,12
40+
; Init
41+
MOV ECX,0x04500
42+
OR ECX,ESI
43+
call SendIPI64
44+
45+
; SIPI 1
46+
MOV ECX,0x05600
47+
OR ECX,ESI
48+
call SendIPI64
49+
50+
; SIPI 2
51+
MOV ECX,0x05600
52+
OR ECX,ESI
53+
call SendIPI64
54+
55+
POP RDI
56+
POP RSI
57+
POP RDX
58+
POP RCX
59+
POP RBX
60+
POP RAX
61+
RET
62+
63+
64+
;-------------------------------------------------------------------------------------------
65+
; Function SendIPI64 : Sends IPI. EBX = CPU Index, ECX = IPI
66+
;-------------------------------------------------------------------------------------------
67+
SendIPI64: ; EBX = CPU INDEX, ECX = IPI
68+
PUSH RAX
69+
PUSH RBX
70+
PUSH RCX
71+
PUSH RDX
72+
PUSH RSI
73+
PUSH RDI
74+
75+
; Lock Mutex
76+
mov ax,mut_ipi
77+
call qwaitlock64
78+
79+
; Write it to 0x310
80+
; EBX is CPU INDEX
81+
; MAKE IT APIC ID
82+
xor eax,eax
83+
mov ax,cpusstructize
84+
mul bx
85+
add ax,cpus
86+
xor rdi,rdi
87+
mov di,ax
88+
add di,4
89+
linear esi,edi
90+
mov bl,[esi]
91+
linear ecx,LocalApic
92+
MOV EDI,[ecx]
93+
ADD EDI,0x310
94+
MOV EDX,[EDI]
95+
AND EDX,0xFFFFFF
96+
XOR EAX,EAX
97+
MOV AL,BL
98+
SHL EAX,24
99+
OR EDX,EAX
100+
MOV [EDI],EDX
101+
102+
103+
; Write it to 0x300
104+
MOV EDI,[ecx]
105+
ADD EDI,0x300
106+
MOV [EDI],ECX
107+
; Verify it got delivered
108+
.Verify:
109+
PAUSE
110+
MOV EAX,[EDI];
111+
SHR EAX,12
112+
TEST EAX,1
113+
JNZ .Verify
114+
; Write it to 0xB0 (EOI)
115+
116+
MOV EDI,[ecx]
117+
ADD EDI,0xB0
118+
MOV dword [EDI],0
119+
120+
; Release Mutex
121+
qunlock64 mut_ipi
122+
123+
POP RDI
124+
POP RSI
125+
POP RDX
126+
POP RCX
127+
POP RBX
128+
POP RAX
129+
RET
130+
131+

asm.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
</None>
160160
<None Include="acpi16.asm" />
161161
<None Include="acpi32.asm" />
162+
<None Include="acpi64.asm" />
162163
<None Include="asmtest.vbox" />
163164
<None Include="bochsrc.bxrc" />
164165
<None Include="build.bat" />
@@ -174,6 +175,7 @@
174175
<None Include="iso.ps1" />
175176
<None Include="mutex16.asm" />
176177
<None Include="mutex32.asm" />
178+
<None Include="mutex64.asm" />
177179
<None Include="page32.asm" />
178180
<None Include="Readme.md" />
179181
<None Include="stack16.asm" />

asm.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@
114114
<None Include="mutex32.asm">
115115
<Filter>32 bit code</Filter>
116116
</None>
117+
<None Include="mutex64.asm">
118+
<Filter>64 bit code</Filter>
119+
</None>
120+
<None Include="acpi64.asm">
121+
<Filter>64 bit code</Filter>
122+
</None>
117123
</ItemGroup>
118124
<ItemGroup>
119125
<ClCompile Include="dos32.asm">

bx_enh_dbg.ini

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ isLittleEndian = TRUE
1919
DefaultAsmLines = 512
2020
DumpWSIndex = 0
2121
DockOrder = 0x123
22-
ListWidthPix[0] = 727
23-
ListWidthPix[1] = 465
24-
ListWidthPix[2] = 174
22+
ListWidthPix[0] = 753
23+
ListWidthPix[1] = 452
24+
ListWidthPix[2] = 161
2525
FontName = System
2626
FontSize = -16
2727
MainWindow = -8, -8, 1374, 746

code16.asm

+10
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,16 @@ mov ax,0900h
325325
int 21h
326326
fail_31:
327327

328+
; Thread 3
329+
mov ax,DATA16
330+
mov gs,ax
331+
cmp [gs:FromThread4],1
332+
jnz fail_32
333+
mov dx,thr4
334+
mov ax,0900h
335+
int 21h
336+
fail_32:
337+
328338
end if
329339

330340
; PM mode test

code64.asm

+19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ macro break64
88
xchg bx,bx
99
}
1010

11+
include 'acpi64.asm'
12+
1113
Start64:
1214

1315
xor r8d,r8d
@@ -23,6 +25,23 @@ Start64:
2325
add rax,d64
2426
mov byte [rax],1
2527

28+
; --------------------------------------- SIPI to real mode test ---------------------------------------
29+
if TEST_LM_SIPI > 0
30+
31+
qlock64 mut_1
32+
33+
linear eax,Thread16_4,CODE16
34+
mov rbx,1
35+
call SendSIPI64
36+
37+
mov ax,mut_1
38+
call qwait64
39+
40+
41+
end if
42+
43+
44+
2645
; Back to Compatibility Mode
2746
push code32_idx
2847
xor rcx,rcx

config.asm

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
TEST_LONG = 1
22
TEST_MULTI = 1
33
TEST_PM_SIPI = 1
4+
TEST_LM_SIPI = 0

data16.asm

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ProcedureStart dd 0
1515
FromThread1 db 0
1616
FromThread2 db 0
1717
FromThread3 db 0
18+
FromThread4 db 0
1819

1920
; --------------------------------------- 16 bit mutexes ---------------------------------------
2021
mut_ipi db 0xFF
@@ -30,9 +31,11 @@ ap2 db "Apic 2 found",0dh,0ah,"$"
3031
cpuf db "CPU Found",0dh,0ah,"$"
3132
thrm1 db "Message from real mode thread",0dh,0ah,"$"
3233
thrm2 db "Message from real mode thread called from protected mode",0dh,0ah,"$"
34+
thrm3 db "Message from real mode thread called from long mode",0dh,0ah,"$"
3335
thr1 db "Thread 1 executed, OK",0dh,0ah,"$"
3436
thr2 db "Thread 2 executed, OK",0dh,0ah,"$"
3537
thr3 db "Thread 3 real mode executed from protected mode, OK",0dh,0ah,"$"
38+
thr4 db "Thread 4 real mode executed from long mode, OK",0dh,0ah,"$"
3639

3740
a20off db "Restoring A20",0dh,0ah,"$"
3841

entry.exe

8.62 KB
Binary file not shown.

mutex64.asm

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
USE64
2+
3+
macro qlock64 trg
4+
{
5+
push rcx
6+
linear ecx,trg
7+
dec byte [ecx]
8+
pop rcx
9+
}
10+
11+
macro qunlock64 trg
12+
{
13+
push rcx
14+
linear ecx,trg
15+
cmp byte [ecx],0xFF
16+
jz .unlk
17+
inc byte [ecx]
18+
.unlk:
19+
pop rcx
20+
}
21+
22+
qwait64:
23+
; ax = target mutex in data16
24+
push rcx
25+
linear ecx,eax
26+
27+
.Loop1:
28+
CMP byte [ecx],0xff
29+
JZ .OutLoop1
30+
pause
31+
JMP .Loop1
32+
.OutLoop1:
33+
34+
pop rcx
35+
ret
36+
37+
38+
qwaitlock64:
39+
; ax = target mutex in data16
40+
push rbx
41+
push rcx
42+
linear ecx,eax
43+
44+
.Loop1:
45+
CMP byte [ecx],0xff
46+
JZ .OutLoop1
47+
pause
48+
JMP .Loop1
49+
.OutLoop1:
50+
51+
; Lock is free, can we grab it?
52+
mov bl,0xfe
53+
MOV AL,0xFF
54+
LOCK CMPXCHG [ecx],bl
55+
JNZ .Loop1 ; Write failed
56+
57+
.OutLoop2: ; Lock Acquired
58+
59+
pop rcx
60+
pop rbx
61+
ret

stack16.asm

+4
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ SEGMENT STACK16T3 USE16
2828
ORG 0
2929
sseg16t3 dw 2048 dup (?)
3030
stack16t3_end:
31+
SEGMENT STACK16T4 USE16
32+
ORG 0
33+
sseg16t4 dw 2048 dup (?)
34+
stack16t4_end:

thread16.asm

+17-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Thread16_2:
6262
6363
Thread16_3:
6464

65-
thread16header STACK16T2,stack16t3_end
65+
thread16header STACK16T3,stack16t3_end
6666

6767
mov [FromThread3],1
6868
sti
@@ -75,3 +75,19 @@ Thread16_3:
7575
cli
7676
hlt
7777
78+
79+
Thread16_4:
80+
81+
thread16header STACK16T4,stack16t4_end
82+
83+
mov [FromThread4],1
84+
sti
85+
mov dx,thrm3
86+
mov ax,0900h
87+
int 21h
88+
cli
89+
90+
qunlock16 mut_1
91+
cli
92+
hlt
93+

0 commit comments

Comments
 (0)