|
From: Frank K. <fbk...@zy...> - 2009-06-25 14:28:40
|
Zulfi Khan wrote:
> Hi Frank,
> I have now downloaded nasm and the linker Link53.exe. I have to do something as described in the attached article. Let me know if its fine.
Okay. I don't think you'll need the linker at this stage. Won't hurt.
The fact that you got an .exe suggests that you're not running Linux, as
the article assumes. You can do it anyway - you may need a different
method to write your bootsector to floppy. That can be arranged.
[snip]
> 3.1 The Boot Sector
>
> Grab your favourite editor and type in these few lines.
>
> ||
>
> entry start
> start:
> mov ax,#0xb800
> mov es,ax
> seg es
> mov [0],#0x41
> seg es
> mov [1],#0x1f
> loop1: jmp loop1
>
> This is an assembly language that as86 will understand.
Nasm will require a slight change in syntax:
;------------------
mov ax, 0xb800
mov es, ax
mov byte [es:0], 0x41
mov byte [es:1], 0x1f
loop1: jmp loop1
times 510 - ($ - $$) db 0
db 0x55, 0xAA
;------------
The last two lines do not appear in Mr. Krishnakumar's code. He adds the
"boot signature" in his C loader code. These lines pad the file out to
512 bytes, and put the two-byte signature in its proper spot (if I got
it right... been a while since I did this...) This way you won't need a
"special" loader.
Save this as "boot0.asm", and assemble with "nasm -f bin -o boot.bin
boot1.asm" (or pick your own names). Hopefully, that will result in
"boot.bin", 512 bytes long.
Now you need to write this to the first sector of a floppy. You could
use Mr. Krishnakumar's code... but if you're running Linux, you could
just do "dd if=boot.bin of=/dev/fd0"... and if you're not running Linux,
his code won't work either...
If you're running some version of Windows that includes dos, you could
use John Fine's "partcopy" (pcopy02.zip):
http://files.osdev.org/mirrors/geezer/johnfine/
Or rawwrite:
http://www.filewatcher.com/m/rawwrite.exe.378368.0.0.html
Or "debug boot.bin"/"w 100 0 0 1"/"q"
Or...
;--------------------------
; nasm -f bin -o writeit.com writeit.asm
[BITS 16]
[ORG 0x100]
mov ax,3D00h
mov dx,filename
int 21h
; check for errors here!
mov bx,ax
mov ah,3Fh
mov dx,buffer
mov cx,512
int 21h
; check for errors here!
mov ah,3Eh
int 21h
push ds
pop es
mov bx, buffer
mov dl, 00h
mov dh, 0
mov cl, 1
mov ch, 0
mov ah, 03h
mov al, 1
int 13h
; check for errors here!
mov ax, 4C00h
int 21h
filename db 'BOOT.BIN',0
buffer times 512 db 0
;---------------------------
As you can see, this is extremely rudimentary - reads "boot.bin" (no
options) and writes it to drive A: (no options). If all doesn't go well,
it just plain fails (this could all be easily fixed... but I'm pretty
lazy). It is a simple way to do it.
[snip]
> From here, we'll want to insert more code into our boot sector program,
> to make it do more complex things (like using BIOS interrupts,
> protected-mode switching, etc). The later parts (PART II, PART III etc.
> ) of this article will guide you on further improvements. Till then GOOD
> BYE !
As I recall, I never found "PART II, etc.". Have you? If not, and if you
need some more examples, I might be able to find some... Here's one:
;------------------------------------
; nasm -f bin -o boot.bin boot02.asm
;
; dd count=1 if=boot.bin of=/dev/fd0
; or
; debug boot.bin
; w 100 0 0 1
; q
;-------------------------------------
org 7C00h
section .text
jmp short overdata
nop
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:
xor ax,ax
mov ds,ax
mov ax,0B800h
mov es,ax
; should probably set up a sane stack here, too.
mov si,msg ; "our dear string"
mov ah,04h ; color
msgloop:
lodsb
or al,al
jz blackhole
stosw
jmp msgloop
blackhole:
jmp blackhole
msg db "We be bootin'!",0
times 510-($-$$) db 0
db 55h, 0AAh ; boot sector signature
;-------------------------
The initial cruft is for FAT12 compatibility - not necessary, but it
keeps debug happier, if you're using that (otherwise you'll have to
format the disk every time). Then, first thing, we initialize ds to a
correct value (could also use "org 0" and load ds with 7C0h). It may be
that your BIOS will leave ds with the "right" value, but some of 'em
don't, so don't count on it! Mr. Krishnakumar's example doesn't depend
on this, so you don't have to do it there, but as soon as you've got
"data", you'll need it.
I'm cc'ing your messages to the nasm-users list, but I didn't tell ya
how to post to it:
Nasm-users mailing list
Nas...@li...
https://lists.sourceforge.net/lists/listinfo/nasm-users
You may have more questions... :)
Best,
Frank
|