2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include <aros/symbolsets.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"
21 static int PlatformInit(struct KernelBase
*KernelBase
)
23 struct PlatformData
*data
;
24 struct table_desc idtr
;
26 data
= AllocMem(sizeof(struct PlatformData
), MEMF_PUBLIC
);
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 */
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
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
))
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 */
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
72 idtr
.base
= (unsigned long)data
->idt
;
77 ::"m"(idtr
),"ax"(0x30)
80 D(bug("[Kernel] System restored\n"));
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);
97 pdata
->kb_APIC
= acpi_APIC_Init();
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))
119 D(bug("[Kernel] Failed to prepare the environment!\n"));
121 pdata
->kb_APIC
->count
= 1; /* We have only one workinng CPU */