| plan 9 kernel history: overview | file list | diff list |
1991/0205/gnot/main.c (diff list | history)
| gnot/main.c on 1990/03091 | ||
| 1990/03091 | #include "u.h" #include "lib.h" #include "mem.h" #include "dat.h" #include "fns.h" #include "io.h" #include "ureg.h" #include "init.h" | |
| 1990/1211 | #include <libg.h> #include <gnot.h> | |
| 1990/0613 | typedef struct Boot Boot; struct Boot { | |
| 1990/0312 | long station; long traffic; char user[NAMELEN]; char server[64]; char line[64]; | |
| 1990/0917 | char device; | |
| 1990/0613 | }; | |
| 1990/0312 | #define BOOT ((Boot*)0) | |
| 1990/11211 | char user[NAMELEN]; | |
| 1990/0613 | char bootline[64]; | |
| 1990/0918 | char bootserver[64]; | |
| 1990/0917 | char bootdevice[2]; | |
| 1990/06021 | int bank[2]; | |
| 1990/0312 | void unloadboot(void); | |
| 1990/03091 | void main(void) { | |
| 1990/0921 | u = 0; | |
| 1990/0312 | unloadboot(); | |
| 1990/03091 | machinit(); mmuinit(); confinit(); | |
| 1990/06021 | kmapinit(); | |
| 1990/03091 | printinit(); | |
| 1990/06021 | print("bank 0: %dM bank 1: %dM\n", bank[0], bank[1]); | |
| 1990/03091 | flushmmu(); procinit0(); pgrpinit(); chaninit(); alarminit(); chandevreset(); | |
| 1990/0310 | streaminit(); | |
| 1990/11211 | /* serviceinit(); /**/ /* filsysinit(); /**/ | |
| 1990/03091 | pageinit(); | |
| 1990/06021 | kmapinit(); | |
| 1990/03091 | userinit(); schedinit(); } void | |
| 1990/0312 | unloadboot(void) { | |
| 1990/11211 | strncpy(user, BOOT->user, NAMELEN); | |
| 1990/0613 | memcpy(bootline, BOOT->line, 64); | |
| 1990/0918 | memcpy(bootserver, BOOT->server, 64); | |
| 1990/0917 | bootdevice[0] = BOOT->device; | |
| 1990/0312 | } void | |
| 1990/03091 | machinit(void) { int n; n = m->machno; memset(m, 0, sizeof(Mach)); m->machno = n; m->mmask = 1<<m->machno; | |
| 1990/08163 | m->fpstate = FPinit; | |
| 1990/0905 | fprestore(&initfp); | |
| 1990/03091 | } void mmuinit(void) { ulong l, d, i; /* * Invalidate user addresses */ for(l=0; l<4*1024*1024; l+=BY2PG) putmmu(l, INVALIDPTE); /* | |
| 1990/0320 | * Four meg of usable memory, with top 256K for screen | |
| 1990/03091 | */ | |
| 1990/0320 | for(i=1,l=KTZERO; i<(4*1024*1024-256*1024)/BY2PG; l+=BY2PG,i++) | |
| 1990/03091 | putkmmu(l, PPN(l)|PTEVALID|PTEKERNEL); /* | |
| 1990/0320 | * Screen at top of memory | |
| 1990/03091 | */ for(i=0,d=DISPLAYRAM; i<256*1024/BY2PG; d+=BY2PG,l+=BY2PG,i++) putkmmu(l, PPN(d)|PTEVALID|PTEKERNEL); } void init0(void) { | |
| 1990/0613 | Chan *c; | |
| 1990/1211 | u->nerrlab = 0; m->proc = u->p; u->p->state = Running; u->p->mach = m; spllo(); | |
| 1990/03091 | chandevinit(); u->slash = (*devtab[0].attach)(0); u->dot = clone(u->slash, 0); | |
| 1990/0613 | if(!waserror()){ c = namec("#e/bootline", Acreate, OWRITE, 0600); (*devtab[c->type].write)(c, bootline, 64); | |
| 1990/0918 | close(c); c = namec("#e/bootserver", Acreate, OWRITE, 0600); (*devtab[c->type].write)(c, bootserver, 64); | |
| 1990/0917 | close(c); c = namec("#e/bootdevice", Acreate, OWRITE, 0600); (*devtab[c->type].write)(c, bootdevice, 2); | |
| 1990/0613 | close(c); } poperror(); | |
| 1990/03091 | touser(); } FPsave initfp; void userinit(void) { Proc *p; Seg *s; User *up; | |
| 1990/06021 | KMap *k; | |
| 1990/03091 | p = newproc(); p->pgrp = newpgrp(); strcpy(p->text, "*init*"); | |
| 1990/11211 | strcpy(p->pgrp->user, user); | |
| 1990/1211 | p->fpstate = FPinit; | |
| 1990/03091 | /* * Kernel Stack */ p->sched.pc = (ulong)init0; p->sched.sp = USERADDR+BY2PG-20; /* BUG */ | |
| 1990/1004 | p->sched.sr = SUPER|SPL(0); | |
| 1990/03091 | p->upage = newpage(0, 0, USERADDR|(p->pid&0xFFFF)); /* * User */ | |
| 1990/06021 | k = kmap(p->upage); | |
| 1990/0614 | up = (User*)VA(k); | |
| 1990/03091 | up->p = p; | |
| 1990/06021 | kunmap(k); | |
| 1990/03091 | /* * User Stack */ s = &p->seg[SSEG]; s->proc = p; s->o = neworig(USTKTOP-BY2PG, 1, OWRPERM, 0); s->minva = USTKTOP-BY2PG; s->maxva = USTKTOP; /* * Text */ s = &p->seg[TSEG]; s->proc = p; s->o = neworig(UTZERO, 1, 0, 0); s->o->pte[0].page = newpage(0, 0, UTZERO); | |
| 1990/0802 | s->o->npage = 1; | |
| 1990/06021 | k = kmap(s->o->pte[0].page); | |
| 1990/0614 | memcpy((ulong*)VA(k), initcode, sizeof initcode); | |
| 1990/06021 | kunmap(k); | |
| 1990/03091 | s->minva = UTZERO; s->maxva = UTZERO+BY2PG; ready(p); } void exit(void) { int i; u = 0; splhi(); print("exiting\n"); for(;;) ; } /* * Insert new into list after where */ void insert(List **head, List *where, List *new) { if(where == 0){ new->next = *head; *head = new; }else{ new->next = where->next; where->next = new; } } /* * Insert new into list at end */ void append(List **head, List *new) { List *where; where = *head; if(where == 0) *head = new; else{ while(where->next) where = where->next; where->next = new; } new->next = 0; } /* * Delete old from list */ void delete0(List **head, List *old) { List *l; l = *head; if(l == old){ *head = old->next; return; } while(l->next != old) l = l->next; l->next = old->next; } /* * Delete old from list. where->next is known to be old. */ void delete(List **head, List *where, List *old) { if(where == 0){ *head = old->next; return; } where->next = old->next; } | |
| 1990/06021 | banksize(int base) { ulong va; if(&end > (int *)((KZERO|1024L*1024L)-BY2PG)) return 0; va = UZERO; /* user page 1 is free to play with */ putmmu(va, PTEVALID|(base+0)*1024L*1024L/BY2PG); | |
| 1990/0613 | *(ulong*)va = 0; /* 0 at 0M */ | |
| 1990/06021 | putmmu(va, PTEVALID|(base+1)*1024L*1024L/BY2PG); | |
| 1990/0613 | *(ulong*)va = 1; /* 1 at 1M */ | |
| 1990/06021 | putmmu(va, PTEVALID|(base+4)*1024L*1024L/BY2PG); | |
| 1990/0613 | *(ulong*)va = 4; /* 4 at 4M */ | |
| 1990/06021 | putmmu(va, PTEVALID|(base+0)*1024L*1024L/BY2PG); | |
| 1990/0613 | if(*(ulong*)va == 0) | |
| 1990/06021 | return 16; putmmu(va, PTEVALID|(base+1)*1024L*1024L/BY2PG); | |
| 1990/0613 | if(*(ulong*)va == 1) | |
| 1990/06021 | return 4; | |
| 1990/0613 | putmmu(va, PTEVALID|(base+0)*1024L*1024L/BY2PG); if(*(ulong*)va == 4) | |
| 1990/06021 | return 1; return 0; } | |
| 1990/03091 | Conf conf; void confinit(void) { | |
| 1990/0603 | int mul; | |
| 1990/03091 | conf.nmach = 1; if(conf.nmach > MAXMACH) panic("confinit"); | |
| 1990/06021 | bank[0] = banksize(0); bank[1] = banksize(16); conf.npage0 = (bank[0]*1024*1024)/BY2PG; conf.base0 = 0; conf.npage1 = (bank[1]*1024*1024)/BY2PG; conf.base1 = 16*1024*1024; conf.npage = conf.npage0+conf.npage1; | |
| 1990/1211 | conf.maxialloc = (4*1024*1024-256*1024-BY2PG); | |
| 1990/0612 | mul = 1 + (conf.npage1>0); | |
| 1990/0721 | conf.nproc = 50*mul; | |
| 1991/0205 | conf.npgrp = 20*mul; | |
| 1990/0603 | conf.npte = 700*mul; conf.nmod = 400*mul; | |
| 1990/0312 | conf.nalarm = 1000; | |
| 1990/0603 | conf.norig = 150*mul; | |
| 1990/0721 | conf.nchan = 200*mul; | |
| 1990/0603 | conf.nenv = 100*mul; conf.nenvchar = 8000*mul; conf.npgenv = 200*mul; conf.nmtab = 50*mul; | |
| 1990/0709 | conf.nmount = 80*mul; | |
| 1990/0603 | conf.nmntdev = 10*mul; | |
| 1991/0118 | conf.nmntbuf = conf.nmntdev+5; | |
| 1990/05313 | conf.nmnthdr = 2*conf.nmntdev; | |
| 1990/1127 | conf.nstream = 40 + 32*mul; | |
| 1990/11151 | conf.nqueue = 5 * conf.nstream; | |
| 1990/1127 | conf.nblock = 24 * conf.nstream; | |
| 1990/1115 | conf.nsrv = 16*mul; /* was 32 */ | |
| 1990/0724 | conf.nbitmap = 300*mul; | |
| 1990/0709 | conf.nbitbyte = 300*1024*mul; if(*(uchar*)MOUSE & (1<<4)) conf.nbitbyte *= 2; /* ldepth 1 */ | |
| 1990/0623 | conf.nfont = 10*mul; | |
| 1990/0717 | conf.nurp = 32; | |
| 1990/0911 | conf.nasync = 1; | |
| 1990/1006 | conf.npipe = conf.nstream/2; | |
| 1990/1115 | conf.nservice = 3*mul; /* was conf.nproc/5 */ | |
| 1990/1110 | conf.nfsyschan = 31 + conf.nchan/20; | |
| 1990/1212 | conf.copymode = 0; /* copy on write */ | |
| 1991/0110 | conf.portispaged = 0; | |
| 1990/1211 | } /* * set up floating point for a new process */ void | |
| 1990/1212 | procsetup(Proc *p) | |
| 1990/1211 | { long fpnull; fpnull = 0; splhi(); m->fpstate = FPinit; p->fpstate = FPinit; fprestore((FPsave*)&fpnull); spllo(); } /* * Save the part of the process state. */ void | |
| 1990/1212 | procsave(uchar *state, int len) | |
| 1990/1211 | { Balu *balu; if(len < sizeof(Balu)) panic("save state too small"); balu = (Balu *)state; fpsave(&u->fpsave); if(u->fpsave.type){ if(u->fpsave.size > sizeof u->fpsave.junk) panic("fpsize %d max %d\n", u->fpsave.size, sizeof u->fpsave.junk); fpregsave(u->fpsave.reg); u->p->fpstate = FPactive; m->fpstate = FPdirty; } if(BALU->cr0 != 0xFFFFFFFF) /* balu busy */ memcpy(balu, BALU, sizeof(Balu)); else{ balu->cr0 = 0xFFFFFFFF; BALU->cr0 = 0xFFFFFFFF; } } /* | |
| 1990/1212 | * Restore what procsave() saves | |
| 1990/1211 | * | |
| 1990/1212 | * Procsave() makes sure that what state points to is long enough | |
| 1990/1211 | */ void | |
| 1990/1212 | procrestore(Proc *p, uchar *state) | |
| 1990/1211 | { Balu *balu; balu = (Balu *)state; if(p->fpstate != m->fpstate){ if(p->fpstate == FPinit){ u->p->fpstate = FPinit; fprestore(&initfp); m->fpstate = FPinit; }else{ fpregrestore(u->fpsave.reg); fprestore(&u->fpsave); m->fpstate = FPdirty; } } if(balu->cr0 != 0xFFFFFFFF) /* balu busy */ memcpy(BALU, balu, sizeof balu); | |
| 1990/03091 | } | |