summaryrefslogtreecommitdiffstats
path: root/sys/ddb
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>2002-09-15 21:49:13 +0000
committerbde <bde@FreeBSD.org>2002-09-15 21:49:13 +0000
commitf2b1deb3e0a6a616985f728745fae05aeb2b18cd (patch)
tree9c972726ddb94b6e1d379684d8ad98ec1a0aef94 /sys/ddb
parentb1a95d8312a609032f4b724907a5070e6870fddf (diff)
downloadFreeBSD-src-f2b1deb3e0a6a616985f728745fae05aeb2b18cd.zip
FreeBSD-src-f2b1deb3e0a6a616985f728745fae05aeb2b18cd.tar.gz
Made this work on i386's at least. It wants ELF section headers for
symbol table sections. Reconstruct the necessary section headers from (ksym_start, ksym_end). This was much easier than converting to use module metadata, and just works for static symbols, unlike db_kld when there is no module metadata. Initialize (ksym_start, ksym_end) from bootinfo on i386's only. The boot loader should load section headers for all sections that it loads, and apparently did this for at least the symbol table sections when this file last worked under FreeBSD (on alphas only) and always did this under NetBSD (where this file was obtained from). At least on i386's, boot2 discards the section headers (except for converting them to (bootinfo.bi_symtab, bootinfo.bi_esymtab), and as far as I can tell, loader(8) discards them apart from converting them to the bootinfo values and module metadata.
Diffstat (limited to 'sys/ddb')
-rw-r--r--sys/ddb/db_elf.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/sys/ddb/db_elf.c b/sys/ddb/db_elf.c
index 3a77089..f683a35 100644
--- a/sys/ddb/db_elf.c
+++ b/sys/ddb/db_elf.c
@@ -49,6 +49,9 @@
#include <sys/systm.h>
#include <sys/proc.h>
+#ifdef __i386__
+#include <machine/bootinfo.h>
+#endif
#include <machine/db_machdep.h>
#include <ddb/ddb.h>
@@ -385,9 +388,38 @@ extern void *ksym_start, *ksym_end;
void
kdb_init(void)
{
+ static Elf_Ehdr elf;
+ static Elf_Shdr sh[2];
+
+#ifdef __i386__
+ ksym_start = (void *)bootinfo.bi_symtab;
+ ksym_end = (void *)bootinfo.bi_esymtab;
+#endif
+ if (ksym_end <= ksym_start)
+ return;
- if (ksym_end > ksym_start)
- X_db_sym_init(ksym_start, ksym_end, "kernel");
+ /*
+ * The FreeBSD boot program doesn't actually load any headers, so
+ * fake just enough for the routines in this file to work.
+ */
+ elf.e_ident[EI_MAG0] = ELFMAG0;
+ elf.e_ident[EI_MAG1] = ELFMAG1;
+ elf.e_ident[EI_MAG2] = ELFMAG2;
+ elf.e_ident[EI_MAG3] = ELFMAG3;
+ elf.e_machine = EM_486;
+ elf.e_shoff = (uintptr_t)(void *)&sh[0] - (uintptr_t)(void *)&elf;
+ sh[0].sh_type = SHT_SYMTAB;
+ sh[0].sh_offset = (uintptr_t)ksym_start + sizeof(long) -
+ (uintptr_t)(void *)&elf;
+ sh[0].sh_size = *(int *)ksym_start;
+ sh[1].sh_type = SHT_STRTAB;
+ sh[1].sh_offset = sh[0].sh_offset + sh[0].sh_size + sizeof(long);
+ sh[1].sh_size = (uintptr_t)ksym_end - (uintptr_t)ksym_start -
+ sizeof(long) - sh[0].sh_size - sizeof(long);
+ elf.e_shstrndx = -1;
+ elf.e_shnum = 2;
+
+ X_db_sym_init(&elf, ksym_end, "kernel");
}
#endif /* DDB_NOKLDSYM */
OpenPOWER on IntegriCloud