From b433f551c6cfd85fb40098b5e9253db2327a8cea Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 27 Jun 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-06-27 --- pc/l.s | 96 +++++++++++++++++++++++++++++++++++++++----------- pc/mem.h | 17 +++++++++ pc/mmu.c | 14 -------- port/devscsi.c | 6 +++- port/portfns.h | 26 +++++++------- 5 files changed, 111 insertions(+), 48 deletions(-) diff --git a/pc/l.s b/pc/l.s index 678eb77d277a9aa6508c0bb33783fe29c4ef8ea0..da3e830e53aabe92f286b094097005f5b7b11c03 100644 --- a/pc/l.s +++ b/pc/l.s @@ -1,41 +1,97 @@ #include "mem.h" +TEXT start(SB),$0 + + JMP start16 + /* - * pointer to initial gdt (must be in first 64K of program) + * gdt to get us to 32-bit/segmented/unpaged mode */ -GLOBL gdtptr(SB),$6 +TEXT tgdt(SB),$0 + + /* null descriptor */ + LONG $0 + LONG $0 + + /* data segment descriptor for 4 gigabytes (PL 0) */ + LONG SEGG|SEGB|(0xF<<16)|SEGP|SEGPL(0)|SEGDATA|SEGW + LONG 0xFFFF - DATA gdtptr+0(SB)/2, $(5*8) - DATA gdtptr+2(SB)/4, $gdt(SB) + /* exec segment descriptor for 4 gigabytes (PL 0) */ + LONG SEGG|SEGD|(0xF<<16)|SEGP|SEGPL(p)|SEGEXEC|SEGR + LONG 0xFFFF /* - * pointer to idt (must be in first 64K of program) + * pointer to initial gdt */ -GLOBL idtptr(SB),$6 +TEXT tgdtptr(SB),$0 - DATA idtptr+0(SB)/2, $(6*8) - DATA idtptr+2(SB)/4, $idt(SB) + WORD $(3*8) + LONG $tgdt(SB) /* - * boot processor + * come here in (16bit) real-address mode */ -TEXT start(SB),$0 - +start16: CLI /* disable interrupts */ - /* point CPU at the interrupt/trap table */ - LEAL idtptr(SB),AX -/* MOVL (AX),IDTR /**/ - /* point data segment at low memory */ XORL AX,AX -/* MOVW AX,DS /**/ + MOVW AX,DS + + /* point CPU at the interrupt descriptor table */ + MOVL tgdt(SB),IDTR - /* point CPU at the interrupt/trap table */ - LEAL gdtptr(SB),AX -/* MOVL (AX),GDTR /**/ + /* point CPU at the global descriptor table */ + MOVL gdtptr(SB),GDTR - CALL main(SB) + /* switch to protected mode */ + MOVL CR0,AX + ORL $1,AX + MOVL AX,CR0 + + /* clear prefetch buffer */ + JMP flush + +/* + * come here in USE16 protected mode + */ +flush: + /* map data and stack address to physical memory */ + MOVW $SELECTOR(1, SELGDT, 0),AX + MOVW AX,DS + MOVW AX,ES + MOVW AX,SS + + /* switch to 32 bit code */ + JMPFAR SELECTOR(2, SELGDT, 0):start32 + +/* + * come here in USE32 protected mode + */ +TEXT start32(SB),$0 + + /* clear bss (should use REP) */ + MOVL $edata(SB),SI + MOVL $edata+4(SB),DI + MOVL $end(SB),CX + SUBL DI,CX + SHRL $2,CX + XORL AX,AX + MOVL AX,edata(SB) + CLD + REP + MOVSL (SI),(DI) + + /* set up stack */ + MOVL $mach0(SB),AX + MOVL A0, m(SB) + MOVL $0, 0(A0) + MOVL A0, A7 + ADDL $(MACHSIZE-4), A7 /* start stack under machine struct */ + MOVL $0, u(SB) + + CALL main(SB),$0 /* never returns */ /* diff --git a/pc/mem.h b/pc/mem.h index eac82bc12133d0fab503c327ce8c38449da6293e..2e6ed7dc1e06e3f2a100602fa144045f84450faa 100644 --- a/pc/mem.h +++ b/pc/mem.h @@ -78,3 +78,20 @@ #define UDSEL SELECTOR(UDSEG, SELGDT, 3) #define USSEL SELECTOR(UDSEG, SELGDT, 3) +/* + * fields in segment descriptors + */ +#define SEGDATA (0x10<<8) /* data/stack segment */ +#define SEGEXEC (0x18<<8) /* executable segment */ +#define SEGCG (0x0C<<8) /* call gate */ +#define SEGIG (0x0E<<8) /* interrupt gate */ +#define SEGTG (0x0F<<8) /* task gate */ + +#define SEGP (1<<15) /* segment present */ +#define SEGPL(x) ((x)<<13) /* priority level */ +#define SEGB (1<<22) /* granularity 1==4k (for expand-down) */ +#define SEGG (1<<23) /* granularity 1==4k (for other) */ +#define SEGE (1<<10) /* expand down */ +#define SEGW (1<<9) /* writable (for data/stack) */ +#define SEGR (1<<9) /* readable (for code) */ +#define SEGD (1<<22) /* default 1==32bit (for code) */ diff --git a/pc/mmu.c b/pc/mmu.c index 2663b0ea8dff821bacfe1ec592a50a69f47a7846..7f2fdcd12d078aa97e1ff9e278643255b1fe0f88 100644 --- a/pc/mmu.c +++ b/pc/mmu.c @@ -14,20 +14,6 @@ struct Segdesc ulong d0; ulong d1; }; -#define SEGDATA (0x10<<8) /* data/stack segment */ -#define SEGEXEC (0x18<<8) /* executable segment */ -#define SEGCG (0x0C<<8) /* call gate */ -#define SEGIG (0x0E<<8) /* interrupt gate */ -#define SEGTG (0x0F<<8) /* task gate */ - -#define SEGP (1<<15) /* segment present */ -#define SEGPL(x) ((x)<<13) /* priority level */ -#define SEGB (1<<22) /* granularity 1==4k (for expand-down) */ -#define SEGG (1<<23) /* granularity 1==4k (for other) */ -#define SEGE (1<<10) /* expand down */ -#define SEGW (1<<9) /* writable (for data/stack) */ -#define SEGR (1<<9) /* readable (for code) */ -#define SEGD (1<<22) /* default 1==32bit (for code) */ /* * gate initializers diff --git a/port/devscsi.c b/port/devscsi.c index 1499e86bb4c8833ab4a5dce894ef6edba0fd1c63..0314ec8cec16b9411f32b60927661c0eb564c03f 100644 --- a/port/devscsi.c +++ b/port/devscsi.c @@ -104,7 +104,7 @@ scsiwalk(Chan *c, char *name) void scsistat(Chan *c, char *db) { - devstat(c, db, 0, 0, scsigen); + devstat(c, db, 0, 0, scsigeno); } Chan * @@ -579,5 +579,9 @@ scsictrlintr(void) default: panic("scsi status 0x%2.2ux", status); } + kprint("resetting..."); + PUT(Own_id, ownid); + PUT(Cmd, Reset); + break; } } diff --git a/port/portfns.h b/port/portfns.h index 45a6f0261246ee8ea82c12965d01739a14e3b9c7..ac5c040e2788e38ffb082421cf93bb914d2408c3 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -1,8 +1,8 @@ #define SET(x) x = 0 #define USED(x) if(x) -void alarminit(void); Alarm* alarm(int, void (*)(Alarm*), void*); +void alarminit(void); Block* allocb(ulong); int anyready(void); void append(List**, List*); @@ -12,8 +12,8 @@ void buzz(int, int); void cancel(Alarm*); int cangetc(void*); int canlock(Lock*); -int canqlock(QLock*); int canputc(void*); +int canqlock(QLock*); void chandevinit(void); void chandevreset(void); void chaninit(void); @@ -30,8 +30,8 @@ int consactive(void); Env* copyenv(Env*, int); int decref(Ref*); void delay(int); -void delete0(List**, List*); void delete(List**, List*, List*); +void delete0(List**, List*); Chan* devattach(int, char*); Chan* devclone(Chan*, Chan*); void devdir(Chan*, Qid, char*, long, long, Dir*); @@ -45,8 +45,8 @@ void* dmaalloc(ulong); void dumpqueues(void); void dumpregs(Ureg*); void dumpstack(void); -void envpgclose(Env *); void envcpy(Pgrp*, Pgrp*); +void envpgclose(Env *); int eqchan(Chan*, Chan*, long); int eqqid(Qid, Qid); void error(int); @@ -82,8 +82,8 @@ void insert(List**, List*, List*); void invalidateu(void); void isdir(Chan*); void kbdclock(void); -void kbdrepeat(int); int kbdputc(IOQ*, int); +void kbdrepeat(int); int kprint(char*, ...); void kproc(char*, void(*)(void*), void*); void lights(int); @@ -95,8 +95,8 @@ Orig* lookorig(ulong, ulong, int, Chan*); void machinit(void); void mapstack(Proc*); void mklockseg(Seg*); -void mntdump(void); void mmurelease(Proc*); +void mntdump(void); int mount(Chan*, Chan*, int); int mouseputc(IOQ*, int); Chan* namec(char*, int, int, ulong); @@ -126,10 +126,6 @@ Pgrp* pgrptab(int); int postnote(Proc*, int, char*, int); int pprint(char*, ...); void printinit(void); -int putc(IOQ*, int); -void putstr(char*); -void putstrn(char*, long); -void puts(IOQ*, void*, int); ulong procalarm(ulong); void procdump(void); void procinit0(void); @@ -138,8 +134,12 @@ Block* pullup(Block *, int); Queue* pushq(Stream*, Qinfo*); int putb(Blist*, Block*); void putbq(Blist*, Block*); +int putc(IOQ*, int); void putmmu(ulong, ulong); int putq(Queue*, Block*); +void puts(IOQ*, void*, int); +void putstr(char*); +void putstrn(char*, long); ulong pwait(Waitmsg*); void qlock(QLock*); void qunlock(QLock*); @@ -153,8 +153,8 @@ void sccintr(void); void sccputs(IOQ*, char*, int); void sccsetup(void*); void sccspecial(int, IOQ*, IOQ*, int); -void schedinit(void); void sched(void); +void schedinit(void); long seconds(void); Seg* seg(Proc*, ulong); int segaddr(Seg*, ulong, ulong); @@ -164,13 +164,13 @@ void sleep(Rendez*, int(*)(void*), void*); int splhi(void); int spllo(void); void splx(int); -int streamclose1(Stream*); int streamclose(Chan*); +int streamclose1(Stream*); int streamenter(Stream*); int streamexit(Stream*, int); Devgen streamgen; -void streaminit0(void); void streaminit(void); +void streaminit0(void); Stream* streamnew(ushort, ushort, ushort, Qinfo*, int); void streamopen(Chan*, Qinfo*); int streamparse(char*, Block*);