/joh'liks/ n.,adj. 386BSD

Porting Unix to the 386: A Practical Approach



William & Lynne Jolitz


Our kernel is a UNIX executable file, just like all of its applications. So what does the a.out file, compiled and loaded usiing GCC and utilities look like?




The GCC Executable Format

The GCC Executable Format

Listing 2: Unix Executable File Header (file: exec.h)

/* Excerpted with permission from 4.3BSD include file
 * "/usr/include/sys/exec.h"
 * Redistribution and use in source and binary forms are freely permitted
 * provided that the above copyright notice and attribution and date of work
 * and this paragraph are duplicated in all such forms.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * Header prepended to each a.out file.
 */
struct exec {
        long    a_magic;        /* magic number */
unsigned long   a_text;         /* size of text segment */
unsigned long   a_data;         /* size of initialized data */
unsigned long   a_bss;          /* size of uninitialized data */
unsigned long   a_syms;         /* size of symbol table */
unsigned long   a_entry;        /* entry point */
unsigned long   a_trsize;       /* size of text relocation */
unsigned long   a_drsize;       /* size of data relocation */
};

#define OMAGIC  0407            /* old impure format */
#define NMAGIC  0410            /* read-only text */
#define ZMAGIC  0413            /* demand load format */
The programs to be loaded have been generated on another UNIX system, where the GCC compiler, GAS assembler, and BSD linkage editor provide cross-development support, allowing us to generate BSD a.out format files.

This format is the oldest of the many (and, unfortunately still growing) different UNIX executable file formats. The BSD a.out format consists of a header structure (see Listing 2 for exec.h) that details the size of sections following, the instruction segment (or text), the data segment, relocation information, and finally, a symbol-table segment. At this time, we are interested only in the information contained in instruction and data sections, which we then load into a large, dynamically allocated temporary array, before moving it into position. We do not use the relocation information or the symbol-table segment.




<<BACK NEXT >>



Copyright 1989, 1990, 2006 TeleMuse Partners, William Jolitz and Lynne Jolitz