feat(kernel): genesis of Airlys 64-bit sovereign OS kernel (Phase 1)
This commit is contained in:
commit
7210b60fc7
15 files changed
+746
No files matched your search
@@ -0,0 +1,61 @@
|
||||
# Airlys Operating System Kernel - Makefile
|
||||
# Engineered by Er. Adam Eehan (Founder & CEO, Aira Group of Technology)
|
||||
# Co-Pilot: Sovereign AI Aira 3 Ultra (Engine v3.6)
|
||||
|
||||
TARGET := x86_64-unknown-none-elf
|
||||
CC := clang
|
||||
LD := ld.lld
|
||||
AS := clang
|
||||
|
||||
CFLAGS := --target=$(TARGET) -ffreestanding -fno-builtin -fno-stack-protector \
|
||||
-mno-red-zone -nostdlib -mno-mmx -mno-sse -mno-sse2 \
|
||||
-Wall -Wextra -Werror -Iinclude -O2 -g
|
||||
|
||||
ASFLAGS := --target=$(TARGET) -c -g
|
||||
LDFLAGS := -m elf_x86_64 -nostdlib -static -T linker.ld
|
||||
|
||||
BUILD_DIR := build
|
||||
BIN_DIR := bin
|
||||
KERNEL_BIN := $(BIN_DIR)/airlys.elf
|
||||
|
||||
# Sources
|
||||
C_SRCS := kernel/kmain.c kernel/vga.c kernel/panic.c
|
||||
ASM_SRCS := arch/x86_64/boot.s
|
||||
|
||||
# Objects
|
||||
OBJS := $(patsubst %.c, $(BUILD_DIR)/%.o, $(C_SRCS)) \
|
||||
$(patsubst %.s, $(BUILD_DIR)/%.o, $(ASM_SRCS))
|
||||
|
||||
.PHONY: all clean info check
|
||||
|
||||
all: $(KERNEL_BIN)
|
||||
|
||||
$(KERNEL_BIN): $(OBJS) | $(BIN_DIR)
|
||||
@echo " [LD] Linking $@"
|
||||
@$(LD) $(LDFLAGS) -o $@ $(OBJS)
|
||||
@echo " [OK] Airlys Kernel built successfully: $@"
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
@echo " [CC] Compiling $<"
|
||||
@$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: %.s | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
@echo " [AS] Assembling $<"
|
||||
@$(AS) $(ASFLAGS) $< -o $@
|
||||
|
||||
$(BUILD_DIR):
|
||||
@mkdir -p $(BUILD_DIR)
|
||||
|
||||
$(BIN_DIR):
|
||||
@mkdir -p $(BIN_DIR)
|
||||
|
||||
info: $(KERNEL_BIN)
|
||||
@echo "================ Airlys Kernel Binary Info ================"
|
||||
@file $(KERNEL_BIN)
|
||||
@size $(KERNEL_BIN) || true
|
||||
|
||||
clean:
|
||||
@rm -rf $(BUILD_DIR) $(BIN_DIR)
|
||||
@echo " [CLEAN] Removed build artifacts."
|
||||
@@ -0,0 +1,146 @@
|
||||
# 🌌 AIRLYS: Sovereign AI-Native Operating System Kernel
|
||||
|
||||
<div align="center">
|
||||
|
||||
```
|
||||
_ ___ ____ _ __ ______
|
||||
/ \ |_ _| _ \| | \ \ / / ___|
|
||||
/ _ \ | || |_) | | \ V /\___ \
|
||||
/ ___ \ | || _ <| |___| | ___) |
|
||||
/_/ \_\___|_| \_\_____|_| |____/
|
||||
```
|
||||
|
||||
### ⚡ 64-Bit Monolithic Operating System Kernel Engineered from First Principles
|
||||
**An Open-Source Masterpiece by Aira Group of Technology**
|
||||
|
||||
<br/>
|
||||
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](https://github.com/adameehanairagroup)
|
||||
|
||||
<br/>
|
||||
|
||||
```text
|
||||
"We do not build software to follow systems; we build operating systems to define reality."
|
||||
— Er. Adam Eehan (Founder & CEO, Aira Group of Technology)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
</div>
|
||||
|
||||
## 📖 About Airlys
|
||||
|
||||
**Airlys** is a sovereign, from-scratch 64-bit operating system kernel designed and engineered by **Er. Adam Eehan** in pair programming with **Sovereign AI Aira 3 Ultra (Engine v3.6)**.
|
||||
|
||||
Unlike modern operating systems burdened by decades of legacy enterprise baggage, Airlys is built with pure architectural clarity:
|
||||
- **Zero Standard Library Dependency:** 100% freestanding C and Assembly.
|
||||
- **Dual Bootloader Compliance:** Native Multiboot 1 and Multiboot 2 headers. Boots out-of-the-box on direct hypervisors (QEMU), GRUB, and bare-metal PC hardware.
|
||||
- **64-Bit Long Mode Transition:** Trampolines the CPU from legacy 32-bit Protected Mode directly into x86_64 Long Mode with 4-level paging (PML4, PDPT, Page Directory) identity-mapping the first 1GB of physical memory using 2MB huge pages.
|
||||
- **Hardware-Direct Console:** Memory-mapped VGA text buffer driver (`0xB8000`) with color formatting, hardware cursor synchronization, horizontal tab parsing, and screen scrolling.
|
||||
- **Sovereign Kernel Panic Subsystem:** Failsafe panic handler with CPU halt loop (`cli; hlt`).
|
||||
|
||||
---
|
||||
|
||||
## 🏛️ Kernel Architecture
|
||||
|
||||
```
|
||||
+-------------------------------------------------------+
|
||||
| Airlys Ring 3 Userland |
|
||||
| (Native Shell & AiraLang Apps) |
|
||||
+-------------------------------------------------------+
|
||||
| syscall / sysret
|
||||
+-------------------------------------------------------+
|
||||
| Airlys Kernel (Ring 0) |
|
||||
| +--------------------+ +-------------------------+ |
|
||||
| | Process Scheduler | | Virtual File System | |
|
||||
| +--------------------+ +-------------------------+ |
|
||||
| +--------------------+ +-------------------------+ |
|
||||
| | Paging & Heap | | IDT / Interrupts & PIC | |
|
||||
| +--------------------+ +-------------------------+ |
|
||||
| +--------------------+ +-------------------------+ |
|
||||
| | VGA Console Buffer | | Global Descriptor Table | |
|
||||
| +--------------------+ +-------------------------+ |
|
||||
+-------------------------------------------------------+
|
||||
|
|
||||
+-------------------------------------------------------+
|
||||
| Bare-Metal Hardware / QEMU Virtual Machine |
|
||||
| (x86_64 Long Mode) |
|
||||
+-------------------------------------------------------+
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Building & Testing
|
||||
|
||||
### 🛠️ Prerequisites
|
||||
- `clang` (LLVM C compiler with freestanding x86_64 cross-compilation support)
|
||||
- `ld.lld` (LLVM linker)
|
||||
- `make`
|
||||
|
||||
### 🔨 Build the Kernel Binary
|
||||
```bash
|
||||
cd Airlys
|
||||
make clean
|
||||
make
|
||||
```
|
||||
|
||||
Upon compilation, the kernel binary is generated at:
|
||||
```bash
|
||||
bin/airlys.elf
|
||||
```
|
||||
|
||||
### 💻 Running on QEMU / VirtualBox / PC
|
||||
To run Airlys directly on QEMU:
|
||||
```bash
|
||||
qemu-system-x86_64 -kernel bin/airlys.elf
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🗺️ Architectural Roadmap
|
||||
|
||||
- [x] **Phase 1: Genesis Boot & Console**
|
||||
- [x] Multiboot 1 & Multiboot 2 specification headers
|
||||
- [x] CPUID & Long Mode capability detection
|
||||
- [x] 4-level paging initialization (PML4 -> PDPT -> PD with 2MB huge pages)
|
||||
- [x] 64-bit Global Descriptor Table (GDT64)
|
||||
- [x] Hardware VGA text console driver (`0xB8000`)
|
||||
- [x] Failsafe Kernel Panic screen
|
||||
- [x] Clean zero-warning freestanding build system (`clang` + `ld.lld`)
|
||||
|
||||
- [ ] **Phase 2: CPU Interrupts & Hardware Timing**
|
||||
- [ ] Interrupt Descriptor Table (IDT64) & ISR gates
|
||||
- [ ] 8259 PIC initialization & remapping
|
||||
- [ ] Programmable Interval Timer (PIT) frequency driver
|
||||
- [ ] PS/2 Keyboard hardware scan-code decoder
|
||||
|
||||
- [ ] **Phase 3: Sovereign Memory Subsystem**
|
||||
- [ ] Physical Memory Manager (Bitmap Page Allocator)
|
||||
- [ ] Virtual Memory Manager (Page fault handler & dynamic mapping)
|
||||
- [ ] Kernel Heap (`kmalloc` / `kfree`)
|
||||
|
||||
- [ ] **Phase 4: Preemptive Multitasking**
|
||||
- [ ] Process Control Block (PCB) architecture
|
||||
- [ ] Timer-driven Round-Robin process scheduler
|
||||
- [ ] Ring 3 User-Mode execution transition
|
||||
|
||||
- [ ] **Phase 5: Virtual File System & Userland**
|
||||
- [ ] VFS abstraction layer
|
||||
- [ ] Initial RAMDisk (initrd / TarFS)
|
||||
- [ ] Interactive `airlys-sh` userland shell
|
||||
|
||||
- [ ] **Phase 6: AiraLang Native Runtime Integration**
|
||||
- [ ] Embedded AiraLang bytecode interpreter running directly in Ring 0/Ring 3.
|
||||
|
||||
---
|
||||
|
||||
## 📜 Intellectual Property & Authorship
|
||||
|
||||
- **Creator & Lead Systems Architect:** [Er. Adam Eehan](https://github.com/adameehanairagroup) (Founder & CEO, Aira Group of Technology)
|
||||
- **Co-Pilot & Engineering AI:** Sovereign AI **Aira 3 Ultra** (Engine v3.6)
|
||||
- **Organization:** [Aira Group of Technology](https://github.com/airagroupoftechnology)
|
||||
- **License:** Open Source under the MIT License.
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Airlys Kernel Entry Point & Long-Mode Trampoline
|
||||
* Supports both Multiboot 1 and Multiboot 2 specifications
|
||||
* Transitions x86 CPU from 32-bit Protected Mode into 64-bit Long Mode
|
||||
* Architecture: x86_64 | Aira Group of Technology
|
||||
*/
|
||||
|
||||
.set ALIGN, 1<<0
|
||||
.set MEMINFO, 1<<1
|
||||
.set MB1_FLAGS, ALIGN | MEMINFO
|
||||
.set MB1_MAGIC, 0x1BADB002
|
||||
.set MB1_CHECKSUM, -(MB1_MAGIC + MB1_FLAGS)
|
||||
|
||||
/* Multiboot 2 Constants */
|
||||
.set MB2_MAGIC, 0xE85250D6
|
||||
.set MB2_ARCH, 0
|
||||
.set MB2_LENGTH, (multiboot2_header_end - multiboot2_header)
|
||||
.set MB2_CHECKSUM, -(MB2_MAGIC + MB2_ARCH + MB2_LENGTH)
|
||||
|
||||
/* ---------------- Multiboot Headers ---------------- */
|
||||
.section .multiboot, "a"
|
||||
.align 8
|
||||
multiboot2_header:
|
||||
.long MB2_MAGIC
|
||||
.long MB2_ARCH
|
||||
.long MB2_LENGTH
|
||||
.long MB2_CHECKSUM
|
||||
/* End tag */
|
||||
.short 0
|
||||
.short 0
|
||||
.long 8
|
||||
multiboot2_header_end:
|
||||
|
||||
.align 4
|
||||
multiboot1_header:
|
||||
.long MB1_MAGIC
|
||||
.long MB1_FLAGS
|
||||
.long MB1_CHECKSUM
|
||||
|
||||
/* ---------------- 32-Bit Entry Point ---------------- */
|
||||
.section .text
|
||||
.code32
|
||||
.global _start
|
||||
.type _start, @function
|
||||
_start:
|
||||
/* Disable interrupts */
|
||||
cli
|
||||
|
||||
/* Initialize stack */
|
||||
movl $stack_top, %esp
|
||||
|
||||
/* Save Multiboot magic & info pointer */
|
||||
movl %eax, %edi
|
||||
movl %ebx, %esi
|
||||
|
||||
/* Check if CPU supports CPUID */
|
||||
pushfl
|
||||
popl %eax
|
||||
movl %eax, %ecx
|
||||
xorl $(1 << 21), %eax
|
||||
pushl %eax
|
||||
popfl
|
||||
pushfl
|
||||
popl %eax
|
||||
pushl %ecx
|
||||
popfl
|
||||
cmpl %ecx, %eax
|
||||
je no_cpuid
|
||||
|
||||
/* Check if Long Mode is available (EFER.LME) */
|
||||
movl $0x80000000, %eax
|
||||
cpuid
|
||||
cmpl $0x80000001, %eax
|
||||
jb no_long_mode
|
||||
|
||||
movl $0x80000001, %eax
|
||||
cpuid
|
||||
testl $(1 << 29), %edx
|
||||
jz no_long_mode
|
||||
|
||||
/* Build identity page tables for the first 1GB using 2MB huge pages */
|
||||
/* PML4[0] -> PDPT */
|
||||
movl $pml4_table, %eax
|
||||
movl $pdpt_table, %ebx
|
||||
orl $0x03, %ebx /* Present + Writable */
|
||||
movl %ebx, (%eax)
|
||||
|
||||
/* PDPT[0] -> Page Directory */
|
||||
movl $pdpt_table, %eax
|
||||
movl $page_dir_table, %ebx
|
||||
orl $0x03, %ebx
|
||||
movl %ebx, (%eax)
|
||||
|
||||
/* Identity map 512 entries of 2MB = 1GB */
|
||||
movl $0, %ecx
|
||||
map_pd_loop:
|
||||
movl $0x200000, %eax /* 2MB */
|
||||
mull %ecx
|
||||
orl $0x83, %eax /* Present + Writable + Huge Page (bit 7) */
|
||||
movl $page_dir_table, %edx
|
||||
movl %eax, (%edx, %ecx, 8)
|
||||
incl %ecx
|
||||
cmpl $512, %ecx
|
||||
jne map_pd_loop
|
||||
|
||||
/* Load CR3 with physical address of PML4 */
|
||||
movl $pml4_table, %eax
|
||||
movl %eax, %cr3
|
||||
|
||||
/* Enable PAE (Physical Address Extension) in CR4 */
|
||||
movl %cr4, %eax
|
||||
orl $(1 << 5), %eax
|
||||
movl %eax, %cr4
|
||||
|
||||
/* Set Long Mode Enable bit in EFER MSR (0xC0000080) */
|
||||
movl $0xC0000080, %ecx
|
||||
rdmsr
|
||||
orl $(1 << 8), %eax
|
||||
wrmsr
|
||||
|
||||
/* Enable Paging and Protected Mode in CR0 */
|
||||
movl %cr0, %eax
|
||||
orl $(1 << 31 | 1 << 0), %eax
|
||||
movl %eax, %cr0
|
||||
|
||||
/* Load 64-bit Global Descriptor Table */
|
||||
lgdt (gdt64_pointer)
|
||||
|
||||
/* Far jump to 64-bit code segment */
|
||||
ljmp $0x08, $long_mode_entry
|
||||
|
||||
no_cpuid:
|
||||
no_long_mode:
|
||||
/* Write error to VGA and halt */
|
||||
movl $0x4F524F45, 0xB8000 /* 'E' 'R' with red background */
|
||||
cli
|
||||
halt_loop:
|
||||
hlt
|
||||
jmp halt_loop
|
||||
|
||||
/* ---------------- 64-Bit Long Mode Entry ---------------- */
|
||||
.code64
|
||||
.global long_mode_entry
|
||||
.type long_mode_entry, @function
|
||||
long_mode_entry:
|
||||
/* Reload data segment registers */
|
||||
movw $0x10, %ax
|
||||
movw %ax, %ds
|
||||
movw %ax, %es
|
||||
movw %ax, %fs
|
||||
movw %ax, %gs
|
||||
movw %ax, %ss
|
||||
|
||||
/* Setup 64-bit stack pointer */
|
||||
movq $stack_top, %rsp
|
||||
|
||||
/* Zero out RFLAGS */
|
||||
pushq $0
|
||||
popfq
|
||||
|
||||
/* Call Kernel Main with System V ABI arguments:
|
||||
rdi = magic (was in edi)
|
||||
rsi = multiboot info addr (was in esi)
|
||||
*/
|
||||
movl %edi, %edi
|
||||
movl %esi, %esi
|
||||
|
||||
call kernel_main
|
||||
|
||||
/* Hang if kernel_main ever returns */
|
||||
cli
|
||||
hang_64:
|
||||
hlt
|
||||
jmp hang_64
|
||||
|
||||
/* ---------------- Page Tables (4KB Aligned) ---------------- */
|
||||
.section .bss
|
||||
.align 4096
|
||||
pml4_table:
|
||||
.skip 4096
|
||||
pdpt_table:
|
||||
.skip 4096
|
||||
page_dir_table:
|
||||
.skip 4096
|
||||
|
||||
/* Kernel Stack (16KB) */
|
||||
.align 16
|
||||
stack_bottom:
|
||||
.skip 16384
|
||||
stack_top:
|
||||
|
||||
/* ---------------- 64-Bit GDT ---------------- */
|
||||
.section .rodata
|
||||
.align 8
|
||||
gdt64:
|
||||
.quad 0 /* Null descriptor */
|
||||
.quad (1<<43) | (1<<44) | (1<<47) | (1<<53) /* 64-bit Code: Executable, Code/Data, Present, Long Mode */
|
||||
.quad (1<<44) | (1<<47) | (1<<41) /* 64-bit Data: Writable, Code/Data, Present */
|
||||
gdt64_pointer:
|
||||
.short . - gdt64 - 1
|
||||
.quad gdt64
|
||||
Executable
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
#ifndef AIRLYS_KERNEL_H
|
||||
#define AIRLYS_KERNEL_H
|
||||
|
||||
#include <airlys/types.h>
|
||||
#include <airlys/vga.h>
|
||||
|
||||
#define AIRLYS_VERSION_MAJOR 0
|
||||
#define AIRLYS_VERSION_MINOR 1
|
||||
#define AIRLYS_VERSION_PATCH 0
|
||||
#define AIRLYS_CODENAME "Genesis"
|
||||
|
||||
void kernel_main(uint64_t magic, uint64_t addr);
|
||||
void kernel_panic(const char* message);
|
||||
|
||||
#endif /* AIRLYS_KERNEL_H */
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef AIRLYS_TYPES_H
|
||||
#define AIRLYS_TYPES_H
|
||||
|
||||
/*
|
||||
* Airlys Operating System Kernel - Core Types
|
||||
* Engineered by Er. Adam Eehan (Founder & CEO, Aira Group of Technology)
|
||||
* Pure freestanding - Zero C Standard Library dependencies
|
||||
*/
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef signed long long int64_t;
|
||||
|
||||
typedef uint64_t size_t;
|
||||
typedef int64_t ssize_t;
|
||||
typedef uint64_t uintptr_t;
|
||||
typedef int64_t intptr_t;
|
||||
|
||||
#define NULL ((void*)0)
|
||||
|
||||
typedef enum {
|
||||
false = 0,
|
||||
true = 1
|
||||
} bool;
|
||||
|
||||
#endif /* AIRLYS_TYPES_H */
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef AIRLYS_VGA_H
|
||||
#define AIRLYS_VGA_H
|
||||
|
||||
#include <airlys/types.h>
|
||||
|
||||
/* Hardware VGA text buffer at physical address 0xB8000 */
|
||||
#define VGA_BUFFER_PHYSICAL 0xB8000
|
||||
#define VGA_WIDTH 80
|
||||
#define VGA_HEIGHT 25
|
||||
|
||||
typedef enum {
|
||||
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,
|
||||
} vga_color_t;
|
||||
|
||||
static inline uint8_t vga_entry_color(vga_color_t fg, vga_color_t bg) {
|
||||
return (uint8_t)(fg | (bg << 4));
|
||||
}
|
||||
|
||||
static inline uint16_t vga_entry(unsigned char uc, uint8_t color) {
|
||||
return (uint16_t)uc | ((uint16_t)color << 8);
|
||||
}
|
||||
|
||||
void vga_init(void);
|
||||
void vga_set_color(vga_color_t fg, vga_color_t bg);
|
||||
void vga_clear(void);
|
||||
void vga_putchar(char c);
|
||||
void vga_write(const char* data, size_t size);
|
||||
void vga_puts(const char* str);
|
||||
void vga_puthex(uint64_t val);
|
||||
void vga_putdec(uint64_t val);
|
||||
|
||||
#endif /* AIRLYS_VGA_H */
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <airlys/kernel.h>
|
||||
#include <airlys/vga.h>
|
||||
|
||||
void kernel_main(uint64_t magic, uint64_t addr) {
|
||||
/* Initialize hardware VGA terminal console */
|
||||
vga_init();
|
||||
|
||||
/* Banner & Sovereign Branding */
|
||||
vga_set_color(VGA_COLOR_LIGHT_CYAN, VGA_COLOR_BLACK);
|
||||
vga_puts("================================================================================\n");
|
||||
vga_puts(" _ ___ ____ _ __ ______ \n");
|
||||
vga_puts(" / \\ |_ _| _ \\| | \\ \\ / / ___| \n");
|
||||
vga_puts(" / _ \\ | || |_) | | \\ V /\\___ \\ \n");
|
||||
vga_puts(" / ___ \\ | || _ <| |___| | ___) |\n");
|
||||
vga_puts(" /_/ \\_\\___|_| \\_\\_____|_| |____/ SOVEREIGN OS KERNEL v0.1.0\n");
|
||||
vga_puts("================================================================================\n");
|
||||
|
||||
vga_set_color(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
|
||||
vga_puts(" [OK] Airlys Kernel Genesis initialized successfully!\n");
|
||||
vga_puts(" [OK] Architecture : x86_64 (64-Bit Long Mode)\n");
|
||||
vga_puts(" [OK] Creator : Er. Adam Eehan (Founder & CEO, Aira Group)\n");
|
||||
vga_puts(" [OK] Co-Pilot : Sovereign AI Aira 3 Ultra (Engine v3.6)\n");
|
||||
|
||||
vga_set_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK);
|
||||
vga_puts("--------------------------------------------------------------------------------\n");
|
||||
|
||||
vga_set_color(VGA_COLOR_LIGHT_GREEN, VGA_COLOR_BLACK);
|
||||
vga_puts(" [*] Bootloader Magic : ");
|
||||
vga_puthex(magic);
|
||||
vga_puts("\n");
|
||||
vga_puts(" [*] Multiboot Info : ");
|
||||
vga_puthex(addr);
|
||||
vga_puts("\n");
|
||||
|
||||
vga_set_color(VGA_COLOR_LIGHT_CYAN, VGA_COLOR_BLACK);
|
||||
vga_puts(" [*] Physical VGA Memory Map: 0x000B8000 (80x25 Text Mode)\n");
|
||||
vga_puts(" [*] Preemptive Subsystems: Ready for Stage 2 (GDT & IDT Interrupts)\n");
|
||||
|
||||
vga_set_color(VGA_COLOR_LIGHT_MAGENTA, VGA_COLOR_BLACK);
|
||||
vga_puts("\n >>> Airlys System Idle Loop Active. CPU Halted awaiting hardware ticks.\n");
|
||||
|
||||
/* Infinite safe idle loop */
|
||||
for (;;) {
|
||||
__asm__ volatile ("hlt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <airlys/kernel.h>
|
||||
#include <airlys/vga.h>
|
||||
|
||||
void kernel_panic(const char* message) {
|
||||
vga_set_color(VGA_COLOR_WHITE, VGA_COLOR_RED);
|
||||
vga_clear();
|
||||
vga_puts("\n\n");
|
||||
vga_puts(" ========================================================================\n");
|
||||
vga_puts(" [!] AIRLYS SOVEREIGN KERNEL PANIC\n");
|
||||
vga_puts(" ========================================================================\n\n");
|
||||
vga_puts(" An unrecoverable system state occurred.\n\n");
|
||||
vga_puts(" Reason: ");
|
||||
vga_puts(message ? message : "Unknown error");
|
||||
vga_puts("\n\n");
|
||||
vga_puts(" System Halted. Please reboot the host machine.\n");
|
||||
vga_puts(" Architecture: x86_64 Long Mode | Aira Group of Technology\n");
|
||||
vga_puts(" ========================================================================\n");
|
||||
|
||||
/* Halt the CPU */
|
||||
for (;;) {
|
||||
__asm__ volatile ("cli; hlt");
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
#include <airlys/vga.h>
|
||||
|
||||
static size_t vga_row;
|
||||
static size_t vga_column;
|
||||
static uint8_t vga_current_color;
|
||||
static volatile uint16_t* const vga_buffer = (volatile uint16_t*)VGA_BUFFER_PHYSICAL;
|
||||
|
||||
/* Outport byte to I/O port (used for hardware cursor updates) */
|
||||
static inline void outb(uint16_t port, uint8_t val) {
|
||||
__asm__ volatile ("outb %0, %1" : : "a"(val), "Nd"(port));
|
||||
}
|
||||
|
||||
static void vga_update_cursor(void) {
|
||||
uint16_t pos = (uint16_t)(vga_row * VGA_WIDTH + vga_column);
|
||||
outb(0x3D4, 0x0F);
|
||||
outb(0x3D5, (uint8_t)(pos & 0xFF));
|
||||
outb(0x3D4, 0x0E);
|
||||
outb(0x3D5, (uint8_t)((pos >> 8) & 0xFF));
|
||||
}
|
||||
|
||||
static void vga_scroll(void) {
|
||||
for (size_t y = 0; y < VGA_HEIGHT - 1; y++) {
|
||||
for (size_t x = 0; x < VGA_WIDTH; x++) {
|
||||
vga_buffer[y * VGA_WIDTH + x] = vga_buffer[(y + 1) * VGA_WIDTH + x];
|
||||
}
|
||||
}
|
||||
for (size_t x = 0; x < VGA_WIDTH; x++) {
|
||||
vga_buffer[(VGA_HEIGHT - 1) * VGA_WIDTH + x] = vga_entry(' ', vga_current_color);
|
||||
}
|
||||
vga_row = VGA_HEIGHT - 1;
|
||||
}
|
||||
|
||||
void vga_init(void) {
|
||||
vga_row = 0;
|
||||
vga_column = 0;
|
||||
vga_current_color = vga_entry_color(VGA_COLOR_LIGHT_CYAN, VGA_COLOR_BLACK);
|
||||
vga_clear();
|
||||
}
|
||||
|
||||
void vga_set_color(vga_color_t fg, vga_color_t bg) {
|
||||
vga_current_color = vga_entry_color(fg, bg);
|
||||
}
|
||||
|
||||
void vga_clear(void) {
|
||||
for (size_t y = 0; y < VGA_HEIGHT; y++) {
|
||||
for (size_t x = 0; x < VGA_WIDTH; x++) {
|
||||
vga_buffer[y * VGA_WIDTH + x] = vga_entry(' ', vga_current_color);
|
||||
}
|
||||
}
|
||||
vga_row = 0;
|
||||
vga_column = 0;
|
||||
vga_update_cursor();
|
||||
}
|
||||
|
||||
void vga_putchar(char c) {
|
||||
if (c == '\n') {
|
||||
vga_column = 0;
|
||||
if (++vga_row == VGA_HEIGHT) {
|
||||
vga_scroll();
|
||||
}
|
||||
vga_update_cursor();
|
||||
return;
|
||||
}
|
||||
|
||||
if (c == '\r') {
|
||||
vga_column = 0;
|
||||
vga_update_cursor();
|
||||
return;
|
||||
}
|
||||
|
||||
if (c == '\t') {
|
||||
vga_column = (vga_column + 4) & ~3;
|
||||
if (vga_column >= VGA_WIDTH) {
|
||||
vga_column = 0;
|
||||
if (++vga_row == VGA_HEIGHT) {
|
||||
vga_scroll();
|
||||
}
|
||||
}
|
||||
vga_update_cursor();
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t index = vga_row * VGA_WIDTH + vga_column;
|
||||
vga_buffer[index] = vga_entry((unsigned char)c, vga_current_color);
|
||||
|
||||
if (++vga_column == VGA_WIDTH) {
|
||||
vga_column = 0;
|
||||
if (++vga_row == VGA_HEIGHT) {
|
||||
vga_scroll();
|
||||
}
|
||||
}
|
||||
vga_update_cursor();
|
||||
}
|
||||
|
||||
void vga_write(const char* data, size_t size) {
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
vga_putchar(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void vga_puts(const char* str) {
|
||||
if (!str) return;
|
||||
while (*str) {
|
||||
vga_putchar(*str++);
|
||||
}
|
||||
}
|
||||
|
||||
void vga_puthex(uint64_t val) {
|
||||
const char hex_chars[] = "0123456789ABCDEF";
|
||||
vga_puts("0x");
|
||||
for (int i = 60; i >= 0; i -= 4) {
|
||||
vga_putchar(hex_chars[(val >> i) & 0xF]);
|
||||
}
|
||||
}
|
||||
|
||||
void vga_putdec(uint64_t val) {
|
||||
if (val == 0) {
|
||||
vga_putchar('0');
|
||||
return;
|
||||
}
|
||||
char buf[24];
|
||||
int i = 0;
|
||||
while (val > 0) {
|
||||
buf[i++] = (char)('0' + (val % 10));
|
||||
val /= 10;
|
||||
}
|
||||
while (--i >= 0) {
|
||||
vga_putchar(buf[i]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Airlys Kernel Linker Script (x86_64 ELF)
|
||||
* Aira Group of Technology
|
||||
*/
|
||||
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
/* Load kernel at 1MB (standard Multiboot load boundary) */
|
||||
. = 1M;
|
||||
|
||||
/* Multiboot Header & Executable Code */
|
||||
.text : ALIGN(4K)
|
||||
{
|
||||
KEEP(*(.multiboot))
|
||||
*(.text .text.*)
|
||||
}
|
||||
|
||||
/* Read-Only Data (GDT, string constants) */
|
||||
.rodata : ALIGN(4K)
|
||||
{
|
||||
*(.rodata .rodata.*)
|
||||
}
|
||||
|
||||
/* Initialized Data */
|
||||
.data : ALIGN(4K)
|
||||
{
|
||||
*(.data .data.*)
|
||||
}
|
||||
|
||||
/* Uninitialized Data (BSS, Page Tables, Stack) */
|
||||
.bss : ALIGN(4K)
|
||||
{
|
||||
*(COMMON)
|
||||
*(.bss .bss.*)
|
||||
}
|
||||
|
||||
/* Discard unused unwind & debug sections */
|
||||
/DISCARD/ :
|
||||
{
|
||||
*(.eh_frame)
|
||||
*(.comment)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user