OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Sep 22, 2021 6:33 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [SOLVED] Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Sun Aug 01, 2021 5:27 pm 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
Code:
[bits 16]
[org 0x7C00]

Bootloader.Code:
;{
    Bootloader.Code.Entry:
    ;{
        mov     [BootDrive], dl     ; DL contains the drive ID used to boot.
       
          mov   al, "B"
          mov   ah, 0x0E
          mov   bh, 0x00
          mov   bl, 0x03
        int     0x10

          mov   ah, 0x02                ; Read sectors function
          mov   al, 1                   ; Number of sectors to read
          mov   ch, 0                   ; Cylinder index
          mov   dh, 0                   ; Head index
          mov   cl, 2                   ; Sector entry to start reading data
          mov   dl, [BootDrive]         ; Drive ID
          mov   bx, Kernel.Code.Entry   ; Pointer where to write the data read
        int     0x13
       
        jnc NoDiskReadError
        ;{
              mov   al, "E"
              mov   ah, 0x0E
              mov   bh, 0x00
              mov   bl, 0x03
            int     0x10
           
            jmp     $
        ;}
        NoDiskReadError:
       
        jmp     Kernel.Code.Entry
    ;}
   
    BootDrive:  db 0
;}
Bootloader.EndCode:

times (510 - Bootloader.EndCode) db 0   ; Fill bin file to reach 510 bytes
dw 0xAA55                              ; + 2 bytes

Kernel.Code.Entry:
;{
      mov   al, "K"
      mov   ah, 0x0E
      mov   bh, 0x00
      mov   bl, 0x03
    int     0x10

    jmp     $
;}


Code:
nasm -f bin ..\Bootloader.asm -o Bootloader.bin


It shows me BE instead of BK

B if bootloader is ok
E if there is a disk error
K if kernel is ok


Last edited by Rukog on Mon Aug 02, 2021 11:34 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Sun Aug 01, 2021 9:42 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3352
You're using DS and ES, but you never set them to known values. You must set the segment registers to known values before you can use them.

It may also be a good idea to set up your own stack instead of relying on the BIOS stack. The BIOS stack can be extremely small.

Edit: another possible cause of the error is the size of your disk image. Have you padded it to at least two sectors big?


Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 5:13 am 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
Octocontrabass wrote:
You're using DS and ES, but you never set them to known values. You must set the segment registers to known values before you can use them.

It may also be a good idea to set up your own stack instead of relying on the BIOS stack. The BIOS stack can be extremely small.

Edit: another possible cause of the error is the size of your disk image. Have you padded it to at least two sectors big?



Sorry you have short seeing the previous code and ive made a simple one since.
So I no more use DS and ES nor the stack.

For padding, here's a version that add it but still doesn't work.

Code:
[bits 16]
[org 0x7C00]

Bootloader:
;{
    jmp     Bootloader.Code.Entry
   
    ;==========================================================================================================================================================================================================
    ; DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA
    ;==========================================================================================================================================================================================================
    Bootloader.Data:
    ;{
        .Drive:  db 0
    ;}
    Bootloader.EndData:
    ;==========================================================================================================================================================================================================
    ; END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA
    ;==========================================================================================================================================================================================================

    ;==========================================================================================================================================================================================================
    ; CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE
    ;==========================================================================================================================================================================================================
    Bootloader.Code:
    ;{
        .Entry:
        ;{
            mov     [Bootloader.Data.Drive], dl  ; DL contains the drive ID used to boot.
           
              mov   al, "B"
              mov   ah, 0x0E
              mov   bh, 0x00
              mov   bl, 0x03
            int     0x10

              mov   ah, 0x02                    ; Read sectors function
              mov   al, 1                       ; Number of sectors to read
              mov   ch, 0                       ; Cylinder index
              mov   dh, 0                       ; Head index
              mov   cl, 2                       ; Sector entry to start reading data
              mov   dl, [Bootloader.Data.Drive] ; Drive ID
              mov   bx, Kernel.Code.Entry       ; Pointer where to write the data read
            int     0x13
           
            jnc     .NoDiskReadError
            ;{
                  mov   al, "E"
                  mov   ah, 0x0E
                  mov   bh, 0x00
                  mov   bl, 0x03
                int     0x10
               
                jmp     $                   ; $ represent the current line address, thus infinite loop
            ;}
            .NoDiskReadError:
           
            jmp     Kernel.Code.Entry
        ;}
        .EndEntry:
    ;}
    Bootloader.EndCode:
    ;==========================================================================================================================================================================================================
    ; END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE
    ;==========================================================================================================================================================================================================
;}
EndBootloader:

times (510 - (EndBootloader - Bootloader)) db 0   ; Fill the 1st sector
BootMagicWord: dw 0xAA55                          ; ...

Kernel:
;{
    ;==========================================================================================================================================================================================================
    ; DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA      DATA
    ;==========================================================================================================================================================================================================
    Kernel.Data:
    ;{
       
    ;}
    Kernel.EndData:
    ;==========================================================================================================================================================================================================
    ; END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA      END_DATA
    ;==========================================================================================================================================================================================================

    ;==========================================================================================================================================================================================================
    ; CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE      CODE
    ;==========================================================================================================================================================================================================
    Kernel.Code:
    ;{
        .Entry:
        ;{
              mov   al, "K"
              mov   ah, 0x0E
              mov   bh, 0x00
              mov   bl, 0x03
            int     0x10

            jmp     $
        ;}
        End.Entry:
    ;}
    ;==========================================================================================================================================================================================================
    ; END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE      END_CODE
    ;==========================================================================================================================================================================================================
;}
EndKernel:

times (512 - (EndKernel - Kernel)) db 0   ; Fill the 2nd sector


Last edited by Rukog on Mon Aug 02, 2021 5:44 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 5:44 am 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 616
What version of NASM are you using, this code produces an error when assembling. Anyway, when this doesn't work are you testing it in a virtual machine or emulator or on real hardware. If real hardware are you using USB in Floppy Disk Drive (FDD) emulation mode?

Although this is almost certainly not the cause of your issue - you should set DS to 0 (since you are using org 0x7c00) before reading and writing to memory in the bootloader. DS is not necessarily 0 when your code starts so you could be writing the data to memory you don't expect.


Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 5:48 am 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
MichaelPetch wrote:
What version of NASM are you using, this code produces an error when assembling. Anyway, when this doesn't work are you testing it in a virtual machine or emulator or on real hardware. If real hardware are you using USB in Floppy Disk Drive (FDD) emulation mode?

Although this is almost certainly not the cause of your issue - you should set DS to 0 (since you are using org 0x7c00) before reading and writing to memory in the bootloader. DS is not necessarily 0 when your code starts so you could be writing the data to memory you don't expect.


Ive updated the code above and no more error.

It's the latest NASM version.
I am using both, Qemu and real PC and it's shows me BK on Qemu but not on PC.
I am using a USB drive and I flash it with HxD.

Ive added
Code:
            xor     ax, ax
            mov     ds, ax


but still doesn't work, only on Qemu.


Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 7:04 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 225
You also have to set ES because int 13h is using it.

Code:
xor ax, ax
mov es, ax


On QEMU is this probably done but on your PC no.


Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 7:16 am 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
Klakap wrote:
You also have to set ES because int 13h is using it.

Code:
xor ax, ax
mov es, ax


On QEMU is this probably done but on your PC no.


oof this is so weird, Ive three PC and the
First one display B
Second one display BK
Third one display BB


Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 7:28 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 225
Please can you post your actual code?

For the first one with B, I think problem lies in BPB. Some BIOSes are checking if your bootloader has BPB and if not, they are writing their one. So this computer is probably overwriting your code with BPB.


Last edited by Klakap on Mon Aug 02, 2021 7:32 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 7:30 am 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
Klakap wrote:
Please can you post your actual code?

Attachment:
Bootloader.asm [7.04 KiB]
Downloaded 8 times


Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 7:38 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 225
You do not set stack pointer.
Code:
xor ax, ax
mov ss, 0
mov sp, 0x7C00 ;stack is going down so we can set it on this value


And as I stated, you should reserve space for BPB(more info in FAT), because some BIOSes can overwrite your code.


Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 7:46 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 225
Also, BTW, you should replace
Code:
jmp $

with
Code:
halt:
  hlt
jmp halt

Because jmp $ will cause overheat of your processor after some time. Command HLT will halt processor to next interrupt, so there is not overheating.


Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 7:51 am 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
Klakap wrote:
You do not set stack pointer.
Code:
xor ax, ax
mov ss, 0
mov sp, 0x7C00 ;stack is going down so we can set it on this value


And as I stated, you should reserve space for BPB(more info in FAT), because some BIOSes can overwrite your code.


Nice it's evolving, my first PC shows me BE, my second is BK and third one is BE.

So Ive only one PC where INT 0x13 works lmao


Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 8:09 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 225
I suggest you to try load your code on 0x10000. You also have to do it, otherwise you can load max 32 KB because of CS segment register.
Code:
mov ax, 0x1000
mov es, ax
...
mov bx, 0
int 13h
...

jmp 0x1000:0x0000 ;execute your code


Quote:
So Ive only one PC where INT 0x13 works lmao

No, int 13h works, but we need to turn his work for our wants.


Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 8:28 am 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
Klakap wrote:
I suggest you to try load your code on 0x10000. You also have to do it, otherwise you can load max 32 KB because of CS segment register.
Code:
mov ax, 0x1000
mov es, ax
...
mov bx, 0
int 13h
...

jmp 0x1000:0x0000 ;execute your code


Quote:
So Ive only one PC where INT 0x13 works lmao

No, int 13h works, but we need to turn his work for our wants.


ok with this code, my both PC show me E

The last one shows me BK as usual.


Top
 Profile  
 
 Post subject: Re: Int 0x13 doesn't want to load up my kernel, strange
PostPosted: Mon Aug 02, 2021 8:31 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 225
Can you figure out if dl on non-working computers is 0x00 or 0x80?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group