From patchwork Sat Jun 28 01:25:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 32649 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E6B9B200B9 for ; Sat, 28 Jun 2014 01:27:32 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id eu11sf24374775pac.10 for ; Fri, 27 Jun 2014 18:27:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=3Zm2iS9b4XP81xhzxFYcGCq3NH5Uz3q8DcvzmPS8V1M=; b=IZIXx/1r6KxwQxoGxj/YSa6aFZLEdtcIaU/yOEaiL/8eVXpM85nPXKY3JldCrYP/cD rW1a6q3D1p6bIHmfcc6spAOrwh9Rsm5n4cYR/gpBJShvrsbRU1oMdEeBdHaYh+C4F4Wq HSRQfNeIzym6bdsSwNA8/1krYNpnUBQYD8Ffn6BOyNItZLgwTFZEMJpYWpRa2HPJyUpk najt+TVc8ffc0fDE0sg54rQhDRZs4lPBHZOUoa8i210XE/rrU1Ue5fWxWab9ZmSrdHie 74vcMe9oKTuNi+jZcJabs7UJpHrpPn5IoEZ6jxRQ4HaZ5EaDBDYgYZLJJVgmqJ0rZTmZ 6ieA== X-Gm-Message-State: ALoCoQnR51U2a7LbFUxVvCd4NIE/Nq4fYmC4SUfbWijosCRLRDah0qPKDT0yjhLEV6QXEyRMHHy9 X-Received: by 10.67.4.202 with SMTP id cg10mr14480408pad.42.1403918852246; Fri, 27 Jun 2014 18:27:32 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.46.99 with SMTP id j90ls794709qga.49.gmail; Fri, 27 Jun 2014 18:27:32 -0700 (PDT) X-Received: by 10.52.92.82 with SMTP id ck18mr19315694vdb.6.1403918852126; Fri, 27 Jun 2014 18:27:32 -0700 (PDT) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id sc8si5499119veb.26.2014.06.27.18.27.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Jun 2014 18:27:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.178 as permitted sender) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id oy12so6076531veb.23 for ; Fri, 27 Jun 2014 18:27:32 -0700 (PDT) X-Received: by 10.52.241.76 with SMTP id wg12mr19255799vdc.5.1403918851880; Fri, 27 Jun 2014 18:27:31 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp147849vcb; Fri, 27 Jun 2014 18:27:31 -0700 (PDT) X-Received: by 10.52.252.226 with SMTP id zv2mr19181107vdc.19.1403918851552; Fri, 27 Jun 2014 18:27:31 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id ls1si7213987vcb.99.2014.06.27.18.27.31 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 27 Jun 2014 18:27:31 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X0hP6-0007Q2-1f; Sat, 28 Jun 2014 01:26:08 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X0hP4-0007O4-LE for xen-devel@lists.xen.org; Sat, 28 Jun 2014 01:26:06 +0000 Received: from [85.158.143.35:17467] by server-3.bemta-4.messagelabs.com id 38/78-16194-EA91EA35; Sat, 28 Jun 2014 01:26:06 +0000 X-Env-Sender: roy.franz@linaro.org X-Msg-Ref: server-3.tower-21.messagelabs.com!1403918763!14110736!1 X-Originating-IP: [209.85.192.174] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18953 invoked from network); 28 Jun 2014 01:26:04 -0000 Received: from mail-pd0-f174.google.com (HELO mail-pd0-f174.google.com) (209.85.192.174) by server-3.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 28 Jun 2014 01:26:04 -0000 Received: by mail-pd0-f174.google.com with SMTP id y10so5116011pdj.19 for ; Fri, 27 Jun 2014 18:26:03 -0700 (PDT) X-Received: by 10.68.254.70 with SMTP id ag6mr34794808pbd.33.1403918763114; Fri, 27 Jun 2014 18:26:03 -0700 (PDT) Received: from rfranz-t520.local (c-24-10-97-91.hsd1.ca.comcast.net. [24.10.97.91]) by mx.google.com with ESMTPSA id eh4sm16637918pbc.79.2014.06.27.18.26.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Jun 2014 18:26:02 -0700 (PDT) From: Roy Franz To: xen-devel@lists.xen.org, ian.campbell@citrix.com, stefano.stabellini@citrix.com, tim@xen.org, jbeulich@suse.com, keir@xen.org Date: Sat, 28 Jun 2014 02:25:31 +0100 Message-Id: <1403918735-30027-16-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1403918735-30027-1-git-send-email-roy.franz@linaro.org> References: <1403918735-30027-1-git-send-email-roy.franz@linaro.org> Cc: Roy Franz , fu.wei@linaro.org, linaro-uefi@lists.linaro.org Subject: [Xen-devel] [PATCH RFC 15/19] Add PE/COFF header in head.S X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: roy.franz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: This patch adds a simple PE/COFF header in head.S. PE/COFF linker support is not available for arm64, so a native build is not possible. Also, this allows the binary to be both a PE/COFF EFI application, and a normal Image file bootable like a Linux kernel. The arm and arm64 Linux kernels use the same methodology to create a single image that is both an EFI application and a zImage/Image file. Signed-off-by: Roy Franz --- xen/arch/arm/arm64/head.S | 118 +++++++++++++++++++++++++++++++++++++++++++++- xen/arch/arm/xen.lds.S | 1 + 2 files changed, 117 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 2a13527..9b88aeb 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -84,7 +84,7 @@ #endif /* !CONFIG_EARLY_PRINTK */ /*.aarch64*/ - +#define CONFIG_EFI_STUB /* * Kernel startup entry point. * --------------------------- @@ -100,12 +100,24 @@ */ .global start +efi_stub_entry: /* Dummy symbol so we can compile before actual stub added */ start: +#ifdef CONFIG_EFI_STUB /* * DO NOT MODIFY. Image header expected by Linux boot-loaders. */ - b real_start /* branch to kernel start, magic */ +efi_head: + /* + * This add instruction has no meaningful effect except that + * its opcode forms the magic "MZ" signature of a PE/COFF file + * that is required for UEFI applications. + */ + add x13, x18, #0x16 + b real_start /* branch to kernel start */ +#else + b real_start /* branch to kernel start */ .long 0 /* reserved */ +#endif .quad 0 /* Image load offset from start of RAM */ .quad 0 /* reserved */ .quad 0 /* reserved */ @@ -116,7 +128,109 @@ start: .byte 0x52 .byte 0x4d .byte 0x64 +#ifdef CONFIG_EFI_STUB + .long pe_header - efi_head /* Offset to the PE header. */ +#else .word 0 /* reserved */ +#endif + +#ifdef CONFIG_EFI_STUB + .align 3 +pe_header: + .ascii "PE" + .short 0 +coff_header: + .short 0xaa64 // AArch64 + .short 2 // nr_sections + .long 0 // TimeDateStamp + .long 0 // PointerToSymbolTable + .long 1 // NumberOfSymbols + .short section_table - optional_header // SizeOfOptionalHeader + .short 0x206 // Characteristics. + // IMAGE_FILE_DEBUG_STRIPPED | + // IMAGE_FILE_EXECUTABLE_IMAGE | + // IMAGE_FILE_LINE_NUMS_STRIPPED +optional_header: + .short 0x20b // PE32+ format + .byte 0x02 // MajorLinkerVersion + .byte 0x14 // MinorLinkerVersion + .long __init_end_efi - real_start // SizeOfCode + .long 0 // SizeOfInitializedData + .long 0 // SizeOfUninitializedData + .long efi_stub_entry - efi_head // AddressOfEntryPoint + .long real_start - efi_head // BaseOfCode + +extra_header_fields: + .quad 0 // ImageBase + .long 0x200000 // SectionAlignment (2MByte) + .long 0x8 // FileAlignment + .short 0 // MajorOperatingSystemVersion + .short 0 // MinorOperatingSystemVersion + .short 0 // MajorImageVersion + .short 0 // MinorImageVersion + .short 0 // MajorSubsystemVersion + .short 0 // MinorSubsystemVersion + .long 0 // Win32VersionValue + + .long __init_end_efi - efi_head // SizeOfImage + + // Everything before the kernel image is considered part of the header + .long real_start - efi_head // SizeOfHeaders + .long 0 // CheckSum + .short 0xa // Subsystem (EFI application) + .short 0 // DllCharacteristics + .quad 0 // SizeOfStackReserve + .quad 0 // SizeOfStackCommit + .quad 0 // SizeOfHeapReserve + .quad 0 // SizeOfHeapCommit + .long 0 // LoaderFlags + .long 0x6 // NumberOfRvaAndSizes + + .quad 0 // ExportTable + .quad 0 // ImportTable + .quad 0 // ResourceTable + .quad 0 // ExceptionTable + .quad 0 // CertificationTable + .quad 0 // BaseRelocationTable + + // Section table +section_table: + + /* + * The EFI application loader requires a relocation section + * because EFI applications must be relocatable. This is a + * dummy section as far as we are concerned. + */ + .ascii ".reloc" + .byte 0 + .byte 0 // end of 0 padding of section name + .long 0 + .long 0 + .long 0 // SizeOfRawData + .long 0 // PointerToRawData + .long 0 // PointerToRelocations + .long 0 // PointerToLineNumbers + .short 0 // NumberOfRelocations + .short 0 // NumberOfLineNumbers + .long 0x42100040 // Characteristics (section flags) + + + .ascii ".text" + .byte 0 + .byte 0 + .byte 0 // end of 0 padding of section name + .long __init_end_efi - real_start // VirtualSize + .long real_start - efi_head // VirtualAddress + .long __init_end_efi - real_start // SizeOfRawData + .long real_start - efi_head // PointerToRawData + + .long 0 // PointerToRelocations (0 for executables) + .long 0 // PointerToLineNumbers (0 for executables) + .short 0 // NumberOfRelocations (0 for executables) + .short 0 // NumberOfLineNumbers (0 for executables) + .long 0xe0500020 // Characteristics (section flags) + .align 5 +#endif real_start: msr DAIFSet, 0xf /* Disable all interrupts */ diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index be55dad..62b9d5b 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -135,6 +135,7 @@ SECTIONS *(.xsm_initcall.init) __xsm_initcall_end = .; } :text + __init_end_efi = .; . = ALIGN(STACK_SIZE); __init_end = .;