中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-10-31 14:51
47,815 topics / 349,930 posts / today 0 new / 48,290 members
DOS开发编程 & 发展交流 (开发室) » A code in C under DOS, please help solve it, thank you.
Printable Version  1,724 / 5
Floor1 pptppt Posted 2008-04-23 15:24
新手上路 Posts 3 Credits 8
以下是翻译后的内容:

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[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);
}
Floor2 zyl910 Posted 2008-04-24 11:27
中级用户 Posts 126 Credits 282
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 ]
Floor3 zyl910 Posted 2008-04-24 11:34
中级用户 Posts 126 Credits 282
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.
Floor4 pptppt Posted 2008-04-27 18:15
新手上路 Posts 3 Credits 8
Thanks 2zyl910. I'll try first.

[ Last edited by pptppt on 2008-4-27 at 06:30 PM ]
Floor5 netwinxp Posted 2008-05-01 16:01
高级用户 Posts 366 Credits 741
_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 ]
Floor6 pptppt Posted 2008-05-10 17:59
新手上路 Posts 3 Credits 8
Thanks everyone, still learning!!
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023