Page 1 of 2

Writing BootSector & Kernel

Posted: Sat Dec 29, 2007 8:46 am
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... :?

use debug (MS-DOS)

Posted: Sat Dec 29, 2007 9:33 am
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

Re: use debug (MS-DOS)

Posted: Sat Dec 29, 2007 9:44 am
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.

Posted: Sat Dec 29, 2007 11:04 am
by Combuster
build a floppy image and copy it to the floppy when its ready.

Posted: Sat Dec 29, 2007 4:01 pm
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.

Posted: Sat Dec 29, 2007 4:33 pm
by Combuster
In cygwin:

Code: Select all

dd if=floppy.img of=/dev/fd0

reply

Posted: Sat Dec 29, 2007 6:36 pm
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

Posted: Sat Dec 29, 2007 10:22 pm
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.

Posted: Sun Dec 30, 2007 8:02 am
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.

Re: reply

Posted: Sun Dec 30, 2007 4:50 pm
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...

Re: reply

Posted: Sun Dec 30, 2007 5:30 pm
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

Posted: Sun Dec 30, 2007 5:42 pm
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.

reply

Posted: Mon Dec 31, 2007 6:15 am
by matias_beretta
not afaik, because the debug commands are inside debug.com and is not a part of ms-dos

Posted: Mon Dec 31, 2007 6:30 am
by Bobalandi
ah... Damn, alright then, thanks for all the help though. :D

Posted: Mon Dec 31, 2007 10:27 am
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: