1
0
Aarav90-cpu 1 сар өмнө
parent
commit
0cdcb6d04c

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 24
arkos/LICENSE


+ 1 - 0
arkos/Makefile

@@ -57,6 +57,7 @@ iso:
 		-o finished/boot.iso \
 		-b boot.img \
 		-hard-disk-boot \
+		-boot-load-size 4 \
 		-eltorito-alt-boot \
 		-e efi_part.img \
 		-no-emul-boot \

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

@@ -39,16 +39,35 @@ 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 Stage 2
+jump_to_stage2:
+    mov dl, [boot_drive]
     jmp 0x0000:0x7E00
 
+
+
 disk_error:
     mov al, ah
     call print_hex_byte
@@ -99,6 +118,71 @@ 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
@@ -106,6 +190,7 @@ 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

+ 1 - 1
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"\\EFI\\BOOT\\animation.bin", &anim_buffer, &anim_size);
+        status = read_file_from_esp(ImageHandle, SystemTable, L"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);

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

@@ -237,8 +237,13 @@ 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
@@ -278,8 +283,22 @@ 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
@@ -306,6 +325,82 @@ 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
@@ -329,7 +424,7 @@ animation_lba:        dd 0
 animation_size_sectors: dd 0
 lfb_addr:             dd 0
 screen_pitch:         dd 0
-cmd_line: db "console=tty0 loglevel=0 logo.nologo init=/init root=/dev/sdb rw quiet vt.global_cursor_default=0", 0
+cmd_line: db "console=ttyS0 loglevel=3 logo.nologo init=/init root=/dev/sdb rw vt.global_cursor_default=0", 0
 
 align 4
 dap:

+ 37 - 0
arkos/system/init.c

@@ -108,6 +108,43 @@ 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();
     

+ 1 - 1
tools/LICENSE

@@ -186,7 +186,7 @@
       same "printed page" as the copyright notice for easier
       identification within third-party archives.
 
-   Copyright [yyyy] [name of copyright owner]
+   Copyright 2026 Aarav Ravindra Kharade
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.

BIN
tools/build


+ 1 - 0
tools/pack_boot.py

@@ -129,6 +129,7 @@ def main():
     os.system(f"mcopy -i {efi_part_path} {kernel_path} ::/EFI/BOOT/bzImage >/dev/null 2>&1")
     os.system(f"mcopy -i {efi_part_path} {initramfs_path} ::/EFI/BOOT/initramfs.img >/dev/null 2>&1")
     os.system(f"mcopy -i {efi_part_path} {animation_path} ::/EFI/BOOT/animation.bin >/dev/null 2>&1")
+    os.system(f"mcopy -i {efi_part_path} {animation_path} ::/animation.bin >/dev/null 2>&1")
 
     with open(efi_part_path, "rb") as f:
         efi_part_data = f.read()

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно