source: trunk/hal/x86_64/hal_acpi.c @ 38

Last change on this file since 38 was 35, checked in by max@…, 7 years ago

Update:

  • Introduce a basic VM manager in hal_gpt.c, to create the initial page tree for cluster0.
  • Locate the ACPI RSDP table, which involves entering the PA into cluster0's VA space.

The definitions are still a bit messy, but they will be reorganized later.

File size: 2.6 KB
Line 
1/*
2 * hal_acpi.c - ACPI parser
3 *
4 * Copyright (c) 2017 Maxime Villard
5 *
6 * This file is part of ALMOS-MKH.
7 *
8 * ALMOS-MKH is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.0 of the License.
11 *
12 * ALMOS-MKH is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <hal_types.h>
23#include <hal_boot.h>
24#include <hal_acpi.h>
25#include <hal_internal.h>
26
27#include <memcpy.h>
28#include <thread.h>
29#include <string.h>
30#include <process.h>
31#include <printk.h>
32#include <vmm.h>
33#include <core.h>
34#include <cluster.h>
35
36
37/* XXX XXX libk XXX XXX */
38int memcmp(char *s1, char *s2, size_t n)
39{
40        size_t i;
41        for(i = 0; i < n; i++) {
42                if (s1[i] != s2[i])
43                        return 1;
44        }
45        return 0;
46}
47
48static bool_t hal_acpi_rsdp_correct(uint8_t *ptr)
49{
50        uint8_t sum = 0;
51        size_t i;
52
53        /* Verify checksum */
54        for (i = 0; i < 20; i++) {
55                sum += ptr[i];
56        }
57
58        return (sum == 0);
59}
60
61static void *hal_acpi_find_rsdp(vaddr_t va_start, vaddr_t va_end)
62{
63        rsdp_t *rsdp;
64        vaddr_t va = va_start;
65        size_t i, n = PAGE_SIZE / ACPI_RSDP_ALIGN;
66        char oem[ACPI_OEM_ID_SIZE + 1];
67        uint8_t *ptr;
68
69        /* The table is on a 16bit boundary */
70        for (va = va_start; va < va_end; va += PAGE_SIZE) {
71                for (i = 0; i < n; i++) {
72                        ptr = (uint8_t *)va + i * ACPI_RSDP_ALIGN;
73                        if (memcmp(ptr, ACPI_RSDP_SIGNATURE, ACPI_RSDP_SIGNATURE_SIZE))
74                                continue;
75                        if (!hal_acpi_rsdp_correct(ptr))
76                                continue;
77                        goto found;
78                }
79        }
80
81        return NULL;
82
83found:
84        rsdp = (rsdp_t *)ptr;
85
86        x86_printf("-> rsdp = %Z\n", rsdp);
87        memcpy(&oem, rsdp->OemId, ACPI_OEM_ID_SIZE);
88        oem[ACPI_OEM_ID_SIZE] = '\0';
89        x86_printf("-> OEM: %s\n", oem);
90
91        return rsdp;
92}
93
94void hal_acpi_init()
95{
96        rsdp_t *rsdp;
97        paddr_t bios_min = 0x0E0000;
98        paddr_t bios_max = 0x100000;
99        vaddr_t vabase;
100        vaddr_t va;
101        paddr_t pa;
102        size_t i, npages;
103
104        npages = (bios_max - bios_min) / PAGE_SIZE;
105        vabase = hal_gpt_bootstrap_valloc(npages);
106
107        for (i = 0; i < npages; i++) {
108                va = vabase + i * PAGE_SIZE;
109                pa = bios_min + i * PAGE_SIZE;
110                hal_gpt_enter(va, pa);
111                invlpg(va);
112        }
113
114        /* First, find RSDP */
115        rsdp = hal_acpi_find_rsdp(vabase, vabase + npages * PAGE_SIZE);
116        if (rsdp == NULL) {
117                x86_printf("[!] RSDP not found\n");
118        }
119}
120
Note: See TracBrowser for help on using the repository browser.