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.

830 lines
19 KiB

  1. page ,132
  2. ; Copyright (c) Microsoft Corporation 1985-1990. All Rights Reserved.
  3. .sall
  4. .xlist
  5. include kernel.inc
  6. include protect.inc
  7. .list
  8. DataBegin
  9. externB Kernel_Flags
  10. externW hGlobalHeap
  11. externW pGlobalHeap
  12. externW sel_alias_array
  13. externW WinFlags
  14. externW SelTableLen
  15. externD SelTableStart
  16. DataEnd
  17. DataBegin INIT
  18. INITIAL_BLOCK_SIZE equ 0 ; one meg
  19. NUM_DPMI_BLOCKS equ 20 ; Impossibly huge number
  20. DPMI_block STRUC
  21. blksize dw 0
  22. addr_lo dw 0
  23. addr_hi dw 0
  24. DPMI_block ENDS
  25. DPMI_memory DPMI_block NUM_DPMI_BLOCKS DUP (<>)
  26. top_block dw ?
  27. DataEnd INIT
  28. sBegin INITCODE
  29. assumes CS,CODE
  30. externW gdtdsc
  31. externNP get_physical_address
  32. externNP set_physical_address
  33. externNP set_sel_limit
  34. externNP alloc_data_sel
  35. externNP get_arena_pointer
  36. externNP get_rover_2
  37. externNP AssociateSelector
  38. externNP AllocDpmiBlock
  39. externNP FormatHeapBlock
  40. externNP AddBlockToHeap
  41. externFP GlobalAlloc
  42. externNP DPMIProc
  43. GA_ALIGN_BYTES = (((GA_ALIGN+1) SHL 4) - 1)
  44. GA_MASK_BYTES = NOT GA_ALIGN_BYTES
  45. ;-----------------------------------------------------------------------;
  46. ; GlobalPigAll ;
  47. ; ;
  48. ; Allocates all the DPMI memory in the system as blocks of 1 Meg. ;
  49. ; or smaller. Stores the addresses and sizes in the DPMI_memory array. ;
  50. ; ;
  51. ;-----------------------------------------------------------------------;
  52. cProc GlobalPigAll,<NEAR,PUBLIC>,<ds,es,di,si,ax,bx,cx,dx>
  53. localV MemInfo,30h
  54. localW saveCX
  55. cBegin
  56. smov es, ss
  57. SetKernelDS
  58. ifdef WOW
  59. ; DOSX is not efficient about the way it manages its heap. If we alloc
  60. ; the largest block an then free it - it will do better management
  61. ; when we alloc 1Mbyte chunks. Otherwise it will alloc 3 selectors
  62. ; and 1k of unused memory per megabyte
  63. lea di, MemInfo
  64. DPMICALL 0500h ; Get Free Memory Info
  65. mov cx, es:[di] ; BX:CX gets largest free block
  66. mov bx, es:[di+2]
  67. or ax,bx
  68. jz idb_gotblocks ; None to be had!
  69. DPMICALL 0501h ; allocate is all
  70. DPMICALL 0502h ; Free it all
  71. endif; WOW
  72. mov si,dataOffset DPMI_memory ; DS:SI -> first DPMI_block
  73. mov cx,NUM_DPMI_BLOCKS
  74. idb_getblock:
  75. mov word ptr saveCX,cx
  76. lea di, MemInfo
  77. DPMICALL 0500h ; Get Free Memory Info
  78. mov cx, es:[di] ; BX:CX gets largest free block
  79. mov bx, es:[di+2]
  80. mov ax,cx
  81. or ax,bx
  82. jz idb_gotblocks ; None to be had!
  83. cmp bx,0010h ; 1 Meg. or more available?
  84. jb @F ; No, use what is available
  85. mov bx,0010h
  86. xor cx,cx
  87. @@: ; BX:CX is bytes to allocate
  88. mov dx,bx ; copy to DX:AX
  89. mov ax,cx
  90. rept 4
  91. shr dx,1
  92. rcr ax,1
  93. endm
  94. mov [si].blksize,ax ; Size is #paragraphs we hope to get
  95. ;
  96. ; This call returns an address in BX:CX, and a handle in SI:DI. We don't
  97. ; use the handle for anything, but we do use SI here.
  98. ;
  99. push si
  100. DPMICALL 0501h ; allocate the block
  101. pop si
  102. jc idb_gotblocks
  103. mov [si].addr_lo,cx
  104. mov [si].addr_hi,bx
  105. add si,SIZE DPMI_block
  106. mov cx,word ptr saveCX
  107. loop idb_getblock
  108. idb_gotblocks:
  109. mov [top_block],si
  110. UnsetKernelDS
  111. cEnd
  112. ;
  113. ;-----------------------------------------------------------------------;
  114. ; Find_DPMI_block ;
  115. ; ;
  116. ; Allocate a block of memory from DPMI that is 1 megabyte in size, ;
  117. ; or the largest available block if smaller. ;
  118. ; ;
  119. ; RETURNS: AX = selector to block if allocated ;
  120. ; AX = zero if error ;
  121. ; CX = size of block in paragraphs (yech!) ;
  122. ; CX = zero if block is 1 megabyte in size. ;
  123. ;-----------------------------------------------------------------------;
  124. cProc Find_DPMI_block,<PUBLIC,NEAR>,<ds,si,es,di,bx,dx>
  125. localV MemInfo,30h
  126. localW SizeOfBlock
  127. cBegin
  128. SetKernelDS
  129. smov es, ds
  130. xor ax,ax ; AX = 0
  131. mov si,dataOffset DPMI_memory ; DS:SI -> first DPMI_block
  132. adb_findfirstblock:
  133. cmp si,[top_block]
  134. jnb adb_ret
  135. mov cx,[si].addr_lo
  136. mov bx,[si].addr_hi
  137. or bx,cx
  138. jnz adb_foundfirstblock
  139. add si,SIZE DPMI_block ; SI -> next block
  140. jmp adb_findfirstblock
  141. adb_foundfirstblock:
  142. mov di,si ; SI -> first block
  143. adb_nextblock:
  144. add di,SIZE DPMI_block ; DI -> next block
  145. cmp di,[top_block]
  146. jnb adb_foundblock
  147. mov dx,[si].addr_lo ; which block is lower?
  148. cmp dx,[di].addr_lo
  149. mov dx,[si].addr_hi
  150. sbb dx,[di].addr_hi
  151. jb adb_nextblock ; block at si is lower than block at di
  152. mov dx,[si].addr_lo
  153. xchg dx,[di].addr_lo
  154. xchg dx,[si].addr_lo
  155. mov dx,[si].addr_hi
  156. xchg dx,[di].addr_hi
  157. xchg dx,[si].addr_hi
  158. mov dx,[si].blksize
  159. xchg dx,[di].blksize
  160. xchg dx,[si].blksize
  161. jmp adb_nextblock
  162. adb_foundblock: ; DS:SI -> block to use
  163. mov bx,ax
  164. mov cx,ax
  165. xchg bx,[si].addr_hi
  166. xchg cx,[si].addr_lo
  167. cCall alloc_data_sel,<bx,cx,1>; Get selector for start of block
  168. ; (return result)
  169. mov cx,[si].blksize
  170. adb_ret:
  171. UnsetKernelDS
  172. cEnd
  173. ;-----------------------------------------------------------------------;
  174. ; GlobalInit ;
  175. ; ;
  176. ; Procedure to initialize the global heap. ;
  177. ; ;
  178. ; Arguments: ;
  179. ; parmW hdelta = size (.25k) of master object ;
  180. ; parmW palloc = selector of block to mark allocated ;
  181. ; parmW pstart = selector pointing to first available address ;
  182. ; parmW pend = selector pointing to last available address ;
  183. ; ;
  184. ; Note: for the ROM kernel, palloc is actually the size in bytes ;
  185. ; of the allocated block, not a pointer! ;
  186. ; ;
  187. ; Returns: ;
  188. ; AX = handle for allocated block ;
  189. ; ;
  190. ; Error Returns: ;
  191. ; ;
  192. ; Alters: ;
  193. ; ES ;
  194. ; Calls: ;
  195. ; ginit ;
  196. ; ;
  197. ; History: ;
  198. ; ;
  199. ; Fri May 05, 1989 09:40:00a -by- Jim Mathews [jimmat] ;
  200. ; Dear diary, many things have happened since the last comment entry... ;
  201. ; Added code to allocate a block of conventional memory and link it ;
  202. ; into the Windows global heap when running under the 286 DOS extender. ;
  203. ; ;
  204. ; Sat Jun 20, 1987 05:55:35p -by- David N. Weise [davidw] ;
  205. ; Making real EMS work with the fast boot version. ;
  206. ; ;
  207. ; Sun Mar 15, 1987 06:38:04p -by- David N. Weise [davidw] ;
  208. ; Added support for the linked free list long ago. ;
  209. ; ;
  210. ; Wed Feb 18, 1987 08:09:18p -by- David N. Weise [davidw] ;
  211. ; Added the initialization of the gi_alt entries. ;
  212. ; ;
  213. ; Mon Sep 08, 1986 07:53:41p -by- David N. Weise [davidw ;
  214. ; Changed the return values so that this can be called from other than ;
  215. ; initialization code. ;
  216. ;-----------------------------------------------------------------------;
  217. cProc GlobalInit,<PUBLIC,NEAR>,<ds,si,di>
  218. parmW hdelta
  219. parmW palloc
  220. parmW pstart
  221. parmW pend
  222. localW hInitMem
  223. localW allocated_sel
  224. localW next_block
  225. localW free_hi
  226. localW free_lo
  227. localV MemInfo,30h
  228. cBegin
  229. mov ax,palloc ; AX = block to mark allocated
  230. mov bx,pstart ; BX = first available address
  231. mov cx,hdelta ; CX = size (.25k) of master object
  232. mov dx,pend ; DX = last available address
  233. call ginit
  234. mov allocated_sel,ax
  235. xor di,di ; Initialize master object
  236. mov [di].hi_first,bx ; Fill in pointers to first and
  237. mov [di].hi_last,dx ; last blocks
  238. mov [di].hi_count,5 ; 5 arena entries
  239. or ax,ax
  240. jnz allocated_block
  241. mov [di].hi_count,4 ; 4 arena entries
  242. allocated_block:
  243. mov [di].gi_lruchain,di ; Nothing in LRU list so far
  244. mov [di].gi_lrucount,di
  245. mov [di].gi_lrulock,di ; ...and not locked
  246. mov [di].gi_reserve,di ; No discardable code reserve area yet
  247. cCall get_physical_address, <dx>
  248. mov word ptr [di].gi_disfence,ax ; gi_disfence = hi_last
  249. mov word ptr [di].gi_disfence_hi,dx
  250. mov [di].hi_hdelta,32
  251. mov [di].gi_alt_first,-1 ; Fill in pointers to first and
  252. mov [di].gi_alt_last,-1 ; last blocks, the -1 is necessary!!
  253. mov [di].gi_alt_count,di ; # of arena entries
  254. mov [di].gi_alt_lruchain,di
  255. mov [di].gi_alt_lrucount,di ; MUST be 0!
  256. mov [di].gi_alt_free_count,di
  257. mov [di].gi_alt_reserve,di
  258. mov [di].gi_alt_disfence,di
  259. mov [di].gi_alt_pPhantom,-1 ; MUST be -1!
  260. mov bx,ds
  261. SetKernelDS es
  262. mov hGlobalHeap,bx
  263. cCall get_arena_pointer,<ds>
  264. mov es,ax
  265. assumes es,nothing
  266. mov es:[di].ga_handle,bx ; Point master object to handle
  267. mov es:[di].ga_count,0
  268. push es:[di].ga_next ; Push free block arena
  269. ife ROM
  270. mov es, [di].hi_last
  271. endif
  272. mov es,es:[di].ga_prev ; Point to allocated object before
  273. mov bx,allocated_sel
  274. StoH bl ; It is moveable
  275. mov es:[di].ga_handle,bx
  276. mov hInitMem,bx
  277. if ROM ; For ROM Windows, the alloc block is
  278. mov es:[di].ga_count,1 ; krnl DS which needs to be locked!
  279. else
  280. mov es:[di].ga_count,0
  281. endif
  282. no_allocated_object:
  283. ; initialize free list
  284. mov [di].gi_free_count,1
  285. mov ax,[di].hi_first
  286. mov cx,[di].hi_last
  287. mov es,ax
  288. pop bx ; Free block arena
  289. mov es:[di].ga_freeprev,-1 ; Fill in first sentinal
  290. mov es:[di].ga_freenext,bx
  291. mov es,cx
  292. mov es:[di].ga_freeprev,bx ; Fill in last sentinal
  293. mov es:[di].ga_freenext,-1
  294. mov es,bx
  295. mov es:[di].ga_freeprev,ax ; Link in free block
  296. mov es:[di].ga_freenext,cx
  297. GI_done:
  298. ;
  299. ; Allocate a block for the heap
  300. ;
  301. mov ax,INITIAL_BLOCK_SIZE
  302. xor si,si
  303. call AllocDpmiBlock
  304. or bx,bx
  305. jnz ginom
  306. mov si,1
  307. ginom: mov dx,ax
  308. call FormatHeapBlock ;build the arenas in the XMS block
  309. assume es:NOTHING
  310. call AddBlockToHeap
  311. if ALIASES
  312. call init_alias_list
  313. endif
  314. mov ax,hInitMem
  315. clc
  316. jmps @f
  317. GI_fail:
  318. xor ax,ax
  319. stc
  320. @@:
  321. cEnd
  322. gi_set_size proc near
  323. cCall get_physical_address, <es:[di].ga_next>
  324. mov bx, ax
  325. mov cx, dx
  326. cCall get_physical_address, <es>
  327. sub bx, ax
  328. sbb cx, dx
  329. rept 4
  330. shr cx, 1
  331. rcr bx, 1
  332. endm
  333. dec bx
  334. mov es:[di].ga_size, bx
  335. ret
  336. gi_set_size endp
  337. ;-----------------------------------------------------------------------;
  338. ; ginit ;
  339. ; ;
  340. ; Procedure to initialize the global heap. ;
  341. ; ;
  342. ; The global heap looks as follows after this procedure returns: ;
  343. ; ;
  344. ; BX - first object in arena, alway busy, zero length. ;
  345. ; - free object ;
  346. ; AX - allocated object ;
  347. ; DS - master object ;
  348. ; DX - last object in arena, alway busy, zero length. ;
  349. ; ;
  350. ; ;
  351. ; Arguments: ;
  352. ; AX = address of block to mark allocated. May be zero. ;
  353. ; BX = address of first paragraph in arena ;
  354. ; DX = address of last paragraph in arena ;
  355. ; CX = initial size of master object, in bytes ;
  356. ; ;
  357. ; Note: for the ROM kernel, AX is actually the size in bytes of ;
  358. ; the allocated block, not it's address. ;
  359. ; ;
  360. ; Returns: ;
  361. ; AX = aligned address of block marked allocated. ;
  362. ; BX = aligned address of first object in arena ;
  363. ; CX = size of master object, in bytes ;
  364. ; DX = aligned address of last object in arena ;
  365. ; DS = aligned address of master object ;
  366. ; ;
  367. ; Registers Preserved: ;
  368. ; ;
  369. ; Registers Destroyed: ;
  370. ; DI,SI,ES ;
  371. ; Calls: ;
  372. ; nothing ;
  373. ; History: ;
  374. ; ;
  375. ; Thu Sep 11, 1986 04:22:02p -by- David N. Weise [davidw] ;
  376. ; Commented it, made it handle the case of no allocated block correctly.;
  377. ;-----------------------------------------------------------------------;
  378. cProc ginit,<PUBLIC,NEAR>
  379. localW size_free
  380. localW size_allocated
  381. localW size_master
  382. localW allocated_arena
  383. localW allocated_sel
  384. localW BurgerMaster_arena
  385. localW BurgerMaster_sel
  386. localW new_last_sel
  387. localW size_free_hi
  388. localW marker_arena
  389. cBegin
  390. ; SI = the first block address (sentinel, always busy)
  391. CheckKernelDS
  392. ReSetKernelDS
  393. if ROM
  394. xchg ax,dx ; want diff stack order if ROM
  395. mov allocated_sel, ds ; something of a hack that this
  396. ; code 'knows' DS is the alloc
  397. ; block
  398. endif
  399. push ax
  400. push dx
  401. cCall get_physical_address,<bx> ; Start of our memory
  402. %OUT Is alignment necessary???
  403. add ax, GA_ALIGN_BYTES ; Align our start
  404. adc dx, 0
  405. and ax, GA_MASK_BYTES
  406. cCall set_physical_address, <bx>
  407. mov si, bx ; first sentinal
  408. mov bx, 10h ; just an arena
  409. xor cx, cx
  410. cCall set_sel_limit, <si>
  411. if ROM ;----------------------------------------------------------------
  412. ; The allocated block (kernel's data segment) is next, and already in place
  413. add ax, 10h+GA_ALIGN_BYTES
  414. adc dx, 0
  415. and al, GA_MASK_BYTES
  416. push ax
  417. cCall alloc_data_sel,<dx,ax,1> ; Get arena for data seg
  418. mov allocated_arena, ax
  419. pop ax
  420. if KDEBUG
  421. push dx
  422. push ax
  423. mov cx,ax
  424. mov bx,dx
  425. add cx,10h
  426. adc bx,0 ; BX:CX better -> DS
  427. cCall get_physical_address,<ds>
  428. cmp ax,cx
  429. jne rom_oh_no
  430. cmp dx,bx
  431. jz @f
  432. rom_oh_no:
  433. Debug_Out "ginit: DS arena in wrong spot!"
  434. @@:
  435. pop ax
  436. pop dx
  437. endif
  438. pop bx ; size of alloc block
  439. add ax,bx
  440. adc dx,0
  441. add bx,15 ; save size of alloc
  442. and bl,NOT 15 ; block in paragraphs
  443. shr bx,4
  444. mov size_allocated,bx
  445. endif ;ROM ---------------------------------------------------------
  446. ; CX = where the master object goes (second block)
  447. add ax, 10h+GA_ALIGN_BYTES ; Skip past sentinal
  448. adc dx, 0
  449. and al, GA_MASK_BYTES
  450. push ax
  451. cCall alloc_data_sel,<dx, ax, 1> ; Get arena for BurgerMaster
  452. mov BurgerMaster_arena, ax
  453. mov cx, size GlobalInfo+1
  454. and cl, NOT 1 ; Word align selector table -
  455. mov word ptr SelTableStart, cx ; it starts after GlobalInfo
  456. ;;;mov ax, 8*1024 ; Selector table length
  457. mov ax, 8*1024*2 ; Assume 8k sels * 2 bytes each
  458. test [WinFlags], WF_ENHANCED ; Slime to allow 286 krnl under
  459. jnz @f ; 386enh mode where LDT grows
  460. mov bx, gdtdsc
  461. or bx, bx
  462. jz @f ; If we party on the LDT,
  463. lsl ax, bx ; use the LDT limit to size
  464. add ax, 1 ; the table
  465. rcr ax, 1
  466. shr ax, 1 ; ASSUMES LDT DOES NOT GROW!!!
  467. @@:
  468. mov SelTableLen, ax
  469. add cx, ax
  470. add cx, GA_ALIGN_BYTES+10h ; Include arena header
  471. and cl, GA_MASK_BYTES
  472. pop ax ; DX:AX is address of arena
  473. mov bx, cx
  474. shr bx, 4 ; length in paras
  475. dec bx ; excluding arena header
  476. mov size_master, bx
  477. push ax ; Save start of master object arena
  478. push dx
  479. add ax, 10h
  480. adc dx, 0
  481. cCall alloc_data_sel, <dx, ax, bx>
  482. mov BurgerMaster_sel, ax
  483. pop dx
  484. pop ax
  485. add ax, cx ; Move past master object
  486. adc dx, 0
  487. ; DI = the third block address (initial free block)
  488. cCall alloc_data_sel,<dx, ax, 1>
  489. mov di, ax ; First free block
  490. ; DX = the last block address (sentinel, always busy)
  491. if ROM
  492. pop dx
  493. cCall get_physical_address,<dx> ; End of our world
  494. else
  495. pop ax
  496. xor dx, dx
  497. REPT 4
  498. shl ax, 1
  499. rcl dx, 1
  500. ENDM
  501. endif
  502. sub ax, 10h
  503. sbb dx, 0
  504. and ax, GA_MASK_BYTES
  505. mov bx, ax ; Save end of allocated block
  506. mov cx, dx
  507. cCall alloc_data_sel, <dx, ax, 1>
  508. mov new_last_sel, ax ; Save it away
  509. ife ROM ;----------------------------------------------------------------
  510. pop ax ; Allocated Block
  511. cCall get_physical_address, <ax>
  512. sub ax, 10h ; Make room for arena
  513. sbb dx, 0
  514. and al, GA_MASK_BYTES ; "Align" it
  515. sub bx, ax
  516. sbb cx, dx ; Length in bytes
  517. rept 4
  518. shr cx, 1
  519. rcr bx, 1
  520. endm
  521. dec bx ; Length in paras
  522. mov size_allocated, bx
  523. push ax
  524. cCall alloc_data_sel, <dx, ax, 1>
  525. mov allocated_arena, ax
  526. pop ax
  527. add ax, 10h
  528. adc dx, 0
  529. push ax
  530. cCall alloc_data_sel, <dx, ax, 1000h>
  531. mov allocated_sel, ax
  532. pop ax
  533. sub ax, 10h
  534. sbb dx, 0 ; Back to arena
  535. mov bx, ax
  536. mov cx, dx ; cx:bx = addr allocated arena
  537. endif ;ROM ---------------------------------------------------------
  538. cCall get_physical_address, <di>
  539. sub bx, ax
  540. sbb cx, dx ; Length in bytes of free block
  541. rept 4
  542. shr cx, 1
  543. rcr bx, 1
  544. endm
  545. sub bx, 1 ; Length in paras
  546. sbb cx, 0
  547. mov size_free, bx
  548. mov size_free_hi, cx
  549. mov ax, allocated_arena
  550. mov cx, BurgerMaster_arena
  551. mov dx, new_last_sel
  552. ; Fill in first block
  553. mov ds,si
  554. assumes ds, nothing
  555. xor bx,bx
  556. mov ds:[bx].ga_sig,GA_SIGNATURE
  557. mov ds:[bx].ga_size,GA_ALIGN
  558. mov ds:[bx].ga_owner,-1
  559. mov ds:[bx].ga_flags,bl
  560. mov ds:[bx].ga_prev,ds ; first.prev = self
  561. if ROM
  562. mov ds:[bx].ga_next,ax ; Next is the allocated block
  563. else
  564. mov ds:[bx].ga_next,cx ; Next is master object
  565. endif
  566. mov ds:[bx].ga_handle,bx
  567. mov ds:[bx].ga_lrunext,bx
  568. mov ds:[bx].ga_lruprev,bx
  569. push ds ; Save pointer to first block
  570. ; Fill in the last block (sentinel block)
  571. mov ds,dx
  572. mov ds:[bx].ga_sig,GA_ENDSIG
  573. mov ds:[bx].ga_size,GA_ALIGN
  574. mov ds:[bx].ga_owner,-1 ; Always allocated
  575. mov ds:[bx].ga_next,ds ; last.next = self
  576. mov ds:[bx].ga_flags,bl
  577. mov ds:[bx].ga_handle,bx
  578. mov ds:[bx].ga_lrunext,bx
  579. mov ds:[bx].ga_lruprev,bx
  580. push ds ; Save pointer to last block
  581. if ROM
  582. mov ds:[bx].ga_prev,di ; Previous is free block
  583. else
  584. mov ds:[bx].ga_prev,ax ; Previous is allocated block
  585. endif
  586. ; Fill in the allocated block
  587. mov ds,ax
  588. if ROM
  589. mov ds:[bx].ga_next, cx ; next object is burger master
  590. else
  591. mov ds:[bx].ga_next, dx ; next object is sentinel
  592. endif
  593. mov dx,size_allocated
  594. mov ds:[bx].ga_sig,GA_SIGNATURE
  595. mov ds:[bx].ga_size,dx
  596. mov ds:[bx].ga_owner,-1
  597. mov ds:[bx].ga_flags,bl
  598. mov ds:[bx].ga_handle,bx
  599. mov ds:[bx].ga_lruprev,bx
  600. mov ds:[bx].ga_lrunext,bx
  601. if ROM
  602. mov ds:[bx].ga_prev, si ; Previous object is sentinal
  603. else
  604. mov ds:[bx].ga_prev, di ; Previous object is free block
  605. endif
  606. ; Fill in free block
  607. mov ds,di
  608. if ROM
  609. mov dx,new_last_sel
  610. mov ds:[bx].ga_next, dx ; Next ojb is last block
  611. else
  612. mov ds:[bx].ga_next, ax ; Next obj allocated block
  613. endif
  614. mov dx,size_free
  615. cmp size_free_hi, 0
  616. je gi_small
  617. xor dx, dx ; BOGUS VALUE!!
  618. gi_small:
  619. mov ds:[bx].ga_sig,GA_SIGNATURE
  620. mov ds:[bx].ga_owner,bx ; This is a free block
  621. mov ds:[bx].ga_flags,bl
  622. mov ds:[bx].ga_size,dx
  623. mov ds:[bx].ga_prev,cx
  624. mov ds:[bx].ga_handle,bx
  625. mov ds:[bx].ga_lruprev,bx
  626. mov ds:[bx].ga_lrunext,bx
  627. ; Fill in the master object
  628. mov ds,cx
  629. mov ds:[bx].ga_next,di
  630. if ROM
  631. mov ds:[bx].ga_prev,ax ; prev obj is allocated block
  632. else
  633. mov ds:[bx].ga_prev,si
  634. endif
  635. mov cx,size_master
  636. mov ds:[bx].ga_sig,GA_SIGNATURE
  637. mov ds:[bx].ga_size,cx
  638. mov ds:[bx].ga_owner,-3
  639. mov ds:[bx].ga_flags,bl
  640. mov ds:[bx].ga_handle,bx ; No handle table entry for this
  641. ; moveable object yet.
  642. mov ds:[bx].ga_lruprev,bx
  643. mov ds:[bx].ga_lrunext,bx
  644. ; Initialize master object
  645. ; CX = size of master object in paras
  646. ;;; mov dx, ds ; DX = address of master object
  647. mov dx,BurgerMaster_sel
  648. shl cx,1 ; Get size of master object in words
  649. shl cx,1
  650. shl cx,1
  651. push cx ; save size in words
  652. SetKernelDS
  653. mov pGlobalHeap,dx
  654. mov es,dx
  655. assumes es,nothing
  656. xor ax,ax
  657. xor di,di ; Init master object to zero
  658. rep stosw
  659. mov ds,dx ; Switch to master object as our DS
  660. UnSetKernelDS
  661. cCall AssociateSelector,<ds,BurgerMaster_arena>
  662. pop cx
  663. shl cx,1 ; CX = size of master object in bytes
  664. mov ax, allocated_sel ; AX = address of allocated block
  665. cCall AssociateSelector,<ax,allocated_arena>
  666. pop dx ; DX = address of last block
  667. pop bx ; BX = address of first block
  668. cEnd
  669. ;-----------------------------------------------------------------------;
  670. ; init_alias_list
  671. ;
  672. ;
  673. ; Entry:
  674. ;
  675. ; Returns:
  676. ;
  677. ; Registers Destroyed:
  678. ;
  679. ; History:
  680. ; Mon 15-Jan-1990 23:59:36 -by- David N. Weise [davidw]
  681. ; Wrote it!
  682. ;-----------------------------------------------------------------------;
  683. assumes ds,nothing
  684. assumes es,nothing
  685. cProc init_alias_list,<PUBLIC,NEAR>
  686. cBegin nogen
  687. push ds
  688. SetKernelDS
  689. cCall GlobalAlloc,<GA_ZEROINIT,0,256>
  690. or ax,ax
  691. jz ial_exit
  692. mov sel_alias_array,ax
  693. mov es,ax
  694. xor di,di
  695. mov es:[di].sa_size,256 - SIZE SASTRUC
  696. mov es:[di].sa_allocated,(256 - (SIZE SASTRUC)) / (SIZE SAENTRY)
  697. mov ax,1 ; signify success
  698. ial_exit:
  699. pop ds
  700. ret
  701. cEnd nogen
  702. sEnd INITCODE
  703. end