refactor(architecture): adopt canonical Linux enterprise directory layout (arch, drivers, fs, mm, kernel, lib, security, scripts, tools)

This commit is contained in:
Adam Eehan committed 2026-10-23 18:23:16 +05:30
1 parent 67ed4de23f
commit 2bbeb3f345
17 files changed
+217 -9

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
#include <airlys/keyboard.h>
#include <airlys/idt.h>
#include <airlys/io.h>
#include <airlys/vga.h>
#include <airlys/pic.h>
#include <airlys/shell.h>
#define KBD_DATA_PORT 0x60
static bool shift_pressed = false;
/* Scan Code Set 1 mapping (lower-case / normal) */
static const char kbd_scancode_normal[128] = {
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b',
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
0, /* Control */
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
0, /* Left Shift */
'\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
0, /* Right Shift */
'*',
0, /* Alt */
' ', /* Space */
0, /* Caps Lock */
};
/* Scan Code Set 1 mapping (Shifted / upper-case) */
static const char kbd_scancode_shift[128] = {
0, 27, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\b',
'\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n',
0, /* Control */
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '\"', '~',
0, /* Left Shift */
'|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',
0, /* Right Shift */
'*',
0, /* Alt */
' ', /* Space */
0, /* Caps Lock */
};
static void keyboard_callback(registers_t* regs) {
(void)regs;
uint8_t scancode = inb(KBD_DATA_PORT);
/* Check for Shift key press (0x2A left, 0x36 right) */
if (scancode == 0x2A || scancode == 0x36) {
shift_pressed = true;
return;
}
/* Check for Shift key release (0xAA left, 0xB6 right) */
if (scancode == 0xAA || scancode == 0xB6) {
shift_pressed = false;
return;
}
/* Key release has bit 7 set (scancode >= 0x80) */
if (scancode & 0x80) {
return;
}
if (scancode < 128) {
char c = shift_pressed ? kbd_scancode_shift[scancode] : kbd_scancode_normal[scancode];
if (c != 0) {
shell_handle_char(c);
}
}
}
void keyboard_init(void) {
/* Register keyboard on IRQ1 (Vector 33) */
register_interrupt_handler(33, keyboard_callback);
/* Unmask IRQ1 on Master PIC */
pic_unmask_irq(1);
}
+77
View File
@@ -0,0 +1,77 @@
#include <airlys/pic.h>
#include <airlys/io.h>
#define ICW1_INIT 0x11
#define ICW4_8086 0x01
void pic_init(void) {
uint8_t a1, a2;
/* Save masks */
a1 = inb(PIC1_DATA);
a2 = inb(PIC2_DATA);
/* Start initialization sequence in cascade mode (ICW1) */
outb(PIC1_COMMAND, ICW1_INIT);
io_wait();
outb(PIC2_COMMAND, ICW1_INIT);
io_wait();
/* ICW2: Master PIC vector offset (32) and Slave PIC vector offset (40) */
outb(PIC1_DATA, PIC1_OFFSET);
io_wait();
outb(PIC2_DATA, PIC2_OFFSET);
io_wait();
/* ICW3: Tell Master PIC there is a Slave PIC at IRQ2 (0000 0100) */
outb(PIC1_DATA, 4);
io_wait();
/* Tell Slave PIC its cascade identity (0000 0010) */
outb(PIC2_DATA, 2);
io_wait();
/* ICW4: Set 8086 mode */
outb(PIC1_DATA, ICW4_8086);
io_wait();
outb(PIC2_DATA, ICW4_8086);
io_wait();
/* Restore masks (or mask all except cascade) */
outb(PIC1_DATA, a1);
outb(PIC2_DATA, a2);
}
void pic_send_eoi(uint8_t irq) {
if (irq >= 8) {
outb(PIC2_COMMAND, PIC_EOI);
}
outb(PIC1_COMMAND, PIC_EOI);
}
void pic_mask_irq(uint8_t irq) {
uint16_t port;
uint8_t value;
if (irq < 8) {
port = PIC1_DATA;
} else {
port = PIC2_DATA;
irq -= 8;
}
value = inb(port) | (uint8_t)(1 << irq);
outb(port, value);
}
void pic_unmask_irq(uint8_t irq) {
uint16_t port;
uint8_t value;
if (irq < 8) {
port = PIC1_DATA;
} else {
port = PIC2_DATA;
irq -= 8;
}
value = inb(port) & (uint8_t)~(1 << irq);
outb(port, value);
}
+47
View File
@@ -0,0 +1,47 @@
#include <airlys/timer.h>
#include <airlys/idt.h>
#include <airlys/io.h>
#include <airlys/pic.h>
#include <airlys/sched.h>
#define PIT_CHANNEL0 0x40
#define PIT_COMMAND 0x43
#define PIT_BASE_FREQ 1193182
static volatile uint64_t timer_ticks = 0;
static void timer_callback(registers_t* regs) {
(void)regs;
timer_ticks++;
sched_timer_tick();
}
void timer_init(uint32_t frequency_hz) {
if (frequency_hz == 0) frequency_hz = 100;
uint32_t divisor = PIT_BASE_FREQ / frequency_hz;
if (divisor == 0) divisor = 1;
if (divisor > 65535) divisor = 65535;
/* Register callback on IRQ0 (Vector 32) */
register_interrupt_handler(32, timer_callback);
/* 0x36 = Channel 0, lobyte/hibyte, Mode 3 (Square wave generator), binary 16-bit */
outb(PIT_COMMAND, 0x36);
outb(PIT_CHANNEL0, (uint8_t)(divisor & 0xFF));
outb(PIT_CHANNEL0, (uint8_t)((divisor >> 8) & 0xFF));
/* Unmask IRQ0 on Master PIC */
pic_unmask_irq(0);
}
uint64_t timer_get_ticks(void) {
return timer_ticks;
}
void timer_sleep(uint32_t ticks) {
uint64_t start = timer_ticks;
while ((timer_ticks - start) < ticks) {
__asm__ volatile ("hlt");
}
}
+180
View File
@@ -0,0 +1,180 @@
#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 == '\b') {
if (vga_column > 12) {
vga_column--;
const size_t index = vga_row * VGA_WIDTH + vga_column;
vga_buffer[index] = vga_entry(' ', vga_current_color);
vga_update_cursor();
}
return;
}
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]);
}
}
static char vga_prompt_path[64] = "/home/user";
void vga_set_prompt_path(const char* path) {
if (!path) return;
size_t i = 0;
while (path[i] != '\0' && i < sizeof(vga_prompt_path) - 1) {
vga_prompt_path[i] = path[i];
i++;
}
vga_prompt_path[i] = '\0';
}
void vga_print_prompt(void) {
/* Line 1: ┌──(root@airlys-os)-[current_path] */
vga_set_color(VGA_COLOR_LIGHT_CYAN, VGA_COLOR_BLACK);
vga_putchar((char)0xDA); /* CP437 box top-left: ┌ */
vga_putchar((char)0xC4); /* CP437 horizontal: ─ */
vga_putchar((char)0xC4); /* CP437 horizontal: ─ */
vga_puts("(");
vga_set_color(VGA_COLOR_LIGHT_RED, VGA_COLOR_BLACK);
vga_puts("root");
vga_set_color(VGA_COLOR_LIGHT_CYAN, VGA_COLOR_BLACK);
vga_puts("@airlys-os)-[");
vga_set_color(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_BLACK);
vga_puts(vga_prompt_path);
vga_set_color(VGA_COLOR_LIGHT_CYAN, VGA_COLOR_BLACK);
vga_puts("]\n");
/* Line 2: └─Airlys >> */
vga_putchar((char)0xC0); /* CP437 box bottom-left: └ */
vga_putchar((char)0xC4); /* CP437 horizontal: ─ */
vga_puts("Airlys >> ");
vga_set_color(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
}