crt0.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2017,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. // no clue what crt0.o is and why gcc-2.6.3 needs it
  21. // instead of calling main, it seems to call either _main or ___main,
  22. // let's try _main first
  23. #include <mes/lib-mini.h>
  24. int _main (int argc, char *argv[]);
  25. // *INDENT-OFF*
  26. void
  27. _start ()
  28. {
  29. asm (
  30. "mov %%ebp,%%eax\n\t"
  31. "add $4,%%eax\n\t"
  32. "movzbl (%%eax),%%eax\n\t"
  33. "add $3,%%eax\n\t"
  34. "shl $2,%%eax\n\t"
  35. "add %%ebp,%%eax\n\t"
  36. "mov %%eax,%0\n\t"
  37. : "=r" (environ)
  38. : //no inputs ""
  39. );
  40. asm (
  41. "mov %ebp,%eax\n\t"
  42. "add $8,%eax\n\t"
  43. "push %eax\n\t"
  44. "mov %ebp,%eax\n\t"
  45. "add $4,%eax\n\t"
  46. "movzbl (%eax),%eax\n\t"
  47. "push %eax\n\t"
  48. "call _main\n\t"
  49. "mov %eax,%ebx\n\t"
  50. "mov $1,%eax\n\t"
  51. "int $0x80\n\t"
  52. "hlt \n\t"
  53. );
  54. }