-
Notifications
You must be signed in to change notification settings - Fork 4
/
global.hpp
98 lines (86 loc) · 2.63 KB
/
global.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma once
#include "hw/vga_stream.hpp"
#include "oslibc/assert.hpp"
#ifdef TESTING_ENABLED
#include <iostream>
#endif
namespace cloudos {
struct global_state;
class allocator;
struct page_allocator;
struct map_virtual;
struct segment_table;
struct interrupt_handler;
struct driver_store;
struct interface_store;
struct device;
struct scheduler;
struct process_fd;
struct rng;
struct clock_store;
struct initrdfs;
struct terminal_store;
struct shmfs;
struct blockdev_store;
struct process_store;
extern global_state *global_state_;
struct global_state {
global_state();
char *cmdline;
cloudos::allocator *alloc;
cloudos::page_allocator *page_allocator;
cloudos::map_virtual *map_virtual;
cloudos::segment_table *gdt; /* for TSS access */
cloudos::interrupt_handler *interrupt_handler;
cloudos::vga_stream *vga;
cloudos::driver_store *driver_store;
cloudos::interface_store *interface_store;
cloudos::device *root_device;
cloudos::scheduler *scheduler;
cloudos::process_fd *init;
cloudos::rng *random;
cloudos::clock_store *clock_store;
cloudos::initrdfs *initrdfs;
cloudos::terminal_store *terminal_store;
cloudos::shmfs *shmfs;
cloudos::blockdev_store *blockdev_store;
cloudos::process_store *process_store;
};
__attribute__((noreturn)) inline void kernel_panic(const char *message) {
#ifdef TESTING_ENABLED
std::cerr << "Kernel panic occurred during testing: " << message << "\n";
abort();
#else
if(global_state_ && global_state_->vga) {
*(global_state_->vga) << "!!! KERNEL PANIC - HALTING !!!\n" << message;
}
asm volatile("cli; halted: hlt; jmp halted;");
while(1) {}
#endif
}
#define GET_GLOBAL(NAME, TYPE, MEMBER) \
inline TYPE *get_##NAME() { \
assert(global_state_ && global_state_->MEMBER); \
return global_state_->MEMBER; \
}
GET_GLOBAL(allocator, allocator, alloc)
GET_GLOBAL(page_allocator, page_allocator, page_allocator)
GET_GLOBAL(map_virtual, map_virtual, map_virtual)
GET_GLOBAL(gdt, segment_table, gdt)
GET_GLOBAL(interrupt_handler, interrupt_handler, interrupt_handler);
GET_GLOBAL(driver_store, driver_store, driver_store)
GET_GLOBAL(interface_store, interface_store, interface_store)
GET_GLOBAL(root_device, device, root_device)
GET_GLOBAL(scheduler, scheduler, scheduler)
GET_GLOBAL(random, rng, random)
GET_GLOBAL(clock_store, clock_store, clock_store);
GET_GLOBAL(initrdfs, initrdfs, initrdfs);
GET_GLOBAL(terminal_store, terminal_store, terminal_store);
GET_GLOBAL(shmfs, shmfs, shmfs);
GET_GLOBAL(blockdev_store, blockdev_store, blockdev_store);
GET_GLOBAL(process_store, process_store, process_store);
inline vga_stream &get_vga_stream() {
assert(global_state_ && global_state_->vga);
return *global_state_->vga;
}
}