├── 0a ├── a.h ├── a.y ├── l.s ├── lex.c ├── mkfile ├── y.debug ├── y.tab.c └── y.tab.h ├── 0c ├── cgen.c ├── enam.c ├── gc.h ├── list.c ├── mkenam ├── mkfile ├── mul.c ├── peep.c ├── reg.c ├── sgen.c ├── swt.c ├── txt.c └── v.out.h ├── 0l ├── Nt.c ├── Plan9.c ├── Posix.c ├── asm.c ├── enam.c ├── l.h ├── list.c ├── mkfile ├── noop.c ├── obj.c ├── optab.c ├── pass.c ├── sched.c └── span.c ├── 1a ├── a.h ├── a.y ├── l.s ├── lex.c ├── mkfile ├── y.debug ├── y.tab.c └── y.tab.h ├── 1c ├── cgen.c ├── enam.c ├── gc.h ├── list.c ├── mkfile ├── mul.c ├── peep.c ├── reg.c ├── sgen.c ├── swt.c └── txt.c ├── 1l ├── Nt.c ├── Plan9.c ├── Posix.c ├── asm.c ├── l.h ├── list.c ├── mkfile ├── obj.c ├── optab.c ├── pass.c └── span.c ├── 2a ├── a.h ├── a.y ├── l.s ├── lex.c ├── mkfile ├── y.debug ├── y.tab.c └── y.tab.h ├── 2c ├── 2.out.h ├── Update ├── cgen.c ├── enam.c ├── gc.h ├── list.c ├── mkfile ├── mul.c ├── peep.c ├── reg.c ├── sgen.c ├── swt.c └── txt.c ├── 2l ├── Nt.c ├── Plan9.c ├── Posix.c ├── asm.c ├── l.h ├── list.c ├── mkfile ├── obj.c ├── optab.c ├── pass.c └── span.c ├── 5a ├── a.h ├── a.y ├── lex.c ├── mkfile ├── y.debug ├── y.tab.c └── y.tab.h ├── 5c ├── 5.out.h ├── cgen.c ├── enam.c ├── gc.h ├── list.c ├── mkenam ├── mkfile ├── mul.c ├── peep.c ├── reg.c ├── sgen.c ├── swt.c └── txt.c ├── 5l ├── Plan9.c ├── Posix.c ├── asm.c ├── l.h ├── list.c ├── mkfile ├── noop.c ├── obj.c ├── optab.c ├── pass.c └── span.c ├── 6a ├── a.h ├── a.y ├── lex.c ├── mkfile ├── y.debug ├── y.tab.c └── y.tab.h ├── 6c ├── 6.out.h ├── cgen.c ├── div.c ├── enam.c ├── gc.h ├── list.c ├── machcap.c ├── mkfile ├── mkfile_o ├── mul.c ├── peep.c ├── pgen.c ├── pswt.c ├── reg.c ├── sgen.c ├── swt.c └── txt.c ├── 6l ├── Nt.c ├── Plan9.c ├── Posix.c ├── asm.c ├── bits.c ├── compat.c ├── l.h ├── list.c ├── mem.h ├── mkfile ├── mkfile_o ├── obj.c ├── optab.c ├── pass.c └── span.c ├── 7a ├── a.h ├── a.y ├── lex.c ├── mkfile ├── y.debug ├── y.tab.c └── y.tab.h ├── 7c ├── 7.out.h ├── cgen.c ├── enam.c ├── gc.h ├── list.c ├── machcap.c ├── mkenam ├── mkfile ├── mul.c ├── peep.c ├── reg.c ├── sgen.c ├── swt.c └── txt.c ├── 7l ├── asm.c ├── asmout.c ├── bits.c ├── cnam.c ├── dyn.c ├── l.h ├── list.c ├── mkfile ├── noop.c ├── obj.c ├── optab.c └── span.c ├── 8a ├── a.h ├── a.y ├── l.s ├── lex.c ├── mkfile ├── y.debug ├── y.tab.c └── y.tab.h ├── 8c ├── 6.out.h ├── 8.out.h ├── cgen.c ├── cgen64.c ├── div.c ├── enam.c ├── gc.h ├── list.c ├── machcap.c ├── mkenam ├── mkfile ├── mul.c ├── peep.c ├── reg.c ├── sgen.c ├── swt.c └── txt.c ├── 8l ├── Plan9.c ├── Posix.c ├── asm.c ├── compat.c ├── elf.c ├── elf.h ├── l.h ├── list.c ├── mkfile ├── obj.c ├── optab.c ├── pass.c └── span.c ├── Cygwin └── 386 │ ├── bin │ ├── ar │ ├── iyacc │ ├── mk │ ├── pad.txt │ └── yacc │ ├── include │ ├── fpuctl.h │ └── lib9.h │ └── lib │ └── .keep ├── Linux └── 386 │ ├── bin │ ├── ar │ ├── data2c │ ├── iyacc │ ├── mk │ └── yacc │ ├── include │ ├── fpuctl.h │ └── lib9.h │ └── lib │ └── .keep ├── MacOSX └── 386 │ ├── bin │ ├── 0c │ ├── 0l │ ├── 1a │ ├── 1c │ ├── 1l │ ├── 2a │ ├── 2c │ ├── 2l │ ├── 5a │ ├── 5c │ ├── 5l │ ├── 6a │ ├── 6c │ ├── 6l │ ├── 7a │ ├── 7c │ ├── 7l │ ├── 8a │ ├── 8c │ ├── 8l │ ├── acid │ ├── ar │ ├── data2c │ ├── data2s │ ├── date │ ├── hoc │ ├── iar │ ├── ilex │ ├── inm │ ├── iyacc │ ├── ka │ ├── kc │ ├── kl │ ├── kprof │ ├── ksize │ ├── kstrip │ ├── mk │ ├── mk.save │ ├── pcc │ ├── qa │ ├── qc │ ├── ql │ ├── rc │ ├── sed │ ├── tc │ ├── va │ ├── vc │ ├── vl │ ├── xd │ ├── yacc │ ├── zc │ └── zl │ ├── include │ ├── fpuctl.h │ └── lib9.h │ └── lib │ ├── .keep │ ├── lib9.a │ ├── libbio.a │ ├── libcc.a │ ├── libl.a │ ├── libmach.a │ ├── libmath.a │ └── libregexp.a ├── Plan9 └── 386 │ ├── bin │ └── data2c │ └── include │ ├── lib9.h │ └── u.h ├── README.md ├── acid ├── 386 ├── B.sh ├── acid.h ├── arm ├── builtin.c ├── dbg.y ├── dot.c ├── exec.c ├── expr.c ├── lex.c ├── list.c ├── main.c ├── mkfile ├── os-Plan9.c ├── os-Posix.c ├── port ├── print.c ├── proc.c ├── rdebug.c ├── util.c ├── y.tab.c └── y.tab.h ├── ar ├── Plan9.c ├── Posix.c ├── ar.c └── mkfile ├── bin ├── cc ├── Plan9.c ├── Posix.c ├── acid.c ├── bits.c ├── c99 ├── cc.h ├── cc.y ├── com.c ├── com64.c ├── dcl.c ├── dpchk.c ├── funct.c ├── lex.c ├── lexbody ├── mac.c ├── macbody ├── mkfile ├── mpatof.c ├── omachcap.c ├── pgen.c ├── pickle.c ├── pswt.c ├── scon.c └── sub.c ├── configure ├── copyright.txt ├── docs ├── acid.ms ├── acid.pdf ├── acidpaper.ms ├── acidpaper.pdf ├── acidtut.ms ├── acidtut.pdf ├── asm.ms ├── asm.pdf ├── comp.ms ├── comp.pdf ├── compiler.ms ├── compiler.pdf ├── lex.pdf ├── mk.ms ├── mk.pdf └── yacc.pdf ├── env ├── etc ├── compilers ├── mkconfig.txt ├── os.arch.dlist ├── os.arch.dlist.sh └── os.dlist ├── include ├── a.out.h ├── ar.h ├── bio.h ├── fcall.h ├── mach.h ├── mathi.h ├── rdbg.h └── regexp.h ├── install.txt ├── install_linux.txt ├── install_macos.txt ├── install_windows.txt ├── ka ├── a.h ├── a.y ├── l.s ├── lex.c ├── mkfile ├── note ├── y.debug ├── y.tab.c └── y.tab.h ├── kc ├── cgen.c ├── enam.c ├── gc.h ├── k.out.h ├── list.c ├── mkenam ├── mkfile ├── mul.c ├── peep.c ├── reg.c ├── sgen.c ├── swt.c └── txt.c ├── kl ├── Nt.c ├── Plan9.c ├── Posix.c ├── asm.c ├── foo.c ├── l.h ├── list.c ├── mkfile ├── noop.c ├── obj.c ├── optab.c ├── pass.c ├── sched.c └── span.c ├── ld ├── Nt.c ├── Plan9.c ├── Posix.c ├── Upd ├── elf.c ├── elf.h ├── falloc.c ├── ld.h ├── mkcname ├── mod.c ├── pass.c ├── pobj.c └── sub.c ├── lex ├── header.c ├── ldefs.h ├── lmain.c ├── mkfile ├── ncform ├── parser.y ├── sub1.c ├── sub2.c ├── y.tab.c └── y.tab.h ├── lib ├── lex.ncform ├── rcmain ├── rcmain.unix ├── yaccpar └── yaccpars ├── lib9 ├── argv0.c ├── charstod.c ├── cistrcmp.c ├── cistrncmp.c ├── cistrstr.c ├── cleanname.c ├── convD2M.c ├── convM2D.c ├── convM2S.c ├── convS2M.c ├── copyright.txt ├── create.c ├── dirstat-posix.c ├── dirwstat.c ├── dofmt.c ├── dorfmt.c ├── errfmt.c ├── errstr-Plan9.c ├── errstr-posix.c ├── exits.c ├── fcallfmt.c ├── fltfmt.c ├── fmt.c ├── fmtdef.h ├── fmtfd.c ├── fmtlock.c ├── fmtprint.c ├── fmtquote.c ├── fmtrune.c ├── fmtstr.c ├── fmtvprint.c ├── fprint.c ├── getcallerpc-Cygwin-386.s ├── getcallerpc-Linux-386.s ├── getcallerpc-MacOSX-386.s ├── getfields.c ├── getuser-posix.c ├── getwd-posix.c ├── lock.c ├── mk.sh ├── mkfile ├── mkfile-Plan9 ├── mkfile-Posix ├── nulldir.c ├── pow10.c ├── print.c ├── qsort.c ├── readn.c ├── rerrstr.c ├── rune.c ├── runeseprint.c ├── runesmprint.c ├── runesnprint.c ├── runestrlen.c ├── runevseprint.c ├── sbrk-posix.c ├── seek.c ├── seprint.c ├── smprint.c ├── snprint.c ├── sprint.c ├── strdup.c ├── strecpy.c ├── strtoll.c ├── sysfatal.c ├── tokenize.c ├── u16.c ├── u32.c ├── u64.c ├── utfecpy.c ├── utflen.c ├── utfnlen.c ├── utfrrune.c ├── utfrune.c ├── vfprint.c ├── vseprint.c ├── vsmprint.c └── vsnprint.c ├── libbio ├── NOTICE ├── bbuffered.c ├── bfildes.c ├── bflush.c ├── bgetc.c ├── bgetd.c ├── bgetrune.c ├── binit.c ├── boffset.c ├── bprint.c ├── bputc.c ├── bputrune.c ├── brdline.c ├── bread.c ├── bseek.c ├── bvprint.c ├── bwrite.c ├── mk.sh └── mkfile ├── liblex ├── allprint.c ├── main.c ├── mkfile ├── reject.c ├── yyless.c └── yywrap.c ├── libmach ├── 5.c ├── 5db.c ├── 5obj.c ├── 6.c ├── 6obj.c ├── 8.c ├── 8db.c ├── 8obj.c ├── NOTICE ├── access.c ├── ar.h ├── bootexec.h ├── elf.h ├── executable.c ├── machdata.c ├── macho.h ├── map.c ├── mkfile ├── obj.c ├── obj.h ├── setmach.c ├── swap.c ├── sym.c ├── ureg5.h ├── ureg6.h └── ureg8.h ├── libmath ├── FPcontrol-Cygwin.c ├── FPcontrol-Linux.c ├── FPcontrol-MacOSX.c ├── FPcontrol-Plan9.c ├── bin │ ├── fdlibm-stubs │ ├── unif_dtoa │ └── unif_fdlibm ├── blas.c ├── copyright.txt ├── dtoa.c ├── fdim.c ├── fdlibm │ ├── e_acos.c │ ├── e_acosh.c │ ├── e_asin.c │ ├── e_atan2.c │ ├── e_atanh.c │ ├── e_cosh.c │ ├── e_exp.c │ ├── e_fmod.c │ ├── e_hypot.c │ ├── e_j0.c │ ├── e_j1.c │ ├── e_jn.c │ ├── e_lgamma_r.c │ ├── e_log.c │ ├── e_log10.c │ ├── e_pow.c │ ├── e_rem_pio2.c │ ├── e_remainder.c │ ├── e_sinh.c │ ├── e_sqrt.c │ ├── fdlibm.h │ ├── k_cos.c │ ├── k_rem_pio2.c │ ├── k_sin.c │ ├── k_tan.c │ ├── readme │ ├── s_asinh.c │ ├── s_atan.c │ ├── s_cbrt.c │ ├── s_ceil.c │ ├── s_copysign.c │ ├── s_cos.c │ ├── s_erf.c │ ├── s_expm1.c │ ├── s_fabs.c │ ├── s_finite.c │ ├── s_floor.c │ ├── s_ilogb.c │ ├── s_isnan.c │ ├── s_log1p.c │ ├── s_modf.c │ ├── s_nextafter.c │ ├── s_rint.c │ ├── s_scalbn.c │ ├── s_sin.c │ ├── s_tan.c │ └── s_tanh.c ├── g_fmt.c ├── gemm.c ├── gfltconv.c ├── mkfile └── pow10.c ├── libregexp ├── mk.sh ├── mkfile ├── regaux.c ├── regcomp.c ├── regcomp.h ├── regerror.c ├── regexec.c ├── regsub.c ├── rregexec.c └── rregsub.c ├── mk ├── Plan9.c ├── Posix.c ├── README ├── arc.c ├── archive.c ├── bufblock.c ├── env.c ├── file.c ├── fns.h ├── graph.c ├── job.c ├── lex.c ├── main.c ├── match.c ├── mk.c ├── mk.h ├── mk.sh ├── mkfile ├── mkfile-Plan9 ├── mkfile-Posix ├── parse.c ├── rc.c ├── recipe.c ├── rule.c ├── run.c ├── sh.c ├── shprint.c ├── symtab.c ├── var.c ├── varsub.c └── word.c ├── mkconfig ├── mkfile ├── mkfiles ├── mkfile-Cygwin-386 ├── mkfile-Linux-386 ├── mkfile-MacOSX-386 ├── mkfile-Plan9-386 ├── mkhost-Cygwin ├── mkhost-Linux ├── mkhost-MacOSX ├── mkhost-Plan9 ├── mklibsubdirs ├── mkone-rc ├── mkone-sh ├── mksubdirs ├── mksyslib-rc └── mksyslib-sh ├── modif-orig.txt ├── pcc ├── Plan9.c ├── Posix.c ├── mkfile └── pcc.c ├── qa ├── Ins ├── a.h ├── a.y ├── branch ├── lex.c ├── mkfile ├── y.debug ├── y.tab.c └── y.tab.h ├── qc ├── cgen.c ├── enam.c ├── gc.h ├── list.c ├── machcap.c ├── mkenam ├── mkfile ├── mul.c ├── peep.c ├── q.out.h ├── reg.c ├── sgen.c ├── swt.c └── txt.c ├── ql ├── asm.c ├── asmout.c ├── cnam.c ├── l.h ├── list.c ├── mkcname ├── mkfile ├── noop.c ├── obj.c ├── optab.c ├── pass.c ├── sched.c └── span.c ├── rc ├── Posix.c ├── code.c ├── exec.c ├── exec.h ├── fns.h ├── getflags.c ├── getflags.h ├── glob.c ├── havefork.c ├── haventfork.c ├── here.c ├── io.c ├── io.h ├── lex.c ├── mkfile ├── pad.txt ├── pcmd.c ├── pfnc.c ├── plan9.c ├── rc.h ├── simple.c ├── subr.c ├── syn.y ├── trap.c ├── tree.c ├── unix.c ├── unix.h ├── var.c ├── win32.c ├── y.tab.c └── y.tab.h ├── readme.txt ├── skip_list.txt ├── tc ├── 5.out.h ├── cgen.c ├── enam.c ├── gc.h ├── list.c ├── mkenam ├── mkfile ├── mul.c ├── peep.c ├── reg.c ├── sgen.c ├── swt.c └── txt.c ├── tl ├── asm.c ├── l.h ├── list.c ├── mkfile ├── noop.c ├── obj.c ├── optab.c ├── pass.c ├── span.c └── thumb.c ├── utilities ├── aux │ ├── data2s.c │ ├── mkfile │ └── mklatinkbd.c ├── date │ ├── date.c │ └── mkfile ├── hoc │ ├── code.c │ ├── hoc.h │ ├── hoc.y │ ├── init.c │ ├── math.c │ ├── mkfile │ ├── symbol.c │ ├── y.tab.c │ └── y.tab.h ├── kprof │ ├── kprof.c │ └── mkfile ├── ksize │ ├── ksize.c │ └── mkfile ├── kstrip │ ├── kstrip.c │ └── mkfile ├── mkfile ├── nm │ ├── mkfile │ └── nm.c ├── pad.txt ├── sed │ ├── mkfile │ ├── pad.txt │ └── sed.c └── xd │ ├── mkfile │ └── xd.c ├── va ├── a.h ├── a.y ├── l.s ├── lex.c ├── mkfile ├── note ├── y.debug ├── y.tab.c └── y.tab.h ├── vc ├── cgen.c ├── enam.c ├── gc.h ├── list.c ├── mkenam ├── mkfile ├── mul.c ├── peep.c ├── reg.c ├── sgen.c ├── swt.c ├── txt.c └── v.out.h ├── vl ├── asm.c ├── compat.c ├── l.h ├── list.c ├── mkfile ├── noop.c ├── obj.c ├── optab.c ├── pass.c ├── sched.c └── span.c ├── yacc ├── mkfile ├── yacc.c └── yaccpar ├── za ├── a.h ├── a.y ├── div.s ├── l.s ├── lex.c ├── mkfile ├── y.debug ├── y.tab.c ├── y.tab.h └── za ├── zc ├── cgen.c ├── enam.c ├── gc.h ├── l.s ├── list.c ├── mkenam ├── mkfile ├── mul.c ├── peep.c ├── reg.c ├── sgen.c ├── swt.c ├── txt.c ├── z.out.h └── zc └── zl ├── Posix.c ├── asm.c ├── compat.c ├── l.h ├── list.c ├── mkfile ├── noop.c ├── obj.c ├── optab.c ├── pass.c ├── span.c └── zl /0a/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../../mkconfig 3 | 4 | TARG=2a 5 | 6 | OFILES=\ 7 | y.tab.$O\ 8 | lex.$O\ 9 | 10 | HFILES=\ 11 | ../2c/2.out.h\ 12 | y.tab.h\ 13 | a.h\ 14 | 15 | YFILES=a.y\ 16 | 17 | LIBS=cc bio 9 # order is important 18 | 19 | BIN=$ROOT/$OBJDIR/bin 20 | 21 | <$ROOT/mkfiles/mkone-$SHELLTYPE 22 | 23 | YFLAGS=-D1 -d 24 | 25 | lex.$O: ../cc/macbody ../cc/lexbody 26 | 27 | $ROOT/$OBJDIR/lib/libcc.a: 28 | cd ../cc 29 | mk $MKFLAGS install 30 | mk $MKFLAGS clean 31 | -------------------------------------------------------------------------------- /0a/y.tab.h: -------------------------------------------------------------------------------- 1 | 2 | typedef union 3 | { 4 | Sym *sym; 5 | long lval; 6 | double dval; 7 | char sval[8]; 8 | Gen gen; 9 | } YYSTYPE; 10 | extern YYSTYPE yylval; 11 | #define LTYPE1 57346 12 | #define LTYPE2 57347 13 | #define LTYPE3 57348 14 | #define LTYPE4 57349 15 | #define LTYPE5 57350 16 | #define LTYPE6 57351 17 | #define LTYPE7 57352 18 | #define LTYPE8 57353 19 | #define LTYPE9 57354 20 | #define LTYPEA 57355 21 | #define LTYPEB 57356 22 | #define LTYPEC 57357 23 | #define LTYPED 57358 24 | #define LTYPEE 57359 25 | #define LTYPEF 57360 26 | #define LTYPEG 57361 27 | #define LTYPEH 57362 28 | #define LTYPEI 57363 29 | #define LTYPEJ 57364 30 | #define LTYPEK 57365 31 | #define LCONST 57366 32 | #define LSP 57367 33 | #define LSB 57368 34 | #define LFP 57369 35 | #define LPC 57370 36 | #define LHI 57371 37 | #define LLO 57372 38 | #define LMREG 57373 39 | #define LTYPEX 57374 40 | #define LREG 57375 41 | #define LFREG 57376 42 | #define LFCREG 57377 43 | #define LR 57378 44 | #define LM 57379 45 | #define LF 57380 46 | #define LFCR 57381 47 | #define LSCHED 57382 48 | #define LFCONST 57383 49 | #define LSCONST 57384 50 | #define LNAME 57385 51 | #define LLAB 57386 52 | #define LVAR 57387 53 | -------------------------------------------------------------------------------- /0c/mkenam: -------------------------------------------------------------------------------- 1 | ed - ../vc/v.out.h <<'!' 2 | v/^ A/d 3 | ,s/^ A/ "/ 4 | g/ .*$/s/// 5 | ,s/,*$/",/ 6 | 1i 7 | char* anames[] = 8 | { 9 | . 10 | $a 11 | }; 12 | . 13 | w enam.c 14 | Q 15 | ! 16 | -------------------------------------------------------------------------------- /0c/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../../mkconfig 3 | 4 | TARG=0c 5 | 6 | OFILES= cgen.$O\ 7 | enam.$O\ 8 | list.$O\ 9 | peep.$O\ 10 | reg.$O\ 11 | sgen.$O\ 12 | swt.$O\ 13 | txt.$O\ 14 | mul.$O\ 15 | 16 | HFILES= gc.h\ 17 | v.out.h\ 18 | ../cc/cc.h\ 19 | 20 | LIBS=cc bio 9 # order is important 21 | 22 | BIN=$ROOT/$OBJDIR/bin 23 | 24 | <$ROOT/mkfiles/mkone-$SHELLTYPE 25 | 26 | 27 | $ROOT/$OBJDIR/lib/libcc.a: 28 | cd ../cc 29 | mk $MKFLAGS install 30 | mk $MKFLAGS clean 31 | -------------------------------------------------------------------------------- /0l/Nt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "l.h" 3 | 4 | /* 5 | * fake malloc 6 | */ 7 | void* 8 | malloc(uint n) 9 | { 10 | void *p; 11 | 12 | while(n & 7) 13 | n++; 14 | while(nhunk < n) 15 | gethunk(); 16 | p = hunk; 17 | nhunk -= n; 18 | hunk += n; 19 | return p; 20 | } 21 | 22 | void 23 | free(void *p) 24 | { 25 | USED(p); 26 | } 27 | 28 | void* 29 | calloc(uint m, uint n) 30 | { 31 | void *p; 32 | 33 | n *= m; 34 | p = malloc(n); 35 | memset(p, 0, n); 36 | return p; 37 | } 38 | 39 | void* 40 | realloc(void *p, uint n) 41 | { 42 | void *new; 43 | 44 | new = malloc(n); 45 | if(new && p) 46 | memmove(new, p, n); 47 | return new; 48 | } 49 | 50 | #define Chunk (1*1024*1024) 51 | 52 | void* 53 | mysbrk(ulong size) 54 | { 55 | void *v; 56 | static int chunk; 57 | static uchar *brk; 58 | 59 | if(chunk < size) { 60 | chunk = Chunk; 61 | if(chunk < size) 62 | chunk = Chunk + size; 63 | brk = VirtualAlloc(NULL, chunk, MEM_COMMIT, PAGE_EXECUTE_READWRITE); 64 | if(brk == 0) 65 | return (void*)-1; 66 | } 67 | v = brk; 68 | chunk -= size; 69 | brk += size; 70 | return v; 71 | } 72 | 73 | double 74 | cputime(void) 75 | { 76 | return ((double)0); 77 | } 78 | -------------------------------------------------------------------------------- /0l/Plan9.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | 3 | /* 4 | * fake malloc 5 | */ 6 | void* 7 | malloc(ulong n) 8 | { 9 | void *p; 10 | 11 | while(n & 7) 12 | n++; 13 | while(nhunk < n) 14 | gethunk(); 15 | p = hunk; 16 | nhunk -= n; 17 | hunk += n; 18 | return p; 19 | } 20 | 21 | void 22 | free(void *p) 23 | { 24 | USED(p); 25 | } 26 | 27 | void* 28 | calloc(ulong m, ulong n) 29 | { 30 | void *p; 31 | 32 | n *= m; 33 | p = malloc(n); 34 | memset(p, 0, n); 35 | return p; 36 | } 37 | 38 | void* 39 | realloc(void *p, ulong n) 40 | { 41 | USED(p); 42 | USED(n); 43 | fprint(2, "realloc called\n"); 44 | abort(); 45 | return 0; 46 | } 47 | 48 | void* 49 | mysbrk(ulong size) 50 | { 51 | return sbrk(size); 52 | } 53 | 54 | void 55 | setmalloctag(void*, ulong) 56 | { 57 | } 58 | -------------------------------------------------------------------------------- /0l/Posix.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | #include 3 | #include 4 | #undef getwd 5 | #include /* For sysconf() and _SC_CLK_TCK */ 6 | 7 | /* 8 | * fake malloc 9 | */ 10 | void* 11 | malloc(size_t n) 12 | { 13 | void *p; 14 | 15 | while(n & 7) 16 | n++; 17 | while(nhunk < n) 18 | gethunk(); 19 | p = hunk; 20 | nhunk -= n; 21 | hunk += n; 22 | return p; 23 | } 24 | 25 | void 26 | free(void *p) 27 | { 28 | USED(p); 29 | } 30 | 31 | void* 32 | calloc(size_t m, size_t n) 33 | { 34 | void *p; 35 | 36 | n *= m; 37 | p = malloc(n); 38 | memset(p, 0, n); 39 | return p; 40 | } 41 | 42 | void* 43 | realloc(void *p, size_t n) 44 | { 45 | fprint(2, "realloc called\n", p, n); 46 | abort(); 47 | return 0; 48 | } 49 | 50 | double 51 | cputime(void) 52 | { 53 | 54 | struct tms tmbuf; 55 | double ret_val; 56 | 57 | /* 58 | * times() only fials if &tmbuf is invalid. 59 | */ 60 | (void)times(&tmbuf); 61 | /* 62 | * Return the total time (in system clock ticks) 63 | * spent in user code and system 64 | * calls by both the calling process and its children. 65 | */ 66 | ret_val = (double)(tmbuf.tms_utime + tmbuf.tms_stime + 67 | tmbuf.tms_cutime + tmbuf.tms_cstime); 68 | /* 69 | * Convert to seconds. 70 | */ 71 | ret_val *= sysconf(_SC_CLK_TCK); 72 | return ret_val; 73 | 74 | } 75 | 76 | void* 77 | mysbrk(ulong size) 78 | { 79 | return (void*)sbrk(size); 80 | } 81 | -------------------------------------------------------------------------------- /0l/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../../mkconfig 3 | 4 | TARG=0l 5 | OFILES=\ 6 | asm.$O\ 7 | list.$O\ 8 | noop.$O\ 9 | sched.$O\ 10 | obj.$O\ 11 | optab.$O\ 12 | pass.$O\ 13 | span.$O\ 14 | enam.$O\ 15 | $TARGMODEL.$O\ 16 | 17 | HFILES=\ 18 | l.h\ 19 | ../vc/v.out.h\ 20 | ${ROOT}/include/ar.h\ 21 | 22 | LIBS=bio 9 23 | 24 | BIN=$ROOT/$OBJDIR/bin 25 | 26 | <$ROOT/mkfiles/mkone-$SHELLTYPE 27 | 28 | CFLAGS= $CFLAGS -I ${ROOT}/include 29 | 30 | enam.$O: ../0c/enam.c 31 | $CC $CFLAGS ../0c/enam.c 32 | -------------------------------------------------------------------------------- /1a/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../../mkconfig 3 | 4 | TARG=1a 5 | 6 | OFILES=\ 7 | y.tab.$O\ 8 | lex.$O\ 9 | 10 | HFILES=\ 11 | ../2c/2.out.h\ 12 | y.tab.h\ 13 | a.h\ 14 | 15 | YFILES=a.y\ 16 | 17 | LIBS=cc bio 9 # order is important 18 | 19 | BIN=$ROOT/$OBJDIR/bin 20 | 21 | <$ROOT/mkfiles/mkone-$SHELLTYPE 22 | 23 | YFLAGS=-D1 -d 24 | 25 | lex.$O: ../cc/macbody ../cc/lexbody 26 | 27 | $ROOT/$OBJDIR/lib/libcc.a: 28 | cd ../cc 29 | mk $MKFLAGS install 30 | mk $MKFLAGS clean 31 | -------------------------------------------------------------------------------- /1a/y.tab.h: -------------------------------------------------------------------------------- 1 | 2 | typedef union { 3 | Sym *sym; 4 | long lval; 5 | double dval; 6 | char sval[8]; 7 | Addr addr; 8 | Gen gen; 9 | Gen2 gen2; 10 | } YYSTYPE; 11 | extern YYSTYPE yylval; 12 | #define LTYPE1 57346 13 | #define LTYPE2 57347 14 | #define LTYPE3 57348 15 | #define LTYPE4 57349 16 | #define LTYPE5 57350 17 | #define LTYPE6 57351 18 | #define LTYPE7 57352 19 | #define LTYPE8 57353 20 | #define LTYPE9 57354 21 | #define LTYPEA 57355 22 | #define LTYPEB 57356 23 | #define LCONST 57357 24 | #define LSP 57358 25 | #define LSB 57359 26 | #define LFP 57360 27 | #define LPC 57361 28 | #define LTOS 57362 29 | #define LAREG 57363 30 | #define LDREG 57364 31 | #define LFREG 57365 32 | #define LFCONST 57366 33 | #define LSCONST 57367 34 | #define LNAME 57368 35 | #define LLAB 57369 36 | #define LVAR 57370 37 | -------------------------------------------------------------------------------- /1c/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../../mkconfig 3 | 4 | TARG=1c 5 | 6 | OFILES=\ 7 | cgen.$O\ 8 | reg.$O\ 9 | txt.$O\ 10 | peep.$O\ 11 | swt.$O\ 12 | sgen.$O\ 13 | list.$O\ 14 | enam.$O\ 15 | mul.$O\ 16 | 17 | HFILES= gc.h\ 18 | ../2c/2.out.h\ 19 | ../cc/cc.h\ 20 | 21 | LIBS=cc bio 9 # order is important 22 | 23 | BIN=$ROOT/$OBJDIR/bin 24 | 25 | <$ROOT/mkfiles/mkone-$SHELLTYPE 26 | 27 | $ROOT/$OBJDIR/lib/libcc.a: 28 | cd ../cc 29 | mk $MKFLAGS install 30 | mk $MKFLAGS clean 31 | -------------------------------------------------------------------------------- /1l/Nt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "l.h" 3 | 4 | /* 5 | * fake malloc 6 | */ 7 | void* 8 | malloc(uint n) 9 | { 10 | void *p; 11 | 12 | while(n & 7) 13 | n++; 14 | while(nhunk < n) 15 | gethunk(); 16 | p = hunk; 17 | nhunk -= n; 18 | hunk += n; 19 | return p; 20 | } 21 | 22 | void 23 | free(void *p) 24 | { 25 | USED(p); 26 | } 27 | 28 | void* 29 | calloc(uint m, uint n) 30 | { 31 | void *p; 32 | 33 | n *= m; 34 | p = malloc(n); 35 | memset(p, 0, n); 36 | return p; 37 | } 38 | 39 | void* 40 | realloc(void *p, uint n) 41 | { 42 | void *new; 43 | 44 | new = malloc(n); 45 | if(new && p) 46 | memmove(new, p, n); 47 | return new; 48 | } 49 | 50 | #define Chunk (1*1024*1024) 51 | 52 | void* 53 | mysbrk(ulong size) 54 | { 55 | void *v; 56 | static int chunk; 57 | static uchar *brk; 58 | 59 | if(chunk < size) { 60 | chunk = Chunk; 61 | if(chunk < size) 62 | chunk = Chunk + size; 63 | brk = VirtualAlloc(NULL, chunk, MEM_COMMIT, PAGE_EXECUTE_READWRITE); 64 | if(brk == 0) 65 | return (void*)-1; 66 | } 67 | v = brk; 68 | chunk -= size; 69 | brk += size; 70 | return v; 71 | } 72 | 73 | double 74 | cputime(void) 75 | { 76 | return ((double)0); 77 | } 78 | -------------------------------------------------------------------------------- /1l/Plan9.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | 3 | /* 4 | * fake malloc 5 | */ 6 | void* 7 | malloc(ulong n) 8 | { 9 | void *p; 10 | 11 | while(n & 7) 12 | n++; 13 | while(nhunk < n) 14 | gethunk(); 15 | p = hunk; 16 | nhunk -= n; 17 | hunk += n; 18 | return p; 19 | } 20 | 21 | void 22 | free(void *p) 23 | { 24 | USED(p); 25 | } 26 | 27 | void* 28 | calloc(ulong m, ulong n) 29 | { 30 | void *p; 31 | 32 | n *= m; 33 | p = malloc(n); 34 | memset(p, 0, n); 35 | return p; 36 | } 37 | 38 | void* 39 | realloc(void *p, ulong n) 40 | { 41 | USED(p); 42 | USED(n); 43 | fprint(2, "realloc called\n"); 44 | abort(); 45 | return 0; 46 | } 47 | 48 | void* 49 | mysbrk(ulong size) 50 | { 51 | return sbrk(size); 52 | } 53 | 54 | void 55 | setmalloctag(void*, ulong) 56 | { 57 | } 58 | -------------------------------------------------------------------------------- /1l/Posix.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | #include 3 | #include 4 | #undef getwd 5 | #include /* For sysconf() and _SC_CLK_TCK */ 6 | 7 | /* 8 | * fake malloc 9 | */ 10 | void* 11 | malloc(size_t n) 12 | { 13 | void *p; 14 | 15 | while(n & 7) 16 | n++; 17 | while(nhunk < n) 18 | gethunk(); 19 | p = hunk; 20 | nhunk -= n; 21 | hunk += n; 22 | return p; 23 | } 24 | 25 | void 26 | free(void *p) 27 | { 28 | USED(p); 29 | } 30 | 31 | void* 32 | calloc(size_t m, size_t n) 33 | { 34 | void *p; 35 | 36 | n *= m; 37 | p = malloc(n); 38 | memset(p, 0, n); 39 | return p; 40 | } 41 | 42 | void* 43 | realloc(void *p, size_t n) 44 | { 45 | fprint(2, "realloc called\n", p, n); 46 | abort(); 47 | return 0; 48 | } 49 | 50 | double 51 | cputime(void) 52 | { 53 | 54 | struct tms tmbuf; 55 | double ret_val; 56 | 57 | /* 58 | * times() only fials if &tmbuf is invalid. 59 | */ 60 | (void)times(&tmbuf); 61 | /* 62 | * Return the total time (in system clock ticks) 63 | * spent in user code and system 64 | * calls by both the calling process and its children. 65 | */ 66 | ret_val = (double)(tmbuf.tms_utime + tmbuf.tms_stime + 67 | tmbuf.tms_cutime + tmbuf.tms_cstime); 68 | /* 69 | * Convert to seconds. 70 | */ 71 | ret_val *= sysconf(_SC_CLK_TCK); 72 | return ret_val; 73 | 74 | } 75 | 76 | void* 77 | mysbrk(ulong size) 78 | { 79 | return (void*)sbrk(size); 80 | } 81 | -------------------------------------------------------------------------------- /1l/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../../mkconfig 3 | 4 | TARG=1l 5 | OFILES=\ 6 | asm.$O\ 7 | obj.$O\ 8 | optab.$O\ 9 | pass.$O\ 10 | span.$O\ 11 | list.$O\ 12 | enam.$O\ 13 | $TARGMODEL.$O\ 14 | 15 | HFILES=\ 16 | l.h\ 17 | ../2c/2.out.h\ 18 | ${ROOT}/include/ar.h\ 19 | 20 | LIBS=bio 9 21 | BIN=$ROOT/$OBJDIR/bin 22 | <$ROOT/mkfiles/mkone-$SHELLTYPE 23 | 24 | CFLAGS= $CFLAGS -I ${ROOT}/include 25 | 26 | enam.$O: ../2c/enam.c 27 | $CC $CFLAGS ../2c/enam.c 28 | 29 | %.1: %.s 30 | 1a $stem.s 31 | 32 | %.1: %.c 33 | 1c -w $stem.c 34 | -------------------------------------------------------------------------------- /2a/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../../mkconfig 3 | 4 | TARG=2a 5 | 6 | OFILES=\ 7 | y.tab.$O\ 8 | lex.$O\ 9 | 10 | HFILES=\ 11 | ../2c/2.out.h\ 12 | y.tab.h\ 13 | a.h\ 14 | 15 | YFILES=a.y\ 16 | 17 | LIBS=cc bio 9 # order is important 18 | 19 | BIN=$ROOT/$OBJDIR/bin 20 | 21 | <$ROOT/mkfiles/mkone-$SHELLTYPE 22 | 23 | YFLAGS=-D1 -d 24 | 25 | lex.$O: ../cc/macbody ../cc/lexbody 26 | 27 | $ROOT/$OBJDIR/lib/libcc.a: 28 | cd ../cc 29 | mk $MKFLAGS install 30 | mk $MKFLAGS clean 31 | -------------------------------------------------------------------------------- /2a/y.tab.h: -------------------------------------------------------------------------------- 1 | 2 | typedef union { 3 | Sym *sym; 4 | long lval; 5 | double dval; 6 | char sval[8]; 7 | Addr addr; 8 | Gen gen; 9 | Gen2 gen2; 10 | } YYSTYPE; 11 | extern YYSTYPE yylval; 12 | #define LTYPE1 57346 13 | #define LTYPE2 57347 14 | #define LTYPE3 57348 15 | #define LTYPE4 57349 16 | #define LTYPE5 57350 17 | #define LTYPE6 57351 18 | #define LTYPE7 57352 19 | #define LTYPE8 57353 20 | #define LTYPE9 57354 21 | #define LTYPEA 57355 22 | #define LTYPEB 57356 23 | #define LCONST 57357 24 | #define LSP 57358 25 | #define LSB 57359 26 | #define LFP 57360 27 | #define LPC 57361 28 | #define LTOS 57362 29 | #define LAREG 57363 30 | #define LDREG 57364 31 | #define LFREG 57365 32 | #define LWID 57366 33 | #define LFCONST 57367 34 | #define LSCONST 57368 35 | #define LNAME 57369 36 | #define LLAB 57370 37 | #define LVAR 57371 38 | -------------------------------------------------------------------------------- /2c/Update: -------------------------------------------------------------------------------- 1 | if(n->op == ONAME) { 2 | < if(o == OSET) 3 | < gopcode(OTST, tint, D_NONE, Z, D_TREE, n); 4 | < else 5 | < gopcode(OTST, tint, D_TREE, n, D_NONE, Z); 6 | < p->as = ANOP; 7 | < } 8 | -------------------------------------------------------------------------------- /2c/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../../mkconfig 3 | 4 | TARG=2c 5 | 6 | OFILES=\ 7 | cgen.$O\ 8 | reg.$O\ 9 | txt.$O\ 10 | peep.$O\ 11 | swt.$O\ 12 | sgen.$O\ 13 | list.$O\ 14 | enam.$O\ 15 | mul.$O\ 16 | 17 | HFILES=\ 18 | gc.h\ 19 | 2.out.h\ 20 | ../cc/cc.h\ 21 | 22 | LIBS=cc bio 9 # order is important 23 | 24 | BIN=$ROOT/$OBJDIR/bin 25 | 26 | <$ROOT/mkfiles/mkone-$SHELLTYPE 27 | 28 | CFLAGS= $CFLAGS -I. 29 | 30 | $ROOT/$OBJDIR/lib/libcc.a: 31 | cd ../cc 32 | mk $MKFLAGS install 33 | mk $MKFLAGS clean 34 | -------------------------------------------------------------------------------- /2l/Nt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "l.h" 3 | 4 | /* 5 | * fake malloc 6 | */ 7 | void* 8 | malloc(uint n) 9 | { 10 | void *p; 11 | 12 | while(n & 7) 13 | n++; 14 | while(nhunk < n) 15 | gethunk(); 16 | p = hunk; 17 | nhunk -= n; 18 | hunk += n; 19 | return p; 20 | } 21 | 22 | void 23 | free(void *p) 24 | { 25 | USED(p); 26 | } 27 | 28 | void* 29 | calloc(uint m, uint n) 30 | { 31 | void *p; 32 | 33 | n *= m; 34 | p = malloc(n); 35 | memset(p, 0, n); 36 | return p; 37 | } 38 | 39 | void* 40 | realloc(void *p, uint n) 41 | { 42 | void *new; 43 | 44 | new = malloc(n); 45 | if(new && p) 46 | memmove(new, p, n); 47 | return new; 48 | } 49 | 50 | #define Chunk (1*1024*1024) 51 | 52 | void* 53 | mysbrk(ulong size) 54 | { 55 | void *v; 56 | static int chunk; 57 | static uchar *brk; 58 | 59 | if(chunk < size) { 60 | chunk = Chunk; 61 | if(chunk < size) 62 | chunk = Chunk + size; 63 | brk = VirtualAlloc(NULL, chunk, MEM_COMMIT, PAGE_EXECUTE_READWRITE); 64 | if(brk == 0) 65 | return (void*)-1; 66 | } 67 | v = brk; 68 | chunk -= size; 69 | brk += size; 70 | return v; 71 | } 72 | 73 | double 74 | cputime(void) 75 | { 76 | return ((double)0); 77 | } 78 | -------------------------------------------------------------------------------- /2l/Plan9.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | 3 | /* 4 | * fake malloc 5 | */ 6 | void* 7 | malloc(ulong n) 8 | { 9 | void *p; 10 | 11 | while(n & 7) 12 | n++; 13 | while(nhunk < n) 14 | gethunk(); 15 | p = hunk; 16 | nhunk -= n; 17 | hunk += n; 18 | return p; 19 | } 20 | 21 | void 22 | free(void *p) 23 | { 24 | USED(p); 25 | } 26 | 27 | void* 28 | calloc(ulong m, ulong n) 29 | { 30 | void *p; 31 | 32 | n *= m; 33 | p = malloc(n); 34 | memset(p, 0, n); 35 | return p; 36 | } 37 | 38 | void* 39 | realloc(void *p, ulong n) 40 | { 41 | USED(p); 42 | USED(n); 43 | fprint(2, "realloc called\n"); 44 | abort(); 45 | return 0; 46 | } 47 | 48 | void* 49 | mysbrk(ulong size) 50 | { 51 | return sbrk(size); 52 | } 53 | 54 | void 55 | setmalloctag(void*, ulong) 56 | { 57 | } 58 | -------------------------------------------------------------------------------- /2l/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../../mkconfig 3 | 4 | TARG=2l 5 | OFILES=\ 6 | asm.$O\ 7 | obj.$O\ 8 | optab.$O\ 9 | pass.$O\ 10 | span.$O\ 11 | list.$O\ 12 | enam.$O\ 13 | $TARGMODEL.$O\ 14 | 15 | HFILES=\ 16 | l.h\ 17 | ../2c/2.out.h\ 18 | ${ROOT}/include/ar.h\ 19 | 20 | LIBS=bio 9 21 | BIN=$ROOT/$OBJDIR/bin 22 | <$ROOT/mkfiles/mkone-$SHELLTYPE 23 | 24 | CFLAGS= $CFLAGS -I ${ROOT}/include 25 | 26 | enam.$O: ../2c/enam.c 27 | $CC $CFLAGS ../2c/enam.c 28 | -------------------------------------------------------------------------------- /5a/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=5a 5 | 6 | OFILES=\ 7 | y.tab.$O\ 8 | lex.$O\ 9 | 10 | HFILES=\ 11 | ../5c/5.out.h\ 12 | y.tab.h\ 13 | a.h\ 14 | 15 | YFILES=a.y\ 16 | 17 | LIBS=cc bio 9 # order is important 18 | 19 | BIN=$ROOT/$OBJDIR/bin 20 | 21 | <$ROOT/mkfiles/mkone-$SHELLTYPE 22 | 23 | YFLAGS=-D1 -d 24 | 25 | lex.$O: ../cc/macbody ../cc/lexbody 26 | 27 | $ROOT/$OBJDIR/lib/libcc.a: 28 | cd ../cc 29 | mk $MKFLAGS install 30 | mk $MKFLAGS clean 31 | -------------------------------------------------------------------------------- /5a/y.tab.h: -------------------------------------------------------------------------------- 1 | 2 | typedef union 3 | { 4 | Sym *sym; 5 | long lval; 6 | double dval; 7 | char sval[8]; 8 | Gen gen; 9 | } YYSTYPE; 10 | extern YYSTYPE yylval; 11 | #define LTYPE1 57346 12 | #define LTYPE2 57347 13 | #define LTYPE3 57348 14 | #define LTYPE4 57349 15 | #define LTYPE5 57350 16 | #define LTYPE6 57351 17 | #define LTYPE7 57352 18 | #define LTYPE8 57353 19 | #define LTYPE9 57354 20 | #define LTYPEA 57355 21 | #define LTYPEB 57356 22 | #define LTYPEC 57357 23 | #define LTYPED 57358 24 | #define LTYPEE 57359 25 | #define LTYPEF 57360 26 | #define LTYPEG 57361 27 | #define LTYPEH 57362 28 | #define LTYPEI 57363 29 | #define LTYPEJ 57364 30 | #define LTYPEK 57365 31 | #define LTYPEL 57366 32 | #define LTYPEM 57367 33 | #define LTYPEN 57368 34 | #define LTYPEBX 57369 35 | #define LCONST 57370 36 | #define LSP 57371 37 | #define LSB 57372 38 | #define LFP 57373 39 | #define LPC 57374 40 | #define LTYPEX 57375 41 | #define LR 57376 42 | #define LREG 57377 43 | #define LF 57378 44 | #define LFREG 57379 45 | #define LC 57380 46 | #define LCREG 57381 47 | #define LPSR 57382 48 | #define LFCR 57383 49 | #define LCOND 57384 50 | #define LS 57385 51 | #define LAT 57386 52 | #define LFCONST 57387 53 | #define LSCONST 57388 54 | #define LNAME 57389 55 | #define LLAB 57390 56 | #define LVAR 57391 57 | -------------------------------------------------------------------------------- /5c/mkenam: -------------------------------------------------------------------------------- 1 | ed - ../5c/5.out.h <<'!' 2 | v/^ A/d 3 | ,s/^ A/ "/ 4 | g/ .*$/s/// 5 | ,s/,*$/",/ 6 | 1i 7 | char* anames[] = 8 | { 9 | . 10 | $a 11 | }; 12 | . 13 | w enam.c 14 | Q 15 | ! 16 | -------------------------------------------------------------------------------- /5c/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=5c 5 | 6 | OFILES=\ 7 | cgen.$O\ 8 | enam.$O\ 9 | list.$O\ 10 | mul.$O\ 11 | peep.$O\ 12 | pgen.$O\ 13 | pswt.$O\ 14 | reg.$O\ 15 | sgen.$O\ 16 | swt.$O\ 17 | txt.$O\ 18 | 19 | HFILES=\ 20 | gc.h\ 21 | 5.out.h\ 22 | ../cc/cc.h\ 23 | 24 | LIBS=cc bio 9 # order is important 25 | 26 | BIN=$ROOT/$OBJDIR/bin 27 | 28 | <$ROOT/mkfiles/mkone-$SHELLTYPE 29 | 30 | $ROOT/$OBJDIR/lib/libcc.a: 31 | cd ../cc 32 | mk $MKFLAGS install 33 | mk $MKFLAGS clean 34 | 35 | %.$O: ../cc/%.c 36 | $CC -I. $CFLAGS ../cc/$stem.c 37 | -------------------------------------------------------------------------------- /5l/Plan9.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | 3 | /* 4 | * fake malloc 5 | */ 6 | void* 7 | malloc(ulong n) 8 | { 9 | void *p; 10 | 11 | while(n & 7) 12 | n++; 13 | while(nhunk < n) 14 | gethunk(); 15 | p = hunk; 16 | nhunk -= n; 17 | hunk += n; 18 | return p; 19 | } 20 | 21 | void 22 | free(void *p) 23 | { 24 | USED(p); 25 | } 26 | 27 | void* 28 | calloc(ulong m, ulong n) 29 | { 30 | void *p; 31 | 32 | n *= m; 33 | p = malloc(n); 34 | memset(p, 0, n); 35 | return p; 36 | } 37 | 38 | void* 39 | realloc(void *p, ulong n) 40 | { 41 | USED(p); 42 | USED(n); 43 | fprint(2, "realloc called\n"); 44 | abort(); 45 | return 0; 46 | } 47 | 48 | void* 49 | mysbrk(ulong size) 50 | { 51 | return sbrk(size); 52 | } 53 | 54 | void 55 | setmalloctag(void*, ulong) 56 | { 57 | } 58 | -------------------------------------------------------------------------------- /5l/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=5l 5 | 6 | OFILES=\ 7 | asm.$O\ 8 | list.$O\ 9 | noop.$O\ 10 | obj.$O\ 11 | optab.$O\ 12 | pass.$O\ 13 | span.$O\ 14 | enam.$O\ 15 | $TARGMODEL.$O\ 16 | 17 | 18 | HFILES=\ 19 | l.h\ 20 | ../5c/5.out.h\ 21 | ${ROOT}/include/ar.h\ 22 | 23 | LIBS=bio 9 # order is important 24 | 25 | 26 | BIN=$ROOT/$OBJDIR/bin 27 | 28 | <$ROOT/mkfiles/mkone-$SHELLTYPE 29 | 30 | enam.$O: ../5c/enam.c 31 | $CC $CFLAGS ../5c/enam.c 32 | 33 | -------------------------------------------------------------------------------- /6a/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | TARG=6a 4 | 5 | OFILES=\ 6 | y.tab.$O\ 7 | lex.$O\ 8 | 9 | HFILES=\ 10 | ../6c/6.out.h\ 11 | y.tab.h\ 12 | a.h\ 13 | 14 | YFILES=a.y\ 15 | 16 | LIBS=cc bio 9 # order is important 17 | 18 | BIN=$ROOT/$OBJDIR/bin 19 | 20 | <$ROOT/mkfiles/mkone-$SHELLTYPE 21 | 22 | YFLAGS=-D1 -d 23 | 24 | lex.$O: ../cc/macbody ../cc/lexbody 25 | 26 | $ROOT/$OBJDIR/lib/libcc.a: 27 | cd ../cc 28 | mk $MKFLAGS install 29 | mk $MKFLAGS clean 30 | -------------------------------------------------------------------------------- /6a/y.tab.h: -------------------------------------------------------------------------------- 1 | 2 | typedef union { 3 | Sym *sym; 4 | vlong lval; 5 | double dval; 6 | char sval[8]; 7 | Gen gen; 8 | Gen2 gen2; 9 | } YYSTYPE; 10 | extern YYSTYPE yylval; 11 | #define LTYPE0 57346 12 | #define LTYPE1 57347 13 | #define LTYPE2 57348 14 | #define LTYPE3 57349 15 | #define LTYPE4 57350 16 | #define LTYPEC 57351 17 | #define LTYPED 57352 18 | #define LTYPEN 57353 19 | #define LTYPER 57354 20 | #define LTYPET 57355 21 | #define LTYPES 57356 22 | #define LTYPEM 57357 23 | #define LTYPEI 57358 24 | #define LTYPEG 57359 25 | #define LTYPEXC 57360 26 | #define LTYPEX 57361 27 | #define LTYPEY 57362 28 | #define LTYPERT 57363 29 | #define LCONST 57364 30 | #define LFP 57365 31 | #define LPC 57366 32 | #define LSB 57367 33 | #define LBREG 57368 34 | #define LLREG 57369 35 | #define LSREG 57370 36 | #define LFREG 57371 37 | #define LMREG 57372 38 | #define LXREG 57373 39 | #define LYREG 57374 40 | #define LFCONST 57375 41 | #define LSCONST 57376 42 | #define LSP 57377 43 | #define LNAME 57378 44 | #define LLAB 57379 45 | #define LVAR 57380 46 | -------------------------------------------------------------------------------- /6c/machcap.c: -------------------------------------------------------------------------------- 1 | #include "gc.h" 2 | 3 | int 4 | machcap(Node *n) 5 | { 6 | 7 | if(n == Z) 8 | return 1; /* test */ 9 | 10 | switch(n->op) { 11 | case OMUL: 12 | case OLMUL: 13 | case OASMUL: 14 | case OASLMUL: 15 | if(typechl[n->type->etype]) 16 | return 1; 17 | if(typev[n->type->etype]) { 18 | return 1; 19 | } 20 | break; 21 | 22 | case OCOM: 23 | case ONEG: 24 | case OADD: 25 | case OAND: 26 | case OOR: 27 | case OSUB: 28 | case OXOR: 29 | case OASHL: 30 | case OLSHR: 31 | case OASHR: 32 | if(typechlv[n->left->type->etype]) 33 | return 1; 34 | break; 35 | 36 | case OCAST: 37 | return 1; 38 | 39 | case OCOND: 40 | case OCOMMA: 41 | case OLIST: 42 | case OANDAND: 43 | case OOROR: 44 | case ONOT: 45 | return 1; 46 | 47 | case OASADD: 48 | case OASSUB: 49 | case OASAND: 50 | case OASOR: 51 | case OASXOR: 52 | return 1; 53 | 54 | case OASASHL: 55 | case OASASHR: 56 | case OASLSHR: 57 | return 1; 58 | 59 | case OPOSTINC: 60 | case OPOSTDEC: 61 | case OPREINC: 62 | case OPREDEC: 63 | return 1; 64 | 65 | case OEQ: 66 | case ONE: 67 | case OLE: 68 | case OGT: 69 | case OLT: 70 | case OGE: 71 | case OHI: 72 | case OHS: 73 | case OLO: 74 | case OLS: 75 | return 1; 76 | } 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /6c/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | TARG=6c 4 | 5 | OFILES=\ 6 | cgen.$O\ 7 | enam.$O\ 8 | list.$O\ 9 | mul.$O\ 10 | peep.$O\ 11 | reg.$O\ 12 | sgen.$O\ 13 | swt.$O\ 14 | txt.$O\ 15 | pswt.$O\ 16 | pgen.$O\ 17 | div.$O\ 18 | 19 | HFILES=\ 20 | gc.h\ 21 | 6.out.h\ 22 | ../cc/cc.h\ 23 | 24 | LIBS=cc bio 9 # order is important 25 | 26 | BIN=$ROOT/$OBJDIR/bin 27 | 28 | <$ROOT/mkfiles/mkone-$SHELLTYPE 29 | 30 | $ROOT/$OBJDIR/lib/libcc.a: 31 | cd ../cc 32 | mk $MKFLAGS install 33 | mk $MKFLAGS clean 34 | -------------------------------------------------------------------------------- /6c/mkfile_o: -------------------------------------------------------------------------------- 1 | 2 | #include "l.h" 3 | 4 | /* 5 | * fake malloc 6 | */ 7 | void* 8 | malloc(uint n) 9 | { 10 | void *p; 11 | 12 | while(n & 7) 13 | n++; 14 | while(nhunk < n) 15 | gethunk(); 16 | p = hunk; 17 | nhunk -= n; 18 | hunk += n; 19 | return p; 20 | } 21 | 22 | void 23 | free(void *p) 24 | { 25 | USED(p); 26 | } 27 | 28 | void* 29 | calloc(uint m, uint n) 30 | { 31 | void *p; 32 | 33 | n *= m; 34 | p = malloc(n); 35 | memset(p, 0, n); 36 | return p; 37 | } 38 | 39 | void* 40 | realloc(void *p, uint n) 41 | { 42 | void *new; 43 | 44 | new = malloc(n); 45 | if(new && p) 46 | memmove(new, p, n); 47 | return new; 48 | } 49 | 50 | #define Chunk (1*1024*1024) 51 | 52 | void* 53 | mysbrk(ulong size) 54 | { 55 | void *v; 56 | static int chunk; 57 | static uchar *brk; 58 | 59 | if(chunk < size) { 60 | chunk = Chunk; 61 | if(chunk < size) 62 | chunk = Chunk + size; 63 | brk = VirtualAlloc(NULL, chunk, MEM_COMMIT, PAGE_EXECUTE_READWRITE); 64 | if(brk == 0) 65 | return (void*)-1; 66 | } 67 | v = brk; 68 | chunk -= size; 69 | brk += size; 70 | return v; 71 | } 72 | 73 | double 74 | cputime(void) 75 | { 76 | return ((double)0); 77 | } 78 | -------------------------------------------------------------------------------- /6l/Plan9.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | 3 | /* 4 | * fake malloc 5 | */ 6 | void* 7 | malloc(ulong n) 8 | { 9 | void *p; 10 | 11 | while(n & 7) 12 | n++; 13 | while(nhunk < n) 14 | gethunk(); 15 | p = hunk; 16 | nhunk -= n; 17 | hunk += n; 18 | return p; 19 | } 20 | 21 | void 22 | free(void *p) 23 | { 24 | USED(p); 25 | } 26 | 27 | void* 28 | calloc(ulong m, ulong n) 29 | { 30 | void *p; 31 | 32 | n *= m; 33 | p = malloc(n); 34 | memset(p, 0, n); 35 | return p; 36 | } 37 | 38 | void* 39 | realloc(void *p, ulong n) 40 | { 41 | USED(p); 42 | USED(n); 43 | fprint(2, "realloc called\n"); 44 | abort(); 45 | return 0; 46 | } 47 | 48 | void* 49 | mysbrk(ulong size) 50 | { 51 | return sbrk(size); 52 | } 53 | -------------------------------------------------------------------------------- /6l/bits.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | void 6 | f(void) 7 | { 8 | struct{ 9 | int twobit:2; 10 | int :1; 11 | int threebit:3; 12 | int onebit:1; 13 | } s3; 14 | struct{ 15 | uint twobit:2; 16 | uint :1; 17 | uint threebit:3; 18 | uint onebit:1; 19 | } s4; 20 | 21 | s3.threebit = 7; 22 | s3.twobit = s3.threebit; 23 | // s3.threebit = s3.twobit; 24 | print("%d %d\n", s3.threebit, s3.twobit); 25 | 26 | s4.threebit = 7; 27 | s4.twobit = s4.threebit; 28 | // s4.threebit = s4.twobit; 29 | print("%d %d\n", s4.threebit, s4.twobit); 30 | } 31 | 32 | void 33 | main(int, char**) 34 | { 35 | f(); 36 | } 37 | -------------------------------------------------------------------------------- /6l/compat.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | 3 | /* 4 | * fake malloc 5 | */ 6 | /* 7 | void* 8 | malloc(ulong n) 9 | { 10 | void *p; 11 | 12 | while(n & 7) 13 | n++; 14 | while(nhunk < n) 15 | gethunk(); 16 | p = hunk; 17 | nhunk -= n; 18 | hunk += n; 19 | return p; 20 | } 21 | 22 | void 23 | free(void *p) 24 | { 25 | USED(p); 26 | } 27 | 28 | void* 29 | calloc(ulong m, ulong n) 30 | { 31 | void *p; 32 | 33 | n *= m; 34 | p = malloc(n); 35 | memset(p, 0, n); 36 | return p; 37 | } 38 | 39 | void* 40 | realloc(void*, ulong) 41 | { 42 | fprint(2, "realloc called\n"); 43 | abort(); 44 | return 0; 45 | } 46 | 47 | void* 48 | mysbrk(ulong size) 49 | { 50 | return sbrk(size); 51 | } 52 | 53 | void 54 | setmalloctag(void *v, ulong pc) 55 | { 56 | USED(v, pc); 57 | } 58 | */ 59 | int 60 | fileexists(char *s) 61 | { 62 | uchar dirbuf[400]; 63 | 64 | /* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */ 65 | return stat(s, dirbuf/*, sizeof(dirbuf)*/) >= 0; 66 | } 67 | -------------------------------------------------------------------------------- /6l/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | TARG=6l 4 | 5 | OFILES=\ 6 | asm.$O\ 7 | list.$O\ 8 | obj.$O\ 9 | optab.$O\ 10 | pass.$O\ 11 | span.$O\ 12 | enam.$O\ 13 | compat.$O\ 14 | $TARGMODEL.$O\ 15 | 16 | HFILES=\ 17 | l.h\ 18 | ../6c/6.out.h\ 19 | ${ROOT}/include/ar.h\ 20 | 21 | LIBS=bio 9 # order is important 22 | 23 | 24 | BIN=$ROOT/$OBJDIR/bin 25 | 26 | <$ROOT/mkfiles/mkone-$SHELLTYPE 27 | 28 | enam.$O: ../6c/enam.c 29 | $CC $CFLAGS ../6c/enam.c 30 | 31 | -------------------------------------------------------------------------------- /6l/mkfile_o: -------------------------------------------------------------------------------- 1 | op) { 11 | case OMUL: 12 | case OLMUL: 13 | case OASMUL: 14 | case OASLMUL: 15 | if(typechlv[n->type->etype]) 16 | return 1; 17 | break; 18 | 19 | case OADD: 20 | case OAND: 21 | case OOR: 22 | case OSUB: 23 | case OXOR: 24 | case OASHL: 25 | case OLSHR: 26 | case OASHR: 27 | if(typechlv[n->left->type->etype]) 28 | return 1; 29 | break; 30 | 31 | case OCAST: 32 | return 1; 33 | 34 | case OCOND: 35 | case OCOMMA: 36 | case OLIST: 37 | case OANDAND: 38 | case OOROR: 39 | case ONOT: 40 | return 1; 41 | 42 | case OASADD: 43 | case OASSUB: 44 | case OASAND: 45 | case OASOR: 46 | case OASXOR: 47 | return 1; 48 | 49 | case OASASHL: 50 | case OASASHR: 51 | case OASLSHR: 52 | return 1; 53 | 54 | case OPOSTINC: 55 | case OPOSTDEC: 56 | case OPREINC: 57 | case OPREDEC: 58 | return 1; 59 | 60 | case OEQ: 61 | case ONE: 62 | case OLE: 63 | case OGT: 64 | case OLT: 65 | case OGE: 66 | case OHI: 67 | case OHS: 68 | case OLO: 69 | case OLS: 70 | return 1; 71 | 72 | case ONEG: 73 | if(typechlv[n->left->type->etype]) 74 | return 1; 75 | break; 76 | 77 | case OCOM: 78 | break; 79 | } 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /7c/mkenam: -------------------------------------------------------------------------------- 1 | ed - ../7c/7.out.h <<'!' 2 | v/^ A/d 3 | ,s/^ A/ "/ 4 | g/ .*$/s/// 5 | ,s/,*$/",/ 6 | 1i 7 | char* anames[] = 8 | { 9 | . 10 | $a 11 | }; 12 | . 13 | w enam.c 14 | Q 15 | ! 16 | -------------------------------------------------------------------------------- /7c/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | TARG=7c 4 | OFILES=\ 5 | cgen.$O\ 6 | enam.$O\ 7 | list.$O\ 8 | machcap.$O\ 9 | mul.$O\ 10 | peep.$O\ 11 | pgen.$O\ 12 | pswt.$O\ 13 | reg.$O\ 14 | sgen.$O\ 15 | swt.$O\ 16 | txt.$O\ 17 | 18 | HFILES=\ 19 | gc.h\ 20 | 7.out.h\ 21 | ../cc/cc.h\ 22 | 23 | LIBS=cc bio 9 # order is important 24 | 25 | BIN=$ROOT/$OBJDIR/bin 26 | 27 | <$ROOT/mkfiles/mkone-$SHELLTYPE 28 | CFLAGS=-I. $CFLAGS 29 | 30 | $ROOT/$OBJDIR/lib/libcc.a: 31 | cd ../cc 32 | mk install 33 | mk clean 34 | 35 | %.$O: ../cc/%.c 36 | $CC $CFLAGS ../cc/$stem.c 37 | 38 | t:V: $O.out 39 | $O.out -S t 40 | $LD -o t.out t.$O 41 | t.out 42 | 43 | #enam.c: 7.out.h 44 | # rc mkenam 45 | -------------------------------------------------------------------------------- /7l/cnam.c: -------------------------------------------------------------------------------- 1 | char *cnames[] = 2 | { 3 | "NONE", 4 | "REG", 5 | "RSP", 6 | "SHIFT", 7 | "EXTREG", 8 | "FREG", 9 | "SPR", 10 | "COND", 11 | "ZCON", 12 | "ADDCON0", 13 | "ADDCON", 14 | "MOVCON", 15 | "BITCON", 16 | "ABCON", 17 | "MBCON", 18 | "LCON", 19 | "FCON", 20 | "VCON", 21 | "AACON", 22 | "LACON", 23 | "AECON", 24 | "SBRA", 25 | "LBRA", 26 | "NPAUTO", 27 | "NSAUTO", 28 | "PSAUTO", 29 | "PPAUTO", 30 | "UAUTO4K", 31 | "UAUTO8K", 32 | "UAUTO16K", 33 | "UAUTO32K", 34 | "UAUTO64K", 35 | "LAUTO", 36 | "SEXT1", 37 | "SEXT2", 38 | "SEXT4", 39 | "SEXT8", 40 | "SEXT16", 41 | "LEXT", 42 | "NPOREG", 43 | "NSOREG", 44 | "ZOREG", 45 | "PSOREG", 46 | "PPOREG", 47 | "UOREG4K", 48 | "UOREG8K", 49 | "UOREG16K", 50 | "UOREG32K", 51 | "UOREG64K", 52 | "LOREG", 53 | "ADDR", 54 | "ROFF", 55 | "XPOST", 56 | "XPRE", 57 | "VREG", 58 | "GOK", 59 | "NCLASS", 60 | }; 61 | -------------------------------------------------------------------------------- /7l/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | HOST=Posix 3 | 4 | TARG=7l 5 | OFILES=\ 6 | $HOST.$O\ 7 | asm.$O\ 8 | asmout.$O\ 9 | bits.$O\ 10 | cnam.$O\ 11 | dyn.$O\ 12 | elf.$O\ 13 | enam.$O\ 14 | list.$O\ 15 | mod.$O\ 16 | noop.$O\ 17 | obj.$O\ 18 | optab.$O\ 19 | pass.$O\ 20 | pobj.$O\ 21 | span.$O\ 22 | sub.$O\ 23 | 24 | HFILES=\ 25 | l.h\ 26 | ../7c/7.out.h\ 27 | ../ld/elf.h\ 28 | ../ld/ld.h\ 29 | 30 | LIBS=bio 9 # order is important 31 | 32 | BIN=$ROOT/$OBJDIR/bin 33 | CFLAGS=$CFLAGS -I. 34 | <$ROOT/mkfiles/mkone-$SHELLTYPE 35 | 36 | #../7c/enam.c: ../7c/7.out.h 37 | # @ { cd ../7c; mk enam.c } 38 | 39 | cnam.c: l.h 40 | sh ../ld/mkcname 41 | 42 | enam.$O: ../7c/enam.c 43 | $CC $CFLAGS ../7c/enam.c 44 | %.$O: ../ld/%.c 45 | $CC $CFLAGS ../ld/$stem.c 46 | 47 | x:V: $O.out 48 | $O.out -la -o/dev/null x.7 49 | 50 | -------------------------------------------------------------------------------- /8a/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=8a 5 | 6 | OFILES=\ 7 | y.tab.$O\ 8 | lex.$O\ 9 | 10 | HFILES=\ 11 | ../8c/8.out.h\ 12 | y.tab.h\ 13 | a.h\ 14 | 15 | YFILES=a.y\ 16 | 17 | LIBS=cc bio 9 # order is important 18 | 19 | BIN=$ROOT/$OBJDIR/bin 20 | 21 | <$ROOT/mkfiles/mkone-$SHELLTYPE 22 | 23 | YFLAGS=-D1 -d 24 | 25 | lex.$O: ../cc/macbody ../cc/lexbody 26 | 27 | $ROOT/$OBJDIR/lib/libcc.a: 28 | cd ../cc 29 | mk $MKFLAGS install 30 | mk $MKFLAGS clean 31 | -------------------------------------------------------------------------------- /8a/y.tab.h: -------------------------------------------------------------------------------- 1 | 2 | typedef union { 3 | Sym *sym; 4 | long lval; 5 | double dval; 6 | char sval[8]; 7 | Gen gen; 8 | Gen2 gen2; 9 | } YYSTYPE; 10 | extern YYSTYPE yylval; 11 | #define LTYPE0 57346 12 | #define LTYPE1 57347 13 | #define LTYPE2 57348 14 | #define LTYPE3 57349 15 | #define LTYPE4 57350 16 | #define LTYPEC 57351 17 | #define LTYPED 57352 18 | #define LTYPEN 57353 19 | #define LTYPER 57354 20 | #define LTYPET 57355 21 | #define LTYPES 57356 22 | #define LTYPEM 57357 23 | #define LTYPEI 57358 24 | #define LCONST 57359 25 | #define LFP 57360 26 | #define LPC 57361 27 | #define LSB 57362 28 | #define LBREG 57363 29 | #define LLREG 57364 30 | #define LSREG 57365 31 | #define LFREG 57366 32 | #define LFCONST 57367 33 | #define LSCONST 57368 34 | #define LSP 57369 35 | #define LNAME 57370 36 | #define LLAB 57371 37 | #define LVAR 57372 38 | -------------------------------------------------------------------------------- /8c/mkenam: -------------------------------------------------------------------------------- 1 | ed - ../8c/8.out.h <<'!' 2 | v/^ A/d 3 | ,s/^ A/ "/ 4 | g/ .*$/s/// 5 | ,s/,*$/",/ 6 | 1i 7 | char* anames[] = 8 | { 9 | . 10 | $a 11 | }; 12 | . 13 | w enam.c 14 | Q 15 | ! 16 | -------------------------------------------------------------------------------- /8c/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=8c 5 | 6 | OFILES=\ 7 | cgen.$O\ 8 | enam.$O\ 9 | list.$O\ 10 | sgen.$O\ 11 | swt.$O\ 12 | txt.$O\ 13 | reg.$O\ 14 | peep.$O\ 15 | pgen.$O\ 16 | pswt.$O\ 17 | machcap.$O\ 18 | cgen64.$O\ 19 | div.$O\ 20 | mul.$O\ 21 | 22 | HFILES=\ 23 | gc.h\ 24 | 8.out.h\ 25 | ../cc/cc.h\ 26 | 27 | LIBS=cc bio 9 # order is important 28 | 29 | BIN=$ROOT/$OBJDIR/bin 30 | 31 | <$ROOT/mkfiles/mkone-$SHELLTYPE 32 | 33 | 34 | $ROOT/$OBJDIR/lib/libcc.a: 35 | cd ../cc 36 | mk $MKFLAGS install 37 | mk $MKFLAGS clean 38 | 39 | %.$O: ../cc/%.c 40 | $CC -I. $CFLAGS ../cc/$stem.c 41 | -------------------------------------------------------------------------------- /8l/Plan9.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | 3 | /* 4 | * fake malloc 5 | */ 6 | void* 7 | malloc(ulong n) 8 | { 9 | void *p; 10 | 11 | while(n & 7) 12 | n++; 13 | while(nhunk < n) 14 | gethunk(); 15 | p = hunk; 16 | nhunk -= n; 17 | hunk += n; 18 | return p; 19 | } 20 | 21 | void 22 | free(void *p) 23 | { 24 | USED(p); 25 | } 26 | 27 | void* 28 | calloc(ulong m, ulong n) 29 | { 30 | void *p; 31 | 32 | n *= m; 33 | p = malloc(n); 34 | memset(p, 0, n); 35 | return p; 36 | } 37 | 38 | void* 39 | realloc(void *p, ulong n) 40 | { 41 | USED(p); 42 | USED(n); 43 | fprint(2, "realloc called\n"); 44 | abort(); 45 | return 0; 46 | } 47 | 48 | void* 49 | mysbrk(ulong size) 50 | { 51 | return sbrk(size); 52 | } 53 | 54 | void 55 | setmalloctag(void*, ulong) 56 | { 57 | } 58 | -------------------------------------------------------------------------------- /8l/compat.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | 3 | /* 4 | * fake malloc 5 | */ 6 | /* 7 | void* 8 | malloc(ulong n) 9 | { 10 | void *p; 11 | 12 | while(n & 7) 13 | n++; 14 | while(nhunk < n) 15 | gethunk(); 16 | p = hunk; 17 | nhunk -= n; 18 | hunk += n; 19 | return p; 20 | } 21 | 22 | void 23 | free(void *p) 24 | { 25 | USED(p); 26 | } 27 | 28 | void* 29 | calloc(ulong m, ulong n) 30 | { 31 | void *p; 32 | 33 | n *= m; 34 | p = malloc(n); 35 | memset(p, 0, n); 36 | return p; 37 | } 38 | 39 | void* 40 | realloc(void*, ulong) 41 | { 42 | fprint(2, "realloc called\n"); 43 | abort(); 44 | return 0; 45 | } 46 | 47 | void* 48 | mysbrk(ulong size) 49 | { 50 | return sbrk(size); 51 | } 52 | 53 | void 54 | setmalloctag(void *v, ulong pc) 55 | { 56 | USED(v, pc); 57 | } 58 | */ 59 | int 60 | fileexists(char *s) 61 | { 62 | uchar dirbuf[400]; 63 | 64 | /* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */ 65 | return stat(s, dirbuf/*, sizeof(dirbuf)*/) >= 0; 66 | } 67 | -------------------------------------------------------------------------------- /8l/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=8l 5 | 6 | OFILES=\ 7 | asm.$O\ 8 | obj.$O\ 9 | optab.$O\ 10 | pass.$O\ 11 | span.$O\ 12 | list.$O\ 13 | enam.$O\ 14 | compat.$O\ 15 | elf.$O\ 16 | $TARGMODEL.$O\ 17 | 18 | HFILES=\ 19 | l.h\ 20 | ../8c/8.out.h\ 21 | ${ROOT}/libmach/ar.h\ 22 | 23 | LIBS=bio 9 # order is important 24 | 25 | BIN=$ROOT/$OBJDIR/bin 26 | 27 | <$ROOT/mkfiles/mkone-$SHELLTYPE 28 | 29 | 30 | enam.$O: ../8c/enam.c 31 | $CC $CFLAGS ../8c/enam.c 32 | -------------------------------------------------------------------------------- /Cygwin/386/bin/ar: -------------------------------------------------------------------------------- 1 | iar -------------------------------------------------------------------------------- /Cygwin/386/bin/iyacc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/Cygwin/386/bin/iyacc -------------------------------------------------------------------------------- /Cygwin/386/bin/mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/Cygwin/386/bin/mk -------------------------------------------------------------------------------- /Cygwin/386/bin/pad.txt: -------------------------------------------------------------------------------- 1 | It was difficult to get a working mk.exe that would work 2 | under cygwin. The mk in the original kencc in Nt/386/bin/mk.exe 3 | was compiled with a shell (rcsh) that was hard to find. 4 | It was looking for c:/inferno/Nt/386/bin/rcsh.exe 5 | but even after setting up this dir, mk would still 6 | sometimes exit saying it could find a shell. 7 | 8 | In the end I produce myself Cygwin/386/bin/mk.exe 9 | by compiling directly all the necessary source 10 | (see the mk.sh scripts in lib9/, libbio/, libregexp/, and mk/). 11 | I just saved the compiling trace under Linux and adapted 12 | it for cygwin. 13 | 14 | Once I had a working mk.exe under cygwin, I could compile 15 | all the rest. 16 | -------------------------------------------------------------------------------- /Cygwin/386/bin/yacc: -------------------------------------------------------------------------------- 1 | iyacc -------------------------------------------------------------------------------- /Cygwin/386/lib/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/Cygwin/386/lib/.keep -------------------------------------------------------------------------------- /Linux/386/bin/ar: -------------------------------------------------------------------------------- 1 | iar -------------------------------------------------------------------------------- /Linux/386/bin/data2c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/Linux/386/bin/data2c -------------------------------------------------------------------------------- /Linux/386/bin/iyacc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/Linux/386/bin/iyacc -------------------------------------------------------------------------------- /Linux/386/bin/mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/Linux/386/bin/mk -------------------------------------------------------------------------------- /Linux/386/bin/yacc: -------------------------------------------------------------------------------- 1 | iyacc -------------------------------------------------------------------------------- /Linux/386/lib/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/Linux/386/lib/.keep -------------------------------------------------------------------------------- /MacOSX/386/bin/0c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/0c -------------------------------------------------------------------------------- /MacOSX/386/bin/0l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/0l -------------------------------------------------------------------------------- /MacOSX/386/bin/1a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/1a -------------------------------------------------------------------------------- /MacOSX/386/bin/1c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/1c -------------------------------------------------------------------------------- /MacOSX/386/bin/1l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/1l -------------------------------------------------------------------------------- /MacOSX/386/bin/2a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/2a -------------------------------------------------------------------------------- /MacOSX/386/bin/2c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/2c -------------------------------------------------------------------------------- /MacOSX/386/bin/2l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/2l -------------------------------------------------------------------------------- /MacOSX/386/bin/5a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/5a -------------------------------------------------------------------------------- /MacOSX/386/bin/5c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/5c -------------------------------------------------------------------------------- /MacOSX/386/bin/5l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/5l -------------------------------------------------------------------------------- /MacOSX/386/bin/6a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/6a -------------------------------------------------------------------------------- /MacOSX/386/bin/6c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/6c -------------------------------------------------------------------------------- /MacOSX/386/bin/6l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/6l -------------------------------------------------------------------------------- /MacOSX/386/bin/7a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/7a -------------------------------------------------------------------------------- /MacOSX/386/bin/7c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/7c -------------------------------------------------------------------------------- /MacOSX/386/bin/7l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/7l -------------------------------------------------------------------------------- /MacOSX/386/bin/8a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/8a -------------------------------------------------------------------------------- /MacOSX/386/bin/8c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/8c -------------------------------------------------------------------------------- /MacOSX/386/bin/8l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/8l -------------------------------------------------------------------------------- /MacOSX/386/bin/acid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/acid -------------------------------------------------------------------------------- /MacOSX/386/bin/ar: -------------------------------------------------------------------------------- 1 | iar -------------------------------------------------------------------------------- /MacOSX/386/bin/data2c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/data2c -------------------------------------------------------------------------------- /MacOSX/386/bin/data2s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/data2s -------------------------------------------------------------------------------- /MacOSX/386/bin/date: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/date -------------------------------------------------------------------------------- /MacOSX/386/bin/hoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/hoc -------------------------------------------------------------------------------- /MacOSX/386/bin/iar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/iar -------------------------------------------------------------------------------- /MacOSX/386/bin/ilex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/ilex -------------------------------------------------------------------------------- /MacOSX/386/bin/inm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/inm -------------------------------------------------------------------------------- /MacOSX/386/bin/iyacc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/iyacc -------------------------------------------------------------------------------- /MacOSX/386/bin/ka: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/ka -------------------------------------------------------------------------------- /MacOSX/386/bin/kc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/kc -------------------------------------------------------------------------------- /MacOSX/386/bin/kl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/kl -------------------------------------------------------------------------------- /MacOSX/386/bin/kprof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/kprof -------------------------------------------------------------------------------- /MacOSX/386/bin/ksize: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/ksize -------------------------------------------------------------------------------- /MacOSX/386/bin/kstrip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/kstrip -------------------------------------------------------------------------------- /MacOSX/386/bin/mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/mk -------------------------------------------------------------------------------- /MacOSX/386/bin/mk.save: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/mk.save -------------------------------------------------------------------------------- /MacOSX/386/bin/pcc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/pcc -------------------------------------------------------------------------------- /MacOSX/386/bin/qa: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/qa -------------------------------------------------------------------------------- /MacOSX/386/bin/qc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/qc -------------------------------------------------------------------------------- /MacOSX/386/bin/ql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/ql -------------------------------------------------------------------------------- /MacOSX/386/bin/rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/rc -------------------------------------------------------------------------------- /MacOSX/386/bin/sed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/sed -------------------------------------------------------------------------------- /MacOSX/386/bin/tc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/tc -------------------------------------------------------------------------------- /MacOSX/386/bin/va: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/va -------------------------------------------------------------------------------- /MacOSX/386/bin/vc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/vc -------------------------------------------------------------------------------- /MacOSX/386/bin/vl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/vl -------------------------------------------------------------------------------- /MacOSX/386/bin/xd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/xd -------------------------------------------------------------------------------- /MacOSX/386/bin/yacc: -------------------------------------------------------------------------------- 1 | iyacc -------------------------------------------------------------------------------- /MacOSX/386/bin/zc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/zc -------------------------------------------------------------------------------- /MacOSX/386/bin/zl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/bin/zl -------------------------------------------------------------------------------- /MacOSX/386/lib/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/lib/.keep -------------------------------------------------------------------------------- /MacOSX/386/lib/lib9.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/lib/lib9.a -------------------------------------------------------------------------------- /MacOSX/386/lib/libbio.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/lib/libbio.a -------------------------------------------------------------------------------- /MacOSX/386/lib/libcc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/lib/libcc.a -------------------------------------------------------------------------------- /MacOSX/386/lib/libl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/lib/libl.a -------------------------------------------------------------------------------- /MacOSX/386/lib/libmach.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/lib/libmach.a -------------------------------------------------------------------------------- /MacOSX/386/lib/libmath.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/lib/libmath.a -------------------------------------------------------------------------------- /MacOSX/386/lib/libregexp.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/MacOSX/386/lib/libregexp.a -------------------------------------------------------------------------------- /Plan9/386/bin/data2c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/Plan9/386/bin/data2c -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kencc-cross 2 | Updated Plan9 cross compilers (for OSX <= 10.14 and Linux) including RISC V target 3 | 4 | * ken-cc compilers based on aryx' fork: https://github.com/aryx/fork-kencc 5 | * RISC V compiler by Richard Miller: https://9p.io/sources/contrib/miller/riscv.tar 6 | 7 | Included platforms: 8 | 9 | * 0c spim little-endian MIPS 3000 family 10 | * 1c 68000 Motorola MC68000 11 | * 2c 68020 Motorola MC68020 12 | * 5c arm little-endian ARM 13 | * 6c amd64 AMD64 and compatibles (e.g., Intel EM64T) 14 | * 7c arm64 little-endian ARM64 15 | * 8c 386 Intel i386, i486, Pentium, etc. 16 | * kc sparc Sun SPARC 17 | * qc power Power PC 18 | * tc arm little-endian ARM THUMB 19 | * uc sparc64 SPARC64 20 | * vc mips big-endian MIPS 3000 family 21 | * zc riscv RISC V 22 | 23 | -------------------------------------------------------------------------------- /acid/B.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | line=`/bin/echo $1 | /bin/sed 's/-//'` 3 | if [ "x$EDITOR" = "x" ] ; then 4 | vi +$line $2 5 | else 6 | $EDITOR +$line $2 7 | fi 8 | -------------------------------------------------------------------------------- /acid/arm: -------------------------------------------------------------------------------- 1 | please remove this file 2 | -------------------------------------------------------------------------------- /acid/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=acid 5 | 6 | OFILES= main.$O\ 7 | y.tab.$O\ 8 | lex.$O\ 9 | util.$O\ 10 | exec.$O\ 11 | expr.$O\ 12 | list.$O\ 13 | builtin.$O\ 14 | proc.$O\ 15 | dot.$O\ 16 | print.$O\ 17 | os-$TARGMODEL.$O\ 18 | rdebug.$O\ 19 | 20 | YFILES=dbg.y 21 | HFILES=acid.h y.tab.h 22 | 23 | LIBS=mach math bio regexp 9 24 | 25 | 26 | BIN=$ROOT/$OBJDIR/bin 27 | 28 | <$ROOT/mkfiles/mkone-$SHELLTYPE 29 | 30 | CFLAGS= $CFLAGS -I${ROOT}/include 31 | -------------------------------------------------------------------------------- /acid/y.tab.h: -------------------------------------------------------------------------------- 1 | 2 | typedef union 3 | { 4 | Node *node; 5 | Lsym *sym; 6 | ulong ival; 7 | float fval; 8 | String *string; 9 | } YYSTYPE; 10 | extern YYSTYPE yylval; 11 | #define Tfmt 57346 12 | #define Toror 57347 13 | #define Tandand 57348 14 | #define Teq 57349 15 | #define Tneq 57350 16 | #define Tleq 57351 17 | #define Tgeq 57352 18 | #define Tlsh 57353 19 | #define Trsh 57354 20 | #define Tdec 57355 21 | #define Tinc 57356 22 | #define Tindir 57357 23 | #define Tid 57358 24 | #define Tconst 57359 25 | #define Tfconst 57360 26 | #define Tstring 57361 27 | #define Tif 57362 28 | #define Tdo 57363 29 | #define Tthen 57364 30 | #define Telse 57365 31 | #define Twhile 57366 32 | #define Tloop 57367 33 | #define Thead 57368 34 | #define Ttail 57369 35 | #define Tappend 57370 36 | #define Tfn 57371 37 | #define Tret 57372 38 | #define Tlocal 57373 39 | #define Tcomplex 57374 40 | #define Twhat 57375 41 | #define Tdelete 57376 42 | #define Teval 57377 43 | -------------------------------------------------------------------------------- /ar/Plan9.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char * 4 | myctime(long x) 5 | { 6 | return ctime(x); 7 | } 8 | -------------------------------------------------------------------------------- /ar/Posix.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char * 4 | myctime(long x) 5 | { 6 | time_t t; 7 | 8 | t = x; 9 | return ctime(&t); 10 | } 11 | -------------------------------------------------------------------------------- /ar/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=iar # inferno archiver 5 | 6 | OFILES= ar.$O\ 7 | $TARGMODEL.$O\ 8 | 9 | HFILES= ${ROOT}/include/a.out.h\ 10 | ${ROOT}/include/bio.h\ 11 | ${ROOT}/include/mach.h\ 12 | 13 | LIBS=mach bio 9 # libbio.a uses lib9.a so order matters. 14 | 15 | BIN=$ROOT/$OBJDIR/bin 16 | 17 | <$ROOT/mkfiles/mkone-$SHELLTYPE 18 | 19 | -------------------------------------------------------------------------------- /bin: -------------------------------------------------------------------------------- 1 | MacOSX/386/bin -------------------------------------------------------------------------------- /cc/bits.c: -------------------------------------------------------------------------------- 1 | #include "cc.h" 2 | 3 | Bits 4 | bor(Bits a, Bits b) 5 | { 6 | Bits c; 7 | int i; 8 | 9 | for(i=0; ib[i]) 45 | return 1; 46 | return 0; 47 | } 48 | 49 | int 50 | beq(Bits a, Bits b) 51 | { 52 | int i; 53 | 54 | for(i=0; i\n" 2 | #define SARMAG 8 3 | 4 | #define ARFMAG "`\n" 5 | #define SARNAME 16 6 | 7 | struct ar_hdr 8 | { 9 | char name[SARNAME]; 10 | char date[12]; 11 | char uid[6]; 12 | char gid[6]; 13 | char mode[8]; 14 | char size[10]; 15 | char fmag[2]; 16 | }; 17 | #define SAR_HDR (SARNAME+44) 18 | -------------------------------------------------------------------------------- /include/rdbg.h: -------------------------------------------------------------------------------- 1 | /* Remote kernel debug protocol */ 2 | enum 3 | { 4 | Terr='0', /* not sent */ 5 | Rerr, 6 | Tmget, 7 | Rmget, 8 | Tmput, 9 | Rmput, 10 | 11 | Tspid, /* obsolete */ 12 | Rspid, /* obsolete */ 13 | Tproc, 14 | Rproc, 15 | Tstatus, 16 | Rstatus, 17 | Trnote, 18 | Rrnote, 19 | 20 | Tstartstop, 21 | Rstartstop, 22 | Twaitstop, 23 | Rwaitstop, 24 | Tstart, 25 | Rstart, 26 | Tstop, 27 | Rstop, 28 | Tkill, 29 | Rkill, 30 | 31 | Tcondbreak, 32 | Rcondbreak, 33 | 34 | RDBMSGLEN = 10 /* tag byte, 9 data bytes */ 35 | }; 36 | -------------------------------------------------------------------------------- /install.txt: -------------------------------------------------------------------------------- 1 | 2 | Installation 3 | 4 | These notes employ the name 'ken-cc' for "the directory containing 5 | this file". 6 | 7 | 8 | On unixen including linuxen and macosen the configure script will 9 | generate 'mkconfig' and 'env' 10 | 11 | In this directory... 12 | 13 | ./configure # (write 'ken-cc/mkconfig' && link 'ken-cc/bin') 14 | . ./env # (prepend 'ken-cc/bin' to path per session) 15 | mk # (build tools for host platform) 16 | mk install # (install tools into 'ken-cc/bin') 17 | 18 | See also... 19 | 20 | docs/mk.pdf 21 | 22 | See install_linux.txt, install_macos.txt, or install_windows.txt for more 23 | details for each platform. 24 | -------------------------------------------------------------------------------- /install_linux.txt: -------------------------------------------------------------------------------- 1 | On recent Linux distributions, you need to install a few extra 2 | packages to be able to produce 32 bits binaries on a 64 bits architecture: 3 | - libc6-dev-i386, otherwise you will get an error about the inexistent 4 | sys/cdefs.h and gnu/stub-32.h files 5 | - linux-libc-dev:i386, otherwise you will get an error about the inexistent 6 | asm/errno.h file. 7 | - gcc-multilib, otherwise you will get an error during linking about a 8 | missing libgcc.a 9 | -------------------------------------------------------------------------------- /install_macos.txt: -------------------------------------------------------------------------------- 1 | Modern macOS should come with a working C compiler (/usr/bin/cc should 2 | point to the Clang compiler). If not, install Xcode from the App 3 | store. You do not need to install anything else to be able to compile 4 | kencc. 5 | 6 | Just follow install.txt. 7 | -------------------------------------------------------------------------------- /install_windows.txt: -------------------------------------------------------------------------------- 1 | To compile kencc you will need to install the 32 bits cygwin environment 2 | (see https://www.cygwin.com/ and setup-x86.exe (not setup-x86_64.exe!)). 3 | You will need to add the gcc-core cygwin packages. 4 | 5 | After that, you can follow install.txt 6 | -------------------------------------------------------------------------------- /ka/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | TARG=ka 4 | 5 | OFILES=\ 6 | y.tab.$O\ 7 | lex.$O\ 8 | 9 | HFILES=\ 10 | ../kc/k.out.h\ 11 | y.tab.h\ 12 | a.h\ 13 | 14 | YFILES=a.y\ 15 | 16 | LIBS=cc bio 9 # order is important 17 | 18 | BIN=$ROOT/$OBJDIR/bin 19 | 20 | <$ROOT/mkfiles/mkone-$SHELLTYPE 21 | 22 | YFLAGS=-D1 -d 23 | 24 | lex.$O: ../cc/macbody ../cc/lexbody 25 | 26 | $ROOT/$OBJDIR/lib/libcc.a: 27 | cd ../cc 28 | mk $MKFLAGS install 29 | mk $MKFLAGS clean 30 | -------------------------------------------------------------------------------- /ka/y.tab.h: -------------------------------------------------------------------------------- 1 | 2 | typedef union 3 | { 4 | Sym *sym; 5 | long lval; 6 | double dval; 7 | char sval[8]; 8 | Gen gen; 9 | } YYSTYPE; 10 | extern YYSTYPE yylval; 11 | #define LMOVW 57346 12 | #define LMOVD 57347 13 | #define LMOVB 57348 14 | #define LSWAP 57349 15 | #define LADDW 57350 16 | #define LCMP 57351 17 | #define LBRA 57352 18 | #define LFMOV 57353 19 | #define LFCONV 57354 20 | #define LFADD 57355 21 | #define LCPOP 57356 22 | #define LTRAP 57357 23 | #define LJMPL 57358 24 | #define LXORW 57359 25 | #define LNOP 57360 26 | #define LEND 57361 27 | #define LRETT 57362 28 | #define LUNIMP 57363 29 | #define LTEXT 57364 30 | #define LDATA 57365 31 | #define LRETRN 57366 32 | #define LCONST 57367 33 | #define LSP 57368 34 | #define LSB 57369 35 | #define LFP 57370 36 | #define LPC 57371 37 | #define LCREG 57372 38 | #define LFLUSH 57373 39 | #define LREG 57374 40 | #define LFREG 57375 41 | #define LR 57376 42 | #define LC 57377 43 | #define LF 57378 44 | #define LFSR 57379 45 | #define LFPQ 57380 46 | #define LPSR 57381 47 | #define LSCHED 57382 48 | #define LFCONST 57383 49 | #define LSCONST 57384 50 | #define LNAME 57385 51 | #define LLAB 57386 52 | #define LVAR 57387 53 | -------------------------------------------------------------------------------- /kc/mkenam: -------------------------------------------------------------------------------- 1 | ed - ../kc/k.out.h <<'!' 2 | v/^ A/d 3 | g/^ AEND/s//&,/ 4 | g/[ ]*=.*,/s//,/ 5 | v/,/p 6 | ,s/^ A/ "/ 7 | ,s/,.*$/",/ 8 | 1i 9 | char *anames[] = 10 | { 11 | . 12 | ,a 13 | }; 14 | . 15 | w enam.c 16 | Q 17 | ! 18 | -------------------------------------------------------------------------------- /kc/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | TARG=kc 4 | 5 | OFILES=\ 6 | peep.$O\ 7 | pgen.$O\ 8 | pswt.$O\ 9 | reg.$O\ 10 | cgen.$O\ 11 | enam.$O\ 12 | list.$O\ 13 | sgen.$O\ 14 | swt.$O\ 15 | txt.$O\ 16 | mul.$O\ 17 | 18 | HFILES=\ 19 | gc.h\ 20 | k.out.h\ 21 | ../cc/cc.h\ 22 | 23 | LIBS=cc bio 9 # order is important. 24 | 25 | BIN=$ROOT/$OBJDIR/bin 26 | 27 | <$ROOT/mkfiles/mkone-$SHELLTYPE 28 | 29 | 30 | $ROOT/$OBJDIR/lib/libcc.a: 31 | cd ../cc 32 | mk $MKFLAGS install 33 | mk $MKFLAGS clean 34 | 35 | %.$O: ../cc/%.c 36 | $CC -I. $CFLAGS ../cc/$stem.c 37 | 38 | #enam.c: k.out.h 39 | # rc mkenam 40 | -------------------------------------------------------------------------------- /kl/Plan9.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | 3 | /* 4 | * fake malloc 5 | */ 6 | void* 7 | malloc(ulong n) 8 | { 9 | void *p; 10 | 11 | while(n & 7) 12 | n++; 13 | while(nhunk < n) 14 | gethunk(); 15 | p = hunk; 16 | nhunk -= n; 17 | hunk += n; 18 | return p; 19 | } 20 | 21 | void 22 | free(void *p) 23 | { 24 | USED(p); 25 | } 26 | 27 | void* 28 | calloc(ulong m, ulong n) 29 | { 30 | void *p; 31 | 32 | n *= m; 33 | p = malloc(n); 34 | memset(p, 0, n); 35 | return p; 36 | } 37 | 38 | void* 39 | realloc(void *p, ulong n) 40 | { 41 | USED(p); 42 | USED(n); 43 | fprint(2, "realloc called\n"); 44 | abort(); 45 | return 0; 46 | } 47 | 48 | void* 49 | mysbrk(ulong size) 50 | { 51 | return sbrk(size); 52 | } 53 | 54 | void 55 | setmalloctag(void*, ulong) 56 | { 57 | } 58 | -------------------------------------------------------------------------------- /kl/foo.c: -------------------------------------------------------------------------------- 1 | int foo(void) 2 | { 3 | return 100; 4 | } 5 | 6 | main() 7 | { 8 | int x; 9 | 10 | x = foo(); 11 | } 12 | 13 | _main() 14 | { 15 | } 16 | -------------------------------------------------------------------------------- /kl/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | 4 | TARG=kl 5 | 6 | OFILES=\ 7 | asm.$O\ 8 | list.$O\ 9 | noop.$O\ 10 | sched.$O\ 11 | obj.$O\ 12 | optab.$O\ 13 | pass.$O\ 14 | span.$O\ 15 | enam.$O\ 16 | $TARGMODEL.$O\ 17 | 18 | HFILES=\ 19 | l.h\ 20 | ../kc/k.out.h\ 21 | ${ROOT}/include/ar.h\ 22 | 23 | LIBS=bio 9 # order is important 24 | 25 | BIN=$ROOT/$OBJDIR/bin 26 | 27 | <$ROOT/mkfiles/mkone-$SHELLTYPE 28 | CFLAGS= $CFLAGS -I. 29 | 30 | enam.$O: ../kc/enam.c 31 | $CC $CFLAGS ../kc/enam.c 32 | 33 | $TARGMODEL.$O: ../ld/$TARGMODEL.c 34 | $CC $CFLAGS ../ld/$TARGMODEL.c 35 | -------------------------------------------------------------------------------- /ld/Nt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | * We can't include l.h, because Windoze wants to use some names 6 | * like FLOAT and ABC which we declare. Define what we need here. 7 | */ 8 | typedef unsigned char uchar; 9 | typedef unsigned int uint; 10 | typedef unsigned long ulong; 11 | 12 | #define Chunk (1*1024*1024) 13 | 14 | void* 15 | mysbrk(ulong size) 16 | { 17 | void *v; 18 | static int chunk; 19 | static uchar *brk; 20 | 21 | if(chunk < size) { 22 | chunk = Chunk; 23 | if(chunk < size) 24 | chunk = Chunk + size; 25 | brk = VirtualAlloc(NULL, chunk, MEM_COMMIT, PAGE_EXECUTE_READWRITE); 26 | if(brk == 0) 27 | return (void*)-1; 28 | } 29 | v = brk; 30 | chunk -= size; 31 | brk += size; 32 | return v; 33 | } 34 | 35 | double 36 | cputime(void) 37 | { 38 | return 0.0; 39 | } 40 | 41 | int 42 | fileexists(char *name) 43 | { 44 | int fd; 45 | 46 | fd = open(name, OREAD); 47 | if(fd < 0) 48 | return 0; 49 | close(fd); 50 | return 1; 51 | } 52 | -------------------------------------------------------------------------------- /ld/Plan9.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | 3 | void* 4 | mysbrk(usize size) 5 | { 6 | return sbrk(size); 7 | } 8 | 9 | int 10 | fileexists(char *s) 11 | { 12 | uchar dirbuf[400]; 13 | 14 | /* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */ 15 | return stat(s, dirbuf, sizeof(dirbuf)) >= 0; 16 | } 17 | -------------------------------------------------------------------------------- /ld/Posix.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | #include 3 | #include 4 | #include 5 | #undef getwd 6 | #include /* For sysconf() and _SC_CLK_TCK */ 7 | 8 | void* 9 | mysbrk(ulong size) 10 | { 11 | return (void*)sbrk(size); 12 | } 13 | 14 | double 15 | cputime(void) 16 | { 17 | 18 | struct tms tmbuf; 19 | double ret_val; 20 | 21 | /* 22 | * times() only fails if &tmbuf is invalid. 23 | */ 24 | (void)times(&tmbuf); 25 | /* 26 | * Return the total time (in system clock ticks) 27 | * spent in user code and system 28 | * calls by both the calling process and its children. 29 | */ 30 | ret_val = (double)(tmbuf.tms_utime + tmbuf.tms_stime + 31 | tmbuf.tms_cutime + tmbuf.tms_cstime); 32 | /* 33 | * Convert to seconds. 34 | */ 35 | ret_val *= sysconf(_SC_CLK_TCK); 36 | return ret_val; 37 | 38 | } 39 | 40 | int 41 | fileexists(char *name) 42 | { 43 | struct stat sb; 44 | 45 | return stat(name, &sb) >= 0; 46 | } 47 | -------------------------------------------------------------------------------- /ld/Upd: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | cp mkcname *.[ch] /n/local/usr/forsyth/7/7acl/ld/. 3 | -------------------------------------------------------------------------------- /ld/falloc.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | 3 | /* 4 | * fake malloc 5 | */ 6 | void* 7 | malloc(ulong n) 8 | { 9 | return halloc(n); 10 | } 11 | 12 | void 13 | free(void *p) 14 | { 15 | USED(p); 16 | } 17 | 18 | void* 19 | calloc(ulong m, ulong n) 20 | { 21 | void *p; 22 | 23 | n *= m; 24 | p = malloc(n); 25 | memset(p, 0, n); 26 | return p; 27 | } 28 | 29 | /* 30 | * not used by compiler or loader, but Windows needs it 31 | */ 32 | void* 33 | realloc(void *p, ulong n) 34 | { 35 | void *new; 36 | 37 | new = malloc(n); 38 | if(new != nil && p != nil) 39 | memmove(new, p, n); /* safe only when adjecent hunks have no gaps */ 40 | return new; 41 | } 42 | 43 | void 44 | setmalloctag(void *v, ulong pc) 45 | { 46 | USED(v); 47 | USED(pc); 48 | } 49 | -------------------------------------------------------------------------------- /ld/mkcname: -------------------------------------------------------------------------------- 1 | ed - l.h <<'!' 2 | v/^ C_/d 3 | g/^ C_NCLASS/s//&,/ 4 | g/[ ]*=.*,/s//,/ 5 | v/,/p 6 | ,s/^ C_/ "/ 7 | ,s/,.*$/",/ 8 | 1i 9 | char *cnames[] = 10 | { 11 | . 12 | ,a 13 | }; 14 | . 15 | w cnam.c 16 | Q 17 | ! 18 | -------------------------------------------------------------------------------- /lex/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=ilex 5 | 6 | OFILES=lmain.$O\ 7 | y.tab.$O\ 8 | sub1.$O\ 9 | sub2.$O\ 10 | header.$O\ 11 | 12 | HFILES=ldefs.h\ 13 | 14 | LIBS=bio 9 15 | 16 | BIN=$ROOT/$OBJDIR/bin 17 | 18 | YFILES=parser.y\ 19 | 20 | <$ROOT/mkfiles/mkone-$SHELLTYPE 21 | 22 | install:V: $ROOT/lib/lex.ncform 23 | 24 | $ROOT/lib/lex.ncform: ncform 25 | rm -f $target && cp $prereq $target 26 | 27 | -------------------------------------------------------------------------------- /lex/y.tab.h: -------------------------------------------------------------------------------- 1 | #define CHAR 57346 2 | #define CCL 57347 3 | #define NCCL 57348 4 | #define STR 57349 5 | #define DELIM 57350 6 | #define SCON 57351 7 | #define ITER 57352 8 | #define NEWE 57353 9 | #define NULLS 57354 10 | #define CAT 57355 11 | -------------------------------------------------------------------------------- /lib/rcmain: -------------------------------------------------------------------------------- 1 | # rcmain: 9pm version 2 | if(~ $#home 0) home=/ 3 | if(~ $#ifs 0) ifs=' 4 | ' 5 | switch($#prompt){ 6 | case 0 7 | case 1 8 | prompt=('% ' ' ') 9 | } 10 | if(~ $rcname v.out) prompt=('broken! ' ' ') 11 | if(! ~ $#cflag 0){ 12 | if(flag l && test -r $home/lib/profile) . $home/lib/profile 13 | status='' 14 | eval $cflag 15 | } 16 | if not if(flag i){ 17 | if(flag l && test -r $home/lib/profile) . $home/lib/profile 18 | status='' 19 | if(! ~ $#* 0) . $* 20 | if not . -i 'stdin$' 21 | } 22 | if not { 23 | if(~ $#* 0) . 'stdin$' 24 | if not{ 25 | status='' 26 | . $* 27 | } 28 | } 29 | exit $status 30 | -------------------------------------------------------------------------------- /lib/rcmain.unix: -------------------------------------------------------------------------------- 1 | # rcmain: unix version 2 | if(~ $#home 0) home=$HOME 3 | if(~ $#ifs 0) ifs=' 4 | ' 5 | switch($#prompt){ 6 | case 0 7 | prompt=('% ' ' ') 8 | case 1 9 | prompt=($prompt ' ') 10 | } 11 | if(~ $rcname ?.out) prompt=('broken! ' ' ') 12 | if(flag p) path=/bin 13 | if not { 14 | #pad: does not work under cygwin, get some syntax error about '( [SUB]' 15 | #finit 16 | if(~ $#path 0) path=(. /bin /usr/bin /usr/local/bin) 17 | } 18 | fn sigexit 19 | if(! ~ $#cflag 0){ 20 | if(flag l && test -r $home/lib/profile) . $home/lib/profile 21 | status='' 22 | eval $cflag 23 | } 24 | if not if(flag i){ 25 | if(flag l && test -r $home/lib/profile) . $home/lib/profile 26 | status='' 27 | if(! ~ $#* 0) . $* 28 | . -i /dev/fd/0 29 | } 30 | if not if(~ $#* 0) . /dev/fd/0 31 | if not{ 32 | status='' 33 | . $* 34 | } 35 | exit $status 36 | -------------------------------------------------------------------------------- /lib9/argv0.c: -------------------------------------------------------------------------------- 1 | char* argv0 = 0; 2 | -------------------------------------------------------------------------------- /lib9/cistrcmp.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | int 4 | cistrcmp(char *s1, char *s2) 5 | { 6 | int c1, c2; 7 | 8 | while(*s1){ 9 | c1 = *(uchar*)s1++; 10 | c2 = *(uchar*)s2++; 11 | 12 | if(c1 == c2) 13 | continue; 14 | 15 | if(c1 >= 'A' && c1 <= 'Z') 16 | c1 -= 'A' - 'a'; 17 | 18 | if(c2 >= 'A' && c2 <= 'Z') 19 | c2 -= 'A' - 'a'; 20 | 21 | if(c1 != c2) 22 | return c1 - c2; 23 | } 24 | return -*s2; 25 | } 26 | -------------------------------------------------------------------------------- /lib9/cistrncmp.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | int 4 | cistrncmp(char *s1, char *s2, int n) 5 | { 6 | int c1, c2; 7 | 8 | while(*s1 && n-- > 0){ 9 | c1 = *(uchar*)s1++; 10 | c2 = *(uchar*)s2++; 11 | 12 | if(c1 == c2) 13 | continue; 14 | 15 | if(c1 >= 'A' && c1 <= 'Z') 16 | c1 -= 'A' - 'a'; 17 | 18 | if(c2 >= 'A' && c2 <= 'Z') 19 | c2 -= 'A' - 'a'; 20 | 21 | if(c1 != c2) 22 | return c1 - c2; 23 | } 24 | if(n <= 0) 25 | return 0; 26 | return -*s2; 27 | } 28 | -------------------------------------------------------------------------------- /lib9/cistrstr.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | char* 4 | cistrstr(char *s, char *sub) 5 | { 6 | int c, csub, n; 7 | 8 | csub = *sub; 9 | if(csub == '\0') 10 | return s; 11 | if(csub >= 'A' && csub <= 'Z') 12 | csub -= 'A' - 'a'; 13 | sub++; 14 | n = strlen(sub); 15 | for(; c = *s; s++){ 16 | if(c >= 'A' && c <= 'Z') 17 | c -= 'A' - 'a'; 18 | if(c == csub && cistrncmp(s+1, sub, n) == 0) 19 | return s; 20 | } 21 | return nil; 22 | } 23 | -------------------------------------------------------------------------------- /lib9/cleanname.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | * In place, rewrite name to compress multiple /, eliminate ., and process .. 5 | */ 6 | #define SEP(x) ((x)=='/' || (x) == 0) 7 | char* 8 | cleanname(char *name) 9 | { 10 | char *p, *q, *dotdot; 11 | int rooted; 12 | 13 | rooted = name[0] == '/'; 14 | 15 | /* 16 | * invariants: 17 | * p points at beginning of path element we're considering. 18 | * q points just past the last path element we wrote (no slash). 19 | * dotdot points just past the point where .. cannot backtrack 20 | * any further (no slash). 21 | */ 22 | p = q = dotdot = name+rooted; 23 | while(*p) { 24 | if(p[0] == '/') /* null element */ 25 | p++; 26 | else if(p[0] == '.' && SEP(p[1])) 27 | p += 1; /* don't count the separator in case it is nul */ 28 | else if(p[0] == '.' && p[1] == '.' && SEP(p[2])) { 29 | p += 2; 30 | if(q > dotdot) { /* can backtrack */ 31 | while(--q > dotdot && *q != '/') 32 | ; 33 | } else if(!rooted) { /* /.. is / but ./../ is .. */ 34 | if(q != name) 35 | *q++ = '/'; 36 | *q++ = '.'; 37 | *q++ = '.'; 38 | dotdot = q; 39 | } 40 | } else { /* real path element */ 41 | if(q != name+rooted) 42 | *q++ = '/'; 43 | while((*q = *p) != '/' && *q != 0) 44 | p++, q++; 45 | } 46 | } 47 | if(q == name) /* empty string is really ``.'' */ 48 | *q++ = '.'; 49 | *q = '\0'; 50 | return name; 51 | } 52 | -------------------------------------------------------------------------------- /lib9/create.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | #include 4 | 5 | int 6 | create(char *f, int mode, int perm) 7 | { 8 | int m; 9 | 10 | m = 0; 11 | switch(mode & 3){ 12 | case OREAD: 13 | case OEXEC: 14 | m = O_RDONLY; 15 | break; 16 | case OWRITE: 17 | m = O_WRONLY; 18 | break; 19 | case ORDWR: 20 | m = O_RDWR; 21 | break; 22 | } 23 | m |= O_CREAT|O_TRUNC; 24 | 25 | if(perm & DMDIR){ 26 | if(mkdir(f, perm&0777) < 0) 27 | return -1; 28 | perm &= ~DMDIR; 29 | m &= 3; 30 | } 31 | return open(f, m, perm); 32 | } 33 | -------------------------------------------------------------------------------- /lib9/dirwstat.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | #include 4 | 5 | int 6 | dirfwstat(int fd, Dir *d) 7 | { 8 | return -1; 9 | } 10 | 11 | int 12 | dirwstat(char *name, Dir *d) 13 | { 14 | return -1; 15 | } 16 | -------------------------------------------------------------------------------- /lib9/errfmt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | #include "fmtdef.h" 16 | 17 | int 18 | errfmt(Fmt *f) 19 | { 20 | char buf[ERRMAX]; 21 | 22 | rerrstr(buf, sizeof buf); 23 | return _fmtcpy(f, buf, utflen(buf), strlen(buf)); 24 | } 25 | -------------------------------------------------------------------------------- /lib9/errstr-Plan9.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | void 4 | oserrstr(char *buf, uint nerr) 5 | { 6 | *buf = 0; 7 | errstr(buf, nerr); 8 | } 9 | -------------------------------------------------------------------------------- /lib9/errstr-posix.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | #include 4 | 5 | static char errstring[ERRMAX]; 6 | 7 | enum 8 | { 9 | Magic = 0xffffff 10 | }; 11 | 12 | void 13 | werrstr(char *fmt, ...) 14 | { 15 | va_list arg; 16 | 17 | va_start(arg, fmt); 18 | vseprint(errstring, errstring+sizeof(errstring), fmt, arg); 19 | va_end(arg); 20 | errno = Magic; 21 | } 22 | 23 | void 24 | oserrstr(char *buf, uint nerr) 25 | { 26 | utfecpy(buf, buf+nerr, strerror(errno)); 27 | } 28 | 29 | int 30 | errstr(char *buf, uint nerr) 31 | { 32 | if(errno == Magic) 33 | utfecpy(buf, buf+nerr, errstring); 34 | else 35 | oserrstr(buf, nerr); 36 | return 1; 37 | } 38 | -------------------------------------------------------------------------------- /lib9/exits.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | void 4 | exits(char *s) 5 | { 6 | if(s == 0 || *s == 0) 7 | exit(0); 8 | exit(1); 9 | } 10 | 11 | void 12 | _exits(char *s) 13 | { 14 | if(s == 0 || *s == 0) 15 | _exit(0); 16 | _exit(1); 17 | } 18 | -------------------------------------------------------------------------------- /lib9/fmtlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | 16 | void 17 | _fmtlock(void) 18 | { 19 | } 20 | 21 | void 22 | _fmtunlock(void) 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /lib9/fmtprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | #include "fmtdef.h" 16 | 17 | 18 | /* 19 | * format a string into the output buffer 20 | * designed for formats which themselves call fmt, 21 | * but ignore any width flags 22 | */ 23 | int 24 | fmtprint(Fmt *f, char *fmt, ...) 25 | { 26 | va_list va; 27 | int n; 28 | 29 | f->flags = 0; 30 | f->width = 0; 31 | f->prec = 0; 32 | va = f->args; 33 | va_start(f->args, fmt); 34 | n = dofmt(f, fmt); 35 | va_end(f->args); 36 | f->flags = 0; 37 | f->width = 0; 38 | f->prec = 0; 39 | f->args = va; 40 | if(n >= 0) 41 | return 0; 42 | return n; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /lib9/fmtrune.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | #include "fmtdef.h" 16 | 17 | int 18 | fmtrune(Fmt *f, int r) 19 | { 20 | Rune *rt; 21 | char *t; 22 | int n; 23 | 24 | if(f->runes){ 25 | rt = f->to; 26 | FMTRCHAR(f, rt, f->stop, r); 27 | f->to = rt; 28 | n = 1; 29 | }else{ 30 | t = f->to; 31 | FMTRUNE(f, t, f->stop, r); 32 | n = t - (char*)f->to; 33 | f->to = t; 34 | } 35 | f->nfmt += n; 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /lib9/fmtstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | 16 | char* 17 | fmtstrflush(Fmt *f) 18 | { 19 | if(f->start == nil) 20 | return nil; 21 | *(char*)f->to = '\0'; 22 | return f->start; 23 | } 24 | -------------------------------------------------------------------------------- /lib9/fmtvprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | #include "fmtdef.h" 16 | 17 | 18 | /* 19 | * format a string into the output buffer 20 | * designed for formats which themselves call fmt, 21 | * but ignore any width flags 22 | */ 23 | int 24 | fmtvprint(Fmt *f, char *fmt, va_list args) 25 | { 26 | va_list va; 27 | int n; 28 | 29 | f->flags = 0; 30 | f->width = 0; 31 | f->prec = 0; 32 | va = f->args; 33 | f->args = args; 34 | n = dofmt(f, fmt); 35 | f->flags = 0; 36 | f->width = 0; 37 | f->prec = 0; 38 | f->args = va; 39 | if(n >= 0) 40 | return 0; 41 | return n; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /lib9/fprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | 16 | int 17 | fprint(int fd, char *fmt, ...) 18 | { 19 | int n; 20 | va_list args; 21 | 22 | va_start(args, fmt); 23 | n = vfprint(fd, fmt, args); 24 | va_end(args); 25 | return n; 26 | } 27 | -------------------------------------------------------------------------------- /lib9/getcallerpc-Cygwin-386.s: -------------------------------------------------------------------------------- 1 | .file "getcallerpc-Linux-386.S" 2 | // .type getcallerpc,@function 3 | .global getcallerpc 4 | getcallerpc: 5 | movl 4(%ebp), %eax 6 | ret 7 | -------------------------------------------------------------------------------- /lib9/getcallerpc-Linux-386.s: -------------------------------------------------------------------------------- 1 | .file "getcallerpc-Linux-386.S" 2 | .type getcallerpc,@function 3 | .global getcallerpc 4 | getcallerpc: 5 | movl 4(%ebp), %eax 6 | ret 7 | -------------------------------------------------------------------------------- /lib9/getcallerpc-MacOSX-386.s: -------------------------------------------------------------------------------- 1 | .file "getcallerpc-MacOSX-386.s" 2 | 3 | .text 4 | 5 | .globl _getcallerpc 6 | _getcallerpc: 7 | movl 4(%ebp), %eax 8 | ret 9 | -------------------------------------------------------------------------------- /lib9/getfields.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | int 3 | getfields(char *str, char **args, int max, int mflag, char *set) 4 | { 5 | Rune r; 6 | int nr, intok, narg; 7 | 8 | if(max <= 0) 9 | return 0; 10 | 11 | narg = 0; 12 | args[narg] = str; 13 | if(!mflag) 14 | narg++; 15 | intok = 0; 16 | for(;; str += nr) { 17 | nr = chartorune(&r, str); 18 | if(r == 0) 19 | break; 20 | if(utfrune(set, r)) { 21 | if(narg >= max) 22 | break; 23 | *str = 0; 24 | intok = 0; 25 | args[narg] = str + nr; 26 | if(!mflag) 27 | narg++; 28 | } else { 29 | if(!intok && mflag) 30 | narg++; 31 | intok = 1; 32 | } 33 | } 34 | return narg; 35 | } 36 | -------------------------------------------------------------------------------- /lib9/getuser-posix.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | char* 5 | getuser(void) 6 | { 7 | struct passwd *p; 8 | 9 | static char *user = 0; 10 | 11 | if (!user) { 12 | p = getpwuid(getuid()); 13 | if (p && p->pw_name) { 14 | user = malloc(strlen(p->pw_name)+1); 15 | if (user) 16 | strcpy(user, p->pw_name); 17 | } 18 | } 19 | if(!user) 20 | user = "unknown"; 21 | return user; 22 | } 23 | -------------------------------------------------------------------------------- /lib9/getwd-posix.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #undef getwd 3 | #include 4 | 5 | char * 6 | infgetwd(char *buf, int size) 7 | { 8 | return getcwd(buf, size); 9 | } 10 | -------------------------------------------------------------------------------- /lib9/mkfile-Plan9: -------------------------------------------------------------------------------- 1 | TARGFILES=errstr-Plan9.$O\ 2 | 3 | -------------------------------------------------------------------------------- /lib9/mkfile-Posix: -------------------------------------------------------------------------------- 1 | TARGFILES=\ 2 | $IMPORTFILES\ 3 | dirstat-posix.$O\ 4 | errstr-posix.$O\ 5 | getuser-posix.$O\ 6 | getcallerpc-$SYSTARG-$OBJTYPE.$O\ 7 | getwd-posix.$O\ 8 | sbrk-posix.$O\ 9 | -------------------------------------------------------------------------------- /lib9/nulldir.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | void 4 | nulldir(Dir *d) 5 | { 6 | memset(d, ~0, sizeof(Dir)); 7 | d->name = d->uid = d->gid = d->muid = ""; 8 | } 9 | -------------------------------------------------------------------------------- /lib9/pow10.c: -------------------------------------------------------------------------------- 1 | #ifdef LINUX_386 2 | #define _MATH_H 3 | #endif 4 | 5 | #include "lib9.h" 6 | 7 | /* 8 | * this table might overflow 127-bit exponent representations. 9 | * in that case, truncate it after 1.0e38. 10 | * it is important to get all one can from this 11 | * routine since it is used in atof to scale numbers. 12 | * the presumption is that C converts fp numbers better 13 | * than multipication of lower powers of 10. 14 | */ 15 | 16 | static 17 | double tab[] = 18 | { 19 | 1.0e0, 1.0e1, 1.0e2, 1.0e3, 1.0e4, 1.0e5, 1.0e6, 1.0e7, 1.0e8, 1.0e9, 20 | 1.0e10,1.0e11,1.0e12,1.0e13,1.0e14,1.0e15,1.0e16,1.0e17,1.0e18,1.0e19, 21 | 1.0e20,1.0e21,1.0e22,1.0e23,1.0e24,1.0e25,1.0e26,1.0e27,1.0e28,1.0e29, 22 | 1.0e30,1.0e31,1.0e32,1.0e33,1.0e34,1.0e35,1.0e36,1.0e37,1.0e38,1.0e39, 23 | 1.0e40,1.0e41,1.0e42,1.0e43,1.0e44,1.0e45,1.0e46,1.0e47,1.0e48,1.0e49, 24 | 1.0e50,1.0e51,1.0e52,1.0e53,1.0e54,1.0e55,1.0e56,1.0e57,1.0e58,1.0e59, 25 | 1.0e60,1.0e61,1.0e62,1.0e63,1.0e64,1.0e65,1.0e66,1.0e67,1.0e68,1.0e69, 26 | }; 27 | 28 | double 29 | pow10(int n) 30 | { 31 | int m; 32 | 33 | if(n < 0) { 34 | n = -n; 35 | if(n < sizeof(tab)/sizeof(tab[0])) 36 | return 1/tab[n]; 37 | m = n/2; 38 | return pow10(-m) * pow10(m-n); 39 | } 40 | if(n < sizeof(tab)/sizeof(tab[0])) 41 | return tab[n]; 42 | m = n/2; 43 | return pow10(m) * pow10(n-m); 44 | } 45 | -------------------------------------------------------------------------------- /lib9/print.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | 16 | int 17 | print(char *fmt, ...) 18 | { 19 | int n; 20 | va_list args; 21 | 22 | va_start(args, fmt); 23 | n = vfprint(1, fmt, args); 24 | va_end(args); 25 | return n; 26 | } 27 | -------------------------------------------------------------------------------- /lib9/readn.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | long 4 | readn(int f, void *av, long n) 5 | { 6 | char *a; 7 | long m, t; 8 | 9 | a = av; 10 | t = 0; 11 | while(t < n){ 12 | m = read(f, a+t, n-t); 13 | if(m <= 0){ 14 | if(t == 0) 15 | return m; 16 | break; 17 | } 18 | t += m; 19 | } 20 | return t; 21 | } 22 | -------------------------------------------------------------------------------- /lib9/rerrstr.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | void 4 | rerrstr(char *buf, uint nbuf) 5 | { 6 | char tmp[ERRMAX]; 7 | 8 | tmp[0] = 0; 9 | errstr(tmp, sizeof tmp); 10 | utfecpy(buf, buf+nbuf, tmp); 11 | errstr(tmp, sizeof tmp); 12 | } 13 | -------------------------------------------------------------------------------- /lib9/runeseprint.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | Rune* 4 | runeseprint(Rune *buf, Rune *e, char *fmt, ...) 5 | { 6 | Rune *p; 7 | va_list args; 8 | 9 | va_start(args, fmt); 10 | p = runevseprint(buf, e, fmt, args); 11 | va_end(args); 12 | return p; 13 | } 14 | -------------------------------------------------------------------------------- /lib9/runesmprint.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | Rune* 4 | runesmprint(char *fmt, ...) 5 | { 6 | va_list args; 7 | Rune *p; 8 | 9 | va_start(args, fmt); 10 | p = runevsmprint(fmt, args); 11 | va_end(args); 12 | return p; 13 | } 14 | -------------------------------------------------------------------------------- /lib9/runesnprint.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | int 4 | runesnprint(Rune *buf, int len, char *fmt, ...) 5 | { 6 | int n; 7 | va_list args; 8 | 9 | va_start(args, fmt); 10 | n = runevsnprint(buf, len, fmt, args); 11 | va_end(args); 12 | return n; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /lib9/runestrlen.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | 4 | long 5 | runestrlen(Rune *s) 6 | { 7 | int i; 8 | 9 | i = 0; 10 | while(*s++) 11 | i++; 12 | return i; 13 | } 14 | -------------------------------------------------------------------------------- /lib9/runevseprint.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | Rune* 4 | runevseprint(Rune *buf, Rune *e, char *fmt, va_list args) 5 | { 6 | Fmt f; 7 | 8 | if(e <= buf) 9 | return nil; 10 | f.runes = 1; 11 | f.start = buf; 12 | f.to = buf; 13 | f.stop = e - 1; 14 | f.flush = nil; 15 | f.farg = nil; 16 | f.nfmt = 0; 17 | f.args = args; 18 | dofmt(&f, fmt); 19 | *(Rune*)f.to = '\0'; 20 | return f.to; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /lib9/sbrk-posix.c: -------------------------------------------------------------------------------- 1 | #ifdef __APPLE_CC__ /* look for a better way */ 2 | #include "lib9.h" 3 | #undef _POSIX_C_SOURCE 4 | #undef getwd 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | 27 | #include 28 | 29 | 30 | __typeof__(sbrk(0)) 31 | sbrk(int size) 32 | { 33 | void *brk; 34 | kern_return_t err; 35 | 36 | err = vm_allocate( (vm_map_t) mach_task_self(), 37 | (vm_address_t *)&brk, 38 | size, 39 | VM_FLAGS_ANYWHERE); 40 | if (err != KERN_SUCCESS) 41 | brk = (void*)-1; 42 | 43 | return brk; 44 | } 45 | #else 46 | /* dummy function for everyone else, in case its ar complains about empty files */ 47 | void __fakesbrk(void){} 48 | #endif 49 | -------------------------------------------------------------------------------- /lib9/seek.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | #include 4 | 5 | vlong 6 | seek(int fd, vlong where, int from) 7 | { 8 | return lseek(fd, where, from); 9 | } 10 | -------------------------------------------------------------------------------- /lib9/seprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | 16 | char* 17 | seprint(char *buf, char *e, char *fmt, ...) 18 | { 19 | char *p; 20 | va_list args; 21 | 22 | va_start(args, fmt); 23 | p = vseprint(buf, e, fmt, args); 24 | va_end(args); 25 | return p; 26 | } 27 | -------------------------------------------------------------------------------- /lib9/smprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | 16 | char* 17 | smprint(char *fmt, ...) 18 | { 19 | va_list args; 20 | char *p; 21 | 22 | va_start(args, fmt); 23 | p = vsmprint(fmt, args); 24 | va_end(args); 25 | return p; 26 | } 27 | -------------------------------------------------------------------------------- /lib9/snprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | 16 | int 17 | snprint(char *buf, int len, char *fmt, ...) 18 | { 19 | int n; 20 | va_list args; 21 | 22 | va_start(args, fmt); 23 | n = vsnprint(buf, len, fmt, args); 24 | va_end(args); 25 | return n; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /lib9/sprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | 16 | int 17 | sprint(char *buf, char *fmt, ...) 18 | { 19 | int n; 20 | uint len; 21 | va_list args; 22 | 23 | len = 1<<30; /* big number, but sprint is deprecated anyway */ 24 | /* 25 | * the stack might be near the top of memory, so 26 | * we must be sure not to overflow a 32-bit pointer. 27 | */ 28 | if(buf+len < buf) 29 | len = -(uint)buf-1; 30 | 31 | va_start(args, fmt); 32 | n = vsnprint(buf, len, fmt, args); 33 | va_end(args); 34 | return n; 35 | } 36 | -------------------------------------------------------------------------------- /lib9/strdup.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | char* 4 | strdup(const char *s) 5 | { 6 | char *os; 7 | 8 | os = malloc(strlen(s) + 1); 9 | if(os == 0) 10 | return 0; 11 | return strcpy(os, s); 12 | } 13 | -------------------------------------------------------------------------------- /lib9/strecpy.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | char* 4 | strecpy(char *to, char *e, char *from) 5 | { 6 | if(to >= e) 7 | return to; 8 | to = memccpy(to, from, '\0', e - to); 9 | if(to == nil){ 10 | to = e - 1; 11 | *to = '\0'; 12 | }else{ 13 | to--; 14 | } 15 | return to; 16 | } 17 | -------------------------------------------------------------------------------- /lib9/sysfatal.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | 4 | 5 | static void 6 | _sysfatalimpl(char *fmt, va_list arg) 7 | { 8 | char buf[1024]; 9 | 10 | vseprint(buf, buf+sizeof(buf), fmt, arg); 11 | if(argv0) 12 | fprint(2, "%s: %s\n", argv0, buf); 13 | else 14 | fprint(2, "%s\n", buf); 15 | exits(buf); 16 | } 17 | 18 | void (*_sysfatal)(char *fmt, va_list arg) = _sysfatalimpl; 19 | 20 | void 21 | sysfatal(char *fmt, ...) 22 | { 23 | va_list arg; 24 | 25 | va_start(arg, fmt); 26 | (*_sysfatal)(fmt, arg); 27 | va_end(arg); 28 | } 29 | -------------------------------------------------------------------------------- /lib9/tokenize.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | static char qsep[] = " \t\r\n"; 4 | 5 | static char* 6 | qtoken(char *s) 7 | { 8 | int quoting; 9 | char *t; 10 | 11 | quoting = 0; 12 | t = s; /* s is output string, t is input string */ 13 | while(*t!='\0' && (quoting || utfrune(qsep, *t)==nil)){ 14 | if(*t != '\''){ 15 | *s++ = *t++; 16 | continue; 17 | } 18 | /* *t is a quote */ 19 | if(!quoting){ 20 | quoting = 1; 21 | t++; 22 | continue; 23 | } 24 | /* quoting and we're on a quote */ 25 | if(t[1] != '\''){ 26 | /* end of quoted section; absorb closing quote */ 27 | t++; 28 | quoting = 0; 29 | continue; 30 | } 31 | /* doubled quote; fold one quote into two */ 32 | t++; 33 | *s++ = *t++; 34 | } 35 | if(*s != '\0'){ 36 | *s = '\0'; 37 | if(t == s) 38 | t++; 39 | } 40 | return t; 41 | } 42 | 43 | int 44 | tokenize(char *s, char **args, int maxargs) 45 | { 46 | int nargs; 47 | 48 | for(nargs=0; nargs 2 | static char t16e[] = "0123456789ABCDEF"; 3 | 4 | int 5 | dec16(uchar *out, int lim, char *in, int n) 6 | { 7 | int c, w = 0, i = 0; 8 | uchar *start = out; 9 | uchar *eout = out + lim; 10 | 11 | while(n-- > 0){ 12 | c = *in++; 13 | if('0' <= c && c <= '9') 14 | c = c - '0'; 15 | else if('a' <= c && c <= 'z') 16 | c = c - 'a' + 10; 17 | else if('A' <= c && c <= 'Z') 18 | c = c - 'A' + 10; 19 | else 20 | continue; 21 | w = (w<<4) + c; 22 | i++; 23 | if(i == 2){ 24 | if(out + 1 > eout) 25 | goto exhausted; 26 | *out++ = w; 27 | w = 0; 28 | i = 0; 29 | } 30 | } 31 | exhausted: 32 | return out - start; 33 | } 34 | 35 | int 36 | enc16(char *out, int lim, uchar *in, int n) 37 | { 38 | uint c; 39 | char *eout = out + lim; 40 | char *start = out; 41 | 42 | while(n-- > 0){ 43 | c = *in++; 44 | if(out + 2 >= eout) 45 | goto exhausted; 46 | *out++ = t16e[c>>4]; 47 | *out++ = t16e[c&0xf]; 48 | } 49 | exhausted: 50 | *out = 0; 51 | return out - start; 52 | } 53 | -------------------------------------------------------------------------------- /lib9/utfecpy.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | char* 4 | utfecpy(char *to, char *e, char *from) 5 | { 6 | char *end; 7 | 8 | if(to >= e) 9 | return to; 10 | end = memccpy(to, from, '\0', e - to); 11 | if(end == nil){ 12 | end = e; 13 | while(end>to && (*--end&0xC0)==0x80) 14 | ; 15 | *end = '\0'; 16 | }else{ 17 | end--; 18 | } 19 | return end; 20 | } 21 | -------------------------------------------------------------------------------- /lib9/utflen.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | int 4 | utflen(char *s) 5 | { 6 | int c; 7 | long n; 8 | Rune rune; 9 | 10 | n = 0; 11 | for(;;) { 12 | c = *(uchar*)s; 13 | if(c < Runeself) { 14 | if(c == 0) 15 | return n; 16 | s++; 17 | } else 18 | s += chartorune(&rune, s); 19 | n++; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /lib9/utfnlen.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | int 4 | utfnlen(char *s, long m) 5 | { 6 | int c; 7 | long n; 8 | Rune rune; 9 | char *es; 10 | 11 | es = s + m; 12 | for(n = 0; s < es; n++) { 13 | c = *(uchar*)s; 14 | if(c < Runeself){ 15 | if(c == '\0') 16 | break; 17 | s++; 18 | continue; 19 | } 20 | if(!fullrune(s, es-s)) 21 | break; 22 | s += chartorune(&rune, s); 23 | } 24 | return n; 25 | } 26 | -------------------------------------------------------------------------------- /lib9/utfrrune.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | char* 4 | utfrrune(char *s, long c) 5 | { 6 | long c1; 7 | Rune r; 8 | char *s1; 9 | 10 | if(c < Runesync) /* not part of utf sequence */ 11 | return strrchr(s, c); 12 | 13 | s1 = 0; 14 | for(;;) { 15 | c1 = *(uchar*)s; 16 | if(c1 < Runeself) { /* one byte rune */ 17 | if(c1 == 0) 18 | return s1; 19 | if(c1 == c) 20 | s1 = s; 21 | s++; 22 | continue; 23 | } 24 | c1 = chartorune(&r, s); 25 | if(r == c) 26 | s1 = s; 27 | s += c1; 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /lib9/utfrune.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | 3 | char* 4 | utfrune(char *s, long c) 5 | { 6 | long c1; 7 | Rune r; 8 | int n; 9 | 10 | if(c < Runesync) /* not part of utf sequence */ 11 | return strchr(s, c); 12 | 13 | for(;;) { 14 | c1 = *(uchar*)s; 15 | if(c1 < Runeself) { /* one byte rune */ 16 | if(c1 == 0) 17 | return 0; 18 | if(c1 == c) 19 | return s; 20 | s++; 21 | continue; 22 | } 23 | n = chartorune(&r, s); 24 | if(r == c) 25 | return s; 26 | s += n; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /lib9/vseprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | 16 | char* 17 | vseprint(char *buf, char *e, char *fmt, va_list args) 18 | { 19 | Fmt f; 20 | 21 | if(e <= buf) 22 | return nil; 23 | f.runes = 0; 24 | f.start = buf; 25 | f.to = buf; 26 | f.stop = e - 1; 27 | f.flush = nil; 28 | f.farg = nil; 29 | f.nfmt = 0; 30 | f.args = args; 31 | dofmt(&f, fmt); 32 | *(char*)f.to = '\0'; 33 | return f.to; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /lib9/vsnprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "lib9.h" 15 | 16 | int 17 | vsnprint(char *buf, int len, char *fmt, va_list args) 18 | { 19 | Fmt f; 20 | 21 | if(len <= 0) 22 | return -1; 23 | f.runes = 0; 24 | f.start = buf; 25 | f.to = buf; 26 | f.stop = buf + len - 1; 27 | f.flush = nil; 28 | f.farg = nil; 29 | f.nfmt = 0; 30 | f.args = args; 31 | dofmt(&f, fmt); 32 | *(char*)f.to = '\0'; 33 | return (char*)f.to - buf; 34 | } 35 | -------------------------------------------------------------------------------- /libbio/bbuffered.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | int 5 | Bbuffered(Biobuf *bp) 6 | { 7 | switch(bp->state) { 8 | case Bracteof: 9 | case Bractive: 10 | return -bp->icount; 11 | 12 | case Bwactive: 13 | return bp->bsize + bp->ocount; 14 | 15 | case Binactive: 16 | return 0; 17 | } 18 | fprint(2, "Bbuffered: unknown state %d\n", bp->state); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /libbio/bfildes.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | int 5 | Bfildes(Biobuf *bp) 6 | { 7 | 8 | return bp->fid; 9 | } 10 | -------------------------------------------------------------------------------- /libbio/bflush.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | int 5 | Bflush(Biobuf *bp) 6 | { 7 | int n, c; 8 | 9 | switch(bp->state) { 10 | case Bwactive: 11 | n = bp->bsize+bp->ocount; 12 | if(n == 0) 13 | return 0; 14 | c = write(bp->fid, bp->bbuf, n); 15 | if(n == c) { 16 | bp->offset += n; 17 | bp->ocount = -bp->bsize; 18 | return 0; 19 | } 20 | bp->state = Binactive; 21 | bp->ocount = 0; 22 | break; 23 | 24 | case Bracteof: 25 | bp->state = Bractive; 26 | 27 | case Bractive: 28 | bp->icount = 0; 29 | bp->gbuf = bp->ebuf; 30 | return 0; 31 | } 32 | return Beof; 33 | } 34 | -------------------------------------------------------------------------------- /libbio/bgetc.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | int 5 | Bgetc(Biobuf *bp) 6 | { 7 | int i; 8 | 9 | loop: 10 | i = bp->icount; 11 | if(i != 0) { 12 | bp->icount = i+1; 13 | return bp->ebuf[i]; 14 | } 15 | if(bp->state != Bractive) { 16 | if(bp->state == Bracteof) 17 | bp->state = Bractive; 18 | return Beof; 19 | } 20 | /* 21 | * get next buffer, try to keep Bungetsize 22 | * characters pre-catenated from the previous 23 | * buffer to allow that many ungets. 24 | */ 25 | memmove(bp->bbuf-Bungetsize, bp->ebuf-Bungetsize, Bungetsize); 26 | i = read(bp->fid, bp->bbuf, bp->bsize); 27 | bp->gbuf = bp->bbuf; 28 | if(i <= 0) { 29 | if(i < 0) 30 | bp->state = Binactive; 31 | return Beof; 32 | } 33 | if(i < bp->bsize) { 34 | memmove(bp->ebuf-i-Bungetsize, bp->bbuf-Bungetsize, i+Bungetsize); 35 | bp->gbuf = bp->ebuf-i; 36 | } 37 | bp->icount = -i; 38 | bp->offset += i; 39 | goto loop; 40 | } 41 | 42 | int 43 | Bungetc(Biobuf *bp) 44 | { 45 | 46 | if(bp->state == Bracteof) 47 | bp->state = Bractive; 48 | if(bp->state != Bractive) 49 | return Beof; 50 | bp->icount--; 51 | return 1; 52 | } 53 | -------------------------------------------------------------------------------- /libbio/bgetd.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | struct bgetd 5 | { 6 | Biobuf* b; 7 | int eof; 8 | }; 9 | 10 | static int 11 | Bgetdf(void *vp) 12 | { 13 | int c; 14 | struct bgetd *bg = vp; 15 | 16 | c = Bgetc(bg->b); 17 | if(c == Beof) 18 | bg->eof = 1; 19 | return c; 20 | } 21 | 22 | int 23 | Bgetd(Biobuf *bp, double *dp) 24 | { 25 | double d; 26 | struct bgetd b; 27 | 28 | b.b = bp; 29 | b.eof = 0; 30 | d = charstod(Bgetdf, &b); 31 | if(b.eof) 32 | return -1; 33 | Bungetc(bp); 34 | *dp = d; 35 | return 1; 36 | } 37 | -------------------------------------------------------------------------------- /libbio/bgetrune.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | long 5 | Bgetrune(Biobuf *bp) 6 | { 7 | int c, i; 8 | Rune rune; 9 | char str[4]; 10 | 11 | c = Bgetc(bp); 12 | if(c < Runeself) { /* one char */ 13 | bp->runesize = 1; 14 | return c; 15 | } 16 | str[0] = c; 17 | 18 | for(i=1;;) { 19 | c = Bgetc(bp); 20 | if(c < 0) 21 | return c; 22 | str[i++] = c; 23 | 24 | if(fullrune(str, i)) { 25 | bp->runesize = chartorune(&rune, str); 26 | while(i > bp->runesize) { 27 | Bungetc(bp); 28 | i--; 29 | } 30 | return rune; 31 | } 32 | } 33 | } 34 | 35 | int 36 | Bungetrune(Biobuf *bp) 37 | { 38 | 39 | if(bp->state == Bracteof) 40 | bp->state = Bractive; 41 | if(bp->state != Bractive) 42 | return Beof; 43 | bp->icount -= bp->runesize; 44 | bp->runesize = 0; 45 | return 1; 46 | } 47 | -------------------------------------------------------------------------------- /libbio/boffset.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | long 5 | Boffset(Biobuf *bp) 6 | { 7 | long n; 8 | 9 | switch(bp->state) { 10 | default: 11 | fprint(2, "Boffset: unknown state %d\n", bp->state); 12 | n = Beof; 13 | break; 14 | 15 | case Bracteof: 16 | case Bractive: 17 | n = bp->offset + bp->icount; 18 | break; 19 | 20 | case Bwactive: 21 | n = bp->offset + (bp->bsize + bp->ocount); 22 | break; 23 | } 24 | return n; 25 | } 26 | -------------------------------------------------------------------------------- /libbio/bprint.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | int 5 | Bprint(Biobuf *bp, char *fmt, ...) 6 | { 7 | va_list ap; 8 | char *ip, *ep, *out; 9 | int n; 10 | 11 | ep = (char*)bp->ebuf; 12 | ip = ep + bp->ocount; 13 | va_start(ap, fmt); 14 | out = vseprint(ip, ep, fmt, ap); 15 | va_end(ap); 16 | if(out == nil || out >= ep-5) { 17 | Bflush(bp); 18 | ip = ep + bp->ocount; 19 | va_start(ap, fmt); 20 | out = vseprint(ip, ep, fmt, ap); 21 | va_end(ap); 22 | if(out >= ep-5) 23 | return Beof; 24 | } 25 | n = out-ip; 26 | bp->ocount += n; 27 | return n; 28 | } 29 | -------------------------------------------------------------------------------- /libbio/bputc.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | int 5 | Bputc(Biobuf *bp, int c) 6 | { 7 | int i, j; 8 | 9 | loop: 10 | i = bp->ocount; 11 | j = i+1; 12 | if(i != 0) { 13 | bp->ocount = j; 14 | bp->ebuf[i] = c; 15 | return 0; 16 | } 17 | if(bp->state != Bwactive) 18 | return Beof; 19 | j = write(bp->fid, bp->bbuf, bp->bsize); 20 | if(j == bp->bsize) { 21 | bp->ocount = -bp->bsize; 22 | bp->offset += j; 23 | goto loop; 24 | } 25 | fprint(2, "Bputc: write error\n"); 26 | bp->state = Binactive; 27 | bp->ocount = 0; 28 | return Beof; 29 | } 30 | -------------------------------------------------------------------------------- /libbio/bputrune.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | int 5 | Bputrune(Biobuf *bp, long c) 6 | { 7 | Rune rune; 8 | char str[4]; 9 | int n; 10 | 11 | rune = c; 12 | if(rune < Runeself) { 13 | Bputc(bp, rune); 14 | return 1; 15 | } 16 | n = runetochar(str, &rune); 17 | if(n == 0) 18 | return Bbad; 19 | if(Bwrite(bp, str, n) != n) 20 | return Beof; 21 | return n; 22 | } 23 | -------------------------------------------------------------------------------- /libbio/bread.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | long 5 | Bread(Biobuf *bp, void *ap, long count) 6 | { 7 | long c; 8 | uchar *p; 9 | int i, n, ic; 10 | 11 | p = ap; 12 | c = count; 13 | ic = bp->icount; 14 | 15 | while(c > 0) { 16 | n = -ic; 17 | if(n > c) 18 | n = c; 19 | if(n == 0) { 20 | if(bp->state != Bractive) 21 | break; 22 | i = read(bp->fid, bp->bbuf, bp->bsize); 23 | if(i <= 0) { 24 | bp->state = Bracteof; 25 | if(i < 0) 26 | bp->state = Binactive; 27 | break; 28 | } 29 | bp->gbuf = bp->bbuf; 30 | bp->offset += i; 31 | if(i < bp->bsize) { 32 | memmove(bp->ebuf-i, bp->bbuf, i); 33 | bp->gbuf = bp->ebuf-i; 34 | } 35 | ic = -i; 36 | continue; 37 | } 38 | memmove(p, bp->ebuf+ic, n); 39 | c -= n; 40 | ic += n; 41 | p += n; 42 | } 43 | bp->icount = ic; 44 | if(count == c && bp->state == Binactive) 45 | return -1; 46 | return count-c; 47 | } 48 | -------------------------------------------------------------------------------- /libbio/bseek.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | long 5 | Bseek(Biobuf *bp, long offset, int base) 6 | { 7 | long n, d; 8 | 9 | switch(bp->state) { 10 | default: 11 | fprint(2, "Bseek: unknown state %d\n", bp->state); 12 | return Beof; 13 | 14 | case Bracteof: 15 | bp->state = Bractive; 16 | bp->icount = 0; 17 | bp->gbuf = bp->ebuf; 18 | 19 | case Bractive: 20 | n = offset; 21 | if(base == 1) { 22 | n += Boffset(bp); 23 | base = 0; 24 | } 25 | 26 | /* 27 | * try to seek within buffer 28 | */ 29 | if(base == 0) { 30 | d = n - Boffset(bp); 31 | bp->icount += d; 32 | if(d >= 0) { 33 | if(bp->icount <= 0) 34 | return n; 35 | } else { 36 | if(bp->ebuf - bp->gbuf >= -bp->icount) 37 | return n; 38 | } 39 | } 40 | 41 | /* 42 | * reset the buffer 43 | */ 44 | n = seek(bp->fid, n, base); 45 | bp->icount = 0; 46 | bp->gbuf = bp->ebuf; 47 | break; 48 | 49 | case Bwactive: 50 | Bflush(bp); 51 | n = seek(bp->fid, offset, base); 52 | break; 53 | } 54 | bp->offset = n; 55 | return n; 56 | } 57 | -------------------------------------------------------------------------------- /libbio/bvprint.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | static int 5 | fmtBflush(Fmt *f) 6 | { 7 | Biobuf *bp; 8 | 9 | bp = f->farg; 10 | bp->ocount = (char*)f->to - (char*)f->stop; 11 | if(Bflush(bp) < 0) 12 | return 0; 13 | f->stop = bp->ebuf; 14 | f->to = (char*)f->stop + bp->ocount; 15 | f->start = f->to; 16 | return 1; 17 | } 18 | 19 | int 20 | Bvprint(Biobuf *bp, char *fmt, va_list arg) 21 | { 22 | int n; 23 | Fmt f; 24 | 25 | f.runes = 0; 26 | f.stop = bp->ebuf; 27 | f.start = (char*)f.stop + bp->ocount; 28 | f.to = f.start; 29 | f.flush = fmtBflush; 30 | f.farg = bp; 31 | f.nfmt = 0; 32 | f.args = arg; 33 | n = dofmt(&f, fmt); 34 | bp->ocount = (char*)f.to - (char*)f.stop; 35 | return n; 36 | } 37 | -------------------------------------------------------------------------------- /libbio/bwrite.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include 3 | 4 | long 5 | Bwrite(Biobuf *bp, void *ap, long count) 6 | { 7 | long c; 8 | uchar *p; 9 | int i, n, oc; 10 | 11 | p = ap; 12 | c = count; 13 | oc = bp->ocount; 14 | 15 | while(c > 0) { 16 | n = -oc; 17 | if(n > c) 18 | n = c; 19 | if(n == 0) { 20 | if(bp->state != Bwactive) 21 | return Beof; 22 | i = write(bp->fid, bp->bbuf, bp->bsize); 23 | if(i != bp->bsize) { 24 | bp->state = Binactive; 25 | return Beof; 26 | } 27 | bp->offset += i; 28 | oc = -bp->bsize; 29 | continue; 30 | } 31 | memmove(bp->ebuf+oc, p, n); 32 | oc += n; 33 | c -= n; 34 | p += n; 35 | } 36 | bp->ocount = oc; 37 | return count-c; 38 | } 39 | -------------------------------------------------------------------------------- /libbio/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | LIB=libbio.a 5 | OFILES=\ 6 | bbuffered.$O\ 7 | bfildes.$O\ 8 | bflush.$O\ 9 | bgetrune.$O\ 10 | bgetc.$O\ 11 | bgetd.$O\ 12 | binit.$O\ 13 | boffset.$O\ 14 | bprint.$O\ 15 | bvprint.$O\ 16 | bputrune.$O\ 17 | bputc.$O\ 18 | brdline.$O\ 19 | bread.$O\ 20 | bseek.$O\ 21 | bwrite.$O\ 22 | 23 | HFILES= $ROOT/include/bio.h 24 | 25 | <$ROOT/mkfiles/mksyslib-$SHELLTYPE 26 | -------------------------------------------------------------------------------- /liblex/allprint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern Biobuf* yyout; 6 | 7 | int 8 | printable(int c) 9 | { 10 | return 040 < c && c < 0177; 11 | } 12 | 13 | void 14 | allprint(char c) 15 | { 16 | 17 | switch(c) { 18 | case '\n': 19 | fprintf(yyout,"\\n"); 20 | break; 21 | case '\t': 22 | fprintf(yyout,"\\t"); 23 | break; 24 | case '\b': 25 | fprintf(yyout,"\\b"); 26 | break; 27 | case ' ': 28 | fprintf(yyout,"\\\bb"); 29 | break; 30 | default: 31 | if(!printable(c)) 32 | fprintf(yyout,"\\%-3o",c); 33 | else 34 | c = putc(c,yyout); 35 | USED(c); 36 | break; 37 | } 38 | return; 39 | } 40 | -------------------------------------------------------------------------------- /liblex/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int yylex(void); 6 | 7 | void 8 | main(int argc, char *argv[]) 9 | { 10 | USED(argc); 11 | yylex(); 12 | exits(0); 13 | } 14 | -------------------------------------------------------------------------------- /liblex/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | LIB=libl.a 5 | 6 | OFILES=\ 7 | allprint.$O\ 8 | main.$O\ 9 | reject.$O\ 10 | yyless.$O\ 11 | yywrap.$O\ 12 | 13 | HFILES=\ 14 | $ROOT/$SYSTARG/$OBJTYPE/include/lib9.h\ 15 | $ROOT/include/bio.h\ 16 | 17 | <$ROOT/mkfiles/mksyslib-$SHELLTYPE 18 | -------------------------------------------------------------------------------- /liblex/reject.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern Biobuf* yyout; 6 | extern Biobuf* yyin; 7 | extern int yyprevious, *yyfnd; 8 | extern char yyextra[]; 9 | extern char yytext[]; 10 | extern int yyleng; 11 | 12 | extern 13 | struct 14 | { 15 | int *yyaa, *yybb; 16 | int *yystops; 17 | } *yylstate [], **yylsp, **yyolsp; 18 | 19 | int yyback(int *p, int m); 20 | int yyinput(void); 21 | void yyoutput(int c); 22 | void yyunput(int c); 23 | 24 | int 25 | yyracc(int m) 26 | { 27 | 28 | yyolsp = yylsp; 29 | if(yyextra[m]) { 30 | while(yyback((*yylsp)->yystops, -m) != 1 && yylsp > yylstate) { 31 | yylsp--; 32 | yyunput(yytext[--yyleng]); 33 | } 34 | } 35 | yyprevious = yytext[yyleng-1]; 36 | yytext[yyleng] = 0; 37 | return m; 38 | } 39 | 40 | int 41 | yyreject(void) 42 | { 43 | for(; yylsp < yyolsp; yylsp++) 44 | yytext[yyleng++] = yyinput(); 45 | if(*yyfnd > 0) 46 | return yyracc(*yyfnd++); 47 | while(yylsp-- > yylstate) { 48 | yyunput(yytext[yyleng-1]); 49 | yytext[--yyleng] = 0; 50 | if(*yylsp != 0 && (yyfnd = (*yylsp)->yystops) && *yyfnd > 0) 51 | return yyracc(*yyfnd++); 52 | } 53 | if(yytext[0] == 0) 54 | return 0; 55 | yyoutput(yyprevious = yyinput()); 56 | yyleng = 0; 57 | return -1; 58 | } 59 | -------------------------------------------------------------------------------- /liblex/yyless.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern char yytext[]; 6 | extern int yyleng; 7 | extern int yyprevious; 8 | 9 | void yyunput(int c); 10 | 11 | void 12 | yyless(int x) 13 | { 14 | char *lastch, *ptr; 15 | 16 | lastch = yytext+yyleng; 17 | if(x>=0 && x <= yyleng) 18 | ptr = x + yytext; 19 | else 20 | ptr = (char*)x; 21 | while(lastch > ptr) 22 | yyunput(*--lastch); 23 | *lastch = 0; 24 | if (ptr >yytext) 25 | yyprevious = lastch[-1]; 26 | yyleng = ptr-yytext; 27 | } 28 | -------------------------------------------------------------------------------- /liblex/yywrap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int 6 | yywrap(void) 7 | { 8 | return 1; 9 | } 10 | -------------------------------------------------------------------------------- /libmach/ar.h: -------------------------------------------------------------------------------- 1 | #define ARMAG "!\n" 2 | #define SARMAG 8 3 | 4 | #define ARFMAG "`\n" 5 | #define SARNAME 16 6 | 7 | struct ar_hdr 8 | { 9 | char name[SARNAME]; 10 | char date[12]; 11 | char uid[6]; 12 | char gid[6]; 13 | char mode[8]; 14 | char size[10]; 15 | char fmag[2]; 16 | }; 17 | #define SAR_HDR 60 18 | 19 | -------------------------------------------------------------------------------- /libmach/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | LIB=libmach.a 5 | OFILES=\ 6 | 5.$O\ 7 | 6.$O\ 8 | 8.$O\ 9 | 5db.$O\ 10 | 8db.$O\ 11 | 5obj.$O\ 12 | 6obj.$O\ 13 | 8obj.$O\ 14 | obj.$O\ 15 | map.$O\ 16 | swap.$O\ 17 | sym.$O\ 18 | access.$O\ 19 | machdata.$O\ 20 | setmach.$O\ 21 | executable.$O\ 22 | 23 | HFILES=\ 24 | $ROOT/include/mach.h\ 25 | $ROOT/include/a.out.h\ 26 | bootexec.h\ 27 | elf.h\ 28 | ureg5.h\ 29 | ureg6.h\ 30 | ureg8.h\ 31 | 32 | <$ROOT/mkfiles/mksyslib-$SHELLTYPE 33 | CFLAGS= $CFLAGS -I.. 34 | -------------------------------------------------------------------------------- /libmach/obj.h: -------------------------------------------------------------------------------- 1 | /* 2 | * obj.h -- defs for dealing with object files 3 | */ 4 | 5 | typedef enum Kind /* variable defs and references in obj */ 6 | { 7 | aNone, /* we don't care about this prog */ 8 | aName, /* introduces a name */ 9 | aText, /* starts a function */ 10 | aData, /* references to a global object */ 11 | } Kind; 12 | 13 | typedef struct Prog Prog; 14 | 15 | struct Prog /* info from .$O files */ 16 | { 17 | Kind kind; /* what kind of symbol */ 18 | char type; /* type of the symbol: ie, 'T', 'a', etc. */ 19 | char sym; /* index of symbol's name */ 20 | char *id; /* name for the symbol, if it introduces one */ 21 | }; 22 | 23 | #define UNKNOWN '?' 24 | void _offset(int, long); 25 | -------------------------------------------------------------------------------- /libmach/swap.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | * big-endian short 5 | */ 6 | ushort 7 | beswab(ushort s) 8 | { 9 | uchar *p; 10 | 11 | p = (uchar*)&s; 12 | return (p[0]<<8) | p[1]; 13 | } 14 | 15 | /* 16 | * big-endian long 17 | */ 18 | long 19 | beswal(long l) 20 | { 21 | uchar *p; 22 | 23 | p = (uchar*)&l; 24 | return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]; 25 | } 26 | 27 | /* 28 | * big-endian vlong 29 | */ 30 | vlong 31 | beswav(vlong v) 32 | { 33 | uchar *p; 34 | 35 | p = (uchar*)&v; 36 | return ((vlong)p[0]<<56) | ((vlong)p[1]<<48) | ((vlong)p[2]<<40) 37 | | ((vlong)p[3]<<32) | ((vlong)p[4]<<24) 38 | | ((vlong)p[5]<<16) | ((vlong)p[6]<<8) 39 | | (vlong)p[7]; 40 | } 41 | 42 | /* 43 | * little-endian short 44 | */ 45 | ushort 46 | leswab(ushort s) 47 | { 48 | uchar *p; 49 | 50 | p = (uchar*)&s; 51 | return (p[1]<<8) | p[0]; 52 | } 53 | 54 | /* 55 | * little-endian long 56 | */ 57 | long 58 | leswal(long l) 59 | { 60 | uchar *p; 61 | 62 | p = (uchar*)&l; 63 | return (p[3]<<24) | (p[2]<<16) | (p[1]<<8) | p[0]; 64 | } 65 | 66 | /* 67 | * little-endian vlong 68 | */ 69 | vlong 70 | leswav(vlong v) 71 | { 72 | uchar *p; 73 | 74 | p = (uchar*)&v; 75 | return ((vlong)p[7]<<56) | ((vlong)p[6]<<48) | ((vlong)p[5]<<40) 76 | | ((vlong)p[4]<<32) | ((vlong)p[3]<<24) 77 | | ((vlong)p[2]<<16) | ((vlong)p[1]<<8) 78 | | (vlong)p[0]; 79 | } 80 | -------------------------------------------------------------------------------- /libmach/ureg5.h: -------------------------------------------------------------------------------- 1 | struct Ureg { 2 | uint r0; 3 | uint r1; 4 | uint r2; 5 | uint r3; 6 | uint r4; 7 | uint r5; 8 | uint r6; 9 | uint r7; 10 | uint r8; 11 | uint r9; 12 | uint r10; 13 | uint r11; 14 | uint r12; 15 | uint r13; 16 | uint r14; 17 | uint link; 18 | uint type; 19 | uint psr; 20 | uint pc; 21 | }; 22 | -------------------------------------------------------------------------------- /libmach/ureg6.h: -------------------------------------------------------------------------------- 1 | struct Ureg 2 | { 3 | uvlong r15; /* general registers */ 4 | uvlong r14; 5 | uvlong r13; 6 | uvlong r12; 7 | uvlong r11; 8 | uvlong r10; 9 | uvlong r9; 10 | uvlong r8; 11 | uvlong di; 12 | uvlong si; /* ... */ 13 | uvlong bp; /* ... */ 14 | uvlong nsp; 15 | uvlong bx; /* ... */ 16 | uvlong dx; /* ... */ 17 | uvlong cx; /* ... */ 18 | uvlong ax; /* ... */ 19 | uvlong gs; /* data segments */ 20 | uvlong fs; /* ... */ 21 | uvlong es; /* ... */ 22 | uvlong ds; /* ... */ 23 | uvlong trap; /* trap type */ 24 | uvlong ecode; /* error code (or zero) */ 25 | uvlong pc; /* pc */ 26 | uvlong cs; /* old context */ 27 | uvlong flags; /* old flags */ 28 | uvlong sp; 29 | uvlong ss; /* old stack segment */ 30 | }; 31 | -------------------------------------------------------------------------------- /libmach/ureg8.h: -------------------------------------------------------------------------------- 1 | struct Ureg 2 | { 3 | ulong di; /* general registers */ 4 | ulong si; /* ... */ 5 | ulong bp; /* ... */ 6 | ulong nsp; 7 | ulong bx; /* ... */ 8 | ulong dx; /* ... */ 9 | ulong cx; /* ... */ 10 | ulong ax; /* ... */ 11 | ulong gs; /* data segments */ 12 | ulong fs; /* ... */ 13 | ulong es; /* ... */ 14 | ulong ds; /* ... */ 15 | ulong trap; /* trap type */ 16 | ulong ecode; /* error code (or zero) */ 17 | ulong pc; /* pc */ 18 | ulong cs; /* old context */ 19 | ulong flags; /* old flags */ 20 | union { 21 | ulong usp; 22 | ulong sp; 23 | } u0; 24 | ulong ss; /* old stack segment */ 25 | }; 26 | -------------------------------------------------------------------------------- /libmath/bin/unif_dtoa: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | test -d /netlib/fp || 9fs netlib 3 | test -d /n/hati/usr/ehg || 9fs hati 4 | 5 | echo '/* derived from /netlib/fp/dtoa.c assuming IEEE, Standard C */' > dtoa.c 6 | echo '/* kudos to dmg@research.att.com, gripes to ehg@research.att.com */' >> dtoa.c 7 | echo '#include "lib9.h"' >> dtoa.c 8 | 9 | sed 's/^#if defined.IEEE_8087. . defined.IEEE_MC68k.*!= 1/#ifndef IEEE_Arith/ 10 | s/^#if defined.IEEE_8087. . defined.IEEE_MC68k.*/#ifdef IEEE_Arith/' \ 11 | /netlib/fp/dtoa.c > /n/hati/usr/ehg/xxx.c 12 | # undefine __STDC__ because we can't depend on HUGE_VAL 13 | rx hati 'unifdef -UIBM -UVAX -UKR_headers -U__cplusplus -U__STDC__ -UDEBUG \ 14 | -UBad_float_h -UJust_16 -UInaccurate_Divide -UROUND_BIASED \ 15 | -URND_PRODQUOT -DNo_leftright -UCheck_FLT_ROUNDS -D__MATH_H__ \ 16 | -DUnsigned_Shifts -DMALLOC=Malloc -DCONST=const \ 17 | -DPack_32 -DIEEE_Arith xxx.c | cb -s' > xxx.c 18 | sam -d >> dtoa.c >[2] err <> dtoa.c 37 | rm xxx.c 38 | -------------------------------------------------------------------------------- /libmath/bin/unif_fdlibm: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | test -d /netlib/fdlibm || 9fs netlib 3 | test -d /n/hati/usr/ehg || 9fs hati 4 | 5 | echo '/* derived from /netlib/fdlibm */' > $1 6 | if (~ $1 fdlibm.h) echo '#include "lib9.h"' >> $1 7 | 8 | cp /netlib/fdlibm/$1 /n/hati/usr/ehg/xxx.c 9 | rx hati 'unifdef -D__STDC__ -D_IEEE_LIBM -D_SCALB_INT -U__NEWVALID xxx.c' > xxx.c 10 | > /n/hati/usr/ehg/xxx.c 11 | sam -d >> $1 >[2] err <> $1 20 | rm xxx.c 21 | -------------------------------------------------------------------------------- /libmath/blas.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include "mathi.h" 3 | 4 | double 5 | dot(int n, double *x, double *y) 6 | { 7 | double sum = 0; 8 | if (n <= 0) 9 | return 0; 10 | while (n--) { 11 | sum += *x++ * *y++; 12 | } 13 | return sum; 14 | } 15 | 16 | 17 | int 18 | iamax(int n, double *x) 19 | { 20 | int i, m; 21 | double xm, a; 22 | if (n <= 0) 23 | return 0; 24 | m = 0; 25 | xm = fabs(*x); 26 | for (i = 1; i < n; i++) { 27 | a = fabs(*++x); 28 | if (xm < a) { 29 | m = i; 30 | xm = a; 31 | } 32 | } 33 | return m; 34 | } 35 | 36 | 37 | double 38 | norm1(int n, double *x) 39 | { 40 | double sum = 0; 41 | if (n <= 0) 42 | return 0; 43 | while (n--) { 44 | sum += fabs(*x); 45 | x++; 46 | } 47 | return sum; 48 | } 49 | 50 | 51 | double 52 | norm2(int n, double *x) 53 | { 54 | double sum = 0; 55 | if (n <= 0) 56 | return 0; 57 | while (n--) { 58 | sum += *x * *x; 59 | x++; 60 | } 61 | return sum; 62 | } 63 | -------------------------------------------------------------------------------- /libmath/fdim.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include "mathi.h" 3 | 4 | double 5 | fdim(double x, double y) 6 | { 7 | if(x>y) 8 | return x-y; 9 | else 10 | return 0; 11 | } 12 | 13 | double 14 | fmax(double x, double y) 15 | { 16 | if(x>y) 17 | return x; 18 | else 19 | return y; 20 | } 21 | 22 | double 23 | fmin(double x, double y) 24 | { 25 | if(x>31; 27 | } 28 | -------------------------------------------------------------------------------- /libmath/fdlibm/s_ilogb.c: -------------------------------------------------------------------------------- 1 | /* derived from /netlib/fdlibm */ 2 | 3 | /* @(#)s_ilogb.c 1.3 95/01/18 */ 4 | /* 5 | * ==================================================== 6 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 7 | * 8 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 9 | * Permission to use, copy, modify, and distribute this 10 | * software is freely granted, provided that this notice 11 | * is preserved. 12 | * ==================================================== 13 | */ 14 | 15 | /* ilogb(double x) 16 | * return the binary exponent of non-zero x 17 | * ilogb(0) = 0x80000001 18 | * ilogb(inf/NaN) = 0x7fffffff (no signal is raised) 19 | */ 20 | 21 | #include "fdlibm.h" 22 | 23 | int ilogb(double x) 24 | { 25 | int hx,lx,ix; 26 | 27 | hx = (__HI(x))&0x7fffffff; /* high word of x */ 28 | if(hx<0x00100000) { 29 | lx = __LO(x); 30 | if((hx|lx)==0) 31 | return 0x80000001; /* ilogb(0) = 0x80000001 */ 32 | else /* subnormal x */ 33 | if(hx==0) { 34 | for (ix = -1043; lx>0; lx<<=1) ix -=1; 35 | } else { 36 | for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1; 37 | } 38 | return ix; 39 | } 40 | else if (hx<0x7ff00000) return (hx>>20)-1023; 41 | else return 0x7fffffff; 42 | } 43 | -------------------------------------------------------------------------------- /libmath/fdlibm/s_isnan.c: -------------------------------------------------------------------------------- 1 | /* derived from /netlib/fdlibm */ 2 | 3 | /* @(#)s_isnan.c 1.3 95/01/18 */ 4 | /* 5 | * ==================================================== 6 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 7 | * 8 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 9 | * Permission to use, copy, modify, and distribute this 10 | * software is freely granted, provided that this notice 11 | * is preserved. 12 | * ==================================================== 13 | */ 14 | 15 | /* 16 | * isnan(x) returns 1 is x is nan, else 0; 17 | * no branching! 18 | */ 19 | 20 | #include "fdlibm.h" 21 | 22 | int isnan(double x) 23 | { 24 | int hx,lx; 25 | hx = (__HI(x)&0x7fffffff); 26 | lx = __LO(x); 27 | hx |= (unsigned)(lx|(-lx))>>31; 28 | hx = 0x7ff00000 - hx; 29 | return ((unsigned)(hx))>>31; 30 | } 31 | -------------------------------------------------------------------------------- /libmath/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARGTYPE=${SYSTARG:os%=Inferno%} # maps 'os' into 'Inferno' 5 | 6 | LIB=libmath.a 7 | OFILES=\ 8 | blas.$O\ 9 | dtoa.$O\ 10 | fdim.$O\ 11 | FPcontrol-$TARGTYPE.$O\ 12 | gemm.$O\ 13 | g_fmt.$O\ 14 | gfltconv.$O\ 15 | pow10.$O\ 16 | e_acos.$O\ 17 | e_acosh.$O\ 18 | e_asin.$O\ 19 | e_atan2.$O\ 20 | e_atanh.$O\ 21 | e_cosh.$O\ 22 | e_exp.$O\ 23 | e_fmod.$O\ 24 | e_hypot.$O\ 25 | e_j0.$O\ 26 | e_j1.$O\ 27 | e_jn.$O\ 28 | e_lgamma_r.$O\ 29 | e_log.$O\ 30 | e_log10.$O\ 31 | e_pow.$O\ 32 | e_rem_pio2.$O\ 33 | e_remainder.$O\ 34 | e_sinh.$O\ 35 | e_sqrt.$O\ 36 | k_cos.$O\ 37 | k_rem_pio2.$O\ 38 | k_sin.$O\ 39 | k_tan.$O\ 40 | s_asinh.$O\ 41 | s_atan.$O\ 42 | s_cbrt.$O\ 43 | s_ceil.$O\ 44 | s_copysign.$O\ 45 | s_cos.$O\ 46 | s_erf.$O\ 47 | s_expm1.$O\ 48 | s_fabs.$O\ 49 | s_finite.$O\ 50 | s_floor.$O\ 51 | s_ilogb.$O\ 52 | s_isnan.$O\ 53 | s_log1p.$O\ 54 | s_nextafter.$O\ 55 | s_rint.$O\ 56 | s_scalbn.$O\ 57 | s_sin.$O\ 58 | s_tan.$O\ 59 | s_tanh.$O\ 60 | 61 | HFILES=\ 62 | $ROOT/include/mathi.h\ 63 | fdlibm/fdlibm.h\ 64 | 65 | <$ROOT/mkfiles/mksyslib-$SHELLTYPE 66 | 67 | %.$O: fdlibm/%.c 68 | $CC $CFLAGS -o $target -Ifdlibm fdlibm/$stem.c 69 | -------------------------------------------------------------------------------- /libmath/pow10.c: -------------------------------------------------------------------------------- 1 | #include "lib9.h" 2 | #include "mathi.h" 3 | 4 | double 5 | ipow10(int n) 6 | { 7 | return pow(10.,n); 8 | } 9 | -------------------------------------------------------------------------------- /libregexp/mk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cc -c -m32 -g -O -I$ROOT/Linux/386/include -I$ROOT/include -DLINUX_386 regcomp.c 3 | cc -c -m32 -g -O -I$ROOT/Linux/386/include -I$ROOT/include -DLINUX_386 regerror.c 4 | cc -c -m32 -g -O -I$ROOT/Linux/386/include -I$ROOT/include -DLINUX_386 regexec.c 5 | cc -c -m32 -g -O -I$ROOT/Linux/386/include -I$ROOT/include -DLINUX_386 regsub.c 6 | cc -c -m32 -g -O -I$ROOT/Linux/386/include -I$ROOT/include -DLINUX_386 regaux.c 7 | cc -c -m32 -g -O -I$ROOT/Linux/386/include -I$ROOT/include -DLINUX_386 rregexec.c 8 | cc -c -m32 -g -O -I$ROOT/Linux/386/include -I$ROOT/include -DLINUX_386 rregsub.c 9 | ar ruvs $ROOT/Linux/386/lib/libregexp.a regcomp.o regerror.o regexec.o regsub.o regaux.o rregexec.o rregsub.o 10 | -------------------------------------------------------------------------------- /libregexp/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | #XXX 5 | <$ROOT/mkfiles/mkhost-$SYSHOST # variables appropriate for host system 6 | <$ROOT/mkfiles/mkfile-$SYSTARG-$OBJTYPE # variables used to build target object type 7 | 8 | LIB=libregexp.a 9 | 10 | OFILES=\ 11 | regcomp.$O\ 12 | regerror.$O\ 13 | regexec.$O\ 14 | regsub.$O\ 15 | regaux.$O\ 16 | rregexec.$O\ 17 | rregsub.$O\ 18 | 19 | HFILES= $ROOT/include/regexp.h\ 20 | regcomp.h\ 21 | 22 | <$ROOT/mkfiles/mksyslib-$SHELLTYPE 23 | -------------------------------------------------------------------------------- /libregexp/regerror.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "regexp.h" 3 | 4 | void 5 | regerror(char *s) 6 | { 7 | char buf[132]; 8 | 9 | strcpy(buf, "regerror: "); 10 | strcat(buf, s); 11 | strcat(buf, "\n"); 12 | write(2, buf, strlen(buf)); 13 | exits("regerr"); 14 | } 15 | -------------------------------------------------------------------------------- /libregexp/regsub.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "regexp.h" 3 | 4 | /* substitute into one string using the matches from the last regexec() */ 5 | extern void 6 | regsub(char *sp, /* source string */ 7 | char *dp, /* destination string */ 8 | Resub *mp, /* subexpression elements */ 9 | int ms) /* number of elements pointed to by mp */ 10 | { 11 | char *ssp; 12 | int i; 13 | 14 | while(*sp != '\0'){ 15 | if(*sp == '\\'){ 16 | switch(*++sp){ 17 | case '0': 18 | case '1': 19 | case '2': 20 | case '3': 21 | case '4': 22 | case '5': 23 | case '6': 24 | case '7': 25 | case '8': 26 | case '9': 27 | i = *sp-'0'; 28 | if(mp[i].s.sp != 0 && mp!=0 && ms>i) 29 | for(ssp = mp[i].s.sp; 30 | ssp < mp[i].e.ep; 31 | ssp++) 32 | *dp++ = *ssp; 33 | break; 34 | case '\\': 35 | *dp++ = '\\'; 36 | break; 37 | case '\0': 38 | sp--; 39 | break; 40 | default: 41 | *dp++ = *sp; 42 | break; 43 | } 44 | }else if(*sp == '&'){ 45 | if(mp[0].s.sp != 0 && mp!=0 && ms>0) 46 | if(mp[0].s.sp != 0) 47 | for(ssp = mp[0].s.sp; 48 | ssp < mp[0].e.ep; ssp++) 49 | *dp++ = *ssp; 50 | }else 51 | *dp++ = *sp; 52 | sp++; 53 | } 54 | *dp = '\0'; 55 | } 56 | -------------------------------------------------------------------------------- /libregexp/rregsub.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "regexp.h" 3 | 4 | /* substitute into one string using the matches from the last regexec() */ 5 | extern void 6 | rregsub(Rune *sp, /* source string */ 7 | Rune *dp, /* destination string */ 8 | Resub *mp, /* subexpression elements */ 9 | int ms) /* number of elements pointed to by mp */ 10 | { 11 | Rune *ssp; 12 | int i; 13 | 14 | while(*sp != '\0'){ 15 | if(*sp == '\\'){ 16 | switch(*++sp){ 17 | case '0': 18 | case '1': 19 | case '2': 20 | case '3': 21 | case '4': 22 | case '5': 23 | case '6': 24 | case '7': 25 | case '8': 26 | case '9': 27 | i = *sp-'0'; 28 | if(mp[i].s.rsp != 0 && mp!=0 && ms>i) 29 | for(ssp = mp[i].s.rsp; 30 | ssp < mp[i].e.rep; 31 | ssp++) 32 | *dp++ = *ssp; 33 | break; 34 | case '\\': 35 | *dp++ = '\\'; 36 | break; 37 | case '\0': 38 | sp--; 39 | break; 40 | default: 41 | *dp++ = *sp; 42 | break; 43 | } 44 | }else if(*sp == '&'){ 45 | if(mp[0].s.rsp != 0 && mp!=0 && ms>0) 46 | if(mp[0].s.rsp != 0) 47 | for(ssp = mp[0].s.rsp; 48 | ssp < mp[0].e.rep; ssp++) 49 | *dp++ = *ssp; 50 | }else 51 | *dp++ = *sp; 52 | sp++; 53 | } 54 | *dp = '\0'; 55 | } 56 | -------------------------------------------------------------------------------- /mk/README: -------------------------------------------------------------------------------- 1 | Using the delivered mk to rebuild mk. 2 | 3 | You should be able to use the delivered executable of mk to 4 | build a new executable. This may be of particular interest 5 | on Windows NT/Win95 where the path of the shell program 6 | can be hard-coded by changing the variable named "shell" 7 | near the beginning of source file Nt.c. 8 | 9 | Mk uses the regular expression library, so build 10 | the program as follows: 11 | 12 | 1. ensure that ../../mkconfig contains the proper system definitions 13 | 14 | 2. ensure that the system libraries lib9, libbio, and libregexp have 15 | been built. you can do this by hand by changing to ../lib9, 16 | ../libbio, and ../libregexp and doing "mk nuke" and a "mk install" 17 | in each. 18 | 19 | 3. in this directory 20 | mk nuke 21 | mk install 22 | 23 | 4. on NT/Win95 the executable must be installed by hand because the current 24 | executable is locked down while it is executing: 25 | 26 | mv obj.out ../../Nt/386/bin/mk.exe 27 | -------------------------------------------------------------------------------- /mk/arc.c: -------------------------------------------------------------------------------- 1 | #include "mk.h" 2 | 3 | Arc * 4 | newarc(Node *n, Rule *r, char *stem, Resub *match) 5 | { 6 | Arc *a; 7 | 8 | a = (Arc *)Malloc(sizeof(Arc)); 9 | a->n = n; 10 | a->r = r; 11 | a->stem = strdup(stem); 12 | rcopy(a->match, match, NREGEXP); 13 | a->next = 0; 14 | a->flag = 0; 15 | a->prog = r->prog; 16 | return(a); 17 | } 18 | 19 | void 20 | dumpa(char *s, Arc *a) 21 | { 22 | char buf[1024]; 23 | 24 | Bprint(&bout, "%sArc@%p: n=%p r=%p flag=0x%x stem='%s'", 25 | s, a, a->n, a->r, a->flag, a->stem); 26 | if(a->prog) 27 | Bprint(&bout, " prog='%s'", a->prog); 28 | Bprint(&bout, "\n"); 29 | 30 | if(a->n){ 31 | snprint(buf, sizeof(buf), "%s ", (*s == ' ')? s:""); 32 | dumpn(buf, a->n); 33 | } 34 | } 35 | 36 | void 37 | nrep(void) 38 | { 39 | Symtab *sym; 40 | Word *w; 41 | 42 | sym = symlook("NREP", S_VAR, 0); 43 | if(sym){ 44 | w = (Word *) sym->value; 45 | if (w && w->s && *w->s) 46 | nreps = atoi(w->s); 47 | } 48 | if(nreps < 1) 49 | nreps = 1; 50 | if(DEBUG(D_GRAPH)) 51 | Bprint(&bout, "nreps = %d\n", nreps); 52 | } 53 | -------------------------------------------------------------------------------- /mk/job.c: -------------------------------------------------------------------------------- 1 | #include "mk.h" 2 | 3 | Job * 4 | newjob(Rule *r, Node *nlist, char *stem, char **match, Word *pre, Word *npre, Word *tar, Word *atar) 5 | { 6 | register Job *j; 7 | 8 | j = (Job *)Malloc(sizeof(Job)); 9 | j->r = r; 10 | j->n = nlist; 11 | j->stem = stem; 12 | j->match = match; 13 | j->p = pre; 14 | j->np = npre; 15 | j->t = tar; 16 | j->at = atar; 17 | j->nproc = -1; 18 | j->next = 0; 19 | return(j); 20 | } 21 | 22 | void 23 | dumpj(char *s, Job *j, int all) 24 | { 25 | Bprint(&bout, "%s\n", s); 26 | while(j){ 27 | Bprint(&bout, "job@%ld: r=%ld n=%ld stem='%s' nproc=%d\n", 28 | j, j->r, j->n, j->stem, j->nproc); 29 | Bprint(&bout, "\ttarget='%s' alltarget='%s' prereq='%s' nprereq='%s'\n", 30 | wtos(j->t, ' '), wtos(j->at, ' '), wtos(j->p, ' '), wtos(j->np, ' ')); 31 | j = all? j->next : 0; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mk/match.c: -------------------------------------------------------------------------------- 1 | #include "mk.h" 2 | 3 | int 4 | match(char *name, char *template, char *stem) 5 | { 6 | Rune r; 7 | int n; 8 | 9 | while(*name && *template){ 10 | n = chartorune(&r, template); 11 | if (PERCENT(r)) 12 | break; 13 | while (n--) 14 | if(*name++ != *template++) 15 | return 0; 16 | } 17 | if(!PERCENT(*template)) 18 | return 0; 19 | n = strlen(name)-strlen(template+1); 20 | if (n < 0) 21 | return 0; 22 | if (strcmp(template+1, name+n)) 23 | return 0; 24 | strncpy(stem, name, n); 25 | stem[n] = 0; 26 | if(*template == '&') 27 | return !shell->charin(stem, "./"); 28 | return 1; 29 | } 30 | 31 | void 32 | subst(char *stem, char *template, char *dest) 33 | { 34 | Rune r; 35 | char *s; 36 | int n; 37 | 38 | while(*template){ 39 | n = chartorune(&r, template); 40 | if (PERCENT(r)) { 41 | template += n; 42 | for (s = stem; *s; s++) 43 | *dest++ = *s; 44 | } else 45 | while (n--) 46 | *dest++ = *template++; 47 | } 48 | *dest = 0; 49 | } 50 | -------------------------------------------------------------------------------- /mk/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=mk 5 | 6 | OFILES= arc.$O\ 7 | archive.$O\ 8 | bufblock.$O\ 9 | env.$O\ 10 | file.$O\ 11 | graph.$O\ 12 | job.$O\ 13 | lex.$O\ 14 | main.$O\ 15 | match.$O\ 16 | mk.$O\ 17 | parse.$O\ 18 | $TARGMODEL.$O\ 19 | recipe.$O\ 20 | rule.$O\ 21 | run.$O\ 22 | rc.$O\ 23 | sh.$O\ 24 | shprint.$O\ 25 | symtab.$O\ 26 | var.$O\ 27 | varsub.$O\ 28 | word.$O\ 29 | #old: there was $TARGSHTYPE.$O instead of rc.$O and sh.$O but 30 | # I now support both 31 | 32 | 33 | HFILES= fns.h\ 34 | ${ROOT}/libmach/ar.h\ 35 | mk.h\ 36 | 37 | LIBS= regexp bio 9 38 | 39 | BIN=$ROOT/$OBJDIR/bin 40 | 41 | <$ROOT/mkfiles/mkone-$SHELLTYPE 42 | 43 | 44 | value = value; 7 | symlook(name, S_MAKEVAR, (void*)""); 8 | } 9 | 10 | static void 11 | print1(Symtab *s) 12 | { 13 | Word *w; 14 | 15 | Bprint(&bout, "\t%s=", s->name); 16 | for (w = (Word *) s->value; w; w = w->next) 17 | Bprint(&bout, "'%s'", w->s); 18 | Bprint(&bout, "\n"); 19 | } 20 | 21 | void 22 | dumpv(char *s) 23 | { 24 | Bprint(&bout, "%s:\n", s); 25 | symtraverse(S_VAR, print1); 26 | } 27 | 28 | char * 29 | shname(char *a) 30 | { 31 | Rune r; 32 | int n; 33 | 34 | while (*a) { 35 | n = chartorune(&r, a); 36 | if (!WORDCHR(r)) 37 | break; 38 | a += n; 39 | } 40 | return a; 41 | } 42 | -------------------------------------------------------------------------------- /mkconfig: -------------------------------------------------------------------------------- 1 | # -*- makefile -*- 2 | # 3 | # Set the following 4 variables. The host system is the system where 4 | # the software will be built; the target system is where it will run. 5 | # They are almost always the same. 6 | 7 | ROOT=/Users/me/Projects/plan9/cross/fork-kencc 8 | 9 | # build system OS type 10 | SYSHOST=MacOSX 11 | 12 | # target system OS type 13 | SYSTARG=MacOSX 14 | 15 | # target system object type 16 | OBJTYPE=386 17 | 18 | # 19 | # no changes required beyond this point 20 | # 21 | OBJDIR=$SYSTARG/$OBJTYPE 22 | 23 | <$ROOT/mkfiles/mkhost-$SYSHOST # variables appropriate for host system 24 | <$ROOT/mkfiles/mkfile-$SYSTARG-$OBJTYPE # variables used to build target object type 25 | 26 | -------------------------------------------------------------------------------- /mkfiles/mkfile-Cygwin-386: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | TARGMODEL= Posix 3 | TARGSHTYPE= sh 4 | CPUS= 386 arm 5 | 6 | O= o 7 | OS= o 8 | 9 | AR= ar 10 | ARFLAGS= ruvs 11 | 12 | AS= cc -c -m32 13 | ASFLAGS= 14 | 15 | CC= cc -c -m32 16 | CFLAGS= -g\ 17 | -O\ 18 | -I$ROOT/Cygwin/386/include\ 19 | -I$ROOT/include\ 20 | -DCYGWIN 21 | 22 | ANSICPP= 23 | LD= cc -m32 24 | LDFLAGS= 25 | 26 | SYSLIBS= 27 | 28 | YACC= iyacc 29 | YFLAGS= -d 30 | -------------------------------------------------------------------------------- /mkfiles/mkfile-Linux-386: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | TARGMODEL= Posix 3 | TARGSHTYPE= sh 4 | CPUS= 386 arm 5 | 6 | O= o 7 | OS= o 8 | 9 | AR= ar 10 | ARFLAGS= ruvs 11 | 12 | AS= cc -c -m32 13 | ASFLAGS= 14 | 15 | CC= cc -c -m32 16 | CFLAGS= -g\ 17 | -O\ 18 | -I$ROOT/Linux/386/include\ 19 | -I$ROOT/include\ 20 | -DLINUX_386 21 | 22 | ANSICPP= 23 | LD= cc -m32 24 | LDFLAGS= 25 | 26 | SYSLIBS= 27 | 28 | YACC= iyacc 29 | YFLAGS= -d 30 | -------------------------------------------------------------------------------- /mkfiles/mkfile-MacOSX-386: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | TARGMODEL= Posix 3 | TARGSHTYPE= sh 4 | CPUS= 386 arm 5 | 6 | O= o 7 | OS= o 8 | 9 | AR= ar 10 | ARFLAGS= ruvs 11 | A= a 12 | 13 | AS= cc -c -arch i386 14 | ASFLAGS= 15 | 16 | ISYSROOT= 17 | 18 | CC= cc -c 19 | COPTFLAGS= -Os 20 | CDEBUGFLAGS= 21 | CTHREADFLAGS= 22 | CFLAGS= -arch i386\ 23 | -Wno-deprecated-declarations -Wuninitialized -Wunused -Wreturn-type -Wimplicit -Wno-four-char-constants -Wno-unknown-pragmas\ 24 | -pipe\ 25 | -fno-strict-aliasing\ 26 | -no-cpp-precomp\ 27 | -I$ROOT/MacOSX/386/include\ 28 | -I$ROOT/include\ 29 | $COPTFLAGS $CDEBUGFLAGS\ 30 | 31 | # -mno-fused-madd\ 32 | 33 | 34 | LD= cc -arch i386 35 | LDFLAGS=\ 36 | -multiply_defined suppress 37 | # -static, but not supported apparently on macos 38 | 39 | SYSLIBS= 40 | 41 | YACC= iyacc 42 | YFLAGS= -d 43 | -------------------------------------------------------------------------------- /mkfiles/mkfile-Plan9-386: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | TARGMODEL= Plan9 3 | TARGSHTYPE= rc 4 | CPUS= 386 sparc mips power amd64 5 | 6 | O= 8 7 | OS= v851ok0q2t6 8 | 9 | AR= ar 10 | ARFLAGS= vu 11 | 12 | AS= 8a 13 | ASFLAGS= 14 | 15 | CC= 8c 16 | CFLAGS= -wFVT -I$ROOT/Plan9/386/include -I$ROOT/include 17 | ANSICPP= -p 18 | 19 | LD= 8l 20 | LDFLAGS= 21 | 22 | SYSLIBS=-lc 23 | 24 | YACC= yacc 25 | YFLAGS= -d 26 | -------------------------------------------------------------------------------- /mkfiles/mkhost-Cygwin: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | 3 | # Variables for host system type = Linux 4 | 5 | SHELLTYPE= sh 6 | SHELLNAME= /bin/sh 7 | HOSTMODEL= Posix 8 | OSTARG= os 9 | 10 | DATA2S= data2s 11 | KSIZE= ksize 12 | AWK= awk 13 | -------------------------------------------------------------------------------- /mkfiles/mkhost-Linux: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | 3 | # Variables for host system type = Linux 4 | 5 | SHELLTYPE= sh 6 | SHELLNAME= /bin/sh 7 | HOSTMODEL= Posix 8 | OSTARG= os 9 | 10 | DATA2S= data2s 11 | KSIZE= ksize 12 | AWK= awk 13 | -------------------------------------------------------------------------------- /mkfiles/mkhost-MacOSX: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | # 3 | # Supports all Darwin based systems (Darwin, Mac OS X, Mac OS X Server) 4 | # Variables for host system type = Darwin 5 | # 6 | 7 | SHELLTYPE= sh 8 | SHELLNAME= /bin/sh 9 | HOSTMODEL= Posix 10 | OSTARG= os 11 | 12 | DATA2S= data2s 13 | KSIZE= ksize 14 | AWK= awk 15 | CP= cp 16 | ECHO= echo 17 | FALSE= false 18 | MKDIR= mkdir -p 19 | RM= rm -f 20 | RMDIR= rmdir 21 | TRUE= true 22 | 23 | JAVAC= /usr/bin/javac 24 | MACOSINF=caseinsensitive # nobble .S rules 25 | -------------------------------------------------------------------------------- /mkfiles/mkhost-Plan9: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | 3 | # Variables for host system type = Plan9 4 | 5 | SHELLTYPE= rc 6 | SHELLNAME= rc 7 | HOSTMODEL= Plan9 8 | OSTARG= Inferno 9 | 10 | DATA2S= data2s 11 | KSIZE= size 12 | AWK= awk 13 | -------------------------------------------------------------------------------- /mkfiles/mklibsubdirs: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | all:V: all-$SHELLTYPE 3 | install:V: install-$SHELLTYPE 4 | uninstall:V: uninstall-$SHELLTYPE 5 | nuke:V: nuke-$SHELLTYPE 6 | clean:V: clean-$SHELLTYPE 7 | 8 | %-rc %-nt:QV: 9 | for (j in $DIRS) 10 | { 11 | { 12 | test -d $j && { 13 | echo '@{builtin cd' $j ';' mk $MKFLAGS 'SYSTARG='$SYSTARG 'OBJTYPE='$OBJTYPE $stem'}' 14 | @{builtin cd $j; mk $MKFLAGS 'SYSTARG='$SYSTARG 'OBJTYPE='$OBJTYPE $stem} 15 | } 16 | } || test ! -e $j 17 | } 18 | 19 | %-sh:QV: 20 | for j in $DIRS 21 | do 22 | if test -d $j; then 23 | echo "(cd $j; mk $MKFLAGS SYSTARG=$SYSTARG OBJTYPE=$OBJTYPE $stem)" 24 | (cd $j; mk $MKFLAGS 'SYSTARG='$SYSTARG 'OBJTYPE='$OBJTYPE $stem) || exit 1 25 | fi || test ! -e $j 26 | done 27 | -------------------------------------------------------------------------------- /mkfiles/mkone-rc: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | libs=${LIBS:%=$ROOT/$OBJDIR/lib/lib%.a} 3 | 4 | all:V: $O.out 5 | 6 | install:V: $BIN/$TARG 7 | 8 | safeinstall: $O.out 9 | mv $BIN/$TARG $BIN/$TARG.`{date -n} 10 | cp $O.out $BIN/$TARG 11 | 12 | installall:V: 13 | for(objtype in $CPUS) 14 | mk $MKFLAGS install 15 | 16 | nuke:V: nuke-std 17 | 18 | clean:V: clean-std 19 | 20 | $O.out: $OFILES $libs 21 | $LD $LDFLAGS $OFILES $libs $SYSLIBS 22 | 23 | %.$O: $HFILES # don't combine with following %.$O rules 24 | 25 | %.$O: %.c 26 | $CC $CFLAGS $stem.c 27 | 28 | %.$O: %.s 29 | $AS $ASFLAGS $stem.s 30 | 31 | y.tab.h y.tab.c: $YFILES 32 | $YACC $YFLAGS $YFILES 33 | 34 | nuke-std:V: clean-std 35 | rm -f y.tab.? y.debug y.output 36 | 37 | clean-std:V: 38 | rm -f *.[$OS] [$OS].out 39 | 40 | $BIN/%: $O.out 41 | rm -f $BIN/$stem && cp $O.out $BIN/$stem 42 | -------------------------------------------------------------------------------- /mkfiles/mkone-sh: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | libs=${LIBS:%=$ROOT/$OBJDIR/lib/lib%.a} 3 | 4 | all:V: $O.out 5 | 6 | install:V: $BIN/$TARG 7 | 8 | installall:V: 9 | for objtype in $CPUS 10 | do 11 | mk $MKFLAGS install 12 | done 13 | 14 | nuke:V: nuke-std 15 | 16 | clean:V: clean-std 17 | 18 | $O.out: $OFILES $libs 19 | $LD $LDFLAGS -o $target $OFILES $libs $SYSLIBS 20 | 21 | %.$O: $HFILES # don't combine with following %.$O rules 22 | 23 | %.$O: %.c 24 | $CC $CFLAGS -o $target $stem.c 25 | 26 | %.$O: %.s 27 | $AS $ASFLAGS -o $target $stem.s 28 | 29 | %.$O: %.S$MACOSINF 30 | $AS $ASFLAGS -o $target $stem.S 31 | 32 | y.tab.h y.tab.c: $YFILES 33 | $YACC $YFLAGS $YFILES 34 | 35 | clean-std:V: 36 | rm -f core [$OS].out 37 | rm -f `echo $OS | sed 's/./ *.&/g'` 38 | 39 | nuke-std:V: clean-std 40 | rm -f y.tab.? y.debug y.output 41 | 42 | $BIN/%: $O.out 43 | rm -f $BIN/$stem && cp $O.out $BIN/$stem 44 | -------------------------------------------------------------------------------- /mkfiles/mksubdirs: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | all:V: all-$SHELLTYPE 3 | install:V: install-$SHELLTYPE 4 | uninstall:V: uninstall-$SHELLTYPE 5 | nuke:V: nuke-$SHELLTYPE 6 | clean:V: clean-$SHELLTYPE 7 | 8 | %-rc %-nt:QV: 9 | for (j in $DIRS) 10 | { 11 | { 12 | test -d $j && { 13 | echo '@{builtin cd' $j '; mk $MKFLAGS $stem}' 14 | @{builtin cd $j; mk $MKFLAGS $stem} 15 | } 16 | } || test ! -e $j 17 | } 18 | 19 | %-sh:QV: 20 | for j in $DIRS 21 | do 22 | if test -d $j; then 23 | echo "(cd $j; mk $MKFLAGS $stem)" 24 | (cd $j; mk $MKFLAGS $stem) || exit 1 25 | fi || test ! -e $j 26 | done 27 | -------------------------------------------------------------------------------- /mkfiles/mksyslib-rc: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | # 3 | # Rules for updating a library with rc 4 | # 5 | LIBDIR=$ROOT/$OBJDIR/lib 6 | LIBRARY=$LIBDIR/$LIB 7 | LIBOBJ=${OFILES:%=$LIBRARY(%)} 8 | 9 | default:V: all 10 | 11 | all install:V: $LIBRARY 12 | 13 | installall:V: 14 | for(objtype in $CPUS) 15 | mk $MKFLAGS install 16 | 17 | clean:V: clean-std 18 | 19 | nuke:V: nuke-std 20 | 21 | $LIBRARY: $LIBOBJ 22 | $AR $ARFLAGS $target $newmember 23 | 24 | $LIBRARY(%.$O):N: %.$O 25 | 26 | %.$O: $HFILES # don't combine with following %.$O rules 27 | 28 | %.$O: %.c 29 | $CC $CFLAGS $stem.c 30 | 31 | %.$O: %.s 32 | $AS $ASFLAGS $stem.s 33 | 34 | y.tab.h y.tab.c: $YFILES 35 | $YACC $YFLAGS $prereq 36 | 37 | clean-std:V: 38 | rm -f *.[$OS] [$OS].out 39 | 40 | nuke-std:V: clean-std 41 | rm -f y.tab.? y.output y.error 42 | rm -f $LIBRARY 43 | -------------------------------------------------------------------------------- /mkfiles/mksyslib-sh: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | # 3 | # Rules for updating a library with sh 4 | # 5 | LIBDIR=$ROOT/$OBJDIR/lib 6 | LIBRARY=$LIBDIR/$LIB 7 | LIBOBJ=${OFILES:%=$LIBRARY(%)} 8 | 9 | default:V: all 10 | 11 | all install:V: $LIBRARY 12 | 13 | installall:V: 14 | for objtype in $CPUS 15 | do 16 | mk $MKFLAGS install 17 | done 18 | 19 | clean:V: clean-std 20 | 21 | nuke:V: nuke-std 22 | 23 | $LIBRARY: $LIBOBJ 24 | $AR $ARFLAGS $target $newmember 25 | 26 | $LIBRARY(%.$O):N: %.$O 27 | 28 | %.$O: $HFILES # don't combine with following %.$O rules 29 | 30 | %.$O: %.c 31 | $CC $CFLAGS $stem.c 32 | 33 | %.$O: %.s 34 | $AS $ASFLAGS $stem.s 35 | 36 | #pad: under cygwin this rule adds an ambiguity for mk. 37 | # It should not, because only one non-vacuous node should remain 38 | # but maybe because under cygwin the filesystem is case insensitive? 39 | #%.$O: %.S$MACOSINF 40 | # $AS $ASFLAGS -o $target $stem.S 41 | 42 | y.tab.h y.tab.c: $YFILES 43 | $YACC $YFLAGS $prereq 44 | 45 | clean-std:V: 46 | rm -f $O.out 47 | rm -f y.tab.? y.output y.error 48 | rm -f `echo $OS | sed 's/./ *.&/g'` 49 | 50 | nuke-std:V: clean-std 51 | rm -f y.tab.? y.output y.error 52 | rm -f $LIBRARY 53 | -------------------------------------------------------------------------------- /modif-orig.txt: -------------------------------------------------------------------------------- 1 | original: https://code.google.com/p/ken-cc/ 2 | 3 | Now at https://bitbucket.org/plan9-from-bell-labs/9-cc/ 4 | but this latest version is worst. Indeed, it does not even compile under 5 | Linux and some files are actually missing from the repository. 6 | The repository https://github.com/JehanneOS/devtools-kencc 7 | fixed some mistakes, but I don't think it's a good starting point. 8 | Indeed, those repositories do not incorporate the latest patches 9 | to 5c that enable to compile Raspberry programs. 10 | 11 | partial list of modifications: 12 | - got rid of old hosts (NetBSD, Irix, etc), except 13 | Linux/386, Macos/386, and Plan9 14 | - got rid of old targets, except 386 (8) and arm (5) 15 | - moved src/* and src/cmd/* at the toplevel 16 | - compiled and commited a correct version of MacOSX/386/bin/iyacc 17 | - updated the Rune type to 'unsigned int' so kencc can compile plan9 programs 18 | using L"..." 19 | - fixed Linux/386/include/lib9.h to comply with recent Linux distributions. 20 | - created Linux/386/lib/.keep and MacOSX/386/lib/.keep, etc. so 21 | 'ar' can correctly create libraries 22 | - added the Cygwin host (mostly a copy of Linux) 23 | -------------------------------------------------------------------------------- /pcc/Posix.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void* 6 | mysbrk(ulong size) 7 | { 8 | return (void*)sbrk(size); 9 | } 10 | 11 | int 12 | mycreat(char *n, int p) 13 | { 14 | 15 | return create(n, 1, p); 16 | } 17 | 18 | int 19 | mywait(int *s) 20 | { 21 | return wait(s); 22 | } 23 | 24 | int 25 | mydup(int f1, int f2) 26 | { 27 | return dup2(f1,f2); 28 | } 29 | 30 | int 31 | mypipe(int *fd) 32 | { 33 | return pipe(fd); 34 | } 35 | 36 | char* 37 | mygetwd(char *path, int len) 38 | { 39 | return (char*)getcwd(path, len); 40 | } 41 | 42 | int 43 | myexec(char *path, char *argv[]) 44 | { 45 | return execvp(path, argv); 46 | } 47 | 48 | 49 | int 50 | myfork(void) 51 | { 52 | return fork(); 53 | } 54 | 55 | int 56 | myaccess(char *f) 57 | { 58 | return access(f, 0); 59 | } 60 | -------------------------------------------------------------------------------- /pcc/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=pcc 5 | 6 | OFILES= \ 7 | $TARGMODEL.$O\ 8 | pcc.$O\ 9 | 10 | 11 | LIBS= 9 12 | 13 | BIN=$ROOT/$OBJDIR/bin 14 | 15 | <$ROOT/mkfiles/mkone-$SHELLTYPE 16 | 17 | -------------------------------------------------------------------------------- /qa/branch: -------------------------------------------------------------------------------- 1 | BO operand encodings 2 | 3 | 0+y 0000y decrement CTR, then branch if CTR != 0 && condition is false 4 | 2+y 0001y decrement CTR, then branch if CTR == 0 && condition is false 5 | 4+y 0010y branch if condition is false 6 | 8+y 0100y decrement CTR, then branch if CTR != 0 && condition is true 7 | 10+y 0101y decrement CTR, then branch if CTR == 0 && condition is true 8 | 12+y 0110y branch if condition is true 9 | 16+y 1000y decrement CTR, then branch if CTR != 0 10 | 18+y 1001y decrement CTR, then branch if CTR == 0 11 | 20 10100 branch always 12 | 13 | y=0: 14 | BCx with negative displacement: branch probably taken 15 | all other cases: branch not taken 16 | 17 | y=1: 18 | reverse prediction 19 | 20 | predict to be taken if 21 | ((BO[0] & BO[2]) | sign(displacement)) xor y 22 | 23 | CR field bit: 24 | 25 | lt 0 26 | gt 1 27 | eq 2 28 | so 3 29 | un 3 (after fp comparison) 30 | 31 | CR fields: 32 | 33 | cr0 0 34 | cr1 4 35 | cr2 8 36 | ... 37 | cr7 28 38 | -------------------------------------------------------------------------------- /qa/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | TARG=qa 4 | OFILES=\ 5 | y.tab.$O\ 6 | lex.$O\ 7 | 8 | HFILES=\ 9 | ../qc/q.out.h\ 10 | y.tab.h\ 11 | a.h\ 12 | 13 | YFILES=a.y\ 14 | 15 | LIBS=cc bio 9 # order is important 16 | 17 | BIN=$ROOT/$OBJDIR/bin 18 | 19 | <$ROOT/mkfiles/mkone-$SHELLTYPE 20 | 21 | YFLAGS=-D1 -d 22 | 23 | lex.$O: ../cc/macbody ../cc/lexbody 24 | 25 | $ROOT/$OBJDIR/lib/libcc.a: 26 | cd ../cc 27 | mk $MKFLAGS install 28 | mk $MKFLAGS clean 29 | -------------------------------------------------------------------------------- /qc/mkenam: -------------------------------------------------------------------------------- 1 | ed - ../qc/q.out.h <<'!' 2 | v/^ A/d 3 | g/^ AEND/s//&,/ 4 | g/^ ALAST/s//&,/ 5 | g/[ ]*=.*,/s//,/ 6 | v/,/p 7 | ,s/^ A/ "/ 8 | ,s/,.*$/",/ 9 | 1i 10 | char *anames[] = 11 | { 12 | . 13 | ,a 14 | }; 15 | . 16 | w enam.c 17 | Q 18 | ! 19 | -------------------------------------------------------------------------------- /qc/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | TARG=qc 4 | OFILES=\ 5 | cgen.$O\ 6 | enam.$O\ 7 | list.$O\ 8 | machcap.$O\ 9 | mul.$O\ 10 | peep.$O\ 11 | pgen.$O\ 12 | pswt.$O\ 13 | reg.$O\ 14 | sgen.$O\ 15 | swt.$O\ 16 | txt.$O\ 17 | 18 | HFILES=\ 19 | gc.h\ 20 | q.out.h\ 21 | ../cc/cc.h\ 22 | 23 | LIBS=cc bio 9 # order is important 24 | 25 | BIN=$ROOT/$OBJDIR/bin 26 | 27 | <$ROOT/mkfiles/mkone-$SHELLTYPE 28 | 29 | $ROOT/$OBJDIR/lib/libcc.a: 30 | cd ../cc 31 | mk $MKFLAGS install 32 | mk $MKFLAGS clean 33 | 34 | %.$O: ../cc/%.c 35 | $CC -I. $CFLAGS ../cc/$stem.c 36 | 37 | #enam.c: q.out.h 38 | # rc mkenam 39 | -------------------------------------------------------------------------------- /ql/cnam.c: -------------------------------------------------------------------------------- 1 | char *cnames[] = 2 | { 3 | "NONE", 4 | "REG", 5 | "FREG", 6 | "CREG", 7 | "SPR", 8 | "SREG", 9 | "ZCON", 10 | "SCON", 11 | "UCON", 12 | "ADDCON", 13 | "ANDCON", 14 | "LCON", 15 | "SACON", 16 | "SECON", 17 | "LACON", 18 | "LECON", 19 | "SBRA", 20 | "LBRA", 21 | "SAUTO", 22 | "LAUTO", 23 | "SEXT", 24 | "LEXT", 25 | "ZOREG", 26 | "SOREG", 27 | "LOREG", 28 | "FPSCR", 29 | "MSR", 30 | "XER", 31 | "LR", 32 | "CTR", 33 | "ANY", 34 | "GOK", 35 | "ADDR", 36 | "NCLASS", 37 | }; 38 | -------------------------------------------------------------------------------- /ql/mkcname: -------------------------------------------------------------------------------- 1 | ed - ../ql/l.h <<'!' 2 | v/^ C_/d 3 | g/^ C_NCLASS/s//&,/ 4 | g/[ ]*=.*,/s//,/ 5 | v/,/p 6 | ,s/^ C_/ "/ 7 | ,s/,.*$/",/ 8 | 1i 9 | char *cnames[] = 10 | { 11 | . 12 | ,a 13 | }; 14 | . 15 | w cnam.c 16 | Q 17 | ! 18 | -------------------------------------------------------------------------------- /ql/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | TARG=ql 4 | 5 | OFILES=\ 6 | asm.$O\ 7 | asmout.$O\ 8 | list.$O\ 9 | noop.$O\ 10 | obj.$O\ 11 | optab.$O\ 12 | pass.$O\ 13 | span.$O\ 14 | enam.$O\ 15 | cnam.$O\ 16 | sched.$O\ 17 | $TARGMODEL.$O\ 18 | elf.$O\ 19 | 20 | HFILES=\ 21 | l.h\ 22 | ../qc/q.out.h\ 23 | ${ROOT}/include/ar.h\ 24 | 25 | LIBS=bio 9 # order is important 26 | 27 | BIN=$ROOT/$OBJDIR/bin 28 | 29 | <$ROOT/mkfiles/mkone-$SHELLTYPE 30 | 31 | CFLAGS= $CFLAGS -I. 32 | 33 | enam.$O: ../qc/enam.c 34 | $CC $CFLAGS ../qc/enam.c 35 | 36 | elf.$O: ../ld/elf.c 37 | $CC $CFLAGS ../ld/elf.c 38 | #cnam.c: l.h 39 | # rc mkcname 40 | 41 | $TARGMODEL.$O: ../ld/$TARGMODEL.c 42 | $CC $CFLAGS ../ld/$TARGMODEL.c 43 | -------------------------------------------------------------------------------- /rc/Posix.c: -------------------------------------------------------------------------------- 1 | unix.c -------------------------------------------------------------------------------- /rc/getflags.h: -------------------------------------------------------------------------------- 1 | #define NFLAG 128 2 | 3 | extern char **flag[NFLAG]; 4 | extern char *cmdname; 5 | extern char *flagset[]; 6 | 7 | int getflags(int, char*[], char*, int); 8 | -------------------------------------------------------------------------------- /rc/io.h: -------------------------------------------------------------------------------- 1 | #define EOF (-1) 2 | #define NBUF 512 3 | 4 | struct io{ 5 | int fd; 6 | uchar *bufp, *ebuf, *strp; 7 | uchar buf[NBUF]; 8 | }; 9 | io *err; 10 | 11 | io *openfd(int), *openstr(void), *opencore(char *, int); 12 | int emptybuf(io*); 13 | void pchr(io*, int); 14 | int rchr(io*); 15 | int rutf(io*, char*, Rune*); 16 | void closeio(io*); 17 | void flush(io*); 18 | int fullbuf(io*, int); 19 | void pdec(io*, int); 20 | void poct(io*, unsigned); 21 | void pptr(io*, void*); 22 | void pquo(io*, char*); 23 | void pwrd(io*, char*); 24 | void pstr(io*, char*); 25 | void pcmd(io*, tree*); 26 | void pval(io*, word*); 27 | void pfnc(io*, thread*); 28 | void pfmt(io*, char*, ...); 29 | -------------------------------------------------------------------------------- /rc/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=rc 5 | 6 | OFILES= \ 7 | code.$O\ 8 | exec.$O\ 9 | getflags.$O\ 10 | glob.$O\ 11 | here.$O\ 12 | io.$O\ 13 | lex.$O\ 14 | pcmd.$O\ 15 | pfnc.$O\ 16 | simple.$O\ 17 | subr.$O\ 18 | trap.$O\ 19 | tree.$O\ 20 | var.$O\ 21 | y.tab.$O\ 22 | havefork.$O\ 23 | $TARGMODEL.$O\ 24 | 25 | # haventfork.$O\ 26 | 27 | HFILES= rc.h y.tab.h 28 | 29 | YFILES= syn.y 30 | 31 | LIBS=9 32 | 33 | BIN=$ROOT/$OBJDIR/bin 34 | 35 | <$ROOT/mkfiles/mkone-$SHELLTYPE 36 | 37 | CFLAGS= $CFLAGS '-DROOT="'$ROOT'"' -DUnix 38 | 39 | install:V: $ROOT/lib/rcmain 40 | -------------------------------------------------------------------------------- /rc/pad.txt: -------------------------------------------------------------------------------- 1 | Porting rc to kencc was surprisingly difficult. I tried many things: 2 | - I adapted the rcsh/ included in kencc, but it was a stripped-down version 3 | that was working only for Windows. I thought I could extend 4 | it to work also under Linux but it did not work out. 5 | Imitating Nt.c in a Posix.c led to some progress but ultimately 6 | pipes were not working. 7 | - I copied rc/ from the latest plan9 which had a unix.c, but 8 | havefork.c was not compiling originally under kencc. I tried 9 | to use haventfork.c and fix it, but again pipes in the end were not working 10 | - I finally used havefork.c, but it was needing libstring/ 11 | which was not in kencc. I tried to provide a stripped-down libstring 12 | but it pulled too many dependencies (locking, utf8) 13 | - I finally copy-pasted some code from plan9port regarding the import 14 | of PATH and the management of Xbackq which did not require libstring 15 | -------------------------------------------------------------------------------- /rc/trap.c: -------------------------------------------------------------------------------- 1 | #include "rc.h" 2 | #include "exec.h" 3 | #include "fns.h" 4 | #include "io.h" 5 | extern char *Signame[]; 6 | 7 | void 8 | dotrap(void) 9 | { 10 | int i; 11 | struct var *trapreq; 12 | struct word *starval; 13 | starval = vlook("*")->val; 14 | while(ntrap) for(i = 0;i!=NSIG;i++) while(trap[i]){ 15 | --trap[i]; 16 | --ntrap; 17 | if(getpid()!=mypid) Exit(getstatus()); 18 | trapreq = vlook(Signame[i]); 19 | if(trapreq->fn){ 20 | start(trapreq->fn, trapreq->pc, (struct var *)0); 21 | runq->local = newvar(strdup("*"), runq->local); 22 | runq->local->val = copywords(starval, (struct word *)0); 23 | runq->local->changed = 1; 24 | runq->redir = runq->startredir = 0; 25 | } 26 | else if(i==SIGINT || i==SIGQUIT){ 27 | /* 28 | * run the stack down until we uncover the 29 | * command reading loop. Xreturn will exit 30 | * if there is none (i.e. if this is not 31 | * an interactive rc.) 32 | */ 33 | while(!runq->iflag) Xreturn(); 34 | } 35 | else Exit(getstatus()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /rc/unix.h: -------------------------------------------------------------------------------- 1 | #undef _BSD_EXTENSION /* avoid multiple def'n if predefined */ 2 | #undef _PLAN9_SOURCE 3 | #undef _POSIX_SOURCE 4 | #undef _RESEARCH_SOURCE 5 | #undef _SUSV2_SOURCE 6 | 7 | #define _BSD_EXTENSION 8 | #define _PLAN9_SOURCE 9 | #define _POSIX_SOURCE 10 | #define _RESEARCH_SOURCE 11 | #define _SUSV2_SOURCE 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #ifndef NSIG 22 | #define NSIG 32 23 | #endif 24 | 25 | /* plan 9 compatibility */ 26 | #define RFPROC 1 27 | #define RFFDG 1 28 | #define RFNOTEG 1 29 | 30 | #define uintptr uintptr_t 31 | 32 | char *strdup(const char *); 33 | 34 | #define nil ((void*)0) 35 | 36 | /* in case uchar, etc. are built-in types */ 37 | #define uchar _fmtuchar 38 | #define ushort _fmtushort 39 | #define uint _fmtuint 40 | #define ulong _fmtulong 41 | #define vlong _fmtvlong 42 | #define uvlong _fmtuvlong 43 | 44 | typedef unsigned char uchar; 45 | typedef unsigned short ushort; 46 | typedef unsigned int uint; 47 | typedef unsigned long ulong; 48 | typedef unsigned long long uvlong; 49 | 50 | //#define OREAD O_RDONLY 51 | //#define OWRITE O_WRONLY 52 | //#define ORDWR O_RDWR 53 | //#define OCEXEC 0 54 | -------------------------------------------------------------------------------- /rc/y.tab.h: -------------------------------------------------------------------------------- 1 | #define FOR 57346 2 | #define IN 57347 3 | #define WHILE 57348 4 | #define IF 57349 5 | #define NOT 57350 6 | #define TWIDDLE 57351 7 | #define BANG 57352 8 | #define SUBSHELL 57353 9 | #define SWITCH 57354 10 | #define FN 57355 11 | #define WORD 57356 12 | #define REDIR 57357 13 | #define DUP 57358 14 | #define PIPE 57359 15 | #define SUB 57360 16 | #define SIMPLE 57361 17 | #define ARGLIST 57362 18 | #define WORDS 57363 19 | #define BRACE 57364 20 | #define PAREN 57365 21 | #define PCMD 57366 22 | #define PIPEFD 57367 23 | #define ANDAND 57368 24 | #define OROR 57369 25 | #define COUNT 57370 26 | 27 | typedef union { 28 | struct tree *tree; 29 | } YYSTYPE; 30 | extern YYSTYPE yylval; 31 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | Kencc is a highly portable C compiler suite, including supporting tools, 2 | originally developed for Plan 9 from Bell Labs and later also used for 3 | Inferno. It was originally developed by Ken Thompson, hence the name 4 | kencc. 5 | 6 | It targets x86 and ARM (the original kencc has more targets, but 7 | this fork supports only x86 and ARM). 8 | 9 | It is small and fast. It includes a stripped-down preprocessor. 10 | 11 | Because all components are written portably, it is easy to use as a 12 | cross-compiler (on Plan 9 itself, a cross-compiler is made simply by 13 | compiling a target compiler with the host compiler; there are no extra 14 | configuration files) 15 | 16 | The suite is pleasant to port, partly because the distribution of 17 | effort across the components is unusual. 18 | 19 | The source code of the compiler suite is included in both Plan 9 and 20 | Inferno distributions, but this provides an independent source that 21 | might be used by other projects. 22 | 23 | The project contains the source of the assemblers, compilers and 24 | loaders; supporting commands such as ar, nm, size etc.; the Acid 25 | debugger; supporting libraries; and the portable build environment, 26 | including mk. 27 | 28 | The only requirement to compile kencc is to have a working C compiler 29 | and C standard library (e.g., gcc and the GNU libc). 30 | -------------------------------------------------------------------------------- /skip_list.txt: -------------------------------------------------------------------------------- 1 | # -*- sh -*- 2 | 3 | #dir: lib9 4 | #dir: libbio 5 | #dir: liblex 6 | #dir: libmach 7 | #dir: libregexp 8 | #dir: libmath 9 | 10 | #dir: cc 11 | 12 | #dir: 8a 13 | #dir: 8c 14 | file: 8c/6.out.h.clang2 15 | #file: 8c/8.out.h.clang2 16 | 17 | #dir: 8l 18 | 19 | #dir: mk 20 | #dir: lex 21 | #dir: yacc 22 | #dir: nm 23 | #dir: iar 24 | #dir: kprof 25 | #dir: ksize 26 | #dir: kstrip 27 | #dir: ndate 28 | 29 | dir: acid 30 | -------------------------------------------------------------------------------- /tc/enam.c: -------------------------------------------------------------------------------- 1 | char* anames[] = 2 | { 3 | "XXX", 4 | "AND", 5 | "EOR", 6 | "SUB", 7 | "RSB", 8 | "ADD", 9 | "ADC", 10 | "SBC", 11 | "RSC", 12 | "TST", 13 | "TEQ", 14 | "CMP", 15 | "CMN", 16 | "ORR", 17 | "BIC", 18 | "MVN", 19 | "B", 20 | "BL", 21 | "BEQ", 22 | "BNE", 23 | "BCS", 24 | "BHS", 25 | "BCC", 26 | "BLO", 27 | "BMI", 28 | "BPL", 29 | "BVS", 30 | "BVC", 31 | "BHI", 32 | "BLS", 33 | "BGE", 34 | "BLT", 35 | "BGT", 36 | "BLE", 37 | "MOVWD", 38 | "MOVWF", 39 | "MOVDW", 40 | "MOVFW", 41 | "MOVFD", 42 | "MOVDF", 43 | "MOVF", 44 | "MOVD", 45 | "CMPF", 46 | "CMPD", 47 | "ADDF", 48 | "ADDD", 49 | "SUBF", 50 | "SUBD", 51 | "MULF", 52 | "MULD", 53 | "DIVF", 54 | "DIVD", 55 | "SRL", 56 | "SRA", 57 | "SLL", 58 | "MULU", 59 | "DIVU", 60 | "MUL", 61 | "DIV", 62 | "MOD", 63 | "MODU", 64 | "MOVB", 65 | "MOVBU", 66 | "MOVH", 67 | "MOVHU", 68 | "MOVW", 69 | "MOVM", 70 | "SWPBU", 71 | "SWPW", 72 | "NOP", 73 | "RFE", 74 | "SWI", 75 | "MULA", 76 | "DATA", 77 | "GLOBL", 78 | "GOK", 79 | "HISTORY", 80 | "NAME", 81 | "RET", 82 | "TEXT", 83 | "WORD", 84 | "DYNT", 85 | "INIT", 86 | "ABCASE", 87 | "ACASE", 88 | "END", 89 | "MULL", 90 | "MULAL", 91 | "MULLU", 92 | "MULALU", 93 | "BX", 94 | "BX", 95 | "DWORD", 96 | "SIGNAME", 97 | "LAST", 98 | }; 99 | -------------------------------------------------------------------------------- /tc/mkenam: -------------------------------------------------------------------------------- 1 | ed - ../5ct/5.out.h <<'!' 2 | v/^ A/d 3 | ,s/^ A/ "/ 4 | g/ .*$/s/// 5 | ,s/,*$/",/ 6 | 1i 7 | char* anames[] = 8 | { 9 | . 10 | $a 11 | }; 12 | . 13 | w enam.c 14 | Q 15 | ! 16 | -------------------------------------------------------------------------------- /tc/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | TARG=tc 4 | 5 | OFILES= cgen.$O\ 6 | enam.$O\ 7 | list.$O\ 8 | mul.$O\ 9 | peep.$O\ 10 | reg.$O\ 11 | sgen.$O\ 12 | swt.$O\ 13 | txt.$O\ 14 | 15 | HFILES= gc.h\ 16 | 5.out.h\ 17 | ../cc/cc.h\ 18 | 19 | LIBS=cc bio 9 # order is important 20 | 21 | BIN=$ROOT/$OBJDIR/bin 22 | 23 | <$ROOT/mkfiles/mkone-$SHELLTYPE 24 | 25 | $ROOT/$OBJDIR/lib/libcc.a: 26 | cd ../cc 27 | mk $MKFLAGS install 28 | mk $MKFLAGS clean 29 | -------------------------------------------------------------------------------- /tl/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | TARG=5l 4 | 5 | OFILES=\ 6 | asm.$O\ 7 | list.$O\ 8 | noop.$O\ 9 | obj.$O\ 10 | optab.$O\ 11 | pass.$O\ 12 | span.$O\ 13 | enam.$O\ 14 | $TARGMODEL.$O\ 15 | thumb.$O\ 16 | 17 | HFILES=\ 18 | l.h\ 19 | ../5c/5.out.h\ 20 | $ROOT/include/ar.h\ 21 | 22 | LIBS=bio 9 # order is important 23 | 24 | CFLAGS=$CFLAGS -I../include -I. 25 | 26 | BIN=$ROOT/$OBJDIR/bin 27 | 28 | <$ROOT/mkfiles/mkone-$SHELLTYPE 29 | 30 | enam.$O: ../5c/enam.c 31 | $CC $CFLAGS ../5c/enam.c 32 | 33 | $TARGMODEL.$O: ../ld/$TARGMODEL.c 34 | $CC $CFLAGS ../ld/$TARGMODEL.c 35 | -------------------------------------------------------------------------------- /utilities/aux/data2s.c: -------------------------------------------------------------------------------- 1 | #include 2 | //#include 3 | //#include 4 | #include 5 | 6 | void 7 | main(int argc, char *argv[]) 8 | { 9 | Biobuf bin, bout; 10 | long len, slen; 11 | int c; 12 | 13 | if(argc != 2){ 14 | fprint(2, "usage: data2s name\n"); 15 | exits("usage"); 16 | } 17 | Binit(&bin, 0, OREAD); 18 | Binit(&bout, 1, OWRITE); 19 | for(len=0; (c=Bgetc(&bin))!=Beof; len++){ 20 | if((len&7) == 0) 21 | Bprint(&bout, "DATA %scode+%ld(SB)/8, $\"", argv[1], len); 22 | if(c) 23 | Bprint(&bout, "\\%uo", c); 24 | else 25 | Bprint(&bout, "\\z"); 26 | if((len&7) == 7) 27 | Bprint(&bout, "\"\n"); 28 | } 29 | slen = len; 30 | if(len & 7){ 31 | while(len & 7){ 32 | Bprint(&bout, "\\z"); 33 | len++; 34 | } 35 | Bprint(&bout, "\"\n"); 36 | } 37 | Bprint(&bout, "GLOBL %scode+0(SB), $%ld\n", argv[1], len); 38 | Bprint(&bout, "GLOBL %slen+0(SB), $4\n", argv[1]); 39 | Bprint(&bout, "DATA %slen+0(SB)/4, $%ld\n", argv[1], slen); 40 | exits(0); 41 | } 42 | -------------------------------------------------------------------------------- /utilities/aux/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../mkconfig 3 | 4 | TARG=data2s 5 | OFILES= data2s.$O\ 6 | 7 | #TARG=mklatinkbd 8 | #OFILES=mklatinkbd.$O 9 | 10 | LIBS= bio 9 11 | 12 | BIN=$ROOT/$OBJDIR/bin 13 | 14 | <$ROOT/mkfiles/mkone-$SHELLTYPE 15 | 16 | -------------------------------------------------------------------------------- /utilities/date/date.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void 4 | main(void) 5 | { 6 | ulong t; 7 | 8 | t = time(0); 9 | print("%lud\n", t); 10 | exits(0); 11 | } 12 | -------------------------------------------------------------------------------- /utilities/date/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../mkconfig 3 | 4 | TARG=date 5 | 6 | OFILES= date.$O\ 7 | 8 | HFILES= 9 | 10 | LIBS=9 11 | 12 | BIN=$ROOT/$OBJDIR/bin 13 | 14 | <$ROOT/mkfiles/mkone-$SHELLTYPE 15 | -------------------------------------------------------------------------------- /utilities/hoc/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../mkconfig 3 | 4 | TARG=hoc 5 | 6 | OFILES=\ 7 | y.tab.$O\ 8 | code.$O\ 9 | init.$O\ 10 | math.$O\ 11 | symbol.$O\ 12 | 13 | HFILES=\ 14 | y.tab.h\ 15 | hoc.h\ 16 | 17 | YFILES=hoc.y 18 | 19 | LIBS=math bio 9 # order is important 20 | 21 | BIN=$ROOT/$OBJDIR/bin 22 | 23 | <$ROOT/mkfiles/mkone-$SHELLTYPE 24 | -------------------------------------------------------------------------------- /utilities/hoc/symbol.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "hoc.h" 3 | #include "y.tab.h" 4 | 5 | static Symbol *symlist = 0; /* symbol table: linked list */ 6 | 7 | Symbol* 8 | lookup(char* s) /* find s in symbol table */ 9 | { 10 | Symbol *sp; 11 | 12 | for (sp = symlist; sp != (Symbol *) 0; sp = sp->next) 13 | if (strcmp(sp->name, s) == 0) 14 | return sp; 15 | return 0; /* 0 ==> not found */ 16 | } 17 | 18 | Symbol* 19 | install(char* s, int t, double d) /* install s in symbol table */ 20 | { 21 | Symbol *sp; 22 | 23 | sp = emalloc(sizeof(Symbol)); 24 | sp->name = emalloc(strlen(s)+1); /* +1 for '\0' */ 25 | strcpy(sp->name, s); 26 | sp->type = t; 27 | sp->u.val = d; 28 | sp->next = symlist; /* put at front of list */ 29 | symlist = sp; 30 | return sp; 31 | } 32 | 33 | void* 34 | emalloc(unsigned n) /* check return from malloc */ 35 | { 36 | char *p; 37 | 38 | p = malloc(n); 39 | if (p == 0) 40 | execerror("out of memory", (char *) 0); 41 | return p; 42 | } 43 | 44 | Formal* 45 | formallist(Symbol *formal, Formal *list) /* add formal to list */ 46 | { 47 | Formal *f; 48 | 49 | f = emalloc(sizeof(Formal)); 50 | f->sym = formal; 51 | f->save = 0; 52 | f->next = list; 53 | return f; 54 | } 55 | -------------------------------------------------------------------------------- /utilities/hoc/y.tab.h: -------------------------------------------------------------------------------- 1 | 2 | typedef union { 3 | Symbol *sym; /* symbol table pointer */ 4 | Inst *inst; /* machine instruction */ 5 | int narg; /* number of arguments */ 6 | Formal *formals; /* list of formal parameters */ 7 | } YYSTYPE; 8 | extern YYSTYPE yylval; 9 | #define NUMBER 57346 10 | #define STRING 57347 11 | #define PRINT 57348 12 | #define VAR 57349 13 | #define BLTIN 57350 14 | #define UNDEF 57351 15 | #define WHILE 57352 16 | #define FOR 57353 17 | #define IF 57354 18 | #define ELSE 57355 19 | #define FUNCTION 57356 20 | #define PROCEDURE 57357 21 | #define RETURN 57358 22 | #define FUNC 57359 23 | #define PROC 57360 24 | #define READ 57361 25 | #define ADDEQ 57362 26 | #define SUBEQ 57363 27 | #define MULEQ 57364 28 | #define DIVEQ 57365 29 | #define MODEQ 57366 30 | #define OR 57367 31 | #define AND 57368 32 | #define GT 57369 33 | #define GE 57370 34 | #define LT 57371 35 | #define LE 57372 36 | #define EQ 57373 37 | #define NE 57374 38 | #define UNARYMINUS 57375 39 | #define NOT 57376 40 | #define INC 57377 41 | #define DEC 57378 42 | -------------------------------------------------------------------------------- /utilities/kprof/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../../mkconfig 3 | 4 | TARG=kprof 5 | 6 | OFILES= kprof.$O\ 7 | 8 | LIBS= mach bio 9 9 | 10 | BIN=$ROOT/$OBJDIR/bin 11 | 12 | <$ROOT/mkfiles/mkone-$SHELLTYPE 13 | 14 | -------------------------------------------------------------------------------- /utilities/ksize/ksize.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mach.h" 4 | 5 | int 6 | size(char *file) 7 | { 8 | int fd; 9 | Fhdr f; 10 | 11 | if((fd = open(file, OREAD)) < 0){ 12 | fprint(2, "size: "); 13 | perror(file); 14 | return 1; 15 | } 16 | if(crackhdr(fd, &f)) { 17 | print("%ldt + %ldd + %ldb = %ld\t%s\n", f.txtsz, f.datsz, 18 | f.bsssz, f.txtsz+f.datsz+f.bsssz, file); 19 | close(fd); 20 | return 0; 21 | } 22 | 23 | /* get error string from libmach and display */ 24 | fprint(2, "ksize: %s %r\n", file); 25 | close(fd); 26 | return 1; 27 | } 28 | 29 | void 30 | main(int argc, char *argv[]) 31 | { 32 | char *err; 33 | int i; 34 | 35 | ARGBEGIN { 36 | default: 37 | fprint(2, "usage: ksize [a.out ...]\n"); 38 | exits("usage"); 39 | } ARGEND; 40 | 41 | err = 0; 42 | if(argc == 0) 43 | if(size("8.out")) 44 | err = "error"; 45 | for(i=0; i= 0; 65 | } 66 | -------------------------------------------------------------------------------- /vl/mkfile: -------------------------------------------------------------------------------- 1 | <../../../mkconfig 2 | 3 | TARG=vl 4 | 5 | OFILES=\ 6 | asm.$O\ 7 | list.$O\ 8 | noop.$O\ 9 | sched.$O\ 10 | obj.$O\ 11 | optab.$O\ 12 | pass.$O\ 13 | span.$O\ 14 | enam.$O\ 15 | $TARGMODEL.$O\ 16 | elf.$O\ 17 | 18 | HFILES=\ 19 | l.h\ 20 | ../vc/v.out.h\ 21 | ${ROOT}/include/ar.h\ 22 | 23 | LIBS=bio 9 # order is important 24 | 25 | BIN=$ROOT/$OBJDIR/bin 26 | 27 | <$ROOT/mkfiles/mkone-$SHELLTYPE 28 | CFLAGS= $CFLAGS -I. 29 | 30 | 31 | enam.$O: ../vc/enam.c 32 | $CC $CFLAGS ../vc/enam.c 33 | elf.$O: ../ld/elf.c 34 | $CC $CFLAGS ../ld/elf.c 35 | 36 | $TARGMODEL.$O: ../ld/$TARGMODEL.c 37 | $CC $CFLAGS ../ld/$TARGMODEL.c 38 | -------------------------------------------------------------------------------- /yacc/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=iyacc 5 | 6 | OFILES= yacc.$O\ 7 | 8 | HFILES= ${ROOT}/include/bio.h\ 9 | 10 | LIBS=bio 9 # libbio.a uses lib9.a so order matters. 11 | 12 | BIN=$ROOT/$OBJDIR/bin 13 | 14 | <$ROOT/mkfiles/mkone-$SHELLTYPE 15 | 16 | CFLAGS= $CFLAGS '-DROOT="'$ROOT'"' '-DPARSER="yaccpar"' '-DPARSERS="yaccpar"' 17 | 18 | install:V: $ROOT/lib/yaccpar 19 | 20 | $ROOT/lib/yaccpar: yaccpar 21 | rm -f $target && cp $prereq $target 22 | -------------------------------------------------------------------------------- /za/l.s: -------------------------------------------------------------------------------- 1 | TEXT _main(SB), $0 2 | 3 | ADD R1,R4 4 | ADD R1,R3,R4 5 | ADD $10,R1,R4 6 | 7 | loop: 8 | BNE R1,R4,loop 9 | 10 | MOVW R3, (R2) 11 | MOVW R3, 10(R2) 12 | MOVW R3, _main(SB) 13 | MOVW R3, (R2) 14 | 15 | RET 16 | -------------------------------------------------------------------------------- /za/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=5a 5 | 6 | OFILES=\ 7 | y.tab.$O\ 8 | lex.$O\ 9 | 10 | HFILES=\ 11 | ../zc/z.out.h\ 12 | y.tab.h\ 13 | a.h\ 14 | 15 | YFILES=a.y\ 16 | 17 | LIBS=cc bio 9 # order is important 18 | 19 | BIN=$ROOT/$OBJDIR/bin 20 | 21 | <$ROOT/mkfiles/mkone-$SHELLTYPE 22 | 23 | YFLAGS=-D1 -d 24 | 25 | lex.$O: ../cc/macbody ../cc/lexbody 26 | 27 | $ROOT/$OBJDIR/lib/libcc.a: 28 | cd ../cc 29 | mk $MKFLAGS install 30 | mk $MKFLAGS clean 31 | -------------------------------------------------------------------------------- /za/y.tab.h: -------------------------------------------------------------------------------- 1 | 2 | typedef union 3 | { 4 | Sym *sym; 5 | long lval; 6 | double dval; 7 | char sval[8]; 8 | Gen gen; 9 | } YYSTYPE; 10 | extern YYSTYPE yylval; 11 | #define LADD 57346 12 | #define LMUL 57347 13 | #define LBEQ 57348 14 | #define LBR 57349 15 | #define LBRET 57350 16 | #define LCALL 57351 17 | #define LMOVB 57352 18 | #define LMOVBU 57353 19 | #define LMOVW 57354 20 | #define LLUI 57355 21 | #define LSYS 57356 22 | #define LSWAP 57357 23 | #define LAMO 57358 24 | #define LCONST 57359 25 | #define LSP 57360 26 | #define LSB 57361 27 | #define LFP 57362 28 | #define LPC 57363 29 | #define LREG 57364 30 | #define LR 57365 31 | #define LCTL 57366 32 | #define LDATA 57367 33 | #define LTEXT 57368 34 | #define LWORD 57369 35 | #define LSCONST 57370 36 | #define LFCONST 57371 37 | #define LNAME 57372 38 | #define LLAB 57373 39 | #define LVAR 57374 40 | -------------------------------------------------------------------------------- /za/za: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/za/za -------------------------------------------------------------------------------- /zc/l.s: -------------------------------------------------------------------------------- 1 | #define EBREAK WORD $(0x73 | 1<<20) 2 | #define STIMER(rs,rd) WORD $(0xB | (rd)<<7 | (rs)<<15 | 0x5<<25 | 6<<12) 3 | 4 | TEXT start(SB), $0 5 | /* set static base */ 6 | MOVW $setSB(SB), R26 7 | 8 | /* set stack pointer */ 9 | MOVW $(512*1024-16),R27 10 | 11 | /* clear bss */ 12 | MOVW $edata(SB), R1 13 | MOVW $end(SB), R2 14 | MOVW R0, 0(R1) 15 | ADD $4, R1 16 | BLT R2, R1, -2(PC) 17 | 18 | #ifdef nope 19 | /* set watchdog timer */ 20 | MOVW $20000000, R10 /* 1 seconds */ 21 | STIMER(10,10) 22 | #endif 23 | 24 | /* but0 interrupt on rising edge */ 25 | MOVW $0x20020000, R1 26 | MOVW $2, R2 27 | MOVW R2, 0(R1) 28 | 29 | /* call main */ 30 | JAL R31, main(SB) 31 | EBREAK 32 | 33 | RET 34 | 35 | TEXT abort(SB), $-4 36 | EBREAK 37 | RET 38 | -------------------------------------------------------------------------------- /zc/mkenam: -------------------------------------------------------------------------------- 1 | ed - ../zc/z.out.h <<'!' 2 | v/^ A/d 3 | ,s/^ A/ "/ 4 | g/ .*$/s/// 5 | ,s/,*$/",/ 6 | 1i 7 | char* anames[] = 8 | { 9 | . 10 | $a 11 | }; 12 | . 13 | w enam.c 14 | Q 15 | ! 16 | -------------------------------------------------------------------------------- /zc/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=zc 5 | 6 | OFILES=\ 7 | cgen.$O\ 8 | enam.$O\ 9 | list.$O\ 10 | mul.$O\ 11 | peep.$O\ 12 | pgen.$O\ 13 | pswt.$O\ 14 | reg.$O\ 15 | sgen.$O\ 16 | swt.$O\ 17 | txt.$O\ 18 | 19 | HFILES=\ 20 | gc.h\ 21 | z.out.h\ 22 | ../cc/cc.h\ 23 | 24 | LIBS=cc bio 9 # order is important 25 | 26 | BIN=$ROOT/$OBJDIR/bin 27 | 28 | <$ROOT/mkfiles/mkone-$SHELLTYPE 29 | 30 | $ROOT/$OBJDIR/lib/libcc.a: 31 | cd ../cc 32 | mk $MKFLAGS install 33 | mk $MKFLAGS clean 34 | 35 | %.$O: ../cc/%.c 36 | $CC -I. $CFLAGS ../cc/$stem.c 37 | -------------------------------------------------------------------------------- /zc/zc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/zc/zc -------------------------------------------------------------------------------- /zl/compat.c: -------------------------------------------------------------------------------- 1 | #include "l.h" 2 | 3 | /* 4 | * fake malloc 5 | */ 6 | void* 7 | malloc(ulong n) 8 | { 9 | void *p; 10 | 11 | while(n & 7) 12 | n++; 13 | while(nhunk < n) 14 | gethunk(); 15 | p = hunk; 16 | nhunk -= n; 17 | hunk += n; 18 | return p; 19 | } 20 | 21 | void 22 | free(void *p) 23 | { 24 | USED(p); 25 | } 26 | 27 | void* 28 | calloc(ulong m, ulong n) 29 | { 30 | void *p; 31 | 32 | n *= m; 33 | p = malloc(n); 34 | memset(p, 0, n); 35 | return p; 36 | } 37 | 38 | void* 39 | realloc(void*, ulong) 40 | { 41 | fprint(2, "realloc called\n"); 42 | abort(); 43 | return 0; 44 | } 45 | 46 | void* 47 | mysbrk(ulong size) 48 | { 49 | return sbrk(size); 50 | } 51 | -------------------------------------------------------------------------------- /zl/mkfile: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | <../mkconfig 3 | 4 | TARG=zl 5 | 6 | OFILES=\ 7 | asm.$O\ 8 | list.$O\ 9 | noop.$O\ 10 | obj.$O\ 11 | optab.$O\ 12 | pass.$O\ 13 | span.$O\ 14 | enam.$O\ 15 | $TARGMODEL.$O\ 16 | 17 | 18 | HFILES=\ 19 | l.h\ 20 | ../zc/z.out.h\ 21 | ${ROOT}/include/ar.h\ 22 | 23 | LIBS=bio 9 # order is important 24 | 25 | 26 | BIN=$ROOT/$OBJDIR/bin 27 | 28 | <$ROOT/mkfiles/mkone-$SHELLTYPE 29 | 30 | enam.$O: ../zc/enam.c 31 | $CC $CFLAGS ../zc/enam.c 32 | 33 | -------------------------------------------------------------------------------- /zl/zl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelengel/kencc-cross/37dc0933c2adfa414d9b1612c43fd7f4791327d0/zl/zl --------------------------------------------------------------------------------