Parcourir la source

Removed ISO Booting (Will readd that later). Added proper UEFI Booting and patched issues related with BIOS

Aarav90-cpu il y a 1 mois
Parent
commit
4722d5edc4

+ 3 - 62
arkos/Makefile

@@ -4,7 +4,7 @@ TOOLS := $(ROOT)/tools
 ARKOS := $(ROOT)/arkos
 CLANG := $(ARKOS)/prebuilts/clang/bin/clang
 
-.PHONY: build run clean run-uefi iso run-iso run-iso-uefi
+.PHONY: build run clean run-uefi
 
 build:
 	@$(MAKE) --no-print-directory -C $(TOOLS)
@@ -48,68 +48,9 @@ run-uefi:
 		-drive file=finished/vend.img,format=raw,index=2,media=disk \
 		-vga virtio
 
-iso:
-	@echo "Creating bootable hybrid ISO..."
-	@mkdir -p out_staging/iso_root
-	@cp finished/boot.img out_staging/iso_root/boot.img
-	@cp out_staging/efi_part.img out_staging/iso_root/efi_part.img
-	@xorriso -as mkisofs \
-		-o finished/boot.iso \
-		-b boot.img \
-		-hard-disk-boot \
-		-boot-load-size 4 \
-		-eltorito-alt-boot \
-		-e efi_part.img \
-		-no-emul-boot \
-		-V "ArkOS" \
-		out_staging/iso_root
-
-run-iso:
-	@echo "Starting ArkOS Testing Window in QEMU (BIOS ISO)..."
-	@dd if=/dev/zero of=finished/dummy.img bs=1M count=1 2>/dev/null
-	@qemu-system-x86_64 \
-		-m 2048 \
-		-smp 2 \
-		-cdrom finished/boot.iso \
-		-drive file=finished/dummy.img,format=raw,index=0,media=disk \
-		-drive file=finished/sys.img,format=raw,index=1,media=disk \
-		-drive file=finished/vend.img,format=raw,index=3,media=disk \
-		-vga virtio \
-		-enable-kvm 2>/dev/null || \
-	qemu-system-x86_64 \
-		-m 2048 \
-		-smp 2 \
-		-cdrom finished/boot.iso \
-		-drive file=finished/dummy.img,format=raw,index=0,media=disk \
-		-drive file=finished/sys.img,format=raw,index=1,media=disk \
-		-drive file=finished/vend.img,format=raw,index=3,media=disk \
-		-vga virtio
-
-run-iso-uefi:
-	@echo "Starting ArkOS Testing Window in QEMU (UEFI ISO)..."
-	@dd if=/dev/zero of=finished/dummy.img bs=1M count=1 2>/dev/null
-	@qemu-system-x86_64 \
-		-bios /usr/share/edk2/x64/OVMF.4m.fd \
-		-m 2048 \
-		-smp 2 \
-		-cdrom finished/boot.iso \
-		-drive file=finished/dummy.img,format=raw,index=0,media=disk \
-		-drive file=finished/sys.img,format=raw,index=1,media=disk \
-		-drive file=finished/vend.img,format=raw,index=3,media=disk \
-		-vga virtio \
-		-enable-kvm 2>/dev/null || \
-	qemu-system-x86_64 \
-		-bios /usr/share/edk2/x64/OVMF.4m.fd \
-		-m 2048 \
-		-smp 2 \
-		-cdrom finished/boot.iso \
-		-drive file=finished/dummy.img,format=raw,index=0,media=disk \
-		-drive file=finished/sys.img,format=raw,index=1,media=disk \
-		-drive file=finished/vend.img,format=raw,index=3,media=disk \
-		-vga virtio
-
 clean:
-	rm -rf out_staging finished
+	rm -rf out_staging finished boot/assets
+	@$(MAKE) --no-print-directory -C $(TOOLS) clean
 
 # Extract securebuild key
 ARK_KEY := $(shell if [ -f vendor/verify/securebuild.ark ]; then grep "^ARK-OS-" vendor/verify/securebuild.ark | tr -d '[:space:]'; else echo "NO_KEY"; fi)

+ 9 - 0
arkos/arkrt/main.swift

@@ -24,6 +24,15 @@ func spawnUserUI() -> pid_t {
     let pid = fork()
     if pid == 0 {
         // Child Process
+        let consoleFd = open("/dev/console", O_RDWR)
+        if consoleFd >= 0 {
+            dup2(consoleFd, 1)
+            dup2(consoleFd, 2)
+            if consoleFd > 2 {
+                close(consoleFd)
+            }
+        }
+        
         let path = "/swift_splash"
         
         let cArg0 = strdup(path)

+ 1 - 124
arkos/boot/source/bootloader.asm

@@ -17,14 +17,6 @@ start:
     mov al, 0x03
     int 0x10
 
-    ; Print boot drive number in dl
-    mov al, dl
-    call print_hex_byte
-    mov ah, 0x0E
-    mov al, 13
-    int 0x10
-    mov al, 10
-    int 0x10
 
     ; Print startup messages
     mov si, msg_start
@@ -39,72 +31,23 @@ start:
     mov si, msg_kernel
     call print_string
 
-    ; Check if Extensions are present
-    mov dl, [boot_drive]
-    mov ah, 0x41
-    mov bx, 0x55AA
-    int 0x13
-    jc load_chs
-    cmp bx, 0xAA55
-    jne load_chs
-
     ; Load Stage 2 from disk using LBA read
     mov dl, [boot_drive]
     mov ah, 0x42
     mov si, dap
     int 0x13
     jc disk_error
-    jmp jump_to_stage2
-
-load_chs:
-    mov al, 7           ; Read 7 sectors
-    mov bx, 0x7E00      ; Destination offset
-    call read_sectors_chs
-    jc disk_error
 
-jump_to_stage2:
-    mov dl, [boot_drive]
+    ; Jump to Stage 2
     jmp 0x0000:0x7E00
 
-
-
 disk_error:
-    mov al, ah
-    call print_hex_byte
-    mov ah, 0x0E
-    mov al, 13
-    int 0x10
-    mov al, 10
-    int 0x10
     mov si, msg_err
     call print_string
 halt:
     hlt
     jmp halt
 
-print_hex_byte:
-    push ax
-    push cx
-    mov cl, 4
-    shr al, cl
-    call print_nibble
-    pop ax
-    push ax
-    call print_nibble
-    pop cx
-    pop ax
-    ret
-
-print_nibble:
-    and al, 0x0F
-    add al, '0'
-    cmp al, '9'
-    jbe .print
-    add al, 7
-.print:
-    mov ah, 0x0E
-    int 0x10
-    ret
 
 ; --- Functions ---
 print_string:
@@ -118,71 +61,6 @@ print_string:
 .done:
     ret
 
-read_sectors_chs:
-    push es
-    push ax             ; Save number of sectors to read
-    push bx             ; Save destination offset
-
-    ; 1. Get drive parameters
-    mov ah, 0x08
-    mov dl, [boot_drive]
-    xor di, di          ; ES:DI = 0:0 to prevent BIOS bugs
-    mov es, di
-    int 0x13
-    jc .use_default
-
-    ; Save H_count (dh + 1) in bl, and S_track (cl & 0x3F) in bh
-    movzx bx, dh
-    inc bx              ; bx = H_count
-    and cx, 0x003F      ; cx = S_track
-    
-    jcxz .use_default
-    test bx, bx
-    jz .use_default
-    jmp .calc_chs
-
-.use_default:
-    mov cx, 63          ; default sectors per track
-    mov bx, 16          ; default heads
-
-.calc_chs:
-    ; 2. Perform LBA to CHS calculation for LBA 34
-    mov ax, 34          ; ax = LBA
-    xor dx, dx
-    div cx              ; ax = LBA / S_track, dx = LBA % S_track
-
-    ; Sector S = (LBA % S_track) + 1
-    mov cl, dl
-    inc cl              ; cl = Sector S (bits 0-5)
-
-    ; Head H = (LBA / S_track) % H_count
-    xor dx, dx
-    div bx              ; ax = Cylinder C (should be 0), dx = Head H
-    mov dh, dl          ; dh = Head H
-
-    ; Cylinder C is 0, so ch = 0, and cl bits 6-7 are 0
-    mov ch, 0
-
-    ; Restore destination offset to bx, and pop ax
-    pop bx              ; es:bx = destination buffer
-    pop ax              ; al = number of sectors to read (7)
-    pop es              ; Restore original ES
-
-    ; Load boot drive to dl
-    mov dl, [boot_drive]
-
-    ; Call CHS Read
-    mov ah, 0x02
-    int 0x13
-    ret
-
-chs_fail:
-    pop bx
-    pop ax
-    pop es
-    stc
-    ret
-
 ; --- Data ---
 msg_start:  db "Welcome to ArkOS Bootloader", 13, 10, 0
 msg_key:    db "Checking Hardware Secure Key... OK", 13, 10, 0
@@ -190,7 +68,6 @@ msg_drm:    db "Loading DRM Module... OK", 13, 10, 0
 msg_kernel: db "Loading Kernel & Launching OS...", 13, 10, 0
 msg_err:    db "Disk Error loading Stage 2!", 13, 10, 0
 
-
 boot_drive: db 0
 
 align 4

+ 2 - 2
arkos/boot/source/bootloader.c

@@ -248,7 +248,7 @@ EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
     if (gop) {
         VOID *anim_buffer = NULL;
         UINTN anim_size = 0;
-        status = read_file_from_esp(ImageHandle, SystemTable, L"animation.bin", &anim_buffer, &anim_size);
+        status = read_file_from_esp(ImageHandle, SystemTable, L"\\EFI\\BOOT\\animation.bin", &anim_buffer, &anim_size);
         if (!EFI_ERROR(status)) {
             UINTN num_frames = 60;
             UINTN expected_size = num_frames * anim_width * anim_height * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
@@ -303,7 +303,7 @@ EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
     );
     if (EFI_ERROR(status)) return status;
 
-    CHAR16 *cmd_line = L"initrd=\\EFI\\BOOT\\initramfs.img console=ttyS0 loglevel=0 logo.nologo init=/init root=/dev/sdb rw quiet vt.global_cursor_default=0";
+    CHAR16 *cmd_line = L"initrd=\\EFI\\BOOT\\initramfs.img console=ttyS0 console=tty0 loglevel=0 logo.nologo init=/init root=/dev/sdb rw quiet vt.global_cursor_default=0";
     kernel_loaded_image->LoadOptions = cmd_line;
     kernel_loaded_image->LoadOptionsSize = (StrLen(cmd_line) + 1) * sizeof(CHAR16);
 

+ 1 - 96
arkos/boot/source/stage2.asm

@@ -237,13 +237,8 @@ read_sectors:
     mov dl, [boot_drive]
     mov si, dap
     int 0x13
-    jnc .ok
-
-    mov eax, [dap_lba]
-    call read_sector_chs
     jc .disk_error
 
-.ok:
     pop cx
     pop eax
     inc eax
@@ -283,22 +278,8 @@ read_sectors_high:
     int 0x13
     pop edi
 
-    jnc .ok_high
-
-    mov eax, [dap_lba]
-    push es
-    push bx
-    xor bx, bx
-    mov es, bx
-    mov bx, 0x2000
-    push edi
-    call read_sector_chs
-    pop edi
-    pop bx
-    pop es
     jc .disk_error_high
 
-.ok_high:
     push ds
     push es
     xor ax, ax
@@ -325,82 +306,6 @@ read_sectors_high:
     stc
     ret
 
-read_sector_chs:
-    push es
-    push eax
-    push bx
-    push cx
-    push dx
-    push di
-
-    ; 1. Get drive parameters
-    mov ah, 0x08
-    mov dl, [boot_drive]
-    xor di, di
-    mov es, di
-    int 0x13
-    jc .use_default
-
-    ; Save H_count (dh + 1) in edi, and S_track (cl & 0x3F) in ecx
-    movzx edi, dh
-    inc edi             ; edi = H_count
-    and cl, 0x3F
-    movzx ecx, cl       ; ecx = S_track
-
-    jecxz .use_default
-    test edi, edi
-    jz .use_default
-    jmp .calc_chs
-
-.use_default:
-    mov ecx, 63         ; default sectors per track
-    mov edi, 16         ; default heads
-
-.calc_chs:
-
-    ; 2. Perform LBA to CHS calculation
-    xor edx, edx
-    div ecx             ; eax = LBA / S_track, edx = LBA % S_track
-
-    ; Sector S = (LBA % S_track) + 1
-    push dx             ; Save LBA % S_track
-    
-    ; Head H = (LBA / S_track) % H_count
-    xor edx, edx
-    div edi             ; eax = Cylinder C, edx = Head H
-    
-    mov dh, dl          ; dh = Head H
-    
-    mov ch, al          ; ch = Cylinder low 8 bits
-    mov cl, ah
-    shl cl, 6           ; cl bits 6-7 = Cylinder high 2 bits
-    
-    pop ax              ; ax = LBA % S_track
-    inc ax              ; ax = Sector S
-    or cl, al           ; cl bits 0-5 = Sector S
-    
-    pop di
-    pop dx              ; Restore dx (original)
-    mov dl, [boot_drive] ; Ensure dl is correct boot drive
-    pop bx              ; es:bx = destination buffer
-    pop eax
-    pop es
-
-    ; Call CHS Read
-    mov ax, 0x0201      ; ah = 0x02 (read), al = 1 sector
-    int 0x13
-    ret
-
-.chs_fail:
-    pop di
-    pop dx
-    pop cx
-    pop bx
-    pop eax
-    pop es
-    stc
-    ret
-
 ; --- Data ---
 msg_stage2: db "Stage 2 Bootloader...", 13, 10, 0
 msg_unreal: db "Unreal Mode Activated...", 13, 10, 0
@@ -424,7 +329,7 @@ animation_lba:        dd 0
 animation_size_sectors: dd 0
 lfb_addr:             dd 0
 screen_pitch:         dd 0
-cmd_line: db "console=ttyS0 loglevel=3 logo.nologo init=/init root=/dev/sdb rw vt.global_cursor_default=0", 0
+cmd_line: db "console=tty0 loglevel=0 logo.nologo init=/init root=/dev/sdb rw quiet vt.global_cursor_default=0", 0
 
 align 4
 dap:

+ 4 - 0
arkos/system/fb_helper.c

@@ -8,3 +8,7 @@ int get_vinfo(int fd, struct fb_var_screeninfo *vinfo) {
 int get_finfo(int fd, struct fb_fix_screeninfo *finfo) {
     return ioctl(fd, FBIOGET_FSCREENINFO, finfo);
 }
+
+int pan_display(int fd, struct fb_var_screeninfo *vinfo) {
+    return ioctl(fd, FBIOPAN_DISPLAY, vinfo);
+}

+ 9 - 37
arkos/system/init.c

@@ -85,6 +85,7 @@ int verify_os_signature() {
     return 1;
 }
 
+
 int main() {
     // Mount essential filesystems
     mkdir("/dev", 0755);
@@ -108,49 +109,20 @@ int main() {
     printf("\033[0;40m\033[2J\033[H\033[?25l");
     fflush(stdout);
     
-    // PERSISTENT MODULE LOAD OPTIMIZATION (First boot vs Subsequent boot)
-    mkdir("/mnt", 0755);
-    int mounted = 0;
-    if (mount("/dev/sdb", "/mnt", "ext4", 0, NULL) == 0) {
-        mounted = 1;
-    } else if (mount("/dev/sda", "/mnt", "ext4", 0, NULL) == 0) {
-        mounted = 1;
-    }
-
-    if (mounted) {
-        struct stat st_cache;
-        if (stat("/mnt/modules.cache", &st_cache) == 0) {
-            printf("[Subsequent Boot] Loading cached modules: ext4, usb-storage, virtio-pci, virtio-gpu, snd-hda-intel... OK\n");
-            fflush(stdout);
-        } else {
-            printf("[First Boot] Kernel loading modules...\n");
-            fflush(stdout);
-            const char *mods[] = { "ext4", "usb-storage", "virtio-pci", "virtio-gpu", "snd-hda-intel" };
-            for (int i = 0; i < 5; i++) {
-                printf("  -> Loading module: %s... ", mods[i]);
-                fflush(stdout);
-                sleep(1); // Simulate slow module loading
-                printf("OK\n");
-                fflush(stdout);
-            }
-            int cache_fd = open("/mnt/modules.cache", O_WRONLY | O_CREAT | O_TRUNC, 0644);
-            if (cache_fd >= 0) {
-                write(cache_fd, "cached=1\n", 9);
-                close(cache_fd);
-            }
-        }
-        umount("/mnt");
-    } else {
-        printf("Warning: Persistent system partition not mounted. Skipping module load optimization.\n");
-        fflush(stdout);
-    }
-    
     // VERIFIED BOOT CHECK
     verify_os_signature();
+
     
     // Launch the swift application
     pid_t pid = fork();
     if (pid == 0) {
+        int sfd = open("/dev/ttyS0", O_RDWR);
+        if (sfd >= 0) {
+            dup2(sfd, 0);
+            dup2(sfd, 1);
+            dup2(sfd, 2);
+            if (sfd > 2) close(sfd);
+        }
         char *argv[] = { "/arkrt", NULL };
         char *envp[] = { "PATH=/bin:/usr/bin:/sbin", NULL };
         execve("/arkrt", argv, envp);

+ 12 - 5
arkos/system/swift_splash.swift

@@ -66,6 +66,9 @@ func get_vinfo(_ fd: Int32, _ vinfo: UnsafeMutableRawPointer) -> Int32
 @_silgen_name("get_finfo")
 func get_finfo(_ fd: Int32, _ finfo: UnsafeMutableRawPointer) -> Int32
 
+@_silgen_name("pan_display")
+func pan_display(_ fd: Int32, _ vinfo: UnsafeMutableRawPointer) -> Int32
+
 // ══════════════════════════════════════════════════════════════════
 //  Anti-Aliased High-Resolution Back-Buffered Renderer
 // ══════════════════════════════════════════════════════════════════
@@ -173,7 +176,8 @@ func ringAA(_ p: UnsafeMutablePointer<UInt8>, _ cx: Double, _ cy: Double, _ r: D
 func blit(_ src: UnsafeMutablePointer<UInt8>,
           _ fbp: UnsafeMutablePointer<UInt8>,
           _ sx: Int, _ sy: Int,
-          _ lineLen: Int, _ scrH: Int) {
+          _ lineLen: Int, _ scrH: Int,
+          _ fd: Int32, _ vinfo: UnsafeMutableRawPointer) {
     for y in 0..<AH {
         let fy = sy + y
         if fy < 0 || fy >= scrH { continue }
@@ -181,6 +185,7 @@ func blit(_ src: UnsafeMutablePointer<UInt8>,
                src + y * AW * 4,
                AW * 4)
     }
+    _ = pan_display(fd, vinfo)
 }
 
 // ── Isolated IPC Client (talks to arkrt daemon) ──
@@ -322,7 +327,7 @@ func drawSwiftSplash() {
             diskAA(work, ex, ey, curElR, 255)
         }
         
-        blit(work, fbp, sx, sy, lineLen, scrH)
+        blit(work, fbp, sx, sy, lineLen, scrH, fd, &vinfo)
         usleep(16666)
     }
 
@@ -352,7 +357,7 @@ func drawSwiftSplash() {
             diskAA(work, ex, ey, Double(ELEC_R), 255)
         }
         
-        blit(work, fbp, sx, sy, lineLen, scrH)
+        blit(work, fbp, sx, sy, lineLen, scrH, fd, &vinfo)
         usleep(16666)
     }
 
@@ -393,7 +398,7 @@ func drawSwiftSplash() {
             }
         }
         
-        blit(work, fbp, sx, sy, lineLen, scrH)
+        blit(work, fbp, sx, sy, lineLen, scrH, fd, &vinfo)
         usleep(16666)
     }
 
@@ -407,12 +412,13 @@ func drawSwiftSplash() {
         if bright > 0 {
             diskAA(work, Double(AC), Double(AC), flashR, bright)
         }
-        blit(work, fbp, sx, sy, lineLen, scrH)
+        blit(work, fbp, sx, sy, lineLen, scrH, fd, &vinfo)
         usleep(16666)
     }
 
     // ── Clear to BLACK ──
     memset(fbp, 0, scrSz)
+    _ = pan_display(fd, &vinfo)
 
     // ── Splash screen ──
     print("\u{1B}[0;40m\u{1B}[2J\u{1B}[H", terminator: "")
@@ -436,6 +442,7 @@ func drawSwiftSplash() {
             fbp[off + 3] = 0
         }
     }
+    _ = pan_display(fd, &vinfo)
 
     tpl.deallocate()
     work.deallocate()

+ 2 - 7
tools/Makefile

@@ -1,10 +1,5 @@
-CC ?= cc
-CFLAGS = -Wall -Wextra -O2
-
-all: build
-
-build: build.c ark_parser.c ark_parser.h
-	$(CC) $(CFLAGS) -o build build.c ark_parser.c
+build: build.c ark_parser.c
+	gcc -O2 build.c ark_parser.c -o build
 
 clean:
 	rm -f build

BIN
tools/build