acpi: read ioapic & local apic bases

git-svn-id: svn://kolibrios.org@2212 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2011-09-19 18:35:05 +00:00
parent 39db646ff8
commit f95c868e2f
10 changed files with 286 additions and 92 deletions

View File

@ -12,9 +12,9 @@ IRQ_COUNT dd 24
endg endg
uglobal uglobal
APIC: dd 0 APIC rd 1
LAPIC_BASE: dd 0 IOAPIC_base rd 1
IOAPIC_base: dd 0 LAPIC_BASE rd 1
endg endg
APIC_ID equ 0x20 APIC_ID equ 0x20
@ -44,17 +44,15 @@ IOAPIC_REDTBL equ 0x10
APIC_init: APIC_init:
mov dword[APIC], 0 mov dword[APIC], 0
; jmp .no_apic ; NO APIC
; bt [cpu_caps], CAPS_APIC mov eax, [acpi_ioapic_base]
; jnc .no_apic test eax, eax
; Check for MP table jz .no_apic
;.....
call IRQ_mask_all call IRQ_mask_all
; IOAPIC init ; IOAPIC init
; 0xfec00000 - may be relocated, see chip reference... & MP table stdcall map_io_mem, [acpi_ioapic_base], 0x20, PG_SW
stdcall map_io_mem, 0xfec00000, 0x20, PG_SW
mov [IOAPIC_base], eax mov [IOAPIC_base], eax
mov eax, IOAPIC_VER mov eax, IOAPIC_VER
@ -135,11 +133,11 @@ LAPIC_init:
; Check MSR support ; Check MSR support
;.... ;....
; Get LAPIC base address ; Get LAPIC base address
mov ecx, 0x1b ; mov ecx, 0x1b
rdmsr ; it may be replaced to ; rdmsr ; it may be replaced to
and ax, 0xf000 ; mov eax, 0xfee00000 ; and ax, 0xf000 ; mov eax, 0xfee00000
stdcall map_io_mem, eax, 0x1000, PG_SW stdcall map_io_mem, [acpi_lapic_base], 0x1000, PG_SW
mov [LAPIC_BASE], eax mov [LAPIC_BASE], eax
mov esi, eax mov esi, eax

View File

@ -141,7 +141,7 @@ proc init_mem
mov [edx], eax mov [edx], eax
add edx, 4 add edx, 4
mov edi, [tmp_page_tabs] mov edi, [tmp_page_tabs]
jmp .map_kernel_heap ; new kernel fits to the first 4Mb - nothing to do with ".map_low" jmp .map_kernel_heap ; new kernel fits to the first 4Mb - nothing to do with ".map_low"
.no_PSE: .no_PSE:
mov eax, PG_SW mov eax, PG_SW
@ -165,7 +165,7 @@ proc init_mem
mov eax, [tmp_page_tabs] mov eax, [tmp_page_tabs]
or eax, PG_SW or eax, PG_SW
mov edi, edx mov edi, edx
.map_kernel_tabs: .map_kernel_tabs:
stosd stosd
add eax, 0x1000 add eax, 0x1000
@ -330,7 +330,7 @@ init_BIOS32:
; çäåñü äîëæíà çàïîëíÿòñÿ pci_emu_dat ; çäåñü äîëæíà çàïîëíÿòñÿ pci_emu_dat
.BIOS32_not_found: .BIOS32_not_found:
.end: .end:
ret ret
align 4 align 4
proc test_cpu proc test_cpu
@ -431,4 +431,122 @@ proc test_cpu
ret ret
endp endp
uglobal
align 4
acpi_rsdp rd 1
acpi_rsdt rd 1
acpi_madt rd 1
acpi_rsdt_base rd 1
acpi_madt_base rd 1
acpi_lapic_base rd 1
acpi_ioapic_base rd 1
endg
ACPI_HI_RSDP_WINDOW_START equ 0x000E0000
ACPI_HI_RSDP_WINDOW_END equ 0x00100000
ACPI_RSDP_CHECKSUM_LENGTH equ 20
ACPI_MADT_SIGN equ 0x43495041
acpi_locate:
push ebx
mov ebx, ACPI_HI_RSDP_WINDOW_START
.check:
cmp [ebx], dword 0x20445352
jne .next
cmp [ebx+4], dword 0x20525450
jne .next
mov edx, ebx
mov ecx, ACPI_RSDP_CHECKSUM_LENGTH
xor eax, eax
.sum:
add al, [edx]
inc edx
loop .sum
test al, al
jnz .next
mov eax, ebx
pop ebx
ret
.next:
add ebx, 16
cmp ebx, ACPI_HI_RSDP_WINDOW_END
jb .check
pop ebx
xor eax, eax
ret
align 4
rsdt_find: ;ecx= rsdt edx= SIG
push ebx
push esi
lea ebx, [ecx+36]
mov esi, [ecx+4]
add esi, ecx
.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:
xchg bx, bx
call acpi_locate
test eax, eax
jz .done
mov ecx, [eax+16]
mov edx, ACPI_MADT_SIGN
mov [acpi_rsdt_base-OS_BASE], ecx
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
lea edx, [eax+44]
mov ecx, [eax+4]
add ecx, eax
.check:
mov eax, [edx]
cmp al, 1
je .ioapic
.next:
movzx eax, ah
add edx, eax
cmp edx, ecx
jb .check
.done:
ret
.ioapic:
mov eax, [edx+4]
mov [acpi_ioapic_base-OS_BASE], eax
ret

View File

@ -258,6 +258,7 @@ B32:
call test_cpu call test_cpu
bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc
call check_acpi
call init_BIOS32 call init_BIOS32
; MEMORY MODEL ; MEMORY MODEL
call mem_test call mem_test

View File

@ -239,10 +239,10 @@ SendPacketDatCommand:
in AL,DX in AL,DX
test AL,80h ;состояние сигнала BSY test AL,80h ;состояние сигнала BSY
jnz @@WaitDevice0 jnz @@WaitDevice0
test AL,08h ;состояние сигнала DRQ
jz @@WaitDevice0
test AL,1 ;состояние сигнала ERR test AL,1 ;состояние сигнала ERR
jnz @@Err6 jnz @@Err6
test AL,08h ;состояние сигнала DRQ
jz @@WaitDevice0
; Послать пакетную команду ; Послать пакетную команду
cli cli
mov DX,[ATABasePortAddr] mov DX,[ATABasePortAddr]
@ -282,10 +282,10 @@ SendPacketDatCommand:
in AL,DX in AL,DX
test AL,80h ;состояние сигнала BSY test AL,80h ;состояние сигнала BSY
jnz @@WaitDevice1 jnz @@WaitDevice1
test AL,08h ;состояние сигнала DRQ
jz @@WaitDevice1
test AL,1 ;состояние сигнала ERR test AL,1 ;состояние сигнала ERR
jnz @@Err6_temp jnz @@Err6_temp
test AL,08h ;состояние сигнала DRQ
jz @@WaitDevice1
; Принять блок данных от контроллера ; Принять блок данных от контроллера
mov EDI,[CDDataBuf_pointer] ;0x7000 ;CDDataBuf mov EDI,[CDDataBuf_pointer] ;0x7000 ;CDDataBuf
; Загрузить адрес регистра данных контроллера ; Загрузить адрес регистра данных контроллера

View File

@ -49,6 +49,12 @@ hd_read:
; Read through BIOS? ; Read through BIOS?
cmp [hdpos], 0x80 cmp [hdpos], 0x80
jae .bios jae .bios
; hd_read_{dma,pio} use old ATA with 28 bit for sector number
cmp eax, 0x10000000
jb @f
inc [hd_error]
jmp return_01
@@:
; DMA read is permitted if [allow_dma_access]=1 or 2 ; DMA read is permitted if [allow_dma_access]=1 or 2
cmp [allow_dma_access], 2 cmp [allow_dma_access], 2
ja .nodma ja .nodma
@ -235,6 +241,8 @@ hd_write:
align 4 align 4
cache_write_pio: cache_write_pio:
cmp dword[esi],0x10000000
jae .bad
; call disable_ide_int ; call disable_ide_int
call wait_for_hd_idle call wait_for_hd_idle
@ -295,6 +303,9 @@ cache_write_pio:
pop esi ecx pop esi ecx
ret ret
.bad:
inc [hd_error]
ret
save_hd_wait_timeout: save_hd_wait_timeout:
@ -686,6 +697,9 @@ write_cache_sector:
write_cache_chain: write_cache_chain:
cmp [hdpos], 0x80 cmp [hdpos], 0x80
jae bd_write_cache_chain jae bd_write_cache_chain
mov eax,[cache_chain_ptr]
cmp dword[eax],0x10000000
jae .bad
push esi push esi
mov eax, IDE_descriptor_table mov eax, IDE_descriptor_table
mov edx,eax mov edx,eax
@ -779,6 +793,9 @@ write_cache_chain:
jnz hd_write_error_dma jnz hd_write_error_dma
pop esi pop esi
ret ret
.bad:
inc [hd_error]
ret
uglobal uglobal
IDEContrRegsBaseAddr dw ? IDEContrRegsBaseAddr dw ?
@ -882,11 +899,11 @@ int13_call:
; Because this code uses fixed addresses, ; Because this code uses fixed addresses,
; it can not be run simultaniously by many threads. ; it can not be run simultaniously by many threads.
; In current implementation it is protected by common mutex 'hd1_status' ; In current implementation it is protected by common mutex 'hd1_status'
mov word [BOOT_VAR + 510h], 10h ; packet length mov word [OS_BASE + 510h], 10h ; packet length
mov word [BOOT_VAR + 512h], cx ; number of sectors mov word [OS_BASE + 512h], cx ; number of sectors
mov dword [BOOT_VAR + 514h], 9A000000h ; buffer 9A00:0000 mov dword [OS_BASE + 514h], 9A000000h ; buffer 9A00:0000
mov dword [BOOT_VAR + 518h], eax mov dword [OS_BASE + 518h], eax
and dword [BOOT_VAR + 51Ch], 0 and dword [OS_BASE + 51Ch], 0
push ebx ecx esi edi push ebx ecx esi edi
mov ebx, int13_regs_in mov ebx, int13_regs_in
mov edi, ebx mov edi, ebx
@ -916,10 +933,12 @@ int13_call:
mov [ebx+v86_regs.eflags], 20200h mov [ebx+v86_regs.eflags], 20200h
mov esi, [sys_v86_machine] mov esi, [sys_v86_machine]
mov ecx, 0x502 mov ecx, 0x502
push fs
call v86_start call v86_start
pop fs
and [bios_hdpos], 0 and [bios_hdpos], 0
pop edi esi ecx ebx pop edi esi ecx ebx
movzx edx, byte [BOOT_VAR + 512h] movzx edx, byte [OS_BASE + 512h]
test byte [int13_regs_out+v86_regs.eflags], 1 test byte [int13_regs_out+v86_regs.eflags], 1
jnz @f jnz @f
mov edx, ecx mov edx, ecx

View File

@ -411,6 +411,8 @@ char_toupper:
jb .ret jb .ret
cmp al, 'z' cmp al, 'z'
jbe .az jbe .az
cmp al, 'ñ'
jz .yo1
cmp al, ' ' cmp al, ' '
jb .ret jb .ret
cmp al, 'à' cmp al, 'à'
@ -426,6 +428,10 @@ char_toupper:
.az: .az:
and al, not 0x20 and al, not 0x20
ret ret
.yo1:
; 0xF1 -> 0xF0
dec ax
ret
fat_get_name: fat_get_name:
; in: edi->FAT entry ; in: edi->FAT entry

View File

@ -21,12 +21,10 @@ saverd_fileinfo:
endg endg
sysfn_saveramdisk: ; 18.6 = SAVE FLOPPY IMAGE (HD version only) sysfn_saveramdisk: ; 18.6 = SAVE FLOPPY IMAGE (HD version only)
call restorefatchain call restorefatchain
mov eax, saverd_fileinfo mov ebx, saverd_fileinfo
mov [saverd_fileinfo.name], ecx mov [saverd_fileinfo.name], ecx
pushad pushad
push eax call file_system_lfn ;in ebx
call file_system_lfn
pop eax
popad popad
mov [esp+32], eax mov [esp+32], eax
ret ret

View File

@ -538,7 +538,6 @@ proc kernel_alloc stdcall, size:dword
push ebx push ebx
push edi push edi
push edx
mov eax, [size] mov eax, [size]
add eax, 4095 add eax, 4095
@ -594,13 +593,11 @@ proc kernel_alloc stdcall, size:dword
jnz @B jnz @B
.end: .end:
mov eax, [lin_addr] mov eax, [lin_addr]
pop edx
pop edi pop edi
pop ebx pop ebx
ret ret
.err: .err:
xor eax, eax xor eax, eax
pop edx
pop edi pop edi
pop ebx pop ebx
ret ret

View File

@ -14,6 +14,11 @@ proc alloc_page
pushfd pushfd
cli cli
push ebx push ebx
;//-
cmp [pg_data.pages_free], 1
jle .out_of_memory
;//-
mov ebx, [page_start] mov ebx, [page_start]
mov ecx, [page_end] mov ecx, [page_end]
.l1: .l1:
@ -27,15 +32,27 @@ proc alloc_page
xor eax,eax xor eax,eax
ret ret
.found: .found:
;//-
dec [pg_data.pages_free]
jz .out_of_memory
;//-
btr [ebx], eax btr [ebx], eax
mov [page_start],ebx mov [page_start],ebx
sub ebx, sys_pgmap sub ebx, sys_pgmap
lea eax, [eax+ebx*8] lea eax, [eax+ebx*8]
shl eax, 12 shl eax, 12
dec [pg_data.pages_free] ;//- dec [pg_data.pages_free]
pop ebx pop ebx
popfd popfd
ret ret
;//-
.out_of_memory:
mov [pg_data.pages_free], 1
xor eax, eax
pop ebx
popfd
ret
;//-
endp endp
align 4 align 4
@ -48,9 +65,14 @@ proc alloc_pages stdcall, count:dword
add eax, 7 add eax, 7
shr eax, 3 shr eax, 3
mov [count], eax mov [count], eax
cmp eax, [pg_data.pages_free] ;//-
ja .fail mov ebx, [pg_data.pages_free]
sub ebx, 9
js .out_of_memory
shr ebx, 3
cmp eax, ebx
jg .out_of_memory
;//-
mov ecx, [page_start] mov ecx, [page_start]
mov ebx, [page_end] mov ebx, [page_end]
.find: .find:
@ -64,6 +86,7 @@ proc alloc_pages stdcall, count:dword
inc ecx inc ecx
cmp ecx,ebx cmp ecx,ebx
jb .match jb .match
.out_of_memory:
.fail: .fail:
xor eax, eax xor eax, eax
pop edi pop edi
@ -479,6 +502,15 @@ proc new_mem_resize stdcall, new_size:dword
cmp edi, esi cmp edi, esi
jb @B jb @B
.grow: .grow:
;//-
pop edi
push edi
mov esi, [pg_data.pages_free]
sub esi, 1
shr edi, 12
cmp esi, edi
jle .out_of_memory
;//-
pop edi pop edi
pop esi pop esi
@@: @@:
@ -500,7 +532,10 @@ proc new_mem_resize stdcall, new_size:dword
jb @B jb @B
jmp .update_size jmp .update_size
;//-
.exit_pop: .exit_pop:
.out_of_memory:
;//-
pop edi pop edi
pop esi pop esi
.exit: .exit:
@ -914,53 +949,72 @@ endp
sys_IPC: sys_IPC:
;input: ;input:
; eax=1 - set ipc buffer area ; ebx=1 - set ipc buffer area
; ebx=address of buffer ; ecx=address of buffer
; ecx=size of buffer ; edx=size of buffer
; eax=2 - send message ; eax=2 - send message
; ebx=PID ; ebx=PID
; ecx=address of message ; ecx=address of message
; edx=size of message ; edx=size of message
cmp eax,1 dec ebx
jne @f jnz @f
call set_ipc_buff
mov [esp+36], eax
ret
@@:
cmp eax, 2
jne @f
stdcall sys_ipc_send, ebx, ecx, edx
mov [esp+36], eax
ret
@@:
xor eax, eax
not eax
mov [esp+36], eax
ret
align 4
proc set_ipc_buff
mov eax,[current_slot] mov eax,[current_slot]
pushf pushf
cli cli
mov [eax+APPDATA.ipc_start],ebx ;set fields in extended information area mov [eax+APPDATA.ipc_start],ecx ;set fields in extended information area
mov [eax+APPDATA.ipc_size],ecx mov [eax+APPDATA.ipc_size],edx
add ecx, ebx add edx, ecx
add ecx, 4095 add edx, 4095
and ecx, not 4095 and edx, not 4095
.touch: mov eax, [ebx] .touch: mov eax, [ecx]
add ebx, 0x1000 add ecx, 0x1000
cmp ebx, ecx cmp ecx, edx
jb .touch jb .touch
popf popf
xor eax, eax mov [esp+32], ebx ;ebx=0
ret ret
endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;2
@@:
dec ebx
jnz @f
stdcall sys_ipc_send, ecx, edx, esi
mov [esp+32], eax
ret
@@:
or eax,-1
mov [esp+32], eax
ret
;align 4
;proc set_ipc_buff
; mov eax,[current_slot]
; pushf
; cli
; mov [eax+APPDATA.ipc_start],ebx ;set fields in extended information area
; mov [eax+APPDATA.ipc_size],ecx
;
; add ecx, ebx
; add ecx, 4095
; and ecx, not 4095
;
;.touch: mov eax, [ebx]
; add ebx, 0x1000
; cmp ebx, ecx
; jb .touch
;
; popf
; xor eax, eax
; ret
;endp
proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
locals locals
@ -1112,25 +1166,7 @@ sysfn_meminfo:
.fail: .fail:
or dword [esp+32], -1 or dword [esp+32], -1
ret ret
iglobal
align 4
f68call:
dd f68.11 ; init_heap
dd f68.12 ; user_alloc
dd f68.13 ; user_free
dd f68.14 ; get_event_ex
dd f68.fail ;moved to f68.24
dd f68.16 ; get_service
dd f68.17 ; call_service
dd f68.fail ;moved to f68.25
dd f68.19 ; load_dll
dd f68.20 ; user_realloc
dd f68.21 ; load_driver
dd f68.22 ; shmem_open
dd f68.23 ; shmem_close
dd f68.24
dd f68.25
endg
align 4 align 4
f68: f68:
cmp ebx,4 cmp ebx,4
@ -1250,6 +1286,27 @@ f68:
mov [esp+32], eax mov [esp+32], eax
ret ret
align 4
f68call: ; keep this table closer to main code
dd f68.11 ; init_heap
dd f68.12 ; user_alloc
dd f68.13 ; user_free
dd f68.14 ; get_event_ex
dd f68.fail ; moved to f68.24
dd f68.16 ; get_service
dd f68.17 ; call_service
dd f68.fail ; moved to f68.25
dd f68.19 ; load_dll
dd f68.20 ; user_realloc
dd f68.21 ; load_driver
dd f68.22 ; shmem_open
dd f68.23 ; shmem_close
dd f68.24
dd f68.25
align 4 align 4
proc load_pe_driver stdcall, file:dword proc load_pe_driver stdcall, file:dword
@ -1369,7 +1426,7 @@ proc set_mtrr stdcall, base:dword,size:dword,mem_type:dword
mov ebx, [size] mov ebx, [size]
dec ebx dec ebx
mov eax, 0xFFFFFFFF mov eax, 0xFFFFFFFF
mov edx, 0x0000000F mov edx, 0x00000000
sub eax, ebx sub eax, ebx
sbb edx, 0 sbb edx, 0
or eax, 0x800 or eax, 0x800

View File

@ -1008,8 +1008,8 @@ sdpdone:
uglobal uglobal
align 4 align 4
bgr_cur_line rd 1280 ; maximum width of screen bgr_cur_line rd 1920 ; maximum width of screen
bgr_next_line rd 1280 bgr_next_line rd 1920
endg endg
smooth_line: smooth_line: