si_prc.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (C) 2022 Loongson Technology Corporation Limited.
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {******************************************************************************
  11. Process start/halt
  12. ******************************************************************************}
  13. {$ifndef FPC_USE_LIBC}
  14. procedure InitTLS; [external name 'FPC_INITTLS'];
  15. {$endif}
  16. var
  17. dlexitproc : pointer;
  18. procedure _FPC_proc_haltproc(e: longint); cdecl; forward;
  19. procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
  20. asm
  21. { clear frame pointer }
  22. ori $fp, $zero, 0
  23. {$ifdef FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  24. la.got $t1, SysInitEntryInformation
  25. { argc = *(int *)sp }
  26. ld.w $a1, $sp, 0
  27. st.w $a1, $t1, TEntryInformation.OS.argc
  28. { argv = (char **)(sp + 8) }
  29. addi.d $a2, $sp, 8
  30. st.d $a2, $t1, TEntryInformation.OS.argv
  31. { save envp }
  32. alsl.d $t0, $a1, $a2, 3
  33. addi.d $t0, $t0, 8
  34. st.d $t0, $t1, TEntryInformation.OS.envp
  35. { adjust $sp for 16-aligned }
  36. bstrins.d $sp, $zero, 3, 0
  37. st.d $sp, $t1, TEntryInformation.OS.stkptr
  38. la.got $t0, StackLength
  39. st.d $t0, $t1, TEntryInformation.OS.stklen
  40. la.got $t2, _FPC_proc_haltproc
  41. st.d $t2, $t1, TEntryInformation.OS.haltproc
  42. move $a0, $t1
  43. {$if defined(FPC_USE_LIBC)}
  44. { call PascalMain }
  45. bl SysEntry
  46. {$else}
  47. bl SysEntry_InitTLS
  48. {$endif}
  49. {$else}
  50. { save operatingsystem parameter argc }
  51. ld.w $a1, $sp, 0
  52. la.got $t0, operatingsystem_parameter_argc
  53. st.w $a1, $t0, 0
  54. { save operatingsystem parameter argv }
  55. addi.d $a2, $sp, 8
  56. la.got $t0, operatingsystem_parameter_argv
  57. st.d $a2, $t0, 0
  58. { save operatingsystem parameter envp }
  59. la.got $t0, operatingsystem_parameter_envp
  60. alsl.d $t1, $a1, $a2, 3
  61. addi.d $t1, $t1, 8
  62. st.d $t1, $t0, 0
  63. { adjust $sp for 16-aligned }
  64. bstrins.d $sp, $zero, 3, 0
  65. { save stack pointer }
  66. la.got $t0, initialstkptr
  67. st.d $sp, $t0, 0
  68. {$if defined(FPC_USE_LIBC)}
  69. { call PascalMain }
  70. bl PASCALMAIN
  71. {$else}
  72. bl InitTLS
  73. {$endif}
  74. {$endif}
  75. break 1
  76. end;
  77. procedure _FPC_dynamic_proc_start; assembler; nostackframe; public name '_dynamic_start';
  78. asm
  79. la.got $t0, dlexitproc
  80. st.d $a0, $t0, 0
  81. b _FPC_proc_start
  82. end;
  83. procedure _FPC_loongarch_exit(e:longint); assembler; nostackframe;
  84. asm
  85. ori $a7, $zero, 94
  86. syscall 0
  87. b _FPC_loongarch_exit
  88. end;
  89. procedure _FPC_proc_haltproc(e:longint); cdecl; public name '_haltproc';
  90. begin
  91. if assigned(dlexitproc) then
  92. TProcedure(dlexitproc);
  93. _FPC_loongarch_exit(e);
  94. end;