2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: DOS function InternalLoadSeg()
10 #include <dos/dosextens.h>
11 #include <proto/dos.h>
12 #include <aros/debug.h>
13 #include "dos_intern.h"
14 #include "internalloadseg.h"
16 /*****************************************************************************
19 #include <proto/dos.h>
21 AROS_LH4(BPTR
, InternalLoadSeg
,
24 AROS_LHA(BPTR
, fh
, D0
),
25 AROS_LHA(BPTR
, table
, A0
),
26 AROS_LHA(LONG_FUNC
*, funcarray
, A1
),
27 AROS_LHA(LONG
* , stack
, A2
),
30 struct DosLibrary
*, DOSBase
, 126, Dos
)
34 Functionarray is a pointer to an array of functions. See below.
36 This function really only tries to load the different file
37 formats aos, elf and aout.
40 fh : Filehandle to load from
42 funcarray : array of functions to be used for read, seek, alloc and free
43 FuncTable[0] -> bytes = ReadFunc(readhandle, buffer, length), DOSBase
45 FuncTable[1] -> Memory = AllocFunc(size,flags), ExecBase
47 FuncTable[2] -> FreeFunc(memory, size), ExecBase
49 FuncTable[3] -> pos = SeekFunc(readhandle, pos, mode), DOSBase
51 stack : pointer to storage (LONG) for stacksize.
55 seglist - pointer to loaded Seglist or NULL in case of failure.
58 FuncTable[3] is not used for Amiga HUNK format files, but is required
64 Use of table and stack are not implemented, yet!
71 *****************************************************************************/
75 typedef struct _segfunc_t
78 BPTR (*func
)(BPTR
, BPTR
, SIPTR
*, LONG
*, struct DosLibrary
*);
79 D(CONST_STRPTR format
;)
82 #define SEGFUNC(id, format) {id, InternalLoadSeg_##format D(, (STRPTR)#format)}
84 static const segfunc_t funcs
[] =
86 SEGFUNC(0x7f454c46, ELF
),
87 SEGFUNC(0x000003f3, AOS
)
95 const UBYTE num_funcs
= sizeof(funcs
) / sizeof(funcs
[0]);
99 len
= ilsRead(fh
, &id
, sizeof(id
));
100 if (len
== sizeof(id
)) {
101 id
= AROS_BE2LONG(id
);
102 for (i
= 0; i
< num_funcs
; i
++) {
103 if (funcs
[i
].id
== id
) {
104 segs
= (*funcs
[i
].func
)(fh
, BNULL
, (SIPTR
*)funcarray
,
106 D(bug("[InternalLoadSeg] %s loading %p as an %s object.\n",
107 segs
? "Succeeded" : "FAILED", fh
, funcs
[i
].format
));
114 /* This routine can be called from partition.library, when
115 * DOSBase is NULL, from HDToolbox, on m68k, when adding
116 * a new device to HDToolbox.
118 * Luckily, we're not trying to read ELF, which has a
119 * mess of SetIoErr() calls in it.
122 SetIoErr(ERROR_NOT_EXECUTABLE
);
127 } /* InternalLoadSeg */
129 int read_block(BPTR file
, APTR buffer
, ULONG size
, SIPTR
* funcarray
, struct DosLibrary
* DOSBase
)
132 UBYTE
*buf
=(UBYTE
*)buffer
;
136 subsize
= ilsRead(file
, buf
, size
);
140 struct Process
*me
= (struct Process
*)FindTask(NULL
);
141 ASSERT_VALID_PROCESS(me
);
142 me
->pr_Result2
=ERROR_BAD_HUNK
;
155 APTR
_ilsAllocVec(SIPTR
*funcarray
, ULONG size
, ULONG req
)
157 UBYTE
*p
= ilsAllocMem(size
, req
);
159 D(bug("allocmem %p %d\n", p
, size
));
163 /* Note that the result is ULONG-aligned even on 64 bits! */
164 *((ULONG
*)p
) = (ULONG
)size
;
165 return p
+ sizeof(ULONG
);
168 void _ilsFreeVec(SIPTR
*funcarray
, void *buf
)
170 UBYTE
*p
= (UBYTE
*)buf
;
175 size
= ((ULONG
*)p
)[0];
176 D(bug("freemem %p %d\n", p
, size
));