• Please review our updated Terms and Rules here

OS/2 1.x PM16 code matching data

kerravon

Experienced Member
Joined
Oct 31, 2021
Messages
137
I am writing a 16-bit (PM16) version of PDOS-generic using an OS/2 1.x executable as a pseudo-BIOS and running under Windows 2000 (also tried HX dpmild16 under Freedos).

I got a protection violation and thought that I needed the equivalent of mprotect to overcome that. DosQueryMem and DosSetMem seem to do such a thing in OS/2 2.0, but don't seem to exist in OS/2 1.x.

Then I realized that there was no choice - code uses cs while data uses ds and you never execute code using ds, so you always need two separate selectors for a single block of memory if you wish to both execute and read/write. Nor can you even theoretically do a cs override to access data using cs, because you can't alter cs because it is permanently in use for the current code.

So my question is - how do you map an OS/2 1.x data selector to a code selector?

I tried this (as a guess):

x -= (__incr / 2) * 65536UL;

D:\devel\pdos\generic>bios pcomm.exe

bios starting
p is FCC7:0004
first byte of code is CB
incr is 8
entry_point is FCC7:0004
about to execute program
genstart is FCC3:0004

D:\devel\pdos\generic>

but still got a protection violation.

I tried doing an add - same result.

Any ideas?

Note that if I get it working, I will then take action to address the offset of 4 (which should be 0 when I try to execute more substantial code - currently it's just zapped to be a retf).

Thanks. Paul.
 
Protected mode or Presentation Manager? Rather a sizable difference between the two.

IIRC, the correct method for doing that is to copy the data segment into a new code segment with a new selector. Code is code and data is data and never shall the two share a memory address.

If you are using OS/2, you could check the documentation for DosCreateCSAlias. Note the limitations. The following is from an online reference which adds the Family API information.

DosCreateCSAlias​

Bindings: C, MASM
This call creates a code segment alias descriptor for a data segment passed as input.

  • DosCreateCSAlias
    • (DataSelector, CodeSelector)
  • DataSelector (SEL) - input
    • Data segment selector.
  • CodeSelector(PSEL) - output
    • Address where the selector of the code segment alias descriptor is returned.
  • rc (USHORT) - return
    • Return code descriptions are:

    • NO_ERROR 5
      • ERROR_ACCESS_DENIED
      • Remarks
      • A selector returned by a call to DosAllocSeg with no sharing options specified can be used as the data segment specified with DosCreateCSAlias. However, to be CS alias, the segment must be a privilege level 2 or privilege level 3 non-shared segment.
      A CS alias segment must be exclusively accessible by the process and cannot be a huge segment. Selectors of shared memory segments and dynamically linked global data segments cannot be used as input for DosCreateCSAlias.
      The code segment selector returned by DosCreateCSAlias is valid for CS. If a procedure is stored in the data segment, it can be called using the CS alias. The procedure may be called from privilege level 3 or I/O privilege level.
      Use DosFreeSeg to free a CS alias selector created with DosCreateCSAlias. Procedures in the segment can continue to be referenced if the data selector for the aliased segment is passed to DosFreeSeg, because the CS alias selector is not affected. Once both selectors have been passed to DosFreeSeg, the segment is deallocated.

      Family API Considerations
      The returned selector is the segment address of the allocated memory. When the returned selector or the original selector is freed, OS/2 immediately deallocates the block of memory.
 
Last edited:
Protected mode or Presentation Manager? Rather a sizable difference between the two.

IIRC, the correct method for doing that is to copy the data segment into a new code segment with a new selector. Code is code and data is data and never shall the two share a memory address.

If you are using OS/2, you could check the documentation for DosCreateCSAlias. Note the limitations. The following is from an online reference which adds the Family API information.

Thanks for that! I would never have figured that out.


I was able to get PDOS-generic working (still kludged though) using that function.

You can see it being used here:


and here is it running:

D:\devel\pdos\generic>bios pcomm.exe

bios starting
about to execute program
welcome to pcomm
type help for help

enter a command
help
commands that might be available are:
exit, type, dir, md, rd, cd, date, time, del, copy
fill, fzap

enter a command
date
Sat Dec 16 11:03:11 2023

enter a command
exit
return from called program is 0
press enter to exit

bios exiting

D:\devel\pdos\generic>
 
Back
Top