Welcome, Guest. Please login or register.

Author Topic: Writing a shared library - ASM Help  (Read 4725 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show all replies
    • http://www.nyteshade.com
Writing a shared library - ASM Help
« on: January 31, 2017, 01:33:33 AM »
So I have been following this guide to create a shared library in C for the Amiga. So far the default example works fine. The questions I have, as I want to adopt my code for the library, are these:

  • How do the registers work? What's the difference between A0/A1/D0 etc...?
  • What happens if I have more than one argument? Which registers do I use?
  • What about var args?
  • Does anybody know how this would differ if done in GCC? Can I, do I have to, link the SAS/C libinit.o/libinitr.o files?


I want to not only post the library I am building, but I want to be able to quickly reuse it for my own applications as I write them. Anybody else do this? Any fun stuff to share?
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500
 

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show all replies
    • http://www.nyteshade.com
Re: Writing a shared library - ASM Help
« Reply #1 on: January 31, 2017, 08:38:26 AM »
So it seems that A[0-7] is for addresses and D[0-7?] is for data? I am still not quite sure which parameters to associate with which registers. I am guessing that anything that is a not a pointer would get D register and all pointers an A register? However, that is purely a guess.
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500
 

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show all replies
    • http://www.nyteshade.com
Re: Writing a shared library - ASM Help
« Reply #2 on: February 16, 2017, 06:09:54 AM »
Answering my previous question, any argument that is a pointer to something goes in an __a register and anything that is a direct value goes in a __d register. It appears there are roughly 7 usable pointer registers and perhaps 7-8 direct value registers per function definition.

Code: [Select]
void __saveds __asm someFunction(
  register __a0 APTR ptr1,
  register __a0 APTR ptr1,
  register __a1 APTR ptr2,
  register __a2 APTR ptr3,
  register __a3 APTR ptr4,
  register __a4 APTR ptr5,
  register __a5 APTR ptr6,
  register __a6 APTR ptr7,
/*register __a7 APTR ptr8,      Seems this one is special */
  register __d0 BPTR val1,
  register __d1 BPTR val2,
  register __d2 BPTR val3,
  register __d3 BPTR val4,
  register __d4 BPTR val5,
  register __d5 BPTR val6,
  register __d6 BPTR val7,
  register __d7 BPTR val8
);

Alright folks, I have this all working fairly well. I have now run into another issue that I am not sure how to fix and I cannot, as of yet, find any docs around. When making the shared library you typically have to tag and define the functions that the library will use with register designations. But I am not sure what to do for varargs style functions

Code: [Select]
/* Typical Example */

struct Person {
  STRPTR name;
  SHORT age;
};

int __saveds __asm getAge(register __a0 struct Person *p) {
  return p->age;
}

/** Varargs?! */

int * __saveds __asm getAges(register __a0 struct Person *first, ...) {
  /* Loop through and collect the ages and return as int array */
}


Does the ... need to be tagged with a register?
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500