diff options
author | Thomas Bushnell <thomas@gnu.org> | 1997-04-04 01:13:44 +0000 |
---|---|---|
committer | Thomas Bushnell <thomas@gnu.org> | 1997-04-04 01:13:44 +0000 |
commit | 8e98bdc7a128545a0b7a8d4686f822719ac74ecb (patch) | |
tree | e33b12a4df3a3665720ce7a8fb08d41a4b6a8551 | |
parent | 2059697c29c926c3ad42efb61993baf2723f0b0e (diff) |
Thu Apr 3 20:00:58 1997 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu>
* elf-load.c (exec_load): Include <elf.h> instead of
<mach/exec/elf.h>. Include "mach-exec.h" instead of
<mach/exec/elf.h>.
(exec_load) [i386]: Check for i386 types directly; abandon old
MY_EI_DATA and MY_E_MACHINE.
* load.c: Include "mach-exec.h" instead of <mach/exec/elf.h>.
* exec.c: Likewise.
* mach-exec.h: New file.
-rw-r--r-- | serverboot/ChangeLog | 11 | ||||
-rw-r--r-- | serverboot/elf-load.c | 12 | ||||
-rw-r--r-- | serverboot/exec.c | 2 | ||||
-rw-r--r-- | serverboot/load.c | 2 | ||||
-rw-r--r-- | serverboot/mach-exec.h | 130 |
5 files changed, 151 insertions, 6 deletions
diff --git a/serverboot/ChangeLog b/serverboot/ChangeLog index 52f60f35..c2caea69 100644 --- a/serverboot/ChangeLog +++ b/serverboot/ChangeLog @@ -1,3 +1,14 @@ +Thu Apr 3 20:00:58 1997 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * elf-load.c (exec_load): Include <elf.h> instead of + <mach/exec/elf.h>. Include "mach-exec.h" instead of + <mach/exec/elf.h>. + (exec_load) [i386]: Check for i386 types directly; abandon old + MY_EI_DATA and MY_E_MACHINE. + * load.c: Include "mach-exec.h" instead of <mach/exec/elf.h>. + * exec.c: Likewise. + * mach-exec.h: New file. + Wed Mar 19 14:45:27 1997 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> * panic.c (panic): Clear possible errors on stdout before printing diff --git a/serverboot/elf-load.c b/serverboot/elf-load.c index 1d103d3c..a30124a2 100644 --- a/serverboot/elf-load.c +++ b/serverboot/elf-load.c @@ -24,8 +24,8 @@ #include <alloca.h> #include <mach/machine/vm_types.h> -#include <mach/exec/elf.h> -#include <mach/exec/exec.h> +#include <elf.h> +#include "mach-exec.h" int exec_load(exec_read_func_t *read, exec_read_exec_func_t *read_exec, void *handle, exec_info_t *out_info) @@ -50,10 +50,14 @@ int exec_load(exec_read_func_t *read, exec_read_exec_func_t *read_exec, return EX_NOT_EXECUTABLE; /* Make sure the file is of the right architecture. */ +#ifdef i386 if ((x.e_ident[EI_CLASS] != ELFCLASS32) || - (x.e_ident[EI_DATA] != MY_EI_DATA) || - (x.e_machine != MY_E_MACHINE)) + (x.e_ident[EI_DATA] != ELFDATA2LSB) || + (x.e_machine != EM_386)) return EX_WRONG_ARCH; +#else +#error Not ported to this architecture! +#endif /* XXX others */ out_info->entry = (vm_offset_t) x.e_entry; diff --git a/serverboot/exec.c b/serverboot/exec.c index 5b5feedc..a0773f4c 100644 --- a/serverboot/exec.c +++ b/serverboot/exec.c @@ -30,7 +30,7 @@ #include <mach.h> #include <mach/machine/vm_param.h> #include <mach/machine/eflags.h> -#include <mach/exec/exec.h> +#include "mach-exec.h" #include <file_io.h> diff --git a/serverboot/load.c b/serverboot/load.c index 9a3e3b98..36e8307b 100644 --- a/serverboot/load.c +++ b/serverboot/load.c @@ -27,7 +27,7 @@ #include <assert.h> #include <mach/mach_interface.h> #include <varargs.h> -#include <mach/exec/exec.h> +#include "mach-exec.h" #include "../boot/boot_script.h" #include <file_io.h> diff --git a/serverboot/mach-exec.h b/serverboot/mach-exec.h new file mode 100644 index 00000000..94b234b0 --- /dev/null +++ b/serverboot/mach-exec.h @@ -0,0 +1,130 @@ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +#ifndef _MACH_EXEC_H_ +#define _MACH_EXEC_H_ + +#include <mach/machine/vm_types.h> +#include <mach/vm_prot.h> + +/* XXX */ +typedef enum +{ + EXEC_ELF = 1, + EXEC_AOUT = 2, +} exec_format_t; + +typedef struct exec_info +{ + /* Format of executable loaded - see above. */ + exec_format_t format; + + /* Program entrypoint. */ + vm_offset_t entry; + + /* Initial data pointer - only some architectures use this. */ + vm_offset_t init_dp; + + /* (ELF) Address of interpreter string for loading shared libraries, null if none. */ + vm_offset_t interp; + +} exec_info_t; + +typedef int exec_sectype_t; +#define EXEC_SECTYPE_READ VM_PROT_READ +#define EXEC_SECTYPE_WRITE VM_PROT_WRITE +#define EXEC_SECTYPE_EXECUTE VM_PROT_EXECUTE +#define EXEC_SECTYPE_PROT_MASK VM_PROT_ALL +#define EXEC_SECTYPE_ALLOC ((exec_sectype_t)0x000100) +#define EXEC_SECTYPE_LOAD ((exec_sectype_t)0x000200) +#define EXEC_SECTYPE_DEBUG ((exec_sectype_t)0x010000) +#define EXEC_SECTYPE_AOUT_SYMTAB ((exec_sectype_t)0x020000) +#define EXEC_SECTYPE_AOUT_STRTAB ((exec_sectype_t)0x040000) + +typedef int exec_read_func_t(void *handle, vm_offset_t file_ofs, + void *buf, vm_size_t size, + vm_size_t *out_actual); + +typedef int exec_read_exec_func_t(void *handle, + vm_offset_t file_ofs, vm_size_t file_size, + vm_offset_t mem_addr, vm_size_t mem_size, + exec_sectype_t section_type); + +/* + * Routines exported from libmach_exec.a + */ + +/* Generic function to interpret an executable "file" + and "load" it into "memory". + Doesn't really know about files, loading, or memory; + all file I/O and destination memory accesses + go through provided functions. + Thus, this is a very generic loading mechanism. + + The read() function is used to read metadata from the file + into the local address space. + + The read_exec() function is used to load the actual sections. + It is used for all kinds of sections - code, data, bss, debugging data. + The 'section_type' parameter specifies what type of section is being loaded. + + For code, data, and bss, the EXEC_SECTYPE_ALLOC flag will be set. + For code and data (i.e. stuff that's actually loaded from the file), + EXEC_SECTYPE_LOAD will also be set. + The EXEC_SECTYPE_PROT_MASK contains the intended access permissions + for the section. + 'file_size' may be less than 'mem_size'; + the remaining data must be zero-filled. + 'mem_size' is always greater than zero, but 'file_size' may be zero + (e.g. in the case of a bss section). + No two read_exec() calls for one executable + will load data into the same virtual memory page, + although they may load from arbitrary (possibly overlapping) file positions. + + For sections that aren't normally loaded into the process image + (e.g. debug sections), EXEC_SECTYPE_ALLOC isn't set, + but some other appropriate flag is set to indicate the type of section. + + The 'handle' is an opaque pointer which is simply passed on + to the read() and read_exec() functions. + + On return, the specified info structure is filled in + with information about the loaded executable. +*/ +int exec_load(exec_read_func_t *read, exec_read_exec_func_t *read_exec, + void *handle, exec_info_t *out_info); + +/* + * Error codes + */ + +#define EX_NOT_EXECUTABLE 6000 /* not a recognized executable format */ +#define EX_WRONG_ARCH 6001 /* valid executable, but wrong arch. */ +#define EX_CORRUPT 6002 /* recognized executable, but mangled */ +#define EX_BAD_LAYOUT 6003 /* something wrong with the memory or file image layout */ + + +#endif /* _MACH_EXEC_H_ */ |