Subject: MI loadfile() cannot load a.out kernel properly?
To: None <>
From: Izumi Tsutsui <>
List: tech-kern
Date: 10/03/1999 14:38:18
Are there any ports which use MI loadfile() to load a.out kernel?

I have been working on a kernel boot loader last week,
and I noticed there are some problems in aout_exec() called
from the MI loadfile() function. (in /sys/lib/libsa/loadfile.c)

1) aout_exec() seems to load the kernel into its entry address,
not text start address. So if kernel entry is not at text start,
the kernel would be loaded on wrong address.

2) If the kernel has OMAGIC header, aout_exec() would try to load
the header before the text, but this would cause problem if text
starts at 0x0. 

3) It seems that aout_exec() cannot load NMAGIC kernel correctly. 
Some alignment code seems wrong:

	 * Provide alignment if required
	if (magic == ZMAGIC || magic == NMAGIC) {
		int size = (int)maxp & __LDPGSZ;

		if (flags & LOAD_TEXTA) {
			PROGRESS(("/%d", size));
			BZERO(maxp, size);
		if (flags & (LOAD_TEXTA|COUNT_TEXTA))
			maxp += size;
I guess the size should be like this:
		int size = ((int)maxp & (__LDPGSZ - 1)) ?
			    __LDPGSZ - ((int)maxp & (__LDPGSZ - 1)) : 0;

I'm not familiar with exec header structures so not sure
how should fix these problems.

Any suggestions?
Izumi Tsutsui