Problems writing a boot loader 
Author Message
 Problems writing a boot loader

Hi all

I'm trying to make a floppy boot sector which will load one (later on
more) sectors from the floppy and pass control to them. For this I'm
using as86 and ld86. My source is:

        .text
        .globl  _main
        .org    0

_main:  cli
        mov     ax,#0x6000      ! Set DS and SS
        mov     ds,ax
        mov     ax,#0x7000
        mov     ss,ax
        sti

        mov     al,#0x0d        ! CR
        call    disp
        mov     al,#0x0a        ! LF
        call    disp
        mov     al,#0x4c        ! L
        call    disp
        mov     al,#0x6f        ! o
        call    disp
        mov     al,#0x61        ! a
        call    disp
        mov     al,#0x64        ! d
        call    disp
        mov     al,#0x69        ! i
        call    disp
        mov     al,#0x6e        ! n
        call    disp
        mov     al,#0x67        ! g
        call    disp

        mov     ax,#0x1000      ! ES = destination segment
        mov     es,ax
        mov     ax,#0x0201      ! Function 20h, 1 sector
        mov     cx,#0x0002      ! C/H/S addr 0/0/2
        xor     dx,dx           ! Drive 0h (1st floppy)
        xor     bx,bx           ! Offset 0
        int     0x13            ! Read it
        jc      forget
        jmpi    0,#0x1000       ! Jump to loaded code

error:  cli                     ! Halt if error (no risk =)
        hlt
        jmp     error

disp:   xor     bh,bh
        mov     ah,#14
        int     0x10
        ret

        .org    510
        db      0x55            ! boot sector signature 55AA
        db      0xAA
        .org    512

        mov     ah,#0x0d        ! floppy sector #2
        call    disp2           ! Displays CR LF 'Done.'
        mov     ah,#0x0a
        call    disp2
        mov     ah,#0x44
        call    disp2
        mov     ah,#0x6f
        call    disp2
        mov     ah,#0x6e
        call    disp2
        mov     ah,#0x65
        call    disp2
        mov     ah,#0x2E
        call    disp2

halt:   cli                     ! and halts, like above
        hlt
        jmp     halt

disp2:  mov     ah,#14
        xor     bh,bh
        int     0x10
        ret

To assemble it use these commands, basically the same as LILO's Makefile
uses:

as86 -0 -a -w -o test.o test.S
ld86 -0 -s -o test.img test.o
dd if=test.img of=test.b bs=32 skip=1

Then copy test.b to the beginning of a floppy:

dd if=test.b of=/dev/fd0

Now boot.... 'Loading' is correctly printed, but then followed by a few
smilies and the system halts. If I put mov cx,#0x0001 (sector 1 instead
of 2) it gets stuck in an endless 'Loading' loop as expected (if sectors
are really counted from 1).

Can anyone tell me what I'm doing wrong?? Thanks in advance.

Thomas

--
Thomas Rast             "If you cannot convince them,

ICQ# 103670088               -- Harry S. Truman



Mon, 26 Apr 2004 08:29:03 GMT  
 Problems writing a boot loader
You program is 99% correct except that in the second half, you mis-typed
"al" as "ah" before you call your "disp".  ^_^ By now you should know why
you see the smiles when booting up. Because your "al" is uninitilized at all
when you output it on the screen...

Hope I explain myself clearly and sorry for my poor English...
xiyuan


Quote:
> Hi all

> I'm trying to make a floppy boot sector which will load one (later on
> more) sectors from the floppy and pass control to them. For this I'm
> using as86 and ld86. My source is:

>         .text
>         .globl  _main
>         .org    0

> _main:  cli
>         mov     ax,#0x6000 ! Set DS and SS
>         mov     ds,ax
>         mov     ax,#0x7000
>         mov     ss,ax
>         sti

>         mov     al,#0x0d ! CR
>         call    disp
>         mov     al,#0x0a ! LF
>         call    disp
>         mov     al,#0x4c ! L
>         call    disp
>         mov     al,#0x6f ! o
>         call    disp
>         mov     al,#0x61 ! a
>         call    disp
>         mov     al,#0x64 ! d
>         call    disp
>         mov     al,#0x69 ! i
>         call    disp
>         mov     al,#0x6e ! n
>         call    disp
>         mov     al,#0x67 ! g
>         call    disp

> mov     ax,#0x1000 ! ES = destination segment
>         mov     es,ax
>         mov     ax,#0x0201 ! Function 20h, 1 sector
>         mov     cx,#0x0002 ! C/H/S addr 0/0/2
>         xor     dx,dx ! Drive 0h (1st floppy)
>         xor     bx,bx ! Offset 0
>         int     0x13 ! Read it
>         jc      forget
>         jmpi    0,#0x1000 ! Jump to loaded code

> error: cli ! Halt if error (no risk =)
>         hlt
>         jmp error

> disp:   xor     bh,bh
>         mov     ah,#14
>         int     0x10
>         ret

>         .org    510
>         db      0x55 ! boot sector signature 55AA
>         db      0xAA
>         .org    512

> mov     ah,#0x0d ! floppy sector #2
>         call    disp2 ! Displays CR LF 'Done.'
>         mov     ah,#0x0a
>         call    disp2
>         mov     ah,#0x44
>         call    disp2
>         mov     ah,#0x6f
>         call    disp2
>         mov     ah,#0x6e
>         call    disp2
>         mov     ah,#0x65
>         call    disp2
>         mov     ah,#0x2E
>         call    disp2

> halt:   cli ! and halts, like above
>         hlt
>         jmp     halt

> disp2:  mov     ah,#14
>         xor     bh,bh
>         int     0x10
>         ret

> To assemble it use these commands, basically the same as LILO's Makefile
> uses:

> as86 -0 -a -w -o test.o test.S
> ld86 -0 -s -o test.img test.o
> dd if=test.img of=test.b bs=32 skip=1

> Then copy test.b to the beginning of a floppy:

> dd if=test.b of=/dev/fd0

> Now boot.... 'Loading' is correctly printed, but then followed by a few
> smilies and the system halts. If I put mov cx,#0x0001 (sector 1 instead
> of 2) it gets stuck in an endless 'Loading' loop as expected (if sectors
> are really counted from 1).

> Can anyone tell me what I'm doing wrong?? Thanks in advance.

> Thomas

> --
> Thomas Rast             "If you cannot convince them,

> ICQ# 103670088               -- Harry S. Truman



Mon, 26 Apr 2004 10:09:50 GMT  
 Problems writing a boot loader
You program is 99% correct except that in the second half, you mis-typed
"al" as "ah" before you call your "disp".  ^_^ By now you should know why
you see the smiles when booting up. Because your "al" is uninitialized at
all
when you output it on the screen...

Hope I explain myself clearly and sorry for my poor English...
xiyuan

PS: I have some problems posting so forgive me if you see duplicates.


Quote:
> Hi all

> I'm trying to make a floppy boot sector which will load one (later on
> more) sectors from the floppy and pass control to them. For this I'm
> using as86 and ld86. My source is:

>         .text
>         .globl  _main
>         .org    0

> _main:  cli
>         mov     ax,#0x6000 ! Set DS and SS
>         mov     ds,ax
>         mov     ax,#0x7000
>         mov     ss,ax
>         sti

>         mov     al,#0x0d ! CR
>         call    disp
>         mov     al,#0x0a ! LF
>         call    disp
>         mov     al,#0x4c ! L
>         call    disp
>         mov     al,#0x6f ! o
>         call    disp
>         mov     al,#0x61 ! a
>         call    disp
>         mov     al,#0x64 ! d
>         call    disp
>         mov     al,#0x69 ! i
>         call    disp
>         mov     al,#0x6e ! n
>         call    disp
>         mov     al,#0x67 ! g
>         call    disp

> mov     ax,#0x1000 ! ES = destination segment
>         mov     es,ax
>         mov     ax,#0x0201 ! Function 20h, 1 sector
>         mov     cx,#0x0002 ! C/H/S addr 0/0/2
>         xor     dx,dx ! Drive 0h (1st floppy)
>         xor     bx,bx ! Offset 0
>         int     0x13 ! Read it
>         jc      forget
>         jmpi    0,#0x1000 ! Jump to loaded code

> error: cli ! Halt if error (no risk =)
>         hlt
>         jmp error

> disp:   xor     bh,bh
>         mov     ah,#14
>         int     0x10
>         ret

>         .org    510
>         db      0x55 ! boot sector signature 55AA
>         db      0xAA
>         .org    512

> mov     ah,#0x0d ! floppy sector #2
>         call    disp2 ! Displays CR LF 'Done.'
>         mov     ah,#0x0a
>         call    disp2
>         mov     ah,#0x44
>         call    disp2
>         mov     ah,#0x6f
>         call    disp2
>         mov     ah,#0x6e
>         call    disp2
>         mov     ah,#0x65
>         call    disp2
>         mov     ah,#0x2E
>         call    disp2

> halt:   cli ! and halts, like above
>         hlt
>         jmp     halt

> disp2:  mov     ah,#14
>         xor     bh,bh
>         int     0x10
>         ret

> To assemble it use these commands, basically the same as LILO's Makefile
> uses:

> as86 -0 -a -w -o test.o test.S
> ld86 -0 -s -o test.img test.o
> dd if=test.img of=test.b bs=32 skip=1

> Then copy test.b to the beginning of a floppy:

> dd if=test.b of=/dev/fd0

> Now boot.... 'Loading' is correctly printed, but then followed by a few
> smilies and the system halts. If I put mov cx,#0x0001 (sector 1 instead
> of 2) it gets stuck in an endless 'Loading' loop as expected (if sectors
> are really counted from 1).

> Can anyone tell me what I'm doing wrong?? Thanks in advance.

> Thomas

> --
> Thomas Rast             "If you cannot convince them,

> ICQ# 103670088               -- Harry S. Truman



Mon, 26 Apr 2004 10:55:58 GMT  
 Problems writing a boot loader
Hello {*filter*}folk!

On Thu, 8 Nov 2001 00:29:03 +0000 (UTC), Thomas Rast spake thus:

Quote:
>    mov     ax,#0x1000      ! ES = destination segment
>        mov     es,ax
>        mov     ax,#0x0201  ! Function 20h, 1 sector
>        mov     cx,#0x0002  ! C/H/S addr 0/0/2
>        xor     dx,dx               ! Drive 0h (1st floppy)
>        xor     bx,bx               ! Offset 0
>        int     0x13                ! Read it
>        jc      forget

what is this     ^^^^^^ ? you don't have a label called 'forget' to
jump to (although this isn't the problem, it could be if you have an
error reading the floppy on any system).

Quote:
>        jmpi    0,#0x1000   ! Jump to loaded code

<snip>

Quote:
>    mov     ah,#0x0d        ! floppy sector #2

                ^^

This and the next 6 mov instructions are wrong. You should be putting
the value to write in AL, you are putting it in AH.

You jumped to this code immediately after the int 13h, ah=2 call, so
al contains the number of sectors read, which is 1. That means that
you are printing the value the display adapter has in it for the value
'1' 7 times.

Changing the register (7 times) will fix your problem :)

debs

If you can't be kind, at least have the decency to be vague.



Mon, 26 Apr 2004 10:55:58 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Seeking advice : Feasiblity of writing boot loader in 1 semester

2. CDROM MULTI OS BOOT LOADER

3. Boot loader

4. My boot strap loader won't load a sec and run it

5. boot loader, need segment info

6. boot from floppy but run the bootstrap loader on the hard drive

7. About Old Boot Loaders???

8. Mini op system was boot loader

9. boot strap loaders wanted

10. Boot loader

11. PC boot loader

12. OS Boot Loader in NASM

 

 
Powered by phpBB® Forum Software