ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/main_unix.cpp
(Generate patch)

Comparing SheepShaver/src/Unix/main_unix.cpp (file contents):
Revision 1.8 by gbeauche, 2003-09-29T15:46:07Z vs.
Revision 1.14 by gbeauche, 2003-11-10T16:05:52Z

# Line 183 | Line 183 | int64 BusClockSpeed;   // Bus clock speed
183  
184  
185   // Global variables
186 < static char *x_display_name = NULL;                     // X11 display name
186 > char *x_display_name = NULL;                            // X11 display name
187   Display *x_display = NULL;                                      // X11 display handle
188  
189   static int zero_fd = 0;                                         // FD of /dev/zero
# Line 224 | Line 224 | static void *nvram_func(void *arg);
224   static void *tick_func(void *arg);
225   #if EMULATED_PPC
226   static void sigusr2_handler(int sig);
227 + extern void emul_ppc(uint32 start);
228 + extern void init_emul_ppc(void);
229 + extern void exit_emul_ppc(void);
230   #else
231   static void sigusr2_handler(int sig, sigcontext_struct *sc);
232   static void sigsegv_handler(int sig, sigcontext_struct *sc);
# Line 232 | Line 235 | static void sigill_handler(int sig, sigc
235  
236  
237   // From asm_linux.S
238 < #if EMULATED_PPC
236 < extern int atomic_add(int *var, int v);
237 < extern int atomic_and(int *var, int v);
238 < extern int atomic_or(int *var, int v);
239 < #else
238 > #if !EMULATED_PPC
239   extern "C" void *get_toc(void);
240   extern "C" void *get_sp(void);
241   extern "C" void flush_icache_range(void *start, void *end);
# Line 251 | Line 250 | extern void paranoia_check(void);
250   #endif
251  
252  
253 + #if EMULATED_PPC
254 + /*
255 + *  Atomic operations
256 + */
257 +
258 + #if HAVE_SPINLOCKS
259 + static spinlock_t atomic_ops_lock = SPIN_LOCK_UNLOCKED;
260 + #else
261 + #define spin_lock(LOCK)
262 + #define spin_unlock(LOCK)
263 + #endif
264 +
265 + int atomic_add(int *var, int v)
266 + {
267 +        spin_lock(&atomic_ops_lock);
268 +        int ret = *var;
269 +        *var += v;
270 +        spin_unlock(&atomic_ops_lock);
271 +        return ret;
272 + }
273 +
274 + int atomic_and(int *var, int v)
275 + {
276 +        spin_lock(&atomic_ops_lock);
277 +        int ret = *var;
278 +        *var &= v;
279 +        spin_unlock(&atomic_ops_lock);
280 +        return ret;
281 + }
282 +
283 + int atomic_or(int *var, int v)
284 + {
285 +        spin_lock(&atomic_ops_lock);
286 +        int ret = *var;
287 +        *var |= v;
288 +        spin_unlock(&atomic_ops_lock);
289 +        return ret;
290 + }
291 + #endif
292 +
293 +
294   /*
295   *  Main program
296   */
# Line 269 | Line 309 | int main(int argc, char **argv)
309          char str[256];
310          uint32 *boot_globs;
311          int16 i16;
272        int drive, driver;
312          int rom_fd;
313          FILE *proc_file;
314          const char *rom_path;
# Line 524 | Line 563 | int main(int argc, char **argv)
563          XPRAMInit();
564  
565          // Set boot volume
566 <        drive = PrefsFindInt32("bootdrive");
566 >        i16 = PrefsFindInt32("bootdrive");
567          XPRAM[0x1378] = i16 >> 8;
568          XPRAM[0x1379] = i16 & 0xff;
569 <        driver = PrefsFindInt32("bootdriver");
569 >        i16 = PrefsFindInt32("bootdriver");
570          XPRAM[0x137a] = i16 >> 8;
571          XPRAM[0x137b] = i16 & 0xff;
572  
# Line 743 | Line 782 | quit:
782  
783   static void Quit(void)
784   {
785 + #if EMULATED_PPC
786 +        // Exit PowerPC emulation
787 +        exit_emul_ppc();
788 + #endif
789 +
790          // Stop 60Hz thread
791          if (tick_thread_active) {
792                  pthread_cancel(tick_thread);
# Line 846 | Line 890 | static void Quit(void)
890   */
891  
892   #if EMULATED_PPC
849 extern void emul_ppc(uint32 start);
850 extern void init_emul_ppc(void);
893   void jump_to_rom(uint32 entry)
894   {
895          init_emul_ppc();
# Line 987 | Line 1029 | void Dump68kRegs(M68kRegisters *r)
1029  
1030   void MakeExecutable(int dummy, void *start, uint32 length)
1031   {
1032 < #if !EMULATED_PPC
991 <        if (((uint32)start >= ROM_BASE) && ((uint32)start < (ROM_BASE + ROM_SIZE)))
1032 >        if (((uintptr)start >= ROM_BASE) && ((uintptr)start < (ROM_BASE + ROM_SIZE)))
1033                  return;
1034 <        flush_icache_range(start, (void *)((uint32)start + length));
1034 > #if EMULATED_PPC
1035 >        FlushCodeCache((uintptr)start, (uintptr)start + length);
1036 > #else
1037 >        flush_icache_range(start, (void *)((uintptr)start + length));
1038   #endif
1039   }
1040  
# Line 1108 | Line 1152 | static void *tick_func(void *arg)
1152  
1153   void Set_pthread_attr(pthread_attr_t *attr, int priority)
1154   {
1155 <        // nothing to do
1155 > #ifdef HAVE_PTHREADS
1156 >        pthread_attr_init(attr);
1157 > #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
1158 >        // Some of these only work for superuser
1159 >        if (geteuid() == 0) {
1160 >                pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED);
1161 >                pthread_attr_setschedpolicy(attr, SCHED_FIFO);
1162 >                struct sched_param fifo_param;
1163 >                fifo_param.sched_priority = ((sched_get_priority_min(SCHED_FIFO) +
1164 >                                              sched_get_priority_max(SCHED_FIFO)) / 2 +
1165 >                                             priority);
1166 >                pthread_attr_setschedparam(attr, &fifo_param);
1167 >        }
1168 >        if (pthread_attr_setscope(attr, PTHREAD_SCOPE_SYSTEM) != 0) {
1169 > #ifdef PTHREAD_SCOPE_BOUND_NP
1170 >            // If system scope is not available (eg. we're not running
1171 >            // with CAP_SCHED_MGT capability on an SGI box), try bound
1172 >            // scope.  It exposes pthread scheduling to the kernel,
1173 >            // without setting realtime priority.
1174 >            pthread_attr_setscope(attr, PTHREAD_SCOPE_BOUND_NP);
1175 > #endif
1176 >        }
1177 > #endif
1178 > #endif
1179   }
1180  
1181  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines