[SOLVED] how to force ld to start at PASCALMAIN? lazarus / 64-FPC development ---------------------------------------------------------------------- Key-Real · 2024-06-06 17:55 my .s Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i          .file "test.pas"        .module nomips16# Begin asmlist al_procedures .section .text,"ax"        .balign 4.globl  P$PROGRAM_$$_INITSCREENP$PROGRAM_$$_INITSCREEN:.ent P$PROGRAM_$$_INITSCREEN        .set    nomips16        .frame  $sp,112,$ra        .mask   0xC0000000,-36        .fmask  0x00000000,0        .set    noreorder        .set    nomacromove $t2,$t2        nop        nop        nop        nop         addiu   $sp,$sp,-112        sw      $ra,76($sp)        sw      $fp,72($sp)        addiu   $fp,$sp,112        move    $a0,$zero        jal     ResetGraph        nop        jal     InitGeom        nop        move    $a0,$zero      jal     SetGraphDebug        nop        addiu   $a1,$zero,256        addiu   $a0,$zero,960        jal     FntLoad        nop        addiu $v0,$zero,512        sw      $v0,20($sp)        addiu   $v0,$zero,1      sw      $v0,16($sp)        addiu   $a3,$zero,64        addiu   $a2,$zero,320        addiu   $a1,$zero,100        addiu   $a0,$zero,100        jal     FntOpen        nop        move    $a0,$v0        jal     SetDumpFnt        nop        lw      $fp,72($sp)        lw      $ra,76($sp)        jr      $ra        addiu   $sp,$sp,112        .set    macro        .set    reorder.end P$PROGRAM_$$_INITSCREEN .section .text,"ax"        .balign 4.globl  mainmain:.globl  PASCALMAINPASCALMAIN:.ent main        .set    nomips16        .frame  $sp,104,$ra        .mask   0xC0000000,-36      .fmask  0x00000000,0        .set    noreorder        .set    nomacro         move $t1,$t1        nop        nop        nop        nop         addiu   $sp,$sp,-104        sw      $ra,68($sp)        sw      $fp,64($sp)        addiu   $fp,$sp,104        jal     fpc_initializeunits        nop        jal     P$PROGRAM_$$_INITSCREEN        nop        addiu   $v0,$zero,1        lui     $v1,%hi(U_$P$PROGRAM_$$_I)        sw      $v0,%lo(U_$P$PROGRAM_$$_I)($v1).Lj5:        lui     $v0,%hi(U_$P$PROGRAM_$$_I)        lw      $v0,%lo(U_$P$PROGRAM_$$_I)($v0)        nop        addiu   $v1,$v0,1      lui     $v0,%hi(U_$P$PROGRAM_$$_I)        sw      $v1,%lo(U_$P$PROGRAM_$$_I)($v0)        lui     $a0,%hi(_$PROGRAM$_Ld1)        addiu   $a0,$a0,%lo(_$PROGRAM$_Ld1)      lui     $v0,%hi(U_$P$PROGRAM_$$_I)        lw      $a1,%lo(U_$P$PROGRAM_$$_I)($v0)        jal     FntPrint        nop      move    $a0,$zero        jal     DrawSync        nop        move  $a0,$zero        jal     VSync        nop        addiu   $a0,$zero,-1        jal     FntFlush        nop        b       .Lj5        nop      jal     fpc_do_exit        nop        lw      $fp,64($sp)        lw    $ra,68($sp)        jr      $ra        addiu   $sp,$sp,104        .set    macro        .set    reorder.end main# End asmlist al_procedures# Begin asmlist al_globals .section .bss,"aw",%nobits      .balign 4U_$P$PROGRAM_$$_DRAW:        .zero 92 .section .bss,"aw",%nobits        .balign 2U_$P$PROGRAM_$$_DISP:        .zero 20 .section .bss,"aw",%nobits        .balign 4U_$P$PROGRAM_$$_I:      .zero 4 .section .bss,"aw",%nobits        .balign 2U_$P$PROGRAM_$$_R:        .zero 8 .section .data        .balign 4.globl  INITFINALINITFINAL:        .long   0,0 .section .data        .balign 4.globl  FPC_THREADVARTABLESFPC_THREADVARTABLES:        .long 0 .section .data        .balign 4.globl  FPC_RESOURCESTRINGTABLESFPC_RESOURCESTRINGTABLES:        .long   0 .section .data        .balign 4.globl  FPC_WIDEINITTABLESFPC_WIDEINITTABLES:        .long   0 .section .data        .balign 4.globl  FPC_RESSTRINITTABLESFPC_RESSTRINITTABLES:      .long   0 .section .fpc,"aw"        .balign 8__fpc_ident:        .ascii  "FPC 3.3.1 [2024/06/06] for mipsel - ps1" .section .data      .balign 4.globl  __stklen__stklen:        .long   33554432 .section .data        .balign 4.globl  __heapsize__heapsize:        .long   0 .section .data        .balign 4.globl  __fpc_valgrind__fpc_valgrind:        .byte   0 .section .data        .balign 4.globl  FPC_RESLOCATIONFPC_RESLOCATION:        .long   0# End asmlist al_globals# Begin asmlist al_typedconsts .section .rodata      .balign 4.globl  _$PROGRAM$_Ld1_$PROGRAM$_Ld1:        .ascii  "\002%d\000"# End asmlist al_typedconsts   my linker script: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i MEMORY{      ram (rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 64K} SECTIONS{      .text : ALIGN(8) {                __exe_start__ = .;                __text_start__ = .;                *(.text .text.*)                __text_end__ = .;                __text_size__ = __text_start__ - __text_end__;        } > ram         .rodata : ALIGN(8) {              __rdata_start__ = .;                *(.rdata .rdata.* .rodata .rodata.*)                __rdata_end__ = .;                __rdata_size__ = __rdata_end__ - __rdata_start__;        } > ram       .ctors : ALIGN(8) {                __ctors_start__ = .;              KEEP(*(.ctors))                KEEP(*(SORT(.ctors.*)))              __ctors_end__ = .;                __ctors_size__ = __ctors_end__ - __ctors_start__;        } > ram         .dtors : ALIGN(8) {              __dtors_start__ = .;                KEEP(*(.dtors))              KEEP(*(SORT(.dtors.*)))                __dtors_end__ = .;              __dtors_size__ = __dtors_end__ - __dtors_start__;        } > ram       .data : ALIGN(8) {                __sdata_start__ = .;              *(.sdata .sdata.*)                __sdata_end__ = .;              __sdata_size__ = __sdata_end__ - __sdata_start__;                __data_start__ = .;                *(.data .data.*)                SORT(CONSTRUCTORS)                . = ALIGN(2048);                __data_end__ = .;                __exe_end__ = .;                __data_size__ = __data_end__ - __data_start__;        } > ram         __exe_size__ = __exe_end__ - __exe_start__;         .sbss : ALIGN(64) {                __sbss_start__ = .;                *(.sbss .sbss.*)              __sbss_end__ = .;                __sbss_size__ = __sbss_end__ - __sbss_start__;        } > ram         .bss : ALIGN(64) {                __bss_start__ = .;                *(.bss .bss.*)              *(COMMON)                . = ALIGN(64);                __bss_end__ = .;                __bss_size__ = __bss_end__ - __bss_start__;        } > ram}  if i load the executable he does not load main first, he loads the P$PROGRAM_$$_INITSCREEN in my bin start address 0x80010000 so the P$PROGRAM_$$_INITSCREEN is executed right at 0x80010000 which is the entry address I don't knew how to force the linker to start at main (PASCALMAIN) ---------------------------------------------------------------------- PascalDragon · 2024-06-06 19:42 You know that you could look at the documentation for ld? Also you shouldn't directly start PASCALMAIN, but your RTL should have a dedicated entry point function that does some low level setup (e.g. arguments and such) and that then calls PASCALMAIN (just look at the Linux RTL for example that has the _start symbol in its various startup files in rtl/linux/). ---------------------------------------------------------------------- Key-Real · 2024-06-06 19:45 I done this but nothing happens ---------------------------------------------------------------------- ccrause · 2024-06-06 19:52 Read Setting the Entry Point. So either specify the entry point symbol with the -e _start command line option to the linker, or add entry(_start) to your linker script. The compiler often use the entry keyword in its own target linker scripts. Edit: Changed symbol name to _start after reading the follow-up discussion. ---------------------------------------------------------------------- Key-Real · 2024-06-06 19:53 Quote from: ccrause on June 06, 2024, 09:52:04 pmRead Setting the Entry Point. So either specify the entry point symbol with the -e PASCALMAIN command line option to the linker, or add entry(PASCALMAIN) to your linker script. The compiler often use the entry keyword in its own target linker scripts. this isn't working because fpc creates several .text sections. this is why we need the si_prc.pp ---------------------------------------------------------------------- Key-Real · 2024-06-06 19:57 @PascalDragon with the setup i posted above nothing of si_prc.pp is written in the .s file ---------------------------------------------------------------------- Key-Real · 2024-06-06 20:09 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i systems_internal_sysinit = [system_i386_win32,system_x86_64_win64,                                 system_i386_linux,system_powerpc64_linux ,system_sparc64_linux,system_x86_64_linux,                                 system_xtensa_linux,system_mips64_linux,system_mips64el_linux,                                 system_m68k_atari,system_m68k_palmos,s ystem_m68k_sinclairql,system_m68k_human68k,                                 system_i386_haiku,system_x86_64_haiku,                                 system_i386_openbsd,system_x86_64_openbsd,                                 system_riscv32_linux,system_riscv64_linux,                                 system_aarch64_win64,                                 system_z80_zxspectrum,system_z80_msxdos,                                 system_wasm32_wasi,system_loongarch64_linux,                                 system_mipsel_ps1                                  ]+systems_darwin+systems_amigalike; i even set this, but still nothing happens ---------------------------------------------------------------------- ccrause · 2024-06-06 20:10 Quote from: Key-Real on June 06, 2024, 09:57:08 pmwith the setup i posted above nothing of si_prc.pp is written in the .s file The test.txt file looks like the compiler generated assembler for the test.pas unit only so it will not contain code from another unit. One can for example use objdump -S to disassemble the final linked executable, objdump -t or readelf -s to list all the symbols linked into the executable image. ---------------------------------------------------------------------- Key-Real · 2024-06-06 20:14 Quote from: ccrause on June 06, 2024, 10:10:23 pmThe test.txt file looks like the compiler generated assembler for the test.pas unit only so it will not contain code from another unit. why is it the case? what to do? Quote from: ccrause on June 06, 2024, 10:10:23 pmOne can for example use objdump -S to disassemble the final linked executable, objdump -t or readelf -s to list all the symbols linked into the executable image. can't do this, my .elf is in a unknown format, I use mipsel-unknown- elf-ld ---------------------------------------------------------------------- PascalDragon · 2024-06-06 20:16 Quote from: Key-Real on June 06, 2024, 10:09:59 pmi even set this, but still nothing happens Because your TExternalLinker descendant also needs to override InitSysInitUnitName. Look at the other targets. And best also override WriteResponseFile to dynamically create the linker script (again, look at the other targets). Quote from: Key-Real on June 06, 2024, 10:14:21 pmQuote from: ccrause on June 06, 2024, 10:10:23 pmThe test.txt file looks like the compiler generated assembler for the test.pas unit only so it will not contain code from another unit. why is it the case? what to do? Because that is how Pascal works?! Every unit is its own object file and thus its own assembly file. It's the linker's task to link these together. Quote from: Key-Real on June 06, 2024, 10:14:21 pmQuote from: ccrause on June 06, 2024, 10:10:23 pmOne can for example use objdump -S to disassemble the final linked executable, objdump -t or readelf -s to list all the symbols linked into the executable image. can't do this, my .elf is in a unknown format, I use mipsel-unknown- elf-ld That does not mean that the format itself is unknown, only that the platform is not specified. Also there should be a mipsel-unknown-elf- objdump. ---------------------------------------------------------------------- Key-Real · 2024-06-06 20:29 I done all this, but the first routine in the disasembled file is still initscreen ---------------------------------------------------------------------- Key-Real · 2024-06-06 20:32 and 80010198 : cames after main ---------------------------------------------------------------------- Key-Real · 2024-06-06 20:40 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  ./test.elf:     file format elf32-littlemips  Disassembly of section .text: 80010000 :80010000:       27bdff90      addiu   sp,sp,-11280010004:       afbf004c        sw      ra,76(sp)80010008:       afbe0048        sw      s8,72(sp)8001000c:     27be0070        addiu   s8,sp,11280010010:       00002025        move    a0,zero80010014:       0c0043da        jal     80010f68 80010018:       00000000        nop8001001c:       0c00500c        jal     80014030 80010020:       00000000      nop80010024:       00002025        move    a0,zero80010028:       0c004437        jal     800110dc 8001002c:       00000000        nop80010030:       240201e0        li      v0,48080010034:       afa20010        sw      v0,16(sp)80010038:     3c048002        lui     a0,0x80028001003c:       24849040        addiu   a0,a0,-2860880010040:       24070280        li      a3,64080010044:     00003025        move    a2,zero80010048:       00002825        move    a1,zero8001004c:       0c00409e        jal     80010278 80010050:       00000000        nop80010054:       240201e0        li      v0,48080010058:       afa20010        sw      v0,16(sp)8001005c:       3c048002        lui     a0,0x800280010060:     2484909c        addiu   a0,a0,-2851680010064:       24070280        li      a3,64080010068:       00003025        move    a2,zero8001006c:       00002825        move    a1,zero80010070:       0c0040ce        jal     80010338 80010074:       00000000        nop80010078:       24040001        li      a0,18001007c:       0c004493        jal     8001124c 80010080:       00000000        nop80010084:       3c048002        lui     a0,0x800280010088:       24849040        addiu   a0,a0,-286088001008c:       0c004652        jal     80011948 80010090:       00000000        nop80010094:       3c048002        lui     a0,0x800280010098:       2484909c        addiu   a0,a0,-285168001009c:       0c0046c5        jal     80011b14 800100a0:       00000000        nop800100a4:       24050100        li      a1,256800100a8:       240403c0        li      a0,960800100ac:       0c0040ee        jal     800103b8 800100b0:       00000000        nop800100b4:       24020200      li      v0,512800100b8:       afa20014        sw      v0,20(sp)800100bc:       24020001        li      v0,1800100c0:       afa20010        sw      v0,16(sp)800100c4:       24070040        li    a3,64800100c8:       24060140        li      a2,320800100cc:       24050064        li      a1,100800100d0:       24040064        li      a0,100800100d4:       0c004116        jal     80010458 800100d8:       00000000        nop800100dc:       00402025      move    a0,v0800100e0:       0c0040de        jal     80010378 800100e4:       00000000        nop800100e8:       8fbe0048        lw      s8,72(sp)800100ec:       8fbf004c        lw    ra,76(sp)800100f0:       03e00008        jr      ra800100f4:       27bd0070        addiu   sp,sp,112 800100f8
:800100f8:       27bdff98        addiu   sp,sp,-104800100fc:       afbf0044        sw    ra,68(sp)80010100:       afbe0040        sw      s8,64(sp)80010104:       27be0068        addiu   s8,sp,10480010108:       0c004091        jal     80010244 8001010c:       00000000        nop80010110:       0c004000        jal     80010000 80010114:       00000000        nop80010118:     24020001        li      v0,18001011c:       3c038002        lui   v1,0x800280010120:       ac6290b0        sw      v0,-28496(v1)80010124:       3c028002        lui     v0,0x800280010128:       8c4290b0        lw      v0,-28496(v0)8001012c:       00000000        nop80010130:       24430001        addiu   v1,v0,180010134:       3c028002        lui   v0,0x800280010138:       ac4390b0        sw      v1,-28496(v0)8001013c:       3c048001        lui     a0,0x800180010140:       24845a38        addiu   a0,a0,2309680010144:     3c028002        lui     v0,0x800280010148:       8c4590b0        lw      a1,-28496(v0)8001014c:       0c00428b        jal     80010a2c 80010150:       00000000        nop80010154:       00002025      move    a0,zero80010158:       0c0044b9        jal     800112e4 8001015c:       00000000        nop80010160:       00002025      move    a0,zero80010164:       0c00526a        jal     800149a8 80010168:       00000000        nop8001016c:       2404ffff      li      a0,-180010170:       0c0041c4        jal     80010710 80010174:       00000000        nop80010178:       1000ffea      b       80010124 8001017c:       00000000        nop80010180:       0c004097        jal     8001025c 80010184:       00000000        nop80010188:       8fbe0040        lw      s8,64(sp)8001018c:       8fbf0044        lw    ra,68(sp)80010190:       03e00008        jr      ra80010194:       27bd0068        addiu   sp,sp,104 80010198 :80010198:       27bdff90        addiu   sp,sp,-1128001019c:       afbf0044        sw      ra,68(sp)800101a0:       afbe0040        sw      s8,64(sp)800101a4:     27be0070        addiu   s8,sp,112800101a8:       0c00403e        jal     800100f8
800101ac:       00000000        nop800101b0:     8fbe0040        lw      s8,64(sp)800101b4:       8fbf0044        lw      ra,68(sp)800101b8:       03e00008        jr      ra800101bc:     27bd0070        addiu   sp,sp,112... ---------------------------------------------------------------------- Key-Real · 2024-06-06 20:46 how to tell ld to put the si_prc in the front? my script: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  MEMORY{      ram (rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 64K} SECTIONS{      .text : ALIGN(8) {                __exe_start__ = .;                __text_start__ = .;                *(.text .text.*)                __text_end__ = .;                __text_size__ = __text_start__ - __text_end__;        } > ram         .rodata : ALIGN(8) {              __rdata_start__ = .;                *(.rdata .rdata.* .rodata .rodata.*)                __rdata_end__ = .;                __rdata_size__ = __rdata_end__ - __rdata_start__;        } > ram       .ctors : ALIGN(8) {                __ctors_start__ = .;              KEEP(*(.ctors))                KEEP(*(SORT(.ctors.*)))              __ctors_end__ = .;                __ctors_size__ = __ctors_end__ - __ctors_start__;        } > ram         .dtors : ALIGN(8) {              __dtors_start__ = .;                KEEP(*(.dtors))              KEEP(*(SORT(.dtors.*)))                __dtors_end__ = .;              __dtors_size__ = __dtors_end__ - __dtors_start__;        } > ram       .data : ALIGN(8) {                __sdata_start__ = .;              *(.sdata .sdata.*)                __sdata_end__ = .;              __sdata_size__ = __sdata_end__ - __sdata_start__;                __data_start__ = .;                *(.data .data.*)                SORT(CONSTRUCTORS)                . = ALIGN(2048);                __data_end__ = .;                __exe_end__ = .;                __data_size__ = __data_end__ - __data_start__;        } > ram         __exe_size__ = __exe_end__ - __exe_start__;         .sbss : ALIGN(64) {                __sbss_start__ = .;                *(.sbss .sbss.*)              __sbss_end__ = .;                __sbss_size__ = __sbss_end__ - __sbss_start__;        } > ram         .bss : ALIGN(64) {                __bss_start__ = .;                *(.bss .bss.*)              *(COMMON)                . = ALIGN(64);                __bss_end__ = .;                __bss_size__ = __bss_end__ - __bss_start__;        } > ram} ---------------------------------------------------------------------- Key-Real · 2024-06-06 20:57 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i STARTUP(./rtl/ps1/si_prc.o)  done the job!!! thx