home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s038 / 1.ddi / SUPP.LIF / CSTART.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-07-06  |  5.9 KB  |  294 lines

  1. ;/*
  2. ; *                 INTEL CORPORATION PROPRIETARY INFORMATION
  3. ; *
  4. ; *           This software is supplied under the terms of a
  5. ; *           license agreement or non-disclosure agreement with
  6. ; *           Intel Corporation and may not be copied or disclosed
  7. ; *           except in accordance with the terms of that agreement.
  8. ; *
  9. ; *   Title:  cstart
  10. ; */
  11. ; This is the starting point for all c programs.
  12. ; $Version: 1.46 $
  13. ; Copyright (C) 1988 Intel Corporation, ALL RIGHTS RESERVED
  14.  
  15. %define(controls)(module=cq_cstart fixedparams %controls)
  16.  
  17. %'      environment symbols
  18.  
  19. %set(MS_DOS,0)
  20. %set(RMX,0)
  21. %set(NUK,0)
  22. %set(ARGS,1)
  23.  
  24. %*define(embedded)      (%set(HOSTED,0))
  25. %*define(nucleus)       (%set(HOSTED,0)%set(RMX,1)%set(NUK,1)%set(ARGS,0))
  26. %*define(rmx1)          (%set(HOSTED,1)%set(RMX,1))
  27. %*define(rmx2)          (%set(HOSTED,1)%set(RMX,1))
  28. %*define(rmx3)          (%set(HOSTED,1)%set(RMX,1))
  29. %*define(rmx4)          (%set(HOSTED,1)%set(RMX,1))
  30. %*define(db386)         (%set(HOSTED,1)%set(ARGS,1))
  31. %*define(dos)           (%set(HOSTED,1)%set(MS_DOS,1))
  32.  
  33. %*define(em)    (%embedded)
  34. %*define(nuc)    (%nucleus)
  35.  
  36.  
  37. %'      define the default environment
  38. %dos
  39.  
  40. $include(:include:util.ah)
  41.  
  42. %set(medium_rom, %far_code and %const_in_code)
  43.  
  44.     %DATA    segment
  45.         dw    ?
  46.     %DATA    ends
  47.  
  48.     %CONST    segment
  49.         dw    ?
  50.     %CONST    ends
  51.  
  52. %if(%i86_asm)
  53. then(
  54.     %STACK    segment
  55.     stacktop    dw    ?
  56.     %STACK    ends
  57. )fi
  58.  
  59. ;
  60. ;    External data and program linkage:
  61. ;
  62. %if(%HOSTED)
  63. then(
  64.   %' If the C-Libraries execute in an environment with operating system
  65.   %' support, then the following externals must be declared:
  66.  
  67.   %' Define the external linkage for the parameters to main():
  68.   %'
  69.   %if(%ARGS)
  70.   then(
  71.     %if(%medium_rom)
  72.     then(
  73.     extrn    _argc:word
  74.     extrn    _argv:%ptr
  75.     )else(
  76.     %extern(%int, _argc)
  77.     %extern(%ptr, _argv)
  78.     )fi
  79.   )fi
  80.   %' Define the external linkage for the C-Library functions that
  81.   %' require operating system support:
  82.   %'
  83.     %extern_fnc(_exit_init)
  84.     %extern_fnc(exit)
  85.     %extern_fnc(_exit)
  86.     %extern_fnc(_stdio_init)
  87.   %if(%ARGS)
  88.   then(
  89.     %extern_fnc(_get_args)
  90.   )fi
  91.  
  92. )fi
  93. %' The RMX operating system environment requires additional initialization:
  94. %'
  95. %if(%RMX)
  96. then(
  97.     %extern_fnc(_global_init)
  98. )fi
  99.  
  100. %' Define the external linkage for initializing the E80187 emulator (86 only):
  101. %'
  102. %if(%i86_asm)
  103. then(
  104.     extrn    xq_inite187:far
  105. )fi
  106.  
  107. %' Define the external linkage for initializing the coprocessor:
  108. %'
  109. %if(%i386_asm)
  110. then(
  111.     extrn    init87:near
  112. )else(
  113.     extrn    init87:far
  114. )fi
  115.  
  116. %' All environments must execute the following routines:
  117. %'
  118.     %extern_fnc(_thread_init)
  119.     %extern_fnc(main)
  120.  
  121. %' Define the size of the memory blocks requested
  122. %' through the sbrk() interface:
  123. %'
  124. %data segment
  125.  
  126.     public    _amblksiz
  127.  
  128.     _amblksiz    %dint    ?
  129.  
  130. %if(%RMX)
  131. then(
  132.     public    _num_eios_bufs
  133.     public    _rmx_nucleus
  134.  
  135.     _num_eios_bufs    %dint    ?
  136.     _rmx_nucleus    %dint    ?
  137. )fi
  138. %data ends
  139.  
  140. %code    segment
  141.  
  142. begin:
  143.     ;
  144.     ; Initialize the C-Library and, if necessary, the target
  145.     ; environment:
  146.     ;
  147.     cld                ;
  148. %if(%i86_asm)
  149. then(
  150.     call    xq_inite187        ; initialize E80187 emulator
  151. )fi
  152.     call    init87            ; initialize the coprocessor
  153.  
  154.     mov    _amblksiz,8192
  155. %if(%RMX)
  156. then(
  157.     mov    _num_eios_bufs,2
  158.   %if(%NUK)
  159.   then(    mov    _rmx_nucleus,1
  160.   )else(mov    _rmx_nucleus,0
  161.   )fi
  162. )fi
  163.  
  164. %' For embedded environments, the following call to _thread_init() is
  165. %' the only initialization required by the C-Library.  Other ebmedded
  166. %' environment specific initializations should be put after this call.
  167. %'
  168. %if(not %HOSTED)
  169. then(
  170.   %if(%NUK)
  171.   then(
  172.     call    _global_init        ; initialize RMX specific global data
  173.     or    %ax, %ax
  174.     jz    L1
  175.     hlt
  176. L1:
  177.   )fi
  178.     call    _thread_init        ; initialize CLIB thread data
  179.     or    %ax, %ax
  180.     jz    L2
  181.     hlt
  182. L2:
  183. )else(
  184.   %if(%RMX)
  185.   then(
  186.     call    _global_init        ; initialize RMX specific global data
  187.     or    %ax, %ax
  188.     jz    L1
  189.     push    %ax
  190.     call    _exit
  191. L1:
  192.   )fi
  193.     call    _thread_init        ; initialize CLIB thread data
  194.     or    %ax, %ax
  195.     jz    L2
  196.     push    %ax
  197.     call    _exit
  198. L2:
  199.     call    _exit_init        ; initialize CLIB exit handlers
  200.     or    %ax, %ax
  201.     jz    L3
  202.     push    %ax
  203.     call    _exit
  204. L3:
  205.     call    _stdio_init        ; initialize CLIB standard streams
  206.     or    %ax, %ax
  207.     jz    L4
  208.     push    %ax
  209.     call    _exit
  210. L4:
  211.   %if(%ARGS)
  212.   then(
  213.     call    _get_args        ; setup parameters to main()
  214.     or    %ax, %ax
  215.     jz    L5
  216.     push    %ax
  217.     call    _exit
  218. L5:
  219.   )fi
  220.  
  221.   %if(%ARGS)
  222.   then(
  223.     %if(%far_data)
  224.     then(
  225.       %' define code for passing paramerers to main() for compact and large models
  226.       %'
  227.       %*define(push_argc)
  228.       (
  229.         %if(%set_ds or %medium_rom)
  230.         then(    mov    cx, seg _argc
  231.         )else(    mov    cx, ds
  232.         )fi
  233.     mov    es, cx
  234.     push    %reg_size es:_argc    ; push number of arguments to main()
  235.       )
  236.       %*define(push_argv)
  237.       (
  238.         %if(%set_ds or %medium_rom)
  239.         then(    mov    cx, seg _argv
  240.         )else(    mov    cx, ds
  241.         )fi
  242.     mov    es, cx
  243.     %movsx    %ax, word ptr es:_argv+%int_size
  244.     push    %ax            ; push segment selector and
  245.     push    %reg_size es:_argv    ; offset of array containing argument
  246.       )
  247.     )else(
  248.       %' define code for passing paramerers to main() for small and medium model
  249.       %'
  250.       %*define(push_argc)
  251.       (
  252.     push    %reg_size  _argc    ; push number of arguments to main()
  253.       )
  254.       %*define(push_argv)
  255.       (
  256.     push    %reg_size _argv        ; push address of array containing argument addresses
  257.       )
  258.     )fi
  259.  
  260.   )fi
  261. )fi
  262.     ;
  263.     ; Invoke the user's program:
  264.     ;
  265. %if(not %HOSTED)
  266. then(
  267.     call    main            ; no parameters passed to main()
  268.     hlt                ; ERROR:  no return expected in a 
  269.                     ;         non-hosted environment
  270.  
  271. )else(
  272.   %' set up command line arguments for main()
  273.   %'
  274.   %if(%ARGS)
  275.   then(
  276.     %if(%fpl)
  277.     then(
  278.     %push_argc
  279.     %push_argv
  280.     )else(
  281.     %push_argv
  282.     %push_argc
  283.     )fi
  284.   )fi
  285.     call    main            ; call the user's programs
  286.     push    %ax            ; set the termination value
  287.     call    exit            ; and quietly exit
  288. )fi
  289.  
  290. %code    ends
  291.  
  292.     end    begin,    ds:%dgroup, %'
  293.             ss:%sgroup %if(%i86_asm)then( :stacktop )fi
  294.