Subject: Re: LKM for MIPS (Qube2)
To: Jowell, Chris {GGRP~Graz} <chris.jowell@Roche.COM>
From: Simon Burge <simonb@wasabisystems.com>
List: port-mips
Date: 05/05/2004 18:24:42
--xHFwDpU9dbj6ez1V
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Wed, May 05, 2004 at 10:04:58AM +0200, Jowell, Chris {GGRP~Graz} wrote:
> Hi,
>
> I was trying to enable loadable kernel modules for my Qube 2 kernel (using 1.6.1 and then current).
>
> This doesn't appear to be completely implemented for this architecture,
> as the kernel compile complains of numerous undefined variables and then fails.
>
> Looking about I see that support was added for MIPS a while ago,
> but I can find nothing for Qube specifically
>
> Does anyone know what work needs to be done to finalize LKM for the Qube2 Arch?
>
> Or is it that I *really* don't know what I'm doing when I enable LKM for my kernel?
LKMs didn't work for MIPS on NetBSD 1.6.2. The attached diff _may_ work
on the 1.6 branch, but I haven't tested them. If they do work, please
let me know and I'll get them pulled up on to the 1.6 branch.
Simon.
--
Simon Burge <simonb@wasabisystems.com>
NetBSD Development, Support and Service: http://www.wasabisystems.com/
--xHFwDpU9dbj6ez1V
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="mips.lkm.diff"
Index: distrib/sets/lists/base/ad.mips
===================================================================
RCS file: distrib/sets/lists/base/ad.mips
diff -N distrib/sets/lists/base/ad.mips
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ distrib/sets/lists/base/ad.mips 5 May 2004 08:21:37 -0000
@@ -0,0 +1,2 @@
+# $NetBSD$
+./usr/lkm/ldscript base-sys-usr
Index: sbin/modload/a.out.c
===================================================================
RCS file: /cvsroot/src/sbin/modload/a.out.c,v
retrieving revision 1.1
diff -d -p -u -r1.1 a.out.c
--- sbin/modload/a.out.c 13 Jun 1999 12:54:40 -0000 1.1
+++ sbin/modload/a.out.c 5 May 2004 08:21:37 -0000
@@ -68,7 +68,8 @@ a_out_linkcmd(char *buf,
const char *entry,
const char *outfile,
const void *address,
- const char *object)
+ const char *object,
+ const char *ldscript) /* XXX ignored */
{
ssize_t n;
Index: sbin/modload/elf.c
===================================================================
RCS file: /cvsroot/src/sbin/modload/elf.c,v
retrieving revision 1.9
diff -d -p -u -r1.9 elf.c
--- sbin/modload/elf.c 3 Apr 2002 19:03:09 -0000 1.9
+++ sbin/modload/elf.c 5 May 2004 08:21:37 -0000
@@ -320,10 +320,14 @@ elf_mod_sizes(fd, modsize, strtablen, re
* -Ttext address to link text segment to in hex (assumes it's
* a page boundry)
* -Tdata address to link data segment to in hex
- * <target> object file */
+ * <target> object file
+ * -T ldscript linker script (on some archs)
+ */
#define LINKCMD "ld -R %s -e %s -o %s -Ttext %p %s"
#define LINKCMD2 "ld -R %s -e %s -o %s -Ttext %p -Tdata %p %s"
+#define LINKSCRIPTCMD "ld -T %s -R %s -e %s -o %s -Ttext %p %s"
+#define LINKSCRIPTCMD2 "ld -T %s -R %s -e %s -o %s -Ttext %p -Tdata %p %s"
/* make a link command; XXX if data_offset above is non-zero, force
data address to be at start of text + offset */
@@ -334,17 +338,30 @@ elf_linkcmd(char *buf,
const char *entry,
const char *outfile,
const void *address,
- const char *object)
+ const char *object,
+ const char *ldscript)
{
ssize_t n;
- if (data_offset == NULL)
- n = snprintf(buf, len, LINKCMD, kernel, entry,
- outfile, address, object);
- else
- n = snprintf(buf, len, LINKCMD2, kernel, entry,
- outfile, address,
- (const char*)address + data_offset, object);
+ if (ldscript == NULL) {
+ if (data_offset == NULL)
+ n = snprintf(buf, len, LINKCMD, kernel, entry,
+ outfile, address, object);
+ else
+ n = snprintf(buf, len, LINKCMD2, kernel, entry,
+ outfile, address,
+ (const char*)address + data_offset,
+ object);
+ } else {
+ if (data_offset == NULL)
+ n = snprintf(buf, len, LINKSCRIPTCMD, ldscript, kernel,
+ entry, outfile, address, object);
+ else
+ n = snprintf(buf, len, LINKSCRIPTCMD2, ldscript, kernel,
+ entry, outfile, address,
+ (const char*)address + data_offset,
+ object);
+ }
if (n >= len)
errx(1, "link command longer than %lu bytes", (u_long)len);
}
Index: sbin/modload/modload.c
===================================================================
RCS file: /cvsroot/src/sbin/modload/modload.c,v
retrieving revision 1.30
diff -d -p -u -r1.30 modload.c
--- sbin/modload/modload.c 8 Nov 2001 15:33:15 -0000 1.30
+++ sbin/modload/modload.c 5 May 2004 08:21:37 -0000
@@ -79,13 +79,14 @@ prelink(const char *kernel,
const char *entry,
const char *outfile,
const void *address,
- const char *object)
+ const char *object,
+ const char *ldscript)
{
char cmdbuf[1024];
int error = 0;
- linkcmd(cmdbuf, sizeof(cmdbuf),
- kernel, entry, outfile, address, object);
+ linkcmd(cmdbuf, sizeof(cmdbuf), kernel, entry, outfile, address, object,
+ ldscript);
if (debug)
fprintf(stderr, "%s\n", cmdbuf);
@@ -246,6 +247,7 @@ main(int argc, char **argv)
char *post = NULL;
char *modobj;
char modout[80], *p;
+ char ldscriptname[PATH_MAX], *ldscript = NULL;
struct stat stb;
int strtablen;
size_t modsize; /* XXX */
@@ -299,6 +301,10 @@ main(int argc, char **argv)
atexit(cleanup);
+ strcpy(ldscriptname, "/usr/lkm/ldscript"); /* XXX XXX generate */
+ if (stat(ldscriptname, &stb) == 0)
+ ldscript = ldscriptname;
+
/*
* Open the virtual device device driver for exclusive use (needed
* to write the new module to it as our means of getting it in the
@@ -343,7 +349,7 @@ main(int argc, char **argv)
/*
* Prelink to get file size
*/
- if (prelink(kname, entry, out, 0, modobj))
+ if (prelink(kname, entry, out, 0, modobj, ldscript))
errx(1, "can't prelink `%s' creating `%s'", modobj, out);
if (Sflag == 0)
fileopen |= OUTFILE_CREAT;
@@ -398,7 +404,7 @@ main(int argc, char **argv)
/*
* Relink at kernel load address
*/
- if (prelink(kname, entry, out, (void*)resrv.addr, modobj))
+ if (prelink(kname, entry, out, (void*)resrv.addr, modobj, ldscript))
errx(1, "can't link `%s' creating `%s' bound to %p",
modobj, out, (void*)resrv.addr);
Index: sbin/modload/modload.h
===================================================================
RCS file: /cvsroot/src/sbin/modload/modload.h,v
retrieving revision 1.2
diff -d -p -u -r1.2 modload.h
--- sbin/modload/modload.h 8 Nov 2001 15:33:15 -0000 1.2
+++ sbin/modload/modload.h 5 May 2004 08:21:38 -0000
@@ -38,15 +38,17 @@
int elf_mod_sizes __P((int, size_t *, int *, struct lmc_resrv *,
struct stat *));
void *elf_mod_load __P((int));
-void elf_linkcmd __P((char*, size_t, const char*, const char*,
- const char*, const void*, const char*));
+void elf_linkcmd __P((char *, size_t, const char *, const char *,
+ const char *, const void *, const char *,
+ const char *));
void elf_mod_symload __P((int));
int a_out_mod_sizes __P((int, size_t *, int *, struct lmc_resrv *,
struct stat *));
void *a_out_mod_load __P((int));
-void a_out_linkcmd __P((char*, size_t, const char*, const char*,
- const char*, const void*, const char*));
+void a_out_linkcmd __P((char *, size_t, const char *, const char *,
+ const char *, const void *, const char *,
+ const char *));
void a_out_mod_symload __P((int));
#ifndef USE_AOUT
@@ -61,9 +63,9 @@ void a_out_mod_symload __P((int));
#define linkcmd a_out_linkcmd
#endif
-void loadbuf(void*, size_t);
+void loadbuf(void *, size_t);
void loadspace(size_t);
-void loadsym(void*, size_t);
+void loadsym(void *, size_t);
extern int debug;
extern int verbose;
Index: sys/arch/mips/Makefile
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/Makefile,v
retrieving revision 1.1
diff -d -p -u -r1.1 Makefile
--- sys/arch/mips/Makefile 12 Jun 1998 23:22:39 -0000 1.1
+++ sys/arch/mips/Makefile 5 May 2004 08:21:38 -0000
@@ -1,5 +1,5 @@
# $NetBSD: Makefile,v 1.1 1998/06/12 23:22:39 cgd Exp $
-SUBDIR= include
+SUBDIR= conf include
.include <bsd.kinc.mk>
Index: sys/arch/mips/conf/Makefile
===================================================================
RCS file: sys/arch/mips/conf/Makefile
diff -N sys/arch/mips/conf/Makefile
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ sys/arch/mips/conf/Makefile 5 May 2004 08:21:38 -0000
@@ -0,0 +1,10 @@
+# $NetBSD
+
+NOOBJ= # defined
+
+FILES= kern.ldscript
+FILESNAME_kern.ldscript= ldscript
+FILESDIR= /usr/lkm
+FILESMODE= 444
+
+.include <bsd.prog.mk>
--xHFwDpU9dbj6ez1V--