From owner-svn-src-head@freebsd.org Fri Dec 29 20:30:11 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 925FDEAEF25; Fri, 29 Dec 2017 20:30:11 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 66C707A6A3; Fri, 29 Dec 2017 20:30:11 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vBTKUAYY006357; Fri, 29 Dec 2017 20:30:10 GMT (envelope-from nwhitehorn@FreeBSD.org) Received: (from nwhitehorn@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBTKUA2V006354; Fri, 29 Dec 2017 20:30:10 GMT (envelope-from nwhitehorn@FreeBSD.org) Message-Id: <201712292030.vBTKUA2V006354@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: nwhitehorn set sender to nwhitehorn@FreeBSD.org using -f From: Nathan Whitehorn Date: Fri, 29 Dec 2017 20:30:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r327358 - in head/sys: conf powerpc/aim powerpc/include X-SVN-Group: head X-SVN-Commit-Author: nwhitehorn X-SVN-Commit-Paths: in head/sys: conf powerpc/aim powerpc/include X-SVN-Commit-Revision: 327358 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Dec 2017 20:30:11 -0000 Author: nwhitehorn Date: Fri Dec 29 20:30:10 2017 New Revision: 327358 URL: https://svnweb.freebsd.org/changeset/base/327358 Log: Add support for 64-bit PowerPC kernels to be directly loaded by kexec, which is used as the bootloader on a number of PPC64 platforms. This involves the following pieces: - Making the first instruction a valid kernel entry point, since kexec ignores the ELF entry value. This requires a separate section and linker magic to prevent the linker from filling the beginning of the section with stubs. - Adding an entry point at 0x60 past the first instruction for systems lacking firmware CPU shutdown support (notably PS3). - Linker script changes to support the above. MFC after: 1 month Modified: head/sys/conf/ldscript.powerpc64 head/sys/powerpc/aim/locore64.S head/sys/powerpc/include/vmparam.h Modified: head/sys/conf/ldscript.powerpc64 ============================================================================== --- head/sys/conf/ldscript.powerpc64 Fri Dec 29 20:25:15 2017 (r327357) +++ head/sys/conf/ldscript.powerpc64 Fri Dec 29 20:30:10 2017 (r327358) @@ -8,8 +8,12 @@ SEARCH_DIR(/usr/lib); PROVIDE (__stack = 0); SECTIONS { - /* Read-only sections, merged into text segment: */ + /* Low-address wrapper for bootloaders (kexec/kboot) that can't parse ELF */ + . = kernbase - 0x100; + .kboot : { *(.text.kboot) } + + /* Read-only sections, merged into text segment: */ . = kernbase; PROVIDE (begin = .); @@ -27,6 +31,9 @@ SECTIONS /* Do not emit PT_INTERP section, which confuses some loaders (kexec-lite) */ .interpX : { *(.interp) } : NONE /DISCARD/ : { *(.interp) } + + /* Also delete notes */ + /DISCARD/ : { *(.note.*) } .hash : { *(.hash) } .dynsym : { *(.dynsym) } Modified: head/sys/powerpc/aim/locore64.S ============================================================================== --- head/sys/powerpc/aim/locore64.S Fri Dec 29 20:25:15 2017 (r327357) +++ head/sys/powerpc/aim/locore64.S Fri Dec 29 20:30:10 2017 (r327358) @@ -61,6 +61,47 @@ GLOBAL(tmpstk) TOC_ENTRY(tmpstk) +/* + * Entry point for bootloaders that do not fully implement ELF and start + * at the beginning of the image (kexec, notably). In its own section so + * that it ends up before any linker-generated call stubs and actually at + * the beginning of the image. kexec on some systems also enters at + * (start of image) + 0x60, so put a spin loop there. + */ + .section ".text.kboot", "x", @progbits +kbootentry: + b __start +. = kbootentry + 0x40 /* Magic address used in platform layer */ + .global smp_spin_sem +ap_kexec_spin_sem: + .long -1 +. = kbootentry + 0x60 /* Entry point for kexec APs */ +ap_kexec_start: /* At 0x60 past start, copied to 0x60 by kexec */ + /* r3 set to CPU ID by kexec */ + + /* Invalidate icache for low-memory copy and jump there */ + li %r0,0x80 + dcbst 0,%r0 + sync + icbi 0,%r0 + isync + ba 0x78 /* Absolute branch to next inst */ + +1: or 31,31,31 /* yield */ + sync + lwz %r1,0x40(0) /* Spin on ap_kexec_spin_sem */ + cmpw %r1,%r3 /* Until it equals our CPU ID */ + bne 1b + + /* Released */ + or 2,2,2 /* unyield */ + ba EXC_RST + + +/* + * Now start the real text section + */ + .text .globl btext btext: Modified: head/sys/powerpc/include/vmparam.h ============================================================================== --- head/sys/powerpc/include/vmparam.h Fri Dec 29 20:25:15 2017 (r327357) +++ head/sys/powerpc/include/vmparam.h Fri Dec 29 20:30:10 2017 (r327358) @@ -108,7 +108,7 @@ #endif #ifdef AIM -#define KERNBASE 0x00100000UL /* start of kernel virtual */ +#define KERNBASE 0x00100100UL /* start of kernel virtual */ #ifndef __powerpc64__ #define VM_MIN_KERNEL_ADDRESS ((vm_offset_t)KERNEL_SR << ADDR_SR_SHFT)