[comp.os.os2.programmer] Serial Port Problems

tanith@csd4.csd.uwm.edu (Michael D Kretzer) (12/14/90)

I vaguely remeber someone sending a post concerning an "easily available"
patch to allow OS/2 to recognize more than 2 serial ports on a non-PS/2
machine, but (s)he did not give a source for this patch.  Did I miss it
or something?

rommel@lan.informatik.tu-muenchen.dbp.de (Kai-Uwe Rommel) (12/14/90)

In article <8331@uwm.edu> tanith@csd4.csd.uwm.edu (Michael D Kretzer) writes:
>I vaguely remeber someone sending a post concerning an "easily available"
>patch to allow OS/2 to recognize more than 2 serial ports on a non-PS/2
>machine, but (s)he did not give a source for this patch.  Did I miss it
>or something?

No, I am also still waiting for these patches.

Kai Uwe Rommel

--
/* Kai Uwe Rommel, Munich ----- rommel@lan.informatik.tu-muenchen.dbp.de */

DOS ... is still a real mode only non-reentrant interrupt
handler, and always will be.                -Russell Williams (MS)

cfreas@eeserv1.ic.sunysb.edu (Terry Freas) (12/14/90)

In article <8331@uwm.edu> tanith@csd4.csd.uwm.edu (Michael D Kretzer) writes:
>I vaguely remeber someone sending a post concerning an "easily available"
>patch to allow OS/2 to recognize more than 2 serial ports on a non-PS/2
>machine, but (s)he did not give a source for this patch.  Did I miss it
>or something?

Someone on Fidonet has succesfully patched the COM driver to support n
ports.  I wanted to post the specifics to Kai Rommel's original posting,
but my Fidonet BBS went down right after that.  So, if anyone has a Fido
connection, that's where to look.

-- 
Jeremy Wohl / wohl@max.physics.sunysb.edu / cfreas@csserv1.ic.sunysb.edu

d9mikael@dtek.chalmers.se (Mikael Wahlgren) (12/16/90)

In article <8331@uwm.edu> tanith@csd4.csd.uwm.edu (Michael D Kretzer) writes:
>I vaguely remeber someone sending a post concerning an "easily available"
>patch to allow OS/2 to recognize more than 2 serial ports on a non-PS/2
>machine, but (s)he did not give a source for this patch.  Did I miss it
>or something?

The following patch will require that you use different interrupts for
all serial ports.  I have heard that someone is working on a path which
would allow you to share interrupts.  This patch will allow you to
install 4 serial ports.


Chapter 2:-- The Software side
------------------------------------------------

(The best side, as you can't see smoke from your PC with this ...)

At present when COM01.SYS driver is loaded, it looks in BIOS data tables
to
know if there are COM devices available. The BIOS table consists of four
entries in which at power-up BIOS puts the base addresses of UARTS.
COM01.SYS looks only the first two entries, and when installs himself, it
puts
 zeros in them, to make them unavailable to others ...
The trick is to put two new addresses in this two entries, and load a new
COM
driver, say COM03.SYS, that can use them.

The first job is accomplished with a small device driver. It performs a
very little initialization work and sets the appropriate values in right
places.
The assembly code follows (there are few comments, i know: i removed the
italian ones ...)


[Save this as
COMEXP.DEF]<cut>-----<cut>-----<cut>-----<cut>-----<cut>-----<cut>

LIBRARY COMEXP INITGLOBAL
DATA PRELOAD NONSHARED
CODE PRELOAD
PROTMODE

[Save this as
COMEXP.ASM]<cut>-----<cut>-----<cut>-----<cut>-----<cut>-----<cut>

; Use this to build COMEXP.SYS
;
; MASM COMEXP;
; LINK COMEXP,COMEXP.SYS,nul,os2,COMEXP.DEF

286p
SEQ

COM3base    EQU 03E8h               ; You may need to change this !!!!!
COM3test    EQU COM3base+2
COM4base    EQU 02E8h
COM4test    EQU COM4base+2


ADATA   SEGMENT PARA PUBLIC 'AUTO'

nexthdr         dd      0FFFFFFFFh        ;pointer to next device driver
devattr         dw      8140h             ;attribute flags
stratof         dw      offset strategy   ;offset of strategy routine
entry
reserv1         dw      0
devname         db      'COMEXP00'
reserv2         db      8 dup (0)
devhelp         dd      0                 ;this is where we save the
DevHelp
                                          ;pointer
end_of_data     label   byte              ;the rest isn't needed after
init


initmsg         db      0Dh,0Ah
                db      'COM expander, '
                db      'Copyright (c) 1990, Carlo Adami',0Dh,0Ah
initmsglen      equ     $-offset initmsg

com3msg         db      'COM3 @3E8 Found',0Dh,0Ah
com3msglen      equ     $-offset com3msg

com4msg         db      'COM4 @2E8 Found',0Dh,0Ah
com4msglen      equ     $-offset com4msg

byteswritten    dw      0

ADATA   ENDS

DGROUP  GROUP   ADATA

        extrn   DosWrite:far


CODE      SEGMENT PARA 'CODE'

ASSUME    CS:CODE,DS:ADATA

strategy        proc far
        mov     al,es:[bx+2]           ;examine command code in req packet
        cmp     al,0                   ;"initialize" command
        je      initialize
        mov     word ptr es:[bx+3],0100h
        ret
end_of_code     label   byte           ;the rest isn't needed after init

initialize:
        mov     ax,es:[bx+14]          ;save "DevHlp" call address
        mov     word ptr devhelp,ax
        mov     ax,es:[bx+16]
        mov     word ptr devhelp+2,ax

        push    1
        push    ds
        push    offset initmsg
        push    initmsglen
        push    ds
        push    offset byteswritten
        call    DosWrite

        push    es
        push    di

        cld
        mov     ax, 40h
        mov     es, ax
        mov     di, 0

        mov     dx,COM3test
        in      al,dx
        test    al,0f8h
        jnz     com4
        mov     es:[di],COM3base

        push    1                   ; com3 found
        push    ds
        push    offset com3msg
        push    com3msglen
        push    ds
        push    offset byteswritten
        call    DosWrite

com4:   inc     di
        inc     di
        mov     dx,COM4test
        in      al,dx
        test    al,0f8h
        jnz     fine
        mov     es:[di],COM4base

        push    1                   ; com4 found
        push    ds
        push    offset com4msg
        push    com4msglen
        push    ds
        push    offset byteswritten
        call    DosWrite

fine:   inc     di
        inc     di
        mov     ax, 0           ; cleanup other addresses
        stosw
        mov     ax, 0
        stosw
        pop     di
        pop     es
        mov     word ptr es:[bx+14],offset end_of_code  ;set ending
offsets
        mov     word ptr es:[bx+16],offset end_of_data
        mov     word ptr es:[bx+18],0       ;set other req packet fields
        mov     word ptr es:[bx+20],0
        mov     word ptr es:[bx+3],0100h    ;set status and exit
        ret

strategy endp

CODE
ENDS

end
--<cut>-----<cut>-----<cut>-----<cut>-----<cut>-----<cut>-----<cut>-----<cut>
 

Chapter 3: -- Patches and installation
-----------------------------------------

Now it's the time to build up COM03.SYS.

Boot DOS, copy COM01.SYS to COM03.SYS and use DEBUG to do the following
patches.
Offsets displayed here are from my COM01.SYS, and may be (surely)
different in
 different versions, and i'll try to explain what we are doing so you can
port this patches on other versions, searching for similar code.

1: Set the proper base address and irq mask.
In the following disassemblies the values that must be adjusted are marked
with ^^.

xxxx:23DA 8B 17            MOV     DX,[BX]
xxxx:23DC 0B D2            OR      DX,DX
xxxx:23DE B9 5B 04         MOV     CX,045B
xxxx:23E1 75 03            JNZ     23E6
xxxx:23E3 E9 DF 00         JMP     24C5
xxxx:23E6 C6 44 18 04      MOV     BYTE PTR [SI+18],04
                   ^^                               ^^
xxxx:23EA 81 FA F8 03      CMP     DX,03F8
                ^^ ^^                 ^^^^
xxxx:23EE 74 10            JZ      2400
xxxx:23F0 C6 44 18 03      MOV     BYTE PTR [SI+18],03
                   ^^                               ^^
xxxx:23F4 81 FA F8 02      CMP     DX,02F8
                ^^ ^^                 ^^^^
xxxx:23F8 B9 5A 04         MOV     CX,045A
xxxx:23FB 74 03            JZ      2400
xxxx:23FD E9 C5 00         JMP     24C5
xxxx:2400 89 54 0E         MOV     [SI+0E],DX
xxxx:2403 83 C2 02         ADD     DX,+02

Offset  Original MyPatch  Description
--------------------------------------------
23E9    04       05       IRQ level COM3    (now 5)
23EC    F8 03    E8 03    Base Address COM3 (now 03E8h)

23F3    03       0A       IRQ level COM4    (now 10)
23F6    F8 02    E8 02    Base Address COM4 (now 02E8h)
--------------------------------------------

2: Set device names: A nice thing is to refer to your new COM devices with
standard names. To do this tou can easily replace the '1' and '2' with '3'
and
 '4' in device header section, whose offset i believe is the same in
whatever
version you're are patching.

xxxx:0300  1A 00 FF FF C0 98 00 00-00 00 43 4F 4D 31 20 20  
.........COM1
                                                  ^^
xxxx:0310  20 20 00 00 00 00 00 00-00 00 FF FF FF FF C0 98    
.............
xxxx:0320  09 00 00 00 43 4F 4D 32-20 20 20 20 00 00 00 00   ....COM2   
...
                                ^^
Doing this enables you to use MODE command to set the various parameters
of communications ports, as you can do with the other 'normal' ports.


3: Finally a cosmetic change: To reflect the modifications made, we can
make the
driver display the string 'COM? installed' with the correct value in '?'
place.
I found that this can be obtained by replacing the '31' (ASCII code for
'1')
with '33' (ASCII code for '3') in the following code.

...
xxxx:2360 8B 5D 0E         MOV     BX,[DI+0E]
xxxx:2363 89 1E 50 01      MOV     [0150],BX
xxxx:2367 C6 06 45 0B 31   MOV     BYTE PTR [0B45],31
                      ^^                           ^^
xxxx:236C 00 06 45 0B      ADD     [0B45],AL
xxxx:2370 A3 D7 0B         MOV     [0BD7],AX
xxxx:2373 FE 06 4B 0B      INC     BYTE PTR [0B4B]
xxxx:2377 80 3E 4B 0B 01   CMP     BYTE PTR [0B4B],01
xxxx:237C 75 06            JNZ     2384
xxxx:237E B9 6C 07         MOV     CX,076C


Write modifications and reboot OS/2, eventually after modifying the
config.sys
 file (the right one, not the DOS one !) as following:
.....

DEVICE={path}COM01.SYS          <- this is already there ..
DEVICE={path}COMEXP.SYS
DEVICE={path}COM03.SYS
....

As you can understand easily, these lines MUST be in this order.
Reboot your machine ... and try your new COM ports.


Note:
The MODE command already recognizes COMs from COM1 to COM9.
I suppose its possible repeat the trick more then once, using an
appropriate
COMEXP and COM05.SYS, to install COM5 and COM6 and so on, until IRQ lines
are
available.



This patch is catched from the FIDONET, and I am not responsible in any way
for the functionality and the legality if the patch.


Mikael Wahlgren      d9mikael@dtek.chalmers.se