freebsd-src icon indicating copy to clipboard operation
freebsd-src copied to clipboard

Add support for 64-bit machines with 32-bit UEFI implementations

Open VexedUXR opened this issue 1 year ago • 44 comments

Some machines (mostly baytrail notebooks) have 64-bit capable cpus but are stuck on 32-bit uefi firmware, with so CSM.

Add support for them by making the amd64 loader compile itself again with DO32=1, (see the amd64 Makefile.inc) all of the extra ia32 specific code is in loader/arch/amd64/ia32. The loader can be disabled using MK_LOADER_IA32.

Tested on qemu and the Acer one 10 s1002 Also cross-compiled to armv6 to make sure nothing broke.

VexedUXR avatar Feb 03 '24 09:02 VexedUXR

Cant reproduce build errors locally. Maybe this can be fixed by using __aligned to force padding? Edit: Instead of casting

VexedUXR avatar Feb 03 '24 10:02 VexedUXR

Clang seems to ignore -Wint-to-pointer-cast and -Wpointer-to-int-cast when -m32 is specified. Can reproduce errors with gcc toolchain.

VexedUXR avatar Feb 03 '24 16:02 VexedUXR

This makes it easier for me to look at this and to have a conversation. I got too busy last time and naybe this way we'll keep momentum.

bsdimp avatar Feb 03 '24 16:02 bsdimp

Fixed. Everything looks fine now

VexedUXR avatar Feb 03 '24 23:02 VexedUXR

Fixed rsdp cast

VexedUXR avatar Feb 04 '24 18:02 VexedUXR

OK. I've ordered an inexpensive laptop to see if I can use it to test this. Generally I like this, but it's all one commit and I've left a few comments, but I'm thinking about others Some of this I think that I can land quickly, but other bits need a little refinement. If things are broken down better I can do that. I'll tag a couple of things first.

bsdimp avatar Feb 06 '24 19:02 bsdimp

Alright, I split everything into a total of 5 commits:

  1. Allow overriding NEWVERSWHAT
  2. Add the LOADER_IA32 build option
  3. Add libefi32
  4. The main commit
  5. Script changes, copy the ia32 loader

I put LOADER_IA32 on its own since it doesn't really fit with adding libefi32. Also about the comment in defs.mk, I ended up moving the comment explaining DO32 up to its first use.

Of course, let me know if you want any of these reverted, thanks!

VexedUXR avatar Feb 07 '24 17:02 VexedUXR

I'll take a look at this. IIRC, I can use qemu-system-x86_64 to test this if I load the i386 EDKII firmware, right? Thanks for the updates.

bsdimp avatar Feb 07 '24 20:02 bsdimp

IIRC, I can use qemu-system-x86_64 to test this if I load the i386 EDKII firmware, right?

Yea, thats how I did it

VexedUXR avatar Feb 07 '24 20:02 VexedUXR

Just a little cleanup: Use NULL instead of 0. Also, put the 32-bit compatibility fixes in their own commit.

VexedUXR avatar Feb 23 '24 06:02 VexedUXR

I'll try to get to this before we have the 14.1 freeze.

bsdimp avatar Mar 12 '24 19:03 bsdimp

I'll try to get to this before we have the 14.1 freeze.

Great :)

VexedUXR avatar Mar 13 '24 11:03 VexedUXR

I've changed all of the __uefi64__ to __i386__ and fixed the merge conflicts, I also updated the linker script stuff in accordance with 5b3b9a5. I added my name to the copyright notice at the top of the amd64_tramp32.S file since I rewrote most of it, let me know if you dont what that.

Also, thers a typo at https://github.com/freebsd/freebsd-src/blob/main/stand/liblua/lutils.h#L37 and I have no idea why it causes the 32-bit loader to crash, but not the 64-bit one, probably some linker weirdness.

Edit: Oh, I didn't realize I had to request a review manually.

VexedUXR avatar Mar 13 '24 17:03 VexedUXR

I thought I'd fixed that typo... It should make it not compile at all..

bsdimp avatar Mar 23 '24 09:03 bsdimp

Wouldn't it just make a set called _LUA_COMPILE_SET instead of Xlua_compile_set

As long as the set isn't accessed outside the macros, there shouldn't be any problems Of course in our case, it is causing problems since we objcopy -j set_Xlua_compile_set

VexedUXR avatar Mar 23 '24 16:03 VexedUXR

I was actually interested in finding out why it only crashed on the 32-bit loader, turns out its fairly straightforward.

With the 32-bit loader, the addend is expected to be present in the set_Xlua_compile_set section, which doesn't exist in this case. The address this section is expected to start at is just full of uninitialized data, so when LUA_FOREACH_SET is used we end up jumping to some garbage and crashing. With the 64-bit loader we get the addend from the relocation entry, so thats not a problem.

Ah, also, while looking into this I noticed that the i386 script I re-added wasn't up to date with d024bc7, I'll check the rest of the script and push a fix soon.

VexedUXR avatar Mar 24 '24 01:03 VexedUXR

This looks closish to being good to go. I'll test it out.

bsdimp avatar Apr 19 '24 23:04 bsdimp

OK. Another round of comments. Apart from the style nits that the style checker highlighted (which I gave advice on), I have worries about uintptr_t only being 4 bytes and whether or not that's a problem.

bsdimp avatar Apr 29 '24 16:04 bsdimp

Ok, I've addressed the comments but I don't think I'll push yet as it looks like there's still some discussion to be had.

VexedUXR avatar Apr 29 '24 21:04 VexedUXR