NASM Forum > Programming with NASM

2 Stage Bootloader

<< < (3/15) > >>

Frank Kotler:
Okay...

--- Code: ---[BITS 16]
[ORG 0x7c00]

jmp Start


Start:
;set up the stack
xor ax, ax;set ax to zero remember that the when both value are the same in the exclusive or operation the both cancel out to zero
mov ds, ax
mov ss, ax

mov sp, 0x9c00
mov es, ax

;pass in the message into si Register
mov si, MSG
;then call the String print function
call sPrint

xor ax, ax;clear out ax for use
int 0x12;returns amount of ram in ax

call itoa


.Reset:
mov ah, 0 ; reset floppy disk function
mov dl, 0 ; drive 0 is floppy drive
int 0x13 ; call BIOS
jc .Reset ; If Carry Flag (CF) is set, there was an error. Try resetting again
 .Read:
mov ax, 0x1000 ; we are going to read sector to into address 0x1000:0
mov es, ax
xor bx, bx
 
mov ah, 0x02 ; read floppy sector function
mov al, 1 ; read 1 sector
; mov ch, 1 ; we are reading the second sector past us, so its still on track 1
        mov ch, 0 ; sectors start with 1, tracks start with 0!
mov cl, 2 ; sector to read (The second sector)
mov dh, 0 ; head number
mov dl, 0 ; drive number. Remember Drive 0 is floppy drive.
int 0x13 ; call BIOS - Read the sector

 
jmp 0x1000:0x0 ; jump to execute the sector!



cli;clear interrupts
hlt;halt the system






%include "itoa_atoi.asm"
Input db 0
BootDrive dw 0
MSG: db "This is my OS! The number is : ",13,10,0

;vars

bpbOEM db "My OS   "

bpbBytesPerSector:  DW 512
bpbSectorsPerCluster: DB 1
bpbReservedSectors: DW 1
bpbNumberOfFATs:     DB 2
bpbRootEntries:     DW 224
bpbTotalSectors:     DW 2880
bpbMedia:             DB 0xF0
bpbSectorsPerFAT:     DW 9
bpbSectorsPerTrack: DW 18
bpbHeadsPerCylinder: DW 2
bpbHiddenSectors:     DD 0
bpbTotalSectorsBig:     DD 0
bsDriveNumber:         DB 0
bsUnused:             DB 0
bsExtBootSignature: DB 0x29
bsSerialNumber:         DD 0xa0a1a2a3
bsVolumeLabel:         DB "MOS FLOPPY "
bsFileSystem:         DB "FAT12   "


;vars

times 510 - ($-$$) db 0
dw 0xAA55

--- End code ---

I think that's your main problem. Confusing that cylinders and heads start with 0 but sectors start with 1!

Initially, I was getting your message (from stage1) and the number three times(!) so I fiddled with your include file, too (wrongly, the first two times!). You were/are checking for zero (end of string) after the interrupt - I'm not sure al will still be zero after the interrupt, so I put the test first (and then forgot to jump back to ".loop"!). That may or may not have been the problem there. I think the main thing was the wrong cylinder/track number.

What I did, for the record, was:

--- Code: ---nasm -f bin stage1.asm -o stage1.bin
nasm -f bin stage2.asm -o stage2.bin
cat stage1.bin stage2.bin>img.bin
dd if=img.bin of=/dev/fd0

--- End code ---
"copy /b" ought to work the same as "cat". Dunno what you do then to get it to work with VirtualBox instead of a real floppy. I should check out that or some emulator - all that rebootin' gets old quick!

Best,
Frank

Anonymous:
Well What I tried to do was to cat in Linux in virtual box email it to myself then copying the img.bin to my Boot.img and then try and run but still no luck will keep trying though I know I am close

Frank Kotler:
Any help here?

https://forums.virtualbox.org/viewtopic.php?t=1426

Best,
Frank

Frank Kotler:
Here's a crazy thought:


--- Code: ---; nasm -f bin fakeflop.asm -o fakeflop.img

bits 16 ; just for clarity
incbin "stage1.bin"
incbin "stage2.bin"
times (512 * 2880) - ($ - $$) db 0

--- End code ---

Makes a big file - 1474560 - is that right? - that you might be able to persuade VirtualBox is a bootable floppy?

Best,
Frank

Anonymous:
Wow It worked How does that work exactly It looks like a file with just two includes but it works like copy or cat

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version