Recent

Author Topic: [SOLVED] I think somebody coded a Bug in MIPS  (Read 922 times)

Key-Real

  • Sr. Member
  • ****
  • Posts: 372
[SOLVED] I think somebody coded a Bug in MIPS
« on: July 15, 2024, 11:17:25 am »
After days of searching I found the place where are a Bug was coded in the MIPS port.

The good news I can "hack" it, but I don't really knew what this code do:

./compiler/mips/hlcgcpu.pas:
Code: Pascal  [Select][+][-]
  1.  
  2. function thlcgmips.a_call_name(list: TAsmList; pd: tprocdef; const s: TSymStr; const paras: array of pcgpara; forceresdef: tdef; weak: boolean): tcgpara;
  3.     var
  4.       ref: treference;
  5.       sym: tasmsymbol;
  6.     begin
  7.  
  8.  
  9. {                                                                                                                                     <---- this starts here
  10.       if weak then
  11.         sym:=current_asmdata.WeakRefAsmSymbol(s,AT_FUNCTION)
  12.       else
  13.         sym:=current_asmdata.RefAsmSymbol(s,AT_FUNCTION);
  14.  
  15.       if (po_external in pd.procoptions) then
  16.         begin
  17.           if not (cs_create_pic in current_settings.moduleswitches) then
  18.             begin
  19.               reference_reset_symbol(ref,current_asmdata.RefAsmSymbol('_gp',AT_DATA),0,sizeof(aint),[]);
  20.               list.concat(tai_comment.create(strpnew('Using PIC code for a_call_name')));
  21.               cg.a_loadaddr_ref_reg(list,ref,NR_GP);
  22.             end;
  23.           TCGMIPS(cg).a_call_sym_pic(list,sym);
  24.         end
  25.       else
  26. }                                                                                                   <--------- ends here
  27.  
  28.  
  29.         cg.a_call_name(list,s,weak);
  30.       { set the result location }
  31.       result:=get_call_result_cgpara(pd,forceresdef);
  32.     end;
  33.  
  34.  


if I comment the PIC stuff out, everything I could test, works!

my fears:
1) I could break something, I can't test at this stage.            <------- this will be tested in my production cycle, we will see ... :)
2) The PIC code will definitely not work!                               <------- cant fix it, I have no idea :(   As my Target doesn't support PIC and this place is difficult for me to understand

somebody Ideas?
« Last Edit: July 17, 2024, 09:08:32 am by Key-Real »

TRon

  • Hero Member
  • *****
  • Posts: 3623
Re: I think somebody coded a Bug in MIPS
« Reply #1 on: July 15, 2024, 11:23:59 am »
somebody Ideas?
Do you remember that the mips target had the pic setting set to true as default ? That what you commented should check for that setting and depending on that setting either use the original code that you commented or when not set use the modified code that you want. Probably a simple if-then statement.
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Key-Real

  • Sr. Member
  • ****
  • Posts: 372
Re: I think somebody coded a Bug in MIPS
« Reply #2 on: July 15, 2024, 11:33:39 am »
unfortunly it is a bit complicated than that, see:

Code: Pascal  [Select][+][-]
  1. function thlcgmips.a_call_name(list: TAsmList; pd: tprocdef; const s: TSymStr; const paras: array of pcgpara; forceresdef: tdef; weak: boolean): tcgpara;
  2.     var
  3.       ref: treference;
  4.       sym: tasmsymbol;
  5.     begin
  6.  
  7.       if weak then
  8.         sym:=current_asmdata.WeakRefAsmSymbol(s,AT_FUNCTION)
  9.       else
  10.         sym:=current_asmdata.RefAsmSymbol(s,AT_FUNCTION);
  11.  
  12.       if (po_external in pd.procoptions) then
  13.         begin
  14.           if not (cs_create_pic in current_settings.moduleswitches) then                                                                                <--- here it tells us: if no pic
  15.             begin
  16.               reference_reset_symbol(ref,current_asmdata.RefAsmSymbol('_gp',AT_DATA),0,sizeof(aint),[]);    <---- but here is pic code
  17.               list.concat(tai_comment.create(strpnew('Using PIC code for a_call_name')));                                 <---- and here is pic code
  18.               cg.a_loadaddr_ref_reg(list,ref,NR_GP);                                                                                            <---- again pic. pay attention: the if check for NO pic, but executes pic code
  19.             end;
  20.           TCGMIPS(cg).a_call_sym_pic(list,sym);                                                                                               <---- this will be executed allways (pic code)
  21.         end
  22.       else                                                                                                                         <----- and this is checked my line 12, and if only: not po_external in pd.procoptions no pic code is executed
  23.  
  24.  
  25.  
  26.         cg.a_call_name(list,s,weak);
  27.       { set the result location }
  28.       result:=get_call_result_cgpara(pd,forceresdef);
  29.     end;
  30.  
  31.  


my first question is:
what is:
Code: Pascal  [Select][+][-]
  1. po_external in pd.procoptions
?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11935
  • FPC developer.
Re: I think somebody coded a Bug in MIPS
« Reply #3 on: July 15, 2024, 12:09:35 pm »
I assume a procedure/function declared with external attribute ?

TRon

  • Hero Member
  • *****
  • Posts: 3623
Re: I think somebody coded a Bug in MIPS
« Reply #4 on: July 15, 2024, 01:13:15 pm »
I assume a procedure/function declared with external attribute ?
+1

@Key-Real:
If you are unsure then perhaps a grep on cs_create_pic for a platform that you are more familiar with might be of assistance.

I can see now that something seems to be going wrong there with the logic but you have to keep in mind that the person or persons that started implementing support for mips probably had a single target to consider (that is how such things usually motivates people to start adding support).

All modifications that you make are currently done in your own private repo so make the changes as you seem fit but simply make a note inside the source-code how the logic seems wrong. If you really do not wish to break existing code then it is possible to use a define for your changes.

This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Key-Real

  • Sr. Member
  • ****
  • Posts: 372
Re: I think somebody coded a Bug in MIPS
« Reply #5 on: July 15, 2024, 01:26:16 pm »
Yes, I think the port was written for MIPS64. I do not knew exactly but i think  it is MIPS3 =>
I think it was never tested on MIPS1, I found an asm writing Error. It is Read After Write Pipeline fail.
I fixed this also. As i have no idea how to fix the PIC code, so I gonna do
if mips1 then ... my stuff.. else ...existing code... can't do more.

The next issue is: in software fpu, he still generates me fpu asm instructions(coprocessor 1 which the playstation do not have). :( this will be a big next step to code.

Is it true that the system RTL can't live without a fpu? It compiles but hangs on start...
So is it true that i HAVE TO implement software fpu?

than: i have to figure it out how to do smartlinking. Everything is written in different .text sections but with no extra symbols for a functions, so ld cut me off the whole .text section and doesn't leave me any code, so everything is stripped out :( ideas?

TRon

  • Hero Member
  • *****
  • Posts: 3623
Re: I think somebody coded a Bug in MIPS
« Reply #6 on: July 15, 2024, 01:40:54 pm »
Sorry Key, too many of your questions are above my knowledge to be able to provide a definitive/correct answer.
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

 

TinyPortal © 2005-2018