Forum > FPC development

Does anyone know why my code halts and raise error when in AA64,RV64,LA64 UEFI?

(1/4) > >>

TYDQ:
My full pascal code is in https://github.com/TYDQSoft/UEFIPascalOS/tree/main(Contains my pascal OS code and elf2efi code)
I have used my elf2efi utility (Pascal-based program running on linux,which programmed by me) to converts my elf file to UEFI pecoff executable.To simulate the elf file executation as a pecoff file,all position relation(Not absolute address) will not changed by this program.
This is the my error pascal code segment about where the error occurs in LA64(LoongArch64,due to its error raising is friendly and according the error exception,I positioned this error directly on this code):

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure efi_initialize(InputImageHandle:efi_handle;InputSystemTable:Pefi_system_table);[public,alias:'EFI_INITIALIZE'];begin ParentImageHandle:=InputImageHandle; GlobalSystemTable:=InputSystemTable;end;And that is where the error occurs in the main program(Start of the program to where the error occurs):

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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);I know FPC in other architecture uses default calling convention and UEFI in architecture which is not x64 uses this too,Using default calling convention is not wrong.However,while reading the assembly code generated,I was confused about why my efi_initialize have error after I convert the elf file to UEFI pecoff file.Does anyone know why my code raise the error(It is raised by UEFI internal debugger) and how can I fix it?(Due to my code cannot pass when in Aarch64,LoongArch,RiscV UEFI)

TYDQ:
Is it too hard for us to respond?
 ;)

Laksen:
Maybe if you said what failed, and gave examples of the disassembly on the address where it failed?

TYDQ:

--- Quote from: Laksen on August 22, 2024, 12:38:59 am ---Maybe if you said what failed, and gave examples of the disassembly on the address where it failed?

--- End quote ---
This is generated assembly code from fpc,I will mark where the error occurs:

--- Code: ASM  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---.section .text.n_uefi_$$_efi_initialize$pointer$pefi_system_table,"ax"        .balign 8.globl  UEFI_$$_EFI_INITIALIZE$POINTER$PEFI_SYSTEM_TABLE        .type   UEFI_$$_EFI_INITIALIZE$POINTER$PEFI_SYSTEM_TABLE,@functionUEFI_$$_EFI_INITIALIZE$POINTER$PEFI_SYSTEM_TABLE:.globl  EFI_INITIALIZE        .type   EFI_INITIALIZE,@functionEFI_INITIALIZE:.Lc14:# [2874] begin        addi.d  $sp,$sp,-32.Lc15:        st.d    $fp,$sp,16.Lc16:        addi.d  $fp,$sp,32.Lc17:# Var InputImageHandle located at $r3+0, size=OS_64# Var InputSystemTable located at $r3+8, size=OS_64        st.d    $a0,$sp,0        st.d    $a1,$sp,8# [2875] ParentImageHandle:=InputImageHandle; GlobalSystemTable:=InputSystemTable;        move    $t0,$sp        pcalau12i       $t1,%got_pc_hi20(TC_$UEFI_$$_PARENTIMAGEHANDLE)        ld.d    $t1,$t1,%got_pc_lo12(TC_$UEFI_$$_PARENTIMAGEHANDLE)        ld.d    $t0,$t0,0        st.d    $t0,$t1,0 #That is where the error occurs.        addi.d  $t1,$sp,8        pcalau12i       $t0,%got_pc_hi20(TC_$UEFI_$$_GLOBALSYSTEMTABLE)        ld.d    $t0,$t0,%got_pc_lo12(TC_$UEFI_$$_GLOBALSYSTEMTABLE)        ld.d    $t1,$t1,0        st.d    $t1,$t0,0# [2876] end;        addi.d  $sp,$fp,-32        ld.d    $fp,$sp,16AArch64 and Riscv64 UEFI internal debugger don't show the ImageBase and EntryPoint address,So I don't have the way to find out where the error occurs in disassembly.

TYDQ:

--- Quote from: Laksen on August 22, 2024, 12:38:59 am ---Maybe if you said what failed, and gave examples of the disassembly on the address where it failed?

--- End quote ---
I have read the assembly in aarch64 target:

--- Code: ASM  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---.section .text.n_uefi_$$_efi_console_get_max_row_and_max_column,"ax"        .balign 8.globl  UEFI_$$_EFI_CONSOLE_GET_MAX_ROW_AND_MAX_COLUMN        .type   UEFI_$$_EFI_CONSOLE_GET_MAX_ROW_AND_MAX_COLUMN,@functionUEFI_$$_EFI_CONSOLE_GET_MAX_ROW_AND_MAX_COLUMN:.globl  EFI_CONSOLE_GET_MAX_ROW_AND_MAX_COLUMN        .type   EFI_CONSOLE_GET_MAX_ROW_AND_MAX_COLUMN,@functionEFI_CONSOLE_GET_MAX_ROW_AND_MAX_COLUMN:.Lc90:// [3330] begin        stp     x29,x30,[sp, #-16]!.Lc91:        mov     x29,sp.Lc92:        sub     sp,sp,#64// Var maxc located at sp+0, size=OS_64// Var maxr located at sp+8, size=OS_64// Var maxcharsize located at sp+16, size=OS_64// Var rescolumn located at sp+24, size=OS_64// Var resrow located at sp+32, size=OS_64// Var maxcharindex located at sp+40, size=OS_64// Var status located at sp+48, size=OS_S64// Var i located at sp+56, size=OS_8// [3331] i:=0; status:=efi_success; maxcharsize:=2000; maxcharindex:=1; rescolumn:=80; resrow:=25;        strb    wzr,[sp, #56]        str     xzr,[sp, #48]        movz    x0,#2000        str     x0,[sp, #16]        movz    x0,#1        str     x0,[sp, #40]        movz    x0,#80        str     x0,[sp, #24]        movz    x0,#25        str     x0,[sp, #32]// [3332] GlobalSystemTable^.ConOut^.SetMode(GlobalSystemTable^.ConOut,0);        adrp    x0,TC_$UEFI_$$_GLOBALSYSTEMTABLE        add     x0,x0,:lo12:TC_$UEFI_$$_GLOBALSYSTEMTABLE        ldr     x0,[x0]        ldr     x0,[x0, #64] #that is where error occurs in assembly        movz    x1,#0        adrp    x2,TC_$UEFI_$$_GLOBALSYSTEMTABLE        add     x2,x2,:lo12:TC_$UEFI_$$_GLOBALSYSTEMTABLE        ldr     x2,[x2]        ldr     x2,[x2, #64]        ldr     x2,[x2, #32]        blr     x2

Navigation

[0] Message Index

[#] Next page

Go to full version