some fixes to accented characters
[tangerine.git] / rom / dos / internalloadseg.c
blobb7af9dd8e23dc5942d58eb0a24cedd0b38aecb6e
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: DOS function InternalLoadSeg()
6 Lang: english
7 */
10 #define DEBUG 0
12 #include <dos/dos.h>
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>
22 #include <string.h>
24 struct MinList debug_seglist, free_debug_segnodes;
26 #endif
28 /*****************************************************************************
30 NAME */
31 #include <proto/dos.h>
33 AROS_LH4(BPTR, InternalLoadSeg,
35 /* SYNOPSIS */
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),
41 /* LOCATION */
42 struct DosLibrary *, DOSBase, 126, Dos)
44 /* FUNCTION
45 Loads from fh.
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.
51 INPUTS
52 fh : Filehandle to load from
53 table : ignored
54 functionarray : array of functions to be used for read, alloc and free
55 FuncTable[0] -> bytes = ReadFunc(readhandle, buffer, length), DOSBase
56 D0 D1 A0 D0 A6
57 FuncTable[1] -> Memory = AllocFunc(size,flags), ExecBase
58 D0 D0 D1 A6
59 FuncTable[2] -> FreeFunc(memory, size), ExecBase
60 A1 D0 A6
61 stack : pointer to storage (ULONG) for stacksize.
62 (currently ignored)
64 RESULT
65 seglist - pointer to loaded Seglist or NULL in case of failure.
67 NOTES
69 EXAMPLE
71 BUGS
72 Use of table and stack are not implemented, yet!
74 SEE ALSO
75 UnLoadSeg()
77 INTERNALS
79 *****************************************************************************/
81 AROS_LIBFUNC_INIT
83 typedef struct _segfunc_t
85 BPTR (*func)(BPTR, BPTR, SIPTR *, SIPTR *,
86 struct MinList *, struct DosLibrary *);
87 D(CONST_STRPTR format;)
88 } segfunc_t;
90 #define SEGFUNC(format) { InternalLoadSeg_##format D(, (STRPTR)#format)}
92 static const segfunc_t funcs[] =
94 SEGFUNC(ELF),
95 SEGFUNC(ELF64),
96 #if !defined(__mc68000__) && !defined(__arm__)
97 SEGFUNC(ELF_AROS),
98 #endif
99 SEGFUNC(AOS),
100 SEGFUNC(AOUT)
103 BPTR segs = 0;
105 if (fh)
107 int i = 0;
108 const int num_funcs = sizeof(funcs)/sizeof(funcs[0]);
109 struct MinList *pseginfos;
110 #if AROS_MODULES_DEBUG
111 struct MinList seginfos;
113 NEWLIST(&seginfos);
114 pseginfos = &seginfos;
115 #else
116 pseginfos = NULL;
117 #endif
121 SetIoErr(0);
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
132 if(segs)
134 struct debug_segnode *segnode;
136 Forbid();
137 segnode = (struct debug_segnode *)REMHEAD(&free_debug_segnodes);
138 Permit();
140 if (segnode)
142 struct seginfo *si;
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);
156 #else
157 #warning "if you want gdb debugging of loaded executables implement __AROS_GET_START_ADDR in machine.h"
158 #endif
160 Forbid();
161 ADDTAIL(&debug_seglist, segnode);
162 Permit();
165 #endif
168 return segs;
170 AROS_LIBFUNC_EXIT
171 } /* InternalLoadSeg */