Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/ews4800mips/stand/common Fix "illegal exceptoin" er...



details:   https://anonhg.NetBSD.org/src/rev/e12b4291ccdd
branches:  trunk
changeset: 934100:e12b4291ccdd
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sun Jun 07 03:00:53 2020 +0000

description:
Fix "illegal exceptoin" error on loading a secondary boot.

Recent gcc/binutils create more than two problem header sections
so the primary bootxx should handle them accordingly.
See my port-mips@ port for more details:
 https://mail-index.netbsd.org/port-mips/2020/06/06/msg000948.html

Should be pulled up to netbsd-9.

diffstat:

 sys/arch/ews4800mips/stand/common/bootxx.c |  42 +++++++++++++++++++++++------
 1 files changed, 33 insertions(+), 9 deletions(-)

diffs (72 lines):

diff -r 6f371617e8cb -r e12b4291ccdd sys/arch/ews4800mips/stand/common/bootxx.c
--- a/sys/arch/ews4800mips/stand/common/bootxx.c        Sun Jun 07 00:51:48 2020 +0000
+++ b/sys/arch/ews4800mips/stand/common/bootxx.c        Sun Jun 07 03:00:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootxx.c,v 1.5 2009/02/04 15:22:13 tsutsui Exp $       */
+/*     $NetBSD: bootxx.c,v 1.6 2020/06/07 03:00:53 tsutsui Exp $       */
 
 /*-
  * Copyright (c) 2004, 2005 The NetBSD Foundation, Inc.
@@ -46,6 +46,10 @@
 
 #include "common.h"
 
+#define        IS_TEXT(p)      (p.p_flags & PF_X)
+#define        IS_DATA(p)      ((p.p_flags & PF_X) == 0)
+#define        IS_BSS(p)       (p.p_filesz < p.p_memsz)
+
 #define        FILHSZ  (sizeof(struct ecoff_filehdr))
 #define        SCNHSZ  (sizeof(struct ecoff_scnhdr))
 #define        N_TXTOFF(f, a)                                                  \
@@ -186,6 +190,7 @@
 {
        Elf32_Ehdr *e = (void *)buf;
        Elf32_Phdr *p;
+       int i;
 
        if (e->e_ident[EI_MAG2] != 'L' || e->e_ident[EI_MAG3] != 'F' ||
            e->e_ident[EI_CLASS] != ELFCLASS32 ||
@@ -197,16 +202,35 @@
        BASSERT(e->e_phentsize == sizeof(Elf32_Phdr));
        p = (void *)(buf + e->e_phoff);
 #ifdef _STANDALONE
-       memcpy((void *)p->p_vaddr, buf + p->p_offset, p->p_filesz);
-       p++;
-       memcpy((void *)p->p_vaddr, buf + p->p_offset, p->p_filesz);
+       for (i = 0; i < e->e_phnum; i++) {
+               if (p[i].p_type != PT_LOAD ||
+                   (p[i].p_flags & (PF_W|PF_R|PF_X)) == 0)
+                       continue;
+               if (IS_TEXT(p[i]) || IS_DATA(p[i])) {
+                       memcpy((void *)p[i].p_vaddr,
+                           buf + p[i].p_offset, p[i].p_filesz);
+               }
+               if (IS_BSS(p[i])) {
+                       memset((void *)(p[i].p_vaddr + p[i].p_filesz), 0,
+                           p[i].p_memsz - p[i].p_filesz);
+               }
+       }
 #else
        DPRINTF("ELF entry point 0x%08x\n", e->e_entry);
-       DPRINTF("[text] 0x%08x 0x%x %dbyte.\n", p->p_vaddr, p->p_offset,
-           p->p_filesz);
-       p++;
-       DPRINTF("[data] 0x%08x 0x%x %dbyte.\n", p->p_vaddr, p->p_offset,
-           p->p_filesz);
+       for (i = 0; i < e->e_phnum; i++) {
+               if (p[i].p_type != PT_LOAD ||
+                   (p[i].p_flags & (PF_W|PF_R|PF_X)) == 0)
+                       continue;
+               if (IS_TEXT(p[i]) || IS_DATA(p[i])) {
+                       DPRINTF("[text/data] 0x%08x 0x%x %dbyte.\n",
+                           p[i].p_vaddr, p[i].p_offset, p[i].p_filesz);
+               }
+               if (IS_BSS(p[i])) {
+                       DPRINTF("[bss] 0x%08x %dbyte.\n",
+                           p[i].p_vaddr + p[i].p_filesz,
+                           p[i].p_memsz - p[i].p_filesz);
+               }
+       }
 #endif
        *entry = e->e_entry;
 



Home | Main Index | Thread Index | Old Index