vm86.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. *
  3. * Copyright © 2000 Keith Packard
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and its
  6. * documentation for any purpose is hereby granted without fee, provided that
  7. * the above copyright notice appear in all copies and that both that
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation, and that the name of Keith Packard not be used in
  10. * advertising or publicity pertaining to distribution of the software without
  11. * specific, written prior permission. Keith Packard makes no
  12. * representations about the suitability of this software for any purpose. It
  13. * is provided "as is" without express or implied warranty.
  14. *
  15. * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  16. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  17. * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  18. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  19. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  20. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  21. * PERFORMANCE OF THIS SOFTWARE.
  22. */
  23. /*
  24. Copyright (c) 2000 by Juliusz Chroboczek
  25. Permission is hereby granted, free of charge, to any person obtaining a copy
  26. of this software and associated documentation files (the "Software"), to deal
  27. in the Software without restriction, including without limitation the rights
  28. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  29. copies of the Software, and to permit persons to whom the Software is
  30. furnished to do so, subject to the following conditions:
  31. The above copyright notice and this permission notice shall be included in
  32. all copies or substantial portions of the Software.
  33. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  34. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  35. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  36. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  37. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  38. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  39. THE SOFTWARE.
  40. */
  41. #ifndef _VM86_H_
  42. #define _VM86_H_
  43. #include <stdlib.h>
  44. #include <errno.h>
  45. #include <unistd.h>
  46. #include <fcntl.h>
  47. #include <sys/mman.h>
  48. #include <asm/vm86.h>
  49. #include <sys/io.h>
  50. #include <X11/X.h>
  51. #include <X11/Xproto.h>
  52. #include <X11/Xos.h>
  53. #include "os.h"
  54. #ifndef IF_MASK
  55. #define IF_MASK X86_EFLAGS_IF
  56. #endif
  57. #ifndef IOPL_MASK
  58. #define IOPL_MASK X86_EFLAGS_IOPL
  59. #endif
  60. typedef unsigned char U8;
  61. typedef unsigned short U16;
  62. typedef unsigned int U32;
  63. /* The whole addressable memory */
  64. #define SYSMEM_BASE 0x00000
  65. #define SYSMEM_SIZE 0x100000
  66. /* Interrupt vectors and BIOS data area */
  67. /* This is allocated privately from /dev/mem */
  68. #define MAGICMEM_BASE 0x00000
  69. #define MAGICMEM_SIZE 0x01000
  70. /* The low memory, allocated privately from /dev/zero */
  71. /* 64KB should be enough for anyone, as they used to say */
  72. #define LOMEM_BASE 0x10000
  73. #define LOMEM_SIZE 0x10000
  74. /* The video memory and BIOS ROM, allocated shared from /dev/mem */
  75. #define HIMEM_BASE 0xA0000
  76. #define HIMEM_SIZE (SYSMEM_BASE + SYSMEM_SIZE - HIMEM_BASE)
  77. #define HOLE1_BASE (MAGICMEM_BASE + MAGICMEM_SIZE)
  78. #define HOLE1_SIZE (LOMEM_BASE - HOLE1_BASE)
  79. #define HOLE2_BASE (LOMEM_BASE + LOMEM_SIZE)
  80. #define HOLE2_SIZE (HIMEM_BASE - HOLE2_BASE)
  81. /* The BIOS ROM */
  82. #define ROM_BASE 0xC0000
  83. #define ROM_SIZE 0x30000
  84. #define STACK_SIZE 0x1000
  85. #define POINTER_SEGMENT(ptr) (((unsigned int)ptr)>>4)
  86. #define POINTER_OFFSET(ptr) (((unsigned int)ptr)&0x000F)
  87. #define MAKE_POINTER(seg, off) (((((unsigned int)(seg))<<4) + (unsigned int)(off)))
  88. #define MAKE_POINTER_1(lw) MAKE_POINTER(((lw)&0xFFFF0000)/0x10000, (lw)&0xFFFF)
  89. #define ALLOC_FAIL ((U32)-1)
  90. typedef struct _Vm86InfoRec {
  91. void *magicMem, *loMem, *hiMem;
  92. void *hole1, *hole2;
  93. U32 brk;
  94. struct vm86_struct vms;
  95. U32 ret_code, stack_base;
  96. } Vm86InfoRec, *Vm86InfoPtr;
  97. #define LM(vi,i) (((U8*)vi->loMem)[i-LOMEM_BASE])
  98. #define LMW(vi,i) (*(U16*)(&LM(vi,i)))
  99. #define LML(vi,i) (*(U32*)(&LM(vi,i)))
  100. #define MM(vi,i) (((U8*)vi->magicMem)[i-MAGICMEM_BASE])
  101. #define MMW(vi,i) (*(U16*)(&MM(vi,i)))
  102. #define MML(vi,i) (*(U32*)(&MM(vi,i)))
  103. #define HM(vi,i) (((U8*)vi->hiMem)[i-HIMEM_BASE])
  104. #define HMW(vi,i) (*(U16*)(&MM(vi,i)))
  105. #define HML(vi,i) (*(U32*)(&MM(vi,i)))
  106. Vm86InfoPtr Vm86Setup(int);
  107. void Vm86Cleanup(Vm86InfoPtr vi);
  108. int Vm86DoInterrupt(Vm86InfoPtr vi, int num);
  109. int Vm86DoPOST(Vm86InfoPtr vi);
  110. U8 Vm86Memory(Vm86InfoPtr, U32);
  111. U16 Vm86MemoryW(Vm86InfoPtr, U32);
  112. int Vm86AllocateMemory(Vm86InfoPtr, int);
  113. int Vm86MarkMemory(Vm86InfoPtr vi);
  114. void Vm86ReleaseMemory(Vm86InfoPtr vi, int mark);
  115. #endif /* _VM86_H_ */