|
|
1.1 ! root 1: TITLE stdalloc - memory allocation routine for stdargv, stdenvp ! 2: ;*** ! 3: ;stdalloc.asm - memory allocation routine for stdargv, stdenvp ! 4: ; ! 5: ; Copyright (c) 1985-1987, Microsoft Corporation. All rights reserved. ! 6: ; ! 7: ;Purpose: ! 8: ; Memory allocation for stdargv and stdenvp. ! 9: ; ! 10: ;******************************************************************************* ! 11: ! 12: include version.inc ! 13: .xlist ! 14: ifdef _QC ;[3] Move these includes out of version.inc ! 15: include \sl\qc\src\include\kernel.inc ;[3] ! 16: include \sl\qc\src\include\kmac.inc ;[3] ! 17: endif ;_QC ;[3] ! 18: ! 19: include cmacros.inc ! 20: include msdos.inc ! 21: include brkctl.inc ! 22: .list ! 23: ! 24: ! 25: sBegin data ! 26: assumes ds,data ! 27: externW _psp ; PSP segment # ! 28: externW _abrktb ; break table for allocation ! 29: externW _asizds ; break table for allocation end ! 30: ! 31: ifdef _QC ; [1] ! 32: extrn __QCrtcsip:DWORD ; [1] ! 33: endif ;_QC ; [1] ! 34: ! 35: sEnd data ! 36: ! 37: sBegin code ! 38: assumes ds,data ! 39: assumes cs,code ! 40: ! 41: externNP _amsg_exit ; write error and die routine ! 42: ! 43: page ! 44: ;*** ! 45: ;_myalloc - low overhead heap allocation ! 46: ; ! 47: ;Purpose: ! 48: ; Used to allocate heap space, without the overhead of ! 49: ; malloc for both wildcard arguments and environment strings, ptrs. ! 50: ; ! 51: ; Tries to find space in heap, failing this calls dos to extend ! 52: ; heap and tries again, failing this spits out error message and ! 53: ; dies. ! 54: ; ! 55: ;Entry: ! 56: ; BP = number of bytes in table ( argv/ or envp ) ! 57: ; AX = total number of bytes to allocate table and strings ! 58: ; DI = error message number in case of death. ! 59: ; ! 60: ;Exit: ! 61: ; BP = points to table ! 62: ; AX = size of table in bytes. ! 63: ; ! 64: ;Uses: ! 65: ; ! 66: ;Exceptions: ! 67: ; If can't get enough memory, gives ! 68: ; error 2009/2008: no space for enviroment/arguments ! 69: ; and then dies. ! 70: ; ! 71: ;******************************************************************************* ! 72: ! 73: ! 74: cProc _myalloc,<NEAR,PUBLIC>,<> ! 75: ! 76: cBegin nogen ! 77: assumes ds,data ! 78: mov dx,ax ; save size of environment ! 79: add ax,[_abrktb].sz ; ax = DS offset of end of environment ! 80: jc _hpovr ; environment won't fit w/in 64k ! 81: ; give error ! 82: cmp [_asizds],ax ; will env fit in allocated mem? ! 83: jnc _hpok ; yes, go move it ! 84: ; need more memory ! 85: add ax,15d ; round up to nearest paragraph ! 86: push ax ; save this for later ! 87: rcr ax,1 ; shift right including carry from add ! 88: mov cl,3 ! 89: shr ax,cl ; convert to # of paragraphs ! 90: mov cx,ds ! 91: mov bx,[_psp] ! 92: sub cx,bx ; DGROUP - _PSP ! 93: add ax,cx ; make # of paragraphs _PSP relative ! 94: mov es,bx ; seg addr of mem area ! 95: mov bx,ax ; set up for OS call ! 96: callos setmem ; change size of mem block to bx paras ! 97: pop ax ; restore (env size + 15) ! 98: jc _hpovr ; not enough memory, give error ! 99: and al,0F0h ; round down to nearest paragraph addr ! 100: dec ax ! 101: mov [_asizds],ax ; store new last byte of DGROUP ! 102: ! 103: _hpok: ! 104: xchg ax,bp ; ax = size of env ptr table ! 105: mov bp,[_abrktb].sz ; bp points to mem for storing env ptrs ! 106: add [_abrktb].sz,dx ; update bottom of heap ! 107: ret ! 108: ! 109: _hpovr: ! 110: ifdef _QC ; [1] ! 111: extrn $F_PSP:WORD ;[2] ! 112: mov ds,cs:[$F_PSP] ;[2] get PSP ! 113: mov ax,ds:[PSP_DGROUP_SEG] ;[2] get DGROUP ! 114: mov ds, ax ;[2] ds = DGROUP ! 115: ! 116: pop word ptr [__QCrtcsip] ; [1] Offset ! 117: mov word ptr [__QCrtcsip+2], cs ; [1] Segment (proc is near) ! 118: endif ;_QC ; [1] ! 119: ! 120: mov ax,di ; error 2009/2008: no space for enviroment/arguments ! 121: jmp _amsg_exit ; give error and die ! 122: ! 123: cEnd nogen ! 124: ! 125: ! 126: sEnd code ! 127: ! 128: end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.