source: trunk/hal/x86_64/hal_lapic.c @ 45

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

Add some code for LAPIC; far from complete, but a good start.

File size: 1.6 KB
Line 
1/*
2 * hal_lapic.c - Local APIC
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_segmentation.h>
24#include <hal_lapic.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
36paddr_t lapic_pa __in_kdata = 0;
37vaddr_t lapic_va __in_kdata = 0;
38
39void lapic_write(uint32_t reg, uint32_t val)
40{
41        *((volatile uint32_t *)(lapic_va + reg)) = val;
42}
43
44uint32_t lapic_read(uint32_t reg)
45{
46        return *((volatile uint32_t *)(lapic_va + reg));
47}
48
49void hal_init_lapic()
50{
51        uint32_t id;
52
53        lapic_va = hal_gpt_bootstrap_valloc(1); // XXX: should be shared
54
55        hal_gpt_enter(lapic_va, lapic_pa);
56
57        lapic_write(LAPIC_TPR, 0);
58        lapic_write(LAPIC_SVR, LAPIC_SVR_ENABLE|LAPIC_SPURIOUS_VECTOR);
59
60        id = lapic_read(LAPIC_ID) >> LAPIC_ID_SHIFT;
61
62        x86_printf("-> LAPIC id: %d\n", id);
63}
64
Note: See TracBrowser for help on using the repository browser.