China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 07:47
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » A code in C under DOS, please help solve it, thank you. View 1,524 Replies 5
Original Poster Posted 2008-04-23 15:24 ·  中国 广东 广州 天河区 电信
新手上路
Credits 8
Posts 3
Joined 2008-04-23 14:49
18-year member
UID 116696
Gender Male
Status Offline
以下是翻译后的内容:

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);
}
Floor 2 Posted 2008-04-24 11:27 ·  中国 广东 广州 越秀区 电信
中级用户
★★
Credits 282
Posts 126
Joined 2006-05-17 22:29
20-year member
UID 55724
Status Offline
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 ]
人类存在的目的就是试图理解人类为何存在
Floor 3 Posted 2008-04-24 11:34 ·  中国 广东 广州 越秀区 电信
中级用户
★★
Credits 282
Posts 126
Joined 2006-05-17 22:29
20-year member
UID 55724
Status Offline
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.
人类存在的目的就是试图理解人类为何存在
Floor 4 Posted 2008-04-27 18:15 ·  中国 广东 广州 电信
新手上路
Credits 8
Posts 3
Joined 2008-04-23 14:49
18-year member
UID 116696
Gender Male
Status Offline
Thanks 2zyl910. I'll try first.

[ Last edited by pptppt on 2008-4-27 at 06:30 PM ]
Floor 5 Posted 2008-05-01 16:01 ·  中国 福建 厦门 电信
高级用户
★★★
Credits 741
Posts 366
Joined 2007-07-25 19:11
19-year member
UID 94024
Gender Male
Status Offline
_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 ]
Floor 6 Posted 2008-05-10 17:59 ·  中国 广东 广州 电信
新手上路
Credits 8
Posts 3
Joined 2008-04-23 14:49
18-year member
UID 116696
Gender Male
Status Offline
Thanks everyone, still learning!!
Forum Jump: