Page 1 of 1

UEFI Print(%s) writes weird characters

Posted: Wed Apr 12, 2023 5:40 pm
by devc1
I don't know why suddenly when I tried to add DLL Loading to my bootloader, Some weird stuff started to happen, first when I loaded one function from one DLL it worked fine but as soon as I added another function the bootloader does no longer work (and the loading code is copied from the previous os which was successful in loading relocatable importing and exporting pe images).

Print() prints some weird stuff when adding an ASCII String Argument "%s" even on the serial.log.

The Kernel "/src/nos" imports "syscruntime.lib" which is the kernel mode version of my cruntime library (basicly its exactly the same as cruntime.lib but compiled with /SUBSYSTEM:native

I don't see anything wrong in the loader "/src/boot/efi/amd64/load.c"

However even if I try to print a string at the start of UefiEntry to same weird thing happens, but if I use a unicode string "%ls" it works fine.

Libraries code is at "/lib/"

project NewOS : https://github.com/NXTdevosc1/New-Operating-System

Although the bootloader gets extremely larger each time I add a function, now it is at 183KB, I don't think it needs to be more then 25KB

Re: UEFI Print(%s) writes weird characters

Posted: Wed Apr 12, 2023 6:12 pm
by klange
EFI does not have a "Print" function, but gnu-efi's efilib does.

The efilib Print function takes a UTF16 format string, and the "%s" formatter also expects UTF16 arguments. If you want to pass an ASCII string argument, it has a "%a" format specifier.

Here's a reference from someone's mirror of gnu-efi: https://github.com/vathpela/gnu-efi/blo ... nt.c#L1055

Re: UEFI Print(%s) writes weird characters

Posted: Wed Apr 12, 2023 10:37 pm
by Octocontrabass
It looks like this is actually EDK2 and not GNU-EFI, but EDK2 also provides a Print() function, and EDK2's Print() function also requires "%a" for ASCII strings.

Re: UEFI Print(%s) writes weird characters

Posted: Wed Apr 12, 2023 11:14 pm
by klange
Octocontrabass wrote:It looks like this is actually EDK2 and not GNU-EFI, but EDK2 also provides a Print() function, and EDK2's Print() function also requires "%a" for ASCII strings.
Ah, my mistake - though, the UefiLib in EDK2 is a descendent of the efilib in gnu-efi, which is why these work the same way :)

Re: UEFI Print(%s) writes weird characters

Posted: Fri Apr 14, 2023 5:44 am
by devc1
Thanks ill try that.

Re: UEFI Print(%s) writes weird characters

Posted: Fri Apr 14, 2023 4:15 pm
by devc1
It's working !