Module Name:    src
Committed By:   tsutsui
Date:           Fri Jan 18 18:41:12 UTC 2013

Modified Files:
        src/sys/arch/luna68k/luna68k: locore.s machdep.c

Log Message:
Handle ddb symbol table loaded by the native bootloader properly.
 - add a function that check if the symbol table is loaded and
  return the table size (taken from sun3/sun3/locore2.c)
 - calculate end of symbol table address in locore.s
 - call ksym_addsyms_elf() with proper args


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/luna68k/luna68k/locore.s
cvs rdiff -u -r1.93 -r1.94 src/sys/arch/luna68k/luna68k/machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/luna68k/luna68k/locore.s
diff -u src/sys/arch/luna68k/luna68k/locore.s:1.49 src/sys/arch/luna68k/luna68k/locore.s:1.50
--- src/sys/arch/luna68k/luna68k/locore.s:1.49	Sat Jul 28 17:33:53 2012
+++ src/sys/arch/luna68k/luna68k/locore.s	Fri Jan 18 18:41:12 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.s,v 1.49 2012/07/28 17:33:53 tsutsui Exp $ */
+/* $NetBSD: locore.s,v 1.50 2013/01/18 18:41:12 tsutsui Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -107,8 +107,6 @@ ASENTRY_NOPROFILE(start)
 	movl	%d7,%a0@		| save boothowto
 	RELOC(bootdev,%a0)
 	movl	%d6,%a0@		| save bootdev
-	RELOC(esym,%a0)
-	movl	%d5,%a0@		| save esym
 #endif
 	RELOC(edata,%a0)		| clear out BSS
 	movl	#_C_LABEL(end)-4,%d0	| (must be <= 256 kB)
@@ -117,10 +115,6 @@ ASENTRY_NOPROFILE(start)
 1:	clrl	%a0@+
 	dbra	%d0,1b
 
-#if 1
-	RELOC(esym,%a0)
-	clrl	%a0@			| store end of symbol table XXX
-#endif
 	RELOC(lowram,%a0)
 	movl	%a5,%a0@		| store start of physical memory
 
@@ -219,6 +213,24 @@ Lstart2:
 	RELOC(physmem,%a0)
 	movl	%d1,%a0@		| and physmem
 
+/* check if symbol table is loaded and set esym address */
+#if NKSYMS || defined(DDB) || defined(LKM)
+	RELOC(end,%a0)
+	pea	%a0@
+	RELOC(_C_LABEL(symtab_size),%a0)
+	jbsr	%a0@			| symtab_size(end)
+	addql	#4,%sp
+	tstl	%d0			| check if valid symtab is loaded
+	jeq	1f			|  no, skip
+	lea	_C_LABEL(end),%a0	| calculate end of symtab address
+	addl	%a0,%d0
+#else
+	clrl	%d0			| no symbol table
+#endif
+1:
+	RELOC(esym,%a0)
+	movl	%d0,%a0@
+	
 /* configure kernel and lwp0 VA space so we can get going */
 #if NKSYMS || defined(DDB) || defined(LKM)
 	RELOC(esym,%a0)			| end of static kernel test/data/syms

Index: src/sys/arch/luna68k/luna68k/machdep.c
diff -u src/sys/arch/luna68k/luna68k/machdep.c:1.93 src/sys/arch/luna68k/luna68k/machdep.c:1.94
--- src/sys/arch/luna68k/luna68k/machdep.c:1.93	Fri Aug 10 12:48:14 2012
+++ src/sys/arch/luna68k/luna68k/machdep.c	Fri Jan 18 18:41:12 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.93 2012/08/10 12:48:14 tsutsui Exp $ */
+/* $NetBSD: machdep.c,v 1.94 2013/01/18 18:41:12 tsutsui Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.93 2012/08/10 12:48:14 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.94 2013/01/18 18:41:12 tsutsui Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -68,6 +68,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 
 #include <sys/kgdb.h>
 #endif
 #include <sys/boot_flag.h>
+#define ELFSIZE 32
+#include <sys/exec_elf.h>
 
 #include <uvm/uvm_extern.h>
 
@@ -117,6 +119,12 @@ int  cpu_dumpsize(void);
 int  cpu_dump(int (*)(dev_t, daddr_t, void *, size_t), daddr_t *);
 void cpu_init_kcore_hdr(void);
 
+#if NKSYMS || defined(DDB) || defined(MODULAR)
+vsize_t symtab_size(vaddr_t);
+#endif
+extern char end[];
+extern void *esym;
+
 /*
  * Machine-independent crash dump header info.
  */
@@ -225,12 +233,7 @@ consinit(void)
 	}
 
 #if NKSYMS || defined(DDB) || defined(MODULAR)
-	{
-		extern char end[];
-		extern int *esym;
-
-		ksyms_addsyms_elf(*(int *)&end, ((int *)&end) + 1, esym);
-	}
+	ksyms_addsyms_elf((esym != NULL) ? 1 : 0, (void *)&end, esym);
 #endif
 #ifdef DDB
 	if (boothowto & RB_KDB)
@@ -238,6 +241,53 @@ consinit(void)
 #endif
 }
 
+#if NKSYMS || defined(DDB) || defined(MODULAR)
+
+/*
+ * Check and compute size of DDB symbols and strings.
+ *
+ * Note this function could be called from locore.s before MMU is turned on
+ * so we should avoid global variables and function calls.
+ */
+vsize_t
+symtab_size(vaddr_t hdr)
+{
+	int i;
+	Elf_Ehdr *ehdr;
+	Elf_Shdr *shp;
+	vaddr_t maxsym;
+
+	/*
+	 * Check the ELF headers.
+	 */
+
+	ehdr = (void *)hdr;
+	if (ehdr->e_ident[EI_MAG0] != ELFMAG0 ||
+	    ehdr->e_ident[EI_MAG1] != ELFMAG1 ||
+	    ehdr->e_ident[EI_MAG2] != ELFMAG2 ||
+	    ehdr->e_ident[EI_MAG3] != ELFMAG3 ||
+	    ehdr->e_ident[EI_CLASS] != ELFCLASS32) {
+		return 0;
+	}
+
+	/*
+	 * Find the end of the symbols and strings.
+	 */
+
+	maxsym = 0;
+	shp = (Elf_Shdr *)(hdr + ehdr->e_shoff);
+	for (i = 0; i < ehdr->e_shnum; i++) {
+		if (shp[i].sh_type != SHT_SYMTAB &&
+		    shp[i].sh_type != SHT_STRTAB) {
+			continue;
+		}
+		maxsym = max(maxsym, shp[i].sh_offset + shp[i].sh_size);
+	}
+
+	return maxsym;
+}
+#endif /* NKSYMS || defined(DDB) || defined(MODULAR) */
+
 /*
  * cpu_startup: allocate memory for variable-sized tables.
  */
@@ -426,7 +476,6 @@ cpu_init_kcore_hdr(void)
 {
 	cpu_kcore_hdr_t *h = &cpu_kcore_hdr;
 	struct m68k_kcore_hdr *m = &h->un._m68k;
-	extern char end[];
 
 	memset(&cpu_kcore_hdr, 0, sizeof(cpu_kcore_hdr)); 
 

Reply via email to