Kernel: Renamed MP -> SMP.

alentours-dev
Sergiusz Bazanski 2011-08-28 13:01:47 +02:00
parent cdbb6c70ba
commit aa562e4203
3 changed files with 62 additions and 62 deletions

View File

@ -1,25 +1,25 @@
#ifndef __MP_H__
#define __MP_H__
#ifndef __SMP_H__
#define __SMP_H__
#include "types.h"
// OS structures
typedef enum {
E_MP_CPU_STATE_DISABLED,
E_MP_CPU_STATE_HALTED,
E_MP_CPU_STATE_IDLE,
E_MP_CPU_STATE_RUNNING
} E_MP_CPU_STATE;
E_SMP_CPU_STATE_DISABLED,
E_SMP_CPU_STATE_HALTED,
E_SMP_CPU_STATE_IDLE,
E_SMP_CPU_STATE_RUNNING
} E_SMP_CPU_STATE;
typedef struct {
u8 ID;
u32 CPUID;
u8 LAPICID;
E_MP_CPU_STATE State;
E_SMP_CPU_STATE State;
u8 Bootstrap : 1;
} T_MP_CPU;
} T_SMP_CPU;
// BIOS-provided Structures
typedef struct {
@ -28,7 +28,7 @@ typedef struct {
u8 Length;
u8 Specification;
u8 Checksum;
} __attribute__((packed)) T_MP_POINTER;
} __attribute__((packed)) T_SMP_POINTER;
typedef struct {
u8 Signature[4];
@ -44,7 +44,7 @@ typedef struct {
u16 ExtendedTableLength;
u8 ExtendedTableChecksum;
u8 Reserved;
} __attribute__((packed)) T_MP_CONFIGURATION_HEADER;
} __attribute__((packed)) T_SMP_CONFIGURATION_HEADER;
typedef struct {
u8 EntryType;
@ -57,10 +57,10 @@ typedef struct {
u32 CPUID;
u32 Reserved1;
u32 Reserved2;
} __attribute__((packed)) T_MP_ENTRY_CPU;
} __attribute__((packed)) T_SMP_ENTRY_CPU;
u64 mp_find_pointer(u64 Start, u64 End);
void mp_initialize(void);
void mp_parse_configuration_table(u32 TableAddress);
u64 smp_find_pointer(u64 Start, u64 End);
void smp_initialize(void);
void smp_parse_configuration_table(u32 TableAddress);
#endif

View File

@ -6,7 +6,7 @@
#include "Tier0/gdt.h"
#include "Tier0/paging.h"
#include "Tier0/acpi.h"
#include "Tier0/mp.h"
#include "Tier0/smp.h"
//#include "Tier0/interrupts.h"
//#include "Tier0/ps2.h"
#include "Tier0/system.h"
@ -64,7 +64,7 @@ void kmain(u32 LoadContextAddress)
if (RSDPAddress == 0)
PANIC("No ACPI!");
mp_initialize();
smp_initialize();
//interrupts_init_simple();
for (;;) {}

View File

@ -1,21 +1,21 @@
#include "Tier0/mp.h"
#include "Tier0/smp.h"
#include "Tier0/paging.h"
#include "Tier0/physmem.h"
#include "Tier0/kstdio.h"
#include "Tier0/kstdlib.h"
#include "Tier0/panic.h"
#define MP_TEMP_BUFFER_LENGTH 1024
u8 g_EntriesBuffer[MP_TEMP_BUFFER_LENGTH];
#define SMP_TESMP_BUFFER_LENGTH 1024
u8 g_EntriesBuffer[SMP_TESMP_BUFFER_LENGTH];
#define MP_MAX_CPU 32
#define SMP_MAX_CPU 32
struct {
T_MP_CPU CPUs[MP_MAX_CPU];
T_SMP_CPU CPUs[SMP_MAX_CPU];
u8 NumCPUs;
} g_MP;
} g_SMP;
u64 mp_find_pointer(u64 Start, u64 End)
u64 smp_find_pointer(u64 Start, u64 End)
{
for (u64 i = Start & ~((u64)0x10); i < End; i += 16)
{
@ -31,12 +31,12 @@ u64 mp_find_pointer(u64 Start, u64 End)
if (Sum)
{
kprintf("[w] Found MP pointer, but its checksum was invalid.");
kprintf("[w] Found SMP pointer, but its checksum was invalid.");
continue;
}
else
{
kprintf("[i] Found MP pointer @0x%x\n", i);
kprintf("[i] Found SMP pointer @0x%x\n", i);
return i;
}
}
@ -45,10 +45,10 @@ u64 mp_find_pointer(u64 Start, u64 End)
return 0;
}
void mp_initialize(void)
void smp_initialize(void)
{
kprintf("[i] Looking for MP Pointer:\n");
// According to the Intel spec, we must look for the MP Pointer in four
kprintf("[i] Looking for SMP Pointer:\n");
// According to the Intel spec, we must look for the SMP Pointer in four
// places:
// EBDA
@ -58,7 +58,7 @@ void mp_initialize(void)
kprintf(" EBDA @0x%x.\n", EBDAStart);
u64 Pointer = mp_find_pointer(EBDAStart, 0x0009FFFF);
u64 Pointer = smp_find_pointer(EBDAStart, 0x0009FFFF);
// Last kilobyte of base memory
if (!Pointer)
@ -67,76 +67,76 @@ void mp_initialize(void)
physmem_read(0x413, 2, &BaseMemoryEnd);
kprintf(" Base memory end @0x%x.\n", BaseMemoryEnd - 1024);
Pointer = mp_find_pointer(BaseMemoryEnd - 1024, BaseMemoryEnd);
Pointer = smp_find_pointer(BaseMemoryEnd - 1024, BaseMemoryEnd);
}
// BIOS ROM
if (!Pointer)
{
kprintf(" BIOS ROM @0x00E00000.\n");
Pointer = mp_find_pointer(0x000F0000, 0x000FFFFF);
Pointer = smp_find_pointer(0x000F0000, 0x000FFFFF);
}
// Just give up already.
if (!Pointer)
PANIC("No MP pointer found! Boo.");
PANIC("No SMP pointer found! Boo.");
T_MP_POINTER PointerTable;
T_SMP_POINTER PointerTable;
physmem_read(Pointer, 16, &PointerTable);
if (PointerTable.Specification != 4)
PANIC("Unsupported MP spec!");
PANIC("Unsupported SMP spec!");
if (PointerTable.TablePhysical)
{
kprintf("[i] MP Configuration Table present.\n");
mp_parse_configuration_table(PointerTable.TablePhysical);
kprintf("[i] SMP Configuration Table present.\n");
smp_parse_configuration_table(PointerTable.TablePhysical);
}
else
{
kprintf("[i] MP Configuration Type present.\n");
kprintf("[i] SMP Configuration Type present.\n");
// do something else... like panic.
PANIC("MP types not implemented!");
PANIC("SMP types not ismplemented!");
}
}
u8 mp_parse_cpu(u32 EntryAddress)
u8 smp_parse_cpu(u32 EntryAddress)
{
u8 i = g_MP.NumCPUs;
T_MP_ENTRY_CPU *CPU = (T_MP_ENTRY_CPU *)&g_EntriesBuffer[EntryAddress];
u8 i = g_SMP.NumCPUs;
T_SMP_ENTRY_CPU *CPU = (T_SMP_ENTRY_CPU *)&g_EntriesBuffer[EntryAddress];
if (CPU->FlagBootstrap)
{
kprintf(" CPU #%i, LAPIC sig %x, cpuid %x (bootstrap)\n", i, CPU->LAPICID, CPU->CPUID);
g_MP.CPUs[i].Bootstrap = 1;
g_MP.CPUs[i].State = E_MP_CPU_STATE_RUNNING;
g_SMP.CPUs[i].Bootstrap = 1;
g_SMP.CPUs[i].State = E_SMP_CPU_STATE_RUNNING;
}
else if (!CPU->FlagAvailable)
{
kprintf(" CPU #%i, LAPIC sig %x, cpuid %x, (UNAVAILABLE!!!)", i, CPU->LAPICID, CPU->CPUID);
g_MP.CPUs[i].Bootstrap = 0;
g_MP.CPUs[i].State = E_MP_CPU_STATE_DISABLED;
g_SMP.CPUs[i].Bootstrap = 0;
g_SMP.CPUs[i].State = E_SMP_CPU_STATE_DISABLED;
}
else
{
kprintf(" CPU #%i, LAPIC sig %x, cpuid %x (halted)\n", i, CPU->LAPICID, CPU->CPUID);
g_MP.CPUs[i].Bootstrap = 0;
g_MP.CPUs[i].State = E_MP_CPU_STATE_HALTED;
g_SMP.CPUs[i].Bootstrap = 0;
g_SMP.CPUs[i].State = E_SMP_CPU_STATE_HALTED;
}
g_MP.CPUs[i].ID = i;
g_MP.CPUs[i].CPUID = CPU->CPUID;
g_MP.CPUs[i].LAPICID = CPU->LAPICID;
g_SMP.CPUs[i].ID = i;
g_SMP.CPUs[i].CPUID = CPU->CPUID;
g_SMP.CPUs[i].LAPICID = CPU->LAPICID;
g_MP.NumCPUs++;
g_SMP.NumCPUs++;
return sizeof(T_MP_ENTRY_CPU);
return sizeof(T_SMP_ENTRY_CPU);
}
void mp_parse_configuration_table(u32 TableAddress)
void smp_parse_configuration_table(u32 TableAddress)
{
T_MP_CONFIGURATION_HEADER Header;
T_SMP_CONFIGURATION_HEADER Header;
physmem_read(TableAddress, 44, &Header);
s8 OEMName[9];
@ -147,25 +147,25 @@ void mp_parse_configuration_table(u32 TableAddress)
kmemcpy(ProductName, Header.ProductName, 12);
ProductName[12] = 0x00;
kprintf("[i] MP OEM: %s\n", OEMName);
kprintf("[i] MP Product: %s\n", ProductName);
kprintf("[i] SMP OEM: %s\n", OEMName);
kprintf("[i] SMP Product: %s\n", ProductName);
kprintf("[i] MP Base Configuration Table length: %i bytes.\n", Header.BaseTableLength);
kprintf("[i] SMP Base Configuration Table length: %i bytes.\n", Header.BaseTableLength);
if (Header.BaseTableLength > MP_TEMP_BUFFER_LENGTH)
PANIC("MP BCT too big!");
if (Header.BaseTableLength > SMP_TESMP_BUFFER_LENGTH)
PANIC("SMP BCT too big!");
physmem_read(TableAddress + 44, Header.BaseTableLength - 44, g_EntriesBuffer);
u32 EntryAddress = 0;
g_MP.NumCPUs = 0;
g_SMP.NumCPUs = 0;
while (1)
{
u8 EntryType = g_EntriesBuffer[EntryAddress];
switch (EntryType)
{
case 0x00:
EntryAddress += mp_parse_cpu(EntryAddress);
EntryAddress += smp_parse_cpu(EntryAddress);
break;
default:
for (;;) {}