#	$NetBSD: README,v 1.6 2023/05/14 16:13:05 phx Exp $

BUILD INSTRUCTIONS

Building LoadBSD isn't easy since several sources from the NetBSD repository
are required. Compiling these sources under AmigaOS without clashes with the
native GCC headers requires some knowledge. This document tries to describe
the steps necessary to rebuild LoadBSD with a modern AmigaOS gcc, or vbcc
with PosixLib.
These instructions do only apply for LoadBSD versions using the loadfile()
interface. Previous version do only require getopt.c and reboot.h.

Note: It is not possible to build LoadBSD with the native NetBSD compiler!
      LoadBSD is an *AmigaOS* program and must be built with an AmigaOS
      compiler. Of course, a properly setup cross-compiler does work.

Required sources from NetBSD (either HEAD or from a release branch)

   From src/sys/lib/libsa: loadfile.h,loadfile.c,loadfile_elf32.c,loadfile_aout.c

      place these files in the directory where you have loadbsd.c

   From src/sys/arch/m68k/include: aout_machdep.h,elf_machdep.h

      place these files in: <loadbsd directory>/include/m68k

   From src/sys/arch/amiga/include: aout_machdep.h,elf_machdep.h,loadfile_machdep.h

      place these files in: <loadbsd directory>/include/machine

   From src/sys/sys: exec.h,exec_elf.h,exec_aout.h,aout_mids.h,reboot.h

      place these files in: <loadbsd directory>/include/sys

   Additional headers (see below): inttypes.h,namespace.h,lib/libsa/stand.h,lib/libkern/libkern.h

      place these files in: <loadbsd directory>/include

If all the mentioned files are placed at the correct place, loadfile_machdep.h
must be modified. The patch is included below. Another small patch to
loadfile_aout.c must be applied to fix an incompatibility for LoadBSD.
However, that patch breaks loadfile() for other architectures using a.out!
Note: This patch is required to be able to suppress loaded symbols when
      booting ancient a.out kernels that don't support them. Without the
      patch symbol suppressing doesn't work! That also means ELF isn't
      affected and LoadBSD could handle it differently but then it could
      probably break in other unpredictable ways...

The headers inttypes.h, namespace.h, include/lib/libsa/stand.h and
lib/libkern/libkern.h are listed completely below.

Then it should be possible to recompile LoadBSD with gcc6 or newer by
typing "make" (or "make -f vmakefile" with vbcc). If make fails, fix the
problem and try again :-P

Good luck!

--- Missing files/patches ---

      include/machine/loadfile_machdep.h modification:
--cut--
--- include/machine/loadfile_machdep.h~     Sun Mar 26 15:46:55 2023
+++ include/machine/loadfile_machdep.h  Sun Mar 26 15:47:17 2023
@@ -38,7 +38,7 @@
 #define	LOAD_KERNEL		LOAD_ALL
 #define	COUNT_KERNEL		COUNT_ALL
 
-#ifdef _STANDALONE
+#if 0
 
 #define LOADADDR(a)		((a) + offset)
 #define ALIGNENTRY(a)		0
--cut--

      loadfile_aout.c modification:
--cut--
--- loadfile_aout.c~	Mon Feb 11 21:25:56 2002
+++ loadfile_aout.c	Thu Jan 23 10:43:27 2003
@@ -217,8 +217,8 @@ loadfile_aout(fd, x, marks, flags)
 		BCOPY(&x->a_syms, maxp, sizeof(x->a_syms));
 
 	if (flags & (LOAD_SYM|COUNT_SYM)) {
-		maxp += sizeof(x->a_syms);
 		aoutp = maxp;
+		maxp += sizeof(x->a_syms);
 	}
 
 	if (x->a_syms > 0) {
--cut--

      include/inttypes.h:
--cut--
#ifndef _INTTYPES_H
#define _INTTYPES_H

#include <sys/types.h>
#include <sys/cdefs.h>

#ifndef be32toh
#define be32toh(x) (x)
#endif

#ifndef roundup
#define roundup(x,y) ((((x)+((y)-1))/(y))*(y))
#endif

typedef unsigned long vaddr_t;
typedef unsigned long paddr_t;

#endif /* !_INTTYPES_H */
--cut--

    include/namespace.h
--cut--
#define _DIAGASSERT(x) /**/

extern char *program_name;
#define getprogname() program_name

#ifndef __UNCONST
#define __UNCONST(a)   ((void *)(unsigned long)(const void *)(a))
#endif
--cut--

      include/lib/libsa/stand.h
--cut--
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "inttypes.h"
--cut--

      include/lib/libkern/libkern.h
--cut--
/* nothing, must only exist! */
--cut--
