|
pptppt
新手上路

积分 8
发帖 3
注册 2008-4-23
状态 离线
|
『楼 主』:
DOS下C的一个代码,求解,谢谢.
使用 LLM 解释/回答一下
以下是一个C写的DOS运行的代码,是一个程序的部分.是BIOS看门狗的,
请教一下具体每句的意思,如果用Debug 汇编怎么写. 谢谢了.
------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <stdlib.h>
#include <inlines/pc.h>
#include <dpmi.h>
#define INDEX_PORT 0x2e
#define DATA_PORT 0x2f
#define WDTBaseAddress 0xDF300000;
int selector[0];
__dpmi_meminfo mi[0];
void InitWDTimer()
{
mi[0].address=WDTBaseAddress; //WDT timer base address//
mi[0].size=0x10; //WDT register //
__dpmi_physical_address_mapping(&(mi[0]));
selector[0]=__dpmi_allocate_ldt_descriptors(1);
__dpmi_set_segment_base_address(selector[0],mi[0].address);
__dpmi_set_segment_limit(selector[0],mi[0].size-1);
}
void SetWDtimer(unsigned long timer)
{
_farsetsel(selector[0]);
//; perform unlock sequence for preload 1//
_farnspokeb(0x0C,0x80);
_farnspokeb(0x0C,0x86);
timer = timer * 1000; // Msec hange to Sec//
_farnspokel( 0x00, timer);
//; perform unlock sequence for preload 2//
_farnspokeb(0x0C,0x80);
_farnspokeb(0x0C,0x86);
_farnspokel(0x04, 0x01);
outportl(0x0cf8,0x8000EC00+0x68); //;enable WDT timer//
outportl(0x0cfc,0x00000002);
}
以下是翻译后的内容:
Here is a part of a code running on DOS written in C. It's about the BIOS watchdog. Please ask about the specific meaning of each sentence and how to write it in Debug assembly. Thanks.
------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <stdlib.h>
#include <inlines/pc.h>
#include <dpmi.h>
#define INDEX_PORT 0x2e
#define DATA_PORT 0x2f
#define WDTBaseAddress 0xDF300000;
int selector;
__dpmi_meminfo mi;
void InitWDTimer()
{
mi.address = WDTBaseAddress; //WDT timer base address//
mi.size = 0x10; //WDT register //
__dpmi_physical_address_mapping(&(mi));
selector = __dpmi_allocate_ldt_descriptors(1);
__dpmi_set_segment_base_address(selector, mi.address);
__dpmi_set_segment_limit(selector, mi.size - 1);
}
void SetWDtimer(unsigned long timer)
{
_farsetsel(selector);
//; perform unlock sequence for preload 1//
_farnspokeb(0x0C, 0x80);
_farnspokeb(0x0C, 0x86);
timer = timer * 1000; // Msec hange to Sec//
_farnspokel( 0x00, timer);
//; perform unlock sequence for preload 2//
_farnspokeb(0x0C, 0x80);
_farnspokeb(0x0C, 0x86);
_farnspokel(0x04, 0x01);
outportl(0x0cf8, 0x8000EC00 + 0x68); //;enable WDT timer//
outportl(0x0cfc, 0x00000002);
}
|
|
2008-4-23 15:24 |
|
|
zyl910
中级用户
  
积分 282
发帖 126
注册 2006-5-17
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
InitWDTimer函数还算简单,利用DPMI得到一个指向WDTBaseAddress的选择子。由于该地址超过实模式24位地址范围,所以用到了DPMI(DOS保护模式接口)
至于SetWDtimer函数。
第一句用_farsetsel设好段描述符后,后面的_farnspokeb、_farnspokel就是端口操作,与具体的接口命令字设计有关。
最后的outportl是用来写PCI配置。0x0cf8是PCI地址端口,0x8000EC00是设备号(分为 总线、设备、功能三级,具体位含义去查PCI规范,我不太记得了),0x68是指该设备的0x68地址的寄存器(自定义寄存器,功能不详,与具体的接口命令字设计有关)。0x0cfc是PCI数据端口,该程序往刚才指定的0x68寄存器写了一个32位数据(0x00000002)。
Last edited by zyl910 on 2008-4-24 at 11:38 AM ]
The InitWDTimer function is relatively simple, using DPMI to get a selector pointing to WDTBaseAddress. Since this address exceeds the 24-bit address range of real mode, DPMI (DOS Protected Mode Interface) is used.
As for the SetWDtimer function. After setting up the segment descriptor with _farsetsel in the first sentence, the following _farnspokeb and _farnspokel are port operations, which are related to the design of specific interface command words.
The final outportl is used to write to the PCI configuration. 0x0cf8 is the PCI address port, 0x8000EC00 is the device number (divided into three levels: bus, device, function, the specific bit meanings are to be checked in the PCI specification, I don't remember exactly), 0x68 refers to the register at address 0x68 of this device (custom register, the function is unknown, related to the design of specific interface command words). 0x0cfc is the PCI data port, and this program writes a 32-bit data (0x00000002) to the previously specified register at address 0x68.
Last edited by zyl910 on 2008-4-24 at 11:38 AM ]
|

人类存在的目的就是试图理解人类为何存在 |
|
2008-4-24 11:27 |
|
|
zyl910
中级用户
  
积分 282
发帖 126
注册 2006-5-17
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
该程序用到了DPMI,用汇编不好写
再加上有很多32位操作(_farnspokel、outportl),但Debug只支持16位汇编,而且应该没人愿意直接写机器码。用Debug是很不现实的
This program uses DPMI, and it's not easy to write in assembly. Also, there are many 32-bit operations (_farnspokel, outportl), but Debug only supports 16-bit assembly, and no one should be willing to write machine code directly. Using Debug is very impractical.
|

人类存在的目的就是试图理解人类为何存在 |
|
2008-4-24 11:34 |
|
|
pptppt
新手上路

积分 8
发帖 3
注册 2008-4-23
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
谢谢 2zyl910 我先.试试看.
Last edited by pptppt on 2008-4-27 at 06:30 PM ]
Thanks 2zyl910. I'll try first.
Last edited by pptppt on 2008-4-27 at 06:30 PM ]
|
|
2008-4-27 18:15 |
|
|
netwinxp
高级用户
   
积分 741
发帖 366
注册 2007-7-25
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
_farpeekb、farpeekw、_farpeekl
_farnspeekb、_farnspeekw、_farnspeekl
_farpokeb、_farpokew、_farpokel
_farnspokeb、void _farnspokew、_farnspokel
这些是dpmi读、写保护模式内存的接口函数。
_farsetsel、 _fargetsel是设置和取得LDT的接口函数。
===以上部分需要学习保护模式编程的资料才能较好滴体会===
后面两句比较简单——
1、该硬件使用PCI配置空间8000EC00段(每段256字节),BUSID=0,DEVICEID=29。
2、其68H是BIOS看门狗定时器使能寄存器(该配置空间具体寄存器分布、格式和功能你最好找厂家索取)。
3、设置该寄存器值为2时使能定时器。
注:定时器的值好像在保护模式内存空间DF300000处
如果你非要用DEBUG来编写,那很多语句只能采用机器语言。推荐你采用masm611,用.386模式,如果你熟悉了保护模式编程,你可以用INT 15H调用完全脱离DPMI。
Last edited by netwinxp on 2008-5-1 at 04:39 PM ]
_farpeekb, _farpeekw, _farpeekl
_farnspeekb, _farnspeekw, _farnspeekl
_farpokeb, _farpokew, _farpokel
_farnspokeb, void _farnspokew, _farnspokel
These are the interface functions for DPMI to read and write protected mode memory.
_farsetsel, _fargetsel are the interface functions for setting and obtaining LDT.
===The above parts need to study the materials of protected mode programming to better understand===
The following two sentences are relatively simple -
1. This hardware uses the PCI configuration space 8000EC00 segment (each segment is 256 bytes), BUSID = 0, DEVICEID = 29.
2. Its 68H is the BIOS watchdog timer enable register (for the specific register distribution, format and function of this configuration space, you'd better get it from the manufacturer).
3. Set the value of this register to 2 to enable the timer.
Note: The value of the timer seems to be at the protected mode memory space DF300000.
If you must use DEBUG to write, then many statements can only use machine language. It is recommended that you use masm611, use the.386 mode, if you are familiar with protected mode programming, you can use INT 15H call to completely get rid of DPMI.
Last edited by netwinxp on 2008-5-1 at 04:39 PM ]
|
|
2008-5-1 16:01 |
|
|
pptppt
新手上路

积分 8
发帖 3
注册 2008-4-23
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
谢谢各位,还在学习中!!
Thanks everyone, still learning!!
|
|
2008-5-10 17:59 |
|
|