├── 9K ├── 386 │ ├── ahci.h │ ├── aoe0.h │ ├── devaoe0.c │ ├── devether.c │ ├── devpmc.c │ ├── devrtc.c │ ├── ether8139.c │ ├── ether8169.c │ ├── ether8169x.c │ ├── ether82557.c │ ├── ether82563.c │ ├── ether82598.c │ ├── ether82598.c.orig │ ├── ether82653.c_o │ ├── etherbcm.c │ ├── etherigbe.c │ ├── etherm10g.c │ ├── etherm10g2k.i │ ├── etherm10g4k.i │ ├── fis.c │ ├── fis.h │ ├── kbd.c │ ├── pci.c │ ├── pmc.h │ ├── pmcio.c │ ├── sdata.c │ ├── sdiahci.c │ ├── sdide.c │ ├── sdscsi.c │ ├── uarti8250.c │ └── uartpci.c ├── CHANGES ├── boot │ ├── aux.c │ ├── boot.c │ ├── boot.h │ ├── bootauth.c │ ├── bootcache.c │ ├── bootip.c │ ├── doauthenticate.c │ ├── embed.c │ ├── getpasswd.c │ ├── local.c │ ├── localpaq.c │ ├── nopsession.c │ ├── paq.c │ ├── printstub.c │ ├── sac.c │ └── settime.c ├── ip │ ├── arp.c │ ├── chandial.c │ ├── devip.c │ ├── esp.c │ ├── ethermedium.c │ ├── gre.c │ ├── icmp.c │ ├── icmp6.c │ ├── il.c │ ├── ip.c │ ├── ip.h │ ├── ipaux.c │ ├── ipifc.c │ ├── iproute.c │ ├── ipv6.c │ ├── ipv6.h │ ├── loopbackmedium.c │ ├── netdevmedium.c │ ├── netlog.c │ ├── nullmedium.c │ ├── pktmedium.c │ ├── ptclbsum.c │ ├── tcp.c │ └── udp.c ├── k10 │ ├── acpi.c │ ├── acpi.h │ ├── adr.h │ ├── amd64.h │ ├── apic.h │ ├── arch.c │ ├── archk10.c │ ├── cga.c │ ├── dat.h │ ├── devacpi.c │ ├── devarch.c │ ├── devkbin.c │ ├── etherif.h │ ├── fns.h │ ├── fpu.c │ ├── hpet.c │ ├── ht.c │ ├── i8254.c │ ├── i8259.c │ ├── init9.c │ ├── intrmon.c │ ├── io.h │ ├── ioapic.c │ ├── k10cpu │ ├── k8aoe │ ├── k8cpu │ ├── k8root │ ├── l32p.s │ ├── l64cpuid.s │ ├── l64fpu.s │ ├── l64idt.s │ ├── l64sipi.s │ ├── l64syscall.s │ ├── l64v.s │ ├── lapic.c │ ├── main.c │ ├── map.c │ ├── mem.h │ ├── memory.c │ ├── mkfile │ ├── mmu.c │ ├── mp.c │ ├── msi.c │ ├── multiboot.c │ ├── options.c │ ├── ptclbsumamd64.s │ ├── root │ │ ├── cpu.c │ │ ├── k8root.namespace │ │ ├── k8root.proto │ │ ├── k8root.rc │ │ ├── mkfile │ │ └── tcp17010 │ ├── sdahci.c │ ├── sipi.c │ ├── sipi.h │ ├── smbus.h │ ├── syscall.c │ ├── t.c │ ├── tmap.c │ ├── trap.c │ ├── uncached.h │ ├── usbehci.h │ ├── usbehcipc.c │ ├── usbohci.c │ ├── usbuhci.c │ └── vsvm.c ├── mk │ ├── bootmkfile │ ├── mkenum │ ├── mkroot │ ├── mkrootall │ ├── mkrr │ ├── parse │ └── portmkfile ├── port │ ├── alarm.c │ ├── allocb.c │ ├── aoe.h │ ├── bud.c │ ├── cache.c │ ├── chan.c │ ├── dev.c │ ├── devaoe.c │ ├── devcap.c │ ├── devcons.c │ ├── devdup.c │ ├── devenv.c │ ├── devfs.c │ ├── devkprof.c │ ├── devmem.c │ ├── devmem1.c │ ├── devmnt.c │ ├── devpci.c │ ├── devpipe.c │ ├── devprobe.c │ ├── devproc.c │ ├── devptrace.c │ ├── devroot.c │ ├── devsd.c │ ├── devsrv.c │ ├── devssl.c │ ├── devtab.c │ ├── devtls.c │ ├── devtrace.c │ ├── devuart.c │ ├── devusb.c │ ├── devwd.c │ ├── dirdep │ ├── edf.c │ ├── edf.h │ ├── error.h │ ├── ethermii.c │ ├── ethermii.h │ ├── fault.c │ ├── image.c │ ├── initcode.c │ ├── iofilter.h │ ├── latin1.c │ ├── latin1.h │ ├── lib.h │ ├── mcslock.c │ ├── mul64fract.c │ ├── net.c │ ├── netif.c │ ├── netif.h │ ├── nocache.c │ ├── noedf.c │ ├── page.c │ ├── parse.c │ ├── pgrp.c │ ├── physalloc.c │ ├── portclock.c │ ├── portdat.h │ ├── portfns.h │ ├── portusbehci.h │ ├── print.c │ ├── proc.c │ ├── ps.c │ ├── qio.c │ ├── qlock.c │ ├── qmalloc.c │ ├── random.c │ ├── rdb.c │ ├── reap.c │ ├── rebootcmd.c │ ├── ref.c │ ├── rmap.c │ ├── sd.h │ ├── sdaoe.c │ ├── sdatafis.c │ ├── segment.c │ ├── sysauth.c │ ├── syscallfmt.c │ ├── sysfile.c │ ├── sysproc.c │ ├── sysseg.c │ ├── systab.c │ ├── taslock.c │ ├── tod.c │ ├── uidgid.c │ ├── usb.h │ └── usbehci.c ├── root │ ├── blow.c │ ├── common │ ├── cpu.c │ ├── mkfile │ ├── pp.c │ ├── profile │ ├── rcmain │ ├── suck.c │ ├── tcp23 │ └── tcp564 └── words │ ├── CHANGES │ ├── boot.out │ └── mm ├── AMD64_compiler ├── 6a │ ├── a.h │ ├── a.y │ ├── lex.c │ └── mkfile ├── 6c │ ├── 6.out.h │ ├── cgen.c │ ├── div.c │ ├── divq.c │ ├── enam.c │ ├── gc.h │ ├── list.c │ ├── machcap.c │ ├── mkenam │ ├── mkfile │ ├── mul.c │ ├── peep.c │ ├── reg.c │ ├── sgen.c │ ├── swt.c │ └── txt.c ├── 6l │ ├── Ld │ ├── Mk │ ├── Nt.c │ ├── Plan9.c │ ├── Posix.c │ ├── World │ ├── asm.c │ ├── bits.c │ ├── compat.c │ ├── l │ ├── l.h │ ├── list.c │ ├── map64 │ ├── mkfile │ ├── notes │ │ ├── Cpus │ │ ├── More │ │ ├── Notes │ │ ├── Pack │ │ ├── Q │ │ ├── T │ │ ├── V │ │ ├── X │ │ ├── Xmm │ │ ├── Y │ │ └── Zs │ ├── obj.c │ ├── optab.c │ ├── pass.c │ └── span.c └── cc │ ├── acid.c │ ├── bits.c │ ├── c99 │ ├── c99.txt │ ├── cc.h │ ├── cc.y │ ├── com.c │ ├── com64.c │ ├── compat │ ├── compat.c │ ├── dcl.c │ ├── dpchk.c │ ├── funct.c │ ├── lex.c │ ├── lexbody │ ├── mac.c │ ├── macbody │ ├── mkfile │ ├── omachcap.c │ ├── pgen.c │ ├── pickle.c │ ├── pswt.c │ ├── scon.c │ ├── sub.c │ ├── tsw │ ├── sw1.c │ ├── sw2.c │ ├── sw3.c │ ├── sw4.c │ ├── vls1.c │ ├── vlsw.c │ └── vlsw2.c │ └── xmachcap.c ├── PART1 ├── amd64 │ └── include │ │ ├── ape │ │ ├── float.h │ │ ├── math.h │ │ ├── stdarg.h │ │ └── ureg.h │ │ ├── gnu │ │ ├── README │ │ ├── float.h │ │ ├── iso646.h │ │ ├── limits.h │ │ ├── math.h │ │ ├── proto.h │ │ ├── stdarg.h │ │ ├── stdbool.h │ │ ├── stddef.h │ │ ├── ureg.h │ │ └── varargs.h │ │ ├── u.h │ │ └── ureg.h └── sys │ └── src │ ├── ape │ └── lib │ │ ├── 9 │ │ └── amd64 │ │ │ ├── getcallerpc.s │ │ │ └── getfcr.s │ │ ├── ap │ │ └── amd64 │ │ │ ├── _seek.c │ │ │ ├── lock.c │ │ │ ├── main9.s │ │ │ ├── main9p.s │ │ │ ├── mkfile │ │ │ ├── notetramp.c │ │ │ ├── setjmp.s │ │ │ ├── sqrt.s │ │ │ ├── strchr.s │ │ │ ├── strlen.s │ │ │ ├── tas.s │ │ │ └── xsetjmp.s │ │ ├── mp │ │ └── amd64 │ │ │ └── mkfile │ │ └── sec │ │ └── amd64 │ │ └── mkfile │ ├── libc │ ├── 9syscall │ │ └── mkfile │ └── amd64 │ │ ├── _seek.c │ │ ├── argv0.s │ │ ├── atom.s │ │ ├── cycles.s │ │ ├── getcallerpc.c │ │ ├── getcallerpc.s.new │ │ ├── getfcr.s │ │ ├── main9.s │ │ ├── main9l.s │ │ ├── main9p.s │ │ ├── main9x.s │ │ ├── memccpy.s │ │ ├── memchr.s │ │ ├── memcmp.s │ │ ├── memcpy.s │ │ ├── memmove.s │ │ ├── memset.s │ │ ├── mkfile │ │ ├── muldiv.s │ │ ├── notejmp.c │ │ ├── rdpmc.s │ │ ├── setjmp.s │ │ ├── sqrt.s │ │ ├── strcat.s │ │ ├── strchr.s │ │ ├── strcpy.s │ │ ├── strlen.s │ │ └── tas.s │ ├── libmp │ └── amd64 │ │ ├── mkfile │ │ ├── mpdigdiv.s │ │ ├── mpvecadd.s │ │ ├── mpvecdigmuladd.s │ │ ├── mpvecdigmulsub.s │ │ └── mpvecsub.s │ └── libsec │ └── amd64 │ └── mkfile ├── PART2 └── src │ ├── ape │ └── lib │ │ └── ap │ │ └── amd64 │ │ ├── atom.s │ │ ├── lock.c │ │ └── mkfile │ └── mkfile.proto ├── PART3 ├── include │ ├── aml.h │ └── ptrace.h └── src │ └── libaml │ ├── aml.7 │ ├── aml.c │ ├── amlalloc.7 │ ├── amlalloc.c │ ├── amldelay.7 │ ├── amldelay.c │ ├── amlmapio.7 │ ├── amlmapio.c │ ├── amlunmapio.7 │ ├── amlunmapio.c │ └── mkfile ├── PART4 ├── boot │ └── bootip.c └── port │ ├── devcons.c │ └── mcslock.c ├── QEMU └── qemu-new.sh ├── README.txt ├── SCHED ├── bench │ └── siglock.c ├── libc.h ├── mcslock.c ├── portdat.h ├── proc.c ├── sys.h ├── sysproc.c └── systab.h └── lock-sched-design.txt /9K/386/aoe0.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ATA-over-Ethernet (AoE) protocol 3 | */ 4 | enum { 5 | ACata, 6 | ACconfig, 7 | }; 8 | 9 | enum { 10 | AQCread, 11 | AQCtest, 12 | AQCprefix, 13 | AQCset, 14 | AQCfset, 15 | }; 16 | 17 | enum { 18 | AEcmd = 1, 19 | AEarg, 20 | AEdev, 21 | AEcfg, 22 | AEver, 23 | }; 24 | 25 | enum { 26 | Aoetype = 0x88a2, 27 | Aoesectsz = 512, /* standard sector size */ 28 | Aoever = 1, 29 | 30 | AFerr = 1<<2, 31 | AFrsp = 1<<3, 32 | 33 | AAFwrite= 1, 34 | AAFext = 1<<6, 35 | }; 36 | 37 | typedef struct { 38 | uchar dst[Eaddrlen]; 39 | uchar src[Eaddrlen]; 40 | uchar type[2]; 41 | uchar verflag; 42 | uchar error; 43 | uchar major[2]; 44 | uchar minor; 45 | uchar cmd; 46 | uchar tag[4]; 47 | uchar payload[]; 48 | } Aoehdr; 49 | 50 | #define AOEHDRSZ offsetof(Aoehdr, payload[0]) 51 | 52 | typedef struct { 53 | Aoehdr; 54 | uchar aflag; 55 | uchar errfeat; 56 | uchar scnt; 57 | uchar cmdstat; 58 | uchar lba[6]; 59 | uchar res[2]; 60 | uchar payload[]; 61 | } Aoeata; 62 | 63 | #define AOEATASZ offsetof(Aoeata, payload[0]) 64 | 65 | typedef struct { 66 | Aoehdr; 67 | uchar bufcnt[2]; 68 | uchar fwver[2]; 69 | uchar scnt; 70 | uchar verccmd; 71 | uchar cslen[2]; 72 | uchar payload[]; 73 | } Aoeqc; 74 | 75 | #define AOEQCSZ offsetof(Aoeqc, payload[0]) 76 | 77 | extern char Echange[]; 78 | extern char Enotup[]; 79 | -------------------------------------------------------------------------------- /9K/386/pmc.h: -------------------------------------------------------------------------------- 1 | typedef struct PmcCtl PmcCtl; 2 | typedef struct PmcCtr PmcCtr; 3 | typedef struct PmcCtlCtrId PmcCtlCtrId; 4 | 5 | /* 6 | * HW performance counters 7 | */ 8 | struct PmcCtl { 9 | u32int coreno; 10 | int enab; 11 | int user; 12 | int os; 13 | int nodesc; 14 | char descstr[KNAMELEN]; 15 | }; 16 | 17 | struct PmcCtr{ 18 | int stale; 19 | Rendez r; 20 | u64int ctr; 21 | int ctrset; 22 | PmcCtl; 23 | int ctlset; 24 | }; 25 | 26 | enum { 27 | PmcMaxCtrs = 4, 28 | }; 29 | 30 | struct PmcCore{ 31 | Lock; 32 | PmcCtr ctr[PmcMaxCtrs]; 33 | }; 34 | 35 | struct PmcCtlCtrId { 36 | char portdesc[KNAMELEN]; 37 | char archdesc[KNAMELEN]; 38 | }; 39 | 40 | enum { 41 | PmcIgn = 0, 42 | PmcGet = 1, 43 | PmcSet = 2, 44 | }; 45 | 46 | enum { 47 | PmcCtlNullval = 0xdead, 48 | }; 49 | 50 | extern int pmcnregs(void); 51 | extern void pmcinitctl(PmcCtl*); 52 | extern int pmcsetctl(u32int, PmcCtl*, u32int); 53 | extern int pmctrans(PmcCtl*); 54 | extern int pmcgetctl(u32int, PmcCtl*, u32int); 55 | extern int pmcdescstr(char*, int); 56 | extern u64int pmcgetctr(u32int, u32int); 57 | extern int pmcsetctr(u32int, u64int, u32int); 58 | 59 | extern void pmcconfigure(void); 60 | -------------------------------------------------------------------------------- /9K/CHANGES: -------------------------------------------------------------------------------- 1 | Quick changes 2 | 3 | - mach[machno]->ptr == m 4 | - sys->ticks 5 | - qmalloc to port 6 | - get rid of conf 7 | - perf counters 8 | - cleanup spurious interrupt handling 9 | - get rid of BY2... 10 | - /dev/config, if not there 11 | - regression testing 12 | - add ahci 13 | - add monitor, waitwhile 14 | 15 | 16 | Slow changes 17 | 18 | - revisit *apic, *ipi, and init code 19 | - int types (look at GiB ull, eg) 20 | - kprof 21 | - sched and lock instrumentation for benchs 22 | 23 | Researchy changes 24 | 25 | - new sched 26 | - new mm 27 | - add XCs 28 | - sems & tubes 29 | - zero copy 30 | -------------------------------------------------------------------------------- /9K/boot/boot.h: -------------------------------------------------------------------------------- 1 | typedef struct Method Method; 2 | struct Method 3 | { 4 | char *name; 5 | void (*config)(Method*); 6 | int (*connect)(void); 7 | char *arg; 8 | }; 9 | enum 10 | { 11 | Statsz= 256, 12 | Nbarg= 16, 13 | }; 14 | 15 | extern void authentication(int); 16 | extern char* bootdisk; 17 | extern char* rootdir; 18 | extern int (*cfs)(int); 19 | extern int cpuflag; 20 | extern char cputype[]; 21 | extern int fflag; 22 | extern int kflag; 23 | extern Method method[]; 24 | extern void (*pword)(int, Method*); 25 | extern char sys[]; 26 | extern uchar hostkey[]; 27 | extern uchar statbuf[Statsz]; 28 | extern int bargc; 29 | extern char *bargv[Nbarg]; 30 | 31 | /* libc equivalent */ 32 | extern int cache(int); 33 | extern char* checkkey(Method*, char*, char*); 34 | extern void fatal(char*, ...); 35 | extern void getpasswd(char*, int); 36 | extern void key(int, Method*); 37 | extern int outin(char*, char*, int); 38 | extern int plumb(char*, char*, int*, char*); 39 | extern int readfile(char*, char*, int); 40 | extern long readn(int, void*, long); 41 | extern void run(char *file, ...); 42 | extern int sendmsg(int, char*); 43 | extern void setenv(char*, char*); 44 | extern void settime(int, int, char*); 45 | extern void srvcreate(char*, int); 46 | extern void warning(char*, ...); 47 | extern int writefile(char*, char*, int); 48 | extern void boot(int, char **); 49 | extern void doauthenticate(int, Method*); 50 | extern int old9p(int); 51 | extern int parsefields(char*, char**, int, char*); 52 | 53 | /* methods */ 54 | extern void configil(Method*); 55 | extern void configtcp(Method*); 56 | extern int connectil(void); 57 | extern int connecttcp(void); 58 | 59 | extern void configlocal(Method*); 60 | extern int connectlocal(void); 61 | 62 | extern void configlocalpaq(Method*); 63 | extern int connectlocalpaq(void); 64 | 65 | extern void configsac(Method*); 66 | extern int connectsac(void); 67 | 68 | extern void configpaq(Method*); 69 | extern int connectpaq(void); 70 | 71 | extern void configembed(Method*); 72 | extern int connectembed(void); 73 | 74 | extern void configip(int, char**, char*); 75 | 76 | /* hack for passing authentication address */ 77 | extern char *authaddr; 78 | -------------------------------------------------------------------------------- /9K/boot/bootauth.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "../boot/boot.h" 6 | 7 | char *authaddr; 8 | static void glenda(void); 9 | 10 | void 11 | authentication(int cpuflag) 12 | { 13 | char *argv[16], **av; 14 | int ac; 15 | 16 | if(access("/boot/factotum", AEXEC) < 0){ 17 | glenda(); 18 | return; 19 | } 20 | 21 | /* start agent */ 22 | ac = 0; 23 | av = argv; 24 | av[ac++] = "factotum"; 25 | if(getenv("debugfactotum")) 26 | av[ac++] = "-p"; 27 | // av[ac++] = "-d"; /* debug traces */ 28 | // av[ac++] = "-D"; /* 9p messages */ 29 | if(cpuflag) 30 | av[ac++] = "-S"; 31 | else 32 | av[ac++] = "-u"; 33 | av[ac++] = "-sfactotum"; 34 | if(authaddr != nil){ 35 | av[ac++] = "-a"; 36 | av[ac++] = authaddr; 37 | } 38 | av[ac] = 0; 39 | switch(fork()){ 40 | case -1: 41 | fatal("starting factotum"); 42 | case 0: 43 | exec("/boot/factotum", av); 44 | fatal("execing /boot/factotum"); 45 | default: 46 | break; 47 | } 48 | 49 | /* wait for agent to really be there */ 50 | while(access("/mnt/factotum", 0) < 0) 51 | sleep(250); 52 | 53 | if(cpuflag) 54 | return; 55 | } 56 | 57 | static void 58 | glenda(void) 59 | { 60 | int fd; 61 | char *s; 62 | 63 | s = getenv("user"); 64 | if(s == nil) 65 | s = "glenda"; 66 | 67 | fd = open("#c/hostowner", OWRITE); 68 | if(fd >= 0){ 69 | if(write(fd, s, strlen(s)) != strlen(s)) 70 | fprint(2, "setting #c/hostowner to %s: %r\n", s); 71 | close(fd); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /9K/boot/bootcache.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include <../boot/boot.h> 4 | 5 | uchar statbuf[Statsz]; 6 | 7 | int 8 | cache(int fd) 9 | { 10 | int argc, i, p[2]; 11 | char *argv[5], bd[32], buf[256], partition[64], *pp; 12 | 13 | if(stat("/boot/cfs", statbuf, sizeof statbuf) < 0) 14 | return fd; 15 | 16 | *partition = 0; 17 | 18 | bind("#S", "/dev", MAFTER); 19 | readfile("#e/cfs", buf, sizeof(buf)); 20 | if(*buf){ 21 | argc = tokenize(buf, argv, 4); 22 | for(i = 0; i < argc; i++){ 23 | if(strcmp(argv[i], "off") == 0) 24 | return fd; 25 | else if(stat(argv[i], statbuf, sizeof statbuf) >= 0){ 26 | strncpy(partition, argv[i], sizeof(partition)-1); 27 | partition[sizeof(partition)-1] = 0; 28 | } 29 | } 30 | } 31 | 32 | if(*partition == 0){ 33 | readfile("#e/bootdisk", bd, sizeof(bd)); 34 | if(*bd){ 35 | if(pp = strchr(bd, ':')) 36 | *pp = 0; 37 | /* damned artificial intelligence */ 38 | i = strlen(bd); 39 | if(strcmp("disk", &bd[i-4]) == 0) 40 | bd[i-4] = 0; 41 | else if(strcmp("fs", &bd[i-2]) == 0) 42 | bd[i-2] = 0; 43 | else if(strcmp("fossil", &bd[i-6]) == 0) 44 | bd[i-6] = 0; 45 | sprint(partition, "%scache", bd); 46 | if(stat(partition, statbuf, sizeof statbuf) < 0) 47 | *bd = 0; 48 | } 49 | if(*bd == 0){ 50 | sprint(partition, "%scache", bootdisk); 51 | if(stat(partition, statbuf, sizeof statbuf) < 0) 52 | return fd; 53 | } 54 | } 55 | 56 | print("cfs..."); 57 | if(pipe(p)<0) 58 | fatal("pipe"); 59 | switch(fork()){ 60 | case -1: 61 | fatal("fork"); 62 | case 0: 63 | close(p[1]); 64 | dup(fd, 0); 65 | close(fd); 66 | dup(p[0], 1); 67 | close(p[0]); 68 | if(fflag) 69 | execl("/boot/cfs", "bootcfs", "-rs", "-f", partition, 0); 70 | else 71 | execl("/boot/cfs", "bootcfs", "-s", "-f", partition, 0); 72 | break; 73 | default: 74 | close(p[0]); 75 | close(fd); 76 | fd = p[1]; 77 | break; 78 | } 79 | return fd; 80 | } 81 | -------------------------------------------------------------------------------- /9K/boot/doauthenticate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../boot/boot.h" 5 | 6 | static char *pbmsg = "AS protocol botch"; 7 | static char *ccmsg = "can't connect to AS"; 8 | 9 | long 10 | readn(int fd, void *buf, long len) 11 | { 12 | int m, n; 13 | char *p; 14 | 15 | p = buf; 16 | for(n = 0; n < len; n += m){ 17 | m = read(fd, p+n, len-n); 18 | if(m <= 0) 19 | return -1; 20 | } 21 | return n; 22 | } 23 | 24 | static char* 25 | fromauth(Method *mp, char *trbuf, char *tbuf) 26 | { 27 | int afd; 28 | char t; 29 | char *msg; 30 | static char error[2*ERRMAX]; 31 | 32 | if(mp->auth == 0) 33 | fatal("no method for accessing auth server"); 34 | afd = (*mp->auth)(); 35 | if(afd < 0) { 36 | sprint(error, "%s: %r", ccmsg); 37 | return error; 38 | } 39 | 40 | if(write(afd, trbuf, TICKREQLEN) < 0 || read(afd, &t, 1) != 1){ 41 | close(afd); 42 | sprint(error, "%s: %r", pbmsg); 43 | return error; 44 | } 45 | switch(t){ 46 | case AuthOK: 47 | msg = 0; 48 | if(readn(afd, tbuf, 2*TICKETLEN) < 0) { 49 | sprint(error, "%s: %r", pbmsg); 50 | msg = error; 51 | } 52 | break; 53 | case AuthErr: 54 | if(readn(afd, error, ERRMAX) < 0) { 55 | sprint(error, "%s: %r", pbmsg); 56 | msg = error; 57 | } 58 | else { 59 | error[ERRMAX-1] = 0; 60 | msg = error; 61 | } 62 | break; 63 | default: 64 | msg = pbmsg; 65 | break; 66 | } 67 | 68 | close(afd); 69 | return msg; 70 | } 71 | 72 | void 73 | doauthenticate(int fd, Method *mp) 74 | { 75 | char *msg; 76 | char trbuf[TICKREQLEN]; 77 | char tbuf[2*TICKETLEN]; 78 | 79 | print("session..."); 80 | if(fsession(fd, trbuf, sizeof trbuf) < 0) 81 | fatal("session command failed"); 82 | 83 | /* no authentication required? */ 84 | memset(tbuf, 0, 2*TICKETLEN); 85 | if(trbuf[0] == 0) 86 | return; 87 | 88 | /* try getting to an auth server */ 89 | print("getting ticket..."); 90 | msg = fromauth(mp, trbuf, tbuf); 91 | print("authenticating..."); 92 | if(msg == 0) 93 | if(fauth(fd, tbuf) >= 0) 94 | return; 95 | 96 | /* didn't work, go for the security hole */ 97 | fprint(2, "no authentication server (%s), using your key as server key\n", msg); 98 | } 99 | 100 | char* 101 | checkkey(Method *mp, char *name, char *key) 102 | { 103 | char *msg; 104 | Ticketreq tr; 105 | Ticket t; 106 | char trbuf[TICKREQLEN]; 107 | char tbuf[TICKETLEN]; 108 | 109 | memset(&tr, 0, sizeof tr); 110 | tr.type = AuthTreq; 111 | strcpy(tr.authid, name); 112 | strcpy(tr.hostid, name); 113 | strcpy(tr.uid, name); 114 | convTR2M(&tr, trbuf); 115 | msg = fromauth(mp, trbuf, tbuf); 116 | if(msg == ccmsg){ 117 | fprint(2, "boot: can't contact auth server, passwd unchecked\n"); 118 | return 0; 119 | } 120 | if(msg) 121 | return msg; 122 | convM2T(tbuf, &t, key); 123 | if(t.num == AuthTc && strcmp(name, t.cuid)==0) 124 | return 0; 125 | return "no match"; 126 | } 127 | -------------------------------------------------------------------------------- /9K/boot/embed.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include <../boot/boot.h> 4 | 5 | static char *paqfile; 6 | 7 | void 8 | configembed(Method *m) 9 | { 10 | if(*sys == '/' || *sys == '#'){ 11 | /* 12 | * if the user specifies the disk in the boot cmd or 13 | * 'root is from' prompt, use it 14 | */ 15 | paqfile = sys; 16 | } else if(m->arg){ 17 | /* 18 | * a default is supplied when the kernel is made 19 | */ 20 | paqfile = m->arg; 21 | } 22 | } 23 | 24 | int 25 | connectembed(void) 26 | { 27 | int i, p[2]; 28 | Dir *dir; 29 | char **arg, **argp; 30 | 31 | dir = dirstat("/boot/paqfs"); 32 | if(dir == nil) 33 | return -1; 34 | free(dir); 35 | 36 | dir = dirstat(paqfile); 37 | if(dir == nil || dir->mode & DMDIR) 38 | return -1; 39 | free(dir); 40 | 41 | print("paqfs..."); 42 | if(bind("#c", "/dev", MREPL) < 0) 43 | fatal("bind #c"); 44 | if(bind("#p", "/proc", MREPL) < 0) 45 | fatal("bind #p"); 46 | if(pipe(p)<0) 47 | fatal("pipe"); 48 | switch(fork()){ 49 | case -1: 50 | fatal("fork"); 51 | case 0: 52 | arg = malloc((bargc+5)*sizeof(char*)); 53 | argp = arg; 54 | *argp++ = "/boot/paqfs"; 55 | *argp++ = "-iv"; 56 | *argp++ = paqfile; 57 | for(i=1; i 2 | #include 3 | #include <../boot/boot.h> 4 | 5 | void 6 | getpasswd(char *p, int len) 7 | { 8 | char c; 9 | int i, n, fd; 10 | 11 | fd = open("#c/consctl", OWRITE); 12 | if(fd < 0) 13 | fatal("can't open consctl; please reboot"); 14 | write(fd, "rawon", 5); 15 | Prompt: 16 | print("password: "); 17 | n = 0; 18 | for(;;){ 19 | do{ 20 | i = read(0, &c, 1); 21 | if(i < 0) 22 | fatal("can't read cons; please reboot"); 23 | }while(i == 0); 24 | switch(c){ 25 | case '\n': 26 | p[n] = '\0'; 27 | close(fd); 28 | print("\n"); 29 | return; 30 | case '\b': 31 | if(n > 0) 32 | n--; 33 | break; 34 | case 'u' - 'a' + 1: /* cntrl-u */ 35 | print("\n"); 36 | goto Prompt; 37 | default: 38 | if(n < len - 1) 39 | p[n++] = c; 40 | break; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /9K/boot/nopsession.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "../boot/boot.h" 6 | 7 | static Fcall hdr; 8 | 9 | static void 10 | rpc(int fd, int type) 11 | { 12 | int n, l; 13 | char buf[128], *p; 14 | 15 | hdr.type = type; 16 | hdr.tag = NOTAG; 17 | n = convS2M(&hdr, buf); 18 | if(write(fd, buf, n) != n) 19 | fatal("write rpc"); 20 | 21 | print("..."); 22 | p = buf; 23 | l = 0; 24 | while(l < 3) { 25 | n = read(fd, p, 3); 26 | if(n <= 0) 27 | fatal("read rpc"); 28 | if(n == 2 && l == 0 && buf[0] == 'O' && buf[1] == 'K') 29 | continue; 30 | p += n; 31 | l += n; 32 | } 33 | if(convM2S(buf, &hdr, n) == 0){ 34 | print("%ux %ux %ux\n", buf[0], buf[1], buf[2]); 35 | fatal("rpc format"); 36 | } 37 | if(hdr.tag != NOTAG) 38 | fatal("rpc tag not NOTAG"); 39 | if(hdr.type == Rerror){ 40 | print("error %s;", hdr.ename); 41 | fatal("remote error"); 42 | } 43 | if(hdr.type != type+1) 44 | fatal("not reply"); 45 | } 46 | 47 | void 48 | nop(int fd) 49 | { 50 | print("nop"); 51 | rpc(fd, Tnop); 52 | } 53 | -------------------------------------------------------------------------------- /9K/boot/paq.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include <../boot/boot.h> 4 | 5 | char *fparts[] = 6 | { 7 | "add bootldr 0x0000000 0x0040000", 8 | "add params 0x0040000 0x0080000", 9 | "add kernel 0x0080000 0x0140000", 10 | "add user 0x0140000 0x0200000", 11 | "add ramdisk 0x0200000 0x0600000", 12 | }; 13 | 14 | void 15 | configpaq(Method*) 16 | { 17 | int fd; 18 | int i; 19 | 20 | if(bind("#F", "/dev", MAFTER) < 0) 21 | fatal("bind #c"); 22 | if(bind("#p", "/proc", MREPL) < 0) 23 | fatal("bind #p"); 24 | fd = open("/dev/flash/flashctl", OWRITE); 25 | if(fd < 0) 26 | fatal("opening flashctl"); 27 | for(i = 0; i < nelem(fparts); i++) 28 | if(fprint(fd, fparts[i]) < 0) 29 | fatal(fparts[i]); 30 | close(fd); 31 | } 32 | 33 | int 34 | connectpaq(void) 35 | { 36 | int p[2]; 37 | char **arg, **argp; 38 | 39 | print("paq..."); 40 | if(pipe(p)<0) 41 | fatal("pipe"); 42 | switch(fork()){ 43 | case -1: 44 | fatal("fork"); 45 | case 0: 46 | arg = malloc(10*sizeof(char*)); 47 | argp = arg; 48 | *argp++ = "paqfs"; 49 | *argp++ = "-v"; 50 | *argp++ = "-i"; 51 | *argp++ = "/dev/flash/ramdisk"; 52 | *argp = 0; 53 | 54 | dup(p[0], 0); 55 | dup(p[1], 1); 56 | close(p[0]); 57 | close(p[1]); 58 | exec("/boot/paqfs", arg); 59 | fatal("can't exec paqfs"); 60 | default: 61 | break; 62 | } 63 | waitpid(); 64 | 65 | close(p[1]); 66 | return p[0]; 67 | } 68 | -------------------------------------------------------------------------------- /9K/boot/printstub.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static Lock fmtl; 5 | 6 | void 7 | _fmtlock(void) 8 | { 9 | lock(&fmtl); 10 | } 11 | 12 | void 13 | _fmtunlock(void) 14 | { 15 | unlock(&fmtl); 16 | } 17 | 18 | int 19 | _efgfmt(Fmt*) 20 | { 21 | return -1; 22 | } 23 | -------------------------------------------------------------------------------- /9K/boot/sac.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include <../boot/boot.h> 4 | 5 | /* 6 | * HACK - take over from boot since file system is not 7 | * available on a pipe 8 | */ 9 | 10 | void 11 | configsac(Method *mp) 12 | { 13 | int fd; 14 | char cmd[64]; 15 | 16 | USED(mp); 17 | 18 | /* 19 | * create the name space, mount the root fs 20 | */ 21 | if(bind("/", "/", MREPL) < 0) 22 | fatal("bind /"); 23 | if(bind("#C", "/", MAFTER) < 0) 24 | fatal("bind /"); 25 | 26 | /* fixed sysname - enables correct namespace file */ 27 | fd = open("#c/sysname", OWRITE); 28 | if(fd < 0) 29 | fatal("open sysname"); 30 | write(fd, "brick", 5); 31 | close(fd); 32 | 33 | fd = open("#c/hostowner", OWRITE); 34 | if(fd < 0) 35 | fatal("open sysname"); 36 | write(fd, "brick", 5); 37 | close(fd); 38 | 39 | sprint(cmd, "/%s/init", cputype); 40 | print("starting %s\n", cmd); 41 | execl(cmd, "init", "-c", 0); 42 | fatal(cmd); 43 | } 44 | 45 | int 46 | connectsac(void) 47 | { 48 | /* does not get here */ 49 | return -1; 50 | } 51 | -------------------------------------------------------------------------------- /9K/ip/chandial.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | #include "../port/error.h" 7 | #include "../ip/ip.h" 8 | 9 | typedef struct DS DS; 10 | static Chan* call(char*, char*, DS*); 11 | static void _dial_string_parse(char*, DS*); 12 | 13 | enum 14 | { 15 | Maxstring= 128, 16 | }; 17 | 18 | struct DS 19 | { 20 | char buf[Maxstring]; /* dist string */ 21 | char *netdir; 22 | char *proto; 23 | char *rem; 24 | char *local; /* other args */ 25 | char *dir; 26 | Chan **ctlp; 27 | }; 28 | 29 | /* 30 | * the dialstring is of the form '[/net/]proto!dest' 31 | */ 32 | Chan* 33 | chandial(char *dest, char *local, char *dir, Chan **ctlp) 34 | { 35 | DS ds; 36 | char clone[Maxpath]; 37 | 38 | ds.local = local; 39 | ds.dir = dir; 40 | ds.ctlp = ctlp; 41 | 42 | _dial_string_parse(dest, &ds); 43 | if(ds.netdir == 0) 44 | ds.netdir = "/net"; 45 | 46 | /* no connection server, don't translate */ 47 | snprint(clone, sizeof(clone), "%s/%s/clone", ds.netdir, ds.proto); 48 | return call(clone, ds.rem, &ds); 49 | } 50 | 51 | static Chan* 52 | call(char *clone, char *dest, DS *ds) 53 | { 54 | int n; 55 | Chan *dchan, *cchan; 56 | char name[Maxpath], data[Maxpath], *p; 57 | 58 | cchan = namec(clone, Aopen, ORDWR, 0); 59 | 60 | /* get directory name */ 61 | if(waserror()){ 62 | cclose(cchan); 63 | nexterror(); 64 | } 65 | n = cchan->dev->read(cchan, name, sizeof(name)-1, 0); 66 | name[n] = 0; 67 | for(p = name; *p == ' '; p++) 68 | ; 69 | sprint(name, "%lud", strtoul(p, 0, 0)); 70 | p = strrchr(clone, '/'); 71 | *p = 0; 72 | if(ds->dir) 73 | snprint(ds->dir, Maxpath, "%s/%s", clone, name); 74 | snprint(data, sizeof(data), "%s/%s/data", clone, name); 75 | 76 | /* connect */ 77 | if(ds->local) 78 | snprint(name, sizeof(name), "connect %s %s", dest, ds->local); 79 | else 80 | snprint(name, sizeof(name), "connect %s", dest); 81 | cchan->dev->write(cchan, name, strlen(name), 0); 82 | 83 | /* open data connection */ 84 | dchan = namec(data, Aopen, ORDWR, 0); 85 | if(ds->ctlp) 86 | *ds->ctlp = cchan; 87 | else 88 | cclose(cchan); 89 | poperror(); 90 | return dchan; 91 | 92 | } 93 | 94 | /* 95 | * parse a dial string 96 | */ 97 | static void 98 | _dial_string_parse(char *str, DS *ds) 99 | { 100 | char *p, *p2; 101 | 102 | strncpy(ds->buf, str, Maxstring); 103 | ds->buf[Maxstring-1] = 0; 104 | 105 | p = strchr(ds->buf, '!'); 106 | if(p == 0) { 107 | ds->netdir = 0; 108 | ds->proto = "net"; 109 | ds->rem = ds->buf; 110 | } else { 111 | if(*ds->buf != '/' && *ds->buf != '#'){ 112 | ds->netdir = 0; 113 | ds->proto = ds->buf; 114 | } else { 115 | for(p2 = p; *p2 != '/'; p2--) 116 | ; 117 | *p2++ = 0; 118 | ds->netdir = ds->buf; 119 | ds->proto = p2; 120 | } 121 | *p = 0; 122 | ds->rem = p + 1; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /9K/ip/loopbackmedium.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | #include "../port/error.h" 7 | 8 | #include "ip.h" 9 | 10 | enum 11 | { 12 | Maxtu= 16*1024, 13 | }; 14 | 15 | typedef struct LB LB; 16 | struct LB 17 | { 18 | Proc *readp; 19 | Queue *q; 20 | Fs *f; 21 | }; 22 | 23 | static void loopbackread(void *a); 24 | 25 | static void 26 | loopbackbind(Ipifc *ifc, int, char**) 27 | { 28 | LB *lb; 29 | 30 | lb = smalloc(sizeof(*lb)); 31 | lb->f = ifc->conv->p->f; 32 | lb->q = qopen(1024*1024, Qmsg, nil, nil); 33 | ifc->arg = lb; 34 | ifc->mbps = 10000; 35 | 36 | kproc("loopbackread", loopbackread, ifc); 37 | 38 | } 39 | 40 | static void 41 | loopbackunbind(Ipifc *ifc) 42 | { 43 | LB *lb = ifc->arg; 44 | 45 | if(lb->readp) 46 | postnote(lb->readp, 1, "unbind", 0); 47 | 48 | /* wait for reader to die */ 49 | while(lb->readp != 0) 50 | tsleep(&up->sleep, return0, 0, 300); 51 | 52 | /* clean up */ 53 | qfree(lb->q); 54 | free(lb); 55 | } 56 | 57 | static void 58 | loopbackbwrite(Ipifc *ifc, Block *bp, int, uchar*) 59 | { 60 | LB *lb; 61 | 62 | lb = ifc->arg; 63 | if(qpass(lb->q, bp) < 0) 64 | ifc->outerr++; 65 | ifc->out++; 66 | } 67 | 68 | static void 69 | loopbackread(void *a) 70 | { 71 | Ipifc *ifc; 72 | Block *bp; 73 | LB *lb; 74 | 75 | ifc = a; 76 | lb = ifc->arg; 77 | lb->readp = up; /* hide identity under a rock for unbind */ 78 | if(waserror()){ 79 | lb->readp = 0; 80 | pexit("hangup", 1); 81 | } 82 | for(;;){ 83 | bp = qbread(lb->q, Maxtu); 84 | if(bp == nil) 85 | continue; 86 | ifc->in++; 87 | if(!canrlock(ifc)){ 88 | freeb(bp); 89 | continue; 90 | } 91 | if(waserror()){ 92 | runlock(ifc); 93 | nexterror(); 94 | } 95 | if(ifc->lifc == nil) 96 | freeb(bp); 97 | else 98 | ipiput4(lb->f, ifc, bp); 99 | runlock(ifc); 100 | poperror(); 101 | } 102 | } 103 | 104 | Medium loopbackmedium = 105 | { 106 | .hsize= 0, 107 | .mintu= 0, 108 | .maxtu= Maxtu, 109 | .maclen= 0, 110 | .name= "loopback", 111 | .bind= loopbackbind, 112 | .unbind= loopbackunbind, 113 | .bwrite= loopbackbwrite, 114 | }; 115 | 116 | void 117 | loopbackmediumlink(void) 118 | { 119 | addipmedium(&loopbackmedium); 120 | } 121 | -------------------------------------------------------------------------------- /9K/ip/nullmedium.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | #include "../port/error.h" 7 | 8 | #include "ip.h" 9 | 10 | static void 11 | nullbind(Ipifc*, int, char**) 12 | { 13 | error("cannot bind null device"); 14 | } 15 | 16 | static void 17 | nullunbind(Ipifc*) 18 | { 19 | } 20 | 21 | static void 22 | nullbwrite(Ipifc*, Block*, int, uchar*) 23 | { 24 | error("nullbwrite"); 25 | } 26 | 27 | Medium nullmedium = 28 | { 29 | .name= "null", 30 | .bind= nullbind, 31 | .unbind= nullunbind, 32 | .bwrite= nullbwrite, 33 | }; 34 | 35 | void 36 | nullmediumlink(void) 37 | { 38 | addipmedium(&nullmedium); 39 | } 40 | -------------------------------------------------------------------------------- /9K/ip/pktmedium.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | #include "../port/error.h" 7 | 8 | #include "ip.h" 9 | 10 | 11 | static void pktbind(Ipifc*, int, char**); 12 | static void pktunbind(Ipifc*); 13 | static void pktbwrite(Ipifc*, Block*, int, uchar*); 14 | static void pktin(Fs*, Ipifc*, Block*); 15 | 16 | Medium pktmedium = 17 | { 18 | .name= "pkt", 19 | .hsize= 14, 20 | .mintu= 40, 21 | .maxtu= 4*1024, 22 | .maclen= 6, 23 | .bind= pktbind, 24 | .unbind= pktunbind, 25 | .bwrite= pktbwrite, 26 | .pktin= pktin, 27 | }; 28 | 29 | /* 30 | * called to bind an IP ifc to an ethernet device 31 | * called with ifc wlock'd 32 | */ 33 | static void 34 | pktbind(Ipifc*, int argc, char **argv) 35 | { 36 | USED(argc, argv); 37 | } 38 | 39 | /* 40 | * called with ifc wlock'd 41 | */ 42 | static void 43 | pktunbind(Ipifc*) 44 | { 45 | } 46 | 47 | /* 48 | * called by ipoput with a single packet to write 49 | */ 50 | static void 51 | pktbwrite(Ipifc *ifc, Block *bp, int, uchar*) 52 | { 53 | /* enqueue onto the conversation's rq */ 54 | bp = concatblock(bp); 55 | if(ifc->conv->snoopers.ref > 0) 56 | qpass(ifc->conv->sq, copyblock(bp, BLEN(bp))); 57 | qpass(ifc->conv->rq, bp); 58 | } 59 | 60 | /* 61 | * called with ifc rlocked when someone write's to 'data' 62 | */ 63 | static void 64 | pktin(Fs *f, Ipifc *ifc, Block *bp) 65 | { 66 | if(ifc->lifc == nil) 67 | freeb(bp); 68 | else { 69 | if(ifc->conv->snoopers.ref > 0) 70 | qpass(ifc->conv->sq, copyblock(bp, BLEN(bp))); 71 | ipiput4(f, ifc, bp); 72 | } 73 | } 74 | 75 | void 76 | pktmediumlink(void) 77 | { 78 | addipmedium(&pktmedium); 79 | } 80 | -------------------------------------------------------------------------------- /9K/ip/ptclbsum.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | #include "../port/error.h" 7 | #include "ip.h" 8 | 9 | static short endian = 1; 10 | static uchar* aendian = (uchar*)&endian; 11 | #define LITTLE *aendian 12 | 13 | ushort 14 | ptclbsum(uchar *addr, int len) 15 | { 16 | ulong losum, hisum, mdsum, x; 17 | ulong t1, t2; 18 | 19 | losum = 0; 20 | hisum = 0; 21 | mdsum = 0; 22 | 23 | x = 0; 24 | if(PTR2UINT(addr) & 1) { 25 | if(len) { 26 | hisum += addr[0]; 27 | len--; 28 | addr++; 29 | } 30 | x = 1; 31 | } 32 | while(len >= 16) { 33 | t1 = *(ushort*)(addr+0); 34 | t2 = *(ushort*)(addr+2); mdsum += t1; 35 | t1 = *(ushort*)(addr+4); mdsum += t2; 36 | t2 = *(ushort*)(addr+6); mdsum += t1; 37 | t1 = *(ushort*)(addr+8); mdsum += t2; 38 | t2 = *(ushort*)(addr+10); mdsum += t1; 39 | t1 = *(ushort*)(addr+12); mdsum += t2; 40 | t2 = *(ushort*)(addr+14); mdsum += t1; 41 | mdsum += t2; 42 | len -= 16; 43 | addr += 16; 44 | } 45 | while(len >= 2) { 46 | mdsum += *(ushort*)addr; 47 | len -= 2; 48 | addr += 2; 49 | } 50 | if(x) { 51 | if(len) 52 | losum += addr[0]; 53 | if(LITTLE) 54 | losum += mdsum; 55 | else 56 | hisum += mdsum; 57 | } else { 58 | if(len) 59 | hisum += addr[0]; 60 | if(LITTLE) 61 | hisum += mdsum; 62 | else 63 | losum += mdsum; 64 | } 65 | 66 | losum += hisum >> 8; 67 | losum += (hisum & 0xff) << 8; 68 | while(hisum = losum>>16) 69 | losum = hisum + (losum & 0xffff); 70 | 71 | return losum & 0xffff; 72 | } 73 | -------------------------------------------------------------------------------- /9K/k10/acpi.h: -------------------------------------------------------------------------------- 1 | typedef struct Fadt Fadt; 2 | typedef struct Gas Gas; 3 | typedef struct Tbl Tbl; 4 | 5 | typedef struct Acpicfg Acpicfg; 6 | 7 | /* 8 | * Header for ACPI description tables 9 | */ 10 | struct Tbl { 11 | uchar sig[4]; /* e.g. "FACP" */ 12 | uchar len[4]; 13 | uchar rev; 14 | uchar csum; 15 | uchar oemid[6]; 16 | uchar oemtblid[8]; 17 | uchar oemrev[4]; 18 | uchar creatorid[4]; 19 | uchar creatorrev[4]; 20 | uchar data[]; 21 | }; 22 | 23 | /* 24 | * Generic address structure. 25 | */ 26 | struct Gas 27 | { 28 | uchar spc; /* address space id */ 29 | uchar len; /* register size in bits */ 30 | uchar off; /* bit offset */ 31 | uchar accsz; /* 1: byte; 2: word; 3: dword; 4: qword */ 32 | u64int addr; /* address (or acpi encoded tbdf + reg) */ 33 | }; 34 | 35 | /* 36 | * Fixed ACPI description table. 37 | */ 38 | struct Fadt { 39 | int rev; 40 | 41 | u32int facs; 42 | u32int dsdt; 43 | uchar pmprofile; 44 | u16int sciint; 45 | u32int smicmd; 46 | uchar acpienable; 47 | uchar acpidisable; 48 | uchar s4biosreq; 49 | uchar pstatecnt; 50 | u32int pm1aevtblk; 51 | u32int pm1bevtblk; 52 | u32int pm1acntblk; 53 | u32int pm1bcntblk; 54 | u32int pm2cntblk; 55 | u32int pmtmrblk; 56 | u32int gpe0blk; 57 | u32int gpe1blk; 58 | uchar pm1evtlen; 59 | uchar pm1cntlen; 60 | uchar pm2cntlen; 61 | uchar pmtmrlen; 62 | uchar gpe0blklen; 63 | uchar gpe1blklen; 64 | uchar gp1base; 65 | uchar cstcnt; 66 | u16int plvl2lat; 67 | u16int plvl3lat; 68 | u16int flushsz; 69 | u16int flushstride; 70 | uchar dutyoff; 71 | uchar dutywidth; 72 | uchar dayalrm; 73 | uchar monalrm; 74 | uchar century; 75 | u16int iapcbootarch; 76 | u32int flags; 77 | Gas resetreg; 78 | uchar resetval; 79 | u64int xfacs; 80 | u64int xdsdt; 81 | Gas xpm1aevtblk; 82 | Gas xpm1bevtblk; 83 | Gas xpm1acntblk; 84 | Gas xpm1bcntblk; 85 | Gas xpm2cntblk; 86 | Gas xpmtmrblk; 87 | Gas xgpe0blk; 88 | Gas xgpe1blk; 89 | }; 90 | #pragma varargck type "G" Gas* 91 | 92 | struct Acpicfg { 93 | uint sval[6][2]; /* p1a.ctl, p1b.ctl */ 94 | }; 95 | 96 | Tbl* acpigettbl(void*); 97 | 98 | extern Fadt fadt; 99 | extern Acpicfg acpicfg; 100 | 101 | extern void hpetinit(uint, uint, uintmem, int); 102 | 103 | enum{ 104 | MemHotPlug= 1<<1, 105 | MemNonVolatile= 1<<2, 106 | }; 107 | extern void memaffinity(u64int, u64int, u32int, int); 108 | 109 | /* 110 | * ACPI 4.0 E820 AddressRange types (table 14-1) 111 | */ 112 | enum { 113 | AddrsNone = 0, 114 | AddrsMemory = 1, 115 | AddrsReserved = 2, 116 | AddrsACPI = 3, 117 | AddrsNVS = 4, 118 | AddrsUnusable = 5, 119 | AddrsDisabled = 6, 120 | 121 | AddrsDEV = 9, /* our internal code */ 122 | 123 | AddrsNVDIMM = 0x5a, /* Viking NVDIMM */ 124 | 125 | /* extended attribute flags, not currently used */ 126 | AddrsNonVolatile = 1<<1, 127 | AddrsSlowAccess = 1<<2, 128 | AddrsErrorLog = 1<<3, 129 | }; 130 | -------------------------------------------------------------------------------- /9K/k10/adr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ycui1984/enhanced-plan9/372cbf8cee7689c372e7dcfb21580220a79daf2f/9K/k10/adr.h -------------------------------------------------------------------------------- /9K/k10/arch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * EPISODE 12B 3 | * How to recognise different types of trees from quite a long way away. 4 | * NO. 1 5 | * THE LARCH 6 | */ 7 | #include "u.h" 8 | #include "../port/lib.h" 9 | #include "mem.h" 10 | #include "dat.h" 11 | #include "fns.h" 12 | #include "../port/error.h" 13 | 14 | void 15 | procrestore(Proc *p) 16 | { 17 | uvlong t; 18 | 19 | if(p->kp) 20 | return; 21 | cycles(&t); 22 | p->pcycles -= t; 23 | 24 | fpuprocrestore(p); 25 | } 26 | 27 | /* 28 | * Save the mach dependent part of the process state. 29 | */ 30 | void 31 | procsave(Proc *p) 32 | { 33 | uvlong t; 34 | 35 | cycles(&t); 36 | p->pcycles += t; 37 | 38 | fpuprocsave(p); 39 | 40 | /* 41 | */ 42 | mmuflushtlb(m->pml4->pa); 43 | } 44 | 45 | static void 46 | linkproc(void) 47 | { 48 | spllo(); 49 | up->kpfun(up->kparg); 50 | pexit("kproc dying", 0); 51 | } 52 | 53 | void 54 | kprocchild(Proc* p, void (*func)(void*), void* arg) 55 | { 56 | /* 57 | * gotolabel() needs a word on the stack in 58 | * which to place the return PC used to jump 59 | * to linkproc(). 60 | */ 61 | p->sched.pc = PTR2UINT(linkproc); 62 | p->sched.sp = PTR2UINT(p->kstack+KSTACK-BY2SE); 63 | p->sched.sp = STACKALIGN(p->sched.sp); 64 | 65 | p->kpfun = func; 66 | p->kparg = arg; 67 | } 68 | 69 | /* 70 | * put the processor in the halt state if we've no processes to run. 71 | * an interrupt will get us going again. 72 | */ 73 | void 74 | idlehands(void) 75 | { 76 | if(sys->nonline == 1) 77 | halt(); 78 | } 79 | -------------------------------------------------------------------------------- /9K/k10/cga.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | 7 | enum { 8 | Black = 0x00, 9 | Blue = 0x01, 10 | Green = 0x02, 11 | Cyan = 0x03, 12 | Red = 0x04, 13 | Magenta = 0x05, 14 | Brown = 0x06, 15 | Grey = 0x07, 16 | 17 | Bright = 0x08, 18 | Blinking = 0x80, 19 | 20 | Attr = (Black<<4)|Grey, /* (background<<4)|foreground */ 21 | }; 22 | 23 | enum { 24 | Index = 0x3d4, 25 | Data = Index+1, 26 | 27 | Width = 80*2, 28 | Height = 25, 29 | 30 | Poststrlen = 0, 31 | Postcodelen = 2, 32 | Postlen = Poststrlen+Postcodelen, 33 | }; 34 | 35 | #define CGA (BIOSSEG(0xb800)) 36 | 37 | static Lock cgalock; 38 | static int cgapos; 39 | static int cgainitdone; 40 | 41 | static int 42 | cgaregr(int index) 43 | { 44 | outb(Index, index); 45 | return inb(Data) & 0xff; 46 | } 47 | 48 | static void 49 | cgaregw(int index, int data) 50 | { 51 | outb(Index, index); 52 | outb(Data, data); 53 | } 54 | 55 | static void 56 | cgacursor(void) 57 | { 58 | uchar *cga; 59 | 60 | cgaregw(0x0e, (cgapos/2>>8) & 0xff); 61 | cgaregw(0x0f, cgapos/2 & 0xff); 62 | 63 | cga = CGA; 64 | cga[cgapos+1] = Attr; 65 | } 66 | 67 | static void 68 | cgaputc(int c) 69 | { 70 | int i; 71 | uchar *cga, *p; 72 | 73 | cga = CGA; 74 | 75 | if(c == '\n'){ 76 | cgapos = cgapos/Width; 77 | cgapos = (cgapos+1)*Width; 78 | } 79 | else if(c == '\t'){ 80 | i = 8 - ((cgapos/2)&7); 81 | while(i-- > 0) 82 | cgaputc(' '); 83 | } 84 | else if(c == '\b'){ 85 | if(cgapos >= 2) 86 | cgapos -= 2; 87 | cgaputc(' '); 88 | cgapos -= 2; 89 | } 90 | else{ 91 | cga[cgapos++] = c; 92 | cga[cgapos++] = Attr; 93 | } 94 | if(cgapos >= (Width*Height)-Postlen*2){ 95 | memmove(cga, &cga[Width], Width*(Height-1)); 96 | p = &cga[Width*(Height-1)-Postlen*2]; 97 | for(i = 0; i < Width/2; i++){ 98 | *p++ = ' '; 99 | *p++ = Attr; 100 | } 101 | cgapos -= Width; 102 | } 103 | cgacursor(); 104 | } 105 | 106 | void 107 | cgaconsputs(char* s, int n) 108 | { 109 | ilock(&cgalock); 110 | while(n-- > 0) 111 | cgaputc(*s++); 112 | iunlock(&cgalock); 113 | } 114 | 115 | void 116 | cgapost(int code) 117 | { 118 | uchar *cga; 119 | 120 | static char hex[] = "0123456789ABCDEF"; 121 | 122 | cga = CGA; 123 | cga[Width*Height-Postcodelen*2] = hex[(code>>4) & 0x0f]; 124 | cga[Width*Height-Postcodelen*2+1] = Attr; 125 | cga[Width*Height-Postcodelen*2+2] = hex[code & 0x0f]; 126 | cga[Width*Height-Postcodelen*2+3] = Attr; 127 | } 128 | 129 | void 130 | cgainit(void) 131 | { 132 | ilock(&cgalock); 133 | cgapos = cgaregr(0x0e)<<8; 134 | cgapos |= cgaregr(0x0f); 135 | cgapos *= 2; 136 | cgainitdone = 1; 137 | iunlock(&cgalock); 138 | } 139 | -------------------------------------------------------------------------------- /9K/k10/devkbin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * keyboard scan code input from outside the kernel. 3 | * to avoid duplication of keyboard map processing for usb. 4 | */ 5 | 6 | #include "u.h" 7 | #include "../port/lib.h" 8 | #include "mem.h" 9 | #include "dat.h" 10 | #include "fns.h" 11 | #include "../port/error.h" 12 | 13 | extern void kbdputsc(int, int); 14 | 15 | enum { 16 | Qdir, 17 | Qkbd, 18 | }; 19 | 20 | Dirtab kbintab[] = { 21 | ".", {Qdir, 0, QTDIR}, 0, 0555, 22 | "kbin", {Qkbd, 0, QTEXCL}, 0, DMEXCL|0200, 23 | }; 24 | 25 | static ulong kbinbusy; /* test and set whether /dev/kbin is open */ 26 | 27 | static Chan * 28 | kbinattach(char *spec) 29 | { 30 | return devattach(L'Ι', spec); 31 | } 32 | 33 | static Walkqid* 34 | kbinwalk(Chan *c, Chan *nc, char **name, int nname) 35 | { 36 | return devwalk(c, nc, name, nname, kbintab, nelem(kbintab), devgen); 37 | } 38 | 39 | static long 40 | kbinstat(Chan *c, uchar *dp, long n) 41 | { 42 | return devstat(c, dp, n, kbintab, nelem(kbintab), devgen); 43 | } 44 | 45 | static Chan* 46 | kbinopen(Chan *c, int omode) 47 | { 48 | c = devopen(c, omode, kbintab, nelem(kbintab), devgen); 49 | if(c->qid.path == Qkbd && 50 | tas32(&kbinbusy) != 0){ 51 | c->flag &= ~COPEN; 52 | error(Einuse); 53 | } 54 | return c; 55 | } 56 | 57 | static void 58 | kbinclose(Chan *c) 59 | { 60 | if((c->flag & COPEN) == 0) 61 | return; 62 | if(c->aux){ 63 | free(c->aux); 64 | c->aux = nil; 65 | } 66 | if(c->qid.path == Qkbd) 67 | kbinbusy = 0; 68 | } 69 | 70 | static long 71 | kbinread(Chan *c, void *a, long n, vlong ) 72 | { 73 | if(c->qid.type & QTDIR) 74 | return devdirread(c, a, n, kbintab, nelem(kbintab), devgen); 75 | return 0; 76 | } 77 | 78 | static long 79 | kbinwrite(Chan *c, void *a, long n, vlong) 80 | { 81 | int i; 82 | uchar *p; 83 | 84 | if(c->qid.type & QTDIR) 85 | error(Eisdir); 86 | switch((int)c->qid.path){ 87 | case Qkbd: 88 | p = a; 89 | for(i = 0; i < n; i++) 90 | kbdputsc(*p++, 1); /* external source */ 91 | break; 92 | default: 93 | error(Egreg); 94 | } 95 | return n; 96 | } 97 | 98 | Dev kbindevtab = { 99 | L'Ι', 100 | "kbin", 101 | 102 | devreset, 103 | devinit, 104 | devshutdown, 105 | kbinattach, 106 | kbinwalk, 107 | kbinstat, 108 | kbinopen, 109 | devcreate, 110 | kbinclose, 111 | kbinread, 112 | // devreadv, 113 | devbread, 114 | kbinwrite, 115 | // devwritev, 116 | devbwrite, 117 | devremove, 118 | devwstat, 119 | }; 120 | -------------------------------------------------------------------------------- /9K/k10/etherif.h: -------------------------------------------------------------------------------- 1 | enum 2 | { 3 | Eaddrlen = 6, 4 | ETHERMINTU = 60, /* minimum transmit size */ 5 | ETHERMAXTU = 1514, /* maximum transmit size */ 6 | ETHERHDRSIZE = 14, /* size of an ethernet header */ 7 | 8 | MaxEther = 48, 9 | Ntypes = 16, 10 | }; 11 | 12 | typedef struct Ether Ether; 13 | struct Ether { 14 | ISAConf; /* hardware info */ 15 | 16 | int ctlrno; 17 | int minmtu; 18 | int maxmtu; 19 | uchar ea[Eaddrlen]; 20 | 21 | void (*attach)(Ether*); /* filled in by reset routine */ 22 | void (*detach)(Ether*); 23 | void (*transmit)(Ether*); 24 | void (*interrupt)(Ureg*, void*); 25 | long (*ifstat)(Ether*, void*, long, ulong); 26 | long (*ctl)(Ether*, void*, long); /* custom ctl messages */ 27 | void (*power)(Ether*, int); /* power on/off */ 28 | void (*shutdown)(Ether*); /* shutdown hardware before reboot */ 29 | void *ctlr; 30 | void *vector; 31 | 32 | int scan[Ntypes]; /* base station scanning interval */ 33 | int nscan; /* number of base station scanners */ 34 | 35 | Netif; 36 | }; 37 | 38 | typedef struct Etherpkt Etherpkt; 39 | struct Etherpkt 40 | { 41 | uchar d[Eaddrlen]; 42 | uchar s[Eaddrlen]; 43 | uchar type[2]; 44 | uchar data[1500]; 45 | }; 46 | 47 | extern Block* etheriq(Ether*, Block*, int); 48 | extern void addethercard(char*, int(*)(Ether*)); 49 | extern ulong ethercrc(uchar*, int); 50 | extern int parseether(uchar*, char*); 51 | extern int ethercfgmatch(Ether*, Pcidev*, uintmem); 52 | 53 | #define NEXT(x, l) (((x)+1)%(l)) 54 | #define PREV(x, l) (((x) == 0) ? (l)-1: (x)-1) 55 | 56 | extern Ether* etherc2e(Chan*); 57 | -------------------------------------------------------------------------------- /9K/k10/hpet.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | #include "io.h" 7 | #include "ureg.h" 8 | #include "../port/error.h" 9 | 10 | typedef struct Hpet Hpet; 11 | typedef struct Tn Tn; 12 | 13 | struct Hpet { /* Event Timer Block */ 14 | u32int cap; /* General Capabilities */ 15 | u32int period; /* Main Counter Tick Period */ 16 | u32int _8_[2]; 17 | u32int cnf; /* General Configuration */ 18 | u32int _20_[3]; 19 | u32int sts; /* General Interrupt Status */ 20 | u32int _36_[51]; 21 | u64int counter; /* Main Counter Value */ 22 | u32int _248[2]; 23 | Tn tn[]; /* Timers */ 24 | }; 25 | 26 | struct Tn { /* Timer */ 27 | u32int cnf; /* Configuration */ 28 | u32int cap; /* Capabilities */ 29 | u64int comparator; /* Comparator */ 30 | u32int val; /* FSB Interrupt Value */ 31 | u32int addr; /* FSB Interrupt Address */ 32 | u32int _24_[2]; 33 | }; 34 | 35 | static Hpet* etb[8]; /* Event Timer Blocks */ 36 | static u64int zerostamp; 37 | static u64int *stamper = &zerostamp; /* hpet counter used for time stamps, or 0 if no hpet */ 38 | static u32int period; /* period of active hpet */ 39 | 40 | uvlong 41 | hpetticks(uvlong*) 42 | { 43 | return *stamper; 44 | } 45 | 46 | uvlong 47 | hpetticks2ns(uvlong ticks) 48 | { 49 | return ticks*period / 1000 / 1000; 50 | } 51 | 52 | uvlong 53 | hpetticks2us(uvlong ticks) 54 | { 55 | return hpetticks2ns(ticks) / 1000; 56 | } 57 | 58 | /* 59 | * called from acpi 60 | */ 61 | void 62 | hpetinit(uint id, uint seqno, uintmem pa, int minticks) 63 | { 64 | Tn *tn; 65 | int i, n; 66 | Hpet *hpet; 67 | 68 | print("hpet: id %#ux seqno %d pa %#P minticks %d\n", id, seqno, pa, minticks); 69 | if(seqno >= nelem(etb)) 70 | return; 71 | if((hpet = vmap(pa, 1024)) == nil) /* HPET §3.2.4 */ 72 | return; 73 | memreserve(pa, 1024); 74 | etb[seqno] = hpet; 75 | 76 | print("HPET: cap %#8.8ux period %#8.8ux\n", hpet->cap, hpet->period); 77 | print("HPET: cnf %#8.8ux sts %#8.8ux\n",hpet->cnf, hpet->sts); 78 | print("HPET: counter %#.16llux\n", hpet->counter); 79 | 80 | n = ((hpet->cap>>8) & 0x0F) + 1; 81 | for(i = 0; i < n; i++){ 82 | tn = &hpet->tn[i]; 83 | DBG("Tn%d: cnf %#8.8ux cap %#8.8ux\n", i, tn->cnf, tn->cap); 84 | DBG("Tn%d: comparator %#.16llux\n", i, tn->comparator); 85 | DBG("Tn%d: val %#8.8ux addr %#8.8ux\n", i, tn->val, tn->addr); 86 | USED(tn); 87 | } 88 | /* 89 | * hpet->period is the number of femtoseconds per counter tick. 90 | */ 91 | 92 | /* 93 | * activate the first hpet as the source of time stamps 94 | */ 95 | if(seqno == 0){ 96 | period = hpet->period; 97 | stamper = &hpet->counter; 98 | /* the timer block must be enabled to start the main counter for timestamping */ 99 | hpet->cap |= 1<<0; /* ENABLE_CNF */ 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /9K/k10/init9.c: -------------------------------------------------------------------------------- 1 | extern void startboot(char*, char**); 2 | 3 | void 4 | main(char* argv0) 5 | { 6 | startboot(argv0, &argv0); 7 | } 8 | -------------------------------------------------------------------------------- /9K/k10/intrmon.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | 7 | enum { 8 | Nalarm = 3*1000, /* alarm when interrupt has run for this long */ 9 | }; 10 | 11 | typedef struct Mon Mon; 12 | struct Mon { 13 | ulong tk; /* tick of mach entry */ 14 | ulong ltk; /* local tick we started tracking it */ 15 | }; 16 | 17 | static void intrmon(Ureg*, Timer*); 18 | 19 | /* 20 | * This code relies on sys->nmach being set properly. Do not call intrmoninit on 21 | * any processor until *ncpu/nmach has been sorted. 22 | */ 23 | void 24 | intrmoninit(void) 25 | { 26 | Timer *t; 27 | 28 | m->intrmon.mon = mallocz(sys->nmach * sizeof (Mon), 1); 29 | if(m->intrmon.mon == nil) { 30 | iprint("intrmoninit: mon alloc failure for cpu%d\n", m->machno); 31 | return; 32 | } 33 | 34 | t = malloc(sizeof(*t)); 35 | t->tmode = Trelative; 36 | t->tt = nil; 37 | /* 38 | * stagger out the timers by mach no to start in 39 | * order to get one running per second 40 | */ 41 | t->tns = m->machno*1000*1000*1000; 42 | t->tf = intrmon; 43 | timeradd(t); 44 | } 45 | 46 | static void 47 | intrmon(Ureg*, Timer *t) 48 | { 49 | Mon *mon; 50 | Mach *mp; 51 | ulong tk; 52 | int i; 53 | Mpl s; 54 | 55 | s = splhi(); 56 | 57 | /* reset timer from startup to scaled out by # procs */ 58 | t->tmode = Tperiodic; 59 | t->tns = sys->nmach*1000*1000*1000; 60 | 61 | mon = m->intrmon.mon; /* my personal monitor array to protect others */ 62 | for(i = 0; i < sys->nmach; i++){ 63 | mp = sys->machptr[i]; 64 | if(mp == nil || !mp->online) 65 | continue; 66 | tk = mp->intrmon.tk; 67 | if(tk == 0 || tk != mon[i].tk){ 68 | mon[i].tk = tk; 69 | mon[i].ltk = m->ticks; 70 | continue; 71 | } 72 | if(TK2MS(m->ticks - mon[i].ltk) < Nalarm) 73 | continue; 74 | /* Lazy avoid multiple cpus reporting the same condition. */ 75 | mp->intrmon.tk++; 76 | xdpanic("cpu%d intr watchdog(%d): tk %ld vno %d fn 0x%ulx\n", 77 | i, m->machno, mp->intrmon.tk, mp->intrmon.vno, 78 | mp->intrmon.fn); 79 | } 80 | splx(s); 81 | } 82 | -------------------------------------------------------------------------------- /9K/k10/k10cpu: -------------------------------------------------------------------------------- 1 | dev +dev 2 | root 3 | cons uidgid 4 | arch 5 | env 6 | pipe 7 | proc 8 | mnt 9 | pci pci 10 | srv 11 | dup 12 | rtc 13 | ssl 14 | cap 15 | kprof 16 | 17 | ether netif 18 | ip arp chandial ip ipv6 ipaux iproute netlog nullmedium pktmedium ptclbsumamd64 19 | 20 | uart 21 | usb 22 | # kbin 23 | acpi hpet acpi lapic ioapic msi sipi 24 | sd 25 | mem 26 | 27 | 28 | uart +dev 29 | uarti8250 30 | uartpci pci 31 | 32 | ip +dev 33 | il 34 | tcp 35 | udp 36 | ipifc 37 | icmp 38 | icmp6 39 | 40 | link +dev 41 | ether8139 pci 42 | ether8169 pci ethermii 43 | ether82557 pci 44 | ether82563 pci 45 | ether82598 pci 46 | etherigbe pci ethermii 47 | ethermedium 48 | loopbackmedium 49 | netdevmedium 50 | 51 | usbuhci 52 | usbohci 53 | usbehci usbehcipc 54 | 55 | # acpi hpet 56 | # ht 57 | 58 | misc +dev 59 | nocache 60 | 61 | sd +dev 62 | sdiahci sdscsi 63 | sdata sdscsi 64 | # sdide pci sdscsi 65 | 66 | #boot cpu 67 | # int cpuflag = 1; 68 | #boot cpu boot $3 69 | # int cpuflag = 1; 70 | # char* bootdisk = "$3"; 71 | #boot rootdir $3 72 | # char* rootdir = "$3"; 73 | #boot (bboot|romboot|dosboot) 74 | # int cpuflag = 1; 75 | # char* bootprog = $2; 76 | #boot boot $3 77 | # char* bootdisk = "$3"; 78 | # 79 | boot cpu 80 | tcp 81 | il 82 | 83 | rootdir 84 | bootk10cpu.out boot 85 | /amd64/bin/auth/factotum factotum 86 | /amd64/bin/ip/ipconfig ipconfig 87 | 88 | conf 89 | int cpuserver = 1; 90 | 91 | # 92 | #dbgflg 93 | # chan 'c' 94 | # apic 'A' 95 | # acpi 'C' 96 | # hpet 'H' 97 | # ht 'H' 98 | # ioapic 'I' 99 | # mp 'M' 100 | # pci 'P' 101 | # arch 'V' 102 | # 103 | dbgflg 104 | lapic 'A' 105 | acpi 'C' 106 | devacpi 'C' 107 | hpet 'H' 108 | ht 'H' 109 | ioapic 'I' 110 | mp 'M' 111 | arch 'V' 112 | archk10 'V' 113 | sysproc 'E' 114 | main 'x' 115 | mmu 'm' 116 | sipi 'y' 117 | sysseg 's' 118 | physalloc 'p' 119 | qmalloc 'q' 120 | 121 | amd64 +dev 122 | l32p 123 | l64v 124 | l64idt 125 | l64syscall 126 | l64fpu 127 | l64cpuid 128 | arch 129 | archk10 130 | cga 131 | options 132 | fpu 133 | i8254 134 | i8259 135 | kbd 136 | main 137 | map 138 | memory 139 | mmu 140 | multiboot 141 | qmalloc 142 | random 143 | syscall 144 | trap 145 | vsvm 146 | 147 | port 148 | alarm 149 | allocb 150 | bud 151 | chan 152 | dev 153 | devtab 154 | edf 155 | fault 156 | image 157 | latin1 158 | mcslock 159 | net 160 | page 161 | parse 162 | pgrp 163 | portclock 164 | print 165 | proc 166 | ps 167 | physalloc 168 | qio 169 | qlock 170 | rebootcmd 171 | ref 172 | rmap 173 | segment 174 | sysauth 175 | sysfile 176 | sysproc 177 | sysseg 178 | systab 179 | tod 180 | 181 | # 182 | #dir 183 | # pc -.I. 184 | # 185 | dir 186 | 386 187 | ip 188 | port 189 | 190 | lib 191 | libc 192 | libip 193 | libsec 194 | libaml 195 | -------------------------------------------------------------------------------- /9K/k10/k8aoe: -------------------------------------------------------------------------------- 1 | dev +dev 2 | root 3 | cons 4 | arch 5 | env 6 | pipe 7 | proc 8 | mnt 9 | srv 10 | dup 11 | rtc 12 | ssl 13 | cap 14 | kprof 15 | 16 | ether netif 17 | ip arp chandial ip ipv6 ipaux iproute netlog nullmedium pktmedium ptclbsum 18 | 19 | sd 20 | aoe 21 | 22 | uart 23 | 24 | sd +dev 25 | sdaoe sdscsi 26 | 27 | uart +dev 28 | uarti8250 29 | uartpci pci 30 | 31 | ip +dev 32 | tcp 33 | udp 34 | ipifc 35 | icmp 36 | icmp6 37 | 38 | link +dev 39 | ether8169 pci ethermii 40 | ether82557 pci 41 | ether82563 pci 42 | etherigbe pci ethermii 43 | etherm10g pci ethermii 44 | ethermedium 45 | loopbackmedium 46 | netdevmedium 47 | 48 | misc +dev 49 | cache 50 | mp apic ioapic pci 51 | 52 | # 53 | #boot cpu 54 | # int cpuflag = 1; 55 | #boot cpu boot $3 56 | # int cpuflag = 1; 57 | # char* bootdisk = "$3"; 58 | #boot rootdir $3 59 | # char* rootdir = "$3"; 60 | #boot (bboot|romboot|dosboot) 61 | # int cpuflag = 1; 62 | # char* bootprog = $2; 63 | #boot boot $3 64 | # char* bootdisk = "$3"; 65 | # 66 | boot cpu 67 | tcp 68 | 69 | rootdir 70 | bootk8aoe.out boot 71 | /amd64/bin/auth/factotum factotum 72 | /amd64/bin/ip/ipconfig ipconfig 73 | 74 | conf 75 | int cpuserver = 1; 76 | 77 | # 78 | #dbgflg 79 | # ioapic 'A' 80 | # chan 'C' 81 | # mp 'M' 82 | # pci 'P' 83 | # 84 | 85 | amd64 +dev 86 | l32p 87 | l64v 88 | l64idt 89 | l64syscall 90 | l64fpu 91 | cpuidamd64 92 | arch 93 | archk8 94 | cga 95 | crap 96 | fpu 97 | i8254 98 | kbd 99 | main 100 | map 101 | memory 102 | mmu 103 | multiboot 104 | random 105 | syscall 106 | trap 107 | vsvm 108 | 109 | port 110 | alarm 111 | alloc xalloc 112 | allocb 113 | chan 114 | dev 115 | devtab 116 | edf 117 | fault 118 | image 119 | latin1 120 | page 121 | parse 122 | pgrp 123 | portclock 124 | print 125 | proc 126 | ps 127 | qio 128 | qlock 129 | rebootcmd 130 | segment 131 | swap 132 | sysauth 133 | sysfile 134 | sysproc 135 | sysseg 136 | systab 137 | taslock 138 | tod 139 | 140 | # 141 | #dir 142 | # pc -.I. 143 | # 144 | dir 145 | 386 146 | ip 147 | port 148 | 149 | lib 150 | libc 151 | libip 152 | libsec 153 | -------------------------------------------------------------------------------- /9K/k10/k8cpu: -------------------------------------------------------------------------------- 1 | dev +dev 2 | root 3 | cons 4 | arch 5 | env 6 | pipe 7 | proc 8 | mnt 9 | srv 10 | dup 11 | rtc 12 | ssl 13 | cap 14 | kprof 15 | 16 | ether netif 17 | ip arp chandial ip ipv6 ipaux iproute netlog nullmedium pktmedium ptclbsum 18 | 19 | uart 20 | 21 | uart +dev 22 | uarti8250 23 | uartpci pci 24 | 25 | ip +dev 26 | tcp 27 | udp 28 | ipifc 29 | icmp 30 | icmp6 31 | 32 | link +dev 33 | ether8169 pci ethermii 34 | ether82557 pci 35 | ether82563 pci 36 | etherigbe pci ethermii 37 | ethermedium 38 | loopbackmedium 39 | netdevmedium 40 | 41 | # acpi hpet 42 | # ht 43 | 44 | misc +dev 45 | # cache 46 | mp apic ioapic pci sipi 47 | 48 | # 49 | #boot cpu 50 | # int cpuflag = 1; 51 | #boot cpu boot $3 52 | # int cpuflag = 1; 53 | # char* bootdisk = "$3"; 54 | #boot rootdir $3 55 | # char* rootdir = "$3"; 56 | #boot (bboot|romboot|dosboot) 57 | # int cpuflag = 1; 58 | # char* bootprog = $2; 59 | #boot boot $3 60 | # char* bootdisk = "$3"; 61 | # 62 | boot cpu 63 | tcp 64 | 65 | rootdir 66 | bootk8cpu.out boot 67 | /amd64/bin/auth/factotum factotum 68 | /amd64/bin/ip/ipconfig ipconfig 69 | 70 | conf 71 | int cpuserver = 1; 72 | 73 | # 74 | #dbgflg 75 | # chan 'c' 76 | # apic 'A' 77 | # acpi 'C' 78 | # hpet 'H' 79 | # ht 'H' 80 | # ioapic 'I' 81 | # mp 'M' 82 | # pci 'P' 83 | # arch 'V' 84 | # 85 | dbgflg 86 | apic 'A' 87 | acpi 'C' 88 | hpet 'H' 89 | ht 'H' 90 | ioapic 'I' 91 | mp 'M' 92 | arch 'V' 93 | archk8 'V' 94 | archk10 'V' 95 | sysproc 'E' 96 | main 'x' 97 | mmu 'm' 98 | asm 'a' 99 | sipi 'y' 100 | 101 | amd64 +dev 102 | l32p 103 | l64v 104 | l64idt 105 | l64syscall 106 | l64fpu 107 | l64cpuid 108 | arch 109 | archk8 110 | asm 111 | cga 112 | crap 113 | fpu 114 | i8254 115 | i8259 116 | kbd 117 | main 118 | map 119 | memory 120 | mmu 121 | multiboot 122 | qmalloc 123 | random 124 | syscall 125 | trap 126 | vsvm 127 | 128 | port 129 | alarm 130 | allocb 131 | chan 132 | dev 133 | devtab 134 | edf 135 | fault 136 | image 137 | latin1 138 | page 139 | parse 140 | pgrp 141 | portclock 142 | print 143 | proc 144 | ps 145 | qio 146 | qlock 147 | rebootcmd 148 | segment 149 | swap 150 | sysauth 151 | sysfile 152 | sysproc 153 | sysseg 154 | systab 155 | taslock 156 | tod 157 | 158 | # 159 | #dir 160 | # pc -.I. 161 | # 162 | dir 163 | 386 164 | ip 165 | port 166 | 167 | lib 168 | libc 169 | libip 170 | libsec 171 | -------------------------------------------------------------------------------- /9K/k10/k8root: -------------------------------------------------------------------------------- 1 | dev +dev 2 | root 3 | cons 4 | arch 5 | env 6 | pipe 7 | proc 8 | mnt 9 | srv 10 | dup 11 | rtc 12 | ssl 13 | cap 14 | kprof 15 | 16 | ether netif 17 | ip arp chandial ip ipv6 ipaux iproute netlog nullmedium pktmedium ptclbsum 18 | 19 | uart 20 | 21 | uart +dev 22 | uarti8250 23 | uartpci pci 24 | 25 | ip +dev 26 | tcp 27 | udp 28 | ipifc 29 | icmp 30 | icmp6 31 | 32 | link +dev 33 | ether8169 pci ethermii 34 | ether82557 pci 35 | etherigbe pci ethermii 36 | ethermedium 37 | loopbackmedium 38 | netdevmedium 39 | 40 | misc +dev 41 | cache 42 | mp apic ioapic 43 | 44 | # 45 | #boot cpu 46 | # int cpuflag = 1; 47 | #boot cpu boot $3 48 | # int cpuflag = 1; 49 | # char* bootdisk = "$3"; 50 | #boot rootdir $3 51 | # char* rootdir = "$3"; 52 | #boot (bboot|romboot|dosboot) 53 | # int cpuflag = 1; 54 | # char* bootprog = $2; 55 | #boot boot $3 56 | # char* bootdisk = "$3"; 57 | # 58 | boot cpu 59 | tcp 60 | 61 | rootdir 62 | k8root.rr 63 | /amd64/bin/echo 64 | /amd64/bin/paqfs 65 | /amd64/bin/rc 66 | ../root/rcmain 67 | ./root/k8root.rc boot 68 | 69 | conf 70 | int cpuserver = 1; 71 | 72 | rr ./root/k8root.proto 73 | ./root/$O.cpu 74 | 75 | # 76 | #dbgflg 77 | # ioapic 'A' 78 | # chan 'C' 79 | # mp 'M' 80 | # pci 'P' 81 | # 82 | 83 | amd64 +dev 84 | l64v 85 | l64idt 86 | l64syscall 87 | l64fpu 88 | arch 89 | cga 90 | crap 91 | fpu 92 | kbd 93 | main 94 | map 95 | memory 96 | mmu 97 | multiboot 98 | random 99 | svm 100 | syscall 101 | trap 102 | 103 | port 104 | alarm 105 | alloc 106 | allocb 107 | chan 108 | dev 109 | devtab 110 | edf 111 | fault 112 | image 113 | latin1 114 | page 115 | parse 116 | pgrp 117 | portclock 118 | print 119 | proc 120 | ps 121 | qio 122 | qlock 123 | rebootcmd 124 | segment 125 | swap 126 | sysauth 127 | sysfile 128 | sysproc 129 | sysseg 130 | taslock 131 | tod 132 | xalloc 133 | 134 | # 135 | #dir 136 | # pc -.I. 137 | # 138 | dir 139 | 386 140 | ip 141 | port 142 | 143 | lib 144 | libc 145 | libip 146 | libsec 147 | -------------------------------------------------------------------------------- /9K/k10/l64cpuid.s: -------------------------------------------------------------------------------- 1 | /* 2 | * The CPUID instruction is always supported on the amd64. 3 | */ 4 | TEXT cpuid(SB), $-4 5 | MOVL RARG, AX /* function in AX */ 6 | MOVLQZX cx+8(FP), CX /* iterator/index/etc. */ 7 | 8 | CPUID 9 | 10 | MOVQ info+16(FP), BP 11 | MOVL AX, 0(BP) 12 | MOVL BX, 4(BP) 13 | MOVL CX, 8(BP) 14 | MOVL DX, 12(BP) 15 | RET 16 | 17 | /* 18 | * Basic timing loop to determine CPU frequency. 19 | * The AAM instruction is not available in 64-bit mode. 20 | */ 21 | TEXT aamloop(SB), 1, $-4 22 | MOVLQZX RARG, CX 23 | aaml1: 24 | XORQ AX, AX /* close enough */ 25 | LOOP aaml1 26 | RET 27 | -------------------------------------------------------------------------------- /9K/k10/l64fpu.s: -------------------------------------------------------------------------------- 1 | /* 2 | * SIMD Floating Point. 3 | * Note: for x87 instructions which have both a 'wait' and 'nowait' version, 4 | * 6a only knows the 'wait' mnemonic but does NOT insert the WAIT prefix byte 5 | * (i.e. they act like their FNxxx variations) so WAIT instructions must be 6 | * explicitly placed in the code if necessary. 7 | */ 8 | TEXT _clts(SB), 1, $-4 9 | CLTS 10 | RET 11 | 12 | TEXT _fldcw(SB), 1, $-4 /* Load x87 FPU Control Word */ 13 | MOVQ RARG, cw+0(FP) 14 | FLDCW cw+0(FP) 15 | RET 16 | 17 | TEXT _fnclex(SB), 1, $-4 18 | FCLEX 19 | RET 20 | 21 | TEXT _fninit(SB), 1, $-4 22 | FINIT /* no WAIT */ 23 | RET 24 | 25 | TEXT _fxrstor(SB), 1, $-4 26 | FXRSTOR64 (RARG) 27 | RET 28 | 29 | TEXT _fxsave(SB), 1, $-4 30 | FXSAVE64 (RARG) 31 | RET 32 | 33 | TEXT _fwait(SB), 1, $-4 34 | WAIT 35 | RET 36 | 37 | TEXT _ldmxcsr(SB), 1, $-4 /* Load MXCSR */ 38 | MOVQ RARG, mxcsr+0(FP) 39 | LDMXCSR mxcsr+0(FP) 40 | RET 41 | 42 | TEXT _stts(SB), 1, $-4 43 | MOVQ CR0, AX 44 | ORQ $8, AX /* Ts */ 45 | MOVQ AX, CR0 46 | RET 47 | -------------------------------------------------------------------------------- /9K/k10/l64syscall.s: -------------------------------------------------------------------------------- 1 | #include "mem.h" 2 | #include "amd64l.h" 3 | 4 | MODE $64 5 | 6 | /* 7 | */ 8 | TEXT touser(SB), 1, $-4 9 | CLI 10 | SWAPGS 11 | MOVQ $SSEL(SiUDS, SsRPL3), AX 12 | MOVW AX, DS 13 | MOVW AX, ES 14 | MOVW AX, FS 15 | MOVW AX, GS 16 | 17 | MOVQ $(UTZERO+0x28), CX /* ip */ 18 | MOVQ $If, R11 /* flags */ 19 | 20 | MOVQ RARG, SP /* sp */ 21 | 22 | BYTE $0x48; SYSRET /* SYSRETQ */ 23 | 24 | /* 25 | */ 26 | TEXT syscallentry(SB), 1, $-4 27 | SWAPGS 28 | BYTE $0x65; MOVQ 0, RMACH /* m-> (MOVQ GS:0x0, R15) */ 29 | MOVQ 16(RMACH), RUSER /* m->proc */ 30 | MOVQ SP, R13 31 | MOVQ 16(RUSER), SP /* m->proc->kstack */ 32 | ADDQ $KSTACK, SP 33 | PUSHQ $SSEL(SiUDS, SsRPL3) /* old stack segment */ 34 | PUSHQ R13 /* old sp */ 35 | PUSHQ R11 /* old flags */ 36 | PUSHQ $SSEL(SiUCS, SsRPL3) /* old code segment */ 37 | PUSHQ CX /* old ip */ 38 | 39 | SUBQ $(18*8), SP /* unsaved registers */ 40 | 41 | MOVW $SSEL(SiUDS, SsRPL3), (15*8+0)(SP) 42 | MOVW ES, (15*8+2)(SP) 43 | MOVW FS, (15*8+4)(SP) 44 | MOVW GS, (15*8+6)(SP) 45 | 46 | PUSHQ SP /* Ureg* */ 47 | PUSHQ RARG /* system call number */ 48 | CALL syscall(SB) 49 | 50 | TEXT syscallreturn(SB), 1, $-4 51 | MOVQ 16(SP), AX /* Ureg.ax */ 52 | MOVQ (16+6*8)(SP), BP /* Ureg.bp */ 53 | _syscallreturn: 54 | ADDQ $(17*8), SP /* registers + arguments */ 55 | 56 | CLI 57 | SWAPGS 58 | MOVW 0(SP), DS 59 | MOVW 2(SP), ES 60 | MOVW 4(SP), FS 61 | MOVW 6(SP), GS 62 | 63 | MOVQ 24(SP), CX /* ip */ 64 | MOVQ 40(SP), R11 /* flags */ 65 | 66 | MOVQ 48(SP), SP /* sp */ 67 | 68 | BYTE $0x48; SYSRET /* SYSRETQ */ 69 | 70 | TEXT sysrforkret(SB), 1, $-4 71 | MOVQ $0, AX 72 | JMP _syscallreturn 73 | -------------------------------------------------------------------------------- /9K/k10/map.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | 7 | /* 8 | * Before mmuinit is done, we can't rely on sys->vmunmapped 9 | * being set, so we use the static limit TMFM 10 | */ 11 | 12 | void* 13 | KADDR(uintmem pa) 14 | { 15 | u8int* va; 16 | 17 | va = UINT2PTR(pa); 18 | if(sys->vmunmapped != 0){ 19 | if(pa < sys->vmunmapped-KSEG0) 20 | return KSEG0+va; 21 | }else if(pa < TMFM) 22 | return KSEG0+va; 23 | return KSEG2+va; 24 | } 25 | 26 | uintmem 27 | PADDR(void* va) 28 | { 29 | uintmem pa; 30 | 31 | pa = PTR2UINT(va); 32 | if(pa >= KSEG2 && pa < KSEG1) 33 | return pa-KSEG2; 34 | if(pa >= KSEG0 && pa < KSEG0+TMFM) 35 | return pa-KSEG0; 36 | if(pa > KSEG2) 37 | return pa-KSEG2; 38 | 39 | panic("PADDR: va %#p pa #%p @ %#p\n", va, mmuphysaddr(PTR2UINT(va)), getcallerpc(&va)); 40 | return 0; 41 | } 42 | 43 | KMap* 44 | kmap(Page* page) 45 | { 46 | DBG("kmap(%#llux) @ %#p: %#p %#p\n", 47 | page->pa, getcallerpc(&page), 48 | page->pa, KADDR(page->pa)); 49 | 50 | return KADDR(page->pa); 51 | } 52 | -------------------------------------------------------------------------------- /9K/k10/mkfile: -------------------------------------------------------------------------------- 1 | CONF=k10cpu 2 | CONFLIST=k10cpu k8cpu k8root 3 | 4 | objtype=amd64 5 | $p$CONF.gz 24 | 25 | install:V: $p$CONF 26 | cp $p$CONF /$objtype 27 | #import lookout / /n/lookout && cp $p$CONF $p$CONF.gz /n/lookout/$objtype/ 28 | 29 | init.out: init9.$O initcode.$O /$objtype/lib/libc.a 30 | $LD -l -R1 -s -o init.out init9.$O initcode.$O -lc 31 | 32 | l32p.$O: ${objtype}l.h 33 | l64idt.$O: ${objtype}l.h 34 | l64syscall.$O: ${objtype}l.h 35 | l64v.$O: ${objtype}l.h 36 | lsipi.$O: ${objtype}l.h 37 | 38 | ${objtype}l.h: $objtype.h 39 | rc ../mk/mkenum $objtype.h > $target 40 | 41 | lapic.$O: apic.h io.h 42 | devarch.$O: ../port/error.h /$objtype/include/ureg.h 43 | fpu.$O: amd64.h 44 | fpu.$O: /$objtype/include/ureg.h 45 | ioapic.$O: apic.h io.h 46 | main.$O: /sys/include/pool.h init.h 47 | memory.$O: amd64.h 48 | mmu.$O: amd64.h 49 | mp.$O: apic.h 50 | sipi.$O: apic.h sipi.h 51 | svm.$O: amd64.h 52 | svm.$O: /$objtype/include/ureg.h 53 | syscall.$O: ../port/error.h /sys/src/libc/9syscall/sys.h 54 | syscall.$O: /sys/include/tos.h /$objtype/include/ureg.h 55 | syscall.$O: amd64.h 56 | trap.$O: ../port/error.h io.h 57 | trap.$O: /sys/include/tos.h /$objtype/include/ureg.h 58 | devacpi.$O acpi.$O: acpi.h /sys/include/aml.h 59 | 60 | devaoe.$O: ../port/error.h ../port/netif.h ../ip/ip.h 61 | devaoe.$O: ../port/aoe.h etherif.h 62 | devether.$O: ../port/error.h ../port/netif.h etherif.h 63 | devrtc.$O: ../port/error.h 64 | ether8169.$O: ../port/error.h ../port/ethermii.h ../port/netif.h 65 | ether8169.$O: etherif.h 66 | ether82557.$O: ../port/netif.h 67 | ether82557.$O: etherif.h io.h 68 | etherigbe.$O: ../port/error.h ../port/ethermii.h ../port/netif.h 69 | etherigbe.$O: etherif.h io.h 70 | etherm10g.$O: ../port/error.h ../port/netif.h 71 | etherm10g.$O: etherif.h io.h 72 | etherm10g.$O: ../386/etherm10g2k.i ../386/etherm10g4k.i 73 | i8259.$O: io.h 74 | kbd.$O: ../port/error.h io.h 75 | pci.$O: io.h 76 | sdaoe.$O: ../port/error.h ../port/netif.h ../port/sd.h 77 | sdaoe.$O: ../port/aoe.h etherif.h io.h 78 | sdiahci.$O: ../386/ahci.h 79 | sdscsi.$O: ../port/error.h 80 | 81 | random.$O: ../port/error.h 82 | 83 | sipi.h: l64sipi.$O mkfile 84 | $LD -o l64sipi.out -T0xfffffffff0003000 -R4 -l -s l64sipi.$O 85 | {echo 'uchar sipihandler[]={' 86 | xd -1x l64sipi.out | 87 | sed -e 's/^[0-9a-f]+ //' \ 88 | -e '1,2d' -e '3s/^ .. .. .. .. .. .. .. ..//' \ 89 | -e 's/ ([0-9a-f][0-9a-f])/0x\1,/g' 90 | echo '};'} > $target 91 | -------------------------------------------------------------------------------- /9K/k10/msi.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | #include "io.h" 7 | #include "apic.h" 8 | 9 | enum { 10 | Dpcicap = 1<<0, 11 | Dmsicap = 1<<1, 12 | Dvec = 1<<2, 13 | Debug = 0, 14 | }; 15 | 16 | enum { 17 | /* address */ 18 | Msiabase = 0xfee00000u, 19 | Msiadest = 1<<12, /* same as 63:56 of apic vector */ 20 | Msiaedest = 1<<4, /* same as 55:48 of apic vector */ 21 | Msialowpri = 1<<3, /* redirection hint */ 22 | Msialogical = 1<<2, 23 | 24 | /* data */ 25 | Msidlevel = 1<<15, 26 | Msidassert = 1<<14, 27 | Msidlogical = 1<<11, 28 | Msidmode = 1<<8, /* 3 bits; delivery mode */ 29 | Msidvector = 0xff<<0, 30 | }; 31 | 32 | enum{ 33 | /* msi capabilities */ 34 | Vmask = 1<<8, 35 | Cap64 = 1<<7, 36 | Mmesgmsk = 7<<4, 37 | Mmcap = 7<<1, 38 | Msienable = 1<<0, 39 | }; 40 | 41 | static int 42 | msicap(Pcidev *p) 43 | { 44 | int c; 45 | 46 | c = pcicap(p, PciCapMSI); 47 | if(c == -1) 48 | return 0; 49 | return c; 50 | } 51 | 52 | static int 53 | blacklist(Pcidev *p) 54 | { 55 | switch(p->vid<<16 | p->did){ 56 | case 0x11ab<<16 | 0x6485: 57 | return -1; 58 | } 59 | return 0; 60 | } 61 | 62 | int 63 | pcimsienable(Pcidev *p, uvlong vec) 64 | { 65 | char *s; 66 | uint c, f, d, datao, lopri, dmode, logical; 67 | 68 | if(ioconf.nomsi) 69 | return -1; 70 | 71 | c = msicap(p); 72 | if(c == 0) 73 | return -1; 74 | 75 | f = pcicfgr16(p, c + 2) & ~Mmesgmsk; 76 | 77 | if(blacklist(p) != 0) 78 | return -1; 79 | datao = 8; 80 | d = vec>>48; 81 | lopri = (vec & 0x700) == MTlp; 82 | logical = (vec & Lm) != 0; 83 | pcicfgw32(p, c + 4, Msiabase | Msiaedest * d 84 | | Msialowpri * lopri | Msialogical * logical); 85 | if(f & Cap64){ 86 | datao += 4; 87 | pcicfgw32(p, c + 8, 0); 88 | } 89 | dmode = (vec >> 8) & 7; 90 | pcicfgw16(p, c + datao, Msidassert | Msidlogical * logical 91 | | Msidmode * dmode | (uint)vec & 0xff); 92 | if(f & Vmask) 93 | pcicfgw32(p, c + datao + 4, 0); 94 | 95 | /* leave vectors configured but disabled for debugging */ 96 | if((s = getconf("*nomsi")) != nil && atoi(s) != 0) 97 | return -1; 98 | 99 | pcicfgw16(p, c + 2, f); 100 | return 0; 101 | } 102 | 103 | int 104 | pcimsimask(Pcidev *p, int mask) 105 | { 106 | uint c, f; 107 | 108 | c = msicap(p); 109 | if(c == 0) 110 | return -1; 111 | f = pcicfgr16(p, c + 2) & ~Msienable; 112 | if(mask){ 113 | pcicfgw16(p, c + 2, f & ~Msienable); 114 | // pciclrbme(p); cheeze 115 | }else{ 116 | pcisetbme(p); 117 | pcicfgw16(p, c + 2, f | Msienable); 118 | } 119 | return 0; 120 | } 121 | -------------------------------------------------------------------------------- /9K/k10/ptclbsumamd64.s: -------------------------------------------------------------------------------- 1 | TEXT ptclbsum(SB), 1, $0 2 | MOVQ RARG, SI /* addr+0(FP) */ 3 | MOVL len+8(FP), CX 4 | 5 | XORL AX, AX /* sum */ 6 | 7 | TESTL $1, SI /* byte aligned? */ 8 | MOVQ SI, DI 9 | JEQ _2align 10 | 11 | DECL CX 12 | JLT _return 13 | 14 | MOVB 0x00(SI), AH 15 | INCQ SI 16 | 17 | _2align: 18 | TESTL $2, SI /* word aligned? */ 19 | JEQ _32loop 20 | 21 | CMPL CX, $2 /* less than 2 bytes? */ 22 | JLT _1dreg 23 | SUBL $2, CX 24 | 25 | XORL BX, BX 26 | MOVW 0x00(SI), BX 27 | ADDL BX, AX 28 | ADCL $0, AX 29 | LEAQ 2(SI), SI 30 | 31 | _32loop: 32 | CMPL CX, $0x20 33 | JLT _8loop 34 | 35 | MOVL CX, BP 36 | SHRL $5, BP 37 | ANDL $0x1F, CX 38 | 39 | _32loopx: 40 | MOVL 0x00(SI), BX 41 | MOVL 0x1C(SI), DX 42 | ADCL BX, AX 43 | MOVL 0x04(SI), BX 44 | ADCL DX, AX 45 | MOVL 0x10(SI), DX 46 | ADCL BX, AX 47 | MOVL 0x08(SI), BX 48 | ADCL DX, AX 49 | MOVL 0x14(SI), DX 50 | ADCL BX, AX 51 | MOVL 0x0C(SI), BX 52 | ADCL DX, AX 53 | MOVL 0x18(SI), DX 54 | ADCL BX, AX 55 | LEAQ 0x20(SI), SI 56 | ADCL DX, AX 57 | 58 | DECL BP 59 | JNE _32loopx 60 | 61 | ADCL $0, AX 62 | 63 | _8loop: 64 | CMPL CX, $0x08 65 | JLT _2loop 66 | 67 | MOVL CX, BP 68 | SHRL $3, BP 69 | ANDL $0x07, CX 70 | 71 | _8loopx: 72 | MOVL 0x00(SI), BX 73 | ADCL BX, AX 74 | MOVL 0x04(SI), DX 75 | ADCL DX, AX 76 | 77 | LEAQ 0x08(SI), SI 78 | DECL BP 79 | JNE _8loopx 80 | 81 | ADCL $0, AX 82 | 83 | _2loop: 84 | CMPL CX, $0x02 85 | JLT _1dreg 86 | 87 | MOVL CX, BP 88 | SHRL $1, BP 89 | ANDL $0x01, CX 90 | 91 | _2loopx: 92 | MOVWLZX 0x00(SI), BX 93 | ADCL BX, AX 94 | 95 | LEAQ 0x02(SI), SI 96 | DECL BP 97 | JNE _2loopx 98 | 99 | ADCL $0, AX 100 | 101 | _1dreg: 102 | TESTL $1, CX /* 1 byte left? */ 103 | JEQ _fold 104 | 105 | XORL BX, BX 106 | MOVB 0x00(SI), BX 107 | ADDL BX, AX 108 | ADCL $0, AX 109 | 110 | _fold: 111 | MOVL AX, BX 112 | SHRL $16, BX 113 | JEQ _swab 114 | 115 | ANDL $0xFFFF, AX 116 | ADDL BX, AX 117 | JMP _fold 118 | 119 | _swab: 120 | TESTL $1, DI /* copy of original RARG */ 121 | JNE _return 122 | XCHGB AH, AL 123 | 124 | _return: 125 | RET 126 | -------------------------------------------------------------------------------- /9K/k10/root/k8root.namespace: -------------------------------------------------------------------------------- 1 | # root 2 | mount -a $rootsrv /root $rootspec 3 | bind -a /root / 4 | bind -c /root/mnt /mnt 5 | 6 | # kernel devices 7 | bind #c /dev 8 | bind #d /fd 9 | bind -c #e /env 10 | bind #p /proc 11 | bind -c #s /srv 12 | 13 | # mount points 14 | 15 | # authentication 16 | mount -a /srv/factotum /mnt 17 | 18 | # standard bin 19 | bind /root/$cputype/bin /bin 20 | bind -a /root/rc/bin /bin 21 | 22 | # networks 23 | bind -a #I /net 24 | bind -a #l0 /net 25 | #mount -a /srv/cs /net 26 | #mount -a /srv/dns /net 27 | 28 | bind -c /usr/$user/tmp /tmp 29 | cd /usr/$user 30 | -------------------------------------------------------------------------------- /9K/k10/root/k8root.proto: -------------------------------------------------------------------------------- 1 | adm d775 sys sys /tmp/empty 2 | nvram 400 sys sys ./root/nvram 3 | timezone d775 sys sys /tmp/empty 4 | lib d775 sys sys /tmp/empty 5 | namespace 664 sys sys ./root/k8root.namespace 6 | profile 664 sys sys ../root/profile 7 | mnt d775 sys sys /tmp/empty 8 | cons d775 sys sys /tmp/empty 9 | cons d775 sys sys /tmp/empty 10 | consctl d775 sys sys /tmp/empty 11 | exportfs d775 sys sys /tmp/empty 12 | 0 d775 sys sys /tmp/empty 13 | 1 d775 sys sys /tmp/empty 14 | 2 d775 sys sys /tmp/empty 15 | 3 d775 sys sys /tmp/empty 16 | 4 d775 sys sys /tmp/empty 17 | 5 d775 sys sys /tmp/empty 18 | 6 d775 sys sys /tmp/empty 19 | 7 d775 sys sys /tmp/empty 20 | 8 d775 sys sys /tmp/empty 21 | 9 d775 sys sys /tmp/empty 22 | 10 d775 sys sys /tmp/empty 23 | 11 d775 sys sys /tmp/empty 24 | 12 d775 sys sys /tmp/empty 25 | 13 d775 sys sys /tmp/empty 26 | 14 d775 sys sys /tmp/empty 27 | 15 d775 sys sys /tmp/empty 28 | 16 d775 sys sys /tmp/empty 29 | keys d775 sys sys /tmp/empty 30 | temp d775 sys sys /tmp/empty 31 | term d775 sys sys /tmp/empty 32 | n d775 sys sys /tmp/empty 33 | dump d775 sys sys /tmp/empty 34 | fs d775 sys sys /tmp/empty 35 | io d775 sys sys /tmp/empty 36 | mnt d775 sys sys /tmp/empty 37 | rc d775 sys sys /tmp/empty 38 | bin d775 sys sys /tmp/empty 39 | service d775 sys sys /tmp/empty 40 | tcp23 775 sys sys ../root/tcp23 41 | tcp17007 775 sys sys /bin/service/tcp17007 42 | tcp17010 775 sys sys ./root/tcp17010 43 | lib d775 sys sys /tmp/empty 44 | rcmain 775 sys sys 45 | tmp d775 sys sys /tmp/empty 46 | usr d775 sys sys /tmp/empty 47 | glenda d775 sys sys /tmp/empty 48 | lib d775 sys sys /tmp/empty 49 | profile 664 sys sys ../root/profile 50 | 51 | amd64 d775 sys sys /tmp/empty 52 | bin d775 sys sys /tmp/empty 53 | # used by k8cpu.rc to get off the ground 54 | bind 775 sys sys 55 | echo 775 sys sys 56 | rc 775 sys sys 57 | sed 775 sys sys 58 | srv 775 sys sys 59 | telnet 775 sys sys 60 | test 775 sys sys 61 | 62 | # used to provide standalone service 63 | auth d775 sys sys /tmp/empty 64 | factotum 775 sys sys 65 | aux d775 sys sys /tmp/empty 66 | listen 775 sys sys 67 | ip d775 sys sys /tmp/empty 68 | telnetd 775 sys sys 69 | ndb d775 sys sys /tmp/empty 70 | cs 775 sys sys 71 | 72 | cpu 775 sys sys ./root/6.cpu 73 | exportfs 775 sys sys 74 | 75 | # used for debugging 76 | 77 | include d775 sys sys /tmp/empty 78 | lib d775 sys sys /tmp/empty 79 | mkfile 775 sys sys 80 | -------------------------------------------------------------------------------- /9K/k10/root/mkfile: -------------------------------------------------------------------------------- 1 | objtype=amd64 2 | args, uintmem); 16 | 17 | if(f->flags & FmtSharp) 18 | return fmtprint(f, "%#16.16llux", pa); 19 | 20 | return fmtprint(f, "%llud", pa); 21 | } 22 | 23 | void 24 | main(int argc, char **argv) 25 | { 26 | char line[128], *p; 27 | int n; 28 | 29 | fmtinstall('P', fmtP); 30 | while((n = read(0, line, sizeof(line))) > 0){ 31 | line[n-1] = 0; 32 | p = strchr(line, ' '); 33 | if(p == nil){ 34 | print("count\n"); 35 | continue; 36 | } 37 | *p++ = 0; 38 | rmapfree(&rm1, strtoull(line, nil, 0), strtoull(p, nil, 0)); 39 | } 40 | rmapgaps(&rm2, &rm1); 41 | rmapprint(&rm1); 42 | rmapprint(&rm2); 43 | exits(0); 44 | } 45 | -------------------------------------------------------------------------------- /9K/k10/uncached.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ycui1984/enhanced-plan9/372cbf8cee7689c372e7dcfb21580220a79daf2f/9K/k10/uncached.h -------------------------------------------------------------------------------- /9K/k10/usbehci.h: -------------------------------------------------------------------------------- 1 | /* override default macros from ../port/usb.h */ 2 | #undef dprint 3 | #undef ddprint 4 | #undef deprint 5 | #undef ddeprint 6 | #define dprint(...) do if(ehcidebug)print(__VA_ARGS__); while(0) 7 | #define ddprint(...) do if(ehcidebug>1)print(__VA_ARGS__); while(0) 8 | #define deprint(...) do if(ehcidebug || ep->debug)print(__VA_ARGS__); while(0) 9 | #define ddeprint(...) do if(ehcidebug>1 || ep->debug>1)print(__VA_ARGS__); while(0) 10 | 11 | typedef struct Ctlr Ctlr; 12 | typedef struct Eopio Eopio; 13 | typedef struct Isoio Isoio; 14 | typedef struct Poll Poll; 15 | typedef struct Qh Qh; 16 | typedef struct Qtree Qtree; 17 | 18 | #pragma incomplete Ctlr; 19 | #pragma incomplete Eopio; 20 | #pragma incomplete Isoio; 21 | #pragma incomplete Poll; 22 | #pragma incomplete Qh; 23 | #pragma incomplete Qtree; 24 | 25 | struct Poll 26 | { 27 | Lock; 28 | Rendez; 29 | int must; 30 | int does; 31 | }; 32 | 33 | struct Ctlr 34 | { 35 | Rendez; /* for waiting to async advance doorbell */ 36 | Lock; /* for ilock. qh lists and basic ctlr I/O */ 37 | QLock portlck; /* for port resets/enable... (and doorbell) */ 38 | int active; /* in use or not */ 39 | Pcidev* pcidev; 40 | Ecapio* capio; /* Capability i/o regs */ 41 | Eopio* opio; /* Operational i/o regs */ 42 | 43 | int nframes; /* 1024, 512, or 256 frames in the list */ 44 | ulong* frames; /* periodic frame list (hw) */ 45 | Qh* qhs; /* async Qh circular list for bulk/ctl */ 46 | Qtree* tree; /* tree of Qhs for the periodic list */ 47 | int ntree; /* number of dummy qhs in tree */ 48 | Qh* intrqhs; /* list of (not dummy) qhs in tree */ 49 | Isoio* iso; /* list of active Iso I/O */ 50 | ulong load; 51 | ulong isoload; 52 | int nintr; /* number of interrupts attended */ 53 | int ntdintr; /* number of intrs. with something to do */ 54 | int nqhintr; /* number of async td intrs. */ 55 | int nisointr; /* number of periodic td intrs. */ 56 | int nreqs; 57 | Poll poll; 58 | }; 59 | 60 | /* 61 | * Operational registers (hw) 62 | */ 63 | struct Eopio 64 | { 65 | u32int cmd; /* 00 command */ 66 | u32int sts; /* 04 status */ 67 | u32int intr; /* 08 interrupt enable */ 68 | u32int frno; /* 0c frame index */ 69 | u32int seg; /* 10 bits 63:32 of EHCI datastructs (unused) */ 70 | u32int frbase; /* 14 frame list base addr, 4096-byte boundary */ 71 | u32int link; /* 18 link for async list */ 72 | uchar d2c[0x40-0x1c]; /* 1c dummy */ 73 | u32int config; /* 40 1: all ports default-routed to this HC */ 74 | u32int portsc[1]; /* 44 Port status and control, one per port */ 75 | }; 76 | 77 | extern int ehcidebug; 78 | extern Ecapio *ehcidebugcapio; 79 | extern int ehcidebugport; 80 | 81 | void ehcilinkage(Hci *hp); 82 | void ehcimeminit(Ctlr *ctlr); 83 | void ehcirun(Ctlr *ctlr, int on); 84 | -------------------------------------------------------------------------------- /9K/mk/bootmkfile: -------------------------------------------------------------------------------- 1 | BOOTDIR=../boot 2 | BOOTLIB=$BOOTDIR/libboot.a$O 3 | 4 | BOOTFILES=\ 5 | bootauth.$O\ 6 | aux.$O\ 7 | boot.$O\ 8 | bootcache.$O\ 9 | bootip.$O\ 10 | local.$O\ 11 | localpaq.$O\ 12 | embed.$O\ 13 | settime.$O\ 14 | sac.$O\ 15 | paq.$O\ 16 | printstub.$O\ 17 | 18 | $BOOTLIB(%.$O):N: %.$O 19 | 20 | $BOOTLIB: ${BOOTFILES:%=$BOOTLIB(%)} 21 | names=`{membername $newprereq} 22 | ar vu $BOOTLIB $names 23 | rm $names 24 | 25 | $BOOTFILES: $BOOTDIR/boot.h 26 | 27 | %.$O: $BOOTDIR/%.c 28 | $CC -I$BOOTDIR $CFLAGS $BOOTDIR/$stem.c 29 | 30 | boot$CONF.out: ../mk/parse $CONF print.$O $BOOTDIR/boot.c $BOOTLIB 31 | awk -f ../mk/parse -- -mkbootconf $CONF > boot$CONF.c 32 | $CC $CFLAGS boot$CONF.c 33 | $CC $CFLAGS ../boot/printstub.c 34 | $LD -o boot$CONF.out boot$CONF.$O $BOOTLIB printstub.$O 35 | -------------------------------------------------------------------------------- /9K/mk/mkenum: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | awk ' 4 | BEGIN{ 5 | oargc = 0; 6 | for(argc = 1; argc < ARGC; argc++){ 7 | if(ARGV[argc] !~ /^-.+/ || ARGV[argc] ~ /--/) 8 | break; 9 | if(ARGV[argc] != "-D") 10 | oargv[ARGV[argc]] = oargc++; 11 | else 12 | DEBUG = 1; 13 | ARGV[argc] = ""; 14 | } 15 | } 16 | 17 | /^enum([ \t]*{|$)/{ 18 | inenum = 1; 19 | if(DEBUG) 20 | printf "inenum = 1\n"; 21 | next; 22 | } 23 | 24 | inenum && /^};$/{ 25 | if(DEBUG) 26 | printf "inenum = 0\n"; 27 | inenum = 0; 28 | } 29 | 30 | inenum && $0 ~ /^[ \t]+[_A-Za-z][_0-9A-Za-z]+[ \t]+=[ \t]+[0-9A-Z_a-z()<> ]+,/{ 31 | tab = "\t"; 32 | if(length($1) < 8) 33 | sep = tab tab; 34 | else 35 | sep = tab; 36 | split($3, a, ","); 37 | printf "#define %s%s%s", $1, sep, a[1]; 38 | if(match($0, /\/\*.*\*\/$/)){ 39 | len = length(a[1]); 40 | sep = ""; 41 | while(len < 24){ 42 | sep = sep tab; 43 | len += 8; 44 | } 45 | printf "%s%s", sep, substr($0, RSTART); 46 | } 47 | printf "\n" 48 | } 49 | 50 | !inenum && /^#(define|include) /{ 51 | printf "%s\n", $0; 52 | } 53 | 54 | /^$/{ 55 | printf "\n"; 56 | } 57 | 58 | END{ 59 | }' $* 60 | -------------------------------------------------------------------------------- /9K/mk/mkroot: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | rfork e 4 | echo mkroot $* 5 | if(! ~ $#* 2){ 6 | echo usage: mkroot path name >[2=1] 7 | exit 1 8 | } 9 | n=`{basename $1} 10 | cp $1 $2.out 11 | t=`{file $2.out} 12 | if(~ $"t *executable*) 13 | strip $2.out 14 | aux/data2s $2 < $2.out > $2.root.s 15 | echo mkroot $* done 16 | -------------------------------------------------------------------------------- /9K/mk/mkrootall: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | rfork e 4 | n=`{echo $#*^'%3' | hoc} 5 | if(! ~ $n 0){ 6 | echo 'usage: mkrootall [name cname file]...' >[1=2] 7 | exit usage 8 | } 9 | 10 | tmp=mkroot.$pid.out 11 | fn sigexit { 12 | rm -f $tmp 13 | } 14 | 15 | allcname=() 16 | while(! ~ $#* 0){ 17 | name=$1 18 | cname=$2 19 | file=$3 20 | shift 21 | shift 22 | shift 23 | allcname=($allcname $cname) 24 | cp $file $tmp 25 | t=`{file $tmp} 26 | # do not strip venti - it uses its own symbols 27 | if(~ $"t *executable* && ! ~ $name venti) 28 | strip $tmp 29 | aux/data2s $cname < $tmp 30 | } 31 | exit 0 32 | -------------------------------------------------------------------------------- /9K/mk/mkrr: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | rfork en 4 | 5 | switch($#*){ 6 | case 1 7 | PROTO=$1.proto 8 | case 2 9 | PROTO=$2 10 | case * 11 | echo $0: usage: $0 conf [proto] 12 | exit "usage" 13 | } 14 | 15 | ramfs -S ramfs.$pid 16 | mount -c /srv/ramfs.$pid /tmp 17 | mkdir /tmp/mnt /tmp/empty 18 | 19 | # clean up files and procs on exit 20 | fn sigexit { 21 | echo sync>>/srv/flcons.$pid 22 | unmount /tmp/mnt 23 | unmount /tmp 24 | echo halt>>/srv/flcons.$pid 25 | rm -f /srv/*.$pid 26 | kill ramfs fossil|rc 27 | } 28 | 29 | {syscall seek 1 8388608 0; echo} >>/tmp/fldisk |[0=2] grep -v 'no error$' 30 | fossil/flfmt -b 4096 -y /tmp/fldisk 31 | 32 | fossil/conf -w /tmp/fldisk <ticks; 18 | qlock(&alarms); 19 | while((rp = alarms.head) && tickscmp(now, rp->alarm) >= 0){ 20 | if(rp->alarm != 0L){ 21 | if(canqlock(&rp->debug)){ 22 | if(!waserror()){ 23 | postnote(rp, 0, "alarm", NUser); 24 | poperror(); 25 | } 26 | qunlock(&rp->debug); 27 | rp->alarm = 0L; 28 | }else 29 | break; 30 | } 31 | alarms.head = rp->palarm; 32 | } 33 | qunlock(&alarms); 34 | 35 | sleep(&alarmr, return0, 0); 36 | } 37 | } 38 | 39 | /* 40 | * called every clock tick 41 | */ 42 | void 43 | checkalarms(void) 44 | { 45 | Proc *p; 46 | ulong now; 47 | 48 | p = alarms.head; 49 | now = sys->ticks; 50 | 51 | if(p != nil && tickscmp(now, p->alarm) >= 0) 52 | wakeup(&alarmr); 53 | } 54 | 55 | ulong 56 | procalarm(ulong time) 57 | { 58 | Proc **l, *f; 59 | ulong when, old; 60 | 61 | if(up->alarm) 62 | old = tk2ms(up->alarm - sys->ticks); 63 | else 64 | old = 0; 65 | if(time == 0) { 66 | up->alarm = 0; 67 | return old; 68 | } 69 | when = ms2tk(time)+sys->ticks; 70 | if(when == 0) 71 | when = 1; 72 | 73 | qlock(&alarms); 74 | l = &alarms.head; 75 | for(f = *l; f; f = f->palarm) { 76 | if(up == f){ 77 | *l = f->palarm; 78 | break; 79 | } 80 | l = &f->palarm; 81 | } 82 | 83 | up->palarm = 0; 84 | if(alarms.head) { 85 | l = &alarms.head; 86 | for(f = *l; f; f = f->palarm) { 87 | if(tickscmp(f->alarm, when) >= 0) { 88 | up->palarm = f; 89 | *l = up; 90 | goto done; 91 | } 92 | l = &f->palarm; 93 | } 94 | *l = up; 95 | } 96 | else 97 | alarms.head = up; 98 | done: 99 | up->alarm = when; 100 | qunlock(&alarms); 101 | 102 | return old; 103 | } 104 | -------------------------------------------------------------------------------- /9K/port/aoe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2011 Coraid, Inc. 3 | * All rights reserved. 4 | */ 5 | 6 | typedef struct Aoehdr Aoehdr; 7 | typedef struct Aoeata Aoeata; 8 | typedef struct Aoeqc Aoeqc; 9 | typedef struct Mdir Mdir; 10 | typedef struct Aoemask Aoemask; 11 | typedef struct Aoesrr Aoesrr; 12 | typedef struct Aoekrr Aoekrr; 13 | typedef struct Kresp Kresp; 14 | typedef struct Kreg Kreg; 15 | typedef struct Kset Kset; 16 | typedef struct Kreplace Kreplace; 17 | 18 | enum 19 | { 20 | ACata, ACconfig, ACmask, ACresrel, ACkresrel, 21 | 22 | AQCread= 0, AQCtest, AQCprefix, AQCset, AQCfset, AQCtar, 23 | 24 | ETAOE= 0x88a2, 25 | Aoever= 1, 26 | 27 | AEcmd= 1, AEarg, AEdev, AEcfg, AEver, AEres, 28 | 29 | AFerr= 1<<2, 30 | AFrsp= 1<<3, 31 | 32 | AAFwrite= 1, 33 | AAFext= 1<<6, 34 | 35 | AKstat = 0, AKreg, AKset, AKreplace, AKreset, 36 | 37 | Aoesectsz = 512, 38 | Szaoeata = 24+12, 39 | Szaoeqc = 24+8, 40 | 41 | /* mask commands */ 42 | Mread= 0, 43 | Medit, 44 | 45 | /* mask directives */ 46 | MDnop= 0, 47 | MDadd, 48 | MDdel, 49 | 50 | /* mask errors */ 51 | MEunspec= 1, 52 | MEbaddir, 53 | MEfull, 54 | 55 | /* Keyed-RR Rflags */ 56 | KRnopreempt = 1<<0, 57 | }; 58 | 59 | struct Aoehdr 60 | { 61 | uchar dst[6]; 62 | uchar src[6]; 63 | uchar type[2]; 64 | uchar verflags; 65 | uchar error; 66 | uchar major[2]; 67 | uchar minor; 68 | uchar cmd; 69 | uchar tag[4]; 70 | }; 71 | 72 | struct Aoeata 73 | { 74 | Aoehdr; 75 | uchar aflags; 76 | uchar errfeat; 77 | uchar scnt; 78 | uchar cmdstat; 79 | uchar lba[6]; 80 | uchar res[2]; 81 | }; 82 | 83 | struct Aoeqc 84 | { 85 | Aoehdr; 86 | uchar bufcnt[2]; 87 | uchar fwver[2]; 88 | uchar scnt; 89 | uchar verccmd; 90 | uchar cslen[2]; 91 | }; 92 | 93 | // mask directive 94 | struct Mdir { 95 | uchar res; 96 | uchar cmd; 97 | uchar mac[6]; 98 | }; 99 | 100 | struct Aoemask { 101 | Aoehdr; 102 | uchar rid; 103 | uchar cmd; 104 | uchar merror; 105 | uchar nmacs; 106 | // struct Mdir m[0]; 107 | }; 108 | 109 | struct Aoesrr { 110 | Aoehdr; 111 | uchar rcmd; 112 | uchar nmacs; 113 | // uchar mac[6][nmacs]; 114 | }; 115 | 116 | struct Aoekrr { 117 | Aoehdr; 118 | uchar rcmd; 119 | }; 120 | 121 | struct Kresp { 122 | Aoehdr; 123 | uchar rcmd; 124 | uchar rtype; 125 | uchar nkeys[2]; 126 | uchar res[4]; 127 | uchar gencnt[4]; 128 | uchar owner[8]; 129 | uchar keys[1]; 130 | }; 131 | 132 | struct Kreg { 133 | Aoehdr; 134 | uchar rcmd; 135 | uchar nmacs; 136 | uchar res[2]; 137 | uchar key[8]; 138 | uchar macs[1]; 139 | }; 140 | 141 | struct Kset { 142 | Aoehdr; 143 | uchar rcmd; 144 | uchar rtype; 145 | uchar res[2]; 146 | uchar key[8]; 147 | }; 148 | 149 | struct Kreplace { 150 | Aoehdr; 151 | uchar rcmd; 152 | uchar rtype; 153 | uchar rflags; 154 | uchar res; 155 | uchar targkey[8]; 156 | uchar replkey[8]; 157 | }; 158 | -------------------------------------------------------------------------------- /9K/port/devtab.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Stub. 3 | */ 4 | #include "u.h" 5 | #include "../port/lib.h" 6 | #include "mem.h" 7 | #include "dat.h" 8 | #include "fns.h" 9 | #include "../port/error.h" 10 | 11 | extern Dev* devtab[]; 12 | 13 | void 14 | devtabreset(void) 15 | { 16 | int i; 17 | Dev *d; 18 | 19 | for(i = 0; devtab[i] != nil; i++){ 20 | d = devtab[i]; 21 | if(d->readv == nil) 22 | d->readv = devreadv; 23 | if(d->writev == nil) 24 | d->writev = devwritev; 25 | d->reset(); 26 | } 27 | } 28 | 29 | void 30 | devtabinit(void) 31 | { 32 | int i; 33 | 34 | for(i = 0; devtab[i] != nil; i++) 35 | devtab[i]->init(); 36 | } 37 | 38 | void 39 | devtabshutdown(void) 40 | { 41 | int i; 42 | 43 | /* 44 | * Shutdown in reverse order. 45 | */ 46 | for(i = 0; devtab[i] != nil; i++) 47 | ; 48 | for(i--; i >= 0; i--) 49 | devtab[i]->shutdown(); 50 | } 51 | 52 | 53 | Dev* 54 | devtabget(int dc, int user) 55 | { 56 | int i; 57 | 58 | for(i = 0; devtab[i] != nil; i++){ 59 | if(devtab[i]->dc == dc) 60 | return devtab[i]; 61 | } 62 | 63 | if(user == 0) 64 | panic("devtabget %C\n", dc); 65 | 66 | return nil; 67 | } 68 | 69 | Dev* 70 | devbyname(char *name) 71 | { 72 | int i; 73 | 74 | for(i = 0; devtab[i] != nil; i++) 75 | if(strcmp(devtab[i]->name, name) == 0) 76 | return devtab[i]; 77 | return nil; 78 | } 79 | 80 | long 81 | devtabread(Chan*, void* buf, long n, vlong off) 82 | { 83 | int i; 84 | Dev *dev; 85 | char *alloc, *e, *p; 86 | 87 | alloc = malloc(READSTR); 88 | if(alloc == nil) 89 | error(Enomem); 90 | 91 | p = alloc; 92 | e = p + READSTR; 93 | for(i = 0; devtab[i] != nil; i++){ 94 | dev = devtab[i]; 95 | p = seprint(p, e, "#%C %s\n", dev->dc, dev->name); 96 | } 97 | 98 | if(waserror()){ 99 | free(alloc); 100 | nexterror(); 101 | } 102 | n = readstr(off, buf, n, alloc); 103 | free(alloc); 104 | poperror(); 105 | 106 | return n; 107 | } 108 | -------------------------------------------------------------------------------- /9K/port/devwd.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | #include "io.h" 7 | #include "../port/error.h" 8 | 9 | enum { 10 | Qdir, 11 | Qwdctl, 12 | }; 13 | 14 | static Watchdog *wd; 15 | static Dirtab wddir[] = { 16 | ".", { Qdir, 0, QTDIR }, 0, 0550, 17 | "wdctl", { Qwdctl, 0 }, 0, 0660, 18 | }; 19 | 20 | 21 | void 22 | addwatchdog(Watchdog *watchdog) 23 | { 24 | if(wd){ 25 | print("addwatchdog: watchdog already installed\n"); 26 | return; 27 | } 28 | wd = watchdog; 29 | if(wd) 30 | wd->disable(); 31 | } 32 | 33 | static Chan* 34 | wdattach(char *spec) 35 | { 36 | return devattach('w', spec); 37 | } 38 | 39 | static Walkqid* 40 | wdwalk(Chan *c, Chan *nc, char **name, int nname) 41 | { 42 | return devwalk(c, nc, name, nname, wddir, nelem(wddir), devgen); 43 | } 44 | 45 | static long 46 | wdstat(Chan *c, uchar *dp, long n) 47 | { 48 | return devstat(c, dp, n, wddir, nelem(wddir), devgen); 49 | } 50 | 51 | static Chan* 52 | wdopen(Chan* c, int omode) 53 | { 54 | return devopen(c, omode, wddir, nelem(wddir), devgen); 55 | } 56 | 57 | static void 58 | wdclose(Chan*) 59 | { 60 | } 61 | 62 | static long 63 | wdread(Chan* c, void* a, long n, vlong off) 64 | { 65 | long offset; 66 | char s[READSTR]; 67 | 68 | offset = off; 69 | switch((ulong)c->qid.path){ 70 | case Qdir: 71 | return devdirread(c, a, n, wddir, nelem(wddir), devgen); 72 | 73 | case Qwdctl: 74 | if(wd == nil || wd->stat == nil) 75 | return 0; 76 | 77 | wd->stat(s, s + READSTR); 78 | return readstr(offset, a, n, s); 79 | 80 | default: 81 | error(Egreg); 82 | break; 83 | } 84 | return 0; 85 | } 86 | 87 | static long 88 | wdwrite(Chan* c, void* a, long n, vlong off) 89 | { 90 | char *p; 91 | 92 | switch((ulong)c->qid.path){ 93 | case Qdir: 94 | error(Eperm); 95 | 96 | case Qwdctl: 97 | if(wd == nil) 98 | return n; 99 | 100 | if(off != 0ll) 101 | error(Ebadarg); 102 | 103 | if(p = strchr(a, '\n')) 104 | *p = 0; 105 | 106 | if(!strncmp(a, "enable", n)) 107 | wd->enable(); 108 | else if(!strncmp(a, "disable", n)) 109 | wd->disable(); 110 | else if(!strncmp(a, "restart", n)) 111 | wd->restart(); 112 | else 113 | error(Ebadarg); 114 | return n; 115 | 116 | default: 117 | error(Egreg); 118 | break; 119 | } 120 | 121 | return 0; 122 | } 123 | 124 | Dev wddevtab = { 125 | 'w', 126 | "watchdog", 127 | 128 | devreset, 129 | devinit, 130 | devshutdown, 131 | wdattach, 132 | wdwalk, 133 | wdstat, 134 | wdopen, 135 | devcreate, 136 | wdclose, 137 | wdread, 138 | devbread, 139 | wdwrite, 140 | devbwrite, 141 | devremove, 142 | devwstat, 143 | devpower, 144 | }; 145 | -------------------------------------------------------------------------------- /9K/port/dirdep: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | awk -v 'confdir='`{basename -d $1} ' 4 | BEGIN{ 5 | collect = isdir = 0 6 | } 7 | 8 | /^[ \t]*$/{ 9 | next 10 | } 11 | /^#/{ 12 | next 13 | } 14 | collect && /^[^ \t]/{ 15 | collect = isdir = 0 16 | } 17 | collect && $0 ~ /[^ \t]+/{ 18 | tab[$0]++; 19 | } 20 | $0 ~ /^[^ \t]/{ 21 | if($1 ~ "dirs"){ 22 | dirs = 1; 23 | collect = 1; 24 | } 25 | next; 26 | } 27 | 28 | END{ 29 | for(i in tab) { 30 | gsub(/[ \t]/, "", i) 31 | mkfragdir = confdir "/" i 32 | print "<|sed ''s!MKFRAGDIR!" mkfragdir "!'' " mkfragdir "/mkfrag" 33 | } 34 | }' $* 35 | -------------------------------------------------------------------------------- /9K/port/edf.h: -------------------------------------------------------------------------------- 1 | enum { 2 | Maxsteps = 200 * 100 * 2, /* 100 periods of 200 procs */ 3 | 4 | /* Edf.flags field */ 5 | Admitted = 0x01, 6 | Sporadic = 0x02, 7 | Yieldonblock = 0x04, 8 | Sendnotes = 0x08, 9 | Deadline = 0x10, 10 | Yield = 0x20, 11 | Extratime = 0x40, 12 | 13 | Infinity = ~0ULL, 14 | }; 15 | 16 | typedef struct Edf Edf; 17 | 18 | struct Edf { 19 | /* All times in µs */ 20 | /* time intervals */ 21 | long D; /* Deadline */ 22 | long Delta; /* Inherited deadline */ 23 | long T; /* period */ 24 | long C; /* Cost */ 25 | long S; /* Slice: time remaining in this period */ 26 | /* times (only low-order bits of absolute time) */ 27 | long r; /* (this) release time */ 28 | long d; /* (this) deadline */ 29 | long t; /* Start of next period, t += T at release */ 30 | long s; /* Time at which this proc was last scheduled */ 31 | /* for schedulability testing */ 32 | long testDelta; 33 | int testtype; /* Release or Deadline */ 34 | long testtime; 35 | Proc *testnext; 36 | /* other */ 37 | ushort flags; 38 | Timer; 39 | /* Stats */ 40 | long edfused; 41 | long extraused; 42 | long aged; 43 | ulong periods; 44 | ulong missed; 45 | }; 46 | 47 | extern Lock edftestlock; /* for atomic admitting/expelling */ 48 | 49 | #pragma varargck type "t" long 50 | #pragma varargck type "U" uvlong 51 | 52 | /* Interface: */ 53 | Edf* edflock(Proc*); 54 | void edfunlock(void); 55 | -------------------------------------------------------------------------------- /9K/port/error.h: -------------------------------------------------------------------------------- 1 | extern char Enoerror[]; /* no error */ 2 | extern char Emount[]; /* inconsistent mount */ 3 | extern char Eunmount[]; /* not mounted */ 4 | extern char Eismtpt[]; /* is a mount point */ 5 | extern char Eunion[]; /* not in union */ 6 | extern char Emountrpc[]; /* mount rpc error */ 7 | extern char Eshutdown[]; /* device shut down */ 8 | extern char Enocreate[]; /* mounted directory forbids creation */ 9 | extern char Enonexist[]; /* file does not exist */ 10 | extern char Eexist[]; /* file already exists */ 11 | extern char Ebadsharp[]; /* unknown device in # filename */ 12 | extern char Enotdir[]; /* not a directory */ 13 | extern char Eisdir[]; /* file is a directory */ 14 | extern char Ebadchar[]; /* bad character in file name */ 15 | extern char Efilename[]; /* file name syntax */ 16 | extern char Eperm[]; /* permission denied */ 17 | extern char Ebadusefd[]; /* inappropriate use of fd */ 18 | extern char Ebadarg[]; /* bad arg in system call */ 19 | extern char Einuse[]; /* device or object already in use */ 20 | extern char Eio[]; /* i/o error */ 21 | extern char Etoobig[]; /* read or write too large */ 22 | extern char Etoosmall[]; /* read or write too small */ 23 | extern char Enoport[]; /* network port not available */ 24 | extern char Ehungup[]; /* i/o on hungup channel */ 25 | extern char Ebadctl[]; /* bad process or channel control request */ 26 | extern char Enodev[]; /* no free devices */ 27 | extern char Eprocdied[]; /* process exited */ 28 | extern char Enochild[]; /* no living children */ 29 | extern char Eioload[]; /* i/o error in demand load */ 30 | extern char Enovmem[]; /* virtual memory allocation failed */ 31 | extern char Ebadfd[]; /* fd out of range or not open */ 32 | extern char Enofd[]; /* no free file descriptors */ 33 | extern char Eisstream[]; /* seek on a stream */ 34 | extern char Ebadexec[]; /* exec header invalid */ 35 | extern char Etimedout[]; /* connection timed out */ 36 | extern char Econrefused[]; /* connection refused */ 37 | extern char Econinuse[]; /* connection in use */ 38 | extern char Eintr[]; /* interrupted */ 39 | extern char Enomem[]; /* kernel allocate failed */ 40 | extern char Esoverlap[]; /* segments overlap */ 41 | extern char Eshort[]; /* i/o count too small */ 42 | extern char Egreg[]; /* ken has left the building */ 43 | extern char Ebadspec[]; /* bad attach specifier */ 44 | extern char Enoreg[]; /* process has no saved registers */ 45 | extern char Enoattach[]; /* mount/attach disallowed */ 46 | extern char Eshortstat[]; /* stat buffer too small */ 47 | extern char Ebadstat[]; /* malformed stat buffer */ 48 | extern char Ecmdargs[]; /* wrong #args in control message */ 49 | extern char Ebadip[]; /* bad ip address syntax */ 50 | -------------------------------------------------------------------------------- /9K/port/initcode.c: -------------------------------------------------------------------------------- 1 | /* 2 | * IMPORTANT! DO NOT ADD LIBRARY CALLS TO THIS FILE. 3 | * The entire text image must fit on one page 4 | * (and there's no data segment, so any read/write data must be on the stack). 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | char cons[] = "#c/cons"; 11 | char boot[] = "/boot/boot"; 12 | char dev[] = "/dev"; 13 | char c[] = "#c"; 14 | char e[] = "#e"; 15 | char ec[] = "#ec"; 16 | char s[] = "#s"; 17 | char srv[] = "/srv"; 18 | char env[] = "/env"; 19 | 20 | void 21 | startboot(char *argv0, char **argv) 22 | { 23 | char buf[200]; 24 | 25 | USED(argv0); 26 | /* 27 | * open the console here so that /boot/boot, 28 | * which could be a shell script, can inherit the open fds. 29 | */ 30 | open(cons, OREAD); 31 | open(cons, OWRITE); 32 | open(cons, OWRITE); 33 | bind(c, dev, MAFTER); 34 | bind(ec, env, MAFTER); 35 | bind(e, env, MCREATE|MAFTER); 36 | bind(s, srv, MREPL|MCREATE); 37 | exec(boot, argv); 38 | 39 | rerrstr(buf, sizeof buf); 40 | buf[sizeof buf - 1] = '\0'; 41 | _exits(buf); 42 | } 43 | -------------------------------------------------------------------------------- /9K/port/iofilter.h: -------------------------------------------------------------------------------- 1 | 2 | enum { 3 | Niosamples = 32, 4 | Lsum = 0, 5 | Lmax, 6 | Lavg, 7 | Lsz, 8 | }; 9 | 10 | typedef struct Iofilter Iofilter; 11 | struct Iofilter { 12 | Lock; 13 | ulong nsamples; /* total samples taken */ 14 | struct { 15 | ulong b; 16 | ulong lat[Lsz]; /* latency min, max, avg for bytes in b */ 17 | } samples[Niosamples]; 18 | 19 | ulong bytes; 20 | ulong lmin; 21 | ulong lmax; 22 | vlong lsum; 23 | ulong nlat; 24 | }; 25 | 26 | #pragma varargck type "Z" Iofilter* 27 | 28 | void incfilter(Iofilter *, ulong, ulong); 29 | void delfilter(Iofilter *); 30 | int addfilter(Iofilter *); 31 | void zfilter(Iofilter *); 32 | int filtersum(Iofilter*, uvlong*, vlong*, int); 33 | int filterfmt(Fmt *); 34 | -------------------------------------------------------------------------------- /9K/port/latin1.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | 4 | /* 5 | * The code makes two assumptions: strlen(ld) is 1 or 2; latintab[i].ld can be a 6 | * prefix of latintab[j].ld only when j=esctab[i+1]) 61 | return unicode(k, esctab[i+1]); 62 | else 63 | return -esctab[i+1]; 64 | } 65 | for(l=latintab; l->ld!=0; l++) 66 | if(k[0] == l->ld[0]){ 67 | if(n == 1) 68 | return -2; 69 | if(l->ld[1] == 0) 70 | c = k[1]; 71 | else if(l->ld[1] != k[1]) 72 | continue; 73 | else if(n == 2) 74 | return -3; 75 | else 76 | c = k[2]; 77 | for(p=l->si; *p!=0; p++) 78 | if(*p == c) 79 | return l->so[p - l->si]; 80 | return -1; 81 | } 82 | return -1; 83 | } 84 | -------------------------------------------------------------------------------- /9K/port/mul64fract.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | 3 | /* mul64fract(uvlong*r, uvlong a, uvlong b) 4 | * 5 | * Multiply two 64 numbers and return the middle 64 bits of the 128 bit result. 6 | * 7 | * The assumption is that one of the numbers is a 8 | * fixed point number with the integer portion in the 9 | * high word and the fraction in the low word. 10 | * 11 | * There should be an assembler version of this routine 12 | * for each architecture. This one is intended to 13 | * make ports easier. 14 | * 15 | * ignored r0 = lo(a0*b0) 16 | * lsw of result r1 = hi(a0*b0) +lo(a0*b1) +lo(a1*b0) 17 | * msw of result r2 = hi(a0*b1) +hi(a1*b0) +lo(a1*b1) 18 | * ignored r3 = hi(a1*b1) 19 | */ 20 | 21 | void 22 | mul64fract(uvlong *r, uvlong a, uvlong b) 23 | { 24 | uvlong bh, bl; 25 | uvlong ah, al; 26 | uvlong res; 27 | 28 | bl = b & 0xffffffffULL; 29 | bh = b >> 32; 30 | al = a & 0xffffffffULL; 31 | ah = a >> 32; 32 | 33 | res = (al*bl)>>32; 34 | res += (al*bh); 35 | res += (ah*bl); 36 | res += (ah*bh)<<32; 37 | 38 | *r = res; 39 | } 40 | -------------------------------------------------------------------------------- /9K/port/net.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | #include "../port/error.h" 7 | 8 | void 9 | hnputv(void *p, uvlong v) 10 | { 11 | uchar *a; 12 | 13 | a = p; 14 | hnputl(a, v>>32); 15 | hnputl(a+4, v); 16 | } 17 | 18 | void 19 | hnputl(void *p, uint v) 20 | { 21 | uchar *a; 22 | 23 | a = p; 24 | a[0] = v>>24; 25 | a[1] = v>>16; 26 | a[2] = v>>8; 27 | a[3] = v; 28 | } 29 | 30 | void 31 | hnputs(void *p, ushort v) 32 | { 33 | uchar *a; 34 | 35 | a = p; 36 | a[0] = v>>8; 37 | a[1] = v; 38 | } 39 | 40 | uvlong 41 | nhgetv(void *p) 42 | { 43 | uchar *a; 44 | 45 | a = p; 46 | return ((vlong)nhgetl(a) << 32) | nhgetl(a+4); 47 | } 48 | 49 | uint 50 | nhgetl(void *p) 51 | { 52 | uchar *a; 53 | 54 | a = p; 55 | return (a[0]<<24)|(a[1]<<16)|(a[2]<<8)|(a[3]<<0); 56 | } 57 | 58 | ushort 59 | nhgets(void *p) 60 | { 61 | uchar *a; 62 | 63 | a = p; 64 | return (a[0]<<8)|(a[1]<<0); 65 | } 66 | -------------------------------------------------------------------------------- /9K/port/nocache.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | #include "../port/error.h" 7 | 8 | // No file caching 9 | 10 | void 11 | cinit(void) 12 | { 13 | } 14 | 15 | void 16 | copen(Chan *c) 17 | { 18 | USED(c); 19 | } 20 | 21 | int 22 | cread(Chan *c, uchar *buf, int len, vlong off) 23 | { 24 | USED(c, buf, len, off); 25 | return 0; 26 | } 27 | 28 | void 29 | cupdate(Chan *c, uchar *buf, int len, vlong off) 30 | { 31 | USED(c, buf, len, off); 32 | } 33 | 34 | void 35 | cwrite(Chan* c, uchar *buf, int len, vlong off) 36 | { 37 | USED(c, buf, len, off); 38 | } 39 | -------------------------------------------------------------------------------- /9K/port/noedf.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | 7 | void 8 | edfinit(Proc*) 9 | { 10 | } 11 | 12 | char* 13 | edfadmit(Proc*) 14 | { 15 | return "edf scheduling not implemented"; 16 | } 17 | 18 | int 19 | edfready(Proc*) 20 | { 21 | return 0; 22 | } 23 | 24 | void 25 | edfrecord(Proc*) 26 | { 27 | } 28 | 29 | void 30 | edfrun(Proc*, int) 31 | { 32 | } 33 | 34 | void 35 | edfstop(Proc*) 36 | { 37 | } 38 | 39 | void 40 | edfyield(void) 41 | { 42 | yield(); 43 | } 44 | -------------------------------------------------------------------------------- /9K/port/parse.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | #include "../port/error.h" 7 | 8 | /* 9 | * Generous estimate of number of fields, including terminal nil pointer 10 | */ 11 | static int 12 | ncmdfield(char *p, int n) 13 | { 14 | int white, nwhite; 15 | char *ep; 16 | int nf; 17 | 18 | if(p == nil) 19 | return 1; 20 | 21 | nf = 0; 22 | ep = p+n; 23 | white = 1; /* first text will start field */ 24 | while(p < ep){ 25 | nwhite = (strchr(" \t\r\n", *p++ & 0xFF) != 0); /* UTF is irrelevant */ 26 | if(white && !nwhite) /* beginning of field */ 27 | nf++; 28 | white = nwhite; 29 | } 30 | return nf+1; /* +1 for nil */ 31 | } 32 | 33 | /* 34 | * parse a command written to a device 35 | */ 36 | Cmdbuf* 37 | parsecmd(char *p, int n) 38 | { 39 | Cmdbuf *volatile cb; 40 | int nf; 41 | char *sp; 42 | 43 | nf = ncmdfield(p, n); 44 | 45 | /* allocate Cmdbuf plus string pointers plus copy of string including \0 */ 46 | sp = smalloc(sizeof(*cb) + nf * sizeof(char*) + n + 1); 47 | cb = (Cmdbuf*)sp; 48 | cb->f = (char**)(&cb[1]); 49 | cb->buf = (char*)(&cb->f[nf]); 50 | 51 | if(up!=nil && waserror()){ 52 | free(cb); 53 | nexterror(); 54 | } 55 | memmove(cb->buf, p, n); 56 | if(up != nil) 57 | poperror(); 58 | 59 | /* dump new line and null terminate */ 60 | if(n > 0 && cb->buf[n-1] == '\n') 61 | n--; 62 | cb->buf[n] = '\0'; 63 | 64 | cb->nf = tokenize(cb->buf, cb->f, nf-1); 65 | cb->f[cb->nf] = nil; 66 | 67 | return cb; 68 | } 69 | 70 | /* 71 | * Reconstruct original message, for error diagnostic 72 | */ 73 | void 74 | cmderror(Cmdbuf *cb, char *s) 75 | { 76 | int i; 77 | char *p, *e; 78 | 79 | p = up->genbuf; 80 | e = p+ERRMAX-10; 81 | p = seprint(p, e, "%s \"", s); 82 | for(i=0; inf; i++){ 83 | if(i > 0) 84 | p = seprint(p, e, " "); 85 | p = seprint(p, e, "%q", cb->f[i]); 86 | } 87 | strcpy(p, "\""); 88 | error(up->genbuf); 89 | } 90 | 91 | /* 92 | * Look up entry in table 93 | */ 94 | Cmdtab* 95 | lookupcmd(Cmdbuf *cb, Cmdtab *ctab, int nctab) 96 | { 97 | int i; 98 | Cmdtab *ct; 99 | 100 | if(cb->nf == 0) 101 | error("empty control message"); 102 | 103 | for(ct = ctab, i=0; icmd, "*") !=0) /* wildcard always matches */ 105 | if(strcmp(ct->cmd, cb->f[0]) != 0) 106 | continue; 107 | if(ct->narg != 0 && ct->narg != cb->nf) 108 | cmderror(cb, Ecmdargs); 109 | return ct; 110 | } 111 | 112 | cmderror(cb, "unknown control message"); 113 | return nil; 114 | } 115 | -------------------------------------------------------------------------------- /9K/port/physalloc.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | 7 | /* 8 | * TO DO: 9 | * big pool -> small pool 10 | */ 11 | 12 | enum{ 13 | MinK= PGSHFT, 14 | MidK= 21, 15 | MaxK= 30, /* last usable k (largest block is 2^k) */ 16 | }; 17 | 18 | static Bpool* physgig; 19 | static Bpool* phys; 20 | 21 | static void* 22 | alloc0(usize nb, int clr) 23 | { 24 | void *p; 25 | 26 | p = basealloc(nb, 0, nil); 27 | if(clr && p != nil) 28 | memset(p, 0, nb); 29 | return p; 30 | } 31 | 32 | uintmem 33 | physalloc(usize size) 34 | { 35 | uintmem a; 36 | 37 | if(physgig != nil && size >= 1ull<= 4ull*GiB) 49 | bpoolfree(physgig, a, size); 50 | else 51 | bpoolfree(phys, a, size); 52 | } 53 | 54 | void 55 | physallocrange(usize *low, usize *high) 56 | { 57 | bpoolallocrange(phys, low, high); 58 | } 59 | 60 | void 61 | physinitfree(uintmem base, uintmem lim) 62 | { 63 | if(physgig != nil && base >= 4ull*GiB) 64 | bpoolinitfree(physgig, base, lim); 65 | else 66 | bpoolinitfree(phys, base, lim); 67 | } 68 | 69 | char* 70 | seprintphysstats(char *s, char *e) 71 | { 72 | return seprintbpoolstats(phys, s, e); 73 | } 74 | 75 | void 76 | physallocinit(void) 77 | { 78 | uintmem top, avail, base, size, lim, pa, lo, hi; 79 | RMapel *e; 80 | 81 | if(DBGFLG) 82 | rmapprint(&rmapram); 83 | avail = rmapsize(&rmapram); 84 | DBG("avail: %#P\n", avail); 85 | top = 0; 86 | for(e = rmapram.map; e != nil; e = e->next) 87 | top = e->addr + e->size; 88 | if(top > 4ull*GiB){ 89 | physgig = bpoolcreate(MidK, MaxK, 4ull*GiB, top, alloc0); 90 | phys = bpoolcreate(MinK, MaxK, 0, 4ull*GiB, alloc0); 91 | }else 92 | phys = bpoolcreate(MinK, MaxK, 0, top, alloc0); 93 | pa = mmuphysaddr(sys->vmstart) + sys->pmunassigned; 94 | if(DBGFLG) 95 | rmapprint(&rmapram); 96 | DBG("pa lim: %#llux top %#llux\n", pa, top); 97 | while(rmapfirst(&rmapram, pa, &base, &size)){ 98 | if(base >= 4ull*GiB) 99 | break; 100 | lim = base+size; 101 | if(lim > 4ull*GiB) 102 | lim = 4ull*GiB; 103 | lo = ROUNDUP(base, (1<pmpaged += hi - lo; 112 | } 113 | } 114 | if(DBGFLG) 115 | physdump(); 116 | } 117 | 118 | void 119 | physdump(void) 120 | { 121 | print("bpooldump phys: "); 122 | bpooldump(phys); 123 | if(physgig != nil){ 124 | print("bpooldump physgig: "); 125 | bpooldump(physgig); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /9K/port/print.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | 7 | static Lock fmtl; 8 | 9 | void 10 | _fmtlock(void) 11 | { 12 | lock(&fmtl); 13 | } 14 | 15 | void 16 | _fmtunlock(void) 17 | { 18 | unlock(&fmtl); 19 | } 20 | 21 | int 22 | _efgfmt(Fmt*) 23 | { 24 | return -1; 25 | } 26 | 27 | int 28 | mregfmt(Fmt* f) 29 | { 30 | Mreg mreg; 31 | 32 | mreg = va_arg(f->args, Mreg); 33 | if(sizeof(Mreg) == sizeof(uvlong)) 34 | return fmtprint(f, "%#16.16llux", (uvlong)mreg); 35 | return fmtprint(f, "%#8.8ux", (uint)mreg); 36 | } 37 | 38 | void 39 | fmtinit(void) 40 | { 41 | quotefmtinstall(); 42 | archfmtinstall(); 43 | } 44 | -------------------------------------------------------------------------------- /9K/port/ps.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | 7 | void 8 | pshash(Proc *p) 9 | { 10 | int h; 11 | 12 | h = p->pid % nelem(procalloc.ht); 13 | lock(&procalloc); 14 | p->pidhash = procalloc.ht[h]; 15 | procalloc.ht[h] = p; 16 | unlock(&procalloc); 17 | } 18 | 19 | void 20 | psunhash(Proc *p) 21 | { 22 | int h; 23 | Proc **l; 24 | 25 | h = p->pid % nelem(procalloc.ht); 26 | lock(&procalloc); 27 | for(l = &procalloc.ht[h]; *l != nil; l = &(*l)->pidhash) 28 | if(*l == p){ 29 | *l = p->pidhash; 30 | break; 31 | } 32 | unlock(&procalloc); 33 | } 34 | 35 | int 36 | psindex(int pid) 37 | { 38 | Proc *p; 39 | int h; 40 | int s; 41 | 42 | s = -1; 43 | h = pid % nelem(procalloc.ht); 44 | lock(&procalloc); 45 | for(p = procalloc.ht[h]; p != nil; p = p->pidhash) 46 | if(p->pid == pid){ 47 | s = p->index; 48 | break; 49 | } 50 | unlock(&procalloc); 51 | return s; 52 | } 53 | 54 | Proc* 55 | psincref(int i) 56 | { 57 | /* 58 | * Placeholder. 59 | */ 60 | if(i >= procalloc.nproc) 61 | return nil; 62 | return &procalloc.arena[i]; 63 | } 64 | 65 | void 66 | psdecref(Proc *p) 67 | { 68 | /* 69 | * Placeholder. 70 | */ 71 | USED(p); 72 | } 73 | 74 | void 75 | psrelease(Proc* p) 76 | { 77 | p->qnext = procalloc.free; 78 | procalloc.free = p; 79 | } 80 | 81 | Proc* 82 | psalloc(void) 83 | { 84 | Proc *p; 85 | char msg[64]; 86 | 87 | lock(&procalloc); 88 | for(;;) { 89 | if(p = procalloc.free) 90 | break; 91 | 92 | unlock(&procalloc); 93 | snprint(msg, sizeof msg, "no procs; %s forking", 94 | up? up->text: "kernel"); 95 | resrcwait(msg, "Noprocs"); 96 | lock(&procalloc); 97 | } 98 | procalloc.free = p->qnext; 99 | unlock(&procalloc); 100 | 101 | while(p->mach != nil || p->nlocks != 0) 102 | {} 103 | 104 | return p; 105 | } 106 | 107 | void 108 | psinit(int nproc) 109 | { 110 | Proc *p; 111 | int i; 112 | 113 | procalloc.nproc = nproc; 114 | procalloc.free = malloc(nproc*sizeof(Proc)); 115 | if(procalloc.free == nil) 116 | panic("cannot allocate %ud procs (%udMB)\n", nproc, nproc*sizeof(Proc)/(1024*1024)); 117 | procalloc.arena = procalloc.free; 118 | 119 | p = procalloc.free; 120 | for(i=0; iqnext = p+1; 122 | p->index = i; 123 | } 124 | p->qnext = 0; 125 | p->index = i; 126 | } 127 | -------------------------------------------------------------------------------- /9K/port/rdb.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | 7 | #include "ureg.h" 8 | 9 | #undef DBG 10 | #define DBG if(0)scrprint 11 | #pragma varargck argpos scrprint 1 12 | static Ureg ureg; 13 | 14 | static void 15 | scrprint(char *fmt, ...) 16 | { 17 | char buf[128]; 18 | va_list va; 19 | int n; 20 | 21 | va_start(va, fmt); 22 | n = vseprint(buf, buf+sizeof buf, fmt, va)-buf; 23 | va_end(va); 24 | putstrn(buf, n); 25 | } 26 | 27 | static char* 28 | getline(void) 29 | { 30 | static char buf[128]; 31 | int i, c; 32 | 33 | for(;;){ 34 | for(i=0; idbgreg = ureg; 66 | m->dbgsp = ureg->sp; 67 | delconsdevs(); /* turn off serial console and kprint */ 68 | // scrprint("Plan 9 debugger\n"); 69 | iprint("Edebugger reset\n"); 70 | for(;;){ 71 | req = getline(); 72 | if(req == nil){ 73 | iprint("Edebugger break\n"); 74 | return; 75 | } 76 | switch(*req){ 77 | case 'r': 78 | a = addr(req+1, ureg, nil); 79 | DBG("read %#p\n", a); 80 | iprint("R%.8lux %.2ux %.2ux %.2ux %.2ux\n", 81 | strtoul(req+1, 0, 16), a[0], a[1], a[2], a[3]); 82 | break; 83 | 84 | case 'w': 85 | a = addr(req+1, ureg, &p); 86 | *(ulong*)a = strtoul(p, nil, 16); 87 | iprint("W\n"); 88 | break; 89 | /* 90 | * case Tmput: 91 | n = min[4]; 92 | if(n > 4){ 93 | mesg(Rerr, Ecount); 94 | break; 95 | } 96 | a = addr(min+0); 97 | scrprint("mput %.8lux\n", a); 98 | memmove(a, min+5, n); 99 | mesg(Rmput, mout); 100 | break; 101 | * 102 | */ 103 | default: 104 | DBG("unknown %c\n", *req); 105 | iprint("Eunknown message\n"); 106 | break; 107 | } 108 | } 109 | } 110 | 111 | void 112 | rdb(void) 113 | { 114 | splhi(); 115 | iprint("rdb..."); 116 | callwithureg(talkrdb); 117 | } 118 | -------------------------------------------------------------------------------- /9K/port/reap.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | 7 | /* 8 | * Bibop table 9 | */ 10 | typedef struct Bibop Bibop; 11 | struct Bibop{ 12 | uintmem base; 13 | uintmem limit; 14 | uint shift; 15 | uint mlen; /* map length */ 16 | uchar map[]; 17 | }; 18 | 19 | enum{ 20 | MaxGiB= 64, 21 | BibUnit= 2*MiB, 22 | BibSize= (MaxGiB*GiB/BibUnit), 23 | 24 | IsReap= 0x40, 25 | IsBusy= 0x80, 26 | SizeMask= 0xF, /* up to 16 size codes */ 27 | }; 28 | 29 | static uint 30 | bibopsize(uintmem base, uintmem limit, uint lg2size) 31 | { 32 | return sizeof(Bibop)+((limit-base)>>lg2size); 33 | } 34 | 35 | Bibop* 36 | bibopalloc(uintmem base, uintmem limit, uint lg2size, void* (*alloc)(uint)) 37 | { 38 | uint need; 39 | Bibop *b; 40 | 41 | need = bibopsize(base, limit, lg2size); 42 | b = alloc(need); 43 | if(b == nil) 44 | panic("needed %ud bytes for bibop table", need); 45 | b->base = base; 46 | b->limit = limit; 47 | b->shift = lg2size; 48 | b->mlen = need-sizeof(Bibop); 49 | memset(b->map, 0, b->mlen); 50 | return b; 51 | } 52 | 53 | int 54 | bibopstate(Bibop *b, uintmem pa) 55 | { 56 | if(pa == 0 || !(pa >= b->base && pa < b->limit)) 57 | return -1; 58 | return b->map[(pa - b->base)>>b->shift]; 59 | } 60 | 61 | /* 62 | * set the state for memory from pa0 to pa1 (half-open) to s 63 | */ 64 | void 65 | bibopsetstate(Bibop *b, uintmem pa0, uintmem pa1, int s) 66 | { 67 | int i, j; 68 | 69 | s |= IsBusy; 70 | if(pa == 0 || !(pa0 >= b->base && pa0 < b->limit)) 71 | return; 72 | if(pa1 > b->limit) 73 | pa1 = b->limit; 74 | i = (pa0 - b->base) >> b->shift; 75 | j = (pa1 - b->base) >> b->shift; 76 | for(i = 0; i < j; i++) 77 | b->map[i] = s; 78 | } 79 | 80 | static Reap reaps[~IsReap & 0xFF]; 81 | 82 | Reap* 83 | findreap(uintmem pa) 84 | { 85 | int s; 86 | 87 | s = memstatus(pa); 88 | if(s < 0 || (s&IsReap) == 0) 89 | return nil; 90 | return &reap[s & ~IsReap]; 91 | } 92 | -------------------------------------------------------------------------------- /9K/port/rebootcmd.c: -------------------------------------------------------------------------------- 1 | #include "u.h" 2 | #include "../port/lib.h" 3 | #include "mem.h" 4 | #include "dat.h" 5 | #include "fns.h" 6 | #include "../port/error.h" 7 | 8 | #include 9 | 10 | static ulong 11 | l2be(long l) 12 | { 13 | uchar *cp; 14 | 15 | cp = (uchar*)&l; 16 | return (cp[0]<<24) | (cp[1]<<16) | (cp[2]<<8) | cp[3]; 17 | } 18 | 19 | 20 | static void 21 | readn(Chan *c, void *vp, long n) 22 | { 23 | char *p; 24 | long nn; 25 | 26 | p = vp; 27 | while(n > 0) { 28 | nn = c->dev->read(c, p, n, c->offset); 29 | if(nn == 0) 30 | error(Eshort); 31 | c->offset += nn; 32 | p += nn; 33 | n -= nn; 34 | } 35 | } 36 | 37 | static void 38 | setbootcmd(int argc, char *argv[]) 39 | { 40 | char *buf, *p, *ep; 41 | int i; 42 | 43 | buf = malloc(1024); 44 | if(buf == nil) 45 | error(Enomem); 46 | p = buf; 47 | ep = buf + 1024; 48 | for(i=0; iref); 13 | if(x <= 0) 14 | panic("incref pc=%#p", getcallerpc(&r)); 15 | return x; 16 | } 17 | 18 | int 19 | decref(Ref *r) 20 | { 21 | int x; 22 | 23 | x = adec(&r->ref); 24 | if(x < 0) 25 | panic("decref pc=%#p", getcallerpc(&r)); 26 | return x; 27 | } 28 | -------------------------------------------------------------------------------- /9K/root/mkfile: -------------------------------------------------------------------------------- 1 | [2]/dev/null sed '' $f 18 | }|sed -e '$!N;s/([^ ])$/\1/;ta' -e 'P;D;b' -e ':a;s/\n//' \ 19 | |sed 's/ +/ /g;s/^([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+) +([^ ]+)+ ([^ ]+ +[^ ]+)(.*)/\2 '^$i^' \5K \3 \1 \7/' 20 | }} 21 | fn netstat {@{ 22 | for(p in tcp udp){ 23 | cd /net/$p; 24 | for(i in `{echo [0-9] [1-9][0-9] [1-9][0-9][0-9] [1-9][0-9][0-9]*|sed 's/\[.*\][ \*]//'}){ 25 | echo -n $p' '$i' *owner* '; 26 | cat $i/status $i/local $i/remote \ 27 | | sed -n -e :a -e '$!N; s/ .*//; s/!/ /; s/\n/ /; ta; 28 | s/([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+)/\1 \3 \5 \4/p' 29 | } 30 | } 31 | }} 32 | 33 | status='' 34 | if(! ~ $#* 0) . $* 35 | . -i '#d/0' 36 | exit $status 37 | -------------------------------------------------------------------------------- /9K/root/tcp23: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | exec /bin/ip/telnetd -at $* 3 | -------------------------------------------------------------------------------- /9K/root/tcp564: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | exec exportfs -r / 3 | -------------------------------------------------------------------------------- /9K/words/CHANGES: -------------------------------------------------------------------------------- 1 | Made 2 | 3 | - get rid of conf, by2pg and vars named m 4 | - add acpi 5 | - add colors to pages and cores 6 | - fixes to exec and rfnomnt 7 | 8 | Quick changes 9 | 10 | - perf counters 11 | - cleanup spurious interrupt handling 12 | - /dev/config, if not there 13 | - regression testing 14 | - add ahci 15 | - add monitor, waitwhile 16 | - aoe from 386 to port 17 | 18 | Slow changes 19 | 20 | - revisit *apic, *ipi, and init code 21 | - int types (look at GiB ull, eg) 22 | - kprof 23 | - sched and lock instrumentation for benchs 24 | - new sched 25 | - new mm 26 | - add XCs 27 | 28 | Researchy changes 29 | 30 | - sems & tubes 31 | - zero copy 32 | -------------------------------------------------------------------------------- /9K/words/mm: -------------------------------------------------------------------------------- 1 | Notes on mm. 2 | 3 | - initialization: 4 | 5 | asminit() 6 | sys->pmstart set to roundup(end, pgsz) 7 | sys->pmend = pmstart 8 | [0, pmstart] allocated as type none 9 | 10 | multiboot() 11 | asmmodinit() and 12 | asmmapinit() 13 | (prints later when called again by main) 14 | asminsert() adjusts things (eg ignores low mem, overlaps...) 15 | sys->pmend = largest addr seen 16 | mmuinit() 17 | archmmu() 18 | m->pgszlg2[0], pgszmask[0], npgsz 19 | cpuidinit() 20 | same for [1] (2M) and [2] (1G) 21 | sys->vmstart = KSEG0 22 | sys->vmunused = vmstart + pmstart rounded to 4KiB 23 | i.e., pmstart in KSEG0 24 | sys->vmunmapped = KSEG0 + 4MiB 25 | sys->vmend = vmstart + TMFM (64MiB kernel memory) 26 | 27 | NB: 28 | mmuinit and walk calls asmmalloc for ptpgs 29 | mmuput calls mallocalign and malloc 30 | if later asmmeminit does not stop taking pages 31 | for the kernel, asmmalloc won't find memory and 32 | mmu will fail to allocate. 33 | 34 | meminit() 35 | asmmeminit() TODO: rename asmmeminit to be meminit()? 36 | 37 | asmalloc from vmunmapped [rnd up to 4KiB] to vmend, type none 38 | TODO: change how this is done; do it directly 39 | map up to vmend with 2MiB in KSEG0 40 | In clu, vmstart:vmend == 0:64M (0x400000) 41 | sys->vmunmapped is now vmend 42 | 43 | map all memory in asm at KSEG2, using larger pages if it can 44 | In clu, from 64M (0x400000) to 1G (0x4000000) 45 | sets asm->base, kbase, npage to reflect the pages there 46 | iallocimit to ½ pages in the kernel memory (vmend - vmstart) 47 | fills palloc pm according to base & npage 48 | 49 | mallocinit() 50 | records tailnuints from sys->vmunused (end or pmstart in KSEG0) 51 | to vmend (up to 64MiB) 52 | nunits grows 128KiB at a time from tailnunits 53 | 54 | pageinit() 55 | takes memory noted in palloc (by meminit) with npage > 0 and 56 | splits banks according to acpi colors and 57 | allocates a Page struct for each one. 58 | But stops when 600MiB have been used, by now. 59 | -------------------------------------------------------------------------------- /AMD64_compiler/6a/mkfile: -------------------------------------------------------------------------------- 1 | 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 | -------------------------------------------------------------------------------- /AMD64_compiler/6c/mkenam: -------------------------------------------------------------------------------- 1 | ed - ../6c/6.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 | -------------------------------------------------------------------------------- /AMD64_compiler/6c/mkfile: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /AMD64_compiler/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 | -------------------------------------------------------------------------------- /AMD64_compiler/6l/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 | void* 51 | mysbrk(ulong size) 52 | { 53 | return (void*)sbrk(size); 54 | } 55 | 56 | double 57 | cputime(void) 58 | { 59 | 60 | struct tms tmbuf; 61 | double ret_val; 62 | 63 | /* 64 | * times() only fials if &tmbuf is invalid. 65 | */ 66 | (void)times(&tmbuf); 67 | /* 68 | * Return the total time (in system clock ticks) 69 | * spent in user code and system 70 | * calls by both the calling process and its children. 71 | */ 72 | ret_val = (double)(tmbuf.tms_utime + tmbuf.tms_stime + 73 | tmbuf.tms_cutime + tmbuf.tms_cstime); 74 | /* 75 | * Convert to seconds. 76 | */ 77 | ret_val *= sysconf(_SC_CLK_TCK); 78 | return ret_val; 79 | 80 | } 81 | -------------------------------------------------------------------------------- /AMD64_compiler/6l/World: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | rfork ne 3 | SRC=`{pwd} 4 | cd .. 5 | @{cd 6c; rc mkenam} 6 | for(a in 6a 6c 6l)@{cd $a; mk nuke; mk install} 7 | cd ../libmach 8 | rm -f 6obj.8 9 | mk -i install 10 | cd ../cmd 11 | rm -f ar.8 nm.8 file.8 size.8 12 | mk -i ar.install nm.install file.install size.install 13 | bind -c $SRC/../../libc /sys/src/libc 14 | objtype=amd64 15 | cd /sys/src 16 | for(lib in lib?*)@{ 17 | cd $lib || exit 18 | mk nuke 19 | mk -i install 20 | } 21 | -------------------------------------------------------------------------------- /AMD64_compiler/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 | -------------------------------------------------------------------------------- /AMD64_compiler/6l/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 | 52 | void 53 | setmalloctag(void *v, ulong pc) 54 | { 55 | USED(v); 56 | USED(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 | -------------------------------------------------------------------------------- /AMD64_compiler/6l/l: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 6l -T0xffff800000000000 -a ta64.6 >M 3 | -------------------------------------------------------------------------------- /AMD64_compiler/6l/map64: -------------------------------------------------------------------------------- 1 | ?m text #ffff800000000000 -1 #20 2 | -------------------------------------------------------------------------------- /AMD64_compiler/6l/mkfile: -------------------------------------------------------------------------------- 1 | QUAD 40 | x peep 41 | ~ MODE 16/32/64 - default operand size, different amode for 16-bit 42 | 43 | x reg num 44 | 0 ax 1 cx 2 dx 3 bx 4 sp 5 bp 6 si 7 di 45 | 46 | - immediate operand values for xmm compare 47 | 0 EQ 48 | 1 LT (or GT with operands exchanged) 49 | 2 LE (or GE with operands exchanged) 50 | 3 unordered 51 | 4 NE 52 | 5 not less than (or not greater than with operands exchanged) 53 | 6 not less than or equal (or not greater than or equal) 54 | 7 ordered 55 | - when exchanging operands, note that 1st operand is overwritten(!) 56 | 57 | abi 58 | x preserved: 59 | rbx, rsp, rbp, r12-r15 60 | 61 | fixes 62 | - 8c (AFMOVW) 63 | - 8l/span.c (Ycl) 64 | - /sys/src/libc/port/malloc.c (ulong) 65 | x JPC was incorrect in 8l 66 | x /sys/src/libc/port/profile.c explicit ref to _subv/_addv, had _ul2v anyhow 67 | - cast in _ptov (ptov should go) 68 | 69 | to do 70 | - long/ulong constants (OCONST) are truncated, because only 32-bit constants are available in 6a (unless not decimal) 71 | x MOVL r,s; MOVLQSX s,s -> MOVLQSX r,s 72 | x see e2.c, e3.c 73 | x fp1.c 74 | - DI hack in sugen 75 | x long as 32 vlong as 64 76 | x fix to float in both versions 77 | x ptrbits? addrbits? uptrint? 78 | x check BSF etc 79 | x update cc (macbody and -.) 80 | x build 6pack dist 81 | x MOVD botch (variously MOVL, MOVQ) 82 | - ../cc/lexbody (ulong)hunk 83 | - ape setjmp (sigsetjmp) 84 | -------------------------------------------------------------------------------- /AMD64_compiler/6l/notes/Pack: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | rfork n 3 | ramfs 4 | mkdir /tmp/empty 5 | bind /tmp/empty /amd64/bin 6 | cd / 7 | bind /tmp/empty /amd64/lib 8 | bind -c $home/tmp /tmp 9 | tar c amd64/include/u*.h amd64/mkfile amd64/bin amd64/lib sys/src/libc sys/src/libmach sys/src/cmd/^(6a 6c 6l cc) | gzip >/tmp/6pack.tgz 10 | -------------------------------------------------------------------------------- /AMD64_compiler/6l/notes/Y: -------------------------------------------------------------------------------- 1 | 14: 0f ae 44 24 00 fxsave 0x0(%rsp) 2 | 19: 0f ae 4c 24 00 fxrstor 0x0(%rsp) 3 | 1e: 0f ae 54 24 00 ldmxcsr 0x0(%rsp) 4 | 23: 0f ae e8 lfence 5 | 26: 0f ae f0 mfence 6 | 29: 0f ae f8 sfence 7 | -------------------------------------------------------------------------------- /AMD64_compiler/6l/notes/Zs: -------------------------------------------------------------------------------- 1 | case Zpseudo: 2 | case Zlit: 3 | case Zm_r: from, reg[p->to.type] 4 | case Zm_r_xm: from, reg[p->to.type] 5 | case Zaut_r: from, reg[p->to.type] 6 | case Zm_o: from, O 7 | case Zr_m: to, reg[p->from.type] 8 | case Zr_m_xm: to, reg[p->from.type] 9 | case Zo_m: to, O 10 | case Zo_m64: to, O 11 | case Zm_ibo: from, O; i8 12 | case Zibo_m: to, O; i8 13 | case Zibo_m_xm: to, O; i8 14 | case Z_ib: i8 15 | case Zib_: i8 16 | case Zib_rp: op+reg[p->to.type], i8 17 | case Zil_rp: op+reg[p->to.type], i16/32 18 | case Ziq_rp: op+reg[p->to.type] complex 19 | case Zib_rr: to, reg[p->to.type] 20 | case Z_il: i16/32 21 | case Zil_: i16/32 22 | case Zm_ilo: from, O; i16/32 23 | case Zilo_m: to, O; i16/32 24 | case Zil_rr: to, reg[p->to.type]; i16/32 25 | case Z_rp: op+reg[p->to.type] 26 | case Zrp_: op+reg[p->from.type] 27 | case Zclr: to, reg[p->to.type] [xor self] 28 | case Zbr: 29 | case Zcall: 30 | case Zjmp: 31 | case Zloop: 32 | case Zbyte: 33 | -------------------------------------------------------------------------------- /AMD64_compiler/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; ipid; 31 | *s = 0; 32 | if(w->msg[0]) 33 | *s = 1; 34 | free(w); 35 | return p; 36 | } 37 | } 38 | 39 | int 40 | mydup(int f1, int f2) 41 | { 42 | return dup(f1,f2); 43 | } 44 | 45 | int 46 | mypipe(int *fd) 47 | { 48 | return pipe(fd); 49 | } 50 | 51 | int 52 | systemtype(int sys) 53 | { 54 | return sys & Plan9; 55 | } 56 | 57 | int 58 | pathchar(void) 59 | { 60 | return '/'; 61 | } 62 | 63 | char* 64 | mygetwd(char *path, int len) 65 | { 66 | return getwd(path, len); 67 | } 68 | 69 | int 70 | myexec(char *path, char *argv[]) 71 | { 72 | return exec(path, argv); 73 | } 74 | 75 | int 76 | myfork(void) 77 | { 78 | return fork(); 79 | } 80 | -------------------------------------------------------------------------------- /AMD64_compiler/cc/compat.c: -------------------------------------------------------------------------------- 1 | #include "cc.h" 2 | #include "compat" 3 | 4 | /* 5 | * fake mallocs 6 | */ 7 | void* 8 | malloc(ulong n) 9 | { 10 | return alloc(n); 11 | } 12 | 13 | void* 14 | calloc(ulong m, ulong n) 15 | { 16 | return alloc(m*n); 17 | } 18 | 19 | void* 20 | realloc(void*, ulong) 21 | { 22 | fprint(2, "realloc called\n"); 23 | abort(); 24 | return 0; 25 | } 26 | 27 | void 28 | free(void*) 29 | { 30 | } 31 | 32 | /* needed when profiling */ 33 | void* 34 | mallocz(ulong size, int clr) 35 | { 36 | void *v; 37 | 38 | v = alloc(size); 39 | if(clr && v != nil) 40 | memset(v, 0, size); 41 | return v; 42 | } 43 | 44 | void 45 | setmalloctag(void*, ulong) 46 | { 47 | } 48 | -------------------------------------------------------------------------------- /AMD64_compiler/cc/mac.c: -------------------------------------------------------------------------------- 1 | #include "cc.h" 2 | 3 | #include "macbody" 4 | -------------------------------------------------------------------------------- /AMD64_compiler/cc/mkfile: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #define INCR ((vlong)(1ULL<<32)) 5 | 6 | vlong j; 7 | 8 | void 9 | main(void) 10 | { 11 | switch(j){ 12 | case 1: 13 | case 2: 14 | case 4: 15 | case 8: 16 | case 16: 17 | case INCR+1LL: 18 | print("0x%016llx %12lld 0x%08x %2d\n", 19 | (uvlong)j, j, (uint)j, (int)j); 20 | break; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /AMD64_compiler/cc/tsw/vlsw.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define INCR ((vlong)(1ULL<<32)) 5 | 6 | int 7 | main(void) 8 | { 9 | vlong i, j; 10 | 11 | for(i = 0; i < 4*INCR; i += INCR){ 12 | for(j = i; j <= i+16; j++){ 13 | switch(j){ 14 | case 1: 15 | case 2: 16 | case 4: 17 | case 8: 18 | case 16: 19 | case INCR+1LL: 20 | print("0x%016llx %12lld 0x%08x %2d\n", 21 | (uvlong)j, j, (uint)j, (int)j); 22 | break; 23 | } 24 | } 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /AMD64_compiler/cc/tsw/vlsw2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define INCR ((vlong)(1ULL<<32)) 5 | 6 | int 7 | main(void) 8 | { 9 | vlong i, j; 10 | 11 | for(i = 0; i < 4*INCR; i += INCR){ 12 | for(j = i; j <= i+16; j++){ 13 | switch((ulong)j){ 14 | case 1: 15 | case 2: 16 | case 4: 17 | case 8: 18 | case 16: 19 | print("0x%016llx %12lld 0x%08x %2d\n", 20 | (uvlong)j, j, (uint)j, (int)j); 21 | break; 22 | default: 23 | {static int x; if(x++ == 0)print("def\n");} 24 | break; 25 | } 26 | } 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /AMD64_compiler/cc/xmachcap.c: -------------------------------------------------------------------------------- 1 | #include "cc.h" 2 | 3 | /* default, like old cc */ 4 | int 5 | machcap(Node* n) 6 | { 7 | if(n == Z) 8 | return 0; 9 | switch(n->op){ 10 | case OCOMMA: 11 | case OCOND: 12 | case OLIST: 13 | return 1; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /PART1/amd64/include/ape/float.h: -------------------------------------------------------------------------------- 1 | #ifndef __FLOAT 2 | #define __FLOAT 3 | /* IEEE, default rounding */ 4 | 5 | #define FLT_ROUNDS 1 6 | #define FLT_RADIX 2 7 | 8 | #define FLT_DIG 6 9 | #define FLT_EPSILON 1.19209290e-07 10 | #define FLT_MANT_DIG 24 11 | #define FLT_MAX 3.40282347e+38 12 | #define FLT_MAX_10_EXP 38 13 | #define FLT_MAX_EXP 128 14 | #define FLT_MIN 1.17549435e-38 15 | #define FLT_MIN_10_EXP -37 16 | #define FLT_MIN_EXP -125 17 | 18 | #define DBL_DIG 15 19 | #define DBL_EPSILON 2.2204460492503131e-16 20 | #define DBL_MANT_DIG 53 21 | #define DBL_MAX 1.797693134862315708145e+308 22 | #define DBL_MAX_10_EXP 308 23 | #define DBL_MAX_EXP 1024 24 | #define DBL_MIN 2.225073858507201383090233e-308 25 | #define DBL_MIN_10_EXP -307 26 | #define DBL_MIN_EXP -1021 27 | #define LDBL_MANT_DIG DBL_MANT_DIG 28 | #define LDBL_EPSILON DBL_EPSILON 29 | #define LDBL_DIG DBL_DIG 30 | #define LDBL_MIN_EXP DBL_MIN_EXP 31 | #define LDBL_MIN DBL_MIN 32 | #define LDBL_MIN_10_EXP DBL_MIN_10_EXP 33 | #define LDBL_MAX_EXP DBL_MAX_EXP 34 | #define LDBL_MAX DBL_MAX 35 | #define LDBL_MAX_10_EXP DBL_MAX_10_EXP 36 | 37 | typedef union FPdbleword FPdbleword; 38 | union FPdbleword 39 | { 40 | double x; 41 | struct { /* little endian */ 42 | long lo; 43 | long hi; 44 | }; 45 | }; 46 | 47 | #ifdef _RESEARCH_SOURCE 48 | /* define stuff needed for floating conversion */ 49 | #define IEEE_8087 1 50 | #define Sudden_Underflow 1 51 | #endif 52 | #ifdef _PLAN9_SOURCE 53 | /* MXCSR */ 54 | /* fcr */ 55 | #define FPFTZ (1<<15) /* amd64 */ 56 | #define FPINEX (1<<12) 57 | #define FPUNFL (1<<11) 58 | #define FPOVFL (1<<10) 59 | #define FPZDIV (1<<9) 60 | #define FPDNRM (1<<8) /* amd64 */ 61 | #define FPINVAL (1<<7) 62 | #define FPDAZ (1<<6) /* amd64 */ 63 | #define FPRNR (0<<13) 64 | #define FPRZ (3<<13) 65 | #define FPRPINF (2<<13) 66 | #define FPRNINF (1<<13) 67 | #define FPRMASK (3<<13) 68 | #define FPPEXT 0 69 | #define FPPSGL 0 70 | #define FPPDBL 0 71 | #define FPPMASK 0 72 | /* fsr */ 73 | #define FPAINEX (1<<5) 74 | #define FPAUNFL (1<<4) 75 | #define FPAOVFL (1<<3) 76 | #define FPAZDIV (1<<2) 77 | #define FPADNRM (1<<1) /* not in plan 9 */ 78 | #define FPAINVAL (1<<0) 79 | #endif 80 | #endif /* __FLOAT */ 81 | -------------------------------------------------------------------------------- /PART1/amd64/include/ape/math.h: -------------------------------------------------------------------------------- 1 | #ifndef __MATH 2 | #define __MATH 3 | #pragma lib "/$M/lib/ape/libap.a" 4 | 5 | /* a HUGE_VAL appropriate for IEEE double-precision */ 6 | /* the correct value, 1.797693134862316e+308, causes a ken overflow */ 7 | #define HUGE_VAL 1.79769313486231e+308 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | extern double acos(double); 14 | extern double asin(double); 15 | extern double atan(double); 16 | extern double atan2(double, double); 17 | extern double cos(double); 18 | extern double sin(double); 19 | extern double tan(double); 20 | extern double cosh(double); 21 | extern double sinh(double); 22 | extern double tanh(double); 23 | extern double exp(double); 24 | extern double frexp(double, int *); 25 | extern double ldexp(double, int); 26 | extern double log(double); 27 | extern double log10(double); 28 | extern double modf(double, double *); 29 | extern double pow(double, double); 30 | extern double sqrt(double); 31 | extern double ceil(double); 32 | extern double fabs(double); 33 | extern double floor(double); 34 | extern double fmod(double, double); 35 | extern double NaN(void); 36 | extern int isNaN(double); 37 | extern double Inf(int); 38 | extern int isInf(double, int); 39 | 40 | #ifdef _RESEARCH_SOURCE 41 | /* does >> treat left operand as unsigned ? */ 42 | #define Unsigned_Shifts 1 43 | #define M_E 2.7182818284590452354 /* e */ 44 | #define M_LOG2E 1.4426950408889634074 /* log 2e */ 45 | #define M_LOG10E 0.43429448190325182765 /* log 10e */ 46 | #define M_LN2 0.69314718055994530942 /* log e2 */ 47 | #define M_LN10 2.30258509299404568402 /* log e10 */ 48 | #define M_PI 3.14159265358979323846 /* pi */ 49 | #define M_PI_2 1.57079632679489661923 /* pi/2 */ 50 | #define M_PI_4 0.78539816339744830962 /* pi/4 */ 51 | #define M_1_PI 0.31830988618379067154 /* 1/pi */ 52 | #define M_2_PI 0.63661977236758134308 /* 2/pi */ 53 | #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 54 | #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 55 | #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 56 | 57 | extern double hypot(double, double); 58 | extern double erf(double); 59 | extern double erfc(double); 60 | extern double j0(double); 61 | extern double y0(double); 62 | extern double j1(double); 63 | extern double y1(double); 64 | extern double jn(int, double); 65 | extern double yn(int, double); 66 | 67 | #endif 68 | 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif /* __MATH */ 75 | -------------------------------------------------------------------------------- /PART1/amd64/include/ape/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDARG 2 | #define __STDARG 3 | 4 | typedef char *va_list; 5 | 6 | #define va_start(list, start) list = (sizeof(start)<8 ? (char *)((long long *)&(start)+1) : \ 7 | (char *)(&(start)+1)) 8 | #define va_end(list) 9 | #define va_arg(list, mode)\ 10 | ((sizeof(mode) == 1)?\ 11 | ((mode*)(list += 8))[-8]:\ 12 | (sizeof(mode) == 2)?\ 13 | ((mode*)(list += 8))[-4]:\ 14 | (sizeof(mode) == 4)?\ 15 | ((mode*)(list += 8))[-2]:\ 16 | ((mode*)(list += sizeof(mode)))[-1]) 17 | 18 | #endif /* __STDARG */ 19 | -------------------------------------------------------------------------------- /PART1/amd64/include/ape/ureg.h: -------------------------------------------------------------------------------- 1 | #ifndef __UREG_H 2 | #define __UREG_H 3 | #if !defined(_PLAN9_SOURCE) 4 | This header file is an extension to ANSI/POSIX 5 | #endif 6 | 7 | struct Ureg { 8 | unsigned long long ax; 9 | unsigned long long bx; 10 | unsigned long long cx; 11 | unsigned long long dx; 12 | unsigned long long si; 13 | unsigned long long di; 14 | unsigned long long bp; 15 | unsigned long long r8; 16 | unsigned long long r9; 17 | unsigned long long r10; 18 | unsigned long long r11; 19 | unsigned long long r12; 20 | unsigned long long r13; 21 | unsigned long long r14; 22 | unsigned long long r15; 23 | 24 | unsigned short ds; 25 | unsigned short es; 26 | unsigned short fs; 27 | unsigned short gs; 28 | 29 | unsigned long long type; 30 | unsigned long long error; /* error code (or zero) */ 31 | unsigned long long ip; /* pc */ 32 | unsigned long long cs; /* old context */ 33 | unsigned long long flags; /* old flags */ 34 | unsigned long long sp; /* sp */ 35 | unsigned long long ss; /* old stack segment */ 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /PART1/amd64/include/gnu/README: -------------------------------------------------------------------------------- 1 | This README file is copied into the directory for GCC-only header files 2 | when fixincludes is run by the makefile for GCC. 3 | 4 | Many of the files in this directory were made from the standard system 5 | header files of this system by the shell script `fixincludes'. 6 | They are system-specific, and will not work on any other kind of system. 7 | They are also not part of GCC. The reason for making the files here 8 | is to fix the places in the header files which use constructs 9 | that are incompatible with ANSI C. 10 | -------------------------------------------------------------------------------- /PART1/amd64/include/gnu/iso646.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1997, 1999 Free Software Foundation, Inc. 2 | 3 | This file is part of GNU CC. 4 | 5 | GNU CC is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2, or (at your option) 8 | any later version. 9 | 10 | GNU CC is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with GNU CC; see the file COPYING. If not, write to 17 | the Free Software Foundation, 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. */ 19 | 20 | /* As a special exception, if you include this header file into source 21 | files compiled by GCC, this header file does not by itself cause 22 | the resulting executable to be covered by the GNU General Public 23 | License. This exception does not however invalidate any other 24 | reasons why the executable file might be covered by the GNU General 25 | Public License. */ 26 | 27 | /* 28 | * ISO C Standard: 7.9 Alternative spellings 29 | */ 30 | 31 | #ifndef _ISO646_H 32 | #define _ISO646_H 33 | 34 | #ifndef __cplusplus 35 | #define and && 36 | #define and_eq &= 37 | #define bitand & 38 | #define bitor | 39 | #define compl ~ 40 | #define not ! 41 | #define not_eq != 42 | #define or || 43 | #define or_eq |= 44 | #define xor ^ 45 | #define xor_eq ^= 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /PART1/amd64/include/gnu/math.h: -------------------------------------------------------------------------------- 1 | #ifndef __MATH 2 | #define __MATH 3 | #pragma lib "/$M/lib/ape/libap.a" 4 | 5 | /* a HUGE_VAL appropriate for IEEE double-precision */ 6 | /* the correct value, 1.797693134862316e+308, causes a ken overflow */ 7 | #define HUGE_VAL 1.79769313486231e+308 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | extern double acos(double); 14 | extern double asin(double); 15 | extern double atan(double); 16 | extern double atan2(double, double); 17 | extern double cos(double); 18 | extern double sin(double); 19 | extern double tan(double); 20 | extern double cosh(double); 21 | extern double sinh(double); 22 | extern double tanh(double); 23 | extern double exp(double); 24 | extern double frexp(double, int *); 25 | extern double ldexp(double, int); 26 | extern double log(double); 27 | extern double log10(double); 28 | extern double modf(double, double *); 29 | extern double pow(double, double); 30 | extern double sqrt(double); 31 | extern double ceil(double); 32 | extern double fabs(double); 33 | extern double floor(double); 34 | extern double fmod(double, double); 35 | extern double NaN(void); 36 | extern int isNaN(double); 37 | extern double Inf(int); 38 | extern int isInf(double, int); 39 | 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | 46 | #ifdef _RESEARCH_SOURCE 47 | /* does >> treat left operand as unsigned ? */ 48 | #define Unsigned_Shifts 1 49 | 50 | extern double hypot(double, double); 51 | #endif 52 | #endif /* __MATH */ 53 | -------------------------------------------------------------------------------- /PART1/amd64/include/gnu/proto.h: -------------------------------------------------------------------------------- 1 | /* This header file is to avoid trouble with semi-ANSI header files 2 | on the Convex in system version 8.0. */ 3 | 4 | #define _PROTO(list) () 5 | -------------------------------------------------------------------------------- /PART1/amd64/include/gnu/stdbool.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. 2 | 3 | This file is part of GNU CC. 4 | 5 | GNU CC is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2, or (at your option) 8 | any later version. 9 | 10 | GNU CC is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with GNU CC; see the file COPYING. If not, write to 17 | the Free Software Foundation, 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. */ 19 | 20 | /* As a special exception, if you include this header file into source 21 | files compiled by GCC, this header file does not by itself cause 22 | the resulting executable to be covered by the GNU General Public 23 | License. This exception does not however invalidate any other 24 | reasons why the executable file might be covered by the GNU General 25 | Public License. */ 26 | 27 | /* 28 | * ISO C Standard: 7.16 Boolean type and values 29 | */ 30 | 31 | #ifndef _STDBOOL_H 32 | #define _STDBOOL_H 33 | 34 | #ifndef __cplusplus 35 | 36 | #define bool _Bool 37 | #define true 1 38 | #define false 0 39 | 40 | #else /* __cplusplus */ 41 | 42 | /* Supporting in C++ is a GCC extension. */ 43 | #define _Bool bool 44 | #define bool bool 45 | #define false false 46 | #define true true 47 | 48 | #endif /* __cplusplus */ 49 | 50 | /* Signal that all the definitions are present. */ 51 | #define __bool_true_false_are_defined 1 52 | 53 | #endif /* stdbool.h */ 54 | -------------------------------------------------------------------------------- /PART1/amd64/include/gnu/ureg.h: -------------------------------------------------------------------------------- 1 | #ifndef __UREG_H 2 | #define __UREG_H 3 | #if !defined(_PLAN9_SOURCE) 4 | This header file is an extension to ANSI/POSIX 5 | #endif 6 | 7 | struct Ureg 8 | { 9 | unsigned long di; /* general registers */ 10 | unsigned long si; /* ... */ 11 | unsigned long bp; /* ... */ 12 | unsigned long nsp; 13 | unsigned long bx; /* ... */ 14 | unsigned long dx; /* ... */ 15 | unsigned long cx; /* ... */ 16 | unsigned long ax; /* ... */ 17 | unsigned long gs; /* data segments */ 18 | unsigned long fs; /* ... */ 19 | unsigned long es; /* ... */ 20 | unsigned long ds; /* ... */ 21 | unsigned long trap; /* trap type */ 22 | unsigned long ecode; /* error code (or zero) */ 23 | unsigned long pc; /* pc */ 24 | unsigned long cs; /* old context */ 25 | unsigned long flags; /* old flags */ 26 | // union { 27 | // unsigned long usp; 28 | unsigned long sp; 29 | // }; 30 | unsigned long ss; /* old stack segment */ 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /PART1/amd64/include/u.h: -------------------------------------------------------------------------------- 1 | #define nil ((void*)0) 2 | typedef unsigned short ushort; 3 | typedef unsigned char uchar; 4 | typedef unsigned long ulong; 5 | typedef unsigned int uint; 6 | typedef signed char schar; 7 | typedef long long vlong; 8 | typedef unsigned long long uvlong; 9 | typedef unsigned long long uintptr; 10 | typedef unsigned long usize; 11 | typedef uint Rune; 12 | typedef union FPdbleword FPdbleword; 13 | typedef uintptr jmp_buf[2]; 14 | #define JMPBUFSP 0 15 | #define JMPBUFPC 1 16 | #define JMPBUFDPC 0 17 | typedef unsigned int mpdigit; /* for /sys/include/mp.h */ 18 | typedef unsigned char u8int; 19 | typedef unsigned short u16int; 20 | typedef unsigned int u32int; 21 | typedef unsigned long long u64int; 22 | 23 | /* MXCSR */ 24 | /* fcr */ 25 | #define FPFTZ (1<<15) /* amd64 */ 26 | #define FPINEX (1<<12) 27 | #define FPUNFL (1<<11) 28 | #define FPOVFL (1<<10) 29 | #define FPZDIV (1<<9) 30 | #define FPDNRM (1<<8) /* amd64 */ 31 | #define FPINVAL (1<<7) 32 | #define FPDAZ (1<<6) /* amd64 */ 33 | #define FPRNR (0<<13) 34 | #define FPRZ (3<<13) 35 | #define FPRPINF (2<<13) 36 | #define FPRNINF (1<<13) 37 | #define FPRMASK (3<<13) 38 | #define FPPEXT 0 39 | #define FPPSGL 0 40 | #define FPPDBL 0 41 | #define FPPMASK 0 42 | /* fsr */ 43 | #define FPAINEX (1<<5) 44 | #define FPAUNFL (1<<4) 45 | #define FPAOVFL (1<<3) 46 | #define FPAZDIV (1<<2) 47 | #define FPADNRM (1<<1) /* not in plan 9 */ 48 | #define FPAINVAL (1<<0) 49 | union FPdbleword 50 | { 51 | double x; 52 | struct { /* little endian */ 53 | uint lo; 54 | uint hi; 55 | }; 56 | }; 57 | 58 | typedef char* va_list; 59 | #define va_start(list, start) list =\ 60 | (sizeof(start) < 8?\ 61 | (char*)((vlong*)&(start)+1):\ 62 | (char*)(&(start)+1)) 63 | #define va_end(list)\ 64 | USED(list) 65 | #define va_arg(list, mode)\ 66 | ((sizeof(mode) == 1)?\ 67 | ((list += 8), (mode*)list)[-8]:\ 68 | (sizeof(mode) == 2)?\ 69 | ((list += 8), (mode*)list)[-4]:\ 70 | (sizeof(mode) == 4)?\ 71 | ((list += 8), (mode*)list)[-2]:\ 72 | ((list += sizeof(mode)), (mode*)list)[-1]) 73 | -------------------------------------------------------------------------------- /PART1/amd64/include/ureg.h: -------------------------------------------------------------------------------- 1 | struct Ureg { 2 | u64int ax; 3 | u64int bx; 4 | u64int cx; 5 | u64int dx; 6 | u64int si; 7 | u64int di; 8 | u64int bp; 9 | u64int r8; 10 | u64int r9; 11 | u64int r10; 12 | u64int r11; 13 | u64int r12; 14 | u64int r13; 15 | u64int r14; 16 | u64int r15; 17 | 18 | u16int ds; 19 | u16int es; 20 | u16int fs; 21 | u16int gs; 22 | 23 | u64int type; 24 | u64int error; /* error code (or zero) */ 25 | u64int ip; /* pc */ 26 | u64int cs; /* old context */ 27 | u64int flags; /* old flags */ 28 | u64int sp; /* sp */ 29 | u64int ss; /* old stack segment */ 30 | }; 31 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/9/amd64/getcallerpc.s: -------------------------------------------------------------------------------- 1 | TEXT getcallerpc(SB), $0 2 | MOVQ -8(RARG), AX 3 | RET 4 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/9/amd64/getfcr.s: -------------------------------------------------------------------------------- 1 | 2 | TEXT setfcr(SB), $4 3 | XORL $(0x3F<<7),RARG /* bits are cleared in csr to enable them */ 4 | ANDL $0xFFC0, RARG /* just the fcr bits */ 5 | WAIT /* is this needed? */ 6 | STMXCSR 0(SP) 7 | MOVL 0(SP), AX 8 | ANDL $~0x3F, AX 9 | ORL RARG, AX 10 | MOVL AX, 0(SP) 11 | LDMXCSR 0(SP) 12 | RET 13 | 14 | TEXT getfcr(SB), $4 15 | WAIT 16 | STMXCSR 0(SP) 17 | MOVWLZX 0(SP), AX 18 | ANDL $0xFFC0, AX 19 | XORL $(0x3F<<7),AX 20 | RET 21 | 22 | TEXT getfsr(SB), $4 23 | WAIT 24 | STMXCSR 0(SP) 25 | MOVL 0(SP), AX 26 | ANDL $0x3F, AX 27 | RET 28 | 29 | TEXT setfsr(SB), $4 30 | ANDL $0x3F, RARG 31 | WAIT 32 | STMXCSR 0(SP) 33 | MOVL 0(SP), AX 34 | ANDL $~0x3F, AX 35 | ORL RARG, AX 36 | MOVL AX, 0(SP) 37 | LDMXCSR 0(SP) 38 | RET 39 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/ap/amd64/_seek.c: -------------------------------------------------------------------------------- 1 | extern long __SEEK(long long*, int, long long, int); 2 | 3 | long long 4 | _SEEK(int fd, long long o, int p) 5 | { 6 | long long l; 7 | 8 | if(__SEEK(&l, fd, o, p) < 0) 9 | l = -1; 10 | return l; 11 | } 12 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/ap/amd64/lock.c: -------------------------------------------------------------------------------- 1 | #define _LOCK_EXTENSION 2 | #include "../plan9/sys9.h" 3 | #include 4 | 5 | int tas(int*); 6 | 7 | void 8 | lock(Lock *lk) 9 | { 10 | while(tas(&lk->val)) 11 | _SLEEP(0); 12 | } 13 | 14 | int 15 | canlock(Lock *lk) 16 | { 17 | if(tas(&lk->val)) 18 | return 0; 19 | return 1; 20 | } 21 | 22 | void 23 | unlock(Lock *lk) 24 | { 25 | lk->val = 0; 26 | } 27 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/ap/amd64/main9.s: -------------------------------------------------------------------------------- 1 | TEXT _main(SB), 1, $(3*8) 2 | 3 | CALL _envsetup(SB) 4 | MOVL inargc-8(FP), RARG 5 | LEAQ inargv+0(FP), AX 6 | MOVQ AX, 8(SP) 7 | MOVQ environ(SB), AX 8 | MOVQ AX, 16(SP) 9 | CALL main(SB) 10 | MOVQ AX, RARG 11 | CALL exit(SB) 12 | RET 13 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/ap/amd64/main9p.s: -------------------------------------------------------------------------------- 1 | TEXT _mainp(SB), 1, $8 2 | 3 | MOVQ AX, _clock(SB) 4 | CALL _profmain(SB) 5 | MOVQ __prof+8(SB), AX 6 | MOVQ AX, __prof+0(SB) 7 | CALL _envsetup(SB) 8 | MOVL inargc-8(FP), RARG 9 | LEAQ inargv+0(FP), AX 10 | MOVQ AX, 8(SP) 11 | CALL main(SB) 12 | 13 | loop: 14 | MOVL AX, RARG 15 | CALL exit(SB) 16 | MOVQ $_profin(SB), AX /* force loading of profile */ 17 | MOVL $0, AX 18 | JMP loop 19 | 20 | TEXT _savearg(SB), 1, $0 21 | RET 22 | 23 | TEXT _callpc(SB), 1, $0 24 | MOVQ 8(RARG), AX 25 | RET 26 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/ap/amd64/mkfile: -------------------------------------------------------------------------------- 1 | APE=/sys/src/ape 2 | objtype=amd64 3 | <$APE/config 4 | LIB=/$objtype/lib/ape/libap.a 5 | OFILES=\ 6 | _seek.$O\ 7 | lock.$O\ 8 | main9.$O\ 9 | main9p.$O\ 10 | notetramp.$O\ 11 | setjmp.$O\ 12 | strchr.$O\ 13 | strlen.$O\ 14 | tas.$O\ 15 | 16 | 4 | #include 5 | 6 | /* A stack to hold pcs when signals nest */ 7 | #define MAXSIGSTACK 20 8 | typedef struct Pcstack Pcstack; 9 | static struct Pcstack { 10 | int sig; 11 | void (*hdlr)(int, char*, Ureg*); 12 | unsigned long long restorepc; 13 | Ureg *u; 14 | } pcstack[MAXSIGSTACK]; 15 | static int nstack = 0; 16 | 17 | static void notecont(Ureg*, char*); 18 | 19 | void 20 | _notetramp(int sig, void (*hdlr)(int, char*, Ureg*), Ureg *u) 21 | { 22 | Pcstack *p; 23 | 24 | if(nstack >= MAXSIGSTACK) 25 | _NOTED(1); /* nesting too deep; just do system default */ 26 | p = &pcstack[nstack]; 27 | p->restorepc = u->ip; 28 | p->sig = sig; 29 | p->hdlr = hdlr; 30 | p->u = u; 31 | nstack++; 32 | u->ip = (unsigned long long) notecont; 33 | _NOTED(2); /* NSAVE: clear note but hold state */ 34 | } 35 | 36 | static void 37 | notecont(Ureg *u, char *s) 38 | { 39 | Pcstack *p; 40 | void(*f)(int, char*, Ureg*); 41 | 42 | p = &pcstack[nstack-1]; 43 | f = p->hdlr; 44 | u->ip = p->restorepc; 45 | nstack--; 46 | (*f)(p->sig, s, u); 47 | _NOTED(3); /* NRSTR */ 48 | } 49 | 50 | #define JMPBUFPC 1 51 | #define JMPBUFSP 0 52 | 53 | extern sigset_t _psigblocked; 54 | 55 | void 56 | siglongjmp(sigjmp_buf j, int ret) 57 | { 58 | struct Ureg *u; 59 | 60 | if(j[0]) 61 | _psigblocked = j[1]; 62 | if(nstack == 0 || pcstack[nstack-1].u->sp > j[2+JMPBUFSP]) 63 | longjmp(j+2, ret); 64 | u = pcstack[nstack-1].u; 65 | nstack--; 66 | u->ax = ret; 67 | if(ret == 0) 68 | u->ax = 1; 69 | u->ip = j[2+JMPBUFPC]; 70 | u->sp = j[2+JMPBUFSP] + 4; 71 | _NOTED(3); /* NRSTR */ 72 | } 73 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/ap/amd64/setjmp.s: -------------------------------------------------------------------------------- 1 | TEXT longjmp(SB), $0 2 | MOVL r+8(FP), AX 3 | CMPL AX, $0 4 | JNE ok /* ansi: "longjmp(0) => longjmp(1)" */ 5 | MOVL $1, AX /* bless their pointed heads */ 6 | ok: 7 | MOVQ 0(RARG), SP /* restore sp */ 8 | MOVQ 8(RARG), BX /* put return pc on the stack */ 9 | MOVQ BX, 0(SP) 10 | RET 11 | 12 | TEXT setjmp(SB), $0 13 | MOVQ SP, 0(RARG) /* store sp */ 14 | MOVQ 0(SP), BX /* store return pc */ 15 | MOVQ BX, 8(RARG) 16 | MOVL $0, AX /* return 0 */ 17 | RET 18 | 19 | TEXT sigsetjmp(SB), $0 20 | MOVL savemask+8(FP), BX 21 | MOVL BX, 0(RARG) 22 | MOVQ $_psigblocked(SB), 8(RARG) 23 | MOVQ SP, 16(RARG) /* store sp */ 24 | MOVQ 0(SP), BX /* store return pc */ 25 | MOVQ BX, 24(RARG) 26 | MOVL $0, AX /* return 0 */ 27 | RET 28 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/ap/amd64/sqrt.s: -------------------------------------------------------------------------------- 1 | TEXT sqrt(SB), $0 2 | MOVSD a+0(FP), X0 3 | SQRTSD X0, X0 4 | RET 5 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/ap/amd64/strchr.s: -------------------------------------------------------------------------------- 1 | TEXT strchr(SB), $0 2 | 3 | MOVQ RARG, DI 4 | MOVB c+8(FP), AX 5 | CMPB AX, $0 6 | JEQ l2 /**/ 7 | 8 | /* 9 | * char is not null 10 | */ 11 | l1: 12 | MOVB (DI), BX 13 | CMPB BX, $0 14 | JEQ ret0 15 | ADDQ $1, DI 16 | CMPB AX, BX 17 | JNE l1 18 | 19 | MOVQ DI, AX 20 | SUBQ $1, AX 21 | RET 22 | 23 | /* 24 | * char is null 25 | */ 26 | l2: 27 | MOVQ $-1, CX 28 | CLD 29 | 30 | REPN; SCASB 31 | 32 | MOVQ DI, AX 33 | SUBQ $1, AX 34 | RET 35 | 36 | ret0: 37 | MOVQ $0, AX 38 | RET 39 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/ap/amd64/strlen.s: -------------------------------------------------------------------------------- 1 | TEXT strlen(SB),$0 2 | 3 | MOVL $0, AX 4 | MOVQ $-1, CX 5 | CLD 6 | /* 7 | * look for end of string 8 | */ 9 | 10 | MOVQ RARG, DI 11 | REPN; SCASB 12 | 13 | MOVQ DI, AX 14 | SUBQ RARG, AX 15 | SUBQ $1, AX 16 | RET 17 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/ap/amd64/tas.s: -------------------------------------------------------------------------------- 1 | TEXT tas(SB),$0 2 | 3 | MOVL $0xdeadead,AX 4 | XCHGL AX,(RARG) 5 | RET 6 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/ap/amd64/xsetjmp.s: -------------------------------------------------------------------------------- 1 | TEXT longjmp(SB), $0 2 | MOVL r+4(FP), AX 3 | CMPL AX, $0 4 | JNE ok /* ansi: "longjmp(0) => longjmp(1)" */ 5 | MOVL $1, AX /* bless their pointed heads */ 6 | ok: MOVL l+0(FP), BX 7 | MOVL 0(BX), SP /* restore sp */ 8 | MOVL 4(BX), BX /* put return pc on the stack */ 9 | MOVL BX, 0(SP) 10 | RET 11 | 12 | TEXT setjmp(SB), $0 13 | MOVL l+0(FP), AX 14 | MOVL SP, 0(AX) /* store sp */ 15 | MOVL 0(SP), BX /* store return pc */ 16 | MOVL BX, 4(AX) 17 | MOVL $0, AX /* return 0 */ 18 | RET 19 | 20 | TEXT sigsetjmp(SB), $0 21 | MOVL buf+0(FP), AX 22 | MOVL savemask+4(FP),BX 23 | MOVL BX,0(AX) 24 | MOVL $_psigblocked(SB),4(AX) 25 | MOVL SP, 8(AX) /* store sp */ 26 | MOVL 0(SP), BX /* store return pc */ 27 | MOVL BX, 12(AX) 28 | MOVL $0, AX /* return 0 */ 29 | RET 30 | -------------------------------------------------------------------------------- /PART1/sys/src/ape/lib/mp/amd64/mkfile: -------------------------------------------------------------------------------- 1 | APE=/sys/src/ape 2 | <$APE/config 3 | 4 | LIB=/$objtype/lib/ape/libmp.a 5 | 6 | SFILES=\ 7 | mpvecadd.s\ 8 | mpvecdigmuladd.s\ 9 | mpvecdigmulsub.s\ 10 | mpvecsub.s\ 11 | mpdigdiv.s\ 12 | 13 | HFILES=\ 14 | /sys/include/ape/mp.h\ 15 | ../../../../libmp/port/dat.h 16 | 17 | OFILES=${SFILES:%.s=%.$O} 18 | 19 | UPDATE=mkfile\ 20 | $HFILES\ 21 | $SFILES\ 22 | 23 | 2 | #include 3 | 4 | extern int _seek(vlong*, int, vlong, int); 5 | 6 | vlong 7 | seek(int fd, vlong o, int p) 8 | { 9 | vlong l; 10 | 11 | if(_seek(&l, fd, o, p) < 0) 12 | l = -1LL; 13 | return l; 14 | } 15 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/argv0.s: -------------------------------------------------------------------------------- 1 | GLOBL argv0(SB), $8 2 | GLOBL _tos(SB), $8 3 | GLOBL _privates(SB), $8 4 | GLOBL _nprivates(SB), $4 5 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/atom.s: -------------------------------------------------------------------------------- 1 | TEXT ainc(SB), 1, $0 /* long ainc(long *); */ 2 | ainclp: 3 | MOVL (RARG), AX /* exp */ 4 | MOVL AX, BX 5 | INCL BX /* new */ 6 | LOCK; CMPXCHGL BX, (RARG) 7 | JNZ ainclp 8 | MOVL BX, AX 9 | RET 10 | 11 | TEXT adec(SB), 1, $0 /* long adec(long*); */ 12 | adeclp: 13 | MOVL (RARG), AX 14 | MOVL AX, BX 15 | DECL BX 16 | LOCK; CMPXCHGL BX, (RARG) 17 | JNZ adeclp 18 | MOVL BX, AX 19 | RET 20 | 21 | /* 22 | * int cas32(u32int *p, u32int ov, u32int nv); 23 | * int cas(uint *p, int ov, int nv); 24 | * int casul(ulong *p, ulong ov, ulong nv); 25 | */ 26 | 27 | TEXT cas32(SB), 1, $0 28 | TEXT cas(SB), 1, $0 29 | TEXT casul(SB), 1, $0 30 | TEXT casl(SB), 1, $0 /* back compat */ 31 | MOVL exp+8(FP), AX 32 | MOVL new+16(FP), BX 33 | LOCK; CMPXCHGL BX, (RARG) 34 | MOVL $1, AX /* use CMOVLEQ etc. here? */ 35 | JNZ _cas32r0 36 | _cas32r1: 37 | RET 38 | _cas32r0: 39 | DECL AX 40 | RET 41 | 42 | /* 43 | * int cas64(u64int *p, u64int ov, u64int nv); 44 | * int casp(void **p, void *ov, void *nv); 45 | */ 46 | 47 | TEXT cas64(SB), 1, $0 48 | TEXT casp(SB), 1, $0 49 | MOVQ exp+8(FP), AX 50 | MOVQ new+16(FP), BX 51 | LOCK; CMPXCHGQ BX, (RARG) 52 | MOVL $1, AX /* use CMOVLEQ etc. here? */ 53 | JNZ _cas64r0 54 | _cas64r1: 55 | RET 56 | _cas64r0: 57 | DECL AX 58 | RET 59 | 60 | /* 61 | * void mfence(void); 62 | */ 63 | TEXT mfence(SB),0,$0 64 | MFENCE 65 | RET 66 | 67 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/cycles.s: -------------------------------------------------------------------------------- 1 | TEXT cycles(SB),1,$0 /* time stamp counter; cycles since power up */ 2 | RDTSC 3 | MOVL AX, 0(RARG) /* lo */ 4 | MOVL DX, 4(RARG) /* hi */ 5 | RET 6 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/getcallerpc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* return type needs to be uintptr */ 5 | uintptr 6 | getcallerpc(void *x) 7 | { 8 | return (((uintptr*)(x))[-1]); 9 | } 10 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/getcallerpc.s.new: -------------------------------------------------------------------------------- 1 | TEXT getcallerpc(SB), $0 2 | MOVQ -8(RARG), AX 3 | RET 4 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/getfcr.s: -------------------------------------------------------------------------------- 1 | 2 | TEXT setfcr(SB), $4 3 | XORL $(0x3F<<7),RARG /* bits are cleared in csr to enable them */ 4 | ANDL $0xFFC0, RARG /* just the fcr bits */ 5 | WAIT /* is this needed? */ 6 | STMXCSR 0(SP) 7 | MOVL 0(SP), AX 8 | ANDL $~0x3F, AX 9 | ORL RARG, AX 10 | MOVL AX, 0(SP) 11 | LDMXCSR 0(SP) 12 | RET 13 | 14 | TEXT getfcr(SB), $4 15 | WAIT 16 | STMXCSR 0(SP) 17 | MOVWLZX 0(SP), AX 18 | ANDL $0xFFC0, AX 19 | XORL $(0x3F<<7),AX 20 | RET 21 | 22 | TEXT getfsr(SB), $4 23 | WAIT 24 | STMXCSR 0(SP) 25 | MOVL 0(SP), AX 26 | ANDL $0x3F, AX 27 | RET 28 | 29 | TEXT setfsr(SB), $4 30 | ANDL $0x3F, RARG 31 | WAIT 32 | STMXCSR 0(SP) 33 | MOVL 0(SP), AX 34 | ANDL $~0x3F, AX 35 | ORL RARG, AX 36 | MOVL AX, 0(SP) 37 | LDMXCSR 0(SP) 38 | RET 39 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/main9.s: -------------------------------------------------------------------------------- 1 | #define NPRIVATES 16 2 | 3 | TEXT _main(SB), 1, $(2*8+NPRIVATES*8) 4 | MOVQ AX, _tos(SB) 5 | LEAQ 16(SP), AX 6 | MOVQ AX, _privates(SB) 7 | MOVL $NPRIVATES, _nprivates(SB) 8 | MOVL inargc-8(FP), RARG 9 | LEAQ inargv+0(FP), AX 10 | MOVQ AX, 8(SP) 11 | CALL main(SB) 12 | 13 | loop: 14 | MOVQ $_exits<>(SB), RARG 15 | CALL exits(SB) 16 | JMP loop 17 | 18 | DATA _exits<>+0(SB)/4, $"main" 19 | GLOBL _exits<>+0(SB), $5 20 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/main9l.s: -------------------------------------------------------------------------------- 1 | /* 2 | * version of main9.s for use in Linux64 test environment with 6load 3 | */ 4 | #define NPRIVATES 16 5 | 6 | /* 7 | * abi expects rbx, rsp, rbp, r12-r15 to be preserved 8 | */ 9 | 10 | TEXT _main(SB), 1, $-1 11 | PUSHQ $0 /* freeze frame */ 12 | MOVQ SP, _origsp(SB) 13 | MOVQ BX, _origbx(SB) 14 | MOVQ BP, _origbp(SB) 15 | MOVQ R12, _origr12(SB) 16 | MOVQ R13, _origr13(SB) 17 | MOVQ R14, _origr14(SB) 18 | MOVQ R15, _origr15(SB) 19 | 20 | MOVQ SP, _tos(SB) 21 | SUBQ $16384, SP 22 | MOVQ SP, _privates(SB) 23 | MOVL $NPRIVATES, _nprivates(SB) 24 | SUBQ $16, SP 25 | MOVQ DI, 0(SP) /* argc */ 26 | MOVQ DI, RARG 27 | MOVQ SI, 8(SP) /* argv */ 28 | MOVQ DX, _svc(SB) 29 | CALL main(SB) 30 | 31 | loop: 32 | MOVQ $_exits<>(SB), RARG 33 | CALL exits(SB) 34 | JMP loop 35 | 36 | TEXT _callsys(SB), $0 37 | MOVQ SP, _newsp(SB) 38 | MOVQ _origsp(SB), SP 39 | MOVQ _svc(SB), R8 40 | MOVQ _sysargs(SB), DI 41 | MOVQ _sysargs+8(SB), SI 42 | MOVQ _sysargs+16(SB), DX 43 | MOVQ _sysargs+24(SB), CX 44 | MOVQ _origbx(SB), BX 45 | MOVQ _origbp(SB), BP 46 | MOVQ _origr12(SB), R12 47 | MOVQ _origr13(SB), R13 48 | MOVQ _origr14(SB), R14 49 | MOVQ _origr15(SB), R15 50 | CALL R8 51 | /* result in RAX */ 52 | MOVQ _newsp(SB), SP 53 | RET 54 | 55 | DATA _exits<>+0(SB)/4, $"main" 56 | GLOBL _exits<>+0(SB), $5 57 | 58 | GLOBL _origsp(SB), $8 59 | GLOBL _origbx(SB), $8 60 | GLOBL _origbp(SB), $8 61 | GLOBL _origr12(SB), $8 62 | GLOBL _origr13(SB), $8 63 | GLOBL _origr14(SB), $8 64 | GLOBL _origr15(SB), $8 65 | GLOBL _newsp(SB), $8 66 | GLOBL _sysargs(SB), $64 67 | GLOBL _svc(SB), $8 68 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/main9p.s: -------------------------------------------------------------------------------- 1 | #define NPRIVATES 16 2 | 3 | TEXT _mainp(SB), 1, $(2*8+NPRIVATES*8) 4 | MOVQ AX, _tos(SB) /* _tos = arg */ 5 | LEAQ 16(SP), AX 6 | MOVQ AX, _privates(SB) 7 | MOVL $NPRIVATES, _nprivates(SB) 8 | 9 | CALL _profmain(SB) /* _profmain(); */ 10 | 11 | MOVQ _tos+0(SB), DX /* _tos->prof.pp = _tos->prof.next; */ 12 | MOVQ 8(DX), CX 13 | MOVQ CX, (DX) 14 | 15 | MOVL inargc-8(FP), RARG /* main(argc, argv); */ 16 | LEAQ inargv+0(FP), AX 17 | MOVQ AX, 8(SP) 18 | CALL main(SB) 19 | 20 | loop: 21 | MOVQ $_exits<>(SB), RARG 22 | CALL exits(SB) 23 | MOVQ $_profin(SB), AX /* force loading of profile */ 24 | JMP loop 25 | 26 | TEXT _savearg(SB), 1, $0 27 | MOVQ RARG, AX 28 | RET 29 | 30 | TEXT _saveret(SB), 1, $0 31 | RET 32 | 33 | TEXT _restorearg(SB), 1, $0 34 | RET /* we want RARG in RARG */ 35 | 36 | TEXT _callpc(SB), 1, $0 37 | MOVQ 8(RARG), AX 38 | RET 39 | 40 | DATA _exits<>+0(SB)/4, $"main" 41 | GLOBL _exits<>+0(SB), $5 42 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/main9x.s: -------------------------------------------------------------------------------- 1 | #define NPRIVATES 16 2 | 3 | TEXT _main(SB), 1, $(2*8+NPRIVATES*8) 4 | MOVQ AX, _tos(SB) 5 | LEAQ 16(SP), AX 6 | MOVQ AX, _privates(SB) 7 | MOVL $NPRIVATES, _nprivates(SB) 8 | MOVL inargc-8(FP), RARG 9 | LEAQ inargv+0(FP), AX 10 | MOVQ AX, 8(SP) 11 | CALL main(SB) 12 | 13 | loop: 14 | MOVQ $_exits<>(SB), RARG 15 | CALL exits(SB) 16 | JMP loop 17 | 18 | DATA _exits<>+0(SB)/4, $"main" 19 | GLOBL _exits<>+0(SB), $5 20 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/memccpy.s: -------------------------------------------------------------------------------- 1 | TEXT memccpy(SB),$0 2 | 3 | MOVL n+24(FP), CX 4 | CMPL CX, $0 5 | JEQ none 6 | MOVQ p2+8(FP), DI 7 | MOVBLZX c+16(FP), AX 8 | CLD 9 | /* 10 | * find the character in the second string 11 | */ 12 | 13 | REPN; SCASB 14 | JEQ found 15 | 16 | /* 17 | * if not found, set count to 'n' 18 | */ 19 | none: 20 | MOVL $0, AX 21 | MOVL n+24(FP), BX 22 | JMP memcpy 23 | 24 | /* 25 | * if found, set count to bytes thru character 26 | */ 27 | found: 28 | MOVQ DI, AX 29 | SUBQ p2+8(FP), AX 30 | MOVQ AX, BX 31 | ADDQ RARG, AX 32 | 33 | /* 34 | * copy the memory 35 | */ 36 | 37 | memcpy: 38 | MOVQ RARG, DI 39 | MOVQ p2+8(FP), SI 40 | /* 41 | * copy whole longs, if aligned 42 | */ 43 | MOVQ DI, DX 44 | ORQ SI, DX 45 | ANDL $3, DX 46 | JNE c3 47 | MOVL BX, CX 48 | SHRQ $2, CX 49 | REP; MOVSL 50 | /* 51 | * copy the rest, by bytes 52 | */ 53 | ANDL $3, BX 54 | c3: 55 | MOVL BX, CX 56 | REP; MOVSB 57 | 58 | RET 59 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/memchr.s: -------------------------------------------------------------------------------- 1 | TEXT memchr(SB),$0 2 | 3 | MOVL n+16(FP), CX 4 | CMPL CX, $0 5 | JEQ none 6 | MOVQ RARG, DI 7 | MOVBLZX c+8(FP), AX 8 | CLD 9 | /* 10 | * SCASB is memchr instruction 11 | */ 12 | 13 | REPN; SCASB 14 | JEQ found 15 | 16 | none: 17 | MOVL $0, AX 18 | RET 19 | 20 | found: 21 | MOVQ DI, AX 22 | SUBQ $1, AX 23 | RET 24 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/memcmp.s: -------------------------------------------------------------------------------- 1 | TEXT memcmp(SB),$0 2 | 3 | MOVL n+16(FP), BX 4 | CMPL BX, $0 5 | JEQ none 6 | MOVQ RARG, DI 7 | MOVQ p2+8(FP), SI 8 | CLD 9 | MOVQ DI, CX 10 | ORQ SI, CX 11 | ANDL $3, CX 12 | JNE c3 13 | /* 14 | * first by longs 15 | */ 16 | 17 | MOVL BX, CX 18 | SHRQ $2, CX 19 | 20 | REP; CMPSL 21 | JNE found 22 | 23 | /* 24 | * then by bytes 25 | */ 26 | ANDL $3, BX 27 | c3: 28 | MOVL BX, CX 29 | REP; CMPSB 30 | JNE found1 31 | 32 | none: 33 | MOVQ $0, AX 34 | RET 35 | 36 | /* 37 | * if long found, 38 | * back up and look by bytes 39 | */ 40 | found: 41 | MOVL $4, CX 42 | SUBQ CX, DI 43 | SUBQ CX, SI 44 | REP; CMPSB 45 | 46 | found1: 47 | JLS lt 48 | MOVQ $-1, AX 49 | RET 50 | lt: 51 | MOVQ $1, AX 52 | RET 53 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/memcpy.s: -------------------------------------------------------------------------------- 1 | TEXT memcpy(SB), $0 2 | MOVQ RARG, DI 3 | MOVQ DI, AX /* return value */ 4 | MOVQ p2+8(FP), SI 5 | MOVL n+16(FP), BX 6 | CMPL BX, $0 7 | JGT _ok 8 | JEQ _return /* nothing to do if n == 0 */ 9 | MOVL $0, SI /* fault if n < 0 */ 10 | 11 | /* 12 | * check and set for backwards: 13 | * (p2 < p1) && ((p2+n) > p1) 14 | */ 15 | _ok: 16 | CMPQ SI, DI 17 | JGT _forward 18 | JEQ _return /* nothing to do if p2 == p1 */ 19 | MOVQ SI, DX 20 | ADDQ BX, DX 21 | CMPQ DX, DI 22 | JGT _back 23 | 24 | /* 25 | * copy whole longs if aligned 26 | */ 27 | _forward: 28 | CLD 29 | MOVQ SI, DX 30 | ORQ DI, DX 31 | ANDL $3, DX 32 | JNE c3f 33 | MOVQ BX, CX 34 | SHRQ $2, CX 35 | ANDL $3, BX 36 | REP; MOVSL 37 | 38 | /* 39 | * copy the rest, by bytes 40 | */ 41 | JEQ _return /* flags set by above ANDL */ 42 | c3f: 43 | MOVL BX, CX 44 | REP; MOVSB 45 | 46 | RET 47 | 48 | /* 49 | * whole thing backwards has 50 | * adjusted addresses 51 | */ 52 | _back: 53 | ADDQ BX, DI 54 | ADDQ BX, SI 55 | STD 56 | SUBQ $4, DI 57 | SUBQ $4, SI 58 | /* 59 | * copy whole longs, if aligned 60 | */ 61 | MOVQ DI, DX 62 | ORQ SI, DX 63 | ANDL $3, DX 64 | JNE c3b 65 | MOVL BX, CX 66 | SHRQ $2, CX 67 | ANDL $3, BX 68 | REP; MOVSL 69 | /* 70 | * copy the rest, by bytes 71 | */ 72 | JEQ _return /* flags set by above ANDL */ 73 | 74 | c3b: 75 | ADDQ $3, DI 76 | ADDQ $3, SI 77 | MOVL BX, CX 78 | REP; MOVSB 79 | 80 | _return: 81 | RET 82 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/memmove.s: -------------------------------------------------------------------------------- 1 | TEXT memmove(SB), $0 2 | MOVQ RARG, DI 3 | MOVQ DI, AX /* return value */ 4 | MOVQ p2+8(FP), SI 5 | MOVL n+16(FP), BX 6 | CMPL BX, $0 7 | JGT _ok 8 | JEQ _return /* nothing to do if n == 0 */ 9 | MOVL $0, SI /* fault if n < 0 */ 10 | 11 | /* 12 | * check and set for backwards: 13 | * (p2 < p1) && ((p2+n) > p1) 14 | */ 15 | _ok: 16 | CMPQ SI, DI 17 | JGT _forward 18 | JEQ _return /* nothing to do if p2 == p1 */ 19 | MOVQ SI, DX 20 | ADDQ BX, DX 21 | CMPQ DX, DI 22 | JGT _back 23 | 24 | /* 25 | * copy whole longs if aligned 26 | */ 27 | _forward: 28 | CLD 29 | MOVQ SI, DX 30 | ORQ DI, DX 31 | ANDL $3, DX 32 | JNE c3f 33 | MOVQ BX, CX 34 | SHRQ $2, CX 35 | ANDL $3, BX 36 | REP; MOVSL 37 | 38 | /* 39 | * copy the rest, by bytes 40 | */ 41 | JEQ _return /* flags set by above ANDL */ 42 | c3f: 43 | MOVL BX, CX 44 | REP; MOVSB 45 | 46 | RET 47 | 48 | /* 49 | * whole thing backwards has 50 | * adjusted addresses 51 | */ 52 | _back: 53 | ADDQ BX, DI 54 | ADDQ BX, SI 55 | STD 56 | SUBQ $4, DI 57 | SUBQ $4, SI 58 | /* 59 | * copy whole longs, if aligned 60 | */ 61 | MOVQ DI, DX 62 | ORQ SI, DX 63 | ANDL $3, DX 64 | JNE c3b 65 | MOVL BX, CX 66 | SHRQ $2, CX 67 | ANDL $3, BX 68 | REP; MOVSL 69 | /* 70 | * copy the rest, by bytes 71 | */ 72 | JEQ _return /* flags set by above ANDL */ 73 | 74 | c3b: 75 | ADDQ $3, DI 76 | ADDQ $3, SI 77 | MOVL BX, CX 78 | REP; MOVSB 79 | 80 | _return: 81 | RET 82 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/memset.s: -------------------------------------------------------------------------------- 1 | TEXT memset(SB),$0 2 | 3 | CLD 4 | MOVQ RARG, DI 5 | MOVBLZX c+8(FP), AX 6 | MOVL n+16(FP), BX 7 | /* 8 | * if not enough bytes, just set bytes 9 | */ 10 | CMPL BX, $9 11 | JLS c3 12 | /* 13 | * if not aligned, just set bytes 14 | */ 15 | MOVQ RARG, CX 16 | ANDL $3,CX 17 | JNE c3 18 | /* 19 | * build word in AX 20 | */ 21 | MOVB AL, AH 22 | MOVL AX, CX 23 | SHLL $16, CX 24 | ORL CX, AX 25 | /* 26 | * set whole longs 27 | */ 28 | c1: 29 | MOVQ BX, CX 30 | SHRQ $2, CX 31 | ANDL $3, BX 32 | REP; STOSL 33 | /* 34 | * set the rest, by bytes 35 | */ 36 | c3: 37 | MOVL BX, CX 38 | REP; STOSB 39 | ret: 40 | MOVQ RARG,AX 41 | RET 42 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/mkfile: -------------------------------------------------------------------------------- 1 | objtype=amd64 2 | 2 | #include 3 | #include 4 | 5 | void 6 | notejmp(void *vr, jmp_buf j, int ret) 7 | { 8 | struct Ureg *r = vr; 9 | 10 | r->ax = ret; 11 | if(ret == 0) 12 | r->ax = 1; 13 | r->ip = j[JMPBUFPC]; 14 | r->sp = j[JMPBUFSP] + 8; 15 | noted(NCONT); 16 | } 17 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/rdpmc.s: -------------------------------------------------------------------------------- 1 | MODE $64 2 | 3 | TEXT rdpmc(SB), 1, $-4 /* performance monitor counter */ 4 | MOVL RARG, CX 5 | RDPMC /* read CX performance counter */ 6 | XCHGL DX, AX /* swap lo/hi, zero-extend */ 7 | SHLQ $32, AX /* hi<<32 */ 8 | ORQ DX, AX /* (hi<<32)|lo */ 9 | RET 10 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/setjmp.s: -------------------------------------------------------------------------------- 1 | TEXT longjmp(SB), $0 2 | MOVL r+8(FP), AX 3 | CMPL AX, $0 4 | JNE ok /* ansi: "longjmp(0) => longjmp(1)" */ 5 | MOVL $1, AX /* bless their pointed heads */ 6 | ok: 7 | MOVQ 0(RARG), SP /* restore sp */ 8 | MOVQ 8(RARG), BX /* put return pc on the stack */ 9 | MOVQ BX, 0(SP) 10 | RET 11 | 12 | TEXT setjmp(SB), $0 13 | MOVQ SP, 0(RARG) /* store sp */ 14 | MOVQ 0(SP), BX /* store return pc */ 15 | MOVQ BX, 8(RARG) 16 | MOVL $0, AX /* return 0 */ 17 | RET 18 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/sqrt.s: -------------------------------------------------------------------------------- 1 | TEXT sqrt(SB), $0 2 | MOVSD a+0(FP), X0 3 | SQRTSD X0, X0 4 | RET 5 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/strcat.s: -------------------------------------------------------------------------------- 1 | TEXT strcat(SB),$0 2 | 3 | MOVL $0, AX 4 | MOVQ $-1, CX 5 | CLD 6 | 7 | /* 8 | * find length of second string 9 | */ 10 | 11 | MOVQ p2+8(FP), DI 12 | REPN; SCASB 13 | 14 | MOVQ DI, BX 15 | SUBQ p2+8(FP), BX 16 | 17 | /* 18 | * find end of first string 19 | */ 20 | 21 | MOVQ RARG, DI 22 | REPN; SCASB 23 | 24 | /* 25 | * copy the memory 26 | */ 27 | SUBQ $1, DI 28 | MOVQ p2+8(FP), SI 29 | /* 30 | * copy whole longs, if aligned 31 | */ 32 | MOVQ DI, CX 33 | ORQ SI, CX 34 | ANDL $3, CX 35 | JNE c3 36 | MOVQ BX, CX 37 | SHRQ $2, CX 38 | REP; MOVSL 39 | /* 40 | * copy the rest, by bytes 41 | */ 42 | ANDL $3, BX 43 | c3: 44 | MOVQ BX, CX 45 | REP; MOVSB 46 | 47 | MOVQ RARG, AX 48 | RET 49 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/strchr.s: -------------------------------------------------------------------------------- 1 | TEXT strchr(SB), $0 2 | 3 | MOVQ RARG, DI 4 | MOVB c+8(FP), AX 5 | CMPB AX, $0 6 | JEQ l2 /**/ 7 | 8 | /* 9 | * char is not null 10 | */ 11 | l1: 12 | MOVB (DI), BX 13 | CMPB BX, $0 14 | JEQ ret0 15 | ADDQ $1, DI 16 | CMPB AX, BX 17 | JNE l1 18 | 19 | MOVQ DI, AX 20 | SUBQ $1, AX 21 | RET 22 | 23 | /* 24 | * char is null 25 | */ 26 | l2: 27 | MOVQ $-1, CX 28 | CLD 29 | 30 | REPN; SCASB 31 | 32 | MOVQ DI, AX 33 | SUBQ $1, AX 34 | RET 35 | 36 | ret0: 37 | MOVQ $0, AX 38 | RET 39 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/strcpy.s: -------------------------------------------------------------------------------- 1 | TEXT strcpy(SB),$0 2 | 3 | MOVL $0, AX 4 | MOVQ $-1, CX 5 | CLD 6 | /* 7 | * find end of second string 8 | */ 9 | 10 | MOVQ p2+8(FP), DI 11 | REPN; SCASB 12 | 13 | MOVQ DI, BX 14 | SUBQ p2+8(FP), BX 15 | 16 | /* 17 | * copy the memory 18 | */ 19 | MOVQ RARG, DI 20 | MOVQ p2+8(FP), SI 21 | /* 22 | * copy whole longs, if aligned 23 | */ 24 | MOVQ DI, CX 25 | ORQ SI, CX 26 | ANDL $3, CX 27 | JNE c3 28 | MOVQ BX, CX 29 | SHRQ $2, CX 30 | REP; MOVSL 31 | /* 32 | * copy the rest, by bytes 33 | */ 34 | ANDL $3, BX 35 | c3: 36 | MOVL BX, CX 37 | REP; MOVSB 38 | 39 | MOVQ RARG, AX 40 | RET 41 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/strlen.s: -------------------------------------------------------------------------------- 1 | TEXT strlen(SB),$0 2 | 3 | MOVL $0, AX 4 | MOVQ $-1, CX 5 | CLD 6 | /* 7 | * look for end of string 8 | */ 9 | 10 | MOVQ RARG, DI 11 | REPN; SCASB 12 | 13 | MOVQ DI, AX 14 | SUBQ RARG, AX 15 | SUBQ $1, AX 16 | RET 17 | -------------------------------------------------------------------------------- /PART1/sys/src/libc/amd64/tas.s: -------------------------------------------------------------------------------- 1 | /* 2 | * The kernel and the libc use the same constant for TAS 3 | */ 4 | TEXT _tas(SB),1,$0 5 | 6 | MOVL $0xdeaddead,AX 7 | XCHGL AX,(RARG) 8 | RET 9 | -------------------------------------------------------------------------------- /PART1/sys/src/libmp/amd64/mkfile: -------------------------------------------------------------------------------- 1 | objtype=amd64 2 | = 2^32 * divisor */ 10 | JHS _divovfl 11 | CMPL BX,CX /* divisor == 0 */ 12 | JE _divovfl 13 | DIVL BX /* AX = DX:AX/BX */ 14 | MOVL AX,0(DI) 15 | RET 16 | 17 | /* return all 1's */ 18 | _divovfl: 19 | NOTL CX 20 | MOVL CX,0(DI) 21 | RET 22 | -------------------------------------------------------------------------------- /PART1/sys/src/libmp/amd64/mpvecadd.s: -------------------------------------------------------------------------------- 1 | /* 2 | * mpvecadd(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *sum) 3 | * 4 | * sum[0:alen] = a[0:alen-1] + b[0:blen-1] 5 | * 6 | * prereq: alen >= blen, sum has room for alen+1 digits 7 | */ 8 | TEXT mpvecadd(SB),$0 9 | 10 | MOVL alen+8(FP),DX 11 | MOVL blen+24(FP),CX 12 | /* MOVL a+0(FP),SI */ 13 | MOVQ RARG, SI 14 | MOVQ b+16(FP),BX 15 | SUBL CX,DX 16 | MOVQ sum+32(FP),DI 17 | XORL BP,BP /* this also sets carry to 0 */ 18 | 19 | /* skip addition if b is zero */ 20 | TESTL CX,CX 21 | JZ _add1 22 | 23 | /* sum[0:blen-1],carry = a[0:blen-1] + b[0:blen-1] */ 24 | _addloop1: 25 | MOVL (SI)(BP*4), AX 26 | ADCL (BX)(BP*4), AX 27 | MOVL AX,(DI)(BP*4) 28 | INCL BP 29 | LOOP _addloop1 30 | 31 | _add1: 32 | /* jump if alen > blen */ 33 | INCL DX 34 | MOVL DX,CX 35 | LOOP _addloop2 36 | 37 | /* sum[alen] = carry */ 38 | _addend: 39 | JC _addcarry 40 | MOVL $0,(DI)(BP*4) 41 | RET 42 | _addcarry: 43 | MOVL $1,(DI)(BP*4) 44 | RET 45 | 46 | /* sum[blen:alen-1],carry = a[blen:alen-1] + 0 */ 47 | _addloop2: 48 | MOVL (SI)(BP*4),AX 49 | ADCL $0,AX 50 | MOVL AX,(DI)(BP*4) 51 | INCL BP 52 | LOOP _addloop2 53 | JMP _addend 54 | 55 | -------------------------------------------------------------------------------- /PART1/sys/src/libmp/amd64/mpvecdigmuladd.s: -------------------------------------------------------------------------------- 1 | /* 2 | * mpvecdigmul(mpdigit *b, int n, mpdigit m, mpdigit *p) 3 | * 4 | * p += b*m 5 | * 6 | * each step look like: 7 | * hi,lo = m*b[i] 8 | * lo += oldhi + carry 9 | * hi += carry 10 | * p[i] += lo 11 | * oldhi = hi 12 | * 13 | * the registers are: 14 | * hi = DX - constrained by hardware 15 | * lo = AX - constrained by hardware 16 | * b+n = SI - can't be BP 17 | * p+n = DI - can't be BP 18 | * i-n = BP 19 | * m = BX 20 | * oldhi = CX 21 | * 22 | */ 23 | TEXT mpvecdigmuladd(SB),$0 24 | 25 | /* MOVQ b+0(FP),SI */ 26 | MOVQ RARG,SI 27 | MOVL n+8(FP),CX 28 | MOVL m+16(FP),BX 29 | MOVQ p+24(FP),DI 30 | MOVL CX,BP 31 | NEGQ BP /* BP = -n */ 32 | SHLL $2,CX 33 | ADDQ CX,SI /* SI = b + n */ 34 | ADDQ CX,DI /* DI = p + n */ 35 | XORL CX,CX 36 | _muladdloop: 37 | MOVL (SI)(BP*4),AX /* lo = b[i] */ 38 | MULL BX /* hi, lo = b[i] * m */ 39 | ADDL CX,AX /* lo += oldhi */ 40 | JCC _muladdnocarry1 41 | INCL DX /* hi += carry */ 42 | _muladdnocarry1: 43 | ADDL AX,(DI)(BP*4) /* p[i] += lo */ 44 | JCC _muladdnocarry2 45 | INCL DX /* hi += carry */ 46 | _muladdnocarry2: 47 | MOVL DX,CX /* oldhi = hi */ 48 | INCQ BP /* i++ */ 49 | JNZ _muladdloop 50 | XORL AX,AX 51 | ADDL CX,(DI)(BP*4) /* p[n] + oldhi */ 52 | ADCL AX,AX /* return carry out of p[n] */ 53 | RET 54 | -------------------------------------------------------------------------------- /PART1/sys/src/libmp/amd64/mpvecdigmulsub.s: -------------------------------------------------------------------------------- 1 | /* 2 | * mpvecdigmulsub(mpdigit *b, int n, mpdigit m, mpdigit *p) 3 | * 4 | * p -= b*m 5 | * 6 | * each step look like: 7 | * hi,lo = m*b[i] 8 | * lo += oldhi + carry 9 | * hi += carry 10 | * p[i] += lo 11 | * oldhi = hi 12 | * 13 | * the registers are: 14 | * hi = DX - constrained by hardware 15 | * lo = AX - constrained by hardware 16 | * b = SI - can't be BP 17 | * p = DI - can't be BP 18 | * i = BP 19 | * n = CX - constrained by LOOP instr 20 | * m = BX 21 | * oldhi = R8 22 | * 23 | */ 24 | TEXT mpvecdigmulsub(SB),$0 25 | 26 | /* MOVL b+0(FP),SI */ 27 | MOVQ RARG,SI 28 | MOVL n+8(FP),CX 29 | MOVL m+16(FP),BX 30 | MOVQ p+24(FP),DI 31 | XORL BP,BP 32 | MOVL BP,R8 33 | _mulsubloop: 34 | MOVL (SI)(BP*4),AX /* lo = b[i] */ 35 | MULL BX /* hi, lo = b[i] * m */ 36 | ADDL R8,AX /* lo += oldhi */ 37 | JCC _mulsubnocarry1 38 | INCL DX /* hi += carry */ 39 | _mulsubnocarry1: 40 | SUBL AX,(DI)(BP*4) 41 | JCC _mulsubnocarry2 42 | INCL DX /* hi += carry */ 43 | _mulsubnocarry2: 44 | MOVL DX,R8 45 | INCL BP 46 | LOOP _mulsubloop 47 | SUBL R8,(DI)(BP*4) 48 | JCC _mulsubnocarry3 49 | MOVQ $-1,AX 50 | RET 51 | _mulsubnocarry3: 52 | MOVQ $1,AX 53 | RET 54 | -------------------------------------------------------------------------------- /PART1/sys/src/libmp/amd64/mpvecsub.s: -------------------------------------------------------------------------------- 1 | /* 2 | * mpvecsub(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *diff) 3 | * 4 | * diff[0:alen-1] = a[0:alen-1] - b[0:blen-1] 5 | * 6 | * prereq: alen >= blen, diff has room for alen digits 7 | */ 8 | TEXT mpvecsub(SB),$0 9 | 10 | /* MOVQ a+0(FP),SI */ 11 | MOVQ RARG, SI 12 | MOVQ b+16(FP),BX 13 | MOVL alen+8(FP),DX 14 | MOVL blen+24(FP),CX 15 | MOVQ diff+32(FP),DI 16 | SUBL CX,DX 17 | XORL BP,BP /* this also sets carry to 0 */ 18 | 19 | /* skip subraction if b is zero */ 20 | TESTL CX,CX 21 | JZ _sub1 22 | 23 | /* diff[0:blen-1],borrow = a[0:blen-1] - b[0:blen-1] */ 24 | _subloop1: 25 | MOVL (SI)(BP*4),AX 26 | SBBL (BX)(BP*4),AX 27 | MOVL AX,(DI)(BP*4) 28 | INCL BP 29 | LOOP _subloop1 30 | 31 | _sub1: 32 | INCL DX 33 | MOVL DX,CX 34 | LOOP _subloop2 35 | RET 36 | 37 | /* diff[blen:alen-1] = a[blen:alen-1] - 0 */ 38 | _subloop2: 39 | MOVL (SI)(BP*4),AX 40 | SBBL $0,AX 41 | MOVL AX,(DI)(BP*4) 42 | INCL BP 43 | LOOP _subloop2 44 | RET 45 | 46 | -------------------------------------------------------------------------------- /PART1/sys/src/libsec/amd64/mkfile: -------------------------------------------------------------------------------- 1 | objtype=amd64 2 | 5 | //#include 6 | 7 | void 8 | lock(Lock *l) 9 | { 10 | if(ainc(&l->key) == 1) 11 | return; /* changed from 0 -> 1: we hold lock */ 12 | /* otherwise wait in kernel */ 13 | while(_SEMACQUIRE(&l->sem, 1) < 0){ 14 | /* interrupted; try again */ 15 | } 16 | } 17 | 18 | void 19 | unlock(Lock *l) 20 | { 21 | if(adec(&l->key) == 0) 22 | return; /* changed from 1 -> 0: no contention */ 23 | _SEMRELEASE(&l->sem, 1); 24 | } 25 | 26 | int 27 | canlock(Lock *l) 28 | { 29 | if(ainc(&l->key) == 1) 30 | return 1; /* changed from 0 -> 1: success */ 31 | /* Undo increment (but don't miss wakeup) */ 32 | if(adec(&l->key) == 0) 33 | return 0; /* changed from 1 -> 0: no contention */ 34 | _SEMRELEASE(&l->sem, 1); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /PART2/src/ape/lib/ap/amd64/mkfile: -------------------------------------------------------------------------------- 1 | APE=/sys/src/ape 2 | objtype=amd64 3 | <$APE/config 4 | LIB=/$objtype/lib/ape/libap.a 5 | OFILES=\ 6 | atom.$O\ 7 | _seek.$O\ 8 | lock.$O\ 9 | main9.$O\ 10 | main9p.$O\ 11 | notetramp.$O\ 12 | setjmp.$O\ 13 | strchr.$O\ 14 | strlen.$O\ 15 | tas.$O\ 16 | 17 | 2 | #include 3 | #include 4 | 5 | void* 6 | amlalloc(int n) 7 | { 8 | return mallocz(n, 1); 9 | } 10 | 11 | void 12 | amlfree(void *p) 13 | { 14 | free(p); 15 | } 16 | -------------------------------------------------------------------------------- /PART3/src/libaml/amldelay.7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ycui1984/enhanced-plan9/372cbf8cee7689c372e7dcfb21580220a79daf2f/PART3/src/libaml/amldelay.7 -------------------------------------------------------------------------------- /PART3/src/libaml/amldelay.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void 6 | amldelay(int) 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /PART3/src/libaml/amlmapio.7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ycui1984/enhanced-plan9/372cbf8cee7689c372e7dcfb21580220a79daf2f/PART3/src/libaml/amlmapio.7 -------------------------------------------------------------------------------- /PART3/src/libaml/amlmapio.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int 6 | amlmapio(Amlio*) 7 | { 8 | return -1; 9 | } 10 | -------------------------------------------------------------------------------- /PART3/src/libaml/amlunmapio.7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ycui1984/enhanced-plan9/372cbf8cee7689c372e7dcfb21580220a79daf2f/PART3/src/libaml/amlunmapio.7 -------------------------------------------------------------------------------- /PART3/src/libaml/amlunmapio.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void 6 | amlunmapio(Amlio*) 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /PART3/src/libaml/mkfile: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | ulong slaves = 2; 5 | long cnt = 0; 6 | int thecount = 5; 7 | 8 | static void ready_detect(void) { 9 | ainc(&cnt); 10 | while (0!=cnt); 11 | } 12 | 13 | static void bench(int id) { 14 | int cnt; 15 | 16 | ready_detect(); 17 | for (cnt = 1; cnt <=thecount; cnt++) { 18 | /* siglock(1, 2); */ 19 | sysr1(0, 0); 20 | } 21 | } 22 | 23 | static void create_slave(void) { 24 | 25 | int ret; 26 | 27 | for (int i = 0; i