WKern
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1/*
2WKern - A Bare Metal OS / Kernel I am maKing (For Fun)
3Copyright (C) 2025 Wdboyes13
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#include <KShell/shell.h>
20#include <err/kerror.h>
21#include <fileio/fileio.h>
22#include <global.h>
23#include <idt/idtirq.h>
24#include <io/kio.h>
25#include <mem/kmem.h>
26#include <net/virtnet.h>
27#include <pci/pci.h>
28#include <types/bool.h>
29#include <utils/util.h>
30
31char *name;
32int row = 0;
33int col = 0;
34bool capson = false;
35bool shift = false;
36u32 iob = 0;
51void KernelMain() {
52 AllIdt(); // Do all IDT/GDT Setup
53
54 u32 lba = FindFat16Partition(); // LooK for a FAT16 Partition on ATA
55 KprintHex(lba); // Print LBA Address
56 if (!lba) { // If an ATA FAT16 Partition was not found
57 lba = 0; // Set LBA To 0 (Superfloppy)
58 }
59 if (!Fat16Mount(lba)) { // Try mounting
60 Panic("Failed to mount FAT16 volume"); // If mount fails panic
61 }
62
63 KheapInit(); // Initialize Heap
64
65 Kcfp();
67 Kprintf("\nHello form WKern!\n");
68 Kprintf("Enter your name: ");
69 Kgetstr(name, 19);
70 Kputchar('\n');
71
72 Kprintf("Hello, %s\n", name);
73
74 Kflush();
75 Kprintf("Welcome!\n\nStarting...\n");
76 ZZZ(5);
77 Sh();
78}
void KheapInit()
Initialize Memory Heap.
Definition alloc.c:35
u32 Fat16Mount(u32 partition_lba)
Mounts the FAT16 filesystem from a given partition LBA.
Definition fat16_mnt.c:67
Definitions and declarations for FAT16 filesystem and ATA I/O.
u32 FindFat16Partition(void)
Finds the FAT16 partition on disk.
Definition MBR.c:69
u32 iob
Definition main.c:36
bool capson
Definition main.c:34
char * name
Definition main.c:31
bool shift
Definition main.c:35
int row
Definition main.c:32
int col
Definition main.c:33
void AllIdt()
Initialize and load the Interrupt Descriptor Table (IDT)
Definition idt.c:73
void Panic(const char *msg)
void Kgetstr(char *str, int length)
Reads a line of input from the keyboard (blocking).
Definition keyin.c:186
void Kflush()
Flushes the keyboard controller input buffer.
Definition keyin.c:219
void Kprintf(const char *fmt,...)
Formatted output to the screen.
Definition printer.c:152
void Kcfp()
Clears the screen by filling the video memory with spaces.
Definition printer.c:28
void KprintHex(u32 num)
Prints a 32-bit unsigned integer in hexadecimal format prefixed with "0x".
Definition printer.c:92
void Kputchar(char c)
Outputs a single character to the screen at the current cursor position.
Definition printer.c:46
void ZZZ(int ms)
Sleeps for 10ms.
Definition ksleep.c:25
void KernelMain()
Kernel entry point.
Definition main.c:51
unsigned int u32
32-Bit Unsigned Int
Definition nums.h:30
void Sh()
The main interactive WKern shell loop.
Definition shell.c:144
void VirtnetSetup()
Performs full setup of the VirtIO network device.
Definition virtio.c:176