si_prc.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. ld.d $t0, $t0, 0
  40. st.d $t0, $t1, TEntryInformation.OS.stklen
  41. la.got $t2, _FPC_proc_haltproc
  42. st.d $t2, $t1, TEntryInformation.OS.haltproc
  43. move $a0, $t1
  44. {$if defined(FPC_USE_LIBC)}
  45. { call PascalMain }
  46. bl SysEntry
  47. {$else}
  48. bl SysEntry_InitTLS
  49. {$endif}
  50. {$else}
  51. { save operatingsystem parameter argc }
  52. ld.w $a1, $sp, 0
  53. la.got $t0, operatingsystem_parameter_argc
  54. st.w $a1, $t0, 0
  55. { save operatingsystem parameter argv }
  56. addi.d $a2, $sp, 8
  57. la.got $t0, operatingsystem_parameter_argv
  58. st.d $a2, $t0, 0
  59. { save operatingsystem parameter envp }
  60. la.got $t0, operatingsystem_parameter_envp
  61. alsl.d $t1, $a1, $a2, 3
  62. addi.d $t1, $t1, 8
  63. st.d $t1, $t0, 0
  64. { adjust $sp for 16-aligned }
  65. bstrins.d $sp, $zero, 3, 0
  66. { save stack pointer }
  67. la.got $t0, initialstkptr
  68. st.d $sp, $t0, 0
  69. {$if not defined(FPC_USE_LIBC)}
  70. bl InitTLS
  71. {$endif}
  72. { call PascalMain }
  73. bl PASCALMAIN
  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;