阅读:6615回复:2
64位驱动下使用汇编代码的技巧
Programatically update the driver for a device
So you need to change the driver loaded for a given device from your application. You have a couple of options to do this. The first method is to use the UpdateDriverForPlugAndPlayDevices API. This method is simple and straightforward to use. But the downside of using this API is that it will update drivers for all devices with the specified hardware id. So if you need to selectively update one of the devices with a new driver you will have to look for something else. And that method is by using the InstalledSelectedDriver API. Sample Code: How to use InstallSelectedDriver to update driver ? posted @ Wednesday, November 12, 2008 3:00 AM | Feedback (0) Monday, April 28, 2008 # USB Monitor for Windows This post is about USBTrace, a software based USB monitor / USB sniffer , which can be used to capture & analyze transactions happening in the USB bus. This tool is helpful for USB firmware/device driver developers while debugging and testing their device implementation. USB requests are captured and displayed in easly readable format to make analyzing easy. USB requests passing though different layers of the USB device stack are captured and displayed. Helps developers to highly reduce their debug session's time. Supports USB 1.x and 2.0 host controllers, hubs and devices. Download : http://www.sysnucleus.com/usbtrace_download.html Keywords : USB Monitor , USB Analyzer , USB Protocol Analyzer , USB Sniffer posted @ Monday, April 28, 2008 10:50 PM | Feedback (1) Friday, March 07, 2008 # X64 Assembly Code in Windows Drivers Writing asm code for 32 bit drivers is straightforward. You can embed the code in an __asm { } block. void DemoFunction() { __asm { mov eax, 0x01 ; more assembly } } But writing assembly in 64 bit driver source code requires a bit more work. The 64 bit compiler will not allow inline assembly. The assembly code will have to be moved to a seperate assembly module (an .asm file). Step 1 : Write necessary assembly routines in a seperate .asm file Example : Test.asm ------------------------------------------ .data ; all data variables in your asm code goes here myData1 dq 0 ; 64 bit data .code ; all assembly routines go here TestFunction PROC ; sample function/routine/procedure ; assembly code for the function goes here ret TestFunction ENDP END ; end of assembly file Step2 : Integrate assembly function with C In one of your C header files declare the function: extern void TestFunction(void); Step 3 : Adding asm file to sources file In the sources file of your driver you can add the .asm file along with other C files. Example: SOURCES = init. c \ ioctl.c \ pnp.c\ power.c\ Test.asm You can add the same under AMD64_SOURCES or IA64_SOURCES if you required to include the same only in those specific architectures. posted @ Friday, March 07, 2008 2:27 AM | Feedback (11) Thursday, March 06, 2008 # X64 Calling Computers with 64 bit processors are becoming popular, at least in enterprise circles. Also the X64 version of Windows Vista is more popular than Windows XP 64 bit edition. 2 Types of 64 bit architecture Yes, unlike 32 bit (aka X32) there are 2 64 bit architectures:
So, whats the difference ? The X64 architecture is a super set of X32 architecture :
And how is programing different ? A lot has been written about porting existing 32 bit code to 64 bit. A lot of these deals with change in sizeof pointers (from 32 bit to 64 bit) and change in the sizeof some of the basic data types (this depends on the compiler which you are using) Links: Porting device drivers to AMD64 [http://www.amd.com/us-en/assets/content_type/DownloadableAssets/dwamd_Porting_Win_DD_to_AMD64_Sept24.pdf] 64 bit driver guidelines [http://www.microsoft.com/whdc/driver/64bitguide.mspx] 20 issues of porting C++ code on the 64-bit platform [http://www.viva64.com/articles/20_issues_of_porting_C++_code_on_the_64-bit_platform.html] ..assembly programming ? Not many program in assembly languages these days. But if it occurs to you there are a few things to keep in mind. Source Link : http://www.quequero.org/X64_Assembly Win32 on X32 provided us with many calling conventions (function calling conventions : fastcall, stdcall etc). In X64 there is no choice. There is only one calling convention: The first parameter is the rcx register, the second one rdx, the third r8 and the fourth r9. Saying that the parameters registers are part of the stack frame, makes it also clear that any function that calls another child function has to initialize the stack providing space for these four registers, even if the parameters passed to the child function are less than four. The initialization of the stack pointer is done only in the prologue of a function, it has to be large enough to hold all the arguments passed to child functions and it's always a duty of the caller to clean the stack. Now, the most important thing to understand how the space is provided in the stack frame is that the stack has to be 16-byte aligned. In fact, the return address has to be aligned to 16 bytes. So, the stack space will always be something like 16n + 8, where n depends on the number of parameters. Here's a small figure of a stack frame:
If you see the disassembly of a 64 bit program, you can see that the stack pointer (RSP) is not messed with throughout the function body. Necessary stack is reserverd ( Sub RSP, 0x[ReqSize] ) in the function prolog. Another important thing to note is that even though the first 4 parameters are passed via registerd (RCX, RDX, R8 and R9) they must be given scratch storage space in the stack (Register Parameters in the above figure/call stack). So while porting asm from 32bit to 64bit, if you have a void routine call MyRoutinemust be changed as: sub rsp, 20h ; Reserve space for register parameters call MyRoutine add rsp, 20h Another difference found was in X64 the luxury of PUSHA/PUSHD POPA/POPD (Push/Pop all registers and flags) is not available. Footnotes
|
|||||
|
沙发#
发布于:2010-06-29 12:24
好贴。受益匪浅!
请教另外一个问题:我在Intel CPU上安装win2k3 sp2 x64 ,检测wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64。也就是说安装在Intel CPU机器上的检查为AMDx64,这正常吗? |
|
板凳#
发布于:2010-06-29 12:29
|
|