Recent

Author Topic: [SOLVED] how to satisfy the system unit for the original RTL?  (Read 1290 times)

Key-Real

  • Sr. Member
  • ****
  • Posts: 372
I don't knew exactly what have to be set in the system unit to compile the standard (platform undependent) RTL.

I have so far this:

Code: Pascal  [Select][+][-]
  1. unit system;
  2. interface
  3. {$define FPC_IS_SYSTEM}
  4. {$DEFINE FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  5.  
  6. {$I systemh.inc}
  7.  
  8. var
  9.   argc:longint=0;
  10.   argv:PPAnsiChar;
  11.   envp:PPAnsiChar;
  12.  
  13. implementation
  14. const
  15.     maxExitCode = 255;
  16.     AllowDirectorySeparators : set of AnsiChar = ['\','/'];
  17.     DirectorySeparator = '/';
  18.   { Default filehandles }
  19.     UnusedHandle    = $ffff;{ instead of -1, as it is a word value}
  20.     StdInputHandle  = 0;
  21.     StdOutputHandle = 1;
  22.     StdErrorHandle  = 2;
  23.     CtrlZMarksEOF: boolean = true; (* #26 is considered as end of file *)
  24.     DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCR;
  25.  
  26.  
  27.  
  28.  
  29. {I ../mips/setjump.inc}
  30. {$I system.inc}
  31.  
  32.  
  33. procedure Randomize;
  34. begin
  35. end;
  36.  
  37. function GetProcessID:LongWord;
  38. begin
  39.   result:= 0;
  40. end;
  41.  
  42. function ParamCount:LongInt;
  43. begin
  44.   ParamCount:= 0;
  45. end;
  46.  
  47. function ParamStr(l: LongInt):ShortString;
  48. begin
  49.   result:= '';
  50. end;
  51.  
  52. procedure SysInitStdIO;
  53. begin
  54. end;
  55.  
  56. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  57. begin
  58.   result := stklen;
  59. end;
  60.  
  61. procedure system_exit;
  62. begin
  63.   repeat
  64.   until false;
  65. end;
  66.  
  67. end.
  68.  


well, this hangs on fpc_initializeunits ....

ideas?

« Last Edit: July 19, 2024, 11:53:45 pm by Key-Real »

Key-Real

  • Sr. Member
  • ****
  • Posts: 372
Re: how to satisfy the system unit for the original RTL?
« Reply #1 on: July 16, 2024, 01:02:11 pm »
hm...

If I do smartlinking the program runs. I mean I link with --gc-sections

If not, it hangs

Thaddy

  • Hero Member
  • *****
  • Posts: 16193
  • Censorship about opinions does not belong here.
Re: how to satisfy the system unit for the original RTL?
« Reply #2 on: July 16, 2024, 01:25:11 pm »
PascalDragon has already explained that.
You need to implement fpc_initializeunits / fpc_uninitializeunits in your system when you need to link the rtl statically.
If I smell bad code it usually is bad code and that includes my own code.

nickysn

  • New Member
  • *
  • Posts: 27
Re: how to satisfy the system unit for the original RTL?
« Reply #3 on: July 16, 2024, 04:49:48 pm »
Thaddy, fpc_initializeunits is already implemented in system.inc, which is included. Key-Real, you need to figure out where exactly it hangs by adding some sort of debug prints, or another primitive output, if you don't have a console. Are you running in an emulator, or on real hardware? Can you use a debugger? How do you debug print on your platform?

Key-Real

  • Sr. Member
  • ****
  • Posts: 372
Re: how to satisfy the system unit for the original RTL?
« Reply #4 on: July 16, 2024, 07:43:44 pm »
the good news: I'm able to print to console (I'm using PCSX-Redux emulator)

Key-Real

  • Sr. Member
  • ****
  • Posts: 372
Re: how to satisfy the system unit for the original RTL?
« Reply #5 on: July 16, 2024, 08:17:50 pm »
SUCCESS!!   I traced it out!!

./rtl/inc/system.inc (line 1148):

Code: Pascal  [Select][+][-]
  1.  
  2. procedure fpc_InitializeUnits;[public,alias:'FPC_INITIALIZEUNITS']; compilerproc;
  3. var
  4.   i : ALUUInt;
  5.   pt : PInitFinalTable;
  6. begin
  7.   printf('INIT UNITS'+#10);
  8.  
  9.   { call cpu/fpu initialisation routine }
  10.   fpc_cpuinit;
  11.  
  12. {$ifdef FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  13.   pt := PInitFinalTable(EntryInformation.InitFinalTable);
  14. {$else FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  15.   pt := @InitFinalTable;
  16. {$endif FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  17.   with pt^ do
  18.    begin
  19.      for i:=1 to ALUUInt(TableCount) do
  20.       begin
  21.         printf('%d'+#10, ALUUInt(TableCount));
  22.         if assigned(Procs[i].InitProc) then
  23.          Procs[i].InitProc();
  24.         InitCount:=i;
  25.       end;
  26.    end;
  27.  
  28.   if assigned(InitProc) then
  29.     TProcedure(InitProc)();
  30.  
  31.  
  32.   printf('DONE UNITS'+#10);
  33. end;
  34.  
  35.  

in ./rtl/inc/systemh.inc (line 516):
Code: Pascal  [Select][+][-]
  1.  ALUUInt = DWord;


If I let i as ALUUInt the for loop continues till infinite!
if i declare i as integer everything works!!!!


IS THIS A COMPILER BUG??????????

Key-Real

  • Sr. Member
  • ****
  • Posts: 372
Re: how to satisfy the system unit for the original RTL?
« Reply #6 on: July 16, 2024, 08:29:00 pm »
word and integer works
dword and longint not!

the error have to be somethere else :(

Key-Real

  • Sr. Member
  • ****
  • Posts: 372
Re: how to satisfy the system unit for the original RTL?
« Reply #7 on: July 16, 2024, 08:37:54 pm »
Code: Pascal  [Select][+][-]
  1. printf('sizeis = %d'+#10,sizeof(dword));

gives me 4

if it helps....

Key-Real

  • Sr. Member
  • ****
  • Posts: 372
Re: how to satisfy the system unit for the original RTL?
« Reply #8 on: July 16, 2024, 08:50:08 pm »
compiling system.pp he tells me:

Code: Pascal  [Select][+][-]
  1. Warning: Source OS Redefined!
  2. Free Pascal Compiler version 3.3.1 [2024/07/16] for mipsel
  3. Copyright (c) 1993-2024 by Florian Klaempfl and others
  4. Target OS: PlayStation 1 for MIPSEL
  5. Compiling ./rtl/ps1/system.pp
  6. mips.inc(191,4) Note: "assembler" not yet supported inside inline procedure/function
  7. generic.inc(88,40) Warning: Converting pointers to signed integers may result in wrong comparison results and range errors, use an unsigned type instead.
  8. generic.inc(347,12) Warning: Comparison might be always true due to range of constant and expression
  9. generic.inc(544,19) Note: Local variable "pendpart" not used
  10. astrings.inc(882,48) Warning: Function result variable of a managed type does not seem to be initialized
  11. astrings.inc(1326,7) Note: Call to subroutine "procedure fpc_pchar_ansistr_intern_charmove(const src:PAnsiChar;const srcindex:LongInt;var dst:RawByteString;const dstindex:LongInt;const len:LongInt);" marked as inline is not inlined
  12. astrings.inc(1353,5) Note: Call to subroutine "procedure fpc_pchar_ansistr_intern_charmove(const src:PAnsiChar;const srcindex:LongInt;var dst:RawByteString;const dstindex:LongInt;const len:LongInt);" marked as inline is not inlined
  13. astrings.inc(1354,3) Note: Call to subroutine "procedure fpc_pchar_ansistr_intern_charmove(const src:PAnsiChar;const srcindex:LongInt;var dst:RawByteString;const dstindex:LongInt;const len:LongInt);" marked as inline is not inlined
  14. astrings.inc(1356,5) Note: Call to subroutine "procedure fpc_pchar_ansistr_intern_charmove(const src:PAnsiChar;const srcindex:LongInt;var dst:RawByteString;const dstindex:LongInt;const len:LongInt);" marked as inline is not inlined
  15. ustrings.inc(580,73) Warning: Function result variable of a managed type does not seem to be initialized
  16. ustrings.inc(646,66) Warning: Function result variable of a managed type does not seem to be initialized
  17. ustrings.inc(767,100) Warning: Function result variable of a managed type does not seem to be initialized
  18. ustrings.inc(1200,54) Warning: Function result variable of a managed type does not seem to be initialized
  19. ustrings.inc(1842,5) Note: Local variable "PRECHAR" is assigned but never used
  20. ustrings.inc(2111,8) Note: Call to subroutine "function Utf8ToUnicode(Dest:PUnicodeChar;MaxDestChars:LongWord;Source:PAnsiChar;SourceBytes:LongWord):LongWord;" marked as inline is not inlined
  21. ustrings.inc(2357,66) Warning: Function result variable of a managed type does not seem to be initialized
  22. ustrings.inc(2367,56) Warning: Function result variable of a managed type does not seem to be initialized
  23. dynarr.inc(351,39) Warning: Function result variable of a managed type does not seem to be initialized
  24. dynarr.inc(759,21) Warning: Function result variable of a managed type does not seem to be initialized
  25. variant.inc(110,38) Warning: Function result variable of a managed type does not seem to be initialized
  26. variant.inc(117,42) Warning: Function result variable of a managed type does not seem to be initialized
  27. variant.inc(123,36) Warning: Function result variable of a managed type does not seem to be initialized
  28. variant.inc(129,38) Warning: Function result variable of a managed type does not seem to be initialized
  29. variant.inc(135,36) Warning: Function result variable of a managed type does not seem to be initialized
  30. variant.inc(141,38) Warning: Function result variable of a managed type does not seem to be initialized
  31. variant.inc(161,33) Warning: Function result variable of a managed type does not seem to be initialized
  32. variant.inc(167,33) Warning: Function result variable of a managed type does not seem to be initialized
  33. variant.inc(173,33) Warning: Function result variable of a managed type does not seem to be initialized
  34. variant.inc(179,33) Warning: Function result variable of a managed type does not seem to be initialized
  35. variant.inc(185,33) Warning: Function result variable of a managed type does not seem to be initialized
  36. variant.inc(191,33) Warning: Function result variable of a managed type does not seem to be initialized
  37. variant.inc(197,36) Warning: Function result variable of a managed type does not seem to be initialized
  38. variant.inc(203,35) Warning: Function result variable of a managed type does not seem to be initialized
  39. variant.inc(223,34) Warning: Function result variable of a managed type does not seem to be initialized
  40. variant.inc(229,34) Warning: Function result variable of a managed type does not seem to be initialized
  41. variant.inc(235,34) Warning: Function result variable of a managed type does not seem to be initialized
  42. variant.inc(243,34) Warning: Function result variable of a managed type does not seem to be initialized
  43. variant.inc(252,34) Warning: Function result variable of a managed type does not seem to be initialized
  44. variant.inc(259,34) Warning: Function result variable of a managed type does not seem to be initialized
  45. variant.inc(265,34) Warning: Function result variable of a managed type does not seem to be initialized
  46. variant.inc(271,34) Warning: Function result variable of a managed type does not seem to be initialized
  47. variant.inc(277,34) Warning: Function result variable of a managed type does not seem to be initialized
  48. variant.inc(283,34) Warning: Function result variable of a managed type does not seem to be initialized
  49. variant.inc(339,36) Warning: Function result variable of a managed type does not seem to be initialized
  50. variant.inc(353,35) Warning: Function result variable of a managed type does not seem to be initialized
  51. variant.inc(476,32) Warning: Function result variable of a managed type does not seem to be initialized
  52. variant.inc(482,32) Warning: Function result variable of a managed type does not seem to be initialized
  53. variant.inc(573,38) Warning: Function result variable of a managed type does not seem to be initialized
  54. variant.inc(831,34) Warning: Function result variable of a managed type does not seem to be initialized
  55. variant.inc(837,34) Warning: Function result variable of a managed type does not seem to be initialized
  56. variant.inc(921,38) Warning: Function result variable of a managed type does not seem to be initialized
  57. variant.inc(927,38) Warning: Function result variable of a managed type does not seem to be initialized
  58. variant.inc(933,38) Warning: Function result variable of a managed type does not seem to be initialized
  59. variant.inc(939,38) Warning: Function result variable of a managed type does not seem to be initialized
  60. variant.inc(945,38) Warning: Function result variable of a managed type does not seem to be initialized
  61. variant.inc(951,38) Warning: Function result variable of a managed type does not seem to be initialized
  62. variant.inc(957,38) Warning: Function result variable of a managed type does not seem to be initialized
  63. variant.inc(963,38) Warning: Function result variable of a managed type does not seem to be initialized
  64. variant.inc(969,53) Warning: Function result variable of a managed type does not seem to be initialized
  65. variant.inc(975,53) Warning: Function result variable of a managed type does not seem to be initialized
  66. variant.inc(981,53) Warning: Function result variable of a managed type does not seem to be initialized
  67. variant.inc(988,39) Warning: Function result variable of a managed type does not seem to be initialized
  68. variant.inc(994,53) Warning: Function result variable of a managed type does not seem to be initialized
  69. variant.inc(1001,39) Warning: Function result variable of a managed type does not seem to be initialized
  70. variant.inc(1007,39) Warning: Function result variable of a managed type does not seem to be initialized
  71. variant.inc(1013,53) Warning: Function result variable of a managed type does not seem to be initialized
  72. variant.inc(1069,53) Warning: Function result variable of a managed type does not seem to be initialized
  73. variant.inc(1083,38) Warning: Function result variable of a managed type does not seem to be initialized
  74. variant.inc(1089,31) Warning: Function result variable of a managed type does not seem to be initialized
  75. variant.inc(1096,33) Warning: Function result variable of a managed type does not seem to be initialized
  76. rtti.inc(98,13) Warning: Case statement does not handle all possible cases
  77. rtti.inc(170,3) Warning: Case statement does not handle all possible cases
  78. rtti.inc(212,3) Warning: Case statement does not handle all possible cases
  79. rtti.inc(263,3) Warning: Case statement does not handle all possible cases
  80. rtti.inc(326,3) Warning: Case statement does not handle all possible cases
  81. heap.inc(1340,3) Note: Local variable "newsize" not used
  82. heap.inc(1345,3) Note: Local variable "poc" not used
  83. heap.inc(1346,3) Note: Local variable "pmcv" not used
  84. heap.inc(1648,8) Note: Local variable "poc_next" not used
  85. sysfile.inc(49,10) Warning: Function result does not seem to be set
  86. sysfile.inc(60,10) Warning: Function result does not seem to be set
  87. sysfile.inc(65,10) Warning: Function result does not seem to be set
  88. system.inc(1981,3) Note: Call to subroutine "procedure do_open(var f:<Formal type>;p:PAnsiChar;flags:LongInt;pchangeable:Boolean);" marked as inline is not inlined
  89. system.inc(1989,3) Note: Call to subroutine "procedure do_erase(p:PAnsiChar;pchangeable:Boolean);" marked as inline is not inlined
  90. system.inc(1998,3) Note: Call to subroutine "procedure do_rename(p1:PAnsiChar;p2:PAnsiChar;p1changeable:Boolean;p2changeable:Boolean);" marked as inline is not inlined
  91. system.inc(2006,3) Note: Call to subroutine "procedure do_rename(p1:PAnsiChar;p2:PAnsiChar;p1changeable:Boolean;p2changeable:Boolean);" marked as inline is not inlined
  92. text.inc(138,41) Warning: Implicit string type conversion from "RawByteString" to "UnicodeString"
  93. file.inc(73,41) Warning: Implicit string type conversion from "RawByteString" to "UnicodeString"
  94. system.pp(44,10) Warning: Function result does not seem to be set
  95. system.pp(53,10) Warning: Function result does not seem to be set
  96. system.inc(70,3) Note: Local variable "initialstklen" not used
  97. Assembling system
  98. 31093 lines compiled, 0.9 sec
  99. 74 warning(s) issued
  100. 17 note(s) issued
  101.  


hm....

PascalDragon

  • Hero Member
  • *****
  • Posts: 5759
  • Compiler Developer
Re: how to satisfy the system unit for the original RTL?
« Reply #9 on: July 16, 2024, 08:51:08 pm »
Code: Pascal  [Select][+][-]
  1.  
  2. procedure fpc_InitializeUnits;[public,alias:'FPC_INITIALIZEUNITS']; compilerproc;
  3. var
  4.   i : ALUUInt;
  5.   pt : PInitFinalTable;
  6. begin
  7.   printf('INIT UNITS'+#10);
  8.  
  9.   { call cpu/fpu initialisation routine }
  10.   fpc_cpuinit;
  11.  
  12. {$ifdef FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  13.   pt := PInitFinalTable(EntryInformation.InitFinalTable);
  14. {$else FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  15.   pt := @InitFinalTable;
  16. {$endif FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  17.   with pt^ do
  18.    begin
  19.      for i:=1 to ALUUInt(TableCount) do
  20.       begin
  21.         printf('%d'+#10, ALUUInt(TableCount));
  22.         if assigned(Procs[i].InitProc) then
  23.          Procs[i].InitProc();
  24.         InitCount:=i;
  25.       end;
  26.    end;
  27.  
  28.   if assigned(InitProc) then
  29.     TProcedure(InitProc)();
  30.  
  31.  
  32.   printf('DONE UNITS'+#10);
  33. end;
  34.  
  35.  

in ./rtl/inc/systemh.inc (line 516):
Code: Pascal  [Select][+][-]
  1.  ALUUInt = DWord;


If I let i as ALUUInt the for loop continues till infinite!
if i declare i as integer everything works!!!!

It might be that TableCount is 0, considering that your System unit does not seem to have an initialization-section. There should be the initialization of some of the core functionality in there (take a look at other System-units).

Key-Real

  • Sr. Member
  • ****
  • Posts: 372
Re: how to satisfy the system unit for the original RTL?
« Reply #10 on: July 16, 2024, 09:03:08 pm »
I put in the system.pp
Code: Pascal  [Select][+][-]
  1. ...
  2. begin
  3.   { Reset IO Error }
  4.   InOutRes:=0;
  5. end.
  6.  

now tablecount is 2:
Code: Pascal  [Select][+][-]
  1. printf('TableCount is %d'+#10, pt^.TableCount);

still the same.


btw. the random(123) doesn't work. can this help?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5759
  • Compiler Developer
Re: how to satisfy the system unit for the original RTL?
« Reply #11 on: July 16, 2024, 09:15:02 pm »
I put in the system.pp
Code: Pascal  [Select][+][-]
  1. ...
  2. begin
  3.   { Reset IO Error }
  4.   InOutRes:=0;
  5. end.
  6.  

now tablecount is 2:
Code: Pascal  [Select][+][-]
  1. printf('TableCount is %d'+#10, pt^.TableCount);

still the same.

Then it could be a bug in the MIPS code generator. After all the code works everywhere else...

btw. the random(123) doesn't work. can this help?

What do you mean with "doesn't work"? Does it always provide the same value? Does it crash?

By the way: you don't need to write '%d'+#10 as you can simply append characters to strings: '%d'#10.

Key-Real

  • Sr. Member
  • ****
  • Posts: 372
Re: how to satisfy the system unit for the original RTL?
« Reply #12 on: July 16, 2024, 09:17:46 pm »
yes, it crashes :(

I think the bug is in mips code, again :(

 

TinyPortal © 2005-2018