164 lines
3.9 KiB
C
164 lines
3.9 KiB
C
/*----------------*\
|
|
|Nanite OS |
|
|
|Copyright (C) 2026|
|
|
|Xircon |
|
|
\*----------------*/
|
|
|
|
// Architecture specific
|
|
|
|
#ifdef __I686
|
|
#include <arch/i686/io.h>
|
|
#include <arch/i686/irq.h>
|
|
#include <arch/i686/util.h>
|
|
#include <arch/i686/cpuid.h>
|
|
#endif
|
|
|
|
#ifdef __XTENSA
|
|
|
|
#endif
|
|
|
|
#ifdef __AARCH64
|
|
|
|
#endif
|
|
|
|
// stdlibs
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <memory.h>
|
|
#include <nanstd.h>
|
|
#include <string.h>
|
|
|
|
// Drivers
|
|
|
|
#include <dri/keyboard.h>
|
|
#include <dri/cmos.h>
|
|
#include <dri/timer.h>
|
|
#include <dri/serial.h>
|
|
#include <dri/fs/fat.h>
|
|
#include <dri/disk/floppy.h>
|
|
#include <dri/disk/ata.h>
|
|
#include <dri/sound/pcspeaker.h>
|
|
|
|
// Core
|
|
|
|
#include <core/hal/hal.h>
|
|
#include <core/memory/vmm.h>
|
|
|
|
// Utilities
|
|
|
|
#include <util/param.h>
|
|
#include <util/util.h>
|
|
#include <util/binary.h>
|
|
|
|
// Other
|
|
|
|
#include <version.h>
|
|
#include <multiboot.h>
|
|
|
|
// Declarations
|
|
|
|
extern uint8_t __bss_start; // Start of Kernel in memory
|
|
extern uint8_t __end; // End of Kernel in memory
|
|
|
|
extern int uptime; // System uptime measured by precision timer unit.
|
|
|
|
uint16_t DEBUG_COM_PORT = COM1_PORT; // COM Port to Output Debug strings to
|
|
|
|
/*Main Kernel Function*/
|
|
void start(unsigned long magic, unsigned long address) {
|
|
|
|
struct multiboot_tag* tag;
|
|
|
|
// Print logo
|
|
clrscr();
|
|
printf("%s", LOGO);
|
|
#ifdef __I686
|
|
printf("[i686]\n");
|
|
#endif
|
|
#ifdef __XTENSA
|
|
printf("[Xtensa]\n");
|
|
#endif
|
|
#ifdef __AARCH64
|
|
printf("[Arm64]\n");
|
|
#endif
|
|
|
|
printf("The Nano OS %s\n--------------------------------------------\n", VERSION);
|
|
printTip();
|
|
printf("--------------------------------------------\n");
|
|
|
|
// Multiboot Debug Stuff
|
|
// if (magic != MULTIBOOT2_BOOTLOADER_MAGIC) {
|
|
// printf ("Invalid magic number: 0x%x\n", (unsigned) magic);
|
|
// return;
|
|
// }
|
|
|
|
// if (address & 7) {
|
|
// printf("Unaligned mbi: 0x%x\n", address);
|
|
// return;
|
|
// }
|
|
|
|
printf("Initializing Basic Drivers...");
|
|
// HAL
|
|
HAL_Initialize();
|
|
// Register IRQs
|
|
#ifdef __I686
|
|
IRQ_RegisterHandler(0, Timer_Handler);
|
|
IRQ_RegisterHandler(1, Keyboard_Handler);
|
|
IRQ_RegisterHandler(4, COM1_Serial_Handler);
|
|
IRQ_RegisterHandler(6, Floppy_Handler);
|
|
IRQ_RegisterHandler(8, CMOS_RTC_Handler);
|
|
srand(Read_CMOS(CMOS_RTC_Hours) + Read_CMOS(CMOS_RTC_Seconds));
|
|
#endif
|
|
// Other Stuff
|
|
Serial_Init(DEBUG_COM_PORT, 9600);
|
|
Keyboard_Init();
|
|
// Storage
|
|
// Floppy_Init(); // This should always be last; its slow as fuck
|
|
printf("Done!\n");
|
|
|
|
// Hardware Detection
|
|
Serial_Printf(DEBUG_COM_PORT, "MEMORY:> There is %dKB of Memory Available\nThe Kernel is loaded between 0x%x and 0x%x\n", Detect_Memory(), __bss_start, __end);
|
|
printf("%dKB Of Memory Availible!\n", Detect_Memory());
|
|
// printf("Random Number! %u\n", rand());
|
|
|
|
// Serial_Printf(DEBUG_COM_PORT, "CPU Vendor: %s\n", CPUID_Get_Vendor()); // CPUID Stuff is pain and suffering, like page faults and suffering
|
|
|
|
// printf("Initializing Memory Paging...");
|
|
// Memory_Page_Init();
|
|
// printf("Done!\n");
|
|
|
|
// Finish Up
|
|
printf("The Current Time and Date Is: %d:%d:%d %d/%d/%d%d\n",
|
|
BCD2BIN(Read_CMOS(CMOS_RTC_Hours)),
|
|
BCD2BIN(Read_CMOS(CMOS_RTC_Minutes)),
|
|
BCD2BIN(Read_CMOS(CMOS_RTC_Seconds)),
|
|
BCD2BIN(Read_CMOS(CMOS_RTC_Day)),
|
|
BCD2BIN(Read_CMOS(CMOS_RTC_Month)),
|
|
BCD2BIN(Read_CMOS(CMOS_RTC_Century)),
|
|
BCD2BIN(Read_CMOS(CMOS_RTC_Year)));
|
|
// Beep!
|
|
PCSP_Beep();
|
|
char* answer = "\0";
|
|
printf("Would you like to change the time and date? [y/N] ");
|
|
scanf("%s", answer);
|
|
if (!strcmp(answer, "Y") || !strcmp(answer, "y")) {
|
|
printf("Please insert Date and Time in [SS]:[MM]:[HH] [DD]/[MM]/[YYYY] Format: ");
|
|
scanf("%s", answer);
|
|
printf("\n");
|
|
}
|
|
printf("Starting Shell...");
|
|
spinner(20);
|
|
printf("Done!\n");
|
|
for(;;) {
|
|
printf(":>");
|
|
scanf("");
|
|
}
|
|
|
|
end:
|
|
for (;;);
|
|
}
|
|
|
|
|