besys.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. /****************************************************************************
  2. *
  3. * BIOS emulator and interface
  4. * to Realmode X86 Emulator Library
  5. *
  6. * ========================================================================
  7. *
  8. * Copyright (C) 2007 Freescale Semiconductor, Inc. All rights reserved.
  9. * Jason Jin<Jason.jin@freescale.com>
  10. *
  11. * Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
  12. *
  13. * This file may be distributed and/or modified under the terms of the
  14. * GNU General Public License version 2.0 as published by the Free
  15. * Software Foundation and appearing in the file LICENSE.GPL included
  16. * in the packaging of this file.
  17. *
  18. * Licensees holding a valid Commercial License for this product from
  19. * SciTech Software, Inc. may use this file in accordance with the
  20. * Commercial License Agreement provided with the Software.
  21. *
  22. * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
  23. * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24. * PURPOSE.
  25. *
  26. * See http://www.scitechsoft.com/license/ for information about
  27. * the licensing options available and how to purchase a Commercial
  28. * License Agreement.
  29. *
  30. * Contact license@scitechsoft.com if any conditions of this licensing
  31. * are not clear to you, or you have questions about licensing options.
  32. *
  33. * ========================================================================
  34. *
  35. * Language: ANSI C
  36. * Environment: Any
  37. * Developer: Kendall Bennett
  38. *
  39. * Description: This file includes BIOS emulator I/O and memory access
  40. * functions.
  41. *
  42. * Jason ported this file to u-boot to run the ATI video card
  43. * BIOS in u-boot. Removed some emulate functions such as the
  44. * timer port access. Made all the VGA port except reading 0x3c3
  45. * be emulated. Seems like reading 0x3c3 should return the high
  46. * 16 bit of the io port.
  47. *
  48. ****************************************************************************/
  49. #include <common.h>
  50. #if defined(CONFIG_BIOSEMU)
  51. #include "biosemui.h"
  52. /*------------------------- Global Variables ------------------------------*/
  53. #ifndef __i386__
  54. static char *BE_biosDate = "08/14/99";
  55. static u8 BE_model = 0xFC;
  56. static u8 BE_submodel = 0x00;
  57. #endif
  58. /*----------------------------- Implementation ----------------------------*/
  59. /****************************************************************************
  60. PARAMETERS:
  61. addr - Emulator memory address to convert
  62. RETURNS:
  63. Actual memory address to read or write the data
  64. REMARKS:
  65. This function converts an emulator memory address in a 32-bit range to
  66. a real memory address that we wish to access. It handles splitting up the
  67. memory address space appropriately to access the emulator BIOS image, video
  68. memory and system BIOS etc.
  69. ****************************************************************************/
  70. static u8 *BE_memaddr(u32 addr)
  71. {
  72. if (addr >= 0xC0000 && addr <= _BE_env.biosmem_limit) {
  73. return (u8*)(_BE_env.biosmem_base + addr - 0xC0000);
  74. } else if (addr > _BE_env.biosmem_limit && addr < 0xD0000) {
  75. DB(printf("BE_memaddr: address %#lx may be invalid!\n", addr);)
  76. return M.mem_base;
  77. } else if (addr >= 0xA0000 && addr <= 0xBFFFF) {
  78. return (u8*)(_BE_env.busmem_base + addr - 0xA0000);
  79. }
  80. #ifdef __i386__
  81. else if (addr >= 0xD0000 && addr <= 0xFFFFF) {
  82. /* We map the real System BIOS directly on real PC's */
  83. DB(printf("BE_memaddr: System BIOS address %#lx\n", addr);)
  84. return _BE_env.busmem_base + addr - 0xA0000;
  85. }
  86. #else
  87. else if (addr >= 0xFFFF5 && addr < 0xFFFFE) {
  88. /* Return a faked BIOS date string for non-x86 machines */
  89. DB(printf("BE_memaddr - Returning BIOS date\n");)
  90. return (u8 *)(BE_biosDate + addr - 0xFFFF5);
  91. } else if (addr == 0xFFFFE) {
  92. /* Return system model identifier for non-x86 machines */
  93. DB(printf("BE_memaddr - Returning model\n");)
  94. return &BE_model;
  95. } else if (addr == 0xFFFFF) {
  96. /* Return system submodel identifier for non-x86 machines */
  97. DB(printf("BE_memaddr - Returning submodel\n");)
  98. return &BE_submodel;
  99. }
  100. #endif
  101. else if (addr > M.mem_size - 1) {
  102. HALT_SYS();
  103. return M.mem_base;
  104. }
  105. return M.mem_base + addr;
  106. }
  107. /****************************************************************************
  108. PARAMETERS:
  109. addr - Emulator memory address to read
  110. RETURNS:
  111. Byte value read from emulator memory.
  112. REMARKS:
  113. Reads a byte value from the emulator memory. We have three distinct memory
  114. regions that are handled differently, which this function handles.
  115. ****************************************************************************/
  116. u8 X86API BE_rdb(u32 addr)
  117. {
  118. if (_BE_env.emulateVGA && addr >= 0xA0000 && addr <= 0xBFFFF)
  119. return 0;
  120. else {
  121. u8 val = readb_le(BE_memaddr(addr));
  122. return val;
  123. }
  124. }
  125. /****************************************************************************
  126. PARAMETERS:
  127. addr - Emulator memory address to read
  128. RETURNS:
  129. Word value read from emulator memory.
  130. REMARKS:
  131. Reads a word value from the emulator memory. We have three distinct memory
  132. regions that are handled differently, which this function handles.
  133. ****************************************************************************/
  134. u16 X86API BE_rdw(u32 addr)
  135. {
  136. if (_BE_env.emulateVGA && addr >= 0xA0000 && addr <= 0xBFFFF)
  137. return 0;
  138. else {
  139. u8 *base = BE_memaddr(addr);
  140. u16 val = readw_le(base);
  141. return val;
  142. }
  143. }
  144. /****************************************************************************
  145. PARAMETERS:
  146. addr - Emulator memory address to read
  147. RETURNS:
  148. Long value read from emulator memory.
  149. REMARKS:
  150. Reads a 32-bit value from the emulator memory. We have three distinct memory
  151. regions that are handled differently, which this function handles.
  152. ****************************************************************************/
  153. u32 X86API BE_rdl(u32 addr)
  154. {
  155. if (_BE_env.emulateVGA && addr >= 0xA0000 && addr <= 0xBFFFF)
  156. return 0;
  157. else {
  158. u8 *base = BE_memaddr(addr);
  159. u32 val = readl_le(base);
  160. return val;
  161. }
  162. }
  163. /****************************************************************************
  164. PARAMETERS:
  165. addr - Emulator memory address to read
  166. val - Value to store
  167. REMARKS:
  168. Writes a byte value to emulator memory. We have three distinct memory
  169. regions that are handled differently, which this function handles.
  170. ****************************************************************************/
  171. void X86API BE_wrb(u32 addr, u8 val)
  172. {
  173. if (!(_BE_env.emulateVGA && addr >= 0xA0000 && addr <= 0xBFFFF)) {
  174. writeb_le(BE_memaddr(addr), val);
  175. }
  176. }
  177. /****************************************************************************
  178. PARAMETERS:
  179. addr - Emulator memory address to read
  180. val - Value to store
  181. REMARKS:
  182. Writes a word value to emulator memory. We have three distinct memory
  183. regions that are handled differently, which this function handles.
  184. ****************************************************************************/
  185. void X86API BE_wrw(u32 addr, u16 val)
  186. {
  187. if (!(_BE_env.emulateVGA && addr >= 0xA0000 && addr <= 0xBFFFF)) {
  188. u8 *base = BE_memaddr(addr);
  189. writew_le(base, val);
  190. }
  191. }
  192. /****************************************************************************
  193. PARAMETERS:
  194. addr - Emulator memory address to read
  195. val - Value to store
  196. REMARKS:
  197. Writes a 32-bit value to emulator memory. We have three distinct memory
  198. regions that are handled differently, which this function handles.
  199. ****************************************************************************/
  200. void X86API BE_wrl(u32 addr, u32 val)
  201. {
  202. if (!(_BE_env.emulateVGA && addr >= 0xA0000 && addr <= 0xBFFFF)) {
  203. u8 *base = BE_memaddr(addr);
  204. writel_le(base, val);
  205. }
  206. }
  207. #if defined(DEBUG) || !defined(__i386__)
  208. /* For Non-Intel machines we may need to emulate some I/O port accesses that
  209. * the BIOS may try to access, such as the PCI config registers.
  210. */
  211. #define IS_TIMER_PORT(port) (0x40 <= port && port <= 0x43)
  212. #define IS_CMOS_PORT(port) (0x70 <= port && port <= 0x71)
  213. /*#define IS_VGA_PORT(port) (_BE_env.emulateVGA && 0x3C0 <= port && port <= 0x3DA)*/
  214. #define IS_VGA_PORT(port) (0x3C0 <= port && port <= 0x3DA)
  215. #define IS_PCI_PORT(port) (0xCF8 <= port && port <= 0xCFF)
  216. #define IS_SPKR_PORT(port) (port == 0x61)
  217. /****************************************************************************
  218. PARAMETERS:
  219. port - Port to read from
  220. type - Type of access to perform
  221. REMARKS:
  222. Performs an emulated read from the Standard VGA I/O ports. If the target
  223. hardware does not support mapping the VGA I/O and memory (such as some
  224. PowerPC systems), we emulate the VGA so that the BIOS will still be able to
  225. set NonVGA display modes such as on ATI hardware.
  226. ****************************************************************************/
  227. static u8 VGA_inpb (const int port)
  228. {
  229. u8 val = 0xff;
  230. switch (port) {
  231. case 0x3C0:
  232. /* 3C0 has funky characteristics because it can act as either
  233. a data register or index register depending on the state
  234. of an internal flip flop in the hardware. Hence we have
  235. to emulate that functionality in here. */
  236. if (_BE_env.flipFlop3C0 == 0) {
  237. /* Access 3C0 as index register */
  238. val = _BE_env.emu3C0;
  239. } else {
  240. /* Access 3C0 as data register */
  241. if (_BE_env.emu3C0 < ATT_C)
  242. val = _BE_env.emu3C1[_BE_env.emu3C0];
  243. }
  244. _BE_env.flipFlop3C0 ^= 1;
  245. break;
  246. case 0x3C1:
  247. if (_BE_env.emu3C0 < ATT_C)
  248. return _BE_env.emu3C1[_BE_env.emu3C0];
  249. break;
  250. case 0x3CC:
  251. return _BE_env.emu3C2;
  252. case 0x3C4:
  253. return _BE_env.emu3C4;
  254. case 0x3C5:
  255. if (_BE_env.emu3C4 < ATT_C)
  256. return _BE_env.emu3C5[_BE_env.emu3C4];
  257. break;
  258. case 0x3C6:
  259. return _BE_env.emu3C6;
  260. case 0x3C7:
  261. return _BE_env.emu3C7;
  262. case 0x3C8:
  263. return _BE_env.emu3C8;
  264. case 0x3C9:
  265. if (_BE_env.emu3C7 < PAL_C)
  266. return _BE_env.emu3C9[_BE_env.emu3C7++];
  267. break;
  268. case 0x3CE:
  269. return _BE_env.emu3CE;
  270. case 0x3CF:
  271. if (_BE_env.emu3CE < GRA_C)
  272. return _BE_env.emu3CF[_BE_env.emu3CE];
  273. break;
  274. case 0x3D4:
  275. if (_BE_env.emu3C2 & 0x1)
  276. return _BE_env.emu3D4;
  277. break;
  278. case 0x3D5:
  279. if ((_BE_env.emu3C2 & 0x1) && (_BE_env.emu3D4 < CRT_C))
  280. return _BE_env.emu3D5[_BE_env.emu3D4];
  281. break;
  282. case 0x3DA:
  283. _BE_env.flipFlop3C0 = 0;
  284. val = _BE_env.emu3DA;
  285. _BE_env.emu3DA ^= 0x9;
  286. break;
  287. }
  288. return val;
  289. }
  290. /****************************************************************************
  291. PARAMETERS:
  292. port - Port to write to
  293. type - Type of access to perform
  294. REMARKS:
  295. Performs an emulated write to one of the 8253 timer registers. For now
  296. we only emulate timer 0 which is the only timer that the BIOS code appears
  297. to use.
  298. ****************************************************************************/
  299. static void VGA_outpb (int port, u8 val)
  300. {
  301. switch (port) {
  302. case 0x3C0:
  303. /* 3C0 has funky characteristics because it can act as either
  304. a data register or index register depending on the state
  305. of an internal flip flop in the hardware. Hence we have
  306. to emulate that functionality in here. */
  307. if (_BE_env.flipFlop3C0 == 0) {
  308. /* Access 3C0 as index register */
  309. _BE_env.emu3C0 = val;
  310. } else {
  311. /* Access 3C0 as data register */
  312. if (_BE_env.emu3C0 < ATT_C)
  313. _BE_env.emu3C1[_BE_env.emu3C0] = val;
  314. }
  315. _BE_env.flipFlop3C0 ^= 1;
  316. break;
  317. case 0x3C2:
  318. _BE_env.emu3C2 = val;
  319. break;
  320. case 0x3C4:
  321. _BE_env.emu3C4 = val;
  322. break;
  323. case 0x3C5:
  324. if (_BE_env.emu3C4 < ATT_C)
  325. _BE_env.emu3C5[_BE_env.emu3C4] = val;
  326. break;
  327. case 0x3C6:
  328. _BE_env.emu3C6 = val;
  329. break;
  330. case 0x3C7:
  331. _BE_env.emu3C7 = (int) val *3;
  332. break;
  333. case 0x3C8:
  334. _BE_env.emu3C8 = (int) val *3;
  335. break;
  336. case 0x3C9:
  337. if (_BE_env.emu3C8 < PAL_C)
  338. _BE_env.emu3C9[_BE_env.emu3C8++] = val;
  339. break;
  340. case 0x3CE:
  341. _BE_env.emu3CE = val;
  342. break;
  343. case 0x3CF:
  344. if (_BE_env.emu3CE < GRA_C)
  345. _BE_env.emu3CF[_BE_env.emu3CE] = val;
  346. break;
  347. case 0x3D4:
  348. if (_BE_env.emu3C2 & 0x1)
  349. _BE_env.emu3D4 = val;
  350. break;
  351. case 0x3D5:
  352. if ((_BE_env.emu3C2 & 0x1) && (_BE_env.emu3D4 < CRT_C))
  353. _BE_env.emu3D5[_BE_env.emu3D4] = val;
  354. break;
  355. }
  356. }
  357. /****************************************************************************
  358. PARAMETERS:
  359. regOffset - Offset into register space for non-DWORD accesses
  360. value - Value to write to register for PCI_WRITE_* operations
  361. func - Function to perform (PCIAccessRegFlags)
  362. RETURNS:
  363. Value read from configuration register for PCI_READ_* operations
  364. REMARKS:
  365. Accesses a PCI configuration space register by decoding the value currently
  366. stored in the _BE_env.configAddress variable and passing it through to the
  367. portable PCI_accessReg function.
  368. ****************************************************************************/
  369. static u32 BE_accessReg(int regOffset, u32 value, int func)
  370. {
  371. #ifdef __KERNEL__
  372. int function, device, bus;
  373. u8 val8;
  374. u16 val16;
  375. u32 val32;
  376. /* Decode the configuration register values for the register we wish to
  377. * access
  378. */
  379. regOffset += (_BE_env.configAddress & 0xFF);
  380. function = (_BE_env.configAddress >> 8) & 0x7;
  381. device = (_BE_env.configAddress >> 11) & 0x1F;
  382. bus = (_BE_env.configAddress >> 16) & 0xFF;
  383. /* Ignore accesses to all devices other than the one we're POSTing */
  384. if ((function == _BE_env.vgaInfo.function) &&
  385. (device == _BE_env.vgaInfo.device) &&
  386. (bus == _BE_env.vgaInfo.bus)) {
  387. switch (func) {
  388. case REG_READ_BYTE:
  389. pci_read_config_byte(_BE_env.vgaInfo.pcidev, regOffset,
  390. &val8);
  391. return val8;
  392. case REG_READ_WORD:
  393. pci_read_config_word(_BE_env.vgaInfo.pcidev, regOffset,
  394. &val16);
  395. return val16;
  396. case REG_READ_DWORD:
  397. pci_read_config_dword(_BE_env.vgaInfo.pcidev, regOffset,
  398. &val32);
  399. return val32;
  400. case REG_WRITE_BYTE:
  401. pci_write_config_byte(_BE_env.vgaInfo.pcidev, regOffset,
  402. value);
  403. return 0;
  404. case REG_WRITE_WORD:
  405. pci_write_config_word(_BE_env.vgaInfo.pcidev, regOffset,
  406. value);
  407. return 0;
  408. case REG_WRITE_DWORD:
  409. pci_write_config_dword(_BE_env.vgaInfo.pcidev,
  410. regOffset, value);
  411. return 0;
  412. }
  413. }
  414. return 0;
  415. #else
  416. PCIDeviceInfo pciInfo;
  417. pciInfo.mech1 = 1;
  418. pciInfo.slot.i = 0;
  419. pciInfo.slot.p.Function = (_BE_env.configAddress >> 8) & 0x7;
  420. pciInfo.slot.p.Device = (_BE_env.configAddress >> 11) & 0x1F;
  421. pciInfo.slot.p.Bus = (_BE_env.configAddress >> 16) & 0xFF;
  422. pciInfo.slot.p.Enable = 1;
  423. /* Ignore accesses to all devices other than the one we're POSTing */
  424. if ((pciInfo.slot.p.Function ==
  425. _BE_env.vgaInfo.pciInfo->slot.p.Function)
  426. && (pciInfo.slot.p.Device == _BE_env.vgaInfo.pciInfo->slot.p.Device)
  427. && (pciInfo.slot.p.Bus == _BE_env.vgaInfo.pciInfo->slot.p.Bus))
  428. return PCI_accessReg((_BE_env.configAddress & 0xFF) + regOffset,
  429. value, func, &pciInfo);
  430. return 0;
  431. #endif
  432. }
  433. /****************************************************************************
  434. PARAMETERS:
  435. port - Port to read from
  436. type - Type of access to perform
  437. REMARKS:
  438. Performs an emulated read from one of the PCI configuration space registers.
  439. We emulate this using our PCI_accessReg function which will access the PCI
  440. configuration space registers in a portable fashion.
  441. ****************************************************************************/
  442. static u32 PCI_inp(int port, int type)
  443. {
  444. switch (type) {
  445. case REG_READ_BYTE:
  446. if ((_BE_env.configAddress & 0x80000000) && 0xCFC <= port
  447. && port <= 0xCFF)
  448. return BE_accessReg(port - 0xCFC, 0, REG_READ_BYTE);
  449. break;
  450. case REG_READ_WORD:
  451. if ((_BE_env.configAddress & 0x80000000) && 0xCFC <= port
  452. && port <= 0xCFF)
  453. return BE_accessReg(port - 0xCFC, 0, REG_READ_WORD);
  454. break;
  455. case REG_READ_DWORD:
  456. if (port == 0xCF8)
  457. return _BE_env.configAddress;
  458. else if ((_BE_env.configAddress & 0x80000000) && port == 0xCFC)
  459. return BE_accessReg(0, 0, REG_READ_DWORD);
  460. break;
  461. }
  462. return 0;
  463. }
  464. /****************************************************************************
  465. PARAMETERS:
  466. port - Port to write to
  467. type - Type of access to perform
  468. REMARKS:
  469. Performs an emulated write to one of the PCI control registers.
  470. ****************************************************************************/
  471. static void PCI_outp(int port, u32 val, int type)
  472. {
  473. switch (type) {
  474. case REG_WRITE_BYTE:
  475. if ((_BE_env.configAddress & 0x80000000) && 0xCFC <= port
  476. && port <= 0xCFF)
  477. BE_accessReg(port - 0xCFC, val, REG_WRITE_BYTE);
  478. break;
  479. case REG_WRITE_WORD:
  480. if ((_BE_env.configAddress & 0x80000000) && 0xCFC <= port
  481. && port <= 0xCFF)
  482. BE_accessReg(port - 0xCFC, val, REG_WRITE_WORD);
  483. break;
  484. case REG_WRITE_DWORD:
  485. if (port == 0xCF8)
  486. {
  487. _BE_env.configAddress = val & 0x80FFFFFC;
  488. }
  489. else if ((_BE_env.configAddress & 0x80000000) && port == 0xCFC)
  490. BE_accessReg(0, val, REG_WRITE_DWORD);
  491. break;
  492. }
  493. }
  494. #endif
  495. /****************************************************************************
  496. PARAMETERS:
  497. port - Port to write to
  498. RETURNS:
  499. Value read from the I/O port
  500. REMARKS:
  501. Performs an emulated 8-bit read from an I/O port. We handle special cases
  502. that we need to emulate in here, and fall through to reflecting the write
  503. through to the real hardware if we don't need to special case it.
  504. ****************************************************************************/
  505. u8 X86API BE_inb(X86EMU_pioAddr port)
  506. {
  507. u8 val = 0;
  508. #if defined(DEBUG) || !defined(__i386__)
  509. if (IS_VGA_PORT(port)){
  510. /*seems reading port 0x3c3 return the high 16 bit of io port*/
  511. if(port == 0x3c3)
  512. val = LOG_inpb(port);
  513. else
  514. val = VGA_inpb(port);
  515. }
  516. else if (IS_TIMER_PORT(port))
  517. DB(printf("Can not interept TIMER port now!\n");)
  518. else if (IS_SPKR_PORT(port))
  519. DB(printf("Can not interept SPEAKER port now!\n");)
  520. else if (IS_CMOS_PORT(port))
  521. DB(printf("Can not interept CMOS port now!\n");)
  522. else if (IS_PCI_PORT(port))
  523. val = PCI_inp(port, REG_READ_BYTE);
  524. else if (port < 0x100) {
  525. DB(printf("WARN: INVALID inb.%04X -> %02X\n", (u16) port, val);)
  526. val = LOG_inpb(port);
  527. } else
  528. #endif
  529. val = LOG_inpb(port);
  530. return val;
  531. }
  532. /****************************************************************************
  533. PARAMETERS:
  534. port - Port to write to
  535. RETURNS:
  536. Value read from the I/O port
  537. REMARKS:
  538. Performs an emulated 16-bit read from an I/O port. We handle special cases
  539. that we need to emulate in here, and fall through to reflecting the write
  540. through to the real hardware if we don't need to special case it.
  541. ****************************************************************************/
  542. u16 X86API BE_inw(X86EMU_pioAddr port)
  543. {
  544. u16 val = 0;
  545. #if defined(DEBUG) || !defined(__i386__)
  546. if (IS_PCI_PORT(port))
  547. val = PCI_inp(port, REG_READ_WORD);
  548. else if (port < 0x100) {
  549. DB(printf("WARN: Maybe INVALID inw.%04X -> %04X\n", (u16) port, val);)
  550. val = LOG_inpw(port);
  551. } else
  552. #endif
  553. val = LOG_inpw(port);
  554. return val;
  555. }
  556. /****************************************************************************
  557. PARAMETERS:
  558. port - Port to write to
  559. RETURNS:
  560. Value read from the I/O port
  561. REMARKS:
  562. Performs an emulated 32-bit read from an I/O port. We handle special cases
  563. that we need to emulate in here, and fall through to reflecting the write
  564. through to the real hardware if we don't need to special case it.
  565. ****************************************************************************/
  566. u32 X86API BE_inl(X86EMU_pioAddr port)
  567. {
  568. u32 val = 0;
  569. #if defined(DEBUG) || !defined(__i386__)
  570. if (IS_PCI_PORT(port))
  571. val = PCI_inp(port, REG_READ_DWORD);
  572. else if (port < 0x100) {
  573. val = LOG_inpd(port);
  574. } else
  575. #endif
  576. val = LOG_inpd(port);
  577. return val;
  578. }
  579. /****************************************************************************
  580. PARAMETERS:
  581. port - Port to write to
  582. val - Value to write to port
  583. REMARKS:
  584. Performs an emulated 8-bit write to an I/O port. We handle special cases
  585. that we need to emulate in here, and fall through to reflecting the write
  586. through to the real hardware if we don't need to special case it.
  587. ****************************************************************************/
  588. void X86API BE_outb(X86EMU_pioAddr port, u8 val)
  589. {
  590. #if defined(DEBUG) || !defined(__i386__)
  591. if (IS_VGA_PORT(port))
  592. VGA_outpb(port, val);
  593. else if (IS_TIMER_PORT(port))
  594. DB(printf("Can not interept TIMER port now!\n");)
  595. else if (IS_SPKR_PORT(port))
  596. DB(printf("Can not interept SPEAKER port now!\n");)
  597. else if (IS_CMOS_PORT(port))
  598. DB(printf("Can not interept CMOS port now!\n");)
  599. else if (IS_PCI_PORT(port))
  600. PCI_outp(port, val, REG_WRITE_BYTE);
  601. else if (port < 0x100) {
  602. DB(printf("WARN:Maybe INVALID outb.%04X <- %02X\n", (u16) port, val);)
  603. LOG_outpb(port, val);
  604. } else
  605. #endif
  606. LOG_outpb(port, val);
  607. }
  608. /****************************************************************************
  609. PARAMETERS:
  610. port - Port to write to
  611. val - Value to write to port
  612. REMARKS:
  613. Performs an emulated 16-bit write to an I/O port. We handle special cases
  614. that we need to emulate in here, and fall through to reflecting the write
  615. through to the real hardware if we don't need to special case it.
  616. ****************************************************************************/
  617. void X86API BE_outw(X86EMU_pioAddr port, u16 val)
  618. {
  619. #if defined(DEBUG) || !defined(__i386__)
  620. if (IS_VGA_PORT(port)) {
  621. VGA_outpb(port, val);
  622. VGA_outpb(port + 1, val >> 8);
  623. } else if (IS_PCI_PORT(port))
  624. PCI_outp(port, val, REG_WRITE_WORD);
  625. else if (port < 0x100) {
  626. DB(printf("WARN: MAybe INVALID outw.%04X <- %04X\n", (u16) port,
  627. val);)
  628. LOG_outpw(port, val);
  629. } else
  630. #endif
  631. LOG_outpw(port, val);
  632. }
  633. /****************************************************************************
  634. PARAMETERS:
  635. port - Port to write to
  636. val - Value to write to port
  637. REMARKS:
  638. Performs an emulated 32-bit write to an I/O port. We handle special cases
  639. that we need to emulate in here, and fall through to reflecting the write
  640. through to the real hardware if we don't need to special case it.
  641. ****************************************************************************/
  642. void X86API BE_outl(X86EMU_pioAddr port, u32 val)
  643. {
  644. #if defined(DEBUG) || !defined(__i386__)
  645. if (IS_PCI_PORT(port))
  646. PCI_outp(port, val, REG_WRITE_DWORD);
  647. else if (port < 0x100) {
  648. DB(printf("WARN: INVALID outl.%04X <- %08X\n", (u16) port,val);)
  649. LOG_outpd(port, val);
  650. } else
  651. #endif
  652. LOG_outpd(port, val);
  653. }
  654. #endif