Yet another small self-loader fix.
diff --git a/if1632/kernel.spec b/if1632/kernel.spec
index 8b161f8..241aee5 100644
--- a/if1632/kernel.spec
+++ b/if1632/kernel.spec
@@ -111,7 +111,7 @@
107 pascal16 SetErrorMode(word) SetErrorMode16
108 pascal16 SwitchStackTo(word word word) SwitchStackTo
109 register SwitchStackBack() SwitchStackBack
-110 pascal16 PatchCodeHandle(word) PatchCodeHandle
+110 pascal PatchCodeHandle(word) PatchCodeHandle
111 pascal GlobalWire(word) GlobalWire16
112 pascal16 GlobalUnWire(word) GlobalUnWire16
113 equate __AHSHIFT 3
diff --git a/include/module.h b/include/module.h
index dd06e33..b7439e8 100644
--- a/include/module.h
+++ b/include/module.h
@@ -74,7 +74,7 @@
typedef struct
{
- WORD version; /* Must be 0xA0 */
+ WORD version; /* Must be "A0" (0x3041) */
WORD reserved;
FARPROC16 BootApp; /* startup procedure */
FARPROC16 LoadAppSeg; /* procedure to load a segment */
diff --git a/include/neexe.h b/include/neexe.h
index 6faf332..df2d882 100644
--- a/include/neexe.h
+++ b/include/neexe.h
@@ -133,6 +133,7 @@
#define NE_SEGFLAGS_EXECUTEONLY 0x0080
#define NE_SEGFLAGS_READONLY 0x0080
#define NE_SEGFLAGS_RELOC_DATA 0x0100
+#define NE_SEGFLAGS_SELFLOAD 0x0800
#define NE_SEGFLAGS_DISCARDABLE 0x1000
/*
diff --git a/loader/ne/segment.c b/loader/ne/segment.c
index 31c8522..c8186f0 100644
--- a/loader/ne/segment.c
+++ b/loader/ne/segment.c
@@ -69,17 +69,20 @@
pSegTable = NE_SEG_TABLE( pModule );
pSeg = pSegTable + segnum - 1;
- pModuleTable = NE_MODULE_TABLE( pModule );
+
+ if (pSeg->flags & NE_SEGFLAGS_LOADED) /* already loaded ? */
+ return TRUE;
if (!pSeg->filepos) return TRUE; /* No file image, just return */
+ pModuleTable = NE_MODULE_TABLE( pModule );
+
fd = NE_OpenFile( pModule );
TRACE(module, "Loading segment %d, hSeg=%04x, flags=%04x\n",
segnum, pSeg->hSeg, pSeg->flags );
lseek( fd, pSeg->filepos << pModule->alignment, SEEK_SET );
if (pSeg->size) size = pSeg->size;
- else if (pSeg->minsize) size = pSeg->minsize;
- else size = 0x10000;
+ else size = pSeg->minsize ? pSeg->minsize : 0x10000;
mem = GlobalLock16(pSeg->hSeg);
if (pModule->flags & NE_FFLAGS_SELFLOAD && segnum > 1)
{
@@ -382,12 +385,12 @@
BOOL32 NE_LoadAllSegments( NE_MODULE *pModule )
{
int i;
+ SEGTABLEENTRY * pSegTable = (SEGTABLEENTRY *) NE_SEG_TABLE(pModule);
if (pModule->flags & NE_FFLAGS_SELFLOAD)
{
HFILE32 hf;
/* Handle self loading modules */
- SEGTABLEENTRY * pSegTable = (SEGTABLEENTRY *) NE_SEG_TABLE(pModule);
SELFLOADHEADER *selfloadheader;
STACK16FRAME *stack16Top;
THDB *thdb = THREAD_Current();
@@ -430,12 +433,8 @@
pSegTable[pModule->dgroup - 1].hSeg = saved_hSeg;
thdb->cur_stack = oldstack;
- /* FIXME
- commented out by Andreas Mohr;
- some self-loading exe ("BLINKER") relies on non-primary segs not loaded.
- contact me if you experience problems */
- /*for (i = 2; i <= pModule->seg_count; i++)
- if (!NE_LoadSegment( pModule, i )) return FALSE;*/
+ for (i = 2; i <= pModule->seg_count; i++)
+ if (!NE_LoadSegment( pModule, i )) return FALSE;
}
else
{
@@ -447,6 +446,20 @@
/***********************************************************************
+ * PatchCodeHandle
+ *
+ * Needed for self-loading modules.
+ */
+
+/* It does nothing */
+DWORD WINAPI PatchCodeHandle(HANDLE16 hSel)
+{
+ FIXME(module,"(%04x): stub.\n",hSel);
+ return (DWORD)NULL;
+}
+
+
+/***********************************************************************
* NE_FixupPrologs
*
* Fixup the exported functions prologs.
@@ -756,19 +769,6 @@
/***********************************************************************
- * PatchCodeHandle
- *
- * Needed for self-loading modules.
- */
-
-/* It does nothing */
-void WINAPI PatchCodeHandle(HANDLE16 hSel)
-{
- FIXME(module,"(%04x): stub.\n",hSel);
-}
-
-
-/***********************************************************************
* NE_Ne2MemFlags
*
* This function translates NE segment flags to GlobalAlloc flags