si_prc.inc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2019 by Jeppe Johansen.
  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. var
  14. dlexitproc : pointer;
  15. var
  16. BSS_START: record end; external name '__bss_start';
  17. STACK_PTR: record end; external name '__stkptr';
  18. procedure _FPC_rv_enter(sp: pptruint);
  19. var
  20. argc: ptruint;
  21. begin
  22. argc:=sp[0];
  23. initialstkptr:=sp;
  24. operatingsystem_parameter_argc:=argc;
  25. operatingsystem_parameter_argv:=@sp[1];
  26. operatingsystem_parameter_envp:=@sp[argc+2];
  27. PascalMain;
  28. end;
  29. procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
  30. asm
  31. { set up GP }
  32. .option push
  33. .option norelax
  34. .L1:
  35. auipc gp, %pcrel_hi(BSS_START+0x800)
  36. addi gp, gp, %pcrel_lo(.L1)
  37. .option pop
  38. { Initialise FP to zero }
  39. addi fp, x0, 0
  40. addi a0, sp, 0
  41. jal x1, _FPC_rv_enter
  42. end;
  43. procedure _FPC_dynamic_proc_start; assembler; nostackframe; public name '_dynamic_start';
  44. asm
  45. .option push
  46. .option norelax
  47. .L1:
  48. auipc t0, %pcrel_hi(dlexitproc)
  49. {$ifdef RISCV64}
  50. sd a0, %pcrel_lo(.L1)(t0)
  51. {$else 32-bit code }
  52. sw a0, %pcrel_lo(.L1)(t0)
  53. {$endif}
  54. .option pop
  55. jal x0, _FPC_proc_start
  56. end;
  57. procedure _FPC_rv_exit(e:longint); assembler; nostackframe;
  58. asm
  59. .L1:
  60. addi a7, x0, 94
  61. ecall
  62. jal x0, .L1
  63. end;
  64. procedure _FPC_proc_haltproc(e:longint); cdecl; public name '_haltproc';
  65. begin
  66. if assigned(dlexitproc) then
  67. TProcedure(dlexitproc);
  68. _FPC_rv_exit(e);
  69. end;