[comp.os.os9] problems running in system state

LUSIANI%VXALTP.DECnet@CERNVAX.BITNET (08/08/88)

I am writing a simple program that allocates some memory, copies an executable
module in it, calls F$VModul, and then exits. F$VModul requires system state,
but I saw that in system state a program like the following exits with error
after F$Exit, while in user mode it completes correctly. The following program
just opens /term, allocates memory, deallocates memory, closes /term.
What I' m doing wrong ? I am using os9 v 2.1.
 Thanks
                                Alberto Lusiani
---------------- cut here ---------------------------------------
                nam Trapini
                ttl User Trap Handler for the TPP
                use oskdefs.d
                use systype.d
*               use tppdefs.d
                opt lx
************************************************
* Edition History
*
*  #   Date     Comments                                        By
* -- -------- ------------------------------------------------- ---------------
*
*

Edition  equ    1                          current edition number
Typ_Lang set    (Prgrm<<8)+Objct           mainline segment
* Attr_Rev set  ((ReEnt!SupStat)<<8)+0
Attr_Rev set    ((ReEnt)<<8)+0

                psect test,Typ_Lang,Attr_Rev,Edition,255,Entry

file_name       dc.b    "small",0
stdout_n        dc.b    "/term",0
crlf_str        dc.b    C$CR,0
delim_s         dc.b    " - ",0

        align

                vsect
path            do.w    1
stdout          do.w    1
buf             do.b    8
mod_addr        do.l    1
                ends

                use     alb_io.a                ; get string/number I/O funcs

err_abort       MACRO
                bcc     ea\@1
                os9     F$Exit
ea\@1
                ENDM

************************************************************************
*
*       Begin of Main
*

Entry
                lea     stdout_n(pc),a0
                move.b  #(Read_!Write_),d0
                os9     I$Open
                err_abort
                move    d0,stdout(a6)

*               Writes  stdout(a6),file_name(pc)
*               Writes  stdout(a6),crlf_str(pc)

                lea     file_name(pc),a0
                move.b  #Read_,d0
                os9     I$Open
                err_abort
                move    d0,path(a6)
*               Writeshort      stdout(a6),#1

                move.l  #8,d1
                lea     buf(a6),a0
                os9     I$Read
                err_abort

                lea     buf(a6),a0
*               Writelong       stdout(a6),4(a0)

                move.l  4(a0),d0
                os9     F$SRqMem
                err_abort
                move.l  a2,mod_addr(a6)
*               Writelong       stdout(a6),a2

                lea     buf(a6),a0
                move.l  (a0),(a2)
                move.l  4(a0),4(a2)

                move    path(a6),d0
                move.l  4(a0),d1
                subq.l  #8,d1
                lea     8(a2),a0
                os9     I$Read
                err_abort

                move    path(a6),d0
                os9     I$Close
                err_abort
*               Writeshort      stdout(a6),#3

                movea   mod_addr(a6),a0
                move.l  #$0000,d0
*               os9     F$VModul

*               Writes  stdout(a6),crlf_str(pc)
*               Writelong       stdout(a6),d1
*               Writelong       stdout(a6),a2
*               Writelong       stdout(a6),a0
*               Writes  stdout(a6),crlf_str(pc)

                move    #0,d0
                lea     file_name(pc),a0
*               os9     F$Link
                err_abort
*               Writeshort      stdout(a6),#4

                move.l  #$80000900,d0
*               os9     F$Sleep
                err_abort
*               Writeshort      stdout(a6),#5

                lea     file_name(pc),a0
*               os9     F$UnLoad
                err_abort
*               Writeshort      stdout(a6),#6

                movea   mod_addr(a6),a2
                move.l  4(a2),d0
                os9     F$SRtMem
                err_abort
*               Writeshort      stdout(a6),#7

close_exit
                move    stdout(a6),d0
                os9     I$Close
                err_abort

                move    #0,d1
                os9     F$Exit

                ends