高手请问:用vc控制8253定时,谁写过? 真正的问题!turbo c程序移植到windows98,其中用到中断,不知怎样写。是只能用DDK吗?用vtoolsD行吗?哪位有现成的例程,可否发一份 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 vtoosd能用的,其它一些驱动程序工具也应该都能用的,如果没用到中断的话,甚至不用编驱动程序也能通过访问端口来访问8253的寄存器的,剩下就是查资料了,找工具了 其实在turbo c下就几句话,先getvect,再setvect(),最后再把中断置回来,可是在vxd中怎么写呢? TC用中断肯定也是为了定时,Win32在user mode就有timer可以用,非得直接去操作8253? win32的timer只是1ms,我要求几百微秒就中断一次。 贴上来吧,免得你找了:// File name : SetClock.cpp// Function1 : SetClock9x(int)// Function2 : SetClockNT(int)// Chu Rui 2001.3.1#include "stdafx.h"#include "ntport.h"#define FREE_INT_NO 5void Ring0(){ //ÔÚWindows9xϽøÈëring0ºó½øÐеIJÙ×÷ __asm { cli mov al,34h out 43h,al //дÈë8253¿ØÖƼĴæÆ÷£¬ÉèÖÃд0ºÅ¶¨Ê±Æ÷ mov ax,bx out 40h,al //д¶¨Ê±ÖµµÍλ mov al,ah out 40h,al //д¶¨Ê±Öµ¸ßλ sti iretd; }}void SetClockNT(int freq){ //NTϵIJÙ×÷ //ÕâÀïʹÓÃÁËNT Port¿â Outport(0x43,0x34); //дÈë8253¿ØÖƼĴæÆ÷£¬ÉèÖÃд0ºÅ¶¨Ê±Æ÷ Outport(0x40,freq&0xff); //д¶¨Ê±ÖµµÍλ Outport(0x40,(freq>>8)&0xff); //д¶¨Ê±Öµ¸ßλ}void SetClock9x(int freq){ union Function_Pointer { void (*pointer)(); char bytes[sizeof(void *)]; }OldIntAddress,NewIntAddress; int IDTAddress; //IDT±í»ùµØÖ· int IDTItemAddress; //ÒªÐ޸ĵÄÖжÏÃÅËùÔÚµØÖ· char *Pointer; //ÒªÐ޸ĵÄÖжÏÃÅËùÔÚµØÖ·£¬Ö¸ÕëÐÎʽ __asm { push eax sidt [esp-2] pop eax mov IDTAddress,eax //µÃµ½IDT±í»ùµØÖ· } IDTItemAddress=FREE_INT_NO*8+IDTAddress; Pointer=(char *)IDTItemAddress; NewIntAddress.pointer=Ring0; OldIntAddress.bytes[0]=Pointer[0]; OldIntAddress.bytes[1]=Pointer[1]; OldIntAddress.bytes[2]=Pointer[6]; OldIntAddress.bytes[3]=Pointer[7]; //±£´æ¾ÉµÄÖжÏÃÅ Pointer[0]=NewIntAddress.bytes[0]; Pointer[1]=NewIntAddress.bytes[1]; Pointer[6]=NewIntAddress.bytes[2]; Pointer[7]=NewIntAddress.bytes[3]; //ÉèÖÃеÄÖжÏÃÅ __asm { mov ebx,freq int FREE_INT_NO //²úÉúÖжϣ¬½øÈëring0 } Pointer[0]=OldIntAddress.bytes[0]; Pointer[1]=OldIntAddress.bytes[1]; Pointer[6]=OldIntAddress.bytes[2]; Pointer[7]=OldIntAddress.bytes[3]; //»Ö¸´¾ÉµÄÖжÏÃÅ} 晕,注释乱码了,改一下内码再贴上来:// File name : SetClock.cpp// Function1 : SetClock9x(int)// Function2 : SetClockNT(int)// Chu Rui 2001.3.1#include "stdafx.h"#include "ntport.h"#define FREE_INT_NO 5void Ring0(){ //在Windows9x下进入ring0后进行的操作 __asm { cli mov al,34h out 43h,al //写入8253控制寄存器,设置写0号定时器 mov ax,bx out 40h,al //写定时值低位 mov al,ah out 40h,al //写定时值高位 sti iretd; }}void SetClockNT(int freq){ //NT下的操作 //这里使用了NT Port库 Outport(0x43,0x34); //写入8253控制寄存器,设置写0号定时器 Outport(0x40,freq&0xff); //写定时值低位 Outport(0x40,(freq>>8)&0xff); //写定时值高位}void SetClock9x(int freq){ union Function_Pointer { void (*pointer)(); char bytes[sizeof(void *)]; }OldIntAddress,NewIntAddress; int IDTAddress; //IDT表基地址 int IDTItemAddress; //要修改的中断门所在地址 char *Pointer; //要修改的中断门所在地址,指针形式 __asm { push eax sidt [esp-2] pop eax mov IDTAddress,eax //得到IDT表基地址 } IDTItemAddress=FREE_INT_NO*8+IDTAddress; Pointer=(char *)IDTItemAddress; NewIntAddress.pointer=Ring0; OldIntAddress.bytes[0]=Pointer[0]; OldIntAddress.bytes[1]=Pointer[1]; OldIntAddress.bytes[2]=Pointer[6]; OldIntAddress.bytes[3]=Pointer[7]; //保存旧的中断门 Pointer[0]=NewIntAddress.bytes[0]; Pointer[1]=NewIntAddress.bytes[1]; Pointer[6]=NewIntAddress.bytes[2]; Pointer[7]=NewIntAddress.bytes[3]; //设置新的中断门 __asm { mov ebx,freq int FREE_INT_NO //产生中断,进入ring0 } Pointer[0]=OldIntAddress.bytes[0]; Pointer[1]=OldIntAddress.bytes[1]; Pointer[6]=OldIntAddress.bytes[2]; Pointer[7]=OldIntAddress.bytes[3]; //恢复旧的中断门} to “草”,你写的那三个例程是并列的吗?那些语句我会写,问题是在操作系统下,必须要切换到ring0才能进行类似的中断调用,我想用vtoolsD写,但不知如何写,你写的这些代码与实际的ring3的应用程序怎样衔接呢? 不一定要写驱动阿,9x和2000下都可以使用callgate。并且你有没有注意到我给你贴的代码使用了使用了NT Port库? to 草这样就可以在nt 下与硬件通讯了吗,电脑本身的8253 地址是在那里找到,每个都是固定的吗?汇编代码是这样嵌入的,那么又有没有ring0的问题呢? ShellExecuteEx启动外部exe被360拦截问题 帖子下面那个PICC是怎么回事?这还是技术论坛吗? 怎么会出错? 契约与防御性编程的疑问 CcomboBox一个问题 Socket编程一个问题,在线等待 关于ODBC访问access2000中m_strSort的问题 如何用VC制作数据库报表和打印它? R6030 CRT not initialized 添加声明消息处理函数为什么要加 afx_msg ,多谢 请教发送WM_CLOSE消息给IE窗口,为什么IE窗口不会关闭? 怎么设置TAB键的顺序啊???
// Function1 : SetClock9x(int)
// Function2 : SetClockNT(int)
// Chu Rui 2001.3.1#include "stdafx.h"
#include "ntport.h"#define FREE_INT_NO 5void Ring0()
{ //ÔÚWindows9xϽøÈëring0ºó½øÐеIJÙ×÷
__asm
{
cli
mov al,34h
out 43h,al //дÈë8253¿ØÖƼĴæÆ÷£¬ÉèÖÃд0ºÅ¶¨Ê±Æ÷
mov ax,bx
out 40h,al //д¶¨Ê±ÖµµÍλ
mov al,ah
out 40h,al //д¶¨Ê±Öµ¸ßλ
sti
iretd;
}
}void SetClockNT(int freq)
{ //NTϵIJÙ×÷
//ÕâÀïʹÓÃÁËNT Port¿â
Outport(0x43,0x34); //дÈë8253¿ØÖƼĴæÆ÷£¬ÉèÖÃд0ºÅ¶¨Ê±Æ÷
Outport(0x40,freq&0xff); //д¶¨Ê±ÖµµÍλ
Outport(0x40,(freq>>8)&0xff); //д¶¨Ê±Öµ¸ßλ
}void SetClock9x(int freq)
{
union Function_Pointer
{
void (*pointer)();
char bytes[sizeof(void *)];
}OldIntAddress,NewIntAddress; int IDTAddress; //IDT±í»ùµØÖ·
int IDTItemAddress; //ÒªÐ޸ĵÄÖжÏÃÅËùÔÚµØÖ·
char *Pointer; //ÒªÐ޸ĵÄÖжÏÃÅËùÔÚµØÖ·£¬Ö¸ÕëÐÎʽ __asm
{
push eax
sidt [esp-2]
pop eax
mov IDTAddress,eax //µÃµ½IDT±í»ùµØÖ·
}
IDTItemAddress=FREE_INT_NO*8+IDTAddress;
Pointer=(char *)IDTItemAddress;
NewIntAddress.pointer=Ring0;
OldIntAddress.bytes[0]=Pointer[0];
OldIntAddress.bytes[1]=Pointer[1];
OldIntAddress.bytes[2]=Pointer[6];
OldIntAddress.bytes[3]=Pointer[7]; //±£´æ¾ÉµÄÖжÏÃÅ Pointer[0]=NewIntAddress.bytes[0];
Pointer[1]=NewIntAddress.bytes[1];
Pointer[6]=NewIntAddress.bytes[2];
Pointer[7]=NewIntAddress.bytes[3]; //ÉèÖÃеÄÖжÏÃÅ
__asm
{
mov ebx,freq
int FREE_INT_NO //²úÉúÖжϣ¬½øÈëring0
} Pointer[0]=OldIntAddress.bytes[0];
Pointer[1]=OldIntAddress.bytes[1];
Pointer[6]=OldIntAddress.bytes[2];
Pointer[7]=OldIntAddress.bytes[3]; //»Ö¸´¾ÉµÄÖжÏÃÅ
}
// Function1 : SetClock9x(int)
// Function2 : SetClockNT(int)
// Chu Rui 2001.3.1#include "stdafx.h"
#include "ntport.h"#define FREE_INT_NO 5void Ring0()
{ //在Windows9x下进入ring0后进行的操作
__asm
{
cli
mov al,34h
out 43h,al //写入8253控制寄存器,设置写0号定时器
mov ax,bx
out 40h,al //写定时值低位
mov al,ah
out 40h,al //写定时值高位
sti
iretd;
}
}void SetClockNT(int freq)
{ //NT下的操作
//这里使用了NT Port库
Outport(0x43,0x34); //写入8253控制寄存器,设置写0号定时器
Outport(0x40,freq&0xff); //写定时值低位
Outport(0x40,(freq>>8)&0xff); //写定时值高位
}void SetClock9x(int freq)
{
union Function_Pointer
{
void (*pointer)();
char bytes[sizeof(void *)];
}OldIntAddress,NewIntAddress; int IDTAddress; //IDT表基地址
int IDTItemAddress; //要修改的中断门所在地址
char *Pointer; //要修改的中断门所在地址,指针形式 __asm
{
push eax
sidt [esp-2]
pop eax
mov IDTAddress,eax //得到IDT表基地址
}
IDTItemAddress=FREE_INT_NO*8+IDTAddress;
Pointer=(char *)IDTItemAddress;
NewIntAddress.pointer=Ring0;
OldIntAddress.bytes[0]=Pointer[0];
OldIntAddress.bytes[1]=Pointer[1];
OldIntAddress.bytes[2]=Pointer[6];
OldIntAddress.bytes[3]=Pointer[7]; //保存旧的中断门 Pointer[0]=NewIntAddress.bytes[0];
Pointer[1]=NewIntAddress.bytes[1];
Pointer[6]=NewIntAddress.bytes[2];
Pointer[7]=NewIntAddress.bytes[3]; //设置新的中断门
__asm
{
mov ebx,freq
int FREE_INT_NO //产生中断,进入ring0
} Pointer[0]=OldIntAddress.bytes[0];
Pointer[1]=OldIntAddress.bytes[1];
Pointer[6]=OldIntAddress.bytes[2];
Pointer[7]=OldIntAddress.bytes[3]; //恢复旧的中断门
}
并且你有没有注意到我给你贴的代码使用了使用了NT Port库?
to 草
这样就可以在nt 下与硬件通讯了吗,电脑本身的8253 地址是在那里找到,每个都是固定的吗?
汇编代码是这样嵌入的,那么又有没有ring0的问题呢?