              <<< NOTED::NOTES$7:[NOTES$LIBRARY]HACKERS.NOTE;1 >>>
                               -< ** Hackers ** >-
================================================================================
Note 1635.0          Execlet initialization: INIT vs SYSINIT           4 replies
SWTHOM::LELEGARD "The Jazzing Troll"                 60 lines  10-DEC-1993 08:12
--------------------------------------------------------------------------------
Hello,

I already entered this note in VMSNOTES but I realized that this conference
is maybe a better place.

I do not understand something in the behaviour of the system loader
(VMS V5.5-2 VAX).

I write an execlet containing an initialization routine. This routine is
supposed to execute in the SYSINIT phase since it requires a process context
(to use system services).

Consequently, at the beginning of the routine, I test the flag
BOOSTATE$V_SYSINIT in EXE$GL_STATE. If it is clear, I clear the
INIRTN$M_NO_RECALL flag in the initialization routines (pointed
by R5 by INI$DOINIT before calling the initialization routine).
In this case, INI$DOINIT sets the LDRIMG$V_DELAY_INIT flag in the
image data block and the initialization procedure is called again
in the next stage.

The execlet is linked with the SYS$DOINIT module (of course).

I declare the execlet using SYSMAN SYS_LOADABLE.

*** Here is the problem:

If the execlet is declared /LOAD_STEP=SYSINIT, everything works fine.
My initialization routine is called with BOOSTATE$V_SYSINIT set in
EXE$GL_STATE. The initialization routine proceeds and then the initialization
psects are deallocated by the loader.

On the other hand, if the execlet is declared /LOAD_STEP=INIT, I have a
problem. My initialization routine is called three times. Each time, I store
the content of EXE$GL_STATE in an array I can examine under SDA after the boot.

  - First time: EXEC$GL_STATE = 000004E2
    The latest flag is BOOSTATE$V_POOL_INIT (ie, last phase in INIT stage
    before user-written execlet). That's fine.

  - Second time: EXEC$GL_STATE = 000004E2 (same value)
    Why am I called twice in the same stage?

  - Third time: EXEC$GL_STATE = 000004E6
    The latest flag is BOOSTATE$V_SWAPPER. This is the stage following INIT.
    That's fine.

  - Not called a fourth time! Why?

Each time, since BOOSTATE$V_SYSINIT is still clear in EXE$GL_STATE, my
routine ask for later recall. But I am never called in the SYSINIT stage,
which normally follows SWAPPER stage. I do not understand why.

Of course, since I never return from my initialization routine with 
INIRTN$M_NO_RECALL flag set, the LDRIMG$V_DELAY_INIT flag remains set
and the initialization psects are not deallocated.

Does anybody have an explanation of this phenomenon?
Thank you in advance for any information.

-Thierry
