problem in booting at int 13h
-
- Posts: 11
- Joined: Tue Sep 15, 2009 1:11 am
problem in booting at int 13h
hi
I followed tutorials to write a simple bootloader that writes a string to screen and also a simple kernel that writes a string to screen. Bootloader i tested from usb drive that worked and kernel bin path i gave from grub which was present on a linux partition. then i tried chainloading from grub to my bootloader on usb device which also worked.
Now the problem is i want to link my kernel to my bootloader. From my understanding my bootloader should first load the kernel to desired location in memory and then jump there to begin execution. So I used this command
dd if=bootl.bin of=/dev/sdb1 bs=512 count=1
and
dd if=kernel.bin of=/dev/sdb1 ibs=9141 obs=512 count=1 seek=4
to write my kernel whose size is 9141. This i suppose would write kernel to 2048 or 0x800 location on usb drive. so i figured that would be the begining of sector 5 and sectors to read = 9141/512 = 18 approx. and es:bx 0000:0x800
then in my asm i used this block of code
[BITS 16]
[ORG 0X7C00]
CALL setvideomode
CALL setcolor
MOV SI,EnterString
CALL PrintString
MOV AH,02
MOV AL,18d
MOV CH,0
MOV CL,5d
MOV DH,0
MOV DL,81h
MOV BX,0
MOV ES,BX
MOV BX,0x800
INT 13H
JC sad
jmp 0x800
sad:
CALL PrintCharacter
CALL PrintCharacter
CALL PrintCharacter
MOV SI, ExitString
CALL PrintString
hlt
JMP $
the problem is it prints EnterString but gets stuck at int 13h i tried inserting strings and found that it does not progress ahead of int 13h i.e it does not even reach jmp 0x800 or sad.it just gets stuck at int 13h. What's wrong? are the offsets i gave incorrect?
Thanks
I followed tutorials to write a simple bootloader that writes a string to screen and also a simple kernel that writes a string to screen. Bootloader i tested from usb drive that worked and kernel bin path i gave from grub which was present on a linux partition. then i tried chainloading from grub to my bootloader on usb device which also worked.
Now the problem is i want to link my kernel to my bootloader. From my understanding my bootloader should first load the kernel to desired location in memory and then jump there to begin execution. So I used this command
dd if=bootl.bin of=/dev/sdb1 bs=512 count=1
and
dd if=kernel.bin of=/dev/sdb1 ibs=9141 obs=512 count=1 seek=4
to write my kernel whose size is 9141. This i suppose would write kernel to 2048 or 0x800 location on usb drive. so i figured that would be the begining of sector 5 and sectors to read = 9141/512 = 18 approx. and es:bx 0000:0x800
then in my asm i used this block of code
[BITS 16]
[ORG 0X7C00]
CALL setvideomode
CALL setcolor
MOV SI,EnterString
CALL PrintString
MOV AH,02
MOV AL,18d
MOV CH,0
MOV CL,5d
MOV DH,0
MOV DL,81h
MOV BX,0
MOV ES,BX
MOV BX,0x800
INT 13H
JC sad
jmp 0x800
sad:
CALL PrintCharacter
CALL PrintCharacter
CALL PrintCharacter
MOV SI, ExitString
CALL PrintString
hlt
JMP $
the problem is it prints EnterString but gets stuck at int 13h i tried inserting strings and found that it does not progress ahead of int 13h i.e it does not even reach jmp 0x800 or sad.it just gets stuck at int 13h. What's wrong? are the offsets i gave incorrect?
Thanks
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: problem in booting at int 13h
Start with setting up a stack
Re: problem in booting at int 13h
I too am having the exact same problem... butI thought i had set up the stack? (or is this just a pointer...?)
boot.asm:
and the file its jumping to is....
The output of this is...
But the 'E' character never fires...
Thanks in advanced for any help.
Sam
boot.asm:
Code: Select all
[BITS 16]
[ORG 0x7C00]
MOV ESP, 0x105000 ; Set the stack pointer
MOV AL, 65
MOV AH, 0x0E ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is lightgrey font on black background
INT 0x10 ;Call video interrupt
read:
MOV AL, 67
MOV AH, 0x0E ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is lightgrey font on black background
INT 0x10 ;Call video interrupt
mov bx, 0x2000 ; Destination Location
mov es, bx ; Into bx
mov bx, 0 ; Offset to read
mov ah, 02 ; Read funct.
mov al, 01 ; Read 1 sector
mov ch, 01 ; First track
mov cl, 02 ; Second sector
mov dh, 01 ; First head
mov dl, 00 ; Drive number 0
int 0x13 ; Call
jc read ; ERROR => Try again
jmp 2000h:0000 ; Jump to the program
TIMES 510 - ($ - $$) db 0
DW 0xAA55
Code: Select all
[BITS 16]
[ORG 0X2000]
MOV AL, 69
MOV AH, 0x0E ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is lightgrey font on black background
INT 0x10 ;Call video interrupt
jmp $
Code: Select all
AC
Thanks in advanced for any help.
Sam
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: problem in booting at int 13h
Ok, we are in Real Mode. Lets ignore the segment registers and the 16-bit addressing...SamW wrote:I too am having the exact same problem... butI thought i had set up the stack? (or is this just a pointer...?)
(...)
[BITS 16]
(...)
MOV ESP, 0x105000 ; Set the stack pointer
-
- Posts: 11
- Joined: Tue Sep 15, 2009 1:11 am
Re: problem in booting at int 13h
well i still didn't get. stack set up yet its stuck at int13h. what is the problem? are inputs to int13 correct and also will mov dl,81h work on usb?? also in the offsets do the sector numbers and head numbers start from 0 or 1. help plz!!!
Re: problem in booting at int 13h
AH gives you the status code after the INT call (Status codes) that can be used for further troubleshooting. Please post the error code here if you continue to have problems.
Also, your stack isnt set up correctly. I don't even see where you set your segment registers up at...
Also, please don't use "plz" like that - spell out the words.
Also, your stack isnt set up correctly. I don't even see where you set your segment registers up at...
Also, please don't use "plz" like that - spell out the words.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: problem in booting at int 13h
Combuster wrote:Ok, we are in Real Mode. Lets ignore the segment registers and the 16-bit addressing...
Phoenix07p, you are familiar with real mode segmented addressing, aren't you?neon wrote:Also, your stack isnt set up correctly. I don't even see where you set your segment registers up at...
Re: problem in booting at int 13h
Try to insert this at begining of your code:
And it would be better if you load your kernel to address 1000:0000 (0x10000) just to ensure that your kernel did'nt overwrites boot loader code
Code: Select all
[bits 16]
[org 0x7c00]
jmp 0:start ; setup cs:ip
start:
xor ax, ax ; setup segment registers
mov ds, ax
mov es, ax
mov ss, ax ; setup stack
xor sp, sp
; - your code here -
-
- Posts: 11
- Joined: Tue Sep 15, 2009 1:11 am
Re: problem in booting at int 13h
ok i will try that and will get back shortly. meanwhile just a question why would I want to initialize segment register if i am not even using them. In this case i just needed es segment register so i initialized it to 00.cause apart from the block of code relating to int 13h, the bootloader was working fine as it is. or r they needed for implicit purposes?
and neon i said in my first post that the program is stuck at int 13h i printed above and below the int command and found that program actually hangs at int 13h line. it just prints entering. so i can't even get the error code.
and yes i am familiar with real mode addressing. but a bit loss in memory related to segments.
thanks.
and neon i said in my first post that the program is stuck at int 13h i printed above and below the int command and found that program actually hangs at int 13h line. it just prints entering. so i can't even get the error code.
and yes i am familiar with real mode addressing. but a bit loss in memory related to segments.
thanks.
Re: problem in booting at int 13h
Hello,
Rather then using jc - grab the reason for it failing from AH.
True. BIOS Interrupts do use them however.phoenix07p wrote:ok i will try that and will get back shortly. meanwhile just a question why would I want to initialize segment register if i am not even using them.
Okay. I highly suspect that it is not hanging at the int call as you think it is. I suspect it returns an error, however do to your jc instruction, it continues to loop forever thus never getting past it.phoenix07p wrote:and neon i said in my first post that the program is stuck at int 13h i printed above and below the int command and found that program actually hangs at int 13h line. it just prints entering. so i can't even get the error code.
Rather then using jc - grab the reason for it failing from AH.
If you are somewhat confused about how memory is referenced in relation to the segments, then you don't have an understanding of segment:offset addressing.phoenix07p wrote:and yes i am familiar with real mode addressing. but a bit loss in memory related to segments
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
-
- Posts: 11
- Joined: Tue Sep 15, 2009 1:11 am
Re: problem in booting at int 13h
Ok that problem taken care of int 13h working fine and sectors are read without error but kernel is not loading. This is the code right now :
[BITS 16]
[ORG 0X7C00]
JMP 0:start
start:
XOR AX,AX
MOV DS,AX
MOV ES,AX
MOV SS,AX
XOR SP,SP
MOV AL,65
CALL setvideomode
CALL setcolor
MOV SI, EnterString
CALL PrintString
MOV AH,02
MOV AL,18d
MOV CH,0
MOV CL,5d
MOV DH,0
MOV DL,81h
MOV BX,0
MOV ES,BX
MOV BX,0X800
INT 13H
JC sad
MOV SI, ConfirmString
CALL PrintString
JMP 0x800
sad:
MOV SI, HelloString
CALL PrintString
hlt
JMP $
setcolor:
MOV AH,0X0B
MOV BH,0X00
MOV BL,0x02
INT 0X10
RET
setvideomode:
MOV AH,0X00
MOV AL,0X12
INT 0X10
MOV AH,0X02
MOV BH,0X00
MOV DH,100
MOV DL,100
RET
PrintCharacter:
MOV AH, 0x0E
MOV BH, 0x00
MOV BL, 0x07
INT 0x10
RET
PrintString:
next_character:
MOV AL, [SI]
INC SI
OR AL, AL
JZ exit_function
CALL PrintCharacter
JMP next_character
exit_function:
RET
HelloString db 'Hello !!! Can't boot',0
ConfirmString db 'jumping to kernel',0
EnterString db 'Entering ......',0
ExitString db 'Exited......',0
TIMES 510 - ($ - $$) db 0
DW 0xAA55
and its not going to 'sad ' label now its printing ConfirmString and jumping to 0x800 but kernel's not getting invoked. the kernel also prints characters on the screen.
like i wrote in my first post i wrote the kernel and bootloader with these:
dd if=bootl.bin of=/dev/sdb1 bs=512 count=1
and
dd if=kernel.bin of=/dev/sdb1 ibs=9141 obs=512 count=1 seek=4
kernel.bin was working fine directly with grub.
what's the problem now??
Thanks
[BITS 16]
[ORG 0X7C00]
JMP 0:start
start:
XOR AX,AX
MOV DS,AX
MOV ES,AX
MOV SS,AX
XOR SP,SP
MOV AL,65
CALL setvideomode
CALL setcolor
MOV SI, EnterString
CALL PrintString
MOV AH,02
MOV AL,18d
MOV CH,0
MOV CL,5d
MOV DH,0
MOV DL,81h
MOV BX,0
MOV ES,BX
MOV BX,0X800
INT 13H
JC sad
MOV SI, ConfirmString
CALL PrintString
JMP 0x800
sad:
MOV SI, HelloString
CALL PrintString
hlt
JMP $
setcolor:
MOV AH,0X0B
MOV BH,0X00
MOV BL,0x02
INT 0X10
RET
setvideomode:
MOV AH,0X00
MOV AL,0X12
INT 0X10
MOV AH,0X02
MOV BH,0X00
MOV DH,100
MOV DL,100
RET
PrintCharacter:
MOV AH, 0x0E
MOV BH, 0x00
MOV BL, 0x07
INT 0x10
RET
PrintString:
next_character:
MOV AL, [SI]
INC SI
OR AL, AL
JZ exit_function
CALL PrintCharacter
JMP next_character
exit_function:
RET
HelloString db 'Hello !!! Can't boot',0
ConfirmString db 'jumping to kernel',0
EnterString db 'Entering ......',0
ExitString db 'Exited......',0
TIMES 510 - ($ - $$) db 0
DW 0xAA55
and its not going to 'sad ' label now its printing ConfirmString and jumping to 0x800 but kernel's not getting invoked. the kernel also prints characters on the screen.
like i wrote in my first post i wrote the kernel and bootloader with these:
dd if=bootl.bin of=/dev/sdb1 bs=512 count=1
and
dd if=kernel.bin of=/dev/sdb1 ibs=9141 obs=512 count=1 seek=4
kernel.bin was working fine directly with grub.
what's the problem now??
Thanks
Re: problem in booting at int 13h
Hello,
Please use code tags when posting code - it makes it easier to read. Also, it might help if you post your bochs crash log (Only the last 10-20 lines please - not the whole log.)
This is where you knowing how to use the bochs debugger becomes important. If you break right before JMPing to the kernel and single step, it might help answer why it is not working. Also, posting a part (or the entire if its small) kernel might help (I see SamW's kernel, not yours.)
Please use code tags when posting code - it makes it easier to read. Also, it might help if you post your bochs crash log (Only the last 10-20 lines please - not the whole log.)
This is where you knowing how to use the bochs debugger becomes important. If you break right before JMPing to the kernel and single step, it might help answer why it is not working. Also, posting a part (or the entire if its small) kernel might help (I see SamW's kernel, not yours.)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: problem in booting at int 13h
Why do people who don't even know how the CPU works (and of course, assembly) try to write OSes?
Okay, I think I've read enough. I will not look through the rest of your "code".
Code: Select all
[BITS 16]
[ORG 0X7C00]
JMP 0:start ; WHAT IS THIS!?
start:
XOR AX,AX
MOV DS,AX
MOV ES,AX
MOV SS,AX
XOR SP,SP ; THE STACK GROWS TO THE BOTTOM OF THE MEMORY!!!
Last edited by Love4Boobies on Sun Sep 20, 2009 1:18 pm, edited 1 time in total.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: problem in booting at int 13h
because some bogus BIOSes jump to 07C0:0000 instead of 0000:7C00.Love4Boobies wrote:Why do people who don't even know how the CPU works (and of course, assembly) try to write OSes?Code: Select all
JMP 0:start ; WHAT IS THIS!? start:
Before pushing something on the stack SP gets decreased.Love4Boobies wrote:Code: Select all
XOR SP,SP ; THE STACK GROWS TO THE BOTTOM OF THE MEMORY!!!
- gravaera
- Member
- Posts: 737
- Joined: Tue Jun 02, 2009 4:35 pm
- Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.
Re: problem in booting at int 13h
I think that's the reason why there's something wrong with zeroing off SP .Before pushing something on the stack SP gets decreased.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.