- Implemented execp*.
[planlOS.git] / system / include / ke / cpu.h
blobcbafa11bf59396152c8a1ba6d9c8119783fa0615
1 /*
2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 /**
22 * \file cpu.h
23 * CPU management functions. Especially in SMP systems the operating system has
24 * to keep track on which CPU the current code is running.
27 #ifndef KE_CPU_H_INCLUDED
28 #define KE_CPU_H_INCLUDED
30 #include <stdint.h>
31 #include "ke/thread.h"
32 #include "ke/level.h"
33 #include "ke/timer.h"
35 /**
36 * Structure holding the information about a CPU.
38 typedef struct
40 /**
41 * APIC ID of the CPU.
43 uint32_t id;
44 /**
45 * If set to 1, this CPU is active.
47 uint32_t running;
48 /**
49 * Pointer to the idle thread. The idle thread is not inserted into the
50 * thread list but is instead created once for every CPU.
52 KeThread *idlethread;
53 /**
54 * Pointer to the currently executed thread. On rescheduling, the active-lock
55 * of the thread is locked.
57 KeThread *currentthread;
58 /**
59 * Set to 1 if the CPU is executing an interrupt.
60 * \todo: This is completely broken atm
62 uint32_t interrupt;
63 /**
64 * Current execution level.
66 KeExecLevel level;
67 /**
68 * Next timer to expire.
70 KeTimer *next_timer;
71 /**
72 * Scheduler timer of the current CPU.
74 KeTimer *sched_timer;
75 /**
76 * Time at which the last timer was activated.
78 uint64_t time;
79 /**
80 * Unix time when the CPU timer was started.
82 uint32_t starttime;
83 } KeCPU;
85 /**
86 * Reads in a cpuid value.
87 * \param code Code of the request.
88 * \param output Pointer to four variables holding the register data which is
89 * read.
91 int keCPUID(uint32_t code, uint32_t *output);
93 /**
94 * Writes something to a machine specific register.
96 void keWriteMSR(uint32_t index, uint64_t value);
97 /**
98 * Reads from a machine specific register.
100 uint64_t keReadMSR(uint32_t index);
103 * Adds a CPU with the given APIC ID to the system.
105 KeCPU *keAddCPU(uint32_t id);
107 * Returns the currently used CPU.
109 KeCPU *keGetCurrentCPU(void);
111 * Returns the number of active CPUs in the system.
113 uint32_t keGetCPUCount(void);
115 #endif