Xyris  0.5
Arch.hpp
Go to the documentation of this file.
1 /**
2  * @file Arch.hpp
3  * @author Keeton Feavel ([email protected])
4  * @brief Architecture control and initialization
5  * @version 0.3
6  * @date 2020-06-01
7  *
8  * @copyright Copyright the Xyris Contributors (c) 2020
9  *
10  */
11 #pragma once
12 
13 #include <stddef.h>
14 #include <stdint.h>
15 #if defined(__i686__)
16 # include <Arch/i686/Arch.i686.hpp>
17 #endif
18 
19 /**
20  * @brief Kernel entry point. Performs all kernel initialization
21  * and starts the init process(es). Should be called from bootloader
22  * entry points.
23  *
24  * @param info Bootloader information structure
25  * @param magic Bootloader magic
26  */
27 void kernelEntry(void* info, uint32_t magic);
28 
29 // Cannot be namespaced since it has to be used by
30 // functions with C linkage for ASM interoperability
31 struct registers;
32 
33 namespace Arch {
34 
35 struct stackframe;
36 
37 /**
38  * @brief Disable interrupts and halts execution
39  *
40  */
41 [[noreturn]] [[gnu::always_inline]]
42 inline void haltAndCatchFire()
43 {
44  while (true) {
45  asm volatile ("cli");
46  asm volatile ("hlt");
47  }
48 }
49 
50 /**
51  * @brief Write all register names and values as a string to a
52  * buffer. Provided buffer size must also take escape and control
53  * characters (for formatting) into account.
54  *
55  * @param buf Buffer to contain register information string
56  * @param regs Register structure
57  */
58 void registersToString(char* buf, struct registers* regs);
59 
60 /**
61  * @brief Print register information to all kernel terminals
62  * (serial, framebuffer, etc.). Used for panic and debug screens.
63  *
64  * @param regs Register structure
65  */
66 void registersPrintInformation(struct registers* regs);
67 
68 }
69 
70 namespace Arch::CPU {
71 
72 // Architecture initialization
73 void init();
74 
75 // Architecture common CPU controls
76 void interruptsDisable();
77 void interruptsEnable();
78 // TODO: Add interruptsRegisterCallback(uint32_t id, func* cb)
79 
80 // Critical region lambda function
81 template<typename Function>
82 void criticalRegion(Function critWork)
83 {
85  critWork();
87 }
88 
89 // CPU Identification
90 const char* vendor();
91 const char* model();
92 
93 } // !namespace Arch::CPU
Arch::CPU::init
void init()
Definition: Arch.i686.cpp:110
Arch::CPU::criticalRegion
void criticalRegion(Function critWork)
Definition: Arch.hpp:82
Arch::CPU::vendor
const char * vendor()
Definition: Arch.i686.cpp:127
Arch::CPU::interruptsEnable
void interruptsEnable()
Definition: Arch.i686.cpp:123
Arch::registersToString
void registersToString(char *buf, struct registers *regs)
Write all register names and values as a string to a buffer. Provided buffer size must also take esca...
Definition: Arch.i686.cpp:51
kernelEntry
void kernelEntry(void *info, uint32_t magic)
Kernel entry point. Performs all kernel initialization and starts the init process(es)....
Definition: Entry.cpp:82
Arch::CPU::interruptsDisable
void interruptsDisable()
Definition: Arch.i686.cpp:119
Arch.i686.hpp
i686 architecture implementation of Arch.hpp
registers
A structure definining values for all x86 registers. Cannot be namespaced due to C linkage and ASM in...
Definition: regs.hpp:19
Arch::stackframe
Definition: Arch.i686.hpp:18
Arch::registersPrintInformation
void registersPrintInformation(struct registers *regs)
Print register information to all kernel terminals (serial, framebuffer, etc.). Used for panic and de...
Definition: Arch.i686.cpp:67
Arch::CPU::model
const char * model()
Definition: Arch.i686.cpp:134
Arch::haltAndCatchFire
void haltAndCatchFire()
Disable interrupts and halts execution.
Definition: Arch.hpp:42
Arch::CPU
Definition: Arch.hpp:70
Arch
Definition: Arch.hpp:33