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.
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
31 #include "ke/thread.h"
36 * Structure holding the information about a CPU.
45 * If set to 1, this CPU is active.
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.
54 * Pointer to the currently executed thread. On rescheduling, the active-lock
55 * of the thread is locked.
57 KeThread
*currentthread
;
59 * Set to 1 if the CPU is executing an interrupt.
60 * \todo: This is completely broken atm
64 * Current execution level.
68 * Next timer to expire.
72 * Scheduler timer of the current CPU.
76 * Time at which the last timer was activated.
80 * Unix time when the CPU timer was started.
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
91 int keCPUID(uint32_t code
, uint32_t *output
);
94 * Writes something to a machine specific register.
96 void keWriteMSR(uint32_t index
, uint64_t value
);
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);