2019-12-28 13:47:10 +01:00
|
|
|
/* Check if the compiler thinks you are targeting the wrong operating system. */
|
|
|
|
#if defined(__linux__)
|
|
|
|
#error "You are not using a cross-compiler, you will most certainly run into trouble"
|
|
|
|
#endif
|
2020-01-28 22:25:37 +01:00
|
|
|
|
2019-12-28 13:47:10 +01:00
|
|
|
/* This tutorial will only work for the 32-bit ix86 targets. */
|
|
|
|
#if !defined(__i386__)
|
2020-01-08 22:36:49 +01:00
|
|
|
#error "This kernel needs to be compiled with a ix86-elf compiler"
|
2019-12-28 13:47:10 +01:00
|
|
|
#endif
|
2019-12-30 14:45:55 +01:00
|
|
|
|
2020-01-08 22:36:49 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "terminal.c"
|
|
|
|
#include "memory.c"
|
|
|
|
#include "interrupts.c"
|
2020-01-09 18:32:12 +01:00
|
|
|
#include "shell.c"
|
2020-01-28 22:25:37 +01:00
|
|
|
#include "util/printer.c"
|
2020-01-08 22:36:49 +01:00
|
|
|
|
|
|
|
static inline bool are_interrupts_enabled() {
|
|
|
|
unsigned long flags;
|
|
|
|
asm volatile ( "pushf\n\t"
|
|
|
|
"pop %0"
|
2020-01-28 22:25:37 +01:00
|
|
|
: "=g"(flags));
|
2020-01-08 22:36:49 +01:00
|
|
|
return flags & (1 << 9);
|
|
|
|
}
|
|
|
|
|
2020-01-28 22:25:37 +01:00
|
|
|
void kernel_main(void) {
|
|
|
|
/* Initialize terminal interface */
|
|
|
|
terminal_initialize();
|
|
|
|
|
|
|
|
terminal_putchar('H');
|
|
|
|
terminal_putchar('e');
|
|
|
|
terminal_putchar('l');
|
|
|
|
terminal_putchar('l');
|
|
|
|
terminal_putchar('o');
|
2019-12-30 16:02:43 +01:00
|
|
|
|
2019-12-28 21:05:22 +01:00
|
|
|
terminal_setcolor(vga_entry_color(VGA_COLOR_GREEN, VGA_COLOR_BLACK));
|
2020-01-28 22:25:37 +01:00
|
|
|
print(" kernel");
|
2019-12-28 21:05:22 +01:00
|
|
|
terminal_setcolor(vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK));
|
2020-01-28 22:25:37 +01:00
|
|
|
print(" World!\n");
|
|
|
|
print("Newlines!\n");
|
2020-01-07 14:53:27 +01:00
|
|
|
|
2020-01-28 22:25:37 +01:00
|
|
|
char *memory_str = alloc(sizeof(char) * 7);
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
memory_str[i] = "Memory"[i];
|
|
|
|
}
|
|
|
|
memory_str[6] = 0;
|
2020-01-08 22:36:49 +01:00
|
|
|
|
2020-01-28 22:25:37 +01:00
|
|
|
char *management_str = alloc(sizeof(char) * 13);
|
2020-01-28 18:54:42 +01:00
|
|
|
for (int i = 0; i < 13; i++) {
|
2020-01-28 22:25:37 +01:00
|
|
|
management_str[i] = " management!\n"[i];
|
2020-01-28 18:54:42 +01:00
|
|
|
}
|
2020-01-28 22:25:37 +01:00
|
|
|
management_str[13] = 0;
|
2020-01-28 18:54:42 +01:00
|
|
|
|
2020-01-28 22:25:37 +01:00
|
|
|
print(memory_str);
|
|
|
|
print(management_str);
|
2020-01-28 18:54:42 +01:00
|
|
|
|
2020-01-28 22:25:37 +01:00
|
|
|
free(memory_str);
|
|
|
|
free(management_str);
|
2020-01-28 18:54:42 +01:00
|
|
|
|
|
|
|
|
2020-01-28 22:25:37 +01:00
|
|
|
print((are_interrupts_enabled()) ? "Interrupts!\n" : "No interrupts :(\n");
|
2020-01-08 22:36:49 +01:00
|
|
|
|
2020-01-28 22:25:37 +01:00
|
|
|
interrupt_init();
|
2020-01-08 22:36:49 +01:00
|
|
|
|
2020-01-28 22:25:37 +01:00
|
|
|
for (;;) {
|
|
|
|
shell_step();
|
|
|
|
}
|
2019-12-28 13:47:10 +01:00
|
|
|
}
|