Writing BootSector & Kernel

Programming, for all ages and all languages.
Bobalandi
Member
Member
Posts: 107
Joined: Mon Dec 03, 2007 7:26 am
Location: Near Boston, MA
Contact:

Writing BootSector & Kernel

Post by Bobalandi »

I have made a very basic bootloader that loads my very basic kernel, but I am having a lot of trouble writing it the floppy, I have tried with copyboot, but that hasn't worked. Any suggestions?

EDIT: I got the bootloader to work using copyboot, but now when I try to write the kernel to the floppy, the disk needs to be formatted, which gets me back to the start... :?
NULL
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

use debug (MS-DOS)

Post by matias_beretta »

> format a:
> debug kernel.bin ;FIRST KERNEL
w 100 0 1 1
> debug boot.bin ;SECOND BOOT
w 100 0 0 1
Matías Beretta
Bobalandi
Member
Member
Posts: 107
Joined: Mon Dec 03, 2007 7:26 am
Location: Near Boston, MA
Contact:

Re: use debug (MS-DOS)

Post by Bobalandi »

matias_beretta wrote:> format a:
> debug kernel.bin ;FIRST KERNEL
w 100 0 1 1
> debug boot.bin ;SECOND BOOT
w 100 0 0 1
Hmm... Debug isn't working properly. After I enter w 100 0 1 1, it just keeps asking for more input.
NULL
User avatar
Combuster
Member
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:

Post by Combuster »

build a floppy image and copy it to the floppy when its ready.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Bobalandi
Member
Member
Posts: 107
Joined: Mon Dec 03, 2007 7:26 am
Location: Near Boston, MA
Contact:

Post by Bobalandi »

Combuster wrote:build a floppy image and copy it to the floppy when its ready.
Well, I have the image, and I am using vfd, but either way, I can't copy it to the correct location.
NULL
User avatar
Combuster
Member
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:

Post by Combuster »

In cygwin:

Code: Select all

dd if=floppy.img of=/dev/fd0
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

reply

Post by matias_beretta »

i'm sorry i forgot 'q'

> format a:
> debug kernel.bin ;FIRST KERNEL
w 100 0 1 1
q
> debug boot.bin ;SECOND BOOT
w 100 0 0 1
q
Matías Beretta
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

It depends on how your loader loads stuff off the disk, but if your geting the format error you need to include something like this in your boot sector

Code: Select all

use16
org 0x7C00

boot:	  jmp	  near start
	  nop

;------------------------------------------;
;  Standard BIOS Parameter Block, "BPB".   ;
;------------------------------------------;
	  bpbOEM	  db  'MY    OS'
	  bpbSectSize	  dw  512
	  bpbClustSize	  db  1
	  bpbReservedSec  dw  1
	  bpbFats	  db  2
	  bpbRootSize	  dw  224
	  bpbTotalSect	  dw  2880
	  bpbMedia	  db  240
	  bpbFatSize	  dw  9
	  bpbTrackSect	  dw  18
	  bpbHeads	  dw  2
	  bpbHiddenSect   dd  0
	  bpbLargeSect	  dd  0
     ;---------------------------------;
     ;  extended BPB for FAT12/FAT16   ;
     ;---------------------------------;
	  bpbDriveNo	  db  0
	  bpbReserved	  db  0
	  bpbSignature	  db  41		      ; 0 = nothing more. 41 = three more (below)..
	  bpbID 	  dd  1
	  bpbVolumeLabel  db  'BOOT FLOPPY'
	  bpbFileSystem   db  'FAT12   '


;----------------------------------------;
;   starting point of bootsector code    ;
;----------------------------------------;
start:
Also try "partcopy" you will find it on the net.
Bobalandi
Member
Member
Posts: 107
Joined: Mon Dec 03, 2007 7:26 am
Location: Near Boston, MA
Contact:

Post by Bobalandi »

Well, this is what I have.

Code: Select all

KERNEL_START equ 1		; Disk block where kernel starts
KERNEL_SIZE equ 1		; Kernel size in disk blocks
KERNEL_SEGMENT equ 1000h	; Segment where kernel will be loaded

; Load kernel
mov ax, 200h + KERNEL_SIZE
push word KERNEL_SEGMENT
pop es
xor bx, bx
mov cx, KERNEL_START + 1
mov dx, 0
int 13h
jnc ok
jmp $
ok:

; Jump to kernel
jmp KERNEL_SEGMENT:0

; Boot signature
times 510 - ($ - $$) db 0
db 55h
db 0aah
But where would I add the code that you gave? All this bootloader does is load my kernel.
NULL
Bobalandi
Member
Member
Posts: 107
Joined: Mon Dec 03, 2007 7:26 am
Location: Near Boston, MA
Contact:

Re: reply

Post by Bobalandi »

matias_beretta wrote:i'm sorry i forgot 'q'

> format a:
> debug kernel.bin ;FIRST KERNEL
w 100 0 1 1
q
> debug boot.bin ;SECOND BOOT
w 100 0 0 1
q
Ahh, yes, after fumbling around with it I figured that out and it works, great, now, I have to figure out how to make a batch file that can do that...
NULL
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: reply

Post by Brendan »

Hi,
Bobalandi wrote:Ahh, yes, after fumbling around with it I figured that out and it works, great, now, I have to figure out how to make a batch file that can do that...
Sounds like you need something like RawWrite (Microsoft OSs can't do it without additional utilities)...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Bobalandi
Member
Member
Posts: 107
Joined: Mon Dec 03, 2007 7:26 am
Location: Near Boston, MA
Contact:

Post by Bobalandi »

Well, I have rawwrite, but I mean if I can do it with Debug, there should be a way to put it in a batch file.
NULL
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

reply

Post by matias_beretta »

not afaik, because the debug commands are inside debug.com and is not a part of ms-dos
Matías Beretta
Bobalandi
Member
Member
Posts: 107
Joined: Mon Dec 03, 2007 7:26 am
Location: Near Boston, MA
Contact:

Post by Bobalandi »

ah... Damn, alright then, thanks for all the help though. :D
NULL
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

You could try this:

Code: Select all

KERNEL_START equ 1		; Disk block where kernel starts
KERNEL_SIZE equ 1		; Kernel size in disk blocks
KERNEL_SEGMENT equ 1000h	; Segment where kernel will be loaded
use16
org 0x7C00

boot:	  jmp	  near start
	  nop

;------------------------------------------;
;  Standard BIOS Parameter Block, "BPB".   ;
;------------------------------------------;
	  bpbOEM	  db  'MY    OS'
	  bpbSectSize	  dw  512
	  bpbClustSize	  db  1
	  bpbReservedSec  dw  1
	  bpbFats	  db  2
	  bpbRootSize	  dw  224
	  bpbTotalSect	  dw  2880
	  bpbMedia	  db  240
	  bpbFatSize	  dw  9
	  bpbTrackSect	  dw  18
	  bpbHeads	  dw  2
	  bpbHiddenSect   dd  0
	  bpbLargeSect	  dd  0
     ;---------------------------------;
     ;  extended BPB for FAT12/FAT16   ;
     ;---------------------------------;
	  bpbDriveNo	  db  0
	  bpbReserved	  db  0
	  bpbSignature	  db  41		      ; 0 = nothing more. 41 = three more (below)..
	  bpbID 	  dd  1
	  bpbVolumeLabel  db  'BOOT FLOPPY'
	  bpbFileSystem   db  'FAT12   '


;----------------------------------------;
;   starting point of bootsector code    ;
;----------------------------------------;
start:
; Load kernel
mov ax, 200h + KERNEL_SIZE
push word KERNEL_SEGMENT
pop es
xor bx, bx
mov cx, KERNEL_START + 1
mov dx, 0
int 13h
jnc ok
jmp $
ok:

; Jump to kernel
jmp KERNEL_SEGMENT:0

; Boot signature
times 510 - ($ - $$) db 0
db 55h
db 0aah
;PUT YOUR SECOND STAGE HERE *********************************
Assemble the lot as a bin file and use rawrite like this
c:\rawrite test.bin a:
Post Reply