feat: added missing lapic code

This commit is contained in:
2021-08-30 19:58:50 +02:00
parent e37222c346
commit e693b12915
2 changed files with 53 additions and 0 deletions

23
include/myke/cpu/lapic.h Normal file
View File

@@ -0,0 +1,23 @@
//
// Created by rick on 23-08-21.
//
#ifndef NEW_KERNEL_LAPIC_H
#define NEW_KERNEL_LAPIC_H
#include <sys/types.h>
#define LAPIC_REG_ID 0x20
#define LAPIC_REG_VERSION 0x30
void lapic_set_addr(uint32_t addr);
void lapic_write(uint32_t offset, uint32_t value);
uint32_t lapic_read(uint32_t offset);
uint32_t lapic_get_id();
uint32_t lapic_get_version();
#endif //NEW_KERNEL_LAPIC_H

30
kernel/cpu/lapic.c Normal file
View File

@@ -0,0 +1,30 @@
//
// Created by rick on 23-08-21.
//
#include <myke/cpu/lapic.h>
void *lapic = NULL;
void lapic_set_addr(uint32_t addr) {
lapic = (void *) addr;
}
void lapic_write(uint32_t offset, uint32_t value) {
*(volatile uint32_t *) ((uintptr_t) lapic + offset) = value;
}
uint32_t lapic_read(uint32_t offset) {
if (lapic == NULL) {
return UINT32_MAX;
}
return *(volatile uint32_t *) ((uintptr_t) lapic + offset);
}
uint32_t lapic_get_id() {
return lapic_read(LAPIC_REG_ID);
}
uint32_t lapic_get_version() {
return lapic_read(LAPIC_REG_VERSION);
}