Source code of Windows XP (NT5)
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.

439 lines
9.6 KiB

  1. ;
  2. ; LibInit.asm library stub to do local init for a Dynamic linked library
  3. ;
  4. ; NOTE!!!! link this MODULE first or you will be sorry!!!!
  5. ;
  6. ?PLM=1 ; pascal call convention
  7. ?WIN=0 ; Windows prolog/epilog code
  8. ?DF=1
  9. PMODE=1
  10. .286
  11. .xlist
  12. include cmacros.inc
  13. include windows.inc
  14. include sysinfo.inc
  15. include mmddk.inc
  16. include mmsystem.inc
  17. include timer.inc
  18. ;include vtdapi.inc
  19. .list
  20. .list
  21. sBegin Data
  22. ;
  23. ; Stuff needed to avoid the C runtime coming in
  24. ;
  25. ; also known as "MAGIC THAT SAVED ME" - Glenn Steffler 2/7/90
  26. ;
  27. ; Do not remove!!
  28. ;
  29. DD 0 ; So null pointers get 0
  30. maxRsrvPtrs = 5
  31. DW maxRsrvPtrs
  32. usedRsrvPtrs = 0
  33. labelDP <PUBLIC,rsrvptrs>
  34. DefRsrvPtr MACRO name
  35. globalW name,0
  36. usedRsrvPtrs = usedRsrvPtrs + 1
  37. ENDM
  38. DefRsrvPtr pLocalHeap ; Local heap pointer
  39. DefRsrvPtr pAtomTable ; Atom table pointer
  40. DefRsrvPtr pStackTop ; top of stack
  41. DefRsrvPtr pStackMin ; minimum value of SP
  42. DefRsrvPtr pStackBot ; bottom of stack
  43. if maxRsrvPtrs-usedRsrvPtrs
  44. DW maxRsrvPtrs-usedRsrvPtrs DUP (0)
  45. endif
  46. public __acrtused
  47. __acrtused = 1
  48. sEnd Data
  49. ;
  50. ;
  51. ; END of nasty stuff...
  52. ;
  53. externA WinFlags
  54. externFP LocalInit
  55. externFP Disable286
  56. externFP Enable286
  57. externW wMaxResolution
  58. externW wMinPeriod
  59. ; here lies the global data
  60. sBegin Data
  61. public wEnabled
  62. wEnabled dw 0 ; enable = 1 ;disable = 0
  63. public PS2_MCA
  64. ifdef NEC_98
  65. PS2_MCA db 0 ; Micro Channel Flag
  66. public bClockFlag ; save machine clock
  67. bClockFlag db 0 ; 5Mhz = 0 ; 8Mhz = other
  68. else ; NEC_98
  69. PS2_MCA db ? ; Micro Channel Flag
  70. endif ; NEC_98
  71. sEnd Data
  72. assumes es,nothing
  73. sBegin CodeInit
  74. assumes cs,CodeInit
  75. assumes ds,Data
  76. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  77. ;
  78. ; Library unload function
  79. ;
  80. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  81. ; Disable routine is same as WEP
  82. cProc WEP,<FAR,PUBLIC>,<>
  83. ; parmW silly_param
  84. cBegin nogen
  85. errn$ Disable
  86. cEnd nogen
  87. cProc Disable,<FAR,PUBLIC>,<>
  88. ; parmW silly_param
  89. cBegin nogen
  90. push ds
  91. mov ax,DGROUP ; set up DS==DGROUP for exported funcs
  92. mov ds,ax
  93. assumes ds,Data
  94. xor ax,ax ; return value = no error
  95. cmp wEnabled,ax ; Q: enabled ?
  96. jz dis_done ; N: exit
  97. mov wEnabled,ax ; disabled now
  98. mov ax,WinFlags
  99. test ax,WF_WIN386
  100. jnz dis_386
  101. ; running under win286
  102. dis_286:
  103. call Disable286
  104. jmp dis_done
  105. ; running under win386
  106. dis_386:
  107. call Disable286
  108. dis_done:
  109. pop ds
  110. ret 2
  111. cEnd nogen
  112. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  113. ;
  114. ; Library Enable function
  115. ;
  116. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  117. cProc Enable,<FAR,PUBLIC>,<>
  118. ; parmW silly_param
  119. cBegin nogen
  120. mov ax,wEnabled
  121. or ax,ax ; Q: already enabled ?
  122. jnz enable_done ; Y: exit
  123. inc wEnabled ; mark as being enabled
  124. ifdef NEC_98
  125. ;
  126. ; Get system clock
  127. ;
  128. mov ax,0002h
  129. mov bx,0040h ; get segment addres
  130. ; make descriptor(real mode segment)
  131. ; return the segment descriptor
  132. ; in the case of exist the appointed segment descriptor already
  133. ; (not make sure repeatedly)
  134. int 31h
  135. jc error_exit ; in the case of failed ->jmp
  136. push es
  137. mov es,ax
  138. mov al,byte ptr es:[101h] ; get system info
  139. and al,80h
  140. mov byte ptr bClockFlag,al ; save clock
  141. pop es
  142. endif ; NEC_98
  143. mov ax,WinFlags
  144. test ax,WF_WIN386
  145. jnz enable_386
  146. ; running under win286
  147. enable_286:
  148. call Enable286
  149. jmp enable_done
  150. ; running under win386
  151. enable_386:
  152. call Enable286
  153. enable_done:
  154. ret 2
  155. ifdef NEC_98
  156. error_exit:
  157. dec wEnabled ; mark as being enabled
  158. xor ax,ax
  159. ret 2
  160. endif ; NEC_98
  161. cEnd nogen
  162. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  163. ;
  164. ; Library entry point
  165. ;
  166. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  167. public LibInit
  168. LibInit proc far
  169. ; CX = size of heap
  170. ; DI = module handle
  171. ; DS = automatic data segment
  172. ; ES:SI = address of command line (not used)
  173. jcxz lib_heapok ; heap size zero? jump over unneeded LocalInit call
  174. cCall LocalInit,<ds,ax,cx> ; dataseg, 0, heapsize
  175. or ax,ax
  176. jnz lib_heapok ; if heap set continue on
  177. lib_error:
  178. xor ax,ax
  179. ret ; return FALSE (ax = 0) -- couldn't init
  180. lib_heapok:
  181. mov ax,WinFlags
  182. test ax,WF_WIN386
  183. jnz lib_386
  184. ; running under win286
  185. lib_286:
  186. call Lib286Init
  187. jmp lib_realdone ; win 286 will enable timer on first event request
  188. ; running under win386
  189. lib_386:
  190. call Lib286Init
  191. lib_realdone:
  192. ret
  193. LibInit endp
  194. sEnd
  195. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  196. ;
  197. ; Win 386 timer VTD code for initialization, and removal
  198. ;
  199. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  200. externFP GetVersion ; in KERNEL
  201. externFP MessageBox ; in USER
  202. externFP LoadString ; in USER
  203. sBegin CodeInit
  204. assumes cs,CodeInit
  205. assumes ds,Data
  206. ;externNP VTDAPI_GetEntryPt
  207. ; Assumes DI contains module handle
  208. cProc WarningMessage <NEAR,PASCAL> <>
  209. LocalV aszErrorTitle, 32
  210. LocalV aszErrorMsg, 256
  211. cBegin
  212. lea ax, WORD PTR aszErrorTitle
  213. cCall LoadString, <di, IDS_ERRORTITLE, ss, ax, 32>
  214. lea ax, WORD PTR aszErrorMsg
  215. cCall LoadString, <di, IDS_ERRORTEXT, ss, ax, 256>
  216. lea ax, WORD PTR aszErrorTitle
  217. lea bx, WORD PTR aszErrorMsg
  218. cCall MessageBox, <NULL, ss, bx, ss, ax, MB_SYSTEMMODAL+MB_OK+MB_ICONHAND>
  219. cEnd
  220. if 0
  221. Lib386Init proc near
  222. call VTDAPI_GetEntryPt ; this will return 0 if the VxD is not loaded
  223. or ax,ax
  224. jnz Lib386InitOk
  225. ifndef NEC_98
  226. DOUT <TIMER: *** unable to find vtdapi.386 ***>
  227. endif ; NEC_98
  228. ;
  229. ; warn the USER that we can't find our VxD, under windows 3.0
  230. ; we can't bring up a message box, so only do this in win 3.1
  231. ;
  232. cCall GetVersion
  233. xchg al,ah
  234. cmp ax,030Ah
  235. jb Lib386InitFail
  236. cCall WarningMessage,<>
  237. Lib386InitFail:
  238. xor ax,ax
  239. Lib386InitOk:
  240. ret
  241. Lib386Init endp
  242. endif
  243. Disable386 proc near
  244. errn$ Enable386 ; fall through
  245. Disable386 endp
  246. Enable386 proc near
  247. mov ax,1 ; nothing to do
  248. ret
  249. Enable386 endp
  250. sEnd Code386
  251. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  252. ;
  253. ; Win 286 timer drv code for initialization, and removal
  254. ;
  255. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  256. externW Events
  257. externFP tddISR ; in local.asm
  258. externFP GlobalWire ; in KERNEL
  259. externFP GlobalPageLock ; in KERNEL
  260. sBegin CodeInit
  261. assumes cs,CodeInit
  262. assumes ds,Data
  263. Lib286Init proc near
  264. ; get the system configuration
  265. ;
  266. ; the FIXED_286 segment is not loaded, load it and pagelock it.
  267. ;
  268. mov dx,seg tddISR ; get the 286 code segment
  269. mov es,dx
  270. mov ax,es:[0] ; load it!
  271. cCall GlobalWire, <dx> ; get it low in memory
  272. cCall GlobalPageLock, <dx> ; and nail it down!
  273. ifndef NEC_98
  274. mov PS2_MCA,0 ; Initialize PS2_MCA = FALSE
  275. stc ; Set this in case BIOS doesn't
  276. mov ah,GetSystemConfig
  277. int 15h
  278. jc Lib286Init_NoMicroChannel ; Successful call?
  279. or ah,ah ; Valid return?
  280. jnz Lib286Init_NoMicroChannel
  281. test es:[bx.SD_feature1],SF1_MicroChnPresent
  282. jz Lib286Init_NoMicroChannel
  283. inc PS2_MCA ; PS2_MCA = TRUE
  284. endif ; NEC_98
  285. Lib286Init_NoMicroChannel:
  286. push di
  287. push ds
  288. pop es
  289. mov di,DataOFFSET Events ; ES:DI --> Events
  290. xor ax,ax
  291. mov cx,(MAXEVENTS * SizeEvent)/2
  292. rep stosw ; zero out event structures.
  293. ; set up one event as the standard call-back routine for the
  294. ; BIOS timer service
  295. ;
  296. ifdef NEC_98
  297. mov ax,0002h
  298. mov bx,0040h
  299. int 31h
  300. jc error_init
  301. push es
  302. mov es,ax
  303. test byte ptr es:[101h],80h
  304. pop es
  305. mov cx,0f000h
  306. jz @f
  307. mov cx,0c300h
  308. @@:
  309. xor bx,bx
  310. else ; NEC_98
  311. xor bx,bx ; BX:CX = 64k
  312. xor cx,cx
  313. inc bx
  314. endif ; NEC_98
  315. mov di,DataOFFSET Events ; DS:DI --> Events
  316. mov [di].evTime.lo,cx ; Program next at ~= 55ms
  317. mov [di].evTime.hi,bx ; standard 18.2 times per second event
  318. mov [di].evDelay.lo,cx ; First event will be set off
  319. mov [di].evDelay.hi,bx ; at 55ms (65536 ticks)
  320. mov [di].evResolution,TDD_MINRESOLUTION ; Allow 55ms either way
  321. mov [di].evFlags,TIME_BIOSEVENT+TIME_PERIODIC
  322. mov ax,WinFlags
  323. test ax,WF_CPU286
  324. jz @f
  325. mov wMaxResolution,TDD_MAX286RESOLUTION
  326. mov wMinPeriod,TDD_MIN286PERIOD
  327. @@:
  328. ifdef NEC_98
  329. mov ax,0001h
  330. else ; NEC_98
  331. mov ax,bx ; Return TRUE
  332. endif ; NEC_98
  333. mov [di].evID,ax ; enable event
  334. pop di
  335. ret
  336. ifdef NEC_98
  337. error_init:
  338. xor ax,ax
  339. pop di
  340. ret
  341. endif ; NEC_98
  342. Lib286Init endp
  343. sEnd
  344. end LibInit