The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: James Ladd on November 30, 2010, 05:17:21 AM

Title: Program startup ...
Post by: James Ladd on November 30, 2010, 05:17:21 AM
Hi All,

Now that I am implementing an assembler of my own for a "virtual" architecture Im needing to know more about how
program loading and starting is done. Previously I relied on MASM/GoASM and other tools to take care of these things.

https://github.com/jamesladd/rasmataz

What follows is my understanding which I'm hoping someone could validate:


Rgs, James.
Title: Re: Program startup ...
Post by: dedndave on November 30, 2010, 09:13:16 AM
i think there's a lot more to it than that
i am certainly not the expert on this stuff for 32-bit
but, the references in the IAT have to be resolved at some point

also, a good look at the PE/COFF spec will give you more of an idea what all goes on

http://www.masm32.com/board/index.php?topic=13135.0
Title: Re: Program startup ...
Post by: FORTRANS on November 30, 2010, 01:56:38 PM
Hi,

   Except for the start symbol, what you describe is basically
the program load and execute for a 16-bit *.COM format
program.  *.EXE also require relocation of symbols (fix-ups).
Oh, and you need to set up the stack segment and pointer.
Protected mode (over simplified) adds various read, write,
and execute permissions to sections of code (IIRC). 

Regards,

Steve N.
Title: Re: Program startup ...
Post by: James Ladd on November 30, 2010, 08:52:49 PM
Just verifying - So I also need to set Stack Pointer to base of stack?
Title: Re: Program startup ...
Post by: dedndave on November 30, 2010, 09:01:44 PM
i think you speicfy the size
the PE/COFF spec should tell you
also - you could assemble a couple programs, playing with the linker stack size
then use PE view to verify results
Title: Re: Program startup ...
Post by: BogdanOntanu on November 30, 2010, 10:01:48 PM
For a "virtual architecture" YOU decide how a program is to be loaded. This comes in part from the hardware architecture and in part from the OS architecture. Being virtual you get to define both.

For Windows you do not. The OS does all the necessary steps needed to load and run an application. Your assembler or compiler does nothing special.

All you have to do is to setup the required fields in the PE32 or PE32+ (for 64 bits) executable format and the OS takes care of the rest.

Now... if you want to talk about you loading an application by yourself in Windows.... by avoiding the OS ... I do suggest that you do not go that way :))
Title: Re: Program startup ...
Post by: brethren on November 30, 2010, 10:07:55 PM
this book may be old but its free :U i think you'll find it indispensable for your current project
http://www.davidsalomon.name/assem.advertis/AssemAd.html
Title: Re: Program startup ...
Post by: MichaelW on December 01, 2010, 02:16:52 AM
The stack pointer needs to be set to the end of the stack, where end means the highest address.
Title: Re: Program startup ...
Post by: James Ladd on December 01, 2010, 03:13:12 AM
>>The stack pointer needs to be set to the end of the stack, where end means the highest address.
Will do.

The assembler is coming along nicely although I spend very little time on it.
I'm presenting it at a meeting on 7th Dec, so Ill follow this thread later with
a post of the presentation.

Currently 'rasmataz' can load a program and you can easily dump the registers, memory, stack and labels.
You can even type instructions on the command line and have them executed immediately.

I'm also going to make it possible to 'clone'/'copy' the machine state so you can wind it back if an
execution fails -  to try again modify the assembly on the fly.

Thanks.
Title: Re: Program startup ...
Post by: dedndave on December 01, 2010, 04:00:30 AM
i dunno 'bout the code, but i like the name   :bg
Title: Re: Program startup ...
Post by: James Ladd on December 01, 2010, 05:20:12 AM
rasmataz is executing code now!

Not all instructions implemented, therefore it does a NOP for a lot of instructions.

Could be an interesting teaching tool, as well as a test bed which is what I want it for.

Anyone brave enough to try it?

Rgs, James.