Loading root directory and kernel does not work

Programming, for all ages and all languages.
Post Reply
ArseniyBe
Posts: 5
Joined: Tue Mar 11, 2025 6:24 pm
Libera.chat IRC: ARSENIYBE
Location: United States

Loading root directory and kernel does not work

Post by ArseniyBe »

Hello, so I have been trying to have the root directory load, find the kernel file and then load the kernel to 0x1000:0x0000, but for some reason it does not work at all. Is there any reason, why?

Code: Select all

LOAD_ROOT_DIR:
    mov si, DAP
    mov word [si + 2], ROOT_DIR_SCTRS ;32
    mov word [si + 4], 0x0000
    mov word [si + 6], 0x4000
    mov dword [si + 8], 514 ;active@ hex editor shows 514 to be the root directory start sector
    mov ah, 0x42
    mov dl, 0x80
    int 0x13
    jc READ_ERR
    mov si, di
    mov cx, 32
    call PRINT_HEX_DUMP
    RET
FIND_KRNL:
    mov di, BUFFER ;0x4000
    mov cx, BPB_NUM_OF_POSSIBLE_ROOT_ENTRIES ;512
.find:
    push cx
    mov si, FILENAME ; 'KERNEL  BIN'
    mov dx, 11
    repe cmpsb
    je .found

    add di, 32
    pop cx
    loop .find
    pop cx
    mov ah, 0x0E
    mov al, 'E'
    int 0x10
    RET
.found:
    pop cx
    mov ax, [di + 26]         ; Load low word of the starting cluster number
    mov [KERNEL_START], ax     ; Store kernel start LBA
    RET
CLUSTR_LBA:
    xor ax, ax
    mov bx, ax
    mov cx, ax
    mov ax, [KERNEL_START]
    sub ax, 2
    mov bx, [BPB_SECTORS_PER_CLUSTER]
    mul bx
    add ax, 514
    add ax, ROOT_DIR_SCTRS
    mov [KERNEL_START], ax
    RET
LOAD_KRNL:
    mov si, DAP
    mov ax, KRNLSEGMNT
    mov es, ax
    mov bx, KRNLOFFSET
    mov word [si + 2], 1
    mov word [si + 4], bx
    mov word [si + 6], ax
    xor ax, ax
    mov ax, [KERNEL_START]
    mov dword [si + 8], eax
    mov ah, 0x42
    mov dl, 0x80
    int 0x13
    jc READ_ERR
    mov ah, 0x0E
    mov al, '6'
    int 0x10
    jmp 0x1000:0x0000
I have attempted to fix it multiple ways, including changing the sector for LOAD_ROOT_DIR, checking the kernel file's ORG, which is at 0x0000, even changed it to 0x1000, which yielded no results whatsoever, and even did ah=0x01 on it, which didn't even print anything out at all. This is the READ_ERR and DAP that I set up before the changes done to it in the functions:

Code: Select all

DAP:
    db 0x10
    db 0x00
    DW 0x0001
    DW 0x0000
    DW 0x0000
    DD 0x00000000
    DD 0x00000000

READ_ERR:
    mov bl, ah
    cmp bl, 9
    jg HEX_ERR
    add bl, '0'
    jmp PRINT_ERR
HEX_ERR:
    add bl, 'A' - 10
PRINT_ERR:
    mov ah, 0x0E
    mov al, bl
    int 0x10
    jmp $
What could the problem be if I did all that, and the MBR did load the FAT Boot Sector correctly with the ah=0x42? And, the hex dump for 32 bytes in the root directory printed a string of different hexes(which did not show up nowhere in the partition AT ALL, the hex codes are in the given screenshot), so it can't be a 13h extensions support issue, especially if it loaded the FAT boot sector properly.
Screenshot 2025-03-22 105631.png
Screenshot 2025-03-22 105631.png (5.64 KiB) Viewed 10976 times
I would very much appreciate as much help as I can receive and can give more information as needed.
Octocontrabass
Member
Member
Posts: 5721
Joined: Mon Mar 25, 2013 7:01 pm

Re: Loading root directory and kernel does not work

Post by Octocontrabass »

ArseniyBe wrote: Sat Mar 22, 2025 12:00 pm

Code: Select all

    mov word [si + 4], 0x0000
    mov word [si + 6], 0x4000
What address are you trying to put in your DAP? What address are you actually putting in your DAP?
ArseniyBe wrote: Sat Mar 22, 2025 12:00 pm

Code: Select all

    mov si, di
    mov cx, 32
    call PRINT_HEX_DUMP
What address are you trying to pass to PRINT_HEX_DUMP? What address are you actually passing to PRINT_HEX_DUMP?
ArseniyBe wrote: Sat Mar 22, 2025 12:00 pmAnd, the hex dump for 32 bytes in the root directory printed a string of different hexes(which did not show up nowhere in the partition AT ALL, the hex codes are in the given screenshot),
It looks like the address you are actually passing to PRINT_HEX_DUMP is 0x0000:0x0000.
ArseniyBe
Posts: 5
Joined: Tue Mar 11, 2025 6:24 pm
Libera.chat IRC: ARSENIYBE
Location: United States

Re: Loading root directory and kernel does not work

Post by ArseniyBe »

Octocontrabass wrote: Sat Mar 22, 2025 9:09 pm
ArseniyBe wrote: Sat Mar 22, 2025 12:00 pm

Code: Select all

    mov word [si + 4], 0x0000
    mov word [si + 6], 0x4000
What address are you trying to put in your DAP? What address are you actually putting in your DAP?
ArseniyBe wrote: Sat Mar 22, 2025 12:00 pm

Code: Select all

    mov si, di
    mov cx, 32
    call PRINT_HEX_DUMP
What address are you trying to pass to PRINT_HEX_DUMP? What address are you actually passing to PRINT_HEX_DUMP?
ArseniyBe wrote: Sat Mar 22, 2025 12:00 pmAnd, the hex dump for 32 bytes in the root directory printed a string of different hexes(which did not show up nowhere in the partition AT ALL, the hex codes are in the given screenshot),
It looks like the address you are actually passing to PRINT_HEX_DUMP is 0x0000:0x0000.
Okay, so I realized that i meant to put the PRINT_HEX_DUMP function in the FIND_KRNL under the ".find". Secondly, when I do that(I changed si+4 to 0x4000 and si+6 to 0x0000), nothing gets printed out at all, despite the function being called.
Octocontrabass
Member
Member
Posts: 5721
Joined: Mon Mar 25, 2013 7:01 pm

Re: Loading root directory and kernel does not work

Post by Octocontrabass »

ArseniyBe wrote: Sun Mar 23, 2025 7:37 amnothing gets printed out at all, despite the function being called.
How do you know the function is called if it doesn't print anything?
ArseniyBe
Posts: 5
Joined: Tue Mar 11, 2025 6:24 pm
Libera.chat IRC: ARSENIYBE
Location: United States

Re: Loading root directory and kernel does not work

Post by ArseniyBe »

Octocontrabass wrote: Sun Mar 23, 2025 7:10 pm
ArseniyBe wrote: Sun Mar 23, 2025 7:37 amnothing gets printed out at all, despite the function being called.
How do you know the function is called if it doesn't print anything?
Well, I did

Code: Select all

mov si, di
mov cx, 32
call PRINT_HEX_DUMP
In the .find part of the FIND_KRNL function, and it printed nothing, but it didn't print 'E', so that's something.
Octocontrabass
Member
Member
Posts: 5721
Joined: Mon Mar 25, 2013 7:01 pm

Re: Loading root directory and kernel does not work

Post by Octocontrabass »

How do you know that part of your code gets called?
ArseniyBe
Posts: 5
Joined: Tue Mar 11, 2025 6:24 pm
Libera.chat IRC: ARSENIYBE
Location: United States

Re: Loading root directory and kernel does not work

Post by ArseniyBe »

Because I used to have the character 'K' be printed out at the start and end of all these functions.
Octocontrabass
Member
Member
Posts: 5721
Joined: Mon Mar 25, 2013 7:01 pm

Re: Loading root directory and kernel does not work

Post by Octocontrabass »

Have you used your debugger to check?
ArseniyBe
Posts: 5
Joined: Tue Mar 11, 2025 6:24 pm
Libera.chat IRC: ARSENIYBE
Location: United States

Re: Loading root directory and kernel does not work

Post by ArseniyBe »

Yes, and I can check it again soon and show the results of probably the LOAD_ROOT_DIR function
Octocontrabass
Member
Member
Posts: 5721
Joined: Mon Mar 25, 2013 7:01 pm

Re: Loading root directory and kernel does not work

Post by Octocontrabass »

Yes please. You might be able to find the problem that way, and if you don't, you can show us what you've checked so we can help you find the problem.
Post Reply