crt0.cpp 883 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Types.h>
  7. #include <assert.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <sys/internals.h>
  11. #include <unistd.h>
  12. #ifndef _DYNAMIC_LOADER
  13. extern "C" {
  14. int main(int, char**, char**);
  15. // Tell the compiler that this may be called from somewhere else.
  16. int _entry(int argc, char** argv) __attribute__((used));
  17. void _start(int, char**, char**) __attribute__((used));
  18. NAKED void _start(int, char**, char**)
  19. {
  20. # if ARCH(AARCH64)
  21. asm(
  22. "mov x29, 0\n"
  23. "mov x30, 0\n"
  24. "bl _entry\n");
  25. # else
  26. asm(
  27. "push $0\n"
  28. "jmp _entry@plt\n");
  29. # endif
  30. }
  31. int _entry(int argc, char** argv)
  32. {
  33. __begin_atexit_locking();
  34. int status = main(argc, argv, environ);
  35. exit(status);
  36. return 20150614;
  37. }
  38. }
  39. #endif