Commit Graph

124 Commits

Author SHA1 Message Date
Callum Farmer
d9b395ac03
Make CopyMemC call CopyMem
* The last part of this: I hope :)
* ISO C permits overwriting of Src even if it marks Src as CONST
* UEFI marks Src as NON CONST, so forward calls via this function
* Allows us to keep in-line with shim without causing Werror havoc with other downstreams

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-07-04 15:29:04 +01:00
Callum Farmer
f8ebcfc077
Use char16_t literals
Add char16_t('u') literals
Remove wchar_t('L') literals

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-06-24 19:34:51 +01:00
Pete Batard
2d6d426b8c
Enable silent rules for compiler output
This is similar to using automake's silent rules and, just as with automake,
can be disabled by invoking 'make V=1'.

Signed-off-by: Pete Batard <pete@akeo.ie>
2024-05-21 11:45:20 +01:00
Callum Farmer
e3c7731bcc
Fixup functions for new ReallocatePool
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-05-20 12:15:20 +01:00
Callum Farmer
eaa624e71d
Add legacy defines for CopyMem
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-05-20 12:15:19 +01:00
Callum Farmer
f3656c8800
Move ReallocatePool to EDK2 ABI
Fixes ncroxon/gnu-efi#9

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-05-20 12:14:01 +01:00
Callum Farmer
c339e077c8
Restore old CopyMem as CopyMemC
CopyMemC cos CONST Src

Reverts 6b9dae0bef

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-05-19 13:56:07 +01:00
Pete Batard
0c7af72ba8
Fix exception on ARM32 with VS2022 when Print() is invoked
On ARM32 only, it appears that whenever Visual Studio inlines the FloatToString()
call (which it does for Release builds), the resulting executable produces an
"Undefined OpCode Exception" on Print() invocation, regardless of whether there
is an actual float to string conversion occurring there.

To work around this, add an explicit clause to prevent inlining, and do so on all
platform just in case.

Signed-off-by: Pete Batard <pete@akeo.ie>
2024-05-14 13:56:03 +01:00
Pete Batard
630ea144cb
Fix MinGW compilation
Per binutils/docs/as/Section.html, COFF assembly, which is what MinGW uses, does not
allow @type/%type, which is an ELF-only thing. As a result, trying to assemble the
recently modified ctor.S with MinGW produces the error:
  Error: junk at end of line, first unrecognized character is `,'
Fix this by making sure ELF-specifics are only added within ELF-guarded sections.

Note: This fixes the now deleted https://sourceforge.net/p/gnu-efi/bugs/38/

Signed-off-by: Pete Batard <pete@akeo.ie>
2024-05-09 12:56:57 +01:00
Nigel Croxon
a77c70718d
Merge pull request #18 from pbatard/master
Add GitHub Actions Linux/gcc and Windows/VS2022 CI builds
2024-05-08 08:05:08 -04:00
Pete Batard
ac8d6944c2 Use EDK2 compatible names for SMBIOS and AsciiStr functions and GUIDs 2024-05-08 10:51:43 +01:00
Richard Hughes
8272cd905e
Replace 'Copright' with 'Copyright' in file headers
This was hopefully just a typo that has been cargo-culted around the codebase.

It certainly confuses the Red Hat license checker and makes the code copyright
clear.
2024-05-07 13:03:52 +01:00
Callum Farmer
6b9dae0bef
Fixup string functions for new CopyMem
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-04-27 18:26:21 +01:00
Callum Farmer
f5bb548df5
Align RTLIB CopyMem/SetMem with normal versions
Looks like 699e452654 broke rEFInd
(189e405630/)
2024-04-25 15:27:26 +01:00
Peter Jones
31913f8489 Make: make TOPDIR actually work and get rid of unused CDIR
Signed-off-by: Richard Hughes <richard@hughsie.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
2024-03-22 10:24:28 -04:00
Peter Jones
95dbde278c make: Make "make clean" use @ and rm -v everywhere
This makes our "make clean" commands show what they've /removed/, rather
than what the shell code that will be run is.

Signed-off-by: Richard Hughes <richard@hughsie.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
2024-03-22 10:24:28 -04:00
Callum Farmer
419e257f34 ctors.S: Align with linker scripts
Remove end padding
Change start padding to 16

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:24:23 -04:00
Xiaotian Wu
e5b1a35303 add non-executable GNU stack marking on ELF-linux
Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
2024-03-22 10:24:23 -04:00
Callum Farmer
30bf99b81e Update error/warning codes to 2.10
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:24:23 -04:00
Peter Jones
699e452654 Make CopyMem() and SetMem() be EFIAPI
For wildly unknown reasons, EFI Boot Services includes CopyMem() and
SetMem() functions, and they are marked as EFIAPI functions.

This patch marks gnu-efi's CopyMem() and SetMem() as EFIAPI functions,
and makes their exposed API match the misguided nonsense in the EFI
spec, so that they can be used there in a test environment.

Signed-off-by: Peter Jones <pjones@redhat.com>
2024-03-22 10:24:09 -04:00
Callum Farmer
f26e5a6eea ctors.S: Fix section definitions
Using @ doesn't work on ARM32

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2024-03-22 10:06:43 -04:00
Callum Farmer
99730f29b2 Structs with no linkage
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-11 15:12:36 +01:00
Callum Farmer
7dac18443f Re-write entry.c/ctors.S to work better
* Make entry.c work correctly in reverse order
* Remove incorrectly sized (on non-32bit) NULLs from ctors.S

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-07 16:43:20 +01:00
Callum Farmer
4c6962457f entry.c: fini_array is run backwards
fini_array is 65535 to 0 but stored 0 to 65535

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-07 16:43:20 +01:00
Callum Farmer
74b7b5e92c entry.c: Fix null pointer exception
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-07 16:43:09 +01:00
Callum Farmer
9c5403e1e6 Copy marker names from binutils for init/fini
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-04 14:29:47 +01:00
Callum Farmer
b3cc412aad entry.c: .ctors is run backwards
Store forwards, run backwards (65535 to 0)
Ref: 5a8e7e1332/ld/scripttempl/elf.sc (L310)
Ref: https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-04 14:29:47 +01:00
Callum Farmer
97499a0cf2 ctors.S: Use LSB defined section perms
Seems to not be correct at the moment, causes errors.

error: expected the entry size
.section .fini_array, "aM", @fini_array

Change per
https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/specialsections.html

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-05-04 13:59:02 +01:00
Callum Farmer
fd3d975161 ia32 GNUC: Use __asm__ instead of asm
Causes an error when using strict ISO modes as
then asm isn't defined

Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
2023-04-21 13:30:00 +01:00
Richard Hughes
7c89273dbe make: Fix shell exit status handling
Right now whenever we have shell commands with loops, errors in the
middle are accidentally ignored, and make continues to process commands.

This adds 'set -e' to all of those, so they'll propagate back up.

Signed-off-by: Peter Jones <pjones@redhat.com>
2023-04-04 09:28:42 -04:00
Peter Jones
4b5db35e9d Implement Print(L"%p", ptr);
Signed-off-by: Peter Jones <pjones@redhat.com>
2023-04-04 09:28:42 -04:00
Peter Jones
4f8b339fac Make ELF constructors and destructors work
This makes setup and teardown functions defined with
__attribute__((__constructor__) and __attribute__((__destructor__)) work
in normal circumstances in EFI binaries.

A couple of notes:
- it implements both the old-style .ctors/.dtors methods and the newer
  style .init_array/.fini_array ELF constructor and destructor arrays,
  processed in the order:
    .init_array[]
    .ctors[]
    efi_main()
    .dtors[]
    .fini_array[]
- Destructors will only be called if efi_main() exits using "return";
  any call to Exit() will still longjmp() past them.
- InitializeLib() has already been called before constructors run, so
  they don't need to call it (and neither does anything else.)  For
  compatibility, it has been altered so calling it more than once is
  safe.
- No attempt is made to handle any constructor or destructor with a
  prototype other than "void func(void);", but note that InitializeLib
  has been called, so LibImageHandle, ST, BS, and RT are set.
- The init_array/ctor/dtor/fini_array lists aren't the using the GNU
  "CONSTRUCTOR" output section command, so they don't start with a size.
- The lists are individually sorted during the link stage via
  SORT_BY_NAME() in the linker script.
- The default (empty) init_array/ctor/dtor/fini_array lists are padded
  out to 8-byte alignment with ".p2align 3, 0", and each list always has
  at least one ".long 0" at the end of it (even if it's completely
  empty).  As a result, they can have NULLs that need to be skipped.
  The sections they're in are mergeable, so the NULLs don't have to be
  exclusively at the end.
- The ia64 and mips64el arches have not been tested.

Signed-off-by: Peter Jones <pjones@redhat.com>
2023-03-28 08:59:41 -04:00
Peter Jones
f7bf4302e4 Semi-asciibetize _Print()'s formatters.
This is ascii order but with upper and lower case letters mixed, so
things like 'X' and 'x' that use fallthrough still stay together.

Signed-off-by: Peter Jones <pjones@redhat.com>
2023-03-28 08:39:09 -04:00
Peter Jones
cc4ef911ee Remove the accidentally created lib/Makefile.orig
This was added in dae0b4b0b0.

Signed-off-by: Peter Jones <pjones@redhat.com>
2023-03-28 08:38:46 -04:00
bmeng@tinylab.org
0f9c15fe4f riscv: Update SPDX license identifiers
The whole gnu-efi project is licensed under BSD license, see [1].
However some of the RISC-V codes have conflict license identifiers:

- Some mention GPL-2.0+ in the SPDX license part, but the long license
  header indicates it's actually BSD and GPL-2.0+ dual-licensed
- Some mention GPL-2.0+ in the SPDX license part only
- Some do not have any license indication

To have a matching license with the whole project, this commit updates
all RISC-V codes to have the correct SPDX license identifiers
(GPL-2.0+ or BSD dual-license).

Link: https://sourceforge.net/p/gnu-efi/ [1]
Signed-off-by: Bin Meng <bmeng@tinylab.org>
Acked-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2023-03-08 10:32:49 -05:00
b'Nigel Croxon
c2102ae059 Merge /u/mingtaoxt/gnu-efi/ branch master into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/29/
2022-11-16 20:56:17 +00:00
Sergei Trofimovich
803b49c40b */*.S: add non-executable GNU stack marking on ELF-linux
binutils-2.39 enabed a few warning by default
(https://sourceware.org/pipermail/binutils/2022-August/122246.html):

> The ELF linker will now generate a warning message if the stack is made executable.

Let's suppress the warnings in assembly files by adding non-executables
stack markings. This fixes at least systemd build which uses '-Wl,--fatal-warnings':

    https://github.com/systemd/systemd/issues/24226
2022-08-08 11:35:10 -04:00
Sergei Trofimovich
2ed6486834 lib/Makefile: add .o file dependency on libsubdirs targets
Without the change there is no guarantee that .o files will be built
after directories are created for them and build fails as:

    gcc -I/build/gnu-efi-code//lib ... -c lib/runtime/rtstr.c -o runtime/rtstr.o
    Assembler messages:
    Fatal error: can't create runtime/rtstr.o: No such file or directory
2022-07-25 10:39:43 -04:00
zhoumingtao
5849eacdce use jr instead of jirl
jirl -> jr
2022-07-07 15:16:10 +08:00
zhoumingtao
e7db4418b1 Add support for LoongArch64 architecture 2021-12-30 15:39:47 +08:00
b'Nigel Croxon
269ef9dbc7 Merge /u/abeato/gnu-efi/ branch add-guids into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/26/
2021-07-16 16:48:28 +00:00
Pete Batard
4ef183353c Fix VS2019 Code Analysis warnings
When compiling for x64, Visual Studio 2019's Code Analysis produces the following warnings:

C:\Projects\gnu-efi\lib\print.c(1380): warning C26451: Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '+' to avoid overflow (io.2).
C:\Projects\gnu-efi\lib\smbios.c(47): warning C26451: Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '+' to avoid overflow (io.2).
C:\Projects\gnu-efi\lib\str.c(289): warning C26451: Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '-' to avoid overflow (io.2).

Fix these by adding an explicit cast to UINTN.
2021-07-16 12:43:24 -04:00
Alfonso Sánchez-Beato
fbbbf47e5c Add definitions for the EFI device tree table
Add definitions for the EFI device tree table, as specified in UEFI
specification 2.9 (March 2021).

Signed-off-by: Alfonso Sánchez-Beato <alfonso.sanchez-beato@canonical.com>
2021-07-16 16:36:46 +02:00
Heinrich Schuchardt
e2fc15ae0e lib/str: simplify Atoi()
Checking that str is non-zero is superfluous in

	(*str && *str == ' ')

0x20 is always non-zero.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2021-06-22 00:17:00 +02:00
Heinrich Schuchardt
500c10f191 lib/misc: avoid NULL dereference in LibInsertToTailOfBootOrder
AllocatePool() may return NULL. We must check the return value before
dereferencing it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2021-06-22 00:17:00 +02:00
Heinrich Schuchardt
70402aa91d lib/hand: missing va_end() in LibReinstallProtocolInterfaces()
For each va_start() there must be a call to va_end().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2021-06-22 00:17:00 +02:00
b'Nigel Croxon
3676bc353c Merge /u/xypron/gnu-efi/ branch riscv64 into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/17/
2021-04-05 14:13:03 +00:00
b'Nigel Croxon
ea4c77ffc5 Merge /u/xypron/gnu-efi/ branch va_args into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/16/
2021-04-05 14:12:39 +00:00
b'Nigel Croxon
e686743ba6 Merge /u/xypron/gnu-efi/ branch xtoi into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/15/
2021-04-05 14:11:53 +00:00
b'Nigel Croxon
2a1200f36f Merge /u/kagurazakakotor/gnu-efi/ branch shell-protocol into master
https://sourceforge.net/p/gnu-efi/code/merge-requests/13/
2021-04-05 14:11:15 +00:00