Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/luna68k/luna68k Handle ddb symbol table loaded by t...



details:   https://anonhg.NetBSD.org/src/rev/73ab8ee91e15
branches:  trunk
changeset: 784112:73ab8ee91e15
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Fri Jan 18 18:41:12 2013 +0000

description:
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

diffstat:

 sys/arch/luna68k/luna68k/locore.s  |  26 ++++++++++---
 sys/arch/luna68k/luna68k/machdep.c |  67 ++++++++++++++++++++++++++++++++-----
 2 files changed, 77 insertions(+), 16 deletions(-)

diffs (170 lines):

diff -r f720f9526c4b -r 73ab8ee91e15 sys/arch/luna68k/luna68k/locore.s
--- a/sys/arch/luna68k/luna68k/locore.s Fri Jan 18 18:12:56 2013 +0000
+++ b/sys/arch/luna68k/luna68k/locore.s Fri Jan 18 18:41:12 2013 +0000
@@ -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 @@
        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 @@
 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 @@
        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
diff -r f720f9526c4b -r 73ab8ee91e15 sys/arch/luna68k/luna68k/machdep.c
--- a/sys/arch/luna68k/luna68k/machdep.c        Fri Jan 18 18:12:56 2013 +0000
+++ b/sys/arch/luna68k/luna68k/machdep.c        Fri Jan 18 18:41:12 2013 +0000
@@ -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 @@
 #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_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 @@
        }
 
 #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 @@
 #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_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)); 
 



Home | Main Index | Thread Index | Old Index