-I$(EM)/h\
-I$(EM)/modules/h
-LIBS=$(EM)/modules/lib/object.a\
- $(EM)/modules/lib/libstring.a\
- $(EM)/modules/lib/libprint.a\
- $(EM)/modules/lib/liballoc.a\
- $(EM)/modules/lib/libsystem.a
+LIBS=$(EM)/modules/lib/*.a
all : data.o con2.o con4.o relocation.o end_back.o gen1.o gen2.o\
gen4.o init_back.o mysprint.o output.o reloc1.o reloc2.o reloc4.o\
#include <out.h>
#include "mach.h"
+/* Global datastructures :
+ * - 'text_area' points to the text segment, 'text' points to first free
+ * entry in the text segment.
+ * - 'data_area' points to the data segment, 'data' points to the first free
+ * entry in the data segmnet.
+ * - 'string_area' points to the string area, 'string' points to the first free
+ * entry in the string area.
+ * - 'reloc_info' points to the relocation table, 'relo' points to the first
+ * free entry in the relocation table.
+ * - 'symbol_table' points to the symbol table, 'nname' is the index of the
+ * first free entry in the symbol_table. If pointers were used it is a pain
+ * to do a realloc on the symbol table, because all pointers in the
+ * relocation table to the symbol table have to be updated.
+ * - The bss segment contains only one vaue, so its enough to count the
+ * the bytes wanted.
+ * - The 'size_*' variables count the number of entries in each segment.
+ * - 'cur_seg' contains the number of the segment to be filled.
+ * (see "back.h")
+ */
+
char *text_area,
*data_area,
end_back()
{
- sync();
- define_segments();
+ finish_tables();
do_local_relocation();
}
-sync()
+finish_tables()
+
+/* Prepare tables for do_local_relocation() and output().
+ */
{
while ( ( text - text_area) % EM_WSIZE != 0 )
text1( '\0');
while ( ( data - data_area) % EM_WSIZE != 0 )
con1( '\0');
+ define_segments();
}
#include "header.h"
#include "mach.h"
-/* The extnd_*() make a name unique. The resulting string is directly stored
- in the symbol_table (by mysprint()). Later additional fields in the
- symbol_table are filled. For these actions the values of the index in
- the symbol_table and the length of the string are stored.
+/* The extnd_*()s make a name unique. The resulting string is directly stored
+ * in the symbol_table (by mysprint()). Later additional fields in the
+ * symbol_table are filled. For these actions the values of the index in
+ * the symbol_table and the length of the string are stored.
*/
extern int string_lengte, index_symbol_table;
char *calloc();
init_back()
+
+/* Allocate space for the tables and set the default values.
+ */
{
text_area = calloc( MAXTEXT, sizeof( char));
data_area = calloc( MAXDATA, sizeof( char));
save_label( lab)
char *lab;
+
+/* It is now not possible to tell where the label belongs to, so store
+ * the string and remember the returned index to store the missing
+ * information later on (see dump_label()). Two labels at one address
+ * is not allowed.
+ */
{
Label = find_sym( lab, SYMBOL_DEFINITION);
label_waiting = 1;
char *realloc();
+/* The routines allocate more space for the segments and update the
+ * global variables. Each time the space asked for is multiplied with 2.
+ */
+
mem_text()
{
/* print( "text_area too small %d %d \n", text_area, text); */
mem_string()
{
- int i;
+ int i = string - string_area;
/* print( "string_area out of memory %d %d \n", string_area, string);*/
- i = string - string_area;
size_string = 2 * size_string;
string_area = realloc( string_area, sizeof( char) * size_string);
string = string_area + i;
#include "back.h"
/* The following functions are called from reloc1(), reloc2(), reloc4(),
- dump_label().
+ * dump_label().
*/
align_word()
+
+/* Do word allignment.
+ */
{
switch ( cur_seg) {
case SEGTXT : return;
long cur_value()
+
+/* Return the index of the first free entry.
+ */
{
switch( cur_seg) {
case SEGTXT: return text - text_area;
#include <system.h>
#include "data.h"
+/* Mysprint() stores the string directly in the string_arae. This saves
+ * a copy action.
+ */
+
int mysprint( fmt, args)
char *fmt;
int args;
#include "data.h"
output()
-/* Notice : entries in the symbol_table are converted.
+/* Dump the tables.
+ * Notice : entries in the symbol_table are converted.
*/
{
#include "back.h"
#include "header.h"
+/* There are two forms of relocation program counter relative or
+ * absolute.
+ */
+
reloc1( sym, off, pcrel)
char *sym;
arith off;
mem_relo();
relo->or_type = RELO1;
-#ifdef BYTES_REVERSED /* Nog optimaliseren?? */
+#ifdef BYTES_REVERSED
relo->or_type |= RELBR;
#endif
#ifdef WORDS_REVERSED
#include "back.h"
#include "header.h"
+/* There are two forms of relocation program counter relative or
+ * absolute.
+ */
+
reloc2( sym, off, pcrel)
char *sym;
arith off;
mem_relo();
relo->or_type = RELO2;
-#ifdef BYTES_REVERSED /* Nog optimaliseren?? */
+#ifdef BYTES_REVERSED
relo->or_type |= RELBR;
#endif
#ifdef WORDS_REVERSED
#include "back.h"
#include "header.h"
+/* There are two forms of relocation program counter relative or
+ * absolute.
+ */
+
reloc4( sym, off, pcrel)
char *sym;
arith off;
mem_relo();
relo->or_type = RELO4;
-#ifdef BYTES_REVERSED /* Nog optimaliseren?? */
+#ifdef BYTES_REVERSED
relo->or_type |= RELBR;
#endif
#ifdef WORDS_REVERSED
#include <out.h>
#include "back.h"
+/* Solve the local references.
+ */
+
#define seg_index( s) ( nname - SEGBSS - 1 + s)
long get4();
-long base_adres();
extern short get2();
extern char get1();
do_local_relocation()
+
+/* Check if this reference is solvable. External references contain
+ * -1 in 'on_valu'.
+ */
{
register struct outrelo *ptr;
register int s;
do_relo(np,rp)
struct outname *np;
struct outrelo *rp;
+
+/* Solve the reference relative to the start of the segment where the symbol
+ * is defined.
+ */
{
long oldval,newval;
char *sect;
break;
}
- /* nu reloceren tov het segment waar het symbool in voorkomt! */
if ( rp->or_type & RELO4) {
oldval = get4( sect, rp->or_addr);
newval = oldval + np->on_valu;
*/
}
-
-
-long base_adres( seg)
-int seg;
-{
- switch ( seg) {
- case SEGTXT : return( 0);
- case SEGCON : return( text-text_area);
- case SEGBSS : return( text-text_area + data-data_area);
- default : fprint( STDERR, "base_adres() wrong seg %d\n", seg);
- }
-}