Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - kerravon

Pages: [1]
1
Programming / native mainframe mini-clone
« on: September 07, 2025, 12:59:53 pm »
I have previously posted here and mentioned that PDOS/386 from pdos.org supports the OS/2 API to a limited extent (enough to run C90-compliant programs).

I have 3 distinct (complete rewrites - sort of) versions of PDOS. One is PDOS-generic - which is portable.

So to put that "portable" claim to the test, I have it running on multiple environments, including the mainframe (z/Arch).

And because it turns out that the basic APIs can be written in terms of C90 (sort of), e.g. DosRead() calling fread() on another environment, it stands to reason that it should be possible to get OS/2 working on z/PDOS-generic.

It's not as simple as it sounds (mainly getting the tools
into shape), but it was indeed possible.

Here is what it looks like (not especially that the "LX" is
in EBCDIC, which is what the mainframe traditionally
uses):

enter a command
hexdump os2.exe 0 100
about to call app at address 04F0C680
000000  D4E90000 00000000 04000000 00000000  MZ..............
000010  00000000 00000000 40000000 00000000  ........ .......
000020  00000000 00000000 00000000 00000000  ................
000030  00000000 00000000 00000000 40000000  ............ ...
000040  D3E70000 00000000 02000100 00000000  LX..............
000050  00020000 13000000 01000000 14C80000  .............H..
000060  02000000                             ....
return from app is hex 0

enter a command
os2 abc def
about to call app at address 04F2D3E4
welcome to pdptest
main function is at 04F21ED0
allocating 10 bytes
m1 is 04ECE7E4
allocating 20 bytes
m2 is 04ECE834
stack is around 00080E78
printing arguments
argc = 3
arg 0 is <os2>
arg 1 is <abc>
arg 2 is <def>
return from app is hex 0

enter a command


Note that this is native z/Arch (or S/370) instructions, not 80386.

I also have the Windows API, including msvcrt.dll, for smaller executables.

Available at https://pdos.org/zpg.zip

You'll need an appropriate emulator (unless you have real hardware) - I provide Hercules/380 and mfemul.


I believe OS/2 was ported to other non-80836 environments, but not the mainframe.

If anyone is interested and wants more information, please let me know.

BFN. Paul.

2
Programming / new gcc toolchain
« on: March 14, 2024, 03:46:07 pm »
I spent a lot of effort making the GCC 3.2.3 source code
C90-compliant instead of being riddled with POSIX stuff,
in order to allow the compiler to be hosted on the IBM mainframe.

I have now created a makefile for OS/2 that uses itself
to build itself. But it's quite simple to modify if you want
to use some other compiler in order to bootstrap from
source. I created such a makefile for Watcom and
Microsoft C for Windows, but don't have anything for
OS/2 currently (but you can bootstrap on Windows
from source if you want, and then use that to continue
over to OS/2).

Also in the chain are two assemblers (pdas and as86).
Note that as86 is a subset of Microsoft MASM unlike
most other assemblers available (including pdas) that
require some other syntax.

So with standard C90 and standard MASM you can
build everything required. The object code produced
is coff, but the pdld linker will take coff input and
produce an LX binary.

If you are interested, get pdoso.zip from http://pdos.org
and because I don't know how to make parted (see
\devel\parted on the disk) produce a VHD that can be
mounted in Virtualbox for use by OS/2 (I use 128
sector as the starting sector (for 4k alignment), but I
tried changing it to 504 (for both 63 sector multiple and
4k alignment), but that wasn't accepted either. But I
just realized now that maybe it needs me to specify 0C
instead of 0B:

< parted --boot devel\pdos\src\mbr.com mkpart 0x80,0x0b,504,956416 ..\pdos.vhd
---
> parted --boot devel\pdos\src\mbr.com mkpart 0x80,0x0b,128,956416 ..\pdos.vhd

given that it is FAT32.

So on Windows or Linux you need to mount a VHD that
is acceptable to OS/2 and then copy the contents of
pdoso.vhd across.

After that, let's say the new disk is the P drive, you can do:

path %path%;p:\dos
cd \devel\pdos\pdpclib
pdmake -f makefile.sos
(run pdptest abc def if you want)

cd \devel
unzip \misc\custom gcc-stage*
unzip gcc-stage*
del gcc-stage*

cd gcc\gcc
copy config\i386\genfiles (don't forget this step)
pdmake -f os2.mak

I see that "fc" is missing, but no problem, you can:

cd \devel\pdos\pdpclib
ren pdptest.c pdptest.bak
copy ..\util\fc.c pdptest.c
pdmake -f makefile.sos
copy pdptest.exe \dos\fc.exe

cd \devel\gcc\gcc
fc /b \dos\gccwin.exe gcc-new.exe

and have a byte-identical copy of the compiler.

Note that gccwin.exe is a historical name
(EDIT: for this OS/2 LX executable).
I'm planning
on renaming it to gcc386.exe in the future.

Note that I have only compiled the essential binaries
needed to be able to compile anything else you may need.
ie the other stuff in \dos are Windows executables mostly,
so "need" to be replaced, eventually.

I am hoping to replace gccwin.exe with SubC anyway.

Is anyone interested in compilers such that they would
like to assist with this?

A build error (will be fixed next drop) is preventing this
from working:

[P:\devel\pdos\world]pdmake -f worldos2.mak
pdcc -E -D__SUBC__ -U__WIN32__ -D__OS2__ -D__32BIT__ -Dunsigned= -Dlong=int -Dsh
ort=int -Dconst= -Ddouble=int -I ../pdpclib -o world.i world.c
sccwin -S world.i
rm -f world.i
pdas -o world.obj --oformat coff world.s
rm -f world.s
pdld -s --no-insert-timestamp -nostdlib --oformat lx  --stub ../pdpclib/needpdos
.exe -o world.exe ../pdpclib/os2strt.obj world.obj ../pdpclib/pdpos2.lib ../pdpc
lib/os2.lib

[P:\devel\pdos\world]world
hello, world

[P:\devel\pdos\world]


Hopefully by then I have a mountable disk too.

Note that I cherish old targets including i370 unlike
others who like to obsolete old targets. YMMV. So
yeah, I have been patiently plugging away at GCC 3.2.3
(including this latest change), for 20 years, instead of
"keeping up with the Joneses". And all source code is
in C90, not Turtle Graphics or whatever "modern" GCC
is written in these days. Except for the minimal
assembler required in the C library.

All clean 32-bit code too (not a single bit of 16-bit in any
executable on the disk except for the MBR, boot sector and
IO.SYS which aren't used if you are running under OS/2),
and all memory allocated with OBJ_ANY.

BFN. Paul.


P.S. gccwin also rebuilds itself on PDOS/386 - which is
what that pdoso.vhd is. PDOS/386 is a sufficient OS/2
mini-clone for that task.

P.P.S. Let me know if you don't know how to mount a
VHD on either Windows or Linux.

3
Programming / DosDevIOCtl disabling keyboard in VIO mode
« on: March 02, 2024, 09:24:07 am »
Running this program in fullscreen mode works fine.

Running it in a VIO window causes the keyboard to be disabled and I need to use the mouse to reboot (CAD also works to initiate a reboot).

Can someone tell me:

1. Are the results (that I noted as strange) correct operation of the OS/2 functions?

2. Is there a way of getting these functions to work as intended (ie switch to binary mode, then switch back to text mode, as the Physical Device Driver Reference documents as supported functionality)?

Note that the switch to binary mode IS successful - even in the VIO windows - and my real (larger) app does work fine (that app doesn't switch back to text mode until termination time though, so I don't see a problem). It's only after it terminates that I have an issue, which is ironic.

Also note that I am aware of the Kbd* functions that could be used instead, but I don't wish to do thunking (including automated compiler thunking) *in my executable*.

If I use the DosDevIOCtl function, my executable is pure 32-bit. What happens in the doscalls.dll I don't care about. At least nominally I have no insight into that, as it is OS/2 internals, and those internals could change overnight. Also I am not interested in using high memory. This isn't a question about high memory. I will be using standard 32-bit DosOpen and standard 32-bit DosDevIOCtl (ordinal 284 in doscalls.dll or equivalent).

Note that I am using ArcaOS 5.0.8.

Code below.

Thanks. Paul.


wcl386 -bt=os2 -l=os2v2 pdptest.c os2386.lib -"option map"

Code: [Select]
#include <stdio.h>

#define INCL_DOS
#include <os2.h>

int main(void)
{
    ULONG kbdfile;
    static USHORT fileAttr = 0;
    static ULONG newsize = 0;
    ULONG action;
    static ULONG openMode = OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE;
    static ULONG openAction = OPEN_ACTION_OPEN_IF_EXISTS;
    ULONG datalen;
    ULONG parmlen;
    USHORT rc;
    BYTE bb;
    static BYTE oldbb;

    rc = DosOpen((PSZ)"KBD$",
                 &kbdfile,
                 &action,
                 newsize,
                 fileAttr,
                 openAction,
                 openMode,
                 0);
    if (rc != 0)
    {
        return (-1);
    }

    parmlen = 0;
    datalen = sizeof oldbb;
    /* get old input mode */
    rc = DosDevIOCtl(kbdfile,
                4,
                0x71,
                NULL,
                0,
                &parmlen,
                &oldbb,
                sizeof oldbb,
                &datalen);

    printf("rc is %d\n", rc);
    printf("surprisingly, oldmode is already binary %x\n", (int)oldbb);
   
    printf("surprisingly, we need to set binary mode, even though it is already set\n");
    /* set binary mode */
    bb = 0x80;
    parmlen = sizeof bb;
    datalen = 0;
    rc = DosDevIOCtl(kbdfile,
                4,
                0x51,
                &bb,
                sizeof bb,
                &parmlen,
                NULL,
                0,
                &datalen);

    printf("rc is %d\n", rc);
    printf("restoring old (binary) mode is identical and useless and behavior is same\n");
    printf("so setting text mode instead\n");
    oldbb = 0;
    parmlen = sizeof oldbb;
    datalen = 0;
    rc = DosDevIOCtl(kbdfile,
                     4,
                     0x51,
                     &oldbb,
                     sizeof oldbb,
                     &parmlen,
                     NULL,
                     0,
                     &datalen);
    printf("rc is %d\n", rc);
    rc = DosClose(kbdfile);
    printf("rc is %d\n", rc);
    printf("surprisingly, keyboard is now inoperative and you need to use mouse to reboot\n");
    return (0);
}

Pages: [1]