News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Writing bootcode

Started by conio, July 27, 2009, 02:07:55 PM

Previous topic - Next topic

conio

Hello there,
I'm tryin' to write a boot sector with MASM.
The program, which is 512 bytes long, ending with 2 byte - special signature (as far as I remember it's a 0xAA55), is located at the first sector of a floppy. Than, BIOS reads it and puts into memory at address 0000:7C00. So, I have to ask general questions about MASM:
1) I'd like to make my file exact 512 bytes.  Should it look like this:

org 0

code of a program

org 510
dw 0xAA55

Or maybe there is some special variable which holds the size of a program, so that I would be able to write as much zereos as 510 - ProgramSize, using for example dup instruction.

2) The second question is basically about memory. I'd like to have my starting procedure loaded at certain address - at 0x7C00, while segment register CS=0. How can I make MASM to set entry point address? Or it is not necessary when it comes to dealing with bootsector - maybe BIOS will do all the job for me?
Is there any way to set exact address of a procedure/variable?
Like in C:
char* variable = 0x1234; // that makes this pointer to point on a certain address

Maybe is there something else I need to know/concern?
Any help will be greatly appreciated.
Thanks,
Konrad

dedndave

#1
well - it has been a while since i have played with this stuff
i have not tried it with newer versions of masm
you need to write the program so that it may be assembled using the tiny memory model
then, the exe file needs to be converted to a bin by using exe2bin.exe (well, that's the old way, at least)

as for getting to 7c00, i suggest you make a bootable DOS floppy and disassemble their code
they do something like this

_LOAD SEGMENT AT 0
assume cs:_LOAD
org 7c00h

jmp far ptr LabelA
.
. or
.
mov eax,_BOOT  ;(7C0h)
push eax
mov eax,offset LabelA
push eax
retf

_LOAD ENDS

_BOOT SEGMENT AT 7C0h
assume cs:_BOOT

LabelA:

_BOOT ENDS

japheth

Hello,

this will create a 512 byte boot sector:



.286
.model tiny

.code

org 7C00h
start:
xor ax,ax
;       additional instructions

org 7E00h-2
dw 55aah

end start


And to create the binary run
ml -c boot.asm
link16 /TINY boot.obj,boot.bin;



redskull

Strange women, lying in ponds, distributing swords, is no basis for a system of government

dedndave

so - the linker performs the function of old exe2bin, then - cool - should have always been that way

conio

Thank you very much for help - I'll give it a try and tell if it works :):) Thanks!!!