annotate loader/setup_FS.c @ 334:8bd3e3135e23

status changed, bugfixes, new codecs
author arpi_esp
date Tue, 10 Apr 2001 23:45:07 +0000
parents a2c9731b2e01
children 1f7c824033fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
236
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
1 #include <string.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
2 #include <stdlib.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
3 #include <errno.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
4 #include <fcntl.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
5 #include <sys/mman.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
6 #include <sys/types.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
7 #include <stdio.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
8 #include <unistd.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
9
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
10 #ifdef __linux__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
11 #include <asm/unistd.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
12 #include <asm/ldt.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
13 #else
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
14
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
15 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
16 #include <machine/sysarch.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
17 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
18
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
19 #ifdef __svr4__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
20 #include <sys/segment.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
21 #include <sys/sysi86.h>
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
22 /* solaris x86: add missing prototype for sysi86() */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
23 extern int sysi86(int, void*);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
24 #define TEB_SEL_IDX NUMSYSLDTS
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
25 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
26
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
27 #define LDT_ENTRIES 8192
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
28 #define LDT_ENTRY_SIZE 8
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
29 #pragma pack(4)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
30 struct modify_ldt_ldt_s {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
31 unsigned int entry_number;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
32 unsigned long base_addr;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
33 unsigned int limit;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
34 unsigned int seg_32bit:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
35 unsigned int contents:2;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
36 unsigned int read_exec_only:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
37 unsigned int limit_in_pages:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
38 unsigned int seg_not_present:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
39 unsigned int useable:1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
40 };
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
41
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
42 #define MODIFY_LDT_CONTENTS_DATA 0
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
43 #define MODIFY_LDT_CONTENTS_STACK 1
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
44 #define MODIFY_LDT_CONTENTS_CODE 2
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
45 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
46
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
47
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
48 /* user level (privilege level: 3) ldt (1<<2) segment selector */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
49 #define LDT_SEL(idx) ((idx) << 3 | 1 << 2 | 3)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
50
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
51 #ifndef TEB_SEL_IDX
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
52 #define TEB_SEL_IDX 1
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
53 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
54
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
55 #define TEB_SEL LDT_SEL(TEB_SEL_IDX)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
56
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
57 void setup_FS_Segment()
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
58 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
59 printf("Setup FS...");fflush(stdout);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
60 __asm__ __volatile__(
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
61 "movl %0,%%eax; movw %%ax, %%fs" : : "i" (TEB_SEL)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
62 );
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
63 printf("OK!\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
64 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
65
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
66
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
67 /**
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
68 *
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
69 * This should be performed before we create first thread. See remarks
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
70 * for write_ldt(), linux/kernel/ldt.c.
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
71 *
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
72 */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
73
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
74 static void* fs_seg=NULL;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
75
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
76 #ifdef __linux__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
77 /* XXX: why is this routine from libc redefined here? */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
78 /* NOTE: the redefined version ignores the count param, count is hardcoded as 16 */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
79 static int modify_ldt( int func, struct modify_ldt_ldt_s *ptr,
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
80 unsigned long count )
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
81 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
82 int res;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
83 #ifdef __PIC__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
84 __asm__ __volatile__( "pushl %%ebx\n\t"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
85 "movl %2,%%ebx\n\t"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
86 "int $0x80\n\t"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
87 "popl %%ebx"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
88 : "=a" (res)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
89 : "0" (__NR_modify_ldt),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
90 "r" (func),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
91 "c" (ptr),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
92 "d"(16)//sizeof(*ptr) from kernel point of view
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
93 :"esi" );
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
94 #else
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
95 __asm__ __volatile__("int $0x80"
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
96 : "=a" (res)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
97 : "0" (__NR_modify_ldt),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
98 "b" (func),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
99 "c" (ptr),
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
100 "d"(16)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
101 :"esi");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
102 #endif /* __PIC__ */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
103 if (res >= 0) return res;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
104 errno = -res;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
105 return -1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
106 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
107 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
108
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
109 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
110 static void LDT_EntryToBytes( unsigned long *buffer, const struct modify_ldt_ldt_s *content )
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
111 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
112 *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
113 (content->limit & 0x0ffff);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
114 *buffer = (content->base_addr & 0xff000000) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
115 ((content->base_addr & 0x00ff0000)>>16) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
116 (content->limit & 0xf0000) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
117 (content->contents << 10) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
118 ((content->read_exec_only == 0) << 9) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
119 ((content->seg_32bit != 0) << 22) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
120 ((content->limit_in_pages != 0) << 23) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
121 0xf000;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
122 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
123 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
124
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
125 void Setup_LDT_Keeper(){
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
126 struct modify_ldt_ldt_s array;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
127 int fd;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
128 int ret;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
129 void* prev_struct;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
130
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
131 if(fs_seg) return; // already set!
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
132
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
133 fd=open("/dev/zero", O_RDWR);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
134 fs_seg=mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE,
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
135 fd, 0);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
136 if(fs_seg==(void*)-1)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
137 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
138 perror("ERROR: Couldn't allocate memory for fs segment");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
139 return;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
140 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
141 array.base_addr=(int)fs_seg;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
142 array.entry_number=TEB_SEL_IDX;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
143 array.limit=array.base_addr+getpagesize()-1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
144 array.seg_32bit=1;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
145 array.read_exec_only=0;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
146 array.seg_not_present=0;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
147 array.contents=MODIFY_LDT_CONTENTS_DATA;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
148 array.limit_in_pages=0;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
149 #ifdef __linux__
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
150 ret=modify_ldt(0x1, &array, sizeof(struct modify_ldt_ldt_s));
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
151 if(ret<0)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
152 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
153 perror("install_fs");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
154 printf("Couldn't install fs segment, expect segfault\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
155 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
156 #endif /*linux*/
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
157
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
158 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
159 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
160 unsigned long d[2];
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
161
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
162 LDT_EntryToBytes( d, &array );
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
163 ret = i386_set_ldt(array.entry_number, (union descriptor *)d, 1);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
164 if (ret < 0)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
165 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
166 perror("install_fs");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
167 printf("Couldn't install fs segment, expect segfault\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
168 printf("Did you reconfigure the kernel with \"options USER_LDT\"?\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
169 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
170 printf("Set_LDT\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
171 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
172 #endif /* __NetBSD__ || __FreeBSD__ || __OpenBSD__ */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
173
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
174 #if defined(__svr4__)
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
175 struct ssd ssd;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
176 ssd.sel = TEB_SEL;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
177 ssd.bo = array.base_addr;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
178 ssd.ls = array.limit - array.base_addr;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
179 ssd.acc1 = ((array.read_exec_only == 0) << 1) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
180 (array.contents << 2) |
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
181 0xf0; /* P(resent) | DPL3 | S */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
182 ssd.acc2 = 0x4; /* byte limit, 32-bit segment */
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
183 if (sysi86(SI86DSCR, &ssd) < 0) {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
184 perror("sysi86(SI86DSCR)");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
185 printf("Couldn't install fs segment, expect segfault\n");
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
186 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
187 #endif
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
188
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
189 setup_FS_Segment();
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
190
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
191 prev_struct=malloc(8);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
192 *(void**)array.base_addr=prev_struct;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
193 close(fd);
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
194 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
195
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
196 void Restore_LDT_Keeper()
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
197 {
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
198 if(fs_seg==0) return;
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
199 munmap((char*)fs_seg, getpagesize());
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
200 }
a2c9731b2e01 Setup_FS_Segment() for VoxWare audio
arpi_esp
parents:
diff changeset
201