From: Frank K. <fbk...@zy...> - 2009-06-27 08:17:46
|
Zulfi Khan wrote: > Hi Frank, > I excuted writeit.com and it stored BOOT.BIN in drive 'a'. I got following mesg when i tried to see the directory of drive 'a' .All its files got removed after execution. > D:\NASMPR~1>dir a: > The volume does not contain a recognized file system. > Please make sure that all required file system drivers are loaded and that the v > olume is not corrupted. Well, it *is* corrupted! We just wrote a bootsector to it that doesn't have a Bios Parameter Block (BPB). This is the cruft at the beginning of the example I sent you: jmp short overdata nop Strictly speaking, a bootsector is "supposed" to start with either a near jump, or short jump / nop (three bytes). I have heard of one case (a laptop, I think) where a bios refused to boot without it. Most biosen ignore it - some don't even check the 55h/0AAh signature. If you want to "boot anywhere", you should really have it. If you just want to boot on your own machine, "whatever works". After these three bytes, the BPB starts with the vendor ID - exactly 8 bytes, space-padded. After that, some info that the File System depends on. db 'MyOS ' ; OEM id dw 200h ; bytes/sector db 1 ; sectors per cluster dw 1 ; sectors before FAT db 2 ; number of FATs dw 0E0h ; max rootdir entries dw 0B40h ; total sectors db 0Fh ; media descriptor dw 9 ; sectors per FAT dw 12h ; sectors per track dw 2 ; number heads times 0Ah db 0 db 29h db 0EFh db 7 db 10h db 24h db 'LINUX BOOT FAT12 ' ; guess where I ; cribbed this from ;---------------------------- overdata: ... I've got a better example - written by Deb Wiles - that I'll probably send you sooner or later. The above was... as I recall... read off a working floppy and beaten into Nasm syntax. I don't even know what some of the numbers mean, it "just works". Maybe can get by with less than that - gotta have "media descriptor", at least... If you had files on that floppy, you can do an experiment: assemble that example "nasm -f bin -o boot.bin boot02.asm" and "writeit". It *may* restore your files... if we haven't scribbled on the FAT (File Allocation Table - two of 'em) or the root directory. No harm tryin'. (the bootsector won't show up with "dir a:" in any case) But never mind that. Did you see the white-on-blue 'A'??? A fully working File System is a few steps down the line yet.. > However, I could not understand the two examples. Do I have to compile them and store them on drive 'a'? The "translation" of the as86 example and the "boot02.asm" example, yes. The "writeit.asm" wants to be assembled to a .com file and used to do the writing... I guess you figured that out. > I am also attaching part 2 and part 3. Excellent! Thank you! I've taken just a quick look at 'em. Looks like in part II, we introduce both bios interrupts, and loading a second sector. My "writeit" isn't going to work for that. I don't think his C code is going to open "/dev/fd0" in dos/doze (he's as sloppy as I am with not checking for errors!!!) We can figure something out, if you get that far. In part III, different authors, and we switch to Nasm (Yay! Although I don't see the code...), and get into protected mode. IMHO, it's a mistake to get into pmode too early - you haven't got interrupts any more! They mention doing "cli" to disable interrupts, but gloss over the fact that you've gotta write and install some before you can "sti" to turn 'em back on! Good enough to write something to the screen, I guess. Mike Gonta has proven me wrong on this. I thought he got into pmode "too early", in his AEBios, but he goes on to load something else (the only sensible thing for a bootsector to do is load something else) by using just the ports. Interesting approach! http://aebios.com/ (for Fasm, not Nasm, but they're close) Here's something completely different - prints the value of the registers on bootup. The point being that they're *not* the same from one machine to another! (dl should always be boot drive) It isn't a "typical" bootsector, in that it starts with a "call" instead of the canonical "jmp short". I don't know if there's any point to it, but it'll give you something to play with. Have fun! (if you switched to Linux, it would solve the linking problem on that other file. :) there's one "problem" with Linux, I've found: I really don't like to reboot! So this is not recently tested...) Best, Frank ;------------------------------------ ; nasm -f bin -o boot.bin boot07.asm ; ; dd count=1 if=boot.bin of=/dev/fd0 ; or ; debug boot.bin ; w 100 0 0 1 ; q ; or "writeit" :) ;------------------------------------- org 7C00h section .text section .text call overdata ; Call? WTF? Don't worry, we pop the ; return address off to get initial IP. ; Note that "call" is longer than ; nop ; "jmp short", so we don't want the nop db 'MyOS ' ; OEM id - space-padded to 8 bytes dw 200h ; bytes/sector db 1 ; sectors per cluster dw 1 ; sectors before FAT db 2 ; number of FATs dw 0E0h ; max rootdir entries dw 0B40h ; total sectors db 0Fh ; media descriptor dw 9 ; sectors per FAT dw 12h ; sectors per track dw 2 ; number heads times 0Ah db 0 db 29h db 0EFh db 7 db 10h db 24h db 'LINUX BOOT FAT12 ' ; guess where I ; cribbed this from ;---------------------------- overdata: push sp ; note that we're doing all these push ss ; pushes to a "wild" stack. Not push es ; good. (0000:03FA on my system - yipes!) push ds ; In a real boot-sector, I'd set up a push cs ; sane stack - very first thing! push bp push si push di push dx push cx push bx push ax mov ax, 0B800h ; screen memory - we assume not mono mov es, ax ; also not good. xor di, di mov ds, di mov cx, 80 * 25 * 2 rep stosb ; clear screen (al is zero from above) mov di, 80 * 5 * 2 mov cx, 13 ; hmmm - could just do cl - a byte! mov si, regnames nextreg: push cx ; save reg-loop counter mov cx, 5 ; char counter for names mov ah, 3 ; color nextchar: lodsb stosw loop nextchar pop cx ; reg-loop counter pop dx ; value of reg mov bx, 4 ; nibble loop counter nextnibble: rol dx, 4 ; rotate a nibble into position mov al, dl ; make a copy to process mov ah, 03h ; color and al, 0Fh ; isolate nibble cmp al, 10 ; short way to convert a nibble sbb al, 69h ; to hex ascii das stosw ; write char and attribute to screen dec bx ; loop counter for nibbles jnz nextnibble add di, 80 * 2 - 18 ; next line loop nextreg blackhole: jmp blackhole regnames: db 'ax = ' db 'bx = ' db 'cx = ' db 'dx = ' db 'di = ' db 'si = ' db 'bp = ' db 'cs = ' db 'ds = ' db 'es = ' db 'ss = ' db 'sp = ' db 'ip = ' times 510-($-$$) db 90h ; don't think it matters, but we'll use NOP db 55h, 0AAh ; boot sector signature ;------------------------- |