summaryrefslogtreecommitdiffstats
path: root/src/kernel/cpumgr.C
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2010-06-02 17:45:11 -0500
committerPatrick Williams <iawillia@us.ibm.com>2010-06-02 17:45:11 -0500
commit2cc0de1f136026f13ca6de363d9e57831c6ba10b (patch)
tree5653bf1244af8c97e63745536bf5ca887d06ea36 /src/kernel/cpumgr.C
parent5235cd52014205f358f1a295c5228091e1847efb (diff)
downloadtalos-hostboot-2cc0de1f136026f13ca6de363d9e57831c6ba10b.tar.gz
talos-hostboot-2cc0de1f136026f13ca6de363d9e57831c6ba10b.zip
Initial cpu / task structs.
Diffstat (limited to 'src/kernel/cpumgr.C')
-rw-r--r--src/kernel/cpumgr.C72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/kernel/cpumgr.C b/src/kernel/cpumgr.C
new file mode 100644
index 000000000..3c2c3b907
--- /dev/null
+++ b/src/kernel/cpumgr.C
@@ -0,0 +1,72 @@
+#include <kernel/cpumgr.H>
+#include <kernel/task.H>
+#include <kernel/cpu.H>
+#include <kernel/scheduler.H>
+#include <kernel/taskmgr.H>
+#include <kernel/pagemgr.H>
+#include <kernel/console.H>
+#include <util/singleton.H>
+
+CpuManager::CpuManager()
+{
+ for (int i = 0; i < MAXCPUS; i++)
+ iv_cpus[i] = NULL;
+}
+
+cpu_t* CpuManager::getCurrentCPU()
+{
+ register task_t* current_task = NULL;
+ asm volatile("mfsprg3 %0" : "=r" (current_task) );
+ return current_task->cpu;
+}
+
+void CpuManager::init()
+{
+ Singleton<CpuManager>::instance().startCPU();
+}
+
+void CpuManager::startCPU(ssize_t i)
+{
+ bool currentCPU = false;
+ if (i < 0)
+ {
+ // TODO: Determine position of this CPU, somehow.
+ i = 0;
+
+ currentCPU = true;
+ }
+
+ printk("Starting CPU %d...", i);
+
+ // Initialize CPU structure.
+ if (NULL == iv_cpus[i])
+ {
+ cpu_t* cpu = iv_cpus[i] = new cpu_t;
+
+ // Initialize CPU.
+ cpu->cpu = i;
+ cpu->scheduler = new Scheduler();
+ cpu->kernel_stack = PageManager::allocatePage(4);
+
+ // Create idle task.
+ task_t * idle_task = TaskManager::createIdleTask();
+ idle_task->cpu = cpu;
+
+ // Add to scheduler.
+ cpu->scheduler->setIdleTask(idle_task);
+ }
+
+ if (currentCPU)
+ {
+ register task_t* idle_task = iv_cpus[i]->scheduler->getIdleTask();
+ asm volatile("mtsprg3 %0" :: "r" (idle_task));
+ }
+ else
+ {
+ // TODO once we get to SMP.
+ }
+
+ printk("done\n");
+
+ return;
+}
OpenPOWER on IntegriCloud