diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d24f18..8086fa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,65 +1,114 @@ -################################# -# Project -############## +# DOS utilities for mars-nwe. +# +# Default mode: install a prebuilt net.exe from this source tree. This keeps the +# normal mars-nwe build independent from Open Watcom. +# +# Maintainer mode: configure with -DMARS_NWE_BUILD_DOSUTILS=ON to rebuild +# net.exe with Open Watcom v2 on Linux. -################################# -# Dependencies -############## - -################################# -# Compiler Switches -############## - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_SOURCE_DIR}/include - ${CMAKE_BINARY_DIR}/include +set(MARS_DOSUTILS_NET_EXE + "${CMAKE_CURRENT_SOURCE_DIR}/net.exe" + CACHE FILEPATH "Prebuilt DOS net.exe used for installation when MARS_NWE_BUILD_DOSUTILS is OFF" ) -if (CMAKE_SYSTEM_NAME MATCHES Linux) - add_definitions( - -DLINUX -D_GNU_SOURCE -Dsignal=__sysv_signal - ) -endif (CMAKE_SYSTEM_NAME MATCHES Linux) +set(MARS_DOSUTILS_PUBLIC_TOOLS + net + login + profile + spawn + passwd + path + pathins + pathdel + map + mapdel + logout + capture + endcap +) -add_definitions( - -D_VERS_H_=\"${VERSION_MAJOR}\" - -D_VERS_L_=\"${VERSION_MINOR}\" - -D_VERS_P_=\"${VERSION_PATCH}\" +# Do not install slist.exe yet: func_slist() is empty and SLIST is disabled in net.c. +# Do not install tests/debug by default either; they are developer-only helpers. + +if(MARS_NWE_BUILD_DOSUTILS) + find_package(OpenWatcom REQUIRED) + + set(DOSUTILS_C_SOURCES + net.c + tools.c + netcall.c + ncpcall.c + login.c + map.c + nwcrypt.c + nwdebug.c + nwtests.c + capture.c ) -################################# -# Source Files -############## + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/kern.obj" + COMMAND "${OPENWATCOM_WASM}" + -q + -zq + -fo="${CMAKE_CURRENT_BINARY_DIR}/kern.obj" + "${CMAKE_CURRENT_SOURCE_DIR}/kern_wasm.asm" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/kern_wasm.asm" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + VERBATIM + ) -#add_executable( net logon.c ... ) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/net.exe" + COMMAND "${OPENWATCOM_WCL}" + -q + -zq + -bt=dos + -ml + -0 + -fe="${CMAKE_CURRENT_BINARY_DIR}/net.exe" + ${DOSUTILS_C_SOURCES} + "${CMAKE_CURRENT_BINARY_DIR}/kern.obj" + DEPENDS + ${DOSUTILS_C_SOURCES} + "${CMAKE_CURRENT_BINARY_DIR}/kern.obj" + net.h + kern.h + nwcrypt.h + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + VERBATIM + ) -################################# -# Linking -############## + add_custom_target(dosutils_net ALL + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/net.exe" + ) -################################# -# Install Files -############## + set(MARS_DOSUTILS_NET_EXE "${CMAKE_CURRENT_BINARY_DIR}/net.exe") +else() + if(NOT EXISTS "${MARS_DOSUTILS_NET_EXE}") + message(FATAL_ERROR + "Prebuilt DOS utility missing: ${MARS_DOSUTILS_NET_EXE}. " + "Either commit net.exe into dosutils or configure with " + "-DMARS_NWE_BUILD_DOSUTILS=ON and Open Watcom installed." + ) + endif() +endif() -# install the system utils -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME login.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME profile.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME spawn.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME passwd.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME path.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME pathins.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME pathdel.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME map.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME mapdel.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME logout.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME slist.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME capture.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public RENAME endcap.exe) - -# and the minimal login utils -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/login RENAME login.exe) -install(FILES net.exe DESTINATION ${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/login RENAME map.exe) +foreach(tool IN LISTS MARS_DOSUTILS_PUBLIC_TOOLS) + if(tool STREQUAL "net") + install(FILES "${MARS_DOSUTILS_NET_EXE}" + DESTINATION "${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public") + else() + install(FILES "${MARS_DOSUTILS_NET_EXE}" + DESTINATION "${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/public" + RENAME "${tool}.exe") + endif() +endforeach() +install(FILES "${MARS_DOSUTILS_NET_EXE}" + DESTINATION "${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/login" + RENAME login.exe) +install(FILES "${MARS_DOSUTILS_NET_EXE}" + DESTINATION "${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/login" + RENAME map.exe) diff --git a/kern_wasm.asm b/kern_wasm.asm new file mode 100644 index 0000000..4081630 --- /dev/null +++ b/kern_wasm.asm @@ -0,0 +1,216 @@ +; kern_wasm.asm +; +; Open Watcom WASM/MASM-syntax port of the old TASM IDEAL kern.asm. +; Intended for 16-bit DOS large memory model builds on Linux with Open Watcom v2. +; +; Keep kern.asm as the historical TASM source and use this file for the +; reproducible Open Watcom build. + +.286 +.model large + +.data +enterIPX dd 0 + +.code + +public _IPXinit +public _IPXopen_socket +public _IPXclose_socket +public _IPXlisten +public _xmemmove +public _Net_Call + +_IPXinit proc far + push bp + mov bp, sp + push ds + push si + push di + + mov ax, 7A00h + int 2Fh + cmp al, 0FFh + jne ipxinit_done + + mov cx, @data + mov ds, cx + mov word ptr enterIPX, di + mov ax, es + mov word ptr enterIPX+2, ax + mov al, 1 + +ipxinit_done: + mov ah, 0 + + pop di + pop si + pop ds + pop bp + ret +_IPXinit endp + +_xmemmove proc far + push bp + mov bp, sp + + ; far procedure stack layout, large model: + ; [bp+0] old bp + ; [bp+2] return offset + ; [bp+4] return segment + ; [bp+6] z offset + ; [bp+8] z segment + ; [bp+10] q offset + ; [bp+12] q segment + ; [bp+14] nmbr + + cli + mov cx, [bp+14] + or cx, cx + jz xmem_done + + push ds + push si + push di + pushf + + lds si, fword ptr [bp+10] + les di, fword ptr [bp+6] + cmp di, si + jl xmem_forward + + std + dec cx + add di, cx + add si, cx + inc cx + jmp xmem_copy + +xmem_forward: + cld + +xmem_copy: + rep movsb + + popf + pop di + pop si + pop ds + +xmem_done: + pop bp + sti + ret +_xmemmove endp + +_IPXopen_socket proc far + push bp + mov bp, sp + push ds + push si + push di + + ; int IPXopen_socket(UI sock, int live) + mov ax, [bp+8] ; live + mov dx, [bp+6] ; sock + mov bx, @data + mov ds, bx + mov bx, 0 + call dword ptr enterIPX + + cmp al, 0FFh + jne ipxopen_not_already + mov ax, -1 ; socket already open + jmp ipxopen_done + +ipxopen_not_already: + cmp al, 0FEh + jne ipxopen_ok + mov ax, -2 ; socket table full + jmp ipxopen_done + +ipxopen_ok: + mov ax, dx + +ipxopen_done: + pop di + pop si + pop ds + pop bp + ret +_IPXopen_socket endp + +_IPXclose_socket proc far + push bp + mov bp, sp + push ds + push si + push di + + ; void IPXclose_socket(UI sock) + mov dx, [bp+6] + mov bx, @data + mov ds, bx + mov bx, 1 + call dword ptr enterIPX + + pop di + pop si + pop ds + pop bp + ret +_IPXclose_socket endp + +_IPXlisten proc far + push bp + mov bp, sp + push ds + push si + push di + + ; int IPXlisten(ECB *ecb) + les si, fword ptr [bp+6] + mov bx, @data + mov ds, bx + mov bx, 4 + call dword ptr enterIPX + + pop di + pop si + pop ds + pop bp + mov ah, 0 + ret +_IPXlisten endp + +_Net_Call proc far + push bp + mov bp, sp + + ; int Net_Call(UI func, void *req, void *repl) + ; [bp+6] func + ; [bp+8] req offset + ; [bp+10] req segment + ; [bp+12] repl offset + ; [bp+14] repl segment + mov ax, [bp+6] + + push ds + push si + push di + pushf + + lds si, fword ptr [bp+8] + les di, fword ptr [bp+12] + int 21h + + popf + pop di + pop si + pop ds + pop bp + mov ah, 0 + ret +_Net_Call endp + +end