BartmanAbyss / vscode-amiga-debug

One-stop Visual Studio Code Extension to compile, debug and profile Amiga C/C++ programs compiled by the bundled gcc 12.2 with the bundled WinUAE/FS-UAE.
GNU General Public License v3.0
315 stars 39 forks source link

__far, register args #4

Closed tehKaiN closed 4 years ago

tehKaiN commented 4 years ago

I'm maintaining game engine/framework/library/whatever as seen here https://github.com/AmigaPorts/ACE . I use some low level stuff in my code via macros in a way that is compatible with Bebbo's GCC, (kinda) VBCC and x86 (logic only).

For example putting function args in registers:

#elif defined(__VBCC__)
#define REGARG(arg, reg) __reg(reg) arg
#elif defined(__GNUC__)
#define REGARG(arg, reg) arg asm(reg)

which is used like:

void INTERRUPT keyIntServer(
    REGARG(volatile tCustom *pCustom, "a0"),
    REGARG(volatile void *pData, "a1")
);

Unfortunately GNUC variant syntax doesn't work with your compiler. In fact I tried some variations and I wasn't able to make it run. Also __far:

#define REGPTR volatile * const
extern tCustom FAR REGPTR g_pCustom; // FAR translates to __far
extern tRayPos FAR REGPTR g_pRayPos;

I've tried putting that __far everywhere but it didn't work. What's the correct syntax in both cases?

BartmanAbyss commented 4 years ago

For registers, have a look at https://github.com/BartmanAbyss/vscode-amiga-debug/blob/master/bin/opt/m68k-amiga-elf/sys-include/inline/macros.h That's how it's done for the AmigaOS interface. You should be able to adapt from there. Otherwise the default calling convention is to just push all arguments on the stack. For __far, I think that's not needed. I have used pointers to custom registers without it.

tehKaiN commented 4 years ago

So I see there are only some wrappers which put regs into certain registers and call os functions using inline asm, but there's no way to declare a function which has params bound to registers - e.g. for declaring OS-friendly interrupt handler. That's a bit of bummer, but should suffice for now since I'm taking over os anyway.

I'll revise my __far usage, perhaps I'm unnecessarily using it, but I think I've added that for a reason which I don't remember right now. Should've done some comments inside code. ;)

Anyway, that's all I need to know right now. Thanks for your reply and for all work on this extension!