Login
Username:

Password:

Remember me



Lost Password?

Register now!
Main Menu
Who's Online
32 user(s) are online (17 user(s) are browsing Forum)

Members: 0
Guests: 32

more...

Browsing this Thread:   1 Anonymous Users





Aros i386 - Assembler

Joined:
2011/4/18 7:10
From Germany
Group:
Member
Posts: 350
Offline
I have a very technical question, I hope someone can answer me. (background: freepascal start routine)

When my program is started (I think) I find following in stack:

12(%esp) ExecBase
8(%esp) Command line parameters length
4(%esp) Command line parameters string ptr
(%esp) return address

so far its ok, when I start my program from Shell I find this values as expected.
When I start from Workbench, Command line parameters length and str = 0, as expected.

When I make a short C program I noticed that argv is not empty when start from Workbench, there is a pointer inside (I guess its WBStartup* ?)

From where do I get this pointer? I guess you set a kind of prestarting routine before you jump into users code (where is it in the source tree?).
Where I can find informations about it?

Thanks.

Posted on: 2013/1/8 13:23
Transfer the post to other applications Transfer


Re: Aros i386 - Assembler

Joined:
2010/1/8 10:07
Group:
Member
Posts: 1208
Offline
ALB42 not sure if you meant this...
http://repo.or.cz/w/AROS.git/tree

Posted on: 2013/1/8 13:45
Transfer the post to other applications Transfer


Re: Aros i386 - Assembler

Joined:
2011/6/30 19:50
Group:
Member
Posts: 2992
Offline
Hi ALB42:

I think what you are looking for is here (it might be that it is a bit different in AROS though. But it aims to be compatible, so...).

i made a post about it here in this thread.

Ofcourse the method to see if running from shell vs wanderer could also be done in pascal-code, but it might be that you need it before pascal is really up'n'running ?.

Posted on: 2013/1/8 15:23
Transfer the post to other applications Transfer


Re: Aros i386 - Assembler

Joined:
2004/10/30 17:13
From Ireland
Group:
Member
Posts: 2070
Offline
The C startup code here might be relevant:

http://repo.or.cz/w/AROS.git/tree/HEAD:/compiler/startup

Posted on: 2013/1/8 15:56
Transfer the post to other applications Transfer


Re: Aros i386 - Assembler

Joined:
2011/6/30 19:50
Group:
Member
Posts: 2992
Offline
Let me disect this bit by bit (as i understand it).

Quote:
I have a very technical question,

Good, i like those. It just took me a little while

Quote:
When my program is started (I think) I find following in stack:
12(%esp) ExecBase
8(%esp) Command line parameters length
4(%esp) Command line parameters string ptr
(%esp) return address

Yes, but i wonder if this pc-asm babble is good for something

Quote:
When I start from Workbench, Command line parameters length and str = 0, as expected.

I'm trying hard not to get confused by fpc's paramstr & paramcount here

Quote:
When I make a short C program I noticed that argv is not empty when start from Workbench, there is a pointer inside (I guess its WBStartup* ?)

Correct, and it follows classic amigaOS in doing so.

Finally, i was able to come up with the code that explains it (Browse beneath codelink forwards and backwards for many more interresting information about the subject).

In this code we read:
Quote:
/* argc is zero when run from the Workbench,
** positive when run from the CLI.
*/

And:
Quote:
/* in SAS/Lattice, argv is a pointer to the WBStartup message
** when argc is zero. (run under the Workbench.)
*/

Because of your findings, i'm assuming this is the same as done in AROS/GCC.

Quote:
From where do I get this pointer?

If we know for sure that it is the WBstartup message, then fpc already provides information that might be of interrest.

Firstly the wbargs unit, also found in the aros branch here.

But unfortunately, that unit does not do us much good as it calls other routines not available in that unit.

A quick scan through the classic amiga units showed me this rtl unit. With this piece of interresting code (little snippet taken as example):
Quote:
309 { AmigaOS specific startup }
310 procedure SysInitAmigaOS;
311 var self: PProcess;
312 begin
313 self:=PProcess(FindTask(nil));
314 if self^.pr_CLI=0 then begin
315 { if we're running from Ambient/Workbench, we catch its message }
316 WaitPort(@self^.pr_MsgPort);
317 AOS_wbMsg:=GetMsg(@self^.pr_MsgPort);
318 end;


So, as mentioned in my first message (the post i refered to in the other thread) we can indeed use the pr_CLI trick _and_ done in pascal \o/

AOS_wbMSG would be the message that you seem to be searching for (but i do place a little ?, because i am not sure if this helps you and if you are able to use pascalcode at the stage you need it)

Quote:
I guess you set a kind of prestarting routine before you jump into users code (where is it in the source tree?).

The startupcode i refered to in my previous post about the subject would be very helpfull if you are able to understand it (68k asm). But i believe the pascalcode pasted in this post will also work

Quote:
Where I can find informations about it?

Surprisingly, in our very own fpc branche and trunk

If you want to be 100% sure, then that would require to follow ncafferkey's link though.

in the hope it was usefull,

Posted on: 2013/1/8 17:56
Transfer the post to other applications Transfer


Re: Aros i386 - Assembler

Joined:
2011/4/18 7:10
From Germany
Group:
Member
Posts: 350
Offline
Sorry to everyone I found the solution yesterday night already, but was too tired to look into this thread again to write it here.

Quote:

magorium wrote:

Quote:
When my program is started (I think) I find following in stack:
12(%esp) ExecBase
8(%esp) Command line parameters length
4(%esp) Command line parameters string ptr
(%esp) return address

Yes, but i wonder if this pc-asm babble is good for something


Thats the way function calling looks like in Assembler.. because the start routine is in assembler, its easier to explain what I mean, I could also write:

Int start(ExecBase, cmdLen, cmdStr);

And I hope to attract someone with a deep insight to the inner core of AROS to this thread because I hope someone will protest if this is not right.
(if there is one parameter more at 16(%esp) for example)

The other question would be what AROS expect after my program?
1. The stack should look like before + returncode in %eax (stdcall)
2. the parameters should be dropped from stack after leave my program (so make a rts 12 at the end) + returncode in %eax (cdecl)

I hoped to find some informations about.. atm I use for every function stdcall and it seems to work but I experience some strange memory effects (no memory errors even largest memory block is 800Mb) which could be due to a full stack (-> wrong calling convention?)

Quote:

Quote:
When I start from Workbench, Command line parameters length and str = 0, as expected.

I'm trying hard not to get confused by fpc's paramstr & paramcount here

Quote:
When I make a short C program I noticed that argv is not empty when start from Workbench, there is a pointer inside (I guess its WBStartup* ?)

Correct, and it follows classic amigaOS in doing so.

What I wanted to show is that this list of parameters does not match the ones I find in the stack when my program is started.

Quote:

Quote:
From where do I get this pointer?

If we know for sure that it is the WBstartup message, then fpc already provides information that might be of interrest.

A quick scan through the classic amiga units showed me this rtl unit. With this piece of interresting code (little snippet taken as example):
Quote:
309 { AmigaOS specific startup }
310 procedure SysInitAmigaOS;
311 var self: PProcess;
312 begin
313 self:=PProcess(FindTask(nil));
314 if self^.pr_CLI=0 then begin
315 { if we're running from Ambient/Workbench, we catch its message }
316 WaitPort(@self^.pr_MsgPort);
317 AOS_wbMsg:=GetMsg(@self^.pr_MsgPort);
318 end;


So, as mentioned in my first message (the post i refered to in the other thread) we can indeed use the pr_CLI trick _and_ done in pascal \o/

AOS_wbMSG would be the message that you seem to be searching for (but i do place a little ?, because i am not sure if this helps you and if you are able to use pascalcode at the stage you need it)


Exactly this was not clear for me (in fact you will find this source snip in aros source as well) that AOS_WBMsg which is introduced as a Pointer is of the type (WBMessage *) which i searched for.

Quote:

Quote:
Where I can find informations about it?

Surprisingly, in our very own fpc branche and trunk

If you want to be 100% sure, then that would require to follow ncafferkey's link though.

in the hope it was usefull,


And exactly there I tried to find it ans failed, thats the reason I asked.

But as I stated alread I got the idea yesterday night already and it works. Nevertheless thanks, it works.

So in next Version of FPC the programm will supply for ParamStr(0) the name and path of the program even the program is started from WB.

Posted on: 2013/1/8 23:56
Transfer the post to other applications Transfer






You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.

[Advanced Search]


Search
Top Posters
1 paolone
paolone
3661
2 nikolaos
nikolaos
3467
3 phoenixkonsole
phoenixkonsole
3032
4 magorium
magorium
2992
5 deadwood
deadwood
2341
6 ncafferkey
ncafferkey
2070
7 mazze
mazze
2068
8 clusteruk
clusteruk
2050
9 damocles
damocles
1769
10 Kalamatee
Kalamatee
1714
© 2004-2014 AROS Exec