| 1 |
---------------------------------------------------------------------- |
| 2 |
Patch name: patch.hosttime-port |
| 3 |
Author: [email protected] |
| 4 |
Date: July, 31th 2002 |
| 5 |
|
| 6 |
Detailed description: |
| 7 |
This patch enables the guest to read to host time (linux only). |
| 8 |
Port 0x8901 is used. Two time values can be set and |
| 9 |
read, along with the difference of the two. |
| 10 |
This can be useful to do performance tests. |
| 11 |
|
| 12 |
port 0x8901 : |
| 13 |
|
| 14 |
Writes can be bytes, word, dword |
| 15 |
Reads must be dword |
| 16 |
write 0x00 : set both times to 0 |
| 17 |
write 0x01 : set the first time |
| 18 |
write 0x02 : set the second time |
| 19 |
write 0x03 : set the both time |
| 20 |
write 0x11 : the seconds of the first time will be read from 0x8901 |
| 21 |
write 0x12 : the microseconds of the first time will be read from 0x8901 |
| 22 |
write 0x21 : the seconds of the second time will be read from 0x8901 |
| 23 |
write 0x22 : the microseconds of the second time will be read from 0x8901 |
| 24 |
write 0x31 : the seconds of the difference will be read from 0x8901 |
| 25 |
write 0x32 : the microseconds of the difference will be read from 0x8901 |
| 26 |
|
| 27 |
Additionnal values have been defined for language that can't do 32bits |
| 28 |
port access. Please look in the source. |
| 29 |
|
| 30 |
Example : Set first time, then second time, and get the difference : |
| 31 |
|
| 32 |
outb(0x8901, 0x01); // Set first time |
| 33 |
outb(0x8901, 0x02); // Set second time |
| 34 |
outb(0x8901, 0x31); // Read difference : seconds fields |
| 35 |
sec = inl(0x8901); |
| 36 |
outb(0x8901, 0x32); // Read difference : microseconds fields |
| 37 |
usec = inl(0x8901); |
| 38 |
|
| 39 |
Patch was created with: |
| 40 |
cvs diff -u |
| 41 |
Apply patch to what version: |
| 42 |
cvs checked out on July, 31th 2002 |
| 43 |
Instructions: |
| 44 |
To patch, go to main bochs directory. |
| 45 |
Type "patch -p0 < THIS_PATCH_FILE". |
| 46 |
---------------------------------------------------------------------- |
| 47 |
Index: iodev/unmapped.cc |
| 48 |
=================================================================== |
| 49 |
RCS file: /cvsroot/bochs/bochs/iodev/unmapped.cc,v |
| 50 |
retrieving revision 1.17 |
| 51 |
diff -u -r1.17 unmapped.cc |
| 52 |
--- iodev/unmapped.cc 30 Jul 2002 08:48:03 -0000 1.17 |
| 53 |
+++ iodev/unmapped.cc 31 Jul 2002 09:01:23 -0000 |
| 54 |
@@ -137,6 +137,40 @@ |
| 55 |
retval = 0xffffffff; |
| 56 |
BX_DEBUG(("unsupported IO read from port %04x", address)); |
| 57 |
break; |
| 58 |
+#ifdef __linux__ |
| 59 |
+ case 0x8901: // host-time port |
| 60 |
+ struct timeval diff; |
| 61 |
+ retval = 0; |
| 62 |
+ |
| 63 |
+ if (timercmp(& BX_UM_THIS s.hosttime_value1, & BX_UM_THIS s.hosttime_value2, < ) ) |
| 64 |
+ timersub(& BX_UM_THIS s.hosttime_value2, & BX_UM_THIS s.hosttime_value1, &diff); |
| 65 |
+ else |
| 66 |
+ timersub(& BX_UM_THIS s.hosttime_value1, & BX_UM_THIS s.hosttime_value2, &diff); |
| 67 |
+ |
| 68 |
+ switch (BX_UM_THIS s.hosttime_field) { |
| 69 |
+ case 0x11: retval = BX_UM_THIS s.hosttime_value1.tv_sec; break; |
| 70 |
+ case 0x12: retval = BX_UM_THIS s.hosttime_value1.tv_usec; break; |
| 71 |
+ case 0x1C: retval = BX_UM_THIS s.hosttime_value1.tv_sec & 0xffff; break; |
| 72 |
+ case 0x1D: retval = BX_UM_THIS s.hosttime_value1.tv_sec >> 16; break; |
| 73 |
+ case 0x1E: retval = BX_UM_THIS s.hosttime_value1.tv_usec & 0xffff; break; |
| 74 |
+ case 0x1F: retval = BX_UM_THIS s.hosttime_value1.tv_usec >> 16; break; |
| 75 |
+ case 0x21: retval = BX_UM_THIS s.hosttime_value2.tv_sec; break; |
| 76 |
+ case 0x22: retval = BX_UM_THIS s.hosttime_value2.tv_usec; break; |
| 77 |
+ case 0x2C: retval = BX_UM_THIS s.hosttime_value2.tv_sec & 0xffff; break; |
| 78 |
+ case 0x2D: retval = BX_UM_THIS s.hosttime_value2.tv_sec >> 16; break; |
| 79 |
+ case 0x2E: retval = BX_UM_THIS s.hosttime_value2.tv_usec & 0xffff; break; |
| 80 |
+ case 0x2F: retval = BX_UM_THIS s.hosttime_value2.tv_usec >> 16; break; |
| 81 |
+ case 0x31: retval = diff.tv_sec; break; |
| 82 |
+ case 0x32: retval = diff.tv_usec; break; |
| 83 |
+ case 0x3C: retval = diff.tv_sec & 0xffff; break; |
| 84 |
+ case 0x3D: retval = diff.tv_sec >> 16; break; |
| 85 |
+ case 0x3E: retval = diff.tv_usec & 0xffff; break; |
| 86 |
+ case 0x3F: retval = diff.tv_usec >> 16; break; |
| 87 |
+ } |
| 88 |
+ |
| 89 |
+ break; |
| 90 |
+#endif |
| 91 |
+ |
| 92 |
default: |
| 93 |
retval = 0xffffffff; |
| 94 |
} |
| 95 |
@@ -256,6 +290,51 @@ |
| 96 |
BX_CPU(0)->kill_bochs_request = 2; |
| 97 |
} |
| 98 |
break; |
| 99 |
+ |
| 100 |
+#ifdef __linux__ |
| 101 |
+ case 0x8901: // host-time port |
| 102 |
+ switch (value) { |
| 103 |
+ case 0x01: // set first time |
| 104 |
+ gettimeofday(& BX_UM_THIS s.hosttime_value1, NULL); |
| 105 |
+ break; |
| 106 |
+ case 0x02: // set second time |
| 107 |
+ gettimeofday(& BX_UM_THIS s.hosttime_value2, NULL); |
| 108 |
+ break; |
| 109 |
+ case 0x03: // set both times |
| 110 |
+ gettimeofday(& BX_UM_THIS s.hosttime_value1, NULL); |
| 111 |
+ BX_UM_THIS s.hosttime_value2.tv_sec = BX_UM_THIS s.hosttime_value1.tv_sec; |
| 112 |
+ BX_UM_THIS s.hosttime_value2.tv_usec = BX_UM_THIS s.hosttime_value1.tv_usec; |
| 113 |
+ break; |
| 114 |
+ case 0x11: // retrieve sec from first time // 32 bits |
| 115 |
+ case 0x12: // retrieve usec from first time // 32 bits |
| 116 |
+ case 0x1C: // retrieve sec from first time // low 16 bits |
| 117 |
+ case 0x1D: // retrieve sec from first time // high 16 bits |
| 118 |
+ case 0x1E: // retrieve usec from first time // low 16 bits |
| 119 |
+ case 0x1F: // retrieve usec from first time // high 16 bits |
| 120 |
+ case 0x21: // retrieve sec from second time // 32 bits |
| 121 |
+ case 0x22: // retrieve usec from second time // 32 bits |
| 122 |
+ case 0x2C: // retrieve sec from second time // low 16 bits |
| 123 |
+ case 0x2D: // retrieve sec from second time // high 16 bits |
| 124 |
+ case 0x2E: // retrieve usec from second time // low 16 bits |
| 125 |
+ case 0x2F: // retrieve usec from second time // high 16 bits |
| 126 |
+ case 0x31: // retrieve sec from difference // 32 bits |
| 127 |
+ case 0x32: // retrieve usec from difference // 32 bits |
| 128 |
+ case 0x3C: // retrieve sec from difference // low 16 bits |
| 129 |
+ case 0x3D: // retrieve sec from difference // high 16 bits |
| 130 |
+ case 0x3E: // retrieve usec from difference // low 16 bits |
| 131 |
+ case 0x3F: // retrieve usec from difference // high 16 bits |
| 132 |
+ BX_UM_THIS s.hosttime_field = value; |
| 133 |
+ break; |
| 134 |
+ default: |
| 135 |
+ BX_UM_THIS s.hosttime_field = 0; |
| 136 |
+ BX_UM_THIS s.hosttime_value1.tv_sec = 0; |
| 137 |
+ BX_UM_THIS s.hosttime_value1.tv_usec = 0; |
| 138 |
+ BX_UM_THIS s.hosttime_value2.tv_sec = 0; |
| 139 |
+ BX_UM_THIS s.hosttime_value2.tv_usec = 0; |
| 140 |
+ break; |
| 141 |
+ } |
| 142 |
+ break; |
| 143 |
+#endif |
| 144 |
|
| 145 |
case 0xfedc: |
| 146 |
bx_dbg.debugger = (value > 0); |
| 147 |
Index: iodev/unmapped.h |
| 148 |
=================================================================== |
| 149 |
RCS file: /cvsroot/bochs/bochs/iodev/unmapped.h,v |
| 150 |
retrieving revision 1.8 |
| 151 |
diff -u -r1.8 unmapped.h |
| 152 |
--- iodev/unmapped.h 29 Jul 2002 12:44:47 -0000 1.8 |
| 153 |
+++ iodev/unmapped.h 31 Jul 2002 09:01:23 -0000 |
| 154 |
@@ -56,6 +56,11 @@ |
| 155 |
Bit8u port80; |
| 156 |
Bit8u port8e; |
| 157 |
Bit8u shutdown; |
| 158 |
+#ifdef __linux__ |
| 159 |
+ Bit8u hosttime_field; |
| 160 |
+ struct timeval hosttime_value1; |
| 161 |
+ struct timeval hosttime_value2; |
| 162 |
+#endif |
| 163 |
} s; // state information |
| 164 |
|
| 165 |
bx_devices_c *devices; |