/*-1* Copyright (c) 2014, 2015 Andrew Turner2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526#include <machine/asm.h>2728/*29* We need to be a PE32 file for EFI. On some architectures we can use30* objcopy to create the correct file, however on arm we need to do31* it ourselves.32*/3334#define IMAGE_FILE_MACHINE_ARM 0x01c23536#define IMAGE_SCN_CNT_CODE 0x0000002037#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x0000004038#define IMAGE_SCN_MEM_DISCARDABLE 0x0200000039#define IMAGE_SCN_MEM_EXECUTE 0x2000000040#define IMAGE_SCN_MEM_READ 0x400000004142.section .peheader,"a"43efi_start:44/* The MS-DOS Stub, only used to get the offset of the COFF header */45.ascii "MZ"46.short 047.space 0x3848.long pe_sig - efi_start4950/* The PE32 Signature. Needs to be 8-byte aligned */51.align 352pe_sig:53.ascii "PE"54.short 055coff_head:56.short IMAGE_FILE_MACHINE_ARM /* ARM file */57.short 2 /* 2 Sections */58.long 0 /* Timestamp */59.long 0 /* No symbol table */60.long 0 /* No symbols */61.short section_table - optional_header /* Optional header size */62.short 0 /* Characteristics TODO: Fill in */6364optional_header:65.short 0x010b /* PE32 (32-bit addressing) */66.byte 0 /* Major linker version */67.byte 0 /* Minor linker version */68.long _edata - _end_header /* Code size */69.long 0 /* No initialized data */70.long 0 /* No uninitialized data */71.long _start - efi_start /* Entry point */72.long _end_header - efi_start /* Start of code */73.long 0 /* Start of data */7475optional_windows_header:76.long 0 /* Image base */77.long 32 /* Section Alignment */78.long 8 /* File alignment */79.short 0 /* Major OS version */80.short 0 /* Minor OS version */81.short 0 /* Major image version */82.short 0 /* Minor image version */83.short 0 /* Major subsystem version */84.short 0 /* Minor subsystem version */85.long 0 /* Win32 version */86.long _edata - efi_start /* Image size */87.long _end_header - efi_start /* Header size */88.long 0 /* Checksum */89.short 0xa /* Subsystem (EFI app) */90.short 0 /* DLL Characteristics */91.long 0 /* Stack reserve */92.long 0 /* Stack commit */93.long 0 /* Heap reserve */94.long 0 /* Heap commit */95.long 0 /* Loader flags */96.long 6 /* Number of RVAs */9798/* RVAs: */99.quad 0100.quad 0101.quad 0102.quad 0103.quad 0104.quad 0105106section_table:107/* We need a .reloc section for EFI */108.ascii ".reloc"109.byte 0110.byte 0 /* Pad to 8 bytes */111.long 0 /* Virtual size */112.long 0 /* Virtual address */113.long 0 /* Size of raw data */114.long 0 /* Pointer to raw data */115.long 0 /* Pointer to relocations */116.long 0 /* Pointer to line numbers */117.short 0 /* Number of relocations */118.short 0 /* Number of line numbers */119.long (IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | \120IMAGE_SCN_MEM_DISCARDABLE) /* Characteristics */121122/* The contents of the loader */123.ascii ".text"124.byte 0125.byte 0126.byte 0 /* Pad to 8 bytes */127.long _edata - _end_header /* Virtual size */128.long _end_header - efi_start /* Virtual address */129.long _edata - _end_header /* Size of raw data */130.long _end_header - efi_start /* Pointer to raw data */131.long 0 /* Pointer to relocations */132.long 0 /* Pointer to line numbers */133.short 0 /* Number of relocations */134.short 0 /* Number of line numbers */135.long (IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | \136IMAGE_SCN_MEM_READ) /* Characteristics */137_end_header:138139.text140.globl _start141_start:142/* Save the boot params to the stack */143push {r0, r1}144145adr r0, .Lbase146ldr r1, [r0]147sub r5, r0, r1148149ldr r0, .Limagebase150add r0, r0, r5151ldr r1, .Ldynamic152add r1, r1, r5153154bl _C_LABEL(self_reloc)155156/* Zero the BSS, _reloc fixed the values for us */157ldr r0, .Lbss158ldr r1, .Lbssend159mov r2, #01601611: cmp r0, r1162bge 2f163str r2, [r0], #4164b 1b1652:166167pop {r0, r1}168bl _C_LABEL(efi_main)1691701: b 1b171172.Lbase:173.word .174.Limagebase:175.word ImageBase176.Ldynamic:177.word _DYNAMIC178.Lbss:179.word __bss_start180.Lbssend:181.word __bss_end182183.align 3184stack:185.space 512186stack_end:187188189190