crt1.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2017,2018,2019 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. // *INDENT-OFF*
  23. void
  24. _start ()
  25. {
  26. asm (
  27. "mov $0,%%eax\n\t"
  28. "mov %%eax,%0\n"
  29. : "=r" (__stdin)
  30. : //no inputs ""
  31. );
  32. asm (
  33. "mov $1,%%eax\n\t"
  34. "mov %%eax,%0\n"
  35. : "=r" (__stdout)
  36. : //no inputs ""
  37. );
  38. asm (
  39. "mov $2,%%eax\n\t"
  40. "mov %%eax,%0\n"
  41. : "=r" (__stderr)
  42. : //no inputs ""
  43. );
  44. asm (
  45. "mov %%ebp,%%eax\n\t"
  46. "add $4,%%eax\n\t"
  47. "movzbl (%%eax),%%eax\n\t"
  48. "add $3,%%eax\n\t"
  49. "shl $2,%%eax\n\t"
  50. "add %%ebp,%%eax\n\t"
  51. "mov %%eax,%0\n\t"
  52. "push %%eax\n\t"
  53. : "=r" (environ)
  54. : //no inputs ""
  55. );
  56. asm (
  57. "mov %ebp,%eax\n\t"
  58. "add $8,%eax\n\t"
  59. "push %eax\n\t"
  60. "mov %ebp,%eax\n\t"
  61. "add $4,%eax\n\t"
  62. "movzbl (%eax),%eax\n\t"
  63. "push %eax\n\t"
  64. "call main\n\t"
  65. "push %eax\n\t"
  66. "call _exit\n\t"
  67. "hlt \n\t"
  68. );
  69. }