Bootloader jmp problem

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
justbreathIT
Posts:2
Joined:Tue Dec 14, 2010 3:18 am
Bootloader jmp problem

Post by justbreathIT » Tue Dec 14, 2010 4:03 am

Hi
I'm italian, english it's not my first language, i'm sorry.

I'm trying to create my own bootloader, following the tutorials in this site.. But it's not working as i wish.
The problem is the jump to the second stage.
When i try to jmp to any type of segment adress, bochs crash or reboot as a infinite loop.
I've just typed the same adress as the tutorial do... but doesn't work.
Why?
What's the matter?

I assemble the asm files with nasm.
i 've created a win32 program that allow me to assemble all files, (assembled with nasm), all in one as a binary image .img.
then i Test all with bochs.

My application simply append one file to another (all files are 512 bytes long, like the floppy sectors)... i have tryed to open the binary image with an hex editor, and it's ok.

this is my code:
stage1.asm

Code: Select all

bits 16
org 0

start:    jmp    main
main:
            mov    ax,0x07c0
            mov    ds,ax
            mov    es,ax
           
            cli
            mov    ax,0x9000
            mov    ss,ax
            mov    sp,0xffff
            sti

            ;output text with Print function [not included]

            ;then
            mov    ax,0x1000    ;read into 0x1000 segment
            mov    es,ax
            xor     bx,bx           ;offset 0x0000
            mov    ax,0x0201    ;read one sector
            mov    cx,0x0002    ;track 0 2nd sector
            mov    dx,0x0000    ;head 0 drive 0= floppy
            int       0x13
            
            ;check carry flag if not
            ;print success [not posted]
            jmp     word 0x1000:0x0000

times 510-($-$$) db 0
dw 0xAA55
stage2.asm

Code: Select all

bits 16
org 0x1000

start:    jmp    main

msg:      db      "Hello!",13,10,0

Print:
             lodsb
             or      al,al
             jz      .Done
             mov   ah,0x0e
             int      0x10
             jmp    Print
.Done:
             ret
main:
            ;print some text with Print function
            mov    si,msg
            call      Print

            cli
            hlt
times 512-($-$$) db 0
ok..
Bochs loads the stage1 from the binary floppy image, into 0x07c0 segment adress then...
but nothing happen, I can see only the first stage message, then, not another.
if i try to change the org of the 2nd stage to 0... i see only an infinite loop
if i try to change the segment adress from 0x1000 to another i receive a bochs error message:
prefetch EIP [0001000] > CS.limit [0000ffff]

Can anyone tell me what is the matter please ?
I feel i'm going crazy... :D Thanks to all

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Re: Bootloader jmp problem

Post by Mike » Tue Dec 14, 2010 4:10 am

Hello,

Please make sure DS=CS in stage2.asm; the software might not be referencing the data correctly. Also, because CS and DS are being set, ORG should be 0.

If problems persists, please verify using the bochs debugger that your stage2 program is being loaded and executed correctly.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

justbreathIT
Posts:2
Joined:Tue Dec 14, 2010 3:18 am

Re: Bootloader jmp problem

Post by justbreathIT » Wed Dec 15, 2010 2:35 am

Hello,

I tried to use bochs debugger but i am not able to use it and cs:ds are the same.
Stage2

Code: Select all

...
Cli
Push cs
Pop   Ds
Sti
...
I tried to use the demo files, and it is the same.
So... I decided to use the second method with fat12 support and it works.
But at the demo 6.1 when i try to jump to 0x8:Stage3 bochs crash again. It reeboot himself as an infinite loop.
But if i copy the knldr.sys and krnl.sys into the floppy drive it works...
I followed the same steps, the same steps and copy and paste... But with this method it still not working @ the jump instruction.
I don't speak english very well as you can see. (i have tryed and co) :oops: i'm so sorry but i need some help.

Post Reply