From f95c868e2f5feaef2bad367a54e5ec8d524ed1d9 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Mon, 19 Sep 2011 18:35:05 +0000 Subject: [PATCH] acpi: read ioapic & local apic bases git-svn-id: svn://kolibrios.org@2212 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/Kolibri-acpi/core/apic.inc | 26 ++-- kernel/branches/Kolibri-acpi/init.inc | 124 ++++++++++++++- kernel/branches/Kolibri-acpi/kernel.asm | 1 + kernel/branches/net/blkdev/cd_drv.inc | 8 +- kernel/branches/net/blkdev/hd_drv.inc | 31 +++- kernel/branches/net/blkdev/rd.inc | 6 + kernel/branches/net/blkdev/rdsave.inc | 6 +- kernel/branches/net/core/heap.inc | 3 - kernel/branches/net/core/memory.inc | 169 ++++++++++++++------- kernel/branches/net/video/vesa20.inc | 4 +- 10 files changed, 286 insertions(+), 92 deletions(-) diff --git a/kernel/branches/Kolibri-acpi/core/apic.inc b/kernel/branches/Kolibri-acpi/core/apic.inc index 235706cc89..d87c085eee 100644 --- a/kernel/branches/Kolibri-acpi/core/apic.inc +++ b/kernel/branches/Kolibri-acpi/core/apic.inc @@ -12,9 +12,9 @@ IRQ_COUNT dd 24 endg uglobal -APIC: dd 0 -LAPIC_BASE: dd 0 -IOAPIC_base: dd 0 +APIC rd 1 +IOAPIC_base rd 1 +LAPIC_BASE rd 1 endg APIC_ID equ 0x20 @@ -44,17 +44,15 @@ IOAPIC_REDTBL equ 0x10 APIC_init: mov dword[APIC], 0 - ; jmp .no_apic ; NO APIC -; bt [cpu_caps], CAPS_APIC -; jnc .no_apic - ; Check for MP table - ;..... + + mov eax, [acpi_ioapic_base] + test eax, eax + jz .no_apic call IRQ_mask_all ; IOAPIC init - ; 0xfec00000 - may be relocated, see chip reference... & MP table - stdcall map_io_mem, 0xfec00000, 0x20, PG_SW + stdcall map_io_mem, [acpi_ioapic_base], 0x20, PG_SW mov [IOAPIC_base], eax mov eax, IOAPIC_VER @@ -135,11 +133,11 @@ LAPIC_init: ; Check MSR support ;.... ; Get LAPIC base address - mov ecx, 0x1b - rdmsr ; it may be replaced to - and ax, 0xf000 ; mov eax, 0xfee00000 +; mov ecx, 0x1b +; rdmsr ; it may be replaced to +; 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 esi, eax diff --git a/kernel/branches/Kolibri-acpi/init.inc b/kernel/branches/Kolibri-acpi/init.inc index 6bf6bf8708..75b5f55222 100644 --- a/kernel/branches/Kolibri-acpi/init.inc +++ b/kernel/branches/Kolibri-acpi/init.inc @@ -141,7 +141,7 @@ proc init_mem mov [edx], eax 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" .no_PSE: mov eax, PG_SW @@ -165,7 +165,7 @@ proc init_mem mov eax, [tmp_page_tabs] or eax, PG_SW mov edi, edx - + .map_kernel_tabs: stosd add eax, 0x1000 @@ -330,7 +330,7 @@ init_BIOS32: ; здесь должна заполнятся pci_emu_dat .BIOS32_not_found: .end: - ret + ret align 4 proc test_cpu @@ -431,4 +431,122 @@ proc test_cpu ret 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 diff --git a/kernel/branches/Kolibri-acpi/kernel.asm b/kernel/branches/Kolibri-acpi/kernel.asm index 5153a316cc..c93fbb7c84 100644 --- a/kernel/branches/Kolibri-acpi/kernel.asm +++ b/kernel/branches/Kolibri-acpi/kernel.asm @@ -258,6 +258,7 @@ B32: call test_cpu bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc + call check_acpi call init_BIOS32 ; MEMORY MODEL call mem_test diff --git a/kernel/branches/net/blkdev/cd_drv.inc b/kernel/branches/net/blkdev/cd_drv.inc index 38f7c90684..bcc184d528 100644 --- a/kernel/branches/net/blkdev/cd_drv.inc +++ b/kernel/branches/net/blkdev/cd_drv.inc @@ -239,10 +239,10 @@ SendPacketDatCommand: in AL,DX test AL,80h ;состояние сигнала BSY jnz @@WaitDevice0 - test AL,08h ;состояние сигнала DRQ - jz @@WaitDevice0 test AL,1 ;состояние сигнала ERR jnz @@Err6 + test AL,08h ;состояние сигнала DRQ + jz @@WaitDevice0 ; Послать пакетную команду cli mov DX,[ATABasePortAddr] @@ -282,10 +282,10 @@ SendPacketDatCommand: in AL,DX test AL,80h ;состояние сигнала BSY jnz @@WaitDevice1 - test AL,08h ;состояние сигнала DRQ - jz @@WaitDevice1 test AL,1 ;состояние сигнала ERR jnz @@Err6_temp + test AL,08h ;состояние сигнала DRQ + jz @@WaitDevice1 ; Принять блок данных от контроллера mov EDI,[CDDataBuf_pointer] ;0x7000 ;CDDataBuf ; Загрузить адрес регистра данных контроллера diff --git a/kernel/branches/net/blkdev/hd_drv.inc b/kernel/branches/net/blkdev/hd_drv.inc index 016f4a2166..ab5af9362a 100644 --- a/kernel/branches/net/blkdev/hd_drv.inc +++ b/kernel/branches/net/blkdev/hd_drv.inc @@ -49,6 +49,12 @@ hd_read: ; Read through BIOS? cmp [hdpos], 0x80 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 cmp [allow_dma_access], 2 ja .nodma @@ -235,6 +241,8 @@ hd_write: align 4 cache_write_pio: + cmp dword[esi],0x10000000 + jae .bad ; call disable_ide_int call wait_for_hd_idle @@ -295,6 +303,9 @@ cache_write_pio: pop esi ecx ret +.bad: + inc [hd_error] + ret save_hd_wait_timeout: @@ -686,6 +697,9 @@ write_cache_sector: write_cache_chain: cmp [hdpos], 0x80 jae bd_write_cache_chain + mov eax,[cache_chain_ptr] + cmp dword[eax],0x10000000 + jae .bad push esi mov eax, IDE_descriptor_table mov edx,eax @@ -779,6 +793,9 @@ write_cache_chain: jnz hd_write_error_dma pop esi ret +.bad: + inc [hd_error] + ret uglobal IDEContrRegsBaseAddr dw ? @@ -882,11 +899,11 @@ int13_call: ; Because this code uses fixed addresses, ; it can not be run simultaniously by many threads. ; In current implementation it is protected by common mutex 'hd1_status' - mov word [BOOT_VAR + 510h], 10h ; packet length - mov word [BOOT_VAR + 512h], cx ; number of sectors - mov dword [BOOT_VAR + 514h], 9A000000h ; buffer 9A00:0000 - mov dword [BOOT_VAR + 518h], eax - and dword [BOOT_VAR + 51Ch], 0 + mov word [OS_BASE + 510h], 10h ; packet length + mov word [OS_BASE + 512h], cx ; number of sectors + mov dword [OS_BASE + 514h], 9A000000h ; buffer 9A00:0000 + mov dword [OS_BASE + 518h], eax + and dword [OS_BASE + 51Ch], 0 push ebx ecx esi edi mov ebx, int13_regs_in mov edi, ebx @@ -916,10 +933,12 @@ int13_call: mov [ebx+v86_regs.eflags], 20200h mov esi, [sys_v86_machine] mov ecx, 0x502 + push fs call v86_start + pop fs and [bios_hdpos], 0 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 jnz @f mov edx, ecx diff --git a/kernel/branches/net/blkdev/rd.inc b/kernel/branches/net/blkdev/rd.inc index 2b6b49d12d..8227c20b1b 100644 --- a/kernel/branches/net/blkdev/rd.inc +++ b/kernel/branches/net/blkdev/rd.inc @@ -411,6 +411,8 @@ char_toupper: jb .ret cmp al, 'z' jbe .az + cmp al, 'с' + jz .yo1 cmp al, ' ' jb .ret cmp al, 'а' @@ -426,6 +428,10 @@ char_toupper: .az: and al, not 0x20 ret +.yo1: +; 0xF1 -> 0xF0 + dec ax + ret fat_get_name: ; in: edi->FAT entry diff --git a/kernel/branches/net/blkdev/rdsave.inc b/kernel/branches/net/blkdev/rdsave.inc index 2e9396e415..158704e2d5 100644 --- a/kernel/branches/net/blkdev/rdsave.inc +++ b/kernel/branches/net/blkdev/rdsave.inc @@ -21,12 +21,10 @@ saverd_fileinfo: endg sysfn_saveramdisk: ; 18.6 = SAVE FLOPPY IMAGE (HD version only) call restorefatchain - mov eax, saverd_fileinfo + mov ebx, saverd_fileinfo mov [saverd_fileinfo.name], ecx pushad - push eax - call file_system_lfn - pop eax + call file_system_lfn ;in ebx popad mov [esp+32], eax ret diff --git a/kernel/branches/net/core/heap.inc b/kernel/branches/net/core/heap.inc index 03d914459c..e9d9ed7125 100644 --- a/kernel/branches/net/core/heap.inc +++ b/kernel/branches/net/core/heap.inc @@ -538,7 +538,6 @@ proc kernel_alloc stdcall, size:dword push ebx push edi - push edx mov eax, [size] add eax, 4095 @@ -594,13 +593,11 @@ proc kernel_alloc stdcall, size:dword jnz @B .end: mov eax, [lin_addr] - pop edx pop edi pop ebx ret .err: xor eax, eax - pop edx pop edi pop ebx ret diff --git a/kernel/branches/net/core/memory.inc b/kernel/branches/net/core/memory.inc index 611fd87ecc..963f878a62 100644 --- a/kernel/branches/net/core/memory.inc +++ b/kernel/branches/net/core/memory.inc @@ -14,6 +14,11 @@ proc alloc_page pushfd cli push ebx +;//- + cmp [pg_data.pages_free], 1 + jle .out_of_memory +;//- + mov ebx, [page_start] mov ecx, [page_end] .l1: @@ -27,15 +32,27 @@ proc alloc_page xor eax,eax ret .found: +;//- + dec [pg_data.pages_free] + jz .out_of_memory +;//- btr [ebx], eax mov [page_start],ebx sub ebx, sys_pgmap lea eax, [eax+ebx*8] shl eax, 12 - dec [pg_data.pages_free] +;//- dec [pg_data.pages_free] pop ebx popfd ret +;//- +.out_of_memory: + mov [pg_data.pages_free], 1 + xor eax, eax + pop ebx + popfd + ret +;//- endp align 4 @@ -48,9 +65,14 @@ proc alloc_pages stdcall, count:dword add eax, 7 shr eax, 3 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 ebx, [page_end] .find: @@ -64,6 +86,7 @@ proc alloc_pages stdcall, count:dword inc ecx cmp ecx,ebx jb .match +.out_of_memory: .fail: xor eax, eax pop edi @@ -479,6 +502,15 @@ proc new_mem_resize stdcall, new_size:dword cmp edi, esi jb @B .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 esi @@: @@ -500,7 +532,10 @@ proc new_mem_resize stdcall, new_size:dword jb @B jmp .update_size +;//- .exit_pop: +.out_of_memory: +;//- pop edi pop esi .exit: @@ -914,53 +949,72 @@ endp sys_IPC: ;input: -; eax=1 - set ipc buffer area -; ebx=address of buffer -; ecx=size of buffer +; ebx=1 - set ipc buffer area +; ecx=address of buffer +; edx=size of buffer ; eax=2 - send message ; ebx=PID ; ecx=address of message ; edx=size of message - cmp eax,1 - jne @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 + dec ebx + jnz @f mov eax,[current_slot] pushf cli - mov [eax+APPDATA.ipc_start],ebx ;set fields in extended information area - mov [eax+APPDATA.ipc_size],ecx + mov [eax+APPDATA.ipc_start],ecx ;set fields in extended information area + mov [eax+APPDATA.ipc_size],edx - add ecx, ebx - add ecx, 4095 - and ecx, not 4095 + add edx, ecx + add edx, 4095 + and edx, not 4095 -.touch: mov eax, [ebx] - add ebx, 0x1000 - cmp ebx, ecx +.touch: mov eax, [ecx] + add ecx, 0x1000 + cmp ecx, edx jb .touch popf - xor eax, eax + mov [esp+32], ebx ;ebx=0 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 locals @@ -1112,25 +1166,7 @@ sysfn_meminfo: .fail: or dword [esp+32], -1 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 f68: cmp ebx,4 @@ -1250,6 +1286,27 @@ f68: mov [esp+32], eax 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 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] dec ebx mov eax, 0xFFFFFFFF - mov edx, 0x0000000F + mov edx, 0x00000000 sub eax, ebx sbb edx, 0 or eax, 0x800 diff --git a/kernel/branches/net/video/vesa20.inc b/kernel/branches/net/video/vesa20.inc index 0a2d130fb7..7b035c8ffe 100644 --- a/kernel/branches/net/video/vesa20.inc +++ b/kernel/branches/net/video/vesa20.inc @@ -1008,8 +1008,8 @@ sdpdone: uglobal align 4 -bgr_cur_line rd 1280 ; maximum width of screen -bgr_next_line rd 1280 +bgr_cur_line rd 1920 ; maximum width of screen +bgr_next_line rd 1920 endg smooth_line: