News:

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

problem with masm

Started by ninjarider, September 07, 2005, 05:25:34 PM

Previous topic - Next topic

ninjarider

i have been studing on how to make a stand alone os written in assembly. i tryed to experiment with it last night. for those that dont know a bootable os has to have AAFF im not sure if its that order, it may be FFAA but it is expected at the 510 - 512 byte of the first sector of the drive. i assembled my file using the command ml /c 16.asm and when i used a hex editor to view the file to make sure it was assembled currectly the file contained the file header, and was padded with 0's till byte 514 which there was the first command.

my questons
using masm is there a way around the above problem?
is there a better assembler to use to make a stand alone operating system?
has an OS ever been written using masm?

P1

Place this at the very end of your code.

Org 07DFEh
BootSig db 055h, 0AAh ;AA55 boot record signature
- or -
BootSig dw 0AA55h ;AA55 boot record signature


Write a macro to pad to the signature.  I going to guess, that you will find it difficult to code a boot loader to fit this sector.

Have fun !!!

Regards,  P1  :8)

MichaelW

ninjarider,

The EXE header is added by the linker. You can avoid this by specifying the /tiny switch for the (16-bit) linker:

ML /c bootcode.asm
pause
LINK16 /tiny bootcode.obj,bootcode.bin;
pause

The executable file can have any extension. The linker will issue a warning if the start address is not set to 100h.

I would use MASM for this, but I think many/most coders would use some other assembler.

eschew obfuscation

ninjarider

also. how do u declare variables in 16 -bit assembly using masm

i tried something like this

.data
  temp db "a", 0

.code

but it keeps giving me an error.
how do i go about setting the start address to 100h

P1

BIOSes of most computers is going to load your code from a storage device to 0:7c00 in memory and far jump to it.

So trying to force it to org 100 is a waste of time, provided your not going to re-write BIOS of your motherboard while your at it.    :wink

BTW, org 100 is in the IVT of the uP, not a recommended starting point.

Regards,  P1  :8)


MichaelW

ninjarider,

The BIOS will load the boot sector at address 0000:7C00, so you probably should set the location counter to 7C00h at the start of the code segment with "org 7C00h". This will cause the linker to issue a warning, so I mentioned the warning so you would not mistake it for an error.


<start of segment>
org 7C00h
entrypoint:     ; Execution will start here
<code and data goes here, 510 bytes max>
org 7DFEh       ; 7C00h + 510
<bootsignature>
<end of segment>

eschew obfuscation

ninjarider

would i have to setup any of th stack pointers or other related registers and what would be the best things to set them to

P1

ninjarider,

You need to help yourself some here.  Read up some more on the available material on the internet.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcedsn40/html/cgconx86biosbootloader.asp
http://www.nondot.org/~sabre/os/articles

Regards,  P1  :8)

MichaelW

ninjarider,

The only registers that will be set for you will be CS and IP. If your code uses the stack, then you will need to set up a stack by loading appropriate values into SS and SP. In addition to the links that P1 provided, you could try searching the old forum:

http://www.old.masmforum.com
eschew obfuscation

ninjarider

ok. looks like i have enough info to read for now.

P1

ninjarider,

You have been here for a while, so I will ask about your thoughts on this.

BootRoot is a project presented at Black Hat USA 2005 by researchers Derek Soeder and Ryan Permeh, as an exploration of technology that custom boot sector code can use to subvert the Windows kernel as it loads. The BootRootKit is a boot sector-based NDIS backdoor that demonstrates the implementation of this technology.

Interest in old boot code, got me curious.  So is this your interest in old boot code?

Regards,  P1  :8)

ninjarider

well i dont know if i will do anything with windows. i was just interested in bootcode because i have a person goal of making a robot. i would like to get it to the point were i can load my old laptop with all the software for the robot and plug the lpt port into the robot and execute commands. i dont have a specific goal for the robot at this time. just getting it to move would be a breakthrew.

Quote from: P1 on September 09, 2005, 05:44:06 PM
ninjarider,

You have been here for a while, so I will ask about your thoughts on this.

BootRoot is a project presented at Black Hat USA 2005 by researchers Derek Soeder and Ryan Permeh, as an exploration of technology that custom boot sector code can use to subvert the Windows kernel as it loads. The BootRootKit is a boot sector-based NDIS backdoor that demonstrates the implementation of this technology.

Interest in old boot code, got me curious.  So is this your interest in old boot code?

Regards,  P1  :8)
to make sure i understand your post currectly.

subvert - to undermine

i dont like windows.

ninjarider

what it the interrupt to allow a 16-bit program to return to dos.

P1

ninjarider,

Thanks for your reply !!!

You don't necessarily need to boot a custom OS to play with Robot Code or AI control of objects.  You would be writing a lot of overhead support code for program support, that frankly, would distract you from your real goals.

My suggestion would be start with MSDOS/W95/W98 boot disk and replace command.com with your robot program.  You get the benefit of a self booting DOS disk with your program automatically loading.

Even then, I know the re-booting is going to get old.  And you will look for other more traditional code support for your ideas.

Regards,  P1  :8)

P1

Fast exit = INT 20h
Exit with a reason code
        MOV     AL, YourExitCode
        MOV     AH, 4Ch
        INT     21h

Regards,  P1  :8)