Win95/98/NT 下對記憶體、埠、中斷的直接控制和讀寫 (轉)

worldblog發表於2007-12-04
Win95/98/NT 下對記憶體、埠、中斷的直接控制和讀寫 (轉)[@more@]

  TVicHw32.DLL version 2.0

  Copyright (C) 1997 Victor Ishikeev
  e-:
  Portions Copyright (C) 1997 EnTech Taiwan
  :

  AS_DLL.TXT

CONTENTS
========

1. GENERAL TVicHW32 FUNCTIONS
2. DIRECT MEMORY ACCESS WITH TVicHW32
3. DIRECT PORT I/O WITH TVicHW32
4. HARDWARE INTERRUPT HANDLING WITH TVicHW32
5. CONTACT INFORMATION

 

1. GENERAL TVicHW32 FUNCTIONS
====================================================

TVicHW32 has the following general functions:

  bool  VICFN OpenTVicHW32(void);
  -------------------------------
  Loads the vichwXX.vxd (under 95) or vichwXX.sys (under
  ) kernel-mode , providing direct access to the
  hardware. If the kernel-mode driver was succesully opened, the
  IsDriverOpened() returns True; if the function fails, the IsDriverOpened()
  returns False.

  void  VICFN CloseTVicHW32(void);
  ----------------------
  Closes the kernel-mode driver and releases memory allocated to it.
  If a hardware interrupt was "unmasked", the "mask" is restored. If the
  driver was successfully closed, the IsDriverOpened() always returns False.

  bool VICFN IsDriverOpened (void);
  ----------------------------------------------

  This boolean function specifies whether the kernel-mode driver is open.
  Returns True if the driver is already open, or False if it is not.


2. DIRECT MEMORY ACCESS WITH TVicHW32
=====================================

The following function pets direct memory acccess:

  void* VICFN MapPhysToLinear(D PhAddr, DWORD Size);
  ---------------------------------------- ----------------------
  Maps a specific physical address to a pointer in linear memory,
  where PhAddr is the base address and Size is the actual number of
  bytes to which access is required.

  Note that a subsequent call to MapPhysToLinear invalidates the
  previous pointer.

  The following example returns a pointer to the system ROM area:

  char *pBios;

  OpenVicHW32();

  if (IsDriverOpened()) {

  pBi= MapPhysToLinear (0xF8000,256); bytes beginning at $F8000

  with pBIOS...

  CloseVicHW32();

  }

  else ...  //  failed

3. DIRECT PORT I/O WITH TVicHW32
================================

The following functions permit direct I/O port access:
------------------------------------------------------

  BYTE  VICFN ReadPort  (WORD wPortAddress);  // read one byte
  WORD  VICFN ReadPortW  (WORD wPortAddress);  // read one word
  DWORD VICFN ReadPortL  (WORD wPortAddress);  // read four bytes
  void  VICFN WritePort  (WORD wPortAddress, BYTE bData);  // write one byte
  void  VICFN WritePortW (WORD wPortAddress, WORD wData);  // write one word
  void  VICFN WritePortL (WORD wPortAddress, DWORD lData); // write four bytes


  void  VICFN SetHardAccess(bool HardAccess);
  -------------------------------------------
  The SetHardAccess() function determines whether the kernel-mode driver
  should use "hard" or "soft" access to the I/O ports. If set to True
  "hard" access is employed; if set to False "soft" access is employed.

  "Soft" access provs higher performance access to ports, but may fail
  if the port(s) addressed are already in use by another kernel-mode
  driver. While slower, "Hard" access provides more reliable access to
  ports which have already been opened by another kernel-mode driver.

  bool  VICFN TestHardAccess(void);
  ---------------------------------
  Returns True is "hard" access is used.

4. HARDWARE INTERRUPT HANDLING WITH TVicHW32
============================================

In a environment, hardware interrupts are normally prohibited
by Windows; the TVicHW32 kernel-mode driver allows you to use the
interrupt for direct handling by your application. Note that only one
interrupt can be handled at a time.

The following functions permit access to hardware interrupts.

  void  VICFN SetIRQ(BYTE IRQNumber, void * lpfnOnHwInterrupt);
  -------------------------------------------------------------

  Assign the interrupt specified by the IRQNumber value (1..15) to
  the lpfnOnHwInterrrupt() handler. If success then IsIRQSet() function
  (see below) returns True.
  Note that IRQ0 (the system timer) is *not* supported.

  bool  VICFN IsIRQSet(void);
  ----------------------------------------
  Specifies whether the hardware interrupt handler has been
  created by the SetIRQ method.


  void  VICFN UnMaskIRQ(void);
  ----------------------------
  Physically unmasks the hardware interrupt specified by the IRQNumber
  property, so that an lpfnOnHWInterrupt function will be generated
  when a hardware interrupt occurs.

  void  VICFN MaskIRQ(void);
  --------------------------
  Physically masks the hardware interrupt specified by the IRQNumber value.

  bool  VICFN IsMasked(void);
  ---------------------------
  Function which specifies whether the hardware interrupt
  handler has been physically masked (True).


  void  VICFN DestroyIRQ(void);
  -----------------------------
  Frees the memory and code previously assigned for the hardware
  interrupt specified by the IRQNumber value.

  DWORD VICFN GetInterruptCounter(void);
  --------------------------------------
  Function which counts the number of hardware interrupts
  intercepted by the TVicHW32 kernel-mode driver. The GetInterruptCounter()
  function is provided largely for deging purposes, allowing you to
  compare the actual number of hardware interrupts generated with the
  number processed by your application.


  void  VICFN SimulateHWInt(void);
  -------------------------------
  This function is provided for purposes of debugging, and allows you to
  simulate a hardware interrupt. When this procedure is called, the TVicHW32
  kernel-mode driver will feign a "hardware interrupt", without directly
  affecting the hardware.


5. CONTACT INFORMATION
======================

  Comments, questions and suggestions regarding TVicHW32 can be directed
by e-mail to or .

With best wishes,

Victor Ishikeev
Jun 1997


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-988397/,如需轉載,請註明出處,否則將追究法律責任。

相關文章