1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-10-30 11:54:01 -04:00
libkernaux/examples/bootloader-stivale2-limine/main.c

46 lines
1.3 KiB
C
Raw Normal View History

2022-01-09 23:31:41 -05:00
#include <stdint.h>
#include <stddef.h>
#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();
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))) {
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
}