Memory handler issues

This forum is for general developer support questions.
Post Reply
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Memory handler issues

Post by xenic »

I've identified a potential memory handler problem in some code that is ported from OS3.

1. The example code for exec AddMemHandler() in the autodoc shows the interrupt structure ln_Type element being set to NT_INTERRUPT but the exec includes show that it should be NT_EXTINTERRUPT for native code. Which is correct?

2. The prototypes for and OS3 memory handler and OS4 memory handler appear to be different. In the ported code I'm working on, the memory handler function has not been changed from the original OS3 version. I need to know if it needs to be changed.

The OS3 AddMemHandler() autodocs state that the interrupt arguments are passed in registers A0 (pointer to struct MemHandlerData), A1 (pointer to is_Data {userdata?} and A6 (execbase). The example handler is in 68k assembler. The handler function in the program has this prototype:

int low_mem_handler(REG(a0,struct MemHandlerData *memh), REG(a1, struct LibData *data));

Based on the register specifications in the prototype it would appear to be correct for OS3.

The OS4 AddMemHandler() autodocs state that interrupt arguments are passed in registers r3 (execbase), r4 ( struct MemHandlerData) and r5 (is_Data). The example handler is in C and this is the prototype:

LONG myhandler_code(struct ExecBase *ExecBase,
struct MemHandlerData *memHandlerData,
APTR is_Data UNUSED);

The handler arguments appear to be in a different order than the OS3 handler arguments. Do I need to change the handler function in the program to the order shown in the OS4 exec AddMemHandler() autodoc?

3. The prototypes for interrupt handlers shown in the exec SetIntVector() and AddIntServer() look like this:

exec.library/SetIntVector
void interruptHandler(struct ExceptionContext *Context, struct ExecBase *SysBase, void *UserData);

exec.library/AddIntServer
ULONG handler(struct ExceptionContext *Context, struct ExecBase *SysBase, APTR userData);

If the low memory handler is an interrupt (or interrupt handler) how can the arguments be in a different order? The execBase argument is second argument for an interrupt vector or server and first argument for the low memory handler. Are the autodocs correct or is there some error?
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 530
Joined: Sat Jun 18, 2011 3:12 pm
Location: Finland
Contact:

Re: Memory handler issues

Post by salass00 »

The diskio.library memhandler is defined like:

Code: Select all

int32 DiskIOMemHandler(struct ExecBase *sysbase, struct MemHandlerData *memh, struct DiskIOBase *libbase);
If you want to use the same prototype for both PPC and m68k you could do it like this:

Code: Select all

int low_mem_handler(REG(a6, struct ExecBase *sysbase), REG(a0,struct MemHandlerData *memh), REG(a1, struct LibData *data));
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: Memory handler issues

Post by xenic »

salass00 wrote:The diskio.library memhandler is defined like:

Code: Select all

int32 DiskIOMemHandler(struct ExecBase *sysbase, struct MemHandlerData *memh, struct DiskIOBase *libbase);
If you want to use the same prototype for both PPC and m68k you could do it like this:

Code: Select all

int low_mem_handler(REG(a6, struct ExecBase *sysbase), REG(a0,struct MemHandlerData *memh), REG(a1, struct LibData *data));
Thanks. The diskio.library low memory handler matches the example in the OS4 exec autodocs, so I'll change the OS4 low memory handler proto and function in the program with some #ifdef __amigaos4__ stuff. I can't touch the OS3 proto/function because the code must also compile for OS3, MOS and AROS. I have no way of compiling or testing MOS or AROS programs so I can't change the code in a way that might affect those.

Since I started this topic I've discovered that a system freeze in the low memory handler isn't a problem with the handler arguments but is a bug in OS4 that I'll report in a seperate topic.

Thanks for confirming the correct argument order for OS4
.
AmigaOne X1000 with 2GB memory - OS4.1 FE
Post Reply