20#include "pedigree/kernel/compiler.h"
21#include "pedigree/kernel/machine/Machine.h"
22#include "pedigree/kernel/machine/Serial.h"
23#include "pedigree/kernel/machine/Vga.h"
24#include "pedigree/kernel/processor/Processor.h"
25#include "pedigree/kernel/utilities/StaticString.h"
30Machine::ShutdownPhase shutdownPhase = Machine::ShutdownPhase::NotStarted;
34 __atomic_store(&shutdownPhase, &phase, __ATOMIC_RELAXED);
39 if (__atomic_load_n(&shutdownPhase, __ATOMIC_RELAXED) == ShutdownPhase::NotStarted) {
43 message +=
"Shutting down...\nPhase: ";
54const char* Machine::shutdownPhaseName() {
57 __atomic_load(&shutdownPhase, &phase, __ATOMIC_RELAXED);
59 case ShutdownPhase::NotStarted:
61 case ShutdownPhase::Requested:
62 return "shutdown request";
63 case ShutdownPhase::Userspace:
64 return "terminating userspace";
65 case ShutdownPhase::Syscalls:
66 return "draining system calls";
67 case ShutdownPhase::Filesystems:
68 return "detaching filesystems";
69 case ShutdownPhase::Modules:
70 return "unloading modules";
71 case ShutdownPhase::Firmware:
72 return "preparing firmware shutdown";
73 case ShutdownPhase::Destructors:
74 return "draining deferred destruction";
75 case ShutdownPhase::Input:
76 return "stopping input";
77 case ShutdownPhase::Caches:
78 return "flushing caches";
79 case ShutdownPhase::Timers:
80 return "stopping info block timer";
81 case ShutdownPhase::Devices:
82 return "stopping platform devices";
83 case ShutdownPhase::Processors:
84 return "stopping other processors";
85 case ShutdownPhase::ProcessorCleanup:
86 return "releasing processor services";
87 case ShutdownPhase::FinalAction:
88 return "final power/reset action";
94 if (type == ShutdownType::Restart) {
97 return type == ShutdownType::Halt ? nullptr :
"Automatic power-off or restart is unavailable.";
107 serial->write_str(
"\r\n");
112 uint16_t* cells = *console;
115 if (cells && rows && cols) {
116 for (
size_t i = 0; i < rows * cols; ++i)
118 auto lineLength = [cols](
const char* text) {
120 while (length < cols && text[length] && text[length] !=
'\n')
126 while (*text && lines < rows) {
127 text += lineLength(text);
133 const size_t firstRow = (rows - lines) / 2;
134 for (
size_t line = 0; line < lines; ++line) {
135 const size_t length = lineLength(text);
136 const size_t start = (firstRow + line) * cols + (cols - length) / 2;
137 for (
size_t i = 0; i < length; ++i)
138 cells[start + i] = 0x0f00 |
static_cast<uint8_t
>(text[i]);
virtual MUST_USE_RESULT bool quiesceAllOtherProcessors()
virtual size_t getNumSerial()=0
virtual const char * finalShutdown(ShutdownType type)
virtual Vga * getVga(size_t n)=0
virtual Serial * getSerial(size_t n)=0
virtual size_t getNumVga()=0
static void setShutdownPhase(ShutdownPhase phase, const char *detail=nullptr)
static void setShutdownDetail(const char *detail)
virtual MUST_USE_RESULT bool resumeAllOtherProcessors()
virtual MUST_USE_RESULT bool stopAllOtherProcessors()
void displayShutdownMessage(const char *message)
virtual void moveCursor(size_t nX, size_t nY)=0
virtual bool setLargestTextMode()=0
virtual size_t getNumRows()=0
virtual size_t getNumCols()=0