From e06410d094cd3a47fe44a25eaa0715c39a762699 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Wed, 21 Sep 2011 09:13:47 +0000 Subject: [PATCH] merge acpi #2217 git-svn-id: svn://kolibrios.org@2218 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/core/memory.inc | 7 ++- kernel/trunk/init.inc | 116 +++++++++++++++++++++++++++++++++++ kernel/trunk/kernel.asm | 1 + 3 files changed, 122 insertions(+), 2 deletions(-) diff --git a/kernel/trunk/core/memory.inc b/kernel/trunk/core/memory.inc index 01f9aedd4c..9cd24427e5 100644 --- a/kernel/trunk/core/memory.inc +++ b/kernel/trunk/core/memory.inc @@ -171,9 +171,14 @@ proc map_io_mem stdcall, base:dword, size:dword, flags:dword push ebx push edi mov eax, [size] + add eax, [base] add eax, 4095 and eax, -4096 + mov ecx, [base] + and ecx, -4096 + sub eax, ecx mov [size], eax + stdcall alloc_kernel_space, eax test eax, eax jz .fail @@ -189,9 +194,7 @@ proc map_io_mem stdcall, base:dword, size:dword, flags:dword or edx, [flags] @@: mov [page_tabs+eax*4], edx - ; push eax invlpg [ebx] - ; pop eax inc eax add ebx, edi add edx, edi diff --git a/kernel/trunk/init.inc b/kernel/trunk/init.inc index bff3c0f049..992e4adff3 100644 --- a/kernel/trunk/init.inc +++ b/kernel/trunk/init.inc @@ -431,4 +431,120 @@ 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: + + 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/trunk/kernel.asm b/kernel/trunk/kernel.asm index 5eb6dc103a..fe29ea838e 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/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