piet@cs.ruu.nl (Piet van Oostrum) (07/11/89)
A colleague of mine put some code in crt0.s and memory.c such that _stksize = -1 means: Use most of the available memory, malloc from the bottom and put the stack in the top. Don't use Malloc. This is very nice to use for cpp and cc1 of the compiler. It allows me to compile most things on a 1MB ST. Often with gulam, foldr100 and fatspeed loaded, otherwis with a minimal shell that he wrote. Here are the diffs: *** crt0.s.old Mon Feb 6 14:39:15 1989 --- crt0.s Fri Jun 23 14:48:57 1989 *************** *** 21,26 | uses Setvec() trap instead of Super()/mov/Super() to change the ae trap | stack now has initial size of 8k (up from 2) | | .globl __start .globl __exit --- 21,34 ----- | uses Setvec() trap instead of Super()/mov/Super() to change the ae trap | stack now has initial size of 8k (up from 2) | + | Revision 1.2.1 89/02/06 AD (Atze Dijkstra) + | Changed malloc/stack mgt so stack is on top of heap + | and they will grow to each other. + | These will only be if __stksize == -1L + | See also memory.c + | + | Revision 1.2.2 89/06/23 PvO (Piet van Oostrum) + | cleanup of ARGV environment variable. | .globl __start .globl __exit *************** *** 26,31 .globl __exit .globl __base .globl _environ .globl _main .globl _errno .globl __in_trap --- 34,40 ----- .globl __exit .globl __base .globl _environ + .globl __heapbase | AD .globl _main .globl _errno .globl __in_trap *************** *** 32,37 .comm __base,4 .comm __stksize,4 .comm _environ,4 .comm _errno,4 .comm old_aet,4 --- 41,47 ----- .comm __base,4 .comm __stksize,4 + .comm __heapbase,4 | AD .comm _environ,4 .comm _errno,4 .comm old_aet,4 *************** *** 74,82 bne L1 | cmpb #0x3d, a4@+ | bne L1 | { ! clrl a3@- | *--s = 0; ! movl a3, a2 | argv = s + 2; ! addql #0x4, a2 | movl a1, a0 | movl a1, d3 | argc = (&a1[1] - argv) subl a2, d3 | / sizeof(long); --- 84,93 ----- bne L1 | cmpb #0x3d, a4@+ | bne L1 | { ! clrb a4@(-5) | PvO **s = 0; ! clrl a3@- | *--s = 0; ! movl a3, a2 | argv = s + 2 ! addql #0x4, a2 | movl a1, a0 | movl a1, d3 | argc = (&a1[1] - argv) subl a2, d3 | / sizeof(long); *************** *** 122,127 bra L8 L6: movl a0, a3 | reserve = argv - __base; subl a5, a3 tstl __stksize | if (!__stksize) --- 133,150 ----- bra L8 L6: + cmpl #0xFFFFFFFF, __stksize | if ( __stksize == -1 ) | AD + bne L30 | | AD + movl a0, __heapbase | __heapbase = argv | AD + movl sp, a3 | __stksize = ( sp - argv -12K )| AD + subl a0, a3 | AD + subl #0x3000, a3 | no checks !! | AD + movl a3, __stksize | AD + addl a0, a3 | reserve = __stksize + argv | AD + subl a5, a3 | - __base | AD + bra L31 | AD + L30: | AD + movl #0, __heapbase | __heapbase = 0 | AD movl a0, a3 | reserve = argv - __base; subl a5, a3 tstl __stksize | if (!__stksize) *************** *** 128,133 bne L13 | movl #0x2000, __stksize | __stksize = 8 * 1024; L13: addl __stksize, a3 | reserve += __stksize; movl a3, d1 addl a5, d1 | compute stack top andl #-2, d1 | even boundry --- 151,157 ----- bne L13 | movl #0x2000, __stksize | __stksize = 8 * 1024; L13: addl __stksize, a3 | reserve += __stksize; + L31: | AD movl a3, d1 addl a5, d1 | compute stack top andl #-2, d1 | even boundry *** memory.c.old Mon Feb 6 15:31:27 1989 --- memory.c Fri Jun 23 15:52:03 1989 *************** *** 1,3 /* malloc, free, realloc: dynamic memory allocation */ --- 1,10 ----- + /* Changed 89/02/06, AD (Atze Dijkstra ) + System request made dependant of _heapbase, init in crt0.s. + If != NULL, mem will not be requested via Malloc, + but heap and stack are contiguous and consume almost + all the free mem. + Corrected 23-Jun-1989 by Piet van Oostrum + */ extern char * _heapbase ; /*AD, PvO*/ extern char * _stksize ; /*AD, PvO*/ *************** *** 1,4 /* malloc, free, realloc: dynamic memory allocation */ /* minimum chunk to ask OS for */ --- 6,14 ----- Corrected 23-Jun-1989 by Piet van Oostrum */ + extern char * _heapbase ; /*AD, PvO*/ + extern char * _stksize ; /*AD, PvO*/ + /* malloc, free, realloc: dynamic memory allocation */ /* minimum chunk to ask OS for */ *************** *** 16,21 struct mem_chunk _mchunk_free_list = { NULL, 0 }; char * malloc(n) unsigned n; { --- 26,51 ----- struct mem_chunk _mchunk_free_list = { NULL, 0 }; + + static char * HeapAlloc( sz ) /*AD, PvO*/ + unsigned long sz ; /*AD*/ + { /*AD*/ + + char slush [64]; /*PvO*/ + register char* sp ; /*AD, PvO*/ + /*AD*/ + sp = slush; /*AD, PvO*/ + if ( sp < _heapbase + sz ) /*AD, PvO*/ + { /*AD*/ + return( NULL ) ; /*AD*/ + } /*AD*/ + sp = _heapbase ; /*AD*/ + _heapbase += sz ; /*AD*/ + _stksize -= sz ; /*AD*/ + /*AD*/ + return( sp ) ; /*AD*/ + } /*AD*/ + char * malloc(n) unsigned n; { *************** *** 58,64 sprintf(dbgbuf, " sz %d -> ", sz); _ps(dbgbuf); */ ! q = (struct mem_chunk * )trap_1_wlww(0x48, sz); /* sprintf(dbgbuf, "%lx\r\n", q); _ps(dbgbuf); --- 88,97 ----- sprintf(dbgbuf, " sz %d -> ", sz); _ps(dbgbuf); */ ! if ( _heapbase ) /*AD*/ ! q = (struct mem_chunk * )HeapAlloc( sz ) ; /*AD*/ ! else /*AD*/ ! q = (struct mem_chunk * )trap_1_wlww(0x48, sz); /* sprintf(dbgbuf, "%lx\r\n", q); _ps(dbgbuf); -- Piet van Oostrum, Dept of Computer Science, University of Utrecht Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands Telephone: +31-30-531806. piet@cs.ruu.nl (mcvax!hp4nl!ruuinf!piet)