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.4KB

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