feat: add Client32 NCP support for FLAG

This commit is contained in:
Mario Fetka
2026-05-23 22:13:54 +02:00
parent 7f98d73738
commit 87c1e50cf9
9 changed files with 432 additions and 2461 deletions

View File

@@ -36,7 +36,6 @@ if(MARS_NWE_BUILD_DOSUTILS)
find_package(OpenWatcom REQUIRED)
set(DOSUTILS_C_SOURCES
kern.c
net.c
tools.c
netcall.c
@@ -45,6 +44,7 @@ if(MARS_NWE_BUILD_DOSUTILS)
map.c
slist.c
flag.c
c32ncp.c
nwcrypt.c
nwdebug.c
nwtests.c

309
c32ncp.c Normal file
View File

@@ -0,0 +1,309 @@
#include "net.h"
#include "c32ncp.h"
/* c32ncp.c - Client32 NCP helpers for mars-dosutils */
static void c32_put_word_lh(uint8 *p, uint16 v)
{
p[0] = (uint8)(v & 0xff);
p[1] = (uint8)((v >> 8) & 0xff);
}
static void c32_put_dword_lh(uint8 *p, uint32 v)
{
p[0] = (uint8)(v & 0xff);
p[1] = (uint8)((v >> 8) & 0xff);
p[2] = (uint8)((v >> 16) & 0xff);
p[3] = (uint8)((v >> 24) & 0xff);
}
static uint16 c32_get_word_lh(uint8 *p)
{
return((uint16)(p[0] | ((uint16)p[1] << 8)));
}
static uint32 c32_get_dword_lh(uint8 *p)
{
return((uint32)p[0] |
((uint32)p[1] << 8) |
((uint32)p[2] << 16) |
((uint32)p[3] << 24));
}
static UI c32_build_handle_path(uint8 *buf, uint8 dhandle,
uint16 dirbase, uint8 style,
int count,
const char *c1, const char *c2, const char *c3)
{
uint8 *p;
int l;
UI used;
/*
* DeveloperNet/ncpdos16 path structure used by NCP87/S6 through
* Client32 COMPATNcpRequestReply.
*
* This is the exact shape verified by TESTS NCP87C32AUTO:
* 00 02 00 00 00 00 01 09 4C 4F 47 49 4E 2E 45 58 45
*
* Meaning:
* word[1] = short dir handle
* word[3] = dir base
* byte[5] = dirstyle
* byte[6] = component count
* then len/name components
*
* The old/simple struct used by the INT 21h F257 fallback is not accepted
* by this Client32 path.
*/
memset(buf, 0, 0x140);
if (dhandle) {
c32_put_word_lh(buf + 1, (uint16)dhandle);
c32_put_word_lh(buf + 3, dirbase);
buf[5] = style;
} else {
buf[5] = 0xff;
}
p = buf + 6;
*p++ = (uint8)count;
if (count > 0 && c1) {
l = strlen(c1);
if (l > 255) l = 255;
*p++ = (uint8)l;
memcpy(p, c1, l);
p += l;
}
if (count > 1 && c2) {
l = strlen(c2);
if (l > 255) l = 255;
*p++ = (uint8)l;
memcpy(p, c2, l);
p += l;
}
if (count > 2 && c3) {
l = strlen(c3);
if (l > 255) l = 255;
*p++ = (uint8)l;
memcpy(p, c3, l);
p += l;
}
used = (UI)(p - buf);
c32_put_word_lh(buf + 0x13c, used);
return(used);
}
/*
* Current verified Client32 path for mars-nwe DOS utilities:
*
* C32_MapVar_Probe(4,0) -> connRefLocal FFFF:FFFE
* C32_OpenRef_Probe(connRefLocal) -> Client32 handle, e.g. 0101:0001
*
* C32_MapVar_Probe currently contains the confirmed Mars server-name scan
* shape. It is intentionally kept small and isolated here so FLAG and later
* tools do not carry the old exploratory tests.
*/
int c32_get_ncp_handle(uint16 *handle_lo, uint16 *handle_hi)
{
uint8 mapout[32];
uint8 openout[32];
uint16 map_ret_ax, map_ret_dx;
uint16 cref_lo, cref_hi;
uint16 open_ret_ax, open_ret_dx;
if (!handle_lo || !handle_hi)
return(1);
*handle_lo = 0;
*handle_hi = 0;
memset(mapout, 0, sizeof(mapout));
C32_MapVar_Probe(4, 0, mapout);
map_ret_ax = c32_get_word_lh(mapout + 14);
map_ret_dx = c32_get_word_lh(mapout + 16);
cref_lo = c32_get_word_lh(mapout + 22);
cref_hi = c32_get_word_lh(mapout + 24);
if (map_ret_ax != 0 || map_ret_dx != 0 || (cref_lo == 0 && cref_hi == 0))
return(2);
memset(openout, 0, sizeof(openout));
C32_OpenRef_Probe(cref_lo, cref_hi, openout);
open_ret_ax = c32_get_word_lh(openout + 14);
open_ret_dx = c32_get_word_lh(openout + 16);
*handle_lo = c32_get_word_lh(openout + 18);
*handle_hi = c32_get_word_lh(openout + 20);
if (open_ret_ax != 0 || open_ret_dx != 0 || (*handle_lo == 0 && *handle_hi == 0))
return(3);
return(0);
}
int c32_ncp87_obtain_rim_attributes(const char *name,
uint16 dir_handle,
uint32 *attr_out,
uint16 *actual_out,
uint16 *handle_lo_out,
uint16 *handle_hi_out)
{
uint16 handle_lo, handle_hi;
uint8 hdr[16];
uint8 path[0x140];
uint8 rep0[0x60];
uint8 rep1[0x110];
uint8 rawout[32];
uint16 raw_ret_ax, raw_ret_dx;
uint16 actual_lo;
int path_len;
int rc;
if (!name || !attr_out)
return(1);
*attr_out = 0;
if (actual_out) *actual_out = 0;
if (handle_lo_out) *handle_lo_out = 0;
if (handle_hi_out) *handle_hi_out = 0;
rc = c32_get_ncp_handle(&handle_lo, &handle_hi);
if (rc)
return(10 + rc);
memset(hdr, 0, sizeof(hdr));
hdr[0] = 6; /* NCP87 subfunction 6 */
hdr[1] = 0; /* source namespace DOS */
hdr[2] = 0; /* target namespace DOS */
c32_put_word_lh(hdr + 3, 0x0006); /* SA_ALL */
c32_put_dword_lh(hdr + 5, 0x00000004UL); /* RIM_ATTRIBUTES */
path_len = c32_build_handle_path(path, (uint8)dir_handle, 0, 0, 1,
name, NULL, NULL);
memset(rep0, 0, sizeof(rep0));
memset(rep1, 0, sizeof(rep1));
memset(rawout, 0, sizeof(rawout));
C32_NCP87_Raw5_Probe(handle_lo, handle_hi,
hdr, 9,
path, (UI)path_len,
rep0, 0x4d,
rep1, 0x100,
rawout);
raw_ret_ax = c32_get_word_lh(rawout + 14);
raw_ret_dx = c32_get_word_lh(rawout + 16);
actual_lo = c32_get_word_lh(rawout + 18);
if (raw_ret_ax != 0 || raw_ret_dx != 0)
return(20);
/*
* Verified reply layout for RIM_ATTRIBUTES:
* REP0+4 little-endian dword = DOS attributes
* Example LOGIN.EXE: 20h archive.
*/
*attr_out = c32_get_dword_lh(rep0 + 4);
if (actual_out) *actual_out = actual_lo;
if (handle_lo_out) *handle_lo_out = handle_lo;
if (handle_hi_out) *handle_hi_out = handle_hi;
return(0);
}
int c32_ncp87_modify_dos_attributes(char *name,
uint16 dir_handle,
uint32 attrs,
uint16 *actual_out,
uint16 *handle_lo_out,
uint16 *handle_hi_out)
{
uint16 handle_lo, handle_hi;
uint8 modbuf[64];
uint8 path[0x140];
uint8 rep0[0x20];
uint8 rep1[0x20];
uint8 rawout[32];
uint8 *p;
UI mod_len;
UI path_len;
uint16 raw_ret_ax, raw_ret_dx;
uint16 actual_lo;
int rc;
if (!name)
return(1);
if (actual_out)
*actual_out = 0;
if (handle_lo_out)
*handle_lo_out = 0;
if (handle_hi_out)
*handle_hi_out = 0;
rc = c32_get_ncp_handle(&handle_lo, &handle_hi);
if (rc)
return(10 + rc);
/*
* NCP 87 subfunction 7: Modify DOS information.
*
* First request fragment contains the fixed header and DOS info structure.
* Second request fragment contains the verified SDK-style path structure.
*
* This avoids the old INT 21h F257 modify path, which can hang under DOS
* Client32 for high FLAG bits such as Transactional.
*/
memset(modbuf, 0, sizeof(modbuf));
p = modbuf;
*p++ = 7; /* subfunction: modify DOS info */
*p++ = 0; /* namespace DOS */
*p++ = 0; /* reserved */
c32_put_word_lh(p, 0x0006); p += 2; /* SA_ALL */
c32_put_dword_lh(p, 0x00000002UL); p += 4; /* DM_ATTRIBUTES: attributes */
c32_put_dword_lh(p, attrs); p += 4; /* Attributes */
memset(p, 0, 34); p += 34; /* rest of DOS info */
mod_len = (UI)(p - modbuf);
path_len = c32_build_handle_path(path, (uint8)dir_handle, 0, 0, 1,
name, NULL, NULL);
memset(rep0, 0, sizeof(rep0));
memset(rep1, 0, sizeof(rep1));
memset(rawout, 0, sizeof(rawout));
C32_NCP87_Raw5_Probe(handle_lo, handle_hi,
modbuf, mod_len,
path, path_len,
rep0, sizeof(rep0),
rep1, sizeof(rep1),
rawout);
raw_ret_ax = c32_get_word_lh(rawout + 14);
raw_ret_dx = c32_get_word_lh(rawout + 16);
actual_lo = c32_get_word_lh(rawout + 18);
if (actual_out)
*actual_out = actual_lo;
if (handle_lo_out)
*handle_lo_out = handle_lo;
if (handle_hi_out)
*handle_hi_out = handle_hi;
if (raw_ret_ax != 0 || raw_ret_dx != 0)
return(20);
return(0);
}

22
c32ncp.h Normal file
View File

@@ -0,0 +1,22 @@
/* c32ncp.h - minimal Client32 NCP helpers for mars-dosutils */
#ifndef C32NCP_H
#define C32NCP_H
int c32_get_ncp_handle(uint16 *handle_lo, uint16 *handle_hi);
int c32_ncp87_obtain_rim_attributes(const char *name,
uint16 dir_handle,
uint32 *attr_out,
uint16 *actual_out,
uint16 *handle_lo_out,
uint16 *handle_hi_out);
int c32_ncp87_modify_dos_attributes(char *name,
uint16 dir_handle,
uint32 attrs,
uint16 *actual_out,
uint16 *handle_lo_out,
uint16 *handle_hi_out);
#endif

101
flag.c
View File

@@ -1,6 +1,7 @@
/* flag.c - Novell FLAG-like DOS utility, stage 1 */
#include "net.h"
#include "c32ncp.h"
#include <dos.h>
/*
@@ -121,6 +122,14 @@ static int flag_ncp87_obtain_attrs(char *name, uint32 *attrs)
if (flag_current_dhandle(&dhandle))
return(-1);
/*
* Prefer the verified Client32 NCP87 path. If it is not available,
* fall back to the historical INT 21h/Net_Call path below.
*/
if (c32_ncp87_obtain_rim_attributes(name, (uint16)dhandle,
attrs, NULL, NULL, NULL) == 0)
return(0);
memset(&req, 0, sizeof(req));
memset(&repl, 0, sizeof(repl));
@@ -167,6 +176,19 @@ static int flag_ncp87_modify_attrs(char *name, uint32 attrs)
if (flag_current_dhandle(&dhandle))
return(-1);
/*
* Prefer verified Client32 modify path. The old INT 21h/F257 modify path
* can hang under DOS Client32 for high FLAG bits such as T/P/DI/RI.
*/
{
uint16 actual = 0;
uint16 hlo = 0;
uint16 hhi = 0;
if (!c32_ncp87_modify_dos_attributes(name, (uint16)dhandle, attrs,
&actual, &hlo, &hhi))
return(0);
}
memset(&req, 0, sizeof(req));
memset(&repl, 0, sizeof(repl));
@@ -257,7 +279,7 @@ static void flag_help(void)
fprintf(stdout, "SUB\n");
}
static int flag_attr_mask(char *s, unsigned *setbits, unsigned *clearbits)
static int flag_attr_mask(char *s, uint32 *setbits, uint32 *clearbits)
{
int set = 1;
char *p = s;
@@ -274,51 +296,51 @@ static int flag_attr_mask(char *s, unsigned *setbits, unsigned *clearbits)
if (flag_same(p, "RO")) {
if (set) {
*setbits |= (unsigned)(NWFA_RO | NWFA_DI | NWFA_RI);
*setbits |= (NWFA_RO | NWFA_DI | NWFA_RI);
} else {
*clearbits |= (unsigned)(NWFA_RO | NWFA_DI | NWFA_RI);
*clearbits |= (NWFA_RO | NWFA_DI | NWFA_RI);
}
} else if (flag_same(p, "RW")) {
*clearbits |= (unsigned)(NWFA_RO | NWFA_DI | NWFA_RI);
*clearbits |= (NWFA_RO | NWFA_DI | NWFA_RI);
} else if (flag_same(p, "S")) {
if (set) *setbits |= (unsigned)NWFA_S;
else *clearbits |= (unsigned)NWFA_S;
if (set) *setbits |= NWFA_S;
else *clearbits |= NWFA_S;
} else if (flag_same(p, "H")) {
if (set) *setbits |= (unsigned)NWFA_H;
else *clearbits |= (unsigned)NWFA_H;
if (set) *setbits |= NWFA_H;
else *clearbits |= NWFA_H;
} else if (flag_same(p, "SY") || flag_same(p, "SYS") || flag_same(p, "SYSTEM")) {
if (set) *setbits |= (unsigned)NWFA_SY;
else *clearbits |= (unsigned)NWFA_SY;
if (set) *setbits |= NWFA_SY;
else *clearbits |= NWFA_SY;
} else if (flag_same(p, "T")) {
if (set) *setbits |= (unsigned)NWFA_T;
else *clearbits |= (unsigned)NWFA_T;
if (set) *setbits |= NWFA_T;
else *clearbits |= NWFA_T;
} else if (flag_same(p, "P")) {
if (set) *setbits |= (unsigned)NWFA_P;
else *clearbits |= (unsigned)NWFA_P;
if (set) *setbits |= NWFA_P;
else *clearbits |= NWFA_P;
} else if (flag_same(p, "A")) {
if (set) *setbits |= (unsigned)NWFA_A;
else *clearbits |= (unsigned)NWFA_A;
if (set) *setbits |= NWFA_A;
else *clearbits |= NWFA_A;
} else if (flag_same(p, "RA")) {
if (set) *setbits |= (unsigned)NWFA_RA;
else *clearbits |= (unsigned)NWFA_RA;
if (set) *setbits |= NWFA_RA;
else *clearbits |= NWFA_RA;
} else if (flag_same(p, "WA")) {
if (set) *setbits |= (unsigned)NWFA_WA;
else *clearbits |= (unsigned)NWFA_WA;
if (set) *setbits |= NWFA_WA;
else *clearbits |= NWFA_WA;
} else if (flag_same(p, "CI")) {
if (set) *setbits |= (unsigned)NWFA_CI;
else *clearbits |= (unsigned)NWFA_CI;
if (set) *setbits |= NWFA_CI;
else *clearbits |= NWFA_CI;
} else if (flag_same(p, "DI")) {
if (set) *setbits |= (unsigned)NWFA_DI;
else *clearbits |= (unsigned)NWFA_DI;
if (set) *setbits |= NWFA_DI;
else *clearbits |= NWFA_DI;
} else if (flag_same(p, "RI")) {
if (set) *setbits |= (unsigned)NWFA_RI;
else *clearbits |= (unsigned)NWFA_RI;
if (set) *setbits |= NWFA_RI;
else *clearbits |= NWFA_RI;
} else if (flag_same(p, "N") || flag_same(p, "NORMAL")) {
*clearbits |= (unsigned)(NWFA_RO | NWFA_H | NWFA_SY | NWFA_A |
*clearbits |= (NWFA_RO | NWFA_H | NWFA_SY | NWFA_A |
NWFA_S | NWFA_T | NWFA_P |
NWFA_RA | NWFA_WA | NWFA_CI | NWFA_DI | NWFA_RI);
} else if (flag_same(p, "ALL")) {
*setbits |= (unsigned)(NWFA_RO | NWFA_H | NWFA_SY | NWFA_A |
*setbits |= (NWFA_RO | NWFA_H | NWFA_SY | NWFA_A |
NWFA_S | NWFA_T | NWFA_P |
NWFA_RA | NWFA_WA | NWFA_CI | NWFA_DI | NWFA_RI);
} else {
@@ -329,18 +351,19 @@ static int flag_attr_mask(char *s, unsigned *setbits, unsigned *clearbits)
return(0);
}
static void flag_print_attrs(unsigned attr)
static void flag_print_attrs(uint32 attr)
{
/*
* Novell order:
* RO/RW S A H Sy T P RA WA CI DI RI
* Ro/Rw S A - H Sy T P Ra Wa CI DI RI
*/
fprintf(stdout, "[ ");
fprintf(stdout, "%s ", (attr & NWFA_RO) ? "RO" : "Rw");
fprintf(stdout, "%s ", (attr & NWFA_RO) ? "Ro" : "Rw");
fprintf(stdout, "%c ", (attr & NWFA_S) ? 'S' : '-');
fprintf(stdout, "%c ", (attr & NWFA_A) ? 'A' : '-');
fprintf(stdout, "- ");
fprintf(stdout, "%c ", (attr & NWFA_H) ? 'H' : '-');
fprintf(stdout, "%s ", (attr & NWFA_SY) ? "Sy" : "-");
fprintf(stdout, "%s ", (attr & NWFA_SY) ? "Sy" : "--");
fprintf(stdout, "%c ", (attr & NWFA_T) ? 'T' : '-');
fprintf(stdout, "%c ", (attr & NWFA_P) ? 'P' : '-');
fprintf(stdout, "%s ", (attr & NWFA_RA) ? "Ra" : "--");
@@ -351,7 +374,7 @@ static void flag_print_attrs(unsigned attr)
fprintf(stdout, "]");
}
static void flag_display_one(char *name, unsigned attr)
static void flag_display_one(char *name, uint32 attr)
{
fprintf(stdout, " %-23s ", name);
flag_print_attrs(attr);
@@ -383,7 +406,7 @@ static int flag_list(char *pattern)
if (flag_ncp87_obtain_attrs(ff.name, &nwattrs))
nwattrs = (uint32)ff.attrib;
flag_display_one(ff.name, (unsigned)nwattrs);
flag_display_one(ff.name, nwattrs);
found++;
}
} while (!_dos_findnext(&ff));
@@ -391,7 +414,7 @@ static int flag_list(char *pattern)
return(found);
}
static int flag_apply(char *pattern, unsigned setbits, unsigned clearbits)
static int flag_apply(char *pattern, uint32 setbits, uint32 clearbits)
{
struct find_t ff;
unsigned findattr = _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_ARCH;
@@ -416,7 +439,7 @@ static int flag_apply(char *pattern, unsigned setbits, unsigned clearbits)
if (newattrs != attrs) {
if (flag_ncp87_modify_attrs(fname, newattrs)) {
unsigned dosattr = (unsigned)(newattrs & (_A_RDONLY|_A_HIDDEN|_A_SYSTEM|_A_ARCH));
unsigned dosattr = (newattrs & (_A_RDONLY|_A_HIDDEN|_A_SYSTEM|_A_ARCH));
if (_dos_setfileattr(fname, dosattr)) {
fprintf(stderr, "You don't have rights to change : %s\n", fname);
continue;
@@ -427,7 +450,7 @@ static int flag_apply(char *pattern, unsigned setbits, unsigned clearbits)
if (flag_ncp87_obtain_attrs(fname, &attrs))
attrs = newattrs;
flag_display_one(fname, (unsigned)attrs);
flag_display_one(fname, newattrs);
shown++;
} while (!_dos_findnext(&ff));
@@ -439,8 +462,8 @@ int func_flag(int argc, char *argv[], int mode)
{
char *path = "*.*";
int i;
unsigned setbits = 0;
unsigned clearbits = 0;
uint32 setbits = 0;
uint32 clearbits = 0;
int have_change = 0;
int rc;

271
kern.c
View File

@@ -1,271 +0,0 @@
/*
* kern.c - C-side experimental NetWare/DOS request wrappers
*
* kern_wasm.asm remains the production/reference implementation.
* These C functions are test wrappers so we can inspect register setup and
* slowly port proven pieces from ASM to C.
*/
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include "net.h"
#if defined(__WATCOMC__)
#define KERN_C_CALL _Cdecl
#else
#define KERN_C_CALL
#endif
typedef struct {
unsigned int in_ax;
unsigned int in_bx;
unsigned int in_cx;
unsigned int in_dx;
unsigned int in_si;
unsigned int in_di;
unsigned int in_ds;
unsigned int in_es;
unsigned int out_ax;
unsigned int out_bx;
unsigned int out_cx;
unsigned int out_dx;
unsigned int out_si;
unsigned int out_di;
unsigned int out_flags;
void far *req_ptr;
void far *repl_ptr;
int rc;
} NET_CALL_C_DEBUG;
NET_CALL_C_DEBUG Net_Call_C_Last;
static void net_call_c_clear(void)
{
memset(&Net_Call_C_Last, 0, sizeof(Net_Call_C_Last));
}
static void net_call_c_save_in(union REGS *r, struct SREGS *s,
void *req, void *repl)
{
Net_Call_C_Last.in_ax = r->x.ax;
Net_Call_C_Last.in_bx = r->x.bx;
Net_Call_C_Last.in_cx = r->x.cx;
Net_Call_C_Last.in_dx = r->x.dx;
Net_Call_C_Last.in_si = r->x.si;
Net_Call_C_Last.in_di = r->x.di;
Net_Call_C_Last.in_ds = s->ds;
Net_Call_C_Last.in_es = s->es;
Net_Call_C_Last.req_ptr = req;
Net_Call_C_Last.repl_ptr = repl;
}
static void net_call_c_save_out(union REGS *r, unsigned int returned_ax)
{
Net_Call_C_Last.out_ax = returned_ax;
Net_Call_C_Last.out_bx = r->x.bx;
Net_Call_C_Last.out_cx = r->x.cx;
Net_Call_C_Last.out_dx = r->x.dx;
Net_Call_C_Last.out_si = r->x.si;
Net_Call_C_Last.out_di = r->x.di;
Net_Call_C_Last.out_flags = r->x.cflag;
Net_Call_C_Last.rc = returned_ax & 0x00ff;
}
/*
* C equivalent of kern_wasm.asm Net_Call:
* AX = func
* DS:SI = request
* ES:DI = reply
* int 21h
* return AL only, because kern_wasm.asm clears AH before return.
*/
int KERN_C_CALL Net_Call_C(unsigned int ax, void *req, void *repl)
{
return Net_Call_CX(ax, 0, 0, 0, req, repl);
}
int KERN_C_CALL Net_Call_CX(unsigned int ax, unsigned int bx,
unsigned int cx, unsigned int dx,
void *req, void *repl)
{
union REGS inregs;
union REGS outregs;
struct SREGS segregs;
unsigned int ret_ax;
memset(&inregs, 0, sizeof(inregs));
memset(&outregs, 0, sizeof(outregs));
memset(&segregs, 0, sizeof(segregs));
net_call_c_clear();
inregs.x.ax = ax;
inregs.x.bx = bx;
inregs.x.cx = cx;
inregs.x.dx = dx;
inregs.x.si = FP_OFF(req);
inregs.x.di = FP_OFF(repl);
segregs.ds = FP_SEG(req);
segregs.es = FP_SEG(repl);
net_call_c_save_in(&inregs, &segregs, req, repl);
int86x(0x21, &inregs, &outregs, &segregs);
ret_ax = outregs.x.ax & 0x00ff; /* match ASM Net_Call return */
net_call_c_save_out(&outregs, ret_ax);
return (int)ret_ax;
}
/*
* Experimental Novell Client/VLM AH=F2 wrapper derived from official FLAG.EXE
* disassembly:
* AH = F2h
* AL = NCP function, e.g. 57h for NCP 87
* CX = request length
* DX = reply buffer length
* DS:SI = request buffer
* ES:DI = reply buffer
*/
int KERN_C_CALL Net_Call_F2_C(unsigned int function,
unsigned int req_len,
unsigned int repl_len,
void *req,
void *repl)
{
union REGS inregs;
union REGS outregs;
struct SREGS segregs;
unsigned int ret_ax;
memset(&inregs, 0, sizeof(inregs));
memset(&outregs, 0, sizeof(outregs));
memset(&segregs, 0, sizeof(segregs));
net_call_c_clear();
inregs.h.ah = 0xF2;
inregs.h.al = (unsigned char)(function & 0xff);
inregs.x.cx = req_len;
inregs.x.dx = repl_len;
inregs.x.si = FP_OFF(req);
inregs.x.di = FP_OFF(repl);
segregs.ds = FP_SEG(req);
segregs.es = FP_SEG(repl);
net_call_c_save_in(&inregs, &segregs, req, repl);
int86x(0x21, &inregs, &outregs, &segregs);
/*
* Novell wrapper behavior:
* xor ah,ah
* or al,al
* if al != 0: ah=89h
* Return AL only for C caller, but keep 89xx in debug out_ax.
*/
ret_ax = outregs.x.ax & 0x00ff;
if (ret_ax)
ret_ax |= 0x8900;
net_call_c_save_out(&outregs, ret_ax);
return (int)(ret_ax & 0x00ff);
}
/*
* Fully generic INT 21h register test wrapper.
* Used for reproducing the NWCREQUEST/NWCSHELLREQ register calls seen in
* DeveloperNet 1997 clndos16.lib.
*/
int KERN_C_CALL Net_Call_F2X_C(unsigned int ax,
unsigned int bx,
unsigned int cx,
unsigned int dx,
void *req,
void *repl)
{
union REGS inregs;
union REGS outregs;
struct SREGS segregs;
unsigned int ret_ax;
memset(&inregs, 0, sizeof(inregs));
memset(&outregs, 0, sizeof(outregs));
memset(&segregs, 0, sizeof(segregs));
net_call_c_clear();
inregs.x.ax = ax;
inregs.x.bx = bx;
inregs.x.cx = cx;
inregs.x.dx = dx;
inregs.x.si = FP_OFF(req);
inregs.x.di = FP_OFF(repl);
segregs.ds = FP_SEG(req);
segregs.es = FP_SEG(repl);
net_call_c_save_in(&inregs, &segregs, req, repl);
int86x(0x21, &inregs, &outregs, &segregs);
ret_ax = outregs.x.ax & 0x00ff;
if (ret_ax)
ret_ax |= 0x8900;
net_call_c_save_out(&outregs, ret_ax);
return (int)(ret_ax & 0x00ff);
}
void KERN_C_CALL Net_Call_C_Dump(void)
{
fprintf(stdout, "NETCALLC in : AX=%04X BX=%04X CX=%04X DX=%04X DS:SI=%04X:%04X ES:DI=%04X:%04X\n",
Net_Call_C_Last.in_ax,
Net_Call_C_Last.in_bx,
Net_Call_C_Last.in_cx,
Net_Call_C_Last.in_dx,
Net_Call_C_Last.in_ds,
Net_Call_C_Last.in_si,
Net_Call_C_Last.in_es,
Net_Call_C_Last.in_di);
fprintf(stdout, "NETCALLC out: AX=%04X BX=%04X CX=%04X DX=%04X SI=%04X DI=%04X CF=%04X RC=%d\n",
Net_Call_C_Last.out_ax,
Net_Call_C_Last.out_bx,
Net_Call_C_Last.out_cx,
Net_Call_C_Last.out_dx,
Net_Call_C_Last.out_si,
Net_Call_C_Last.out_di,
Net_Call_C_Last.out_flags,
Net_Call_C_Last.rc);
}
unsigned int KERN_C_CALL Net_Call_C_GetDebug(unsigned int idx)
{
switch (idx) {
case 0: return Net_Call_C_Last.in_ax;
case 1: return Net_Call_C_Last.in_bx;
case 2: return Net_Call_C_Last.in_cx;
case 3: return Net_Call_C_Last.in_dx;
case 4: return Net_Call_C_Last.in_ds;
case 5: return Net_Call_C_Last.in_si;
case 6: return Net_Call_C_Last.in_es;
case 7: return Net_Call_C_Last.in_di;
case 8: return Net_Call_C_Last.out_ax;
case 9: return Net_Call_C_Last.out_bx;
case 10: return Net_Call_C_Last.out_cx;
case 11: return Net_Call_C_Last.out_dx;
case 12: return Net_Call_C_Last.out_si;
case 13: return Net_Call_C_Last.out_di;
case 14: return Net_Call_C_Last.out_flags;
case 15: return (unsigned int)Net_Call_C_Last.rc;
}
return 0xffff;
}

20
kern.h
View File

@@ -15,10 +15,6 @@ extern void asm_esr_routine(void);
extern void esr_routine(ECB *ecb);
extern void KERN_CALL xmemmove(void *ziel, void *quelle, UI anz);
extern int KERN_CALL Net_Call(UI func, void *req, void *repl);
extern int KERN_CALL C32_LoadNios_Probe(UI axfunc, void *outbuf);
extern int KERN_CALL C32_GetFunc_Probe(char *name, void *outbuf);
extern int KERN_CALL C32_CallVersion_Nios_Probe(void *outbuf);
extern int KERN_CALL C32_MapLock_Probe(void *ptr, UI len, void *outbuf);
extern int KERN_CALL C32_MapVar_Probe(UI specLen, UI flag, void *outbuf);
extern int KERN_CALL C32_OpenRef_Probe(UI refLo, UI refHi, void *outbuf);
extern int KERN_CALL C32_NCP87_Raw5_Probe(UI connLo, UI connHi,
@@ -27,22 +23,6 @@ extern int KERN_CALL C32_NCP87_Raw5_Probe(UI connLo, UI connHi,
void *rep0, UI rep0Len,
void *rep1, UI rep1Len,
void *outbuf);
extern int KERN_CALL Net_Call_VLM_Raw(UI ax, UI bx, UI cx, UI dx,
void *req, void *repl,
UI p1, UI p2, UI p3);
extern int KERN_CALL Net_Call_C(UI func, void *req, void *repl);
extern int KERN_CALL Net_Call_CX(UI func, UI bx, UI cx, UI dx,
void *req, void *repl);
extern int KERN_CALL Net_Call_F2_C(UI function, UI req_len, UI repl_len,
void *req, void *repl);
extern int KERN_CALL Net_Call_F2X_C(UI ax, UI bx, UI cx, UI dx,
void *req, void *repl);
extern void KERN_CALL Net_Call_C_Dump(void);
extern UI KERN_CALL Net_Call_C_GetDebug(UI idx);
#undef KERN_CALL

View File

@@ -20,14 +20,9 @@ public _IPXclose_socket
public _IPXlisten
public _xmemmove
public _Net_Call
public _C32_LoadNios_Probe
public _C32_GetFunc_Probe
public _C32_CallVersion_Nios_Probe
public _C32_MapLock_Probe
public _C32_NCP87_Raw5_Probe
public _C32_OpenRef_Probe
public _C32_MapVar_Probe
public _Net_Call_VLM_Raw
_IPXinit proc far
push bp
mov bp, sp
@@ -220,495 +215,6 @@ _Net_Call proc far
ret
_Net_Call endp
; int Net_Call_VLM_Raw(UI ax, UI bx, UI cx, UI dx,
; void *req, void *repl,
; UI p1, UI p2, UI p3)
;
; Experimental VLM entry caller.
; INT 2F AX=7A20 returns ES:BX = VLM entry if AX == 0000.
;
; Register setup for VLM entry:
; AX, BX, CX, DX from function args
; DS:SI = req
; ES:DI = repl
;
; Extra stack args pushed before calling VLM entry:
; p3, p2, p1
;
; For NWCREQUEST/VLM test:
; AX=function
; BX=numReqFrags
; CX=connid
; DX=numReplyFrags
; DS:SI=reqFragList
; ES:DI=replyFragList
; p1=6, p2=20h, p3=0
_Net_Call_VLM_Raw proc far
push bp
mov bp, sp
sub sp, 4
push ds
push si
push di
push es
mov ax, 7A20h
xor bx, bx
int 2Fh
or ax, ax
jz vlm_raw_found
mov ax, 88FFh
jmp short vlm_raw_done
vlm_raw_found:
; save VLM entry ES:BX in stack locals
mov [bp-4], bx
mov ax, es
mov [bp-2], ax
; load caller-requested registers
mov ax, [bp+6]
mov bx, [bp+8]
mov cx, [bp+10]
mov dx, [bp+12]
lds si, dword ptr [bp+14]
les di, dword ptr [bp+18]
push word ptr [bp+26]
push word ptr [bp+24]
push word ptr [bp+22]
call dword ptr [bp-4]
vlm_raw_done:
pop es
pop di
pop si
pop ds
mov sp, bp
pop bp
ret
_Net_Call_VLM_Raw endp
; int C32_LoadNios_Probe(UI axfunc, void *outbuf)
;
; 16-bit object, but captures 32-bit ESI and ECX using manual 386 opcodes.
; This keeps the OMF/linker in 16-bit mode while still reading Client32/NIOS
; values returned by:
; INT 2F AX=D8C1
;
; outbuf:
; +00 word AX after INT 2F
; +02 dword ESI after INT 2F
; +06 dword ECX after INT 2F
; +0A word BX
; +0C word CX low
; +0E word DX
; +10 word SI low
; +12 word DS
; +14 word ES
_C32_LoadNios_Probe proc far
push bp
mov bp, sp
push ds
push es
push si
push di
; xor ecx, ecx
db 66h, 33h, 0C9h
; xor esi, esi
db 66h, 33h, 0F6h
mov ax, [bp+6]
int 2Fh
push ds
push es
push si
push cx
push bx
push dx
push ax
les di, dword ptr [bp+8]
; restore AX result into AX and store word at out+0
pop ax
mov es:[di+0], ax
; Store ESI dword at es:[di+2].
; Encoding: ES override + operand-size prefix + MOV r/m32,r32
; mov es:[di+02], esi = 26 66 89 75 02
db 26h, 66h, 89h, 75h, 02h
; Store ECX dword at es:[di+6].
; mov es:[di+06], ecx = 26 66 89 4Dh 06
db 26h, 66h, 89h, 4Dh, 06h
pop dx
pop bx
pop cx
mov es:[di+10], bx
mov es:[di+12], cx
mov es:[di+14], dx
pop ax ; saved SI
mov es:[di+16], ax
pop ax ; saved ES
pop bx ; saved DS
mov es:[di+18], bx
mov es:[di+20], ax
pop di
pop si
pop es
pop ds
pop bp
xor ah, ah
ret
_C32_LoadNios_Probe endp
; int C32_GetFunc_Probe(char *name, void *outbuf)
;
; 16-bit OMF Client32 function resolver probe.
; This mimics C32BEGINUSE for one function name:
; INT 2F AX=D8C1
; save ESI as far pointer to __Nios+8 function resolver
; push name segment
; push name offset
; push 0
; push 0
; call far [ESI]
; add sp,8
;
; outbuf:
; +00 word load AX from INT2F
; +02 dword ESI from INT2F
; +06 dword ECX from INT2F
; +0A word resolver return AX
; +0C word resolver return DX
; +0E word BX
; +10 word CX
_C32_GetFunc_Probe proc far
push bp
mov bp, sp
sub sp, 4
push ds
push es
push si
push di
; clear ECX/ESI
db 66h, 33h, 0C9h
db 66h, 33h, 0F6h
mov ax, 0D8C1h
int 2Fh
; save ESI dword to [bp-4]
db 66h, 89h, 76h, 0FCh
push ax ; save load AX
; call resolver only if AX == 0
or ax, ax
jne c32get_store_fail
push word ptr [bp+8] ; name segment
push word ptr [bp+6] ; name offset
push 0
push 0
call dword ptr [bp-4]
add sp, 8
jmp short c32get_store
c32get_store_fail:
xor dx, dx
xor ax, ax
c32get_store:
push dx
push ax
les di, dword ptr [bp+10]
pop ax ; resolver AX
pop dx ; resolver DX
pop bx ; load AX saved in BX temporarily
mov es:[di+0], bx
; Store ESI dword at out+2: ES override + operand prefix
db 26h, 66h, 89h, 75h, 02h
; Store ECX dword at out+6
db 26h, 66h, 89h, 4Dh, 06h
mov es:[di+10], ax
mov es:[di+12], dx
mov es:[di+14], bx
mov es:[di+16], cx
pop di
pop si
pop es
pop ds
mov sp, bp
pop bp
xor ah, ah
ret
_C32_GetFunc_Probe endp
; int C32_CallVersion_Nios_Probe(void *outbuf)
;
; Safe Client32 version call using the exact d32wrap convention:
; 1) INT 2F AX=D8C1
; 2) use ESI resolver to resolve "CLIENT32GetVersion"
; 3) call ECX trampoline, not the function pointer directly:
; push 0
; push 0
; push fn_seg
; push fn_off
; call ECX
; add sp,8
;
; outbuf:
; +00 load AX
; +02 resolver off
; +04 resolver seg
; +06 trampoline off
; +08 trampoline seg
; +0A fn off
; +0C fn seg
; +0E call AX
; +10 call DX
; +12 flags
_C32_CallVersion_Nios_Probe proc far
push bp
mov bp, sp
sub sp, 12
push ds
push es
push si
push di
pushf
; clear ECX/ESI
db 66h, 33h, 0C9h
db 66h, 33h, 0F6h
mov ax, 0D8C1h
int 2Fh
; save ESI resolver at [bp-4]
db 66h, 89h, 76h, 0FCh
; save ECX trampoline at [bp-8]
db 66h, 89h, 4Eh, 0F8h
push ax ; load AX for output
or ax, ax
jne c32ver_fail
push cs
push offset c32ver_name
push 0
push 0
call dword ptr [bp-4]
add sp, 8
; resolver returns DX:AX function pointer
mov [bp-12], ax
mov [bp-10], dx
or ax, dx
je c32ver_fail
; d32wrap _CLIENT32GetVersion convention:
push 0
push 0
push word ptr [bp-10]
push word ptr [bp-12]
call dword ptr [bp-8]
add sp, 8
pushf
push dx
push ax
jmp short c32ver_store
c32ver_fail:
xor dx, dx
xor ax, ax
pushf
push dx
push ax
c32ver_store:
les di, dword ptr [bp+6]
pop ax ; call AX
pop dx ; call DX
pop bx ; flags
pop cx ; load AX
mov es:[di+0], cx
mov cx, word ptr [bp-4]
mov es:[di+2], cx
mov cx, word ptr [bp-2]
mov es:[di+4], cx
mov cx, word ptr [bp-8]
mov es:[di+6], cx
mov cx, word ptr [bp-6]
mov es:[di+8], cx
mov cx, word ptr [bp-12]
mov es:[di+10], cx
mov cx, word ptr [bp-10]
mov es:[di+12], cx
mov es:[di+14], ax
mov es:[di+16], dx
mov es:[di+18], bx
popf
pop di
pop si
pop es
pop ds
mov sp, bp
pop bp
xor ah, ah
ret
c32ver_name db 'CLIENT32GetVersion',0
_C32_CallVersion_Nios_Probe endp
; int C32_MapLock_Probe(void *ptr, UI len, void *outbuf)
;
; Probe d32wrap.o __MapLockFlat / __UnlockFlat:
; INT 2F AX=D8C1
; ESI resolver returned by D8C1 is used with command 2 and 3:
; push len_hi
; push len_lo
; push seg
; push off
; push 0
; push 2
; call ESI ; returns flat DX:AX
;
; push len_hi
; push len_lo
; push flat_hi
; push flat_lo
; push 0
; push 3
; call ESI ; unlock
;
; outbuf:
; +00 load AX
; +02 ESI off
; +04 ESI seg
; +06 map AX low
; +08 map DX high
; +0A unlock AX
; +0C unlock DX
_C32_MapLock_Probe proc far
push bp
mov bp, sp
sub sp, 8
push ds
push es
push si
push di
; clear ECX/ESI
db 66h, 33h, 0C9h
db 66h, 33h, 0F6h
mov ax, 0D8C1h
int 2Fh
; save ESI resolver at [bp-4]
db 66h, 89h, 76h, 0FCh
push ax ; load AX
or ax, ax
jne mapflat_fail
; MapLockFlat(ptr, len)
push 0
push word ptr [bp+10] ; len
push word ptr [bp+8] ; ptr seg
push word ptr [bp+6] ; ptr off
push 0
push 2
call dword ptr [bp-4]
add sp, 0cH
; save mapped flat DX:AX at [bp-8]
mov word ptr [bp-8], ax
mov word ptr [bp-6], dx
; UnlockFlat(flat, len)
push 0
push word ptr [bp+10] ; len
push dx
push ax
push 0
push 3
call dword ptr [bp-4]
add sp, 0cH
jmp short mapflat_store
mapflat_fail:
xor dx, dx
xor ax, ax
mov word ptr [bp-8], ax
mov word ptr [bp-6], dx
mapflat_store:
les di, dword ptr [bp+12]
mov bx, ax ; unlock AX
mov cx, dx ; unlock DX
pop ax ; load AX
mov es:[di+0], ax
mov ax, word ptr [bp-4]
mov es:[di+2], ax
mov ax, word ptr [bp-2]
mov es:[di+4], ax
mov ax, word ptr [bp-8]
mov es:[di+6], ax
mov ax, word ptr [bp-6]
mov es:[di+8], ax
mov es:[di+10], bx
mov es:[di+12], cx
pop di
pop si
pop es
pop ds
mov sp, bp
pop bp
xor ah, ah
ret
_C32_MapLock_Probe endp
; int C32_OpenRef_Probe(UI refLo, UI refHi, void *outbuf)

1672
nwtests.c

File diff suppressed because it is too large Load Diff

View File

@@ -328,7 +328,7 @@ int putglobenv(char *option)
}
search=nextp;
}
/* nicht gefunden , nun eintragen, falls mglich */
/* nicht gefunden , nun eintragen, falls m<EFBFBD>glich */
if (*(equal+1) && optionlen < maxenvsize - aktenvsize) {
strcpy(search, option);
*(search+optionlen+1) = '\0'; /* letzter Eintrag '\0' nicht vergessen */