Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Bootloader Is Not Working. Help?

asm bootloader boot load sectors kernel bootstrap problem floppy

  • Please log in to reply
23 replies to this topic

#1 Guest45316

Guest45316

    CC Newcomer

  • Member
  • PipPip
  • 14 posts

Posted 23 April 2012 - 04:03 PM

Hello! I have made a bootloader on x86. The rest of it works, its just that the program hangs after jumping to the (supposedly) loaded sector. Could someone please tell me what I am doing wrong?

	    [BITS 16]
	    org 0x0
	    mov ax, cs
	    mov ds, ax
	    cli
	    mov ss, ax
	    mov sp, 0xFFF0
	    sti
	    jmp 0x07C0:start
print:
	    lodsb
	    or al, al
	    jz done
	    mov ah, 0x0E
	    int 0x10
	    jmp print
done:
	    ret
resetmsg db "Resetting floppy...", 10, 13, 0
loadmsg db "Loading sectors...", 10, 13, 0
jumpmsg db "Jumping to loaded sectors...", 10, 13, 0
start:
	    nop
reset:								   ; Resets floppy
	    mov si, resetmsg
	    call print
	    xor ax, ax
	    xor dx, dx
	    int 13h
	    jc reset
load:
	    mov si, loadmsg
	    call print
	    mov bx, 0x1000
	    mov es, bx
	    xor bx, bx
	    mov al, 10				   ; Load 10 sectors
	    mov ah, 2			   
	    mov cl, 2					 ; Load 10 sectors
	    mov ch, 0				    ; Track 0
	    mov dx, 0x0000		  ; Head 0, Drive 0
	    int 13h
	    jc load
jumpto:
	    mov si, jumpmsg
	    call print
	    jmp 0x1000:0000
times 510 - ($-$$) db 0
; end of sector 1
	    mov ax, cs
	    mov ds, ax
	    cli
	    mov ss, ax
	    mov sp, 0xFFFF0
	    sti
	    jmp sec2start
message db "It works!", 0
sec2start:
	    mov si, message
print2:
	    lodsb
	    or al, al
	    jz done2
	    mov ah, 0x0E
	    int 0x10
	    jmp print2
done2:
	    nop
	    cli
	    hlt
times 512 * 2880 - ($-$$) db 0	  ; Pad out 0's to make floppy disk image.


Here's the output:

Resetting disk...
Loading sectors...
Jumping to loaded sectors...


And then nothing...It just hangs!
So can someone help me with this?


P.S. The last line of code was to make a bootable floppy image! I know its not the best way but it works!
  • 0

#2 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1311 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 23 April 2012 - 04:40 PM

Have you tried replacing the jump code? This:
... 

jmp 0x1000:0000

...
with this?:
... 

jmp 0x100:0000

...

  • 0
Regards,
RR

#3 Guest45316

Guest45316

    CC Newcomer

  • Member
  • PipPip
  • 14 posts

Posted 23 April 2012 - 05:28 PM

Why? Could you explain?
I loaded 0x1000 into ES and 0x0 into BX before calling INT 13h so shouldn't it be loaded at 0x1000:0000 (ES:BX)? I'm kinda confused...
  • 0

#4 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1311 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 23 April 2012 - 05:54 PM

Actually, the loading part of the code looks right, now that I take a closer look at it.


Two things that come to mind are:

1. Are you allowed to use a number, that is greater than 16-bits in size, for a register that can only hold 16-bits of data? As in here?:
... 
mov sp, 0xFFFF0 
...

2. Are the jump instructions relative or absolute? Like here:
... 
jmp sec2start 
...

  • 0
Regards,
RR

#5 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 23 April 2012 - 09:44 PM

A few things:
1) You're not enabling A20.
2) ORG 0x7C00, not 0x0000.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#6 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1311 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 23 April 2012 - 09:47 PM

The ORG 0x7C00 is not mandatory, you can use ORG 0x0000, as long as you have this part (which you seem to have):
... 
jmp 0x07C0:start 
...

I don't see anything wrong with using ORG 0x0000; at least supernovah.com agrees with me (that's where I learned this stuff).
  • 0
Regards,
RR

#7 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 23 April 2012 - 09:52 PM

That might vary by assembler. The BIOS loads the boot sector at address 0x7c00, so it makes more sense to have an ORG 0x7c00 than at 0x0000. Change your load address to 0x0000:0x8000 and put the org directive like I said and see what happens.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#8 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1311 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 23 April 2012 - 09:55 PM

Supernovah.com said that it depends on the BIOS of the specific computer; some computers load the boot sector to 0x07C0:0000, while some load it to 0x0000:0x7C00, so it's important to either have this:
ORG 0x7C00 

jmp 0x0000:start 

start:
, or this:
ORG 0x0000 

jmp 0x07C0:start 

start:
, at the beginning of the boot sector, to ensure that it's one way or the other.
  • 0
Regards,
RR

#9 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 23 April 2012 - 09:56 PM

07c0:0000 and 0000:7c00 are the same address. If you don't believe me look up the way addressing works on the 8086.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#10 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1311 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 23 April 2012 - 10:02 PM

It's the same place in memory, I understand.

It's just it might cause a little incompatibility in some things (such as non-relative-but-not-far jumps, etc.), for some machines. That's why one might want to ensure that it is either one way or the other.
  • 0
Regards,
RR

#11 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 23 April 2012 - 10:08 PM

I've never had that problem. Intel processors should work the same, and the BIOS should be compliant to that end. Near jumps within the same segment should be fine.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#12 Guest45316

Guest45316

    CC Newcomer

  • Member
  • PipPip
  • 14 posts

Posted 24 April 2012 - 03:25 AM

Sorry, the 'mov sp, 0xFFFF0' was a typo. It's not actually like that in my code.

I used 'org 0x0' instead of 'org 0x7c00' so I could include sector 2 without having to change the origin. Nasm only supports one 'org' statement per file! :(

Then I used 'jmp 0x07c0:start'. It's a far jump to start label.

After loading sectors, I jumped to 1000:0000. Then nothing happened...I don't know if this is an issue with the far jump or if the data wasn't there.

A few questions:

dargueta:
I'm a beginner, I've never used the A20 before...what would it do? I think it has something to do with 32-bit protected mode, but wouldn't it reset the interrupts? I don't know, but could you give me me more info? Thanks!

RhetoricalRuvim:
I use a combination of short and far jumps. Mainly short within segments and far to set the CS to the segment I want. What's relative and absolute?

Thanks to all!
  • 0





Also tagged with one or more of these keywords: asm, bootloader, boot, load, sectors, kernel, bootstrap, problem, floppy

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download