📄 os2v1acc.c
字号:
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: OS/2 1.x debug core.
*
****************************************************************************/
#include <stddef.h>
#include <string.h>
#include <i86.h>
#define INCL_BASE
#define INCL_DOSDEVICES
#define INCL_DOSMEMMGR
#define INCL_DOSSIGNALS
#include <os2.h>
#include <os2dbg.h>
#include "trpimp.h"
#include "trperr.h"
#include "os2trap.h"
#include "madregs.h"
#include "x86cpu.h"
#include "misc7086.h"
extern void BreakPoint( ULONG );
#pragma aux BreakPoint = 0xCC parm [ dx ax ] aborts;
extern void far *Automagic( unsigned short );
#pragma aux Automagic = 0x29 0xc4 /* sub sp,ax */\
0x89 0xe0 /* mov ax,sp */\
0x8c 0xd2 /* mov dx,ss */\
parm caller [ax] \
value [ax dx] \
modify [sp];
extern void LoadThisDLL( void );
extern void EndLoadThisDLL( void );
extern PID Pid;
extern bool AtEnd;
extern USHORT SID;
extern bool Remote;
extern char UtilBuff[BUFF_SIZE];
extern HFILE SaveStdIn;
extern HFILE SaveStdOut;
extern bool CanExecTask;
extern USHORT far *ModHandles;
extern USHORT NumModHandles;
extern int CurrModHandle;
extern int ExceptNum;
extern HMODULE ThisDLLModHandle;
extern scrtype Screen;
static TRACEBUF Buff;
static USHORT SessionType;
__GINFOSEG far *GblInfo;
char OS2ExtList[] = { ".exe\0" };
typedef struct watch {
addr48_ptr addr;
dword value;
} watch;
#define MAX_WP 32
watch WatchPoints[ MAX_WP ];
short WatchCount = 0;
#if 0
static void Out( char far *str )
{
USHORT written;
DosWrite( 1, str, strlen( str ), &written );
}
static void OutNL()
{
Out( "\r\n" );
}
static void OutNum( unsigned i )
{
char numbuff[10];
char far *ptr;
ptr = numbuff+10;
*--ptr = '\0';
while( i != 0 ) {
*--ptr = "0123456789abcdef"[ i & 0x0f ];
i >>= 4;
}
Out( ptr );
}
static void OutBuff( TRACEBUF far *buf )
{
Out( "pid = " ); OutNum( buf->pid ); Out( "\r\n" );
Out( "tid = " ); OutNum( buf->tid ); Out( "\r\n" );
Out( "cmd = " ); OutNum( buf->cmd ); Out( "\r\n" );
Out( "value = " ); OutNum( buf->value ); Out( "\r\n" );
Out( "offv = " ); OutNum( buf->offv ); Out( "\r\n" );
Out( "segv = " ); OutNum( buf->segv ); Out( "\r\n" );
Out( "mte = " ); OutNum( buf->mte ); Out( "\r\n" );
}
#endif
static USHORT WriteRegs( TRACEBUF far *buff )
{
buff->cmd = PT_CMD_WRITE_REGS;
return( DosPTrace( buff ) );
}
static USHORT ReadRegs( TRACEBUF far *buff )
{
buff->cmd = PT_CMD_READ_REGS;
return( DosPTrace( buff ) );
}
static USHORT WriteBuffer( char far *data, USHORT segv,
USHORT offv, USHORT size )
{
USHORT length;
length = size;
if( Pid != 0 ) {
while( length != 0 ) {
Buff.cmd = PT_CMD_WRITE_MEM_D;
if( length == 1 ) {
Buff.cmd = PT_CMD_READ_MEM_D;
Buff.offv = offv;
Buff.segv = segv;
DosPTrace( &Buff );
Buff.cmd = PT_CMD_WRITE_MEM_D;
Buff.offv = offv;
Buff.segv = segv;
Buff.value &= 0xff00;
Buff.value |= *data;
DosPTrace( &Buff );
if( Buff.cmd != PT_RET_SUCCESS ) break;
data++;
length--;
offv++;
} else {
Buff.value = *data;
data++;
Buff.value |= *data << 8;
data++;
Buff.offv = offv;
Buff.segv = segv;
DosPTrace( &Buff );
if( Buff.cmd != PT_RET_SUCCESS ) break;
length -= 2;
offv += 2;
}
}
}
return( size - length ); /* return amount written */
}
static USHORT ReadBuffer( char far *data, USHORT segv, USHORT offv, USHORT size )
{
USHORT length;
length = size;
if( Pid != 0 ) {
while( length != 0 ) {
Buff.cmd = PT_CMD_READ_MEM_D;
Buff.offv = offv;
Buff.segv = segv;
DosPTrace( &Buff );
if( Buff.cmd != PT_RET_SUCCESS ) break;
*data = Buff.value & 0xff;
data++;
offv++;
length--;
if( length != 0 ) {
*data = Buff.value >> 8;
data++;
offv++;
length--;
}
}
}
return( size - length );
}
static void RecordModHandle( USHORT value )
{
SEL sel;
if( ModHandles == NULL ) {
DosAllocSeg( sizeof( USHORT ), (PSEL)&sel, 0 );
ModHandles = MK_FP( sel, 0 );
} else {
DosReallocSeg( (NumModHandles+1)*sizeof( USHORT ),
FP_SEG( ModHandles ) );
}
ModHandles[ NumModHandles ] = value;
++NumModHandles;
}
static void ExecuteCode( TRACEBUF far *buff )
{
for( ;; ) {
buff->cmd = PT_CMD_GO;
buff->value = 0;
DosPTrace( buff ); // go here
if( buff->cmd != PT_RET_LIB_LOADED ) break;
RecordModHandle( buff->value );
}
}
#pragma aux DoOpen parm [ dx ax ] [ bx ] [ cx ];
static void DoOpen( char FAR *name, int mode, int flags )
{
BreakPoint( OpenFile( name, mode, flags ) );
}
#pragma aux DoClose parm [ ax ];
static void DoClose( HFILE hdl )
{
BreakPoint( DosClose( hdl ) );
}
#pragma aux DoDupFile parm [ ax ] [ dx ];
static void DoDupFile( HFILE old, HFILE new )
{
HFILE new_t;
USHORT rc;
new_t = new;
rc = DosDupHandle( old, &new_t );
if( rc != 0 ) {
BreakPoint( NIL_DOS_HANDLE );
} else {
BreakPoint( new_t );
}
}
#pragma aux DoWritePgmScrn parm [dx ax] [ bx ];
static void DoWritePgmScrn( char far *buff, USHORT len )
{
USHORT written;
DosWrite( 2, buff, len, &written );
BreakPoint( 0 );
}
static void DoGetMSW( void )
{
BreakPoint( GetMSW() );
}
static char stack[1024];
static long TaskExecute( void (*rtn)() )
{
TRACEBUF buff;
if( CanExecTask ) {
buff = Buff;
buff.u.r.CS = FP_SEG( rtn );
buff.u.r.IP = FP_OFF( rtn );
buff.u.r.SS = FP_SEG( stack );
buff.u.r.SP = FP_OFF( stack ) + sizeof( stack );
WriteRegs( &buff );
ExecuteCode( &buff );
return( ( (unsigned long)buff.u.r.DX << 16 ) + buff.u.r.AX );
} else {
return( -1 );
}
}
long TaskOpenFile( char far *name, int mode, int flags ) {
WriteBuffer( name, FP_SEG( UtilBuff ), FP_OFF( UtilBuff ),
strlen( name ) + 1 );
Buff.u.r.DX = FP_SEG( UtilBuff );
Buff.u.r.AX = FP_OFF( UtilBuff );
Buff.u.r.BX = mode;
Buff.u.r.CX = flags;
return( TaskExecute( DoOpen ) );
}
long TaskCloseFile( HFILE hdl )
{
Buff.u.r.AX = hdl;
return( TaskExecute( DoClose ) );
}
HFILE TaskDupFile( HFILE old, HFILE new )
{
Buff.u.r.AX = old;
Buff.u.r.DX = new;
return( TaskExecute( DoDupFile ) );
}
unsigned ReqGet_sys_config()
{
get_sys_config_ret *ret;
CHAR npx;
USHORT version;
USHORT shift;
long emu;
TRACEBUF buff;
char tmp[108];
ret = GetOutPtr(0);
ret->sys.os = OS_OS2;
DosGetVersion( &version );
ret->sys.osmajor = version >> 8;
ret->sys.osminor = version & 0xff;
ret->sys.cpu = X86CPUType();
DosDevConfig( &npx, 3, 0 );
if( npx ) {
if( ret->sys.cpu >= X86_486 ) {
ret->sys.fpu = ret->sys.cpu & X86_CPU_MASK;
} else {
ret->sys.fpu = NPXType();
}
} else {
ret->sys.fpu = X86_NO;
}
emu = TaskExecute( &DoGetMSW );
if( emu != -1 && (emu & 0x04) ) { /* if EM bit is on in the MSW */
ret->sys.fpu = X86_EMU;
}
WriteRegs( &Buff );
if( ret->sys.fpu != X86_NO ) {
buff.cmd = PT_CMD_READ_8087;
buff.segv = FP_SEG( tmp );
buff.offv = FP_OFF( tmp );
buff.tid = 1;
buff.pid = Pid;
DosPTrace( &buff );
if( buff.cmd != PT_RET_SUCCESS ) ret->sys.fpu = X86_NO;
}
DosGetHugeShift( &shift );
ret->sys.huge_shift = shift;
ret->sys.mad = MAD_X86;
return( sizeof( *ret ) );
}
unsigned ReqMap_addr()
{
map_addr_req *acc;
map_addr_ret *ret;
acc = GetInPtr(0);
ret = GetOutPtr(0);
if( Pid != 0 ) {
Buff.cmd = PT_CMD_SEG_TO_SEL;
Buff.value = acc->in_addr.segment;
switch( Buff.value ) {
case MAP_FLAT_CODE_SELECTOR:
case MAP_FLAT_DATA_SELECTOR:
Buff.value = 1;
break;
}
Buff.mte = ModHandles[ acc->handle ];
DosPTrace( &Buff );
Buff.mte = ModHandles[ 0 ];
ret->out_addr.segment = Buff.value;
}
ret->out_addr.offset = acc->in_addr.offset;
ret->lo_bound = 0;
ret->hi_bound = ~(addr48_off)0;
return( sizeof( *ret ) );
}
unsigned ReqAddr_info()
{
addr_info_ret *retblk;
retblk = GetOutPtr( 0 );
retblk->is_32 = FALSE;
return( sizeof( *retblk ) );
}
unsigned ReqMachine_data()
{
machine_data_ret *ret;
unsigned_8 *data;
ret = GetOutPtr( 0 );
data = GetOutPtr( sizeof( *ret ) );
ret->cache_start = 0;
ret->cache_end = ~(addr_off)0;
*data = 0;
return( sizeof( *ret ) + sizeof( *data ) );
}
unsigned ReqChecksum_mem()
{
USHORT offset;
USHORT length;
ULONG sum;
checksum_mem_req *acc;
checksum_mem_ret *ret;
acc = GetInPtr(0);
ret = GetOutPtr(0);
length = acc->len;
sum = 0;
if( Pid != 0 ) {
offset = acc->in_addr.offset;
while( length != 0 ) {
Buff.cmd = PT_CMD_READ_MEM_D;
Buff.offv = offset;
Buff.segv = acc->in_addr.segment;
DosPTrace( &Buff );
if( Buff.cmd != PT_RET_SUCCESS ) break;
sum += Buff.value & 0xff;
offset++;
length--;
if( length != 0 ) {
sum += Buff.value >> 8;
offset++;
length--;
}
}
}
ret->result = sum;
return( sizeof( *ret ) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -