Xyris  0.5
Entry.cpp
Go to the documentation of this file.
1 /**
2  * @file entry.cpp
3  * @author Keeton Feavel ([email protected])
4  * @brief The entry point into the Xyris kernel.
5  * @version 0.3
6  * @date 2019-11-14
7  *
8  * @copyright Copyright the Xyris Contributors (c) 2019
9  *
10  */
11 #include "Logger.hpp"
12 #include "Panic.hpp"
13 // System library functions
14 #include <Library/stdio.hpp>
15 #include <Library/time.hpp>
16 #include <Scheduler/tasks.hpp>
17 // Bootloader
18 #include <Bootloader/Handoff.hpp>
19 // Architecture specific code
20 #include <Arch/Arch.hpp>
21 // Memory management & paging
22 #include <Memory/paging.hpp>
23 // Generic devices
24 #include <Devices/Clock/rtc.hpp>
28 #include <Devices/Serial/rs232.hpp>
29 // Apps
30 #include <Applications/primes.hpp>
31 #include <Applications/spinner.hpp>
32 // Meta
33 #include <Support/defines.hpp>
34 #include <stdint.h>
35 
36 static void printSplash();
37 static void bootTone();
38 
39 // TODO: Find a better way of doing this in the future
40 // Maybe some sort of way to register driver init
41 // functions that can be walked and called?
42 static void devInit()
43 {
45  RTC::init();
46 }
47 
48 static void printSplash()
49 {
51  "\033[93m"
52  "Xyris %s\n"
53  "Copyright the Xyris Contributors (c) %i. All rights reserved.\n"
54  "Kernel source available at %s.\n"
55  "\033[0m",
56  VER_NAME,
57  BUILD_DATE,
58  REPO_URL);
59  Console::printf("Commit %s (v%s.%s.%s) built on %s at %s.\n\n", COMMIT, VER_MAJOR, VER_MINOR, VER_PATCH, __DATE__, __TIME__);
60 }
61 
62 static void bootTone()
63 {
64  // Beep beep!
65  spkr_beep(1000, 50);
66  spkr_beep(1000, 50);
67 }
68 
69 /**
70  * _ __ _ ___ _
71  * | |/ /___ _ _ _ _ ___| | | __|_ _| |_ _ _ _ _
72  * | ' </ -_) '_| ' \/ -_) | | _|| ' \ _| '_| || |
73  * |_|\_\___|_| |_||_\___|_| |___|_||_\__|_| \_, |
74  * |__/
75  */
76 
77 /**
78  * @brief This is the Xyris kernel entry point. This function is called directly
79  * from the assembly written in boot.S located in Arch/i686/boot.S. The pragma
80  * allows this function to be declared without needing a former declaration.
81  */
82 void kernelEntry(void* info, uint32_t magic)
83 {
86 
87  Boot::Handoff handoff(info, magic);
88  Memory::init(handoff.MemoryMap());
90  tasks_init();
91 
92  printSplash();
94  Console::printf("UTC: %i/%i/%i %i:%i\n",
95  time.getMonth(),
96  time.getDay(),
97  time.getYear(),
98  time.getHour(),
99  time.getMinutes());
100  Logger::Info(__func__, "%s\n%s\n", Arch::CPU::vendor(), Arch::CPU::model());
101 
102  struct task compute, status, spinner;
103  tasks_new(Apps::find_primes, &compute, TASK_READY, "prime_compute");
104  tasks_new(Apps::show_primes, &status, TASK_READY, "prime_display");
105  tasks_new(Apps::spinner, &spinner, TASK_READY, "spinner");
106  // Now that we're done make a joyful noise
107  bootTone();
108 
109  // Keep the kernel task alive.
111  panic("Kernel terminated unexpectedly!");
112 }
Boot::Handoff
Definition: Handoff.hpp:88
stdio.hpp
tasks_init
void tasks_init()
Initializes the kernel task manager.
Definition: tasks.cpp:151
Arch::CPU::init
void init()
Definition: Arch.i686.cpp:110
Boot::Handoff::MemoryMap
Memory::MemoryMap * MemoryMap()
Definition: Handoff.hpp:98
Arch::CPU::criticalRegion
void criticalRegion(Function critWork)
Definition: Arch.hpp:82
task
Definition: tasks.hpp:32
graphics.hpp
TASK_READY
@ TASK_READY
Definition: tasks.hpp:22
Arch::CPU::vendor
const char * vendor()
Definition: Arch.i686.cpp:127
Memory::init
void init(MemoryMap *map)
Sets up the environment, page directories etc and enables paging.
Definition: paging.cpp:57
Apps::show_primes
void show_primes(void)
Starts a task to display number of primes found by find_primes.
Definition: primes.cpp:37
console.hpp
Framebuffer console.
Time::TimeDescriptor::getHour
int getHour()
Definition: time.hpp:28
rtc.hpp
spkr.hpp
BUILD_DATE
#define BUILD_DATE
Definition: defines.hpp:31
spkr_beep
void spkr_beep(uint32_t freq, uint32_t ms)
Plays a given frequency for the provided duration.
Definition: spkr.cpp:36
tasks.hpp
tasks_new
struct task * tasks_new(void(*entry)(void), struct task *storage, task_state state, const char *name)
Creates a new kernel task with a provided entry point, register storage struct, and task state struct...
Definition: tasks.cpp:289
VER_MAJOR
#define VER_MAJOR
Definition: defines.hpp:19
primes.hpp
Prime computation tasks.
Time::TimeDescriptor
Definition: time.hpp:19
Apps::find_primes
void find_primes(void)
Starts a task to find prime numbers.
Definition: primes.cpp:27
rs232.hpp
A simple, write-only driver for the RS232 serial device standard. Code mostly ported from Panix-Archi...
RTC::init
void init()
Initializes the Real Time Clock driver for the x86_64 architecture.
Definition: rtc.cpp:43
Arch.hpp
Architecture control and initialization.
Logger::Info
static void Info(const char *tag, const char *fmt,...)
Definition: Logger.cpp:81
Apps::spinner
void spinner(void)
Starts a spinner in an infinite loop.
Definition: spinner.cpp:16
Panic.hpp
Kernel panic management.
defines.hpp
Compiler pre-processor definitions.
Time::TimeDescriptor::getMinutes
int getMinutes()
Definition: time.hpp:27
TASK_PAUSED
@ TASK_PAUSED
Definition: tasks.hpp:26
COMMIT
#define COMMIT
Definition: defines.hpp:15
REPO_URL
#define REPO_URL
Definition: defines.hpp:28
Time::TimeDescriptor::getDay
int getDay()
Definition: time.hpp:29
Time::TimeDescriptor::getYear
int getYear()
Definition: time.hpp:31
spinner.hpp
Kernel spinner task.
VER_PATCH
#define VER_PATCH
Definition: defines.hpp:21
Console::printf
int printf(const char *fmt,...)
Definition: console.cpp:273
Arch::CPU::model
const char * model()
Definition: Arch.i686.cpp:134
Handoff.hpp
RS232::init
void init(uint16_t com_id)
Activates the RS232 serial driver.
Definition: rs232.cpp:112
Boot::Handoff::FramebufferInfo
Graphics::Framebuffer * FramebufferInfo()
Definition: Handoff.hpp:96
paging.hpp
kernelEntry
void kernelEntry(void *info, uint32_t magic)
This is the Xyris kernel entry point. This function is called directly from the assembly written in b...
Definition: Entry.cpp:82
Time::TimeDescriptor::getMonth
int getMonth()
Definition: time.hpp:30
RS_232_COM1
#define RS_232_COM1
Definition: rs232.hpp:18
VER_NAME
#define VER_NAME
Definition: defines.hpp:25
time.hpp
Time lib code.
panic
void panic(const char *msg)
Halt the system and print the provided message on the panic screen.
Definition: Panic.cpp:82
VER_MINOR
#define VER_MINOR
Definition: defines.hpp:20
tasks_block_current
void tasks_block_current(task_state reason)
Blocks the current task.
Definition: tasks.cpp:422
Graphics::init
void init(Framebuffer *fb)
Initializes the framebuffer (if available)
Definition: graphics.cpp:32
Logger.hpp