xf86int10.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * XFree86 int10 module
  3. * execute BIOS int 10h calls in x86 real mode environment
  4. * Copyright 1999 Egbert Eich
  5. */
  6. #ifndef _XF86INT10_H
  7. #define _XF86INT10_H
  8. #include <X11/Xmd.h>
  9. #include <X11/Xdefs.h>
  10. #include "xf86Pci.h"
  11. #define SEG_ADDR(x) (((x) >> 4) & 0x00F000)
  12. #define SEG_OFF(x) ((x) & 0x0FFFF)
  13. #define SET_BIOS_SCRATCH 0x1
  14. #define RESTORE_BIOS_SCRATCH 0x2
  15. /* int10 info structure */
  16. typedef struct {
  17. int entityIndex;
  18. uint16_t BIOSseg;
  19. uint16_t inb40time;
  20. ScrnInfoPtr pScrn;
  21. void *cpuRegs;
  22. char *BIOSScratch;
  23. int Flags;
  24. void *private;
  25. struct _int10Mem *mem;
  26. int num;
  27. int ax;
  28. int bx;
  29. int cx;
  30. int dx;
  31. int si;
  32. int di;
  33. int es;
  34. int bp;
  35. int flags;
  36. int stackseg;
  37. struct pci_device *dev;
  38. struct pci_io_handle *io;
  39. } xf86Int10InfoRec, *xf86Int10InfoPtr;
  40. typedef struct _int10Mem {
  41. uint8_t (*rb) (xf86Int10InfoPtr, int);
  42. uint16_t (*rw) (xf86Int10InfoPtr, int);
  43. uint32_t (*rl) (xf86Int10InfoPtr, int);
  44. void (*wb) (xf86Int10InfoPtr, int, uint8_t);
  45. void (*ww) (xf86Int10InfoPtr, int, uint16_t);
  46. void (*wl) (xf86Int10InfoPtr, int, uint32_t);
  47. } int10MemRec, *int10MemPtr;
  48. typedef struct {
  49. uint8_t save_msr;
  50. uint8_t save_pos102;
  51. uint8_t save_vse;
  52. uint8_t save_46e8;
  53. } legacyVGARec, *legacyVGAPtr;
  54. /* OS dependent functions */
  55. extern _X_EXPORT xf86Int10InfoPtr xf86InitInt10(int entityIndex);
  56. extern _X_EXPORT xf86Int10InfoPtr xf86ExtendedInitInt10(int entityIndex,
  57. int Flags);
  58. extern _X_EXPORT void xf86FreeInt10(xf86Int10InfoPtr pInt);
  59. extern _X_EXPORT void *xf86Int10AllocPages(xf86Int10InfoPtr pInt, int num,
  60. int *off);
  61. extern _X_EXPORT void xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase,
  62. int num);
  63. extern _X_EXPORT void *xf86int10Addr(xf86Int10InfoPtr pInt, uint32_t addr);
  64. /* x86 executor related functions */
  65. extern _X_EXPORT void xf86ExecX86int10(xf86Int10InfoPtr pInt);
  66. #ifdef _INT10_PRIVATE
  67. #define I_S_DEFAULT_INT_VECT 0xFF065
  68. #define SYS_SIZE 0x100000
  69. #define SYS_BIOS 0xF0000
  70. #if 1
  71. #define BIOS_SIZE 0x10000
  72. #else /* a bug in DGUX requires this - let's try it */
  73. #define BIOS_SIZE (0x10000 - 1)
  74. #endif
  75. #define LOW_PAGE_SIZE 0x600
  76. #define V_RAM 0xA0000
  77. #define VRAM_SIZE 0x20000
  78. #define V_BIOS_SIZE 0x10000
  79. #define V_BIOS 0xC0000
  80. #define BIOS_SCRATCH_OFF 0x449
  81. #define BIOS_SCRATCH_END 0x466
  82. #define BIOS_SCRATCH_LEN (BIOS_SCRATCH_END - BIOS_SCRATCH_OFF + 1)
  83. #define HIGH_MEM V_BIOS
  84. #define HIGH_MEM_SIZE (SYS_BIOS - HIGH_MEM)
  85. #define SEG_ADR(type, seg, reg) type((seg << 4) + (X86_##reg))
  86. #define SEG_EADR(type, seg, reg) type((seg << 4) + (X86_E##reg))
  87. #define X86_TF_MASK 0x00000100
  88. #define X86_IF_MASK 0x00000200
  89. #define X86_IOPL_MASK 0x00003000
  90. #define X86_NT_MASK 0x00004000
  91. #define X86_VM_MASK 0x00020000
  92. #define X86_AC_MASK 0x00040000
  93. #define X86_VIF_MASK 0x00080000 /* virtual interrupt flag */
  94. #define X86_VIP_MASK 0x00100000 /* virtual interrupt pending */
  95. #define X86_ID_MASK 0x00200000
  96. #define MEM_RB(name, addr) (*name->mem->rb)(name, addr)
  97. #define MEM_RW(name, addr) (*name->mem->rw)(name, addr)
  98. #define MEM_RL(name, addr) (*name->mem->rl)(name, addr)
  99. #define MEM_WB(name, addr, val) (*name->mem->wb)(name, addr, val)
  100. #define MEM_WW(name, addr, val) (*name->mem->ww)(name, addr, val)
  101. #define MEM_WL(name, addr, val) (*name->mem->wl)(name, addr, val)
  102. /* OS dependent functions */
  103. extern _X_EXPORT Bool MapCurrentInt10(xf86Int10InfoPtr pInt);
  104. /* x86 executor related functions */
  105. extern _X_EXPORT Bool xf86Int10ExecSetup(xf86Int10InfoPtr pInt);
  106. /* int.c */
  107. extern _X_EXPORT xf86Int10InfoPtr Int10Current;
  108. int int_handler(xf86Int10InfoPtr pInt);
  109. /* helper_exec.c */
  110. int setup_int(xf86Int10InfoPtr pInt);
  111. void finish_int(xf86Int10InfoPtr, int sig);
  112. uint32_t getIntVect(xf86Int10InfoPtr pInt, int num);
  113. void pushw(xf86Int10InfoPtr pInt, uint16_t val);
  114. int run_bios_int(int num, xf86Int10InfoPtr pInt);
  115. void dump_code(xf86Int10InfoPtr pInt);
  116. void dump_registers(xf86Int10InfoPtr pInt);
  117. void stack_trace(xf86Int10InfoPtr pInt);
  118. uint8_t bios_checksum(const uint8_t *start, int size);
  119. void LockLegacyVGA(xf86Int10InfoPtr pInt, legacyVGAPtr vga);
  120. void UnlockLegacyVGA(xf86Int10InfoPtr pInt, legacyVGAPtr vga);
  121. #if defined (_PC)
  122. extern _X_EXPORT void xf86Int10SaveRestoreBIOSVars(xf86Int10InfoPtr pInt,
  123. Bool save);
  124. #endif
  125. int port_rep_inb(xf86Int10InfoPtr pInt,
  126. uint16_t port, uint32_t base, int d_f, uint32_t count);
  127. int port_rep_inw(xf86Int10InfoPtr pInt,
  128. uint16_t port, uint32_t base, int d_f, uint32_t count);
  129. int port_rep_inl(xf86Int10InfoPtr pInt,
  130. uint16_t port, uint32_t base, int d_f, uint32_t count);
  131. int port_rep_outb(xf86Int10InfoPtr pInt,
  132. uint16_t port, uint32_t base, int d_f, uint32_t count);
  133. int port_rep_outw(xf86Int10InfoPtr pInt,
  134. uint16_t port, uint32_t base, int d_f, uint32_t count);
  135. int port_rep_outl(xf86Int10InfoPtr pInt,
  136. uint16_t port, uint32_t base, int d_f, uint32_t count);
  137. uint8_t x_inb(uint16_t port);
  138. uint16_t x_inw(uint16_t port);
  139. void x_outb(uint16_t port, uint8_t val);
  140. void x_outw(uint16_t port, uint16_t val);
  141. uint32_t x_inl(uint16_t port);
  142. void x_outl(uint16_t port, uint32_t val);
  143. uint8_t Mem_rb(uint32_t addr);
  144. uint16_t Mem_rw(uint32_t addr);
  145. uint32_t Mem_rl(uint32_t addr);
  146. void Mem_wb(uint32_t addr, uint8_t val);
  147. void Mem_ww(uint32_t addr, uint16_t val);
  148. void Mem_wl(uint32_t addr, uint32_t val);
  149. /* helper_mem.c */
  150. void setup_int_vect(xf86Int10InfoPtr pInt);
  151. int setup_system_bios(void *base_addr);
  152. void reset_int_vect(xf86Int10InfoPtr pInt);
  153. void set_return_trap(xf86Int10InfoPtr pInt);
  154. extern _X_EXPORT void *xf86HandleInt10Options(ScrnInfoPtr pScrn,
  155. int entityIndex);
  156. Bool int10skip(const void *options);
  157. Bool int10_check_bios(int scrnIndex, int codeSeg,
  158. const unsigned char *vbiosMem);
  159. Bool initPrimary(const void *options);
  160. extern _X_EXPORT BusType xf86int10GetBiosLocationType(const xf86Int10InfoPtr
  161. pInt);
  162. extern _X_EXPORT Bool xf86int10GetBiosSegment(xf86Int10InfoPtr pInt,
  163. void *base);
  164. #ifdef DEBUG
  165. void dprint(unsigned long start, unsigned long size);
  166. #endif
  167. #endif /* _INT10_PRIVATE */
  168. #endif /* _XF86INT10_H */