Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

realmode.h 3.2KB

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