Why my code about efi raise errors when I compile the same code to Aarch64,LoongArch64,Riscv64

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
TYDQSoft
Posts: 8
Joined: Sun Mar 17, 2024 9:11 am
Libera.chat IRC: TYDQSoft

Why my code about efi raise errors when I compile the same code to Aarch64,LoongArch64,Riscv64

Post by TYDQSoft »

These days I am trying to boot my tiny and test kernel with my own uefi bootloader.
On x64 platform my system booted successfully.However,when I trying to cross compile the system to other platform such as AArch64,My pascal code failed to boot and this error was located to my procedure efi_initialize that is just a statement that ParentImageHandle:=InputImageHandle;.I cannot understand why this code raises error,it is just a variable=value statement.Why this code is wrong as it is returned a great value for $8000000000000000?
This is my code that error occurs:

Code: Select all

program uefiloader;

{$MODE FPC}

uses uefi,binarybase,bootconfig,graphics;
    
function efi_main(ImageHandle:efi_handle;systemtable:Pefi_system_table):efi_status;{$ifdef cpux86_64}MS_ABI_Default;{$endif}{$ifdef cpui386}cdecl;{$endif}[public,alias:'_start'];
var {For checking elf file}
    sfsp:Pefi_simple_file_system_protocol;
    fp:Pefi_file_protocol;
    efsl:efi_file_system_list;
    i,j,count,procindex:natuint;
    status:efi_status;
    finfo:efi_file_info;
    finfosize:natuint;
    proccontent:Pointer;
    procsize:natuint;
    partstr:PWideChar;
    gpl:efi_graphics_list;
    isgraphics:boolean;
    loaderscreenconfig:screen_config;
    {For elf structure}
    header:elf64_header;
    program_headers:^elf64_program_header;
    LowAddress,HighAddress:qword;
    PageCount:qword;
    KernelRelocateBase:qword;
    RelocateOffset:qword;
    ZeroStart:^qword;
    SourceStart,DestStart:^byte;
    KernelEntry:Pointer;
    bool:array[1..4] of boolean;
    {For loading elf files}
    initparam:Psys_parameter_item;
    param:sys_parameter;
    func:sys_parameter_function;
    funcandparam:sys_parameter_function_and_parameter;
    res:Pointer;
    {For memory initializtion}
    memorymap:efi_memory_map;
    memoryavailable:efi_memory_result;
    addressoffset:natuint;
    allocaddress:natuint;
begin  
 {Initialize the uefi loader}
 efi_initialize(ImageHandle,systemtable);{Where the error occurs}
 efi_console_initialize(efi_bck_black,efi_lightgrey,0);
 efsl:=efi_list_all_file_system(2);
I am using elf2efi built by myself to convert the elf file to efi file.Does this tool have the error?
My Repository is on the github:https://github.com/TYDQSoft/UEFIPascalOS.
Octocontrabass
Member
Member
Posts: 5418
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why my code about efi raise errors when I compile the same code to Aarch64,LoongArch64,Riscv64

Post by Octocontrabass »

TYDQSoft wrote: Tue Aug 20, 2024 8:16 amI cannot understand why this code raises error,it is just a variable=value statement.
It's a global variable. Did the compiler use an absolute address to access the global variable? Does your PE binary have the correct relocations for the absolute address?

Some UEFI implementations (like OVMF) will try to load PE binaries at their base address. When this happens, your PE binary will work even if there's a problem with the relocations.
TYDQSoft
Posts: 8
Joined: Sun Mar 17, 2024 9:11 am
Libera.chat IRC: TYDQSoft

Re: Why my code about efi raise errors when I compile the same code to Aarch64,LoongArch64,Riscv64

Post by TYDQSoft »

Octocontrabass wrote: Tue Aug 20, 2024 12:10 pm
TYDQSoft wrote: Tue Aug 20, 2024 8:16 amI cannot understand why this code raises error,it is just a variable=value statement.
It's a global variable. Did the compiler use an absolute address to access the global variable? Does your PE binary have the correct relocations for the absolute address?

Some UEFI implementations (like OVMF) will try to load PE binaries at their base address. When this happens, your PE binary will work even if there's a problem with the relocations.
Yes.However,the compiler use an absolute address to access the global variable needs to be tested.I will test for this.I will post my test result later.
Post Reply