Hi!

- firstAvailableBuf far pointer changed to HMAuserarea offset.
- AllocateHMASpace() renamed to freeHMAbuffers().
- config.c: some source cleanup and code optimization.
- proto.h: added nice/smart macros; later may/should be moved into portab.h.
- *.h: some source cleanup - removed garbage, fixed prototypes, added
  brackets for parameter of macro.

DGROUP reduced from 164ch to 164ah;
TGROUP reduced from 0e197h to 0e16eh;
_BSS reduced from 2b2h to 2b0h;
HMA_TEXT reduced from 0a642h to 0a63eh;
INIT_TEXT reduced from 3b47h to 3b2eh.
--- Begin Message ---
diff -ruNp old/kernel/blockio.c new/kernel/blockio.c
--- old/kernel/blockio.c        2004-04-20 11:43:06.000000000 +0000
+++ new/kernel/blockio.c        2004-05-10 01:19:12.000000000 +0000
@@ -469,12 +469,14 @@ UWORD dskxfer(COUNT dsk, ULONG blkno, VO
 
 }
 
-/*
-       this removes any (additionally allocated) buffers 
-       from the HMA buffer chain, because they get allocated to the 'user'
-*/     
-     
-void AllocateHMASpace (size_t lowbuffer, size_t highbuffer)
+/* this removes any (additionally allocated) buffers from the
+   HMA buffer chain, because they get allocated to the 'user'.
+   There assumed that:
+       LoL_nbuffers > 0
+       not all buffers inside [start..last] area
+*/
+
+void freeHMAbuffers (ofs_t startarea, ofs_t nextarea)
 {
   REG struct buffer FAR *bp = firstbuf;
   int n;
@@ -486,7 +488,7 @@ void AllocateHMASpace (size_t lowbuffer,
   do
   {
     /* check if buffer intersects with requested area                  */
-    if (FP_OFF(bp) < highbuffer && FP_OFF(bp+1) > lowbuffer)
+    if (FP_OFF(bp) < nextarea && FP_OFF(bp+1) > startarea)
     {
       flush1(bp);
       /* unlink bp from buffer chain */
diff -ruNp old/kernel/config.c new/kernel/config.c
--- old/kernel/config.c 2004-05-10 00:21:22.000000000 +0000
+++ new/kernel/config.c 2004-05-09 23:29:48.000000000 +0000
@@ -1691,43 +1691,40 @@ STATIC void config_init_buffers(int want
   struct buffer FAR *pbuffer;
   unsigned buffers = 0;
 
-  /* fill HMA with buffers if BUFFERS count >=0 and DOS in HMA        */
+  /* fill HMA with buffers if BUFFERS count >=0 and DOS in HMA          */
   if (wantedbuffers < 0)
     wantedbuffers = -wantedbuffers;
   else if (HMAState == HMA_DONE)
     buffers = (0xfff0 - HMAFree) / sizeof(struct buffer);
 
-  if (wantedbuffers < 6)         /* min 6 buffers                     */
+  if (wantedbuffers < 6)                /* min 6 buffers                */
     wantedbuffers = 6;
-  if (wantedbuffers > 99)        /* max 99 buffers                    */
+  if (wantedbuffers > 99)               /* max 99 buffers               */
   {
     printf("BUFFERS=%u not supported, reducing to 99\n", wantedbuffers);
     wantedbuffers = 99;
   }
-  if (wantedbuffers > buffers)   /* more specified than available -> get em */
+  if (buffers < wantedbuffers)          /* not less than requested      */
     buffers = wantedbuffers;
 
   LoL->nbuffers = buffers;
   LoL->inforecptr = &LoL->firstbuf;
   {
     size_t bytes = sizeof(struct buffer) * buffers;
-    pbuffer = HMAalloc(bytes);
-
-    if (pbuffer == NULL)
+    if ((pbuffer = HMAalloc(bytes)) == NULL)
     {
       pbuffer = KernelAlloc(bytes, 'B', 0);
-      if (HMAState == HMA_DONE)
-        firstAvailableBuf = MK_FP(0xffff, HMAFree);
+      HMAuserarea = HMAState == HMA_DONE ? HMAFree : 0xffff;
     }
     else
     {
       LoL->bufloc = LOC_HMA;
       LoL->deblock_buf = KernelAlloc(SEC_SIZE, 'B', 0);
-      /* space in HMA beyond requested buffers available as user space */
-      firstAvailableBuf = pbuffer + wantedbuffers;
+
+      /* space in HMA beyond requested buffers available as user space  */
+      HMAuserarea = FP_OFF (pbuffer + wantedbuffers);
     }
   }
-
   LoL->firstbuf = pbuffer;
 
   DebugPrintf(("init_buffers (size %u) at (%p)",
@@ -1742,20 +1739,13 @@ STATIC void config_init_buffers(int want
       pbuffer->b_next = FP_OFF(pbuffer + 1);
       pbuffer++;
       pbuffer->b_prev = FP_OFF(pbuffer - 1);
-    }
-    while (--i);
+    } while (--i);
   }
   pbuffer->b_next = FP_OFF(pbuffer - buffers);
 
-    /* now, we can have quite some buffers in HMA
-       -- up to 50 for KE38616.
-       so we fill the HMA with buffers
-       but not if the BUFFERS count is negative ;-)
-     */
-
   DebugPrintf((" done\n"));
 
-  if (FP_SEG(pbuffer) == 0xffff)
+  if (FP_SEG(pbuffer) == /*HMASEG*/0xFFFF)
   {
     buffers++;
     printf("Kernel: allocated %d Diskbuffers = %u Bytes in HMA\n",
diff -ruNp old/kernel/globals.h new/kernel/globals.h
--- old/kernel/globals.h        2004-05-04 02:32:32.000000000 +0000
+++ new/kernel/globals.h        2004-05-09 20:59:32.000000000 +0000
@@ -250,7 +250,7 @@ FAR *ASM firstbuf;                  /* h
 enum {LOC_CONV=0, LOC_HMA=1};
 extern unsigned char ASM bufloc;    /* 0=conv, 1=HMA                        */
 extern void far * ASM deblock_buf;  /* pointer to workspace buffer      */
-GLOBAL char FAR *firstAvailableBuf;
+GLOBAL size_t HMAuserarea;
 extern struct cds FAR * ASM CDSp;   /* Current Directory Structure          */
 extern
 struct cds FAR * ASM current_ldt;
@@ -359,8 +359,7 @@ extern UWORD ASM f_nodes_cnt;   /* numbe
 
 /* Process related functions - not under automatic generation.  */
 /* Typically, these are in ".asm" files.                        */
-VOID ASMCFUNC FAR cpm_entry(VOID)
-/*INRPT FAR handle_break(VOID) */ ;
+VOID ASMCFUNC FAR cpm_entry(VOID);
 COUNT ASMCFUNC
     CriticalError(COUNT nFlag, COUNT nDrive, COUNT nError,
                            struct dhdr FAR * lpDevice);
@@ -370,7 +369,6 @@ VOID ASMCFUNC FAR CharMapSrvc(VOID);
 VOID ASMCFUNC FAR set_stack(VOID);
 VOID ASMCFUNC FAR restore_stack(VOID);
 #endif
-/*VOID INRPT FAR handle_break(VOID); */
 
 ULONG ASMPASCAL ReadPCClock(VOID);
 VOID ASMPASCAL WriteATClock(BYTE *, BYTE, BYTE, BYTE);
diff -ruNp old/kernel/init-mod.h new/kernel/init-mod.h
--- old/kernel/init-mod.h       2004-05-10 00:16:56.000000000 +0000
+++ new/kernel/init-mod.h       2004-05-09 20:59:06.000000000 +0000
@@ -238,7 +238,7 @@ extern struct lol FAR *LoL;
 
 extern struct dhdr DOSTEXTFAR ASM blk_dev; /* Block device (Disk) driver           */
 
-extern struct buffer FAR *DOSFAR firstAvailableBuf; /* first 'available' buffer   */
+extern size_t DOSFAR HMAuserarea;
 extern struct lol ASM FAR DATASTART;
 
 extern BYTE DOSFAR ASM _HMATextAvailable,    /* first byte of available CODE area    
*/
diff -ruNp old/kernel/inthndlr.c new/kernel/inthndlr.c
--- old/kernel/inthndlr.c       2004-05-04 02:34:30.000000000 +0000
+++ new/kernel/inthndlr.c       2004-05-10 01:23:44.000000000 +0000
@@ -1757,13 +1757,14 @@ STATIC VOID StartTrace(VOID)
 }
 #endif
 
-/* this function is called from an assembler wrapper function
-   and serves the internal dos calls - int2f/12xx and int2f/4a01,4a02.
+/* this function is called from an assembler wrapper function and
+   serves the internal dos calls - int2f/12xx and int2f/4a01,4a02
 */
+
 struct int2f12regs {
 #ifdef I386
 #ifdef __WATCOMC__
-  /* UWORD gs, fs;  ** GS/FS are protected through SI/DI */
+  /* UWORD gs, fs; ** GS/FS are protected through SI/DI */
 #else
   UWORD high_edx, high_ecx, high_ebx, high_eax;
 #endif
@@ -1780,24 +1781,20 @@ struct int2f12regs {
  */
 VOID ASMCFUNC int2F_12_handler(struct int2f12regs r)
 {
-  if (r.AH == 0x4a)
+  if (r.AH == 0x4A)                    /* AX==0x4A01 or 0x4A02 */
   {
-    size_t size = 0, offs = 0xffff;
+    size_t size = ~(r.DI = HMAuserarea);/* remained HMA space; */
+                                       /*  offset 0xFFFF -> 0  */
+    r.ES = /*HMASEG*/0xFFFF;
 
-    r.ES = offs;
-    if (FP_SEG(firstAvailableBuf) == offs) /* HMA present? */
+    if (size && r.AL == 2)             /* allocate HMA space?  */
     {
-      offs = FP_OFF(firstAvailableBuf);
-      size = ~offs;                        /* BX for query HMA   */
-      if (r.AL == 0x02)                    /* allocate HMA space */
-      {
-        if (r.BX < size)
+      if (size > r.BX)
           size = r.BX;
-        AllocateHMASpace(offs, offs+size);
-        firstAvailableBuf += size;
-      }
+      freeHMAbuffers(HMAuserarea, HMAuserarea + size);
+      HMAuserarea += size;
     }
-    r.DI = offs;
+
     r.BX = size;
     return;
   }
diff -ruNp old/kernel/proto.h new/kernel/proto.h
--- old/kernel/proto.h  2004-05-02 08:21:06.000000000 +0000
+++ new/kernel/proto.h  2004-05-09 20:57:42.000000000 +0000
@@ -33,6 +33,35 @@ static BYTE *Proto_hRcsId =
 #endif
 #endif
 
+typedef UWORD ofs_t;
+typedef UWORD seg_t;
+
+#define lonibble(v) (0x0f & (v))
+#define hinibble(v) (0xf0 & (v))
+
+#if CHAR_BIT == 8
+# define lobyte(v) ((UBYTE)(v))
+#else
+# define lobyte(v) (UBYTE)(0xff & (v))
+#endif
+#define hibyte(v) lobyte ((UWORD)(v) >> 8u)
+
+#if USHRT_MAX == 0xFFFF
+# define loword(v) ((unsigned short)(v))
+#else
+# define loword(v) (unsigned short)(0xFFFF & (v))
+#endif
+#define hiword(v) loword ((v) >> 16u)
+
+#if __TURBOC__ > 0x202
+# define FP_PTR(type,seg,ofs) ((type FAR*) MK_FP (seg, ofs))
+# define FP_SEG_PTR(type,seg) ((type _seg*) (seg))
+#else
+# define _seg FAR
+# define FP_PTR(type,seg,ofs) ((type FAR*) MK_FP (seg, ofs))
+# define FP_SEG_PTR(type,seg) ((type FAR*) MK_FP (seg, 0))
+#endif
+
 /* blockio.c */
 struct buffer FAR *getblk(ULONG blkno, COUNT dsk, BOOL overwrite);
 #define getblock(blkno, dsk) getblk(blkno, dsk, FALSE);
@@ -46,7 +75,7 @@ BOOL DeleteBlockInBufferCache(ULONG blkn
 UWORD dskxfer(COUNT dsk, ULONG blkno, VOID FAR * buf, UWORD numblocks,
               COUNT mode);
 /* *** End of change */
-void AllocateHMASpace (size_t lowbuffer, size_t highbuffer);
+void freeHMAbuffers (ofs_t startarea, ofs_t nextarea);
 
 /* break.c */
 unsigned char ctrl_break_pressed(void);
@@ -227,8 +256,8 @@ void FcbCloseAll(void);
 UBYTE FcbFindFirstNext(xfcb FAR * lpXfcb, BOOL First);
 
 /* intr.asm */
-COUNT ASMPASCAL res_DosExec(COUNT mode, exec_blk * ep, BYTE * lp);
-UCOUNT ASMPASCAL res_read(int fd, void *buf, UCOUNT count);
+int ASMPASCAL res_DosExec(int mode, exec_blk * ep, const char * lp);
+unsigned ASMPASCAL res_read(int fd, void *buf, unsigned count);
 #ifdef __WATCOMC__
 #pragma aux (pascal) res_DosExec modify exact [ax bx dx es]
 #pragma aux (pascal) res_read modify exact [ax bx cx dx]
@@ -238,9 +267,6 @@ UCOUNT ASMPASCAL res_read(int fd, void *
 COUNT DosDevIOctl(lregs * r);
 
 /* memmgr.c */
-seg far2para(VOID FAR * p);
-seg long2para(ULONG size);
-void FAR *add_far(void FAR * fp, unsigned off);
 VOID FAR *adjust_far(const void FAR * fp);
 COUNT DosMemAlloc(UWORD size, COUNT mode, seg * para, UWORD * asize);
 COUNT DosMemLargest(UWORD * size);
@@ -404,5 +430,4 @@ VOID ASMCFUNC exec_user(iregs FAR * irp,
         ASSERT_CONST( (BYTE FAR *)x->fcb_ext - (BYTE FAR *)x->fcbname == 8)
 */
 
-#define ASSERT_CONST(x) { typedef struct { char _xx[x ? 1 : -1]; } xx ; }
-
+#define ASSERT_CONST(x) { typedef struct { char _[(x) ? 1 : -1]; } _; }

--- End Message ---

Reply via email to