Support rastport clipping rectangle for layerless rastports
[tangerine.git] / rom / dos / loadseg.c
blob46f08159eb47bdb11f04b52b60c53bbb56eac454
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: DOS function LoadSeg()
6 Lang: english
7 */
9 #define DEBUG 0
11 #include <dos/dos.h>
12 #include <dos/dosextens.h>
13 #include <proto/dos.h>
14 #include <aros/debug.h>
15 #include "dos_intern.h"
17 #if AROS_MODULES_DEBUG
18 #include <exec/nodes.h>
19 #include <exec/lists.h>
20 #include <string.h>
22 struct MinList debug_seglist, free_debug_segnodes;
24 #endif
26 /*****************************************************************************
28 NAME */
29 #include <proto/dos.h>
31 AROS_LH1(BPTR, LoadSeg,
33 /* SYNOPSIS */
34 AROS_LHA(CONST_STRPTR, name, D1),
36 /* LOCATION */
37 struct DosLibrary *, DOSBase, 25, Dos)
39 /* FUNCTION
40 Loads an executable file into memory. Each hunk of the loadfile
41 is loaded into his own memory section and a handle on all of them
42 is returned. The segments can be freed with UnLoadSeg().
44 INPUTS
45 name - NUL terminated name of the file.
47 RESULT
48 Handle to the loaded executable or NULL if the load failed.
49 IoErr() gives additional information in that case.
51 NOTES
52 This function is built on top of InternalLoadSeg()
54 EXAMPLE
56 BUGS
58 SEE ALSO
59 UnLoadSeg()
61 INTERNALS
63 *****************************************************************************/
65 AROS_LIBFUNC_INIT
66 AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
68 void (* FunctionArray[3])();
69 BPTR file, segs=0;
71 FunctionArray[0] = __AROS_GETVECADDR(DOSBase,7);
72 FunctionArray[1] = __AROS_GETVECADDR(SysBase,33);
73 FunctionArray[2] = __AROS_GETVECADDR(SysBase,35);
75 /* Open the file */
76 D(bug("[LoadSeg] Opening '%s'...\n", name));
77 file = Open (name, FMF_READ);
79 if (file)
81 D(bug("[LoadSeg] Loading '%s'...\n", name));
83 segs = InternalLoadSeg (file, NULL, (void *)FunctionArray, NULL);
85 if (segs)
87 #if AROS_MODULES_DEBUG
88 struct debug_segnode *segnode;
90 Forbid();
91 segnode = (struct debug_segnode *)REMHEAD(&free_debug_segnodes);
92 Permit();
94 if (segnode)
96 NameFromFH(file, segnode->name, sizeof(segnode->name));
98 segnode->seglist = segs;
99 #if defined(__AROS_SET_START_ADDR)
100 __AROS_SET_START_ADDR(segnode);
101 #else
102 #warning "if you want gdb debugging of loaded executables implement __AROS_GET_START_ADDR in machine.h"
103 #endif
105 Forbid();
106 ADDTAIL(&debug_seglist, segnode);
107 Permit();
109 #endif
111 SetIoErr(0);
113 else
114 bug("[LoadSeg] Failed to load '%s'\n", name);
115 Close(file);
117 D(else
118 bug("[LoadSeg] Failed to open '%s'\n", name));
121 /* And return */
122 return segs;
124 AROS_LIBFUNC_EXIT
125 } /* LoadSeg */