crt1.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "mes/lib-mini.h"
  21. int main (int argc, char *argv[], char *envp[]);
  22. int
  23. _start ()
  24. {
  25. asm ("mov____$i8,%rax !0");
  26. asm ("movl___%eax,0x32 &__stdin");
  27. asm ("mov____$i8,%rax !1");
  28. asm ("movl___%eax,0x32 &__stdout");
  29. asm ("mov____$i8,%rax !2");
  30. asm ("movl___%eax,0x32 &__stderr");
  31. #if 0 //MES_CCAMD64
  32. asm ("add____$i32,%rbp %0x80"); // FIXME: corresponds to x86_64/as.scm function-preamble-fu
  33. #endif
  34. asm ("mov____%rbp,%rax");
  35. asm ("add____$i8,%rax !8");
  36. asm ("mov____(%rax),%rax");
  37. asm ("add____$i8,%rax !0x03");
  38. asm ("shl____$i8,%rax !0x03");
  39. asm ("add____%rbp,%rax");
  40. // FIXME: 64-bit addresses...
  41. asm ("mov____%rax,0x32 &environ");
  42. #if 0 //MES_CCAMD64
  43. asm ("mov____%rax,%rdx"); // amd
  44. #else
  45. asm ("push___%rax"); // bootstrap
  46. #endif
  47. asm ("mov____%rbp,%rax");
  48. asm ("add____$i8,%rax !16");
  49. #if 0 //MES_CCAMD64
  50. asm ("mov____%rax,%rsi"); // amd
  51. #else
  52. asm ("push___%rax"); // bootstrap
  53. #endif
  54. asm ("mov____%rbp,%rax");
  55. asm ("add____$i8,%rax !8");
  56. asm ("mov____(%rax),%rax");
  57. #if 0 //MES_CCAMD64
  58. asm ("mov____%rax,%rdi"); // amd
  59. #else
  60. asm ("push___%rax"); // bootstrap
  61. #endif
  62. main ();
  63. asm ("mov____%rax,%rdi");
  64. asm ("mov____$i32,%rax %0x3c");
  65. asm ("syscall");
  66. asm ("hlt");
  67. }