kernel: Split acpi.inc and hpet.inc from init.inc.

Also, replace some hardcoded constants with macros.

git-svn-id: svn://kolibrios.org@8111 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Ivan Baravy 2020-10-21 14:23:51 +00:00
parent a26092c937
commit a9121a0da9
8 changed files with 524 additions and 307 deletions

298
kernel/trunk/acpi/acpi.inc Normal file
View File

@ -0,0 +1,298 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2020. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Revision$
; ACPI Generic Address Structure
struct GAS
ASID db ? ; address space id
BitWidth db ?
BitOffset db ?
AccessSize db ?
Address DQ ?
ends
ASID.SYSTEM_MEMORY = 0
ASID.SYSTEM_IO = 1
ASID.PCI_CONFIG = 2
ASID.PCI_EC = 3
ASID.PCI_SMBUS = 4
ACCESS_SIZE.UNDEFINED = 0
ACCESS_SIZE.BYTE = 1
ACCESS_SIZE.WORD = 2
ACCESS_SIZE.DWORD = 3
ACCESS_SIZE.QWORD = 4
struct ACPI_RSDP
Signature DQ ?
Checksum db ?
OEMID rb 6
Revision db ?
RsdtAddress dd ?
; for Revision >= 2
Length dd ?
XsdtAddress DQ ?
ExtChecksum db ?
Reserved rb 3
ends
struct ACPI_TABLE ; DESCRIPTION_HEADER
Signature dd ?
Length dd ?
Revision db ?
Checksum db ?
OEMID rb 6
OEMTableID rb 8
OEMRevision rb 4
CreatorID rb 4
CreatorRevision rb 4
ends
struct ACPI_RSDT ACPI_TABLE
Entry rd (0x1000-sizeof.ACPI_TABLE)/4
ends
struct ACPI_HPET ACPI_TABLE
ID dd ?
Base GAS
SeqNumber db ?
MainCounterMinimum dw ?
PageProtectionOEM db ?
ends
struct ACPI_MADT ACPI_TABLE
Local_IC_Addr dd ?
Flags dd ?
IntController rb 0x1000-sizeof.ACPI_TABLE-ACPI_MADT.IntController
ends
struct ACPI_FADT ACPI_TABLE
FirmwareCtrl dd ?
DSDT dd ?
db ?
PreferredPMProfile db ?
SCI_INT dw ?
SMI_CMD dd ?
ACPI_ENABLE db ?
ACPI_DISABLE db ?
S4BIOS_REQ db ?
PSTATE_CNT db ?
PM1a_EVT_BLK dd ?
PM1b_EVT_BLK dd ?
PM1a_CNT_BLK dd ?
PM1b_CNT_BLK dd ?
PM2_CNT_BLK dd ?
PM_TMR_BLK dd ?
GPE0_BLK dd ?
GPE1_BLK dd ?
PM1_EVT_LEN db ?
PM1_CNT_LEN db ?
PM2_CNT_LEN db ?
PM_TMR_LEN db ?
GPE0_BLK_LEN db ?
GPE1_BLK_LEN db ?
GPE1_BASE db ?
CST_CNT db ?
P_LVL2_LAT dw ?
P_LVL3_LAT dw ?
FLUSH_SIZE dw ?
FLUSH_STRIDE dw ?
DUTY_OFFSET db ?
DUTY_WIDTH db ?
DAY_ALRM db ?
MON_ALRM db ?
CENTURY db ?
IAPC_BOOT_ARCH dw ?
db ?
Flags dd ?
RESET_REG GAS
RESET_VALUE db ?
ARM_BOOT_ARCH dw ?
FADT_Minor_Version db ?
X_FIRMWARE_CTRL DQ ?
X_DSDT DQ ?
X_PM1a_EVT_BLK GAS
X_PM1b_EVT_BLK GAS
X_PM1a_CNT_BLK GAS
X_PM1b_CNT_BLK GAS
X_PM2_CNT_BLK GAS
X_PM_TMR_BLK GAS
X_GPE0_BLK GAS
X_GPE1_BLK GAS
SLEEP_CONTROL_REG GAS
SLEEP_STATUS_REG GAS
HypervisorVendorID rb 8
ends
MAX_SSDTS = 32
iglobal
align 4
acpi_lapic_base dd 0xfee00000 ; default local apic base
endg
uglobal
align 4
acpi_dev_data rd 1
acpi_dev_size rd 1
acpi_rsdp_base rd 1
acpi_rsdt_base rd 1
acpi_rsdt_size rd 1
acpi_fadt_base rd 1
acpi_fadt_size rd 1
acpi_ssdt_base rd MAX_SSDTS
acpi_ssdt_size rd MAX_SSDTS
acpi_ssdt_cnt rd 1
acpi_madt_base rd 1
acpi_madt_size rd 1
acpi_ioapic_base rd MAX_IOAPICS
acpi_hpet_base rd 1
acpi_hpet_size rd 1
cpu_count rd 1
smpt rd 16
endg
align 4
acpi_get_root_ptr:
mov eax, [acpi_rsdp_base]
ret
align 4
rsdt_find: ;ecx= rsdt edx= SIG
push ebx
push esi
lea ebx, [ecx+ACPI_RSDT.Entry]
mov esi, [ecx+ACPI_RSDT.Length]
add esi, ecx
align 4
.next:
mov eax, [ebx]
cmp [eax], edx
je .done
add ebx, 4
cmp ebx, esi
jb .next
xor eax, eax
pop esi
pop ebx
ret
.done:
mov eax, [ebx]
pop esi
pop ebx
ret
align 4
check_acpi:
cmp [acpi_rsdp_base], 0
jz .done
stdcall map_io_mem, [acpi_rsdp_base], sizeof.ACPI_RSDP, \
PG_GLOBAL+PAT_WB+PG_READ
mov [acpi_rsdp_base], eax
.rsdp_done:
cmp [acpi_rsdt_base], 0
jz .rsdt_done
stdcall map_io_mem, [acpi_rsdt_base], [acpi_rsdt_size], \
PG_GLOBAL+PAT_WB+PG_READ
mov [acpi_rsdt_base], eax
.rsdt_done:
cmp [acpi_fadt_base], 0
jz .fadt_done
stdcall map_io_mem, [acpi_fadt_base], [acpi_fadt_size], \
PG_GLOBAL+PAT_WB+PG_READ
mov [acpi_fadt_base], eax
.fadt_done:
cmp [acpi_hpet_base], 0
jz .hpet_done
stdcall map_io_mem, [acpi_hpet_base], [acpi_hpet_size], \
PG_GLOBAL+PAT_WB+PG_READ
mov [acpi_hpet_base], eax
mov eax, [eax+ACPI_HPET.Base.Address.lo]
mov [hpet_base], eax
.hpet_done:
cmp [acpi_madt_base], 0
jz .madt_done
stdcall map_io_mem, [acpi_madt_base], [acpi_madt_size], \
PG_GLOBAL+PAT_WB+PG_READ
mov [acpi_madt_base], eax
mov ecx, [eax+ACPI_MADT.Local_IC_Addr]
mov [acpi_lapic_base], ecx
mov edi, smpt
mov ebx, [ecx+APIC_ID]
shr ebx, 24 ; read APIC ID
mov [edi], ebx ; bootstrap always first
inc [cpu_count]
add edi, 4
mov [ioapic_cnt], 0
lea edx, [eax+ACPI_MADT.IntController]
mov ecx, [eax+ACPI_MADT.Length]
add ecx, eax
.check:
mov eax, [edx]
cmp al, 0
je .lapic
cmp al, 1
je .io_apic
jmp .next
.lapic:
shr eax, 24 ; get APIC ID
cmp eax, ebx ; skip self
je .next
test [edx+4], byte 1 ; is enabled ?
jz .next
cmp [cpu_count], 16
jae .next
stosd ; store APIC ID
inc [cpu_count]
jmp .next
.io_apic:
mov eax, [ioapic_cnt]
push dword[edx+4]
pop [acpi_ioapic_base+eax*4]
push dword[edx+8]
pop [ioapic_gsi_base+eax*4]
inc [ioapic_cnt]
jmp .next
.next:
mov eax, [edx]
movzx eax, ah
add edx, eax
cmp edx, ecx
jb .check
.madt_done:
xor ecx, ecx
.next_ssdt:
cmp ecx, [acpi_ssdt_cnt]
jz .ssdt_done
push ecx
stdcall map_io_mem, [acpi_ssdt_base+ecx*4], [acpi_ssdt_size+ecx*4], \
PG_GLOBAL+PAT_WB+PG_READ
pop ecx
mov [acpi_ssdt_base+ecx*4], eax
inc ecx
jmp .next_ssdt
.ssdt_done:
.done:
ret

View File

@ -13,33 +13,12 @@
$Revision$
; ACPI Generic Address Structure
struct GAS
asid db ? ; address space id
bit_width db ?
bit_offset db ?
access_size db ?
address DQ ?
ends
ASID.SYSTEM_MEMORY = 0
ASID.SYSTEM_IO = 1
ASID.PCI_CONFIG = 2
ASID.PCI_EC = 3
ASID.PCI_SMBUS = 4
ACCESS_SIZE.UNDEFINED = 0
ACCESS_SIZE.BYTE = 1
ACCESS_SIZE.WORD = 2
ACCESS_SIZE.DWORD = 3
ACCESS_SIZE.QWORD = 4
align 4
system_shutdown: ; shut down the system
cmp byte [BOOT.shutdown_type], SYSTEM_SHUTDOWN
cmp [BOOT.shutdown_type], SYSTEM_SHUTDOWN
jb @F
cmp byte [BOOT.shutdown_type], SYSTEM_RESTART
cmp [BOOT.shutdown_type], SYSTEM_RESTART
jbe .valid
@@:
ret
@ -83,7 +62,7 @@ yes_shutdown_param:
cli
call IRQ_mask_all
mov eax, dword[BOOT.shutdown_type]
movzx eax, [BOOT.shutdown_type]
cmp al, SYSTEM_RESTART
jne @F
@ -98,34 +77,24 @@ yes_shutdown_param:
mov ecx, (restart_code_end - restart_code_start)/4
rep movsd
call create_trampoline_pgmap
mov cr3, eax
jmp @F
org $-OS_BASE
@@:
;disable paging
mov eax, cr0
and eax, 0x7FFFFFFF
mov cr0, eax
mov eax, cr3
mov cr3, eax
cmp byte [BOOT_LO.shutdown_type], SYSTEM_SHUTDOWN
jne no_acpi_power_off
cmp [BOOT.shutdown_type], SYSTEM_SHUTDOWN
jne not_power_off
; system_power_off
mov ebx, [acpi_fadt_base-OS_BASE]
cmp dword [ebx], 'FACP'
jne no_acpi_power_off
mov esi, [acpi_dsdt_base-OS_BASE]
cmp dword [esi], 'DSDT'
jne no_acpi_power_off
mov eax, [esi+4] ; DSDT length
mov ebx, [acpi_fadt_base]
test ebx, ebx
jz no_acpi
cmp [ebx+ACPI_TABLE.Signature], 'FACP'
jne no_acpi
mov esi, [acpi_ssdt_base] ; first SSDT is DSDT
test esi, esi
jz no_acpi
cmp [esi+ACPI_TABLE.Signature], 'DSDT'
jne no_acpi
mov eax, [esi+ACPI_TABLE.Length]
sub eax, 36+4
jbe no_acpi_power_off
jbe no_acpi
add esi, 36
.scan_dsdt:
cmp dword [esi], '_S5_'
@ -143,7 +112,7 @@ org $-OS_BASE
cmp byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx
jz @f
cmp byte [esi], 0xA
jnz no_acpi_power_off
jnz no_acpi
inc esi
mov cl, [esi]
@@:
@ -153,7 +122,7 @@ org $-OS_BASE
cmp byte [esi], 0
jz @f
cmp byte [esi], 0xA
jnz no_acpi_power_off
jnz no_acpi
inc esi
mov ch, [esi]
@@:
@ -162,14 +131,14 @@ org $-OS_BASE
inc esi
dec eax
jnz .scan_dsdt
jmp no_acpi_power_off
jmp no_acpi
do_acpi_power_off:
mov edx, [ebx+48]
mov edx, [ebx+ACPI_FADT.SMI_CMD]
test edx, edx
jz .nosmi
mov al, [ebx+52]
mov al, [ebx+ACPI_FADT.ACPI_ENABLE]
out dx, al
mov edx, [ebx+64]
mov edx, [ebx+ACPI_FADT.PM1a_CNT_BLK]
@@:
in ax, dx
test al, 1
@ -178,12 +147,12 @@ do_acpi_power_off:
and cx, 0x0707
shl cx, 2
or cx, 0x2020
mov edx, [ebx+64]
mov edx, [ebx+ACPI_FADT.PM1a_CNT_BLK]
in ax, dx
and ax, 203h
or ah, cl
out dx, ax
mov edx, [ebx+68]
mov edx, [ebx+ACPI_FADT.PM1b_CNT_BLK]
test edx, edx
jz @f
in ax, dx
@ -191,40 +160,72 @@ do_acpi_power_off:
or ah, ch
out dx, ax
@@:
jmp $
jmp no_acpi
no_acpi_power_off:
cmp byte[BOOT_LO.shutdown_type], SYSTEM_REBOOT
jnz no_acpi_reboot
not_power_off:
cmp [BOOT.shutdown_type], SYSTEM_REBOOT
jnz not_reboot
; try to reboot via ACPI fixed features
mov ebx, [acpi_fadt_base-OS_BASE]
cmp dword[ebx], 'FACP'
jne no_acpi_power_off
test dword[ebx+0x70], 1 SHL 10 ; RESET_REG_SUP
jz no_acpi_reboot
cmp [ebx+0x74+GAS.asid], ASID.SYSTEM_IO
jnz no_acpi_reboot
cmp [ebx+0x74+GAS.bit_width], 8
jnz no_acpi_reboot
cmp [ebx+0x74+GAS.bit_offset], 0
jnz no_acpi_reboot
cmp [ebx+0x74+GAS.access_size], ACCESS_SIZE.BYTE
ja no_acpi_reboot
cmp [ebx+0x74+GAS.address.hi], 0
jnz no_acpi_reboot
mov edx, [ebx+0x74+GAS.address.lo]
movzx eax, byte[ebx+0x80]
mov ebx, [acpi_fadt_base]
test ebx, ebx
jz no_acpi
cmp [ebx+ACPI_TABLE.Signature], 'FACP'
jne no_acpi
cmp [ebx+ACPI_FADT.Length], ACPI_FADT.RESET_VALUE
jbe no_acpi
test [ebx+ACPI_FADT.Flags], 1 SHL 10 ; reset_reg_supported
jz no_acpi
cmp [ebx+ACPI_FADT.RESET_REG.ASID], ASID.SYSTEM_IO
jnz no_acpi
cmp [ebx+ACPI_FADT.RESET_REG.BitWidth], 8
jnz no_acpi
cmp [ebx+ACPI_FADT.RESET_REG.BitOffset], 0
jnz no_acpi
cmp [ebx+ACPI_FADT.RESET_REG.AccessSize], ACCESS_SIZE.BYTE
ja no_acpi
cmp [ebx+ACPI_FADT.RESET_REG.Address.hi], 0
jnz no_acpi
; 'enable' ACPI
mov edx, [ebx+ACPI_FADT.SMI_CMD]
test edx, edx
jz .nosmi
mov al, [ebx+ACPI_FADT.ACPI_ENABLE]
out dx, al
jmp $
; unreachable
no_acpi_reboot:
mov edx, [ebx+ACPI_FADT.PM1a_CNT_BLK]
@@:
in ax, dx
test al, 1
jz @b
.nosmi:
mov edx, [ebx+ACPI_FADT.RESET_REG.Address.lo]
movzx eax, [ebx+ACPI_FADT.RESET_VALUE]
out dx, al
jmp no_acpi
not_reboot:
no_acpi:
call create_trampoline_pgmap
mov cr3, eax
jmp @F
org $-OS_BASE
@@:
;disable paging
mov eax, cr0
and eax, 0x7FFFFFFF
mov cr0, eax
mov eax, cr3
mov cr3, eax
jmp 0x50000
align 4
restart_code_start:
org 0x50000
cmp byte [BOOT_LO.shutdown_type], SYSTEM_RESTART
cmp [BOOT_LO.shutdown_type], SYSTEM_RESTART
jne @F
mov esi, _CLEAN_ZONE-OS_BASE

View File

@ -248,7 +248,6 @@ BTN_ADDR = OS_BASE + 0x000FE88
MEM_AMOUNT = OS_BASE + 0x000FE8C
SYS_SHUTDOWN = OS_BASE + 0x000FF00
TASK_ACTIVATE = OS_BASE + 0x000FF01
TMP_STACK_TOP = 0x007CC00
@ -278,7 +277,7 @@ LFB_BASE = 0xFE000000
new_app_base = 0;
twdw = 0x2000 ; CURRENT_TASK - window_data
twdw = CURRENT_TASK - window_data
std_application_base_address = new_app_base
RING0_STACK_SIZE = 0x2000

View File

@ -561,8 +561,3 @@ get_clock_ns:
mov edx, 10000000
mul edx
ret
align 4
acpi_get_root_ptr:
mov eax, [acpi_rsdp]
ret

View File

@ -0,0 +1,74 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2020. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Revision$
HPET_ID = 0x0000
HPET_PERIOD = 0x0004
HPET_CFG_ENABLE = 0x0001
HPET_CFG = 0x0010
HPET_COUNTER = 0x00f0
HPET_T0_CFG = 0x0100
HPET_TN_LEVEL = 0x0002
HPET_TN_ENABLE = 0x0004
HPET_TN_FSB = 0x4000
uglobal
hpet_base rd 1
hpet_period rd 1
hpet_timers rd 1
hpet_tsc_start rd 2
endg
align 4
init_hpet:
mov ebx, [hpet_base]
test ebx, ebx
jz .done
mov eax, [ebx]
and ah, 0x1F
inc ah
movzx eax, ah
mov [hpet_timers], eax
mov ecx, eax
mov eax, [ebx+HPET_PERIOD]
xor edx, edx
shld edx, eax, 10
shl eax, 10
mov esi, 1000000
div esi
mov [hpet_period], eax
mov esi, [ebx+HPET_CFG]
and esi, not HPET_CFG_ENABLE
mov [ebx+HPET_CFG], esi ;stop main counter
lea edx, [ebx+HPET_T0_CFG]
@@:
jcxz @F
mov eax, [edx]
and eax, not (HPET_TN_ENABLE+HPET_TN_LEVEL+HPET_TN_FSB)
mov [edx], eax
add edx, 0x20
dec ecx
jmp @B
@@:
mov [ebx+HPET_COUNTER], ecx ;reset main counter
mov [ebx+HPET_COUNTER+4], ecx
or esi, HPET_CFG_ENABLE
mov [ebx+HPET_CFG], esi ;and start again
.done:
rdtsc
mov [hpet_tsc_start], eax
mov [hpet_tsc_start+4], edx
ret

View File

@ -410,43 +410,66 @@ proc test_cpu
ret
endp
iglobal
align 4
acpi_lapic_base dd 0xfee00000 ; default local apic base
endg
uglobal
align 4
acpi_rsdp rd 1
acpi_rsdt rd 1
acpi_madt rd 1
acpi_dev_data rd 1
acpi_dev_size rd 1
acpi_rsdt_base rd 1
acpi_fadt_base rd 1
acpi_dsdt_base rd 1
acpi_dsdt_size rd 1
acpi_madt_base rd 1
acpi_ioapic_base rd MAX_IOAPICS
acpi_hpet_base rd 1
hpet_base rd 1
hpet_period rd 1
hpet_timers rd 1
hpet_tsc_start rd 2
cpu_count rd 1
smpt rd 16
endg
ACPI_HI_RSDP_WINDOW_START = 0x000E0000
ACPI_HI_RSDP_WINDOW_END = 0x00100000
ACPI_RSDP_CHECKSUM_LENGTH = 20
ACPI_HPET_SIGN = 'HPET'
ACPI_MADT_SIGN = 'APIC'
ACPI_FADT_SIGN = 'FACP'
proc acpi_locate_tables uses ebx esi edi
mov ebx, [ebx+ACPI_RSDP.RsdtAddress]
mov [acpi_rsdt_base-OS_BASE], ebx
mov eax, [ebx+ACPI_RSDT.Length]
mov [acpi_rsdt_size-OS_BASE], eax
mov esi, [acpi_rsdt_base-OS_BASE]
mov ecx, [esi+ACPI_RSDT.Length]
lea edi, [esi+ecx]
add esi, sizeof.ACPI_TABLE
movi ecx, 1
.next_table:
cmp esi, edi
jae .done
lodsd
cmp [eax+ACPI_TABLE.Signature], 'SSDT' ; skip DSDT if present
jz .ssdt ; read it from FADT
cmp [eax+ACPI_TABLE.Signature], 'FACP' ; this is FADT
jz .fadt
cmp [eax+ACPI_TABLE.Signature], 'APIC' ; this is MADT
jz .madt
cmp [eax+ACPI_TABLE.Signature], 'HPET'
jz .hpet
jmp .next_table
.ssdt:
mov [acpi_ssdt_base+ecx*4-OS_BASE], eax
mov eax, [eax+ACPI_TABLE.Length]
mov [acpi_ssdt_size+ecx*4-OS_BASE], eax
inc ecx
jmp .next_table
.fadt:
mov [acpi_fadt_base-OS_BASE], eax
cmp [eax+ACPI_FADT.DSDT], 0
jz @f
mov edx, [eax+ACPI_FADT.DSDT]
mov [acpi_ssdt_base-OS_BASE], edx
mov edx, [edx+ACPI_TABLE.Length]
mov [acpi_ssdt_size-OS_BASE], edx
@@:
mov eax, [eax+ACPI_TABLE.Length]
mov [acpi_fadt_size-OS_BASE], eax
jmp .next_table
.madt:
mov [acpi_madt_base-OS_BASE], eax
mov eax, [eax+ACPI_TABLE.Length]
mov [acpi_madt_size-OS_BASE], eax
jmp .next_table
.hpet:
mov [acpi_hpet_base-OS_BASE], eax
mov eax, [eax+ACPI_TABLE.Length]
mov [acpi_hpet_size-OS_BASE], eax
jmp .next_table
.done:
mov [acpi_ssdt_cnt-OS_BASE], ecx
ret
endp
acpi_locate:
push ebx
@ -474,7 +497,11 @@ else
call .check
end if
.done:
mov eax, ebx
mov [acpi_rsdp_base-OS_BASE], ebx
test ebx, ebx
jz @f
call acpi_locate_tables
@@:
pop edi
pop ebx
ret
@ -502,185 +529,3 @@ end if
jb .check
xor ebx, ebx
ret
align 4
rsdt_find: ;ecx= rsdt edx= SIG
push ebx
push esi
lea ebx, [ecx+36]
mov esi, [ecx+4]
add esi, ecx
align 4
.next:
mov eax, [ebx]
cmp [eax], edx
je .done
add ebx, 4
cmp ebx, esi
jb .next
xor eax, eax
pop esi
pop ebx
ret
.done:
mov eax, [ebx]
pop esi
pop ebx
ret
align 4
check_acpi:
call acpi_locate
test eax, eax
jz .done
mov [acpi_rsdp-OS_BASE], eax
mov ecx, [eax+16]
mov edx, ACPI_FADT_SIGN
mov [acpi_rsdt_base-OS_BASE], ecx
call rsdt_find
mov [acpi_fadt_base-OS_BASE], eax
test eax, eax
jz @f
mov eax, [eax+40]
mov [acpi_dsdt_base-OS_BASE], eax
mov eax, [eax+4]
mov [acpi_dsdt_size-OS_BASE], eax
@@:
mov edx, ACPI_HPET_SIGN
mov ecx, [acpi_rsdt_base-OS_BASE]
call rsdt_find
test eax, eax
jz @F
mov [acpi_hpet_base-OS_BASE], eax
mov eax, [eax+44]
mov [hpet_base-OS_BASE], eax
@@:
mov edx, ACPI_MADT_SIGN
mov ecx, [acpi_rsdt_base-OS_BASE]
call rsdt_find
test eax, eax
jz .done
mov [acpi_madt_base-OS_BASE], eax
mov ecx, [eax+36]
mov [acpi_lapic_base-OS_BASE], ecx
mov edi, smpt-OS_BASE
mov ebx, [ecx+0x20]
shr ebx, 24 ; read APIC ID
mov [edi], ebx ; bootstrap always first
inc [cpu_count-OS_BASE]
add edi, 4
mov [ioapic_cnt-OS_BASE], 0
lea edx, [eax+44]
mov ecx, [eax+4]
add ecx, eax
.check:
mov eax, [edx]
cmp al, 0
je .lapic
cmp al, 1
je .io_apic
jmp .next
.lapic:
shr eax, 24 ; get APIC ID
cmp eax, ebx ; skip self
je .next
test [edx+4], byte 1 ; is enabled ?
jz .next
cmp [cpu_count-OS_BASE], 16
jae .next
stosd ; store APIC ID
inc [cpu_count-OS_BASE]
.next:
mov eax, [edx]
movzx eax, ah
add edx, eax
cmp edx, ecx
jb .check
.done:
ret
.io_apic:
mov eax, [ioapic_cnt-OS_BASE]
push dword[edx+4]
pop [acpi_ioapic_base-OS_BASE+eax*4]
push dword[edx+8]
pop [ioapic_gsi_base-OS_BASE+eax*4]
inc [ioapic_cnt-OS_BASE]
jmp .next
HPET_PERIOD = 0x0004
HPET_CFG_ENABLE = 0x0001
HPET_CFG = 0x0010
HPET_COUNTER = 0x00f0
HPET_T0_CFG = 0x0100
HPET_TN_LEVEL = 0x0002
HPET_TN_ENABLE = 0x0004
HPET_TN_FSB = 0x4000
align 4
init_hpet:
mov ebx, [hpet_base-OS_BASE]
test ebx, ebx
jz .done
mov eax, [ebx]
and ah, 0x1F
inc ah
movzx eax, ah
mov [hpet_timers-OS_BASE], eax
mov ecx, eax
mov eax, [ebx+HPET_PERIOD]
xor edx, edx
shld edx, eax, 10
shl eax, 10
mov esi, 1000000
div esi
mov [hpet_period-OS_BASE], eax
mov esi, [ebx+HPET_CFG]
and esi, not HPET_CFG_ENABLE
mov [ebx+HPET_CFG], esi ;stop main counter
lea edx, [ebx+HPET_T0_CFG]
@@:
jcxz @F
mov eax, [edx]
and eax, not (HPET_TN_ENABLE+HPET_TN_LEVEL+HPET_TN_FSB)
mov [edx], eax
add edx, 0x20
dec ecx
jmp @B
@@:
mov [ebx+HPET_COUNTER], ecx ;reset main counter
mov [ebx+HPET_COUNTER+4], ecx
or esi, HPET_CFG_ENABLE
mov [ebx+HPET_CFG], esi ;and start again
.done:
rdtsc
mov [hpet_tsc_start-OS_BASE], eax
mov [hpet_tsc_start+4-OS_BASE], edx
ret

View File

@ -210,8 +210,7 @@ B32:
call test_cpu
bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc
call check_acpi
call init_hpet
call acpi_locate
call init_BIOS32
; MEMORY MODEL
call mem_test
@ -552,14 +551,17 @@ high_code:
@@:
mov [clipboard_main_list], eax
call check_acpi
mov eax, [hpet_base]
test eax, eax
jz @F
mov eax, [hpet_base]
stdcall map_io_mem, [hpet_base], 1024, PG_GLOBAL+PAT_UC+PG_SWR
mov [hpet_base], eax
mov eax, [eax]
mov eax, [eax+HPET_ID]
DEBUGF 1, "K : HPET caps %x\n", eax
call init_hpet
@@:
; SET UP OS TASK
@ -892,7 +894,7 @@ include "detect/vortex86.inc" ; Vortex86 SoC detection code
mov ebx, [hpet_base]
test ebx, ebx
jz @F
mov ebx, [ebx+0xF0]
mov ebx, [ebx+HPET_COUNTER]
rdtsc
mov ecx, 1000

View File

@ -24,10 +24,13 @@ include "core/string.inc"
include "core/v86.inc" ; 16-bit mode machine
include "core/irq.inc" ; interrupt handling functions
include "core/apic.inc"
include "core/hpet.inc"
include "core/timers.inc"
include "core/clipboard.inc"
include "core/slab.inc"
include "acpi/acpi.inc"
include "posix/posix.inc"
include "boot/shutdown.inc" ; kernel shutdown