UEFI Print(%s) writes weird characters

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

UEFI Print(%s) writes weird characters

Post 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
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: UEFI Print(%s) writes weird characters

Post 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
Octocontrabass
Member
Member
Posts: 5418
Joined: Mon Mar 25, 2013 7:01 pm

Re: UEFI Print(%s) writes weird characters

Post 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.
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: UEFI Print(%s) writes weird characters

Post 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 :)
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

Re: UEFI Print(%s) writes weird characters

Post by devc1 »

Thanks ill try that.
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

Re: UEFI Print(%s) writes weird characters

Post by devc1 »

It's working !
Post Reply