User Tools

Site Tools


blog:pushbx:2024:0428_late_april_work

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

blog:pushbx:2024:0428_late_april_work [2024-04-28 17:47:43 +0200 Apr Sun] (current)
ecm created
Line 1: Line 1:
 +====== Late April work ======
 +
 +
 +**2024-04-28**
 +
 +I didn't upload the prior blog post yet as of the time of this writing. Oh well.
 +
 +This week I worked some on ACEGALS, lDebug, and the MS-DOS v4.01 sources newly released as free software.
 +
 +
 +===== ACEGALS =====
 +
 +The CHG definition [[https://hg.pushbx.org/ecm/acegals/rev/ad9d87a6dc0e|now lists that CHGed registers are call-clobbered]] whereas those not listed in a CHG nor OUT block (when a CHG block exists) are call-preserved. These terms are [[https://stackoverflow.com/questions/9268586/what-are-callee-and-caller-saved-registers/56178078#56178078|from stackoverflow's Peter Cordes]].
 +
 +
 +===== lDebug =====
 +
 +  * Display BYTE/WORD/DWORD size keywords within square brackets for displacement sizes if needed in the disassembler (to ensure a successful roundtrip) ([[https://hg.pushbx.org/ecm/ldebug/rev/0b94a6d37b41|1]], [[https://hg.pushbx.org/ecm/ldebug/rev/d15b39f854cb|2]], [[https://hg.pushbx.org/ecm/ldebug/rev/a056ee45828c|3]], [[https://hg.pushbx.org/ecm/ldebug/rev/eba4ac32374e|4]])
 +  * [[https://hg.pushbx.org/ecm/ldebug/rev/d1074ddf490d|Allow MODRM keywords in assembler operands]] to force assembler to pick a form in which this operand is a ModR/M operand
 +  * [[https://hg.pushbx.org/ecm/ldebug/rev/dcfa98a527c0|OP_X operand type to extend the space of possible operand types]] (after OP_X an OPX_ type follows, which can utilise the full 8 bits)
 +  * [[https://hg.pushbx.org/ecm/ldebug/rev/fb035d823316|Support AFORMAT commands ON, OFF, and TOGGLE]] (and display status on plain AFORMAT)
 +  * Display MODRM keywords in disassembler when needed
 +  * [[https://hg.pushbx.org/ecm/ldebug/rev/1f577a9799e2|Read SIB byte using a new function and flag]], to support MODRM keyword checks reading it early
 +  * mktables: [[https://hg.pushbx.org/ecm/ldebug/rev/26c18280b481|Increase maximum line length]] to 256 Bytes
 +  * instr.set: [[https://hg.pushbx.org/ecm/ldebug/rev/ee8d326028d6|Avoid swapping XCHG operand order]] between assembler and disassembler, use same order as NASM/NDISASM
 +  * [[https://hg.pushbx.org/ecm/ldebug/rev/75a67f495f34|Add a DAO flag to hide the MODRM keywords]]
 +  * [[https://hg.pushbx.org/ecm/ldebug/rev/b918a7aa7f7a|Avoid displaying two MODRM keywords]] for same operand
 +  * [[https://hg.pushbx.org/ecm/ldebug/rev/9fb597347c80|Add DAO flag to disassemble LOOP with ASIZE keyword using the NASM style second operand]] (CX or ECX)
 +  * Assembler fix: [[https://hg.pushbx.org/ecm/ldebug/rev/93c3abcbc119|Skip whitespace after calling aaconvindex]]
 +  * Disassembler: [[https://hg.pushbx.org/ecm/ldebug/rev/89046bd14752|Display SIB scale=00b (times 1) as "*1"]] rather than hiding it
 +  * Assembler: [[https://hg.pushbx.org/ecm/ldebug/rev/7feb11a5cd36|Do not optimise index "*1" to a Base addressing mode]], to allow roundtrip (like NASM's NOSPLIT mode)
 +  * mktables: [[https://hg.pushbx.org/ecm/ldebug/rev/23cc011ed951|Allow line continuation]] with a trailing backslash
 +  * [[https://hg.pushbx.org/ecm/ldebug/rev/90fc14e78240|Add an assembler reference chapter]] to the manual
 +
 +
 +==== In detail: MODRM keyword detection ====
 +
 +As opposed to [[https://hg.pushbx.org/ecm/ldebug/rev/d1074ddf490d|the assembler]], it is somewhat difficult for the **dis**assembler to detect when it should display a MODRM keyword. The first trick was [[https://hg.pushbx.org/ecm/ldebug/rev/dcfa98a527c0|to add the OP_X operand type extension]], so that we don't have to worry about overflowing [[https://hg.pushbx.org/ecm/ldebug/file/58a82dd92d49/source/debug.asm#l1540|the 63 allowed sizeless operand types]].
 +
 +Then it came down to inserting a number of (extended) operand types [[https://hg.pushbx.org/ecm/ldebug/rev/2924fb102503|which check]] for [[https://hg.pushbx.org/ecm/ldebug/rev/16cf3d53c632|certain conditions]], such as the operand being for a word or dword sized register (for inc and dec), or the other operand (in the reg/spare field) being one of the accumulator registers (al, ax, eax) and the operand being a memory address that consists only of a disp16 or disp32 without any address registers (for mov).
 +
 +Some of the checks are only for the ModR/M operand to encode a register, this is [[https://hg.pushbx.org/ecm/ldebug/rev/cf95e0fc2ed5|for push, pop]], and [[https://hg.pushbx.org/ecm/ldebug/rev/ae61f52747c0|forms of mov]] and [[https://hg.pushbx.org/ecm/ldebug/rev/ae61f52747c0|ALU instructions]] that wouldn't be selected by default when assembling with two registers. A mov with immediate source and ModR/M register destination also takes this OPX type.
 +
 +Initially I thought I could get away without a check for a MODRM keyword already having been displayed. However, it turned out that ''xchg ax, modrm ax'' would have the disassembler display two MODRM keywords because both the "this operand is ax" check and the "the other operand is ax" check for xchg did match. So [[https://hg.pushbx.org/ecm/ldebug/rev/b918a7aa7f7a|I enabled the already displayed check]].
 +
 +I'd [[https://hg.pushbx.org/ecm/ldebug/rev/c62ca9aa8786|previously written this]] when I [[https://hg.pushbx.org/ecm/ldebug/rev/813e885aa138|added two different checks for the same form of mov]], however in that case I noticed only one of them can match at the same time. Namely, one checking for a register and the other for a memory operand (with just disp16/disp32, and other operand is al/ax/eax).
 +
 +Two different operands can never both be flagged with a MODRM keyword because only one operand can be a ModR/M operand and the keyword is only ever displayed for ModR/M operands.
 +
 +
 +===== MS-DOS v4.01 source release =====
 +
 +This week, [[https://cloudblogs.microsoft.com/opensource/2024/04/25/open-sourcing-ms-dos-4-0/|the MS-DOS version 4.01 sources were released as free software]], along with all the tools needed to re-build the entire release (as binaries only). Of course I immediately played with it some.
 +
 +<blockquote>
 +ecm says:
 +April 26, 2024 at 11:24 pm
 +
 +The line endings actually were problematic for nosrvbld.exe and for exe2bin which has its stdin redirected to supply a default answer to a prompt for a relocation segment (done using int 21h service 0Ah).
 +<cite>https://www.os2museum.com/wp/how-not-to-release-historic-source-code/#comment-381254</cite>
 +</blockquote>
 +
 +<blockquote>
 +ecm says:
 +April 28, 2024 at 11:21 am
 +
 +@felsqualle
 +
 +That’s me. The commands don’t really “fix” things, especially not select. They just make it so the build can finish. The sed avoids the too long assembly source lines. The unix2dos fixes the files that come out of git with LF line endings (at least on Linux). When I made these adjustments I didn’t even know how broken select is. Probably someone will have to identicalise select using a known good build to restore the correct text.
 +<cite>https://www.os2museum.com/wp/how-not-to-release-historic-source-code/#comment-381457</cite>
 +</blockquote>
 +
 +<blockquote>
 +I had similar errors, in mapper/getmsg.asm, select/select2.asm, and 
 +select/usa.inf
 +
 +For me these turned out to be errors involving a single-byte character 
 +being expanded to a three-byte UTF-8 encoded value. When nearly a whole 
 +line (of 80 columns) is filled with these EF BF BD strings then MASM 
 +(the version shipped with the repo) doesn't like the total line length 
 +in bytes. I eventually fixed this by running: (After manually deleting a 
 +few lines to work around the problem.)
 +
 +''sed -i -re 's/\xEF\xBF\xBD|\xC4\xBF|\xC4\xB4/#/g' FILENAMES...''
 +
 +I had many more errors, starting with nosrvbld.exe running on eg 
 +boot/boot.skl complaining it couldn't find something. The something was 
 +named as a bunch of gibberish text however. This, and some other 
 +problems, turned out to be because git and/or Microsoft spat out text 
 +files with LF line endings whereas many of the DOS tools expect CR LF 
 +line endings. The following command worked for me:
 +
 +''find -iname '*.bat' -o -iname '*.asm' -o -iname '*.skl' -o -iname 
 +'zero.dat' -o -iname 'locscr' | xargs unix2dos -f''
 +
 +(The zero.dat and locscr files are used to redirect numbers into 
 +exe2bin's relocation number prompt. Failure to unix2dos those ended up 
 +hanging dosemu2 and/or ConnectBot, and spamming notifications to 
 +ConnectBot. Likely related to the old problem of int 21h service 0Ah not 
 +properly detecting and handling an EOF.)
 +
 +To successfully compile the C program parts, I had to fix the setenv.bat 
 +script (apart from using another drive) to point to the headers and 
 +libraries that actually ship with the repo:
 +
 +<code>$ cat src/e.bat
 +@echo off
 +echo setting up system to build the MS-DOS 4.01 SOURCE BAK...
 +set CL=
 +set LINK=
 +set MASM=
 +set COUNTRY=usa-ms
 +set BAKROOT=e:
 +rem BAKROOT points to the home drive/directory of the sources.
 +set LIB=%BAKROOT%\src\tools\bld\lib
 +set INIT=%BAKROOT%\src\tools
 +set INCLUDE=%BAKROOT%\src\tools\bld\inc
 +set PATH=%BAKROOT%\src\tools;%PATH%</code>
 +
 +To boot the kernel, I used lDebug's command BOOT PROTOCOL MSDOS6 hda1/ 
 +to boot off a file system that I created using my bootimg.asm script. I 
 +had to set -D_OEM_NAME="'IBM  3.1'" to make the kernel accept my file 
 +system; with my default it calculated a wrong (at least) Sectors per 
 +Cluster value of 4 and failed to load the DOS module. This is my command 
 +line to create the image:
 +
 +''nasm -I ../../lmacros/ -I ../../bootimg/ ../../bootimg/bootimg.asm 
 +-D_PAYLOADFILE="io.sys,msdos.sys,mem.exe,sys.com,../../ldebug/bin/callver.com,::rename,../../../.dosemu/drive_c/command.com,freecom.exe,command.com" 
 +-o disk.img -D_MEDIAID=0F8h -D_BPE=16 -D_ERROR_SMALL32=0 -D_SPF=256 
 +-D_SPI=128000 -D_SPC=2 -D_MBR -D_MBR_PART_TYPE=fat16_chs 
 +-D_CHS_HEADS=128 -D_CHS_SECTORS=32 -D_OEM_NAME="'IBM  3.1'"''
 +
 +Regards,
 +ecm
 +<cite>https://sourceforge.net/p/freedos/mailman/message/58765259/</cite>
 +</blockquote>
 +
 +{{tag>acegals ldebug msdos msdos4}}
 +
 +
 +~~DISCUSSION~~
  
blog/pushbx/2024/0428_late_april_work.txt · Last modified: 2024-04-28 17:47:43 +0200 Apr Sun by ecm