├── .cherryci └── ci-test ├── .editorconfig ├── .travis.yml ├── AUTHORS ├── AUTHORS-ASL ├── AUTHORS-LGPL ├── LICENSE ├── README ├── meson.build ├── meson_options.txt └── src ├── c-efi-base.h ├── c-efi-protocol-device-path-from-text.h ├── c-efi-protocol-device-path-to-text.h ├── c-efi-protocol-device-path-utility.h ├── c-efi-protocol-device-path.h ├── c-efi-protocol-loaded-image-device-path.h ├── c-efi-protocol-loaded-image.h ├── c-efi-protocol-simple-text-input-ex.h ├── c-efi-protocol-simple-text-input.h ├── c-efi-protocol-simple-text-output.h ├── c-efi-system.h ├── c-efi.h ├── example-hello-world.c ├── meson.build ├── test-api.c ├── test-basic.c ├── test-native.c └── x86_64-unknown-uefi.mesoncross.ini /.cherryci/ci-test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | rm -Rf "./ci-build" 6 | mkdir "./ci-build" 7 | cd "./ci-build" 8 | 9 | ${CHERRY_LIB_MESONSETUP} \ 10 | --cross-file "${CHERRY_LIB_SRCDIR}/src/x86_64-unknown-uefi.mesoncross.ini" \ 11 | . \ 12 | "${CHERRY_LIB_SRCDIR}" 13 | ${CHERRY_LIB_NINJABUILD} 14 | ${CHERRY_LIB_MESONTEST} 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | trim_trailing_whitespace = true 7 | charset = utf-8 8 | 9 | [*.{c,h}] 10 | indent_style = space 11 | indent_size = 8 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | os: linux 2 | dist: trusty 3 | language: c 4 | 5 | services: 6 | - docker 7 | 8 | before_install: 9 | - curl -O -L "https://raw.githubusercontent.com/cherry-pick/cherry-images/v1/scripts/vmrun" 10 | - curl -O -L "https://raw.githubusercontent.com/cherry-pick/cherry-ci/v1/scripts/cherryci" 11 | - chmod +x "./vmrun" "./cherryci" 12 | 13 | jobs: 14 | include: 15 | - stage: test 16 | script: 17 | - ./vmrun -- ../src/cherryci -d ../src/.cherryci -s c-util -m 18 | - script: 19 | - ./vmrun -T armv7hl -- ../src/cherryci -d ../src/.cherryci -s c-util 20 | - script: 21 | - ./vmrun -T i686 -- ../src/cherryci -d ../src/.cherryci -s c-util 22 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | LICENSE: 2 | This project is dual-licensed under both the Apache License, Version 3 | 2.0, and the GNU Lesser General Public License, Version 2.1+. 4 | 5 | AUTHORS-ASL: 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | 18 | AUTHORS-LGPL: 19 | This program is free software; you can redistribute it and/or modify it 20 | under the terms of the GNU Lesser General Public License as published 21 | by the Free Software Foundation; either version 2.1 of the License, or 22 | (at your option) any later version. 23 | 24 | This program is distributed in the hope that it will be useful, but 25 | WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | Lesser General Public License for more details. 28 | 29 | You should have received a copy of the GNU Lesser General Public License 30 | along with this program; If not, see . 31 | 32 | COPYRIGHT: (ordered alphabetically) 33 | Copyright (C) 2017-2018 Red Hat, Inc. 34 | 35 | AUTHORS: (ordered alphabetically) 36 | David Herrmann 37 | Tom Gundersen 38 | -------------------------------------------------------------------------------- /AUTHORS-ASL: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /AUTHORS-LGPL: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | AUTHORS-ASL -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | c-efi - UEFI Reference Specification Protocol Constants and Definitions 2 | 3 | ABOUT: 4 | The c-efi project provides the protocol constants and definitions of 5 | the UEFI Reference Specification as native C11 code. The scope of this 6 | project is limited to those protocol definitions. The protocols are not 7 | actually implemented. As such, this project serves as base for any UEFI 8 | application that needs to interact with UEFI, or implement (parts of) 9 | the UEFI specification. 10 | 11 | Additionally to providing a C library, this project also serves as 12 | documentation base for UEFI programming in C. It provides 13 | target-triples for UEFI, bootstrap helpers, and a bunch of 14 | documentation how to get started. 15 | 16 | DETAILS: 17 | https://c-util.github.io/c-efi 18 | 19 | BUG REPORTS: 20 | https://github.com/c-util/c-efi/issues 21 | 22 | GIT: 23 | git@github.com:c-util/c-efi.git 24 | https://github.com/c-util/c-efi.git 25 | 26 | GITWEB: 27 | https://github.com/c-util/c-efi 28 | 29 | LICENSE: 30 | Apache Software License 2.0 31 | Lesser General Public License 2.1+ 32 | See AUTHORS for details. 33 | 34 | REQUIREMENTS: 35 | There are no runtime requirements for c-efi. 36 | 37 | At build-time, the following software is required: 38 | 39 | meson >= 0.41 40 | pkg-config >= 0.29 41 | 42 | INSTALL: 43 | The meson build-system is used for this project. Contact upstream 44 | documentation for detailed help. In most situations the following 45 | commands are sufficient to build and install from source: 46 | 47 | $ mkdir build 48 | $ cd build 49 | $ meson setup \ 50 | --cross-file ../src/x86_64-unknown-uefi.mesoncross.ini \ 51 | .. 52 | $ ninja 53 | $ meson test 54 | # ninja install 55 | 56 | For custom configuration options see meson_options.txt. 57 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | project( 2 | 'c-efi', 3 | 'c', 4 | version: '1', 5 | license: 'Apache', 6 | default_options: [ 7 | 'c_std=c11' 8 | ], 9 | ) 10 | project_description = 'UEFI Reference Specification Protocol Constants and Definitions' 11 | 12 | mod_pkgconfig = import('pkgconfig') 13 | 14 | # 15 | # Get canonical FS paths 16 | # 17 | 18 | prefixdir = get_option('prefix') 19 | datadir = join_paths(prefixdir, get_option('datadir')) 20 | 21 | mesoncrossdir = get_option('mesoncrossdir') 22 | if mesoncrossdir == '' 23 | mesoncrossdir = join_paths(datadir, 'meson/cross') 24 | endif 25 | 26 | # 27 | # Config: mesoncross 28 | # 29 | 30 | use_mesoncross = get_option('mesoncross') 31 | 32 | # 33 | # Recurse into subdirs 34 | # 35 | 36 | subdir('src') 37 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | option('mesoncross', type: 'boolean', value: false, description: 'Install Meson cross-files') 2 | option('mesoncrossdir', type: 'string', value: '', description: 'Meson cross-file directory') 3 | -------------------------------------------------------------------------------- /src/c-efi-base.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * UEFI Base Environment 5 | * 6 | * This header defines the base environment for UEFI development. It provides 7 | * types and macros as declared in the UEFI specification, as well as de-facto 8 | * standard additions provided by the reference implementation by Intel. 9 | * 10 | * This file does not depend on a standard library, but can be used as base to 11 | * port a standard library to UEFI. Note, though, the ISO-C Standard Library is 12 | * in many ways incompatible to the style of UEFI development. While it is 13 | * technically possible to implement it, it would work against many of the UEFI 14 | * characteristics. 15 | * 16 | * This header provides the base types and macros used throughout the project. 17 | * It provides basic fixed-size integers, a NULL-equivalent, booleans, standard 18 | * UEFI types, and more. All symbols are prefixed with `C_EFI_*` or `CEfi*`. 19 | * 20 | * You are highly recommended to conduct the UEFI Specification for details on 21 | * the programming environment. Following a summary of key parts from the 22 | * specification: 23 | * 24 | * * All integers are either fixed-size, or native size. That is, either use 25 | * CEfi{8,..,64} and CEfiU{8,..,64} directly, or use the native-size 26 | * CEfiSize and CEfiUSize. Native size integers are sized according to the 27 | * architecture restrictions. You should assume they are pointer-sized. 28 | * 29 | * Whenever you refer to memory (either pointing to it, or remember the size 30 | * of a memory block), the native size integers should be your tool of 31 | * choice. 32 | * 33 | * * Even though the CPU might run in any endianness, all stored data is 34 | * little-endian. That means, if you encounter integers split into 35 | * byte-arrays (e.g., `CEfiDevicePathProtocol.length`), you must assume it 36 | * is little-endian encoded. But if you encounter native integers, you must 37 | * assume they are encoded in native endianness. 38 | * For now the UEFI specification only defines little-endian architectures, 39 | * hence this did not pop up as actual issue. Future extensions might change 40 | * this, though. 41 | * 42 | * * The Microsoft calling-convention is used. If you configure your compiler 43 | * correctly, you should be good to go. In all other cases, all UEFI 44 | * functions are annotated with the correct calling-convention. As long as 45 | * your compiler supports it, it will automatically pick the correct style. 46 | * The UEFI Specification defines some additional common rules for all its 47 | * APIs, though. You will most likely not see any of these mentioned in the 48 | * individual API documentions, though. Here is a short reminder: 49 | * 50 | * - Pointers must reference physical-memory locations (no I/O mappings, no 51 | * virtual addresses, etc.). Once ExitBootServices() was called, and the 52 | * virtual address mapping was set, you must provide virtual-memory 53 | * locations instead. 54 | * - Pointers must be correctly aligned. 55 | * - NULL is disallowed, unless explicitly mentioned otherwise. 56 | * - Data referenced by pointers is undefined on error-return from a 57 | * function. 58 | * - You must not pass data larger than native-size (sizeof(CEfiUSize)) on 59 | * the stack. You must pass them by reference. 60 | * 61 | * * Stack size is at least 128KiB and 16-byte aligned. All stack space might 62 | * be marked non-executable! Once ExitBootServices() was called, you must 63 | * guarantee at least 4KiB of stack space, 16-byte aligned for all runtime 64 | * services you call. These numbers differ depending on the target 65 | * architecture, but should be roughly the same. 66 | */ 67 | 68 | #ifdef __cplusplus 69 | extern "C" { 70 | #endif 71 | 72 | /** 73 | * CEFICALL: Annotate Functions with UEFI Calling-Convention 74 | * 75 | * This macro annotates function declarations with the correct calling 76 | * convention. The UEFI Specification defines the calling-convention for each 77 | * architecture it supports in great detail. It is almost identical to the 78 | * calling-convention used on Microsoft Windows. 79 | */ 80 | #if defined(__arm__) || defined(_M_ARM) 81 | # define CEFICALL __attribute__((pcs("aapcs"))) 82 | #elif defined(__aarch64__) || defined(_M_ARM64) 83 | # define CEFICALL /* XXX: No ABI-specifier supported so far */ 84 | #elif defined(__i386__) || defined(_M_IX86) 85 | # define CEFICALL __attribute__((cdecl)) 86 | #elif defined(__x86_64__) || defined(_M_X64) 87 | # define CEFICALL __attribute__((ms_abi)) 88 | #else 89 | # define CEFICALL /* Use native ABI; assume it matches the host. */ 90 | #endif 91 | 92 | /* 93 | * The UEFI Specification has several circular type dependencies. We simply use 94 | * forward declarations to get the required types in-scope. We really try to 95 | * limit the number of circular type dependencies, so make sure to only add 96 | * them here if really necessary. 97 | */ 98 | typedef struct CEfiDevicePathProtocol CEfiDevicePathProtocol; 99 | typedef struct CEfiSimpleTextInputProtocol CEfiSimpleTextInputProtocol; 100 | typedef struct CEfiSimpleTextOutputProtocol CEfiSimpleTextOutputProtocol; 101 | typedef struct CEfiSystemTable CEfiSystemTable; 102 | 103 | /** 104 | * C_EFI_NULL: NULL symbol 105 | * 106 | * Since NULL is defined by stdint.h, we need an equivalent. We follow what 107 | * everyone else does and define it as ((void *)0). 108 | */ 109 | #define C_EFI_NULL ((void *)0) 110 | 111 | /** 112 | * C_EFI_JOIN: Join two compiler symbols 113 | * @_a: First symbol 114 | * @_b: Second symbol 115 | * 116 | * This joins two compiler symbols via the `a ## b` preprocessor construct. It 117 | * first resolves the arguments to their values, then concatenates them. 118 | */ 119 | #define C_EFI_JOIN(_a, _b) C_EFI_JOIN_LITERALS(_a, _b) 120 | #define C_EFI_JOIN_LITERALS(_a, _b) _a ## _b 121 | 122 | /** 123 | * CEfiI8, CEfiU8, CEfiI16, CEfiU16, 124 | * CEfiI32, CEfiU32, CEfiI64, CEfiU64: Fixed size integers 125 | * 126 | * The CEfiI* and CEfiU* fixed size integers are UEFI equivalents to uint*_t 127 | * from stdint.h in ISO-C. Note that we rely on `__INTX_TYPE__` to be defined 128 | * by your compiler. This is what is used in most stdint.h implementations as 129 | * well. 130 | * 131 | * Other compiler-constants known from ISO-C are defined as well, including for 132 | * instance the UINTX_C() equivalents for fixed size integers. 133 | * 134 | * Note: UEFI provides 128-bit types as well, but most compilers lack support 135 | * to expose the required types. We simply skip their definition. If the 136 | * need arises, we can reconsider and add them. 137 | */ 138 | 139 | #if !defined(__INT8_TYPE__) || \ 140 | !defined(__UINT8_TYPE__) || \ 141 | !defined(__INT16_TYPE__) || \ 142 | !defined(__UINT16_TYPE__) || \ 143 | !defined(__INT32_TYPE__) || \ 144 | !defined(__UINT32_TYPE__) || \ 145 | !defined(__INT64_TYPE__) || \ 146 | !defined(__UINT64_TYPE__) || \ 147 | (!defined(__INT8_C) && !defined(__INT8_C_SUFFIX__)) || \ 148 | (!defined(__INT16_C) && !defined(__INT16_C_SUFFIX__)) || \ 149 | (!defined(__INT32_C) && !defined(__INT32_C_SUFFIX__)) || \ 150 | (!defined(__INT64_C) && !defined(__INT64_C_SUFFIX__)) || \ 151 | (!defined(__UINT8_C) && !defined(__UINT8_C_SUFFIX__)) || \ 152 | (!defined(__UINT16_C) && !defined(__UINT16_C_SUFFIX__)) || \ 153 | (!defined(__UINT32_C) && !defined(__UINT32_C_SUFFIX__)) || \ 154 | (!defined(__UINT64_C) && !defined(__UINT64_C_SUFFIX__)) 155 | # error "Compiler does not provide fixed-size integer macros." 156 | #endif 157 | 158 | typedef __INT8_TYPE__ CEfiI8; 159 | typedef __UINT8_TYPE__ CEfiU8; 160 | typedef __INT16_TYPE__ CEfiI16; 161 | typedef __UINT16_TYPE__ CEfiU16; 162 | typedef __INT32_TYPE__ CEfiI32; 163 | typedef __UINT32_TYPE__ CEfiU32; 164 | typedef __INT64_TYPE__ CEfiI64; 165 | typedef __UINT64_TYPE__ CEfiU64; 166 | 167 | #if defined(__INT8_C_SUFFIX__) 168 | # define C_EFI_I8_C(_v) C_EFI_JOIN(_v, __INT8_C_SUFFIX__) 169 | # define C_EFI_U8_C(_v) C_EFI_JOIN(_v, __UINT8_C_SUFFIX__) 170 | # define C_EFI_I16_C(_v) C_EFI_JOIN(_v, __INT16_C_SUFFIX__) 171 | # define C_EFI_U16_C(_v) C_EFI_JOIN(_v, __UINT16_C_SUFFIX__) 172 | # define C_EFI_I32_C(_v) C_EFI_JOIN(_v, __INT32_C_SUFFIX__) 173 | # define C_EFI_U32_C(_v) C_EFI_JOIN(_v, __UINT32_C_SUFFIX__) 174 | # define C_EFI_I64_C(_v) C_EFI_JOIN(_v, __INT64_C_SUFFIX__) 175 | # define C_EFI_U64_C(_v) C_EFI_JOIN(_v, __UINT64_C_SUFFIX__) 176 | #else 177 | # define C_EFI_I8_C(_v) __INT8_C(_v) 178 | # define C_EFI_U8_C(_v) __UINT8_C(_v) 179 | # define C_EFI_I16_C(_v) __INT16_C(_v) 180 | # define C_EFI_U16_C(_v) __UINT16_C(_v) 181 | # define C_EFI_I32_C(_v) __INT32_C(_v) 182 | # define C_EFI_U32_C(_v) __UINT32_C(_v) 183 | # define C_EFI_I64_C(_v) __INT64_C(_v) 184 | # define C_EFI_U64_C(_v) __UINT64_C(_v) 185 | #endif 186 | 187 | /** 188 | * CEfiISize, CEfiUSize: Native sized integers 189 | * 190 | * The CEfiISize and CEfiUSize types are native-size integer types. They 191 | * always have the same size as the target-architecture instruction width as 192 | * defined by the UEFI specification ('instruction width' is the wording of the 193 | * specification, and effectively means the pointer and address width). 194 | */ 195 | typedef __INTPTR_TYPE__ CEfiISize; 196 | typedef __UINTPTR_TYPE__ CEfiUSize; 197 | 198 | /** 199 | * CEfiBool: Boolean Type 200 | * 201 | * The CEfiBool type corresponds to the C11 definition of the _Bool type. It 202 | * is a simple typedef. 203 | */ 204 | typedef _Bool CEfiBool; 205 | 206 | /** 207 | * C_EFI_TRUE, C_EFI_FALSE: Boolean values 208 | * 209 | * Both constants, C_EFI_TRUE and C_EFI_FALSE, follow the C11 standard for 210 | * the `true' and `false' constants defined in `stdbool.h'. 211 | */ 212 | #define C_EFI_TRUE 1 213 | #define C_EFI_FALSE 0 214 | 215 | /** 216 | * CEfiChar8, CEfiChar16: Character Types 217 | * 218 | * The CEfiChar8 type is an unsigned 8-byte integer type that stores 8-bit 219 | * ASCII compatible characters (or character strings), using the ISO-Latin-1 220 | * character set. 221 | * 222 | * The CEfiChar16 type is an unsigned 16-byte integer type that stores 223 | * characters (or character strings) compatible to the UCS-2 encoding. 224 | */ 225 | typedef CEfiU8 CEfiChar8; 226 | typedef CEfiU16 CEfiChar16; 227 | 228 | /** 229 | * CEfiStatus: Status Codes 230 | * 231 | * The CEfiStatus type is used to indicate the return status of functions, 232 | * operations, and internal state. A value of 0 indicates success. Positive 233 | * values (MSB unset) indicate warnings, negative values (MSB set) indicate 234 | * errors. The second-MSB distinguishes OEM warnings and errors. 235 | */ 236 | 237 | typedef CEfiUSize CEfiStatus; 238 | 239 | #if __UINTPTR_MAX__ == __UINT32_MAX__ 240 | # define C_EFI_STATUS_C C_EFI_U32_C 241 | # define C_EFI_STATUS_WIDTH 32 242 | #elif __UINTPTR_MAX__ == __UINT64_MAX__ 243 | # define C_EFI_STATUS_C C_EFI_U64_C 244 | # define C_EFI_STATUS_WIDTH 64 245 | #else 246 | # error "Unsupported value of __UINTPTR_MAX__" 247 | #endif 248 | 249 | #define C_EFI_STATUS_ERROR_MASK (C_EFI_STATUS_C(0x80) << (C_EFI_STATUS_WIDTH - 8)) 250 | #define C_EFI_STATUS_ERROR_OEM_MASK (C_EFI_STATUS_C(0xc0) << (C_EFI_STATUS_WIDTH - 8)) 251 | #define C_EFI_STATUS_WARNING_MASK (C_EFI_STATUS_C(0x00) << (C_EFI_STATUS_WIDTH - 8)) 252 | #define C_EFI_STATUS_WARNING_OEM_MASK (C_EFI_STATUS_C(0x40) << (C_EFI_STATUS_WIDTH - 8)) 253 | 254 | #define C_EFI_STATUS_ERROR_C(_x) (C_EFI_STATUS_C(_x) | C_EFI_STATUS_ERROR_MASK) 255 | #define C_EFI_STATUS_ERROR_OEM_C(_x) (C_EFI_STATUS_C(_x) | C_EFI_STATUS_ERROR_OEM_MASK) 256 | #define C_EFI_STATUS_WARNING_C(_x) (C_EFI_STATUS_C(_x) | C_EFI_STATUS_WARNING_MASK) 257 | #define C_EFI_STATUS_WARNING_OEM_C(_x) (C_EFI_STATUS_C(_x) | C_EFI_STATUS_WARNING_OEM_MASK) 258 | 259 | #define C_EFI_ERROR(_x) (!!((_x) & C_EFI_STATUS_ERROR_MASK)) 260 | 261 | #define C_EFI_SUCCESS C_EFI_STATUS_C(0) 262 | 263 | #define C_EFI_LOAD_ERROR C_EFI_STATUS_ERROR_C(1) 264 | #define C_EFI_INVALID_PARAMETER C_EFI_STATUS_ERROR_C(2) 265 | #define C_EFI_UNSUPPORTED C_EFI_STATUS_ERROR_C(3) 266 | #define C_EFI_BAD_BUFFER_SIZE C_EFI_STATUS_ERROR_C(4) 267 | #define C_EFI_BUFFER_TOO_SMALL C_EFI_STATUS_ERROR_C(5) 268 | #define C_EFI_NOT_READY C_EFI_STATUS_ERROR_C(6) 269 | #define C_EFI_DEVICE_ERROR C_EFI_STATUS_ERROR_C(7) 270 | #define C_EFI_WRITE_PROTECTED C_EFI_STATUS_ERROR_C(8) 271 | #define C_EFI_OUT_OF_RESOURCES C_EFI_STATUS_ERROR_C(9) 272 | #define C_EFI_VOLUME_CORRUPTED C_EFI_STATUS_ERROR_C(10) 273 | #define C_EFI_VOLUME_FULL C_EFI_STATUS_ERROR_C(11) 274 | #define C_EFI_NO_MEDIA C_EFI_STATUS_ERROR_C(12) 275 | #define C_EFI_MEDIA_CHANGED C_EFI_STATUS_ERROR_C(13) 276 | #define C_EFI_NOT_FOUND C_EFI_STATUS_ERROR_C(14) 277 | #define C_EFI_ACCESS_DENIED C_EFI_STATUS_ERROR_C(15) 278 | #define C_EFI_NO_RESPONSE C_EFI_STATUS_ERROR_C(16) 279 | #define C_EFI_NO_MAPPING C_EFI_STATUS_ERROR_C(17) 280 | #define C_EFI_TIMEOUT C_EFI_STATUS_ERROR_C(18) 281 | #define C_EFI_NOT_STARTED C_EFI_STATUS_ERROR_C(19) 282 | #define C_EFI_ALREADY_STARTED C_EFI_STATUS_ERROR_C(20) 283 | #define C_EFI_ABORTED C_EFI_STATUS_ERROR_C(21) 284 | #define C_EFI_ICMP_ERROR C_EFI_STATUS_ERROR_C(22) 285 | #define C_EFI_TFTP_ERROR C_EFI_STATUS_ERROR_C(23) 286 | #define C_EFI_PROTOCOL_ERROR C_EFI_STATUS_ERROR_C(24) 287 | #define C_EFI_INCOMPATIBLE_VERSION C_EFI_STATUS_ERROR_C(25) 288 | #define C_EFI_SECURITY_VIOLATION C_EFI_STATUS_ERROR_C(26) 289 | #define C_EFI_CRC_ERROR C_EFI_STATUS_ERROR_C(27) 290 | #define C_EFI_END_OF_MEDIA C_EFI_STATUS_ERROR_C(28) 291 | #define C_EFI_END_OF_FILE C_EFI_STATUS_ERROR_C(31) 292 | #define C_EFI_INVALID_LANGUAGE C_EFI_STATUS_ERROR_C(32) 293 | #define C_EFI_COMPROMISED_DATA C_EFI_STATUS_ERROR_C(33) 294 | #define C_EFI_IP_ADDRESS_CONFLICT C_EFI_STATUS_ERROR_C(34) 295 | #define C_EFI_HTTP_ERROR C_EFI_STATUS_ERROR_C(35) 296 | 297 | #define C_EFI_WARN_UNKNOWN_GLYPH C_EFI_STATUS_WARNING_C(1) 298 | #define C_EFI_WARN_DELETE_FAILURE C_EFI_STATUS_WARNING_C(2) 299 | #define C_EFI_WARN_WRITE_FAILURE C_EFI_STATUS_WARNING_C(3) 300 | #define C_EFI_WARN_BUFFER_TOO_SMALL C_EFI_STATUS_WARNING_C(4) 301 | #define C_EFI_WARN_STALE_DATA C_EFI_STATUS_WARNING_C(5) 302 | #define C_EFI_WARN_FILE_SYSTEM C_EFI_STATUS_WARNING_C(6) 303 | #define C_EFI_WARN_RESET_REQUIRED C_EFI_STATUS_WARNING_C(7) 304 | 305 | /** 306 | * CEfiHandle, CEfiEvent, CEfiLba, CEfiTpl, CEfiPhysicalAddress, 307 | * CEfiVirtualAddress: Common UEFI Aliases 308 | * 309 | * These types are all aliases as defined by the UEFI specification. They are 310 | * solely meant for documentational purposes. 311 | * 312 | * CEfiHandle represents handles to allocated objects. CEfiEvent represents 313 | * slots that can be waited on (like Windows events). CEfiLba represents 314 | * logical block addresses. CEfiTpl represents thread priority levels. 315 | * CEfiPhysicalAddress, and CEfiVirtualAddress are used to denote physical, 316 | * and virtual addresses. 317 | */ 318 | typedef void *CEfiHandle; 319 | typedef void *CEfiEvent; 320 | typedef CEfiU64 CEfiLba; 321 | typedef CEfiUSize CEfiTpl; 322 | typedef CEfiU64 CEfiPhysicalAddress; 323 | typedef CEfiU64 CEfiVirtualAddress; 324 | 325 | /** 326 | * CEfiImageEntryPoint: Type of image entry points 327 | * 328 | * All loaded images must have an entry point of this type. The entry point is 329 | * pointed to in the PE/COFF header. No particular symbol-name is required, 330 | * though most setups automatically pick the function named `efi_main`. 331 | * 332 | * On load, the entry-point is called with a pointer to the own image as first 333 | * argument, a pointer to the global system table as second argument. Normal 334 | * applications are unloaded when this function returns. Drivers might stay in 335 | * memory, depending on the return type. See the specification for details. 336 | */ 337 | typedef CEfiStatus (CEFICALL *CEfiImageEntryPoint)(CEfiHandle image, CEfiSystemTable *st); 338 | 339 | /** 340 | * CEfiGuid: Globally Unique Identifier Type 341 | * 342 | * The CEfiGuid type represents a GUID. It is always 128bit in size and 343 | * aligned to 64bit. Only its binary representation is guaranteed to be stable. 344 | * You are highly recommended to only ever access the `u8' version of it. 345 | * 346 | * The @ms1 to @ms4 fields can be used to encode Microsoft-style GUIDs, where 347 | * @ms1, @ms2, and @ms3 are little-endian encoded. 348 | */ 349 | typedef struct CEfiGuid { 350 | union { 351 | _Alignas(8) CEfiU8 u8[16]; 352 | _Alignas(8) CEfiU16 u16[8]; 353 | _Alignas(8) CEfiU32 u32[4]; 354 | _Alignas(8) CEfiU64 u64[2]; 355 | struct { 356 | _Alignas(8) CEfiU32 ms1; 357 | CEfiU16 ms2; 358 | CEfiU16 ms3; 359 | CEfiU8 ms4[8]; 360 | }; 361 | }; 362 | } CEfiGuid; 363 | 364 | #define C_EFI_GUID(_ms1, _ms2, _ms3, \ 365 | _ms4, _ms5, _ms6, _ms7, \ 366 | _ms8, _ms9, _ms10, _ms11) \ 367 | ((struct CEfiGuid){ \ 368 | .ms1 = (_ms1), \ 369 | .ms2 = (_ms2), \ 370 | .ms3 = (_ms3), \ 371 | .ms4 = { \ 372 | (_ms4), (_ms5), (_ms6), (_ms7), \ 373 | (_ms8), (_ms9), (_ms10), (_ms11), \ 374 | }, \ 375 | }) 376 | 377 | /** 378 | * CEfiMacAddress, CEfiIpv4Address, 379 | * CEfiIpv6Address, CEfiIpAddress: Networking Types 380 | * 381 | * These types represent the corresponding networking entities. CEfiMacAddress, 382 | * CEfiIpv4Address, and CEfiIpv6Address are mere byte-buffers. CEfiIpAddress is 383 | * a 16-byte buffer, but required to be 4-byte aligned. 384 | */ 385 | 386 | typedef struct CEfiMacAddress { 387 | CEfiU8 u8[32]; 388 | } CEfiMacAddress; 389 | 390 | typedef struct CEfiIpv4Address { 391 | CEfiU8 u8[4]; 392 | } CEfiIpv4Address; 393 | 394 | typedef struct CEfiIpv6Address { 395 | CEfiU8 u8[16]; 396 | } CEfiIpv6Address; 397 | 398 | typedef struct CEfiIpAddress { 399 | union { 400 | _Alignas(4) CEfiIpv4Address ipv4; 401 | _Alignas(4) CEfiIpv6Address ipv6; 402 | }; 403 | } CEfiIpAddress; 404 | 405 | #ifdef __cplusplus 406 | } 407 | #endif 408 | -------------------------------------------------------------------------------- /src/c-efi-protocol-device-path-from-text.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * UEFI Protocol - Device Path From Text 5 | * 6 | * XXX 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #define C_EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID C_EFI_GUID(0x5c99a21, 0xc70f, 0x4ad2, 0x8a, 0x5f, 0x35, 0xdf, 0x33, 0x43, 0xf5, 0x1e) 18 | 19 | typedef struct CEfiDevicePathFromTextProtocol { 20 | CEfiDevicePathProtocol *(CEFICALL *convert_text_to_device_node) ( 21 | CEfiChar16 *text_device_node 22 | ); 23 | CEfiDevicePathProtocol *(CEFICALL *convert_text_to_device_path) ( 24 | CEfiChar16 *text_device_path 25 | ); 26 | } CEfiDevicePathFromTextProtocol; 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /src/c-efi-protocol-device-path-to-text.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * UEFI Protocol - Device Path To Text 5 | * 6 | * XXX 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #define C_EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID C_EFI_GUID(0x8b843e20, 0x8132, 0x4852, 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c) 18 | 19 | typedef struct CEfiDevicePathToTextProtocol { 20 | CEfiChar16 *(CEFICALL *convert_device_node_to_text) ( 21 | CEfiDevicePathProtocol *device_node, 22 | CEfiBool display_only, 23 | CEfiBool allow_shortcuts 24 | ); 25 | CEfiChar16 *(CEFICALL *convert_device_path_to_text) ( 26 | CEfiDevicePathProtocol *device_path, 27 | CEfiBool display_only, 28 | CEfiBool allow_shortcuts 29 | ); 30 | } CEfiDevicePathToTextProtocol; 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /src/c-efi-protocol-device-path-utility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * UEFI Protocol - Device Path Utility 5 | * 6 | * XXX 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #define C_EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID C_EFI_GUID(0x379be4e, 0xd706, 0x437d, 0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4) 18 | 19 | typedef struct CEfiDevicePathUtilitiesProtocol { 20 | CEfiUSize (CEFICALL *get_device_path_size) ( 21 | CEfiDevicePathProtocol *device_path 22 | ); 23 | CEfiDevicePathProtocol *(CEFICALL *duplicate_device_path) ( 24 | CEfiDevicePathProtocol *device_path 25 | ); 26 | CEfiDevicePathProtocol *(CEFICALL *append_device_path) ( 27 | CEfiDevicePathProtocol *src1, 28 | CEfiDevicePathProtocol *src2 29 | ); 30 | CEfiDevicePathProtocol *(CEFICALL *append_device_node) ( 31 | CEfiDevicePathProtocol *device_path, 32 | CEfiDevicePathProtocol *device_node 33 | ); 34 | CEfiDevicePathProtocol *(CEFICALL *append_device_path_instance) ( 35 | CEfiDevicePathProtocol *device_path, 36 | CEfiDevicePathProtocol *device_path_instance 37 | ); 38 | CEfiDevicePathProtocol *(CEFICALL *get_next_device_path_instance) ( 39 | CEfiDevicePathProtocol **device_path_instance, 40 | CEfiUSize *device_path_instance_size 41 | ); 42 | CEfiBool (CEFICALL *is_device_path_multi_instance) ( 43 | CEfiDevicePathProtocol *device_path 44 | ); 45 | CEfiDevicePathProtocol *(CEFICALL *create_device_node) ( 46 | CEfiU8 node_type, 47 | CEfiU8 node_subtype, 48 | CEfiU16 node_length 49 | ); 50 | } CEfiDevicePathUtilitiesProtocol; 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /src/c-efi-protocol-device-path.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * UEFI Protocol - Device Path 5 | * 6 | * XXX 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | #include 15 | 16 | #define C_EFI_DEVICE_PATH_PROTOCOL_GUID C_EFI_GUID(0x09576e91, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) 17 | 18 | #define C_EFI_DEVICE_PATH_TYPE_HARDWARE C_EFI_U8_C(0x01) 19 | #define C_EFI_DEVICE_PATH_TYPE_ACPI C_EFI_U8_C(0x02) 20 | #define C_EFI_DEVICE_PATH_TYPE_MESSAGE C_EFI_U8_C(0x03) 21 | #define C_EFI_DEVICE_PATH_TYPE_MEDIA C_EFI_U8_C(0x04) 22 | #define C_EFI_DEVICE_PATH_TYPE_BIOS C_EFI_U8_C(0x05) 23 | #define C_EFI_DEVICE_PATH_TYPE_END C_EFI_U8_C(0x7f) 24 | 25 | /** 26 | * CEfiDevicePathProtocol: Device Paths 27 | * @type: type of this device node 28 | * @subtype: subtype of this device node 29 | * @length: length of this device node (including this header) 30 | * 31 | * This structure is used to represent paths to all kinds of devices. A device 32 | * path is a concatenation of structures of this type. The end is marked with a 33 | * type/subtype combination of TYPE_END and SUBTYPE_END_ALL. 34 | * 35 | * Note that thus structure is unaligned! That is, its alignment is 1-byte and 36 | * thus must be accessed with unaligned helpers, or in individual pieces. 37 | * 38 | * Also note that any function taking an object of this type usually never 39 | * accepts NULL. That is, the empty device-path is represented by 40 | * C_EFI_DEVICE_PATH_NULL (which is just a TYPE_END+SUBTYPE_END_ALL). Though, 41 | * the UEFI Specification contradicts itself there and uses NULL in several 42 | * cases. Make sure to check each of these use-cases carefully. 43 | */ 44 | typedef struct CEfiDevicePathProtocol { 45 | CEfiU8 type; 46 | CEfiU8 subtype; 47 | CEfiU8 length[2]; 48 | } CEfiDevicePathProtocol; 49 | 50 | #define C_EFI_DEVICE_PATH_SUBTYPE_END_ALL C_EFI_U8_C(0xff) 51 | #define C_EFI_DEVICE_PATH_SUBTYPE_END_INSTANCE C_EFI_U8_C(0x01) 52 | 53 | #define C_EFI_DEVICE_PATH_SUBTYPE_HARDWARE_PCI C_EFI_U8_C(0x01) 54 | #define C_EFI_DEVICE_PATH_SUBTYPE_HARDWARE_PCCARD C_EFI_U8_C(0x02) 55 | #define C_EFI_DEVICE_PATH_SUBTYPE_HARDWARE_MMAP C_EFI_U8_C(0x03) 56 | #define C_EFI_DEVICE_PATH_SUBTYPE_HARDWARE_VENDOR C_EFI_U8_C(0x04) 57 | #define C_EFI_DEVICE_PATH_SUBTYPE_HARDWARE_CONTROLLER C_EFI_U8_C(0x05) 58 | #define C_EFI_DEVICE_PATH_SUBTYPE_HARDWARE_BMC C_EFI_U8_C(0x06) 59 | 60 | #define C_EFI_DEVICE_PATH_NULL { \ 61 | .type = C_EFI_DEVICE_PATH_TYPE_END, \ 62 | .subtype = C_EFI_DEVICE_PATH_SUBTYPE_END_ALL, \ 63 | .length = { 4, 0 }, \ 64 | } 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /src/c-efi-protocol-loaded-image-device-path.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * UEFI Protocol - Loaded Image Device Path 5 | * 6 | * XXX 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #define C_EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID C_EFI_GUID(0xbc62157e, 0x3e33, 0x4fec, 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf) 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /src/c-efi-protocol-loaded-image.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * UEFI Protocol - Loaded Image 5 | * 6 | * XXX 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | #include 15 | 16 | #define C_EFI_LOADED_IMAGE_PROTOCOL_GUID C_EFI_GUID(0x5B1B31A1, 0x9562, 0x11d2, 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B) 17 | 18 | #define C_EFI_LOADED_IMAGE_PROTOCOL_REVISION C_EFI_U32_C(0x1000) 19 | 20 | typedef struct CEfiLoadedImageProtocol { 21 | CEfiU32 revision; 22 | CEfiHandle parent_handle; 23 | CEfiSystemTable *system_table; 24 | 25 | CEfiHandle device_handle; 26 | CEfiDevicePathProtocol *file_path; 27 | void *reserved; 28 | 29 | CEfiU32 load_options_size; 30 | void *load_options; 31 | 32 | void *image_base; 33 | CEfiU64 image_size; 34 | CEfiMemoryType image_code_type; 35 | CEfiMemoryType image_data_type; 36 | 37 | CEfiStatus (CEFICALL *unload) ( 38 | CEfiHandle image_handle 39 | ); 40 | } CEfiLoadedImageProtocol; 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /src/c-efi-protocol-simple-text-input-ex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * UEFI Protocol - Simple Text Input Ex 5 | * 6 | * XXX 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | #include 15 | 16 | typedef struct CEfiSimpleTextInputExProtocol CEfiSimpleTextInputExProtocol; 17 | 18 | #define C_EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID C_EFI_GUID(0xdd9e7534, 0x7762, 0x4698, 0x8c, 0x14, 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa) 19 | 20 | #define C_EFI_TOGGLE_STATE_VALID C_EFI_U8_C(0x80) 21 | #define C_EFI_KEY_STATE_EXPOSED C_EFI_U8_C(0x40) 22 | #define C_EFI_SCROLL_LOCK_ACTIVE C_EFI_U8_C(0x01) 23 | #define C_EFI_NUM_LOCK_ACTIVE C_EFI_U8_C(0x02) 24 | #define C_EFI_CAPS_LOCK_ACTIVE C_EFI_U8_C(0x04) 25 | 26 | typedef CEfiU8 CEfiKeyToggleState; 27 | 28 | #define C_EFI_SHIFT_STATE_VALID C_EFI_U32_C(0x80000000) 29 | #define C_EFI_RIGHT_SHIFT_PRESSED C_EFI_U32_C(0x00000001) 30 | #define C_EFI_LEFT_SHIFT_PRESSED C_EFI_U32_C(0x00000002) 31 | #define C_EFI_RIGHT_CONTROL_PRESSED C_EFI_U32_C(0x00000004) 32 | #define C_EFI_LEFT_CONTROL_PRESSED C_EFI_U32_C(0x00000008) 33 | #define C_EFI_RIGHT_ALT_PRESSED C_EFI_U32_C(0x00000010) 34 | #define C_EFI_LEFT_ALT_PRESSED C_EFI_U32_C(0x00000020) 35 | #define C_EFI_RIGHT_LOGO_PRESSED C_EFI_U32_C(0x00000040) 36 | #define C_EFI_LEFT_LOGO_PRESSED C_EFI_U32_C(0x00000080) 37 | #define C_EFI_MENU_KEY_PRESSED C_EFI_U32_C(0x00000100) 38 | #define C_EFI_SYS_REQ_PRESSED C_EFI_U32_C(0x00000200) 39 | 40 | typedef struct CEfiKeyState { 41 | CEfiU32 key_shift_state; 42 | CEfiKeyToggleState key_toggle_state; 43 | } CEfiKeyState; 44 | 45 | typedef struct CEfiKeyData { 46 | CEfiInputKey key; 47 | CEfiKeyState key_state; 48 | } CEfiKeyData; 49 | 50 | typedef CEfiStatus (CEFICALL *CEfiKeyNotifyFunction) (CEfiKeyData *key_data); 51 | 52 | typedef struct CEfiSimpleTextInputExProtocol { 53 | CEfiStatus (CEFICALL *reset) ( 54 | CEfiSimpleTextInputExProtocol *this_, 55 | CEfiBool extended_verification 56 | ); 57 | CEfiStatus (CEFICALL *read_key_stroke_ex) ( 58 | CEfiSimpleTextInputExProtocol *this_, 59 | CEfiKeyData *key_data 60 | ); 61 | CEfiEvent wait_for_key_ex; 62 | CEfiStatus (CEFICALL *set_state) ( 63 | CEfiSimpleTextInputExProtocol *this_, 64 | CEfiKeyToggleState *key_toggle_state 65 | ); 66 | CEfiStatus (CEFICALL *register_key_notify) ( 67 | CEfiSimpleTextInputExProtocol *this_, 68 | CEfiKeyData *key_data, 69 | CEfiKeyNotifyFunction key_notification_function, 70 | void **notify_handle 71 | ); 72 | CEfiStatus (CEFICALL *unregister_key_notify) ( 73 | CEfiSimpleTextInputExProtocol *this_, 74 | void *notification_handle 75 | ); 76 | } CEfiSimpleTextInputExProtocol; 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | -------------------------------------------------------------------------------- /src/c-efi-protocol-simple-text-input.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * UEFI Protocol - Simple Text Input 5 | * 6 | * XXX 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | #include 15 | 16 | #define C_EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID C_EFI_GUID(0x387477c1, 0x69c7, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) 17 | 18 | typedef struct CEfiInputKey { 19 | CEfiU16 scan_code; 20 | CEfiChar16 unicode_char; 21 | } CEfiInputKey; 22 | 23 | typedef struct CEfiSimpleTextInputProtocol { 24 | CEfiStatus (CEFICALL *reset) ( 25 | CEfiSimpleTextInputProtocol *this_, 26 | CEfiBool extended_verification 27 | ); 28 | CEfiStatus (CEFICALL *read_key_stroke) ( 29 | CEfiSimpleTextInputProtocol *this_, 30 | CEfiInputKey *key 31 | ); 32 | CEfiEvent wait_for_key; 33 | } CEfiSimpleTextInputProtocol; 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /src/c-efi-protocol-simple-text-output.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * UEFI Protocol - Simple Text Output 5 | * 6 | * XXX 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | #include 15 | 16 | #define C_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID C_EFI_GUID(0x387477c2, 0x69c7, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) 17 | 18 | typedef struct CEfiSimpleTextOutputMode { 19 | CEfiI32 max_mode; 20 | CEfiI32 mode; 21 | CEfiI32 attribute; 22 | CEfiI32 cursor_column; 23 | CEfiI32 cursor_row; 24 | CEfiBool cursor_visible; 25 | } CEfiSimpleTextOutputMode; 26 | 27 | #define C_EFI_BLACK C_EFI_U8_C(0x00) 28 | #define C_EFI_BLUE C_EFI_U8_C(0x01) 29 | #define C_EFI_GREEN C_EFI_U8_C(0x02) 30 | #define C_EFI_CYAN C_EFI_U8_C(0x03) 31 | #define C_EFI_RED C_EFI_U8_C(0x04) 32 | #define C_EFI_MAGENTA C_EFI_U8_C(0x05) 33 | #define C_EFI_BROWN C_EFI_U8_C(0x06) 34 | #define C_EFI_LIGHTGRAY C_EFI_U8_C(0x07) 35 | #define C_EFI_BRIGHT C_EFI_U8_C(0x08) 36 | #define C_EFI_DARKGRAY (C_EFI_BLACK | C_EFI_BRIGHT) 37 | #define C_EFI_LIGHTBLUE (C_EFI_BLUE | C_EFI_BRIGHT) 38 | #define C_EFI_LIGHTGREEN (C_EFI_GREEN | C_EFI_BRIGHT) 39 | #define C_EFI_LIGHTCYAN (C_EFI_CYAN | C_EFI_BRIGHT) 40 | #define C_EFI_LIGHTRED (C_EFI_RED | C_EFI_BRIGHT) 41 | #define C_EFI_LIGHTMAGENTA (C_EFI_MAGENTA | C_EFI_BRIGHT) 42 | #define C_EFI_YELLOW (C_EFI_BROWN | C_EFI_BRIGHT) 43 | #define C_EFI_WHITE C_EFI_U8_C(0x0f) 44 | 45 | #define C_EFI_BACKGROUND_BLACK C_EFI_U8_C(0x00) 46 | #define C_EFI_BACKGROUND_BLUE C_EFI_U8_C(0x10) 47 | #define C_EFI_BACKGROUND_GREEN C_EFI_U8_C(0x20) 48 | #define C_EFI_BACKGROUND_CYAN C_EFI_U8_C(0x30) 49 | #define C_EFI_BACKGROUND_RED C_EFI_U8_C(0x40) 50 | #define C_EFI_BACKGROUND_MAGENTA C_EFI_U8_C(0x50) 51 | #define C_EFI_BACKGROUND_BROWN C_EFI_U8_C(0x60) 52 | #define C_EFI_BACKGROUND_LIGHTGRAY C_EFI_U8_C(0x70) 53 | 54 | typedef struct CEfiSimpleTextOutputProtocol { 55 | CEfiStatus (CEFICALL *reset) ( 56 | CEfiSimpleTextOutputProtocol *this_, 57 | CEfiBool extended_verification 58 | ); 59 | CEfiStatus (CEFICALL *output_string) ( 60 | CEfiSimpleTextOutputProtocol *this_, 61 | CEfiChar16 *string 62 | ); 63 | CEfiStatus (CEFICALL *test_string) ( 64 | CEfiSimpleTextOutputProtocol *this_, 65 | CEfiChar16 *string 66 | ); 67 | CEfiStatus (CEFICALL *query_mode) ( 68 | CEfiSimpleTextOutputProtocol *this_, 69 | CEfiUSize mode_number, 70 | CEfiUSize *columns, 71 | CEfiUSize *rows 72 | ); 73 | CEfiStatus (CEFICALL *set_mode) ( 74 | CEfiSimpleTextOutputProtocol *this_, 75 | CEfiUSize mode_number 76 | ); 77 | CEfiStatus (CEFICALL *set_attribute) ( 78 | CEfiSimpleTextOutputProtocol *this_, 79 | CEfiUSize attribute 80 | ); 81 | CEfiStatus (CEFICALL *clear_screen) ( 82 | CEfiSimpleTextOutputProtocol *this_ 83 | ); 84 | CEfiStatus (CEFICALL *set_cursor_position) ( 85 | CEfiSimpleTextOutputProtocol *this_, 86 | CEfiUSize column, 87 | CEfiUSize row 88 | ); 89 | CEfiStatus (CEFICALL *enable_cursor) ( 90 | CEfiSimpleTextOutputProtocol *this_, 91 | CEfiBool visible 92 | ); 93 | CEfiSimpleTextOutputMode *mode; 94 | } CEfiSimpleTextOutpuProtocol; 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | -------------------------------------------------------------------------------- /src/c-efi-system.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * UEFI System Integration 5 | * 6 | * This header defines the structures and types of the surrounding system of an 7 | * UEFI application. It contains the definitions of the system table, the 8 | * runtime and boot services, as well as common types. 9 | * 10 | * We do not document the behavior of each of these types and functions. They 11 | * follow the UEFI specification, which does a well-enough job of documenting 12 | * each. This file just provides you the C definitions of each symbol and some 13 | * limited hints on some pecularities. 14 | */ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include 21 | 22 | /* 23 | * Time Management 24 | * 25 | * UEFI time management is modeled around the CEfiTime structure, which 26 | * represents any arbitrary timestamp. The runtime and boot services provide 27 | * helper functions to query and set the system time. 28 | */ 29 | 30 | #define C_EFI_TIME_ADJUST_DAYLIGHT C_EFI_U8_C(0x01) 31 | #define C_EFI_TIME_IN_DAYLIGHT C_EFI_U8_C(0x02) 32 | 33 | #define C_EFI_UNSPECIFIED_TIMEZONE C_EFI_I16_C(0x07ff) 34 | 35 | typedef struct CEfiTime { 36 | CEfiU16 year; 37 | CEfiU8 month; 38 | CEfiU8 day; 39 | CEfiU8 hour; 40 | CEfiU8 minute; 41 | CEfiU8 second; 42 | CEfiU8 pad1; 43 | CEfiU32 nanosecond; 44 | CEfiI16 timezone; 45 | CEfiU8 daylight; 46 | CEfiU8 pad2; 47 | } CEfiTime; 48 | 49 | typedef struct CEfiTimeCapabilities { 50 | CEfiU32 resolution; 51 | CEfiU32 accuracy; 52 | CEfiBool sets_to_zero; 53 | } CEfiTimeCapabilities; 54 | 55 | /* 56 | * UEFI Variables 57 | * 58 | * UEFI systems provide a way to store global variables. These can be 59 | * persistent or volatile. The variable store must be provided by the platform, 60 | * but persistent storage might not be available. 61 | */ 62 | 63 | #define C_EFI_VARIABLE_NON_VOLATILE C_EFI_U32_C(0x00000001) 64 | #define C_EFI_VARIABLE_BOOTSERVICE_ACCESS C_EFI_U32_C(0x00000002) 65 | #define C_EFI_VARIABLE_RUNTIME_ACCESS C_EFI_U32_C(0x00000004) 66 | #define C_EFI_VARIABLE_HARDWARE_ERROR_RECORD C_EFI_U32_C(0x00000008) 67 | #define C_EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS C_EFI_U32_C(0x00000010) 68 | #define C_EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS C_EFI_U32_C(0x00000020) 69 | #define C_EFI_VARIABLE_APPEND_WRITE C_EFI_U32_C(0x00000040) 70 | #define C_EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS C_EFI_U32_C(0x00000080) 71 | 72 | #define C_EFI_VARIABLE_AUTHENTICATION_3_CERT_ID_SHA256 C_EFI_U32_C(1) 73 | 74 | typedef struct CEfiVariableAuthentication3CertId { 75 | CEfiU8 type; 76 | CEfiU32 id_size; 77 | CEfiU8 id[]; 78 | } CEfiVariableAuthentication3CertId; 79 | 80 | typedef struct CEfiVariableAuthentication { 81 | CEfiU64 monotonic_count; 82 | CEfiU8 auth_info[]; /* WIN_CERTIFICATE_UEFI_ID from PE/COFF */ 83 | } CEfiVariableAuthentication; 84 | 85 | typedef struct CEfiVariableAuthentication2 { 86 | CEfiTime timestamp; 87 | CEfiU8 auth_info[]; /* WIN_CERTIFICATE_UEFI_ID from PE/COFF */ 88 | } CEfiVariableAuthentication2; 89 | 90 | #define C_EFI_VARIABLE_AUTHENTICATION_3_TIMESTAMP_TYPE C_EFI_U32_C(1) 91 | #define C_EFI_VARIABLE_AUTHENTICATION_3_NONCE_TYPE C_EFI_U32_C(2) 92 | 93 | typedef struct CEfiVariableAuthentication3 { 94 | CEfiU8 version; 95 | CEfiU8 type; 96 | CEfiU32 metadata_size; 97 | CEfiU32 flags; 98 | } CEfiVariableAuthentication3; 99 | 100 | typedef struct CEfiVariableAuthentication3Nonce { 101 | CEfiU32 nonce_size; 102 | CEfiU8 nonce[]; 103 | } CEfiVariableAuthentication3Nonce; 104 | 105 | #define C_EFI_HARDWARE_ERROR_VARIABLE_GUID C_EFI_GUID(0x414E6BDD, 0xE47B, 0x47cc, 0xB2, 0x44, 0xBB, 0x61, 0x02, 0x0C, 0xF5, 0x16) 106 | 107 | /* 108 | * Virtual Mappings 109 | * 110 | * UEFI runs in an 1-to-1 mapping from virtual to physical addresses. But once 111 | * you exit boot services, you can apply any address mapping you want, as long 112 | * as you inform UEFI about it (or, alternatively, stop using the UEFI runtime 113 | * services). 114 | */ 115 | 116 | #define C_EFI_OPTIONAL_POINTER C_EFI_U32_C(0x00000001) 117 | 118 | /* 119 | * System Reset 120 | * 121 | * UEFI provides access to firmware functions to reset the system. This 122 | * includes a wide variety of different possible resets. 123 | */ 124 | 125 | typedef enum CEfiResetType { 126 | C_EFI_RESET_COLD, 127 | C_EFI_RESET_WARM, 128 | C_EFI_RESET_SHUTDOWN, 129 | C_EFI_RESET_PLATFORM_SPECIFIC, 130 | _C_EFI_RESET_N, 131 | } CEfiResetType; 132 | 133 | /* 134 | * Update Capsules 135 | * 136 | * The process of firmware updates is generalized in UEFI. There are small 137 | * blobs called capsules that you can push into the firmware to be run either 138 | * immediately or on next reboot. 139 | */ 140 | 141 | typedef struct CEfiCapsuleBlockDescriptor { 142 | CEfiU64 length; 143 | union { 144 | CEfiPhysicalAddress data_block; 145 | CEfiPhysicalAddress continuation_pointer; 146 | }; 147 | } CEfiCapsuleBlockDescriptor; 148 | 149 | #define C_EFI_CAPSULE_FLAGS_PERSIST_ACROSS_RESET C_EFI_U32(0x00010000) 150 | #define C_EFI_CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE C_EFI_U32(0x00020000) 151 | #define C_EFI_CAPSULE_FLAGS_INITIATE_RESET C_EFI_U32(0x00040000) 152 | 153 | typedef struct CEfiCapsuleHeader { 154 | CEfiGuid capsule_guid; 155 | CEfiU32 header_size; 156 | CEfiU32 flags; 157 | CEfiU32 capsule_image_size; 158 | } CEfiCapsuleHeader; 159 | 160 | #define C_EFI_OS_INDICATIONS_BOOT_TO_FW_UI C_EFI_U64_C(0x0000000000000001) 161 | #define C_EFI_OS_INDICATIONS_TIMESTAMP_REVOCATION C_EFI_U64_C(0x0000000000000002) 162 | #define C_EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED C_EFI_U64_C(0x0000000000000004) 163 | #define C_EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED C_EFI_U64_C(0x0000000000000008) 164 | #define C_EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED C_EFI_U64_C(0x0000000000000010) 165 | #define C_EFI_OS_INDICATIONS_START_OS_RECOVERY C_EFI_U64_C(0x0000000000000020) 166 | #define C_EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY C_EFI_U64_C(0x0000000000000040) 167 | 168 | #define C_EFI_CAPSULE_REPORT_GUID C_EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3) 169 | 170 | typedef struct CEfiCapsuleResultVariableHeader { 171 | CEfiU32 variable_total_size; 172 | CEfiU32 reserved; 173 | CEfiGuid capsule_guid; 174 | CEfiTime capsule_processed; 175 | CEfiStatus capsule_status; 176 | } CEfiCapsuleResultVariableHeader; 177 | 178 | typedef struct CEfiCapsuleResultVariableFMP { 179 | CEfiU16 version; 180 | CEfiU8 payload_index; 181 | CEfiU8 update_image_index; 182 | CEfiGuid update_image_type_id; 183 | CEfiChar16 capsule_file_name_and_target[]; 184 | } CEfiCapsuleResultVariableFMP; 185 | 186 | /* 187 | * Tasks 188 | * 189 | * UEFI uses a simplified task model, and only ever runs on a single CPU. 190 | * Usually, there is only one single task running on the system, which is the 191 | * current execution. No interrupts are supported, other than timer interrupts. 192 | * That is, all device management must be reliant on polling. 193 | * 194 | * You can, however, register callbacks to be run by the UEFI core. That is, 195 | * either when execution is returned to the UEFI core, or when a timer 196 | * interrupt fires, the scheduler will run the highest priority task next, 197 | * interrupting the current task. You can use simple task-priority-levels (TPL) 198 | * to adjust the priority of your callbacks and current task. 199 | */ 200 | 201 | #define C_EFI_EVT_TIMER C_EFI_U32_C(0x80000000) 202 | #define C_EFI_EVT_RUNTIME C_EFI_U32_C(0x40000000) 203 | #define C_EFI_EVT_NOTIFY_WAIT C_EFI_U32_C(0x00000100) 204 | #define C_EFI_EVT_NOTIFY_SIGNAL C_EFI_U32_C(0x00000200) 205 | #define C_EFI_EVT_SIGNAL_EXIT_BOOT_SERVICES C_EFI_U32_C(0x00000201) 206 | #define C_EFI_EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE C_EFI_U32_C(0x60000202) 207 | 208 | typedef void (CEFICALL *CEfiEventNotify) (CEfiEvent event, void *context); 209 | 210 | #define C_EFI_EVENT_GROUP_EXIT_BOOT_SERVICES C_EFI_GUID(0x27abf055, 0xb1b8, 0x4c26, 0x80, 0x48, 0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf) 211 | #define C_EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE C_EFI_GUID(0x13fa7698, 0xc831, 0x49c7, 0x87, 0xea, 0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96) 212 | #define C_EFI_EVENT_GROUP_MEMORY_MAP_CHANGE C_EFI_GUID(0x78bee926, 0x692f, 0x48fd, 0x9e, 0xdb, 0x1, 0x42, 0x2e, 0xf0, 0xd7, 0xab) 213 | #define C_EFI_EVENT_GROUP_READY_TO_BOOT C_EFI_GUID(0x7ce88fb3, 0x4bd7, 0x4679, 0x87, 0xa8, 0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b) 214 | #define C_EFI_EVENT_GROUP_RESET_SYSTEM C_EFI_GUID(0x62da6a56, 0x13fb, 0x485a, 0xa8, 0xda, 0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b) 215 | 216 | typedef enum CEfiTimerDelay { 217 | C_EFI_TIMER_CANCEL, 218 | C_EFI_TIMER_PERIODIC, 219 | C_EFI_TIMER_RELATIVE, 220 | } CEfiTimerDelay; 221 | 222 | #define C_EFI_TPL_APPLICATION 4 223 | #define C_EFI_TPL_CALLBACK 8 224 | #define C_EFI_TPL_NOTIFY 16 225 | #define C_EFI_TPL_HIGH_LEVEL 31 226 | 227 | /* 228 | * Memory management 229 | * 230 | * The UEFI boot services provide you pool-allocation helpers to reserve 231 | * memory. The region for each allocation can be selected by the caller, 232 | * allowing to reserve memory that even survives beyond boot services. However, 233 | * dynamic allocations can only performed via boot services, so no dynamic 234 | * modifications can be done once you exit boot services. 235 | */ 236 | 237 | typedef enum CEfiAllocateType { 238 | C_EFI_ALLOCATE_ANY_PAGES, 239 | C_EFI_ALLOCATE_MAX_ADDRESS, 240 | C_EFI_ALLOCATE_ADDRESS, 241 | _C_EFI_ALLOCATE_TYPE_N, 242 | } CEfiAllocateType; 243 | 244 | typedef enum CEfiMemoryType { 245 | C_EFI_RESERVED_MEMORY_TYPE, 246 | C_EFI_LOADER_CODE, 247 | C_EFI_LOADER_DATA, 248 | C_EFI_BOOT_SERVICES_CODE, 249 | C_EFI_BOOT_SERVICES_DATA, 250 | C_EFI_RUNTIME_SERVICES_CODE, 251 | C_EFI_RUNTIME_SERVICES_DATA, 252 | C_EFI_CONVENTIONAL_MEMORY, 253 | C_EFI_UNUSABLE_MEMORY, 254 | C_EFI_ACPI_RECLAIM_MEMORY, 255 | C_EFI_ACPI_MEMORY_NVS, 256 | C_EFI_MEMORY_MAPPED_IO, 257 | C_EFI_MEMORY_MAPPED_IO_PORT_SPACE, 258 | C_EFI_PAL_CODE, 259 | C_EFI_PERSISTENT_MEMORY, 260 | _C_EFI_MEMORY_TYPE_N, 261 | } CEfiMemoryType; 262 | 263 | #define C_EFI_MEMORY_UC C_EFI_U64_C(0x0000000000000001) 264 | #define C_EFI_MEMORY_WC C_EFI_U64_C(0x0000000000000002) 265 | #define C_EFI_MEMORY_WT C_EFI_U64_C(0x0000000000000004) 266 | #define C_EFI_MEMORY_WB C_EFI_U64_C(0x0000000000000008) 267 | #define C_EFI_MEMORY_UCE C_EFI_U64_C(0x0000000000000010) 268 | #define C_EFI_MEMORY_WP C_EFI_U64_C(0x0000000000001000) 269 | #define C_EFI_MEMORY_RP C_EFI_U64_C(0x0000000000002000) 270 | #define C_EFI_MEMORY_XP C_EFI_U64_C(0x0000000000004000) 271 | #define C_EFI_MEMORY_NV C_EFI_U64_C(0x0000000000008000) 272 | #define C_EFI_MEMORY_MORE_RELIABLE C_EFI_U64_C(0x0000000000010000) 273 | #define C_EFI_MEMORY_RO C_EFI_U64_C(0x0000000000020000) 274 | #define C_EFI_MEMORY_RUNTIME C_EFI_U64_C(0x8000000000000000) 275 | 276 | #define C_EFI_MEMORY_DESCRIPTOR_VERSION C_EFI_U32_C(0x00000001) 277 | 278 | typedef struct CEfiMemoryDescriptor { 279 | CEfiU32 type; 280 | CEfiPhysicalAddress physical_start; 281 | CEfiVirtualAddress virtual_start; 282 | CEfiU64 number_of_pages; 283 | CEfiU64 attribute; 284 | } CEfiMemoryDescriptor; 285 | 286 | /* 287 | * Protocol Management 288 | * 289 | * The UEFI driver model provides ways to have bus-drivers, device-drivers, and 290 | * applications as separate, independent entities. They use protocols to 291 | * communicate, and handles to refer to common state. Drivers and devices can 292 | * be registered dynamically at runtime, and can support hotplugging. 293 | */ 294 | 295 | typedef enum CEfiInterfaceType { 296 | C_EFI_NATIVE_INTERFACE, 297 | } CEfiInterfaceType; 298 | 299 | typedef enum CEfiLocateSearchType { 300 | C_EFI_ALL_HANDLES, 301 | C_EFI_BY_REGISTER_NOTIFY, 302 | C_EFI_BY_PROTOCOL, 303 | } CEfiLocateSearchType; 304 | 305 | #define C_EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL C_EFI_U32_C(0x00000001) 306 | #define C_EFI_OPEN_PROTOCOL_GET_PROTOCOL C_EFI_U32_C(0x00000002) 307 | #define C_EFI_OPEN_PROTOCOL_TEST_PROTOCOL C_EFI_U32_C(0x00000004) 308 | #define C_EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER C_EFI_U32_C(0x00000008) 309 | #define C_EFI_OPEN_PROTOCOL_BY_DRIVER C_EFI_U32_C(0x00000010) 310 | #define C_EFI_OPEN_PROTOCOL_EXCLUSIVE C_EFI_U32_C(0x00000020) 311 | 312 | typedef struct CEfiOpenProtocolInformationEntry { 313 | CEfiHandle agent_handle; 314 | CEfiHandle controller_handle; 315 | CEfiU32 attributes; 316 | CEfiU32 open_count; 317 | } CEfiOpenProtocolInformationEntry; 318 | 319 | /* 320 | * Configuration Tables 321 | * 322 | * The system table contains an array of auxiliary tables, indexed by their 323 | * GUID, called configuration tables. Each table uses the generic 324 | * CEfiConfigurationTable structure as header. 325 | */ 326 | 327 | typedef struct CEfiConfigurationTable { 328 | CEfiGuid vendor_guid; 329 | void *vendor_table; 330 | } CEfiConfigurationTable; 331 | 332 | #define C_EFI_PROPERTIES_TABLE_GUID C_EFI_GUID(0x880aaca3, 0x4adc, 0x4a04, 0x90, 0x79, 0xb7, 0x47, 0x34, 0x8, 0x25, 0xe5) 333 | #define C_EFI_PROPERTIES_TABLE_VERSION C_EFI_U32_C(0x00010000) 334 | 335 | #define C_EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA C_EFI_U64_C(0x1) 336 | 337 | typedef struct CEfiPropertiesTable { 338 | CEfiU32 version; 339 | CEfiU32 length; 340 | CEfiU64 memory_protection_attribute; 341 | } CEfiPropertiesTable; 342 | 343 | #define C_EFI_MEMORY_ATTRIBUTES_TABLE_GUID C_EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20) 344 | #define C_EFI_MEMORY_ATTRIBUTES_TABLE_VERSION C_EFI_U32_C(0x00000001) 345 | 346 | typedef struct CEfiMemoryAttributesTable { 347 | CEfiU32 version; 348 | CEfiU32 number_of_entries; 349 | CEfiU32 descriptor_size; 350 | CEfiU32 reserved; 351 | CEfiMemoryDescriptor entry[]; 352 | } CEfiMemoryAttributesTable; 353 | 354 | /* 355 | * Global Tables 356 | * 357 | * UEFI uses no global state, so all access to UEFI internal state is done 358 | * through vtables you get passed to your entry-point. The global entry is the 359 | * system-table, which encorporates several sub-tables, including the runtime 360 | * and boot service tables, and configuration tables (including vendor 361 | * extensions). 362 | */ 363 | 364 | #define C_EFI_2_70_SYSTEM_TABLE_REVISION ((2 << 16) | (70)) 365 | #define C_EFI_2_60_SYSTEM_TABLE_REVISION ((2 << 16) | (60)) 366 | #define C_EFI_2_50_SYSTEM_TABLE_REVISION ((2 << 16) | (50)) 367 | #define C_EFI_2_40_SYSTEM_TABLE_REVISION ((2 << 16) | (40)) 368 | #define C_EFI_2_31_SYSTEM_TABLE_REVISION ((2 << 16) | (31)) 369 | #define C_EFI_2_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30)) 370 | #define C_EFI_2_20_SYSTEM_TABLE_REVISION ((2 << 16) | (20)) 371 | #define C_EFI_2_10_SYSTEM_TABLE_REVISION ((2 << 16) | (10)) 372 | #define C_EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | ( 0)) 373 | #define C_EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10)) 374 | #define C_EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | ( 2)) 375 | #define C_EFI_SPECIFICATION_VERSION C_EFI_SYSTEM_TABLE_REVISION 376 | #define C_EFI_SYSTEM_TABLE_REVISION C_EFI_2_70_SYSTEM_TABLE_REVISION 377 | #define C_EFI_RUNTIME_SERVICES_REVISION C_EFI_SPECIFICATION_VERSION 378 | #define C_EFI_BOOT_SERVICES_REVISION C_EFI_SPECIFICATION_VERSION 379 | 380 | typedef struct CEfiTableHeader { 381 | CEfiU64 signature; 382 | CEfiU32 revision; 383 | CEfiU32 header_size; 384 | CEfiU32 crc32; 385 | CEfiU32 reserved; 386 | } CEfiTableHeader; 387 | 388 | #define C_EFI_RUNTIME_TABLE_SIGNATURE C_EFI_U64_C(0x56524553544e5552) /* "RUNTSERV" */ 389 | 390 | typedef struct CEfiRuntimeServices { 391 | CEfiTableHeader hdr; 392 | 393 | CEfiStatus (CEFICALL *get_time) ( 394 | CEfiTime *time, 395 | CEfiTimeCapabilities *capabilities 396 | 397 | ); 398 | CEfiStatus (CEFICALL *set_time) ( 399 | CEfiTime *time 400 | ); 401 | CEfiStatus (CEFICALL *get_wakeup_time) ( 402 | CEfiBool *enabled, 403 | CEfiBool *pending, 404 | CEfiTime *time 405 | ); 406 | CEfiStatus (CEFICALL *set_wakeup_time) ( 407 | CEfiBool enable, 408 | CEfiTime *time 409 | ); 410 | 411 | CEfiStatus (CEFICALL *set_virtual_address_map) ( 412 | CEfiUSize memory_map_size, 413 | CEfiUSize descriptor_size, 414 | CEfiU32 descriptor_version, 415 | CEfiMemoryDescriptor *virtual_map 416 | ); 417 | CEfiStatus (CEFICALL *convert_pointer) ( 418 | CEfiUSize debug_disposition, 419 | void **address 420 | ); 421 | 422 | CEfiStatus (CEFICALL *get_variable) ( 423 | CEfiChar16 *variable_name, 424 | CEfiGuid *vendor_guid, 425 | CEfiU32 *attributes, 426 | CEfiUSize *data_size, 427 | void *data 428 | ); 429 | CEfiStatus (CEFICALL *get_next_variable_name) ( 430 | CEfiUSize *variable_name_size, 431 | CEfiChar16 *variable_name, 432 | CEfiGuid *vendor_guid 433 | ); 434 | CEfiStatus (CEFICALL *set_variable) ( 435 | CEfiChar16 *variable_name, 436 | CEfiGuid *vendor_guid, 437 | CEfiU32 attributes, 438 | CEfiUSize data_size, 439 | void *data 440 | ); 441 | 442 | CEfiStatus (CEFICALL *get_next_high_mono_count) ( 443 | CEfiU32 *high_count 444 | ); 445 | void (CEFICALL *reset_system) ( 446 | CEfiResetType reset_type, 447 | CEfiStatus reset_status, 448 | CEfiUSize data_size, 449 | void *reset_data 450 | ); 451 | 452 | CEfiStatus (CEFICALL *update_capsule) ( 453 | CEfiCapsuleHeader **capsule_header_array, 454 | CEfiUSize capsule_count, 455 | CEfiPhysicalAddress scatter_gather_list 456 | ); 457 | CEfiStatus (CEFICALL *query_capsule_capabilities) ( 458 | CEfiCapsuleHeader **capsule_header_array, 459 | CEfiUSize capsule_count, 460 | CEfiU64 *maximum_capsule_size, 461 | CEfiResetType *reset_type 462 | ); 463 | 464 | CEfiStatus (CEFICALL *query_variable_info) ( 465 | CEfiU32 attributes, 466 | CEfiU64 *maximum_variable_storage_size, 467 | CEfiU64 *remaining_variable_storage_size, 468 | CEfiU64 *maximum_variable_size 469 | ); 470 | } CEfiRuntimeServices; 471 | 472 | #define C_EFI_BOOT_SERVICES_SIGNATURE C_EFI_U64_C(0x56524553544f4f42) /* "BOOTSERV" */ 473 | 474 | typedef struct CEfiBootServices { 475 | CEfiTableHeader hdr; 476 | 477 | CEfiTpl (CEFICALL *raise_tpl) ( 478 | CEfiTpl new_tpl 479 | ); 480 | void (CEFICALL *restore_tpl) ( 481 | CEfiTpl old_tpl 482 | ); 483 | 484 | CEfiStatus (CEFICALL *allocate_pages) ( 485 | CEfiAllocateType type, 486 | CEfiMemoryType memory_type, 487 | CEfiUSize pages, 488 | CEfiPhysicalAddress *memory 489 | ); 490 | CEfiStatus (CEFICALL *free_pages) ( 491 | CEfiPhysicalAddress memory, 492 | CEfiUSize pages 493 | ); 494 | CEfiStatus (CEFICALL *get_memory_map) ( 495 | CEfiUSize *memory_map_size, 496 | CEfiMemoryDescriptor *memory_map, 497 | CEfiUSize *map_key, 498 | CEfiUSize *descriptor_size, 499 | CEfiU32 *descriptor_version 500 | ); 501 | CEfiStatus (CEFICALL *allocate_pool) ( 502 | CEfiMemoryType pool_type, 503 | CEfiUSize size, 504 | void **buffer 505 | ); 506 | CEfiStatus (CEFICALL *free_pool) ( 507 | void *buffer 508 | ); 509 | 510 | CEfiStatus (CEFICALL *create_event) ( 511 | CEfiU32 type, 512 | CEfiTpl notify_tpl, 513 | CEfiEventNotify notify_function, 514 | void *notify_context, 515 | CEfiEvent *event 516 | ); 517 | CEfiStatus (CEFICALL *set_timer) ( 518 | CEfiEvent event, 519 | CEfiTimerDelay type, 520 | CEfiU64 trigger_time 521 | ); 522 | CEfiStatus (CEFICALL *wait_for_event) ( 523 | CEfiUSize number_of_events, 524 | CEfiEvent *event, 525 | CEfiUSize *index 526 | ); 527 | CEfiStatus (CEFICALL *signal_event) ( 528 | CEfiEvent event 529 | ); 530 | CEfiStatus (CEFICALL *close_event) ( 531 | CEfiEvent event 532 | ); 533 | CEfiStatus (CEFICALL *check_event) ( 534 | CEfiEvent event 535 | ); 536 | 537 | CEfiStatus (CEFICALL *install_protocol_interface) ( 538 | CEfiHandle *handle, 539 | CEfiGuid *protocol, 540 | CEfiInterfaceType interface_type, 541 | void *interface 542 | ); 543 | CEfiStatus (CEFICALL *reinstall_protocol_interface) ( 544 | CEfiHandle handle, 545 | CEfiGuid *protocol, 546 | void *old_interface, 547 | void *new_interface 548 | ); 549 | CEfiStatus (CEFICALL *uninstall_protocol_interface) ( 550 | CEfiHandle handle, 551 | CEfiGuid *protocol, 552 | void *interface 553 | ); 554 | CEfiStatus (CEFICALL *handle_protocol) ( 555 | CEfiHandle handle, 556 | CEfiGuid *protocol, 557 | void **interface 558 | ); 559 | void *reserved; 560 | CEfiStatus (CEFICALL *register_protocol_notify) ( 561 | CEfiGuid *protocol, 562 | CEfiEvent event, 563 | void **registration 564 | ); 565 | CEfiStatus (CEFICALL *locate_handle) ( 566 | CEfiLocateSearchType search_type, 567 | CEfiGuid *protocol, 568 | void *search_key, 569 | CEfiUSize *buffer_size, 570 | CEfiHandle *buffer 571 | ); 572 | CEfiStatus (CEFICALL *locate_device_path) ( 573 | CEfiGuid *protocol, 574 | CEfiDevicePathProtocol **device_path, 575 | CEfiHandle *device 576 | ); 577 | 578 | CEfiStatus (CEFICALL *install_configuration_table) ( 579 | CEfiGuid *guid, 580 | void *table 581 | ); 582 | 583 | CEfiStatus (CEFICALL *load_image) ( 584 | CEfiBool boot_policy, 585 | CEfiHandle parent_image_handle, 586 | CEfiDevicePathProtocol *device_path, 587 | void *source_buffer, 588 | CEfiUSize source_size, 589 | CEfiHandle *image_handle 590 | ); 591 | CEfiStatus (CEFICALL *start_image) ( 592 | CEfiHandle image_handle, 593 | CEfiUSize *exit_data_size, 594 | CEfiChar16 **exit_data 595 | ); 596 | CEfiStatus (CEFICALL *exit) ( 597 | CEfiHandle image_handle, 598 | CEfiStatus exit_status, 599 | CEfiUSize exit_data_size, 600 | CEfiChar16 *exit_data 601 | ); 602 | CEfiStatus (CEFICALL *unload_image) ( 603 | CEfiHandle image_handle 604 | ); 605 | CEfiStatus (CEFICALL *exit_boot_services) ( 606 | CEfiHandle image_handle, 607 | CEfiUSize map_key 608 | ); 609 | 610 | CEfiStatus (CEFICALL *get_next_monotonic_count) ( 611 | CEfiU64 *count 612 | ); 613 | CEfiStatus (CEFICALL *stall) ( 614 | CEfiUSize microseconds 615 | ); 616 | CEfiStatus (CEFICALL *set_watchdog_timer) ( 617 | CEfiUSize timeout, 618 | CEfiU64 watchdog_code, 619 | CEfiUSize data_size, 620 | CEfiChar16 *watchdog_data 621 | ); 622 | 623 | /* 1.1+ */ 624 | 625 | CEfiStatus (CEFICALL *connect_controller) ( 626 | CEfiHandle controller_handle, 627 | CEfiHandle *driver_image_handle, 628 | CEfiDevicePathProtocol *remaining_device_path, 629 | CEfiBool recursive 630 | ); 631 | CEfiStatus (CEFICALL *disconnect_controller) ( 632 | CEfiHandle controller_handle, 633 | CEfiHandle driver_image_handle, 634 | CEfiHandle child_handle 635 | ); 636 | 637 | CEfiStatus (CEFICALL *open_protocol) ( 638 | CEfiHandle handle, 639 | CEfiGuid *protocol, 640 | void **interface, 641 | CEfiHandle agent_handle, 642 | CEfiHandle controller_handle, 643 | CEfiU32 attributes 644 | ); 645 | CEfiStatus (CEFICALL *close_protocol) ( 646 | CEfiHandle handle, 647 | CEfiGuid *protocol, 648 | CEfiHandle agent_handle, 649 | CEfiHandle controller_handle 650 | ); 651 | CEfiStatus (CEFICALL *open_protocol_information) ( 652 | CEfiHandle handle, 653 | CEfiGuid *protocol, 654 | CEfiOpenProtocolInformationEntry **entry_buffer, 655 | CEfiUSize *entry_count 656 | ); 657 | 658 | CEfiStatus (CEFICALL *protocols_per_handle) ( 659 | CEfiHandle handle, 660 | CEfiGuid ***protocol_buffer, 661 | CEfiUSize *protocol_buffer_count 662 | ); 663 | CEfiStatus (CEFICALL *locate_handle_buffer) ( 664 | CEfiLocateSearchType search_type, 665 | CEfiGuid *protocol, 666 | void *search_key, 667 | CEfiUSize *no_handles, 668 | CEfiHandle **buffer 669 | ); 670 | CEfiStatus (CEFICALL *locate_protocol) ( 671 | CEfiGuid *protocol, 672 | void *registration, 673 | void **interface 674 | ); 675 | CEfiStatus (CEFICALL *install_multiple_protocol_interfaces) ( 676 | CEfiHandle *handle, 677 | ... 678 | ); 679 | CEfiStatus (CEFICALL *uninstall_multiple_protocol_interfaces) ( 680 | CEfiHandle handle, 681 | ... 682 | ); 683 | 684 | CEfiStatus (CEFICALL *calculate_crc32) ( 685 | void *data, 686 | CEfiUSize data_size, 687 | CEfiU32 *crc32 688 | ); 689 | 690 | void (CEFICALL *copy_mem) ( 691 | void *destination, 692 | void *source, 693 | CEfiUSize length 694 | ); 695 | void (CEFICALL *set_mem) ( 696 | void *buffer, 697 | CEfiUSize size, 698 | CEfiU8 value 699 | ); 700 | 701 | /* 2.0+ */ 702 | 703 | CEfiStatus (CEFICALL *create_event_ex) ( 704 | CEfiU32 type, 705 | CEfiTpl notify_tpl, 706 | CEfiEventNotify notify_function, 707 | void *notify_context, 708 | CEfiGuid *event_group, 709 | CEfiEvent *event 710 | ); 711 | } CEfiBootServices; 712 | 713 | #define C_EFI_SYSTEM_TABLE_SIGNATURE C_EFI_U64_C(0x5453595320494249) /* "IBI SYST" */ 714 | 715 | typedef struct CEfiSystemTable { 716 | CEfiTableHeader hdr; 717 | CEfiChar16 *firmware_vendor; 718 | CEfiU32 firmware_revision; 719 | 720 | CEfiHandle console_in_handle; 721 | CEfiSimpleTextInputProtocol *con_in; 722 | CEfiHandle console_out_handle; 723 | CEfiSimpleTextOutputProtocol *con_out; 724 | CEfiHandle standard_error_handle; 725 | CEfiSimpleTextOutputProtocol *std_err; 726 | 727 | CEfiRuntimeServices *runtime_services; 728 | CEfiBootServices *boot_services; 729 | 730 | CEfiUSize number_of_table_entries; 731 | CEfiConfigurationTable *configuration_table; 732 | } CEfiSystemTable; 733 | 734 | #ifdef __cplusplus 735 | } 736 | #endif 737 | -------------------------------------------------------------------------------- /src/c-efi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * UEFI Reference Specification Protocol Constants and Definitions 5 | * 6 | * This project provides a basic UEFI environment as well as the definitions of 7 | * protocol constants from the UEFI Specification. The c-efi-base.h header 8 | * provides the basic programming environment that is necessary once you 9 | * compile without a Standard C Library. The c-efi-system.h header provides the 10 | * UEFI system integration including global vtables and types. All remaining 11 | * functionality is provided in UEFI protocols. 12 | */ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /src/example-hello-world.c: -------------------------------------------------------------------------------- 1 | /* 2 | * UEFI Hello World 3 | * 4 | * This is the classic 'Hello World' example written against c-efi. It uses the 5 | * standard console to print a string, then waits for any key-event before 6 | * exiting. 7 | */ 8 | 9 | #include 10 | 11 | CEfiStatus efi_main(CEfiHandle h, CEfiSystemTable *st) { 12 | CEfiStatus r; 13 | CEfiUSize x; 14 | 15 | r = st->con_out->output_string(st->con_out, L"Hello World!\n"); 16 | if (C_EFI_ERROR(r)) 17 | return r; 18 | 19 | r = st->boot_services->wait_for_event(1, &st->con_in->wait_for_key, &x); 20 | if (C_EFI_ERROR(r)) 21 | return r; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/meson.build: -------------------------------------------------------------------------------- 1 | # 2 | # Install meson cross-files 3 | # 4 | 5 | if use_mesoncross 6 | install_data( 7 | [ 8 | 'x86_64-unknown-uefi.mesoncross.ini' 9 | ], 10 | rename: [ 11 | 'x86_64-unknown-uefi' 12 | ], 13 | install_dir: mesoncrossdir, 14 | ) 15 | endif 16 | 17 | # 18 | # target: libcefi.dep 19 | # 20 | 21 | libcefi_dep = declare_dependency( 22 | include_directories: include_directories('.'), 23 | version: meson.project_version(), 24 | ) 25 | 26 | if not meson.is_subproject() 27 | install_headers( 28 | 'c-efi.h', 29 | 'c-efi-base.h', 30 | 'c-efi-system.h', 31 | 'c-efi-protocol-device-path.h', 32 | 'c-efi-protocol-device-path-from-text.h', 33 | 'c-efi-protocol-device-path-to-text.h', 34 | 'c-efi-protocol-device-path-utility.h', 35 | 'c-efi-protocol-loaded-image.h', 36 | 'c-efi-protocol-loaded-image-device-path.h', 37 | ) 38 | 39 | mod_pkgconfig.generate( 40 | version: meson.project_version(), 41 | name: 'libcefi', 42 | filebase: 'libcefi', 43 | description: project_description, 44 | ) 45 | endif 46 | 47 | # 48 | # target: example-* 49 | # 50 | 51 | example_hello_world = executable('example-hello-world', ['example-hello-world.c'], dependencies: libcefi_dep) 52 | 53 | # 54 | # target: test-* 55 | # 56 | 57 | test_api = executable('test-api', ['test-api.c'], native: true, dependencies: libcefi_dep) 58 | test('API Symbol Visibility', test_api) 59 | 60 | test_basic = executable('test-basic', ['test-basic.c'], native: true, dependencies: libcefi_dep) 61 | test('Basic Functionality', test_basic) 62 | 63 | test_native = executable('test-native', ['test-native.c'], dependencies: libcefi_dep) 64 | test('Basic Native UEFI Tests', test_native) 65 | -------------------------------------------------------------------------------- /src/test-api.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tests for Public API 3 | * This simply tests for visibility of all API symbols. It does not invoke any 4 | * code nor test for fitness for purpose. 5 | */ 6 | 7 | #include 8 | #include 9 | #include "c-efi.h" 10 | 11 | static void test_api(void) { 12 | assert(!C_EFI_NULL); 13 | assert(C_EFI_JOIN(1, 1) == 11); 14 | } 15 | 16 | int main(int argc, char **argv) { 17 | test_api(); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/test-basic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Basic Functionality Tests 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "c-efi.h" 11 | 12 | static void test_basic(void) { 13 | /* 14 | * Verify basic types and definitions. These should all be 15 | * straightforward. 16 | */ 17 | { 18 | assert(C_EFI_NULL == NULL); 19 | assert(C_EFI_NULL == 0); 20 | 21 | assert(sizeof(CEfiI8) == 1); 22 | assert(sizeof(CEfiU8) == 1); 23 | assert(sizeof(CEfiI16) == 2); 24 | assert(sizeof(CEfiU16) == 2); 25 | assert(sizeof(CEfiI32) == 4); 26 | assert(sizeof(CEfiU32) == 4); 27 | assert(sizeof(CEfiI64) == 8); 28 | assert(sizeof(CEfiU64) == 8); 29 | 30 | assert(C_EFI_I8_C(0) == 0); 31 | assert(C_EFI_U8_C(0) == 0); 32 | assert(C_EFI_I16_C(0) == 0); 33 | assert(C_EFI_U16_C(0) == 0); 34 | assert(C_EFI_I32_C(0) == 0); 35 | assert(C_EFI_U32_C(0) == 0); 36 | assert(C_EFI_I64_C(0) == 0); 37 | assert(C_EFI_U64_C(0) == 0); 38 | 39 | assert(sizeof(CEfiISize) == sizeof(void *)); 40 | assert(sizeof(CEfiUSize) == sizeof(void *)); 41 | 42 | assert(sizeof(CEfiChar8) == sizeof(CEfiU8)); 43 | assert(sizeof(CEfiChar16) == sizeof(CEfiU16)); 44 | } 45 | 46 | /* 47 | * Intel defines BOOLEAN as UINT8, so make sure we are binary 48 | * compatible. 49 | */ 50 | { 51 | assert(sizeof(CEfiBool) == sizeof(uint8_t)); 52 | assert(C_EFI_TRUE); 53 | assert(!C_EFI_FALSE); 54 | assert((int)C_EFI_TRUE == 1); 55 | assert((int)C_EFI_FALSE == 0); 56 | } 57 | 58 | /* 59 | * Verify some status codes with constants taken directly from the 60 | * spec. Note that CEfiStatus depends on CEfiUSize, as such matches the 61 | * target architecture word width. 62 | */ 63 | { 64 | assert(!C_EFI_SUCCESS); 65 | assert(sizeof(C_EFI_SUCCESS) == sizeof(CEfiStatus)); 66 | assert(!C_EFI_ERROR(C_EFI_SUCCESS)); 67 | assert(C_EFI_ERROR(C_EFI_UNSUPPORTED)); 68 | 69 | if (sizeof(CEfiStatus) == sizeof(uint32_t)) { 70 | assert((uint32_t)C_EFI_UNSUPPORTED == (uint32_t)0x80000003UL); 71 | } else if (sizeof(CEfiStatus) == sizeof(uint64_t)) { 72 | assert((uint64_t)C_EFI_UNSUPPORTED == (uint64_t)0x8000000000000003UL); 73 | } else { 74 | assert(0); 75 | } 76 | } 77 | 78 | /* 79 | * Verify alignment and size of GUID is correct. The type itself is 80 | * required to be 64bit aligned, 128bit in size. 81 | */ 82 | { 83 | CEfiGuid id = {}; 84 | 85 | assert(_Alignof(CEfiGuid) >= 8); 86 | assert(_Alignof(id) >= 8); 87 | assert(_Alignof(id.u8) >= 8); 88 | assert(_Alignof(id.u16) >= 8); 89 | assert(_Alignof(id.u32) >= 8); 90 | assert(_Alignof(id.u64) >= 8); 91 | 92 | assert(sizeof(CEfiGuid) == 16); 93 | assert(sizeof(id) == 16); 94 | assert(sizeof(id.u8) == 16); 95 | assert(sizeof(id.u16) == 16); 96 | assert(sizeof(id.u32) == 16); 97 | assert(sizeof(id.u64) == 16); 98 | } 99 | 100 | /* 101 | * Verify alignments and size of networking types. 102 | */ 103 | { 104 | assert(_Alignof(CEfiMacAddress) == 1); 105 | assert(_Alignof(CEfiIpv4Address) == 1); 106 | assert(_Alignof(CEfiIpv6Address) == 1); 107 | assert(_Alignof(CEfiIpAddress) == 4); 108 | 109 | assert(sizeof(CEfiMacAddress) == 32); 110 | assert(sizeof(CEfiIpv4Address) == 4); 111 | assert(sizeof(CEfiIpv6Address) == 16); 112 | assert(sizeof(CEfiIpAddress) == 16); 113 | } 114 | } 115 | 116 | int main(int argc, char **argv) { 117 | test_basic(); 118 | return 0; 119 | } 120 | -------------------------------------------------------------------------------- /src/test-native.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Basic Native UEFI Tests 3 | */ 4 | 5 | #include "c-efi.h" 6 | 7 | #define ASSERT_RETURN(_expr) { \ 8 | if (!(_expr)) \ 9 | return -1; \ 10 | } 11 | 12 | static int test_native(void) { 13 | ASSERT_RETURN(!C_EFI_NULL); 14 | 15 | return 0; 16 | } 17 | 18 | CEfiStatus efi_main(CEfiHandle h, CEfiSystemTable *st) { 19 | return test_native(); 20 | } 21 | -------------------------------------------------------------------------------- /src/x86_64-unknown-uefi.mesoncross.ini: -------------------------------------------------------------------------------- 1 | # 2 | # x86_64-unknown-uefi - UEFI Target Specification 3 | # 4 | # This is a meson-cross file to compile meson-based projects for UEFI 5 | # environments. We use 'clang' for these targets, as 'gcc' has several 6 | # shortcomings compiling for PE+ on non-windows systems. 7 | # 8 | # Since UEFI systems use the basic MS Windows calling convention and PE+ format 9 | # this file looks similar to cross-compiling for Windows 64bit. A few things 10 | # are special, though: 11 | # 12 | # - We need to disable the red-zone, as must be able to serve timer 13 | # interrupts. Similarly, we disable the stack-protector and compile as 14 | # free-standing binary. 15 | # 16 | # - UEFI uses UCS-2 strings, so use the 'short-wchar' option to allow use of 17 | # wide-string literals in combination with UEFI APIs. 18 | # 19 | # - We disable MMX and SSE code-generation. Note that UEFI generally allows 20 | # using MMX and SSE and it works fine. However, several existing systems 21 | # seem to lack initialization of the FP co-processors, and thus causing 22 | # exceptions to be thrown with random exception handlers. We therefore 23 | # disable both MMX and SSE by default. You can override this in the 24 | # individual projects, if you want. 25 | # 26 | # - Force 'lld-link' and link as EFI-Application. We must use the LLVM linker 27 | # as we have to cross link into PE+ binaries (which again GNU binutils seems 28 | # to only support through mingw). Furthermore, we need to set the correct 29 | # PE/COFF subsystem and define an entry-point compatible with the reference 30 | # implementation. 31 | # 32 | [binaries] 33 | c = 'clang' 34 | cpp = 'clang' 35 | ar = 'ar' 36 | strip = 'strip' 37 | pkgconfig = 'pkg-config' 38 | 39 | [properties] 40 | needs_exe_wrapper = true 41 | c_args = 42 | [ 43 | '-target', 'x86_64-unknown-windows', 44 | '-fno-stack-protector', 45 | '-ffreestanding', 46 | '-fshort-wchar', 47 | '-mno-red-zone', 48 | '-mno-mmx', 49 | '-mno-sse', 50 | ] 51 | c_link_args = 52 | [ 53 | '-target', 'x86_64-unknown-windows', 54 | '-nostdlib', 55 | '-Wl,-entry:efi_main', 56 | '-Wl,-subsystem:efi_application', 57 | '-fuse-ld=lld-link', 58 | ] 59 | 60 | [host_machine] 61 | system = 'uefi' 62 | cpu_family = 'x86_64' 63 | cpu = 'x86_64' 64 | endian = 'little' 65 | --------------------------------------------------------------------------------