vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

commit 99843ed18b65e16b10f49b73956f7bfd9c495aac
parent ff994e189d20894dfe7276dd12ac5d5317ae3e8c
Author: Jesus Galan Lopez (yiyus) <yiyu.jgl@gmail.com>
Date:   Wed,  2 Jun 2010 22:56:51 +0200

net device: compiles (in linux), not tested. still a long a way

Diffstat:
src/9vx/Makefrag | 18++++++++++++++----
src/9vx/a/fns.ed | 47+++++++++++++++++++++++++++++++++++++++++++++++
src/9vx/a/fns.h | 50++++++++++++++++++++++++++++++++++++++++++++++----
src/9vx/a/netif.h | 8++++----
src/9vx/a/portfns.h | 20++++++++++----------
src/9vx/a/qlock.c | 18++++++++++--------
src/9vx/devtab.c | 48++++++++++++++++++++++++++++++++++++++++++++++++
src/9vx/main.c | 18+++++++++++++++---
src/9vx/mmu.c | 2+-
src/9vx/sched.c | 8++++----
src/9vx/sdloop.c | 6------
11 files changed, 199 insertions(+), 44 deletions(-)

diff --git a/src/9vx/Makefrag b/src/9vx/Makefrag @@ -19,8 +19,8 @@ endif # If you don't have/want X11 #PLAN9GUI=nogui -#PLAN9NET=virtualip -PLAN9NET=posixip +PLAN9NET=virtualip +#PLAN9NET=posixip PLAN9NATIVEFS=1 @@ -61,7 +61,6 @@ PLAN9_A_OBJS = \ $(addprefix 9vx/a/, \ allocb.o \ auth.o \ - bo.o \ chan.o \ classmask.o \ cleanname.o \ @@ -115,12 +114,21 @@ PLAN9_A_OBJS = \ ) PLAN9_posixip_OBJS = \ + bo.o \ $(addprefix 9vx/, \ devip.o \ devip-posix.o \ ) +PLAN9_posixip_LIBS = PLAN9_virtualip_OBJS = \ + 9vx/etherve.o \ + $(addprefix 9vx/a/,\ + devaoe.o \ + devether.o \ + netif.o \ + sdaoe.o \ + ) \ $(addprefix 9vx/a/ip/,\ arp.o \ chandial.o \ @@ -147,6 +155,7 @@ PLAN9_virtualip_OBJS = \ tcp.o \ udp.o \ ) +PLAN9_virtualip_LIBS = -lpcap PLAN9_nogui_OBJS = \ $(addprefix 9vx/,\ @@ -177,6 +186,7 @@ PLAN9_GUI_OBJS = $(PLAN9_$(PLAN9GUI)_OBJS) PLAN9_GUI_LIBS = $(PLAN9_$(PLAN9GUI)_LIBS) PLAN9_IP_OBJS = $(PLAN9_$(PLAN9NET)_OBJS) +PLAN9_IP_LIBS = $(PLAN9_$(PLAN9NET)_LIBS) ifeq ($(PLAN9NATIVEFS),1) PLAN9_OBJS := $(PLAN9_OBJS) 9vx/fossil.o 9vx/venti.o @@ -195,7 +205,7 @@ PLAN9_DEPS = \ libvx32/libvx32.a \ 9vx/9vx: $(PLAN9_DEPS) - $(HOST_CC) -o $@ $(PLAN9_DEPS) $(PLAN9_GUI_LIBS) -lpthread + $(HOST_CC) -o $@ $(PLAN9_DEPS) $(PLAN9_GUI_LIBS) $(PLAN9_IP_LIBS) -lpthread 9vx/a/%.o: 9vx/a/%.c $(HOST_CC) $(HOST_CFLAGS) -I. -I9vx -I9vx/a -Wall -Wno-missing-braces -c -o $@ $< diff --git a/src/9vx/a/fns.ed b/src/9vx/a/fns.ed @@ -19,4 +19,51 @@ void uartinit(int); #define GSHORT(p) (((p)[1]<<8)|(p)[0]) #define GLONG(p) ((GSHORT(p+2)<<16)|GSHORT(p)) + +void __plock(Psleep*); +void __punlock(Psleep*); +void __pwakeup(Psleep*); +void __psleep(Psleep*); + +extern int tracelock; + +#define lockfngen(type) __ ## type + +#define lockgen(type, arg) \ + do { \ + if (tracelock) { \ + iprint("%s %p %s %d\n", (#type), (arg), __FILE__, __LINE__); \ + lockfngen(type)((arg)); \ + } else { \ + lockfngen(type)((arg)); \ + } \ + } while (0) + +#define qlock(x) lockgen(qlock, (x)) +#define qunlock(x) lockgen(qunlock, (x)) +#define rlock(x) lockgen(rlock, (x)) +#define runlock(x) lockgen(runlock, (x)) +#define wlock(x) lockgen(wlock, (x)) +#define wunlock(x) lockgen(wunlock, (x)) +#define plock(x) lockgen(plock, (x)) +#define punlock(x) lockgen(punlock, (x)) +#define pwakeup(x) lockgen(pwakeup, (x)) +#define psleep(x) lockgen(psleep, (x)) +// #define lock(x) lockgen(lock, (x)) +// #define unlock(x) lockgen(unlock, (x)) +#define lock(x) __lock(x) +#define unlock(x) __unlock(x) +#define canqlock __canqlock +#define canrlock __canrlock + +#define LOCK(x) lock(&((x)->lk)) +#define UNLOCK(x) unlock(&((x)->lk)) +#define CANQLOCK(x) canqlock(&((x)->qlock)) +#define QLOCK(x) qlock(&((x)->qlock)) +#define QUNLOCK(x) qunlock(&((x)->qlock)) +#define CANRLOCK(x) canrlock(&((x)->rwlock)) +#define RLOCK(x) rlock(&((x)->rwlock)) +#define RUNLOCK(x) runlock(&((x)->rwlock)) +#define WLOCK(x) wlock(&((x)->rwlock)) +#define WUNLOCK(x) wunlock(&((x)->rwlock)) . diff --git a/src/9vx/a/fns.h b/src/9vx/a/fns.h @@ -170,8 +170,50 @@ void setsigsegv(int invx32); #define GSHORT(p) (((p)[1]<<8)|(p)[0]) #define GLONG(p) ((GSHORT(p+2)<<16)|GSHORT(p)) -void plock(Psleep*); -void punlock(Psleep*); -void pwakeup(Psleep*); -void psleep(Psleep*); +void __plock(Psleep*); +void __punlock(Psleep*); +void __pwakeup(Psleep*); +void __psleep(Psleep*); + +extern int tracelock; + +#define lockfngen(type) __ ## type + +#define lockgen(type, arg) \ + do { \ + if (tracelock) { \ + iprint("%s %p %s %d\n", (#type), (arg), __FILE__, __LINE__); \ + lockfngen(type)((arg)); \ + } else { \ + lockfngen(type)((arg)); \ + } \ + } while (0) + +#define qlock(x) lockgen(qlock, (x)) +#define qunlock(x) lockgen(qunlock, (x)) +#define rlock(x) lockgen(rlock, (x)) +#define runlock(x) lockgen(runlock, (x)) +#define wlock(x) lockgen(wlock, (x)) +#define wunlock(x) lockgen(wunlock, (x)) +#define plock(x) lockgen(plock, (x)) +#define punlock(x) lockgen(punlock, (x)) +#define pwakeup(x) lockgen(pwakeup, (x)) +#define psleep(x) lockgen(psleep, (x)) +// #define lock(x) lockgen(lock, (x)) +// #define unlock(x) lockgen(unlock, (x)) +#define lock(x) __lock(x) +#define unlock(x) __unlock(x) +#define canqlock __canqlock +#define canrlock __canrlock + +#define LOCK(x) lock(&((x)->lk)) +#define UNLOCK(x) unlock(&((x)->lk)) +#define CANQLOCK(x) canqlock(&((x)->qlock)) +#define QLOCK(x) qlock(&((x)->qlock)) +#define QUNLOCK(x) qunlock(&((x)->qlock)) +#define CANRLOCK(x) canrlock(&((x)->rwlock)) +#define RLOCK(x) rlock(&((x)->rwlock)) +#define RUNLOCK(x) runlock(&((x)->rwlock)) +#define WLOCK(x) wlock(&((x)->rwlock)) +#define WUNLOCK(x) wunlock(&((x)->rwlock)) diff --git a/src/9vx/a/netif.h b/src/9vx/a/netif.h @@ -31,7 +31,7 @@ enum */ struct Netfile { - QLock lk; + QLock qlock; int inuse; ulong mode; @@ -64,7 +64,7 @@ struct Netaddr */ struct Netif { - QLock lk; + QLock qlock; /* multiplexing */ char name[KNAMELEN]; /* for top level directory */ @@ -87,8 +87,8 @@ struct Netif /* statistics */ int misses; - int inpackets; - int outpackets; + uvlong inpackets; + uvlong outpackets; int crcs; /* input crc errors */ int oerrs; /* output errors */ int frames; /* framing errors */ diff --git a/src/9vx/a/portfns.h b/src/9vx/a/portfns.h @@ -32,8 +32,8 @@ void callwithureg(void(*)(Ureg*)); char* chanpath(Chan*); int canlock(Lock*); int canpage(Proc*); -int canqlock(QLock*); -int canrlock(RWlock*); +int __canqlock(QLock*); +int __canrlock(RWlock*); void chandevinit(void); void chandevreset(void); void chandevshutdown(void); @@ -166,7 +166,7 @@ void ksetenv(char*, char*, int); void kstrcpy(char*, char*, int); void kstrdup(char**, char*); long latin1(Rune*, int); -int lock(Lock*); +int __lock(Lock*); void logopen(Log*); void logclose(Log*); char* logctl(Log*, int, char**, Logflag*); @@ -277,7 +277,7 @@ void qhangup(Queue*, char*); int qisclosed(Queue*); int qiwrite(Queue*, void*, int); int qlen(Queue*); -void qlock(QLock*); +void __qlock(QLock*); Queue* qopen(int, int, void (*)(void*), void*); int qpass(Queue*, Block*); int qpassnolim(Queue*, Block*); @@ -287,7 +287,7 @@ long qread(Queue*, void*, int); Block* qremove(Queue*); void qreopen(Queue*); void qsetlimit(Queue*, int); -void qunlock(QLock*); +void __qunlock(QLock*); int qwindow(Queue*); int qwrite(Queue*, void*, int); void qnoblock(Queue*, int); @@ -305,9 +305,9 @@ void renameuser(char*, char*); void resched(char*); void resrcwait(char*); int return0(void*); -void rlock(RWlock*); +void __rlock(RWlock*); long rtctime(void); -void runlock(RWlock*); +void __runlock(RWlock*); Proc* runproc(void); void savefpregs(FPsave*); void sched(void); @@ -361,7 +361,7 @@ int uartstageoutput(Uart*); void unbreak(Proc*); void uncachepage(Page*); long unionread(Chan*, void*, long); -void unlock(Lock*); +void __unlock(Lock*); uvlong us2fastticks(uvlong); void userinit(void); ulong userpc(void); @@ -372,8 +372,8 @@ void validstat(uchar*, int); void* vmemchr(void*, int, int); Proc* wakeup(Rendez*); int walk(Chan**, char**, int, int, int*); -void wlock(RWlock*); -void wunlock(RWlock*); +void __wlock(RWlock*); +void __wunlock(RWlock*); void* xalloc(ulong); void* xallocz(ulong, int); void xfree(void*); diff --git a/src/9vx/a/qlock.c b/src/9vx/a/qlock.c @@ -5,6 +5,8 @@ #include "dat.h" #include "fns.h" +int tracelock = 0; + struct { ulong rlock; ulong rlockq; @@ -15,7 +17,7 @@ struct { } rwstats; void -qlock(QLock *q) +__qlock(QLock *q) { Proc *p; @@ -50,7 +52,7 @@ qlock(QLock *q) } int -canqlock(QLock *q) +__canqlock(QLock *q) { if(!canlock(&q->use)) return 0; @@ -64,7 +66,7 @@ canqlock(QLock *q) } void -qunlock(QLock *q) +__qunlock(QLock *q) { Proc *p; @@ -86,7 +88,7 @@ qunlock(QLock *q) } void -rlock(RWlock *q) +__rlock(RWlock *q) { Proc *p; @@ -115,7 +117,7 @@ rlock(RWlock *q) } void -runlock(RWlock *q) +__runlock(RWlock *q) { Proc *p; @@ -138,7 +140,7 @@ runlock(RWlock *q) } void -wlock(RWlock *q) +__wlock(RWlock *q) { Proc *p; @@ -170,7 +172,7 @@ wlock(RWlock *q) } void -wunlock(RWlock *q) +__wunlock(RWlock *q) { Proc *p; @@ -209,7 +211,7 @@ wunlock(RWlock *q) /* same as rlock but punts if there are any writers waiting */ int -canrlock(RWlock *q) +__canrlock(RWlock *q) { lock(&q->use); rwstats.rlock++; diff --git a/src/9vx/devtab.c b/src/9vx/devtab.c @@ -4,7 +4,10 @@ #include "dat.h" #include "fns.h" #include "error.h" +#include "ip/ip.h" +#include "sd.h" +extern Dev aoedevtab; extern Dev consdevtab; extern Dev rootdevtab; extern Dev pipedevtab; @@ -24,14 +27,20 @@ extern Dev mntloopdevtab; extern Dev dupdevtab; extern Dev sddevtab; extern Dev capdevtab; +extern Dev etherdevtab; + +extern SDifc sdloopifc; +extern SDifc sdaoeifc; Dev *devtab[] = { &rootdevtab, /* must be first */ + &aoedevtab, &audiodevtab, &consdevtab, &drawdevtab, &dupdevtab, &envdevtab, + &etherdevtab, &fsdevtab, &ipdevtab, &mntdevtab, @@ -48,3 +57,42 @@ Dev *devtab[] = { 0 }; +extern void ethervelink(void); +extern void ethermediumlink(void); +extern void loopbackmediumlink(void); +extern void netdevmediumlink(void); +void links(void) { + ethermediumlink(); + loopbackmediumlink(); + netdevmediumlink(); + ethervelink(); +} + +extern void ilinit(Fs*); +extern void tcpinit(Fs*); +extern void udpinit(Fs*); +extern void ipifcinit(Fs*); +extern void icmpinit(Fs*); +extern void icmp6init(Fs*); +extern void greinit(Fs*); +extern void ipmuxinit(Fs*); +extern void espinit(Fs*); +void (*ipprotoinit[])(Fs*) = { + ilinit, + tcpinit, + udpinit, + ipifcinit, + icmpinit, + icmp6init, + greinit, + ipmuxinit, + espinit, + nil, +}; + +SDifc *sdifc[] = +{ + &sdloopifc, + &sdaoeifc, + 0, +}; diff --git a/src/9vx/main.c b/src/9vx/main.c @@ -33,7 +33,7 @@ #include "cursor.h" #include "screen.h" -#define BOOTLINELEN 64 +#define BOOTLINELEN 64 #define BOOTARGSLEN (3584-0x200-BOOTLINELEN) #define MAXCONF 100 @@ -46,6 +46,7 @@ int doabort = 1; // for now int abortonfault; char* argv0; char* conffile = "9vx"; +char* netdev; Conf conf; static char* inifile; @@ -79,7 +80,7 @@ void usage(void) { // TODO(yy): add debug and other options by ron - fprint(2, "usage: 9vx [-p file.ini] [-bgit] [-r root] [-u user]\n"); + fprint(2, "usage: 9vx [-p file.ini] [-bgit] [-n netdev] [-r root] [-u user]\n"); exit(1); } @@ -150,6 +151,9 @@ main(int argc, char **argv) case 'p': inifile = EARGF(usage()); break; + case 'n': + netdev = EARGF(usage()); + break; case 'r': localroot = EARGF(usage()); break; @@ -219,14 +223,20 @@ main(int argc, char **argv) if(bootboot | nogui | initrc | usetty) print("-%s%s%s%s ", bootboot ? "b" : "", nogui ? "g" : "", initrc ? "i " : "", usetty ? "t " : ""); + if(netdev) + print("-n %s ", netdev); print("-r %s -u %s\n", localroot, username); printinit(); procinit0(); initseg(); + if(netdev) + links(); + chandevreset(); if(!singlethread){ - makekprocdev(&ipdevtab); + if(!netdev) + makekprocdev(&ipdevtab); makekprocdev(&fsdevtab); makekprocdev(&drawdevtab); makekprocdev(&audiodevtab); @@ -352,6 +362,8 @@ iniopt(char *name, char *value) initrc = 1; else if(strcmp(name, "localroot") == 0 && !localroot) localroot = value; + else if(strcmp(name, "netdev") == 0 && !netdev) + netdev = value; else if(strcmp(name, "user") == 0 && !username) username = value; else if(strcmp(name, "usetty") == 0) diff --git a/src/9vx/mmu.c b/src/9vx/mmu.c @@ -26,7 +26,7 @@ int tracemmu; * Plan 9 assumes this, and while it's not a ton of work to break that * assumption, it was easier not to. */ -#define MEMSIZE (256<<20) +#define MEMSIZE (256<<20) // same as ../mmu.c:29 (TODO: var) static int pagefile; static char* pagebase; diff --git a/src/9vx/sched.c b/src/9vx/sched.c @@ -174,7 +174,7 @@ struct Pwaiter }; void -plock(Psleep *p) +__plock(Psleep *p) { int r; @@ -193,7 +193,7 @@ plock(Psleep *p) } void -punlock(Psleep *p) +__punlock(Psleep *p) { int r; @@ -202,7 +202,7 @@ punlock(Psleep *p) } void -psleep(Psleep *p) +__psleep(Psleep *p) { int r; Pwaiter w; @@ -218,7 +218,7 @@ psleep(Psleep *p) } void -pwakeup(Psleep *p) +__pwakeup(Psleep *p) { int r; Pwaiter *w; diff --git a/src/9vx/sdloop.c b/src/9vx/sdloop.c @@ -324,11 +324,5 @@ SDifc sdloopifc = { loopwtopctl, }; -SDifc *sdifc[] = -{ - &sdloopifc, - nil -}; -