Good news - the Borland 386 bug is now fixed!

Bart was right - using EAX in one of the small functions in main.c caused the trouble. How I came to this? First, I decided to rely on the fact that it hangs only when built for 386. So, first I compiled all the kernel for 386 but only config.c for 186. Crash! Good it wasn't there as config.c is rather big! ;-) Next, I tried the same with main.c. No crash! So it was in main.c! Next I tried to determine which function there is the culprit by using "#pragma option -1" for the second half of the main.c file. Crash! Then I moved the pragma below the first quarter. Crash! Then below the first 1/8 of the file. Crash! Then only the 4 small functions (memset, fmemset, strcpy, fmemcpy) were left above it. After a couple of similar "binary searches", I found that the culprit was fmemcpy! If only fmemcpy was compiled for 186, and everything else for 386, it worked!

How did I fix it? First I decided to disable 386 code only for fmemcpy but that would be ugly. So, I looked at the code and as fmemcpy wasn't the only one of those 4 small functions that caused the compiler to use EAX, I decided that if I fix only it, this problem may arise in the future. So, finally I decided to change them all and used the Pat Villani's original code in misc.c, slightly modified. Now Borland doesn't use EAX in none of them even if they're all compiled for 386! And of course this led to a code size reduction as well. With the last Bart's fcbfns.c patch applied, the kernel is now just 41.55 KB (42548 bytes) long (aPacked - OK, I know but expect good news here ;-)

Don't call truename from FcbNameInit(). It was only necessary for "FcbRename", which can call it itself. This avoids yesterday's hack.

Thanks! Tested and it works with EJECT! But the Borland compiler warned about an unused assignment and variable (lpFcb in FcbDelete), so I had to remove it and included this into my patches below (available at http://linux.tu-varna.acad.bg/~lig/freedos/CVSPATCH.TXT).


Lucho

diff -ruN cvs/kernel/hdr/portab.h src/kernel/hdr/portab.h
--- cvs/kernel/hdr/portab.h     2004-02-08 14:16:06.000000000 +0200
+++ src/kernel/hdr/portab.h     2004-02-10 12:28:36.000000000 +0200
@@ -94,6 +94,8 @@
 #pragma aux SS = "mov dx,ss" value [dx];
 /* enable Possible loss of precision warning for compatibility with Borland */
 #pragma enable_message(130)
+/* disable "lvalue cast is not standard C" (it's for legacy pre-ANSI code) */
+#pragma disable_message(120)

 #if _M_IX86 >= 300 || defined(M_I386)
 #define I386
diff -ruN cvs/kernel/kernel/fcbfns.c src/kernel/kernel/fcbfns.c
--- cvs/kernel/kernel/fcbfns.c  2004-02-10 13:23:44.000000000 +0200
+++ src/kernel/kernel/fcbfns.c  2004-02-10 13:28:12.000000000 +0200
@@ -477,7 +477,7 @@
   void FAR *lpOldDta = dta;

   /* Build a traditional DOS file name                            */
-  fcb FAR *lpFcb = CommonFcbInit(lpXfcb, SecPathName, &FcbDrive);
+  CommonFcbInit(lpXfcb, SecPathName, &FcbDrive);
   /* check for a device                                           */
   if (IsDevice(SecPathName))
   {
diff -ruN cvs/kernel/kernel/main.c src/kernel/kernel/main.c
--- cvs/kernel/kernel/main.c    2004-02-08 14:14:06.000000000 +0200
+++ src/kernel/kernel/main.c    2004-02-10 12:22:42.000000000 +0200
@@ -71,30 +71,29 @@
 #endif

 /* little functions - could be ASM but does not really matter in this context */
-void memset(void *s, int c, unsigned n)
+
+void memset(void *s, int c, size_t n)
 {
-  char *t = s;
-  while(n--) *t++ = c;
+  while(n--)
+    *((char *)s)++ = c;
 }

-void fmemset(void far *s, int c, unsigned n)
+void fmemset(void far *s, int c, size_t n)
 {
-  char far *t = s;
-  while(n--) *t++ = c;
+  while (n--)
+    *((char far *)s)++ = c;
 }

-void strcpy(char *dest, const char *src)
+void strcpy(char *t, const char *s)
 {
-  while(*src)
-    *dest++ = *src++;
-  *dest = '\0';
+  while ((*t++ = *s++) != '\0')
+    ;
 }

-void fmemcpy(void far *dest, const void far *src, unsigned n)
+void fmemcpy(void far *t, const void far *s, size_t n)
 {
-  char far *d = dest;
-  const char far *s = src;
-  while(n--) *d++ = *s++;
+  while (n--)
+    *((char far *)t)++ = *((char far *)s)++;
 }

VOID ASMCFUNC FreeDOSmain(void)


------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ Freedos-kernel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/freedos-kernel

Reply via email to