Contiki 3.x
bootstrap_uefi.c
1 /*
2  * Copyright (C) 2015, Intel Corporation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include <Uefi.h>
32 #include <Protocol/LoadedImage.h>
33 
34 #define MAX_MEM_DESC 128
35 
36 void start(void);
37 
38 /* The section attribute below is copied from ATTR_BOOT_CODE in prot-domains.h.
39  * prot-domains.h includes stdlib.h which defines NULL. The UEFI headers also
40  * define NULL, which induces a warning when the compiler detects the conflict.
41  * To avoid that, we avoid including prot-domains.h from this file.
42  */
43 EFI_STATUS EFIAPI __attribute__((section(".boot_text")))
44 uefi_start(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
45 {
46  EFI_MEMORY_DESCRIPTOR mem_map[MAX_MEM_DESC];
47  UINTN mem_map_len = sizeof(mem_map);
48  UINTN mem_map_key;
49  UINTN mem_map_desc_sz;
50  UINT32 mem_map_rev;
51 
52  EFI_STATUS res;
53 
54  res = SystemTable->BootServices->GetMemoryMap(&mem_map_len,
55  mem_map,
56  &mem_map_key,
57  &mem_map_desc_sz,
58  &mem_map_rev);
59  if(res != EFI_SUCCESS) {
60  return EFI_ABORTED;
61  }
62 
63  res = SystemTable->BootServices->ExitBootServices(ImageHandle, mem_map_key);
64  if(res != EFI_SUCCESS) {
65  return EFI_ABORTED;
66  }
67 
68  start();
69 
70  /* Should not be reachable: */
71  return EFI_SUCCESS;
72 }
static void start(void)
Start measurement.
#define __attribute__(nothing)
Define attribute to nothing since it isn't handled by IAR.
Definition: iar.h:194