- Don't clear BSS in mach_init() if a kernel is loaded

by our native bootloader.
- Restore lwp0.l_cpu (which is required for curcpu()) and
  cpu_info_store.ci_curlwp after clearing BSS in case
  a kernel is loaded by the firmware directly since these
  values are in BSS and initilized before mach_init() is called.
  (actually they are restored in mips_machdep.c:mips_vector_init()
   but we use curcpu() earlier than that point)

Fixes silent hang right after boot on cobalt.
This commit is contained in:
tsutsui 2007-05-27 14:10:49 +00:00
parent 5964c0cd2d
commit cd02a491e7
1 changed files with 24 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.82 2007/05/17 14:51:16 yamt Exp $ */
/* $NetBSD: machdep.c,v 1.83 2007/05/27 14:10:49 tsutsui Exp $ */
/*
* Copyright (c) 2006 Izumi Tsutsui.
@ -53,7 +53,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.82 2007/05/17 14:51:16 yamt Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.83 2007/05/27 14:10:49 tsutsui Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@ -174,7 +174,7 @@ mach_init(unsigned int memsize, u_int bim, char *bip)
#endif
/*
* Clear the BSS segment.
* Clear the BSS segment (if needed).
*/
#if NKSYMS || defined(DDB) || defined(LKM)
if (memcmp(((Elf_Ehdr *)end)->e_ident, ELFMAG, SELFMAG) == 0 &&
@ -182,12 +182,33 @@ mach_init(unsigned int memsize, u_int bim, char *bip)
esym = end;
esym += ((Elf_Ehdr *)end)->e_entry;
kernend = (char *)mips_round_page(esym);
/*
* We don't have to clear BSS here
* since our bootloader already does it.
*/
#if 0
memset(edata, 0, end - edata);
#endif
} else
#endif
{
kernend = (void *)mips_round_page(end);
/*
* No symbol table, so assume we are loaded by
* the firmware directly with "bfd" command.
* The firmware loader doesn't clear BSS of
* a loaded kernel, so do it here.
*/
memset(edata, 0, kernend - edata);
/*
* XXX
* lwp0 and cpu_info_store are allocated in BSS
* and initialized before mach_init() is called,
* so restore them again.
*/
lwp0.l_cpu = &cpu_info_store;
cpu_info_store.ci_curlwp = &lwp0;
}
/* Check for valid bootinfo passed from bootstrap */