shithub: riscv

Download patch

ref: 06f6b1c9e2ab5508b922ead05f89596063e5bcb0
parent: b7e7e5ef3fb563b2f52c15a7a680d814ba477840
author: cinap_lenrek <[email protected]>
date: Wed Dec 17 21:53:49 EST 2014

xen: remove segmentation constants, not used on xen.

--- a/sys/src/9/xen/fns.h
+++ b/sys/src/9/xen/fns.h
@@ -4,8 +4,6 @@
 void	archinit(void);
 void	bootargs(ulong);
 ulong	cankaddr(ulong);
-int		cistrcmp(char*, char*);
-int		cistrncmp(char*, char*, int);
 #define	clearmmucache()				/* x86 doesn't have one */
 void	clockintr(Ureg*, void*);
 int		(*cmpswap)(long*, long, long);
@@ -63,10 +61,7 @@
 int	isaconfig(char*, int, ISAConf*);
 void	kbdenable(void);
 #define	kmapinval()
-void	lgdt(ushort[3]);					// XXX remove and in l.s
-void	lidt(ushort[3]);					// XXX remove and in l.s
 void	links(void);
-void	ltr(ulong);						// XXX remove?
 void	mach0init(void);
 void	mathinit(void);
 void	mb386(void);
--- a/sys/src/9/xen/l.s
+++ b/sys/src/9/xen/l.s
@@ -54,25 +54,6 @@
  * CR4 and the 'model specific registers' should only be read/written
  * after it has been determined the processor supports them
  */
-TEXT lgdt(SB), $0				/* GDTR - global descriptor table */
-	MOVL	gdtptr+0(FP), AX
-	MOVL	(AX), GDTR
-	RET
-
-TEXT lidt(SB), $0				/* IDTR - interrupt descriptor table */
-	MOVL	idtptr+0(FP), AX
-	MOVL	(AX), IDTR
-	RET
-
-TEXT ltr(SB), $0				/* TR - task register */
-	MOVL	tptr+0(FP), AX
-	MOVW	AX, TASK
-	RET
-
-TEXT rtsr(SB), $0
-	MOVW	TASK, AX
-	RET
-
 TEXT _cycles(SB), $0				/* time stamp counter; cycles since power up */
 	RDTSC
 	MOVL	vlong+0(FP), CX			/* &vlong */
@@ -88,13 +69,9 @@
 	MOVL	DX, 4(CX)			/* hi */
 	RET
 	
+/* Xen doesn't let us do this */
 TEXT wrmsr(SB), $0
-	MOVL	index+0(FP), CX
-	MOVL	lo+4(FP), AX
-	MOVL	hi+8(FP), DX
-/* Xen doesn't let us do this
-	WRMSR
- */
+	MOVL	$-1, AX
 	RET
 
 /*
--- a/sys/src/9/xen/main.c
+++ b/sys/src/9/xen/main.c
@@ -118,9 +118,6 @@
 	conf.nmach = 1;
 	MACHP(0) = (Mach*)CPU0MACH;
 	m->pdb = (ulong*)xenstart->pt_base;
-#ifdef NOT
-	m->gdt = (Segdesc*)CPU0GDT;
-#endif
 
 	machinit();
 
@@ -133,15 +130,12 @@
 {
 	int machno;
 	ulong *pdb;
-	Segdesc *gdt;
 
 	machno = m->machno;
 	pdb = m->pdb;
-	gdt = m->gdt;
 	memset(m, 0, sizeof(Mach));
 	m->machno = machno;
 	m->pdb = pdb;
-	m->gdt = gdt;
 	m->perf.period = 1;
 
 	/*
@@ -585,16 +579,6 @@
 	p->kentry = up->kentry;
 	p->pcycles = -p->kentry;
 
-	/* inherit user descriptors */
-	memmove(p->gdt, up->gdt, sizeof(p->gdt));
-
-	/* copy local descriptor table */
-	if(up->ldt != nil && up->nldt > 0){
-		p->ldt = smalloc(sizeof(Segdesc) * up->nldt);
-		memmove(p->ldt, up->ldt, sizeof(Segdesc) * up->nldt);
-		p->nldt = up->nldt;
-	}
-
 	/* save floating point state */
 	s = splhi();
 	switch(up->fpstate & ~FPillegal){
@@ -750,51 +734,3 @@
 	shutdown(ispanic);
 	arch->reset();
 }
-
-int
-cistrcmp(char *a, char *b)
-{
-	int ac, bc;
-
-	for(;;){
-		ac = *a++;
-		bc = *b++;
-	
-		if(ac >= 'A' && ac <= 'Z')
-			ac = 'a' + (ac - 'A');
-		if(bc >= 'A' && bc <= 'Z')
-			bc = 'a' + (bc - 'A');
-		ac -= bc;
-		if(ac)
-			return ac;
-		if(bc == 0)
-			break;
-	}
-	return 0;
-}
-
-int
-cistrncmp(char *a, char *b, int n)
-{
-	unsigned ac, bc;
-
-	while(n > 0){
-		ac = *a++;
-		bc = *b++;
-		n--;
-
-		if(ac >= 'A' && ac <= 'Z')
-			ac = 'a' + (ac - 'A');
-		if(bc >= 'A' && bc <= 'Z')
-			bc = 'a' + (bc - 'A');
-
-		ac -= bc;
-		if(ac)
-			return ac;
-		if(bc == 0)
-			break;
-	}
-
-	return 0;
-}
-
--- a/sys/src/9/xen/mem.h
+++ b/sys/src/9/xen/mem.h
@@ -63,67 +63,14 @@
 
 /*
  *  known x86 segments (in GDT) and their selectors
+ *  using the selectors that xen gives us.
  */
-#define	NULLSEG	0	/* null segment */
-#define	KDSEG	1	/* kernel data/stack */
-#define	KESEG	2	/* kernel executable */	
-#define	UDSEG	3	/* user data/stack */
-#define	UESEG	4	/* user executable */
-#define	TSSSEG	5	/* task segment */
-#define	APMCSEG		6	/* APM code segment */
-#define	APMCSEG16	7	/* APM 16-bit code segment */
-#define	APMDSEG		8	/* APM data segment */
-#define	PROCSEG0	11	/* per process descriptor0 */
-#define	NPROCSEG	3	/* number of per process descriptors */
-#define	NGDT		13	/* number of GDT entries required */
-/* #define	APM40SEG	8	/* APM segment 0x40 */
-
-#define	SELGDT	(0<<2)	/* selector is in gdt */
-#define	SELLDT	(1<<2)	/* selector is in ldt */
-
-#define	SELECTOR(i, t, p)	(((i)<<3) | (t) | (p))
-
-#define	NULLSEL	SELECTOR(NULLSEG, SELGDT, 0)
-/* these are replaced by XEN entries */
-#ifdef NOPE  // XXX investigate more
-#define	KDSEL	SELECTOR(KDSEG, SELGDT, 0)
-#define	KESEL	SELECTOR(KESEG, SELGDT, 0)
-#define	UESEL	SELECTOR(UESEG, SELGDT, 3)
-#define	UDSEL	SELECTOR(UDSEG, SELGDT, 3)
-/* comment out to make sure unused ... */
-
-#define	TSSSEL	SELECTOR(TSSSEG, SELGDT, 0)
-#define	APMCSEL 	SELECTOR(APMCSEG, SELGDT, 0)
-#define	APMCSEL16	SELECTOR(APMCSEG16, SELGDT, 0)
-#define	APMDSEL		SELECTOR(APMDSEG, SELGDT, 0)
-/* #define	APM40SEL	SELECTOR(APM40SEG, SELGDT, 0) */
-#else
-/* use the selectors that xen gives us */
 #define KESEL FLAT_KERNEL_CS
 #define KDSEL FLAT_KERNEL_DS
 #define UESEL FLAT_USER_CS
 #define UDSEL FLAT_USER_DS
-#endif
 
-/*
- *  fields in segment descriptors
- */
-#define	SEGDATA	(0x10<<8)	/* data/stack segment */
-#define	SEGEXEC	(0x18<<8)	/* executable segment */
-#define	SEGTSS	(0x9<<8)	/* TSS segment */
-#define	SEGCG	(0x0C<<8)	/* call gate */
-#define	SEGIG	(0x0E<<8)	/* interrupt gate */
-#define	SEGTG	(0x0F<<8)	/* trap gate */
-#define	SEGTYPE	(0x1F<<8)
-
-#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) */
+#define	NPROCSEG	1	/* number of per process descriptors */
 
 /*
  *  virtual MMU
--- a/sys/src/9/xen/mmu.c
+++ b/sys/src/9/xen/mmu.c
@@ -13,35 +13,10 @@
 #define MFN(pa)		(patomfn[(pa)>>PGSHIFT])
 #define	MAPPN(x)	(paemode? matopfn[*(uvlong*)(&x)>>PGSHIFT]<<PGSHIFT : matopfn[(x)>>PGSHIFT]<<PGSHIFT)
 
-#define	DATASEGM(p) 	{ 0xFFFF, SEGG|SEGB|(0xF<<16)|SEGP|SEGPL(p)|SEGDATA|SEGW }
-#define	EXECSEGM(p) 	{ 0xFFFF, SEGG|SEGD|(0xF<<16)|SEGP|SEGPL(p)|SEGEXEC|SEGR }
-#define	TSSSEGM(b,p)	{ ((b)<<16)|sizeof(Tss),\
-			  ((b)&0xFF000000)|(((b)>>16)&0xFF)|SEGTSS|SEGPL(p)|SEGP }
-
-Segdesc gdt[NGDT] =
-{
-[NULLSEG]	{ 0, 0},		/* null descriptor */
-[KDSEG]		DATASEGM(0),		/* kernel data/stack */
-[KESEG]		EXECSEGM(0),		/* kernel code */
-[UDSEG]		DATASEGM(3),		/* user data/stack */
-[UESEG]		EXECSEGM(3),		/* user code */
-[TSSSEG]	TSSSEGM(0,0),		/* tss segment */
-};
-
 /* note: pdb must already be pinned */
 static void
 taskswitch(Page *pdb, ulong stack)
 {
-	Tss *tss;
-
-	tss = m->tss;
-	tss->ss0 = KDSEL;
-	tss->esp0 = stack;
-	tss->ss1 = KDSEL;
-	tss->esp1 = stack;
-	tss->ss2 = KDSEL;
-	tss->esp2 = stack;
-	//tss->cr3 = pdb;
 	HYPERVISOR_stack_switch(KDSEL, stack);
 	mmuflushtlb(pdb);
 }
@@ -164,10 +139,7 @@
 void
 mmuinit(void)
 {
-//XXX	ulong x;
-//XXX	ushort ptr[3];
 	ulong *pte, npgs, pa;
-	extern int rtsr(void);
 
 	if(paemode){
 		int i;
@@ -193,39 +165,6 @@
 
 	memglobal();
 
-	m->tss = malloc(sizeof(Tss));
-	memset(m->tss, 0, sizeof(Tss));
-	m->tss->iomap = 0xDFFF<<16;
-
-	/*
-	 * We used to keep the GDT in the Mach structure, but it
-	 * turns out that that slows down access to the rest of the
-	 * page.  Since the Mach structure is accessed quite often,
-	 * it pays off anywhere from a factor of 1.25 to 2 on real
-	 * hardware to separate them (the AMDs are more sensitive
-	 * than Intels in this regard).  Under VMware it pays off
-	 * a factor of about 10 to 100.
-	 */
-
-#ifdef we_dont_set_gdt_or_lidt
-	memmove(m->gdt, gdt, sizeof gdt);
-	x = (ulong)m->tss;
-	m->gdt[TSSSEG].d0 = (x<<16)|sizeof(Tss);
-	m->gdt[TSSSEG].d1 = (x&0xFF000000)|((x>>16)&0xFF)|SEGTSS|SEGPL(0)|SEGP;
-
-	ptr[0] = sizeof(gdt)-1;
-	x = (ulong)m->gdt;
-	ptr[1] = x & 0xFFFF;
-	ptr[2] = (x>>16) & 0xFFFF;
-	lgdt(ptr);
-
-	ptr[0] = sizeof(Segdesc)*256-1;
-	x = IDTADDR;
-	ptr[1] = x & 0xFFFF;
-	ptr[2] = (x>>16) & 0xFFFF;
-	lidt(ptr);
-#endif
-
 #ifdef we_may_eventually_want_this
 	/* make kernel text unwritable */
 	for(x = KTZERO; x < (ulong)etext; x += BY2PG){
@@ -237,9 +176,6 @@
 #endif
 
 	taskswitch(0,  (ulong)m + BY2PG);
-#ifdef we_dont_do_this
-	ltr(TSSSEL);
-#endif
 }
 
 void