Subject: LKMs on the pmax.
To: None <current-users@NetBSD.ORG>
From: Simon Burge <simonb@NetBSD.ORG>
List: current-users
Date: 08/15/1999 16:57:29
I had a quick tinker with LKMs on the pmax, and have hit a few snags.
I'm sure never having used or played with LKMs is part of the problem.
Is there a intro to LKMs on NetBSD anywhere?  I've started by trying to
get the syscall example in /usr/share/lkm working.

The first problem is that the ELF prelink fails, so I told ld(1) to use
the kernel linker script.  Linking then fails cause the module is told
to load at address 0x0 and the kernel symbols are > 0x8000000 - I'm
pretty sure this is too far apart for mips.  Errors look like:

	mona:lkm/syscall/module 52# ld -R /netbsd -G 0 -T /NetBSD/src/sys/arch/mips/ ...
		... conf/kern.ldscript -e newsyscall -o newsyscall -Ttext 0x0 combined.o
	combined.o: In function `newsyscall_load':
	newsyscall.c(.text+0x2c): relocation truncated to fit: R_MIPS_26 printf
	newsyscall.c(.text+0x38): relocation truncated to fit: R_MIPS_26 printf
	newsyscall.c(.text+0x44): relocation truncated to fit: R_MIPS_26 printf
	newsyscall.c(.text+0x50): relocation truncated to fit: R_MIPS_26 printf
	combined.o: In function `newsyscall':
	newsyscall.c(.text+0x140): relocation truncated to fit: R_MIPS_26 lkm_nofunc
	newsyscall.c(.text+0x17c): relocation truncated to fit: R_MIPS_26 lkm_nofunc
	newsyscall.c(.text+0x1b8): relocation truncated to fit: R_MIPS_26 lkmdispatch
	combined.o: In function `mycall':
	mycall.c(.text+0x200): relocation truncated to fit: R_MIPS_26 printf
	mycall.c(.text+0x20c): relocation truncated to fit: R_MIPS_26 printf

Making the prelink use 0x8000000 gave me something that links, but then
elf_mod_sizes seems to have some signed arithmetic problems.  Fixing(?)
that then gives:

	mona:lkm/syscall/module 6# ../../modload/obj.pmax/modload -d -v \
		-o newsyscall -enewsyscall combined.o
	ld -R /netbsd -G 0 -T /NetBSD/src/sys/arch/mips/conf/kern.ldscript \
		-e newsyscall -o newsyscall -Ttext 0x80000000 combined.o
	.text: addr = 0x80000000 size = 0x230 align = 0x10
	.rodata: addr = 0x80000230 size = 0xe0 align = 0x10
	.reginfo: addr = 0x80000310 size = 0x18 align = 0x4
	.data: addr = 0x80001330 size = 0x30 align = 0x10
	.data section forced to offset 0x80000328 (was 0x80001330)
	.bss: addr = 0x80001360 size = 0 align = 0x10
	modload: reserving 4096 bytes of memory
	modload: can't reserve memory: Operation not permitted

It was here that I gave up for now :-(

Can the prelink load the LKM at any address?  I'm running with
securelevel=0 - any hints for the "Operation not permitted"?

Simon.