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.

realmode.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef REALMODE_H
  2. #define REALMODE_H
  3. #ifndef ASSEMBLY
  4. #include "stdint.h"
  5. #include "registers.h"
  6. #include "io.h"
  7. /*
  8. * Data structures and type definitions
  9. *
  10. */
  11. /* All i386 registers, as passed in by prot_call or kir_call */
  12. struct real_mode_regs {
  13. struct i386_all_regs;
  14. } PACKED;
  15. /* Segment:offset structure. Note that the order within the structure
  16. * is offset:segment.
  17. */
  18. typedef struct {
  19. uint16_t offset;
  20. uint16_t segment;
  21. } segoff_t PACKED;
  22. /* Macro hackery needed to stringify bits of inline assembly */
  23. #define RM_XSTR(x) #x
  24. #define RM_STR(x) RM_XSTR(x)
  25. /* Drag in the selected real-mode transition library header */
  26. #ifdef KEEP_IT_REAL
  27. #include "libkir.h"
  28. #else
  29. #include "librm.h"
  30. #endif
  31. /*
  32. * The API to some functions is identical between librm and libkir, so
  33. * they are documented here, even though the prototypes are in librm.h
  34. * and libkir.h.
  35. *
  36. */
  37. /*
  38. * void copy_to_real ( uint16_t dest_seg, uint16_t dest_off,
  39. * void *src, size_t n )
  40. * void copy_from_real ( void *dest, uint16_t src_seg, uint16_t src_off,
  41. * size_t n )
  42. *
  43. * These functions can be used to copy data to and from arbitrary
  44. * locations in base memory.
  45. */
  46. /*
  47. * put_real ( variable, uint16_t dest_seg, uint16_t dest_off )
  48. * get_real ( variable, uint16_t src_seg, uint16_t src_off )
  49. *
  50. * These macros can be used to read or write single variables to and
  51. * from arbitrary locations in base memory. "variable" must be a
  52. * variable of either 1, 2 or 4 bytes in length.
  53. */
  54. /*
  55. * REAL_CALL ( routine, num_out_constraints, out_constraints,
  56. * in_constraints, clobber )
  57. * REAL_EXEC ( name, asm_code_str, num_out_constraints, out_constraints,
  58. * in_constraints, clobber )
  59. *
  60. * If you have a pre-existing real-mode routine that you want to make
  61. * a far call to, use REAL_CALL. If you have a code fragment that you
  62. * want to copy down to base memory, execute, and then remove, use
  63. * REAL_EXEC.
  64. *
  65. * out_constraints must be of the form OUT_CONSTRAINTS(constraints),
  66. * and in_constraints must be of the form IN_CONSTRAINTS(constraints),
  67. * where "constraints" is a constraints list as would be used in an
  68. * inline __asm__()
  69. *
  70. * clobber must be of the form CLOBBER ( clobber_list ), where
  71. * "clobber_list" is a clobber list as would be used in an inline
  72. * __asm__().
  73. *
  74. * These are best illustrated by example. To write a character to the
  75. * console using INT 10, you would do something like:
  76. *
  77. * REAL_EXEC ( rm_test_librm,
  78. * "int $0x10",
  79. * 1,
  80. * OUT_CONSTRAINTS ( "=a" ( discard ) ),
  81. * IN_CONSTRAINTS ( "a" ( 0x0e00 + character ),
  82. * "b" ( 1 ) ),
  83. * CLOBBER ( "ebx", "ecx", "edx", "ebp", "esi", "edi" ) );
  84. *
  85. * IMPORTANT: gcc does not automatically assume that input operands
  86. * get clobbered. The only way to specify that an input operand may
  87. * be modified is to also specify it as an output operand; hence the
  88. * "(discard)" in the above code.
  89. */
  90. #warning "realmode.h contains placeholders for obsolete macros"
  91. /* Just for now */
  92. #define SEGMENT(x) ( virt_to_phys ( x ) >> 4 )
  93. #define OFFSET(x) ( virt_to_phys ( x ) & 0xf )
  94. #define SEGOFF(x) { OFFSET(x), SEGMENT(x) }
  95. /* To make basemem.c compile */
  96. extern int lock_real_mode_stack;
  97. extern char *real_mode_stack;
  98. extern char real_mode_stack_size[];
  99. #define RM_FRAGMENT(name,asm) \
  100. void name ( void ) {} \
  101. extern char name ## _size[];
  102. #endif /* ASSEMBLY */
  103. #endif /* REALMODE_H */