OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 5:52 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 5:13 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 19, 2009 1:48 pm
Posts: 201
Location: Brazil
Hello,
I'm learning Assembly and i'm trying to develop my own boot loader for my OS that is only a test to build something big, but my boot loader that i'm developing isn't booting, i know the boot loader that don't boot is very funny, but it's not a joke. Let's go to the problem, i insert the floppy of my boot loader(Beginning of an OS, because my OS only shows a message and then reboot the computer, because it's only a test to start the develop of my own OS) and select the floppy as primary boot drive, then when is at the time of the boot, the computer searches in the floppy, because i see the light of the floppy drive on, then like it don't have any OS there it goes and boot in the hard drive and initialize Windows(In my laptop, Ubuntu), but it haves an OS there in the floppy(i suppose that is), but here is my code for Nasm:
Code:
[BITS 16]    ; 16 bit code generation
[ORG 0x7C00]    ; ORGin location is 7C00

;Main program
main:       ; Main program label

mov ah,0x0E    ; This number is the number of the function in the BIOS to run.
       ;  This function is put character on screen function
mov bh,0x00    ; Page number (I'm not 100% sure of this myself but it is best
       ;  to leave it as zero for most of the work we will be doing)
mov bl,0x07    ; Text attribute (Controls the background and foreground colour
       ;  and possibly some other options)
       ;  07 = White text, black background.
       ; (Feel free to play with this value as it shouldn't harm
       ;  anything)
mov al,65    ; This should (in theory) put a ASCII value into al to be
       ;  displayed. (This is not the normal way to do this)
int 0x10    ; Call the BIOS video interrupt.

jmp $       ; Put it into a coninuous loop to stop it running off into
       ;  the memory running any junk it may find there.

; End matter
times 510-($-$$) db 0   ; Fill the rest of the sector with zeros
dw 0xAA55      ; Boot signature

Here is my code developed in emu8086(That is the default):
Code:
; directive to create BOOT file:
#make_boot#

; Boot record is loaded at 0000:7C00,
; so inform compiler to make required
; corrections:
ORG 7C00h

PUSH    CS   ; make sure DS=CS
POP     DS

; load message address into SI register:
LEA SI, msg

; teletype function id:
MOV AH, 0Eh

print:   MOV AL, [SI]
         CMP AL, 0
         JZ done
         INT 10h   ; print using teletype.
         INC SI
         JMP print

; wait for 'any key':
done:      MOV AH, 0
           INT 16h


; store magic value at 0040h:0072h:
;   0000h - cold boot.
;   1234h - warm boot.
MOV     AX, 0040h
MOV     DS, AX
MOV     w.[0072h], 0000h ; cold boot.

JMP   0FFFFh:0000h    ; reboot!

new_line EQU 13, 10     

msg DB  'Hello This is My First Boot Program!'
    DB  new_line, 'Press any key to reboot', 0                                                                                               

DW 0xAA55      ; Add the boot loader signature to the end

And here is the process to that i use to write in the floppy:
Code:
> DEBUG os-test.asm
-w 100 0 0 1
-q

What i'm doing wrong?

Thanks,
Nathan Paulino Campos

_________________
About.Me - Blog


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 5:23 pm 
Offline
Member
Member
User avatar

Joined: Mon Jul 06, 2009 12:55 am
Posts: 51
Location: Kamloops, BC, Canada
You probably have to set the floppy to the main boot device in your BIOS.

The floppy LED will turn on at boot every time regardless of if it's the the main boot device or not.

_________________
Vancouver Canucks fan for life


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 5:38 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 19, 2009 1:48 pm
Posts: 201
Location: Brazil
Hello Thor,
In my laptop i have to press ESC when the computer starts to enter at a boot menu to select from what device i want to boot, i select the floppy(that is in USB) and the led turns on, but in some seconds it go and boot the Hard Drive(Ubuntu), then my OS don't work, then this isn't the problem.

Try to compile my project and see by own.

Thanks,
Nathan Paulino Campos

Thor wrote:
You probably have to set the floppy to the main boot device in your BIOS.

The floppy LED will turn on at boot every time regardless of if it's the the main boot device or not.

_________________
About.Me - Blog


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 5:48 pm 
Offline
Member
Member
User avatar

Joined: Mon Jul 06, 2009 12:55 am
Posts: 51
Location: Kamloops, BC, Canada
Oh *facepalm* can't believe I didn't see that.

Code:
JMP   0FFFFh:0000h    ; reboot!

new_line EQU 13, 10     

msg DB  'Hello This is My First Boot Program!'
    DB  new_line, 'Press any key to reboot', 0                                                                                               

DW 0xAA55      ; Add the boot loader signature to the end


You need a 'times 510-($-$$) db 0' before the dw 0xAA55. The BIOS expects the bootsignature to be in bytes 510 and 511 of the bootloader, and if it doesn't find them, it assumes the drive isn't bootable.

Should work with that :)

_________________
Vancouver Canucks fan for life


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 5:58 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 19, 2009 1:48 pm
Posts: 201
Location: Brazil
Hello Thor,
I try to put that code in the emu8086 code, but when i try to compile the project i got this error:
Code:
(44) illegal instruction: TIMES 510-($-$$) DB 0 or wrong parameters.

Here is an screenshot:
Image
Remember that emu8086 use Fasm as compiler.
And i posted the two code in my question.

Thanks,
Nathan Paulino Campos

_________________
About.Me - Blog


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 6:08 pm 
Offline
Member
Member
User avatar

Joined: Thu Feb 14, 2008 10:46 am
Posts: 277
Location: Italy
If you look in the sample folder you will find a bootloader and a simple kernel to try ^_^


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 6:36 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
For crying out loud, don't use Emu8086.

I'd use NASM + Bochs if I were you (that's the closest thing in terms of user experience, just that... it's closer to a toolchain rather than Lego).

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 7:28 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
Emu8086 is teh fail.

You pay a lot for a broken simulator(that doesn't even support a fully stand alone environment) and a debugger than can disassemble and a very standard-breaking assembler. Wow

_________________
My new NEW blag


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 7:32 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
Not to mention that it only emulates an 8086. You *can* do better from that right from the start, trust us :P

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 7:49 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 19, 2009 1:48 pm
Posts: 201
Location: Brazil
Ok, now i'm using Nasm and here is my code:
Code:
[BITS 16]    ; 16 bit code generation
[ORG 0x7C00]    ; ORGin location is 7C00

main:
MOV AH, 0Eh
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BP, msg1
MOV AH, 13h
INT 10h
JMP msg1                                   

msg1 DB "Hello, World!"

; Boot things
times 510-($-$$) db 0   ; Fill the rest of the sector with zeros
dw 0xAA55      ; Boot signature

But when i boot up it with Bochs it only shows me nothing.
I compiled and write at the floppy correct.
Thanks!

_________________
About.Me - Blog


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 7:55 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
First of all, Bochs images need to be the right size; if you're emulating a 1.44 floppy disk, the file must be exactly 1474560 bytes long (pad with 0's). Also, you want "JMP $" (i.e., infinite loop or hanging) instead of "JMP msg1" (i.e., random code).

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 8:02 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 19, 2009 1:48 pm
Posts: 201
Location: Brazil
Ok, i changed the JMP, but i tested it with the first code of my question and it works perfectly.
Thanks!

_________________
About.Me - Blog


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 8:47 pm 
Offline
Member
Member

Joined: Sat Sep 08, 2007 11:26 pm
Posts: 143
Location: Canada
A quick example - doesn't enable A20 (see the forum)

Code:
; I was bored, echo said to do something hardware related...

; Jump to PMODE
[BITS 16]
[ORG 0x7C00]

   cli                       ; Disable interrupts; Cleanup registers
   xor     ax, ax            ; zero AX
   mov     ds, ax            ; DS is used by lgdt

   lgdt    [gdt_desc]        ; Load the GDT
   mov     eax, cr0          ; Load the value of cr0 (control register) into eax (general purpose register)
   or      eax, 1            ; OR (|) the value of eax with 1
   mov     cr0, eax          ; Load the value of eax into cr0
   jmp     0x8:main          ; Far jump (dirty value in cs)

[BITS 32]

   main:
   mov ax,  10h              ; Store data segment (10h)
   mov ds,  ax               ; Store valid segment in ds
   mov ss,  ax               ; Store valid segment it ss
   mov esp, 0x90000          ; Shove the stack at 0x90000

;; Make your program

   jmp $
; GDT Must have 3 entries
;...Null...
   gdt_null:    dd 0         
                dd 0
;...Code segment...
   gdt_code:    dw 0x0FFFF   ; limit low
                dw 0         ; base low
                db 0         ; base mid
                db 10011010b ; access
                db 11001111b ; granularity
                db 0         ; base high
;...Data segment...
   gdt_data:    dw 0x0FFFF   ; limit low
                dw 0         ; base low
                db 0         ; base mid
                db 10010010b ; access
                db 11001111b ; granularity
                db 0         ; base high
   gdt_end:
   
;...GDT Descripor
   gdt_desc:    dw gdt_end - gdt_null - 1; limit
                dd gdt_null              ; base
       
times 510-($-$$) db 0         ; Pad the file to 512 bytes
db 0x55                       ; Boot signature
db 0xAA


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 22, 2009 8:57 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 19, 2009 1:48 pm
Posts: 201
Location: Brazil
Thanks, but you can help me with this: http://forum.osdev.org/viewtopic.php?f=1&t=20776.
I will be very happy if you can, because my OS is in the beginning of the beginning.

_________________
About.Me - Blog


Top
 Profile  
 
 Post subject: Re: Boot Loader Don't Boot
PostPosted: Sat Aug 29, 2009 1:30 pm 
Offline
Member
Member
User avatar

Joined: Mon Mar 23, 2009 3:15 am
Posts: 124
Location: Germany
Quote:
OS development will not make you rich nor famous.
I could not quite agree with that. Think of famous people like Bill Gates et al. (MS DOS, MS Windows), Linus Torvalds (Linux), Andrew Tanenbaum (Minix <== famous).

_________________
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 192 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group