VARARGS68K

7 posts / 0 new
Last post
afxgroup
afxgroup's picture
Offline
Last seen: 5 months 5 days ago
Joined: 2011-02-03 15:26
VARARGS68K

Hello, for a program i'm translating from 68k to PPC i have a problem on a varargs function. Or better.. i have a lot of problems..

First of all: The original definition

struct aReq *CreateDummy(ULONG flags, Tag tag1, ...);

i've changed it to use VARARGS68K parameters. so now i have:

struct aReq * VARARGS68K CreateDummy(ULONG flags, Tag tag1, ...);

When i enter into the function as usual i try to pack them as TagItem using the va_start/va_end macro

  1. va_list ap;
  2. struct TagItem *tags;
  3. va_startlinear(ap, tag1);
  4. tags = va_getlinearva(ap, struct TagItem *);

The function in the old 68k program is called in this way:

  1. pr = CreateDummy(MYULONGFLAG,
  2. A_Title, MyTitle,
  3. A_Objects, MyObjects,
  4. A_Addresses, MyAddr,
  5. TAG_END);

Now. let's start with the various problems..
If i print them with a cycle:

  1. if (tags) {
  2. Tag tag;
  3. while ((tag=tags->ti_Tag)) {
  4. printf("tags->ti_Tag=%lx - %d\n",tags->ti_Tag,tags->ti_Tag);
  5. tags++;
  6. }
  7. }
  8. va_end(ap);

my ti_tag values are wrong.. they not are the correct defined in the .h file
And this is the first problem.
My huge doubt is that one.. This function calls another function defined into a .library file that i've translated for ppc use and it calls the function in this way:

in the 68k version it use the tags passed into the stack using the pointer to the first tag:

  1. pr = CreateLibDummy(A_Tag1, Taga1,
  2. A_Tag2, Taga2,
  3. A_Tag3, Taga3,
  4. A_Tag4, Taga4,
  5. TAG_MORE, &tag1); // no TAG_END required

for the ppc use i've changed them into:

  1. pr = CreateLibDummy(A_Tag1, Taga1,
  2. A_Tag2, Taga2,
  3. A_Tag3, Taga3,
  4. A_Tag4, Taga4,
  5. TAG_MORE, tags); // note the tags variable

So i think there is another problem. When the external library is called it packs the Tag parameters into TagItem like the previous one, indeed if i use the same cycle to print the ti_Tag, the first 4 values are correct, the TAG_MORE is printed as 2 (and it is correct) but the other parameters are always wrong.
So my question are:

1) Is the pack needed in the first function since i cannot pass the tags like the 68k version?
2) If i pack them can i avoid to repack them when my library receive the parameters?
3) is there a solution??

Hope i'm clear..
Thank you

salass00
salass00's picture
Offline
Last seen: 6 months 3 days ago
Joined: 2011-02-03 11:27
The problem is that you list

The problem is that you list the first vararg parameter as a variable (tag1) which is wrong. Instead your function prototype should like this:

  1. struct aReq * VARARGS68K CreateDummy(ULONG flags, ...);

and the va_start code should be like:

  1. va_list ap;
  2. struct TagItem *tags;
  3. va_startlinear(ap, flags);
  4. tags = va_getlinearva(ap, struct TagItem *);
afxgroup
afxgroup's picture
Offline
Last seen: 5 months 5 days ago
Joined: 2011-02-03 15:26
i think i've alredy tried

i think i've alredy tried it.. but i'll retry when i go home. But what about the tags passend into TAG_MORE? it is correct to pack them? And what about the library that receive them as TagItem instead of Tag?

salass00
salass00's picture
Offline
Last seen: 6 months 3 days ago
Joined: 2011-02-03 11:27
No idea what you mean by

No idea what you mean by packing here but this code on ppc-amigaos:

  1. APTR VARARGS68K BlahTags (ULONG some_arg, ...) {
  2. APTR res;
  3. va_list tags;
  4. va_startlinear(tags, some_arg);
  5. res = BlahTagList(some_arg, va_getlinearva(tags, struct TagItem *));
  6. va_end(tags);
  7. return res;
  8. }

is equivalent to the following code on m68k-amigaos:

  1. APTR BlahTags (ULONG some_arg, Tag tag1, ...) {
  2. return BlahTagList(some_arg, (struct TagItem *)&tag1);
  3. }

or without using tag1 (m68k-amigaos only as above):

  1. APTR BlahTags (ULONG some_arg, ...) {
  2. return BlahTagList(some_arg, (struct TagItem *)(&some_arg+1));
  3. }
afxgroup
afxgroup's picture
Offline
Last seen: 5 months 5 days ago
Joined: 2011-02-03 15:26
Ok, but did you have an

Ok, but did you have an external PPC library that receive this parameters?
The problem is that i have something like this:

MyProgram calls function A inside the program
The function A will use va_start/va_end macro
The function A call an external .library that receive this parameters in this way:

CalledFunction(Tag1, 1, Tag2, 2, TAG_MORE, myvatags)

The ppc library will use va_start/va_end on received parameters. So, for the first two couple of parameters it is working, so i will have {Tag1, 1} and {Tag2, 2}. I halso receive TAG_MORE correct but the next parameter is the TagItem i have passed from my function A.
How the va_startlinear change them?

thomas
thomas's picture
Offline
Last seen: 2 months 4 weeks ago
Joined: 2011-05-16 14:23
If i print them with a


If i print them with a cycle:

  1. while ((tag=tags->ti_Tag)) {
  2. printf("tags->ti_Tag=%lx - %d\n",tags->ti_Tag,tags->ti_Tag);
  3. tags++;
  4. }

This part of your code does not work with TAG_MORE. You have to use NextTagItem() to traverse a tag list correctly.

afxgroup
afxgroup's picture
Offline
Last seen: 5 months 5 days ago
Joined: 2011-02-03 15:26
well that part was working

well that part was working because there no was tag more in the first function.. but basically it was the problem since the tag pointer was increased.. and then passed wrong to the second function.. now all is working perfectly..

Log in or register to post comments