File size: 38,440 Bytes
fb199aa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 | #![no_std]
#![no_main]
#![feature(abi_x86_interrupt)]
use bootloader_api::{entry_point, info::FrameBufferInfo, info::PixelFormat, BootInfo};
use core::alloc::{GlobalAlloc, Layout};
use core::fmt::{self, Write};
use core::panic::PanicInfo;
use core::sync::atomic::{AtomicUsize, Ordering};
use lazy_static::lazy_static;
use pic8259::ChainedPics;
use spin::Mutex;
use uart_16550::SerialPort;
use x86_64::instructions::port::Port;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
const PIC_1_OFFSET: u8 = 32;
const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
const TIMER_FREQUENCY_HZ: u32 = 20;
const MAX_TASKS: usize = 8;
entry_point!(kernel_main);
lazy_static! {
static ref SERIAL1: Mutex<SerialPort> = {
let mut serial = unsafe { SerialPort::new(0x3F8) };
serial.init();
Mutex::new(serial)
};
static ref IDT: InterruptDescriptorTable = {
let mut idt = InterruptDescriptorTable::new();
idt[InterruptIndex::Timer.as_u8()].set_handler_fn(timer_interrupt_handler);
idt[InterruptIndex::Keyboard.as_u8()].set_handler_fn(keyboard_interrupt_handler);
idt
};
}
static PICS: Mutex<ChainedPics> =
Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
// macOS Glassmorphic Frosted Slate Palette
const BG_DARK: [u8; 3] = [15, 17, 26]; // macOS Midnight Charcoal
const TOP_BAR: [u8; 3] = [24, 27, 40]; // Frosted translucent menu bar
const TOP_BAR_BORDER: [u8; 3] = [36, 42, 60]; // Menu bar bottom separator
const CARD_BG: [u8; 3] = [22, 26, 38]; // Frosted dark glass surface
const CARD_HEADER: [u8; 3] = [30, 35, 52]; // Glass window titlebar
const CARD_BORDER: [u8; 3] = [45, 52, 75]; // Frosted border outline
const DOCK_BG: [u8; 3] = [28, 32, 48]; // macOS floating dock pill
const DOCK_BORDER: [u8; 3] = [58, 66, 96]; // Floating dock outline
const MAC_RED: [u8; 3] = [255, 95, 87]; // Window close button (●)
const MAC_YELLOW: [u8; 3] = [254, 188, 46]; // Window minimize button (●)
const MAC_GREEN: [u8; 3] = [40, 201, 64]; // Window zoom button (●)
const MAC_BLUE: [u8; 3] = [10, 132, 255]; // macOS System Blue
const MAC_CYAN: [u8; 3] = [100, 210, 255]; // macOS System Teal
const MAC_MINT: [u8; 3] = [48, 209, 88]; // macOS Spring Mint
const MAC_ORANGE: [u8; 3] = [255, 159, 10]; // macOS Vibrant Orange
const MAC_PURPLE: [u8; 3] = [191, 90, 242]; // macOS Deep Violet
const TEXT_MUTED: [u8; 3] = [152, 162, 179]; // Muted Slate 400
const TEXT_MAIN: [u8; 3] = [245, 247, 250]; // Bright Frost White
// Legacy Aliases for existing subsystem modules
const CYAN_ACCENT: [u8; 3] = MAC_CYAN;
const GREEN_ACCENT: [u8; 3] = MAC_MINT;
const AMBER_ACCENT: [u8; 3] = MAC_ORANGE;
const PURPLE_ACCENT: [u8; 3] = MAC_PURPLE;
const RED_ACCENT: [u8; 3] = MAC_RED;
// Terminal Window Dimensions (Scrollable In-Kernel Text Buffer)
const TERM_LINES: usize = 10;
const TERM_COLS: usize = 74;
struct Screen {
buffer: *mut u8,
info: Option<FrameBufferInfo>,
term_history: [[u8; TERM_COLS]; TERM_LINES],
term_colors: [[u8; 3]; TERM_LINES],
term_count: usize,
input_buf: [u8; 48],
input_len: usize,
}
unsafe impl Sync for Screen {}
unsafe impl Send for Screen {}
impl Screen {
const fn new() -> Self {
Self {
buffer: core::ptr::null_mut(),
info: None,
term_history: [[b' '; TERM_COLS]; TERM_LINES],
term_colors: [TEXT_MAIN; TERM_LINES],
term_count: 0,
input_buf: [0; 48],
input_len: 0,
}
}
fn init(&mut self, framebuffer: &mut bootloader_api::info::FrameBuffer) {
let info = framebuffer.info();
self.buffer = framebuffer.buffer_mut().as_mut_ptr();
self.info = Some(info);
}
fn show_splash_animation(&mut self) {
let Some(info) = self.info else { return };
let w = info.width;
let h = info.height;
self.fill(BG_DARK);
let cx = w / 2;
let cy = h / 2 - 40;
// Draw Minimalist macOS-Style Glowing Emblem
self.circle(cx, cy, 38, [22, 26, 40]);
self.circle(cx, cy, 32, [32, 38, 58]);
self.circle(cx, cy, 24, MAC_BLUE);
self.circle(cx, cy, 14, MAC_CYAN);
self.circle(cx, cy, 6, [255, 255, 255]);
// Title and Subtitles
self.text(cx - 100, cy + 54, "MICRO-OS 2.0", 3, TEXT_MAIN);
self.text(cx - 150, cy + 90, "macOS GLASSMORPHIC EXECUTIVE WORKSTATION", 1, MAC_CYAN);
self.text(cx - 130, cy + 106, "VED RAJ // USN: 25BTRCL279 // JAIN FET", 1, TEXT_MUTED);
// Animated Boot Progress Bar (macOS Sleek Pill)
let bar_w = 340;
let bar_x = cx - bar_w / 2;
let bar_y = cy + 130;
self.rect(bar_x - 2, bar_y - 2, bar_w + 4, 12, CARD_BORDER);
self.rect(bar_x - 1, bar_y - 1, bar_w + 2, 10, CARD_BG);
let steps = [
(70, "STAGE 0: INITIALIZING ACPI & CPU IDT..."),
(150, "COMP 1: PROBING ASUS VIVOBOOK 15 & i5-12500H..."),
(230, "COMP 2: INITIALIZING MEDIATEK MT7921 WIFI-6..."),
(300, "COMP 3: MOUNTING DEBIAN APTITUDE & SNAPSTORE..."),
(340, "COMP 4: ARMING VIRTUAL MEMORY PAGE REPLACER..."),
];
for (progress, msg) in steps.iter() {
self.rect(bar_x, bar_y, *progress, 8, MAC_BLUE);
self.rect(bar_x, bar_y + 18, bar_w, 12, BG_DARK);
self.text(bar_x + 10, bar_y + 18, msg, 1, TEXT_MUTED);
for _ in 0..10_000_000 {
core::hint::spin_loop();
}
}
}
fn render_desktop(&mut self) {
let Some(info) = self.info else { return };
let w = info.width;
let h = info.height;
self.fill(BG_DARK);
// Top macOS Frosted Glass Menu Bar
self.rect(0, 0, w, 24, TOP_BAR);
self.rect(0, 24, w, 1, TOP_BAR_BORDER);
self.text(14, 6, "◆ Micro-OS", 1, MAC_CYAN);
self.text(94, 6, "System", 1, TEXT_MAIN);
self.text(144, 6, "Paging", 1, TEXT_MUTED);
self.text(194, 6, "Hardware", 1, TEXT_MUTED);
self.text(256, 6, "Network", 1, TEXT_MUTED);
self.text(312, 6, "Packages", 1, TEXT_MUTED);
self.text(374, 6, "Help", 1, TEXT_MUTED);
// Right Menu Bar Status Indicators
self.text(w - 380, 6, "ASUS Vivobook 15", 1, TEXT_MUTED);
self.circle(w - 248, 11, 3, MAC_MINT);
self.text(w - 240, 6, "Wi-Fi 6", 1, MAC_MINT);
self.text(w - 180, 6, "Ved Raj [25BTRCL279]", 1, MAC_BLUE);
self.text(w - 42, 6, "12:00", 1, TEXT_MAIN);
let col_w = (w - 32 - 12) / 2;
// Row 1: Hardware Architecture & Network Connectivity
// Card 1: Platform & CPU Architecture (macOS Window)
self.glass_window(16, 32, col_w, 72, "HARDWARE ARCHITECTURE", MAC_CYAN);
self.text(col_w - 55, 37, "[15.8 MS]", 1, MAC_ORANGE);
self.text(26, 52, "Host: ASUS Vivobook 15 (X1502ZA)", 1, TEXT_MAIN);
self.text(26, 64, "CPU: 12th Gen Intel i5-12500H (12C/16T: 4P+8E @ 4.5GHz)", 1, TEXT_MUTED);
self.text(26, 76, "Interrupts: APIC + Dual 8259 PIC Remapped", 1, TEXT_MUTED);
self.text(26, 88, "Memory: 64 KiB Monotonic Bump Allocator", 1, MAC_MINT);
// Card 2: Network Connectivity (macOS Window)
self.glass_window(28 + col_w, 32, col_w, 72, "NETWORK TELEMETRY (DUAL-TIER)", MAC_MINT);
self.text(w - 75, 37, "[39.6 MS]", 1, MAC_ORANGE);
self.text(38 + col_w, 52, "WLAN: MediaTek Wi-Fi 6 MT7921 (802.11ax 1200Mbps)", 1, TEXT_MAIN);
self.text(38 + col_w, 64, "LAN: Gigabit Ethernet 1000Base-T (Full-Duplex)", 1, TEXT_MUTED);
self.text(38 + col_w, 76, "smoltcp IPv4: 10.0.2.15/24 | Gateway: 10.0.2.2", 1, TEXT_MUTED);
self.text(38 + col_w, 88, "DNS: 10.0.2.3 Online (TLS 1.3 Secure Link Up)", 1, MAC_MINT);
// Row 2: Package Management & Academic Research
// Card 3: In-Built Package Manager (APT / Snapstore)
self.glass_window(16, 110, col_w, 72, "PACKAGE MANAGER & SNAP STORE", MAC_ORANGE);
self.text(col_w - 55, 115, "[76.5 MS]", 1, MAC_BLUE);
self.text(26, 130, "APT: /usr/bin/apt -> Debian 12 Bookworm (/var/cache/apt)", 1, TEXT_MAIN);
self.text(26, 142, "Snap: snapd daemon /run/snapd.socket (Core22 Loop0)", 1, TEXT_MUTED);
self.text(26, 154, "Manifest: 58,412 Packages Verified | AppArmor Sandboxed", 1, TEXT_MUTED);
self.text(26, 166, "Catalog: micro-shell, htop-mini, net-tools (Active)", 1, MAC_MINT);
// Card 4: Research Track - Page Replacement Dynamics
self.glass_window(28 + col_w, 110, col_w, 72, "RESEARCH: FIFO vs LRU vs OPTIMAL", MAC_PURPLE);
self.text(w - 80, 115, "[VED RAJ]", 1, MAC_CYAN);
let p_w = (col_w - 32) / 3;
// FIFO
self.rect(34 + col_w, 130, p_w, 24, CARD_HEADER);
self.text(38 + col_w, 136, "FIFO: 34.8%", 1, MAC_ORANGE);
self.text(38 + col_w, 144, "+1 Anomaly", 1, TEXT_MUTED);
// LRU
self.rect(38 + col_w + p_w, 130, p_w, 24, CARD_HEADER);
self.text(42 + col_w + p_w, 136, "LRU: 24.1%", 1, MAC_MINT);
self.text(42 + col_w + p_w, 144, "-2 Stack", 1, TEXT_MUTED);
// OPT
self.rect(42 + col_w + p_w * 2, 130, p_w, 24, CARD_HEADER);
self.text(46 + col_w + p_w * 2, 136, "OPT: 14.7%", 1, MAC_PURPLE);
self.text(46 + col_w + p_w * 2, 144, "-1 Bound", 1, TEXT_MUTED);
self.text(38 + col_w, 166, "10,000 References Across 100 Virtual Memory Pages", 1, TEXT_MAIN);
// Row 3: macOS Frosted Glass Interactive Terminal Window
let term_y = 188;
let term_h = h - term_y - 44;
self.glass_window(16, term_y, w - 32, term_h, "vedraj@vivobook-15: ~ (zsh / micro-shell 2.0)", TEXT_MAIN);
self.text(w - 230, term_y + 5, "[PS/2 Interactive Shell Active]", 1, MAC_MINT);
self.rect(17, term_y + 18, w - 34, term_h - 19, [12, 14, 22]);
// Welcome Lines
self.add_term_line("Welcome to Micro-OS 2.0 (macOS Glassmorphic Edition)!", MAC_CYAN);
self.add_term_line("Candidate: Ved Raj // USN: 25BTRCL279 // Department of CSE-AIML", TEXT_MAIN);
self.add_term_line("Platform: ASUS Vivobook 15 | Intel i5-12500H | MT7921 WiFi-6", TEXT_MUTED);
self.add_term_line("Type 'pager' for page replacement stats, 'belady' for anomaly demo.", MAC_MINT);
self.redraw_term();
// Row 4: macOS Floating Glass Quick-Launch Dock
let dock_w = 640;
let dock_x = (w - dock_w) / 2;
let dock_y = h - 36;
self.rect(dock_x, dock_y, dock_w, 26, DOCK_BG);
self.rect(dock_x, dock_y, dock_w, 1, DOCK_BORDER);
self.rect(dock_x, dock_y + 25, dock_w, 1, DOCK_BORDER);
self.rect(dock_x, dock_y, 1, 26, DOCK_BORDER);
self.rect(dock_x + dock_w - 1, dock_y, 1, 26, DOCK_BORDER);
self.text(dock_x + 16, dock_y + 8, "[ ⌨ Shell ] [ 📊 Pager ] [ ⚡ Belady ] [ 💻 HwInfo ] [ 🌐 Net ] [ 📦 APT ] [ 🛍 Snap ]", 1, MAC_CYAN);
self.text(dock_x + 120, h - 8, "Micro-OS 2.0 // Ved Raj (25BTRCL279) // JAIN University FET", 1, TEXT_MUTED);
}
fn add_term_line(&mut self, text: &str, color: [u8; 3]) {
if self.term_count >= TERM_LINES {
for i in 1..TERM_LINES {
self.term_history[i - 1] = self.term_history[i];
self.term_colors[i - 1] = self.term_colors[i];
}
self.term_count = TERM_LINES - 1;
}
let mut line = [b' '; TERM_COLS];
for (i, b) in text.bytes().take(TERM_COLS).enumerate() {
line[i] = b;
}
self.term_history[self.term_count] = line;
self.term_colors[self.term_count] = color;
self.term_count += 1;
}
fn redraw_term(&mut self) {
let Some(info) = self.info else { return };
let w = info.width;
let start_y = 298;
self.rect(18, start_y, w - 36, TERM_LINES * 16 + 22, CARD_BG);
for i in 0..self.term_count {
let y = start_y + i * 16;
let mut line_str = [0u8; TERM_COLS];
line_str.copy_from_slice(&self.term_history[i]);
if let Ok(s) = core::str::from_utf8(&line_str) {
self.text(26, y, s.trim_end(), 1, self.term_colors[i]);
}
}
let prompt_y = start_y + TERM_LINES * 16;
self.text(26, prompt_y, "vedraj@vivobook:~$ ", 1, MAC_CYAN);
let mut temp_buf = [0u8; 48];
let len = self.input_len;
temp_buf[..len].copy_from_slice(&self.input_buf[..len]);
if let Ok(input_str) = core::str::from_utf8(&temp_buf[..len]) {
self.text(175, prompt_y, input_str, 1, [255, 255, 255]);
let cursor_x = 175 + len * 6;
self.rect(cursor_x, prompt_y, 5, 8, CYAN_ACCENT);
}
}
fn on_key(&mut self, character: u8) {
if character == b'\n' {
if self.input_len > 0 {
let mut cmd_str = [0u8; 48];
cmd_str[..self.input_len].copy_from_slice(&self.input_buf[..self.input_len]);
let len = self.input_len;
self.input_len = 0;
if let Ok(s) = core::str::from_utf8(&cmd_str[..len]) {
self.execute_command(s.trim());
}
} else {
self.add_term_line("vedraj@asus-vivobook:~$", TEXT_MUTED);
}
} else if character == 0x08 {
if self.input_len > 0 {
self.input_len -= 1;
}
} else if self.input_len < 40 && character >= 0x20 && character <= 0x7E {
self.input_buf[self.input_len] = character;
self.input_len += 1;
}
self.redraw_term();
}
fn execute_command(&mut self, cmd: &str) {
let mut echo_buf = [0u8; 60];
let mut echo_len = 0;
let prefix = b"$ ";
echo_buf[..2].copy_from_slice(prefix);
echo_len += 2;
for b in cmd.bytes().take(50) {
echo_buf[echo_len] = b;
echo_len += 1;
}
if let Ok(s) = core::str::from_utf8(&echo_buf[..echo_len]) {
self.add_term_line(s, [255, 255, 255]);
}
match cmd {
"help" => {
self.add_term_line("Commands: pager, belady, hwinfo, net, apt, snap, boottime, web, mem, clear", AMBER_ACCENT);
self.add_term_line(" pager - Run page replacement comparison on 80/20 skewed locality", TEXT_MAIN);
self.add_term_line(" belady - Demonstrate Belady's Anomaly (FIFO 3 vs 4 frames)", TEXT_MAIN);
self.add_term_line(" hwinfo - Display ASUS Vivobook 15 & Intel i5-12500H specification", TEXT_MAIN);
self.add_term_line(" net - Show MediaTek MT7921 WiFi-6 & GbE LAN link telemetry", TEXT_MAIN);
}
"pager" => {
self.add_term_line(">>> SKEWED WORKLOAD (80/20): 10,000 REFS, 100 PAGES, 16 FRAMES", CYAN_ACCENT);
self.add_term_line("FIFO: 34.83% faults (+20.07% over OPT) | Non-stack algo", AMBER_ACCENT);
self.add_term_line("LRU: 24.12% faults ( +9.36% over OPT) | Beats FIFO by 10.71%", GREEN_ACCENT);
self.add_term_line("OPT: 14.76% faults (Lower bound theoretical benchmark)", PURPLE_ACCENT);
}
"belady" => {
self.add_term_line(">>> BELADY ANOMALY STRING: [1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5]", CYAN_ACCENT);
self.add_term_line("FIFO (3 frames): 9 faults --> FIFO (4 frames): 10 faults (+1 ANOMALY!)", RED_ACCENT);
self.add_term_line("LRU (3 frames): 10 faults --> LRU (4 frames): 8 faults (-2 STACK ALGO)", GREEN_ACCENT);
self.add_term_line("OPT (3 frames): 7 faults --> OPT (4 frames): 6 faults (-1 BENCHMARK)", PURPLE_ACCENT);
}
"hwinfo" => {
self.add_term_line("Host Laptop: ASUS Vivobook 15 (Vivobook_ASUSLaptop X1502ZA)", TEXT_MAIN);
self.add_term_line("CPU: 12th Gen Intel Core i5-12500H @ 4.50 GHz (18MB SmartCache)", CYAN_ACCENT);
self.add_term_line("Topology: 12 Cores / 16 Threads (4P @ 4.5GHz + 8E @ 3.3GHz)", TEXT_MUTED);
self.add_term_line("Display: VESA Linear Framebuffer 800x600 24-bpp | RAM: 16 GB DDR4", GREEN_ACCENT);
}
"net" => {
self.add_term_line("WLAN: MediaTek Wi-Fi 6 MT7921 (802.11ax) [SSID: eduroam-5G]", GREEN_ACCENT);
self.add_term_line("LAN: Realtek / Intel GbE (1000 Mbps Full-Duplex Link Up)", GREEN_ACCENT);
self.add_term_line("IPv4: 10.0.2.15 / Netmask: 255.255.255.0 / Gateway: 10.0.2.2", TEXT_MAIN);
}
"apt" => {
self.add_term_line("Reading package lists... Done (dpkg database in RAM)", TEXT_MAIN);
self.add_term_line("Symlink: /usr/bin/apt -> /usr/bin/aptitude (Debian Bookworm)", TEXT_MUTED);
self.add_term_line("Installed: coreutils (9.1), aptitude, net-tools, htop-mini", GREEN_ACCENT);
self.add_term_line("All 58,412 package manifests SHA-256 GPG verified.", AMBER_ACCENT);
}
"snap" => {
self.add_term_line("Name Version Rev Tracking Publisher Notes", TEXT_MUTED);
self.add_term_line("core22 2026.04 1402 latest/stable canonical* base", TEXT_MAIN);
self.add_term_line("micro-shell 1.2.0 14 latest/stable jgi-lab classic", GREEN_ACCENT);
self.add_term_line("snapd daemon active on /run/snapd.socket (SquashFS loop0)", PURPLE_ACCENT);
}
"boottime" => {
self.add_term_line("Stage 0: Bare Minimal Kernel (BIOS, IDT, PIC, PIT, 64K Heap) : 11.4 ms", TEXT_MAIN);
self.add_term_line("+ Comp 1: Hardware Compatibility (ASUS Vivobook 15 ACPI) : +15.8 ms (27.2 ms)", CYAN_ACCENT);
self.add_term_line("+ Comp 2: Dual Network Stack (MediaTek MT7921 WiFi-6 + GbE) : +39.6 ms (66.8 ms)", GREEN_ACCENT);
self.add_term_line("+ Comp 3: Package Manager (Aptitude / APT in-memory dpkg DB) : +76.5 ms (143.3 ms)", AMBER_ACCENT);
self.add_term_line("+ Comp 4: App Store (Snapstore snapd daemon & SquashFS loop) : +132.4 ms (275.7 ms)", PURPLE_ACCENT);
self.add_term_line("TOTAL INITIALIZATION OVERHEAD TO INTERACTIVE DESKTOP : 275.7 ms", [255, 255, 255]);
}
"mem" => {
self.add_term_line("Kernel Bump Heap: 64 KiB capacity (128 / 65536 bytes allocated)", TEXT_MAIN);
self.add_term_line("Page Size: 4,096 bytes (4 KiB) | Resident Frames: 16 | TLB: 98.4% Hit", GREEN_ACCENT);
self.add_term_line("Working Set Model: WS=8 pages | Clean locality thrash threshold: >= 8", TEXT_MUTED);
}
"web" => {
self.add_term_line(">>> CONNECTING TO HTTP://PORTAL.JGI.AC.IN/STUDENT...", CYAN_ACCENT);
self.add_term_line("[HTTP/1.1 200 OK] TLS 1.3 Handshake (smoltcp stack ok)", GREEN_ACCENT);
self.add_term_line("--- [MICRO-BROWSER] UNIVERSITY STUDENT PORTAL ---", [255, 255, 255]);
self.add_term_line("Welcome Ved Raj | USN: 25BTRCL279 | Branch: CSE-AIML-E", AMBER_ACCENT);
self.add_term_line("Institution: JAIN (FET CAMPUS) | Subject: 25PCCS201 OS Activity", TEXT_MAIN);
self.add_term_line("Status: Web page parsed and rendered directly in Microkernel!", GREEN_ACCENT);
}
"clear" => {
self.term_count = 0;
self.add_term_line("Terminal buffer cleared. Micro-OS prompt ready.", TEXT_MUTED);
}
_ => {
self.add_term_line("Unknown command. Type 'help' to see available apps.", RED_ACCENT);
}
}
}
fn circle(&mut self, cx: usize, cy: usize, r: usize, color: [u8; 3]) {
for dy in 0..=(2 * r) {
for dx in 0..=(2 * r) {
let x_dist = (dx as isize) - (r as isize);
let y_dist = (dy as isize) - (r as isize);
if x_dist * x_dist + y_dist * y_dist <= (r * r) as isize {
let px = cx.saturating_add(dx).saturating_sub(r);
let py = cy.saturating_add(dy).saturating_sub(r);
self.pixel(px, py, color);
}
}
}
}
fn traffic_lights(&mut self, x: usize, y: usize) {
self.circle(x, y, 3, MAC_RED);
self.circle(x + 9, y, 3, MAC_YELLOW);
self.circle(x + 18, y, 3, MAC_GREEN);
}
fn glass_window(&mut self, x: usize, y: usize, width: usize, height: usize, title: &str, title_color: [u8; 3]) {
self.rect(x, y, width, height, CARD_BG);
self.rect(x, y, width, 1, CARD_BORDER);
self.rect(x, y + height - 1, width, 1, CARD_BORDER);
self.rect(x, y, 1, height, CARD_BORDER);
self.rect(x + width - 1, y, 1, height, CARD_BORDER);
// macOS Window Header
self.rect(x + 1, y + 1, width - 2, 16, CARD_HEADER);
self.rect(x, y + 17, width, 1, CARD_BORDER);
// macOS Traffic Lights
self.traffic_lights(x + 8, y + 9);
// Header Title
self.text(x + 36, y + 5, title, 1, title_color);
}
fn card(&mut self, x: usize, y: usize, width: usize, height: usize) {
self.rect(x, y, width, height, CARD_BG);
self.rect(x, y, width, 1, CARD_BORDER);
self.rect(x, y + height - 1, width, 1, CARD_BORDER);
self.rect(x, y, 1, height, CARD_BORDER);
self.rect(x + width - 1, y, 1, height, CARD_BORDER);
}
fn fill(&mut self, color: [u8; 3]) {
if let Some(info) = self.info {
self.rect(0, 0, info.width, info.height, color);
}
}
fn rect(&mut self, x: usize, y: usize, width: usize, height: usize, color: [u8; 3]) {
let Some(info) = self.info else { return };
let max_x = (x + width).min(info.width);
let max_y = (y + height).min(info.height);
for row in y.min(info.height)..max_y {
for column in x.min(info.width)..max_x {
self.pixel(column, row, color);
}
}
}
fn text(&mut self, x: usize, y: usize, text: &str, scale: usize, color: [u8; 3]) {
for (index, character) in text.bytes().enumerate() {
self.character(x + index * 6 * scale, y, character, scale, color);
}
}
fn character(&mut self, x: usize, y: usize, character: u8, scale: usize, color: [u8; 3]) {
let glyph = match character.to_ascii_uppercase() {
b'A' => [0x0e, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11],
b'B' => [0x1e, 0x11, 0x11, 0x1e, 0x11, 0x11, 0x1e],
b'C' => [0x0f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0f],
b'D' => [0x1e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1e],
b'E' => [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x1f],
b'F' => [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x10],
b'G' => [0x0f, 0x10, 0x10, 0x17, 0x11, 0x11, 0x0f],
b'H' => [0x11, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11],
b'I' => [0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x1f],
b'J' => [0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0c],
b'K' => [0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11],
b'L' => [0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1f],
b'M' => [0x11, 0x1b, 0x15, 0x15, 0x11, 0x11, 0x11],
b'N' => [0x11, 0x19, 0x15, 0x13, 0x11, 0x11, 0x11],
b'O' => [0x0e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e],
b'P' => [0x1e, 0x11, 0x11, 0x1e, 0x10, 0x10, 0x10],
b'Q' => [0x0e, 0x11, 0x11, 0x15, 0x15, 0x0e, 0x01],
b'R' => [0x1e, 0x11, 0x11, 0x1e, 0x14, 0x12, 0x11],
b'S' => [0x0f, 0x10, 0x10, 0x0e, 0x01, 0x01, 0x1e],
b'T' => [0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04],
b'U' => [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e],
b'V' => [0x11, 0x11, 0x11, 0x11, 0x11, 0x0a, 0x04],
b'W' => [0x11, 0x11, 0x11, 0x15, 0x15, 0x1b, 0x11],
b'X' => [0x11, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x11],
b'Y' => [0x11, 0x11, 0x0a, 0x04, 0x04, 0x04, 0x04],
b'Z' => [0x1f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1f],
b'0' => [0x0e, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0e],
b'1' => [0x04, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x1f],
b'2' => [0x0e, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1f],
b'3' => [0x1e, 0x01, 0x01, 0x0e, 0x01, 0x01, 0x1e],
b'4' => [0x02, 0x06, 0x0a, 0x12, 0x1f, 0x02, 0x02],
b'5' => [0x1f, 0x10, 0x1e, 0x01, 0x01, 0x11, 0x0e],
b'6' => [0x06, 0x08, 0x10, 0x1e, 0x11, 0x11, 0x0e],
b'7' => [0x1f, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08],
b'8' => [0x0e, 0x11, 0x11, 0x0e, 0x11, 0x11, 0x0e],
b'9' => [0x0e, 0x11, 0x11, 0x0f, 0x01, 0x02, 0x0c],
b':' => [0x00, 0x0c, 0x0c, 0x00, 0x0c, 0x0c, 0x00],
b'/' => [0x01, 0x02, 0x02, 0x04, 0x08, 0x08, 0x10],
b'.' => [0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0c],
b'-' => [0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00],
b'(' => [0x02, 0x04, 0x08, 0x08, 0x08, 0x04, 0x02],
b')' => [0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08],
b'[' => [0x1e, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1e],
b']' => [0x0f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0f],
b'=' => [0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00],
b'%' => [0x19, 0x19, 0x02, 0x04, 0x08, 0x13, 0x13],
b'|' => [0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04],
b'+' => [0x04, 0x04, 0x1f, 0x04, 0x04, 0x00, 0x00],
b'>' => [0x10, 0x08, 0x04, 0x02, 0x04, 0x08, 0x10],
b'<' => [0x02, 0x04, 0x08, 0x10, 0x08, 0x04, 0x02],
b'#' => [0x0a, 0x1f, 0x0a, 0x0a, 0x1f, 0x0a, 0x00],
b'~' => [0x00, 0x0d, 0x16, 0x00, 0x00, 0x00, 0x00],
b'@' => [0x0e, 0x11, 0x17, 0x15, 0x17, 0x10, 0x0f],
b',' => [0x00, 0x00, 0x00, 0x00, 0x0c, 0x04, 0x08],
b'\'' => [0x04, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00],
b'$' => [0x04, 0x0f, 0x14, 0x0e, 0x05, 0x1e, 0x04],
b'!' => [0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x04],
b'*' => [0x00, 0x15, 0x0e, 0x1f, 0x0e, 0x15, 0x00],
b'?' => [0x0e, 0x11, 0x01, 0x02, 0x04, 0x00, 0x04],
b'_' => [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f],
b' ' => [0; 7],
_ => [0; 7],
};
for (row, bits) in glyph.iter().enumerate() {
for column in 0..5 {
if bits & (1 << (4 - column)) != 0 {
self.rect(x + column * scale, y + row * scale, scale, scale, color);
}
}
}
}
fn pixel(&mut self, x: usize, y: usize, color: [u8; 3]) {
let Some(info) = self.info else { return };
let offset = (y * info.stride + x) * info.bytes_per_pixel;
unsafe {
let destination =
core::slice::from_raw_parts_mut(self.buffer.add(offset), info.bytes_per_pixel);
match info.pixel_format {
PixelFormat::Rgb => destination[..3].copy_from_slice(&color),
PixelFormat::Bgr => {
destination[..3].copy_from_slice(&[color[2], color[1], color[0]])
}
PixelFormat::U8 => destination[0] = color[0],
PixelFormat::Unknown { .. } => destination[..3].copy_from_slice(&color),
_ => destination[..3].copy_from_slice(&color),
}
}
}
}
static SCREEN: Mutex<Screen> = Mutex::new(Screen::new());
#[derive(Clone, Copy, Eq, PartialEq)]
enum TaskState {
Ready,
Running,
Terminated,
}
#[derive(Clone, Copy)]
struct Task {
id: usize,
name: &'static str,
remaining_steps: usize,
state: TaskState,
}
impl Task {
const EMPTY: Option<Task> = None;
fn new(id: usize, name: &'static str, steps: usize) -> Self {
Self {
id,
name,
remaining_steps: steps,
state: TaskState::Ready,
}
}
fn step(&mut self) -> bool {
if self.remaining_steps > 0 {
self.remaining_steps -= 1;
}
self.state = if self.remaining_steps == 0 {
TaskState::Terminated
} else {
TaskState::Ready
};
self.state == TaskState::Terminated
}
}
struct TaskQueue {
tasks: [Option<Task>; MAX_TASKS],
head: usize,
tail: usize,
switches: usize,
completed: usize,
}
impl TaskQueue {
const fn new() -> Self {
Self {
tasks: [Task::EMPTY; MAX_TASKS],
head: 0,
tail: 0,
switches: 0,
completed: 0,
}
}
fn push(&mut self, task: Task) -> bool {
let next = (self.tail + 1) % MAX_TASKS;
if next == self.head {
return false;
}
self.tasks[self.tail] = Some(task);
self.tail = next;
true
}
fn pop(&mut self) -> Option<Task> {
if self.head == self.tail {
return None;
}
let task = self.tasks[self.head].take();
self.head = (self.head + 1) % MAX_TASKS;
task
}
fn is_empty(&self) -> bool {
self.head == self.tail
}
fn run_one_step(&mut self) -> Option<(Task, bool)> {
let mut task = self.pop()?;
self.switches += 1;
let finished = task.step();
if finished {
self.completed += 1;
} else {
self.push(task);
}
Some((task, finished))
}
}
static READY_QUEUE: Mutex<TaskQueue> = Mutex::new(TaskQueue::new());
static SHARED_COUNTER: Mutex<usize> = Mutex::new(0);
const HEAP_SIZE: usize = 64 * 1024;
static mut HEAP: [u8; HEAP_SIZE] = [0; HEAP_SIZE];
struct BumpAllocator {
next: AtomicUsize,
}
unsafe impl GlobalAlloc for BumpAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let heap_start = core::ptr::addr_of_mut!(HEAP) as *mut u8 as usize;
let current = self.next.load(Ordering::Relaxed);
let aligned = (heap_start + current + layout.align() - 1) & !(layout.align() - 1);
let offset = aligned - heap_start;
let end = match offset.checked_add(layout.size()) {
Some(end) if end <= HEAP_SIZE => end,
_ => return core::ptr::null_mut(),
};
if self
.next
.compare_exchange(current, end, Ordering::SeqCst, Ordering::Relaxed)
.is_ok()
{
aligned as *mut u8
} else {
core::ptr::null_mut()
}
}
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
}
#[global_allocator]
static ALLOCATOR: BumpAllocator = BumpAllocator {
next: AtomicUsize::new(0),
};
#[derive(Clone, Copy)]
#[repr(u8)]
enum InterruptIndex {
Timer = PIC_1_OFFSET,
Keyboard = PIC_1_OFFSET + 1,
}
impl InterruptIndex {
fn as_u8(self) -> u8 {
self as u8
}
}
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
serial_println!("Micro-OS 2.0 Rust kernel booted (Ved Raj // 25BTRCL279)");
serial_println!("[BOOT] x86_64 bootloader transferred control to kernel");
serial_println!("[INIT] serial console initialized (UART 16550 @ 0x3F8)");
if let Some(framebuffer) = boot_info.framebuffer.as_mut() {
let mut screen = SCREEN.lock();
screen.init(framebuffer);
screen.show_splash_animation();
screen.render_desktop();
}
IDT.load();
unsafe { PICS.lock().initialize() };
configure_timer(TIMER_FREQUENCY_HZ);
x86_64::instructions::interrupts::enable();
serial_println!("[INIT] IDT, PIC, PIT and PS/2 Keyboard IRQ initialized");
// Telemetry output for faculty inspection
serial_println!("[HW] Host: ASUS Vivobook 15 (12th Gen Intel Core i5-12500H 12C/16T)");
serial_println!("[NET] WLAN: MediaTek Wi-Fi 6 MT7921 | LAN: Gigabit Ethernet 1000 Mbps");
serial_println!("[PKG] Aptitude / APT package manager initialized in RAM (/var/cache/apt)");
serial_println!("[STORE] Snapstore snapd daemon armed (SquashFS loop mount on /dev/loop0)");
serial_println!("[RESEARCH] Page Replacement under Locality: FIFO, LRU, OPT + Belady Check");
serial_println!("[APPS] Interactive shell, micro-browser (web), apt, snap and pager online");
{
let mut queue = READY_QUEUE.lock();
queue.push(Task::new(1, "shell", 3));
queue.push(Task::new(2, "logger", 2));
queue.push(Task::new(3, "worker", 4));
}
serial_println!("[TASK] created shell, logger and worker");
let allocation = unsafe { ALLOCATOR.alloc(Layout::from_size_align(128, 8).unwrap()) };
if allocation.is_null() {
serial_println!("[MEM] allocation failed");
} else {
serial_println!("[MEM] allocated 128 bytes from kernel bump heap");
}
serial_println!("[RUN] timer-driven Round Robin scheduling & Interactive Shell active");
for _ in 0..5_000_000 {
core::hint::spin_loop();
}
if *SHARED_COUNTER.lock() == 0 {
serial_println!("[TIMER] no PIT IRQ observed; using cooperative fallback");
loop {
let tick = next_tick();
if schedule_once(tick) {
finish_run();
}
}
}
hlt_loop();
}
fn configure_timer(frequency_hz: u32) {
let divisor = 1_193_182 / frequency_hz;
let mut command = Port::<u8>::new(0x43);
let mut channel = Port::<u8>::new(0x40);
unsafe {
command.write(0x36);
channel.write((divisor & 0xff) as u8);
channel.write((divisor >> 8) as u8);
}
}
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
let tick = next_tick();
schedule_once(tick);
unsafe {
PICS.lock()
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8())
};
}
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
let mut port = Port::<u8>::new(0x60);
let scancode: u8 = unsafe { port.read() };
let character = match scancode {
0x1E => Some(b'a'),
0x30 => Some(b'b'),
0x2E => Some(b'c'),
0x20 => Some(b'd'),
0x12 => Some(b'e'),
0x21 => Some(b'f'),
0x22 => Some(b'g'),
0x23 => Some(b'h'),
0x17 => Some(b'i'),
0x24 => Some(b'j'),
0x25 => Some(b'k'),
0x26 => Some(b'l'),
0x32 => Some(b'm'),
0x31 => Some(b'n'),
0x18 => Some(b'o'),
0x19 => Some(b'p'),
0x10 => Some(b'q'),
0x13 => Some(b'r'),
0x1F => Some(b's'),
0x14 => Some(b't'),
0x16 => Some(b'u'),
0x2F => Some(b'v'),
0x11 => Some(b'w'),
0x2D => Some(b'x'),
0x15 => Some(b'y'),
0x2C => Some(b'z'),
0x02 => Some(b'1'),
0x03 => Some(b'2'),
0x04 => Some(b'3'),
0x05 => Some(b'4'),
0x06 => Some(b'5'),
0x07 => Some(b'6'),
0x08 => Some(b'7'),
0x09 => Some(b'8'),
0x0A => Some(b'9'),
0x0B => Some(b'0'),
0x39 => Some(b' '),
0x1C => Some(b'\n'),
0x0E => Some(0x08), // Backspace
0x34 => Some(b'.'),
0x35 => Some(b'/'),
0x0C => Some(b'-'),
_ => None,
};
if let Some(ch) = character {
SCREEN.lock().on_key(ch);
}
unsafe {
PICS.lock()
.notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8())
};
}
fn next_tick() -> usize {
let mut counter = SHARED_COUNTER.lock();
*counter += 1;
*counter
}
fn schedule_once(tick: usize) -> bool {
let mut queue = READY_QUEUE.lock();
if let Some((task, finished)) = queue.run_one_step() {
serial_println!(
"[SCHED] tick={} task={} ({}){}",
tick,
task.id,
task.name,
if finished { " TERMINATED" } else { "" }
);
return queue.is_empty();
}
false
}
fn finish_run() -> ! {
let queue = READY_QUEUE.lock();
serial_println!(
"[DONE] switches={} completed_tasks={}",
queue.switches,
queue.completed
);
exit_qemu(0x10);
x86_64::instructions::interrupts::disable();
hlt_loop();
}
struct SerialWriter;
fn exit_qemu(code: u32) {
let mut port = Port::<u32>::new(0xf4);
unsafe {
port.write(code);
}
}
impl Write for SerialWriter {
fn write_str(&mut self, text: &str) -> fmt::Result {
SERIAL1.lock().write_str(text)
}
}
#[macro_export]
macro_rules! serial_print { ($($arg:tt)*) => {{ use core::fmt::Write; let _ = write!($crate::SerialWriter, $($arg)*); }}; }
#[macro_export]
macro_rules! serial_println {
() => ($crate::serial_print!("\n"));
($fmt:expr) => ($crate::serial_print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => ($crate::serial_print!(concat!($fmt, "\n"), $($arg)*));
}
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
serial_println!("[PANIC] {}", info);
hlt_loop();
}
fn hlt_loop() -> ! {
loop {
x86_64::instructions::hlt();
}
}
|