Subject: Loadable Kernel Modules - modload fails?
To: None <port-alpha@NetBSD.ORG>
From: Henry Houh <hhh@dill.lcs.mit.edu>
List: port-alpha
Date: 12/03/1996 16:05:52
Hi,

I am trying to use modload to load some kernel modules.  Is this
supported under the alpha port?  I am still using 1.1.  I had to
change modload (-A to -R, -T to -Ttext) to get it to use the correct
flags for ld, but now modload doesn't properly recognize the output of
ld as valid.

Specifically, this check in modroot.c fails:

	/*
	 * Magic number...
	 */
	if (N_BADMAG(info_buf))
		errx(4, "not an a.out format file");

Any clues?  If the magic number isn't correct, I can try to tell ld
to output in a.out, but I assumed that that was the default output
anyway.  

N_BADMAG (defined in sys/exec_aout.h) is sufficiently heinous that I
can't tell if it is right for the alpha - though the masking
quantities look like 32 bit numbers to me. 

/* Valid magic number check. */
#define	N_BADMAG(ex) \
	(N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \
	N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC)

/*
 * The a.out structure's a_midmag field is a network-byteorder encoding
 * of this int
 *	FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
 * Where `F' is 6 bits of flag like EX_DYNAMIC,
 *       `m' is 10 bits of machine-id like MID_I386, and
 *       `M' is 16 bits worth of magic number, ie. ZMAGIC.
 * The macros below will set/get the needed fields.
 */
#define	N_GETMAGIC(ex) \
    ( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : ((ex).a_midmag))
#define	N_GETMAGIC2(ex) \
    ( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : \
    (((ex).a_midmag) | 0x10000) )
#define	N_GETMID(ex) \
    ( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>16)&0x03ff) : MID_ZERO )
#define	N_GETFLAG(ex) \
    ( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>26)&0x3f) : 0 )
#define	N_SETMAGIC(ex,mag,mid,flag) \
    ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \
    (((mag)&0xffff)) ) )

/* a_magic */
#define	OMAGIC		0407	/* old impure format */
#define	NMAGIC		0410	/* read-only text */
#define	ZMAGIC		0413	/* demand load format */
#define	QMAGIC		0314	/* "compact" demand load format; deprecated */

The head of the file looks like this:

paprika# od lkmodule | more
0000000  000605 000007 000000 000000 060000 000000 000000 000000
0000020  000220 000000 000120 000407 000413 001413 000002 000000
0000040  040000 000000 000000 000000 020000 000000 000000 000000

Any clues?

Thanks,

Henry