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 Firmware,
54 Destructors,
55 Input,
56 Caches,
57 Timers,
58 Devices,
59 Processors,
60 ProcessorCleanup,
61 FinalAction,
62 };
63
65 static void setShutdownPhase(ShutdownPhase phase, const char* detail = nullptr);
67 static void setShutdownDetail(const char* detail);
68 static const char* shutdownPhaseName();
69
70 static Machine& instance();
71
72 virtual bool supportsPowerOff() const {
73 return false;
74 }
76 virtual bool prepareShutdown(ShutdownType type) {
77 return true;
78 }
81 virtual const char* finalShutdown(ShutdownType type);
82
84 void displayShutdownMessage(const char* message);
85
89 virtual void initialise() = 0;
91 virtual void initialise2() {}
93 virtual void initialise3() {}
98 virtual void deinitialise() {
99 m_bInitialised = false;
100 }
101 inline bool isInitialised() {
102 return m_bInitialised;
103 }
104
110 virtual void initialiseDeviceTree() {}
111
115 virtual Serial* getSerial(size_t n) = 0;
116
120 virtual size_t getNumSerial() = 0;
121
125 virtual Vga* getVga(size_t n) = 0;
126
130 virtual size_t getNumVga() = 0;
131
132 virtual IrqManager* getIrqManager() = 0;
137
141 virtual Timer* getTimer() = 0;
142
146 virtual Keyboard* getKeyboard() = 0;
147
151 virtual void setKeyboard(Keyboard* kb) = 0;
152
154 MUST_USE_RESULT virtual bool quiesceAllOtherProcessors();
155
157 MUST_USE_RESULT virtual bool resumeAllOtherProcessors();
158
164 MUST_USE_RESULT virtual bool stopAllOtherProcessors();
165
166 protected:
167 inline Machine() : m_bInitialised(false) {}
168 virtual ~Machine();
169
170 bool m_bInitialised;
171
172 private:
173 Machine(const Machine&);
174 Machine& operator=(const Machine&);
175};
176
177#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.
virtual bool prepareShutdown(ShutdownType type)