Indentation fix, cleanup.
[AROS.git] / arch / i386-pc / kernel / platform_init.c
blob567e9eb5292dd7def4b882f184a87a99d66278db
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/symbolsets.h>
7 #include <asm/cpu.h>
8 #include <exec/execbase.h>
9 #include <proto/exec.h>
11 #include "kernel_base.h"
12 #include "kernel_debug.h"
13 #include "kernel_intern.h"
14 #include "apic.h"
15 #include "traps.h"
16 #include "utils.h"
17 #include "xtpic.h"
19 #define D(x) x
21 static int PlatformInit(struct KernelBase *KernelBase)
23 struct PlatformData *data;
24 struct table_desc idtr;
26 data = AllocMem(sizeof(struct PlatformData), MEMF_PUBLIC);
27 if (!data)
28 return FALSE;
30 D(bug("[Kernel] Allocated platform data at 0x%p\n", data));
31 KernelBase->kb_PlatformData = data;
33 /* By default we have no APIC data */
34 data->kb_APIC = NULL;
37 * Now we have a complete memory list and working AllocMem().
38 * We can allocate space for IDT and TSS now and build them to make
39 * interrupts working.
41 data->tss = krnAllocMemAligned(sizeof(struct tss), 64);
42 data->idt = krnAllocMemAligned(sizeof(long long) * 256, 256);
43 SysBase->SysStkLower = AllocMem(0x10000, MEMF_PUBLIC); /* 64KB of system stack */
45 if ((!data->tss) || (!data->idt) || (!SysBase->SysStkLower))
46 return FALSE;
48 data->tss->ssp_seg = KERNEL_DS; /* SSP segment descriptor */
49 data->tss->cs = USER_CS;
50 data->tss->ds = USER_DS;
51 data->tss->es = USER_DS;
52 data->tss->ss = USER_DS;
53 data->tss->iomap = 104;
55 /* Set up system stack */
56 SysBase->SysStkUpper = SysBase->SysStkLower + 0x10000;
57 data->tss->ssp = (IPTR)SysBase->SysStkUpper;
59 /* Restore IDT structure */
60 Init_Traps(data);
62 /* Set correct TSS address in the GDT */
63 GDT[6].base_low = ((unsigned long)data->tss) & 0xffff;
64 GDT[6].base_mid = (((unsigned long)data->tss) >> 16) & 0xff;
65 GDT[6].base_high = (((unsigned long)data->tss) >> 24) & 0xff;
68 * As we prepared all necessary stuff, we can hopefully load IDT
69 * into CPU. We may also play a bit with TSS
71 idtr.size = 0x07FF;
72 idtr.base = (unsigned long)data->idt;
73 asm
75 "lidt %0\n\t"
76 "ltr %%ax\n\t"
77 ::"m"(idtr),"ax"(0x30)
80 D(bug("[Kernel] System restored\n"));
82 return TRUE;
85 ADD2INITLIB(PlatformInit, 10);
87 /* acpica.library is optional */
88 struct Library *ACPICABase = NULL;
90 void PlatformPostInit(void)
92 struct PlatformData *pdata = KernelBase->kb_PlatformData;
94 ACPICABase = OpenLibrary("acpica.library", 0);
96 if (ACPICABase)
97 pdata->kb_APIC = acpi_APIC_Init();
99 if (!pdata->kb_APIC)
101 /* No APIC was discovered by ACPI/whatever else. Do the probe. */
102 pdata->kb_APIC = core_APIC_Probe();
105 if ((!pdata->kb_APIC) || (pdata->kb_APIC->flags & APF_8259))
107 /* Initialize our XT-PIC */
108 XTPIC_Init(&pdata->xtpic_mask);
111 if (pdata->kb_APIC && (pdata->kb_APIC->count > 1))
113 if (smp_Setup())
115 smp_Wake();
117 else
119 D(bug("[Kernel] Failed to prepare the environment!\n"));
121 pdata->kb_APIC->count = 1; /* We have only one workinng CPU */