si_c.inc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. BSS_START: record end; external name '__bss_start';
  15. procedure ini_dummy;
  16. begin
  17. end;
  18. procedure libc_start_main(main: TProcedure; argc: ptruint; argv: PPAnsiChar; init, fini, rtld_fini: TProcedure; stack_end: pointer); cdecl; external name '__libc_start_main';
  19. procedure libc_exit(code: ptruint); cdecl; external name 'exit';
  20. procedure _FPC_rv_enter(at_exit: TProcedure; sp: pptruint);
  21. var
  22. argc: ptruint;
  23. argv: PPAnsiChar;
  24. begin
  25. argc:=sp[0];
  26. argv:=@sp[1];
  27. initialstkptr:=sp;
  28. operatingsystem_parameter_argc:=argc;
  29. operatingsystem_parameter_argv:=argv;
  30. operatingsystem_parameter_envp:=@sp[argc+2];
  31. libc_start_main(@PascalMain, argc, argv, @ini_dummy, @ini_dummy, at_exit, sp);
  32. end;
  33. procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
  34. asm
  35. { set up GP }
  36. .option push
  37. .option norelax
  38. .L1:
  39. auipc gp, %pcrel_hi(BSS_START+0x800)
  40. addi gp, gp, %pcrel_lo(.L1)
  41. .option pop
  42. { Initialise FP to zero }
  43. addi fp, x0, 0
  44. { atexit is in a0 }
  45. addi a1, sp, 0
  46. jal x1, _FPC_rv_enter
  47. end;
  48. procedure _FPC_rv_exit(e:longint); assembler; nostackframe;
  49. asm
  50. addi a7, x0, 94
  51. ecall
  52. end;
  53. procedure _FPC_proc_haltproc(e:longint); cdecl; public name '_haltproc';
  54. begin
  55. while true do
  56. begin
  57. libc_exit(e);
  58. _FPC_rv_exit(e);
  59. end;
  60. end;
  61. procedure initgp; assembler; nostackframe;
  62. asm
  63. .Linitgp:
  64. .option push
  65. .option norelax
  66. .L1:
  67. auipc gp, %pcrel_hi(BSS_START+0x800)
  68. addi gp, gp, %pcrel_lo(.L1)
  69. .option pop
  70. jalr x0, x1
  71. .section ".preinit_array","aw"
  72. .dc.a .Linitgp
  73. .text
  74. end;