The Pedigree Project 0.1
include/pedigree/kernel/machine/Machine.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef MACHINE_MACHINE_H
21#define MACHINE_MACHINE_H
22
23#include "pedigree/kernel/compiler.h"
24#include "pedigree/kernel/processor/types.h"
25
26class IrqManager;
27class Keyboard;
28class SchedulerTimer;
29class Serial;
30class Timer;
31class Vga;
32
41class EXPORTED_PUBLIC Machine {
42 friend void system_reset();
43
44 public:
45 enum class ShutdownType { Restart, Halt, PowerOff };
46 enum class ShutdownPhase {
47 NotStarted,
48 Requested,
49 Userspace,
50 Syscalls,
51 Filesystems,
52 Modules,
53 Destructors,
54 Input,
55 Caches,
56 Timers,
57 Devices,
58 Processors,
59 ProcessorCleanup,
60 FinalAction,
61 };
62
63 static void setShutdownPhase(ShutdownPhase phase);
64 static const char* shutdownPhaseName();
65
66 static Machine& instance();
67
68 virtual bool supportsPowerOff() const {
69 return false;
70 }
72 virtual void finalShutdown(ShutdownType type);
73
75 void displayShutdownMessage(const char* message);
76
80 virtual void initialise() = 0;
82 virtual void initialise2() {}
84 virtual void initialise3() {}
89 virtual void deinitialise() {
90 m_bInitialised = false;
91 }
92 inline bool isInitialised() {
93 return m_bInitialised;
94 }
95
101 virtual void initialiseDeviceTree() {}
102
106 virtual Serial* getSerial(size_t n) = 0;
107
111 virtual size_t getNumSerial() = 0;
112
116 virtual Vga* getVga(size_t n) = 0;
117
121 virtual size_t getNumVga() = 0;
122
123 virtual IrqManager* getIrqManager() = 0;
128
132 virtual Timer* getTimer() = 0;
133
137 virtual Keyboard* getKeyboard() = 0;
138
142 virtual void setKeyboard(Keyboard* kb) = 0;
143
145 MUST_USE_RESULT virtual bool quiesceAllOtherProcessors();
146
148 MUST_USE_RESULT virtual bool resumeAllOtherProcessors();
149
155 MUST_USE_RESULT virtual bool stopAllOtherProcessors();
156
157 protected:
158 inline Machine() : m_bInitialised(false) {}
159 virtual ~Machine();
160
161 bool m_bInitialised;
162
163 private:
164 Machine(const Machine&);
165 Machine& operator=(const Machine&);
166};
167
168#endif
virtual void initialise2()
Called after debugger startup.
virtual void initialise()=0
virtual size_t getNumSerial()=0
virtual SchedulerTimer * getSchedulerTimer()=0
virtual Vga * getVga(size_t n)=0
virtual Keyboard * getKeyboard()=0
virtual Serial * getSerial(size_t n)=0
virtual size_t getNumVga()=0
virtual Timer * getTimer()=0
virtual void setKeyboard(Keyboard *kb)=0
virtual void initialise3()
Called after processor startup - for thread creation etc.