2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: DOS function InternalLoadSeg()
13 #include <dos/dosextens.h>
14 #include <proto/dos.h>
15 #include <aros/debug.h>
16 #include "dos_intern.h"
17 #include "internalloadseg.h"
19 #if AROS_MODULES_DEBUG
20 #include <exec/nodes.h>
21 #include <exec/lists.h>
24 struct MinList debug_seglist
, free_debug_segnodes
;
28 /*****************************************************************************
31 #include <proto/dos.h>
33 AROS_LH4(BPTR
, InternalLoadSeg
,
36 AROS_LHA(BPTR
, fh
, D0
),
37 AROS_LHA(BPTR
, table
, A0
),
38 AROS_LHA(LONG_FUNC
, functionarray
, A1
),
39 AROS_LHA(LONG
* , stack
, A2
),
42 struct DosLibrary
*, DOSBase
, 126, Dos
)
46 Functionarray is a pointer to an array of functions. See below.
48 This function really only tries to load the different file
49 formats aos, elf and aout.
52 fh : Filehandle to load from
54 functionarray : array of functions to be used for read, alloc and free
55 FuncTable[0] -> bytes = ReadFunc(readhandle, buffer, length), DOSBase
57 FuncTable[1] -> Memory = AllocFunc(size,flags), ExecBase
59 FuncTable[2] -> FreeFunc(memory, size), ExecBase
61 stack : pointer to storage (ULONG) for stacksize.
65 seglist - pointer to loaded Seglist or NULL in case of failure.
72 Use of table and stack are not implemented, yet!
79 *****************************************************************************/
83 typedef struct _segfunc_t
85 BPTR (*func
)(BPTR
, BPTR
, SIPTR
*, SIPTR
*,
86 struct MinList
*, struct DosLibrary
*);
87 D(CONST_STRPTR format
;)
90 #define SEGFUNC(format) { InternalLoadSeg_##format D(, (STRPTR)#format)}
92 static const segfunc_t funcs
[] =
96 #if !defined(__mc68000__) && !defined(__arm__)
108 const int num_funcs
= sizeof(funcs
)/sizeof(funcs
[0]);
109 struct MinList
*pseginfos
;
110 #if AROS_MODULES_DEBUG
111 struct MinList seginfos
;
114 pseginfos
= &seginfos
;
123 segs
= (*funcs
[i
].func
)(fh
, MKBADDR(NULL
), (SIPTR
*)functionarray
,
124 NULL
, pseginfos
, DOSBase
);
126 D(bug("[InternalLoadSeg] %s loading %p as an %s object.\n",
127 segs
? "Succeeded" : "FAILED", fh
, funcs
[i
].format
));
129 } while (!segs
&& (IoErr() == ERROR_NOT_EXECUTABLE
) && (++i
< num_funcs
));
131 #if AROS_MODULES_DEBUG
134 struct debug_segnode
*segnode
;
137 segnode
= (struct debug_segnode
*)REMHEAD(&free_debug_segnodes
);
144 NameFromFH(fh
, segnode
->name
, sizeof(segnode
->name
));
145 D(bug("[InternalLoadSeg] loaded: %s\n", segnode
->name
));
147 segnode
->seglist
= segs
;
149 /* copy the segments info list */
150 NEWLIST(&segnode
->seginfos
);
151 while ((si
= REMHEAD(&seginfos
)))
152 ADDTAIL(&segnode
->seginfos
, si
);
154 #if defined(__AROS_SET_START_ADDR)
155 __AROS_SET_START_ADDR(segnode
);
157 #warning "if you want gdb debugging of loaded executables implement __AROS_GET_START_ADDR in machine.h"
161 ADDTAIL(&debug_seglist
, segnode
);
171 } /* InternalLoadSeg */