Eliminated long2para and avoided use of "long"s in DosExeLoader, using

paragraphs to measure size instead. Saves ~130 bytes together.


git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@806 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
Bart Oldeman 2004-03-21 12:36:47 +00:00
parent 7bf976be3f
commit 00ef6b1be2
2 changed files with 32 additions and 43 deletions

View File

@ -80,14 +80,6 @@ seg far2para(VOID FAR * p)
return FP_SEG(p) + (FP_OFF(p) >> 4); return FP_SEG(p) + (FP_OFF(p) >> 4);
} }
seg long2para(ULONG size)
{
UWORD high = (UWORD)(size >> 16);
if ((UWORD) size > 0xfff0)
high++;
return (((UWORD) size + 0x0f) >> 4) + (high << 12);
}
/* /*
* Add a displacement to a far pointer and return the result normalized. * Add a displacement to a far pointer and return the result normalized.
*/ */

View File

@ -127,8 +127,8 @@ STATIC COUNT ChildEnv(exec_blk * exp, UWORD * pChildEnvSeg, char far * pathname)
} }
/* allocate enough space for env + path */ /* allocate enough space for env + path */
if ((RetCode = DosMemAlloc(long2para(nEnvSize + ENV_KEEPFREE), if ((RetCode = DosMemAlloc((nEnvSize + ENV_KEEPFREE + 15)/16,
mem_access_mode, (seg FAR *) pChildEnvSeg, mem_access_mode, pChildEnvSeg,
NULL /*(UWORD FAR *) MaxEnvSize ska */ )) < 0) NULL /*(UWORD FAR *) MaxEnvSize ska */ )) < 0)
return RetCode; return RetCode;
pDest = MK_FP(*pChildEnvSeg + 1, 0); pDest = MK_FP(*pChildEnvSeg + 1, 0);
@ -551,22 +551,18 @@ VOID return_user(void)
COUNT DosExeLoader(BYTE FAR * namep, exec_blk * exp, COUNT mode, COUNT fd) COUNT DosExeLoader(BYTE FAR * namep, exec_blk * exp, COUNT mode, COUNT fd)
{ {
UWORD mem, env, start_seg, asize = 0; UWORD mem, env, start_seg, asize = 0;
ULONG exe_size; UWORD exe_size;
{ {
ULONG image_size; UWORD image_size;
ULONG image_offset;
/* compute image offset from the ExeHeader */
image_offset = (ULONG) ExeHeader.exHeaderSize * 16;
/* compute image size by removing the offset from the */ /* compute image size by removing the offset from the */
/* number pages scaled to bytes plus the remainder and */ /* number pages scaled to bytes plus the remainder and */
/* the psp */ /* the psp */
/* First scale the size */ /* First scale the size and remove the offset */
image_size = (ULONG) ExeHeader.exPages * 512; if (ExeHeader.exPages >= 2048)
/* remove the offset */ return DE_INVLDDATA; /* we're not able to get >=1MB in dos memory */
image_size -= image_offset; image_size = ExeHeader.exPages * 32 - ExeHeader.exHeaderSize;
/* We should not attempt to allocate /* We should not attempt to allocate
memory if we are overlaying the current process, because the new memory if we are overlaying the current process, because the new
process will simply re-use the block we already have allocated. process will simply re-use the block we already have allocated.
@ -579,8 +575,8 @@ COUNT DosExeLoader(BYTE FAR * namep, exec_blk * exp, COUNT mode, COUNT fd)
COUNT rc; COUNT rc;
/* and finally add in the psp size */ /* and finally add in the psp size */
image_size += sizeof(psp); /*TE 03/20/01 */ image_size += sizeof(psp) / 16; /*TE 03/20/01 */
exe_size = (ULONG) long2para(image_size) + ExeHeader.exMinAlloc; exe_size = image_size + ExeHeader.exMinAlloc;
/* Clone the environement and create a memory arena */ /* Clone the environement and create a memory arena */
if (mode & 0x80) if (mode & 0x80)
@ -593,10 +589,12 @@ COUNT DosExeLoader(BYTE FAR * namep, exec_blk * exp, COUNT mode, COUNT fd)
if (rc == SUCCESS) if (rc == SUCCESS)
/* Now find out how many paragraphs are available */ /* Now find out how many paragraphs are available */
rc = ExecMemLargest(&asize, (UWORD)exe_size); rc = ExecMemLargest(&asize, exe_size);
exe_size = (ULONG) long2para(image_size) + ExeHeader.exMaxAlloc; exe_size = image_size + ExeHeader.exMaxAlloc;
if (exe_size > asize) /* second test is for overflow (avoiding longs) --
exMaxAlloc can be high */
if (exe_size > asize || exe_size < image_size)
exe_size = asize; exe_size = asize;
/* TE if ExeHeader.exMinAlloc == ExeHeader.exMaxAlloc == 0, /* TE if ExeHeader.exMinAlloc == ExeHeader.exMaxAlloc == 0,
@ -609,7 +607,7 @@ COUNT DosExeLoader(BYTE FAR * namep, exec_blk * exp, COUNT mode, COUNT fd)
/* Allocate our memory and pass back any errors */ /* Allocate our memory and pass back any errors */
if (rc == SUCCESS) if (rc == SUCCESS)
rc = ExecMemAlloc((UWORD)exe_size, &mem, &asize); rc = ExecMemAlloc(exe_size, &mem, &asize);
if (rc != SUCCESS) if (rc != SUCCESS)
DosMemFree(env); DosMemFree(env);
@ -645,7 +643,7 @@ COUNT DosExeLoader(BYTE FAR * namep, exec_blk * exp, COUNT mode, COUNT fd)
/* Now load the executable */ /* Now load the executable */
/* offset to start of image */ /* offset to start of image */
if (SftSeek(fd, image_offset, 0) != SUCCESS) if (SftSeek(fd, ExeHeader.exHeaderSize * 16UL, 0) != SUCCESS)
{ {
if (mode != OVERLAY) if (mode != OVERLAY)
{ {
@ -660,33 +658,32 @@ COUNT DosExeLoader(BYTE FAR * namep, exec_blk * exp, COUNT mode, COUNT fd)
exe_size = image_size; exe_size = image_size;
if (mode != OVERLAY) if (mode != OVERLAY)
{ {
exe_size -= sizeof(psp); exe_size -= sizeof(psp) / 16;
start_seg += long2para(sizeof(psp)); start_seg += sizeof(psp) /16;
if (exe_size > 0 && (ExeHeader.exMinAlloc == 0) && (ExeHeader.exMaxAlloc == 0)) if (exe_size > 0 && (ExeHeader.exMinAlloc == 0) && (ExeHeader.exMaxAlloc == 0))
{ {
mcb FAR *mp = MK_FP(mem - 1, 0); mcb FAR *mp = MK_FP(mem - 1, 0);
/* then the image should be placed as high as possible */ /* then the image should be placed as high as possible */
start_seg = start_seg + mp->m_size - (UWORD)((image_size + 15) / 16); start_seg += mp->m_size - image_size;
} }
} }
} }
/* read in the image in 32K chunks */ /* read in the image in 32256 chunks */
{ {
int nBytesRead; int nBytesRead, toRead = CHUNK;
BYTE FAR *sp = MK_FP(start_seg, 0x0); seg sp = start_seg;
while (exe_size > 0) while (toRead == CHUNK)
{ {
nBytesRead = if (exe_size < CHUNK/16)
(int)DosRWSft(fd, toRead = exe_size*16;
(COUNT) (exe_size < CHUNK ? exe_size : CHUNK), nBytesRead = (int)DosRWSft(fd, toRead, MK_FP(sp, 0), XFR_READ);
(VOID FAR *) sp, XFR_READ); if (nBytesRead < toRead)
if (nBytesRead <= 0)
break; break;
sp = add_far((VOID FAR *) sp, nBytesRead); sp += CHUNK/16;
exe_size -= nBytesRead; exe_size -= CHUNK/16;
} }
} }