source: trunk/hal/x86_64/core/hal_lapic.c @ 67

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

Create the core/ sub-directory for x86_64.

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 hal_lapic_write(uint32_t reg, uint32_t val)
40{
41        *((volatile uint32_t *)(lapic_va + reg)) = val;
42}
43
44uint32_t hal_lapic_read(uint32_t reg)
45{
46        return *((volatile uint32_t *)(lapic_va + reg));
47}
48
49uint32_t hal_lapic_gid()
50{
51        return hal_lapic_read(LAPIC_ID) >> LAPIC_ID_SHIFT;
52}
53
54void hal_lapic_init()
55{
56        lapic_va = hal_gpt_bootstrap_valloc(1); // XXX: should be shared
57
58        hal_gpt_enter(lapic_va, lapic_pa);
59
60        hal_lapic_write(LAPIC_TPR, 0);
61        hal_lapic_write(LAPIC_SVR, LAPIC_SVR_ENABLE|LAPIC_SPURIOUS_VECTOR);
62}
63
Note: See TracBrowser for help on using the repository browser.