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.

573 lines
11 KiB

  1. page ,132
  2. title LOADHIGH Internal Command
  3. ;/*
  4. ; * Microsoft Confidential
  5. ; * Copyright (C) Microsoft Corporation 1991
  6. ; * All Rights Reserved.
  7. ; */
  8. ;
  9. ;************ LOADHIGH command -- loads programs into UMBs.
  10. ;
  11. comment %==================================================================
  12. This is a new module added to support loading programs into UMBs provided
  13. by DOS 5.0.
  14. Usage:
  15. LOADHIGH <filespec>
  16. <filespec> has to be a filename that is not wildcarded.
  17. ==========================================================================%
  18. ;
  19. ; Revision History
  20. ; ================
  21. ;
  22. ; M009 SR 08/01/90 Set flags to indicate that we are
  23. ; loading and high and also remember
  24. ; current UMB state.
  25. ;
  26. ; M016 SR 08/09/90 Give special error message on attempt
  27. ; to loadhigh batch files and invalid
  28. ; filename on Loadhigh command line.
  29. ;
  30. ; M039 SR 11/19/90 Bug #4270. Copy all the whitespaces
  31. ; after the program name also as part
  32. ; of the command line being passed to
  33. ; the program to be invoked.
  34. ;
  35. ;*** INCLUDE FILES
  36. .xlist
  37. .xcref
  38. include comseg.asm
  39. include comequ.asm
  40. include dossym.inc
  41. include syscall.inc
  42. include arena.inc
  43. .list
  44. .cref
  45. ;*** EQUATES AND STRUCTURES
  46. NUM_LH_SWS equ 5 ;number of valid switches
  47. ResultBuffer struc ; structure of parse result buffer
  48. ValueType db ?
  49. ValueTag db ?
  50. SynPtr dw ?
  51. ValuePtr dd ?
  52. ResultBuffer ends
  53. DATARES segment
  54. extrn LoadHiFlg :BYTE
  55. DATARES ends
  56. TRANDATA segment
  57. extrn ComExt :BYTE
  58. extrn ExeExt :BYTE
  59. extrn Extend_Buf_Ptr :WORD
  60. extrn Msg_Disp_Class :BYTE
  61. extrn Parse_LoadHi :BYTE
  62. extrn NoExecBat_Ptr :WORD ; M016
  63. extrn LhInvFil_Ptr :WORD ; M016
  64. TRANDATA ends
  65. TRANSPACE segment
  66. extrn ResSeg :WORD
  67. extrn ExecPath :BYTE
  68. extrn Comsw :WORD
  69. extrn Arg :BYTE
  70. extrn SwitChar :BYTE ; M039
  71. TRANSPACE ends
  72. TRANCODE segment
  73. extrn Cerror:near
  74. extrn Parse_With_Msg:near
  75. extrn Lh_Execute:near ;new execute label; M051
  76. extrn Path_Search:near
  77. assume cs:TRANGROUP,ds:TRANGROUP,es:nothing,ss:TRANGROUP
  78. ;**** LoadHigh -- Main routine for Loadhigh command
  79. ;
  80. ; ENTRY Command line tail is at PSP:81h terminated by 0dh
  81. ; CS = DS = SS = TRANGROUP
  82. ;
  83. ; EXIT None
  84. ;
  85. ; USED ax, bx, cx, dx, si, di, es
  86. ;
  87. ; ERROR EXITS
  88. ; Message pointers are setup at the error locations and then
  89. ; we jump back to CERROR which is the transient error recycle point.
  90. ; Apart from parse errors, the other errors handled are too many
  91. ; switches anf invalid filenames.
  92. ;
  93. ; EFFECTS
  94. ; The allocation strategy and the state of the arena chain are
  95. ; put in the requested state according to the given options. If a
  96. ; filename is also given, it is executed as well.
  97. ;
  98. ;
  99. public LoadHigh
  100. LoadHigh proc near
  101. push ds
  102. pop es
  103. assume es:TRANGROUP
  104. ;
  105. ;M039
  106. ; Get command tail to be passed to the program. This includes any whitespace
  107. ;chars between the program name and its parameters as well.
  108. ;On return, ds:si points at the start of the command tail.
  109. ;
  110. call GetCmdTail ;Get command tail for pgm ;M039
  111. push si ;save its start offset ;M039
  112. call ParseLhCmd ;parse the command line
  113. pop si ;restore start offset ;M039
  114. jc LhErr ;error parsing, abort
  115. call SetupCmdLine ;setup pgm's command line
  116. call SetupPath ;setup path for file
  117. jc LhErr ;file not found
  118. ;
  119. ;Set allocation strategy to HighFirst and link in UMBs for exec. This will
  120. ;be reset after return from the Exec
  121. ;We will also set a resident flag to indicate that UMBs were activated for
  122. ;the Exec. On return from the Exec, this flag will be used to deactivate UMBs
  123. ;
  124. call SetupUMBs ;set alloc strat & link state
  125. jmp Lh_Execute ;go and exec file ;M051
  126. LhErr:
  127. ;
  128. ;The error message has been setup at this stage
  129. ;
  130. jmp Cerror ;print error message and recycle
  131. LoadHigh endp
  132. ;*** ParseLhCmd -- calls system parser to parse command line
  133. ;
  134. ; ENTRY Parse block Parse_LoadHi setup
  135. ;
  136. ; EXIT Carry clear -- command line parsed successfully
  137. ; Carry set -- appropriate error message setup
  138. ;
  139. ; USED di, cx, bx, ax, si, dx
  140. ;
  141. ; EFFECTS
  142. ; Options set up
  143. ; Filename to be executed setup
  144. ;
  145. ParseLhCmd proc near
  146. assume ds:TRANGROUP, es:TRANGROUP
  147. mov si,81h ;ds:si points at command line
  148. mov Comsw,0 ;clear switch indicator
  149. mov di,offset TRANGROUP:Parse_LoadHi ;es:di = ptr to parse blk
  150. xor cx,cx ;no positionals found yet
  151. lhParse:
  152. call Parse_With_Msg
  153. cmp ax,END_OF_LINE
  154. je lhpRet ;EOL encountered, return(no carry)
  155. cmp ax,RESULT_NO_ERROR
  156. jne lhperrRet ;parse error, return
  157. ;
  158. ;Parse call succeeded. We have a filespec
  159. ;DX = ptr to result buffer
  160. ;
  161. mov bx,dx ;BX = ptr to parse result buffer
  162. call LhCopyFilename ;copy filename into our buffer
  163. jc lhpRet ;bad filename, return
  164. jmp short lhpRet ;done parsing, return (no error)
  165. lhperrRet:
  166. stc
  167. lhpRet:
  168. ret
  169. ParseLhCmd endp
  170. ;*** Lh_On -- Activate allocation of UMBs
  171. ;
  172. ; ENTRY None
  173. ;
  174. ; EXIT None
  175. ;
  176. ; USED
  177. ;
  178. ; EFFECTS
  179. ; Allocation strategy is set to HighFirst
  180. ;
  181. Lh_On proc near
  182. mov ax,(ALLOCOPER shl 8) OR 0
  183. int 21h ;get alloc strategy
  184. mov bx,ax
  185. or bx,HIGH_FIRST ;set alloc to HighFirst
  186. mov ax,(ALLOCOPER shl 8) OR 1
  187. int 21h ;set alloc strategy
  188. ret
  189. Lh_On endp
  190. ;*** Lh_Link -- links UMBs to arena
  191. ;
  192. ; ENTRY None
  193. ;
  194. ; EXIT None
  195. ;
  196. ; USED ax, bx
  197. ;
  198. ; EFFECTS
  199. ; UMBs are linked into the DOS arena chain
  200. ;
  201. Lh_Link proc near
  202. mov ax,(ALLOCOPER shl 8) OR 3
  203. mov bx,1
  204. int 21h ;link in UMBs
  205. ret
  206. Lh_Link endp
  207. ;*** LhCopyFilename -- copy filename from command line to buffer
  208. ;
  209. ; ENTRY ds:bx points at parse result block
  210. ;
  211. ; EXIT CY set -- filename has wildcards
  212. ; Setup for error message
  213. ;
  214. ; USED ax
  215. ;
  216. ; EFFECTS
  217. ; ExecPath contains the filename
  218. ;
  219. LhCopyFilename proc near
  220. assume ds:TRANGROUP, es:TRANGROUP
  221. push ds
  222. push si
  223. push di
  224. lds si,[bx].ValuePtr
  225. mov di,offset TRANGROUP:ExecPath
  226. movlp:
  227. lodsb
  228. ;
  229. ;If there are any wildcards in the filename, then we have an error
  230. ;
  231. cmp al,'*' ;wildcard?
  232. je lhfilerr ;yes, error
  233. cmp al,'?' ;wildcard?
  234. je lhfilerr ;yes, error
  235. stosb ;store char
  236. or al,al ;EOS reached?
  237. jnz movlp ;no, continue
  238. clc ;indicate no error
  239. lhcopyret:
  240. pop di
  241. pop si
  242. pop ds
  243. ret
  244. lhfilerr:
  245. mov dx,offset TRANGROUP:LhInvFil_Ptr ; "Invalid Filename" ; M016
  246. stc
  247. jmp short lhcopyret
  248. LhCopyFilename endp
  249. ;
  250. ;M039; Begin changes
  251. ;*** GetCmdTail -- scan through the command line looking for the start
  252. ; of the command tail to be passed to program that is to be invoked.
  253. ;
  254. ; ENTRY ds = TRANGROUP
  255. ; At ds:80h, command tail for lh is present.
  256. ;
  257. ; EXIT ds:si points at the command tail for program
  258. ;
  259. ; USED
  260. ;
  261. GetCmdTail proc near
  262. assume ds:TRANGROUP, es:TRANGROUP
  263. mov si,81h ;ds:si = command line for lh
  264. invoke scanoff ;scan all delims before name
  265. ;
  266. ; Skip over the program name until we hit a delimiter
  267. ;
  268. lhdo_skipcom:
  269. lodsb ;
  270. invoke delim ;is it a delimiter?
  271. jz scandone ;yes, we are done
  272. cmp AL, 0DH ;end of line?
  273. jz scandone ;yes, found command tail
  274. cmp al,SwitChar ;switch char?
  275. jnz lhdo_skipcom ;no, continue scanning
  276. scandone:
  277. dec si ;point at the command tail start
  278. ret
  279. GetCmdTail endp
  280. ;M039; End changes
  281. ;
  282. ;*** SetupCmdLine -- prepare command line for the program
  283. ;
  284. ; ENTRY ds:si = points just beyond prog name on command line
  285. ;
  286. ; EXIT None
  287. ;
  288. ; USED
  289. ;
  290. ; EFFECTS
  291. ; The rest of the command line following the pgm name is
  292. ; moved to the top of the command line buffer (at TRANGROUP:80h)
  293. ; and a new command line length is put in
  294. ;
  295. SetupCmdLine proc near
  296. assume ds:TRANGROUP, es:TRANGROUP
  297. mov di,81h
  298. xor cl,cl
  299. dec cl ;just CR means count = 0
  300. stcllp:
  301. lodsb
  302. stosb
  303. inc cl ;update count
  304. cmp al,0dh ;carriage return?
  305. jne stcllp ;no, continue storing
  306. mov es:[80h],cl ;store new cmd line length
  307. ret
  308. SetupCmdLine endp
  309. ;*** LhSetupErrMsg -- Sets up error messages
  310. ;
  311. ; ENTRY ax = error message number
  312. ;
  313. ; EXIT None
  314. ;
  315. ; USED dx
  316. ;
  317. ; EFFECTS
  318. ; Everything setup to display error message
  319. ;
  320. LhSetupErrMsg proc near
  321. assume ds:TRANGROUP, es:TRANGROUP
  322. mov msg_disp_class,EXT_MSG_CLASS
  323. mov dx,offset TranGroup:Extend_Buf_ptr
  324. mov Extend_Buf_ptr,ax
  325. ret
  326. LhSetupErrMsg endp
  327. ;
  328. ;M009; Start of changes
  329. ;
  330. ;*** GetUMBState -- get the current alloc strat and link state
  331. ;
  332. ; ENTRY None
  333. ;
  334. ; EXIT al contains the status as follows:
  335. ; b0 = 1 if Alloc strat is HighFirst
  336. ; = 0 if alloc strat is LowFirst
  337. ; b1 = 1 if UMBs are linked in
  338. ; = 0 if UMBs are unlinked
  339. ;
  340. ; USED ax, bx
  341. ;
  342. GetUMBState proc near
  343. assume ds:TRANGROUP, es:TRANGROUP
  344. mov ax,(ALLOCOPER shl 8) OR 0 ;get alloc strat
  345. int 21h
  346. mov bl,al
  347. mov ax,(ALLOCOPER shl 8) OR 2 ;get link state
  348. int 21h
  349. mov bh,al
  350. xchg ax,bx ;ax contains the state
  351. rol al,1 ;get HighFirst state in b0
  352. and al,01 ;mask off b1-b7
  353. shl ah,1 ;linkstate in b1
  354. or al,ah ;b0=HighFirst, b1=Linkstate
  355. ret
  356. GetUMBState endp
  357. ;
  358. ; M009; End of changes
  359. ;
  360. ;*** SetupUMBs -- set allocation strategy to HighFirst and link in UMBs to
  361. ; DOS arena to load the program into UMBs
  362. ;
  363. ; ENTRY None
  364. ;
  365. ; EXIT None
  366. ;
  367. ; USED
  368. ;
  369. ; EFFECTS
  370. ; Allocation strategy set to HighFirst
  371. ; UMBs linked into DOS arena
  372. SetupUMBs proc near
  373. assume ds:TRANGROUP
  374. push ds
  375. call GetUMBState ;get current state of UMBs ;M009
  376. mov ds,ds:ResSeg ; M009
  377. assume ds:DATARES ; M009
  378. mov LoadHiFlg,al ; M009
  379. or LoadHiFlg,80h ;indicate loadhigh issued ; M009
  380. pop ds
  381. assume ds:TRANGROUP
  382. call Lh_On ;alloc strategy to HighFirst
  383. call Lh_Link ;link in UMBs
  384. ret
  385. SetupUMBs endp
  386. ;*** SetupPath -- Do path search for the file to be executed
  387. ;
  388. ; ENTRY None
  389. ;
  390. ; EXIT Carry set if file not found or not executable file
  391. ;
  392. ; EFFECTS
  393. ; ExecPath contains the full path of the file to be executed
  394. ;
  395. SetupPath proc near
  396. assume ds:TRANGROUP, es:TRANGROUP
  397. ;
  398. ;Juggle around the argv pointers to make argv[1] into argv[0]. This is
  399. ;because the path search routine that we are about to invoke expects the
  400. ;filename to search for to be argv[0]
  401. ;
  402. mov ax,arg.argvcnt ;total number of arguments
  403. dec ax ;less one - skip "LoadHigh"
  404. mov bx,SIZE Argv_ele
  405. mul bx ;dx:ax = size of argument lists
  406. ;
  407. ;Move argv[1]..argv[n] to argv[0]..argv[n-1]
  408. ;
  409. mov di,offset TRANGROUP:Arg
  410. mov si,di
  411. add si,SIZE Argv_ele
  412. mov cx,ax ;size to move
  413. cld
  414. rep movsb ;Move the argument list
  415. dec arg.argvcnt ;fake one less argument
  416. call path_search ;look in the path
  417. ;
  418. ;ax = 0, no file found
  419. ;ax < 4, batch file found -- cant be executed
  420. ;ax = 4,8 => .com or .exe file found
  421. ;
  422. or ax,ax ;any file found?
  423. jz no_exec_file ;no, error
  424. cmp ax,4 ;executable file?
  425. jl no_exec_bat ;no, indicate fail ; M016
  426. clc
  427. ret
  428. no_exec_bat: ; M016
  429. mov dx,offset TRANGROUP:NoExecBat_Ptr ;Setup message ptr ; M016
  430. jmp short lhsp_errret ;return error; M016
  431. no_exec_file:
  432. mov ax,ERROR_FILE_NOT_FOUND
  433. call LhSetupErrMsg ;setup error message
  434. lhsp_errret: ; M016
  435. stc
  436. ret
  437. SetupPath endp
  438. TRANCODE ends
  439. end
  440.