si_c.inc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. libc_init_proc: TProcedure; weakexternal name '_init';
  19. libc_fini_proc: TProcedure; weakexternal name '_fini';
  20. procedure libc_start_main(main: TProcedure; argc: ptruint; argv: ppchar; init, fini, rtld_fini: TProcedure; stack_end: pointer); cdecl; external name '__libc_start_main';
  21. procedure libc_exit(code: ptruint); cdecl; external name 'exit';
  22. procedure _FPC_rv_enter(at_exit: TProcedure; sp: pptruint);
  23. var
  24. argc: ptruint;
  25. argv: ppchar;
  26. begin
  27. argc:=sp[0];
  28. argv:=@sp[1];
  29. initialstkptr:=sp;
  30. operatingsystem_parameter_argc:=argc;
  31. operatingsystem_parameter_argv:=argv;
  32. operatingsystem_parameter_envp:=@sp[1+argc];
  33. libc_start_main(@PascalMain, argc, argv, libc_init_proc, libc_fini_proc, at_exit, sp);
  34. end;
  35. procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
  36. asm
  37. { set up GP }
  38. .option push
  39. .option norelax
  40. .L1:
  41. auipc gp, %pcrel_hi(BSS_START+0x800)
  42. addi gp, gp, %pcrel_lo(.L1)
  43. .option pop
  44. { Initialise FP to zero }
  45. addi fp, x0, 0
  46. { atexit is in a0 }
  47. addi a1, sp, 0
  48. jal x1, _FPC_rv_enter
  49. end;
  50. procedure _FPC_rv_exit(e:longint); assembler; nostackframe;
  51. asm
  52. addi a7, x0, 94
  53. ecall
  54. end;
  55. procedure _FPC_proc_haltproc(e:longint); cdecl; public name '_haltproc';
  56. begin
  57. while true do
  58. begin
  59. libc_exit(e);
  60. _FPC_rv_exit(e);
  61. end;
  62. end;