Indentation fix, cleanup.
[AROS.git] / arch / i386-pc / cpu / cpu_init.c
blob2349af697093e2c09bb833c754382ec7ea6cf8ca
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: CPU Initialisation.
6 Lang: english
7 */
9 #include <aros/symbolsets.h>
10 #include "cpu_intern.h"
11 #include LC_LIBDEFS_FILE
13 void i386_CheckCPU_Type( struct i386_compat_intern *CPU_intern );
15 #define SMP_SUPPORT 1
17 static struct CPU_Definition *BootCPU; /* Pointer used by the exec launched boot cpu probe */
19 /* acpica.library is optional */
20 struct Library *ACPICABase = NULL;
22 static int GM_UNIQUENAME(Init)(LIBBASETYPEPTR CPUBase)
24 struct intel_mp_confblock *mpcfb = NULL;
25 struct CPU_Definition *AvailCPUs = NULL;
27 CPUBase->CPUB_BOOT_Physical = -1; /* set to a single cpu for now */
28 CPUBase->CPUB_BOOT_Logical = -1;
30 /* Parse the ACPI tables for possible boot-time SMP configuration. */
31 ACPICABase = OpenLibrary("acpica.library",0);
32 kprintf(DEBUG_NAME_STR ": acpica.library @ %p\n", ACPICABase);
33 if (ACPICABase)
34 return TRUE;
36 mpcfb = (APTR)find_smp_config();
38 if ( mpcfb )
40 kprintf(DEBUG_NAME_STR ": Found SMP 1.4 MP table = 0x%p\n", mpcfb);
41 AllocAbs( 4096, mpcfb);
42 if (mpcfb->mpcf_physptr) AllocAbs( 4096, (APTR)mpcfb->mpcf_physptr );
43 kprintf(DEBUG_NAME_STR ": SMP Table(s) protected\n");
45 else kprintf(DEBUG_NAME_STR ": NO compatable SMP hardware found.\n");
47 AvailCPUs = AllocMem( sizeof(struct CPU_Definition), MEMF_CLEAR | MEMF_PUBLIC ); /* Create our new CPU List */
49 if( AvailCPUs )
52 NEWLIST((struct List *)&(AvailCPUs->CPU_CPUList));
53 AvailCPUs->CPU_Physical = 1;
55 InitSemaphore( &CPUBase->CPUB_ListLock);
56 kprintf(DEBUG_NAME_STR ": Initialised CPU List Semaphore\n");
58 else
60 kprintf(DEBUG_NAME_STR ": ERROR - Couldnt allocate CPU list memory!\n");
61 return FALSE;
64 /* TODO: Patch functions with suitable replacements (bug fixes/speed ups) - BEFORE SMP SETUP! */
66 if ( mpcfb ) /* SMP? */
68 AllocAbs( 4096, (APTR)smp_alloc_memory()); /* Create The Trampoline page..
69 Has to be in very low memory so we can execute
70 real-mode AP code. */
71 BootCPU->CPU_Private2 = mpcfb; /* Store the pointer to the SMP config block */
72 kprintf(DEBUG_NAME_STR ": SMP Trampoline page protected, SMP config stored.\n");
75 CPUBase->CPUB_Processors = AvailCPUs; // done !
77 AddTail((struct List *)&AvailCPUs->CPU_CPUList,(struct Node *)&BootCPU->CPU_CPUList);
78 kprintf(DEBUG_NAME_STR ": CPU List created = 0x%p, Boot CPU inserted..0x%p\n",AvailCPUs,BootCPU);
80 if (mpcfb) get_smp_config( mpcfb, CPUBase );
82 return TRUE;
85 ADD2INITLIB(GM_UNIQUENAME(Init), 0)
87 /* WARNING!!! THIS NEXT FUNCTION RUS IN KERNEL LAND _ NO DEBUG OUTPUT ETC>> BE CAREFULL! */
89 #undef SysBase
90 void prepare_primary_cpu(struct ExecBase *SysBase)
92 struct i386_compat_intern *BootCPU_intern;
94 BootCPU = AllocMem( sizeof(struct CPU_Definition), MEMF_CLEAR | MEMF_PUBLIC ); /* Add the boot CPU to the CPU List */
95 if( BootCPU )
98 BootCPU->CPU_Family = CPU_Family_i386; /* we are i386 compatable.. */
99 BootCPU->CPU_Model = CPU_i386_386;
100 BootCPU->CPU_ID = 1; /* we are the only CPU at this time .. */
101 BootCPU->CPU_IsOnline = TRUE; /* CPU is online .. */
102 BootCPU->CPU_BootCPU = TRUE; /* CPU bootd system.. */
104 BootCPU_intern = AllocMem(sizeof(struct i386_compat_intern), MEMF_CLEAR | MEMF_PUBLIC ); /* Create its per CPU internal struct */
106 if( BootCPU_intern )
109 /* TODO: The next line is broken - fix the checkcpu function */
110 i386_CheckCPU_Type( BootCPU_intern );
112 BootCPU->CPU_Private1 = BootCPU_intern;
114 switch (BootCPU_intern->x86_model)
116 case 4:
117 BootCPU->CPU_Model = CPU_i386_486;
118 break;
119 case 5:
120 BootCPU->CPU_Model = CPU_i386_586;
121 break;
122 case 6:
123 BootCPU->CPU_Model = CPU_i386_686;
124 break;
125 case 7:
126 BootCPU->CPU_Model = CPU_i386_786;
127 break;
128 case 8:
129 BootCPU->CPU_Model = CPU_i386_886;
130 break;