2022-01-09 23:31:41 -05:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2022-01-15 08:04:46 -05:00
|
|
|
#include <kernaux/console.h>
|
|
|
|
|
2022-01-09 23:31:41 -05:00
|
|
|
#include "stivale2.h"
|
2022-01-12 04:40:35 -05:00
|
|
|
|
|
|
|
static void poweroff();
|
|
|
|
|
2022-01-15 08:10:47 -05:00
|
|
|
uint8_t stack[8192];
|
2022-01-09 23:31:41 -05:00
|
|
|
|
|
|
|
// We will now write a helper function which will allow us to scan for tags
|
|
|
|
// that we want FROM the bootloader (structure tags).
|
|
|
|
void *stivale2_get_tag(struct stivale2_struct *stivale2_struct, uint64_t id) {
|
|
|
|
struct stivale2_tag *current_tag = (void *)stivale2_struct->tags;
|
|
|
|
for (;;) {
|
|
|
|
// If the tag pointer is NULL (end of linked list), we did not find
|
|
|
|
// the tag. Return NULL to signal this.
|
|
|
|
if (current_tag == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the identifier matches. If it does, return a pointer
|
|
|
|
// to the matching tag.
|
|
|
|
if (current_tag->identifier == id) {
|
|
|
|
return current_tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a pointer to the next tag in the linked list and repeat.
|
|
|
|
current_tag = (void *)current_tag->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The following will be our kernel's entry point.
|
2022-01-12 04:45:13 -05:00
|
|
|
void _start(struct stivale2_struct *stivale2_struct __attribute__((unused))) {
|
2022-01-15 08:04:46 -05:00
|
|
|
kernaux_console_puts("Hello, World!");
|
2022-01-12 04:40:35 -05:00
|
|
|
poweroff();
|
|
|
|
}
|
|
|
|
|
|
|
|
void poweroff()
|
|
|
|
{
|
|
|
|
const uint16_t port = 0x604;
|
|
|
|
const uint16_t value = 0x2000;
|
|
|
|
__asm__ volatile("outw %1, %0" : : "dN" (port), "a" (value));
|
2022-01-09 23:31:41 -05:00
|
|
|
}
|