added pretty colors & fixed header guards

This commit is contained in:
rami 2024-05-22 12:25:52 -04:00
parent 33e53c70b2
commit 216e3e59fb
13 changed files with 65 additions and 31 deletions

View File

@ -1,5 +1,5 @@
#ifndef ACPI_H_ #ifndef RK_ACPI_H_
#define ACPI_H_ #define RK_ACPI_H_
#include <stdint.h> #include <stdint.h>

View File

@ -1,5 +1,5 @@
#ifndef GDT_H_ #ifndef RK_GDT_H_
#define GDT_H_ #define RK_GDT_H_
#define GDT_NULL 0 #define GDT_NULL 0
#define GDT_KERNEL_CODE 1 #define GDT_KERNEL_CODE 1

View File

@ -1,5 +1,5 @@
#ifndef IDE_H_ #ifndef RK_IDE_H_
#define IDE_H_ #define RK_IDE_H_
enum IDE_MODE { enum IDE_MODE {
ISA_ONLY = 0x00, ISA_ONLY = 0x00,

View File

@ -1,5 +1,5 @@
#ifndef ANDEWOS_IDT_H_ #ifndef RK_IDT_H_
#define ANDEWOS_IDT_H_ #define RK_IDT_H_
#include <stdint.h> #include <stdint.h>

View File

@ -1,5 +1,5 @@
#ifndef IO_H_ #ifndef RK_IO_H_
#define IO_H_ #define RK_IO_H_
#include <stdint.h> #include <stdint.h>

View File

@ -1,5 +1,5 @@
#ifndef MULTIBOOT_H_ #ifndef RK_MULTIBOOT_H_
#define MULTIBOOT_H_ #define RK_MULTIBOOT_H_
#include <stdint.h> #include <stdint.h>

View File

@ -1,5 +1,5 @@
#ifndef PCI_H_ #ifndef RK_PCI_H_
#define PCI_H_ #define RK_PCI_H_
#include <stdint.h> #include <stdint.h>
#include <acpi.h> #include <acpi.h>

View File

@ -1,5 +1,5 @@
#ifndef ANDEWOS_PIC8259_H #ifndef RK_PIC8259_H
#define ANDEWOS_PIC8259_H #define RK_PIC8259_H
#define PIC_1_COMMAND 0x20 #define PIC_1_COMMAND 0x20
#define PIC_2_COMMAND 0xA0 #define PIC_2_COMMAND 0xA0

View File

@ -1,5 +1,5 @@
#ifndef ANDEWOS_PS2_H #ifndef RK_PS2_H
#define ANDEWOS_PS2_H #define RK_PS2_H
#define PS2_8042_DATA 0x60 #define PS2_8042_DATA 0x60
#define PS2_8042_STATUS 0x64 #define PS2_8042_STATUS 0x64

View File

@ -13,14 +13,31 @@
#define VGA_MAX_COLS 80 #define VGA_MAX_COLS 80
#define VGA_MAX_ROWS 25 #define VGA_MAX_ROWS 25
#define WHITE_ON_BLACK 0x0f
#define CRTC_ADDR_PORT 0x3d4 #define CRTC_ADDR_PORT 0x3d4
#define CRTC_DATA_PORT 0x3d5 #define CRTC_DATA_PORT 0x3d5
#define CRTC_CURSOR_LO_REGISTER 0x0f #define CRTC_CURSOR_LO_REGISTER 0x0f
#define CRTC_CURSOR_HI_REGISTER 0x0e #define CRTC_CURSOR_HI_REGISTER 0x0e
enum VGA_COLOR {
VGA_COLOR_BLACK = 0,
VGA_COLOR_BLUE = 1,
VGA_COLOR_GREEN = 2,
VGA_COLOR_CYAN = 3,
VGA_COLOR_RED = 4,
VGA_COLOR_MAGENTA = 5,
VGA_COLOR_BROWN = 6,
VGA_COLOR_LIGHT_GREY = 7,
VGA_COLOR_DARK_GREY = 8,
VGA_COLOR_LIGHT_BLUE = 9,
VGA_COLOR_LIGHT_GREEN = 10,
VGA_COLOR_LIGHT_CYAN = 11,
VGA_COLOR_LIGHT_RED = 12,
VGA_COLOR_LIGHT_MAGENTA = 13,
VGA_COLOR_LIGHT_BROWN = 14,
VGA_COLOR_WHITE = 15
};
/** /**
* @brief Gets the text-mode cursor's position. * @brief Gets the text-mode cursor's position.
* *
@ -43,4 +60,6 @@ void clear_screen(void);
void popchar(); void popchar();
void set_color(enum VGA_COLOR col);
#endif #endif

25
kmain.c
View File

@ -28,6 +28,7 @@ extern void ps2_isr();
void kmain(struct multiboot_info *info) { void kmain(struct multiboot_info *info) {
clear_screen(); clear_screen();
set_color(VGA_COLOR_CYAN);
// Check if the bootloader gave us the upper and lower memory // Check if the bootloader gave us the upper and lower memory
if (!(info->flags & 0x1)) goto halt; if (!(info->flags & 0x1)) goto halt;
@ -41,16 +42,17 @@ void kmain(struct multiboot_info *info) {
asm volatile ("lidt %0" :: "m"(g_idtr)); asm volatile ("lidt %0" :: "m"(g_idtr));
struct rsdp *found_rsdp = acpi_locate_rsdp(); struct rsdp *found_rsdp = acpi_locate_rsdp();
if (!found_rsdp) { if (!found_rsdp) {
set_color(VGA_COLOR_RED);
printf("Failed to find RSDP signature\n"); printf("Failed to find RSDP signature\n");
goto halt; goto halt;
} }
printf("RSDP detected at 0x%X\n", found_rsdp);
if (found_rsdp->Revision == ACPI_VER_1) { if (found_rsdp->Revision == ACPI_VER_1) {
if (!acpi_validate_rsdp_checksum(found_rsdp)) { if (!acpi_validate_rsdp_checksum(found_rsdp)) {
set_color(VGA_COLOR_RED);
printf("RSDP has an invalid checksum\n"); printf("RSDP has an invalid checksum\n");
goto halt; goto halt;
} }
@ -58,18 +60,19 @@ void kmain(struct multiboot_info *info) {
ctx.xsdp = 0; ctx.xsdp = 0;
if (!acpi_validate_sdt_checksum((struct ACPISDTHeader *)found_rsdp->RsdtAddress)) { if (!acpi_validate_sdt_checksum((struct ACPISDTHeader *)found_rsdp->RsdtAddress)) {
set_color(VGA_COLOR_RED);
printf("RSDT has an invalid checksum\n"); printf("RSDT has an invalid checksum\n");
goto halt; goto halt;
} }
ctx.rsdt = (struct rsdt*)found_rsdp->RsdtAddress; ctx.rsdt = (struct rsdt*)found_rsdp->RsdtAddress;
printf("RSDT detected at 0x%X\n", found_rsdp->RsdtAddress);
} else if (found_rsdp->Revision == ACPI_VER_OTHER) { } else if (found_rsdp->Revision == ACPI_VER_OTHER) {
printf("ACPI versions higher than 1.0 are not supported\n"); set_color(VGA_COLOR_RED);
printf("ACPI versions higher than 1.0 are not yet supported because I'm lazy\n");
goto halt; goto halt;
} else { } else {
set_color(VGA_COLOR_RED);
printf("Invalid RSDP\n"); printf("Invalid RSDP\n");
goto halt; goto halt;
} }
@ -78,13 +81,15 @@ void kmain(struct multiboot_info *info) {
struct fadt *fadt = acpi_locate_sdt(ctx.rsdt, "FACP"); struct fadt *fadt = acpi_locate_sdt(ctx.rsdt, "FACP");
if (!fadt) { if (!fadt) {
set_color(VGA_COLOR_RED);
printf("Failed to find FADT\n"); printf("Failed to find FADT\n");
goto halt; goto halt;
} }
printf("Found FADT at 0x%x\n", fadt); printf("Found FADT at 0x%x\n", fadt);
if (fadt->Flags & 1) if (fadt->Flags & 1)
printf("Legacy devices are supported.\n"); printf("Legacy devices are supported\n");
else { else {
set_color(VGA_COLOR_RED);
printf("Legacy devices are not supported. I'm too lazy to support modern devices, bye bye.\n"); printf("Legacy devices are not supported. I'm too lazy to support modern devices, bye bye.\n");
goto halt; goto halt;
} }
@ -96,14 +101,18 @@ void kmain(struct multiboot_info *info) {
struct mcfg *mcfg = acpi_locate_sdt(ctx.rsdt, "MCFG"); struct mcfg *mcfg = acpi_locate_sdt(ctx.rsdt, "MCFG");
if (!mcfg) { if (!mcfg) {
printf("failed to find mcfg\n"); set_color(VGA_COLOR_RED);
printf("Failed to find MCFG\n");
} else { } else {
printf("Found MCFG at 0x%x\n", mcfg); printf("Looks like you are using PCIe- Found MCFG at 0x%x\n", mcfg);
struct pci_config_space *ide = pcie_find_device(mcfg, MASS_STORAGE_CONTROLLER, IDE_INTERFACE); struct pci_config_space *ide = pcie_find_device(mcfg, MASS_STORAGE_CONTROLLER, IDE_INTERFACE);
if (ide) printf("IDE controller detected. Program Interface: %X\n", ide->program_interface); if (ide) printf("IDE controller detected. Program Interface: %X\n", ide->program_interface);
} }
set_color(VGA_COLOR_WHITE);
printf("You are now being dropped into a kernel shell\n$ ");
halt: halt:
for (;;) {} for (;;) {}
} }

4
ps2.c
View File

@ -33,14 +33,14 @@ void initialize_8042ps2() {
outportb(PS2_8042_COMMAND, 0xAA); outportb(PS2_8042_COMMAND, 0xAA);
while (!(inportb(PS2_8042_STATUS) & 0x1)) cpu_relax; while (!(inportb(PS2_8042_STATUS) & 0x1)) cpu_relax;
uint8_t result = inportb(PS2_8042_DATA); uint8_t result = inportb(PS2_8042_DATA);
if (result == 0x55) printf("Passed PS/2 self test!\n"); if (result == 0x55) printf("Passed PS/2 self test\n");
else printf("Failed!\n"); else printf("Failed!\n");
// perform port test // perform port test
outportb(PS2_8042_COMMAND, 0xAB); outportb(PS2_8042_COMMAND, 0xAB);
while (!(inportb(PS2_8042_STATUS) & 0x1)) cpu_relax; while (!(inportb(PS2_8042_STATUS) & 0x1)) cpu_relax;
result = inportb(PS2_8042_DATA); result = inportb(PS2_8042_DATA);
if (!result) printf("Passed PS/2 port 1 test!!\n"); if (!result) printf("Passed PS/2 port 1 test\n");
else printf("Failed!\n"); else printf("Failed!\n");
// enable ps/2 port // enable ps/2 port

8
vga.c
View File

@ -10,6 +10,8 @@
#include <io.h> #include <io.h>
#include <printf.h> #include <printf.h>
enum VGA_COLOR vga_color = VGA_COLOR_WHITE;
uint16_t get_cursor_pos() { uint16_t get_cursor_pos() {
uint16_t pos = 0; uint16_t pos = 0;
@ -55,7 +57,7 @@ void _putchar(char character) {
set_cursor_pos(next_line); set_cursor_pos(next_line);
} else { } else {
video_memory[0] = character; video_memory[0] = character;
video_memory[1] = WHITE_ON_BLACK; video_memory[1] = vga_color;
set_cursor_pos(pos + 1); set_cursor_pos(pos + 1);
} }
} }
@ -67,3 +69,7 @@ void popchar() {
video_memory[0] = 0; video_memory[0] = 0;
set_cursor_pos(pos - 1); set_cursor_pos(pos - 1);
} }
void set_color(enum VGA_COLOR col) {
vga_color = col;
}