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.

librm_mgmt.c 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * librm: a library for interfacing to real-mode code
  3. *
  4. * Michael Brown <mbrown@fensystems.co.uk>
  5. *
  6. */
  7. #ifdef KEEP_IT_REAL
  8. /* Build a null object under -DKEEP_IT_REAL */
  9. #else
  10. #include "stdint.h"
  11. #include "stddef.h"
  12. #include "string.h"
  13. #include "librm.h"
  14. /*
  15. * This file provides functions for managing librm.
  16. *
  17. */
  18. /* Current location of librm in base memory */
  19. char *installed_librm = librm;
  20. /*
  21. * Install librm to base memory
  22. *
  23. */
  24. void install_librm ( void *addr ) {
  25. memcpy ( addr, librm, librm_size );
  26. installed_librm = addr;
  27. }
  28. /*
  29. * Increment lock count of librm
  30. *
  31. */
  32. void lock_librm ( void ) {
  33. inst_librm_ref_count++;
  34. }
  35. /*
  36. * Decrement lock count of librm
  37. *
  38. */
  39. void unlock_librm ( void ) {
  40. #ifdef DEBUG_LIBRM
  41. if ( inst_librm_ref_count == 0 ) {
  42. printf ( "librm: ref count gone negative\n" );
  43. lockup();
  44. }
  45. #endif
  46. inst_librm_ref_count--;
  47. }
  48. /*
  49. * Allocate space on the real-mode stack and copy data there.
  50. *
  51. */
  52. uint16_t copy_to_rm_stack ( void *data, size_t size ) {
  53. #ifdef DEBUG_LIBRM
  54. if ( inst_rm_stack.offset <= size ) {
  55. printf ( "librm: out of space in RM stack\n" );
  56. lockup();
  57. }
  58. #endif
  59. inst_rm_stack.offset -= size;
  60. copy_to_real ( inst_rm_stack.segment, inst_rm_stack.offset,
  61. data, size );
  62. return inst_rm_stack.offset;
  63. };
  64. /*
  65. * Deallocate space on the real-mode stack, optionally copying back
  66. * data.
  67. *
  68. */
  69. void remove_from_rm_stack ( void *data, size_t size ) {
  70. if ( data ) {
  71. copy_from_real ( data,
  72. inst_rm_stack.segment, inst_rm_stack.offset,
  73. size );
  74. }
  75. inst_rm_stack.offset += size;
  76. };
  77. #endif /* KEEP_IT_REAL */