Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/zaurus Make zaurus kernels use symbol tables loaded...
details: https://anonhg.NetBSD.org/src/rev/9cd3aaa5aac2
branches: trunk
changeset: 1004771:9cd3aaa5aac2
user: tsutsui <tsutsui%NetBSD.org@localhost>
date: Wed Nov 13 17:59:56 2019 +0000
description:
Make zaurus kernels use symbol tables loaded by the bootloader.
Now COPY_SYMTAB is no longer necessary and it saves ~500kbytes of
GENERIC, so re-enable options DDB (i.e. revert GENERIC rev 1.85).
Also fix zbsdmod.o (a kernel loader for Zaurus Linux) to load symbols
at a proper address as the MI sys/lib/libsa/loadfile_elf32.c does.
No particular comment on port-zaurus@:
https://mail-index.netbsd.org/port-zaurus/2019/11/11/msg000086.html
Note zbsdmod.c (derived from OpenBSD/zaurus) assumed that the loaded
kernels had "esym" variable at the top of its data section and
implicitly overwrote it with the address of loaded symbol tables.
OpenBSD/zaurus kernels used the esym value written by the zbsdmod.o
to initialize ksyms(4) on startup, but we will avoid such implicit
MD interface between the bootloader and kernels (though we don't
bother to add a symbol address value into bootinfo but just assume
symbols are loaded at end[] of a loaded kernel, as per the MI
libsa loadfile() implementation).
Worth to pullup to both netbsd-8 and netbsd-9.
diffstat:
sys/arch/zaurus/conf/GENERIC | 7 +-
sys/arch/zaurus/conf/INSTALL | 3 +-
sys/arch/zaurus/stand/zbsdmod/zbsdmod.c | 6 +-
sys/arch/zaurus/zaurus/machdep.c | 72 +++++++++++++++++++++++++++-----
4 files changed, 66 insertions(+), 22 deletions(-)
diffs (191 lines):
diff -r 9d4ded8cb579 -r 9cd3aaa5aac2 sys/arch/zaurus/conf/GENERIC
--- a/sys/arch/zaurus/conf/GENERIC Wed Nov 13 17:52:12 2019 +0000
+++ b/sys/arch/zaurus/conf/GENERIC Wed Nov 13 17:59:56 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.88 2019/11/02 23:13:00 tsutsui Exp $
+# $NetBSD: GENERIC,v 1.89 2019/11/13 17:59:56 tsutsui Exp $
#
# GENERIC machine description file
#
@@ -150,11 +150,10 @@
options DIAGNOSTIC # internal consistency checks
#options DEBUG
#options VERBOSE_INIT_ARM # verbose bootstraping messages
-#options DDB # in-kernel debugger
-#options DDB_HISTORY_SIZE=100 # Enable history editing in DDB
+options DDB # in-kernel debugger
+options DDB_HISTORY_SIZE=100 # Enable history editing in DDB
#options KGDB
#makeoptions DEBUG="-g" # compile full symbol table
-makeoptions COPY_SYMTAB=1
# Kernel root file system and dump configuration.
diff -r 9d4ded8cb579 -r 9cd3aaa5aac2 sys/arch/zaurus/conf/INSTALL
--- a/sys/arch/zaurus/conf/INSTALL Wed Nov 13 17:52:12 2019 +0000
+++ b/sys/arch/zaurus/conf/INSTALL Wed Nov 13 17:59:56 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: INSTALL,v 1.39 2019/02/07 20:56:27 rin Exp $
+# $NetBSD: INSTALL,v 1.40 2019/11/13 17:59:56 tsutsui Exp $
#
# INSTALL config file (GENERIC with memory disk root)
#
@@ -59,7 +59,6 @@
no options DIAGNOSTIC
no options DDB
no options DDB_HISTORY_SIZE
-no makeoptions COPY_SYMTAB
no options PXA2X0_DMAC_DMOVER_CONCURRENCY
diff -r 9d4ded8cb579 -r 9cd3aaa5aac2 sys/arch/zaurus/stand/zbsdmod/zbsdmod.c
--- a/sys/arch/zaurus/stand/zbsdmod/zbsdmod.c Wed Nov 13 17:52:12 2019 +0000
+++ b/sys/arch/zaurus/stand/zbsdmod/zbsdmod.c Wed Nov 13 17:59:56 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: zbsdmod.c,v 1.11 2019/10/28 15:26:09 tsutsui Exp $ */
+/* $NetBSD: zbsdmod.c,v 1.12 2019/11/13 17:59:56 tsutsui Exp $ */
/* $OpenBSD: zbsdmod.c,v 1.7 2005/05/02 02:45:29 uwe Exp $ */
/*
@@ -139,8 +139,8 @@
if (maxv < posv)
maxv = posv;
}
- if (IS_DATA(phdr[i]) && IS_BSS(phdr[i])) {
- posv += phdr[i].p_memsz;
+ if (IS_BSS(phdr[i])) {
+ posv += phdr[i].p_memsz - phdr[i].p_filesz;
if (maxv < posv)
maxv = posv;
}
diff -r 9d4ded8cb579 -r 9cd3aaa5aac2 sys/arch/zaurus/zaurus/machdep.c
--- a/sys/arch/zaurus/zaurus/machdep.c Wed Nov 13 17:52:12 2019 +0000
+++ b/sys/arch/zaurus/zaurus/machdep.c Wed Nov 13 17:59:56 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.44 2019/11/04 10:36:18 tsutsui Exp $ */
+/* $NetBSD: machdep.c,v 1.45 2019/11/13 17:59:56 tsutsui Exp $ */
/* $OpenBSD: zaurus_machdep.c,v 1.25 2006/06/20 18:24:04 todd Exp $ */
/*
@@ -107,7 +107,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.44 2019/11/04 10:36:18 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.45 2019/11/13 17:59:56 tsutsui Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@@ -247,6 +247,12 @@
struct bootinfo *bootinfo;
struct btinfo_howto *bi_howto;
+extern char etext[], end[];
+extern void *esym;
+#if NKSYMS || defined(DDB) || defined(MODULAR)
+#include <sys/exec_elf.h>
+#endif
+
#define KERNEL_BASE_PHYS ((paddr_t)&KERNEL_BASE_phys)
#define BOOTINFO_PAGE (KERNEL_BASE_PHYS - PAGE_SIZE)
@@ -647,6 +653,9 @@
psize_t memsize;
struct pxa2x0_gpioconf **zaurus_gpioconf;
u_int *magicaddr;
+#if NKSYMS || defined(DDB) || defined(MODULAR)
+ u_int symbolsize;
+#endif
/* Get ready for zaurus_restart() */
pxa2x0_memctl_bootstrap(PXA2X0_MEMCTL_BASE);
@@ -917,6 +926,48 @@
pmap_curmaxkvaddr =
KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
+ /* check symbol table loaded by bootloader (zbsdmod.o) */
+ esym = end;
+#if NKSYMS || defined(DDB) || defined(MODULAR)
+ symbolsize = 0;
+ Elf_Ehdr *eh = (Elf_Ehdr *)end;
+#ifdef VERBOSE_INIT_ARM
+ printf("Checking ELF MAGIC at end: %02x %02x %02x %02x\n",
+ end[0], end[1], end[2], end[3]);
+#endif
+ if (memcmp(eh->e_ident, ELFMAG, SELFMAG) == 0) {
+ Elf_Shdr *sh;
+#ifdef VERBOSE_INIT_ARM
+ printf("ELF header found at end\n");
+#endif
+ sh = (Elf_Shdr *)((char *)end + eh->e_shoff);
+ for (loop = 0; loop < eh->e_shnum; loop++, sh++) {
+#ifdef VERBOSE_INIT_ARM
+ printf("Checking ELF header %d\n", loop);
+#endif
+ if (sh->sh_type != SHT_SYMTAB &&
+ sh->sh_type != SHT_STRTAB) {
+ continue;
+ }
+#ifdef VERBOSE_INIT_ARM
+ printf("Section[%2d]: offset = %d, size = %d\n",
+ loop, sh->sh_offset, sh->sh_size);
+#endif
+ if (sh->sh_offset > 0 &&
+ (sh->sh_offset + sh->sh_size) > symbolsize) {
+ symbolsize = sh->sh_offset + sh->sh_size;
+ }
+#ifdef VERBOSE_INIT_ARM
+ printf("Updating symbolsize = %d\n", symbolsize);
+#endif
+ }
+ esym = (char *)esym + symbolsize;
+ }
+#ifdef VERBOSE_INIT_ARM
+ printf("symbolsize = %d\n", symbolsize);
+#endif
+#endif /* NKSYMS || defined(DDB) || defined(MODULAR) */
+
#ifdef VERBOSE_INIT_ARM
printf("Mapping kernel\n");
#endif
@@ -924,9 +975,9 @@
/* Now we fill in the L2 pagetable for the kernel static code/data
* and the symbol table. */
{
- extern char etext[], _end[];
+
size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
- size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
+ size_t totalsize = (uintptr_t) esym - KERNEL_TEXT_BASE;
u_int logical;
textsize = (textsize + PGOFSET) & ~PGOFSET;
@@ -1012,10 +1063,9 @@
* variables.
*/
{
- extern char _end[];
physical_freestart = physical_start +
- ((((uintptr_t) _end + PGOFSET) & ~PGOFSET) - KERNEL_BASE);
+ ((((uintptr_t) esym + PGOFSET) & ~PGOFSET) - KERNEL_BASE);
physical_freeend = physical_end;
free_pages =
(physical_freeend - physical_freestart) / PAGE_SIZE;
@@ -1109,13 +1159,9 @@
md_root_setconf(memory_disk, sizeof memory_disk);
#endif
-#if NKSYMS || defined(MODULAR)
-# ifdef DDB
- ddb_init(0, NULL, NULL);
-# else
- /* Firmware doesn't load symbols. */
- ksyms_addsyms_elf(0, NULL, NULL);
-# endif
+#if NKSYMS || defined(DDB) || defined(MODULAR)
+ if (symbolsize > 0)
+ ksyms_addsyms_elf(symbolsize, &end, esym);
#endif
#ifdef KGDB
Home |
Main Index |
Thread Index |
Old Index