转自http://www.aogosoft.com/masmplus/
MASMPlus 自带各种类型的开发例程和框架,可以迅速基于汇编开发各种应用程序(dos, win32, 窗口应用程序)或DLL,甚至windows驱动
MASMPlus 是一个使用纯 MASM 编写的 MASM Integrate Develop Environment.
专业汇编程序员90%均使用 MASM,为它开发的编辑器非常多,其中最有名的是 RadASM, 而现在,真正能与 RadASM 同级的就只有 MASMPlus 了,理由是只有 MASMPlus 与 RadASM 一样编写了自定义编辑类,并且比它更出色,只有自已的类,才能在各方面尽情发挥,在量身定制方面,MASMPlus 更是费尽心思,笔者长时间从事工业硬件汇编程序编写,认识到对于专业汇编程序员而言,最重要的,就是代码书写,不需要华而不实的界面,不需要莫名其妙的功能,不需要可有可无的设置,更不需要所谓的封装,总的来说, MASMPlus 是半自动,这也是 MASMPlus 没有取名为 MASMIDE 的主要原因.
MASMPlus 工程模式极为简单,简单但并不简陋,这种小巧方便的工程管理方式,能同时打开任意多个单个文件/工程,各自编译/链接互不相关,工程单个文件属性设置,带来的,是真正的多工程,一个工程,可以包含多个主程序,多个动态库,多个静态库,组的设置,各库之间关键字搜索相互独立,共享文件全局搜索,并可实现简单方便的混合编程.你需要做的只是稍稍设置参数,按 Ctrl+1 即可一步完成所有操作.MASMPlus 还可以导出工程为模板,可以完全用于工程的发布,因为导出时,MASMPlus 会将工程中所有文件全部打包进apt中,而这个文件交给其它人时,可以直接使用它创建新工程而不会破坏apt.同时,MASMPlus 的工程模块拥有独一无二的功能:保存附加信息,它在每次关闭工程时将工程所有文件的撤消缓冲保存到工程app中,用户在下次重新打开时可以继续上一次的撤消,如果中间没有使用其它工具编辑文件, MASMPlus 可以记录整个软件的编写过程.详细请参考 "使用工程" 一节.
代码辅助书写方面,MASMPlus 可以说是做得最好的一个编辑器,函数原型参数突出显示,标志参数自动列出,全局搜索可以搜索整个工程,全部关键字列出慢慢浏览,自动大小写支持全部关键字,结构类型变量成员列出,鼠标提示关键字信息,同时,输入与列出遵守一定的编程规则,不会误导使用者,详细请参考 "语法提示规则" 一节.
查找方面 MASMPlus 支持正则表达式查找与替换,这是一个自主开发的正则表达式引擎,同时它的库已带入 MASMPlus,MASMPlus 使用者可直接在自己的程序中使用,MASMPlus 的正则表达式语法与通用的略有不同,详细使用及规则请参考 "正则表达式" 一节.
同时,MASMPlus 支持插件开发,通过装植插件,可以扩展程序功能,尤其是窗口类插件,这种创新的插件模型,可以让 MASMPlus 扩展成为任何编辑器,随着之后插件的增加,使用者会发现 MASMPlus 能打开各种各样的文件,如果您是专业程序员,想为 MASMPlus 编写插件,请参考 "PDK 开发手册" 一章.同时,官方已经预留了二个插件,一个是 "资源编辑器" ,另一个是 "调试器" ,不久这两个插件均会开发并内置在 MASMPlus 下述版本中.
转自:http://blog.csdn.net/KingWolfOfSky/archive/2009/07/12/4342511.aspx
If you've recently purchased Assembly Language for Intel-Based Computers, 5th edition, you probably want to get the software set up so you can start working. This tutorial should make the process easier. If you're in a hurry to get started, you only need to read Item 1.
Found an error in this document? Please email me immediately. Except where noted, all instructions in this document apply equally to Visual Studio and Visual C++ Express.
You can verify that the Microsoft Assembler is installed by looking for the file ml.exe in the \vc\bin folder of your Visual Studio installation directory, such as c:\Program Files\Microsoft Visual Studio 9.0\vc\bin.
Downloading and installing the Microsoft Assembler 8.0: Visit Microsoft's MASM 8.0 download site. Follow the download and installation instructions on the Microsoft page. If the link is broken, please let us know by email. Note that this MASM download only works with Visual C++ 2005 Express. MASM 8.0 is almost identical to MASM 9.0.
Click this link to get the latest copy of the book's link libraries and example programs. The examples are stored in a self-extracting archive file that automatically extracts to the c:\Irvine folder. Unless you have some objection to using that location, do not alter the path. (Lab managers: you can designate c:\Irvine directory as read-only.) If you plan to change the installation location, read our instructions relating to changing project properties.
The folllowing files will be copied into the c:\Irvine directory:
Filename
Description
GraphWin.inc
Include file for writing Windows applications
Irvine16.inc
Include file used with the Irvine16 link library (16-bit applications)
Irvine16.lib
16-bit link function library used with this book
Irvine32.inc
Include file used with the Irvine32 link library (32-bit applications)
Link16.exe
16-bit linker
Irvine32.lib
32-bit link function library used with this book
Macros.inc
Include file containing macros (explained in Chapter 10)
SmallWin.inc
Small-sized include file, used by Irvine32.inc
make16.bat
Batch file for building 16-bit applications
VirtualKeys.inc
Keyboard code definitions file, used by Irvine32.inc
A subdirectory named Examples will contain all the example programs shown in the book.
Start Visual C++ Express, and select Options from the Tools menu. Select Text Editor, Select All Languages, and select Tabs:
Set the Tab Size and Indent Size to 5.
Visual Studio and Visual C++ Express require assembly language source files to belong to a project, which is a kind of container. A project holds configuration information such as the locations of the assembler, linker, and required libraries. A project has its own folder, and it holds the names and locations of all files belonging to it. We have created a sample project folder in the c:\Irvine\Examples directory, and its name is Project_Sample.
Do the following steps, in order:
Tip: If the Solution Explorer window is not visible, select Solution Explorer from the View menu. Also, if you do not see main.asm in the Solution Explorer window, look at the tabs along the bottom of the window. Click the Solution Explorer tab.
You should see the following program in the editor window:
TITLE MASM Template (main.asm) ; Description: ; ; Revision date: INCLUDE Irvine32.inc .data myMessage BYTE "MASM program example",0dh,0ah,0 .code main PROC call Clrscr mov edx,OFFSET myMessage call WriteString exit main ENDP END main
Later, we'll show you how to copy this program and use it as a starting point to write your own programs.
Next, you will build (assemble and link) the sample program:
In the output window at the bottom of the screen, you should see messages similar to the following, indicating the build progress:
1>------ Build started: Project: Project, Configuration: Debug Win32 ------ 1>Assembling... 1>Assembling: .\main.asm 1>Linking... 1>Embedding manifest... 1>Build log was saved at "file://g:\masm\Project_sample\Debug\BuildLog.htm" 1>Project - 0 error(s), 0 warning(s) ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
If you do not see these messages, the project has probably not been modified since it was last built. No problem--just add a space somewhere in the document, save it, and try the Build command again.
Select Start without Debugging from the Debug menu. The following console window should appear, although your window will be larger than the one shown here:
The "Press any key to continue..." message is automatically generated by Visual C++ Express.
Congratulations, you have just run your first Assembly Language program.
Press any key to close the Console window.
When you assembled and linked the project, a file named Project.exe was created inside the project's \Debug folder. This is the file that executes when you run the project. You can execute Project.exe by double-clicking its name inside Windows Explorer, but it will just flash on the screen and disappear. That is because Windows Explorer does not pause the display before closing the command window.
Before long, you will want to create your own projects. The easiest way to do this is to copy the entire c:\Irvine\Examples\Project_Sample folder to a new location. Copy it to a folder in which you have read/write permissions. (If you're working in a college computer lab, a useful location is a portable USB drive. Then you can modify the program, build, and run it again.
In this step, you will set a breakpoint inside the sample program. Then you will use the Visual C++ debugger to step through the program's execution one statement at a time.
If you want to display the CPU registers, do the following: Start debugging the program, then select Windows from the Debug menu. Select Registers from the drop-down list. The bottom window will display the register contents. Right click this window and check the item Flags to enable the display of conditional flags.
You can interrupt a debugging session at any time by selecting Stop Debugging from the Debug menu. You can do the same by clicking the blue square button on the toolbar. To remove a breakpoint from the program, click on the red dot so that it disappears.
If you set a breakpoint in a program, you can use the debugger to execute the program a full speed (more or less) until it reaches the breakpoint. At that point, the debugger drops into single-step mode.
You can remove a breakpoint by clicking its red dot with the mouse. Take a few minutes to experiment with the Debug menu commands. Set more breakpoints and run the program again. For the time being, you can use the F11 key to step through the program in the same way the F10 key did.
Suppose you want to run another example program, or possibly create your own program. You can either edit and modify main.asm, or you can remove main.asm from the project and insert some other .asm file into the project.
The easiest way to add an assembly language source file to an open project is to drag its filename with the mouse from a Windows Explorer window onto the name of your project in the Solution Explorer window. A reference to the file (not a copy) will be inserted in your project's directory. Try this now:
Here is what you should see in the Console window, except that only your EAX register will have the same value as ours:
When you press a key, the console window will close.
If you want to make a copy of an existing file, use Windows Explorer to copy the file into your project directory. Then, right-click the project name in Solution Explorer, select Add, select Existing Item, and select the filename.
Return to top or read about Project Properties settings.
Only Chapters 12 through 16 require the building of 16-bit applications. Except for a few exceptions, which are noted in the book, your 16-bit applications will run under Windows XP and Windows Vista.
If you plan to build 16-bit applications, you need to add two new commands to the Tools menu in Visual C++ Express (or Visual Studio). To add a command, select External Tools from the Tools menu. The following dialog will appear, although many of the items in your list on the left side will be missing:
Click the Add button and fill in the Title, Command, Arguments, and Initial directory fields as shown in the screen snapshot. If you click the buttons with arrows on the right side of the Arguments and Initial directory fields, a convenient list appears. You can select an item without having to worry about spelling:
Click the Apply button to save the command.
Click the Add button again, and create a new command named Run 16-bit ASM:
Click the OK button to save the command and close the External Tools dialog.
To test your new 16-bit commands, open the file named 16-bit.asm from the ch03 folder in the book's example programs. Select Build 16-bit ASM from the Tools menu. The following command window should appear, showing the successful execution of the assembler and linker, followed by a listing of all files related to this program:
Press a key to close the window. Next, you will run the program. Select Run 16-bit ASM from the Tools menu. The following window will appear, although the contents of all registers except EAX will be different:
Press a key to close the window.
You have completed the setup for building and running 16-bit assembly language programs.
You might be interested to know more about how Visual C++ projects are set up for assembly language programs.
Assuming that our sample project is still open, select Project Properties from the Project menu. Expand the entry under Configuration Properties. Then expand the entry named Microsoft Macro Assembler. This is what you should see:
Click the entry named General under Microsoft Macro Assembler . Notice that the Include Paths option has been set to the c:\Irvine directory. This tells the assembler where to find files having a filename extension of ".inc". Here is a sample:
Next, select the Listing File entry, also in the Microsoft Macro Assembler group. Notice that the Assembled Code Listing File entry (shown below) has been assigned a macro name (starting with $) that identifies the name of the source input file, with a file extension of .lst. So, if your program were named main.asm, the listing file would be named main.lst:
Find the Linker entry under Configuration Properties. Select the Input entry, and notice that two filenames have been added to the Additional Dependencies entry. The user32.lib file is a standard MS-Windows file. The irvine32.lib file is the link library file supplied with this book. There must be at least one space separating the file names:
Next, select Linker under Configuration Properties, and then select General. The Additional Library Directories option equals c:\Irvine, so the linker can find the Irvine32.lib library file:
Select Linker under the Configuration Properties and select Debugging. Notice that the Generate Debug Info option is set to Yes:
Select System under the Linker entry. Notice that the SubSystem option has been set to Console:
We use the Console setting because it is easy for assembly language programs to write output to a text console (Command) window. This is the window you see when running cmd.exe from the Start > Run menu in Windows.
Click the OK button to close the Project Property Pages window.
Prior to 7/26/06, the sample Visual Express projects in the book's download file did not generate source listing files. Here's how to change that behavior in a single project:
Open the project. From the menu, select Project, select Project Properties. In the list box, select Microsoft Macro Assembler, then select Listing File. Set the Assembled Code Listing file option to $(InputName).lst .
You do not have to create your own projects completely by yourself. Quite frankly, it's a lot of work. We've placed a copy of the Project_sample project in each folder of the book's example programs. You can just add your own program to one of these projects.
You can name a project anything you want, of course, but we will assume your project is named MyProject in the following examples, and that you will save it in the c:\temp directory. The commands are a little different, depending on which software you use:
1. Select New from the File menu, and select Project.
2. In the New Project window, select General, and select Empty Project as the project type:
You probably will want to leave the Create directory for solution option unchecked.
3. Click the OK button to create the empty project.
You probably will want to leave the Create directory for solution option unchecked.
Click the OK button to close this window.
4. Next, you need to add some customizations. We will assume you installed the book's files in the c:\Irvine directory. Make all changes shown in the Project Properties Settings section of this document. If you installed the book's sample programs in some other location than c:\Irvine, you'll need to make appropriate changes to the project properties.
5. Select Build Solution. If your Output window is similar to the following message, you did everything right:
1>------ Build started: Project: MyProject, Configuration: Debug Win32 1>Linking... 1>Embedding manifest... 1>Build log was saved at "file://c:\temp\MyProject\Debug\BuildLog.htm" 1>MyProject - 0 error(s), 0 warning(s) ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped
When a text editor uses syntax highlighting, language keywords, strings, and other elements appear in different colors. Visual Studio and Visual C++ Express can highlight MASM reserved words and strings, as shown in the following example:
This won't happen automatically, but you can create a syntax definition file named Usertype.dat that contains MASM keywords. Then when Visual Studio (or Visual C++ Express) starts, it reads the syntax file and highlights MASM keywords.
Here are the required steps to set up MASM syntax highlighting in Visual Studio or Visual C++ Express:
1) Download the Usertype.dat file given here to a folder in which you have read/write permissions. If you are using Windows Vista, download to My Documents, or C:\temp, or any folder that doesn't have security restrictions.
2) Copy Usertype.dat to the C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE folder. If you are using Windows Vista, it will display a verification window before copying the file.
3) Open Visual Studio or Visual C++ Express, select Options from the Tools menu, select Text Editor, and select File Extension. On the right side of the dialog (shown below), enter asm as the extension, select Microsoft Visual C++ from the Editor list, and click the Add button. Click the OK button to save your changes.
Close Visual Studio and restart it. Open your project and display an ASM file. You should see syntax highlighting in the editor.
Many people like to use a Windows batch file to assemble and link programs. A batch file is a text file containing a sequence of commands that execute as if they had been typed at the command prompt. In fact, they are powerful enough to contain variables, loops, IF statements, and so on.
The easiest way to run a batch file is to first open a Command window and then type the name of the batch file (along with arguments) at the command prompt. To open a Command window, you must execute a program named cmd.exe. We will make that easy for you.
Step 1:Download a ZIP file containing the following items:
There are two different versions of the ZIP file:
Step 2: Extract the ZIP file into the c:\Irvine\Examples directory on your computer.
Step 3: Do the following:
This file assembles, links, and debugs a single assembly language source file. Before using it, install Visual Studio 2008 in the following directory: C:\Program Files\Microsoft Visual Studio 9.0 Next, install the Irvine 5th edition link libraires and include files in the following directory: C:\Irvine Finally, copy this batch file to a location on your system path. We recommend the following directory: C:\Program Files\Microsoft Visual Studio 9.0\VC\bin Command-line syntax: asm32 [/H | /h | -H | -h] -- display this help information asm32 filelist -- assemble and link all files asm32 /D filelist -- assemble, link, and debug asm32 /C filelist -- assemble only <filelist> is a list of up to 5 filenames (without extensions), separated by spaces. The filenames are assumed to refer to files having .asm extensions. Command-line switches are case-sensitive.
Type the following command to assemble and link a source file named main.asm:
asm32 main
You should see the following messages:
Assembling: main.asm
The file main.obj was produced. ..................................
Linking main.obj to the Irvine32, Kernel32, and User32 libraries.
The file main.exe was produced. ..................................
In fact, several files were produced.
If there were errors in the program, you would see error messages generated by the assembler. Here is an example:
Assembling: main.asm
main.asm(9) : error A2008: syntax error : myMessage
main.asm(15) : error A2006: undefined symbol : myMessage
You would then open the main.asm file with a text editor (such as Notepad), fix the errors, and run the asm32 batch file again.
Although we used a file named main.asm in this example, the asm32.bat batch file will work for any assembly language file, regardless of the name. The only requirement is that your assembly language source file have a .asm filename extension.
No doubt, you will want to assemble programs in various different disk folders, not just the batch_sample folder used in the foregoing example. All you need to do is copy the cmd.exe shortcut we gave you to your working directory, where your assembly language source files are located. When you double-click to run the shortcut, it will open a Command window in the current folder.
In addition to assembling and linking, you can use the asm32.bat file to launch your program in the Visual Studio debugger. Try the following command:
asm32 /D main
If the program assembles and links with no errors, your program should load in Visual Studio. The first time you do this with a new program, the source code will not appear. All you have to do is press the F10 key to begin debugging, and your program should appear with a yellow band across the first executable line:
(Depending on how Visual Studio is configured, you might have to press F8 to do the same thing.)
From here, you can step through the program. When you get to the call to WriteString, you can even trace into its code by pressing the F11 key (trace to). When you finish, close Visual Studio.
From this time on, when you load the same program in the Visual Studio debugger, your source code will appear right away.
Occasionally, you may want to assemble programs but not link them. This happens, for example, when you are creating a multimodule project and you want to assemble each asm file into an obj file separately before linking them into the final exe program. Or, you might be assembling a module to be inserted into a link library (like Irvine32.lib).
To assemble a source file only, inser the /C option before the name of the file being assembled:
asm32 /C main
You should see the following output:
Assembling: main.asm
The file main.obj was produced. ..................................
If you are interested in learning more about how batch file commands work, here are some reference links we found:
Links go out of date quickly, but you can google for Windows batch files and get plenty of hits.
转自:http://blog.csdn.net/KingWolfOfSky/archive/2009/07/12/4342511.aspx
转自:http://blogold.chinaunix.net/u3/98810/showart_1963291.html,
特此感谢作者:jmyu2006.cublog.cn
------------------------------------ 正文 --------------------------------------------
说明:
- 以下结论都是基于Windows XP系统所得出的,不保证在其他系统的适用性。
- 在此讨论的是HID自定义设备,对于标准设备,譬如USB鼠标和键盘,由于操作系统对其独占,许多操作未必能正确执行。
1. 所使用的典型Windows API
CreateFile
ReadFile
WriteFile
以下函数是DDK的内容:
HidD_SetFeature
HidD_GetFeature
HidD_SetOutputReport
HidD_GetInputReport
其中,CreateFile用于打开设备;ReadFile、HidD_GetFeature、HidD_GetInputReport用于设备到主机方向的数据通信;WriteFile、HidD_SetFeature、HidD_SetOutputReport用于主机到设备方向的数据通信。鉴于实际应用,后文主要讨论CreateFile,WriteFile,ReadFile,HidD_SetFeature四个函数,明白了这四个函数,其它的可以类推之。
2. 几个常见错误
当使用以上API时,如果操作失败,调用GetLastError()会得到以下常见错误:
6: 句柄无效
23: 数据错误(循环冗余码检查)
87: 参数错误
1784: 用户提供的buffer无效
后文将会详细说明这些错误情况。
3. 主机端设备枚举程序流程
4. 函数使用说明
CreateFile(devDetail->DevicePath, //设备路径
GENERIC_READ | GENERIC_WRITE, //访问方式
FILE_SHARE_READ | FILE_SHARE_WRITE, //共享模式
NULL,
OPEN_EXISTING, //文件不存在时,返回失败
FILE_FLAG_OVERLAPPED, //以重叠(异步)模式打开
NULL);
在这里,CreateFile用于打开HID设备,其中设备路径通过函数SetupDiGetInterfaceDeviceDetail取得。CreateFile有以下几点需要注意:
- 访问方式: 如果是系统独占设备,例如鼠标、键盘等等,应将此参数设置为0,否则后续函数操作将失败(譬如HidD_GetAttributes);也就是说,不能对独占设备进行除了查询以外的任何操作,所以能够使用的函数也是很有限的,下文的一些函数并不一定适合这些设备。在此顺便列出MSDN上关于此参数的说明:
If this parameter is zero, the application can query file and device attributes without accessing the device. This is useful if an application wants to determine the size of a floppy disk drive and the formats it supports without requiring a floppy in the drive. It can also be used to test for the file's or directory's existence without opening it for read or write access。
- 重叠(异步)模式:此参数并不会在此处表现出明显的意义,它主要是对后续的WriteFile,ReadFile有影响。如果这里设置为重叠(异步)模式,那么在使用WriteFile,ReadFile时也应该使用重叠(异步)模式,反之亦然。这首先要求WriteFile,ReadFile的最后一个参数不能为空(NULL)。否则,便会返回87(参数错误)错误号。当然,87号错误并不代表就是此参数不正确,更多的信息将在具体讲述这两个函数时指出。此参数为0时,代表同步模式,即WriteFile,ReadFile操作会在数据处理完成之后才返回,否则阻塞在函数内部。
ReadFile(hDev, //设备句柄,即CreateFile的返回值
recvBuffer, //用于接收数据的buffer
IN_REPORT_LEN, //要读取数据的长度
&recvBytes, //实际收到的数据的字节数
&ol); //异步模式
在这里,ReadFile用于读取HID设备通过中断IN传输发来的输入报告。有以下几点要注意:
1、ReadFile的调用不会引起设备的任何反应,即HID设备与主机之间的中断IN传输不与ReadFile打交道。实际上主机会在最大间隔时间(由设备的端点描述符来指定)内轮询设备,发出中断IN传输的请求。“读取”即意味着从某个buffer里面取回数据,实际上这个buffer就是HID设备驱动中的buffer。这个buffer的大小可以通过HidD_SetNumInputBuffers来改变。在XP上缺省值是32(个报告)。
2、读取的数据对象是输入报告,也即通过中断输入管道传入的数据。所以,如果设备不支持中断IN传输,那么是无法使用此函数来得到预期结果的。实际上这种情况不可能在HID中出现,因为协议指明了至少要有一个中断IN端点。
3、IN_REPORT_LEN代表要读取的数据的长度(实际的数据正文+一个byte的报告ID),这里是一个常数,主要是因为设备固件的信息我是完全知道的,当然知道要读取多少数据(也就是报告的长度);不过也可以通过另外的函数(HidD_GetPreparsedData)来事先取得报告的长度,这里不做详细讨论。因为很难想象在不了解固件信息的情况下来做自定义设备的HID通信,在实际应用中一般来说就是固件与PC程序匹配着来开发。此参数如果设置过大,不会有实质性的错误,在recvBytes参数中会输出实际读到的长度;如果设置过小,即小于报告的长度,会返回1784号错误(用户提供的buffer无效)。
4、关于异步模式。前面已经提过,此参数的设置必须与CreateFile时的设置相对应,否则会返回87号错误(参数错误)。如果不需要异步模式,此参数需置为NULL。在这种情况下,ReadFile会一直等待直到数据读取成功,所以会阻塞住程序的当前过程。
WriteFile(hDev, //设备句柄,即CreateFile的返回值
reportBuf, //存有待发送数据的buffer
OUT_REPORT_LEN, //待发送数据的长度
&sendBytes, //实际收到的数据的字节数
&ol); //异步模式
在这里,WriteFile用于传输一个输出报告给HID设备。有以下几点要注意:
1、 与ReadFile不同,WriteFile函数被调用后,虽然也是经过驱动程序,但是最终会反映到设备中。也就是说,调用WriteFile后,设备会接收到输出报告的请求。如果设备使用了中断OUT传输,则WriteFile会通过中断OUT管道来进行传输;否则会使用SetReport请求通过控制管道来传输。
2、 OUT_REPORT_LEN代表要写入的数据长度(实际的数据正文+一个byte的报告ID)。如果大于实际报告的长度,则使用实际报告长度;如果小于实际报告长度,会返回1784号错误(用户提供的buffer无效)。
3、 reportBuf[0]必须存有待发送报告的ID,并且此报告ID指示的必须是输出报告,否则会返回87号错误(参数错误)。这种情况可能容易被程序员忽略,结果不知错误号所反映的是什么,网上也经常有类似疑问的帖子。顺便指出,输入报告、输入报告、特征报告这些报告类型,是反映在HID设备的报告描述符中。后文将做举例讨论。
4、 关于异步模式。前面已经提过,此参数的设置必须与CreateFile时的设置相对应,否则会返回87号错误(参数错误)。如果不需要异步模式,此参数需置为NULL。在这种情况下,WriteFile会一直等待直到数据读取成功,所以会阻塞住程序的当前过程。
HidD_SetFeature(hDev, //设备句柄,即CreateFile的返回值
reportBuf, //存有待发送数据的buffer
FEATURE_REPORT_LEN); //buffer的长度
HidD_SetOutputReport(hDev, //设备句柄,即CreateFile的返回值
reportBuf, //存有待发送数据的buffer
OUT_REPORT_LEN); //buffer的长度
HidD_SetFeature发送一个特征报告给设备,HidD_ SetOutputReport发送一个输出报告给设备。注意以下几点:
1、 跟WriteFile类似,必须在reportBuf[0]中指明要发送的报告的ID,并且和各自适合的类型相对应。也就是说,HidD_SetFeature只能发送特征报告,因此报告ID必须是特征报告的ID;HidD_SetOutputReport只能发送输出报告,因此报告ID只能是输出报告的ID。
2、 这两个函数最常返回的错误代码是23(数据错误)。包括但不仅限于以下情况:
- 报告ID与固件描述的不符。
- 传入的buffer长度少于固件描述的报告的长度。
据有关资料反映(非官方文档),只要是驱动程序对请求无反应,都会产生此错误。
5. 常见错误汇总
- HID ReadFile
- Error Code 6 (handle is invalid)
传入的句柄无效
- Error Code 87 (参数错误)
很可能是createfile时声明了异步方式,但是读取时按同步读取。
- Error Code 1784 (用户提供的buffer无效):
传参时传入的“读取buffer长度”与实际的报告长度不符。
- HID WriteFile
- Error Code 6 (handle is invalid)
传入的句柄无效
- Error Code 87(参数错误)
- CreateFile时声明的同步/异步方式与实际调用WriteFile时传入的不同。
- 报告ID与固件中定义的不一致(buffer的首字节是报告ID)
- Error Code 1784 (用户提供的buffer无效)
传参时传入的“写入buffer长度”与实际的报告长度不符。
- HidD_SetFeature
- HidD_SetOutputReport
- Error Code 1 (incorrect function)
不支持此函数,很可能是设备的报告描述符中未定义这样的报告类型(输入、输出、特征)
- Error Code 6 (handle is invalid)
传入的句柄无效
- Error Code 23(数据错误(循环冗余码检查))
- 报告ID与固件中定义的不相符(buffer的首字节是报告ID)
- 传入的buffer长度少于固件定义的报告长度(报告正文+1byte, 1byte为报告ID)
- 据相关资料反映(非官方文档),只要是驱动程序不接受此请求(对请求无反应),都会产生此错误
6. 报告描述符及数据通信程序示例
报告描述符(由于是汇编代码,所以不必留意其语法,仅需注意表中的每个数据都占1个字节):
_ReportDescriptor: //报告描述符
.dw 0x06, 0x00, 0xff //用法页
.dw 0x09, 0x01 //用法(供应商用法1)
.dw 0xa1, 0x01 //集合开始
.dw 0x85, 0x01 //报告ID(1)
.dw 0x09, 0x01 //用法(供应商用法1)
.dw 0x15, 0x00 //逻辑最小值(0)
.dw 0x26, 0xff, 0x0 //逻辑最大值(255)
.dw 0x75, 0x08 //报告大小(8)
.dw 0x95, 0x07 //报告计数(7)
.dw 0x81, 0x06 //输入(数据,变量,相对值)
.dw 0x09, 0x01 //用法(供应商用法1)
.dw 0x85, 0x03 //报告ID(3)
.dw 0xb1, 0x06 //特征(数据,变量,相对值)
.dw 0x09, 0x01 //用法(供应商用法1)
.dw 0x85, 0x02 //报告ID(2)
.dw 0xb1, 0x06 //特征(数据,变量,相对值)
.dw 0x09, 0x01 //用法(供应商用法1)
.dw 0x85, 0x04 //报告ID(4)
.dw 0x91, 0x06 //输出(数据,变量,相对值)
.dw 0xc0 //结合结束
_ReportDescriptor_End:
这个报告描述符,定义了4个不同的报告:输入报告1,特征报告2,特征报告3,输出报告4(数字代表其报告ID)。为了简化,每个报告都是7个字节(加上报告ID就是8个字节)。下面用一个简单的示例来描述PC端与USB HID设备进行通信的一般方法。
#define USB_VID 0xFC0 #define USB_PID 0x420 HANDLE OpenMyHIDDevice(int overlapped); void HIDSampleFunc() { HANDLE hDev; BYTE recvDataBuf[8]; BYTE reportBuf[8]; DWORD bytes; hDev = OpenMyHIDDevice(0); //打开设备,不使用重叠(异步)方式; if (hDev == INVALID_HANDLE_VALUE) return; reportBuf[0] = 4; //输出报告的报告ID是4 memset(reportBuf, 0, 8); reportBuf[1] = 1; if (!WriteFile(hDev, reportBuf, 8, &bytes, NULL)) //写入数据到设备 return; ReadFile(hDev, recvDatatBuf, 8, &bytes, NULL); //读取设备发给主机的数据 } HANDLE OpenMyHIDDevice(int overlapped) { HANDLE hidHandle; GUID hidGuid; HidD_GetHidGuid(&hidGuid); HDEVINFO hDevInfo = SetupDiGetClassDevs( &hidGuid, NULL, NULL, (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)); if (hDevInfo == INVALID_HANDLE_VALUE) { return INVALID_HANDLE_VALUE; } SP_DEVICE_INTERFACE_DATA devInfoData; devInfoData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA); int deviceNo = 0; SetLastError(NO_ERROR); while (GetLastError() != ERROR_NO_MORE_ITEMS) { if (SetupDiEnumInterfaceDevice (hDevInfo, 0, &hidGuid, deviceNo, &devInfoData)) { ULONG requiredLength = 0; SetupDiGetInterfaceDeviceDetail(hDevInfo, &devInfoData, NULL, 0, &requiredLength, NULL); PSP_INTERFACE_DEVICE_DETAIL_DATA devDetail = (SP_INTERFACE_DEVICE_DETAIL_DATA*) malloc (requiredLength); devDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); if(!SetupDiGetInterfaceDeviceDetail(hDevInfo, &devInfoData, devDetail, requiredLength, NULL, NULL)) { free(devDetail); SetupDiDestroyDeviceInfoList(hDevInfo); return INVALID_HANDLE_VALUE; } if (overlapped) { hidHandle = CreateFile(devDetail->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); } else { hidHandle = CreateFile(devDetail->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); } free(devDetail); if (hidHandle==INVALID_HANDLE_VALUE) { SetupDiDestroyDeviceInfoList(hDevInfo); free(devDetail); return INVALID_HANDLE_VALUE; } _HIDD_ATTRIBUTES hidAttributes; if(!HidD_GetAttributes(hidHandle, &hidAttributes)) { CloseHandle(hidHandle); SetupDiDestroyDeviceInfoList(hDevInfo); return INVALID_HANDLE_VALUE; } if (USB_VID == hidAttributes.VendorID && USB_PID == hidAttributes.ProductID) { break; } else { CloseHandle(hidHandle); ++deviceNo; } } } SetupDiDestroyDeviceInfoList(hDevInfo); return hidHandle; }
一个把自己的生命和代码和为一体的人,看了报道后自己又找了一些相关消息跟大家分享一下。:
ALS是肌肉萎縮性側索硬化症的略稱。又稱漸凍人症。
文中所提到的bug,2002年就报出来了,9年没有被解决掉,最后是这样的一个人解决的。这个bug是:https://bugzilla.gnome.org/show_bug.cgi?id=78514
再贴一张这个程序员的最后照片。一位ALS患者在生命走到尽头前用脚贡献了最后一个代码补丁
Adrian Hands就是一位ALS病人,他在已经失去了运动能力、双手残废无法使用键盘的情况下,用脚在一个莫尔斯码键盘模拟器上编写代码,为GNOME提交了生 命中最后一个patch。
以下是他的儿子Ian Hands在GNOME的邮件列表里的一段话
I would like to extend my thanks to the gnome team/community for a great last moment with my dad. Adrian H
在Visual DSP++的安装目录下“..\Analog Devices\VisualDSP 5.0\System\ArchDef”包含了针对各种类型处理器的的调试加载信息设置文件(.xml),文件主要完成在利用仿真器加载调试代码前,初始化处理器相关寄存器和准备好程序运行的环境等工作,为调试程序的运行准备好必要的环境。
比如,以一个“ADSP-BF561-proc.xml”文件为例,文件的最后几行就是初始化DSP中SDRAM控制器的寄存器的代码(均以“EBIU_”字样开头,其含义详见处理器参考手册),便于在调试程序运行前,按照SDRAM特性初始化SDRAM控制器的控制方式。
那么,第一个问题是:Visual DSP++默认的文件中的SDRAM控制器的设置是按照哪种类型的SDRAM进行的设置呢?
答案是:按照ADI自己的参考板上的SDARM性能进行设置的,所以如果我们要设计自己的电路板采用不同的SDRAM的话,就必须修改对应处理器文件中的寄存器设置内容。
第二个问题是:调试的时候我们使用这个文件初始化SDRAM或其他初始化工作,那么,当程序下载到板载Flash的时候,谁来初始化SDRAM和其他资源的呢?
答案是:ADI为每一种处理器都提供了一个“ADSP-xxx-ROM-Vxx.dxe”的文件(在对应的处理器类型目录下的LDR子目录中),在你生成ldr文件准备烧写的时候,编译器就会提示你要加载这个文件的。他干的就是类似前面提到的“ADSP-BF561-proc.xml”文件的活,只不过“ADSP-BF561-proc.xml”文件还要多干一样活是将易失性存储器的空间初始化,以模拟处理器刚上电的状态。要不然调试时不掉电,反复加载程序后可能程序会乱掉,以至于无法正确模拟处理器刚上电后的运行状态了。 既然这个也是ADI随着Visual DSP++预装好的(自然也是针对ADI的参考板设置的),那么也必然会遇到前面的问题,如果使用我自己的SDRAM怎么办的问题,还好ADI提供了源代码和工程(也在LDR子目录下,自己找找看吧~),代码仅仅是很简单的一个汇编文件,里面就设置了几个寄存器,改一下重编译即可。
总结:其实ADI的Visual DSP++的安装目录下有很多“资源”,只要用心从这些资源里是可以学到很多东西的!
转自:http://www.vckbase.com/document/viewdoc/?id=443
作者:武汉市中国地质大学 印涛,秦剑
人们在使用电脑时,有时由于异常操作,有时由于病毒侵袭,会导致某个分区消失或硬盘无法启动。究其原因,就是硬盘分区表受损。硬盘分区表可以说是支持硬盘正常工作的骨架.操作系统正是通过它把硬盘划分为若干个分区,然后再在每个分区里面创建文件系统,写入数据文件.本文主要讲述的是分区表的位置,结构以及各个分区表是如何链接起来的.当掌握了这些知识后,即使分区表受到破坏,一样也可以根据残存的数据手工修复分区表,从而修复分区。
一.分区表的位置及识别标志
分区表一般位于硬盘某柱面的0磁头 1扇区.而第1个分区表(也即主分区表)总是位于
(0柱面,1磁头,1扇区),剩余的分区表位置可以由主分区表依次推导出来.分区表有64个字节,占据其所在扇区的[441-509]字节.要判定是不是分区表,就看其后紧邻的两个字节(也即[510-511])是不是 "55AA",若是,则为分区表.
二.分区表的结构
分区表由4项组成,每项16个字节.共4×16 = 64个字节.每项描述一个分区的基本信息.每个字节的含义如下:
分区表项含义
字节 | 含义 |
0 | Activeflag.活动标志.若为0x80H,则表示该分区为活动分区.若为0x00H,则表示该分区为非活动分区 |
1,2,3 | 该分区的起始磁头号,扇区号,柱面号磁头号 -- 1字节, 扇区号 -- 2字节低6位,柱面号 -- 2字节高2位 + 3字节 |
4 | 分区文件系统标志: 分区未用: 0x00H. 扩展分区: 0x05H, 0x0FH. FAT16分区: 0x06H. FAT32分区: 0x0BH, 0x1BH, 0x0CH, 0x1CH. NTFS分区: 0x07H. |
5,6,7 | 该分区的结束磁头号,扇区号,柱面号,含义同上 |
8,9,10,11 | 逻辑起始扇区号。表示分区起点之前已用了的扇区数 |
12,13,14,15 | 该分区所占用的扇区数. |
分区表项有几个字节比较重要,下面分别阐述之:
1、(1,2,3)字节 磁头号由(1)字节8位表示,其范围为(0 -- 28 - 1),也即(0 磁头-- 254磁头)。 扇区号由(2)字节低6位表示,其范围为(0 -- 26 - 1),由于扇区号从1开始,所以其范围是(1扇区-- 63扇区)。 柱面号由(2)字节高2位 + (3)字节,共10位表示,其范围为(0 --2 10 - 1),也即(0 柱面-- 1023柱面)。 当柱面号超过1023时,这10位依然表示成1023,需要注意。 (5,6,7)字节含义同上。
2、(8, 9, 10, 11)字节 如果是主分区表,则这4 个字节表示该分区起始逻辑扇区号与逻辑0扇区(0柱面,0磁头,1扇区)之差。如果非主分区表, 则这4 个字节要么表示该分区起始逻辑扇区号与扩展分区起始逻辑扇区号之差,要么为63。详细情况在后面有所阐述。注意:
1、扇区上的字节是按左边低位,右边高位的顺序排列的。所以在取值时,需要把字节再反一下,让高位字节在左边,低位字节在右边, 这一点在读取逻辑起始扇区号和分区大小时需要注意。举个例子:第一项的逻辑起始扇区为(3F 00 00 00),转换为十进制前要先反一下字 节顺序,为(00 00 00 3F)然后在转换为十进制,即63 .同理分区大小为(3F 04 7D 00),先反为(00 7D 04 3F)再转换为十进制, 即8193087。
2、逻辑扇区号与(柱面,磁头,扇区)的相互转换: 令L = 逻辑扇区号,C = 柱面号,H = 磁头号,S = 扇区号。 每道扇区数 = 63 每柱面磁头数 = 255 每柱面扇区数 = 每道扇区数* 每柱面磁头数 = 63 × 255 = 16065 柱面号下标从0开始。磁头号[0 -- 254],扇区号[1 -- 63]。 逻辑扇区号下标也从0开始。 (柱面,磁头,扇区)转换成逻辑扇区号的公式为: L = C×16065 + H ×63 + S - 1 ; 比如(1柱面,1磁头,1扇区),其逻辑扇区号为: L = 1×16065 + 1×63 + 1 - 1 = 16128 逻辑扇区号转换成(柱面,磁头,扇区) 公式为: C = L / 16065 H = (L % 16065) / 63 S = (L % 16065) % 63 + 1 比如逻辑扇区号 16127: C = 16127 / 16065 = 1 H = (16127 % 16065) / 63 = 0 S = (16127 % 16065) % 63 + 1 = 63 即(1柱面,0磁头,63扇区)
3、分区表上有四项,每一项表示一个分区,所以一个分区表最多只能表示4个分区。主分 区表上的4项用来表示主分区和扩展分区的信息。因为扩展分区最多只能有一个,所以硬盘 最多可以有四个主分区或者三个主分区,一个扩展分区。余下的分区表是表示逻辑分区的。 这里有必要阐述一点:逻辑区都是位于扩展分区里面的,并且逻辑分区的个数没有限制。
4、分区表所在扇区通常在(0磁头,1扇区),而该分区的开始扇区通常位于(1磁头,1扇区),中间隔了63 个隐藏扇区。三.分区表链的查找
[80 01 01 00 0B FE 7F FD 3F 00 00 00 3F 04 7D 00 ] [00 00 41 FE 0F FE FF FF 7E 04 7D 00 1F 2C B4 00 ] [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ] [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]
第一项: (80)(01 01 00)(0B)(FE 7F FD )(3F 00 00 00 )(3F 04 7D 00) 描述的是C盘的情况。 1.(80):表示C盘为活动分区。即系统会从C盘启动。 2.(01 01 00):表示C盘的起始扇区为(0柱面,0磁头,1扇区)。 3.(0B):表示C盘的文件系统为FAT32。 4.(FE 7F FD): (FE) 16 = (254) 10 (7F) 16 = (0111 1111) 2 (FD) 16 = (1111 1101) 2 磁头号:(254) 10; 扇区号:(11 1111) 2 = (63) 10. 柱面号:(01 1111 1101) 2 = (509) 10 故C盘结束扇区为(509柱面,254磁头,63扇区)。 5.(3F 00 00 00): 反向,(00 00 00 3F) 16 = (63) 10,为C盘起始逻辑扇区号与逻辑0扇区号之差。表示C盘前面已有63个扇区,这63个扇区为系统隐藏扇区。 6. (3F 04 7D 00): 反向,(00 7D 04 3F) 16 = (8193087) 10。表明C盘有8193087个扇区。即(0柱面,1磁头,1扇区)至(509柱面,254磁头,63扇区) 共有8193087个扇区。
第二项: (00)(00 41 FE)(0F)(FE FF FF)(7E 04 7D 00)(1F 2C B4 00) 描述的是扩展分区的情况。 1. (00): 表示该分区不是活动分区。 2. (00 41 FE): (00) 16 = (0) 10 (41) 16 = (0100 0001) 2 (FE) 16 = (1111 1110) 2 磁头号:(0) 10; 扇区号:(00 0001) 2 = (1) 10. 柱面号:(01 1111 1110) 2 = (510) 10 所以扩展分区的起始扇区为(510柱面,0磁头,1扇区)。 3. (0F): 表示该分区为扩展分区。 4. (FE FF FF): (FE) 16 = (254) 10 (FF) 16 = (1111 1111) 2 (FF) 16 = (1111 1111) 2; 磁头号:(254) 10; 扇区号:(11 1111) 2 = (63) 10. 柱面号:(11 1111 1111) 2 = (1023) 10 但这是不准确的,因为当柱面号的真实值超过1023时,表示柱面号的10位也依然是1023。 5. (7E 04 7D 00): 反向,(00 7D 04 7E) 16 = (8193150) 10. 表示扩展分区的起始扇区号为8193150,即(510 柱面,0磁头,1扇区)。这是真实准确的, 我一般都用这一项来定位分区起点。 6. (1F 2C B4 00): 反向, (00 B4 2C 1F) 16 = (11807775) 10. 表示扩展分区共有11807775个扇区。通过上面得到的起点和分区的大小, 可以推导出扩展分区的结束位置:8193150 + 11807775 = 20000925号扇区,即(1244 柱面,254磁头,63扇区)。二.查找D盘分区表 根据上面的信息,第二个分区表,也即D盘分区表在(510柱面,0磁头,1扇区)处。读取该扇区,得到分区表如下:
[00 01 41 FE 0B FE FF 7B 3F 00 00 00 BF A3 5D 00 ] [00 00 C1 7C 05 FE FF FF FE A3 5D 00 21 88 56 00 ] [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ] [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]
第一项: (00)(01 41 FE)(0B)(FE FF 7B)(3F 00 00 00 )(BF A3 5D 00) 描述的是D盘的情况。 1.(00):表示D盘不是活动分区。 2.(01 41 FE): (01) 16 = (1) 10 (41) 16 = (0100 0001) 2 (FE) 16 = (1111 1110) 2. 磁头号:(1) 10; 扇区号:(00 0001) 2 = (1) 10. 柱面号:(01 1111 1110) 2 = (510) 10; 故D盘开始扇区为(510柱面,1磁头,1扇区)。 3.(0B):表示D盘的文件系统为FAT32。 4.(FE FF 7B): (FE) 16 = (254) 10 。 (FF) 16 = (1111 1111) 2 (7B) 16 = (0111 1011) 2. 磁头号:(254) 10; 扇区号:(11 1111) 2 = (63) 10. 柱面号:(11 0111 1011) 2 = (891) 10 故D盘结束扇区为(891柱面,254磁头,63扇区)。 5.(3F 00 00 00): 反向,(00 00 00 3F)16 = (63)10,为D盘起始逻辑扇区号(510柱面,1磁头,1扇区)与扩展分区起始逻辑扇区号 (510柱面,0磁头,1扇区)之差。表示D盘前面已有63个扇区,这63个扇区为系统隐藏扇区。 6. (BF A3 5D 00): 反向,(00 5D A3 BF) 16 = (6136767) 10。表明D盘有6136767个扇区。 通过上面得到的起点和分区的大小,可以推导出D盘的结束位置:8193150 + 63 + 6136767 = 14329980号扇区。 即(891柱面,254磁头,63扇区)。与上面的正好吻合。
第二项: (00)(00 C1 7C)(05)(FE FF FF)(FE A3 5D 00)(21 88 56 00) 描述的是E盘的情况。 1. (00): 表示E盘不是活动分区。 2. (00 C1 7C): (00) 16 = (0) 10 (C1) 16 = (1100 0001) 2 (7C) 16 = (0111 1100) 2 磁头号:(0) 10 扇区号:(00 0001) 2 = (1) 10 柱面号:(11 0111 1100) 2 = (892) 10 所以E盘的起始扇区为(892柱面,0磁头,1扇区)。 3. (05): 表示E盘的在扩展分区里面。 4.(FE FF FF): (FE) 16 = (254) 10 (FF) 16 = (1111 1111) 2 (FF) 16 = (1111 1111) 2 磁头号:(254) 10 扇区号:(11 1111) 2 = (63) 10 柱面号:(11 1111 1111) 2 = (1023) 10 但这是不准确的,原因同上。 5.(FE A3 5D 00): 反向,(00 5D A3 FE) 16 = (6136830) 10. 这一项非常重要,它定位了E盘分区表所在扇区。其值为E盘分区表所在扇区号 与扩展分区起始扇区号之差。所以,E盘分区表所在扇区号为: 8193150 + 6136830 = 14329980。即(892柱面,0磁头,1扇区)。 6.(21 88 56 00): 反向,(00 56 88 21) 16 = (5670945) 10.表示E盘共有11807775个扇区。通过上面得到的起点和分区的大小,可以推导出E 盘的结束位置:14329980 + 5670945 = 20000925号扇区,即(1244 柱面,254磁头,63扇区)。三.查找E盘分区表 根据上面的信息,第三个分区表,也即E盘分区表在(892柱面,0磁头,1扇区)处。读取该扇区,得到分区表如下:
[00 01 C1 7C 0B FE FF FF 3F 00 00 00 E2 87 56 00] [ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ] [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ] [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ] 该分区表第二项全为0,说明没有下一个分区表了。该分区表就是分区表链的最后一个节点。
第一项: (00)(01 C1 7C)(0B)(FE FF FF)(3F 00 00 00 )(E2 87 56 00) 该项与D盘分区表的第二项描述的都是E盘的情况,但它们在某些细节上又有所区别。 1.(00):表示E盘不是活动分区。 2.(01 C1 7C): (01) 16 = (1) 10 (C1) 16 = (1100 0001) 2 (7C) 16 = (0111 1100) 2. 磁头号:(1) 10 扇区号:(00 0001) 2 = (1) 10 柱面号:(11 0111 1100) 2 = (892) 10 故E盘起始扇区为(892柱面,1磁头,1扇区)。 3.(0B):表示E盘的文件系统为FAT32。 4.(FE FF FF): (FE) 16 = (254) 10 。 (FF) 16 = (1111 1111) 2 (FF) 16 = (1111 1111) 2. 磁头号:(254) 10; 扇区号:(11 1111) 2 = (63) 10. 柱面号:(11 1111 1111) 2 = (1023) 10 但这是不准确的,原因同上。 5.(3F 00 00 00): 反向,(00 00 00 3F) 16 = (63) 10.这一项与D盘分区表相应项有所不同.为E盘起始逻辑 扇区号(892柱面,1磁头,1扇区)与(892柱面,0磁头,1扇区)之差。表示E盘前面已有63个扇区, 这63个扇区为系统隐藏扇区。 操作系统无法对这些扇区进行读写,所以可以把自己的秘密信息写在这里. 6. (E2 87 56 00): 反向,(00 56 87 E2) 16 = (5670882) 10。表明E盘有5670882个扇区。而D盘分区表相应项为5670945. 5670945 - 5670882 = 63. 正好等于63个隐藏扇区.这是因为D盘分区表描述的是(892柱面,0磁头,1扇区) 到 (1244 柱面,254磁头,63扇区) 之间的扇区数。 而E盘分区表描述的是(892柱面, 1磁头,1扇区) 到 (1244 柱面,254磁头,63扇区) 之间的扇区数。四.结束语
Bus Hound 5.0 默认的显示buff长度32字节,当主机获取usb设备的描述符长度大于32字节时,Bus Hound就不显示。
这样在调试的时候就会令人迷惑。其实只要修改一下设置即可。
在setting界面下,修改Limits标签项的“max Phase”的值为更大的值即可。如下图修改为64:
当buffer设置的比较小导致一部分信息没有显示的时候,其实可以通过分析USB协议本身的长度信息相关数据就可以推断,如果推断出的确有信息没有被显示,就可以修改buffer长度在获取一次,即可。
如下例。
修改Buffer前,获取的某设备信息:
通过第七行第三个字节根据协议推断本段应该有0x27(39)个字节信息,实际仅仅显示了32字节信息。
修改Buffer后,获取的某设备信息:
RT-Thread : http://www.rt-thread.org/phpbbforum
http://code.google.com/p/rt-thread/
ucos
2、开发模拟器
qemu: 处理器模拟器 www.qemu.org
ucGUI:基于VC模拟器
skyeye:一款不错的linux模拟器
官网:http://www.swig.org/ 该工具很活跃,从2000年开始持续更新中…
中文版主页面:http://www.swig.org/translations/chinese/index.html
功能概述:
SWIG是个帮助使用C或者C++编写的软件能与其它各种高级编程语言进行嵌入联接的开发工具。SWIG能应用于各种不同类型的语言包括常用脚本编译语言例如Perl, PHP, Python, Tcl, Ruby and PHP。支持语言列表中也包括非脚本编译语言,例如C#, Common Lisp (CLISP, Allegro CL, CFFI, UFFI), Java, Modula-3, OCAML以及R,甚至是编译器或者汇编的计划应用(Guile, MzScheme, Chicken)。SWIG普遍应用于创建高级语言解析或汇编程序环境,用户接口,作为一种用来测试C/C++或进行原型设计的工具。SWIG还能够导出XML或Lisp s-expressions格式的解析树。SWIG可以被自由使用,发布,修改用于商业或非商业中。
已经支持一下这些语言: