From 42b826e665601dd85f86d39b03aef8ae5ecec299 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 29 Jun 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-06-29 --- pc/l.s | 297 ++++++++++++++++++++-------------------------- pc/main.c | 49 +++++++- pc/mem.h | 2 +- port/deviproute.c | 2 +- 4 files changed, 178 insertions(+), 172 deletions(-) diff --git a/pc/l.s b/pc/l.s index 8834bc808cc88f6da14d3ffbb3e9691474c15f51..0b101bd2070e48d72c37a63343f520aad04225da 100644 --- a/pc/l.s +++ b/pc/l.s @@ -1,212 +1,177 @@ #include "mem.h" -TEXT start(SB),$0 - JMP start16 - /* * gdt to get us to 32-bit/segmented/unpaged mode */ -TEXT tgdt(SB),$0 +GLOBL tgdt(SB),$(6*4) /* null descriptor */ - LONG $0 - LONG $0 + DATA tgdt+0(SB)/4, $0 + DATA tgdt+4(SB)/4, $0 /* data segment descriptor for 4 gigabytes (PL 0) */ - LONG $(SEGG|SEGB|(0xF<<16)|SEGP|SEGPL(0)|SEGDATA|SEGW) - LONG $(0xFFFF) + DATA tgdt+8(SB)/4, $(0xFFFF) + DATA tgdt+12(SB)/4, $(SEGG|SEGB|(0xF<<16)|SEGP|SEGPL(0)|SEGDATA|SEGW) /* exec segment descriptor for 4 gigabytes (PL 0) */ - LONG $(SEGG|SEGD|(0xF<<16)|SEGP|SEGPL(0)|SEGEXEC|SEGR) - LONG $(0xFFFF) + DATA tgdt+16(SB)/4, $(0xFFFF) + DATA tgdt+20(SB)/4, $(SEGG|SEGD|(0xF<<16)|SEGP|SEGPL(0)|SEGEXEC|SEGR) /* * pointer to initial gdt */ -TEXT tgdtptr(SB),$0 +GLOBL tgdtptr(SB),$6 - WORD $(3*8) - LONG tgdt(SB) + DATA tgdtptr+0(SB)/2, $(3*8) + DATA tgdtptr+2(SB)/4, $tgdt(SB) + +TEXT start(SB),$0 /* - * come here in (16bit) real-address mode + * about to walk all over ms/dos - turn off interrupts */ -start16: - CLI /* disable interrupts */ + CLI - /* point data segment at low memory */ - XORL AX,AX - MOVW AX,DS +/* + * move the first 1k bytes down to low core and jump to them + * - looks wierd because it is being assembled by a 32 bit + * assembler for a 16 bit world + */ + MOVL $0,BX + INCL BX + SHLL $(10-1),BX + MOVL BX,CX + MOVL $0,SI + MOVW SI,ES + MOVL SI,DI + CLD + REP + MOVSL +/* JMPFAR* 00:$lowcore(SB) /**/ + BYTE $0xEA + WORD $lowcore(SB) + WORD $0 + +TEXT lowcore(SB),$0 + +/* + * move the next 63K down + */ + MOVL $0,CX + INCL CX + SHLL $(15-1),CX + SUBL BX,CX + SHLL $1,BX + MOVL BX,SI + MOVL BX,DI + REP + MOVSL - /* point CPU at the interrupt descriptor table */ - MOVL tgdt(SB),IDTR +/* + * now that we're in low core, update the DS + */ - /* point CPU at the global descriptor table */ - MOVL gdtptr(SB),GDTR + MOVL $0,BX + MOVW BX,DS - /* switch to protected mode */ +/* + * goto protected mode + */ +/* MOVL tgdtptr(SB),GDTR /**/ + BYTE $0x0f + BYTE $0x01 + BYTE $0x16 + WORD $tgdtptr(SB) MOVL CR0,AX ORL $1,AX MOVL AX,CR0 - /* clear prefetch buffer */ - JMP flush - /* - * come here in USE16 protected mode + * clear prefetch queue (wierd code to avoid optimizations) */ + CLC + JCC flush + MOVL AX,AX flush: - /* map data and stack address to physical memory */ - MOVW $SELECTOR(1, SELGDT, 0),AX + +/* + * set all segs + */ +/* MOVW $SELECTOR(1, SELGDT, 0),AX /**/ + BYTE $0xc7 + BYTE $0xc0 + WORD $SELECTOR(1, SELGDT, 0) MOVW AX,DS - MOVW AX,ES MOVW AX,SS + MOVW AX,ES - /* switch to 32 bit code */ -/* JMPFAR SELECTOR(2, SELGDT, 0):start32 /**/ +/* JMPFAR* SELECTOR(2, SELGDT, 0):$protected(SB) /**/ + BYTE $0xEA + WORD $mode32bit(SB) + WORD $SELECTOR(2, SELGDT, 0) + +TEXT mode32bit(SB),$0 /* - * come here in USE32 protected mode + * print a blue 3 on a red background */ -TEXT start32(SB),$0 - - /* clear bss (should use REP) */ - MOVL $edata(SB),SI - MOVL $edata+4(SB),DI - MOVL $end(SB),CX + MOVL $0xb8100,BX + MOVB $0x33,AL + MOVB AL,(BX) + INCW BX + MOVB $0x43,AL + MOVB AL,(BX) + + /* + * Clear BSS + */ + LEAL edata(SB),SI + LEAL edata+4(SB),DI + MOVL $0,AX + MOVL AX,(SI) + LEAL 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 AX, m(SB) - MOVL $0, 0(AX) - MOVL AX, SP - ADDL $(MACHSIZE-4), AX /* start stack under machine struct */ - MOVL $0, u(SB) - - CALL main(SB),$0 - /* never returns */ - -/* - * first 16 ``standard'' traps - */ -TEXT trap0(SB),$0 + MOVSL - PUSHL $0 /* put on an error code */ - PUSHL $0 - JMP alltrap - -TEXT trap1(SB),$0 - - PUSHL $0 /* put on an error code */ - PUSHL $1 - JMP alltrap - -TEXT trap2(SB),$0 - - PUSHL $0 /* put on an error code */ - PUSHL $2 - JMP alltrap - -TEXT trap3(SB),$0 - - PUSHL $0 /* put on an error code */ - PUSHL $3 - JMP alltrap - -TEXT trap4(SB),$0 - - PUSHL $0 /* put on an error code */ - PUSHL $4 - JMP alltrap - -TEXT trap5(SB),$0 - - PUSHL $0 /* put on an error code */ - PUSHL $5 - JMP alltrap - -TEXT trap6(SB),$0 - - PUSHL $0 /* put on an error code */ - PUSHL $6 - JMP alltrap - -TEXT trap7(SB),$0 - - PUSHL $0 /* put on an error code */ - PUSHL $7 - JMP alltrap - -TEXT trap8(SB),$0 - - PUSHL $8 - JMP alltrap - -TEXT trap9(SB),$0 - - PUSHL $0 /* put on an error code */ - PUSHL $9 - JMP alltrap - -TEXT trap10(SB),$0 - - PUSHL $0 /* put on an error code */ - PUSHL $10 - JMP alltrap - -TEXT trap11(SB),$0 - - PUSHL $11 - JMP alltrap - -TEXT trap12(SB),$0 - - PUSHL $12 - JMP alltrap - -TEXT trap13(SB),$0 - - PUSHL $13 - JMP alltrap - -TEXT trap14(SB),$0 - - PUSHL $14 - JMP alltrap - -TEXT trap15(SB),$0 - - PUSHL $0 /* put on an error code */ - PUSHL $15 - JMP alltrap /* - * invalid trap + * print a blue 4 on a red background */ -TEXT invtrap(SB),$0 - - PUSHL $0 /* put on an error code */ - PUSHL $16 - JMP alltrap + MOVL $0xb8100,BX + MOVB $0x34,AL + MOVB AL,(BX) + INCW BX + MOVB $0x43,AL + MOVB AL,(BX) +here: + JMP here + + + /* + * stack and mach + */ + MOVL $mach0(SB),SP + MOVL SP,m(SB) + MOVL $0,0(SP) + ADDL $(MACHSIZE-4),SP /* start stack under machine struct */ + MOVL $0, u(SB) + CALL main(SB) /* - * common trap code + * print a blue 4 on a red background */ -alltrap: - -/* PUSHL DS /**/ - PUSHAL - MOVL $KDSEL, AX -/* MOVW AX, DS /**/ - CALL trap(SB) - POPAL -/* POPL DS /**/ - ADDL $8,SP /* pop the trap and error codes */ - IRETL + MOVL $0xb8100,BX + MOVB $0x34,AL + MOVB AL,(BX) + INCW BX + MOVB $0x43,AL + MOVB AL,(BX) + +loop: + JMP loop + +GLOBL mach0+0(SB), $MACHSIZE +GLOBL u(SB), $4 +GLOBL m(SB), $4 diff --git a/pc/main.c b/pc/main.c index da4872081e3022eaed39a0bdc171c2a93dbf1af5..85674fad9746c3ca5b2acd5372f8b4610821e328 100644 --- a/pc/main.c +++ b/pc/main.c @@ -1,15 +1,56 @@ -main(void) +#include + +#define WIDTH 80 +#define HEIGHT 22 +#define SCREEN ((char *)0xB8000) +int pos; + +void +prchar(int x) { + if(x == '\n'){ + pos = pos/WIDTH; + pos = (pos+1)*WIDTH; + } else { + SCREEN[pos++] = x; + SCREEN[pos++] = 0x43; + } + if(pos >= WIDTH*HEIGHT) + pos = 0; } -trap(void) +void +prstr(char *s) { + while(*s) + prchar(*s++); } -edata(void) +void +prdig(ulong x) { + if(x < 0xA) + prchar('0' + x); + else + prchar('A' + x); } -end(void) +void +prhex(ulong x) { + ulong y; + + if(x <= 0xF){ + prdig(x); + } else { + y = x&0xF; + prhex(x>>4); + prdig(y); + } } + +main(void) +{ + prstr("hello world\n"); +} + diff --git a/pc/mem.h b/pc/mem.h index 2e6ed7dc1e06e3f2a100602fa144045f84450faa..f66a8fb83cf74b889eaa2d07f114cd3868ba391d 100644 --- a/pc/mem.h +++ b/pc/mem.h @@ -68,7 +68,7 @@ #define SELGDT (0<<3) /* selector is in gdt */ #define SELLDT (1<<3) /* selector is in ldt */ -#define SELECTOR(i, t, p) (((i)<<4) | (t) | (p)) +#define SELECTOR(i, t, p) (((i)<<3) | (t) | (p)) #define NULLSEL SELECTOR(NULLSEG, SELGDT, 0) #define KESEL SELECTOR(KESEG, SELGDT, 0) diff --git a/port/deviproute.c b/port/deviproute.c index 2a6abb6f721f949b5b557f3dc4ec498a073f1ec2..0b2167618bf864082b9d9138fb86efc9e651e297 100644 --- a/port/deviproute.c +++ b/port/deviproute.c @@ -190,7 +190,7 @@ enum{ Qdata, }; Dirtab iproutetab[]={ - "iproute", {Qdata}, 0, 0600, + "iproute", {Qdata}, 0, 0666, }; #define Niproutetab (sizeof(iproutetab)/sizeof(Dirtab))