News:

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

Program startup ...

Started by James Ladd, November 30, 2010, 05:17:21 AM

Previous topic - Next topic

James Ladd

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:


  • Program code is loaded into memory
  • A start symbol is located, and this is what instruction pointer points to
  • The instruction at 'instruction pointer' is executed
  • 'instruction pointer' is adjusted accordingly
  • next instruction is executed until halt or end of instructions

Rgs, James.

dedndave

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

FORTRANS

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.

James Ladd

Just verifying - So I also need to set Stack Pointer to base of stack?

dedndave

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

BogdanOntanu

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 :))
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

brethren

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

MichaelW

The stack pointer needs to be set to the end of the stack, where end means the highest address.
eschew obfuscation

James Ladd

>>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.

dedndave

i dunno 'bout the code, but i like the name   :bg

James Ladd

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.