Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1922 lines
44 KiB

  1. page ,132
  2. title TASK - task create/destroy procedures
  3. .xlist
  4. include kernel.inc
  5. include tdb.inc
  6. include pdb.inc
  7. include newexe.inc
  8. include dbgsvc.inc
  9. include bop.inc
  10. .list
  11. outd macro msg,n
  12. %out msg n
  13. endm
  14. if2
  15. ; outd <TDBsize =>,%TDBsize
  16. endif
  17. externW pStackBot
  18. externW pStackMin
  19. externW pStackTop
  20. externFP SafeCall
  21. externFP BuildPDB
  22. externFP LockSegment
  23. externFP UnlockSegment
  24. ;externFP Yield
  25. externFP LocalInit
  26. externFP GlobalAlloc
  27. externFP GlobalFree
  28. ;externFP GlobalLock
  29. externFP GlobalUnLock
  30. externFP GlobalCompact
  31. externFP IGlobalHandle
  32. externFP GlobalLRUOldest
  33. externFP AllocDStoCSAlias
  34. ;;;externFP FarMyLock
  35. externFP FarSetOwner
  36. externFP default_sig_handler
  37. externFP CVW_Hack
  38. externFP GlobalDOSAlloc
  39. externFP GlobalDOSFree
  40. externFP AllocSelector
  41. externFP LongPtrAdd
  42. externFP MyFarDebugCall
  43. externFP Int21Handler
  44. externFP far_get_arena_pointer32
  45. externFP FarAssociateSelector32
  46. externFP KRebootInit
  47. if KDEBUG
  48. externFP SetupAllocBreak
  49. endif
  50. ifdef WOW
  51. externFP SetAppCompatFlags
  52. externFP WowReserveHtask
  53. externFP FreeSelector
  54. externFP WowPassEnvironment
  55. externFP ExitCall
  56. endif
  57. DataBegin
  58. ;externB fEMM
  59. externB fBooting
  60. externB kernel_flags
  61. externB num_tasks
  62. ;externW hexehead
  63. externW pGlobalHeap
  64. externW curTDB
  65. externW loadTDB
  66. externW headTDB
  67. externW headPDB
  68. externW topPDB
  69. externW cur_DOS_PDB
  70. externW Win_PDB
  71. externW MyCSAlias
  72. externD pUserInitDone
  73. externD ptrace_app_entry
  74. externD ptrace_DLL_entry
  75. externD pSignalProc
  76. if KDEBUG
  77. globalW allocTask,0
  78. globalD allocCount,0
  79. globalD allocBreak,0
  80. globalB allocModName,0,8
  81. endif ;KDEBUG
  82. ifdef WOW
  83. externD FastBop
  84. externW DebugWOW
  85. endif
  86. DataEnd
  87. sBegin CODE
  88. assumes CS,CODE
  89. assumes DS,NOTHING
  90. assumes ES,NOTHING
  91. externD prevInt00proc
  92. externNP SaveState
  93. externNP UnlinkObject
  94. externNP genter
  95. externNP gleave
  96. nullcomline DB 0,0Dh
  97. ;-----------------------------------------------------------------------;
  98. ; GetCurrentTask ;
  99. ; ;
  100. ; Returns the current task. ;
  101. ; ;
  102. ; Arguments: ;
  103. ; none ;
  104. ; ;
  105. ; Returns: ;
  106. ; AX = curTDB ;
  107. ; DX = headTDB ;
  108. ; ;
  109. ; Error Returns: ;
  110. ; ;
  111. ; Registers Preserved: ;
  112. ; all ;
  113. ; ;
  114. ; Registers Destroyed: ;
  115. ; ;
  116. ; Calls: ;
  117. ; nothing ;
  118. ; ;
  119. ; History: ;
  120. ; ;
  121. ; Sun Feb 01, 1987 07:45:40p -by- David N. Weise [davidw] ;
  122. ; Added this nifty comment block. ;
  123. ;-----------------------------------------------------------------------;
  124. assumes ds,nothing
  125. assumes es,nothing
  126. cProc GetCurrentTask,<PUBLIC,FAR>
  127. cBegin nogen
  128. push es
  129. SetKernelDS ES
  130. mov ax,curTDB
  131. mov dx,headTDB
  132. ; mov bx,codeOffset headTDB
  133. ; mov cx,codeOffset curTDB
  134. pop es
  135. ret
  136. assumes es,nothing
  137. cEnd nogen
  138. ;-----------------------------------------------------------------------;
  139. ; InsertTask ;
  140. ; ;
  141. ; Inserts a task into the task list. ;
  142. ; ;
  143. ; Arguments: ;
  144. ; parmW hTask ;
  145. ; ;
  146. ; Returns: ;
  147. ; ;
  148. ; Error Returns: ;
  149. ; ;
  150. ; Registers Preserved: ;
  151. ; CX,DX,DI,SI,DS ;
  152. ; ;
  153. ; Registers Destroyed: ;
  154. ; AX,BX,ES ;
  155. ; ;
  156. ; Calls: ;
  157. ; nothing ;
  158. ; ;
  159. ; History: ;
  160. ; ;
  161. ; Sun Feb 01, 1987 09:41:24p -by- David N. Weise [davidw] ;
  162. ; Added this nifty comment block. ;
  163. ;-----------------------------------------------------------------------;
  164. assumes ds,nothing
  165. assumes es,nothing
  166. cProc InsertTask,<PUBLIC,NEAR>,<ds>
  167. parmW hTask
  168. cBegin
  169. mov es,hTask ; get task handle
  170. SetKernelDS
  171. mov ax,headTDB ; get head of task list
  172. UnSetKernelDS
  173. or ax,ax ; anybody here?
  174. jz ins1 ; no, just do trivial case
  175. ins0: mov ds,ax ; point to head TDB
  176. mov bl,es:[TDB_priority] ; get insert priority
  177. cmp bl,ds:[TDB_priority] ; is it less than head task?
  178. jg ins2 ; no, insert elsewhere
  179. mov es:[TDB_next],ax
  180. ins1: SetKernelDS
  181. mov headTDB,es
  182. UnSetKernelDS
  183. jmps ins4
  184. ins2: mov ds,ax ; save segment of previous TDB
  185. mov ax,ds:[TDB_next] ; get segment of next tdb
  186. or ax,ax ; if zero, insert now
  187. jz ins3
  188. mov es,ax ; point to new TDB
  189. cmp bl,es:[TDB_priority]
  190. jg ins2
  191. ins3: mov es,hTask
  192. mov ds:[TDB_next],es
  193. mov es:[TDB_next],ax
  194. ins4:
  195. cEnd
  196. ;-----------------------------------------------------------------------;
  197. ; DeleteTask ;
  198. ; ;
  199. ; Deletes a task from the task list. ;
  200. ; ;
  201. ; Arguments: ;
  202. ; parmW hTask ;
  203. ; ;
  204. ; Returns: ;
  205. ; AX = hTask ;
  206. ; ;
  207. ; Error Returns: ;
  208. ; ;
  209. ; Registers Preserved: ;
  210. ; ;
  211. ; Registers Destroyed: ;
  212. ; ;
  213. ; Calls: ;
  214. ; UnlinkObject ;
  215. ; ;
  216. ; History: ;
  217. ; ;
  218. ; Sun Feb 01, 1987 09:41:24p -by- David N. Weise [davidw] ;
  219. ; Added this nifty comment block. ;
  220. ;-----------------------------------------------------------------------;
  221. assumes ds,nothing
  222. assumes es,nothing
  223. cProc DeleteTask,<PUBLIC,NEAR>
  224. parmW hTask
  225. cBegin
  226. mov es,hTask
  227. mov bx,dataOffset headTDB
  228. mov dx,TDB_next
  229. call UnlinkObject ; returns AX = hTask
  230. cEnd
  231. cProc FarCreateTask,<PUBLIC,FAR> ; Called from CreateTask
  232. ; parmW fPrev ; Calls several 'near' CODE funcs
  233. cBegin
  234. cCall SaveState,<ds>
  235. SetKernelDS es
  236. mov loadTDB,ds
  237. cCall InsertTask,<ds>
  238. clc
  239. cEnd
  240. if KDEBUG
  241. ;-----------------------------------------------------------------------
  242. ;
  243. ; CheckGAllocBreak
  244. ;
  245. ; Checks to see if the allocation break count has been reached.
  246. ; Returns CARRY SET if the allocation should fail, CLEAR otherwise.
  247. ; Increments the allocation count.
  248. ;
  249. ;-----------------------------------------------------------------------
  250. LabelNP <PUBLIC, CheckGAllocBreak>
  251. errn$ CheckLAllocBreak
  252. cProc CheckLAllocBreak,<PUBLIC,NEAR>,<DS,AX>
  253. cBegin
  254. SetKernelDS
  255. assumes ds,DATA
  256. mov ax,allocTask ; if allocTask != curTDB, exit.
  257. or ax,ax ; curTDB may be NULL during boot.
  258. jz cab_nofail
  259. cmp ax,curTDB
  260. jnz cab_nofail
  261. mov ax,word ptr allocBreak
  262. cmp ax,word ptr allocCount ; if allocBreak != allocCount
  263. jnz cab_increment ; inc allocCount
  264. mov ax,word ptr allocBreak+2
  265. cmp ax,word ptr allocCount+2
  266. jnz cab_increment
  267. or ax,word ptr allocBreak ; if allocBreak is 0L, just inc.
  268. jz cab_increment
  269. krDebugOut <DEB_ERROR>, "Alloc break: Failing allocation"
  270. stc ; return carry set
  271. jmp short cab_exit
  272. cab_increment:
  273. inc word ptr allocCount ; increment allocCount
  274. jnz cab_nofail
  275. inc word ptr allocCount+2
  276. cab_nofail:
  277. clc
  278. cab_exit:
  279. assumes ds,NOTHING
  280. cEnd
  281. endif ;KDEBUG
  282. sEnd CODE
  283. sBegin NRESCODE
  284. assumes CS,NRESCODE
  285. assumes DS,NOTHING
  286. assumes ES,NOTHING
  287. externNP MapDStoDATA
  288. externNP GetInstance
  289. externNP StartProcAddress
  290. ;-----------------------------------------------------------------------;
  291. ; CreateTask ;
  292. ; ;
  293. ; "Creates" a new task. It allocates the memory for the TDB+PDB struc, ;
  294. ; builds the PDB, constructs the TDB, initializes the EEMS memory ;
  295. ; arena, and sets the signature word in the TDB. TDB actually added ;
  296. ; to task queue by StartTask. ;
  297. ; ;
  298. ; Arguments: ;
  299. ; parmD pParmBlk ;
  300. ; parmW pExe ;
  301. ; parmW hPrev instance ;
  302. ; parmW fWOA ;
  303. ; ;
  304. ; Returns: ;
  305. ; AX = segment of TDB ;
  306. ; ;
  307. ; Error Returns: ;
  308. ; AX = 0 ;
  309. ; ;
  310. ; Registers Preserved: ;
  311. ; DI,SI,DS ;
  312. ; ;
  313. ; Registers Destroyed: ;
  314. ; ;
  315. ; Calls: ;
  316. ; ;
  317. ; History: ;
  318. ; ;
  319. ; Thu 04-Jan-1990 21:18:25 -by- David N. Weise [davidw] ;
  320. ; Added support for OS/2 apps. ;
  321. ; ;
  322. ; Mon 07-Aug-1989 23:28:15 -by- David N. Weise [davidw] ;
  323. ; Added support for long command lines to winoldap. ;
  324. ; ;
  325. ; Thu Apr 09, 1987 03:53:16p -by- David N. Weise [davidw] ;
  326. ; Added the initialization for EMS a while ago, recently added the ;
  327. ; switching of stacks to do it. ;
  328. ; ;
  329. ; Sun Feb 01, 1987 07:46:53p -by- David N. Weise [davidw] ;
  330. ; Added this nifty comment block. ;
  331. ;-----------------------------------------------------------------------;
  332. assumes ds,nothing
  333. assumes es,nothing
  334. cProc CreateTask,<PUBLIC,FAR>,<si,di>
  335. parmD pParmBlk
  336. parmW pExe
  337. ; parmW fPrev
  338. parmW fWOA
  339. localW env_seg
  340. localW comline_start
  341. cBegin
  342. call MapDStoDATA
  343. ReSetKernelDS
  344. cld
  345. xor si,si
  346. mov env_seg,si
  347. mov comline_start,si
  348. cmp si,pParmBlk.sel
  349. jz parm_block_considered
  350. cCall pass_environment,<pExe,pParmBlk>
  351. inc ax
  352. jnz @F
  353. jmp ats6
  354. @@: dec ax
  355. mov env_seg,ax
  356. mov comline_start,dx
  357. mov si,size PDB ; start with size of PDB
  358. cmp fWOA,0
  359. jz parm_block_considered
  360. les di,pParmBlk
  361. les di,es:[di].lpcmdline
  362. mov cx,es:[di]
  363. sub cx,127 ; account for terminating 0Dh
  364. jbe parm_block_considered
  365. add si,cx
  366. add si,15
  367. and si,NOT 15
  368. parm_block_considered:
  369. add si,TDBsize+15 ; Room for task data and paragraph aligned.
  370. ; xor ax,ax ; Room for EMM save area if needed.
  371. ; mov al,fEMM
  372. ; add si,ax
  373. and si,0FFF0h
  374. mov di,si
  375. mov cl,4
  376. shr si,cl
  377. ifdef WOW
  378. ; We need to ensure task handles are unique across multiple WOW VDMs
  379. ; on Windows NT, so that for example the undocumented feature of
  380. ; passing a 16-bit htask to Win32 Post(App|Thread)Message instead
  381. ; of a thread ID will work reliably with multiple WOW VDMs.
  382. ;
  383. ; To accomplish this we call WowReserveHtask, which will return
  384. ; the htask if the htask (ptdb) was previously unused and has
  385. ; been reserved for us. If it returns 0 another VDM is already
  386. ; using that value and so we need to allocate another and try again.
  387. ; To avoid risking exhausting low memory, we allocate memory for the
  388. ; TDB once using GlobalDOSAlloc, then clone it using AllocSelector.
  389. ; We test this cloned selector value using WowReserveHtask, if it
  390. ; fails we get another clone until one works. Then we free all but
  391. ; the clone we'll return, and magically swap things around so that
  392. ; the cloned selector owns the TDB memory and then free the original
  393. ; selector from GlobalDOSAlloc
  394. ;
  395. xor dx,dx ; Make size of allocation a dword
  396. regptr xsize,dx,di
  397. cCall GlobalDOSAlloc,<xsize>
  398. or ax,ax
  399. jnz @f
  400. jmp ats6 ; Return zero for failure.
  401. @@: push di ; save TDB size on stack
  402. push ax ; save GlobalDOSAlloc selector on stack
  403. mov di,ax ; and in DI
  404. cCall WowReserveHtask,<ax> ; returns htask or 0
  405. or ax,ax ; Is this selector value avail as htask?
  406. jz MustClone ; no, start cloning loop
  407. pop ax ; htask to return
  408. pop di ; TDB size
  409. jmps NoClone
  410. MustClone:
  411. xor cx,cx ; count of clone selectors
  412. xor si,si ; no selector to return yet
  413. AnotherHtask:
  414. push cx
  415. cCall AllocSelector,<di> ; clone the selector
  416. pop cx
  417. or ax,ax
  418. jz FreeAnyHtasks ; Out of selectors cleanup and exit
  419. push ax ; save cloned selector on stack
  420. inc cx
  421. push cx
  422. cCall WowReserveHtask,<ax> ; returns htask or 0
  423. pop cx
  424. or ax,ax
  425. jz AnotherHtask ; conflict
  426. mov si,ax ; SI = selector to return
  427. pop bx ; pop the selector we're returning
  428. dec cx
  429. jcxz @f
  430. FreeLoop:
  431. pop bx ; pop an allocated selector from stack
  432. push cx
  433. cCall FreeSelector,<bx>
  434. pop cx
  435. dec cx
  436. FreeAnyHtasks:
  437. jcxz @f ; have we popped all the allocated selectors? Yes
  438. jmps FreeLoop ; No
  439. @@: mov ax,si
  440. or si,si
  441. jnz @f
  442. pop ax ; original selector from GlobalDOSAlloc
  443. cCall GlobalDOSFree,<ax>
  444. pop di
  445. jmp ats6
  446. @@:
  447. ; SI is selector to return, top of stack is original GlobalDOSAlloc
  448. ; selector. We need to free the original selector and make the clone
  449. ; selector "own" the memory so it will be freed properly by GlobalDOSFree
  450. ; during task cleanup.
  451. pop di ; DI = original GlobalDOSAlloc selector
  452. push ds
  453. mov ds, pGlobalHeap
  454. UnSetKernelDS
  455. .386
  456. cCall far_get_arena_pointer32,<di>
  457. push eax
  458. cCall FarAssociateSelector32,<di,0,0>
  459. pop eax
  460. mov ds:[eax].pga_handle, si
  461. cCall FarAssociateSelector32,<si,eax>
  462. .286p
  463. pop ds
  464. ReSetKernelDS
  465. cCall FreeSelector,<di>
  466. mov ax,si ; AX is the final TDB selector/handle.
  467. pop di ; TDB size
  468. NoClone:
  469. else
  470. xor dx,dx ; Make size of allocation a dword
  471. regptr xsize,dx,di
  472. cCall GlobalDOSAlloc,<xsize>
  473. or ax,ax
  474. jnz @f
  475. jmp ats6 ; Return zero for failure.
  476. @@:
  477. endif
  478. mov es, ax
  479. xor ax, ax ; zero allocated block
  480. mov cx, di
  481. shr cx, 1
  482. xor di, di
  483. rep stosw
  484. mov ax, es
  485. ats2a:
  486. cCall FarSetOwner,<ax,ax> ; Set TDB owner to be itself
  487. cmp fWOA,0 ; Is this WinOldApp?
  488. mov ds,ax
  489. UnSetKernelDS
  490. jz no_it_isnt
  491. or ds:[TDB_flags],TDBF_WINOLDAP
  492. no_it_isnt:
  493. ; Initialize the task stack.
  494. mov si,1 ; 1 for show means open window
  495. les di,pParmBlk
  496. mov ax,es
  497. or ax,di
  498. jnz @F
  499. jmp ats4 ; AX = DI = 0 if no parmblock
  500. @@: xor ax,ax ; Skip past EMM save area and
  501. push ds
  502. xor dx, dx
  503. push es
  504. mov es,pExe
  505. mov dx,es:[ne_flags]
  506. pop es
  507. test dx,NEPROT
  508. jz @F
  509. or ds:[TDB_flags],TDBF_OS2APP
  510. or ds:[TDB_ErrMode],08000h ; don't prompt for .DLL's
  511. @@:
  512. call MapDStoDATA
  513. ReSetKernelDS
  514. test dx,NEPROT ; OS/2 app?
  515. mov dx,TopPDB ; DX has segment of parent PDB
  516. jz use_kernel_TDB
  517. ; %OUT This should probably be Win_PDB
  518. mov dx,cur_DOS_PDB ; inherit parent's stuff
  519. use_kernel_TDB:
  520. pop ds
  521. UnSetKernelDS
  522. push dx ; yes, get address of PDB
  523. push es
  524. mov si,(TDBsize+15) and not 15 ; Round up TDB size
  525. cCall AllocSelector,<ds> ; Get us an alias selector
  526. or ax, ax ; did we get it?
  527. jnz ats_gotsel
  528. mov bx, ds ; No, tidy up
  529. mov ds, ax ; We will current ds, so zero it
  530. cCall GlobalDOSFree,<bx> ; Free the memory
  531. pop es
  532. pop dx
  533. xor ax, ax
  534. jmp ats6
  535. ats_gotsel:
  536. xor dx, dx
  537. cCall LongPtrAdd,<ax,dx,dx,si>
  538. mov si, dx ; SI = selector of new PDB
  539. pop es
  540. pop dx
  541. regptr esbx,es,bx ; es:bx points at parm block
  542. mov bx,di
  543. mov cx,256 ; just include enough room for PDB
  544. cCall BuildPDB,<dx,si,esbx,cx,fWOA>; go build it
  545. mov ax,si ; link on another PDB
  546. push ds
  547. call MapDStoDATA
  548. ReSetKernelDS
  549. xchg HeadPDB,ax
  550. mov es,si
  551. mov es:[PDB_Chain],ax
  552. les di,pParmBlk
  553. push si
  554. lds si,es:[di].lpfcb1
  555. UnSetKernelDS
  556. mov di,PDB_5C_FCB
  557. pop es
  558. mov cx,ds
  559. or cx,si
  560. jz ats3b
  561. mov cx,ds:[si]
  562. inc cx
  563. inc cx
  564. cmp cx,24h
  565. jbe ats3a
  566. mov cx,24h
  567. ats3a: rep movsb
  568. ats3b: mov si,es
  569. pop ds
  570. mov ax,env_seg
  571. or ax,ax
  572. jz no_new_env
  573. mov es:[PDB_environ],ax
  574. no_new_env:
  575. ats4: mov es,pExe
  576. mov ds:[TDB_pModule],es ; Do this before InitTaskEMS
  577. mov ax,comline_start ;!!! just for now os2
  578. mov ds:[TDB_Validity],ax
  579. push si
  580. push ds
  581. push ds
  582. push es
  583. pop ds
  584. pop es
  585. mov di,TDB_ModName
  586. mov si,ds:[ne_restab]
  587. lodsb ; get no of bytes in name
  588. cbw
  589. cmp ax,8
  590. jbe @F
  591. mov ax, ds
  592. krDebugOut <DEB_WARN or DEB_krLoadMod>, "Module Name %AX0 (%AX1) too long"
  593. mov ax,8
  594. @@: mov cx,ax
  595. cld
  596. rep movsb
  597. ifdef WOW
  598. ; (see other bug #74369 note)
  599. ; Load the App compatibility flags
  600. ; This ifdef WOW chunk is the same place as Win'95 task.asm to help get compat
  601. ; flags loaded sooner
  602. mov cx,ds:[ne_expver]
  603. mov es:[TDB_ExpWinVer],cx
  604. cCall SetAppCompatFlags, <es>
  605. mov es:[TDB_CompatFlags], ax
  606. mov es:[TDB_CompatFlags2], dx
  607. if KDEBUG
  608. mov bx, ax
  609. or bx, dx
  610. jz @F
  611. krDebugOut DEB_WARN, "Backward compatibility hack enabled: #dx#AX"
  612. @@:
  613. endif
  614. endif
  615. ; initialize the interrupt vectors
  616. mov di,TDB_INTVECS
  617. call MapDStoDATA
  618. ReSetKernelDS
  619. mov ds,MyCSAlias
  620. assumes ds,CODE
  621. mov si,codeOffset prevInt00proc
  622. mov cx,(4 * numTaskInts)/2
  623. rep movsw
  624. assumes ds,nothing
  625. pop ds
  626. pop si
  627. cCall FarCreateTask ;,<fPrev>
  628. jnc @F
  629. jmp ats6
  630. @@:
  631. push ds
  632. call MapDStoDATA
  633. ReSetKernelDS
  634. mov es,curTDB ; inherit the parents
  635. pop ds
  636. UnSetKernelDS
  637. mov ds:[TDB_PDB],si ; save new PDB
  638. or si,si ; do we have a new PDB?
  639. jnz @F ; zero means no
  640. mov si,es:[TDB_PDB]
  641. mov ds:[TDB_PDB],si
  642. @@: mov ds:[TDB_Parent],es
  643. ;
  644. ; Inherit parent's wow compatibiltiy flags
  645. ; Special code is required in wkman.c to exploit this
  646. mov ax,es:[TDB_WOWCompatFlags]
  647. mov ds:[TDB_WOWCompatFlags],ax
  648. mov ax,es:[TDB_WOWCompatFlags2]
  649. mov ds:[TDB_WOWCompatFlags2],ax
  650. mov ax,es:[TDB_WOWCompatFlagsEx]
  651. mov ds:[TDB_WOWCompatFlagsEx],ax
  652. mov ax,es:[TDB_WOWCompatFlagsEx2]
  653. mov ds:[TDB_WOWCompatFlagsEx2],ax
  654. mov ds:[TDB_thread_tdb],ds
  655. mov ds:[TDB_DTA].off,80h ; set initial DTA
  656. mov ds:[TDB_DTA].sel,si
  657. mov ds:[TDB_sig],TDB_SIGNATURE ; Set signature word.
  658. mov ax,SEG default_sig_handler
  659. mov ds:[TDB_ASignalProc].sel,ax
  660. mov ax,codeOffset default_sig_handler
  661. mov ds:[TDB_ASignalProc].off,ax
  662. ; Initialize the MakeProcInstance Thunks.
  663. cCall AllocDStoCSAlias,<ds>
  664. mov ds:[TDB_MPI_Sel],ax
  665. mov ds:[TDB_MPI_Thunks],0
  666. mov ds:[TDB_MPI_Thunks].2,MPIT_SIGNATURE
  667. mov bx,TDB_MPI_Thunks + THUNKSIZE-2
  668. mov cx,THUNKELEM-1
  669. mov dx,bx
  670. mp1: add dx,THUNKSIZE
  671. .errnz THUNKELEM and 0FF00h
  672. mov ds:[bx],dx
  673. mov bx,dx
  674. loop mp1
  675. mov ds:[bx],cx
  676. mov si, ds
  677. mov di, ax
  678. call MapDStoDATA
  679. ReSetKernelDS
  680. mov ds, pGlobalHeap
  681. UnSetKernelDS
  682. .386
  683. cCall far_get_arena_pointer32,<si>
  684. cCall FarAssociateSelector32,<di, eax>
  685. .286p
  686. mov ax, si
  687. mov ds, si
  688. ats6:
  689. cEnd
  690. ;-----------------------------------------------------------------------;
  691. ; pass_environment
  692. ;
  693. ;
  694. ; Entry:
  695. ;
  696. ; Returns:
  697. ; AX = seg of new env if any
  698. ; DX = start of comline
  699. ;
  700. ; Error Return:
  701. ; AX = -1
  702. ;
  703. ; Registers Destroyed:
  704. ;
  705. ; History:
  706. ; Wed 27-Dec-1989 23:36:25 -by- David N. Weise [davidw]
  707. ; Wrote it!
  708. ;-----------------------------------------------------------------------;
  709. assumes ds,nothing
  710. assumes es,nothing
  711. ifdef WOW
  712. cProc pass_environment,<PUBLIC,NEAR>,<di,si,ds>
  713. parmW pExe
  714. parmD pParmBlk
  715. cBegin
  716. ReSetKernelDS
  717. test fBooting,1
  718. jz @F
  719. xor ax,ax
  720. jmp pe_exit
  721. @@:
  722. cCall WowPassEnvironment,<cur_DOS_PDB, pParmBlk, pExe>
  723. or ax,ax
  724. jz pe_error_exit
  725. cCall FarSetOwner,<ax,pExe> ; Make this new guy the owner
  726. jmps pe_exit
  727. pe_error_exit:
  728. mov ax, -1
  729. pe_exit:
  730. cEnd
  731. else
  732. cProc pass_environment,<PUBLIC,NEAR>,<di,si,ds>
  733. parmW pExe
  734. parmD pParmBlk
  735. localW myEnv
  736. cBegin
  737. ReSetKernelDS
  738. cld
  739. test fBooting,1
  740. jz @F
  741. xor ax,ax
  742. jmp pe_exit
  743. @@:
  744. cCall WowPassEnvironment,<Win_PDB, cur_DOS_PDB, pParmBlk, pExe>
  745. mov es,curTDB
  746. mov bl,es:[TDB_flags]
  747. @@:
  748. ; massage environment
  749. les di,pParmBlk
  750. mov ax,es:[di].envseg
  751. or ax,ax
  752. jnz pe_given_env
  753. ; %OUT This should probably be Win_PDB
  754. mov ds,cur_DOS_PDB
  755. UnsetKernelDS
  756. mov ax,ds:[PDB_environ]
  757. pe_given_env:
  758. mov myEnv,ax
  759. mov es,ax ; ES => environment
  760. xor ax,ax
  761. mov cx,-1
  762. xor di,di
  763. @@: repnz scasb
  764. cmp es:[di],al
  765. jnz @B
  766. neg cx
  767. ; dec cx ; include space for extra 0
  768. push cx ; length of environment
  769. mov dx,cx
  770. ; MORE TEST CODE TO SEE IF IT FIXES THE PROBLEM.
  771. mov es,pExe
  772. test es:[ne_flags],NEPROT
  773. jnz @f
  774. mov cx,3 ; Save room for magic word and nul
  775. add dx,cx
  776. push 8000h ; No command line after the env.
  777. jmps pe_got_com_len
  778. @@:
  779. les di,pParmBlk
  780. test bl,TDBF_OS2APP ; execer an OS/2 app?
  781. jz pe_execer_dos_app
  782. les di,es:[di].lpCmdLine
  783. mov cx,-1
  784. repnz scasb
  785. repnz scasb ; get both strings
  786. neg cx
  787. add dx,cx
  788. dec cx ; length of command line
  789. or ch,80h ; mark special
  790. push cx
  791. jmps pe_got_com_len
  792. pe_execer_dos_app:
  793. inc es:[di].lpCmdLine.off
  794. les di,es:[di].lpCmdLine
  795. xor cx,cx
  796. mov cl,es:[di][-1] ; length of command line
  797. add dx,cx
  798. inc dx ; We add a '\0' when we move it anyway
  799. push cx
  800. pe_got_com_len:
  801. mov es,pExe
  802. mov di,es:[ne_pfileinfo]
  803. lea di,[di].opfile
  804. mov cx,-1
  805. repnz scasb
  806. neg cx
  807. dec cx
  808. push cx ; length of file name
  809. shl cx,1 ; for program pointer and arg 1
  810. add dx,cx
  811. cCall GlobalAlloc,<ax,ax,dx>
  812. or ax,ax
  813. jz @f
  814. push ax
  815. cCall FarSetOwner,<ax,pExe> ; Make this new guy the owner
  816. pop ax
  817. @@:
  818. mov es,ax
  819. pop dx ; length of filename
  820. pop bx ; length of command line
  821. pop cx ; length of environment
  822. or ax,ax
  823. jz pe_error_exit
  824. mov ds,myEnv
  825. xor di,di
  826. xor si,si
  827. rep movsb
  828. mov ds,pExe
  829. ; MORE TEST CODE TO SEE IF IT FIXED THE PROBLEM
  830. test ds:[ne_flags],NEPROT
  831. jnz @f
  832. mov ax,1
  833. stosw
  834. @@:
  835. mov si,ds:[ne_pfileinfo]
  836. lea si,[si].opfile
  837. mov cx,dx ; length of filename
  838. rep movsb
  839. mov ax,di ; save position of comline start
  840. test bh,80h ; if OS/2 execer comline is correct
  841. jnz @F
  842. mov si,ds:[ne_pfileinfo]
  843. lea si,[si].opfile
  844. mov cx,dx ; length of filename
  845. rep movsb
  846. @@: and bh,NOT 80h
  847. lds si,pParmBlk
  848. lds si,ds:[si].lpCmdLine
  849. mov cx,bx
  850. rep movsb
  851. mov byte ptr es:[di],0 ; zero terminate
  852. mov dx,ax ; comline start
  853. mov ax,es
  854. jmps pe_exit
  855. pe_error_exit:
  856. mov ax,-1
  857. pe_exit:
  858. cEnd
  859. endif
  860. ;-----------------------------------------------------------------------;
  861. ; StartLibrary ;
  862. ; ;
  863. ; Initialize library registers. ;
  864. ; ;
  865. ; Arguments: ;
  866. ; parmW hExe ;
  867. ; parmD lpParms ;
  868. ; parmD startAddr ;
  869. ; ;
  870. ; Returns: ;
  871. ; ;
  872. ; Error Returns: ;
  873. ; AX = 0 ;
  874. ; DS = data segment ;
  875. ; ;
  876. ; Registers Preserved: ;
  877. ; DI,SI ;
  878. ; ;
  879. ; Registers Destroyed: ;
  880. ; BX,CX,DX,ES ;
  881. ; ;
  882. ; Calls: ;
  883. ; GetInstance ;
  884. ; FarMyLock ;
  885. ; ;
  886. ; History: ;
  887. ; ;
  888. ; Thu 04-Jan-1990 22:48:25 -by- David N. Weise [davidw] ;
  889. ; Added support for OS/2 apps. ;
  890. ; ;
  891. ; Sat Apr 18, 1987 08:54:50p -by- David N. Weise [davidw] ;
  892. ; Added this nifty comment block. ;
  893. ;-----------------------------------------------------------------------;
  894. assumes ds,nothing
  895. assumes es,nothing
  896. cProc StartLibrary,<PUBLIC,NEAR>,<ds,si,di>
  897. parmW hExe
  898. parmD lpParms
  899. parmD startAddr
  900. localW hStartSeg
  901. cBegin
  902. cCall MapDStoDATA
  903. ReSetKernelDS
  904. cmp loadTDB,0
  905. je notloading
  906. test kernel_flags,KF_pUID ; All done booting?
  907. jz notloading
  908. mov es,loadTDB
  909. test es:[TDB_Flags],TDBF_OS2APP
  910. jnz notloading
  911. mov ax,hExe
  912. mov es,es:[TDB_LibInitSeg]
  913. mov bx,es:[pStackTop]
  914. xchg es:[bx-2],ax
  915. mov es:[bx],ax
  916. add es:[pStackTop],2
  917. mov ax,hExe
  918. jmp slxx
  919. notloading:
  920. mov si,hExe
  921. mov es,si
  922. test es:[ne_flags],NEPROT
  923. jnz no_user_yet
  924. cmp pSignalProc.sel,0
  925. jz no_user_yet
  926. xor ax,ax
  927. mov bx,40h
  928. cCall pSignalProc,<hExe,bx,ax,ax,ax> ; SignalProc(hModule,40h,wParam,lParam)
  929. no_user_yet:
  930. cCall GetInstance,<si>
  931. mov di,ax
  932. cCall IGlobalHandle,<SEG_startAddr>
  933. xchg startAddr.sel,dx
  934. mov hStartSeg,ax
  935. ;** Send the SDM_LOADDLL notification
  936. mov bx,startAddr.off
  937. mov cx,startAddr.sel
  938. mov ax,SDM_LOADDLL
  939. cCall MyFarDebugCall
  940. cmp SEG_startAddr, 0
  941. jnz HaveStart
  942. mov ax, di
  943. jmps slxx
  944. HaveStart:
  945. cCall IGlobalHandle,<di>
  946. mov ds,si
  947. UnSetKernelDS
  948. mov cx,ds:[ne_heap]
  949. mov ds,dx
  950. les si,lpParms
  951. mov ax,es
  952. or ax,ax
  953. jz dont_fault
  954. les si,es:[si].lpcmdline
  955. dont_fault:
  956. mov ax,1 ; An Arts & Letters lib init doesn't
  957. push di ; touch AX!!
  958. ifdef WOW
  959. push cs
  960. push offset RetAddr
  961. pushf
  962. push startAddr.sel
  963. push startAddr.off
  964. push ax
  965. push ds
  966. push ax
  967. mov ax,hExe
  968. mov ds,ax
  969. pop ax
  970. push 0 ; hTask (meaningless for a DLL)
  971. push ds ; hModule
  972. push ds ; Pointer to module name
  973. push ds:ne_restab
  974. push ds ; Pointer to module path
  975. push word ptr ds:ne_crc+2
  976. cCall MapDStoDATA
  977. ReSetKernelDS ds
  978. push DBG_DLLSTART
  979. test DebugWOW,DW_DEBUG
  980. jz skip_bop
  981. FBOP BOP_DEBUGGER,,FastBop
  982. .286p
  983. skip_bop:
  984. add sp,+14
  985. pop ds
  986. UnSetKernelDS ds
  987. pop ax
  988. iret
  989. RetAddr equ $
  990. else
  991. cCall SafeCall,<startAddr>
  992. endif
  993. pop di ; USER.EXE didn't save DI, maybe others
  994. or ax,ax
  995. jz slx
  996. mov ax,di
  997. slx:
  998. push ax
  999. pop ax
  1000. slxx:
  1001. cEnd
  1002. ;-----------------------------------------------------------------------;
  1003. ; StartTask ;
  1004. ; ;
  1005. ; Sets up the standard register values for a Windows task. ;
  1006. ; ;
  1007. ; Arguments: ;
  1008. ; HANDLE hPrev = a previous instance ;
  1009. ; HANDLE hExe = the EXE header ;
  1010. ; FARP stackAddr = the normal task stack address (initial SS:SP) ;
  1011. ; FARP startAddr = the normal task start address (initial CS:IP) ;
  1012. ; ;
  1013. ; Returns: ;
  1014. ; AX = HANDLE ;
  1015. ; ;
  1016. ; Error Returns: ;
  1017. ; AX = NULL ;
  1018. ; ;
  1019. ; Registers Preserved: ;
  1020. ; ;
  1021. ; Registers Destroyed: ;
  1022. ; ;
  1023. ; Calls: ;
  1024. ; GetInstance ;
  1025. ; FarMyLock ;
  1026. ; ;
  1027. ; History: ;
  1028. ; ;
  1029. ; Tue Apr 21, 1987 06:41:05p -by- David N. Weise [davidw] ;
  1030. ; Added the EMS initialization of the entry tables in page 0. ;
  1031. ; ;
  1032. ; Thu Dec 11, 1986 11:38:53a -by- David N. Weise [dnw] ;
  1033. ; Removed the superfluous call to calculate the largesr NR seg. ;
  1034. ; ;
  1035. ; Fri Sep 19, 1986 12:08:23p -by- Charles Whitmer [cxw] ;
  1036. ; Made it return 0000 on error rather than terminate. ;
  1037. ; ;
  1038. ; Thu Sep 18, 1986 02:33:39p -by- Charles Whitmer [cxw] ;
  1039. ; Wrote it. ;
  1040. ;-----------------------------------------------------------------------;
  1041. assumes ds,nothing
  1042. assumes es,nothing
  1043. cProc StartTask,<PUBLIC,NEAR>,<si,di>
  1044. parmW hPrev
  1045. parmW hExe
  1046. parmD stackAddr
  1047. parmD startAddr
  1048. cBegin
  1049. cCall MapDStoDATA
  1050. ReSetKernelDS
  1051. xor di,di
  1052. cmp loadTDB,di
  1053. jnz st1
  1054. jmp stx
  1055. stfail0:
  1056. xor ax,ax
  1057. pop ds
  1058. jmp stfail
  1059. st1: push ds
  1060. cmp stackAddr.sel,di
  1061. jz stfail0
  1062. cmp startAddr.sel,di
  1063. jz stfail0
  1064. mov ds,loadTDB
  1065. UnSetKernelDS
  1066. cmp ds:[TDB_sig],TDB_SIGNATURE
  1067. jnz stfail0
  1068. ; Get new task stack
  1069. cCall IGlobalHandle,<SEG_stackAddr>
  1070. mov ds:[TDB_taskSS],dx
  1071. mov ax,stackAddr.off
  1072. sub ax,(SIZE TASK_REGS)
  1073. mov ds:[TDB_taskSP],ax
  1074. ; get my instance
  1075. cCall GetInstance,<hExe>
  1076. mov di,ax
  1077. mov ds:[TDB_Module],ax
  1078. ; find my real code segment
  1079. cCall IGlobalHandle,<SEG_startAddr>
  1080. or dx,dx
  1081. jz stfail0
  1082. mov startAddr.sel,dx
  1083. ; find my real data segment
  1084. cCall IGlobalHandle,<di> ; DI = handle of DGROUP
  1085. mov si,dx ; SI = address of DGROUP
  1086. if KDEBUG
  1087. ; Set up the allocBreak globals if needed
  1088. cCall SetupAllocBreak,<ds>
  1089. endif ;KDEBUG
  1090. ; copy junk from hExe -> TDB
  1091. mov es,hExe
  1092. mov cx,es:[ne_expver]
  1093. mov ds:[TDB_ExpWinVer],cx
  1094. mov cx,es:[ne_stack] ; CX = STACKSIZE
  1095. mov dx,es:[ne_heap] ; DX = HEAPSIZE
  1096. ; set up the task registers
  1097. test es:[ne_flags],NEPROT
  1098. jnz st_OS2_binary
  1099. les bx,dword ptr ds:[TDB_TaskSP]
  1100. mov es:[bx].TASK_AX,0 ; Task AX = NULL
  1101. mov ax,ds:[TDB_PDB]
  1102. mov es:[bx].TASK_ES,ax ; Task ES = PDB
  1103. mov es:[bx].TASK_DI,di ; Task DI = hInstance or hExe
  1104. mov es:[bx].TASK_DS,si ; Task DS = data segment
  1105. mov ax,hPrev
  1106. mov es:[bx].TASK_SI,ax ; Task SI = previous instance
  1107. mov es:[bx].TASK_BX,cx ; Task BX = STACKSIZE
  1108. mov es:[bx].TASK_CX,dx ; Task CX = HEAPSIZE
  1109. mov es:[bx].TASK_BP,1 ; Task BP = 1 (far frame)
  1110. jmps st_regs_set
  1111. st_OS2_binary:
  1112. push di
  1113. mov es,ds:[TDB_PDB]
  1114. mov di,es:[PDB_environ]
  1115. les bx,dword ptr ds:[TDB_TaskSP]
  1116. mov es:[bx].TASK_AX,di ; Task AX = environment
  1117. mov es:[bx].TASK_DX,cx ; Task DX = STACKSIZE
  1118. lsl cx,si
  1119. inc cx
  1120. mov es:[bx].TASK_CX,cx ; Task CX = Length of data segment
  1121. mov ax,ds:[TDB_pModule]
  1122. mov es:[bx].TASK_DI,ax ; Task DI = hExe
  1123. mov es:[bx].TASK_SI,dx ; Task SI = HEAPSIZE
  1124. mov es:[bx].TASK_DS,si ; Task DS = data segment
  1125. mov es:[bx].TASK_ES,0 ; Task ES = 0
  1126. mov es:[bx].TASK_BP,1 ; Task BP = 1 (far frame)
  1127. xor ax,ax
  1128. xchg ax,ds:[TDB_Validity]
  1129. mov es:[bx].TASK_BX,ax ; Task BX = offset in env of comline
  1130. pop di
  1131. st_regs_set:
  1132. pop ds
  1133. push ds
  1134. ReSetKernelDS
  1135. test Kernel_Flags[2],KF2_PTRACE ;TOOLHELP.DLL and/or WINDEBUG.DLL?
  1136. jz st_NoPTrace
  1137. mov ax,startAddr.sel
  1138. mov ptrace_app_entry.sel,ax
  1139. mov ax,startAddr.off
  1140. mov ptrace_app_entry.off,ax
  1141. mov ax,SEG CVW_HACK
  1142. mov ds,ax
  1143. UnSetKernelDS
  1144. mov ax,codeOffset CVW_Hack
  1145. jmps st_PTraceHere
  1146. st_NoPTrace:
  1147. lds ax,startAddr ; Task CS:IP = start address
  1148. UnSetKernelDS
  1149. st_PTraceHere:
  1150. mov es:[bx].TASK_CS,ds
  1151. mov es:[bx].TASK_IP,ax
  1152. pop ds
  1153. ReSetKernelDS
  1154. stx: mov ax,di
  1155. stfail:
  1156. cEnd
  1157. ;-----------------------------------------------------------------------;
  1158. ; InitTask ;
  1159. ; ;
  1160. ; This should be the first thing called by app when first started. ;
  1161. ; It massages the registers, massages the command line and inits ;
  1162. ; the heap. ;
  1163. ; ;
  1164. ; Arguments: ;
  1165. ; ;
  1166. ; When a windows application starts up the registers look ;
  1167. ; like this: ;
  1168. ; ;
  1169. ; AX = 0 ;
  1170. ; BX = stack size ;
  1171. ; CX = heap size ;
  1172. ; DX = ? ;
  1173. ; DI = hInstance ;
  1174. ; SI = hPrevInstance ;
  1175. ; BP = 0 ;
  1176. ; ES = Segment of Program Segment Prefix (see page E-8) ;
  1177. ; DS = Applications DS ;
  1178. ; SS = DS ;
  1179. ; SP = stack area ;
  1180. ; ;
  1181. ; FCB1 field at PSP:5CH contains up to 24h bytes of binary data. ;
  1182. ; Windows apps get their ShowWindow parameter in the first word of ;
  1183. ; of this data. ;
  1184. ; ;
  1185. ; Returns: ;
  1186. ; AX = PSP address ;
  1187. ; CX = stack limit ;
  1188. ; DX = command show ;
  1189. ; ES:BX = command line ;
  1190. ; ;
  1191. ; Error Returns: ;
  1192. ; ;
  1193. ; Registers Preserved: ;
  1194. ; ;
  1195. ; Registers Destroyed: ;
  1196. ; ;
  1197. ; Calls: ;
  1198. ; LocalInit ;
  1199. ; FarEMS_FirstTime ;
  1200. ; ;
  1201. ; History: ;
  1202. ; ;
  1203. ; Mon 11-Sep-1989 19:13:52 -by- David N. Weise [davidw] ;
  1204. ; Remove entry of AX = validity check. ;
  1205. ; ;
  1206. ; Wed Mar 16, 1988 22:45:00a -by- T.H. [ ] ;
  1207. ; Fix bug in exit path. It was not popping the saved DS from the ;
  1208. ; far call frame properly. Normally, this is not a problem (since ;
  1209. ; it does indeed save the DS register across the entire routine), ;
  1210. ; but if the RET has to go through a RetThunk, the saved DS is not ;
  1211. ; really the original DS value, but a special value needed by the ;
  1212. ; INT3F RetThunk code. This causes a crash when something in this ;
  1213. ; routine (like the call to UserInitDone) causes our calling code ;
  1214. ; segment to be discarded. ;
  1215. ; ;
  1216. ; Sat Apr 18, 1987 08:43:54p -by- David N. Weise [davidw] ;
  1217. ; Added this nifty comment block. ;
  1218. ;-----------------------------------------------------------------------;
  1219. STACKSLOP equ 150 ; stack slop for interrupt overhead
  1220. assumes ds,nothing
  1221. assumes es,nothing
  1222. ; ES = TDB
  1223. public do_libinit
  1224. do_libinit proc near
  1225. push si
  1226. push es
  1227. mov si,es:[TDB_LibInitOff]
  1228. mov es,cx
  1229. libinit_loop:
  1230. cld
  1231. lods word ptr es:[si]
  1232. or ax,ax
  1233. jz libinit_done
  1234. push es
  1235. mov es,ax
  1236. cmp es:[ne_magic],NEMAGIC
  1237. jne libinit_loop1
  1238. mov ax,-1
  1239. push es
  1240. cCall StartProcAddress,<es,ax>
  1241. pop es
  1242. ;;; jcxz libinit_loop1
  1243. xor cx,cx
  1244. cCall StartLibrary,<es,cx,cx,dx,ax>
  1245. or ax,ax
  1246. jnz libinit_loop1
  1247. mov ax,4CF0h
  1248. DOSFCALL
  1249. libinit_loop1:
  1250. pop es
  1251. jmp libinit_loop
  1252. libinit_done:
  1253. mov si,es
  1254. cCall GlobalUnlock,<si>
  1255. cCall GlobalFree,<si>
  1256. pop es
  1257. mov es:[TDB_LibInitSeg],0
  1258. mov es:[TDB_LibInitOff],0
  1259. pop si
  1260. ret
  1261. do_libinit endp
  1262. assumes ds,nothing
  1263. assumes es,nothing
  1264. cProc InitTask,<PUBLIC,FAR>
  1265. cBegin nogen
  1266. pop ax ; Get return address
  1267. pop dx
  1268. mov ss:[pStackMin],sp ; Save bottom of stack
  1269. mov ss:[pStackBot],sp
  1270. sub bx,sp ; Compute top of stack
  1271. neg bx
  1272. add bx,STACKSLOP
  1273. mov ss:[pStackTop],bx ; Setup for chkstk
  1274. xor bp,bp ; Initial stack frame
  1275. push bp ; is not a far frame as there
  1276. mov bp,sp ; is no return address
  1277. push dx ; Push return address back on
  1278. push ax
  1279. inc bp
  1280. push bp
  1281. mov bp,sp
  1282. push ds
  1283. jcxz noheap ; Initialize local heap if any
  1284. xor ax,ax
  1285. push es
  1286. cCall LocalInit,<ax,ax,cx>
  1287. pop es
  1288. or ax,ax
  1289. jnz noheap
  1290. push ds
  1291. jmp noinit
  1292. noheap:
  1293. push es
  1294. cCall GetCurrentTask
  1295. mov es,ax
  1296. mov cx,es:[TDB_LibInitSeg]
  1297. jcxz no_libinit
  1298. call do_libinit
  1299. no_libinit:
  1300. ifdef WOW
  1301. ; (see other bug #74369 note)
  1302. ; App compatibility flags are set during CreateTask time to make them avilable
  1303. ; to .dll's that are loaded by do_libinit (this is the same as Win'95)
  1304. else
  1305. call SetAppCompatFlags
  1306. mov es:[TDB_CompatFlags], ax
  1307. mov es:[TDB_CompatFlags2], dx
  1308. if KDEBUG
  1309. mov bx, ax
  1310. or bx, dx
  1311. jz @F
  1312. krDebugOut DEB_WARN, "Backward compatibility hack enabled: #dx#AX"
  1313. @@:
  1314. endif
  1315. endif
  1316. pop es
  1317. push ds
  1318. cCall MapDStoDATA
  1319. ReSetKernelDS
  1320. test kernel_flags,KF_pUID ; All done booting?
  1321. jnz noboot ; Yes, continue
  1322. or kernel_flags,KF_pUID
  1323. mov fBooting,0
  1324. mov cx,ds
  1325. pop ds ; DS = caller's data segment
  1326. UnSetKernelDS
  1327. push es ; Save ES
  1328. push ax
  1329. push cx
  1330. cCall IGlobalHandle,<ds>
  1331. push ax
  1332. cCall UnlockSegment,<ds>
  1333. xor dx,dx
  1334. cCall GlobalCompact,<dx,dx> ; Compact memory
  1335. xor dx,dx
  1336. cCall GlobalCompact,<dx,dx> ; Once more for completeness
  1337. cCall IGlobalHandle ; ,<ax> from above
  1338. mov ds,dx
  1339. cCall LockSegment,<ds>
  1340. pop cx
  1341. push ds
  1342. mov ds,cx
  1343. ReSetKernelDS
  1344. cmp pUserInitDone.sel,0 ; for Iris's server
  1345. jz no_User_to_call
  1346. call pUserInitDone ; Let USER lock down stuff.
  1347. no_USER_to_call:
  1348. pop ds
  1349. UnSetKernelDS
  1350. pop ax
  1351. pop es
  1352. push ds
  1353. ;** Initialize the reboot stuff here
  1354. push es ; Save across call
  1355. cCall KRebootInit ; Local reboot init code
  1356. pop es
  1357. noboot:
  1358. mov bx,PDB_DEF_DTA ; point at command line
  1359. mov cx,bx ; save copy in cx
  1360. cmp bh,es:[bx] ; any chars in command line?
  1361. je ws3a ; no - exit
  1362. ws1: inc bx ; point to next char
  1363. mov al,es:[bx] ; get the char
  1364. cmp al,' ' ; SPACE?
  1365. je ws1
  1366. cmp al,9 ; TAB?
  1367. je ws1
  1368. mov cx,bx ; save pointer to beginning
  1369. dec bx ; compensate for next inc
  1370. ws2: inc bl ; move to next char
  1371. jz ws3a ; bailout if wrapped past 0FFh
  1372. cmp byte ptr es:[bx],13 ; end of line?
  1373. jne ws2
  1374. ws3:
  1375. mov byte ptr es:[bx],0 ; null terminate the line
  1376. ws3a:
  1377. mov bx,cx ; ES:BX = command line
  1378. mov cx,ss:[pStackTop] ; CX = stack limit
  1379. mov dx,1 ; DX = default cmdshow
  1380. cmp word ptr es:[PDB_5C_FCB],2 ; Valid byte count?
  1381. jne wsa4 ; No, use default
  1382. mov dx,word ptr es:[PDB_5C_FCB][2] ; Yes, DX = passed cmdshow
  1383. wsa4:
  1384. mov ax,es ; AX = PSP address
  1385. noinit:
  1386. pop ds
  1387. ; THIS is correct way to pop the call frame. Must pop the saved
  1388. ; DS properly from stack (might have been plugged with a RetThunk).
  1389. sub bp,2
  1390. mov sp,bp
  1391. pop ds
  1392. pop bp
  1393. dec bp
  1394. ret
  1395. cEnd nogen
  1396. ;-----------------------------------------------------------------------;
  1397. ; InitLib ;
  1398. ; ;
  1399. ; Does what it says. ;
  1400. ; ;
  1401. ; Arguments: ;
  1402. ; CX = # bytes wanted for heap ;
  1403. ; ;
  1404. ; Returns: ;
  1405. ; ES:SI => null command line ;
  1406. ; ;
  1407. ; Error Returns: ;
  1408. ; CX = 0 ;
  1409. ; ;
  1410. ; Registers Preserved: ;
  1411. ; DI,DS ;
  1412. ; ;
  1413. ; Registers Destroyed: ;
  1414. ; AX,BX,DX ;
  1415. ; ;
  1416. ; Calls: ;
  1417. ; LocalInit ;
  1418. ; ;
  1419. ; History: ;
  1420. ; ;
  1421. ; Sat Apr 18, 1987 08:31:27p -by- David N. Weise [davidw] ;
  1422. ; Added this nifty comment block. ;
  1423. ;-----------------------------------------------------------------------;
  1424. assumes ds,nothing
  1425. assumes es,nothing
  1426. cProc InitLib,<PUBLIC,FAR>
  1427. cBegin nogen
  1428. xor ax,ax
  1429. jcxz noheap1 ; Done if no heap
  1430. mov si,cx
  1431. cCall LocalInit,<ax,ax,cx>
  1432. jcxz noheap1 ; Done if no heap
  1433. mov cx,si
  1434. noheap1:
  1435. push ds
  1436. cCall MapDStoDATA
  1437. push ds
  1438. pop es
  1439. pop ds
  1440. mov si,codeOFFSET nullcomline
  1441. ret
  1442. cEnd nogen
  1443. if KDEBUG
  1444. if 0
  1445. ;-----------------------------------------------------------------------
  1446. ; SetupAllocBreak
  1447. ;
  1448. ; Initializes the allocation break globals
  1449. ; from the ALLOCBRK environment variable.
  1450. ;
  1451. ; ALLOCBRK=MODULE,0x12345678
  1452. ;
  1453. ; Assumes:
  1454. ; DS = loadTDB
  1455. ;
  1456. ; Trashes:
  1457. ; ES, SI, AX, BX, CX, DX
  1458. ;
  1459. szALLOCBRK db "ALLOCBRK="
  1460. cchALLOCBRK equ $-szALLOCBRK
  1461. cProc SetupAllocBreak,<NEAR, PUBLIC>,<SI>
  1462. cBegin
  1463. mov es,ds:[TDB_PDB]
  1464. mov es,es:[PDB_environ]
  1465. lea bx,szALLOCBRK
  1466. mov dx,cchALLOCBRK
  1467. call LookupEnvString
  1468. or bx,bx
  1469. jz nomatch
  1470. ;
  1471. ; See if TDB_ModName is the same as the ALLOCBRK= module.
  1472. ;
  1473. mov si,TDB_ModName
  1474. modloop:
  1475. mov al,es:[bx] ; get next environment char
  1476. or al,al
  1477. jz nomatch ; if at end of environment, no match
  1478. cmp al,','
  1479. jz match ; if at comma, then they might match
  1480. cmp al,ds:[si]
  1481. jnz nomatch
  1482. inc bx ; advance ptrs and try next char
  1483. inc si
  1484. jmp modloop
  1485. match:
  1486. cmp byte ptr ds:[si],0 ; at end of module name string?
  1487. jnz nomatch
  1488. inc bx ; skip past comma.
  1489. call ParseHex ; parse hex constant into dx:ax
  1490. SetKernelDSNRes es
  1491. mov word ptr es:allocBreak,ax
  1492. mov word ptr es:allocBreak+2,dx
  1493. or ax,dx ; if allocBreak is 0, clear allocTask
  1494. jz @F
  1495. mov ax,ds ; otherwise allocTask = loadTDB.
  1496. @@:
  1497. mov es:allocTask,ax
  1498. xor ax,ax ; reset allocCount
  1499. mov word ptr es:allocCount,ax
  1500. mov word ptr es:allocCount+2,ax
  1501. nomatch:
  1502. cEnd
  1503. ;-----------------------------------------------------------------------
  1504. ; LookupEnvString
  1505. ;
  1506. ; ES -> environment segment
  1507. ; CS:BX -> string to search for (which must include trailing '=')
  1508. ; DX -> length of string to search for
  1509. ;
  1510. ; returns:
  1511. ; es:bx = pointer to environment string past '='
  1512. ;
  1513. cProc LookupEnvString,<NEAR, PUBLIC>,<SI,DI,DS>
  1514. cBegin
  1515. push cs ; ds = cs
  1516. pop ds
  1517. cld
  1518. xor di,di ;start at beginning of environment seg
  1519. lenv_nextstring:
  1520. mov si,bx ;si = start of compare string
  1521. mov cx,dx ;cx = string length
  1522. mov ax,di ;Save current position in env seg
  1523. repe cmpsb
  1524. je lenv_foundit
  1525. mov di,ax ; start at beginning again
  1526. xor ax,ax ; and skip to end.
  1527. xor cx,cx
  1528. dec cx ; cx = -1
  1529. repne scasb
  1530. cmp es:[di],al ;End of environment?
  1531. jne lenv_nextstring ;No, try next string
  1532. xor bx,bx ; BX == NULL == not found.
  1533. jmp short lenv_exit
  1534. lenv_foundit:
  1535. mov bx,di
  1536. lenv_exit:
  1537. cEnd
  1538. ;---------------------------------------------------------------------------
  1539. ;
  1540. ; ParseHex
  1541. ;
  1542. ; Assumes:
  1543. ; es:bx - pointer to hex string of form 0x12345678
  1544. ;
  1545. ; Returns:
  1546. ; Hex value in dx:ax, es:bx pointing to char past constant.
  1547. ;
  1548. ; Trashes:
  1549. ; cx
  1550. ;
  1551. cProc ParseHex,<NEAR, PUBLIC>
  1552. cBegin
  1553. xor dx,dx ; zero break count
  1554. xor ax,ax
  1555. xor cx,cx ; clear hi byte of char
  1556. hexloop:
  1557. mov cl,es:[bx] ; get first digit
  1558. jcxz parse_exit
  1559. inc bx
  1560. cmp cl,' ' ; skip spaces
  1561. jz hexloop
  1562. cmp cl,'x' ; skip 'x' or 'X'
  1563. jz hexloop
  1564. cmp cl,'X'
  1565. jz hexloop
  1566. cmp cl,'0' ; '0'..'9'?
  1567. jb parse_exit
  1568. cmp cl,'9'
  1569. jbe hexdigit
  1570. or cl,'a'-'A' ; convert to lower case
  1571. cmp cl,'a' ; 'a'..'f'?
  1572. jb parse_exit
  1573. cmp cl,'f'
  1574. ja parse_exit
  1575. sub cl,'a'-'0'-10
  1576. hexdigit:
  1577. sub cl,'0'
  1578. add ax,ax ; dx:ax *= 16
  1579. adc dx,dx
  1580. add ax,ax
  1581. adc dx,dx
  1582. add ax,ax
  1583. adc dx,dx
  1584. add ax,ax
  1585. adc dx,dx
  1586. add ax,cx ; add in the new digit
  1587. adc dx,0
  1588. jmp hexloop
  1589. parse_exit:
  1590. cEnd
  1591. endif; 0
  1592. endif ;KDEBUG
  1593. sEnd NRESCODE
  1594. if KDEBUG
  1595. sBegin CODE
  1596. assumes cs,CODE
  1597. ;------------------------------------------------------------------------
  1598. ;
  1599. ; char FAR* GetTaskModNamePtr(HTASK htask)
  1600. ;
  1601. ; Returns a far pointer to a task's module name
  1602. ; Used by SetupAllocBreak to access the task module name.
  1603. ;
  1604. ; Coded in assembly because no C header file that describes
  1605. ; the TDB exists (and it's a little late to create one now)
  1606. ;
  1607. cProc GetTaskModNamePtr,<NEAR, PUBLIC>
  1608. ParmW htask
  1609. cBegin
  1610. mov dx,htask
  1611. mov ax,TDB_ModName
  1612. cEnd
  1613. sEnd CODE
  1614. endif; KDEBUG
  1615. sBegin MISCCODE
  1616. assumes cs, misccode
  1617. assumes ds, nothing
  1618. assumes es, nothing
  1619. externNP MISCMapDStoDATA
  1620. ;-----------------------------------------------------------------------;
  1621. ; GetDOSEnvironment
  1622. ;
  1623. ; Gets a pointer to the current task's starting environment string.
  1624. ; Basically used by DLL's to find the environment.
  1625. ;
  1626. ; Entry:
  1627. ; none
  1628. ;
  1629. ; Returns:
  1630. ; DX:AX = pointer to current task's starting environment string
  1631. ;
  1632. ; Registers Destroyed:
  1633. ;
  1634. ; History:
  1635. ; Tue 13-Jun-1989 20:52:58 -by- David N. Weise [davidw]
  1636. ; Wrote it!
  1637. ;-----------------------------------------------------------------------;
  1638. assumes ds,nothing
  1639. assumes es,nothing
  1640. cProc GetDOSEnvironment,<PUBLIC,FAR>
  1641. cBegin nogen
  1642. push ds
  1643. call GetCurrentTask
  1644. mov ds,ax
  1645. mov ds,ds:[TDB_PDB]
  1646. mov dx,ds:[PDB_environ]
  1647. xor ax,ax
  1648. pop ds
  1649. ret
  1650. cEnd nogen
  1651. ;-----------------------------------------------------------------------;
  1652. ; GetNumTasks ;
  1653. ; ;
  1654. ; Gets the number of tasks (AKA TDB) in the system. ;
  1655. ; ;
  1656. ; Arguments: ;
  1657. ; none ;
  1658. ; ;
  1659. ; Returns: ;
  1660. ; AX = number of tasks ;
  1661. ; ;
  1662. ; Error Returns: ;
  1663. ; ;
  1664. ; Registers Preserved: ;
  1665. ; all ;
  1666. ; ;
  1667. ; Registers Destroyed: ;
  1668. ; ;
  1669. ; Calls: ;
  1670. ; nothing ;
  1671. ; ;
  1672. ; History: ;
  1673. ; ;
  1674. ; Thu Apr 09, 1987 11:34:30p -by- David N. Weise [davidw] ;
  1675. ; Wrote it. ;
  1676. ;-----------------------------------------------------------------------;
  1677. assumes ds,nothing
  1678. assumes es,nothing
  1679. cProc GetNumTasks,<PUBLIC,FAR>
  1680. cBegin nogen
  1681. xor ax,ax
  1682. push ds
  1683. call MISCMapDStoDATA
  1684. ReSetKernelDS
  1685. mov al,num_tasks
  1686. pop ds
  1687. UnSetKernelDS
  1688. ret
  1689. cEnd nogen
  1690. sEnd MISCCODE
  1691. end