[SOLVED] I think somebody coded a Bug in MIPS lazarus / 64-FPC development ---------------------------------------------------------------------- Key-Real · 2024-07-15 09:17 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  function thlcgmips.a_call_name(list: TAsmList; pd: tprocdef; const s: TSymStr; const paras: array of pcgpara; forceresdef: tdef; weak: boolean): tcgpara;    var      ref: treference;      sym: tasmsymbol;    begin  {                                                                                                                                   <---- this starts here      if weak then        sym:=current_asmdata.WeakRefAsmSymbol(s,AT_FUNCTION)      else        sym:=current_asmdata.RefAsmSymbol(s,AT_FUNCTION);       if (po_external in pd.procoptions) then        begin          if not (cs_create_pic in current_settings.moduleswitches) then            begin              reference_reset_symbol(ref,current_asmdata.RefAsmSy mbol('_gp',AT_DATA),0,sizeof(aint),[]);              list.concat(tai_comment.create(strpnew('Using PIC code for a_call_name')));              cg.a_loadaddr_ref_reg(list,ref,NR_GP);          end;          TCGMIPS(cg).a_call_sym_pic(list,sym);        end      else}                                                                                                 <--------- ends here        cg.a_call_name(list,s,weak);      { set the result location }      result:=get_call_result_cgpara(pd,forceresdef);    end;   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? ---------------------------------------------------------------------- TRon · 2024-07-15 09:23 Quote from: Key-Real on July 15, 2024, 11:17:25 amsomebody 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. ---------------------------------------------------------------------- Key-Real · 2024-07-15 09:33 unfortunly it is a bit complicated than that, see: 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 function thlcgmips.a_call_name(list: TAsmList; pd: tprocdef; const s: TSymStr; const paras: array of pcgpara; forceresdef: tdef; weak: boolean): tcgpara;    var      ref: treference;      sym: tasmsymbol;    begin       if weak then        sym:=current_asmdata.WeakRefAsmSymbol(s,AT_FUNCTION)      else        sym:=current_asmdata.RefAsmSymbol(s,AT_FUNCTION);       if (po_external in pd.procoptions) then        begin          if not (cs_create_pic in current_settings.moduleswitches) then                                                                              <--- here it tells us: if no pic            begin              reference_re set_symbol(ref,current_asmdata.RefAsmSymbol('_gp',AT_DATA),0,sizeof(ai nt),[]);    <---- but here is pic code              list.concat(tai_comment.create(strpnew('Using PIC code for a_call_name')));                                 <---- and here is pic code              cg.a_loadaddr_ref_reg(list,ref,NR_GP);                                                                                        <---- again pic. pay attention: the if check for NO pic, but executes pic code             end;          TCGMIPS(cg).a_call_sym_pic(list,sym);                                                                                             <---- this will be executed allways (pic code)         end       else                                                                                                                     <----- and this is checked my line 12, and if only: not po_external in pd.procoptions no pic code is executed           cg.a_call_name(list,s,weak);      { set the result location }      result:=get_call_result_cgpara(pd,forceresdef);    end;   my first question is: what is: 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 po_external in pd.procoptions? ---------------------------------------------------------------------- marcov · 2024-07-15 10:09 I assume a procedure/function declared with external attribute ? ---------------------------------------------------------------------- TRon · 2024-07-15 11:13 Quote from: marcov on July 15, 2024, 12:09:35 pmI 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. ---------------------------------------------------------------------- Key-Real · 2024-07-15 11:26 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 · 2024-07-15 11:40 Sorry Key, too many of your questions are above my knowledge to be able to provide a definitive/correct answer.