荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: tang (独孤九剑〖玄铁重剑〗), 信区: Program
标  题: [转载] 如何在Windows程序中编写中断服务程序    Rojey (转寄)
发信站: BBS 荔园晨风站 (Sat Dec  4 14:40:19 1999), 站内信件

【 以下文字转载自 tang 的信箱 】
【 原文由 tang.bbs@bbs.net.tsinghua.edu.cn 所发表 】
                 简介:

  本文从Ask Dr.GUI.#4摘录,介绍了,如何在windows程序中建立
一个中断服务程序(ISR).相信对大家会有益的。

                 正文:

Dear Dr. GUI:
  I want to place an interrupt service routine (ISR) in my Windows-based
application. How do I do it? Does the ISR have to be in physical memory
 below 1 megabyte (MB)? Does  the ISR have to be in a dynamic-link library
(DLL)? What are the rules, especially now that real mode is dead?

Dr. GUI replies:

   I assume you are trying to talk to some specialized piece
of hardware through a hardware interrupt. The rules are:

1.  Put the ISR and any code or data used by the ISR
in a DLL and mark everything that is needed at interrupt
time as FIXED in the SEGMENTS section of your .DEF file.
Don't mark everything fixed梛ust the stuff you need at
interrupt time. Fixed DLL code and data is automatically
page-locked to keep it from being paged in enhanced mode.

2.  Use the MS-DOS Get Interrupt Vector call (Interrupt 21h,
Function 35h) and Set Interrupt Vector
call (Interrupt 21h, Function 25h) to manipulate the
interrupt vector. Don't worry梂indows does the right
thing to reflect the interrupt into protected mode. If
the hardware you are dealing with is memory mapped or
passes real-mode addresses in registers, you will need to
obtain protected-mode selectors for the memory (because
your ISR will be running in protected mode). DOS
protected-mode interface (DPMI) calls are available for
this purpose.

3.  The ISR does not have to reside in the lower 1 MB
of physical memory. However, if you are allocating memory
for a device that expects it to be in physical memory
below 1 MB, you need to allocate the memory with
GlobalDOSAlloc.


4.  The only Windows function that you can call from
an ISR is PostMessage.


    Now for a bit of a sermon: If you want to support
specialized hardware under enhanced-mode Windows, you
will more than likely have to write a virtual device
(VxD) for the hardware. Windows running in enhanced mode
is very good about reflecting interrupts from devices
into the appropriate virtual machine (VM), but this
virtualization comes at a price: interrupt latency. Most
devices are quite sensitive to delays in servicing their
interrupts, especially devices that transfer data. The
only way to guarantee that interrupts from your device
are processed in a timely manner is to write a VxD for
it. The VxD runs in ring 0 and handles the interrupt
directly, and thus does not incur any VM scheduling or
virtualization overhead.

  Information on how to write VxDs is contained in the
Windows version 3.1 Device Driver Kit (DDK) Virtual
Device Adaptation Guide.




--
※ 转载:·BBS 荔园晨风站 bbs.szu.edu.cn·[FROM: 210.39.3.94]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店