[fpc-devel] about freepascal for mips

Jeppe Græsdal Johansen jjohan07 at student.aau.dk
Fri May 25 21:04:41 CEST 2012


Den 25-05-2012 13:54, Jonas Maebe skrev:
>
> Fuxin Zhang wrote on Fri, 25 May 2012:
>
>> And my progress and problems:
>>   I've got the source from subversion and tried to build it in ubuntu
>> 11.10 x86-64 machine. With the following patch and commands, I can get a
>> partly working ppcrossmipsel(it can at least build a helloworld and
>> runnable):
>> patch:
>>   Index: Makefile.fpc
>> ===================================================================
>> --- Makefile.fpc    (版本 21354)
>> +++ Makefile.fpc    (工作副本)
> [snip]
>> This is to fix various file not found errors. I am not sure whether 
>> it is
>> 'right' fix.
>
> No, definitely it's definitely not right. It's strange that you need 
> those changes, since the Linux RTL Makefile is used daily. Did you 
> need those changes even to compile it for i386?
>
>> commands:
>>   cd rtl/linux;
>>   patch Makefile.fpc; fpcmake -Ti386-linux,mipsel-linux
>
> It's better to use -Tall (since there are more Linux targets than just 
> i386 and mipsel).
>
>> /home/foxsen/fpc/rtl/units/mipsel-linux/sysutils.o: In function
>> `SYSUTILS_$$_finalize':
>> /home/foxsen/fpc/rtl/unix/sysutils.pp:1414: relocation truncated to fit:
>> R_MIPS_PC16 against
>> `SYSTEM$_$TINTERFACEDOBJECT_$__$$_QUERYINTERFACE$TGUID$formal$$LONGINT'
>> /home/foxsen/fpc/rtl/unix/sysutils.pp:1414: relocation truncated to fit:
>> R_MIPS_PC16 against `SYSTEM$_$TINTERFACEDOBJECT_$__$$__ADDREF$$LONGINT'
>> /home/foxsen/fpc/rtl/unix/sysutils.pp:1414: relocation truncated to fit:
>> R_MIPS_PC16 against `SYSTEM$_$TINTERFACEDOBJECT_$__$$__RELEASE$$LONGINT'
>> pp.pas(224,36) Error: Error while linking
>> pp.pas(224,36) Fatal: There were 1 errors compiling module, stopping
>> Fatal: Compilation aborted> make[1]: *** [ppcmipsel] 错误 1
>> make[1]:正在离开目录 `/home/foxsen/fpc/compiler'
>> make: *** [cycle] 错误 2
>>
>> I know it is related to mips branch offset overflow.
>
> A similar issue exists on PowerPC: conditional branches are limited to 
> 16 bit offsets, while unconditional branches can reach up to 26 bits 
> or so. As far as I can see, it's similar on MIPS (the B* opcodes 
> versus the J opcode). If so, you may be able to create a MIPS version 
> of the fixup_jmps procedure in compiler/ppcgen/aasmcpu.pas and add it 
> to compiler/mips/aasmcpu.pas (it's called from psub.pas, you'll have 
> to modify the ifdef there to also activate it for MIPS and MIPSEL).
>
> The actual errors you get are strange though. We never insert 
> conditional branches from one routine to another (in the above case: 
> from SYSUTILS_$$_finalize, or more likely from interface wrappers 
> following that symbol, to various other routines). Looking at the code 
> for tcgcpu.g_intf_wrapper in compiler/mips/cgcpu.pas, the code for 
> interface wrappers uses the "B" as opposed to the "J" instruction to 
> branch to the interface wrappers. Maybe that's a copy/paste error from 
> another platform. I'm not sure what "B" means though, I don't see it 
> listed at http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html
>
> Anyway, I guess this patch will solve the above error:
>
> Index: compiler/mips/cgcpu.pas
> ===================================================================
> --- compiler/mips/cgcpu.pas    (revision 21359)
> +++ compiler/mips/cgcpu.pas    (working copy)
> @@ -1722,7 +1722,7 @@
>      op_onr24methodaddr;
>    end
>    else
> -   
> list.concat(taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(procdef.mangledname)));
> +   
> list.concat(taicpu.op_sym(A_J,current_asmdata.RefAsmSymbol(procdef.mangledname)));
>    { Delay slot }
>    list.Concat(TAiCpu.Op_none(A_NOP));
>
>> After some
>> research,I've found that ppc code support -fPIC.
>
> PIC normally won't help with branch offset overflows.
>
>> But when I try to enable
>> it,the other issue appears:
>
> Yes, PIC requires cpu-specific support. It shouldn't be necessary to 
> get an initial port up and running though.
>
>
> Jonas
I wonder how you people managed to build anything at all.

When I tried to build from SVN trunk there would be an endless steam of 
internalerrors related to fpu registers, no matter if compiled with MIPS 
FPU or softfloat.

I managed to remove the errors with the following patch, such that 
everything compiled, but I haven't been able to test it: 
http://j-software.dk/fpc-mipsel.patch

Does anyone know if there's an easy way to set up an emulator for 
testing? Been fighting with qemu for the last half hour without results.

Regards,
Jeppe



More information about the fpc-devel mailing list