You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hooks.c 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "stdint.h"
  2. #include "stddef.h"
  3. #include "registers.h"
  4. #include "string.h"
  5. #include "hooks.h"
  6. #include "init.h"
  7. #include "main.h"
  8. #ifdef REALMODE
  9. #include "realmode.h"
  10. #endif
  11. /* Symbols defined by the linker */
  12. extern char _bss[], _ebss[];
  13. /*
  14. * This file provides the basic entry points from assembly code. See
  15. * README.i386 for a description of the entry code path.
  16. *
  17. * This file is compiled to two different object files: hooks.o and
  18. * hooks_rm.o. REALMODE is defined when compiling hooks_rm.o
  19. *
  20. */
  21. /*
  22. * arch_initialise(): perform any required initialisation such as
  23. * setting up the console device and relocating to high memory. Note
  24. * that if we relocate to high memory and the prefix is in base
  25. * memory, then we will need to install a copy of librm in base memory
  26. * and adjust retaddr so that we return to the installed copy.
  27. *
  28. */
  29. #ifdef REALMODE
  30. void arch_rm_initialise ( struct i386_all_regs *regs,
  31. void (*retaddr) (void) )
  32. #else /* REALMODE */
  33. void arch_initialise ( struct i386_all_regs *regs,
  34. void (*retaddr) (void) __unused )
  35. #endif /* REALMODE */
  36. {
  37. /* Zero the BSS */
  38. memset ( _bss, 0, _ebss - _bss );
  39. /* Call all registered initialisation functions.
  40. */
  41. call_init_fns ();
  42. }
  43. #ifdef REALMODE
  44. /*
  45. * arch_rm_main() : call main() and then exit via whatever exit mechanism
  46. * the prefix requested.
  47. *
  48. */
  49. void arch_rm_main ( struct i386_all_regs *regs ) {
  50. struct i386_all_regs regs_copy;
  51. void (*exit_fn) ( struct i386_all_regs *regs );
  52. /* Take a copy of the registers, because the memory holding
  53. * them will probably be trashed by the time main() returns.
  54. */
  55. regs_copy = *regs;
  56. exit_fn = ( typeof ( exit_fn ) ) regs_copy.eax;
  57. /* Call to main() */
  58. regs_copy.eax = main();
  59. /* Call registered per-object exit functions */
  60. call_exit_fns ();
  61. if ( exit_fn ) {
  62. /* Prefix requested that we use a particular function
  63. * as the exit path, so we call this function, which
  64. * must not return.
  65. */
  66. exit_fn ( &regs_copy );
  67. }
  68. }
  69. #else /* REALMODE */
  70. /*
  71. * arch_main() : call main() and return
  72. *
  73. */
  74. void arch_main ( struct i386_all_regs *regs ) {
  75. regs->eax = main();
  76. /* Call registered per-object exit functions */
  77. call_exit_fns ();
  78. };
  79. #endif /* REALMODE */