forked from includeos/IncludeOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos.cpp
More file actions
119 lines (106 loc) · 2.6 KB
/
Copy pathos.cpp
File metadata and controls
119 lines (106 loc) · 2.6 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <kernel.hpp>
#include <kernel/events.hpp>
#include <kernel/rng.hpp>
#include <kernel/service.hpp>
#include <kernel/timers.hpp>
#include <system_log>
#include <sys/random.h>
#include <sys/time.h>
#include <unistd.h>
#ifndef PORTABLE_USERSPACE
#include <sched.h>
#include "epoll_evloop.hpp"
#endif
void os::event_loop()
{
Events::get().process_events();
do
{
Timers::timers_handler();
Events::get().process_events();
#ifndef PORTABLE_USERSPACE
if (kernel::is_running()) linux::epoll_wait_events();
#endif
Events::get().process_events();
}
while (kernel::is_running());
// call on shutdown procedure
Service::stop();
}
#include <kernel/rtc.hpp>
#include <time.h>
RTC::timestamp_t RTC::booted_at = time(0);
#include <smp>
int SMP::cpu_id() noexcept {
return 0;
}
void SMP::global_lock() noexcept {}
void SMP::global_unlock() noexcept {}
void SMP::add_task(SMP::task_func, int) {}
void SMP::signal(int) {}
// timer system
static void begin_timer(std::chrono::nanoseconds) {}
static void stop_timers() {}
void kernel::start(const char* cmdline)
{
kernel::state().libc_initialized = true;
// setup timer system
Timers::init(begin_timer, stop_timers);
Timers::ready();
// seed RNG with entropy
char entropy[2048];
ssize_t rngres = getrandom(entropy, sizeof(entropy), 0);
assert(rngres == sizeof(entropy));
rng_absorb(entropy, sizeof(entropy));
// fake CPU frequency
kernel::state().cmdline = cmdline;
kernel::state().cpu_khz = decltype(os::cpu_freq()) {3000000ul};
}
// stdout
void kernel::default_stdout(const char* text, size_t len)
{
ssize_t bytes = write(STDOUT_FILENO, text, len);
assert(bytes == (ssize_t) len);
}
// system_log has no place on Linux because stdout goes --> pipe
void SystemLog::initialize() {}
#ifdef __MACH__
#include <stdlib.h>
#include <stddef.h>
#include <gsl/gsl_assert>
void* memalign(size_t alignment, size_t size) {
void* ptr {nullptr};
int res = posix_memalign(&ptr, alignment, size);
Ensures(res == 0);
return ptr;
}
void* aligned_alloc(size_t alignment, size_t size) {
return memalign(alignment, size);
}
#endif
multiboot_info_t* kernel::bootinfo() {
return nullptr;
}
void kernel::init_heap(uintptr_t, uintptr_t) noexcept {
}
bool kernel::heap_ready() { return true; }
bool os::mem::heap_ready() { return true; }
size_t kernel::heap_usage() noexcept {
return 0;
}
size_t kernel::heap_avail() noexcept {
return 0xFFFFFFFF;
}
uintptr_t kernel::heap_end() noexcept {
return 0x7FFFFFFF;
}
#include <memory>
namespace os::mem
{
uintptr_t virt_to_phys(uintptr_t linear) {
return linear;
}
size_t min_psize() {
return 4096;
}
}