--- a/fpcsrc/rtl/linux/mips/cprt0.as +++ b/fpcsrc/rtl/linux/mips/cprt0.as @@ -63,6 +63,7 @@ char **argv, void (*init) (void), void (*fini) (void), void (*rtld_fini) (void), void *stack_end) */ + .abicalls .text .globl main .globl __start @@ -75,37 +76,33 @@ .set noreorder - move $0, $31 bal 10f nop 10: .cpload $31 move $31, $0 .set reorder - /* Setup GP correctly if we're non-PIC. */ - la $28,_gp - lui $4, %hi(main_stub) /* main */ - addiu $4,$4,%lo(main_stub) + lw $4, %got(main_stub)($gp) /* main */ lw $5, 0($29) /* argc */ addiu $6, $29, 4 /* argv */ /* store argc */ lw $t0,0($29) - lui $t1,%hi(operatingsystem_parameter_argc) - sw $t0,%lo(operatingsystem_parameter_argc)($t1) + lw $t1,%got(operatingsystem_parameter_argc)($gp) + sw $t0,0($t1) /* store argv */ addiu $t1,$29,4 - lui $t2,%hi(operatingsystem_parameter_argv) - sw $t1,%lo(operatingsystem_parameter_argv)($t2) + lw $t2,%got(operatingsystem_parameter_argv)($gp) + sw $t1,0($t2) /* store envp */ addiu $t2,$t0,1 sll $t2,$t2,0x2 addu $t2,$t2,$t1 - lui $t3,%hi(operatingsystem_parameter_envp) - sw $t2,%lo(operatingsystem_parameter_envp)($t3) + lw $t3,%got(operatingsystem_parameter_envp)($gp) + sw $t2,0($t3) /* Allocate space on the stack for seven arguments (o32 only) and make sure the stack is aligned to double words (8 bytes) @@ -119,22 +116,26 @@ sw $2, 20($29) /* rtld_fini */ sw $29, 24($29) /* stack_end */ - lw $t9,%got(__libc_start_main)($gp) + lw $t9,%call16(__libc_start_main)($gp) jalr $t9 .end _start .size _start, . - _start .globl main_stub + .ent main_stub .type main_stub,@function main_stub: - lui $v0,%hi(__fpc_ret_sp) - sw $sp,%lo(__fpc_ret_sp)($v0) - lui $v0,%hi(__fpc_ret_ra) - sw $ra,%lo(__fpc_ret_ra)($v0) - lui $v0,%hi(main) - addiu $t9,$v0,%lo(main) + .set noreorder + .cpload $t9 + .set reorder + lw $v0,%got(__fpc_ret_sp)($gp) + sw $sp,0($v0) + lw $v0,%got(__fpc_ret_ra)($gp) + sw $ra,0($v0) + lw $t9,%got(main)($gp) jr $t9 nop + .end main_stub .size main_stub,.-main_stub @@ -142,10 +143,13 @@ .ent _haltproc .type _haltproc,@function _haltproc: - lui $v0,%hi(__fpc_ret_sp) - lw $sp,%lo(__fpc_ret_sp)($v0) - lui $v0,%hi(__fpc_ret_ra) - lw $ra,%lo(__fpc_ret_ra)($v0) + .set noreorder + .cpload $t9 + .set reorder + lw $v0,%got(__fpc_ret_sp)($gp) + lw $sp,0($v0) + lw $v0,%got(__fpc_ret_ra)($gp) + lw $ra,0($v0) /* $a0 contains exitcode, we need to move it to $v0, as it would be at return of C main unction. */ move $v0,$a0 --- a/fpcsrc/rtl/linux/mips/prt0.as +++ b/fpcsrc/rtl/linux/mips/prt0.as @@ -11,6 +11,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ + .abicalls .set noat .set noreorder .section ".text" @@ -20,9 +21,14 @@ .ent _dynamic_start .type _dynamic_start,@function _dynamic_start: - lui $a2,%hi(__dl_fini) + bal 1f + nop +1: + .cpload $31 + move $31,$0 + lw $a2,%got(__dl_fini)($gp) b _start - sw $v0,%lo(__dl_fini)($a2) + sw $v0,0($a2) .end _dynamic_start .size _dynamic_start, .-_dynamic_start @@ -50,10 +56,16 @@ ra ($31) Return address set to zero. */ _start: + bal 10f + nop +10: + .cpload $31 + move $31,$0 + /* load fp */ move $s8,$sp - lui $at,%hi(__stkptr) - sw $s8,%lo(__stkptr)($at) + lw $at,%got(__stkptr)($gp) + sw $s8,0($at) /* align stack */ li $at,-8 @@ -63,22 +75,22 @@ /* store argc */ lw $a0,0($s8) - lui $a1,%hi(operatingsystem_parameter_argc) - sw $a0,%lo(operatingsystem_parameter_argc)($a1) + lw $a1,%got(operatingsystem_parameter_argc)($gp) + sw $a0,0($a1) /* store argv */ addiu $a1,$s8,4 - lui $a2,%hi(operatingsystem_parameter_argv) - sw $a1,%lo(operatingsystem_parameter_argv)($a2) + lw $a2,%got(operatingsystem_parameter_argv)($gp) + sw $a1,0($a2) /* store envp */ addiu $a2,$a0,1 sll $a2,$a2,0x2 addu $a2,$a2,$a1 - lui $a3,%hi(operatingsystem_parameter_envp) - sw $a2,%lo(operatingsystem_parameter_envp)($a3) - lui $t9,%hi(PASCALMAIN) - addiu $t9,$t9,%lo(PASCALMAIN) + lw $a3,%got(operatingsystem_parameter_envp)($gp) + sw $a2,0($a3) + + lw $t9,%call16(PASCALMAIN)($gp) jalr $t9 nop b _haltproc @@ -91,10 +103,14 @@ .ent _haltproc .type _haltproc,@function _haltproc: + bal 20f + nop +20: + .cpload $31 addiu $sp,$sp,-24 sw $a0,16($sp) /* $a0 contains the exitcode */ - lui $at,%hi(__dl_fini) - lw $t9,%lo(__dl_fini)($at) + lw $at,%got(__dl_fini)($gp) + lw $t9,0($at) beqz $t9,.L1 nop jalr $t9