M pc/l.s => pc/l.s +76 -20
@@ 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 */
/*
M pc/mem.h => pc/mem.h +17 -0
@@ 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) */
M pc/mmu.c => pc/mmu.c +0 -14
@@ 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
M port/devscsi.c => port/devscsi.c +5 -1
@@ 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;
}
}
M port/portfns.h => port/portfns.h +13 -13
@@ 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*);