-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Local APIC handling code to support multiprocessor, irq handle…
…r for Local APIC, enabling interrupts in ISR code so that high priority IRQ can be served while low priority interrupts are being served, added tick count, fixed VGA buffer overflow, added wait function using PIT channel 2, fixed itoa routine handling MSB, added print_msg routine.
- Loading branch information
Showing
9 changed files
with
327 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/*****************************************************************************/ | ||
/* File: apic.c */ | ||
/* */ | ||
/* Description: Source file for IOAPIC and Local APIC code. */ | ||
/* */ | ||
/* Author: Shoily O Rahman <[email protected]> */ | ||
/* */ | ||
/* Date: Aug 2, 2020 */ | ||
/* */ | ||
/*****************************************************************************/ | ||
|
||
#include "apic.h" | ||
#include "page32.h" | ||
#include "util.h" | ||
|
||
int lapic_present = 0; | ||
int lapic_base_register; | ||
int lapic_id; | ||
|
||
#define ADD2PTR(x, y) ((int)(x) + (int)(y)) | ||
|
||
extern int _kernel_pg_dir; | ||
|
||
char __attribute__((aligned(4096))) lapic_pg_table[4096]; | ||
|
||
void read_msr(int msr, int *eax, int *edx) { | ||
|
||
__asm__ __volatile__("rdmsr;" | ||
: "=a" (*eax), "=d" (*edx) | ||
: "c" (msr) | ||
: ); | ||
} | ||
|
||
int read_lapic_register(int lapic_register) { | ||
|
||
return *((int*)(lapic_base_register+lapic_register)); | ||
} | ||
|
||
void write_lapic_register(int lapic_register, int value) { | ||
|
||
*((int*)(lapic_base_register+lapic_register)) = value; | ||
} | ||
|
||
void init_lapic() { | ||
|
||
int eax, edx; | ||
pte_t *pgtable[1]; | ||
|
||
__asm__ __volatile__("movl $1, %%eax;" | ||
"cpuid;" | ||
"andl $0x200, %%edx;" | ||
"shrl $9, %%edx;" | ||
"movl %%edx, %0;" | ||
: "=r" (lapic_present) | ||
: | ||
: "%eax", "%edx" | ||
); | ||
|
||
print_msg("Local APIC present", lapic_present, 10, true); | ||
|
||
if (!lapic_present) { | ||
|
||
return; | ||
} | ||
|
||
memset(lapic_pg_table, sizeof(lapic_pg_table), 0); | ||
pgtable[0] = (pte_t*)lapic_pg_table; | ||
|
||
read_msr(0x1b, &eax, &edx); | ||
lapic_base_register = eax & 0xfffff000; | ||
|
||
build_pagetable((pgd_t*)&_kernel_pg_dir, pgtable, lapic_base_register, lapic_base_register, PAGE_SIZE, PGD_PRESENT | PGD_WRITE, PTE_PRESENT | PTE_WRITE); | ||
|
||
print_msg("Local APIC address", eax, 16, false); | ||
|
||
lapic_id = read_lapic_register(LAPIC_ID_REG) >> 24; | ||
|
||
print_msg("Local APIC id", lapic_id, 16, true); | ||
|
||
// enable receiving interrupt | ||
//write_lapic_register(LAPIC_SPURIOUS_REG, read_lapic_register(LAPIC_SPURIOUS_REG)| 0x100); | ||
} | ||
|
||
void lapic_switch(bool enable) { | ||
|
||
int value; | ||
|
||
value = read_lapic_register(LAPIC_SPURIOUS_REG); | ||
if (enable) | ||
value |= 0x1ff; | ||
else | ||
value &= ~0x1ff; | ||
|
||
print_msg("lapic_switch", value, 16, true); | ||
|
||
write_lapic_register(LAPIC_SPURIOUS_REG, value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*****************************************************************************/ | ||
/* File: apic.c */ | ||
/* */ | ||
/* Description: Source file for IOAPIC and Local APIC code. */ | ||
/* */ | ||
/* Author: Shoily O Rahman <[email protected]> */ | ||
/* */ | ||
/* Date: Aug 2, 2020 */ | ||
/* */ | ||
/*****************************************************************************/ | ||
|
||
#ifndef APIC_H | ||
#define APIC_H | ||
|
||
#include "type.h" | ||
|
||
#define LAPIC_ID_REG 0x20 | ||
#define LAPIC_VERSION_REG 0x30 | ||
#define LAPIC_TPR 0x80 | ||
#define LAPIC_APR 0x90 | ||
#define LAPIC_PPR 0xa0 | ||
#define LAPIC_EOI_REG 0xb0 | ||
#define LAPIC_SPURIOUS_REG 0xf0 | ||
#define ISR_0_31 0x100 | ||
#define TMR_0_31 0x180 | ||
#define IRR_0_31 0x200 | ||
#define ERROR_STATUS_REG 0x280 | ||
#define ICR_1 0x300 | ||
#define ICR_2 0x310 | ||
#define LVT_TIMER_REG 0x320 | ||
#define LVT_LINT_0_REG 0x350 | ||
#define LVT_LINT_1_REG 0x360 | ||
#define LVT_ERROR_REG 0x370 | ||
#define INITIAL_COUNTER_REG 0x380 | ||
#define CURRENT_COUNTER_REG 0x390 | ||
#define DIVIDE_CONFIGURATION_REG 0x3e0 | ||
|
||
void init_lapic(); | ||
void lapic_switch(bool enable); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.