Page 1 of 2
[SOLVED] Int 0x13 doesn't want to load up my kernel, strange
Posted: Sun Aug 01, 2021 5:27 pm
by Rukog
Code: Select all
[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: Select all
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
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Sun Aug 01, 2021 9:42 pm
by Octocontrabass
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?
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 5:13 am
by Rukog
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: Select all
[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
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 5:44 am
by MichaelPetch
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.
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 5:48 am
by Rukog
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
but still doesn't work, only on Qemu.
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 7:04 am
by Klakap
You also have to set ES because int 13h is using it.
On QEMU is this probably done but on your PC no.
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 7:16 am
by Rukog
Klakap wrote:You also have to set ES because int 13h is using it.
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
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 7:28 am
by Klakap
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.
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 7:30 am
by Rukog
Klakap wrote:Please can you post your actual code?
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 7:38 am
by Klakap
You do not set stack pointer.
Code: Select all
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.
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 7:46 am
by Klakap
Also, BTW, you should replace
with
Because jmp $ will cause overheat of your processor after some time. Command HLT will halt processor to next interrupt, so there is not overheating.
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 7:51 am
by Rukog
Klakap wrote:You do not set stack pointer.
Code: Select all
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
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 8:09 am
by Klakap
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: Select all
mov ax, 0x1000
mov es, ax
...
mov bx, 0
int 13h
...
jmp 0x1000:0x0000 ;execute your code
So Ive only one PC where INT 0x13 works lmao
No, int 13h works, but we need to turn his work for our wants.
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 8:28 am
by Rukog
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: Select all
mov ax, 0x1000
mov es, ax
...
mov bx, 0
int 13h
...
jmp 0x1000:0x0000 ;execute your code
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.
Re: Int 0x13 doesn't want to load up my kernel, strange
Posted: Mon Aug 02, 2021 8:31 am
by Klakap
Can you figure out if dl on non-working computers is 0x00 or 0x80?