housel@ea.ecn.purdue.edu (Peter S. Housel) (09/17/88)
In article <4073@louie.udel.EDU> Leisner.Henr@xerox.com (marty) writes: >I think the gnu tools would be a welcome addition to Minix -- I haven't filtered >through the source code, but the only think I know of which is missing from >Minix would be alloca(). Also the gnu distribution has a plethora of tools. > >I've had terrible luck with the Minix C compiler (everything I port to it has >problems). I quickly recompiled some of my favorite programs on gnu on the >Vaxstation (John Gilmore's tar, Ian Darwin's file) and had no problems. > Funny you should mention alloca()... I'd just been thinking about posting it. It's at the end of this article. I've gotten GNU's bison (yacc replacement) working under Minix with the help of shortc, a program which allows you to compile programs that contain identifiers longer than seven characters. alloca() was required, of course, as well as some tweaking of table sizes. Right now I'm trying gawk, but that's not done yet. Most of the other GNU tools, however, are really such memory hogs that they wouldn't work out. The GCC preprocessor, for instance, malloc()'s a buffer big enough for each input file and modifies it in place. I haven't had such bad luck with the Minix C compiler. You just have to be patient and hack at the program until it compiles. Some nifty things I've got running include: - bison - shortc (available from comp.sources.unix archives) - Allen Holub's NR nroff clone, as published by Dr. Dobbs/M&T (this took about six hours, and it had to be done twice. The result was a halfway decent nroff.) - smail, the uucp mail router. This is still a novelty at the moment. - pathalias, the uucp path router. Ditto. - the public-domain dial(3) modem capability library - SVC, the Shell Version Control system (of course) -Peter S. Housel- housel@ei.ecn.purdue.edu ...!pur-ee!housel -----------------cut here------------------------------------------------ .define _alloca | | alloca() for Minix | by Peter S. Housel 8/15/88 - in the public domain | | Stack frame: | on entry on return | | ... | | ... | | |-----------| <=caller sp |-----------| | | size arg | | | | |-----------| |alloca data| | | ret addr | | ... | | |-----------| <=sp |-----------| <= return value in ax | | dummy word| | |-----------| <= sp | .globl _alloca _alloca: mov bx,sp | bx = sp (for indexing) mov ax,sp add ax,#4 | ax = sp from calling routine sub ax,2(bx) | ax = beginning of alloca block mov bx,0(bx) | save return address mov sp,ax | set new sp push bx | push a random value for caller to remove jmp (bx) | jump back to caller
tholm@uvicctr.UUCP (Terrence W. Holm) (11/09/88)
EFTH MINIX report #57 - November 1988 - alloca(3) for MINIX-ST There follows an implementation of alloca(3) for MINIX-ST. The code is directly derived from Peter S. Housel's alloca(3) for MINIX-XT. "man" pages are included. ---------------------------------------------------------- echo x - alloca.3 gres '^X' '' > alloca.3 << '/' XSUBROUTINES X alloca(3) - allocate space on the stack X XINVOCATION X char *alloca( size ) X unsigned size; X XEXPLANATION X Alloca(3) allocates <size> bytes on the stack. Blocks X allocated within a stack frame are released on exit X from the current subroutine. X XRESULTS X o/w : Pointer to allocated memory. X NULL : No room for block. X XREFERENCES X chmem(1), malloc(3) / echo x - free.3 gres '^X' '' > free.3 << '/' XSUBROUTINES X free(3) - release allocated memory X XINVOCATION X free( p ) X char *p; X XEXPLANATION X Free(3) releases a block previously allocated by malloc(3), X realloc(3) or calloc(3). X XREFERENCES X malloc(3) / echo x - malloc.3 gres '^X' '' > malloc.3 << '/' XSUBROUTINES X malloc(3) - memory allocation routines X XINVOCATION X char *malloc( size ) X unsigned size; X X char *realloc( old, size ) X char *old; X unsigned size; X X char *calloc( n, size ) X unsigned n; X unsigned size; X XEXPLANATION X These routines allocate blocks of memory above the X process' bss section. Malloc(3) requests <size> bytes. X Realloc(3) requests a change in an <old> block's X allocation to <size>. Calloc(3) allocates <n> times X <size> bytes, and then clears the memory before returning. X XRESULTS X o/w : Pointer to allocated memory. X NULL : No room for block. For realloc(3), <old> is not X released. X XREFERENCES X chmem(1), brk(2), alloca(3), free(3) / echo x - alloca.s gres '^X' '' > alloca.s << '/' X .define _alloca X .sect text X! X! alloca() for Minix X! by Peter S. Housel 8/15/88 - in the public domain X! X! Changed for 68000 - Terrence W. Holm & X! - Frans Meulenbroeks - Nov. 1988 X! X! Stack frame: X! on entry on return X! | ... | | ... | X! |-----------| <=caller sp |-----------| X! | size arg | | | X! |-----------| |alloca data| X! | ret addr | | ... | X! |-----------| <=sp |-----------| <= return value in d0 X! | dummy word| X! |-----------| <= sp X! X .globl _alloca X .globl _brksize X_alloca: X move.l (a7),a0 ! save return address X move.l a7,d0 X add.l #6,d0 ! d0 = sp from calling routine X clr.l d1 X move.w 4(a7),d1 X sub.l d1,d0 ! d0 = beginning of alloca block X and.b #0xfc,d0 ! round to long address X move.l _brksize,d1 X add.l #40,d1 ! ensure space below new sp X cmp.l d1,d0 X ble fail X move.l d0,a7 ! set new sp X sub.l #2,a7 ! push a dummy value for caller to remove X jmp (a0) ! jump back to caller Xfail: X clr.l d0 ! return NULL pointer X rts / ---------------------------------------------------------- Frans Meulenbroeks uunet!mcvax!philmds!prle!cst!meulenbr Terrence W. Holm uw-beaver!uvicctr!tholm