Function Numbers for AROS_LVO_CALLs

NathanH · 628

NathanH

  • Newbie
  • *
    • Posts: 17
    • Karma: +1/-0
on: November 14, 2022, 11:33:06 AM
Hi,

About 10 years ago I compiled pForth using the AROS_LVO_CALL system to be able to implement calls to AROS functions from within pForth.  I just retired from work so I have some time on my hands.  I'm working on this system for eventual upload to AROS Archives.  For example, within pForth, I define Lock as:

: Lock ( buf accessMode -- lock ) 14 EXEC_DOSBASE CALL2 ;

where 14 is the index into the jump table for the Dos library for the Lock function.  I'm currently writing examples to open windows with menus, gadgets, and such and have been using an old Multi-Forth for the Amiga manual for identifying the function numbers for each function by library.  I'm currently using old JForth .j files for includes.

I'd like to begin, however, using AROS information rather than old info from outdated AmigaDOS sources.  For example, It looks like if I start counting at 5 at the top of the AROS fd file for a given library I can guess the function number.  I'd rather not guess though.  Is this an acceptable method or is there another way/place to find function numbers for an arbitrary library?  Thanks.

NathanH



deadwood

  • AROS Developer
  • Legendary Member
  • *****
    • Posts: 1524
    • Karma: +118/-0
Reply #1 on: November 14, 2022, 01:37:54 PM
Hi,

Once reference are .conf files available in each libraries, here is example for DOS

https://github.com/deadw00d/AROS/blob/alt-abiv0/rom/dos/dos.conf. You will have the table starting after ##begin functionlist entry, but you will have to do the counting yourself. Otherwise you can check each of source codes, like for Lock, https://github.com/deadw00d/AROS/blob/alt-abiv0/rom/dos/lock.c. There you will have part of function definition something like:

Code: [Select]
/*  LOCATION */
        struct DosLibrary *, DOSBase, 14, Dos)

If you have AROS locally complied, you can also check _start.c files which lists all functions for a library along with their offsets.

Please keep in mind that when looking at source code, you need to use ABIv0 branch (https://github.com/deadw00d/AROS/blob/alt-abiv0/). Master branch has different LVOs.



NathanH

  • Newbie
  • *
    • Posts: 17
    • Karma: +1/-0
Reply #2 on: November 14, 2022, 02:51:42 PM
Thank you very much!  I should be able to make at least one of those choices work.  I've never tried to compile AROS before but that choice seems the most convenient if I can make it work.

NathanH



deadwood

  • AROS Developer
  • Legendary Member
  • *****
    • Posts: 1524
    • Karma: +118/-0
Reply #3 on: November 14, 2022, 11:29:56 PM
I've never tried to compile AROS before but that choice seems the most convenient if I can make it work.

It's really quite simple if you have Linux or a Linux VM. Let me know if you are interested.



magorium

  • Legendary Member
  • *****
    • Posts: 632
    • Karma: +62/-0
  • Convicted non contributor
Reply #4 on: November 15, 2022, 03:24:49 AM
@NathanH:
As deadwood wrote: the .conf files are the prime source for your information on library function index numbers.

But, it is a bit of an annoyance to use them in case you are not familiar with them as they start "counting" from a certain index and each empty line or line indicated with .skip <number> skips a number of indexes.

We had to use the same .conf files for creating header files for Free Pascal so you could take a look at those header files to verify or use them as your source.

Because all structural and other defined elements are tucked in there as well you could use that information from the Pascal header files as as well for implementing your forth headers. I honestly can't remember if forth uses separate include files (as c does) or requires everything to be included in a single header file so you might be unfamiliar with how Pascal does it.


Main Pascal header files source directory can for example be found here https://github.com/fpc/FPCSource/tree/main/packages/arosunits/src

The only difference is that some header files are named differently in order to avoid naming conflicts with other (RTL) Pascal header files so, for instance the AROS header file for DOS is named amigados, Graphics is named agraphics, etc.


The function names and index numbers can be found at the bottom of each header file. The function implementations at the bottom are usually macro's (FreePascal does not support c-style macro's) and variadic versions of certain functions. The information you are probably more interested in is situated just above those implementations.


For instance your Lock function can be found inside Pascal unit header AmigaDOS.pas at line #2217 (https://github.com/fpc/FPCSource/blob/main/packages/arosunits/src/amigados.pas#L2217) which reads:
Code: [Select]
function Lock(const Name: STRPTR; AccessMode: LongInt): BPTR; syscall AOS_DOSBase 14;
Indicating that a function named Lock returning a BPTR takes two parameters named Name (type = STRPTR) and AccessMode (type = Long integer) using a SYSCALL (probably your jforth CALL2 implementation) using a LVO index of 14.

If you do tend to use the Pascal header files as a source of information then please take note that Pascal is case insensitive so Lock, LOCK, LoCK and lock all refer to the same thing.

Also always make sure to verify against original AROS c source/include files because it functions can behave strange or wrong when pushing/popping the wrong sized elements to/from the stack. Sometime this is obvious but sometime the difference is subtle.

regards,
« Last Edit: November 15, 2022, 03:32:52 AM by magorium »



deadwood

  • AROS Developer
  • Legendary Member
  • *****
    • Posts: 1524
    • Karma: +118/-0
Reply #5 on: November 15, 2022, 03:29:21 AM
That's actually even easier than .conf files. Thanks @magorium.