2 Subject: vanilla sources from www.maconlinux.org
7 Never modify this patch! Create new patches for build fixes.
10 drivers/macintosh/mol/_dev.c | 376 ++++++++++
11 drivers/macintosh/mol/_fault.c | 159 ++++
12 drivers/macintosh/mol/_hostirq.c | 116 +++
13 drivers/macintosh/mol/_kuname.c | 48 +
14 drivers/macintosh/mol/_misc.c | 147 +++
15 drivers/macintosh/mol/_mmu.c | 41 +
16 drivers/macintosh/mol/actions.c | 548 ++++++++++++++
17 drivers/macintosh/mol/asm-files/603.S | 218 +++++
18 drivers/macintosh/mol/asm-files/dec.S | 228 ++++++
19 drivers/macintosh/mol/asm-files/emuaccel.S | 188 +++++
20 drivers/macintosh/mol/asm-files/emulation.S | 714 +++++++++++++++++++
21 drivers/macintosh/mol/asm-files/entry.S | 433 +++++++++++
22 drivers/macintosh/mol/asm-files/iopage.S | 89 ++
23 drivers/macintosh/mol/asm-files/linux.S | 129 +++
24 drivers/macintosh/mol/asm-files/ptintercept.S | 303 ++++++++
25 drivers/macintosh/mol/asm-files/splitmode.S | 428 +++++++++++
26 drivers/macintosh/mol/asm-files/traps.S | 501 +++++++++++++
27 drivers/macintosh/mol/asm-files/vsid.S | 123 +++
28 drivers/macintosh/mol/asm_offsets.c | 161 ++++
29 drivers/macintosh/mol/context.c | 99 ++
30 drivers/macintosh/mol/emu.c | 228 ++++++
31 drivers/macintosh/mol/fault.c | 601 ++++++++++++++++
32 drivers/macintosh/mol/hash.c | 126 +++
33 drivers/macintosh/mol/include/actions.h | 177 ++++
34 drivers/macintosh/mol/include/alloc.h | 70 +
35 drivers/macintosh/mol/include/archinclude.h | 77 ++
36 drivers/macintosh/mol/include/asm.m4 | 141 +++
37 drivers/macintosh/mol/include/asm_offsets.inc | 136 +++
38 drivers/macintosh/mol/include/asmdbg.h | 184 ++++
39 drivers/macintosh/mol/include/asmdefs.h | 397 ++++++++++
40 drivers/macintosh/mol/include/asmfuncs.h | 80 ++
41 drivers/macintosh/mol/include/atomic.h | 26
42 drivers/macintosh/mol/include/config.h | 90 ++
43 drivers/macintosh/mol/include/constants.h | 36
44 drivers/macintosh/mol/include/context.h | 62 +
45 drivers/macintosh/mol/include/dbg.h | 31
46 drivers/macintosh/mol/include/debugger.h | 96 ++
47 drivers/macintosh/mol/include/emu.h | 29
48 drivers/macintosh/mol/include/emuaccel_sh.h | 41 +
49 drivers/macintosh/mol/include/extralib.h | 70 +
50 drivers/macintosh/mol/include/hash.h | 36
51 drivers/macintosh/mol/include/kernel_vars.h | 225 ++++++
52 drivers/macintosh/mol/include/locks.h | 39 +
53 drivers/macintosh/mol/include/mac_registers.h | 168 ++++
54 drivers/macintosh/mol/include/map.h | 43 +
55 drivers/macintosh/mol/include/misc.h | 105 ++
56 drivers/macintosh/mol/include/mmu.h | 102 ++
57 drivers/macintosh/mol/include/mmu_contexts.h | 55 +
58 drivers/macintosh/mol/include/mmu_mappings.h | 48 +
59 drivers/macintosh/mol/include/mmutypes.h | 76 ++
60 drivers/macintosh/mol/include/mol-ioctl.h | 121 +++
61 drivers/macintosh/mol/include/mol_config.h | 76 ++
62 drivers/macintosh/mol/include/molasm.h | 138 +++
63 drivers/macintosh/mol/include/molversion.h | 6
64 drivers/macintosh/mol/include/mtable.h | 71 +
65 drivers/macintosh/mol/include/osi.h | 170 ++++
66 drivers/macintosh/mol/include/osi_calls.h | 475 ++++++++++++
67 drivers/macintosh/mol/include/performance.h | 71 +
68 drivers/macintosh/mol/include/platform.h | 73 +
69 drivers/macintosh/mol/include/processor.h | 409 +++++++++++
70 drivers/macintosh/mol/include/prom.h | 46 +
71 drivers/macintosh/mol/include/rvec.h | 147 +++
72 drivers/macintosh/mol/include/skiplist.h | 87 ++
73 drivers/macintosh/mol/include/tlbie.h | 102 ++
74 drivers/macintosh/mol/include/uaccess.h | 36
75 drivers/macintosh/mol/include/vector.h | 189 +++++
76 drivers/macintosh/mol/include/version.h | 11
77 drivers/macintosh/mol/include/weaksym.h | 39 +
78 drivers/macintosh/mol/init.c | 191 +++++
79 drivers/macintosh/mol/misc.c | 255 ++++++
80 drivers/macintosh/mol/mmu.c | 251 ++++++
81 drivers/macintosh/mol/mmu_fb.c | 186 +++++
82 drivers/macintosh/mol/mmu_io.c | 470 ++++++++++++
83 drivers/macintosh/mol/mmu_tracker.c | 128 +++
84 drivers/macintosh/mol/mtable.c | 960 ++++++++++++++++++++++++++
85 drivers/macintosh/mol/ptaccess.c | 153 ++++
86 drivers/macintosh/mol/sheep.c | 701 ++++++++++++++++++
87 drivers/macintosh/mol/skiplist.c | 222 ++++++
88 78 files changed, 14428 insertions(+)
91 +++ b/drivers/macintosh/mol/_dev.c
94 + * Creation Date: <2003/08/20 17:31:44 samuel>
95 + * Time-stamp: <2004/02/14 14:43:13 samuel>
101 + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
103 + * This program is free software; you can redistribute it and/or
104 + * modify it under the terms of the GNU General Public License
109 +#include "archinclude.h"
110 +#include <linux/module.h>
111 +#include <linux/miscdevice.h>
112 +#include <linux/spinlock.h>
113 +#include <linux/init.h>
114 +#include <linux/interrupt.h>
115 +#include <linux/irq.h>
116 +#include <linux/bitops.h>
117 +#include <asm/prom.h>
118 +#include <asm/machdep.h>
119 +#include <asm/atomic.h>
120 +#include "kernel_vars.h"
121 +#include "mol-ioctl.h"
122 +#include "version.h"
128 +MODULE_AUTHOR("Samuel Rydh <samuel@ibrium.se>");
129 +MODULE_DESCRIPTION("Mac-on-Linux kernel module");
130 +MODULE_LICENSE("GPL");
132 +static DECLARE_MUTEX( initmutex );
136 +/************************************************************************/
138 +/************************************************************************/
144 +dummy_ipi( void *dummy )
146 + /* we don't need to _do_ anything, the exception itself is sufficient */
151 + smp_call_function( dummy_ipi, NULL, 1, 0 );
153 +#else /* CONFIG_SMP */
156 +#define send_ipi() do {} while(0)
158 +#endif /* CONFIG_SMP */
162 +find_physical_rom( int *base, int *size )
164 +#ifndef CONFIG_AMIGAONE
165 + struct device_node *dn;
169 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
170 + if( !(dn=find_devices("boot-rom")) && !(dn=find_type_devices("rom")) )
173 + if (! (dn = of_find_node_by_name(NULL, "boot-rom"))) {
175 + if (! (dn = of_find_node_by_type(NULL, "rom")))
178 +#endif /* < Linux 2.6.21 */
180 + if( !(p=(int*)get_property(dn, "reg", &len)) || len != sizeof(int[2]) ) {
184 + if( (unsigned int)(0xfff00100 - p[0]) < (unsigned int)p[1] ) {
190 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
193 + dn = by_type ? of_find_node_by_type(dn, "rom") :
194 + of_find_node_by_name(dn, "boot-rom");
195 +#endif /* < Linux 2.6.21 */
197 +#endif /* CONFIG_AMIGA_ONE */
202 +get_info( mol_kmod_info_t *user_retinfo, int size )
204 + mol_kmod_info_t info;
206 + memset( &info, 0, sizeof(info) );
207 + asm volatile("mfpvr %0" : "=r" (info.pvr) : );
208 + info.version = MOL_VERSION;
209 + find_physical_rom( &info.rombase, &info.romsize );
210 + info.tb_freq = HZ * tb_ticks_per_jiffy;
211 + info.smp_kernel = HAS_SMP;
213 + if( (uint)size > sizeof(info) )
214 + size = sizeof(info);
216 + if( copy_to_user(user_retinfo, &info, size) )
223 +prevent_mod_unload( void )
228 + __module_get( THIS_MODULE );
233 +get_irqs( kernel_vars_t *kv, irq_bitfield_t *irq_info_p )
235 + irq_bitfield_t irq_mask;
238 + /* copy the interrupt mask from userspace */
239 + if (copy_from_user(&irq_mask, irq_info_p, sizeof(irq_mask)))
242 + /* see which of the mapped interrupts need to be enabled */
243 + for (i = 0; i < NR_HOST_IRQS; i++) {
244 + if (check_bit_mol(i, (char *) kv->mregs.mapped_irqs.irqs)
245 + && check_bit_mol(i, (char *) irq_mask.irqs)
246 + && check_bit_mol(i, (char *) kv->mregs.active_irqs.irqs)) {
247 + if (test_and_clear_bit(i, kv->mregs.active_irqs.irqs))
248 + atomic_dec_mol((mol_atomic_t *) &(kv->mregs.hostirq_active_cnt));
253 + /* if one of the enabled interrupts was pending, it should have fired
254 + * now, updating active_irqs */
255 + if (copy_to_user(irq_info_p, &(kv->mregs.active_irqs), sizeof(kv->mregs.active_irqs)))
261 +/************************************************************************/
263 +/************************************************************************/
266 +debugger_op( kernel_vars_t *kv, dbg_op_params_t *upb )
268 + dbg_op_params_t pb;
271 + if( copy_from_user(&pb, upb, sizeof(pb)) )
274 + switch( pb.operation ) {
275 + case DBG_OP_GET_PHYS_PAGE:
276 + ret = dbg_get_linux_page( pb.ea, &pb.ret.page );
279 + ret = do_debugger_op( kv, &pb );
283 + if( copy_to_user(upb, &pb, sizeof(pb)) )
289 +arch_handle_ioctl( kernel_vars_t *kv, int cmd, int p1, int p2, int p3 )
295 + case MOL_IOCTL_GET_IRQS:
296 + return get_irqs( kv, (irq_bitfield_t *) p1 );
298 + case MOL_IOCTL_GET_DIRTY_FBLINES: /* short *retbuf, int size -- npairs */
299 + if( compat_verify_area(VERIFY_WRITE, (short*)p1, p2) )
301 + ret = get_dirty_fb_lines( kv, (short*)p1, p2 );
304 + case MOL_IOCTL_DEBUGGER_OP:
305 + ret = debugger_op( kv, (dbg_op_params_t*)p1 );
308 + case MOL_IOCTL_GRAB_IRQ:
309 + ret = grab_host_irq(kv, p1);
312 + case MOL_IOCTL_RELEASE_IRQ:
313 + ret = release_host_irq(kv, p1);
316 + case MOL_IOCTL_COPY_LAST_ROMPAGE: /* p1 = dest */
318 + if( (rompage=ioremap(0xfffff000, 0x1000)) ) {
319 + ret = copy_to_user( (char*)p1, rompage, 0x1000 );
320 + iounmap( rompage );
324 + case MOL_IOCTL_SET_RAM: /* void ( char *lvbase, size_t size ) */
325 + if( compat_verify_area(VERIFY_WRITE, (char*)p1, p2) )
328 + kv->mmu.userspace_ram_base = p1;
329 + kv->mmu.ram_size = p2;
330 + mtable_tune_alloc_limit( kv, p2/(1024 * 1024) );
333 + case MOL_IOCTL_GET_MREGS_PHYS:
334 + ret = virt_to_phys( &kv->mregs );
338 + ret = handle_ioctl( kv, cmd, p1, p2, p3 );
345 +/************************************************************************/
346 +/* device interface */
347 +/************************************************************************/
350 +mol_open( struct inode *inode, struct file *file )
354 + if( !(file->f_mode & FMODE_READ) )
357 + down( &initmutex );
359 + if( common_init() ) {
366 + file->private_data = NULL;
371 +mol_release( struct inode *inode, struct file *file )
373 + kernel_vars_t *kv = (kernel_vars_t*)file->private_data;
375 + down( &initmutex );
377 + destroy_session( kv->session_index );
386 +mol_ioctl( struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg )
394 + if( cmd == MOL_IOCTL_SMP_SEND_IPI ) {
399 + if( copy_from_user(&pb, (void*)arg, sizeof(pb)) )
403 + case MOL_IOCTL_GET_INFO:
404 + return get_info( (mol_kmod_info_t*)pb.arg1, pb.arg2 );
406 + case MOL_IOCTL_CREATE_SESSION:
407 + if( !(file->f_mode & FMODE_WRITE) || !capable(CAP_SYS_ADMIN) )
410 + down( &initmutex );
411 + if( (uint)pb.arg1 < MAX_NUM_SESSIONS && !file->private_data ) {
412 + if( !(ret=initialize_session(pb.arg1)) ) {
413 + kv = g_sesstab->kvars[pb.arg1];
414 + init_MUTEX( &kv->ioctl_sem );
415 + file->private_data = kv;
421 + case MOL_IOCTL_DBG_COPY_KVARS:
424 + down( &initmutex );
425 + if( session < MAX_NUM_SESSIONS && (kv=g_sesstab->kvars[session]) )
426 + ret = copy_to_user( (char*)pb.arg2, kv, sizeof(*kv) );
431 + if( !(kv=(kernel_vars_t*)file->private_data) )
434 + down( &kv->ioctl_sem );
435 + ret = arch_handle_ioctl( kv, cmd, pb.arg1, pb.arg2, pb.arg3 );
436 + up( &kv->ioctl_sem );
441 +static struct file_operations mol_device_fops = {
442 + .owner = THIS_MODULE,
444 + .release = mol_release,
445 + .ioctl = mol_ioctl,
446 +// .poll = mol_poll,
447 +// .mmap: = mol_mmap,
450 +static struct miscdevice mol_device = {
451 + MISC_DYNAMIC_MINOR, "mol", &mol_device_fops
455 +dev_register( void )
457 + printk("MOL %s kernel module loaded\n", MOL_RELEASE );
458 + return misc_register( &mol_device );
462 +dev_unregister( void )
464 + misc_deregister( &mol_device );
467 +module_init( dev_register );
468 +module_exit( dev_unregister );
470 +++ b/drivers/macintosh/mol/_fault.c
473 + * Creation Date: <2002/06/08 21:01:54 samuel>
474 + * Time-stamp: <2004/02/19 11:54:33 samuel>
480 + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
482 + * This program is free software; you can redistribute it and/or
483 + * modify it under the terms of the GNU General Public License
484 + * as published by the Free Software Foundation
488 +#include "archinclude.h"
490 +#include "kernel_vars.h"
492 +#include "mmu_contexts.h"
493 +#include "asmfuncs.h"
497 +#include "performance.h"
498 +#include "mol-ioctl.h"
501 +#ifdef CONFIG_HIGHPTE
502 +#error "MOL is currently incompatible with CONFIG_HIGHPTE"
506 +fix_pte( ulong *p, ulong set, ulong flags )
508 + unsigned long ret, tmp;
510 + __asm__ __volatile__("\n"
511 + "1: lwarx %0,0,%3 \n"
512 + " andc. %1,%5,%0 \n"
516 + " stwcx. %1,0,%3 \n"
519 + : "=&r" (tmp), "=&r" (ret), "=m" (*p)
520 + : "r" (p), "r" (set), "r" (flags), "m" (*p)
526 + * Get physical page corresponding to linux virtual address. Invokes linux page
527 + * fault handler if the page is missing. This function never fails since we
528 + * know there is a valid mapping...
530 +#define PAGE_BITS_WRITE (_PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_HASHPTE )
531 +#define PAGE_BITS_READ (_PAGE_ACCESSED | _PAGE_HASHPTE )
534 +get_phys_page( kernel_vars_t *kv, ulong va, int request_rw )
536 + char *lvptr = (char*)va;
537 + ulong lpte, uptr, *ptr;
539 + struct mm_struct *mm;
540 + struct vm_area_struct *vma;
542 + /* pte bits that must be set */
543 + flags = request_rw ? (_PAGE_USER | _PAGE_RW | _PAGE_PRESENT)
544 + : (_PAGE_USER | _PAGE_PRESENT);
546 + uptr = ((ulong*)current->thread.pgdir)[va>>22]; /* top 10 bits */
547 + ptr = (ulong*)(uptr & ~0xfff);
551 + ptr = phys_to_virt( (int)ptr );
553 + ptr = ptr + ((va>>12) & 0x3ff); /* next 10 bits */
555 + /* this allows us to keep track of this page until we have
556 + * added a full mtable entry for it. The reservation is lost if
557 + * a TLB invalidation occurs.
559 + make_lvptr_reservation( kv, lvptr );
561 + /* we atomically set _PAGE_HASHPTE after checking PAGE_PRESENT and PAGE_RW.
562 + * We are then guaranteed to be notified about a TLB invalidation through the
563 + * flush_hash_page hook.
565 + lpte = fix_pte( ptr, (request_rw? PAGE_BITS_WRITE : PAGE_BITS_READ), flags );
567 + /* permissions violation */
571 + return lpte & ~0xfff;
574 + BUMP( page_missing );
576 + /* no mac page found... */
578 + down_read( &mm->mmap_sem );
580 + if( !(vma=find_vma(mm,va)) || vma->vm_start > va )
582 + if( !(vma->vm_flags & (request_rw ? VM_WRITE : (VM_READ | VM_EXEC))) )
585 + handle_mm_fault( mm, vma, va, request_rw );
587 + up_read( &mm->mmap_sem );
588 + return get_phys_page(kv, va, request_rw);
591 + up_read( &mm->mmap_sem );
592 + printk("get_phys_page: BAD AREA, lvptr = %08lx\n", va );
593 + force_sig(SIGSEGV, current);
598 +/************************************************************************/
599 +/* Debugger functions */
600 +/************************************************************************/
603 +dbg_get_linux_page( ulong va, dbg_page_info_t *r )
605 + ulong val, uptr, *ptr;
607 + uptr = ((ulong*)current->thread.pgdir)[va>>22]; /* top 10 bits */
608 + ptr = (ulong*)(uptr & ~0xfff);
612 + ptr = phys_to_virt( (int)ptr );
614 + val = ptr[ (va>>12)&0x3ff ]; /* next 10 bits */
616 + r->phys = val & ~0xfff;
618 + DBG_TRANSL_PAGE_FLAG( val, _PAGE_PRESENT )
619 + | DBG_TRANSL_PAGE_FLAG( val, _PAGE_USER )
620 + | DBG_TRANSL_PAGE_FLAG( val, _PAGE_GUARDED )
621 + | DBG_TRANSL_PAGE_FLAG( val, _PAGE_COHERENT )
622 + | DBG_TRANSL_PAGE_FLAG( val, _PAGE_NO_CACHE )
623 + | DBG_TRANSL_PAGE_FLAG( val, _PAGE_WRITETHRU )
624 + | DBG_TRANSL_PAGE_FLAG( val, _PAGE_DIRTY )
625 + | DBG_TRANSL_PAGE_FLAG( val, _PAGE_ACCESSED )
626 + | DBG_TRANSL_PAGE_FLAG( val, _PAGE_RW )
627 + | DBG_TRANSL_PAGE_FLAG( val, _PAGE_HASHPTE )
628 + | DBG_TRANSL_PAGE_FLAG( val, _PAGE_EXEC );
632 +++ b/drivers/macintosh/mol/_hostirq.c
637 + * host IRQ handling (for pciproxied devices)
639 + * Copyright (C) 2005 Mattias Nissler <mattias.nissler@gmx.de>
641 + * This program is free software; you can redistribute it and/or
642 + * modify it under the terms of the GNU General Public License
646 +#include <linux/version.h>
647 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
648 +#include <linux/threads.h>
649 +#include <linux/spinlock.h>
651 +#include <linux/interrupt.h>
652 +#include <linux/irq.h>
653 +#include <linux/sched.h>
654 +#include <linux/bitops.h>
655 +#include <asm/atomic.h>
657 +#include "archinclude.h"
658 +#include "kernel_vars.h"
663 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
664 +hostirq_handler(int irq, void *pkv)
666 +hostirq_handler(int irq, void *pkv, struct pt_regs *regs)
670 + kernel_vars_t *kv = (kernel_vars_t *) pkv;
672 + /* disable the irq */
673 + disable_irq_nosync(irq);
674 + /* have the interrupt handled */
675 + if (!test_and_set_bit(irq, kv->mregs.active_irqs.irqs))
676 + atomic_inc_mol((mol_atomic_t *) &(kv->mregs.hostirq_active_cnt));
677 + kv->mregs.hostirq_update = 1;
678 + kv->mregs.interrupt = 1;
679 + /* signal the main thread (it might be DOZEing) */
680 + if (kv->main_thread != NULL) {
681 + memset(&si, 0, sizeof(si));
682 + si.si_signo = SIGHUP;
684 + send_sig_info(SIGHUP, &si, kv->main_thread);
687 + return IRQ_HANDLED;
690 +static char *molirqdescstring = "MOL irq mapping";
693 +grab_host_irq(kernel_vars_t *kv, int irq)
698 + if (irq < 0 || irq >= NR_HOST_IRQS
699 + || check_bit_mol(irq, (char *) kv->mregs.mapped_irqs.irqs))
702 + /* request the irq */
703 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 21)
704 + ret = request_irq(irq, hostirq_handler, IRQF_DISABLED | IRQF_SHARED, molirqdescstring, kv);
706 + ret = request_irq(irq, hostirq_handler, SA_INTERRUPT | SA_SHIRQ, molirqdescstring, kv);
709 +// printk(KERN_INFO "mapped irq line %d\n", irq);
710 + set_bit_mol(irq, (char *) kv->mregs.mapped_irqs.irqs);
717 +release_host_irq(kernel_vars_t *kv, int irq)
720 + if (irq < 0 || irq >= NR_HOST_IRQS
721 + || !check_bit_mol(irq, (char *) kv->mregs.mapped_irqs.irqs))
724 + clear_bit_mol(irq, (char *) kv->mregs.mapped_irqs.irqs);
732 +init_host_irqs(kernel_vars_t *kv)
734 + memset(&(kv->mregs.mapped_irqs), 0, sizeof(kv->mregs.mapped_irqs));
735 + kv->main_thread = current;
736 + kv->mregs.hostirq_update = 0;
740 +cleanup_host_irqs(kernel_vars_t *kv)
744 + for (n = 0; n < NR_HOST_IRQS; n++) {
745 + if (check_bit_mol(n, (char *) kv->mregs.mapped_irqs.irqs))
746 + release_host_irq(kv, n);
751 +++ b/drivers/macintosh/mol/_kuname.c
754 + * Creation Date: <2001/08/15 01:11:01 samuel>
755 + * Time-stamp: <2003/10/24 10:22:00 samuel>
759 + * Extract from the kernel source
761 + * Copyright (C) 2001, 2002, 2003 Samuel Rydh (samuel@ibrium.se)
763 + * This program is free software; you can redistribute it and/or
764 + * modify it under the terms of the GNU General Public License
765 + * as published by the Free Software Foundation
769 +#include <linux/version.h>
771 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
772 +#include <linux/utsrelease.h>
775 +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
776 +#include <linux/config.h>
778 +#include <linux/autoconf.h>
781 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
784 +#define SMP_STRING "-smp"
786 +#define SMP_STRING ""
789 +#ifndef CONFIG_ALTIVEC
790 +#define ALTIVEC_STRING "-noav"
792 +#define ALTIVEC_STRING ""
796 +#define SMP_STRING ""
797 +#define ALTIVEC_STRING ""
800 +char *cross_compiling_magic = "-MAGIC-" UTS_RELEASE SMP_STRING ALTIVEC_STRING ;
802 +++ b/drivers/macintosh/mol/_misc.c
805 + * Creation Date: <97/05/26 02:10:43 samuel>
806 + * Time-stamp: <2004/03/13 14:14:20 samuel>
812 + * Copyright (C) 1997-2004 Samuel Rydh (samuel@ibrium.se)
814 + * This program is free software; you can redistribute it and/or
815 + * modify it under the terms of the GNU General Public License
816 + * as published by the Free Software Foundation
820 +#include "archinclude.h"
821 +#include <linux/vmalloc.h>
822 +#include <linux/sched.h>
823 +#include <asm/uaccess.h>
824 +#include <asm/prom.h>
825 +#include "kernel_vars.h"
827 +#include "performance.h"
833 +alloc_kvar_pages( void )
839 + for( i=1, order=0; i<NUM_KVARS_PAGES; i=i<<1, order++ )
841 + if( !(kv=(kernel_vars_t*)__get_free_pages(GFP_KERNEL, order)) )
844 + /* To be able to export the kernel variables to user space, we
845 + * must set the PG_reserved bit. This is due to a check
846 + * in remap_pte_range() in kernel/memory.c (is this bug or a feature?).
848 + for( ptr=(char*)kv, i=0; i<NUM_KVARS_PAGES; i++, ptr+=0x1000 )
849 + SetPageReserved( virt_to_page(ptr) );
855 +free_kvar_pages( kernel_vars_t *kv )
857 + char *ptr = (char*)kv;
860 + for( i=0; i<NUM_KVARS_PAGES; i++, ptr+=0x1000 )
861 + ClearPageReserved( virt_to_page(ptr) );
863 + for( i=1, order=0; i<NUM_KVARS_PAGES; i=i<<1, order++ )
865 + free_pages( (ulong)kv, order );
869 +/************************************************************************/
871 +/************************************************************************/
874 +map_emulated_hash( kernel_vars_t *kv, ulong mbase, ulong size )
876 + return (ulong*)(MMU.userspace_ram_base + mbase);
880 +unmap_emulated_hash( kernel_vars_t *kv )
885 +/************************************************************************/
886 +/* kernel lowmem asm <-> kernel C-code switching */
887 +/************************************************************************/
889 +typedef int (*kernelfunc_t)( kernel_vars_t *, ulong, ulong, ulong );
890 +typedef void (*trampoline_t)( struct pt_regs *regs );
891 +static trampoline_t old_trampoline;
894 +mol_trampoline_vector( struct pt_regs *r )
896 + kernel_vars_t *kv = (kernel_vars_t*)r->gpr[8];
899 + /* the 0x2f00 trap does not enable MSR_EE */
900 + local_irq_enable();
902 + TICK_CNTR_PUSH( kv );
903 + r->gpr[3] = (*(kernelfunc_t)r->gpr[3])( kv, r->gpr[4], r->gpr[5], r->gpr[6] );
904 + TICK_CNTR_POP( kv, in_kernel );
908 +set_trampoline( trampoline_t tramp )
912 + extern trampoline_t mol_trampoline;
913 + old = mol_trampoline;
914 + mol_trampoline = tramp;
916 + /* we steal the unused 0x2f00 exception vector... */
917 + u32 *p = (u32*)(KERNELBASE + 0x2f00);
918 + static trampoline_t *tptr = NULL;
921 + /* look for bl xxxx ; .long vector; .long exception_return */
922 + for( i=0; !tptr && i<0x100/4; i++ ) {
923 + if( (p[i] & ~0xffff) != 0x48000000 )
925 + if( (p[i+1] & ~0x7fffff) != KERNELBASE || (p[i+2] & ~0x0fffff) != KERNELBASE )
927 + tptr = (trampoline_t*)&p[i+1];
930 + printk("MOL trampoline not found!\n");
940 +arch_common_init( void )
942 + old_trampoline = set_trampoline( mol_trampoline_vector );
943 + return !old_trampoline;
947 +arch_common_cleanup( void )
949 + set_trampoline( old_trampoline );
952 +++ b/drivers/macintosh/mol/_mmu.c
955 + * Creation Date: <2002/07/13 13:58:00 samuel>
956 + * Time-stamp: <2004/02/14 12:47:09 samuel>
962 + * Copyright (C) 2002, 2003 Samuel Rydh (samuel@ibrium.se)
964 + * This program is free software; you can redistribute it and/or
965 + * modify it under the terms of the GNU General Public License
966 + * as published by the Free Software Foundation
970 +#include "archinclude.h"
972 +#include "kernel_vars.h"
974 +#include "asmfuncs.h"
976 +#define MMU (kv->mmu)
979 +void (*xx_tlbie_lowmem)( void );
980 +void (*xx_store_pte_lowmem)( void );
982 +void (*xx_store_pte_lowmem)( ulong *slot, int pte0, int pte1 );
986 +arch_mmu_init( kernel_vars_t *kv )
988 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
989 + MMU.emulator_context = current->mm->context.id;
991 + MMU.emulator_context = current->mm->context;
996 +++ b/drivers/macintosh/mol/actions.c
999 + * Creation Date: <2001/04/07 17:33:52 samuel>
1000 + * Time-stamp: <2004/03/13 14:17:40 samuel>
1004 + * Handle assambly actions (relocations, exception vector
1005 + * hooking, lowmem relocations and other stuff)
1007 + * Copyright (C) 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
1009 + * This program is free software; you can redistribute it and/or
1010 + * modify it under the terms of the GNU General Public License
1011 + * as published by the Free Software Foundation
1015 +#include "archinclude.h"
1017 +#include "kernel_vars.h"
1019 +#include "asmfuncs.h"
1020 +#include "actions.h"
1025 +int reloc_virt_offs;
1027 +static char *code_base;
1028 +static uint code_size;
1031 +#define OPCODE_ADDIS( dreg, sreg, hi_val ) ((15<<26) | ((dreg)<<21) | ((sreg)<<16) | (hi_val))
1032 +#define OPCODE_LIS( dreg, hi_val ) OPCODE_ADDIS( dreg, 0, hi_val )
1033 +#define OPCODE_ORI( dreg, sreg, val ) ((24<<26) | ((dreg)<<16) | ((sreg)<<21) | (val))
1034 +#define OPCODE_MTSPRG2( sreg ) (0x7c1243a6 + ((sreg)<<21))
1037 +/************************************************************************/
1038 +/* lowmem allocations (allocates within the first 32 MB of RAM) */
1039 +/************************************************************************/
1041 +/* The low-level assembly code need to be located in memory which is
1042 + * physically continuous. The kernel exception vector are patched
1043 + * through pseudo symbols (action symbols).
1046 +#define MAX_NUM_CLEANUP_HANDLERS 32
1049 + char *lowmem_addr;
1053 + ulong *inst_addr; /* these fields are used */
1054 + ulong opcode; /* be the hook code */
1057 +static int num_cleanup_entries;
1058 +static cleanup_entry_t cleanup_table[ MAX_NUM_CLEANUP_HANDLERS ];
1059 +static ulong lowmem_phys_cursor;
1061 +/* Memory mapping of exception vectors */
1062 +static ulong lowmem_phys_base;
1063 +static char *lowmem_virt_base;
1064 +static void *lowmem_mapping;
1067 +static inline ulong *
1068 +lowmem_phys_to_virt( ulong paddr ) {
1069 + return (ulong*)(lowmem_virt_base + (paddr - lowmem_phys_base));
1072 +static inline ulong
1073 +lowmem_tophys( void *vaddr ) {
1074 + return lowmem_phys_base + ((ulong)vaddr - (ulong)lowmem_virt_base);
1079 +lowmem_initialize( void )
1081 + if( num_cleanup_entries ) {
1082 + printk("Internal error in lowmem_initialize\n");
1085 + lowmem_phys_cursor = 0x100;
1087 + /* In Darwin, the mapping will fail if we put lowmem_phys_base to zero */
1088 + lowmem_phys_base = 0x100;
1089 + lowmem_mapping = map_phys_range( lowmem_phys_base, 0x4000, &lowmem_virt_base );
1093 +lowmem_alloc( int size, cleanup_entry_t **ret_ce )
1096 + cleanup_entry_t ce;
1099 + memset( &ce, 0, sizeof(ce) );
1103 + if( num_cleanup_entries >= MAX_NUM_CLEANUP_HANDLERS ) {
1104 + printk("MOL: Need more cleanup slots!\n");
1108 + /* Find big enough empty piece of memory */
1112 + pstart = lowmem_phys_to_virt(lowmem_phys_cursor);
1113 + pstart = (ulong*)(((ulong)pstart + 0xf) & ~0xf);
1114 + for( ; lowmem_phys_cursor < 0x3000; lowmem_phys_cursor+=4 ) {
1115 + ulong *p = lowmem_phys_to_virt(lowmem_phys_cursor);
1116 + if( ((int)p - (int)pstart) >= size ) {
1121 + pstart = (ulong*)(((ulong)p + sizeof(ulong) + 0xf) & ~0xf);
1126 + printk("MOL: Did not find an empty piece of lowmem memory!\n");
1129 + /* printk("lowmem alloc: %08lX\n", pstart ); */
1131 + ce.lowmem_addr = (char*)pstart;
1132 + ce.alloc_method = 0;
1133 + ce.alloc_size = size;
1134 + /* printk("lowmem-alloc SPACE %X bytes at %08lX\n", size, (ulong)pstart ); */
1136 + cleanup_table[num_cleanup_entries] = ce;
1138 + *ret_ce = &cleanup_table[num_cleanup_entries];
1139 + num_cleanup_entries++;
1141 + return ce.lowmem_addr;
1145 +lowmem_free_all( void )
1147 + cleanup_entry_t *ce = &cleanup_table[0];
1150 + for(i=0; i<num_cleanup_entries; i++, ce++ )
1151 + memset( ce->lowmem_addr, 0, ce->alloc_size );
1153 + num_cleanup_entries = 0;
1155 + if( lowmem_mapping ) {
1156 + unmap_phys_range( lowmem_mapping );
1157 + lowmem_mapping = NULL;
1162 +/************************************************************************/
1163 +/* helper functions */
1164 +/************************************************************************/
1166 +static action_pb_t *
1167 +find_action( int action, int index )
1169 + extern int r__actions_offs_section[], r__actions_offs_section_end[];
1170 + extern char *r__actions_section[];
1171 + const int n = ((int)r__actions_offs_section_end - (int)r__actions_offs_section)/sizeof(int);
1172 + int i, *op = r__actions_offs_section;
1174 + for( i=0; i<n; i++ ) {
1175 + action_pb_t *p = (action_pb_t*)((char*)r__actions_section + op[i]);
1177 + if( p->action != action || index-- )
1185 +relocate_inst( ulong *opc_ptr, ulong from, ulong to )
1187 + ulong opcode = *opc_ptr;
1190 + /* XXX: UNTESTED if target instruction is a branch */
1192 + /* Since we use this on the _first_ instruction of the
1193 + * exception vector, it can't touch LR/CR. Thus, we
1194 + * only look for unconditional, relative branches.
1197 + /* relativ branch b */
1198 + if( (opcode & 0xfc000003) == (18<<26) ){
1199 + offs = (opcode & 0x03fffffc);
1201 + if( offs & 0x03000000 )
1202 + offs |= ~0x03ffffff;
1204 + /* unconditional, relativ bc branch (b 0100 001z1zz ...) */
1205 + if( (opcode & 0xfe800003) == 0x42800000 ){
1206 + offs = (opcode & 0xfffc);
1207 + if( offs & 0x8000 )
1210 + /* construct the absolute branch */
1211 + if( offs != -1 ) {
1212 + int dest = from + offs;
1213 + if( dest < 0 || dest > 33554431 ) {
1214 + printk("relocation of branch at %08lX to %08lX failed\n", from, to);
1217 + /* absolute branch */
1218 + *opc_ptr = ((18<<26) + 2) | dest;
1224 +/************************************************************************/
1226 +/************************************************************************/
1228 +typedef int (*action_func_t)( int action, ulong *target, const int *pb );
1231 +action_li_phys( int action, ulong *target, const int *pb )
1233 + int r = pb[0] & 0x1f;
1234 + ulong addr = pb[1] + tophys_mol( code_base );
1236 + /* target[0] = addis r,0,addr@h ; target[1] = ori r,r,addr@l */
1237 + target[0] = (15 << 26) | (r << 21) | (addr >> 16);
1238 + target[1] = (24 << 26) | (r << 21) | (r << 16) | (addr & 0xffff);
1240 + /* printk("ACTION_LI_PHYS %d %08lX\n", dreg, addr ); */
1245 +action_lwz_physaddr_r( int action, ulong *target, const int *pb )
1247 + ulong addr = pb[1] + tophys_mol( code_base );
1248 + int dr = (pb[0] >> 5) & 0x1f;
1249 + int r = pb[0] & 0x1f;
1250 + short low = (addr & 0xffff);
1252 + /* target[0] = addis dr,r,addr@h ; target[1] = lwz dr,addr@l(dr) */
1253 + target[0] = (15 << 26) | (dr << 21) | (r << 16) | ((addr - low) >> 16);
1254 + target[1] = (32 << 26) | (dr << 21) | (dr << 16) | ((int)low & 0xffff);
1256 + /* printk("ACTION_LI_PHYS %d %08lX\n", dreg, addr ); */
1261 +action_specvar( int action, ulong *target, const int *pb )
1263 + int r = pb[0] & 0x1f;
1267 + case SPECVAR_SESSION_TABLE:
1268 + addr = tophys_mol(g_sesstab);
1274 + if( action == ACTION_LIS_SPECVAR_H ) {
1275 + /* target[0] = addis r,0,addr@h */
1276 + target[0] = OPCODE_LIS( r, (addr >> 16) & 0xffff );
1279 + if( action == ACTION_ORI_SPECVAR_L ) {
1280 + /* target[0] = ori rD,rS,addr@l */
1281 + int rD = (pb[0] >> 5) & 0x1f;
1282 + target[0] = OPCODE_ORI( rD, r, (addr & 0xffff));
1289 +/* Note: this only works under linux */
1291 +action_tophysvirt( int action, ulong *target, const int *pb )
1293 + ulong addr = tophys_mol(0);
1294 + int dr = (pb[0] >> 5) & 0x1f;
1295 + int sr = pb[0] & 0x1f;
1297 + if( action == ACTION_TOVIRT )
1300 + /* target[0] = addis dr,sr,(tophys(0))@hi */
1301 + target[0] = OPCODE_ADDIS( dr, sr, (addr >> 16) & 0xffff );
1305 +/* pb[] = { vector, size, vret_offs, ...hook_code... } */
1307 +action_reloc_hook( int action, ulong *hookcode, const int *pb )
1309 + ulong addr, inst, vector=pb[0], size=pb[1], vret_offs=pb[2];
1310 + cleanup_entry_t *clean;
1311 + ulong *vector_virt, *target;
1316 + /* Virtual address of exception vector */
1317 + vector_virt = lowmem_phys_to_virt(vector);
1319 + /* address of the vector hook code */
1320 + addr = tophys_mol( (char*)hookcode );
1322 + /* allocate lowmem and add cleanup handler */
1323 + if( !(lowmem=lowmem_alloc(size, &clean)) )
1326 + /* printk("ACTION_RELOC_HOOK: %lx, %lx, %lx, %lx %p\n", vector, size, vret_action, vret_offs, lowmem); */
1328 + memcpy( lowmem, &pb[3], size );
1330 + /* perform the vret_action */
1331 + for( i=0; (apb=find_action(ACTION_VRET, i)); i++ ) {
1332 + if( apb->params[0] != vector )
1335 + /* insert the absolut branch */
1336 + target = (ulong*)(code_base + apb->offs);
1337 + *target = ((18<<26) + 2) | lowmem_tophys(lowmem + vret_offs);
1338 + flush_icache_mol( (ulong)target, (ulong)target + 4 );
1339 + /* printk("'ba xxx' added (opcode %08lX at %p)\n", *target, target ); */
1342 + /* fix the hook address in the glue code */
1343 + target = (ulong*)lowmem;
1344 + target[1] = (target[1] & ~0xffff) | (addr >> 16); /* target[0] = addis r3,0,0 */
1345 + target[3] = (target[3] & ~0xffff) | (addr & 0xffff); /* target[1] = ori r3,r3,0 */
1347 + /* relocate instruction to be overwritten with a branch */
1348 + inst = *vector_virt;
1349 + clean->opcode = inst;
1350 + if( relocate_inst( &inst, vector, lowmem_tophys(lowmem+vret_offs) ))
1352 + *(ulong*)(lowmem + vret_offs) = inst;
1353 + flush_icache_mol( (ulong)lowmem, (ulong)lowmem + size );
1355 + /* insert branch, 'ba lowmem_ph' */
1356 + *(volatile ulong*)vector_virt = 0x48000002 + lowmem_tophys(lowmem);
1357 + flush_icache_mol( (ulong)vector_virt, (ulong)vector_virt+4 );
1359 + /* we are in business! */
1360 + clean->inst_addr = vector_virt;
1365 +/* pb = { size, where_to_store_lowmem_addr, ...code... } */
1367 +action_reloc_low( int action, ulong *dummy, const int *pb )
1370 + char **func_ptr = (char**)pb[1];
1373 + if( !(lowmem=lowmem_alloc(size, NULL)) )
1375 + memcpy( lowmem, (char*)&pb[2], size );
1377 + flush_icache_mol( (ulong)lowmem, (ulong)lowmem+size );
1378 + *func_ptr = lowmem;
1382 +/* pb = { symind, size, fret_offset, codeglue... } */
1384 +action_hook_function( int action, ulong *hookcode, const int *pb )
1386 + ulong addr, fhook=pb[0], size=pb[1], fret_offs=pb[2];
1387 + ulong *target, inst;
1388 + char *lowmem, *func_addr=NULL;
1389 + cleanup_entry_t *clean;
1393 + case FHOOK_FLUSH_HASH_PAGE:
1394 + func_addr = (char*)compat_flush_hash_pages;
1398 + printk("Bad fhook index %ld\n", fhook );
1402 + /* this does not have to be in lowmem, but it is simpler with a unified approach */
1403 + if( !(lowmem=lowmem_alloc(size, &clean)) )
1406 + /* printk("ACTION_HOOK_FUNCTION: %lx, %lx, %lx %p\n", fhook, size, fret_offs, lowmem); */
1408 + memcpy( lowmem, &pb[3], size );
1410 + /* fix the hook address in the glue code */
1411 + target = (ulong*)lowmem;
1412 + addr = (ulong)hookcode;
1413 + target[1] = (target[1] & ~0xffff) | (addr >> 16); /* target[1] = addis rX,0,0 */
1414 + target[2] = (target[2] & ~0xffff) | (addr & 0xffff); /* target[2] = ori rX,rX,0 */
1416 + /* relocate overwritten instruction and add relative return branch */
1417 + inst = *(ulong*)func_addr;
1418 + clean->opcode = inst;
1419 + if( relocate_inst(&inst, (ulong)func_addr, (ulong)lowmem + fret_offs) )
1421 + target = (ulong*)(lowmem + fret_offs);
1423 + target[1] = (18<<26) | (((ulong)func_addr - (ulong)&target[1] + sizeof(long)) & 0x03fffffc);
1424 + flush_icache_mol( (ulong)lowmem, (ulong)lowmem + size );
1427 + /* insert relative branch, 'b lowmem' */
1428 + *(volatile ulong*)func_addr = (18<<26) | ((lowmem - func_addr) & 0x03fffffc);
1429 + flush_icache_mol( (ulong)func_addr, (ulong)func_addr+4 );
1433 + /* we are in business! */
1434 + clean->inst_addr = (ulong*)func_addr;
1439 +action_fix_sprg2( int action, ulong *target, const int *pb )
1443 + int r = pb[0] & 0x1f;
1444 + asm volatile("mfspr %0,274" : "=r" (sprg2) );
1445 + target[0] = OPCODE_LIS( r, (sprg2 >> 16) & 0xffff );
1446 + target[1] = OPCODE_ORI( r, r, (sprg2 & 0xffff) );
1447 + target[2] = OPCODE_MTSPRG2( r );
1453 +action_noaction( int action, ulong *hookcode, const int *pb )
1458 +static action_func_t actiontable[MAX_NUM_ACTIONS] = {
1459 + [ACTION_LI_PHYS] = action_li_phys,
1460 + [ACTION_LWZ_PHYSADDR_R] = action_lwz_physaddr_r,
1461 + [ACTION_TOPHYS] = action_tophysvirt,
1462 + [ACTION_TOVIRT] = action_tophysvirt,
1463 + [ACTION_RELOC_HOOK] = action_reloc_hook,
1464 + [ACTION_RELOCATE_LOW] = action_reloc_low,
1465 + [ACTION_HOOK_FUNCTION] = action_hook_function,
1466 + [ACTION_VRET] = action_noaction,
1467 + [ACTION_FIX_SPRG2] = action_fix_sprg2,
1469 + [ACTION_LIS_SPECVAR_H] = action_specvar,
1470 + [ACTION_ORI_SPECVAR_L] = action_specvar,
1474 +/************************************************************************/
1475 +/* write/remove hooks */
1476 +/************************************************************************/
1479 +relocate_code( void )
1481 + extern char r__reloctable_start[], r__reloctable_end[];
1483 + code_size = r__reloctable_end - r__reloctable_start;
1485 + if( !(code_base=kmalloc_cont_mol(code_size)) )
1488 + memcpy( code_base, r__reloctable_start, code_size );
1489 + reloc_virt_offs = (int)code_base - (int)r__reloctable_start;
1494 +perform_actions( void )
1499 + if( relocate_code() )
1501 + lowmem_initialize();
1503 + for( action=0; action < MAX_NUM_ACTIONS; action++ ) {
1504 + for( i=0; (pb=find_action(action,i)); i++ ) {
1505 + ulong *target = (ulong*)(code_base + pb->offs);
1507 + if( pb->offs > code_size ) {
1508 + printk("OFFSET ERROR!\n");
1512 + if( !actiontable[action] )
1514 + if( (*actiontable[action])(action, target, pb->params) )
1518 + /* we need to flush the icache before the hook actions are performed */
1519 + if( action == FLUSH_CACHE_ACTION )
1520 + flush_icache_mol( (ulong)code_base, (ulong)code_base + code_size );
1522 + /* to be on the safe side, flush the cache once more */
1523 + flush_icache_mol( (ulong)code_base, (ulong)code_base + code_size );
1526 + printk("MOL: action %d error\n", action );
1527 + cleanup_actions();
1532 +cleanup_actions( void )
1534 + cleanup_entry_t *ce = &cleanup_table[0];
1537 + for( i=0; i<num_cleanup_entries; i++, ce++ ) {
1538 + if( ce->inst_addr ) {
1539 + *(volatile ulong*)ce->inst_addr = cleanup_table[i].opcode;
1540 + flush_icache_mol( (ulong)ce->inst_addr, (ulong)ce->inst_addr + 4 );
1543 + lowmem_free_all();
1544 + kfree_cont_mol( code_base );
1547 +++ b/drivers/macintosh/mol/asm-files/603.S
1550 + * Creation Date: <2001/06/15 20:10:49 samuel>
1551 + * Time-stamp: <2001/06/16 15:35:22 samuel>
1557 + * Copyright (C) 2001 Samuel Rydh (samuel@ibrium.se)
1559 + * This program is free software; you can redistribute it and/or
1560 + * modify it under the terms of the GNU General Public License
1561 + * as published by the Free Software Foundation
1565 +#define P603_USE_G_BIT
1566 +#define P603_USE_R_BIT
1567 +#define P603_USE_C_BIT
1569 +/* NOTE: The 603 vectors are called with ctr saved in r0.
1570 + * Secondary interrupts are not detected automatically.
1573 +/************************************************************************/
1574 +/* Instruction TLB Miss (603 specific vector) */
1575 +/************************************************************************/
1577 +VECTOR_603( 0x1000, "Instruction TLB Miss - 603" )
1578 +// mfctr r0 // Need to save this - CTR can't be touched!
1579 + mfspr r2,HASH1 // Get PTE pointer
1580 + mfspr r3,ICMP // Partial item compare value
1581 +00: li r1,8 // 8 items / bucket
1583 + subi r2,r2,8 // Preset pointer
1584 +10: lwzu r1,8(r2) // Get next PTE
1585 + cmp 0,r1,r3 // Found entry yet?
1586 + bdnzf 2,10b // Jump back if not, until CTR==0
1587 + bne 30f // Try secondary hash if CTR==0
1588 + lwz r1,4(r2) // Get second word of entry
1589 +#ifdef P603_USE_G_BIT
1590 + andi. r3,r1,8 // check G-bit
1591 + bne DoISI_603_G // if guarded, take an ISI
1593 + mtctr r0 // Restore CTR
1594 + mfspr r3,SRR1 // Need to restore CR0
1596 + mfspr r0,IMISS // Set to update TLB
1598 +#ifdef P603_USE_R_BIT
1599 + ori r1,r1,0x100 // Set reference bit
1600 + srwi r1,r1,8 // Get byte 7 of pte
1601 + tlbli r0 // Load the ITLB
1602 + stb r1,6(r2) // update page table
1604 + tlbli r0 // Load the ITLB
1609 +30: andi. r1,r3,0x40 // Already doing secondary hash?
1610 + bne DoISI_603 // Yes - item not in hash table
1611 + mfspr r2,HASH2 // Get hash table pointer
1612 + ori r3,r3,0x40 // Set secondary hash
1613 + b 00b // Try lookup again
1616 +/************************************************************************/
1617 +/* Data Store TLB Miss (603 specific vector) */
1618 +/************************************************************************/
1620 +VECTOR_603( 0x1200, "Data Store TLB Miss - 603" )
1621 +// mfctr r0 // Need to save this - CTR can't be touched!
1622 + mfspr r2,HASH1 // Get PTE pointer
1623 + mfspr r3,DCMP // Partial item compare value
1624 +00: li r1,8 // 8 items / bucket
1626 + subi r2,r2,8 // Preset pointer
1627 +10: lwzu r1,8(r2) // Get next PTE
1628 + cmp 0,r1,r3 // Found entry yet?
1629 + bdnzf 2,10b // Jump back if not, until CTR==0
1630 + bne 30f // Try secondary hash if CTR==0
1631 + lwz r1,4(r2) // Get second word of entry
1632 +#ifdef P603_USE_C_BIT
1633 + andi. r3,r1,0x80 // Check the C-bit
1637 +20: mtctr r0 // Restore CTR
1638 + mfspr r3,SRR1 // Need to restore CR0
1640 + mfspr r0,DMISS // Set to update TLB
1646 +30: andi. r1,r3,0x40 // Already doing secondary hash?
1647 + bne DoDSI_603 // Yes - item not in hash table
1648 + mfspr r2,HASH2 // Get hash table pointer
1649 + ori r3,r3,0x40 // Set secondary hash
1650 + b 00b // Try lookup again
1652 +#ifdef P603_USE_C_BIT
1653 + // Entry found and PTE[c] == 0. Check protection before setting PTE[c]
1654 + // r0 = saved ctr, r1 = second word of PTE, r2 = pointer to pteg, r3 = trash
1656 + rlwinm. r3,r1,30,0,1 // test PP
1657 + bge- 50f // if (PP == 00 or PP == 01) goto 50
1658 + andi. r3,r1,1 // test PP[0]
1659 + beq+ 60f // return if PP[0] == 0
1660 + b DoDSI_603_P // else DSI_P, (PP==11, read-only)
1662 +50: mfspr r3,SRR1 // get old msr
1663 + andis. r3,r3,0x0008 // test the KEY bit (SRR1-bit 12)
1664 + beq 60f // if KEY==0, goto 60
1665 + b DoDSI_603_P // else DSI_P
1667 +60: ori r1,r1,0x180 // set reference and change bit
1668 + sth r1,6(r2) // update page table
1669 + b 16b // and back we go
1673 +/************************************************************************/
1674 +/* Data Load TLB Miss (603 specific vector) */
1675 +/************************************************************************/
1677 +VECTOR_603( 0x1100, "Data Load TLB Miss - 603" )
1678 +// mfctr r0 // Need to save this - CTR can't be touched!
1679 + mfspr r2,HASH1 // Get PTE pointer
1680 + mfspr r3,DCMP // Partial item compare value
1681 +00: li r1,8 // 8 items / bucket
1683 + subi r2,r2,8 // Preset pointer
1684 +10: lwzu r1,8(r2) // Get next PTE
1685 + cmp 0,r1,r3 // Found entry yet?
1686 + bdnzf 2,10b // Jump back if not, until CTR==0
1687 + bne 30f // Try secondary hash if CTR==0
1688 + lwz r1,4(r2) // Get second word of entry
1689 +20: mtctr r0 // Restore CTR
1690 + mfspr r3,SRR1 // Need to restore CR0
1692 + mfspr r0,DMISS // Set to update TLB
1694 +#ifdef P603_USE_R_BIT
1695 + ori r1,r1,0x100 // set reference bit
1705 +30: andi. r1,r3,0x40 // Already doing secondary hash?
1706 + bne DoDSI_603 // Yes - item not in hash table
1707 + mfspr r2,HASH2 // Get hash table pointer
1708 + ori r3,r3,0x40 // Set secondary hash
1709 + b 00b // Try lookup again
1712 +/************************************************************************/
1713 +/* Synthesize an ISI Exception */
1714 +/************************************************************************/
1718 + andi. r2,r3,0xFFFF // Clear upper bits of SRR1
1719 + addis r2,r2,0x4000 // Set bit 1 -> PTE not found (in HTAB)
1720 + mtctr r0 // Restore CTR
1722 + mfmsr r0 // Restore "normal" registers
1723 + xoris r0,r0,MSR_TGPR>>16
1724 + mtcrf 0x80,r3 // Restore CR0
1725 + sync // Some chip revs have problems here...
1727 + SOFT_VECTOR_ENTRY_603( 0x400 ) // Jump to the ISI vector
1730 +#ifdef P603_USE_G_BIT
1733 + andi. r2,r3,0xFFFF // Clear upper bits of SRR1
1734 +// addis r2,r2,0x0800 // Page protection violation
1735 + addis r2,r2,0x1000 // Guarded memory access
1740 +/************************************************************************/
1741 +/* Synthesize a DSI exception */
1742 +/************************************************************************/
1746 + rlwinm r1,r3,9,6,6 // Get load/store bit
1747 + addis r1,r1,0x4000 // Set bit 1 -> PTE not found
1750 + mtctr r0 // Restore CTR
1751 + andi. r2,r3,0xFFFF // Clear upper bits of SRR1
1753 + mfspr r1,DMISS // Get failing address
1754 + mtspr DAR,r1 // Set fault address
1755 + mfmsr r0 // Restore "normal" registers
1756 + xoris r0,r0,MSR_TGPR>>16
1757 + mtcrf 0x80,r3 // Restore CR0
1758 + sync // Some chip revs have problems here...
1760 + SOFT_VECTOR_ENTRY_603( 0x300 ) // Jump to the DSI vector
1764 + rlwinm r1,r3,9,6,6 // get load/store bit
1765 + addis r1,r1,0x800 // Set bit 4 (prot. violation)
1768 +++ b/drivers/macintosh/mol/asm-files/dec.S
1771 + * Creation Date: <2001/06/21 17:10:35 samuel>
1772 + * Time-stamp: <2004/03/07 13:16:58 samuel>
1776 + * DEC / TimeBase stuff
1778 + * Copyright (C) 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
1780 + * This program is free software; you can redistribute it and/or
1781 + * modify it under the terms of the GNU General Public License
1782 + * as published by the Free Software Foundation
1786 +/************************************************************************/
1788 +/************************************************************************/
1792 + blr // read (won't come here)
1798 + blr // read (won't come here)
1801 + // ...fall through...
1803 +// r3 = tbu, r4 = tbl, r0,r2,r5 free.
1805 + lwz r5,K_LOADED_DEC(r1)
1807 + sub r5,r5,r2 // r5 = elapsed ticks
1809 + li r2,0 // Set timebase
1824 +/************************************************************************/
1825 +/* Load/restore DEC and TB */
1826 +/************************************************************************/
1828 + //////////////////////////////////////////////////////////////
1829 + // recalc_int_stamp
1831 + // May modify: r0,r2-r5
1835 + crclr FBIT_RecalcDecInt
1837 + lwz r5,xTIMER_STAMP(r1)
1838 + bf FBIT_DecSeenZero, 1f // FBIT_DecSeenZero must be set when DEC is loaded
1839 + bt FBIT_DecINT, 1f // interrupt might already be flagged...
1841 + lwz r4,xDEC_STAMP(r1) // Has the xDEC overflown already?
1843 + blt 2f // branch if xDEC < 0
1845 + blt 2f // branch if xDEC < xTIMER
1847 +2: stw r4,K_INT_STAMP(r1) // dec = xTIMER
1851 + //////////////////////////////////////////////////////////////
1854 + // May modify: r0,r2-r5
1856 + // Old 2.4 kernels assume that linux-DEC never ticks faster
1857 + // than the DEC interval measured from TB. Unfortunately,
1858 + // it is virtually impossible to keep DEC/TB in sync.
1860 + // Experimentally, the "worst case" senario is a linux DEC tick
1861 + // beeing delayed 0.04 ms (to be compare with the 20 ms period).
1863 + // Sequences similar to
1865 + // 1: mftb r2; mfdec r3; mftb r4; cmp r2,r4; bne 1b
1867 + // do *not* work - DEC and TB probably ticks on different edges.
1870 + lwz r5,K_INT_STAMP(r1) // DEC = K_INT_STAMP - tbl
1871 + mfdec r3 // Make sure linux interrupts *never*
1872 + mftb r2 // occur too fast
1877 + add r5,r3,r2 // K_DEC_STAMP = DEC + tbl
1880 + stw r5,K_DEC_STAMP(r1)
1881 + crset FBIT_MolDecLoaded
1884 + ///////////////////////////////////////////////////////////////
1887 + // May modify: r0,r2, cr
1891 + lwz r0,K_DEC_STAMP(r1)
1892 + crclr FBIT_MolDecLoaded
1893 + mftb r2 // Keep linux-DEC coherent
1894 + sub r2,r0,r2 // DEC = stamp - tbl
1900 +/************************************************************************/
1901 +/* DEC read/write */
1902 +/************************************************************************/
1905 + lwz r4,xDEC_STAMP(r1)
1910 + GET_TICK_CNT(entry,"dec_read")
1916 + // dec write. r0 = spr_value
1918 + rlwinm. r5,r0,0,0,0 // seen zero?
1920 + cror FBIT_DecSeenZero,FBIT_DecSeenZero,eq
1922 + stw r5,xDEC_STAMP(r1) // set new dec value
1923 + bf FBIT_DecSeenZero, emulation_done
1924 + bl recalc_int_stamp // M: r0,r2-r5
1925 + btl FBIT_MolDecLoaded, set_kernel_dec // M: r0,r2
1926 + bl set_mol_dec // M: r0,r2-r5
1930 +/************************************************************************/
1931 +/* Decrementer Exception */
1932 +/************************************************************************/
1934 + // __dec_VECTOR (non-MOL dec exception)
1936 + // r3=cr, sprg1=saved_r1, sprg0=saved_r3
1938 + // An exception with DEC>=0 can occur if a mac-DEC overflows occurs
1939 + // just prior to a context switch. These exceptions should be
1940 + // dropped silently.
1946 + mtcr r3 // Restore and exit
1947 + ABORT_TRAP( 0x900 )
1949 + mtcr r3 // Restore and continue trap
1950 + CONTINUE_TRAP( 0x900 )
1952 +VECTOR_( 0x900, "Decrementer", secint_bad, __dec_VECTOR )
1953 + EXCEPTION_PREAMBLE // r0-r5, CR, LR, r6/r7 = msr/nip
1954 + TRACE(0x900, "Decrementer")
1957 + bge exception_return
1958 + bf FBIT_MolDecLoaded, take_linux_dec_exception
1961 + lis r2,0x1000 // r2 = DEC rearm constant
1963 + bf FBIT_DecSeenZero, 1f // check for xDEC overflow
1964 + lwz r4,xDEC_STAMP(r1)
1965 + sub. r0,r4,r3 // lt set if xDEC has overflown
1966 + cror FBIT_DecINT, FBIT_DecINT, lt // dec_int |= lt
1967 + crandc FBIT_DecSeenZero, FBIT_DecSeenZero, lt // szero &= ~lt
1969 + lwz r5,xTIMER_STAMP(r1) // r5 = xTIMER_STAMP
1970 + sub. r0,r5,r3 // lt set if xTIMER has overflown
1971 + mtdec r2 // rearm DEC
1972 + blt- 2f // xTIMER has higher priority...
1974 + // mac-dec interrupt
1975 + BUMP("DEC-overflow")
1977 + bl recalc_int_stamp
1979 + GET_TICK_CNT(entry,"dec-overflow")
1980 + bf- FBIT_DecINT,exception_return // could occur if xTIMER has changed on us
1982 + rlwinm. r0,r4,0,MSR_EE
1983 + beq- exception_return // no... simply return
1984 + BUMP("DEC-exception")
1987 + // timer interrupt
1988 +2: BUMP("Timer-interrupt")
1989 + crset FBIT_RecalcDecInt // dec must be recalced
1990 + GET_TICK_CNT(entry,"timer-overflow")
1991 + MAC_EXIT_SAVE( RVEC_TIMER )
1994 +take_linux_dec_exception:
1996 + bl save_middle_regs
1997 + TAKE_EXCEPTION( 0x900 )
1999 +++ b/drivers/macintosh/mol/asm-files/emuaccel.S
2002 + * Creation Date: <2003/01/24 13:54:52 samuel>
2003 + * Time-stamp: <2003/08/14 03:12:00 samuel>
2007 + * Emulation acceleration
2009 + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
2011 + * This program is free software; you can redistribute it and/or
2012 + * modify it under the terms of the GNU General Public License
2013 + * as published by the Free Software Foundation
2017 +#include "emuaccel_sh.h"
2019 + // emuaccel registers:
2021 + // r2 = emuaccel_slot
2022 + // r6,r7 = nip(return address)/mregs
2026 +emuaccel_mtmsr_rNN:
2027 +mFORLOOP([i],0,31,[
2028 + LOAD_EMUGPR_IM r0,i
2029 + b emulate_mtmsr_accel
2031 +emuaccel_mtsrr0_rNN:
2032 +mFORLOOP([i],0,31,[
2034 + LOAD_EMUGPR_IM r0,i
2035 + b emulate_mtsrr0_accel
2037 + stw rPREFIX[]i,xSRR0(r1)
2038 + b emulation_done_noinc
2041 +emuaccel_mtsrr1_rNN:
2042 +mFORLOOP([i],0,31,[
2044 + LOAD_EMUGPR_IM r0,i
2045 + b emulate_mtsrr1_accel
2047 + stw rPREFIX[]i,xSRR1(r1)
2048 + b emulation_done_noinc
2051 +emuaccel_mtsprg0_rNN:
2052 +mFORLOOP([i],0,31,[
2054 + LOAD_EMUGPR_IM r0,i
2055 + b emulate_mtsprg0_accel
2057 + stw rPREFIX[]i,xSPRG0(r1)
2058 + b emulation_done_noinc
2061 +emuaccel_mtsprg1_rNN:
2062 +mFORLOOP([i],0,31,[
2064 + LOAD_EMUGPR_IM r0,i
2065 + b emulate_mtsprg1_accel
2067 + stw rPREFIX[]i,xSPRG1(r1)
2068 + b emulation_done_noinc
2071 +emuaccel_mtsprg2_rNN:
2072 +mFORLOOP([i],0,31,[
2074 + LOAD_EMUGPR_IM r0,i
2075 + b emulate_mtsprg2_accel
2077 + stw rPREFIX[]i,xSPRG2(r1)
2078 + b emulation_done_noinc
2081 +emuaccel_mtsprg3_rNN:
2082 +mFORLOOP([i],0,31,[
2084 + LOAD_EMUGPR_IM r0,i
2085 + b emulate_mtsprg3_accel
2087 + stw rPREFIX[]i,xSPRG3(r1)
2088 + b emulation_done_noinc
2091 +emuaccel_mthid0_rNN:
2092 +mFORLOOP([i],0,31,[
2094 + LOAD_EMUGPR_IM r0,i
2095 + b emulate_mthid0_accel
2097 + stw rPREFIX[]i,xHID0(r1)
2098 + b emulation_done_noinc
2103 + b emulation_done_noinc
2106 + addi r6,r6,-4 // point nip to the rfi instruction
2109 +emuaccel_update_dec:
2110 + lwz r4,xDEC_STAMP(r1)
2114 + b emulation_done_noinc
2118 + lwz r4,12(r2) // emuaccel paramamter (opcode)
2119 + addi r6,r6,-4 // back NIP
2120 + rlwinm r5,r4,14,24,28 // reg_num << 3
2124 +/************************************************************************/
2125 +/* implementation */
2126 +/************************************************************************/
2128 +emulate_mtsrr0_accel:
2130 + b emulation_done_noinc
2131 +emulate_mtsrr1_accel:
2133 + b emulation_done_noinc
2134 +emulate_mtsprg0_accel:
2136 + b emulation_done_noinc
2137 +emulate_mtsprg1_accel:
2139 + b emulation_done_noinc
2140 +emulate_mtsprg2_accel:
2142 + b emulation_done_noinc
2143 +emulate_mtsprg3_accel:
2145 + b emulation_done_noinc
2146 +emulate_mthid0_accel:
2148 + b emulation_done_noinc
2151 +emulate_mtmsr_accel:
2152 + lwz r3,xMSR(r1) // r3 = old MSR
2155 + GET_TICK_CNT(entry, "mtmsr-accel")
2156 + BUMP("emulate_mtmsr-accel")
2158 + beq+ cr1,emulation_done_noinc // no doze... we are done
2159 + MAC_EXIT_SAVE( RVEC_MSR_POW ) // doze
2163 +/************************************************************************/
2165 +/************************************************************************/
2167 +#define EMUACCEL_REL(s) s - emuaccel_table
2170 + .text 70 /* this table does not need to be relocated */
2172 + // format: emuaccel_inst, offset, table_index_mask
2173 +GLOBAL_SYMBOL(emuaccel_table):
2174 + .long EMUACCEL_MTMSR, EMUACCEL_REL( emuaccel_mtmsr_rNN ), 0x1f
2175 + .long EMUACCEL_MTSRR0, EMUACCEL_REL( emuaccel_mtsrr0_rNN ), 0x1f
2176 + .long EMUACCEL_MTSRR1, EMUACCEL_REL( emuaccel_mtsrr1_rNN ), 0x1f
2177 + .long EMUACCEL_MTSPRG0, EMUACCEL_REL( emuaccel_mtsprg0_rNN ), 0x1f
2178 + .long EMUACCEL_MTSPRG1, EMUACCEL_REL( emuaccel_mtsprg1_rNN ), 0x1f
2179 + .long EMUACCEL_MTSPRG2, EMUACCEL_REL( emuaccel_mtsprg2_rNN ), 0x1f
2180 + .long EMUACCEL_MTSPRG3, EMUACCEL_REL( emuaccel_mtsprg3_rNN ), 0x1f
2181 + .long EMUACCEL_MTHID0, EMUACCEL_REL( emuaccel_mthid0_rNN ), 0x1f
2182 + .long EMUACCEL_RFI, EMUACCEL_REL( emuaccel_rfi ), 0
2183 + .long EMUACCEL_UPDATE_DEC, EMUACCEL_REL( emuaccel_update_dec ), 0
2184 + .long EMUACCEL_MTSR, EMUACCEL_REL( emuaccel_mtsr ), 0
2185 + .long EMUACCEL_NOP, EMUACCEL_REL( emuaccel_nop ), 0
2186 + .long 0, 0, 0 /* end marker */
2190 +++ b/drivers/macintosh/mol/asm-files/emulation.S
2193 + * Creation Date: <97/07/26 18:23:02 samuel>
2194 + * Time-stamp: <2004/02/22 13:12:14 samuel>
2198 + * Low-level emulation of some privileged instructions
2200 + * Copyright (C) 1997-2004 Samuel Rydh (samuel@ibrium.se)
2202 + * This program is free software; you can redistribute it and/or
2203 + * modify it under the terms of the GNU General Public License
2204 + * as published by the Free Software Foundation
2213 +/************************************************************************/
2214 +/* program exception vector */
2215 +/************************************************************************/
2217 + //////////////////////////////////////////////////////////////
2218 + // exception preamble
2219 + // r1 stack (mregs)
2220 + // r6,r7 nip / srr1
2221 + // cr4-7 flag_bits
2223 + // Saved r0-r5 (NOT SAVED: ctr, xer)
2225 +VECTOR_( 0x700, "Program", secint_bad, mac_entry )
2226 + EXCEPTION_PREAMBLE // 46 cycles on a G3
2227 + TRACE(0x700, "Program")
2229 + mtcrf 0x10,r7 // put srr1 bits (12-15) into cr3
2230 + bt 14,mac_program_trap
2231 + GET_INSTR_OPCODE // r6=nip, r2-r3, r4=opcode (cr not touched)
2232 + bt+ 13,emulate_priv_instr
2233 + bt+ 12,emulate_illegal_instr
2234 + mtcrf 0x20,r7 // put srr1 bits (8-11) into cr2
2235 + bt+ 11,mac_program_trap // bit 11 = fpu_exception
2237 + // we should not come here
2238 + MAC_EXIT_SAVE( RVEC_UNUSUAL_PROGRAM_EXCEP )
2240 +unhandled_priv_inst:
2241 + MAC_EXIT_SAVE( RVEC_PRIV_INST ) // r4 = opcode
2243 +emulate_illegal_instr:
2244 + rlwinm r2,r4,32-1,22,31
2246 + rlwinm r5,r4,14,24,28 // r5 = reg_num << 3 (instr. bits 6-10)
2247 + rlwimi r2,r4,16,16,21 // r2 = opcode
2249 + rlwinm r0,r2,0,~0x80 // clear mtspr/mfspr bit
2250 + cmpwi r0,OPCODE(31,339) // mfspr/mtspr
2253 + rlwinm r7,r7,0,14,10 // clear srr1 bit 11-13
2254 + cmpwi cr1,r2,OPCODE(31,339) // mfspr
2255 + oris r7,r7,0x4 // set bit 13 (privileged instr)
2257 + beq- cr1,emulate_mfspr // r3=xMSR, r4=opcode, r5=reg_num
2258 + b emulate_mtspr // must be mtspr
2261 + bl emulate_603_instr
2263 + MAC_EXIT_SAVE( RVEC_ILLEGAL_INST ) // r4 = opcode
2266 +/************************************************************************/
2267 +/* mac exceptions */
2268 +/************************************************************************/
2270 + /////////////////////////////////////////////////////////////
2273 + // r2 exception vector
2275 + // r7 reason bits (0-15)
2277 + // r0,r2-r5 may be modified
2281 + li r7,0 // no reason bits
2287 + li r7,0 // no reason bits
2291 +mac_program_trap: // the reason bits already in r7 are used
2292 + __BUMP("mac_trap")
2296 + stw r6,xSRR0(r1) // mac-srr0 = nip
2297 + mr r4,r3 // copy xMSR to SRR1
2298 + mr r6,r2 // new nip
2299 + rlwinm r5,r3,25+1,31,31 // put MSR_IP (bit 25) in r5[31]
2300 + rlwimi r4,r7,0,0,15 // copy reason bits from r7 to SRR1
2301 + rlwimi r4,r3,0,6,6 // copy MSR_VEC bit of xMSR to SRR1
2302 + stw r4,xSRR1(r1) // srr1 = (msr & (0xffff|MSR_VEC)) | (srr1 & ~(0xffff|MSR_VEC))
2303 + rlwinm r4,r3,0,25,25 // copy MSR_IP to xMSR
2304 + neg r5,r5 // r5 = 0xffffffff * MSR_IP
2305 + rlwimi r4,r3,0,19,19 // copy MSR_ME to xMSR
2306 + rlwimi r6,r5,0,0,11 // insert exception prefix
2308 + GET_TICK_CNT(entry,"mac-expception")
2309 + b msr_exception_return
2312 + MAC_EXIT_SAVE( RVEC_TRACE_TRAP )
2315 +/************************************************************************/
2316 +/* decode privileged instruction */
2317 +/************************************************************************/
2319 + /////////////////////////////////////////////////////////////
2320 + // emulate_priv_instr
2324 + // r0,r2-r5,lr free
2327 +emulate_priv_instr:
2328 + rlwinm r2,r4,32-1,22,31
2330 + rlwinm r5,r4,14,24,28 // r5 = reg_num << 3 (instr. bits 6-10)
2331 + rlwimi r2,r4,16,16,21 // r2 = opcode
2333 + GET_TICK_CNT(entry,"get_inst")
2334 + BUMP("decode_priv_inst")
2336 + cmpwi cr1,r2,OPCODE(31,339) // mfspr (both user and supervisor mode)
2337 + beq- cr1,emulate_mfspr // r3=xMSR, r4=opcode, r5=reg_num
2339 + cmpwi cr2,r2,OPCODE(31,467) // mtspr (both user and supervisor mode)
2340 + beq- cr2,emulate_mtspr
2342 + andi. r3,r3,MSR_PR // only emulate in supervisor mode
2343 + bne- mac_program_trap
2345 + cmpwi cr3,r2,OPCODE(31,83) // mfmsr
2346 + beq- cr3,emulate_mfmsr
2348 + cmpwi cr0,r2,OPCODE(31,146) // mtmsr
2349 + beq- cr0,emulate_mtmsr
2351 + cmpwi cr1,r2,OPCODE(19,50) // rfi
2352 + beq- cr1,emulate_rfi
2354 + cmpwi cr2,r2,OPCODE(31,595) // mfsr
2355 + beq- cr2,emulate_mfsr
2357 + cmpwi cr3,r2,OPCODE(31,659) // mfsrin
2358 + beq- cr3,emulate_mfsrin
2360 + cmpwi cr0,r2,OPCODE(31,210) // mtsr
2361 + beq- cr0,emulate_mtsr
2363 + cmpwi cr1,r2,OPCODE(31,242) // mtsrin
2364 + beq- cr1,emulate_mtsrin
2366 + cmpwi cr2,r2,OPCODE(31,306) // tlbie
2367 + beq- cr2,emulate_tlbie
2369 + cmpwi cr3,r2,OPCODE(31,566) // tlbsync
2370 + beq- cr3,emulate_tlbsync
2372 + cmpwi cr0,r2,OPCODE(31,467) // dcbi
2373 + beq- cr0,emulate_dcbi
2375 + cmpwi cr1,r2,OPCODE(31,978) // tlbld
2376 + beq- cr1,emulate_tlbld
2378 + cmpwi cr2,r2,OPCODE(31,1010) // tlbli
2379 + beq- cr2,emulate_tlbli
2381 + // Program-trap, illegal instruction
2382 + b unhandled_priv_inst // r4 = opcode
2387 + rlwinm r2,r4,32-1,22,31
2388 + rlwimi r2,r4,16,16,21 // r2 = opcode
2390 + cmpwi cr0,r2,OPCODE(31,978) // tlbld
2392 + cmpwi cr1,r2,OPCODE(31,1010) // tlbli
2394 + cmpwi cr2,r2,OPCODE(31,339) // mfspr
2396 + cmpwi cr3,r2,OPCODE(31,467) // mtspr
2398 +1: rlwinm r3,r4,32-16,27,31
2399 + rlwimi r3,r4,32-6,22,26 // r3 = spr#
2400 + cmpwi r3,976 // first 603 SPR
2402 + cmpwi r3,982 // last 603 SPR
2405 + rlwinm r7,r7,0,14,10 // clear bit 11-13
2406 + oris r7,r7,0x4 // set bit 13
2407 + b emulate_priv_instr
2409 +#endif /* EMULATE_603 */
2412 +/************************************************************************/
2413 +/* mac register access */
2414 +/************************************************************************/
2416 +MACRO(LOAD_EMUGPR_IM, [dreg,ereg], [
2418 + lwz _dreg,xGPR0+_ereg[]*4(r1)
2420 + mr _dreg,rPREFIX[]_ereg
2424 +MACRO(STORE_EMUGPR_IM, [sreg,ereg], [
2426 + stw _sreg,xGPR0+_ereg[]*4(r1)
2428 + mr rPREFIX[]_ereg, _sreg
2434 +mFORLOOP([i],0,31,[
2435 + STORE_EMUGPR_IM r0,i
2440 +mFORLOOP([i],0,31,[
2441 + LOAD_EMUGPR_IM r0,i
2445 +MACRO(EMU_LOAD_GPR, [reg, scr], [
2446 + LI_PHYS( _scr, load_gpr_table )
2447 + add rPREFIX[]_scr,_reg,rPREFIX[]_scr
2448 + mtlr rPREFIX[]_scr
2452 +MACRO(EMU_STORE_GPR, [reg, scr], [
2453 + LI_PHYS( _scr, store_gpr_table )
2454 + add rPREFIX[]_scr,_reg,rPREFIX[]_scr
2455 + mtlr rPREFIX[]_scr
2461 +/************************************************************************/
2462 +/* instruction emulation */
2463 +/************************************************************************/
2465 + //////////////////////////////////////////////////////////
2469 + // r5 regnum<<3 (from opcode bits 6-10)
2471 + // May modify: r0,r2-r5 (lr)
2473 +/********************************************************************/
2476 + EMU_STORE_GPR r5, /**/ R2
2477 + GET_TICK_CNT( entry, "mfmsr" )
2480 +/********************************************************************/
2481 +emulate_mfspr: // r3 = xMSR
2482 + BUMP("emulate_mfspr")
2483 + rlwimi r4,r4,32-10,21,25 // flip spr
2484 + rlwinm r0,r3,32-14,31,31 // r0(bit31) = MSR_PR
2485 + addi r3,r1,K_SPR_HOOKS
2486 + rlwinm r2,r4,32-4,20,29 // r2 = spr# << 2
2487 + addi r4,r1,xSPR_BASE
2488 + lwzx r3,r2,r3 // hook in r3
2489 + and. r0,r0,r3 // privileged SPR?
2490 + bne- mac_program_trap
2491 + lwzx r0,r2,r4 // value in r0
2495 +/********************************************************************/
2496 +emulate_mtspr: // r3 = xMSR
2497 + BUMP("emulate_mtspr")
2498 + rlwimi r4,r4,32-10,21,25 // flip spr
2499 + EMU_LOAD_GPR r5, /**/ R2 // value in r0
2500 + rlwinm r2,r4,32-4,20,29 // r2 = spr# << 2
2501 + addi r4,r1,K_SPR_HOOKS
2502 + rlwinm r3,r3,32-14,31,31 // r3(bit31) = MSR_PR
2503 + lwzx r4,r2,r4 // hook in r4
2504 + addi r5,r2,xSPR_BASE // r5+r1 points to SPR reg
2505 + addi r4,r4,4 // branch to hook +4
2506 + and. r3,r3,r4 // privileged SPR?
2507 + bne- mac_program_trap // privileged exception
2508 + mtlr r4 // lsb is discarded...
2512 +/********************************************************************/
2515 + lwz r3,xMSR(r1) // r3 = old MSR
2516 + LI_PHYS( R2, load_gpr_table )
2519 + blrl // r0 = new MSR
2524 + GET_TICK_CNT(entry, "mtmsr")
2525 + BUMP("emulate_mtmsr")
2527 + beq+ cr1,emulation_done_noinc
2528 + MAC_EXIT_SAVE( RVEC_MSR_POW ) // POW 1 => doze
2531 +/********************************************************************/
2534 + lis r4,(MSR_VEC)>>16
2538 + oris r4,r4,(MSR_TGPR)>>16
2540 + lwz r3,xMSR(r1) // r3 = old MSR
2543 + lwz r6,xSRR0(r1) // new nip = SRR0
2546 + bl msr_altered // r0,r2-r5, r7 [srr1] updated
2548 + GET_TICK_CNT(entry,"rfi")
2550 + lwz r3,K_BREAK_FLAGS(r1) // break at rfi support
2551 + andi. r3,r3,BREAK_RFI
2552 + beq+ exception_return
2553 + li r4,BREAK_RFI // r4 = flag causing the break
2554 + MAC_EXIT_SAVE( RVEC_BREAK )
2557 +/********************************************************************/
2560 + LOADI r3,EXTERN(do_tlbli)
2563 + LOADI r3,EXTERN(do_tlbld)
2566 + LOADI r3,EXTERN(do_tlbie)
2568 + rlwinm r5,r4,32-8,24,28 // r5 = #B << 3
2569 + EMU_LOAD_GPR r5, /**/ R2 // value ret. in r0
2570 + mr r4,r0 // r4 = ea
2571 + b call_kernel_save
2575 +#endif /* EMULATE_603 */
2577 +/********************************************************************/
2581 +/********************************************************************/
2583 + b unhandled_priv_inst // r4 = opcode
2585 +/********************************************************************/
2587 + rlwinm r2,r4,32-8,24,28 // r2 = #B << 3
2588 + EMU_LOAD_GPR r2, /**/ R3 // r0 = reg B
2589 + rlwinm r3,r0,6,26,29 // r3 = #sr << 2
2592 + rlwinm r3,r4,32-14,26,29 // r3 = #sr << 2
2593 +1: addi r2,r1,xSEGR_BASE
2595 + EMU_STORE_GPR r5, /**/ R2
2596 + GET_TICK_CNT(entry, "mfsr")
2602 +/************************************************************************/
2603 +/* SPR - emulation */
2604 +/************************************************************************/
2606 + ////////////////////////////////////////////////////////////
2607 + // read (offset 0)
2612 + // write (offset 4)
2615 + // r5 spr offset (relative r1)
2617 + // Safe to modify: r2-r5, lr
2618 + // NOT SAVED: ctr, xer
2620 +/********************************************************************/
2622 + EMU_STORE_GPR r5, /**/ R3
2623 + GET_TICK_CNT(entry,"simple_mfspr")
2626 +GLOBAL_SYMBOL(r__spr_read_write):
2629 + stwx r0,r5,r1 // value in r0
2630 + GET_TICK_CNT(entry,"simple_mtspr")
2634 +/********************************************************************/
2635 +GLOBAL_SYMBOL(r__spr_read_only):
2637 + b simple_mfspr // allow read
2638 + b emulation_done // ignore write
2640 +/********************************************************************/
2641 +GLOBAL_SYMBOL(r__spr_illegal):
2643 + nop // spr read entry
2644 + rlwinm r7,r7,0,15,10 // clear srr1 bit 11-14
2645 + oris r7,r7,0x8 // set bit 12 (privileged instr)
2646 + b mac_program_trap
2649 +/********************************************************************/
2650 +unhandled_spr_read:
2655 + MAC_EXIT_SAVE( RVEC_SPR_READ )
2658 + b unhandled_spr_read // read hook (offs 0)
2659 +unhandled_spr_write: // write hook (offs 4)
2663 + // r5 = register-value
2664 + MAC_EXIT_SAVE( RVEC_SPR_WRITE )
2666 +/********************************************************************/
2668 + b simple_mfspr // read has no side-effects
2670 + LOADI r3,EXTERN(do_mtbat)
2671 + bl save_middle_regs // Must do this before touching r6-r12
2672 + srwi r4,r2,2 // r4 = spr#
2673 + mr r5,r0 // r5 = value
2674 + li r6,0 // not forced
2677 +/********************************************************************/
2679 + b simple_mfspr // read has no side-effects
2681 + LOADI r3,EXTERN(do_mtsdr1)
2682 + mr r4,r0 // r4 = value
2683 + b call_kernel_save
2688 +/************************************************************************/
2689 +/* handle MSR changes */
2690 +/************************************************************************/
2692 + ////////////////////////////////////////////////////////////
2693 + // msr_exception_return (exception taken)
2695 + // r6, r7: nip / srr1
2697 + // modifies: r0,r2-r5 (r7 updated)
2700 +msr_exception_return:
2701 + addi r3,r1,K_UNMAPPED_SR_BASE // set unmapped context
2702 + li r7,(MSR_ME | MSR_SE | MSR_IR | MSR_DR | MSR_PR)
2703 + stw r3,K_CUR_SR_BASE(r1)
2704 + li r5,(fb_DbgTrace | fb_Trace)
2707 + bt+ FBIT_DbgTrace, 1f
2709 + rlwinm r7,r7,0,~MSR_SE
2711 + stw r3,K_SR_DATA(r1)
2712 + li r4,fb_LoadSegreg
2714 + stw r3,K_SR_INST(r1)
2715 + mtcrf TRACE_CR_FIELD,r5 // set singlestep bits [cr6]
2716 + mtcrf MMU_CR_FIELD,r4
2719 + b exception_return
2722 + ////////////////////////////////////////////////////////////
2725 + // r6, r7: nip / srr1
2730 + // Sets cr1.ne if we MSR_POW is set
2732 + // M: r2-r5 (r7 updated).
2733 + // r0 may _NOT_ be modified
2735 +#define MSR_CLEARBITS (MSR_FP | MSR_FE0 | MSR_FE1 | MSR_BE | MSR_SE)
2736 +#define MSR_COPYBITS (MSR_BE | MSR_SE)
2741 + bf+ FBIT_603_AltGPR,7f // 603 alternate GPR support
2742 + rlwinm. r5,r0,0,MSR_TGPR
2744 + lwz r2,xGPRSAVE0_603(r1) // MSR_TGPR cleared...
2745 + lwz r4,xGPRSAVE1_603(r1)
2746 + lwz r5,xGPRSAVE2_603(r1)
2748 + lwz r2,xGPRSAVE3_603(r1)
2752 + crclr FBIT_603_AltGPR
2755 + li r7,(MSR_ME | MSR_SE | MSR_IR | MSR_DR | MSR_PR)
2757 + xor r3,r3,r0 // r3 == MSR bit toggle
2758 + bt- FBIT_IRQPending,test_for_irq // M: r2
2760 + rlwinm r4,r0,0,MSR_POW // MSR_POW
2762 + andi. r3,r3,(MSR_DR|MSR_IR|MSR_PR) // MMU change (cr unused)?
2763 + bt- FBIT_DecINT,test_for_dec // M: r2
2765 + cmpwi cr1,r4,0 // MSR_POW set?
2766 + li r2,(fb_DbgTrace | fb_Trace)
2768 + bt- FBIT_DbgTrace,1f
2769 + rlwinm r2,r0,(21+32-FBIT_Trace),fb_Trace // MSR_SE[21] -> FBIT_Trace
2770 + rlwimi r7,r0,0,(MSR_SE|MSR_BE) // no debugger; copy MSR_SE and MSR_BE
2773 + mtcrf TRACE_CR_FIELD,r2 // set singlestep bits [cr6]
2775 + bne cr2,1f // bnelr is slower...
2779 + BUMP("MMU-change")
2781 + andi. r3,r0,(MSR_IR | MSR_DR) // IR DR part of index
2782 + addi r5,r1,K_MSR_SR_TABLE
2783 + addi r4,r3,MSR_DR // splitmode (MSR_DR != MSR_IR) testing
2784 + rlwimi r3,r0,32-8,25,25 // [PR IR DR] index to K_MSR_SR_TABLE
2785 + lwzux r3,r5,r3 // set sr bases from K_MSR_SR_TABLE
2786 + andi. r4,r4,MSR_IR // non-zero if in splitmode
2788 + li r4,(fb_InSplitmode | fb_LoadSegreg | fb_PrepareSplitmode)
2790 + stw r3,K_CUR_SR_BASE(r1) // new sr base in r3 (used below)
2791 + stw r2,K_SR_DATA(r1)
2793 + li r4,fb_LoadSegreg // cur_sr_base changed
2794 +1: stw r5,K_SR_INST(r1)
2795 + mtcrf MMU_CR_FIELD,r4
2799 + BUMP("test-for-irq")
2800 + and r2,r3,r0 // check whether we are turning external interrupts on
2801 + andi. r2,r2,MSR_EE // we need to recheck IRQs in userspace then
2803 + lwz r4,xHOSTIRQ_ACTIVE_CNT(r1)
2804 + cmpwi r4,0 // only return if some host irq is up
2806 + MAC_EXIT_SAVE(RVEC_CHECK_IRQS)
2808 +1: andi. r2,r0,MSR_EE
2813 + BUMP("test-for-dec")
2814 + andi. r2,r0,MSR_EE
2819 + BUMP("force-msr-altered")
2820 + lwz r0,xMSR(r1) // r0 = new MSR
2821 + xori r3,r0,(MSR_DR|MSR_IR) // r3 = faked old MSR
2822 + b msr_altered // might throw an exception...
2824 + // msr_altered( kv )
2825 +GLOBAL_SYMBOL(r__msr_altered):
2826 + lwz r5,xFLAG_BITS(r3)
2827 + ori r5,r5,fb_MsrModified
2828 + stw r5,xFLAG_BITS(r3)
2832 +/************************************************************************/
2833 +/* initialize special purpose register table */
2834 +/************************************************************************/
2836 +MACRO(SPR_HOOK, [spr, hook], [ LI_PHYS( R8, _hook ) ; stw r8,(((_spr)*4)+K_SPR_HOOKS)(r3) ])
2838 +// The LSB of a SPR hook specifies that the SPR is privileged (these bits are
2839 +// set from C-code).
2842 +GLOBAL_SYMBOL(r__initialize_spr_table):
2843 + LI_PHYS( R7, unhandled_spr )
2844 + addi r8,r3,K_SPR_HOOKS-4
2851 + SPR_HOOK TBWU, spr_read_write
2852 + SPR_HOOK TBWL, spr_read_write
2854 + // SPRs that have side effects
2855 + SPR_HOOK SDR1, spr_sdr1
2856 + SPR_HOOK DEC, spr_dec
2859 + mFORLOOP([nn],0,15,[
2860 + SPR_HOOK eval(nn+IBAT0U), spr_bat
2865 +/************************************************************************/
2866 +/* initialize msr segment register table */
2867 +/************************************************************************/
2869 + /////////////////////////////////////////////////////////////
2870 + // initialize_sr_offs_table
2872 + // Copy sr_offs_table to K_MSR_SR_TABLE
2873 + // r1 is added to each element
2875 +initialize_msr_sr_table:
2876 + mflr r8 // Get address of table
2881 + li r5,4*8 // #words in table
2884 + addi r4,r1,K_MSR_SR_TABLE-4
2887 + add r6,r6,r1 // And add r1
2892 + // Used to construct msr_sr_table (mbase is added)
2895 + /* K_CUR_SR_BASE, K_SR_DATA_BASE, K_SR_INST_BASE, dummy */
2897 + .long K_UNMAPPED_SR_BASE, K_UNMAPPED_SR_BASE, K_UNMAPPED_SR_BASE, 0
2898 + .long K_SPLIT_SR_BASE, K_SV_SR_BASE, K_UNMAPPED_SR_BASE, 0 /* DR */
2899 + .long K_SPLIT_SR_BASE, K_UNMAPPED_SR_BASE, K_SV_SR_BASE, 0 /* IR */
2900 + .long K_SV_SR_BASE, K_SV_SR_BASE, K_SV_SR_BASE, 0 /* DR|IR */
2902 + .long K_UNMAPPED_SR_BASE, K_UNMAPPED_SR_BASE, K_UNMAPPED_SR_BASE, 0 /* PR */
2903 + .long K_SPLIT_SR_BASE, K_USER_SR_BASE, K_UNMAPPED_SR_BASE, 0 /* PR|DR */
2904 + .long K_SPLIT_SR_BASE, K_UNMAPPED_SR_BASE, K_USER_SR_BASE, 0 /* PR|IR */
2905 + .long K_USER_SR_BASE, K_USER_SR_BASE, K_USER_SR_BASE, 0 /* PR|DR|IR */
2907 +++ b/drivers/macintosh/mol/asm-files/entry.S
2910 + * Creation Date: <2001/01/30 00:22:35 samuel>
2911 + * Time-stamp: <2004/03/07 13:33:39 samuel>
2915 + * Emulator/mac switching
2917 + * Copyright (C) 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
2919 + * This program is free software; you can redistribute it and/or
2920 + * modify it under the terms of the GNU General Public License
2921 + * as published by the Free Software Foundation
2925 +/* Short note about DEC. Due to the kernel implementation of the DEC
2926 + * exception handler (and get_time_of_day) in the 2.3/2.4 kernel, we
2927 + * must try to maintain coherency between DEC and TB. In any case,
2928 + * we must NEVER let DEC tick faster than TB, or get_time_of_day will
2929 + * occasionally return bogus values (the result is usually
2933 +/************************************************************************/
2935 +/************************************************************************/
2937 + //////////////////////////////////////////////////////////
2938 + // mac_entry_initialize
2940 + // Run once in order to store certain things (segment
2941 + // registers and NIP)
2943 + // sprg1 userspace stack
2944 + // r6 emulator return point after 'call_kernel'
2946 + // Safe to modify: r0-r12, lr, ctr
2948 +mac_entry_initialize:
2949 + __ZERO_TICK_CNT(entry)
2951 + // Save emulator return point (skip over illegal inst)
2954 + stw r5,K_EMULATOR_NIP(r1) // This sets the return point once and for all
2955 + stw r2,K_EMULATOR_TOC(r1) // r2==TOC (not on linux though)
2956 + stw r6,K_EMULATOR_KCALL_NIP(r1) // Return point after 'call_kernel'
2959 + stw r6,K_EMULATOR_MSR(r1) // we want to return through mac_exit
2960 + stw r3,K_EMULATOR_STACK(r1)
2962 + lwz r3,xFLAG_BITS(r1) // Best to initialize the flag bits
2965 + // msr to be used in mac-mode
2966 + LOADI r3,(MSR_ME | MSR_IR | MSR_DR | MSR_PR | MSR_EE)
2969 + PERF_MONITOR_SETUP /**/ r4
2971 + addi r3,r1,K_EMULATOR_SR // Save segment registers
2972 + SAVE_SEGMENT_REGS r3, /**/ r4,r5
2973 + SAVE_IBATS K_IBAT0U_SAVE, /**/ r3 // And save linux BAT registers
2974 + SAVE_DBATS K_DBAT0U_SAVE, /**/ r3
2976 + bl initialize_msr_sr_table
2978 + addi r3,r1,K_EMULATOR_SR
2979 + LOAD_SEGMENT_REGS r3, /**/ r4,r5
2985 + ////////////////////////////////////////////////////////////////////
2986 + // mac_entry [ENTRYPOINT]
2988 + // sprg1 userspace stack
2989 + // r4 MOL_ENTRY_R4_MAGIC
2991 + // r6 call_kernel return point (if initializing)
2992 + // r7 session number | initialize flag
2994 + // srr1 emulator msr
2995 + // r13-r31 mac gprs
2996 + // fr14-fr31 mac fp registers
2997 + // fr0-fr12 mac fp registers (see xFPU_STATE)
3000 + stw r4,ST_MAGIC(r1)
3001 +2: mtcr r3 // restore registers
3002 + CONTINUE_TRAP( 0x700 ) // not MOL, take the trap
3006 + lis_svh R1,SPECVAR_SESSION_TABLE
3007 + cmpwi r4,MOL_ENTRY_R4_MAGIC // MOL switch magic.
3008 + ori_svl R1,R1,SPECVAR_SESSION_TABLE
3010 + lwz r4,ST_MAGIC(r1) // check that the magic match
3011 + cmplwi r5,1 // and is greater than 1
3014 + addi r5,r1,ST_KVARS_PH // get kvars for this session
3015 + rlwinm r4,r7,2,((MAX_NUM_SESSIONS-1)*4)
3016 + bne- cr1,1b // r1 must point to session table
3017 + lwzx r1,r4,r5 // set r1 to kvars
3019 + cmplwi r7,MAX_NUM_SESSIONS
3020 + beq- cr1,2b // kvars == NULL
3021 + bge- mac_entry_initialize // initialize flag set
3023 + // =====================================================================
3025 + // =====================================================================
3027 + __ZERO_TICK_CNT(entry)
3028 + TRACE(0x1111, "mac_entry")
3030 + // Save emulator registers (r1,msr) and restore flag bits
3032 + lwz r4,xFLAG_BITS(r1)
3033 + stw r3,K_EMULATOR_STACK(r1)
3036 + stw r6,K_EMULATOR_MSR(r1) // The MSR_FP/MSR_VEC bits are of interest...
3038 + // Setup mac-environment
3040 + btl FBIT_RecalcDecInt, recalc_int_stamp // M: r0,r2-r5
3041 + bl set_mac_context // M: r0,r2-r12,XER
3042 + bl set_mol_dec // M: r0,r2-r5
3044 + crset FBIT_LoadSegreg // Load segment registers below
3046 + RESTORE_MIDDLE_REGS // Loads r6,r7 (nip/msr) r8-r12, ctr, xer,
3048 + rlwinm r7,r7,0,~MSR_VEC // We always clear MSR_VEC (MSR_FP should be off already)
3049 + stw r7,K_MSR(r1) // (enabling MSR_VEC is relatively cheap)
3050 + btl- FBIT_MsrModified,msr_altered_entry
3052 + GET_TICK_CNT(entry, "mac_entry")
3054 + bt- FBIT_DecINT,test_for_dec_int // check for DEC interrupts
3055 + b exception_return
3059 + rlwinm. r3,r3,0,MSR_EE // MSR_EE is set?
3060 + bne mac_dec_trap // if so take a DEC interrupt
3061 + b exception_return
3064 + crclr FBIT_MsrModified
3065 + b force_msr_altered
3068 + /////////////////////////////////////////////////////////////
3069 + // All paths back to mac-mode goes through one of these
3073 + // emulation_done_noinc
3074 + // exception_return
3078 + addi r6,r6,4 // increase NIP
3079 +emulation_done_noinc:
3080 + bt- FBIT_Trace, rvec_trace_trap
3081 + GET_TICK_CNT(entry,"emulation_done")
3083 + btl- FBIT_LoadSegreg,reload_sr // M: r3-r5, r6=nip
3084 + mtsrr1 r7 // setup SRR1
3090 + mfcr r2 // Save flag bits
3094 + stw r2,xFLAG_BITS(r1)
3099 + __GET_TICK_CNT(entry,"asm-all") // performance measurements
3105 +/************************************************************************/
3106 +/* Exit Mac-Mode Paths */
3107 +/************************************************************************/
3109 + // THESE ARE _ALL_ THE POSSIBLE EXIT PATHS. KEEP IT THAT WAY
3110 + // OR HAVE A *VERY GOOD* REASON TO INTRODUCE A NEW ONE.
3112 + /////////////////////////////////////////////////////////
3115 + // Save fpscr and fpr13 and clear the MSR_FP bit.
3116 + // Restore the emulator fpscr value.
3118 + // IMPORTANT: Call this function only if FBIT_FPUInUse is set
3120 + // modifies: r7,r8 (turns on MSR_FP if FP is set in K_MSR)
3123 + li r8,MSR_FP | MSR_FE0 | MSR_FE1
3125 + andc r8,r7,r8 // Clear MSR_FEx bits
3128 + mfmsr r7 // Temporary enable FPU in order to
3129 + ori r8,r7,MSR_FP // save fpscr and fpr13
3132 + stfd fr13,xFPR13(r1)
3134 + stfd fr13,xFPSCR-4(r1)
3135 + li r7,FPU_STATE_DIRTY
3136 + lfd fr13,xEMULATOR_FPSCR-4(r1) // We must restore FPSCR before since the emulator might
3137 + mtfsf 0xff,fr13 // use the FPU at any time, for instance in a signal handler.
3138 + stw r7,xFPU_STATE(r1) // Go to FPU_STATE_DIRTY
3140 + crclr FBIT_FPUInUse // FPU no longer in use
3144 + ////////////////////////////////////////////////////////
3147 + // M: r0,r2, r9-r11
3149 +MACRO(PREP_ERET,[nip_variable], [
3150 + btl FBIT_MolDecLoaded, set_kernel_dec // M: r0,r2,r9-r11
3152 + lwz r10,_nip_variable[](r1)
3154 + lwz r11,K_EMULATOR_MSR(r1)
3156 + lwz r2,K_EMULATOR_TOC(r1)
3157 + stw r9,xFLAG_BITS(r1)
3161 + ////////////////////////////////////////////////////////
3162 + // mac_exit (return to emulator)
3163 + // r3 RVEC return code
3165 + // On stack: nip, ctr, lr, xer, r0-r12
3166 + // In registers: r13-r31
3169 + TRACE(0x2220, "mac_exit")
3170 + bl set_emulator_context // M: r0,r2,r7-r11,XER
3172 + PREP_ERET K_EMULATOR_NIP // M: r0-r2,r9-r11
3173 + GET_TICK_CNT(entry, "mac_exit")
3174 + lwz r1,K_EMULATOR_STACK(r1)
3178 + ////////////////////////////////////////////////////////
3179 + // take_exception (take a linux exception)
3181 + // On stack: nip, ctr, lr, xer, r0-r12
3182 + // In registers: r13-r31
3185 + TRACE(0x2221, "take_exception")
3188 + bl set_emulator_context // M: r0,r2,r7-r11,XER
3190 + PREP_ERET K_EMULATOR_NIP // M: r0,r2,r9-r11
3191 + GET_TICK_CNT(entry, "take_exception")
3192 + lwz r1,K_EMULATOR_STACK(r1)
3198 + //////////////////////////////////////////////////////////////
3199 + // call_kernel (call mol kernel routine)
3200 + // r3 kernel routine
3203 + // On stack: nip, ctr, lr, xer, r0-r12
3204 + // In registers: r13-r31
3208 + bl save_middle_regs // saves r8-r11, nip, ctr, xer
3210 + bl set_emulator_context // M: r0,r2,r7-r11,XER
3212 + TRACE(0x2222, "call_kernel")
3214 + lwz r8,K_KERNEL_VARS(r1) // r8 = kvars (lvptr)
3215 + PREP_ERET K_EMULATOR_KCALL_NIP // M: r0,r2,r9-r11
3216 + GET_TICK_CNT(entry, "call_kernel_save")
3217 + lwz r1,K_EMULATOR_STACK(r1)
3218 + ba 0x2f00 // MOL trampoline
3221 +/************************************************************************/
3222 +/* Set Mac/Emulator Context */
3223 +/************************************************************************/
3225 + //////////////////////////////////////////////////////////////
3226 + // set_mac_context [r0,r2-r12, ctr, --->XER<---]
3228 + // - clear BATs (except DBAT0)
3230 + // - reload_sr loads segment registers later on
3232 + // Currently unmodified r8-r12, ctr
3235 + // Save and setup SPRG2 (magic) and SPRG3 (mol stack)
3238 + stw r6,K_EMULATOR_SPRG2(r1)
3239 + stw r7,K_EMULATOR_SPRG3(r1)
3240 + li r2,MOL_SPRG2_MAGIC
3249 + // DBAT0 set from reload_sr
3254 + lwz r4,K_MOL_SDR1(r1)
3260 + ///////////////////////////////////////////////////////////////
3261 + // set_emulator_context [r0,r2,r7-r11,cr, --->XER<---]
3263 + // - load segr 0-15 with emulator context
3265 + // - restore DEC register
3267 +set_emulator_context:
3268 + lwz r0,K_EMULATOR_SPRG2(r1)
3269 + lwz r2,K_EMULATOR_SPRG3(r1)
3273 + // Restore segment registers
3274 + addi r8,r1,K_EMULATOR_SR
3275 + LOAD_SEGMENT_REGS r8, /**/ r2,r10
3277 + // BATS, r11 = linux DEC
3279 + lwz r7,K_IBAT0U_SAVE(r1)
3281 + lwz r2,K_IBAT1U_SAVE(r1)
3283 + lwz r7,K_IBAT2U_SAVE(r1)
3285 + lwz r2,K_IBAT3U_SAVE(r1)
3288 + lwz r7,K_DBAT0U_SAVE(r1)
3290 + lwz r7,K_DBAT0L_SAVE(r1) // must also restore lower bat...
3292 + lwz r2,K_DBAT1U_SAVE(r1)
3294 + lwz r7,K_DBAT2U_SAVE(r1)
3296 + lwz r2,K_DBAT3U_SAVE(r1)
3299 + lwz r2,K_OS_SDR1(r1)
3301 + fix_sprg2 /**/ R2 // must not modify sprg2 (i.e. sprg_a0) under OSX 10.3
3306 +/************************************************************************/
3307 +/* Reload Segment Registers */
3308 +/************************************************************************/
3310 + //////////////////////////////////////////////////////////////
3315 + // - loads segr 0-15 with mac context [modifies r3-r5]
3316 + // - reloads DBAT0 (used for splitmode)
3318 + // Modifies: r3-r5
3321 + bt FBIT_InSplitmode,prepare_splitmode // M: r0,r3-r5, r6=mac-nip
3323 + lwz r3,K_TRANSL_DBAT0L(r1)
3324 + lwz r4,K_TRANSL_DBAT0U(r1)
3327 + mtcrf MMU_CR_FIELD,r5 // clear FBIT_LoadSegreg (and splitmode stuff)
3330 + lwz r4,K_CUR_SR_BASE(r1)
3331 + LOAD_SEGMENT_REGS r4, /**/ r3,r5
3334 +ret_from_prep_splitmode:
3335 + lwz r3,K_SPLIT_DBAT0L(r1)
3336 + lwz r4,K_SPLIT_DBAT0U(r1)
3337 + li r5,fb_InSplitmode
3339 + mtcrf MMU_CR_FIELD,r5 // clear FBIT_LoadSegreg and FBIT_PrepareSplitmode
3343 +++ b/drivers/macintosh/mol/asm-files/iopage.S
3346 + * Creation Date: <97/07/26 18:23:02 samuel>
3347 + * Time-stamp: <2002/07/06 12:12:10 samuel>
3351 + * IO low-level support
3353 + * Copyright (C) 2002 Samuel Rydh (samuel@ibrium.se)
3355 + * This program is free software; you can redistribute it and/or
3356 + * modify it under the terms of the GNU General Public License
3357 + * as published by the Free Software Foundation
3361 + // NOTE: This function is also called from the splitmode secondary interrupt
3362 + // handler (splitmode segment registers are resetup at return).
3365 + ///////////////////////////////////////////////////////////////////
3368 + // xINST_OPCODE is always valid at this point
3370 + // Examine if the page (which DAR points to) is an I/O page.
3371 + // Safe to modify: r0,r2-r12
3374 + // Is this is an IO-page? IMPORTANT: we must *never* insert mappings
3375 + // that are unreadable by supervisor (will cause a freeze right here).
3377 + mfdsisr r10 // r10 = DSISR
3378 + rlwinm. r3,r10,0,1,1 // BIT 1 set if no PTE (or BAT mapping)
3383 + ori r3,r7,MSR_DR // set MSR_DR
3387 + rlwinm r5,r8,0,0,19 // mask page index
3389 + // XXX: TO BE FIXED. These instruction will _never_ cause an exceptions on a
3390 + // single processor system. However, on a SMP machine we *could* receive a
3391 + // tlbie invalidate broadcast. Thus we must implement a secondary
3392 + // interrupt handler to cover that case.
3394 + lwz r2,IOP_MAGIC(r5)
3395 + lwz r3,IOP_MAGIC2(r5) // These should _never_ cause any exceptions
3396 + lwz r9,IOP_ME_PHYS(r5) // r9 = physical addr of iopage
3398 + mtmsr r7 // restore MSR
3401 + lis r6,HI(IO_PAGE_MAGIC_1) // check MAGIC 1
3402 + ori r6,r6,LO(IO_PAGE_MAGIC_1)
3406 + lis r7,HI(IO_PAGE_MAGIC_2) // check MAGIC 2
3407 + ori r7,r7,LO(IO_PAGE_MAGIC_2)
3411 + // Obtain translation info from the iopage:
3413 + // r4 = mphys_ioaddr = iop->mphys | (dar & 0xfff);
3414 + // r5 = usr_data = iop->usr_data[ (dar & 0xfff) >> 3 ];
3416 + lwz r4,IOP_MPHYS(r9)
3417 + rlwimi r4,r8,0,20,31 // insert page offset
3419 + rlwinm r7,r8,32-1,21,29 // grain = double word
3420 + addi r7,r7,IOP_USR_DATA // usr_data[ (dar&0xfff) ]
3421 + lwzx r5,r9,r7 // r5 = usr_data
3423 + rlwinm. r2,r10,0,6,6 // was it a write? (r10=DSISR)
3426 + // r4 = mphys_ioaddr
3428 + MAC_EXIT( RVEC_IO_READ )
3431 + // r4 = mphys_ioaddr
3433 + MAC_EXIT( RVEC_IO_WRITE )
3435 +++ b/drivers/macintosh/mol/asm-files/linux.S
3438 + * Creation Date: <2001/02/24 14:08:28 samuel>
3439 + * Time-stamp: <2003/09/03 12:34:20 samuel>
3443 + * Linux Kernel Hooks
3445 + * Copyright (C) 2001, 2002, 2003 Samuel Rydh (samuel@ibrium.se)
3447 + * This program is free software; you can redistribute it and/or
3448 + * modify it under the terms of the GNU General Public License
3449 + * as published by the Free Software Foundation
3453 + ////////////////////////////////////////////////////////
3454 + // flush_hash_page_hook
3459 + // r4: virtual address
3460 + // r5: 2.4.6 pointer to linux PTE (2.4.6 or later)
3463 + // r10: return address
3465 + // [must not modify: r3-r5,r10 - otherwise normal C-function]
3468 +.set STACK_SPACE, 32
3469 +.set STACK_LR, STACK_SPACE+4
3477 +FHOOK( FHOOK_FLUSH_HASH_PAGE )
3478 +GLOBAL_SYMBOL( r__flush_hash_page_hook ):
3479 + stwu r1,-STACK_SPACE(r1) // Push stackframe
3481 + stw r0,STACK_LR(r1)
3483 + LOADI r7,EXTERN(do_flush)
3486 + stw r10,STACK_V1(r1) // Save registers
3487 + stw r3,STACK_V2(r1)
3488 + stw r4,STACK_V3(r1)
3489 + stw r5,STACK_V4(r1)
3491 + stw r6,STACK_V5(r1)
3497 + lwz r10,STACK_V1(r1) // Restore registers
3498 + lwz r3,STACK_V2(r1)
3499 + lwz r4,STACK_V3(r1)
3500 + lwz r5,STACK_V4(r1)
3502 + lwz r6,STACK_V5(r1)
3505 + lwz r0,STACK_LR(r1) // Pop stackframe
3506 + addi r1,r1,STACK_SPACE
3511 +/************************************************************************/
3512 +/* lowmem reallocations */
3513 +/************************************************************************/
3517 + /* r3=ea, r4=pte_slot, r5=pte1, r6=pte2, r7=lock, r8=lockval, M: r0 */
3518 +RELOC_LOW(xx_store_pte_lowmem)
3522 + stwcx. r8,0,r7 // take hash lock
3524 + // isync // sync below is sufficient
3525 + stw r0,0(r4) // clear old PTE[V] (if we evict something)
3526 + sync // probably not needed - no other CPU uses this PTE
3527 + stw r6,4(r4) // store PTE2
3529 + stw r5,0(r4) // store PTE1
3530 + tlbie r3 // flush old pte
3531 + eieio // order tlbie before tlbsync
3532 + tlbsync // ensure tlbie finish on all processors
3533 + sync // ensure tlbsync completed
3534 + stw r0,0(r7) // release hash lock
3536 +RELOC_LOW_END(xx_store_pte_lowmem)
3539 + /* r3=ea, r7=lock, r8=lockval, M: r0 */
3540 +RELOC_LOW(xx_tlbie_lowmem)
3544 + stwcx. r8,0,r7 // take hash lock
3546 + //isync // needed if we get rid of the sync
3547 + sync // make sure any PTE zero-outs have finished
3548 + tlbie r3 // flush old pte
3549 + eieio // order tlbie before tlbsync
3550 + tlbsync // ensure tlbie finish on all processors
3551 + sync // ensure tlbsync completed
3552 + stw r0,0(r7) // release hash lock
3554 +RELOC_LOW_END(xx_tlbie_lowmem)
3558 + /* r3=pte_slot, r4=pte0, r5=pte1 */
3559 +RELOC_LOW(xx_store_pte_lowmem)
3560 + stw r4,0(r3) // interrupts are off and we won't take a page fault
3561 + stw r5,4(r3) // so this is safe...
3563 +RELOC_LOW_END(xx_store_pte_lowmem)
3567 +++ b/drivers/macintosh/mol/asm-files/ptintercept.S
3570 + * Creation Date: <2001/03/17 18:00:05 samuel>
3571 + * Time-stamp: <2003/05/26 00:08:48 samuel>
3575 + * Handles writes to the (mac) hash table
3577 + * Copyright (C) 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
3579 + * This program is free software; you can redistribute it and/or
3580 + * modify it under the terms of the GNU General Public License
3581 + * as published by the Free Software Foundation
3585 +//////////////////////////////////////////////////////////////////////
3586 +// Implementing the tlbie instruction properly is tricky.
3587 +// The tlbie is supposed to invalidate an equivalence
3588 +// class of PTEs and this does not map well to the huge TLB
3589 +// MOL uses (the linux PTE hash, a lot bigger than the 2x64
3590 +// table found in most CPUs).
3592 +// The solution is intercepting PTE writes and maintain
3593 +// coherence without relying on the tlbie instruction (which
3594 +// can safely be replaced by a nop).
3596 +// Splitmode: The instruction sr might be active. DBAT0 does
3597 +// _not_ have the supervisor valid bit set so we have to load
3598 +// the data segment register.
3599 +//////////////////////////////////////////////////////////////////////
3601 +MACRO(SET_MSR_DR, [scr], [
3606 +MACRO(CLEAR_MSR_DR, [scr], [
3612 + // r3 = exception vector
3614 + bf+ FBIT_InSplitmode,1f
3616 + lwz r4,K_TMP_SCRATCH0(r1) // in splitmode (might be
3617 + mtsrin r4,r2 // the instrucion sr)
3619 + lwz r6,xNIP(r1) // restore NIP & MSR
3623 + cmpwi r3,0x600 // Alignment
3625 + DEBUGGER_SAVE( 0x6909 )
3626 +1: bl save_middle_regs
3628 +2: bl save_middle_regs
3631 + ////////////////////////////////////////////////////////////////////////
3632 + // check_pthash_hit
3634 + // m: r0,r2-r5, cr
3638 + rlwinm. r4,r3,0,4,4 // Is this a protection violation?
3640 + rlwinm. r4,r3,0,6,6 // and a write?
3643 + mfdar r2 // Is this a pthash hit?
3644 + lwz r3,K_TLBHASH_BASE_EA(r1) // First check EA...
3645 + lwz r4,K_HASH_MASK(r1)
3650 + lwz r5,K_SR_DATA(r1) // Correct context for EA?
3651 + rlwinm r3,r2,4+2,26,29 // #sr << 2
3652 + lwz r4,K_TLBHASH_SR(r1)
3657 + /////////////////////////////////////////////////
3658 + // Handle page table write, r2=dar, r4=segreg
3659 + /////////////////////////////////////////////////
3661 + bf+ FBIT_InSplitmode,1f
3662 + mfsrin r3,r2 // save old segment register
3663 + stw r3,K_TMP_SCRATCH0(r1) // in splitmode (might be
3664 + mtsrin r4,r2 // the instrucion sr)
3666 + lwz r3,xINST_OPCODE(r1)
3667 + LI_PHYS( R4,secint_pt_store ) // r4 = secondary exception handler
3670 + // r2 = dar, r3 = opcode
3671 + rlwinm r0,r3,6,0x3e // primary opcode & ~1
3672 + rlwinm r5,r3,6+5+3,(0x1f<<3) // r5 = rS << 3
3673 + cmpwi r0,30 // 31 & ~1
3675 + mtcrf 0x40,r3 // cr[5] = update bit
3676 + cmpwi r0,36 // 36, stw/stwu
3678 + cmpwi r0,38 // 38, stb/stbu
3680 + cmpwi r0,44 // 44, stb/stbu
3682 + cmpwi r0,52 // 52, stfs/stsu
3684 + cmpwi r0,54 // 54, stfd/stfdu
3686 + cmpwi r0,46 // 47, stmw
3688 + b do_st_bad // ???
3691 + rlwinm r0,r3,32-1,22,31 // secondary opcode
3692 + rlwinm. r6,r3,0,(32<<1) // update form?
3693 + rlwinm r0,r0,0,~32 // clear update bit
3696 + cmpwi r0,151 // stwx/stwxu
3698 + cmpwi r0,215 // stbx / stbxu
3700 + cmpwi r0,150 // stwcx.
3702 + cmpwi r0,407 // sthx / sthxu
3704 + cmpwi r0,727 // stfdx / stfdxu
3706 + cmpwi r0,663 // stfsx / stfsxu
3709 + rlwinm r0,r3,32-1,22,31 // unmasked secondary opcode
3710 + cmpwi r0,470 // dcbi
3712 + cmpwi r0,1014 // dcbz
3714 + cmpwi r0,983 // stfiwx [optional]
3716 + cmpwi r0,725 // stswi
3720 + b do_st_bad // float, cache or altivec
3729 + DEBUGGER_SAVE(0x1882) // unimplemented store instruction
3731 + // r2=dar, r3=opcode, r4=secint_handler, r5=rS_offs
3735 + SET_MSR_DR /**/ r6
3736 + rlwinm r6,r2,0,~0x7
3740 + CLEAR_MSR_DR /**/ r0
3743 + EMU_LOAD_GPR r5, /**/ R6 // r0 = value
3745 + SET_MSR_DR /**/ r6
3746 + rlwinm r6,r2,0,~0x7
3750 + CLEAR_MSR_DR /**/ r0
3753 + rlwimi r6,r0,0,0,3
3757 + EMU_LOAD_GPR r5, /**/ R6 // r0 = value
3759 + SET_MSR_DR /**/ r6
3760 + rlwinm r6,r2,0,~0x7
3766 + EMU_LOAD_GPR r5, /**/ R6 // r0 = value
3768 + SET_MSR_DR /**/ r6
3769 + rlwinm r6,r2,0,~0x7
3775 + EMU_LOAD_GPR r5, /**/ R6 // r0 = value
3777 + SET_MSR_DR /**/ r6
3778 + rlwinm r6,r2,0,~0x7
3784 + // r4=PTE0, r5=PTE1, r3=opcode, r2=dar, scratch: r0
3786 + CLEAR_MSR_DR /**/ r0
3787 + bf+ 5,st_continue_2 // update form?
3788 + rlwinm r3,r3,6+5+5+3,(31<<3)
3790 + EMU_STORE_GPR r3, /**/ R6 // r0 = value
3792 + // check if the old PTE has been used (r2=dar,r4/r5=PTE)
3793 + lwz r3,K_TLBHASH_BASE_EA(r1) // Calculate tlb offset
3794 + sub r0,r2,r3 // r0 = pte_nr * 8
3795 + lwz r6,K_PTHASH_INUSE_PH(r1)
3796 + rlwinm r3,r0,32-6,6,29 // r3 = word offset
3800 + rlwinm r6,r2,32-3,27,31 // pte_nr & 0x1f
3802 + slw r6,r0,r6 // r6 = bit
3804 + GET_TICK_CNT(entry,"ptintercept-1")
3807 + BUMP("pt_intercept_not_taken")
3808 + // return from exception [r2=dar]
3809 + lwz r6,xNIP(r1) // restore r6
3810 + bf+ FBIT_InSplitmode,emulation_done
3811 + lwz r3,K_TMP_SCRATCH0(r1) // in splitmode (might be
3812 + mtsrin r3,r2 // the instrucion sr)
3815 + // transfer to C-function [r2=dar, r3/r4=pte]
3817 + BUMP("pt_intercept_taken")
3818 + lwz r6,xNIP(r1) // restore r6
3819 + lwz r3,K_TLBHASH_BASE_EA(r1) // calculate tlb offset
3820 + addi r6,r6,4 // inc NIP
3821 + bl save_middle_regs
3823 + rlwinm r6,r6,0,0,28 // argument pteoffs (dword aligned)
3825 + // r4=PTE0, r5=PTE1
3826 + LOADI r3,EXTERN(do_intercept_tlbie)
3829 + // stmw uses another emulator entry point because it might overwrite a bunch of PTEs
3833 + // save some debugging info
3834 +// stw r2,xDBG_TRACE_SPACE(r1)
3836 + SET_MSR_DR /**/ r6
3838 + // now do the stmw. we do that manually since we have to access emulator regs.
3839 + mr r4,r2 // r4: memory pointer
3840 + srwi r6,r5,3 // r6: rS
3841 +1: cmpwi r5,32 << 3 // loop condition
3843 + EMU_LOAD_GPR r5, /**/ R3 // r0 = value
3844 + stw r0,0(r4) // store the value
3845 + addi r5,r5,1 << 3 // update register counter
3846 + addi r4,r4,4 // and memory pointer
3849 +2: CLEAR_MSR_DR /**/ r0
3851 + // load up r4 and r5 for do_intercept_tlbie_block (see below)
3852 + subfic r5,r6,32 // number of registers (=words) stored
3853 + slwi r5,r5,2 // number of bytes stored
3854 + add r4,r2,r5 // last byte stored
3855 + addi r4,r4,7 // alignment to
3856 + rlwinm r5,r4,0,~0x7 // PTE size
3857 + rlwinm r4,r2,0,~0x7 // pte block pointer
3858 + sub r5,r5,r4 // substract block pointer -> length (in bytes)
3859 + lwz r3,K_TLBHASH_BASE_EA(r1) // calculate tlb offset
3860 + sub r4,r4,r3 // tlb offset
3861 + b st_block_continue
3863 + // transfer to C-function [r2=dar, r4=pte block offset, r5=pte block length]
3865 + BUMP("pt_intercept_taken")
3867 + addi r6,r6,4 // inc NIP
3868 + bl save_middle_regs
3870 + LOADI r3,EXTERN(do_intercept_tlbie_block)
3873 +++ b/drivers/macintosh/mol/asm-files/splitmode.S
3876 + * Creation Date: <2000/07/11 03:38:32 samuel>
3877 + * Time-stamp: <2003/08/20 16:37:04 samuel>
3881 + * Handles splitmode (MSR_IR != MSR_DR)
3883 + * Copyright (C) 2000, 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
3885 + * This program is free software; you can redistribute it and/or
3886 + * modify it under the terms of the GNU General Public License
3887 + * as published by the Free Software Foundation
3891 +MACRO(SM_SET_MSR_DR, [scr], [
3896 +MACRO(SM_CLEAR_MSR_DR, [scr], [
3901 +MACRO(SPLITMODE_SMP_LOCK, [scr1,scr2], [
3903 + LI_PHYS( _scr1,splitmode_lock )
3904 +7: lwarx _scr2,0,_scr1
3908 + stwcx. _scr2,0,_scr1
3913 +MACRO(SPLITMODE_SMP_UNLOCK, [scr1,scr2], [
3915 + LI_PHYS( _scr1,splitmode_lock )
3917 + stw _scr2,0(_scr1)
3921 + /////////////////////////////////////////////////////////////
3922 + // prepare_splitmode
3924 + // r6,r7: nip/srr1
3928 + // Fill in splitmode segment register table. The segment register
3929 + // containing xNIP is set up for instruction access (if xNIP does
3930 + // not hold nip, an extra ISI exception will occur). The instruction
3931 + // segment is protected from data access through the use of a DBAT
3934 + // It MUST be safe to call this function even if we are *not* in
3938 + bf FBIT_PrepareSplitmode, ret_from_prep_splitmode
3940 + ZERO_TICK_CNT(splitmode_prep)
3942 + // fill split mode table with data segment registers
3943 + lwz r3,K_SR_DATA(r1) // physical addr
3944 + addi r4,r1,K_SPLIT_SR_BASE-4
3946 + mfctr r0 // save ctr in r0
3950 + oris r5,r5,0x1000 // no-execute segment bit
3953 + mtctr r0 // restore ctr
3955 + // insert instruction mode segment
3956 + rlwinm r3,r6,0,0,3
3957 + stw r3,K_SPLIT_NIP_SEGMENT(r1)
3958 + rlwinm r3,r6,4+2,26,29 // r3 = offset, ((sr & 0xf000000) >> 28 ) * 4
3959 + lwz r5,K_SR_INST(r1)
3960 + lwzx r5,r3,r5 // segment register for instructions
3961 + addi r4,r1,K_SPLIT_SR_BASE
3964 + // and protect it with DBAT0.
3966 + // The supervisor valid bit must be cleared
3967 + // - we don't want to block get_opcode.
3969 + rlwinm r3,r6,0,0,3 // segment base
3970 + ori r3,r3,0x1ffd // user valid bit | 256MB mask
3971 + stw r3,K_SPLIT_DBAT0U(r1)
3973 + stw r4,K_SPLIT_DBAT0L(r1) // pp=0, wimg=0
3974 + GET_TICK_CNT(splitmode_prep, "splitmode_prep")
3975 + b ret_from_prep_splitmode
3978 + ///////////////////////////////////////////////////////////////////
3979 + // split_sr_no_execute
3981 + // r6,r7: nip/srr1
3983 + // An instruction is to be fetched from one of the no-execute
3984 + // segments. This function reinitializes the segment registers.
3988 +split_sr_no_execute:
3989 + rlwinm. r0,r7,0,3,3 // Guarded access or no-execute?
3992 + rlwinm r3,r6,0,0,3 // segment
3993 + lwz r4,K_SPLIT_NIP_SEGMENT(r1)
3995 + beqlr // guarded PTE/mac-guarded segment
3997 + crset FBIT_PrepareSplitmode
3998 + crset FBIT_LoadSegreg
3999 + b exception_return
4003 + //////////////////////////////////////////////////////////////////
4006 + // r6/r7: nip/srr1
4008 + // An DSI exception occured (DBAT protection violation).
4009 + // That is, a load/store instruction targeted the segment
4010 + // instructions was fetched from.
4012 + // Safe to modify: r0,r2-r5, (lr)
4015 + mfdsisr r3 // DBAT/page protection violation?
4016 + rlwinm. r0,r3,0,4,4
4017 + beqlr- // If not, it does not concern us
4019 + mfdar r2 // Normal page protected exception?
4020 + lwz r4,K_SPLIT_NIP_SEGMENT(r1) // the instruction segment?
4021 + rlwinm r5,r2,0,0,3 // data segment
4023 + bnelr // exit - not in the instruction segment
4025 + // splitmode write, r2=dar
4026 + mfsrin r0,r2 // r0 = old segment register
4027 + stw r6,xNIP(r1) // need one additional reg
4028 + rlwinm r4,r2,4+2,26,29 // sr_offset = sr_num * 4
4029 + lwz r5,K_SR_DATA(r1)
4031 + stw r0,K_TMP_SCRATCH0(r1) // save old segment register
4032 + oris r4,r4,0x4000 // set supervisor key bit (Ks)
4035 + rlwinm. r3,r3,0,6,6 // cr[eq] set if this a read
4036 + lwz r3,xINST_OPCODE(r1)
4037 + LI_PHYS( R4, secint_splitm ) // r4 = secint handler
4039 + // handle simple stores r2=seg#, r3=opcode, r4=secint
4042 + rlwinm r5,r3,6+5+3,(0x1f<<3) // r5 = rS << 3
4043 + EMU_LOAD_GPR r5, /**/ R6 // r0 = value
4044 + mtlr r4 // secint handler
4045 + SM_SET_MSR_DR /**/ r5
4047 + rlwinm r6,r3,6,0x3e // primary opcode & ~1
4048 + mtcrf 0x40,r3 // cr[5] = update bit (if opcode != 31)
4049 + cmpwi r6,30 // 31 & ~1
4050 + beq- splitm_store_op31
4051 + cmpwi r6,36 // 36, stw/stwu
4053 + cmpwi r6,38 // 38, stb/stbu
4055 + cmpwi r6,44 // 44, stb/stbu
4059 + rlwinm. r6,r3,0,(32<<1) // update form?
4060 + rlwinm r6,r3,32-1,22,31 // secondary opcode
4061 + rlwinm r6,r6,0,~32 // clear update bit
4063 + cmpwi r6,151 // stwx/stwxu
4065 + cmpwi r6,215 // stbx / stbxu
4067 + cmpwi r6,407 // sthx / sthxu
4069 + rlwinm r6,r3,32-1,22,31 // secondary opcode
4070 + cmpwi r6,150 // stwcx.
4072 + cmpwi r6,1014 // 1014, dcbz
4074 + cmpwi r6,662 // 662, stwbrx
4075 + beq- splitm_stwbrx
4079 + mtlr r4 // secint handler
4080 + SM_SET_MSR_DR /**/ r5
4081 + rlwinm r6,r3,6,0x3e // primary opcode & ~1
4082 + mtcrf 0x40,r3 // cr[5] = update bit (if opcode != 31)
4083 + cmpwi r6,30 // 31 & ~1
4084 + beq- splitm_load_op31
4085 + cmpwi r6,32 // 32, lwz/lwzu
4087 + cmpwi r6,34 // 34, lbz/lbzu
4089 + cmpwi r6,40 // 40, lhz/lhzu
4093 + rlwinm. r6,r3,0,(32<<1) // update form?
4094 + rlwinm r6,r3,32-1,22,31 // secondary opcode
4095 + rlwinm r6,r6,0,~32 // clear update bit
4097 + cmpwi r6,23 // 23, lwzx/lwzux
4099 + cmpwi r6,87 // 87, lbzx/lbzux
4101 + cmpwi r6,279 // 279, lhzx/lhzux
4103 + rlwinm r6,r3,32-1,22,31 // secondary opcode
4105 + cmpwi r6,20 // 20, lwarx
4107 + cmpwi r6,86 // 86, dcbf
4109 + cmpwi r6,982 // 982, icbi
4111 + cmpwi r6,534 // 534, lwbrx
4116 + // r0=value, r2=ea, r3=opcode
4119 + SM_CLEAR_MSR_DR /**/ r0
4122 + rlwimi r6,r0,0,0,3
4127 + b splitm_store_continue
4130 + b splitm_store_continue
4133 + b splitm_store_continue
4136 + b splitm_load_continue
4139 + b splitm_load_continue
4142 + b splitm_load_continue
4145 + b splitm_load_continue
4148 + b splitm_load_continue
4162 +splitm_load_continue:
4163 + SM_CLEAR_MSR_DR /**/ r4
4164 + BUMP("splitm_load")
4165 + rlwinm r4,r3,6+5+3,(0x1f<<3) // r5 = rS << 3
4166 + EMU_STORE_GPR r4, /**/ R6 // r0 = value
4167 + bf+ 5,splitm_done2 // update form?
4170 +splitm_store_continue:
4171 + SM_CLEAR_MSR_DR /**/ r0
4172 + BUMP("splitm_store")
4173 + bf+ 5,splitm_done2 // update form?
4174 +1: rlwinm r3,r3,6+5+5+3,(31<<3)
4176 + EMU_STORE_GPR r3, /**/ R6 // r0 = value
4179 + SM_CLEAR_MSR_DR /**/ r0
4181 + lwz r3,K_TMP_SCRATCH0(r1)
4182 + lwz r6,xNIP(r1) // restore NIP
4187 + // fallback, store and execute the instruction, r3=opcode
4189 + SM_CLEAR_MSR_DR /**/ r0
4191 + stw r3,xDEBUG1(r1)
4192 + stw r6,xDEBUG0(r1)
4194 + DEBUGGER_SAVE(0x1111)
4196 + SPLITMODE_SMP_LOCK /**/ r0,r2
4198 + BUMP("splitm_fallback")
4199 + bl secint_splitm_fallback // set secondary exception handler
4201 + LI_PHYS( R2,split_store_patch ) // r2 = addr of split_store_patch
4202 + stw r3,0(r2) // store instruction
4206 + sync // 74xx needs this
4208 + mtsrr0 r2 // The simplest thing is to do an RFI
4209 + LOADI r3,(MSR_EE | MSR_PR | MSR_IR | MSR_SE | MSR_BE)
4210 + andc r4,r7,r3 // Clear msr bits (r7=srr1)
4214 + xGPR_LOAD_RANGE R2,R5,r1 // Restore registers (except r1)
4222 + mtsprg_a0 r1 // restore MSR
4226 + mfsprg_a3 r1 // and stack pointer
4228 + xGPR_SAVE_RANGE R2,R7,r1
4229 + SPLITMODE_SMP_UNLOCK /**/ r3,r4
4231 + mfsprg_a0 r2 // r1 - to be saved
4232 + lwz r6,xNIP(r1) // restore r6,r7 and segment register
4236 + lwz r2,K_TMP_SCRATCH0(r1)
4239 + GET_TICK_CNT( entry, "splitmode_dsi" )
4243 + //////////////////////////////////////////////////////////////////////
4244 + // secint_splitm / secint_splitm_fallback
4245 + // r1: stack (sprg1 = old r1)
4246 + // r3: vector index (sprg0 = old r3)
4247 + // srr0/srr1: kernel nip/msr
4249 + // xGPR(0-5) are valid (unless this is a trace exception)
4251 +secint_splitm_fallback:
4253 + SPLITMODE_SMP_UNLOCK /**/ R2,R4
4256 + lwz r6,xNIP(r1) // Restore nip/msr
4259 + cmpwi r3,0x300 // ** DSI **
4261 + mfsrin r2,r6 // r6 = NIP
4262 + rlwinm r2,r2,0,2,0 // Clear Ks [bit1] (supervisor key bit)
4264 + bl save_middle_regs // Note: If dsi_cont ever returns immediately,
4265 + bl check_io_page // we will need to fix the segment registers before
4266 + b dsi_cont // the last dsi_cont branch.
4268 +1: lwz r2,K_TMP_SCRATCH0(r1) // We might return immediately...
4271 + cmpwi r3,0x600 // ** Alignment **
4273 + bl save_middle_regs
4276 +2: cmpwi r3,0x800 // ** FPU Unavailable **
4278 + cmpwi r3,0xf20 // ** AltiVec Unavailable **
4281 + DEBUGGER_SAVE( 0x5918 ) // ERROR...
4284 + ////////////////////////////////////////////////////////////////////////
4285 + // invalidate_splitmode( kernel_vars_t *kv )
4287 + // This function must be called whenever the segment registers are
4288 + // modified. A flag is set which will force a refresh of the slitmode
4289 + // segment registers (at mac context switch in). We could rewrite this
4290 + // in C but it might be better to keep things centralized.
4292 +GLOBAL_SYMBOL(r__invalidate_splitmode_sr):
4293 + // this will have no effect if fb_InSplitmode is not set
4294 + lwz r4,xFLAG_BITS(r3)
4295 + ori r4,r4,fb_PrepareSplitmode | fb_LoadSegreg
4296 + stw r4,xFLAG_BITS(r3)
4304 +++ b/drivers/macintosh/mol/asm-files/traps.S
4307 + * Creation Date: <2001/01/27 16:25:14 samuel>
4308 + * Time-stamp: <2004/03/07 21:58:48 samuel>
4312 + * Exception Vectors
4314 + * Copyright (C) 2000, 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
4316 + * This program is free software; you can redistribute it and/or
4317 + * modify it under the terms of the GNU General Public License
4318 + * as published by the Free Software Foundation
4322 +#define DBG_TRACE 0 // enable TRACE macro?
4324 +#include "archinclude.h"
4325 +#include "processor.h" /* avoid <asm/processor.h> (bogus SPRN_TBWU/L) */
4326 +#include "asm_offsets.h"
4327 +#include "asmdefs.h"
4328 +#include "molasm.h"
4329 +#include "asmdbg.h"
4330 +#include "actions.h"
4331 +#include "vector.h"
4333 +#include "constants.h"
4334 +#include "mac_registers.h"
4337 +#include "kernel_vars.h"
4340 +/************************************************************************/
4341 +/* Exception Vector Definitions */
4342 +/************************************************************************/
4345 +GLOBAL_SYMBOL(r__actions_section):
4346 + ACTIONS_OFFS_SECTION
4347 +GLOBAL_SYMBOL(r__actions_offs_section):
4350 +GLOBAL_SYMBOL(r__reloctable_start):
4352 +MACRO_0(EXCEPTION_PREAMBLE, [
4353 + // SPRG1 = r1, SPRG0 = r3, r3=CR, r1=MOL_STACK
4354 + __ZERO_TICK_CNT(entry)
4355 + stw r4,xGPR4(r1) // store instruction are store serializing
4356 + lwz r4,xFLAG_BITS(r1)
4357 + stw r5,xGPR5(r1) // and mix very badly with execution serializing
4358 + stw r6,xGPR6(r1) // instructions (like mfspr)
4367 + mfsprg_a1 r5 // SPRG1 = r1
4369 + mfsprg_a0 r3 // SPRG0 = r3
4373 + // saved: r0-r7, cr, lr
4374 + // r1 = stack, cr5-7=flag_bits, r6/r7 = nip/msr
4378 +save_middle_regs: // save r8-r12 and nip (r13-r31 should always be in regs)
4384 + stw r10,xGPR10(r1)
4385 + stw r11,xGPR11(r1)
4386 + stw r12,xGPR12(r1)
4389 + bt- FBIT_FPUInUse,giveup_fpu // modifies r7/r8
4392 +MACRO_0(RESTORE_MIDDLE_REGS, [ // reverse save_middle_regs, restores registers
4393 + lwz r11,xCTR(r1) // r8-r12, ctr, xer, r6/r7 = nip/msr
4398 + lwz r10,xGPR10(r1)
4399 + lwz r11,xGPR11(r1)
4401 + lwz r12,xGPR12(r1)
4406 +#define EXCEPTION_SAVE_ALL \
4407 + EXCEPTION_PREAMBLE ;\
4408 + bl save_middle_regs ;
4410 +#define VECTOR_KERNEL( v, dummy_name, secint ) \
4411 + VECTOR( v, dummy_name, secint ) ;\
4412 + EXCEPTION_SAVE_ALL ;\
4413 + TAKE_EXCEPTION( v ) ;
4415 +#define VECTOR_RESERVED( v, dummy_name, secint ) \
4416 + VECTOR( v, dummy_name, secint ) ;\
4417 + DEBUGGER_SAVE( v ) ;
4419 +#define MAC_EXIT( rvec_code ) \
4420 + li r3,rvec_code ;\
4423 +#define MAC_EXIT_SAVE( rvec_code ) \
4424 + bl save_middle_regs ;\
4425 + li r3,rvec_code ;\
4428 +#define MAC_TRAP( trap_num ) \
4432 +#define DEBUGGER(n) li r4,n ; MAC_EXIT( RVEC_DEBUGGER );
4433 +#define DEBUGGER_SAVE(n) li r4,n ; MAC_EXIT_SAVE( RVEC_DEBUGGER );
4436 +/************************************************************************/
4438 +/************************************************************************/
4440 + //////////////////////////////////////////////////////////////
4441 + // _get_instr_opcode
4445 + // Modifies: r2,r3.
4446 + // Side-effects: Might return from the exception
4448 +MACRO(GET_INSTR_OPCODE, [dummy], [
4449 + mfmsr r3 // r3 = exception MSR
4453 + // secondary interrupt entry (we _know_ this must be a DSI)
4455 + LOADI r5,EXTERN(compat_hash_table_lock)
4458 +7: lwarx r0,0,r5 // lock
4468 + stw r0,0(r5) // release lock
4470 + tlbie r6 // flush PTE from ITLB
4472 + b exception_return
4477 + lwz r4,0(r6) // get opcode
4479 + mtmsr r3 // restore exception MSR
4483 +/************************************************************************/
4484 +/* Reserved / Kernel Vectors */
4485 +/************************************************************************/
4487 +VECTOR_KERNEL( 0x100, "System Reset", secint_bad )
4488 +VECTOR_KERNEL( 0x500, "External Interrupt", secint_bad )
4489 +VECTOR_KERNEL( 0x1400, "System Management Interrupt", secint_bad )
4490 +VECTOR_KERNEL( 0x1700, "Thermal Management Interrupt", secint_bad )
4492 +VECTOR_RESERVED( 0x200, "Machine Check", secint_bad )
4493 +VECTOR_RESERVED( 0xa00, "Reserved", secint_bad )
4494 +VECTOR_RESERVED( 0xb00, "Reserved", secint_bad )
4495 +VECTOR_RESERVED( 0xe00, "FPU Assist", secint_bad )
4497 +PERFMON_VECTOR_RELOCATION( PERFMON_VECTOR )
4498 +VECTOR_RESERVED( PERFMON_VECTOR, "Performance Monitor Interrupt", secint_bad )
4500 +//VECTOR_RESERVED( 0x1000, "InstructionTLBMiss-603", secint_bad )
4501 +//VECTOR_RESERVED( 0x1100, "DataLoadTLBMiss-603", secint_bad )
4502 +//VECTOR_RESERVED( 0x1200, "DataLoadTLBMiss-603", secint_bad )
4504 +/************************************************************************/
4505 +/* DSI Exceptions */
4506 +/************************************************************************/
4508 +VECTOR( 0x300, "DSI", secint_lr_call )
4509 + EXCEPTION_PREAMBLE
4510 + TRACE(0x300, "DSI")
4512 + GET_INSTR_OPCODE // m: r2-r3, ret: r4=opcode, r6=nip
4513 + stw r4,xINST_OPCODE(r1)
4514 + bl check_pthash_hit // m: r0,r2-r5
4515 + btl- FBIT_InSplitmode,splitmode_dsi
4516 + bl save_middle_regs
4520 + LOADI r3,EXTERN(dsi_exception)
4521 + mfdar r4 // We might need to do this earlier
4522 + mfdsisr r5 // when the splitmode code is activated...
4526 +/************************************************************************/
4527 +/* ISI Exceptions */
4528 +/************************************************************************/
4530 +VECTOR( 0x400, "ISI", secint_bad )
4531 + EXCEPTION_PREAMBLE
4532 + TRACE(0x400, "ISI")
4534 + // emuaccel engine
4535 + rlwinm. r0,r7,0,4,4 // protection violation
4537 + lwz r3,K_EMUACCEL_MPHYS(r1)
4538 + rlwinm r4,r6,0,~0x0fff // nip page
4539 + rlwinm r2,r6,0,0x0ff8 // nip offset (dword align)
4540 + lwz r5,K_EMUACCEL_PAGE_PHYS(r1)
4543 + lwzux r0,r2,r5 // r0 = handler
4545 + lwz r6,4(r2) // address of next instruction
4546 + blr // parameters: r2 == emuaccel_slot
4548 + btl- FBIT_InSplitmode, split_sr_no_execute
4549 + bl save_middle_regs
4551 + LOADI r3,EXTERN(isi_exception)
4557 +/************************************************************************/
4558 +/* Alignement Exception */
4559 +/************************************************************************/
4561 +VECTOR( 0x600, "Alignment", secint_lr_call )
4562 + EXCEPTION_SAVE_ALL
4563 + TRACE(0x400, "Alignment")
4568 + MAC_EXIT( RVEC_ALIGNMENT_TRAP )
4571 +/************************************************************************/
4572 +/* FPU Unavailable Exception */
4573 +/************************************************************************/
4575 + // xFPU_STATE has only meaning when FBIT_FPUInUse is not set
4577 + // FPU_STATE_DIRTY - fr13 & fpscr are not loaded (everything else is).
4578 + // FPU_STATE_HALF_SAVED - fr14-fr31 are loaded.
4579 + // FPU_STATE_SAVED - fr14-fr31 are loaded (but also saved in mregs).
4581 + // FPU_STATE_DIRTY in the *emulator* means that all floating point
4582 + // registers *EXCEPT* fr13 and fpscr are valid.
4584 + // Implementation note: When we do not own the fpu, the MSR_FEx bits
4585 + // must be cleared. Otherwise we might experience bogus FPU exceptions.
4587 + // MOL will never throw FPU exceptions went the FP bit is off. This
4588 + // is a small violation of the standard but the alternative would be
4589 + // always loading FPSCR (which requires FPU ownership...)
4592 +VECTOR( 0x800, "FPU Unavailable", secint_lr_call )
4593 + EXCEPTION_PREAMBLE
4594 + TRACE(0x800, "FPU Unavailable")
4597 + lwz r2,xMSR(r1) // r2 = xMSR (used below too)
4598 + andi. r4,r2,MSR_FP
4599 + beq- mac_fpu_unavailable // mac trap?
4600 + bt FBIT_FPUInUse,2f // FPU ready for use?
4602 + lwz r3,K_EMULATOR_MSR(r1) // FPU owned by our userland process?
4603 + andi. r4,r3,MSR_FP
4605 + MAC_EXIT_SAVE( RVEC_ENABLE_FPU ) // No... grab FPU in userspace
4607 +mac_fpu_unavailable:
4608 + BUMP( "mac-fpu-trap" )
4611 + // userland process owns FPU
4612 +1: BUMP( "enable-fpu" )
4613 + ENABLE_MSR_FP /**/ r4 // enable kernel FPU
4614 + // flag the fpu dirty
4615 + lwz r3,xFPU_STATE(r1)
4616 + lfd fr13,xFPSCR-4(r1) // fp13 and fpscr are *ALWAYS* saved
4617 + crset FBIT_FPUInUse // we own the FPU now
4618 + cmpwi r3,FPU_STATE_HALF_SAVED
4620 + lfd fr13,xFPR13(r1)
4622 + xLOAD_LOW_FPU r1 // load fr0-fr12
4624 + li r3,MSR_FP| MSR_FE0 | MSR_FE1 // FPU bits
4625 + lwz r7,K_MSR(r1) // enable MSR_FP
4626 + and r2,r2,r3 // r2 = (xMSR & MSR_FEx)
4627 + andc r7,r7,r3 // K_MSR &= ~MSR_FEx
4628 + or r7,r7,r2 // K_MSR |= (xMSR & MSR_FEx)
4630 + GET_TICK_CNT(entry,"enable_fpu")
4631 + b exception_return
4634 +/************************************************************************/
4635 +/* Decrementer Exception */
4636 +/************************************************************************/
4638 +// The 0x900 decrementer vector is in dec.S
4640 +/************************************************************************/
4641 +/* System Call Exception */
4642 +/************************************************************************/
4644 +VECTOR( 0xc00, "System Call", secint_bad )
4645 + EXCEPTION_PREAMBLE
4646 + TRACE( 0xc00, "System Call")
4649 + LOADI r5,OSI_SC_MAGIC_R3
4651 + LOADI r2,OSI_SC_MAGIC_R4
4654 + crand eq,eq,cr1_eq
4657 + MAC_TRAP(0xc00) // r7 reason bits used (zero)
4659 + MAC_EXIT_SAVE( RVEC_OSI_SYSCALL )
4662 +/************************************************************************/
4663 +/* Trace Exception */
4664 +/************************************************************************/
4666 +VECTOR( 0xd00, "Trace", secint_bad )
4668 + EXCEPTION_PREAMBLE
4669 + TRACE(0xd00, "Trace")
4671 + MAC_EXIT_SAVE( RVEC_TRACE_TRAP );
4674 +/************************************************************************/
4675 +/* AltiVec Exception */
4676 +/************************************************************************/
4678 +VECTOR( 0xf20, "AltiVec", secint_lr_call )
4679 + EXCEPTION_PREAMBLE
4680 + TRACE(0xf20, "AltiVec")
4683 + lwz r4,xNO_ALTIVEC(r1) // AltiVec support disabled?
4685 + bne- mac_altivec_unavailable
4688 + rlwinm. r4,r2,0,6,6 // bit 6 = MSR_VEC
4689 + beq- mac_altivec_unavailable
4691 + lwz r3,K_EMULATOR_MSR(r1)
4692 + rlwinm. r4,r3,0,6,6 // bit 6 = MSR_VEC
4693 + bne+ enable_altivec
4694 + MAC_EXIT_SAVE( RVEC_ENABLE_ALTIVEC )
4696 +mac_altivec_unavailable:
4697 + MAC_EXIT_SAVE( RVEC_ALTIVEC_UNAVAIL_TRAP )
4700 + // We don't need to load any registers since the emulator
4701 + // won't touch the altivec unit (at least for now).
4704 + oris r7,r7,HI(MSR_VEC)
4706 + b exception_return
4709 +VECTOR( 0x1600, "AltiVec Assist", secint_bad )
4710 + EXCEPTION_SAVE_ALL
4711 + TRACE(0x1600, "AltiVec Assist")
4714 + MAC_EXIT( RVEC_ALTIVEC_ASSIST ) // r4 = srr1
4717 +/************************************************************************/
4718 +/* Instruction Breakpoint */
4719 +/************************************************************************/
4721 +VECTOR( 0x1300, "Instruction Breakpoint", secint_bad )
4722 + EXCEPTION_SAVE_ALL
4723 + TRACE(0x1300, "IABR")
4728 +/************************************************************************/
4729 +/* RunMode-601 (trace) */
4730 +/************************************************************************/
4732 +VECTOR( 0x2000, "RunMode-601", secint_bad )
4736 +/************************************************************************/
4737 +/* Secondary Interrupt Handlers */
4738 +/************************************************************************/
4740 + //////////////////////////////////////////////////////////////////////
4743 + // r1: stack (sprg1 = old r1)
4744 + // r3: vector addr (sprg0 = old r3)
4745 + // srr0/srr1: kernel nip/msr
4747 + // secint_lr_call:
4748 + // lr secondary interrupt handler
4751 + TRACE(0xbad, "secint_bad")
4753 + MAC_EXIT( RVEC_INTERNAL_ERROR )
4758 + MAC_EXIT( RVEC_INTERNAL_ERROR )
4761 +/**************************************************************
4763 +**************************************************************/
4765 +// We need to be sure this code is contiguous, the simplest/safest
4766 +// method is using only a single file. This will also effectively
4767 +// reduce the size of the relocation table.
4770 +#include "darwin.S"
4774 +#include "emulation.S"
4775 +#include "emuaccel.S"
4776 +#include "iopage.S"
4777 +#include "splitmode.S"
4778 +#include "ptintercept.S"
4781 +#include "./mpc107/mpc107.S"
4792 +GLOBAL_SYMBOL(r__reloctable_end):
4794 + ACTIONS_OFFS_SECTION
4795 +GLOBAL_SYMBOL(r__actions_offs_section_end):
4797 +// The BUMP("counter") macro adds entries to text subsection 90.
4798 +// This adds labels before the counter entries.
4802 +GLOBAL_SYMBOL(__start_bumptable):
4804 +GLOBAL_SYMBOL(__end_bumptable):
4808 +++ b/drivers/macintosh/mol/asm-files/vsid.S
4811 + * Creation Date: <2003/03/06 22:03:59 samuel>
4812 + * Time-stamp: <2004/02/21 16:30:45 samuel>
4816 + * VSID lookup (skiplist search)
4818 + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
4820 + * This program is free software; you can redistribute it and/or
4821 + * modify it under the terms of the GNU General Public License
4822 + * as published by the Free Software Foundation
4826 +#include "mtable.h"
4828 +#if (SKIPLIST_LEVELSIZE == 4)
4829 +#define SLEVEL_SHIFT 2
4831 +#if (SKIPLIST_LEVELSIZE == 8)
4832 +#define SLEVEL_SHIFT 3
4836 + rlwinm r2,r4,32-8,24,28 // r2 = #B << 8
4837 + EMU_LOAD_GPR r2, /**/ R3 // r0 = reg B
4838 + rlwinm r4,r0,0,0,3 // #sr top 4 bits of r4
4841 + rlwinm r4,r4,12,0,3 // #sr in top 4 bits of r4
4842 +1: EMU_LOAD_GPR r5, /**/ R2 // r0 = new segr value
4844 + stw r8,xGPR8(r1) // save r8
4845 + rlwinm r8,r4,6,26,29 // r8 = #sr << 2
4846 + stw r9,xGPR9(r1) // save r9
4847 + add r8,r8,r1 // r8 = r1 + sr_offset
4848 + stw r6,xNIP(r1) // save r6 (need more registers)
4849 + rlwinm r9,r0,0,0,3 // r9 = [T Ks Kp N]
4850 + stw r0,xSEGR_BASE(r8) // store new value
4851 + rlwinm r0,r0,0,8,31 // mask VSID
4853 + /******* vsid lookup (skiplist search) *******/
4855 + lwz r2,K_VSID_SL_SLEVEL(r1) // n = search level (0..15)
4856 + rlwinm r2,r2,SLEVEL_SHIFT,0,29 // n *= 4 (or n *= 8 on darwin)
4858 + addi r3,r1,K_VSID_SL_ROOT_ELEM // p = root element
4860 +2: lwz r3,SKIPLIST_NEXT(r5) // r3 = p->next[n]
4864 + lwz r4,SKIPLIST_KEY(r3) // r0 = p->next[n].key
4869 + addi r2,r2,-SKIPLIST_LEVELSIZE // r2 -= 4|8
4870 + beq- cr1,vsid_found // jump if key matches
4872 + addi r5,r5,-SKIPLIST_LEVELSIZE // r5 -= 4|8
4875 + /******* vsid missing *******/
4876 + BUMP("vsid_missing")
4878 + lwz r2,K_ILLEGAL_SR(r1) // vsid unallocated...
4879 + li r4,0 // no entry...
4880 + stw r2,K_SV_SR_BASE(r8)
4881 + stw r2,K_USER_SR_BASE(r8)
4882 + stw r2,K_SPLIT_SR_BASE(r8) // this way we can forget the splitmode case
4883 + stw r4,K_VSID_ENT_BASE(r8)
4884 + sub r5,r8,r1 // r5 = VSID offset
4885 + lwz r0,K_CUR_SR_BASE(r1) // r0 = cur_sr_table
4888 + /******* vsid found *******/
4891 + BUMP("vsid_found")
4892 + // match, r3 points to the skiplist element
4893 + addi r4,r3,-SIZEOF_VSID_ENT // sizeof(vsid_ent_t)
4894 + lwz r2,VSID_USER_OFFS(r4) // vsid_user
4895 + lwz r3,VSID_SV_OFFS(r4) // vsid_sv
4897 + tovirt R4,R4 // r4 = vsid_element
4899 + lwz r4,VSID_MYSELF_VIRT(r4)
4901 + rlwinm r6,r9,2,31,31 // r6 = Ks ? 1:0
4902 + stw r4,K_VSID_ENT_BASE(r8) // store vsid entry (possibly NULL)
4903 + rlwinm r4,r9,3,31,31 // r4 = Kp ? 1:0
4904 + rlwimi r2,r9,0,3,3 // copy the N-bit (no-execute)
4905 + rlwimi r3,r9,0,3,3 // copy the N-bit (no-execute)
4906 + cror FBIT_LoadSegreg, FBIT_LoadSegreg, FBIT_InSplitmode
4907 + addi r6,r6,-1 // r6 = Ks-mask
4908 + addi r4,r4,-1 // r4 = Kp-mask
4909 + andc r0,r2,r6 // Kp == 1 case
4910 + and r6,r3,r6 // Kp == 0 case
4911 + crmove FBIT_PrepareSplitmode, FBIT_InSplitmode
4912 + andc r9,r2,r4 // Ks == 1 case
4914 + lwz r0,K_CUR_SR_BASE(r1) // r0 = cur_sr_table
4915 + and r4,r3,r4 // Ks == 0 case
4916 + stw r6,K_SV_SR_BASE(r8) // sv_sr set
4918 + sub r5,r8,r1 // r5 = VSID offset
4919 + stw r4,K_USER_SR_BASE(r8) // user_sr set
4922 + rlwinm r2,r5,32-6,0,3 // r2 = sr# in bits 0-3
4923 + lwzx r3,r5,r0 // r3 = sr to be loaded into sr#
4924 + mtsrin r3,r2 // update segment register
4926 + lwz r6,xNIP(r1) // restore r6
4927 + lwz r8,xGPR8(r1) // restore r8
4928 + lwz r9,xGPR9(r1) // restore r9
4929 + GET_TICK_CNT(entry, "mtsr")
4934 +++ b/drivers/macintosh/mol/asm_offsets.c
4937 + * This program is used to generate definitions needed by
4938 + * some assembly functions.
4940 + * We use the technique used in the OSF Mach kernel code:
4941 + * generate asm statements containing #defines,
4942 + * compile this file to assembler, and then extract the
4943 + * #defines from the assembly-language output.
4947 +#include "archinclude.h"
4948 +#include "kernel_vars.h"
4951 +#include "mol_config.h"
4952 +#include <stddef.h>
4953 +#include "mac_registers.h"
4956 +#include "processor.h"
4958 +#define DEFINE(sym, val) \
4959 + asm volatile("\n#define\t" #sym "\t%0" : : "i" (val))
4961 +#define K_DEF(sym, val ) \
4962 + DEFINE(sym, offsetof(kernel_vars_t, val ))
4964 +#define ST_DEF(sym, val ) \
4965 + DEFINE(sym, offsetof(session_table_t, val ))
4967 +#define M_DEF(sym, val ) \
4968 + DEFINE(sym, XOFFS + offsetof(mac_regs_t, val ))
4970 +#define IO_DEF(sym, val) \
4971 + DEFINE(sym, offsetof(struct io_page, val ))
4976 + #define XOFFS offsetof(kernel_vars_t, mregs)
4980 + /* --- mac_regs offsets --- */
4982 + M_DEF( xVEC_BASE, vec[0] );
4983 + M_DEF( xVEC0, vec[0] );
4984 + M_DEF( xVEC1, vec[1] );
4985 + M_DEF( xVEC2, vec[2] );
4986 + M_DEF( xVSCR, vscr );
4987 + M_DEF( xVRSAVE, spr[S_VRSAVE] );
4989 + M_DEF( xGPR_BASE, gpr[0] );
4990 + M_DEF( xGPR0, gpr[0] );
4991 + M_DEF( xGPR1, gpr[1] );
4992 + M_DEF( xGPR2, gpr[2] );
4993 + M_DEF( xGPR3, gpr[3] );
4994 + M_DEF( xGPR4, gpr[4] );
4995 + M_DEF( xGPR5, gpr[5] );
4996 + M_DEF( xGPR6, gpr[6] );
4997 + M_DEF( xGPR7, gpr[7] );
4998 + M_DEF( xGPR8, gpr[8] );
4999 + M_DEF( xGPR9, gpr[9] );
5000 + M_DEF( xGPR10, gpr[10] );
5001 + M_DEF( xGPR11, gpr[11] );
5002 + M_DEF( xGPR12, gpr[12] );
5003 + M_DEF( xGPR13, gpr[13] );
5004 + M_DEF( xGPR14, gpr[14] );
5005 + M_DEF( xGPR15, gpr[15] );
5006 + M_DEF( xGPR16, gpr[16] );
5007 + M_DEF( xGPR17, gpr[17] );
5008 + M_DEF( xGPR18, gpr[18] );
5009 + M_DEF( xGPR19, gpr[19] );
5010 + M_DEF( xGPR20, gpr[20] );
5011 + M_DEF( xGPR21, gpr[21] );
5012 + M_DEF( xGPR22, gpr[22] );
5013 + M_DEF( xGPR23, gpr[23] );
5014 + M_DEF( xGPR24, gpr[24] );
5015 + M_DEF( xGPR25, gpr[25] );
5016 + M_DEF( xGPR26, gpr[26] );
5017 + M_DEF( xGPR27, gpr[27] );
5018 + M_DEF( xGPR28, gpr[28] );
5019 + M_DEF( xGPR29, gpr[29] );
5020 + M_DEF( xGPR30, gpr[30] );
5021 + M_DEF( xGPR31, gpr[31] );
5023 + M_DEF( xNIP, nip);
5025 + M_DEF( xFPR_BASE, fpr[0]);
5026 + M_DEF( xFPR13, fpr[13]);
5027 + M_DEF( xFPSCR, fpscr );
5028 + M_DEF( xEMULATOR_FPSCR, emulator_fpscr );
5029 + M_DEF( xFPU_STATE, fpu_state );
5031 + M_DEF( xLINK, link);
5032 + M_DEF( xXER, xer);
5033 + M_DEF( xCTR, ctr);
5034 + M_DEF( xFLAG_BITS, flag_bits );
5035 + M_DEF( xDEC, spr[S_DEC]);
5036 + M_DEF( xDEC_STAMP, dec_stamp);
5037 + M_DEF( xTIMER_STAMP, timer_stamp);
5038 + M_DEF( xMSR, msr);
5039 + M_DEF( xSPR_BASE, spr[0]);
5041 + M_DEF( xHID0, spr[S_HID0]);
5043 + M_DEF( xSRR0, spr[S_SRR0]);
5044 + M_DEF( xSRR1, spr[S_SRR1]);
5046 + M_DEF( xSPRG0, spr[S_SPRG0]);
5047 + M_DEF( xSPRG1, spr[S_SPRG1]);
5048 + M_DEF( xSPRG2, spr[S_SPRG2]);
5049 + M_DEF( xSPRG3, spr[S_SPRG3]);
5051 + M_DEF( xSEGR_BASE, segr[0]);
5052 + M_DEF( xIBAT_BASE, spr[S_IBAT0U] );
5053 + M_DEF( xSDR1, spr[S_SDR1] );
5055 + M_DEF( xINST_OPCODE, inst_opcode );
5056 + M_DEF( xALTIVEC_USED, altivec_used );
5057 + M_DEF( xNO_ALTIVEC, no_altivec );
5059 + M_DEF( xINTERRUPT, interrupt );
5060 + M_DEF( xIN_VIRTUAL_MODE, in_virtual_mode );
5062 + M_DEF( xRVEC_PARAM0, rvec_param[0] );
5063 + M_DEF( xRVEC_PARAM1, rvec_param[1] );
5064 + M_DEF( xRVEC_PARAM2, rvec_param[2] );
5067 + M_DEF( xGPRSAVE0_603, gprsave_603[0] );
5068 + M_DEF( xGPRSAVE1_603, gprsave_603[1] );
5069 + M_DEF( xGPRSAVE2_603, gprsave_603[2] );
5070 + M_DEF( xGPRSAVE3_603, gprsave_603[3] );
5073 + M_DEF( xDEBUG0, debug[0] );
5074 + M_DEF( xDEBUG1, debug[1] );
5075 + M_DEF( xDEBUG2, debug[2] );
5076 + M_DEF( xDEBUG3, debug[3] );
5077 + M_DEF( xDEBUG4, debug[4] );
5078 + M_DEF( xDEBUG5, debug[5] );
5079 + M_DEF( xDEBUG6, debug[6] );
5080 + M_DEF( xDEBUG7, debug[7] );
5081 + M_DEF( xDEBUG8, debug[8] );
5082 + M_DEF( xDEBUG9, debug[9] );
5084 + M_DEF( xDEBUG_SCR1, debug_scr1 );
5085 + M_DEF( xDEBUG_SCR2, debug_scr2 );
5086 + M_DEF( xDEBUG_TRACE, debug_trace );
5087 + M_DEF( xDBG_TRACE_SPACE, dbg_trace_space[0] );
5088 + M_DEF( xDBG_LAST_RVEC, dbg_last_rvec );
5090 + M_DEF( xKERNEL_DBG_STOP, kernel_dbg_stop );
5092 + M_DEF( xHOSTIRQ_ACTIVE_CNT, hostirq_active_cnt );
5098 +++ b/drivers/macintosh/mol/context.c
5101 + * Creation Date: <1998-11-20 16:18:20 samuel>
5102 + * Time-stamp: <2004/02/28 19:16:44 samuel>
5106 + * MMU context allocation
5108 + * Copyright (C) 1998-2004 Samuel Rydh (samuel@ibrium.se)
5110 + * This program is free software; you can redistribute it and/or
5111 + * modify it under the terms of the GNU General Public License
5112 + * as published by the Free Software Foundation
5116 +#include "archinclude.h"
5119 +#include "mmu_contexts.h"
5121 +#include "asmfuncs.h"
5123 +#include "mtable.h"
5124 +#include "performance.h"
5125 +#include "context.h"
5128 +#define MMU (kv->mmu)
5132 +flush_all_PTEs( kernel_vars_t *kv )
5134 + int i, count=0, npte=(ptehash.pte_mask + 8)/8;
5135 + ulong *pte, ea, v;
5137 + for( pte=ptehash.base, i=0; i<npte; i++, pte+=2 ) {
5139 + if( !(v & BIT(0)) ) /* test V-bit */
5141 + v = (v & ~BIT(0)) >> 7;
5142 + v = (v - ((v & 0xf) * MUNGE_ESID_ADD)) * MUNGE_MUL_INVERSE;
5143 + v = (v>>4) & CTX_MASK;
5145 + if( v >= MMU.first_mol_context && v <= MMU.last_mol_context ) {
5151 + /* perform a tlbia */
5152 + for( ea=0; ea <= (0x3f << 12); ea += 0x1000 )
5156 + printk("%d stale PTEs flushed (something is wrong)\n", count );
5161 +init_contexts( kernel_vars_t *kv )
5163 + MMU.first_mol_context = FIRST_MOL_CONTEXT( kv->session_index );
5164 + MMU.last_mol_context = LAST_MOL_CONTEXT( kv->session_index );
5165 + MMU.next_mol_context = MMU.first_mol_context;
5167 + MMU.illegal_sr = alloc_context(kv) | VSID_Kp | VSID_N;
5169 + flush_all_PTEs( kv );
5174 +cleanup_contexts( kernel_vars_t *kv )
5176 + flush_all_PTEs( kv );
5180 +handle_context_wrap( kernel_vars_t *kv, int n )
5182 + if( MMU.next_mol_context + n > MMU.last_mol_context ) {
5183 + printk("MOL context wrap\n");
5185 + clear_all_vsids( kv );
5186 + init_contexts( kv );
5191 +alloc_context( kernel_vars_t *kv )
5193 + int mol_context = MMU.next_mol_context++;
5194 + int vsid = MUNGE_CONTEXT(mol_context >> 4);
5196 + vsid += MUNGE_ESID_ADD * (mol_context & 0xf);
5197 + return (vsid & VSID_MASK);
5200 +++ b/drivers/macintosh/mol/emu.c
5203 + * Creation Date: <1998-11-21 16:07:47 samuel>
5204 + * Time-stamp: <2004/03/13 14:08:18 samuel>
5208 + * Emulation of some assembly instructions
5210 + * Copyright (C) 1998-2004 Samuel Rydh (samuel@ibrium.se)
5212 + * This program is free software; you can redistribute it and/or
5213 + * modify it under the terms of the GNU General Public License
5214 + * as published by the Free Software Foundation
5218 +#include "archinclude.h"
5221 +#include "kernel_vars.h"
5223 +#include "asmfuncs.h"
5225 +#include "processor.h"
5226 +#include "mtable.h"
5227 +#include "performance.h"
5228 +#include "emuaccel_sh.h"
5232 +#define BAT_PERFORMANCE_HACK
5235 +/* If BAT_PERFORMANCE_HACK is defined, PTEs corresponding to a mac bat
5236 + * mapping will not necessary be flushed when the bat registers are
5237 + * touched. This gives a huge performance gain in MacOS 9.1 (which
5238 + * clears the bat registers in the idle loop). Of course, this break
5239 + * compatibility (although most operating systems initializes the
5240 + * BATs once and for all).
5243 +#ifdef BAT_PERFORMANCE_HACK
5244 + #define BAT_HACK(kv) (!MREGS.use_bat_hack || kv->mmu.bat_hack_count++ < 0x100)
5246 + #define BAT_HACK(kv) 1
5249 +#define MREGS (kv->mregs)
5250 +#define MMU (kv->mmu)
5254 +do_mtsdr1( kernel_vars_t *kv, ulong value )
5256 + ulong mbase, mask;
5259 + MREGS.spr[S_SDR1] = value;
5261 + /* the mask must be a valid one; we hade better make sure we are
5262 + * not tricked by a bogus sdr1 value
5264 + for( mask=BIT(23); mask && !(mask & value) ; mask=mask>>1 )
5266 + mask = mask? ((mask | (mask-1)) << 16) | 0xffff : 0xffff;
5267 + mbase = value & ~mask;
5269 + if( mbase + mask >= MMU.ram_size ) {
5270 + /* S_SDR1 out of range, fallback to a safe setting */
5271 + printk("WARNING, S_SDR1, %08lX is out of range\n", value);
5276 + MMU.hash_mbase = mbase;
5277 + MMU.hash_mask = mask;
5278 + MMU.pthash_sr = -1; /* clear old tlbhash matching */
5280 + if( MMU.hash_base )
5281 + unmap_emulated_hash( kv );
5282 + MMU.hash_base = map_emulated_hash( kv, MMU.hash_mbase, mask+1 );
5284 + /* try to allocate the PTE bitfield table (16K/128 MB ram). The worst
5285 + * case is 512K which will fail since the kmalloc limit is 128K.
5286 + * If the allocation fails, we simply don't use the bitfield table.
5289 + if( MMU.pthash_inuse_bits )
5290 + kfree_cont_mol( MMU.pthash_inuse_bits );
5291 + if( !(MMU.pthash_inuse_bits=kmalloc_cont_mol(s)) )
5292 + MMU.pthash_inuse_bits_ph = 0;
5294 + memset( MMU.pthash_inuse_bits, 0, s );
5295 + MMU.pthash_inuse_bits_ph = tophys_mol( MMU.pthash_inuse_bits );
5298 + /* make sure the unmapped ram range is flushed... */
5299 + flush_lv_range( kv, MMU.userspace_ram_base + mbase, mask+1 );
5301 + /* ...as well as any MMU mappings */
5302 + clear_pte_hash_table( kv );
5308 +/* This function is _very_ slow, since it must destroy a lot of PTEs.
5309 + * Fortunately, BAT-maps are normally static.
5312 +do_mtbat( kernel_vars_t *kv, int sprnum, ulong value, int force )
5320 + if( !force && MREGS.spr[sprnum] == value )
5323 + /* printk("do_mtbat %d %08lX\n", sprnum, value); */
5325 + MREGS.spr[sprnum] = value;
5327 + /* upper bat register have an even number */
5328 + batnum = (sprnum - S_IBAT0U) >>1;
5329 + d = &MMU.bats[batnum];
5331 + /* First we must make sure that all PTEs corresponding to
5332 + * the old BAT-mapping are purged from the hash table.
5334 + if( BAT_HACK(kv) && d->valid )
5335 + flush_ea_range(kv, d->base & ~0xf0000000, d->size );
5337 + p = (mBAT*)&MREGS.spr[sprnum & ~1];
5338 + d->valid = p->batu.vs | p->batu.vp;
5339 + d->vs = p->batu.vs;
5340 + d->vp = p->batu.vp;
5341 + d->wimg = (p->batl.w<<3) | (p->batl.i<<2) | (p->batl.m<<1) | p->batl.g;
5342 + d->ks = d->ku = 1; /* IBAT/DBATs, behaves as if key==1 */
5343 + d->pp = p->batl.pp;
5344 + d->size = (p->batu.bl+1)<<17;
5345 + d->base = (p->batu.bepi & ~p->batu.bl)<<17;
5346 + d->mbase = (p->batl.brpn & ~p->batu.bl)<<17;
5348 + /* Next, we must make sure that no PTEs refer to the new
5349 + * BAT-mapped area.
5352 + if( BAT_HACK(kv) && d->valid )
5353 + flush_ea_range( kv, d->base & ~0xf0000000, d->size );
5359 +/************************************************************************/
5360 +/* Emulation acceleration */
5361 +/************************************************************************/
5364 +lookup_emuaccel_handler( int emuaccel )
5366 + extern ulong emuaccel_table[];
5367 + ulong handler, *p = emuaccel_table;
5369 + for( ; p[0]; p+=3 ) {
5370 + if( (emuaccel & EMUACCEL_INST_MASK) != p[0] )
5372 + emuaccel &= p[2]; /* offset mask */
5373 + handler = p[1] + (ulong)emuaccel_table + emuaccel * 8;
5374 + return tophys_mol( (ulong*)reloc_ptr(handler) );
5380 +alloc_emuaccel_slot( kernel_vars_t *kv, int emuaccel, int param, int inst_addr )
5382 + ulong *p = (ulong*)((char*)kv->emuaccel_page + kv->emuaccel_size);
5383 + ulong handler = lookup_emuaccel_handler( emuaccel );
5386 + size = (emuaccel & EMUACCEL_HAS_PARAM)? 16 : 8;
5387 + if( !handler || !p || kv->emuaccel_size + size > 0x1000 )
5390 + ret = kv->emuaccel_mphys + kv->emuaccel_size;
5392 + p[1] = inst_addr + 4;
5394 + if( emuaccel & EMUACCEL_HAS_PARAM ) {
5395 + /* p[2] is already EMUACCEL_NOP */
5399 + kv->emuaccel_size += size;
5404 +mapin_emuaccel_page( kernel_vars_t *kv, int mphys )
5409 + if( kv->emuaccel_page || (mphys & 0xfff) )
5412 + if( !(kv->emuaccel_page=alloc_page_mol()) )
5415 + kv->emuaccel_page_phys = tophys_mol( (char*)kv->emuaccel_page );
5416 + kv->emuaccel_mphys = mphys;
5417 + p = (ulong*)kv->emuaccel_page;
5419 + handler = lookup_emuaccel_handler( EMUACCEL_NOP );
5420 + for( i=0; i<0x1000/sizeof(int); i+=2 ) {
5425 + /* flush translations - an old translation is overridden */
5426 + clear_pte_hash_table( kv );
5427 + /* printk("emuaccel_mapin: %08x\n", mphys ); */
5431 +++ b/drivers/macintosh/mol/fault.c
5434 + * Creation Date: <2002/06/08 20:53:20 samuel>
5435 + * Time-stamp: <2004/02/22 13:07:50 samuel>
5439 + * Page fault handler
5441 + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
5443 + * This program is free software; you can redistribute it and/or
5444 + * modify it under the terms of the GNU General Public License
5445 + * as published by the Free Software Foundation
5449 +#include "archinclude.h"
5452 +#include "kernel_vars.h"
5454 +#include "mmu_contexts.h"
5455 +#include "asmfuncs.h"
5458 +#include "constants.h"
5460 +#include "mtable.h"
5461 +#include "performance.h"
5462 +#include "processor.h"
5465 +/* exception bits (srr1/dsisr and a couple of mol defined bits) */
5466 +#define EBIT_PAGE_FAULT BIT(1) /* I/D, PTE missing */
5467 +#define EBIT_NO_EXEC BIT(3) /* I, no-execute or guarded */
5468 +#define EBIT_PROT_VIOL BIT(4) /* I/D, protection violation */
5469 +#define EBIT_IS_WRITE BIT(6) /* D */
5470 +#define EBIT_IS_DSI 1 /* D, virtual bit */
5471 +#define EBIT_USE_MMU 2 /* I/D, virtual bit */
5473 +#define use_mmu(ebits) ((ebits) & EBIT_USE_MMU)
5474 +#define is_write(ebits) ((ebits) & EBIT_IS_WRITE)
5475 +#define is_dsi(ebits) ((ebits) & EBIT_IS_DSI)
5476 +#define is_prot_viol(ebits) ((ebits) & EBIT_PROT_VIOL)
5477 +#define is_page_fault(ebits) ((ebits) & EBIT_PAGE_FAULT)
5480 + /* filled in by exception handler */
5483 + struct vsid_ent **vsid_eptr; /* pointer to MMU.vsid or MMU.unmapped_vsid */
5485 + /* filled in by lookup_mphys */
5486 + mPTE_t *mpte; /* lvptr to mac-pte (if != NULL) */
5487 + ulong mphys_page; /* ea of mphys page */
5488 + int pte1; /* RPN | 000 | R | C | WIMG | 00 | PP */
5489 + int key; /* pp key bit */
5492 +static const char priv_viol_table[16] = { /* [is_write | key | PP] */
5493 + 0,0,0,0,1,0,0,0, /* read (1 == violation) */
5494 + 0,0,0,1,1,1,0,1 /* write */
5497 +#define NO_MMU_PTE1 (PTE1_R | PTE1_C /*| PTE1_M*/ | 0x2 /*pp*/ )
5499 +#define MREGS (kv->mregs)
5500 +#define MMU (kv->mmu)
5503 +#define SMP_PTE1_M PTE1_M
5505 +#define SMP_PTE1_M 0
5509 +/************************************************************************/
5511 +/************************************************************************/
5514 +DEBUG_print_inserted_pte( ulong *slot, ulong pte0, ulong pte1, ulong ea )
5518 + ulong *p = (ulong)&pte;
5522 + printk("[%p] ", slot );
5523 + printk("RPN %08X API %08X EA %08lX ", pte.rpn << 12, pte.api<<12, ea );
5524 + printk("%c%c %c%c; PP %d\n",
5525 + pte.h ? 'H' : 'h',
5526 + pte.v ? 'V' : 'v',
5527 + pte.r ? 'R' : 'r',
5528 + pte.c ? 'C' : 'c', pte.pp );
5533 +/************************************************************************/
5534 +/* MMU virtualization and page fault handling */
5535 +/************************************************************************/
5539 +lookup_603_pte( kernel_vars_t *kv, ulong vsid, ulong ea, int is_dsi, mPTE_t **ret_pte )
5541 + int ind = (ea >> 12) & 0x1f; /* 32x2 PTEs */
5542 + ulong mask, phash, cmp, pteg, cmp_ea, *eap;
5545 + // printk("lookup_603_pte %08lX\n", ea);
5548 + p = &MMU.ptes_d_603[ind];
5549 + eap = &MMU.ptes_d_ea_603[ind];
5551 + p = &MMU.ptes_i_603[ind];
5552 + eap = &MMU.ptes_i_ea_603[ind];
5554 + cmp_ea = ea & 0x0ffff000;
5555 + for( ; ind < 64 ; ind += 32, p += 32, eap += 32 ) {
5556 + if( *eap == cmp_ea && p->vsid == vsid ) {
5561 + mask = MMU.hash_mask >> 6;
5563 + /* calculate primary and secondary PTEG */
5564 + phash = (cmp_ea >> 12) ^ (vsid & 0x7ffff);
5565 + pteg = ((phash & mask) << 6);
5566 + MREGS.spr[S_HASH1] = MMU.hash_mbase + pteg;
5567 + MREGS.spr[S_HASH2] = MMU.hash_mbase + (pteg ^ (mask << 6));
5569 + /* construct compare word */
5570 + cmp = BIT(0) | (vsid <<7) | (cmp_ea >> 22);
5572 + MREGS.spr[S_DCMP] = cmp;
5573 + MREGS.spr[S_DMISS] = ea;
5575 + MREGS.spr[S_ICMP] = cmp;
5576 + MREGS.spr[S_IMISS] = ea;
5582 +static inline mPTE_t *
5583 +lookup_mac_pte( kernel_vars_t *kv, ulong vsid, ulong ea )
5585 + ulong phash, cmp, pteg, *p;
5589 + /* make sure the hash is mapped... */
5590 + if( !MMU.hash_base )
5593 + /* we are only interested in the page index */
5595 + mask = MMU.hash_mask>>6;
5597 + /* calculate primary hash function */
5598 + phash = (ea >> 12) ^ (vsid & 0x7ffff);
5599 + pteg = ((phash & mask) << 6);
5601 + /* construct compare word */
5602 + cmp = BIT(0) | (vsid <<7) | ((ea&0x0fffffff)>>22);
5604 + /* look in primary PTEG */
5605 + p = (ulong*)((ulong)MMU.hash_base + pteg);
5606 + for( i=0; i<8; i++, p+=2 )
5608 + return (mPTE_t*)p;
5610 + /* look in secondary PTEG */
5611 + p = (ulong*)( (ulong)MMU.hash_base + (pteg ^ (mask << 6)) );
5614 + for( i=0; i<8; i++,p+=2 )
5616 + return (mPTE_t*)p;
5621 +lookup_mphys( kernel_vars_t *kv, fault_param_t *pb, const int ebits )
5623 + ulong ea = (pb->ea & ~0xfff);
5626 + int sv_mode, i, sbits;
5631 + if( !use_mmu(ebits) ) {
5632 + pb->mphys_page = ea;
5633 + pb->pte1 = NO_MMU_PTE1;
5638 + segr = *(mSEGREG*)&MREGS.segr[ea>>28];
5639 + sv_mode = !(MREGS.msr & MSR_PR);
5641 + /* I/O segment? */
5643 + /* Memory forced (601/604)? Note that the 601 uses I/O segments
5644 + * even if translation is off(!). We don't implement this though.
5646 + ulong sr = MREGS.segr[ea>>28];
5647 + BUMP( memory_forced_segment );
5649 + if( ((sr >> 20) & 0x1ff) != 0x7f )
5650 + return RVEC_MMU_IO_SEG_ACCESS;
5651 + pb->mphys_page = (ea & 0x0ffff000) | ((sr & 0xf)<<28);
5652 + pb->pte1 = NO_MMU_PTE1;
5657 + /* BAT translation? 0-3 = IBATs, 4-7 = DBATs. Separated I/D BATS, hace 3/8/99 */
5658 + bp = is_dsi(ebits) ? &MMU.bats[4] : &MMU.bats[0];
5659 + for( i=0; i<4; i++, bp++ ) {
5662 + if( (sv_mode && !bp->vs) || (!sv_mode && !bp->vp) )
5664 + if( ea < bp->base || ea > bp->base+bp->size-1 )
5667 + pb->mphys_page = ea - bp->base + bp->mbase;
5668 + pb->pte1 = bp->pp | (bp->wimg << 3) | PTE1_R | PTE1_C;
5669 + pb->key = sv_mode ? bp->ks : bp->ku;
5674 + if( (MREGS.spr[S_PVR] >> 16) == 3 ) {
5675 + if( lookup_603_pte(kv, segr.vsid, ea, is_dsi(ebits), &mpte) )
5676 + return is_dsi(ebits) ? (is_write(ebits) ? RVEC_DMISS_STORE_TRAP :
5677 + RVEC_DMISS_LOAD_TRAP) : RVEC_IMISS_TRAP;
5679 + pb->mpte = NULL; /* imporant */
5680 + pb->mphys_page = (mpte->rpn << 12);
5681 + pb->pte1 = ((ulong*)mpte)[1] & (PTE1_PP | PTE1_WIMG | PTE1_R | PTE1_C);
5682 + pb->key = sv_mode ? segr.ks : segr.kp;
5686 + /* mac page table lookup */
5687 + if( (mpte=lookup_mac_pte(kv, segr.vsid, ea)) ) {
5689 + pb->mphys_page = (mpte->rpn << 12);
5690 + pb->pte1 = ((ulong*)mpte)[1] & (PTE1_PP | PTE1_WIMG | PTE1_R | PTE1_C);
5691 + pb->key = sv_mode ? segr.ks : segr.kp;
5694 + /* mac page fault */
5695 + sbits = EBIT_PAGE_FAULT | (ebits & EBIT_IS_WRITE); /* r/w bit + page_fault */
5696 + RVEC_RETURN_2( &MREGS, is_dsi(ebits) ? RVEC_DSI_TRAP : RVEC_ISI_TRAP, pb->ea, sbits );
5700 +/* PTE0 must be fully initialized on entry (with V=1 and H=0).
5701 + * The pte_present flag should be set from srr1/dsisr bit and indicates
5702 + * that a valid PTE might already be present in the hash table.
5704 +static inline ulong *
5705 +find_pte_slot( ulong ea, ulong *pte0, int pte_present, int *pte_replaced )
5707 + static int grab_add=0;
5708 + ulong phash, pteg, *p, cmp = *pte0;
5709 + ulong *primary, *secondary;
5712 + /* we are only interested in the page index */
5715 + /* primary hash function */
5716 + phash = (ea >> 12) ^ (PTE0_VSID(cmp) & 0x7ffff);
5718 + pteg = (phash << 6) & ptehash.pteg_mask;
5719 + primary = (ulong*)((ulong)ptehash.base + pteg);
5721 + pteg = pteg ^ ptehash.pteg_mask;
5722 + secondary = (ulong*)((ulong)ptehash.base + pteg);
5724 + if( pte_present ) {
5725 + *pte_replaced = 1;
5727 + /* look in primary PTEG */
5729 + for( i=0; i<8; i++, p+=2 )
5733 + /* look in secondary PTEG */
5736 + for( i=0; i<8; i++, p+=2 )
5741 + /* we will actually come here if the previous PTE
5742 + * was only available in the on-chip cache.
5745 + *pte_replaced = 0;
5747 + /* free slot in primary PTEG? */
5748 + for( p=primary, i=0; i<8; i++, p+=2 )
5749 + if( !(*p & BIT(0)) )
5752 + /* free slot in secondary PTEG? */
5753 + for( p=secondary, i=0; i<8; i++, p+=2 )
5754 + if( !(*p & BIT(0)) ) {
5759 + /* steal a primary PTEG slot */
5760 + grab_add = (grab_add+1) & 0x7;
5762 + /* printk("Grabbing slot %d, EA %08X\n",grab_add, ea ); */
5763 + return (ulong*)((ulong)primary + grab_add * sizeof(ulong[2]));
5767 +insert_pte( kernel_vars_t *kv, fault_param_t *pb, const int ebits )
5769 + ulong ea=pb->ea, mphys=pb->mphys_page;
5770 + ulong sr=pb->sr_base[ea>>28];
5771 + int status, pte_replaced;
5772 + pte_lvrange_t *lvrange;
5773 + ulong pte0, pte1, *slot;
5776 +#ifdef CONFIG_AMIGAONE
5777 + pte1 = PTE1_R | (pb->pte1 & (PTE1_R | PTE1_C | PTE1_WIMG))
5778 + | (is_write(ebits) ? 2:3);
5780 + pte1 = PTE1_M | PTE1_R | (pb->pte1 & (PTE1_R | PTE1_C | PTE1_WIMG))
5781 + | (is_write(ebits) ? 2:3);
5784 + /* PP and WIMG bits must set before the call to mphys_to_pte */
5785 + status = mphys_to_pte( kv, mphys, &pte1, is_write(ebits), &lvrange );
5787 + if( !status || (is_write(ebits) && (status & MAPPING_RO)) ) {
5788 + ulong addr = (mphys | (ea & 0xfff));
5789 + if( is_dsi(ebits) ) {
5790 + int rvec = is_write(ebits) ? RVEC_IO_WRITE : RVEC_IO_READ;
5791 + BUMP( io_read_write );
5792 + RVEC_RETURN_2( &MREGS, rvec, addr, NULL );
5794 + RVEC_RETURN_1( &MREGS, RVEC_BAD_NIP, addr );
5798 + /* tlbhash table hit? */
5799 + if( (ulong)(pb->mphys_page - MMU.hash_mbase) < (ulong)MMU.hash_mask ) {
5800 + /* printk("hash_table_hit at %08lX\n", pb->ea ); */
5801 + MMU.pthash_sr = sr;
5802 + MMU.pthash_ea_base = ea & ~MMU.hash_mask;
5804 + /* user read (always), superuser r/w */
5806 + pte1 |= is_write(ebits) ? 1:3;
5807 + /* write accesses of the page table are handled in ptintercept.S */
5810 + pte0 = PTE0_V | (sr << 7) | ((ea>>22) & PTE0_API);
5811 + slot = find_pte_slot( ea, &pte0, !is_page_fault(ebits), &pte_replaced );
5813 + lvptr = (status & MAPPING_PHYSICAL) ? 0 : (pte1 & PTE1_RPN);
5815 + /* the RC bits should correspond to the is_write flag; this prevents the
5816 + * CPU from stamping RC bits unnecessary (besides, the kernel seems to
5817 + * assume no RC-stamps will ever occur so RC-stamping is unsafe).
5819 + if( is_write(ebits) )
5821 + pte1 |= SMP_PTE1_M;
5823 + /* if a page-out occurs between prepare_pte_insert() and the pte_inserted()
5824 + * call, then the PTE slot is zeroed out.
5826 + if( !(status & MAPPING_PHYSICAL) ) {
5828 + if( is_write(ebits) )
5829 + lvpage_dirty( kv, lvptr );
5831 + pte1 &= ~PTE1_RPN;
5833 + /* zero pages should work just fine now... */
5834 + pte1 |= get_phys_page( kv, lvptr, is_write(ebits) );
5835 + /* pte1 |= get_phys_page( kv, lvptr, !(status & MAPPING_RO) ); */
5838 + if( status & MAPPING_FB_ACCEL )
5839 + video_pte_inserted( kv, lvptr, slot, pte0, pte1, ea );
5841 + BUMP( page_fault_ctr );
5842 + DEBUG_print_inserted_pte( slot, pte0, pte1, ea );
5844 + __store_PTE( ea, slot, pte0, pte1 );
5846 + pte_inserted( kv, ea, (char*)lvptr, lvrange, slot, pb->vsid_eptr[ea>>28], sr );
5848 + /* debugger support */
5849 + if( (kv->break_flags & BREAK_EA_PAGE) && (ea & ~0xfff) == MREGS.mdbg_ea_break )
5850 + RVEC_RETURN_1( &MREGS, RVEC_BREAK, BREAK_EA_PAGE );
5856 +page_fault( kernel_vars_t *kv, fault_param_t *pb, const int ebits )
5858 + int topind = pb->ea >> 28;
5861 + BUMP( access_exception_ctr );
5863 + if( (ret=lookup_mphys(kv, pb, ebits)) ) {
5864 + BUMP(mac_page_fault);
5868 + /* printk("MPHYS_PAGE: %08lX, pp %d, key %d, wimg %d, mpte %p\n",
5869 + pb->mphys_page, (pb->pte1 & 3), pb->key, ((pb->pte1 >> 3) & 0xf), pb->mpte ); */
5871 + /* check privileges */
5872 + ind = (is_write(ebits) ? 8:0) | (pb->pte1 & PTE1_PP) | (pb->key?4:0);
5873 + if( priv_viol_table[ind] ) {
5874 + /* r/w bit + priv. violation */
5875 + int sbits = EBIT_PROT_VIOL | (ebits & EBIT_IS_WRITE);
5876 + BUMP(mac_priv_violation);
5877 + RVEC_RETURN_2( &MREGS, is_dsi(ebits) ? RVEC_DSI_TRAP : RVEC_ISI_TRAP, pb->ea, sbits );
5880 + /* stamp R/C bits (mpte is NULL if this is not a page translation). */
5883 + if( is_write(ebits) )
5886 + /* stamp pthash_inuse_bit */
5887 + if( MMU.pthash_inuse_bits ) {
5888 + int nr = ((int)pb->mpte - (int)MMU.hash_base) >> 3;
5889 + set_bit_mol( nr, MMU.pthash_inuse_bits );
5893 + /* perform memory allocations if necessary; we are not allowed to
5894 + * do this later (the mtable insertion must be atomic)
5896 + if( mtable_memory_check(kv) )
5897 + return RVEC_NOP; /* out of memory */
5899 + /* the vsid entry might have been released */
5900 + if( !pb->vsid_eptr[topind] )
5903 + return insert_pte( kv, pb, ebits );
5907 +/************************************************************************/
5908 +/* VSID allocation (the normal VSID lookup occurs in vsid.S) */
5909 +/************************************************************************/
5912 +fix_sr( kernel_vars_t *kv, int sr, int mapped )
5914 + int macvsid = mapped ? (MREGS.segr[sr] & VSID_MASK) : VSID_MASK + 1 + sr;
5915 + ulong user_sr, sv_sr;
5916 + vsid_ent_t *r = vsid_get_user_sv( kv, macvsid, &user_sr, &sv_sr );
5923 + int value = MREGS.segr[sr];
5924 + int nbit = value & VSID_N;
5926 + MMU.user_sr[sr] = ((value & VSID_Kp) ? user_sr : sv_sr) | nbit;
5927 + MMU.sv_sr[sr] = ((value & VSID_Ks) ? user_sr : sv_sr) | nbit;
5929 + MMU.unmapped_vsid[sr] = r;
5930 + MMU.unmapped_sr[sr] = user_sr;
5932 + invalidate_splitmode_sr( kv );
5936 +/************************************************************************/
5937 +/* Exception entrypoints (called from assembly) */
5938 +/************************************************************************/
5940 +extern int dsi_exception( kernel_vars_t *kv, ulong dar, ulong dsisr );
5941 +extern int isi_exception( kernel_vars_t *kv, ulong nip, ulong srr1 );
5944 +dsi_exception( kernel_vars_t *kv, ulong dar, ulong dsisr )
5946 + int ebits, topind = dar >> 28;
5949 + /* printk("DSI: EA %08lX, DSISR %08lX\n", dar, dsisr ); */
5950 + if( dsisr & 0x84500000 ) /* 0,5,9,11 */
5951 + RVEC_RETURN_2( &MREGS, RVEC_UNUSUAL_DSISR_BITS, dar, dsisr );
5954 + ebits = EBIT_IS_DSI | (dsisr & (EBIT_PAGE_FAULT | EBIT_PROT_VIOL | EBIT_IS_WRITE))
5955 + | ((MREGS.msr & MSR_DR) ? EBIT_USE_MMU : 0);
5957 + pb.vsid_eptr = (MREGS.msr & MSR_DR) ? MMU.vsid : MMU.unmapped_vsid;
5958 + pb.sr_base = (ulong*)((ulong)MMU.sr_data - kv->kvars_tophys_offs);
5960 + /* segment register switch-in required? */
5961 + if( !pb.vsid_eptr[topind] ) {
5962 + fix_sr( kv, topind, use_mmu(ebits) );
5966 + return page_fault( kv, &pb, ebits );
5970 +isi_exception( kernel_vars_t *kv, ulong nip, ulong srr1 )
5973 + /* printk("ISI: NIP %08lX, SRR1 %08lX\n", nip, srr1 ); */
5975 + pb.vsid_eptr = (MREGS.msr & MSR_IR) ? MMU.vsid : MMU.unmapped_vsid;
5977 + if( srr1 & EBIT_PAGE_FAULT ) {
5978 + int ebits = EBIT_PAGE_FAULT | ((MREGS.msr & MSR_IR) ? EBIT_USE_MMU : 0);
5980 + pb.sr_base = (ulong*)((ulong)MMU.sr_inst - kv->kvars_tophys_offs);
5981 + BUMP(isi_page_fault);
5982 + return page_fault( kv, &pb, ebits );
5984 + if( srr1 & EBIT_NO_EXEC ) {
5985 + int sr = nip >> 28;
5986 + if( !pb.vsid_eptr[sr] ) {
5987 + fix_sr( kv, sr, (MREGS.msr & MSR_IR) );
5990 + /* printk("Guarded memory access at %08lX\n", nip ); */
5991 + RVEC_RETURN_2( &MREGS, RVEC_ISI_TRAP, nip, EBIT_NO_EXEC );
5994 + BUMP(isi_prot_violation);
5995 + /* must be privileges violation */
5996 + RVEC_RETURN_2( &MREGS, RVEC_ISI_TRAP, nip, EBIT_PROT_VIOL );
6000 +/************************************************************************/
6001 +/* debugger functions */
6002 +/************************************************************************/
6005 +dbg_translate_ea( kernel_vars_t *kv, int context, ulong va, int *ret_mphys, int data_access )
6007 + int ebits = data_access ? EBIT_IS_DSI : 0;
6010 + memset( &pb, 0, sizeof(pb) );
6013 + switch( context ) {
6014 + case kContextUnmapped:
6015 + pb.sr_base = MMU.unmapped_sr;
6017 + case kContextMapped_S:
6018 + pb.sr_base = MMU.sv_sr;
6019 + ebits |= EBIT_USE_MMU;
6021 + case kContextMapped_U:
6022 + pb.sr_base = MMU.user_sr;
6023 + ebits |= EBIT_USE_MMU;
6029 + if( lookup_mphys(kv, &pb, ebits) )
6031 + *ret_mphys = pb.mphys_page | (va & 0xfff);
6035 +++ b/drivers/macintosh/mol/hash.c
6038 + * Creation Date: <2004/02/14 11:42:19 samuel>
6039 + * Time-stamp: <2004/03/13 14:25:00 samuel>
6043 + * CPU PTE hash handling
6045 + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
6047 + * This program is free software; you can redistribute it and/or
6048 + * modify it under the terms of the GNU General Public License
6049 + * as published by the Free Software Foundation
6053 +#include "archinclude.h"
6055 +#include "kernel_vars.h"
6057 +#include "mmu_contexts.h"
6058 +#include "asmfuncs.h"
6061 +#include "mtable.h"
6062 +#include "performance.h"
6063 +#include "context.h"
6068 +hash_info_t ptehash;
6078 +create_pte_hash( void )
6080 + ulong size = 1024*128; /* 128K is the kmalloc limit */
6081 + ulong sdr1, mask, base, physbase;
6084 + if( !(p=kmalloc_cont_mol(size)) )
6086 + memset( p, 0, size );
6088 + physbase = tophys_mol( (char*)base );
6090 + if( (physbase & (size-1)) ) {
6092 + printk("Badly aligned SDR1 allocation - 64K wasted\n");
6094 + offs = ((physbase + size) & ~(size-1)) - physbase;
6098 + mask = (size-1) >> 6;
6099 + sdr1 = mask >> 10;
6102 + hs.allocation = p;
6103 + ptehash.sdr1 = sdr1;
6104 + ptehash.base = (ulong*)base;
6106 + printk("SDR1 = %08lX\n", sdr1 );
6115 + memset( &ptehash, 0, sizeof(ptehash) );
6118 + sdr1 = _get_sdr1();
6120 + /* linux does not use SDR1 on the 603[e] */
6122 + create_pte_hash();
6123 + sdr1 = ptehash.sdr1;
6124 + _set_sdr1( sdr1 );
6125 + hs.sdr1_loaded = 1;
6128 + /* sharing the hash under darwin is too complicated */
6129 + create_pte_hash();
6130 + sdr1 = ptehash.sdr1;
6136 + ptehash.sdr1 = sdr1;
6137 + ptehash.pteg_mask = (((sdr1 & 0x1ff) << 10) | 0x3ff) << 6;
6138 + ptehash.pte_mask = ptehash.pteg_mask | 0x38;
6139 + ptehash.physbase = sdr1 & ~0xffff;
6141 + if( !ptehash.base ) {
6142 + hs.hash_mapped = 1;
6143 + ptehash.base = map_hw_hash( ptehash.physbase, ptehash.pte_mask + 8 );
6146 + return !ptehash.base;
6150 +cleanup_hash( void )
6152 + if( hs.hash_mapped )
6153 + unmap_hw_hash( ptehash.base );
6155 + if( hs.sdr1_loaded )
6157 + if( hs.allocation )
6158 + kfree_cont_mol( hs.allocation );
6160 + memset( &ptehash, 0, sizeof(ptehash) );
6161 + memset( &hs, 0, sizeof(hs) );
6164 +++ b/drivers/macintosh/mol/include/actions.h
6167 + * Creation Date: <2004/01/31 13:08:42 samuel>
6168 + * Time-stamp: <2004/03/07 14:25:23 samuel>
6174 + * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
6176 + * This program is free software; you can redistribute it and/or
6177 + * modify it under the terms of the GNU General Public License
6185 +/* Certain assembly macros (like LI_PHYS) adds meta information to a special
6186 + * ELF segment. This information is parsed when the module is loaded/used and
6187 + * the appropriate action is performed (a few assembly instruction are typically
6190 + * Actions with lower opcodes are performed before actions with higher opcodes.
6193 +#define ACTION_LIS_SPECVAR_H 1 /* dreg, special_var_index */
6194 +#define ACTION_ORI_SPECVAR_L 2 /* dreg*32 + sreg, special_var_index */
6195 +#define ACTION_LI_PHYS 3 /* dreg, addr_offs */
6196 +#define ACTION_LWZ_PHYSADDR_R 4 /* dreg*32 + reg, addr_offs */
6197 +#define ACTION_TOPHYS 5 /* dreg*32 + sreg */
6198 +#define ACTION_TOVIRT 6 /* dreg*32 + sreg */
6199 +#define ACTION_RELOCATE_LOW 7 /* code_size, destvar, code... */
6200 +#define ACTION_VRET 8 /* vector [special, used by RELOC_HOOK] */
6201 +#define ACTION_FIX_SPRG2 9 /* scratch_reg */
6203 +#define FLUSH_CACHE_ACTION 9 /* flush the icache at this point */
6205 +#define ACTION_HOOK_FUNCTION 10
6206 +#define ACTION_RELOC_HOOK 11 /* trigger, size, vret_action#, vret_offs */
6207 +#define MAX_NUM_ACTIONS 12
6209 +/* Special vars (ACTION_*_SPECVAR) */
6210 +#define SPECVAR_SESSION_TABLE 1
6212 +/* Function hooks (ACTION_HOOK_FUNCTION) */
6213 +#define FHOOK_FLUSH_HASH_PAGE 1
6215 +#ifndef __ASSEMBLY__
6217 + int action; /* ACTION_xxx */
6218 + int offs; /* target instruction offset (from r__reloctable_start) */
6219 + int params[1]; /* parameters */
6221 +#endif /* __ASSEMBLY__ */
6224 +/************************************************************************/
6225 +/* assembly macros */
6226 +/************************************************************************/
6229 + * WARNING: These macros uses the 9 label (the OSX assembler
6230 + * can only use labels (0-9).
6233 +#ifdef __ASSEMBLY__
6236 +#define ACTIONS_SECTION .text 95
6237 +#define ACTIONS_OFFS_SECTION .text 96
6240 +#define ACTIONS_SECTION .section __TEXT,__areloc
6241 +#define ACTIONS_OFFS_SECTION .section __DATA,__areloc_offs
6244 +mDEFINE(ACTION_PB, [action], [
6248 + .long _action /* action */
6249 + .long (9b - r__reloctable_start) /* target PC */
6251 + ACTIONS_OFFS_SECTION
6252 + .long (9b - r__actions_section - 8) /* store pointer to PB */
6256 +mDEFINE(ACTION_1, [action, p1], [
6257 + ACTION_PB( _action )
6260 + nop /* replaced */
6263 +mDEFINE(ACTION_21, [action, p1, p2], [
6264 + ACTION_PB( _action )
6267 + nop /* replaced */
6270 +mDEFINE(ACTION_2, [action, p1, p2], [
6271 + ACTION_PB( _action )
6274 + nop /* replaced */
6275 + nop /* replaced */
6278 +mDEFINE(ACTION_13, [action, p1], [
6279 + ACTION_PB( _action )
6282 + nop /* replaced */
6283 + nop /* replaced */
6284 + nop /* replaced */
6288 + /* replaced with lis dreg,addr@ha ; addi dreg,dreg,addr@l */
6289 +#define LI_PHYS( dreg, addr ) \
6290 + ACTION_2( ACTION_LI_PHYS, dreg, (addr - r__reloctable_start) )
6292 + /* replaced with addis dreg,reg,addr@ha ; lwz dreg,addr@lo(dreg). */
6293 +#define LWZ_PHYSADDR_R( dreg, addr, reg ) \
6294 + ACTION_2( ACTION_LWZ_PHYSADDR_R, (dreg*32 + reg), (addr - r__reloctable_start) )
6296 +#define LWZ_PHYS( dreg, addr ) \
6297 + LWZ_PHYSADDR_R( dreg, addr, 0 );
6299 + /* syntax: tophys rD,rS */
6300 +MACRO(tophys, [dreg, sreg], [
6301 + ACTION_1( ACTION_TOPHYS, (_dreg * 32 + _sreg) )
6303 + /* syntax: tovirt rD,rS */
6304 +MACRO(tovirt, [dreg, sreg], [
6305 + ACTION_1( ACTION_TOVIRT, (_dreg * 32 + _sreg) )
6308 + /* syntax: lis_specvar_ha rD,SPECIAL_VAR */
6309 +MACRO(lis_svh, [dreg, specvariable], [
6310 + ACTION_21( ACTION_LIS_SPECVAR_H, _dreg, _specvariable )
6313 + /* syntax: addi_specvar_ha rD,rS,SPECIAL_VAR */
6314 +MACRO(ori_svl, [dreg, sreg, specvariable], [
6315 + ACTION_21( ACTION_ORI_SPECVAR_L, (_dreg * 32)+_sreg, _specvariable )
6318 + /* syntax: FIX_SPRG2 rN */
6319 +MACRO(fix_sprg2, [reg], [
6320 + /* only darwin needs this (sprg_a0 holds bits describing the CPU) */
6322 + ACTION_13( ACTION_FIX_SPRG2, _reg )
6326 +mDEFINE(RELOC_LOW, [destvar], [
6327 + ACTION_PB( ACTION_RELOCATE_LOW )
6328 + .long _destvar[]_end - _destvar[]_start
6329 + .long EXTERN([]_destvar)
6333 +mDEFINE(RELOC_LOW_END, [destvar], [
6339 +#endif /* __ASSEMBLY__ */
6342 +#endif /* _H_ACTIONS */
6344 +++ b/drivers/macintosh/mol/include/alloc.h
6347 + * Creation Date: <2002/01/13 16:35:18 samuel>
6348 + * Time-stamp: <2004/01/25 17:36:49 samuel>
6352 + * Memory allocation and mappings
6354 + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
6356 + * This program is free software; you can redistribute it and/or
6357 + * modify it under the terms of the GNU General Public License
6365 +#include <linux/slab.h>
6366 +#include <linux/vmalloc.h>
6367 +#include <linux/mm.h>
6368 +#include <asm/uaccess.h>
6371 +#include <asm/cacheflush.h>
6372 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
6373 +#include <asm/io.h>
6377 +static inline void *kmalloc_mol( int size ) {
6378 + return kmalloc( size, GFP_KERNEL );
6380 +static inline void kfree_mol( void *p ) {
6383 +static inline void *vmalloc_mol( int size ) {
6384 + return vmalloc( size );
6386 +static inline void vfree_mol( void *p ) {
6389 +static inline ulong alloc_page_mol( void ) {
6390 + return get_zeroed_page( GFP_KERNEL );
6392 +static inline void free_page_mol( ulong addr ) {
6393 + free_page( addr );
6395 +static inline void *kmalloc_cont_mol( int size ) {
6396 + return kmalloc( size, GFP_KERNEL );
6398 +static inline void kfree_cont_mol( void *addr ) {
6401 +static inline ulong tophys_mol( void *addr ) {
6402 + return virt_to_phys(addr);
6404 +static inline void flush_icache_mol( ulong start, ulong stop ) {
6405 + flush_icache_range( start, stop );
6407 +static inline void *map_phys_range( ulong paddr, ulong size, char **ret_addr ) {
6408 + /* Warning: This works only for certain addresses... */
6409 + *ret_addr = phys_to_virt(paddr);
6410 + return (void*)(-2); /* dummy */
6412 +static inline void unmap_phys_range( void *handle ) {}
6415 +#endif /* _H_ALLOC */
6417 +++ b/drivers/macintosh/mol/include/archinclude.h
6420 + * Creation Date: <2002/01/12 22:11:51 samuel>
6421 + * Time-stamp: <2004/04/10 22:27:41 samuel>
6427 + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
6429 + * This program is free software; you can redistribute it and/or
6430 + * modify it under the terms of the GNU General Public License
6431 + * as published by the Free Software Foundation
6435 +#ifndef _H_ARCHINCLUDE
6436 +#define _H_ARCHINCLUDE
6438 +//#define PERF_MONITOR
6439 +//#define PERFORMANCE_INFO /* collect performance statistics */
6440 +//#define PERFORMANCE_INFO_LIGHT /* sample only the most important counters */
6442 +#include "mol_config.h"
6443 +#include "kconfig.h"
6445 +#include <linux/version.h>
6447 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
6448 +#include <linux/utsrelease.h>
6451 +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
6452 +#include <linux/config.h>
6454 +#include <linux/autoconf.h>
6457 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6461 +#ifndef __ASSEMBLY__
6462 +#include <linux/kernel.h>
6463 +#include <asm/atomic.h>
6464 +#include <linux/sched.h> /* needed by <asm/mmu_context.h> */
6465 +#include <asm/mmu_context.h>
6466 +#include <asm/time.h>
6470 +/* these are declared, but we just want to be sure the definition does not change */
6471 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
6472 +extern int flush_hash_pages( unsigned context, unsigned long va, unsigned long pmdval, int count ); /* 2.6 */
6474 +extern int flush_hash_page( unsigned context, unsigned long va, pte_t *ptep ); /* 2.5 */
6475 +#endif /* Linux 2.6 */
6477 +#endif /* __ASSEMBLY__ */
6480 +#define compat_flush_hash_pages flush_hash_pages
6481 +#define compat_hash_table_lock mmu_hash_lock
6483 +#define compat_flush_hash_pages flush_hash_page
6484 +#define compat_hash_table_lock hash_table_lock
6488 +#define ENOSYS_MOL ENOSYS
6489 +#define EFAULT_MOL EFAULT
6492 +#define IS_DARWIN 0
6495 +#endif /* _H_ARCHINCLUDE */
6497 +++ b/drivers/macintosh/mol/include/asm.m4
6500 + * Creation Date: <2001/12/30 20:08:53 samuel>
6501 + * Time-stamp: <2002/01/14 00:48:09 samuel>
6505 + * m4 initialization (m4 is used as an assembly preprocessor)
6507 + * Copyright (C) 2001, 2002, 2004 Samuel Rydh (samuel@ibrium.se)
6509 + * This program is free software; you can redistribute it and/or
6510 + * modify it under the terms of the GNU General Public License
6511 + * as published by the Free Software Foundation
6515 +/* This end-of-quote matches the start-of-quote in mol_config.h */
6520 +dnl m4 macros to avoid in header files (we can not rename these)
6521 +dnl ==========================================================
6522 +dnl shift, eval, expr, decr, incr, ifelse, popdef, pushdef
6525 +dnl **************************************************************
6526 +dnl * Rename to reduce namespace conflicts
6527 +dnl **************************************************************
6529 +dnl *** Changing the name of built-in macros using defn does not always work ***
6531 +undefine([changecom])
6532 +undefine([changequote])
6533 +dnl undefine([decr])
6535 +dnl undefine([divert])
6537 +undefine([errprint])
6538 +dnl undefine([eval])
6539 +dnl undefine([expr])
6544 +dnl undefine([ifelse])
6545 +dnl undefine([incr])
6547 +undefine([include])
6549 +undefine([maketemp])
6551 +undefine([patsubst])
6552 +dnl undefine([popdef])
6553 +dnl undefine([pushdef])
6555 +dnl undefine([shift])
6556 +undefine([sinclude])
6561 +undefine([translit])
6562 +undefine([traceoff])
6563 +undefine([traceon])
6564 +undefine([undivert])
6566 +dnl undefine([__gnu__])
6567 +dnl undefine([__unix__])
6569 +dnl Uncomment to list m4 definitions
6572 +/************************************************************************/
6574 +/************************************************************************/
6577 +dnl WARNING - M4 BUG IN MacOS X (10.1.2):
6578 +dnl eval() in MacOS X (10.1.2) handles '&' as '&&' and '|' as '||'.
6581 +/* FORLOOP(var, from, to, [body var...]) */
6582 +define([mFORLOOP], [pushdef([$1], [$2])_mFORLOOP([$1], [$2], [$3], [$4])popdef([$1])])
6583 +define([_mFORLOOP], [$4[]ifelse($1, [$3], ,
6584 + [define([$1], incr($1))_mFORLOOP([$1], [$2], [$3], [$4])])])
6586 +define([mFIRST],[$1])
6587 +define([mCONCAT_C],[ [$@] ])
6589 +/* FOREACH(var, [item1, ...], [body var ...]) */
6590 +define([mFOREACH],[pushdef([$1],mFIRST($2))_mFOREACH([$1],[shift($2)],[$3])popdef([$1])])
6591 +define([_mFOREACH],[$3] [ifelse(mFIRST($2),,,[define([$1],mFIRST($2)) _mFOREACH([$1],[shift($2)],[$3])])])
6594 +/******************** Nice macro definitions **************************/
6596 +/* MACRO(name, [param1, ...], [body _param1 ...]) */
6600 + mFOREACH([i],[$2],[ pushdef(_[]i,\i) ])
6603 + mFOREACH([i],[$2],[ popdef(_[]i) ])
6609 + mFOREACH([i],[$2],[ pushdef(_[]i,[$[]]_n) define([_n],incr(_n)) ])
6612 + mFOREACH([i],[$2],[ popdef(_[]i) ])
6616 +define([MACRO_0], [MACRO([$1],[_dummy_param_],[$2])])
6619 +/* mDEFINE(name, [param1, ...], [body _param1 ...]) */
6620 +define([mDEFINE], [
6622 + mFOREACH([i],[$2],[ pushdef(_[]i,[$[]]_n) define([_n],incr(_n)) ])
6623 + define([$1], mCONCAT_C($3) )
6624 + mFOREACH([i],[$2],[ popdef(_[]i) ])
6629 +/* rLABEL(label): b label_b ; b label_f */
6631 +ifdef([$1]_curnum,,[$1[]f:])dnl
6632 + define([_tmp_curnum],ifdef($1[]_curnum, [eval($1_curnum+1)], 1)) dnl
6633 + define([$1]_curnum,_tmp_curnum)dnl
6634 + define([$1]f,$1_[]eval($1_curnum[]+1) )dnl
6635 + define([$1]b,$1_[]$1_curnum[] )
6636 +$1[]_[]$1_curnum[]dnl
6641 +++ b/drivers/macintosh/mol/include/asm_offsets.inc
6644 + * Creation Date: <2001/10/20 17:51:10 samuel>
6645 + * Time-stamp: <2004/02/21 21:38:27 samuel>
6647 + * <asm_offsets.inc>
6649 + * Extra offsets (included from asm_offsets.c)
6651 + * Copyright (C) 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
6653 + * This program is free software; you can redistribute it and/or
6654 + * modify it under the terms of the GNU General Public License
6655 + * as published by the Free Software Foundation
6659 +extern void extra( void );
6664 + DEFINE(SIZE_OF_KERNEL_VARS, sizeof( kernel_vars_t ));
6666 + ST_DEF( ST_MAGIC, magic );
6667 + ST_DEF( ST_KVARS_PH, kvars_ph );
6669 + K_DEF( K_EMUACCEL_PAGE, emuaccel_page );
6670 + K_DEF( K_EMUACCEL_PAGE_PHYS, emuaccel_page_phys );
6671 + K_DEF( K_EMUACCEL_MPHYS, emuaccel_mphys );
6672 + K_DEF( K_EMUACCEL_SIZE, emuaccel_size );
6674 + K_DEF( K_KERNEL_VARS, kvars_virt );
6675 + K_DEF( K_BREAK_FLAGS, break_flags );
6676 +#ifdef PERFORMANCE_INFO
6677 + K_DEF( K_ASM_BUMP_CNTRS, asm_bump_cntr );
6678 + K_DEF( K_ASM_TICK_STAMPS, asm_tick_stamp );
6681 + K_DEF( K_ILLEGAL_SR, mmu.illegal_sr );
6682 + K_DEF( K_CUR_SR_BASE, mmu.cur_sr_base );
6683 + K_DEF( K_SR_DATA, mmu.sr_data );
6684 + K_DEF( K_SR_INST, mmu.sr_inst );
6686 + K_DEF( K_UNMAPPED_SR_BASE, mmu.unmapped_sr[0] );
6687 + K_DEF( K_USER_SR_BASE, mmu.user_sr[0] );
6688 + K_DEF( K_SV_SR_BASE, mmu.sv_sr[0] );
6689 + K_DEF( K_SPLIT_SR_BASE, mmu.split_sr[0] );
6690 + K_DEF( K_VSID_ENT_BASE, mmu.vsid[0] );
6693 + K_DEF( K_OS_SDR1, mmu.os_sdr1 );
6694 + K_DEF( K_MOL_SDR1, mmu.mol_sdr1 );
6695 + DEFINE( SKIPLIST_NEXT, offsetof(skiplist_el_t, level[0].next_phys) );
6698 + DEFINE( SKIPLIST_NEXT, offsetof(skiplist_el_t, level[0].next) );
6700 + DEFINE( SKIPLIST_LEVELSIZE, sizeof(skiplist_level_t) );
6701 + DEFINE( SKIPLIST_KEY, offsetof(skiplist_el_t, key) );
6702 + DEFINE( K_VSID_SL_ROOT_ELEM, offsetof(kernel_vars_t, mmu.vsid_sl.root)
6703 + - offsetof(skiplist_el_t, level));
6704 + K_DEF( K_VSID_SL_SLEVEL, mmu.vsid_sl.slevel );
6706 + K_DEF( K_IBAT0U_SAVE, _bp.ibat_save[0].word[0] );
6707 + K_DEF( K_IBAT0L_SAVE, _bp.ibat_save[0].word[1] );
6708 + K_DEF( K_IBAT1U_SAVE, _bp.ibat_save[1].word[0] );
6709 + K_DEF( K_IBAT1L_SAVE, _bp.ibat_save[1].word[1] );
6710 + K_DEF( K_IBAT2U_SAVE, _bp.ibat_save[2].word[0] );
6711 + K_DEF( K_IBAT2L_SAVE, _bp.ibat_save[2].word[1] );
6712 + K_DEF( K_IBAT3U_SAVE, _bp.ibat_save[3].word[0] );
6713 + K_DEF( K_IBAT3L_SAVE, _bp.ibat_save[3].word[1] );
6715 + K_DEF( K_DBAT0U_SAVE, _bp.dbat_save[0].word[0] );
6716 + K_DEF( K_DBAT0L_SAVE, _bp.dbat_save[0].word[1] );
6717 + K_DEF( K_DBAT1U_SAVE, _bp.dbat_save[1].word[0] );
6718 + K_DEF( K_DBAT1L_SAVE, _bp.dbat_save[1].word[1] );
6719 + K_DEF( K_DBAT2U_SAVE, _bp.dbat_save[2].word[0] );
6720 + K_DEF( K_DBAT2L_SAVE, _bp.dbat_save[2].word[1] );
6721 + K_DEF( K_DBAT3U_SAVE, _bp.dbat_save[3].word[0] );
6722 + K_DEF( K_DBAT3L_SAVE, _bp.dbat_save[3].word[1] );
6724 + K_DEF( K_SPLIT_DBAT0U, mmu.split_dbat0.word[0] );
6725 + K_DEF( K_SPLIT_DBAT0L, mmu.split_dbat0.word[1] );
6726 + K_DEF( K_TRANSL_DBAT0U, mmu.transl_dbat0.word[0] );
6727 + K_DEF( K_TRANSL_DBAT0L, mmu.transl_dbat0.word[1] );
6729 + K_DEF( K_TLBHASH_SR, mmu.pthash_sr );
6730 + K_DEF( K_TLBHASH_BASE_EA, mmu.pthash_ea_base );
6731 + K_DEF( K_HASH_MASK, mmu.hash_mask );
6732 + K_DEF( K_PTHASH_INUSE_PH, mmu.pthash_inuse_bits_ph );
6734 + /* fields private to the assembly files */
6735 + K_DEF( K_MSR, _bp._msr );
6737 + K_DEF( K_DEC_STAMP, _bp.dec_stamp );
6738 + K_DEF( K_INT_STAMP, _bp.int_stamp);
6740 + K_DEF( K_TMP_SCRATCH0, _bp.tmp_scratch[0] );
6741 + K_DEF( K_TMP_SCRATCH1, _bp.tmp_scratch[1] );
6742 + K_DEF( K_TMP_SCRATCH2, _bp.tmp_scratch[2] );
6743 + K_DEF( K_TMP_SCRATCH3, _bp.tmp_scratch[3] );
6745 + K_DEF( K_SPLIT_NIP_SEGMENT, _bp.split_nip_segment );
6747 + K_DEF( K_SPR_HOOKS, _bp.spr_hooks );
6749 + /* private to emulation.S */
6750 + K_DEF( K_MSR_SR_TABLE, _bp.msr_sr_table[0] );
6752 + /* io_page_t type */
6753 + IO_DEF( IOP_MAGIC, magic );
6754 + IO_DEF( IOP_MAGIC2, magic2 );
6755 + IO_DEF( IOP_MPHYS, mphys );
6756 + IO_DEF( IOP_ME_PHYS, me_phys );
6757 + IO_DEF( IOP_NEXT, next );
6758 + IO_DEF( IOP_USR_DATA, usr_data );
6760 + /****** New Low-level assembly implementation ***********/
6762 + K_DEF( K_EMULATOR_STACK, _bp.emulator_stack );
6763 + K_DEF( K_EMULATOR_TOC, _bp.emulator_toc );
6764 + K_DEF( K_EMULATOR_NIP, _bp.emulator_nip );
6765 + K_DEF( K_EMULATOR_MSR, _bp.emulator_msr );
6766 + K_DEF( K_EMULATOR_SPRG2, _bp.emulator_sprg2 );
6767 + K_DEF( K_EMULATOR_SPRG3, _bp.emulator_sprg3 );
6768 + K_DEF( K_EMULATOR_KCALL_NIP, _bp.emulator_kcall_nip );
6770 + K_DEF( K_EMULATOR_SR, mmu.emulator_sr );
6773 + K_DEF( K_KCALL_ROUTINE, kcall_routine );
6774 + K_DEF( K_KCALL_ARG0, kcall_args[0] );
6775 + K_DEF( K_KCALL_ARG1, kcall_args[1] );
6776 + K_DEF( K_KCALL_ARG2, kcall_args[2] );
6780 +++ b/drivers/macintosh/mol/include/asmdbg.h
6783 + * Creation Date: <2004/01/29 20:12:41 samuel>
6784 + * Time-stamp: <2004/03/06 13:17:36 samuel>
6790 + * Copyright (C) 2004 Samuel Rydh (samuel@ibrium.se)
6792 + * This program is free software; you can redistribute it and/or
6793 + * modify it under the terms of the GNU General Public License
6802 +/************************************************************************/
6803 +/* Performance Statistics */
6804 +/************************************************************************/
6806 +#ifdef PERFORMANCE_INFO
6807 + define([_bump_ind_], 0)
6809 +#define __BUMP( str ) \
6811 +debug_str_[]_bump_ind_: ;\
6812 + .if (_bump_ind_ >= NUM_ASM_BUMP_CNTRS) ;\
6813 + .print "** too many BUMP counters **" ; .fail 1 ;\
6815 + .ascii str "\0" ;\
6818 + .long (debug_str_[]_bump_ind_-__start_bumptable) ;\
6820 + stw r3,xDEBUG_SCR1(r1) ;\
6821 + lwz r3,(K_ASM_BUMP_CNTRS+4*_bump_ind_)(r1) ;\
6823 + stw r3,(K_ASM_BUMP_CNTRS+4*_bump_ind_)(r1) ;\
6824 + lwz r3,xDEBUG_SCR1(r1) ;\
6825 + define([_bump_ind_],eval(_bump_ind_+1))
6828 + define([_tick_ind_], 0)
6830 +#define __ZERO_TICK_CNT(cntr) \
6831 + ifdef([##cntr##_ind_],[],[ \
6832 + define([##cntr##_ind_], _tick_ind_) \
6833 + define([_tick_ind_], eval(_tick_ind_+1)) \
6835 + .if (_tick_ind_ > NUM_ASM_TICK_CNTRS) ;\
6836 + .print "** too many TICK counters **" ; .fail 1 ;\
6838 + stw r3,xDEBUG_SCR1(r1) ;\
6840 + stw r3,(K_ASM_TICK_STAMPS + 4*cntr##_ind_)(r1) ;\
6841 + lwz r3,xDEBUG_SCR1(r1)
6843 +#define __GET_TICK_CNT(cntr, name) \
6845 +debug_str_[]_bump_ind_: ;\
6846 + .if (_bump_ind_ >= NUM_ASM_BUMP_CNTRS) ;\
6847 + .print "** too many BUMP counters **" ; .fail 1 ;\
6849 + .ascii name "_ticks\0" ;\
6852 + .long (debug_str_[]_bump_ind_-__start_bumptable) ;\
6854 + ifdef([##cntr##_ind_],[],[ \
6855 + define([##cntr##_ind_], _tick_ind_) \
6856 + define([_tick_ind_], eval(_tick_ind_+1)) \
6858 + .if (_tick_ind_ > NUM_ASM_TICK_CNTRS) ;\
6859 + .print "** too many TICK counters **" ; .fail 1 ;\
6861 + stw r3,xDEBUG_SCR1(r1) ;\
6863 + stw r4,xDEBUG_SCR2(r1) ;\
6864 + lwz r4,(K_ASM_TICK_STAMPS + 4*cntr##_ind_)(r1) ;\
6866 + lwz r4,(K_ASM_BUMP_CNTRS+4*_bump_ind_)(r1) ;\
6868 + stw r4,(K_ASM_BUMP_CNTRS+4*_bump_ind_)(r1) ;\
6869 + lwz r3,xDEBUG_SCR1(r1) ;\
6871 + stw r4,(K_ASM_TICK_STAMPS + 4*cntr##_ind_)(r1) ;\
6872 + lwz r4,xDEBUG_SCR2(r1) ;\
6873 + define([_bump_ind_],eval(_bump_ind_+1))
6875 +#endif /* PERFORMANCE_INFO */
6877 +#ifndef PERFORMANCE_INFO_LIGHT
6878 +#define BUMP(s) __BUMP(s)
6879 +#define ZERO_TICK_CNT(c) __ZERO_TICK_CNT(c)
6880 +#define GET_TICK_CNT(c, name) __GET_TICK_CNT(c,name)
6883 +#define ZERO_TICK_CNT(c)
6884 +#define GET_TICK_CNT(c, name)
6888 +#define __BUMP(str)
6889 +#define __ZERO_TICK_CNT(cntr)
6890 +#define __GET_TICK_CNT(cntr, name)
6893 +#ifdef PERF_MONITOR
6894 +MACRO(PERF_MONITOR_GET, [
6895 + stw r5,xDEBUG_SCR1(r1)
6897 + stw r4,xDEBUG_SCR2(r1)
6901 + stw r5,xDEBUG0(r1)
6904 + lwz r4,xDEBUG_SCR2(r1)
6905 + lwz r5,xDEBUG_SCR1(r1)
6907 +MACRO(PERF_MONITOR_SETUP, [scr], [
6908 + LOADI _scr,BIT(2) | BIT(3) | BIT(31) // count in SV-mode if PM is zero.
6909 + mtspr S_MMCR0,_scr
6911 + mtspr S_MMCR1,_scr
6915 +#else /* PERF_MONITOR */
6916 +#define PERF_MONITOR_GET
6917 +MACRO(PERF_MONITOR_SETUP, [scr], [])
6921 +/************************************************************************/
6923 +/************************************************************************/
6925 +MACRO(STOP_EMULATION, [val], [
6926 + stw r3,xDEBUG_SCR1(r1)
6928 + stw r3,xKERNEL_DBG_STOP(r1)
6930 + stw r3,xINTERRUPT(r1)
6931 + lwz r3,xDEBUG_SCR1(r1)
6934 +MACRO(DEBUG_TRACE, [num, dummy], [
6935 + stw r3,xDEBUG_SCR1(r1)
6936 + lwz r3,xDEBUG_TRACE(r1)
6938 + stw r3,xDEBUG_TRACE(r1)
6939 + stw r3,(xDEBUG0+4*_num)(r1)
6940 + lwz r3,xDEBUG_SCR1(r1)
6943 +MACRO(TRACE_VAL, [val, dummy], [
6945 + stw r30,xDEBUG_SCR1(r1)
6946 + stw r29,xDEBUG_SCR2(r1)
6947 + lwz r30,xDEBUG_TRACE(r1)
6948 + rlwinm r30,r30,0,24,31 // 256 entries
6949 + rlwinm r30,r30,2,22,29
6950 + addi r30,r30,xDBG_TRACE_SPACE
6952 + addi r29,r29,LO(_val)
6954 + lwz r30,xDEBUG_TRACE(r1)
6956 + rlwinm r30,r30,0,24,31 // 256 entries
6957 + stw r30,xDEBUG_TRACE(r1)
6958 + lwz r29,xDEBUG_SCR2(r1)
6959 + lwz r30,xDEBUG_SCR1(r1)
6962 +#define TRACE( a,b ) TRACE_VAL a,b
6965 +#endif /* _H_ASMDBG */
6967 +++ b/drivers/macintosh/mol/include/asmdefs.h
6971 + * Creation Date: <2001/02/03 19:38:07 samuel>
6972 + * Time-stamp: <2004/02/22 15:36:20 samuel>
6976 + * Common assembly definitions
6978 + * Copyright (C) 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
6980 + * This program is free software; you can redistribute it and/or
6981 + * modify it under the terms of the GNU General Public License
6982 + * as published by the Free Software Foundation
6991 +#ifndef __ASSEMBLY__
6992 +#error This file is only to be included from assembler code!
6996 +/************************************************************************/
6997 +/* High/low halfword compatibility macros */
6998 +/************************************************************************/
7001 +#define ha16( v ) (v)##@ha
7002 +#define hi16( v ) (v)##@h
7003 +#define lo16( v ) (v)##@l
7005 +#define HA(v) ha16(v)
7006 +#define HI(v) hi16(v)
7007 +#define LO(v) lo16(v)
7009 +/************************************************************************/
7011 +/************************************************************************/
7014 +#define STACK_LR_OFFSET 4
7018 +#define STACK_LR_OFFSET 8 /* 4 is the CR offset */
7021 +/************************************************************************/
7022 +/* Register name prefix */
7023 +/************************************************************************/
7026 +define([rPREFIX], [])
7027 +define([fPREFIX], [])
7028 +define([srPREFIX], [])
7030 +define([rPREFIX], [r])
7031 +define([fPREFIX], [f])
7032 +define([srPREFIX], [sr])
7034 +mFORLOOP([i],0,31,[define(fr[]i,f[]i)])
7037 +/************************************************************************/
7038 +/* Macros and definitions */
7039 +/************************************************************************/
7042 +#define balign_4 .align 2,0
7043 +#define balign_8 .align 3,0
7044 +#define balign_16 .align 4,0
7045 +#define balign_32 .align 5,0
7049 +#define balign_4 .balign 4,0
7050 +#define balign_8 .balign 8,0
7051 +#define balign_16 .balign 16,0
7052 +#define balign_32 .balign 32,0
7055 +MACRO(LOADVAR, [dreg, variable], [
7056 + lis _dreg,HA(_variable)
7057 + lwz _dreg,LO(_variable)(_dreg)
7060 +MACRO(LOADI, [dreg, addr], [
7061 + lis _dreg,HA(_addr)
7062 + addi _dreg,_dreg,LO(_addr)
7065 +MACRO(LOAD_GPR_RANGE, [start, endx, offs, base], [
7066 + mFORLOOP([i],0,31,[ .if (i >= _start) & (i <= _endx)
7067 + lwz rPREFIX[]i,_offs+i[]*4(_base)
7071 +MACRO(STORE_GPR_RANGE, [start, endx, offs, base], [
7072 + mFORLOOP([i],0,31,[ .if (i >= _start) & (i <= _endx)
7073 + stw rPREFIX[]i,_offs+i[]*4(_base)
7077 +MACRO(LOAD_FPR_RANGE, [start, endx, offs, base], [
7078 + mFORLOOP([i],0,31,[ .if (i >= _start) & (i <= _endx)
7079 + lfd fPREFIX[]i,_offs+i[]*8(_base)
7083 +MACRO(STORE_FPR_RANGE, [start, endx, offs, base], [
7084 + mFORLOOP([i],0,31,[ .if (i >= _start) & (i <= _endx)
7085 + stfd fPREFIX[]i,_offs+i[]*8(_base)
7089 +/************************************************************************/
7090 +/* FPU load/save macros */
7091 +/************************************************************************/
7093 + // The FPU macros are used both in the kernel and in
7094 + // mainloop_asm.h.
7096 +MACRO(xFPR_LOAD_RANGE, [from, to, mbase], [
7097 + LOAD_FPR_RANGE _from,_to,xFPR_BASE,_mbase
7099 +MACRO(xFPR_SAVE_RANGE, [from, to, mbase], [
7100 + STORE_FPR_RANGE _from,_to,xFPR_BASE,_mbase
7102 + // The low half of the fpu is fr0-fr12. I.e. the FPU registers
7103 + // that might be overwritten when a function call is taken
7104 + // (fr13 and fpscr are treated specially).
7106 +MACRO(xLOAD_LOW_FPU, [mbase], [
7107 + xFPR_LOAD_RANGE 0,12,_mbase
7110 +MACRO(xLOAD_TOPHALF_FPU, [mbase], [
7111 + xFPR_LOAD_RANGE 14,31,_mbase
7113 +MACRO(xLOAD_FULL_FPU, [mbase], [
7114 + xLOAD_LOW_FPU _mbase
7115 + xLOAD_TOPHALF_FPU _mbase
7118 +MACRO(xSAVE_LOW_FPU, [mbase], [
7119 + xFPR_SAVE_RANGE 0,12,_mbase
7121 +MACRO(xSAVE_TOPHALF_FPU, [mbase], [
7122 + xFPR_SAVE_RANGE 14,31,_mbase
7124 +MACRO(xSAVE_FULL_FPU, [mbase], [
7125 + xSAVE_LOW_FPU _mbase
7126 + xSAVE_TOPHALF_FPU _mbase
7130 +/************************************************************************/
7131 +/* GPR load/save macros */
7132 +/************************************************************************/
7134 +MACRO(xGPR_SAVE_RANGE, [from, to, mbase], [
7135 + STORE_GPR_RANGE _from, _to, xGPR0, _mbase
7138 +MACRO(xGPR_LOAD_RANGE, [from, to, mbase], [
7139 + LOAD_GPR_RANGE _from, _to, xGPR0, _mbase
7143 +/************************************************************************/
7145 +/************************************************************************/
7151 +#ifndef HAVE_ALTIVEC
7152 +#define VEC_OPCODE( op1,op2,A,B,C ) \
7153 + .long (((op1) << (32-6)) | (op2) | ((A) << (32-11)) | ((B) << (32-16)) | ((C) << (32-21))) ;
7155 +#define __stvx( vS,rA,rB ) VEC_OPCODE( 31,0x1ce,vS,rA,rB )
7156 +#define __lvx( vD,rA,rB ) VEC_OPCODE( 31,0xce, vD,rA,rB )
7157 +#define __mfvscr( vD ) VEC_OPCODE( 4,1540,vD,0,0 )
7158 +#define __mtvscr( vB ) VEC_OPCODE( 4,1604,0,0,vB )
7159 +#define __stvewx( vS,rA,rB ) VEC_OPCODE( 31,(199<<1), vS,rA,rB )
7161 +mFORLOOP([i],0,31,[define(v[]i,[]i)])
7162 +MACRO(stvx, [vS,rA,rB], [ __stvx( _vS,_rA,_rB ) ; ])
7163 +MACRO(lvx, [vD,rA,rB], [ __lvx( _vD,_rA,_rB ) ; ])
7164 +MACRO(mfvscr, [vD], [ __mfvscr( _vD ) ; ])
7165 +MACRO(mtvscr, [vB], [ __mtvscr( _vB ) ; ])
7166 +MACRO(stvewx, [vS,rA,rB], [ __stvewx( _vS,_rA,_rB ) ; ])
7168 +#else /* __linux__ */
7170 +define(vPREFIX,[v])
7172 +#endif /* __linux__ */
7175 +// NOTE: Writing to VSCR won't cause exceptions (this
7176 +// is different compared to FPSCR).
7178 +MACRO(xVEC_SAVE, [mbase, scr], [
7179 + addi _scr,_mbase,xVEC_BASE
7180 + mFORLOOP([i],0,31,[
7181 + stvx vPREFIX[]i,0,_scr
7184 + addi _scr,_mbase,xVSCR-12
7187 + addi _scr,_mbase,xVEC0
7189 + mfspr _scr,S_VRSAVE
7190 + stw _scr,xVRSAVE(_mbase)
7193 +MACRO(xVEC_LOAD, [mbase, scr], [
7194 + addi _scr,_mbase,xVSCR-12
7197 + addi _scr,_mbase,xVEC_BASE
7198 + mFORLOOP([i],0,31,[
7199 + lvx vPREFIX[]i,0,_scr
7202 + lwz _scr,xVRSAVE(_mbase)
7203 + mtspr S_VRSAVE,_scr
7206 +/************************************************************************/
7208 +/************************************************************************/
7211 +MACRO(mtsprg0, [reg], [mtspr SPRG0,_reg] )
7212 +MACRO(mtsprg1, [reg], [mtspr SPRG1,_reg] )
7213 +MACRO(mtsprg2, [reg], [mtspr SPRG2,_reg] )
7214 +MACRO(mtsprg3, [reg], [mtspr SPRG3,_reg] )
7215 +MACRO(mfsprg0, [reg], [mfspr _reg,SPRG0] )
7216 +MACRO(mfsprg1, [reg], [mfspr _reg,SPRG1] )
7217 +MACRO(mfsprg2, [reg], [mfspr _reg,SPRG2] )
7218 +MACRO(mfsprg3, [reg], [mfspr _reg,SPRG3] )
7221 +/************************************************************************/
7222 +/* Register names */
7223 +/************************************************************************/
7246 +/* IMPORTANT: we may *not* define crN on darwin; If we do, the
7247 + * assembler will generate bogus code. For instance,
7248 + * bne cr1,1f is not equivalent to bne 1,1f but to
7251 +#define lt 0 /* Less than */
7252 +#define gt 1 /* Greater than */
7253 +#define eq 2 /* Equal */
7254 +#define so 3 /* Summary Overflow */
7255 +#define un 3 /* Unordered (after floating point) */
7258 +/* FPU register names (to be used as macro arguments) */
7292 +/* GPR register names (to be used as macro arguments) */
7328 +/* GPR register names, rN -> N, frN -> N, vN -> N */
7329 +mFORLOOP([i],0,31,[define(r[]i,[]i)])
7330 +mFORLOOP([i],0,31,[define(fr[]i,[]i)])
7331 +mFORLOOP([i],0,31,[define(v[]i,[]i)])
7333 +#endif /* __darwin__ */
7336 +/************************************************************************/
7337 +/* useful macros */
7338 +/************************************************************************/
7340 +MACRO(ori_, [reg1, reg2, value], [
7341 + .if (_value & 0xffff)
7342 + ori _reg1, _reg2, (_value) & 0xffff
7344 + .if (_value & ~0xffff)
7345 + oris _reg1, _reg2, (_value) >> 16
7349 +/************************************************************************/
7351 +/************************************************************************/
7354 +#define GLOBL( name ) .globl name ; name
7355 +#define EXTERN( name ) name
7357 +/* an underscore is needed on Darwin */
7358 +#define GLOBL( name ) .globl _##name ; name: ; _##name
7359 +#define EXTERN( name ) _##name
7362 +#define BIT(n) (1<<(31-(n)))
7364 +#endif /* _H_ASMDEFS */
7367 +++ b/drivers/macintosh/mol/include/asmfuncs.h
7370 + * Creation Date: <1999/09/26 01:02:58 samuel>
7371 + * Time-stamp: <2003/07/27 19:20:24 samuel>
7375 + * Exports from <base.S>
7377 + * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
7379 + * This program is free software; you can redistribute it and/or
7380 + * modify it under the terms of the GNU General Public License
7381 + * as published by the Free Software Foundation
7385 +#ifndef _H_ASMFUNCS
7386 +#define _H_ASMFUNCS
7388 +#include "kernel_vars.h"
7392 +/* globl variable defined in actions.c */
7393 +extern int reloc_virt_offs;
7394 +#define reloc_ptr( v ) ((ulong)(v) + (ulong)reloc_virt_offs)
7397 +/* The code in base.o (all low-level assembly) are copied to a physically
7398 + * continuous memory area. The following inline functions maps function calls
7399 + * to the relocated area.
7402 +static inline void msr_altered( kernel_vars_t *kv ) {
7403 + typedef void ftype( kernel_vars_t * );
7404 + extern ftype r__msr_altered;
7405 + (*(ftype*)reloc_ptr( r__msr_altered ))( kv );
7408 +static inline void invalidate_splitmode_sr( kernel_vars_t *kv ) {
7409 + typedef void ftype( kernel_vars_t *);
7410 + extern ftype r__invalidate_splitmode_sr;
7411 + (*(ftype*)reloc_ptr( r__invalidate_splitmode_sr ))( kv );
7414 +static inline void initialize_spr_table( kernel_vars_t *kv ) {
7415 + typedef void ftype( kernel_vars_t *);
7416 + extern ftype r__initialize_spr_table;
7417 + (*(ftype*)reloc_ptr( r__initialize_spr_table ))( kv );
7421 +/************************************************************************/
7423 +/************************************************************************/
7425 +#define _sync() ({ asm volatile("sync ;\n isync" : : ); })
7427 +static inline ulong _get_sdr1( void ) {
7429 + asm volatile("mfsdr1 %0" : "=r" (sdr1) : );
7432 +static inline void _set_sdr1( ulong sdr1 ) {
7433 + asm volatile("mtsdr1 %0" : : "r" (sdr1) );
7436 +static inline int cpu_is_601( void ) {
7438 + asm volatile("mfpvr %0" : "=r" (pvr) : );
7439 + return (pvr>>16)==1;
7442 +static inline int cpu_is_603( void ) {
7444 + asm volatile("mfpvr %0" : "=r" (pvr) : );
7446 + return pvr==3 || pvr==6 || pvr==7; /* 603, 603e, 603ev */
7448 +#endif /* _H_ASMFUNCS */
7450 +++ b/drivers/macintosh/mol/include/atomic.h
7453 + * Creation Date: <2004/01/25 17:00:12 samuel>
7454 + * Time-stamp: <2004/01/29 22:32:30 samuel>
7460 + * Copyright (C) 2004 Samuel Rydh (samuel@ibrium.se)
7462 + * This program is free software; you can redistribute it and/or
7463 + * modify it under the terms of the GNU General Public License
7471 +#define mol_atomic_t atomic_t
7472 +#define atomic_inc_return_mol(x) atomic_inc_return(x)
7473 +#define atomic_inc_mol(x) atomic_inc(x)
7474 +#define atomic_dec_mol(x) atomic_dec(x)
7475 +#define atomic_read_mol(x) atomic_read(x)
7477 +#endif /* _H_ATOMIC */
7479 +++ b/drivers/macintosh/mol/include/config.h
7481 +/* config.h. Generated from config.h.in by configure. */
7482 +/* config.h.in. Generated from configure.in by autoheader. */
7484 +/* Define if _syscall macro is borken */
7485 +#define BROKEN_SYSCALL 1
7487 +/* Defined if ALSA support is available */
7488 +#define HAVE_ALSA 1
7490 +/* Define if clearenv is available */
7491 +#define HAVE_CLEARENV 1
7493 +/* Define to 1 if you have the <getopt.h> header file. */
7494 +#define HAVE_GETOPT_H 1
7496 +/* Define to 1 if you have the <inttypes.h> header file. */
7497 +#define HAVE_INTTYPES_H 1
7499 +/* Define to 1 if you have the <memory.h> header file. */
7500 +#define HAVE_MEMORY_H 1
7502 +/* Define to 1 if you have the <obstack.h> header file. */
7503 +#define HAVE_OBSTACK_H 1
7505 +/* Define if libpng support is to be included */
7508 +/* Define to 1 if you have the <poll.h> header file. */
7509 +#define HAVE_POLL_H 1
7511 +/* Define to 1 if you have the <stdint.h> header file. */
7512 +#define HAVE_STDINT_H 1
7514 +/* Define to 1 if you have the <stdlib.h> header file. */
7515 +#define HAVE_STDLIB_H 1
7517 +/* Define to 1 if you have the <strings.h> header file. */
7518 +#define HAVE_STRINGS_H 1
7520 +/* Define to 1 if you have the <string.h> header file. */
7521 +#define HAVE_STRING_H 1
7523 +/* Define to 1 if you have the <sys/stat.h> header file. */
7524 +#define HAVE_SYS_STAT_H 1
7526 +/* Define to 1 if you have the <sys/types.h> header file. */
7527 +#define HAVE_SYS_TYPES_H 1
7529 +/* Define to 1 if you have the <unistd.h> header file. */
7530 +#define HAVE_UNISTD_H 1
7532 +/* Define if X11 is available */
7535 +/* Define if XDGA support is to be included */
7536 +#define HAVE_XDGA 1
7538 +/* Defined for the MOL user binary */
7539 +#define MOL_PROPER 1
7541 +/* Define if off_t is known to be 64-bit */
7542 +#define OFF_T_IS_64 1
7544 +/* Define to the address where bug reports for this package should be sent. */
7545 +#define PACKAGE_BUGREPORT ""
7547 +/* Define to the full name of this package. */
7548 +#define PACKAGE_NAME ""
7550 +/* Define to the full name and version of this package. */
7551 +#define PACKAGE_STRING ""
7553 +/* Define to the one symbol short name of this package. */
7554 +#define PACKAGE_TARNAME ""
7556 +/* Define to the version of this package. */
7557 +#define PACKAGE_VERSION ""
7559 +/* Define to 1 if you have the ANSI C header files. */
7560 +#define STDC_HEADERS 1
7562 +/* Define if uc_context has gregs field */
7563 +/* #undef UCCONTEXT_HAS_GREGS */
7565 +/* Define to 1 if the X Window System is missing or not being used. */
7566 +/* #undef X_DISPLAY_MISSING */
7568 +/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
7570 +#define YYTEXT_POINTER 1
7572 +++ b/drivers/macintosh/mol/include/constants.h
7575 + * Creation Date: <2001/02/11 18:19:42 samuel>
7576 + * Time-stamp: <2003/07/27 18:58:35 samuel>
7580 + * Constants used both in the kernel module and in the emulator
7582 + * Copyright (C) 2001, 2002, 2003 Samuel Rydh (samuel@ibrium.se)
7584 + * This program is free software; you can redistribute it and/or
7585 + * modify it under the terms of the GNU General Public License
7586 + * as published by the Free Software Foundation
7590 +#ifndef _H_CONSTANTS
7591 +#define _H_CONSTANTS
7593 +/* flags for _breakpoint_flags() */
7594 +#define BREAK_RFI 1 /* break at next rfi */
7595 +#define BREAK_SINGLE_STEP 2 /* singlestep */
7596 +#define BREAK_EA_PAGE 4 /* break when mdbg_break_ea is mapped */
7597 +#define BREAK_USER 8 /* break when MSR_PR is set */
7598 +#define BREAK_SINGLE_STEP_CONT 16 /* single step (but don't continue running) */
7600 +/* action for _tune_spr() */
7601 +#define kTuneSPR_Illegal 1 /* SPR is illegal */
7602 +#define kTuneSPR_Privileged 2 /* SPR is privileged */
7603 +#define kTuneSPR_Unprivileged 3 /* SPR is unprivileged */
7604 +#define kTuneSPR_ReadWrite 4 /* SPR is read-write */
7605 +#define kTuneSPR_ReadOnly 5 /* SPR is read-only */
7607 +#endif /* _H_CONSTANTS */
7611 +++ b/drivers/macintosh/mol/include/context.h
7614 + * Creation Date: <2004/01/25 17:48:51 samuel>
7615 + * Time-stamp: <2004/01/25 22:12:13 samuel>
7621 + * Copyright (C) 2004 Samuel Rydh (samuel@ibrium.se)
7623 + * This program is free software; you can redistribute it and/or
7624 + * modify it under the terms of the GNU General Public License
7632 +#define CTX_MASK 0xfffff /* VSID_MASK >> 4 */
7635 + * Three types of contexts are used:
7637 + * VSIDs (24 bit, loaded into the CPU register)
7638 + * mol_contexts (number between FIRST_ and LAST_MOL_CONTEXT)
7639 + * arch_contexts (context number used by the kernel)
7641 + * The relation between them is
7643 + * mol_context = (os_context << 4) + segment#
7644 + * VSID_context = MUNGE_CONTEXT(mol_context>>4) + ESID_ADD * (mol_context & 0xf)
7648 + * The new MM implementation (about 2.4.14 (?)) uses the following algorithm
7650 + * VSID = (((context * 897) << 4) + ((va>>28) * 0x111)) & 0xffffff
7652 + * Only context 0..32767 are used. We can use context 32768..0xfffff.
7653 + * The old MM implementation used
7655 + * VSID = (((context * 897) << 4) + (va>>28)) & 0xffffff
7658 +#define MUNGE_ADD_NEXT 897
7659 +#define MUNGE_MUL_INVERSE 2899073 /* Multiplicative inverse of 897 (modulo VSID_MASK+1) */
7660 +#define MUNGE_ESID_ADD 0x111
7661 +#define MUNGE_CONTEXT(c) (((c) * (MUNGE_ADD_NEXT * 16)) & (CTX_MASK <<4))
7663 +/* mol_contexts == linux_context * 16 + esid */
7664 +#define PER_SESSION_CONTEXTS 0x10000 /* more than we will need (10^6) */
7665 +#define FIRST_MOL_CONTEXT(sess) ((CTX_MASK - PER_SESSION_CONTEXTS*((sess)+1)) << 4)
7666 +#define LAST_MOL_CONTEXT(sess) (((CTX_MASK - PER_SESSION_CONTEXTS*(sess)) << 4) | 0xf)
7669 +#if FIRST_MOL_CONTEXT(MAX_NUM_SESSIONS-1) < (32768 << 4)
7670 +#error "Too many MOL contexts..."
7674 +#endif /* _H_CONTEXT */
7676 +++ b/drivers/macintosh/mol/include/dbg.h
7679 + * Creation Date: <2004/04/10 22:14:43 samuel>
7680 + * Time-stamp: <2004/04/10 22:26:24 samuel>
7686 + * Copyright (C) 2004 Samuel Rydh (samuel@ibrium.se)
7688 + * This program is free software; you can redistribute it and/or
7689 + * modify it under the terms of the GNU General Public License
7696 +#ifdef CONFIG_MOL_HOSTED
7702 +#define printk printm
7703 +extern int printm( const char *fmt, ... );
7704 +extern void debugger( int n );
7706 +#endif /* CONFIG_MOL_HOSTED */
7708 +#endif /* _H_DBG */
7710 +++ b/drivers/macintosh/mol/include/debugger.h
7713 + * Creation Date: <1999/02/22 22:46:22 samuel>
7714 + * Time-stamp: <2003/07/27 14:42:05 samuel>
7718 + * World interface of the debugger
7720 + * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
7722 + * This program is free software; you can redistribute it and/or
7723 + * modify it under the terms of the GNU General Public License
7724 + * as published by the Free Software Foundation
7728 +#ifndef _H_DEBUGGER
7729 +#define _H_DEBUGGER
7731 +#ifdef CONFIG_DEBUGGER
7732 +extern void debugger_init( void );
7733 +extern void debugger_cleanup( void );
7734 +extern int debugger_enabled( void );
7735 +extern int debugger_attached( void );
7737 +static inline int debugger_enabled( void ) { return 0; }
7738 +static inline int debugger_attached( void ) { return 0; }
7739 +static inline void debugger_init( void ) {}
7740 +static inline void debugger_cleanup( void ) {}
7743 +/*******************************************/
7744 +/* montior.c / nub.c */
7745 +/*******************************************/
7747 +extern void refresh_debugger_window( void );
7748 +extern void refresh_debugger( void );
7749 +extern void redraw_inst_win( void );
7750 +extern int debugger_in_68k_mode( void );
7751 +extern void debugger_nub_poll( void );
7753 +/* debug actions */
7755 + kDbgNOP=0, kDbgGo, kDbgGoRFI, kDbgStep, kDbgExit, kDbgStop, kDbgGoUser
7759 +/*******************************************/
7760 +/* cmdline.c / nub.c */
7761 +/*******************************************/
7763 +/* put functions used exclusively in debugger mode in the dbg section */
7765 +#ifdef CONFIG_DEBUGGER
7766 +#define __dbg __attribute__ ((__section__ (".moldbg")))
7767 +#define __dcmd __dbg
7769 +#define __dbg __attribute__ ((__section__ (".moldbg")))
7770 +#define __dcmd inline __attribute__ ((__section__ (".moldbg")))
7774 +#define __dcmd inline
7779 + int (*func)( int argc, char **argv );
7783 +typedef int (*dbg_cmd_fp)( int argc, char **argv );
7785 +#ifdef CONFIG_DEBUGGER
7786 +extern void add_cmd( const char *cmdname, const char *help,
7787 + int dummy, dbg_cmd_fp func );
7788 +extern void add_dbg_cmds( dbg_cmd_t *table, int tablesize );
7790 +#define add_cmd( a,b,c,d ) do {} while(0)
7791 +static inline void add_dbg_cmds( dbg_cmd_t *table, int tablesize ) {}
7794 +/* for debugging */
7795 +#define HARD_BREAKPOINT \
7796 + ({ printm("Hardcoded breakpoint in '"__FILE__"'\n"); stop_emulation(); })
7799 +/*******************************************/
7801 +/*******************************************/
7803 +extern int __dbg get_inst_context( void );
7804 +extern int __dbg get_data_context( void );
7805 +extern int __dbg ea_to_lvptr( ulong ea, int context, char **lvptr, int data_access );
7807 +#endif /* _H_DEBUGGER */
7809 +++ b/drivers/macintosh/mol/include/emu.h
7812 + * Creation Date: <2003/01/26 00:45:55 samuel>
7813 + * Time-stamp: <2003/01/27 01:26:25 samuel>
7817 + * Emulation of some assembly functions
7819 + * Copyright (C) 1998, 2000, 2001, 2002, 2003 Samuel Rydh (samuel@ibrium.se)
7821 + * This program is free software; you can redistribute it and/or
7822 + * modify it under the terms of the GNU General Public License
7823 + * as published by the Free Software Foundation
7832 +extern int do_mtsdr1( kernel_vars_t *kv, ulong value );
7833 +extern int do_mtbat( kernel_vars_t *kv, int sprnum, ulong value, int force );
7835 +extern int alloc_emuaccel_slot( kernel_vars_t *kv, int inst_flags, int param, int inst_addr );
7836 +extern int mapin_emuaccel_page( kernel_vars_t *kv, int mphys );
7839 +#endif /* _H_EMU */
7841 +++ b/drivers/macintosh/mol/include/emuaccel_sh.h
7844 + * Creation Date: <2003/01/25 14:57:36 samuel>
7845 + * Time-stamp: <2003/01/27 23:11:29 samuel>
7849 + * Acceleration of the emulation of certain privileged instructions
7851 + * Copyright (C) 2003 Samuel Rydh (samuel@ibrium.se)
7853 + * This program is free software; you can redistribute it and/or
7854 + * modify it under the terms of the GNU General Public License
7855 + * as published by the Free Software Foundation
7859 +#ifndef _H_EMUACCEL
7860 +#define _H_EMUACCEL
7862 +/* OSI_AllocInstAccelSlot( EMULATE_xxx + source_reg, NIP ) */
7864 +#define EMUACCEL_MAPIN_PAGE 0
7865 +#define EMUACCEL_MTSRR0 (1 << 5)
7866 +#define EMUACCEL_MTSRR1 (2 << 5)
7867 +#define EMUACCEL_MTSPRG0 (3 << 5)
7868 +#define EMUACCEL_MTSPRG1 (4 << 5)
7869 +#define EMUACCEL_MTSPRG2 (5 << 5)
7870 +#define EMUACCEL_MTSPRG3 (6 << 5)
7871 +#define EMUACCEL_MTMSR (7 << 5)
7872 +#define EMUACCEL_RFI (8 << 5)
7873 +#define EMUACCEL_UPDATE_DEC (9 << 5) /* update xDEC */
7874 +#define EMUACCEL_MTSR ((10 << 5) | EMUACCEL_HAS_PARAM)
7875 +#define EMUACCEL_NOP (11 << 5)
7876 +#define EMUACCEL_MTHID0 (12 << 5)
7878 +#define EMUACCEL_HAS_PARAM (1 << 10)
7879 +#define EMUACCEL_INST_MASK 0xffe0
7880 +#define EMUACCEL_DESTREG_MASK 0x1f
7883 +#endif /* _H_EMUACCEL */
7885 +++ b/drivers/macintosh/mol/include/extralib.h
7888 + * Creation Date: <1997/07/02 19:52:18 samuel>
7889 + * Time-stamp: <2004/04/03 18:29:26 samuel>
7895 + * Copyright (C) 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
7897 + * This program is free software; you can redistribute it and/or
7898 + * modify it under the terms of the GNU General Public License
7899 + * as published by the Free Software Foundation
7903 +#ifndef _H_EXTRALIB
7904 +#define _H_EXTRALIB
7906 +#define CLEAR( x ) memset( &x, 0, sizeof(x))
7908 +/* in extralib.h */
7909 +extern int ilog2( int val );
7911 +extern char *num_to_string( ulong num );
7912 +extern int is_number_str( char *str );
7913 +extern ulong string_to_ulong( char * );
7914 +extern ulong hexbin( int num );
7916 +extern char *strncpy0( char *dest, const char *str, size_t n );
7917 +extern char *strncat0( char *dest, const char *str, size_t n );
7918 +extern char *strncat3( char *dest, const char *s1, const char *s2, size_t n );
7919 +extern char *strnpad( char *dest, const char *s1, size_t n );
7922 +extern int memcpy_tovec( const struct iovec *vec, size_t nvec, const char *src, unsigned int len );
7923 +extern int memcpy_fromvec( char *dst, const struct iovec *vec, size_t nvec, unsigned int len );
7924 +extern int iovec_getbyte( int offs, const struct iovec *vec, size_t nvec );
7925 +extern int iovec_skip( int skip, struct iovec *vec, size_t nvec );
7927 +extern void open_logfile( const char *filename );
7928 +extern void close_logfile( void );
7930 +#define __printf_format __attribute__ ((format (printf, 1, 2)))
7931 +extern int printm( const char *fmt,...) __printf_format;
7932 +extern int aprint( const char *fmt,... ) __printf_format;
7933 +extern void perrorm(const char *fmt,... ) __printf_format;
7934 +extern void fatal(const char *fmt,... ) __printf_format __attribute__((noreturn));
7935 +#define fatal_err(fmt, args...) \
7936 + do { printm("Fatal error: "); perrorm(fmt, ## args ); exit(1); } while(0)
7937 +extern void fail_nil( void *p );
7938 +extern void set_print_hook( int (*hook)(char *buf) );
7939 +extern void set_print_guard( void (*hook)(void) );
7941 +extern int script_exec( char *name, char *arg1, char *arg2 );
7944 +extern int asc2uni( unsigned char *ustr, const char *astr, int maxlen );
7945 +extern int uni2asc( char *astr, const unsigned char *ustr, int ustrlen, int maxlen );
7947 +/* in backtrace.c */
7948 +extern void print_btrace_sym( ulong addr, const char *sym_filename );
7950 +/* color output support */
7951 +#define C_GREEN "\33[1;32m"
7952 +#define C_YELLOW "\33[1;33m"
7953 +#define C_NORMAL "\33[0;39m"
7954 +#define C_RED "\33[1;31m"
7956 +#endif /* _H_EXTRALIB */
7958 +++ b/drivers/macintosh/mol/include/hash.h
7961 + * Creation Date: <2004/02/14 11:45:23 samuel>
7962 + * Time-stamp: <2004/02/21 21:24:46 samuel>
7968 + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
7970 + * This program is free software; you can redistribute it and/or
7971 + * modify it under the terms of the GNU General Public License
7972 + * as published by the Free Software Foundation
7980 + ulong sdr1; /* sdr1 used by MOL */
7982 + ulong pteg_mask; /* pteg offset mask (e.g. 0xffc0) */
7983 + ulong pte_mask; /* pte offset mask (e.g. 0xfff8) */
7985 + ulong *base; /* kernel mapping of hash */
7986 + ulong physbase; /* physical address of hash */
7989 +extern hash_info_t ptehash;
7991 +extern int init_hash( void );
7992 +extern void cleanup_hash( void );
7995 +#endif /* _H_HASH */
7997 +++ b/drivers/macintosh/mol/include/kernel_vars.h
8000 + * Creation Date: <97/07/14 15:53:06 samuel>
8001 + * Time-stamp: <2004/02/21 21:37:37 samuel>
8005 + * Variables used by the kernel
8007 + * Copyright (C) 1997-2004 Samuel Rydh (samuel@ibrium.se)
8009 + * This program is free software; you can redistribute it and/or
8010 + * modify it under the terms of the GNU General Public License
8011 + * as published by the Free Software Foundation
8015 +#ifndef H_KERNEL_VARS
8016 +#define H_KERNEL_VARS
8018 +#define MAX_NUM_SESSIONS 8
8020 +#include "mac_registers.h"
8022 +#ifdef PERFORMANCE_INFO
8023 +#define NUM_ASM_BUMP_CNTRS 64
8024 +#define NUM_ASM_TICK_CNTRS 6
8027 +#ifndef __ASSEMBLY__
8028 +#include "mmu_mappings.h"
8029 +#include "skiplist.h"
8034 +#include "atomic.h"
8036 +typedef int mol_mutex_t;
8037 +typedef int mol_atomic_t;
8041 + ulong word[2]; /* upper, lower */
8044 +typedef struct mac_bat {
8045 + int valid; /* record in use */
8050 + ulong wimg:4; /* WIMG-bits */
8051 + ulong vs:1; /* valid supervisor mode */
8052 + ulong vp:1; /* valid user mode */
8053 + ulong ks:1; /* key superuser */
8054 + ulong ku:1; /* key user */
8055 + ulong pp:2; /* page protection */
8057 + /* possibly we should track inserted PTEs here... */
8061 + struct vsid_ent *vsid[16]; /* entries might be NULL */
8062 + struct vsid_ent *unmapped_vsid[16]; /* entries might be NULL, linux_vsid_sv used */
8064 + ulong emulator_sr[16]; /* segment registers used by the userspace process */
8066 + ulong user_sr[16]; /* segment registers for MSR=user */
8067 + ulong sv_sr[16]; /* segment registers for MSR=sv */
8068 + ulong unmapped_sr[16]; /* segment registers for unmapped mode */
8069 + ulong split_sr[16]; /* segment registers used in split mode */
8071 + ulong cur_sr_base; /* (physical) pointer to user_sr or sv_sr */
8072 + ulong sr_inst; /* (physical) pointer to us user_sr or sv_sr */
8073 + ulong sr_data; /* (physical) pointer to us user_sr or sv_sr */
8075 + ulong illegal_sr; /* used for the lazy segment register impl. */
8077 + ppc_bat_t split_dbat0; /* loaded to DBAT0 (used in splitmode) */
8078 + ppc_bat_t transl_dbat0; /* DBAT0 mapping the framebuffer */
8080 + ulong emulator_context; /* context of emulator (equals VSID >> 4) in Linux */
8082 + ulong userspace_ram_base; /* userspace RAM base */
8085 + ulong bat_hack_count; /* HACK to speed up MacOS 9.1 */
8086 + mac_bat_t bats[8]; /* 4 IBAT + 4 DBAT */
8089 + ulong ptes_d_ea_603[64]; /* EA4-EA19 of dPTE */
8090 + mPTE_t ptes_d_603[64]; /* Data on-chip PTEs (603-emulation) */
8091 + ulong ptes_i_ea_603[64]; /* EA4-EA19 of iPTE */
8092 + mPTE_t ptes_i_603[64]; /* Instruction on-chip PTEs (603-emulation) */
8094 + /* emulated PTE hash */
8095 + ulong hash_mbase; /* mac physical hash base */
8096 + ulong *hash_base; /* kernel pointer to mac hash */
8097 + ulong hash_mask; /* hash mask (0x000fffff etc) */
8099 + /* context number allocation */
8100 + int next_mol_context; /* in the range FIRST .. LAST_MOL_CONTEXT(n) */
8101 + int first_mol_context; /* first context number this session may use */
8102 + int last_mol_context; /* last context number this session may use */
8104 + ulong pthash_sr; /* segment register corresponding to */
8105 + ulong pthash_ea_base; /* pthash_ea_base */
8106 + void *pthash_inuse_bits; /* bitvector (one bit per PTE) */
8107 + ulong pthash_inuse_bits_ph; /* physical base address */
8109 + /* various tables */
8110 + struct io_data *io_data; /* translation info */
8111 + struct fb_data *fb_data; /* ea -> PTE table */
8112 + struct tracker_data *tracker_data; /* Keeps track of modified pages */
8114 + /* mtable stuff */
8115 + skiplist_t vsid_sl; /* skiplist (with vsid_ent_t objects) */
8116 + struct vsid_info *vsid_info; /* mtable data */
8118 + char *lvptr_reservation; /* lvptr associated with PTE to be inserted */
8119 + int lvptr_reservation_lost; /* set if reservation is lost (page out) */
8122 + ulong os_sdr1; /* SDR1 used by the host OS */
8123 + ulong mol_sdr1; /* SDR1 used by MOL */
8128 +/* variables which are private to the low level assembly code */
8130 + ulong spr_hooks[NUM_SPRS]; /* hooks */
8132 + ppc_bat_t ibat_save[4]; /* kernel values of the BAT-registers */
8133 + ppc_bat_t dbat_save[4];
8135 + ulong _msr; /* MSR used in mac-mode (_not_ the emulated msr) */
8137 + /* saved kernel/emulator registers */
8138 + ulong emulator_nip;
8139 + ulong emulator_msr;
8140 + ulong emulator_sprg2;
8141 + ulong emulator_sprg3;
8142 + ulong emulator_kcall_nip;
8143 + ulong emulator_stack;
8144 + ulong emulator_toc; /* == r2 on certain systems */
8146 + /* DEC and timebase */
8147 + ulong dec_stamp; /* linux DEC = dec_stamp - tbl */
8148 + ulong int_stamp; /* next DEC event = int_stamp - tbl */
8151 + int split_nip_segment; /* segment (top 4) used for inst. fetches */
8153 + /* segment register offset table */
8154 + ulong msr_sr_table[ 4*8 ]; /* see emulation.S */
8156 + ulong tmp_scratch[4]; /* temporary storage */
8160 +#ifdef PERFORMANCE_INFO
8161 +#define MAX_ACC_CNTR_DEPTH 8
8162 +typedef struct acc_counter {
8168 +typedef struct kernel_vars {
8169 + struct mac_regs mregs; /* must go first */
8170 + char page_filler[0x1000 - (sizeof(mac_regs_t)&0xfff) ];
8172 + base_private_t _bp;
8173 + char aligner[32 - (sizeof(base_private_t)&0x1f) ];
8175 + char aligner2[16 - (sizeof(mmu_vars_t)&0xf) ];
8177 + ulong emuaccel_mphys; /* mphys address of emuaccel_page */
8178 + int emuaccel_size; /* size used */
8179 + ulong emuaccel_page_phys; /* phys address of page */
8180 + ulong emuaccel_page; /* page used for instruction acceleration */
8183 + ulong kvars_tophys_offs; /* physical - virtual address of kvars */
8184 + struct kernel_vars *kvars_virt; /* me */
8185 + int session_index;
8187 + mol_mutex_t ioctl_sem; /* ioctl lock */
8189 + void *kcall_routine;
8190 + int kcall_args[3];
8191 + char *mregs_virtual; /* mregs address used by client */
8195 +#ifdef PERFORMANCE_INFO
8196 + ulong asm_bump_cntr[NUM_ASM_BUMP_CNTRS];
8197 + ulong asm_tick_stamp[NUM_ASM_TICK_CNTRS];
8199 + acc_counter_t acntrs[MAX_ACC_CNTR_DEPTH];
8202 + void *main_thread; /* pointer to the main thread task_struct */
8206 +#define NUM_KVARS_PAGES ((sizeof(kernel_vars_t)+0xfff)/0x1000)
8209 + kernel_vars_t *kvars[MAX_NUM_SESSIONS];
8211 + ulong kvars_ph[MAX_NUM_SESSIONS];
8213 + mol_atomic_t external_thread_cnt;
8216 +#define SESSION_LOCK down_mol( &g_sesstab->lock )
8217 +#define SESSION_UNLOCK up_mol( &g_sesstab->lock )
8219 +extern session_table_t *g_sesstab;
8222 +#endif /* __ASSEMBLY__ */
8225 +++ b/drivers/macintosh/mol/include/locks.h
8228 + * Creation Date: <2004/01/25 16:31:13 samuel>
8229 + * Time-stamp: <2004/01/29 22:33:29 samuel>
8235 + * Copyright (C) 2004 Samuel Rydh (samuel@ibrium.se)
8237 + * This program is free software; you can redistribute it and/or
8238 + * modify it under the terms of the GNU General Public License
8248 +typedef struct semaphore mol_mutex_t;
8249 +#define init_MUTEX_mol(mu) init_MUTEX( mu )
8250 +#define free_MUTEX_mol(mu) do {} while(0)
8251 +#define down_mol(x) down(x)
8252 +#define up_mol(x) up(x)
8257 +typedef spinlock_t mol_spinlock_t;
8258 +#define spin_lock_mol(x) spin_lock(x)
8259 +#define spin_unlock_mol(x) spin_unlock(x)
8260 +//#define spin_lock_irqsave_mol(x, flags) spin_lock_irqsave(x, flags)
8261 +//#define spin_unlock_irqrestore_mol(x,flags) spin_unlock_irqrestore(x, flags)
8262 +#define spin_lock_init_mol(x) spin_lock_init(x)
8265 +#endif /* _H_LOCKS */
8267 +++ b/drivers/macintosh/mol/include/mac_registers.h
8270 + * Creation Date: <97/06/24 22:25:04 samuel>
8271 + * Time-stamp: <2004/02/08 20:32:59 samuel>
8273 + * <mac_registers.h>
8277 + * Copyright (C) 1997-2004 Samuel Rydh (samuel@ibrium.se)
8279 + * This program is free software; you can redistribute it and/or
8280 + * modify it under the terms of the GNU General Public License
8281 + * as published by the Free Software Foundation
8285 +#ifndef _MAC_REGISTERS_H
8286 +#define _MAC_REGISTERS_H
8288 +#ifndef __ASSEMBLY__
8290 +#include "mmutypes.h"
8291 +#include "processor.h"
8294 + unsigned long h,l;
8297 +#define NUM_DEBUG_REGS 10
8300 + unsigned long words[4];
8303 +#define NR_HOST_IRQS 64
8305 +typedef struct irq_bitfield {
8306 + unsigned long irqs[(NR_HOST_IRQS - 1) / sizeof(unsigned long) + 1];
8309 +typedef struct mac_regs { /* this struct is page aligned */
8310 + /* the sprs should be page aligned (occupies one page) */
8311 + unsigned long spr[NUM_SPRS]; /* special purpose registers */
8313 + unsigned long segr[16]; /* segment registers */
8314 + altivec_reg_t vec[32]; /* AltiVec vector registers */
8315 + fpu_register fpr[32]; /* FPU registers (64 bits) */
8317 + unsigned long vscr_pad[3], vscr; /* AltiVec status control register */
8318 + unsigned long pad_fpscr, fpscr; /* fp. status and control register */
8319 + unsigned long pad_ef, emulator_fpscr; /* emulator fp. status and control reg */
8321 + /* Keep this cache-block aligned (typcically 8 words) */
8322 + unsigned long cr; /* Condition register */
8323 + unsigned long link; /* Link register */
8324 + unsigned long flag_bits; /* Various flags (fbXXXXX) */
8325 + unsigned long inst_opcode; /* opcode of instruction */
8326 + unsigned long gpr[32]; /* gprs */
8328 + unsigned long ctr; /* Count register */
8329 + unsigned long xer; /* Integer exception register */
8330 + unsigned long nip; /* Instruction pointer */
8331 + unsigned long msr; /* Machine state register (virtual) */
8333 + /* interrupts and timers */
8334 + int interrupt; /* set if the kernel should return to the emulator */
8335 + int in_virtual_mode; /* set while MOL is in virtualization mode */
8336 + ulong dec_stamp; /* xDEC = dec_stamp - tbl */
8337 + ulong timer_stamp; /* TIMER = dec_stamp - tbl */
8338 + int obsolete_irq; /* unused */
8340 + /* RVEC parameters */
8342 + ulong rvec_vector; /* Used in kernel C-mode */
8344 + ulong rvec_param[3]; /* Used in kernel C-mode */
8347 + int fpu_state; /* FPU_STATE_xxx (see below) */
8348 + int processor; /* processor to emulate, 1=601, 4=604 */
8349 + int altivec_used; /* useful for altivec detection */
8350 + int no_altivec; /* Don't use altivec (e.g. no kernel support) */
8352 + int use_bat_hack; /* Newworld BAT optimization (HACK) */
8355 + unsigned long gprsave_603[4]; /* GPR0-3 (for 603 DMISS/IMISS) */
8357 + /* moldeb support */
8358 + unsigned long mdbg_ea_break; /* used together with BREAK_EA_PAGE */
8361 + unsigned long debug[NUM_DEBUG_REGS];
8362 + unsigned long debug_scr1; /* dbg scratch register */
8363 + unsigned long debug_scr2; /* dbg scratch register */
8364 + unsigned long debug_trace; /* dbg trace register */
8365 + unsigned long dbg_trace_space[256];
8366 + unsigned long dbg_last_rvec; /* useful for tracing segfaults etc. */
8367 + unsigned long dbg_last_osi;
8369 + unsigned long kernel_dbg_stop; /* stop emulation flag */
8371 + /* host irq mapping data */
8372 + irq_bitfield_t mapped_irqs; /* keeps track of used host irqs */
8373 + irq_bitfield_t active_irqs; /* irqs that are up are marked here */
8374 + int hostirq_update; /* whether userspace should update the pic */
8375 + /* should be mol_atomic_t but causes trouble... */
8376 + int hostirq_active_cnt; /* number of active host irq lines */
8380 +#define NUM_MREGS_PAGES ((sizeof(mac_regs_t)+0xfff)/0x1000)
8382 +#define BIT(n) (1U<<(31-(n))) /* bit 0 is MSB */
8385 +extern mac_regs_t *mregs;
8387 +#endif /* __ASSEMBLY__ */
8389 +/* mregs->fpu_state (only valid when FBIT_FPUInUse is false) */
8390 +#define FPU_STATE_HALF_SAVED 0 /* fpscr & fr0-fr13 saved */
8391 +#define FPU_STATE_DIRTY 1 /* fpscr & fr13 saved */
8392 +#define FPU_STATE_SAVED 3 /* everything is saved to mregs */
8394 +/* flag_bits (loaded into cr4-7). TOUCH THESE *ONLY* FROM THE MAIN THREAD! */
8396 +/* these must be in cr7 (set through a mtcrf) */
8397 +#define MMU_CR_FIELD 0x01
8398 +#define FBIT_InSplitmode 31 /* (S) */
8399 +#define FBIT_PrepareSplitmode 30 /* (S) */
8400 +#define FBIT_LoadSegreg 29 /* (S) */
8402 +/* must be in cr6; (set through a mtcrf) */
8403 +#define TRACE_CR_FIELD 0x02
8404 +#define FBIT_DbgTrace 27 /* (S) equals BREAK_SINGLE_STEP */
8405 +#define FBIT_Trace 26 /* (S) */
8407 +#define FBIT_MolDecLoaded 23 /* (S) */
8408 +#define FBIT_DecSeenZero 22 /* (S) */
8409 +#define FBIT_DecINT 21 /* (S) */
8410 +#define FBIT_FPUInUse 20 /* (S) Set when fpu is mac-owned (only valid in the kernel) */
8414 +#define FBIT_MsrModified 19 /* (U) */
8415 +#define FBIT_RecalcDecInt 18 /* (U) */
8416 +#define FBIT_IRQPending 17 /* (U) IRQ is pending */
8418 +#define FBIT_603_AltGPR 16 /* (U) Alternate GPR0-3 in use */
8423 +#define fb_DbgTrace BIT( FBIT_DbgTrace )
8424 +#define fb_Trace BIT( FBIT_Trace )
8425 +#define fb_PrepareSplitmode BIT( FBIT_PrepareSplitmode )
8426 +#define fb_InSplitmode BIT( FBIT_InSplitmode )
8427 +#define fb_LoadSegreg BIT( FBIT_LoadSegreg )
8429 +#define fb_MsrModified BIT( FBIT_MsrModified )
8430 +#define fb_RecalcDecInt BIT( FBIT_RecalcDecInt )
8431 +#define fb_IRQPending BIT( FBIT_IRQPending )
8433 +#define fb_603_AltGPR BIT( FBIT_603_AltGPR )
8436 +#endif /* _MAC_REGISTERS_H */
8438 +++ b/drivers/macintosh/mol/include/map.h
8441 + * Creation Date: <2004/03/13 13:25:42 samuel>
8442 + * Time-stamp: <2004/03/13 14:07:11 samuel>
8448 + * Copyright (C) 2004 Samuel Rydh (samuel@ibrium.se)
8450 + * This program is free software; you can redistribute it and/or
8451 + * modify it under the terms of the GNU General Public License
8458 +/* map a userspace address into the kernel address space */
8459 +extern void *map_phys_range( ulong paddr, ulong size, char **ret_addr );
8460 +extern void unmap_phys_range( void *handle );
8462 +/* map a userspace address into the kernel address space */
8463 +extern void *map_virt_range( ulong va, ulong size, char **ret_addr );
8464 +extern void unmap_virt_range( void *handle );
8466 +/* map the virtualized PTE hash into the kernel address space */
8467 +extern ulong *map_emulated_hash( kernel_vars_t *kv, ulong mbase, ulong size );
8468 +extern void unmap_emulated_hash( kernel_vars_t *kv );
8471 +static inline ulong* map_hw_hash( ulong physbase, int size ) {
8472 + return phys_to_virt( physbase );
8474 +static inline void unmap_hw_hash( ulong *base ) {}
8478 +static inline void *map_hw_hash( ulong physbase, int size ) { return NULL; }
8479 +static inline void unmap_hw_hash( ulong *base ) {}
8482 +#endif /* _H_MAP */
8484 +++ b/drivers/macintosh/mol/include/misc.h
8487 + * Creation Date: <97/06/16 18:02:12 samuel>
8488 + * Time-stamp: <2004/03/13 14:03:30 samuel>
8494 + * Copyright (C) 1997-2004 Samuel Rydh (samuel@ibrium.se)
8496 + * This program is free software; you can redistribute it and/or
8497 + * modify it under the terms of the GNU General Public License
8498 + * as published by the Free Software Foundation
8507 +#include <linux/version.h>
8508 +#include <asm/uaccess.h>
8510 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
8511 +#define compat_verify_area(a,b,c) ( ! access_ok(a,b,c) )
8513 +#define compat_verify_area(a,b,c) verify_area(a,b,c)
8516 +#endif /* __linux__ */
8518 +extern int g_num_sessions; /* number of active sessions */
8520 +struct kernel_vars;
8523 +extern int common_init( void );
8524 +extern void common_cleanup( void );
8525 +extern int initialize_session( unsigned int sess_index );
8526 +extern void destroy_session( unsigned int sess_index );
8527 +extern uint get_session_magic( uint random_magic );
8529 +/* arch specific functions */
8530 +extern int arch_common_init( void );
8531 +extern void arch_common_cleanup( void );
8532 +extern struct kernel_vars *alloc_kvar_pages( void );
8533 +extern void free_kvar_pages( struct kernel_vars *kv );
8534 +extern void prevent_mod_unload( void );
8537 +struct dbg_op_params;
8539 +extern int do_debugger_op( kernel_vars_t *kv, struct dbg_op_params *pb );
8540 +extern int handle_ioctl( kernel_vars_t *kv, int what, int arg1, int arg2, int arg3 );
8543 +extern int grab_host_irq(kernel_vars_t *kv, int irq);
8544 +extern int release_host_irq(kernel_vars_t *kv, int irq);
8545 +extern void init_host_irqs(kernel_vars_t *kv);
8546 +extern void cleanup_host_irqs(kernel_vars_t *kv);
8549 +extern int perform_actions( void );
8550 +extern void cleanup_actions( void );
8552 +/* bit table manipulation */
8554 +set_bit_mol( int nr, char *addr )
8556 + ulong mask = 1 << (nr & 0x1f);
8557 + ulong *p = ((ulong*)addr) + (nr >> 5);
8562 +clear_bit_mol( int nr, char *addr )
8564 + ulong mask = 1 << (nr & 0x1f);
8565 + ulong *p = ((ulong*)addr) + (nr >> 5);
8570 +check_bit_mol( int nr, char *addr )
8572 + ulong mask = 1 << (nr & 0x1f);
8573 + ulong *p = ((ulong*)addr) + (nr >> 5);
8574 + return (*p & mask) != 0;
8577 +/* typesafe min/max (stolen from kernel.h) */
8578 +#define min_mol(x,y) ({ \
8579 + const typeof(x) _x = (x); \
8580 + const typeof(y) _y = (y); \
8581 + (void) (&_x == &_y); \
8582 + _x < _y ? _x : _y; })
8584 +#define max_mol(x,y) ({ \
8585 + const typeof(x) _x = (x); \
8586 + const typeof(y) _y = (y); \
8587 + (void) (&_x == &_y); \
8588 + _x > _y ? _x : _y; })
8592 +++ b/drivers/macintosh/mol/include/mmu.h
8595 + * Creation Date: <1998-11-11 13:55:49 samuel>
8596 + * Time-stamp: <2004/02/28 19:20:23 samuel>
8600 + * MMU related things
8602 + * Copyright (C) 1998-2004 Samuel Rydh (samuel@ibrium.se)
8604 + * This program is free software; you can redistribute it and/or
8605 + * modify it under the terms of the GNU General Public License
8606 + * as published by the Free Software Foundation
8613 +#ifndef __ASSEMBLY__
8614 +#include "kernel_vars.h"
8615 +#include "mac_registers.h"
8616 +#include "mmu_mappings.h"
8619 +#ifdef CONFIG_MOL_HOSTED
8620 +#define IO_PAGE_MAGIC_1 0x10BADA57
8621 +#define IO_PAGE_MAGIC_2 0x136AB779
8623 +#define IO_PAGE_MAGIC_1 0x10BACA57
8624 +#define IO_PAGE_MAGIC_2 0x135AB779
8627 +#ifndef __ASSEMBLY__
8628 +typedef struct io_page { /* Must fit within a single 4K page */
8629 + ulong magic; /* identifier 1 */
8630 + ulong magic2; /* identifier 2 */
8632 + ulong me_phys; /* physical address of this block */
8633 + ulong mphys; /* mac-physical address of block */
8634 + struct io_page *next; /* next io_page */
8636 + void *usr_data[512]; /* usr data (grain=double word) */
8640 +extern int init_mmu( kernel_vars_t *kv );
8641 +extern void cleanup_mmu( kernel_vars_t *kv );
8642 +extern void do_flush( ulong vsid, ulong va, ulong *dummy, int num );
8643 +extern void mmu_altered( kernel_vars_t *kv );
8644 +extern void clear_vsid_refs( kernel_vars_t *kv );
8647 +extern int arch_mmu_init( kernel_vars_t *kv );
8649 +/* from mmu_io.c */
8650 +struct pte_lvrange;
8651 +extern int init_mmu_io( kernel_vars_t *kv );
8652 +extern void cleanup_mmu_io( kernel_vars_t *kv );
8653 +extern int add_io_trans( kernel_vars_t *kv, ulong mbase, int size, void *usr_data );
8654 +extern int remove_io_trans( kernel_vars_t *kv, ulong mbase, int size );
8655 +extern int mphys_to_pte( kernel_vars_t *kv, ulong mphys, ulong *pte1, int is_write, struct pte_lvrange **lvrange );
8656 +extern void mmu_add_map( kernel_vars_t *kv, struct mmu_mapping *m );
8657 +extern void mmu_remove_map( kernel_vars_t *kv, struct mmu_mapping *m );
8659 +/* from context.c */
8660 +extern int init_contexts( kernel_vars_t *kv );
8661 +extern void cleanup_contexts( kernel_vars_t *kv );
8662 +extern int alloc_context( kernel_vars_t *kv );
8663 +extern void handle_context_wrap( kernel_vars_t *kv, int nvsid_needed );
8665 +/* from mmu_fb.c */
8666 +extern int init_mmu_fb( kernel_vars_t *kv );
8667 +extern void cleanup_mmu_fb( kernel_vars_t *kv );
8668 +extern void video_pte_inserted( kernel_vars_t *kv, ulong lvptr, ulong *slot,
8669 + ulong pte0, ulong pte1, ulong ea );
8670 +extern void setup_fb_acceleration( kernel_vars_t *kv, char *lvbase, int bytes_per_row, int height );
8671 +extern int get_dirty_fb_lines( kernel_vars_t *kv, short *retbuf, int num_bytes );
8673 +/* from mmu_tracker.c */
8674 +extern int init_mmu_tracker( kernel_vars_t *kv );
8675 +extern void cleanup_mmu_tracker( kernel_vars_t *kv );
8676 +extern int track_lvrange( kernel_vars_t *kv );
8677 +extern size_t get_track_buffer( kernel_vars_t *kv, char *retbuf );
8678 +extern void set_track_buffer( kernel_vars_t *kv, char *buf );
8679 +extern void lvpage_dirty( kernel_vars_t *kv, ulong lvpage );
8681 +/* These functions should be used by the debugger only */
8682 +struct dbg_page_info;
8683 +extern int dbg_get_PTE( kernel_vars_t *kv, int context, ulong va, mPTE_t *ret );
8684 +extern int dbg_get_linux_page( ulong va, struct dbg_page_info *r );
8685 +extern int dbg_translate_ea( kernel_vars_t *kv, int context, ulong va, int *ret_mphys, int data_access );
8687 +/* arch functions */
8688 +extern ulong get_phys_page( kernel_vars_t *kv, ulong lvptr, int request_rw );
8691 +#define VSID_MASK 0xffffff
8694 +#endif /* __ASSEMBLY__ */
8695 +#endif /* _H_MMU */
8697 +++ b/drivers/macintosh/mol/include/mmu_contexts.h
8700 + * Creation Date: <97/07/17 14:26:14 samuel>
8701 + * Time-stamp: <2003/06/06 19:17:26 samuel>
8703 + * <mmu_contexts.h>
8707 + * Copyright (C) 1997, 2001, 2002, 2003 Samuel Rydh
8709 + * This program is free software; you can redistribute it and/or
8710 + * modify it under the terms of the GNU General Public License
8715 +#ifndef _H_MMU_CONTEXTS
8716 +#define _H_MMU_CONTEXTS
8718 +/**********************************************************
8719 + * EVERYTHING IN THIS FILE IS UESED FOR DEBUGGING ONLY
8720 + *********************************************************/
8722 +/* MMU context identifiers */
8723 +#define kContextUnmapped 1
8724 +#define kContextMapped_S 2
8725 +#define kContextMapped_U 3
8727 +#define kContextEmulator 20 /* for debugging purposes ONLY !!!! */
8728 +#define kContextKernel 21 /* for debugging purposes ONLY !!!! */
8731 +/* Flags returned by _get_physical_page(). The first flags should
8732 + * equal the _PAGE_XXX of the old MM implementation (<2.4.6).
8734 +#define M_PAGE_PRESENT 0x001 /* software: pte contains a translation */
8735 +#define M_PAGE_USER 0x002 /* usermode access allowed */
8736 +#define M_PAGE_RW 0x004 /* usermode access allowed */
8737 +#define M_PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8738 +#define M_PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8739 +#define M_PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8740 +#define M_PAGE_WRITETHRU 0x040 /* W: cache write-through */
8741 +#define M_PAGE_DIRTY 0x080 /* C: page changed */
8742 +#define M_PAGE_ACCESSED 0x100 /* R: page referenced */
8743 +/* new linux-MM implementation */
8744 +#define M_PAGE_HASHPTE 0x1000 /* hash_page has made an HPTE for this pte */
8745 +#define M_PAGE_EXEC 0x2000 /* software: i-cache coherency required */
8748 +#define DBG_TRANSL_PAGE_FLAG( val, flagname ) \
8749 + (((val) & flagname )? M##flagname : 0)
8753 +#endif /* _H_MMU_CONTEXTS */
8755 +++ b/drivers/macintosh/mol/include/mmu_mappings.h
8758 + * Creation Date: <1998-10-31 03:11:06 samuel>
8759 + * Time-stamp: <2004/03/13 16:44:58 samuel>
8761 + * <mmu_mappings.h>
8763 + * Mappings mac physical <-> linux virtual
8765 + * Copyright (C) 1998-2004 Samuel Rydh (samuel@ibrium.se)
8767 + * This program is free software; you can redistribute it and/or
8768 + * modify it under the terms of the GNU General Public License
8769 + * as published by the Free Software Foundation
8773 +#ifndef _H_MMU_MAPPINGS
8774 +#define _H_MMU_MAPPINGS
8776 +typedef struct mmu_mapping {
8777 + ulong mbase; /* mac physical base */
8778 + char *lvbase; /* linux virtual base */
8779 + size_t size; /* size (in bytes) */
8780 + int flags; /* MAPPING_xxx */
8782 + int id; /* set to zero, returned by the kerrnel module */
8785 +/* mmu_mapping flags */
8787 +#define MAPPING_RO 1 /* read only memory (ROM etc) */
8788 +#define MAPPING_PHYSICAL 2 /* physical (ROM etc) */
8789 +#define MAPPING_SCRATCH 4 /* (block transl) scratch area */
8790 +#define MAPPING_FORCE_CACHE 8 /* force write-through caching */
8791 +#define MAPPING_FB_ACCEL 16 /* offscreen framebuffer, track changes */
8792 +#define MAPPING_FB 32 /* framebuffer (ea assumed to be constant) */
8793 +#define MAPPING_DBAT 64 /* allow use of a DBAT register */
8794 +#define MAPPING_MACOS_CONTROLS_CACHE 128 /* do not force WIM bits to 001 */
8795 +#define MAPPING_PUT_FIRST 256 /* take precedence over other translations */
8796 +#define MAPPING_MREGS 512 /* map mregs into emulated process */
8797 +#define MAPPING_FORCE_WRITABLE 4096 /* guess what... */
8800 +#define MAPPING_IO 1024 /* I/O translation */
8801 +#define MAPPING_VALID 2048 /* valid bit */
8804 +#endif /* _H_MMU_MAPPINGS */
8806 +++ b/drivers/macintosh/mol/include/mmutypes.h
8809 + * Creation Date: <2002/01/13 13:53:14 samuel>
8810 + * Time-stamp: <2002/01/27 19:56:11 samuel>
8816 + * Most of these declarations originate from the Linux Kernel
8818 + * Copyright (C) 2002 Samuel Rydh (samuel@ibrium.se)
8820 + * This program is free software; you can redistribute it and/or
8821 + * modify it under the terms of the GNU General Public License
8822 + * as published by the Free Software Foundation
8826 +#ifndef _H_MMUTYPES
8827 +#define _H_MMUTYPES
8829 +/* Hardware Page Table Entry */
8830 +typedef struct mPTE {
8831 + unsigned long v:1; /* Entry is valid */
8832 + unsigned long vsid:24; /* Virtual segment identifier */
8833 + unsigned long h:1; /* Hash algorithm indicator */
8834 + unsigned long api:6; /* Abbreviated page index */
8836 + unsigned long rpn:20; /* Real (physical) page number */
8837 + unsigned long :3; /* Unused */
8838 + unsigned long r:1; /* Referenced */
8839 + unsigned long c:1; /* Changed */
8840 + unsigned long w:1; /* Write-thru cache mode */
8841 + unsigned long i:1; /* Cache inhibited */
8842 + unsigned long m:1; /* Memory coherence */
8843 + unsigned long g:1; /* Guarded */
8844 + unsigned long :1; /* Unused */
8845 + unsigned long pp:2; /* Page protection */
8849 +typedef struct _mBATU { /* Upper part of BAT (all except 601) */
8850 + unsigned long bepi:15; /* Effective page index (virtual address) */
8851 + unsigned long :4; /* Unused */
8852 + unsigned long bl:11; /* Block size mask */
8853 + unsigned long vs:1; /* Supervisor valid */
8854 + unsigned long vp:1; /* User valid */
8857 +typedef struct _mBATL { /* Lower part of BAT (all except 601) */
8858 + unsigned long brpn:15; /* Real page index (physical address) */
8859 + unsigned long :10; /* Unused */
8860 + unsigned long w:1; /* Write-thru cache */
8861 + unsigned long i:1; /* Cache inhibit */
8862 + unsigned long m:1; /* Memory coherence */
8863 + unsigned long g:1; /* Guarded (MBZ in IBAT) */
8864 + unsigned long :1; /* Unused */
8865 + unsigned long pp:2; /* Page access protections */
8868 +typedef struct _mBAT {
8869 + mBATU batu; /* Upper register */
8870 + mBATL batl; /* Lower register */
8873 +typedef struct _mSEGREG {
8874 + unsigned long t:1; /* Normal or I/O type */
8875 + unsigned long ks:1; /* Supervisor 'key' (normally 0) */
8876 + unsigned long kp:1; /* User 'key' (normally 1) */
8877 + unsigned long n:1; /* No-execute */
8878 + unsigned long :4; /* Unused */
8879 + unsigned long vsid:24; /* Virtual Segment Identifier */
8883 +#endif /* _H_MMUTYPES */
8885 +++ b/drivers/macintosh/mol/include/mol-ioctl.h
8888 + * Creation Date: <2003/08/26 10:53:07 samuel>
8889 + * Time-stamp: <2004/02/08 20:17:58 samuel>
8895 + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
8897 + * This program is free software; you can redistribute it and/or
8898 + * modify it under the terms of the GNU General Public License
8903 +#ifndef _H_MOL_IOCTL
8904 +#define _H_MOL_IOCTL
8906 +#ifndef __ASSEMBLY__
8907 +#include "mmutypes.h"
8910 + int version; /* MOL version */
8911 + int smp_kernel; /* compiled with CONFIG_SMP */
8912 + int pvr; /* cpu version/revision (PVR) */
8915 + unsigned int tb_freq;
8918 +typedef struct perf_ctr {
8923 +typedef struct dbg_page_info {
8925 + int mflags; /* M_PAGE_XXX */
8928 +typedef struct dbg_op_params {
8930 + int operation; /* DBG_OP_xxx */
8938 + dbg_page_info_t page;
8943 +typedef struct mol_ioctl_pb {
8944 + int arg1, arg2, arg3;
8950 +#endif /* __ASSEMBLY__ */
8952 +/* ioctls that do not use the mol_ioctl_pb arg */
8953 +#define MOL_IOCTL_SMP_SEND_IPI _IO('M', 1) /* void ( void ) */
8955 +#define MOL_IOCTL_CALL_KERNEL _IO('M', 2) /* void ( void ) */
8958 +/* debugger ioctls */
8959 +#define MOL_IOCTL_DEBUGGER_OP _IOWR('M', 10, mol_ioctl_pb_t) /* int ( dbg_op_params *p ) */
8960 +#define DBG_OP_EMULATE_TLBIE 1 /* void ( ulong pageindex ) */
8961 +#define DBG_OP_EMULATE_TLBIA 2 /* void ( void ) */
8962 +#define DBG_OP_GET_PTE 3 /* lvptr, context, int ( ulong vsid, ulong va, PTE *retpte ) */
8963 +#define DBG_OP_GET_PHYS_PAGE 4 /* int ( ulong lvptr, ulong *retptr ) */
8964 +#define DBG_OP_BREAKPOINT_FLAGS 5 /* void ( ulong flags ) */
8965 +#define DBG_OP_TRANSLATE_EA 6 /* ea, context, is_data -- mphys */
8966 +#define MOL_IOCTL_CLEAR_PERF_INFO _IOWR('M', 11, mol_ioctl_pb_t) /* void ( void ) */
8967 +#define MOL_IOCTL_GET_PERF_INFO _IOWR('M', 12, mol_ioctl_pb_t) /* int ( int index, perf_ctr_t *ctr ) */
8969 +/* config selectors */
8970 +#define MOL_IOCTL_CREATE_SESSION _IOWR('M', 30, mol_ioctl_pb_t) /* int ( int session_index ) */
8971 +#define MOL_IOCTL_GET_INFO _IOWR('M', 31, mol_ioctl_pb_t) /* int ( mol_kmod_info_t *retinfo, int size ) */
8972 +#define MOL_IOCTL_SET_RAM _IOWR('M', 33, mol_ioctl_pb_t) /* void ( ulong ram_start, ulong ram_end ) */
8973 +#define MOL_IOCTL_COPY_LAST_ROMPAGE _IOWR('M', 34, mol_ioctl_pb_t) /* void ( char *destpage ) */
8974 +#define MOL_IOCTL_SPR_CHANGED _IOWR('M', 35, mol_ioctl_pb_t) /* void ( void ) */
8975 +#define MOL_IOCTL_IDLE_RECLAIM_MEMORY _IOWR('M', 36, mol_ioctl_pb_t) /* void ( void ) */
8976 +#define MOL_IOCTL_MMU_MAP _IOWR('M', 37, mol_ioctl_pb_t) /* void ( struct mmu_mapping *m, int add_map ) */
8977 +#define MOL_IOCTL_ADD_IORANGE _IOWR('M', 39, mol_ioctl_pb_t) /* void ( ulong mbase, size_t size, io_ops_t *) */
8978 +#define MOL_IOCTL_REMOVE_IORANGE _IOWR('M', 40, mol_ioctl_pb_t) /* void ( ulong mbase, size_t size ) */
8979 +#define MOL_IOCTL_SETUP_FBACCEL _IOWR('M', 41, mol_ioctl_pb_t) /* void * ( char *lvbase, int bytes_per_row, int height ) */
8980 +#define MOL_IOCTL_GET_DIRTY_FBLINES _IOWR('M', 42, mol_ioctl_pb_t) /* int ( short *rettable, int table_size_in_bytes ) */
8981 +#define MOL_IOCTL_TRACK_DIRTY_RAM _IOWR('M', 43, mol_ioctl_pb_t) /* int ( char *lvbase, size_t size ) */
8982 +#define MOL_IOCTL_GET_DIRTY_RAM _IOWR('M', 44, mol_ioctl_pb_t) /* size_t ( char *retbuf ) */
8983 +#define MOL_IOCTL_SET_DIRTY_RAM _IOWR('M', 45, mol_ioctl_pb_t) /* void ( char *dirtybuf ) */
8984 +#define MOL_IOCTL_GET_MREGS_PHYS _IOWR('M', 46, mol_ioctl_pb_t) /* ulong ( void ) */
8985 +#define MOL_IOCTL_ALLOC_EMUACCEL_SLOT _IOWR('M', 47, mol_ioctl_pb_t) /* int ( int inst_flags, int param, int inst_addr ) */
8986 +#define MOL_IOCTL_MAPIN_EMUACCEL_PAGE _IOWR('M', 48, mol_ioctl_pb_t) /* int ( int mphys ) */
8987 +#define MOL_IOCTL_TUNE_SPR _IOWR('M', 49, mol_ioctl_pb_t) /* int ( int spr, int action ) */
8988 +#define MOL_IOCTL_GET_SESSION_MAGIC _IOWR('M', 50, mol_ioctl_pb_t) /* uint ( uint new_random_magic ) */
8990 +#define MOL_IOCTL_DBG_COPY_KVARS _IOWR('M', 51, mol_ioctl_pb_t) /* int ( int session, kernel_vars_t *dest ) */
8993 +#define MOL_IOCTL_GET_MREGS_VIRT _IOWR('M', 52, mol_ioctl_pb_t) /* int ( mac_regs_t **ret ) */
8996 +#define MOL_IOCTL_GRAB_IRQ _IOWR('M', 53, mol_ioctl_pb_t) /* int ( int irq ) */
8997 +#define MOL_IOCTL_RELEASE_IRQ _IOWR('M', 54, mol_ioctl_pb_t) /* int ( int irq ) */
8998 +#define MOL_IOCTL_GET_IRQS _IOWR('M', 55, mol_ioctl_pb_t) /* int ( irq_bitfield_t * ) */
9001 +/* MOL error codes */
9002 +#define EMOLGENERAL 100
9003 +#define EMOLINUSE 101
9004 +#define EMOLINVAL 102
9005 +#define EMOLSECURITY 103
9007 +#endif /* _H_MOL_IOCTL */
9009 +++ b/drivers/macintosh/mol/include/mol_config.h
9012 + * Creation Date: <1999/05/30 15:30:25 samuel>
9013 + * Time-stamp: <2004/06/05 19:47:33 samuel>
9017 + * Header to be included first...
9019 + * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
9021 + * This program is free software; you can redistribute it and/or
9022 + * modify it under the terms of the GNU General Public License
9023 + * as published by the Free Software Foundation
9027 +#ifndef _H_MOL_CONFIG
9028 +#define _H_MOL_CONFIG
9030 +/* Some debugging flags */
9031 +#define COLLECT_RVEC_STATISTICS
9032 +//#define EMULATE_603
9033 +//#define ENABLE_ASSERT
9035 +#define _GNU_SOURCE
9037 +#define _LARGEFILE64_SOURCE
9039 +#if defined(__powerpc__) && !defined(__ppc__)
9042 +#if defined(__ppc__) && !defined(__powerpc__)
9043 +#define __powerpc__
9046 +#if !defined(__linux__) && !defined(__ASSEMBLY__)
9047 +typedef unsigned long ulong;
9050 +#if !defined(__ASSEMBLY__) && !defined(__KERNEL__)
9052 +#include <stdlib.h>
9053 +#include <string.h>
9054 +#include <unistd.h>
9055 +#include <sys/types.h>
9056 +#include <sys/stat.h>
9061 +#include "config.h"
9062 +#include "autoconf.h"
9063 +#include "unconfig.h"
9065 +#ifdef CONFIG_OLDWORLD
9066 +#define OLDWORLD_SUPPORT
9069 +#include "platform.h"
9071 +/* from emulaiton/main.c */
9072 +extern int in_security_mode;
9074 +/* common MOL header fiels */
9076 +#include "debugger.h" /* for printm */
9077 +#include "extralib.h"
9079 +#endif /* __ASSEMBLY__ && __KERNEL__ */
9081 +#ifdef __ASSEMBLY__
9082 +changequote([[[[[,]]]]])
9083 +[[[[[ /* shield includes from m4-expansion */
9086 +#endif /* _H_MOL_CONFIG */
9088 +++ b/drivers/macintosh/mol/include/molasm.h
9092 + * Creation Date: <2001/01/28 20:33:22 samuel>
9093 + * Time-stamp: <2004/01/29 19:29:10 samuel>
9097 + * Utility assembly macros
9099 + * Copyright (C) 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
9101 + * This program is free software; you can redistribute it and/or
9102 + * modify it under the terms of the GNU General Public License
9103 + * as published by the Free Software Foundation
9110 +#define GLOBAL_SYMBOL( sym_name ) \
9114 +/************************************************************************/
9116 +/************************************************************************/
9118 +/* Darwin and Linux uses the sprg's differently. Linux uses sprg0/1 in
9119 + * the exception vectors while Darwin uses sprg2/3.
9122 +define([mfsprg_a0], [mfsprg0])
9123 +define([mfsprg_a1], [mfsprg1])
9124 +define([mfsprg_a2], [mfsprg2])
9125 +define([mfsprg_a3], [mfsprg3])
9126 +define([mtsprg_a0], [mtsprg0])
9127 +define([mtsprg_a1], [mtsprg1])
9128 +define([mtsprg_a2], [mtsprg2])
9129 +define([mtsprg_a3], [mtsprg3])
9131 +define([mfsprg_a0], [mfsprg2])
9132 +define([mfsprg_a1], [mfsprg3])
9133 +define([mfsprg_a2], [mfsprg0])
9134 +define([mfsprg_a3], [mfsprg1])
9135 +define([mtsprg_a0], [mtsprg2])
9136 +define([mtsprg_a1], [mtsprg3])
9137 +define([mtsprg_a2], [mtsprg0])
9138 +define([mtsprg_a3], [mtsprg1])
9142 +/************************************************************************/
9144 +/************************************************************************/
9146 +MACRO(LOAD_VARIABLE, [reg, offs], [
9147 + lis _reg,HA(k_mol_stack + _offs)
9148 + lwz _reg,LO(k_mol_stack + _offs)(_reg)
9151 +MACRO(SET_SESSION_TABLE, [reg], [
9152 + lis _reg,HA(EXTERN(Symbol_SESSION_TABLE))
9153 + addi _reg,_reg,LO(EXTERN(Symbol_SESSION_TABLE))
9157 +/************************************************************************/
9158 +/* GPR save / restore */
9159 +/************************************************************************/
9161 +MACRO(xGPR_SAVE, [reg], [
9162 + stw rPREFIX[]_reg,(xGPR0 + _reg*4)(r1)
9165 +MACRO(xGPR_LOAD, [reg], [
9166 + lwz rPREFIX[]_reg,(xGPR0 + _reg*4)(r1)
9170 +/************************************************************************/
9172 +/************************************************************************/
9174 +MACRO(ENABLE_MSR_FP, [scr], [
9176 + ori _scr,_scr,MSR_FP
9181 +/************************************************************************/
9182 +/* Segment registers */
9183 +/************************************************************************/
9185 +MACRO(LOAD_SEGMENT_REGS, [base, scr, scr2], [
9186 + mFORLOOP([i],0,7,[
9187 + lwz _scr,eval(i * 8)(_base)
9188 + lwz _scr2,eval((i * 8)+4)(_base)
9189 + mtsr srPREFIX[]eval(i*2),_scr
9190 + mtsr srPREFIX[]eval(i*2+1),_scr2
9194 +MACRO(SAVE_SEGMENT_REGS, [base, scr, scr2], [
9195 + mFORLOOP([i],0,7,[
9196 + mfsr _scr,srPREFIX[]eval(i*2)
9197 + mfsr _scr2,srPREFIX[]eval(i*2+1)
9198 + stw _scr,eval(i * 8)(_base)
9199 + stw _scr2,eval((i * 8) + 4)(_base)
9203 +/************************************************************************/
9205 +/************************************************************************/
9207 +MACRO(SAVE_DBATS, [varoffs, scr1], [
9209 + srwi _scr1,_scr1,16
9212 + mFORLOOP([nn],0,7,[
9213 + mfspr _scr1, S_DBAT0U + nn
9214 + stw _scr1,(_varoffs + (4 * nn))(r1)
9219 +MACRO(SAVE_IBATS, [varoffs, scr1], [
9220 + mFORLOOP([nn],0,7,[
9221 + mfspr _scr1, S_IBAT0U + nn
9222 + stw _scr1,(_varoffs + (4 * nn))(r1)
9227 +#endif /* _H_MOLASM */
9229 +++ b/drivers/macintosh/mol/include/molversion.h
9231 +#define MOL_BUILD_DATE "Okt 13 2007 11:49"
9232 +#define MOL_VERSION_STR "0.9.73"
9233 +#define MOL_RELEASE "0.9.73-SVN"
9234 +#define MOL_MAJOR_VERSION 0
9235 +#define MOL_MINOR_VERSION 9
9236 +#define MOL_PATCHLEVEL 73
9238 +++ b/drivers/macintosh/mol/include/mtable.h
9241 + * Creation Date: <2002/05/26 15:52:50 samuel>
9242 + * Time-stamp: <2004/02/21 16:18:11 samuel>
9246 + * Keeps track of the PTEs
9248 + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
9250 + * This program is free software; you can redistribute it and/or
9251 + * modify it under the terms of the GNU General Public License
9252 + * as published by the Free Software Foundation
9259 +#ifndef __ASSEMBLY__
9260 +typedef struct pte_lvrange pte_lvrange_t;
9261 +typedef struct vsid_info vsid_info_t;
9262 +typedef struct vsid_ent vsid_ent_t;
9264 +extern int init_mtable( kernel_vars_t *kv );
9265 +extern void cleanup_mtable( kernel_vars_t *kv );
9267 +extern pte_lvrange_t *register_lvrange( kernel_vars_t *kv, char *lvbase, int size );
9268 +extern void free_lvrange( kernel_vars_t *kv, pte_lvrange_t *pte_range );
9270 +extern vsid_ent_t *vsid_get_user_sv( kernel_vars_t *kv, int mac_vsid, ulong *user_sr, ulong *sv_sr );
9272 +extern int mtable_memory_check( kernel_vars_t *kv );
9273 +extern void pte_inserted( kernel_vars_t *kv, ulong ea, char *lvptr,
9274 + pte_lvrange_t *lvrange, ulong *pte, vsid_ent_t *r,
9277 +extern void flush_vsid_ea( kernel_vars_t *kv, int vsid, ulong ea );
9278 +extern void flush_ea_range( kernel_vars_t *kv, ulong ea, int size );
9279 +extern void flush_lvptr( kernel_vars_t *kv, ulong lvptr );
9280 +extern void flush_lv_range( kernel_vars_t *kv, ulong lvbase, int size );
9282 +extern void clear_all_vsids( kernel_vars_t *kv );
9283 +extern void clear_pte_hash_table( kernel_vars_t *kv );
9285 +extern void mtable_reclaim( kernel_vars_t *kv );
9286 +extern void mtable_tune_alloc_limit( kernel_vars_t *kv, int ramsize_mb );
9289 +make_lvptr_reservation( kernel_vars_t *kv, char *lvptr ) {
9290 + kv->mmu.lvptr_reservation = lvptr;
9291 + kv->mmu.lvptr_reservation_lost = 0;
9295 +#endif /* __ASSEMBLY__ */
9297 +/* offsets to linux_vsid and linux_vsid_sv (used from assembly) */
9298 +#define VSID_MYSELF_VIRT 0
9299 +#define VSID_USER_OFFS 4
9300 +#define VSID_SV_OFFS 8
9301 +#define SIZEOF_VSID_ENT (64*4 + 12)
9303 +#define VSID_OFFSETS_OK \
9304 + ((offsetof(vsid_ent_t, linux_vsid) == VSID_USER_OFFS ) || \
9305 + (offsetof(vsid_ent_t, linux_vsid_sv) == VSID_SV_OFFS ) || \
9306 + (sizeof(vsid_ent_t) == SIZEOF_VSID_ENT))
9308 +#endif /* _H_MTABLE */
9312 +++ b/drivers/macintosh/mol/include/osi.h
9315 + * Creation Date: <1999/03/18 03:19:43 samuel>
9316 + * Time-stamp: <2003/12/26 16:58:19 samuel>
9318 + * <os_interface.h>
9320 + * This file includes definitions for drivers
9321 + * running in the "emulated" OS. (Mainly the 'sc'
9322 + * mechanism of communicating)
9324 + * Copyright (C) 1999, 2000, 2001, 2002, 2003 Samuel Rydh (samuel@ibrium.se)
9326 + * This program is free software; you can redistribute it and/or
9327 + * modify it under the terms of the GNU General Public License
9328 + * as published by the Free Software Foundation
9335 +/* Magic register values loaded into r3 and r4 before the 'sc' assembly instruction */
9336 +#define OSI_SC_MAGIC_R3 0x113724FA
9337 +#define OSI_SC_MAGIC_R4 0x77810F9B
9340 +/************************************************************************/
9341 +/* Selectors (passed in r5) */
9342 +/************************************************************************/
9344 +#define OSI_CALL_AVAILABLE 0
9345 +#define OSI_DEBUGGER 1 /* enter debugger */
9346 +/* obsolete OSI_LOG_STR 3 */
9347 +#define OSI_CMOUNT_DRV_VOL 4 /* conditionally mount driver volume */
9348 +/* obsolete OSI_SCSI_xxx 5-6 */
9349 +#define OSI_GET_GMT_TIME 7
9350 +#define OSI_MOUSE_CNTRL 8
9351 +#define OSI_GET_LOCALTIME 9 /* return time in secs from 01/01/04 */
9353 +#define OSI_ENET_OPEN 10
9354 +#define OSI_ENET_CLOSE 11
9355 +#define OSI_ENET_GET_ADDR 12
9356 +#define OSI_ENET_GET_STATUS 13
9357 +#define OSI_ENET_CONTROL 14
9358 +#define OSI_ENET_ADD_MULTI 16
9359 +#define OSI_ENET_DEL_MULTI 17
9360 +#define OSI_ENET_GET_PACKET 18
9361 +#define OSI_ENET_SEND_PACKET 19
9363 +#define OSI_OF_INTERFACE 20
9364 +#define OSI_OF_TRAP 21
9365 +#define OSI_OF_RTAS 22
9367 +#define OSI_SCSI_CNTRL 23
9368 +#define OSI_SCSI_SUBMIT 24
9369 +#define OSI_SCSI_ACK 25
9371 +#define OSI_GET_MOUSE 26 /* -- r3 status, r4-r8 mouse data */
9372 +#define OSI_ACK_MOUSE_IRQ 27 /* -- int */
9374 +#define OSI_SET_VMODE 28 /* modeID, depth -- error */
9375 +#define OSI_GET_VMODE_INFO 29 /* mode, depth -- r3 status, r4-r9 pb */
9376 +#define OSI_GET_MOUSE_DPI 30 /* -- mouse_dpi */
9378 +#define OSI_SET_VIDEO_POWER 31
9379 +#define OSI_GET_FB_INFO 32 /* void -- r3 status, r4-r8 video data */
9381 +#define OSI_SOUND_WRITE 33
9382 +/* #define OSI_SOUND_FORMAT 34 */
9383 +#define OSI_SOUND_SET_VOLUME 35
9384 +#define OSI_SOUND_CNTL 36
9385 +/* obsolete OSI_SOUND call 37 */
9387 +#define OSI_VIDEO_ACK_IRQ 38
9388 +#define OSI_VIDEO_CNTRL 39
9390 +#define OSI_SOUND_IRQ_ACK 40
9391 +#define OSI_SOUND_START_STOP 41
9393 +#define OSI_REGISTER_IRQ 42 /* reg_property[0] appl_int -- irq_cookie */
9394 +/* obsolete OSI_IRQ 43-46 */
9396 +#define OSI_LOG_PUTC 47 /* char -- */
9398 +#define OSI_KBD_CNTRL 50
9399 +#define OSI_GET_ADB_KEY 51 /* -- adb_keycode (keycode | keycode_id in r4) */
9401 +#define OSI_WRITE_NVRAM_BYTE 52 /* offs, byte -- */
9402 +#define OSI_READ_NVRAM_BYTE 53 /* offs -- byte */
9404 +#define OSI_EXIT 54
9406 +#define OSI_KEYCODE_TO_ADB 55 /* (keycode | keycode_id) -- adb_keycode */
9407 +#define OSI_MAP_ADB_KEY 56 /* keycode, adbcode -- */
9408 +#define OSI_SAVE_KEYMAPPING 57 /* -- */
9409 +#define OSI_USLEEP 58 /* usecs -- */
9410 +#define OSI_SET_COLOR 59 /* index value -- */
9412 +#define OSI_PIC_MASK_IRQ 60 /* irq -- */
9413 +#define OSI_PIC_UNMASK_IRQ 61 /* irq -- */
9414 +#define OSI_PIC_ACK_IRQ 62 /* irq mask_flag -- */
9415 +#define OSI_PIC_GET_ACTIVE_IRQ 63
9417 +#define OSI_GET_COLOR 64 /* index -- value */
9419 +/* 65-67 old ablk implementation */
9420 +#define OSI_IRQTEST 65
9422 +#define OSI_ENET2_OPEN 68
9423 +#define OSI_ENET2_CLOSE 69
9424 +#define OSI_ENET2_CNTRL 70
9425 +#define OSI_ENET2_RING_SETUP 71
9426 +#define OSI_ENET2_KICK 72
9427 +#define OSI_ENET2_GET_HWADDR 73
9428 +#define OSI_ENET2_IRQ_ACK 74
9430 +#define OSI_PROM_IFACE 76
9431 +#define kPromClose 0
9432 +#define kPromPeer 1
9433 +#define kPromChild 2
9434 +#define kPromParent 3
9435 +#define kPromPackageToPath 4
9436 +#define kPromGetPropLen 5
9437 +#define kPromGetProp 6
9438 +#define kPromNextProp 7
9439 +#define kPromSetProp 8
9440 +#define kPromChangePHandle 9
9442 +#define OSI_PROM_PATH_IFACE 77
9443 +#define kPromCreateNode 16
9444 +#define kPromFindDevice 17
9446 +#define OSI_BOOT_HELPER 78
9447 +#define kBootHAscii2Unicode 32
9448 +#define kBootHUnicode2Ascii 33
9449 +#define kBootHGetStrResInd 34 /* key, buf, len -- buf */
9450 +#define kBootHGetRAMSize 35 /* -- ramsize */
9452 +#define OSI_ABLK_RING_SETUP 79
9453 +#define OSI_ABLK_CNTRL 80
9454 +#define OSI_ABLK_DISK_INFO 81
9455 +#define OSI_ABLK_KICK 82
9456 +#define OSI_ABLK_IRQ_ACK 83
9457 +#define OSI_ABLK_SYNC_READ 84
9458 +#define OSI_ABLK_SYNC_WRITE 85
9459 +#define OSI_ABLK_BLESS_DISK 86
9461 +#define OSI_EMUACCEL 89 /* EMULATE_xxx, nip -- index */
9462 +#define OSI_MAPIN_MREGS 90 /* mphys */
9463 +#define OSI_NVRAM_SIZE 91
9465 +#define OSI_MTICKS_TO_USECS 92
9466 +#define OSI_USECS_TO_MTICKS 93
9468 +/* obsolete OSI_BLK 94-95 */
9470 +#define OSI_PSEUDO_FS 96
9471 +#define kPseudoFSOpen 1
9472 +#define kPseudoFSClose 2
9473 +#define kPseudoFSGetSize 3
9474 +#define kPseudoFSRead 4
9475 +#define kPseudoFSIndex2Name 5
9477 +#define OSI_TTY_PUTC 97
9478 +#define OSI_TTY_GETC 98
9479 +#define OSI_TTY_IRQ_ACK 99
9481 +#define NUM_OSI_SELECTORS 100 /* remember to increase this... */
9483 +#endif /* _H_OSI */
9485 +++ b/drivers/macintosh/mol/include/osi_calls.h
9488 + * Creation Date: <2002/06/16 01:40:57 samuel>
9489 + * Time-stamp: <2004/02/23 01:04:31 samuel>
9493 + * OSI call inlines
9495 + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
9497 + * This program is free software; you can redistribute it and/or
9498 + * modify it under the terms of the GNU General Public License
9499 + * as published by the Free Software Foundation
9503 +#ifndef _H_OSI_CALLS
9504 +#define _H_OSI_CALLS
9508 +/* Old gcc versions have a limit on the number of registers used.
9509 + * Newer gcc versions (gcc 3.3) require that the clobber list does
9510 + * not overlap declared registers.
9512 +#if __GNUC__ == 2 || ( __GNUC__ == 3 && __GNUC_MINOR__ < 3 )
9513 +#define SHORT_REGLIST
9517 +/************************************************************************/
9518 +/* OSI call instantiation macros */
9519 +/************************************************************************/
9521 +#define dreg(n) __oc_##n __asm__ (#n)
9522 +#define ir(n) "r" (__oc_##n)
9523 +#define rr(n) "=r" (__oc_##n)
9525 +#define _oc_head( input_regs... ) \
9529 + register unsigned long dreg(r3); \
9530 + register unsigned long dreg(r4); \
9531 + register unsigned long dreg(r5) \
9534 +#define _oc_syscall( number, extra_ret_regs... ) \
9535 + __oc_r3 = OSI_SC_MAGIC_R3; \
9536 + __oc_r4 = OSI_SC_MAGIC_R4; \
9537 + __oc_r5 = number; \
9538 + __asm__ __volatile__ ( \
9539 + "sc " : rr(r3) ,## extra_ret_regs
9541 +#define _oc_input( regs... ) \
9542 + : ir(r3), ir(r4), ir(r5) \
9546 +/* the tail memory clobber is necessary since we violate the strict
9547 + * aliasing rules when we return structs through the registers.
9550 + asm volatile ( "" : : : "memory" ); \
9557 +/************************************************************************/
9559 +/************************************************************************/
9561 +#ifdef SHORT_REGLIST
9563 +#define _oc_syscall_r10w6( number, inputregs... ) \
9564 + __oc_r3 = OSI_SC_MAGIC_R3; \
9565 + __oc_r4 = OSI_SC_MAGIC_R4; \
9566 + __oc_r5 = number; \
9567 + __asm__ __volatile__ ( \
9569 + "stw 4,0(10) \n" \
9570 + "stw 5,4(10) \n" \
9571 + "stw 6,8(10) \n" \
9572 + "stw 7,12(10) \n" \
9573 + "stw 8,16(10) \n" \
9574 + "stw 9,20(10) \n" \
9576 + : ir(r3), ir(r4), ir(r5), ir(r10) \
9579 + "r4", "r5", "r6", "r7", "r8", "r9" );
9582 +#define _oc_syscall_r10w6( number, inputregs... ) \
9583 + __oc_r3 = OSI_SC_MAGIC_R3; \
9584 + __oc_r4 = OSI_SC_MAGIC_R4; \
9585 + __oc_r5 = number; \
9586 + __asm__ __volatile__ ( \
9588 + "stw r4,0(r10) \n" \
9589 + "stw r5,4(r10) \n" \
9590 + "stw r6,8(r10) \n" \
9591 + "stw r7,12(r10) \n" \
9592 + "stw r8,16(r10) \n" \
9593 + "stw r9,20(r10) \n" \
9595 + : ir(r3), ir(r4), ir(r5), ir(r10) \
9598 + "r4", "r5", "r6", "r7", "r8", "r9" );
9603 +/************************************************************************/
9604 +/* Common helper functions */
9605 +/************************************************************************/
9607 +#define _osi_call0( type, name, number ) \
9608 +type name( void ) \
9610 + _oc_syscall( number ) \
9614 +#define _osi_call1( type, name, number, type1, arg1 ) \
9615 +type name( type1 arg1 ) \
9616 + _oc_head( dreg(r6) ) \
9617 + __oc_r6 = (ulong)arg1; \
9618 + _oc_syscall( number ) \
9619 + _oc_input( ir(r6) ) \
9622 +#define _osi_call2( type, name, number, t1, a1, t2, a2 ) \
9623 +type name( t1 a1, t2 a2 ) \
9624 + _oc_head( dreg(r6), dreg(r7) ) \
9625 + __oc_r6 = (ulong)a1; \
9626 + __oc_r7 = (ulong)a2; \
9627 + _oc_syscall( number ) \
9628 + _oc_input( ir(r6), ir(r7) ) \
9631 +#define _osi_call3( type, name, number, t1, a1, t2, a2, t3, a3 ) \
9632 +type name( t1 a1, t2 a2, t3 a3 ) \
9633 + _oc_head( dreg(r6), dreg(r7), dreg(r8) ) \
9634 + __oc_r6 = (ulong)a1; \
9635 + __oc_r7 = (ulong)a2; \
9636 + __oc_r8 = (ulong)a3; \
9637 + _oc_syscall( number ) \
9638 + _oc_input( ir(r6), ir(r7), ir(r8) ) \
9641 +#define _osi_call4( type, name, number, t1, a1, t2, a2, t3, a3, t4, a4 ) \
9642 +type name( t1 a1, t2 a2, t3 a3, t4 a4 ) \
9643 + _oc_head( dreg(r6), dreg(r7), dreg(r8), dreg(r9) ) \
9644 + __oc_r6 = (ulong)a1; \
9645 + __oc_r7 = (ulong)a2; \
9646 + __oc_r8 = (ulong)a3; \
9647 + __oc_r9 = (ulong)a4; \
9648 + _oc_syscall( number ) \
9649 + _oc_input( ir(r6), ir(r7), ir(r8), ir(r9) ) \
9652 +#define _osi_call5( type, name, number, t1, a1, t2, a2, t3, a3, t4, a4, t5, a5 ) \
9653 +type name( t1 a1, t2 a2, t3 a3, t4 a4, t5 a5 ) \
9654 + _oc_head( dreg(r6), dreg(r7), dreg(r8), dreg(r9), dreg(r10) ) \
9655 + __oc_r6 = (ulong)a1; \
9656 + __oc_r7 = (ulong)a2; \
9657 + __oc_r8 = (ulong)a3; \
9658 + __oc_r9 = (ulong)a4; \
9659 + __oc_r10 = (ulong)a5; \
9660 + _oc_syscall( number ) \
9661 + _oc_input( ir(r6), ir(r7), ir(r8), ir(r9), ir(r10) ) \
9664 +#define _osi_call6( type, name, number, t1, a1, t2, a2, t3, a3, t4, a4, t5, a5, t6, a6 ) \
9665 +type name( t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6 ) \
9666 + _oc_head( dreg(r6), dreg(r7), dreg(r8), dreg(r9), dreg(r10), dreg(r11) )\
9667 + __oc_r6 = (ulong)a1; \
9668 + __oc_r7 = (ulong)a2; \
9669 + __oc_r8 = (ulong)a3; \
9670 + __oc_r9 = (ulong)a4; \
9671 + __oc_r10 = (ulong)a5; \
9672 + __oc_r11 = (ulong)a6; \
9673 + _oc_syscall( number ) \
9674 + _oc_input( ir(r6), ir(r7), ir(r8), ir(r9), ir(r10), ir(r11) ) \
9678 +/************************************************************************/
9680 +/************************************************************************/
9682 +/* r4 returned in retarg1 pointer */
9683 +#define _osi_call0_w1( type, name, number, type1, retarg1 ) \
9684 +type name( type1 retarg1 ) \
9686 + _oc_syscall( number, rr(r4) ) \
9688 + *retarg1 = __oc_r4; \
9691 +#define _osi_call0_w2( type, name, number, type1, retarg1 ) \
9692 +type name( type1 retarg1 ) \
9694 + _oc_syscall( number, rr(r4), rr(r5) ) \
9696 + ((ulong*)retarg1)[0] = __oc_r4; \
9697 + ((ulong*)retarg1)[1] = __oc_r5; \
9700 +/* r4-r8 returned in retarg1 pointer */
9701 +#define _osi_call0_w5( type, name, number, type1, retarg1 ) \
9702 +type name( type1 retarg1 ) \
9703 + _oc_head( dreg(r6), dreg(r7), dreg(r8) ) \
9704 + _oc_syscall( number, \
9705 + rr(r4), rr(r5), rr(r6), rr(r7), rr(r8) ) \
9707 + ((ulong*)retarg1)[0] = __oc_r4; \
9708 + ((ulong*)retarg1)[1] = __oc_r5; \
9709 + ((ulong*)retarg1)[2] = __oc_r6; \
9710 + ((ulong*)retarg1)[3] = __oc_r7; \
9711 + ((ulong*)retarg1)[4] = __oc_r8; \
9714 +/* r4 returned in retarg pointer */
9715 +#define _osi_call1_w1( type, name, number, t1, a1, t2, retarg ) \
9716 +type name( t1 a1, t2 retarg ) \
9717 + _oc_head( dreg(r6) ) \
9718 + __oc_r6 = (ulong)a1; \
9719 + _oc_syscall( number, rr(r4) ) \
9720 + _oc_input( ir(r6) ) \
9721 + ((ulong*)retarg)[0] = __oc_r4; \
9724 +/* r4,r5 returned in retarg1, retarg2 */
9725 +#define _osi_call1_w1w1( type, name, number, t1, a1, t2, retarg1, t3, retarg2 ) \
9726 +type name( t1 a1, t2 retarg1, t3 retarg2 ) \
9727 + _oc_head( dreg(r6) ) \
9728 + __oc_r6 = (ulong)a1; \
9729 + _oc_syscall( number, rr(r4), rr(r5) ) \
9730 + _oc_input( ir(r6) ) \
9731 + ((ulong*)retarg1)[0] = __oc_r4; \
9732 + ((ulong*)retarg2)[0] = __oc_r5; \
9735 +/* r4,r5 returned in retarg1, retarg2, retarg3 */
9736 +#define _osi_call1_w1w1w1( type, name, number, t1, a1, t2, retarg1, t3, retarg2, t4, retarg3 ) \
9737 +type name( t1 a1, t2 retarg1, t3 retarg2, t4 retarg3 ) \
9738 + _oc_head( dreg(r6) ) \
9739 + __oc_r6 = (ulong)a1; \
9740 + _oc_syscall( number, rr(r4), rr(r5), rr(r6) ) \
9741 + _oc_input( ir(r6) ) \
9742 + ((ulong*)retarg1)[0] = __oc_r4; \
9743 + ((ulong*)retarg2)[0] = __oc_r5; \
9744 + ((ulong*)retarg3)[0] = __oc_r6; \
9747 +/* r4,r5 returned in retarg pointer */
9748 +#define _osi_call1_w2( type, name, number, t1, a1, t2, retarg ) \
9749 +type name( t1 a1, t2 retarg ) \
9750 + _oc_head( dreg(r6) ) \
9751 + __oc_r6 = (ulong)a1; \
9752 + _oc_syscall( number, rr(r4), rr(r5) ) \
9753 + _oc_input( ir(r6) ) \
9754 + ((ulong*)retarg)[0] = __oc_r4; \
9755 + ((ulong*)retarg)[1] = __oc_r5; \
9758 +/* r4-r7 returned in retarg pointer */
9759 +#define _osi_call1_w4( type, name, number, t1, a1, t2, retarg ) \
9760 +type name( t1 a1, t2 retarg ) \
9761 + _oc_head( dreg(r6), dreg(r7) ) \
9762 + __oc_r6 = (ulong)a1; \
9763 + _oc_syscall( number, rr(r4), rr(r5), rr(r6), rr(r7) ) \
9764 + _oc_input( ir(r6) ) \
9765 + ((ulong*)retarg)[0] = __oc_r4; \
9766 + ((ulong*)retarg)[1] = __oc_r5; \
9767 + ((ulong*)retarg)[2] = __oc_r6; \
9768 + ((ulong*)retarg)[3] = __oc_r7; \
9772 +/* r4-r5 returned in retarg pointer */
9773 +#define _osi_call2_w2( type, name, number, t1, a1, t2, a2, t3, retarg ) \
9774 +type name( t1 a1, t2 a2, t3 retarg ) \
9775 + _oc_head( dreg(r6), dreg(r7) ) \
9776 + __oc_r6 = (ulong)a1; \
9777 + __oc_r7 = (ulong)a2; \
9778 + _oc_syscall( number, rr(r4), rr(r5) ) \
9779 + _oc_input( ir(r6), ir(r7) ) \
9780 + ((ulong*)retarg)[0] = __oc_r4; \
9781 + ((ulong*)retarg)[1] = __oc_r5; \
9784 +/* r4-r7 returned in retarg pointer */
9785 +#define _osi_call2_w4( type, name, number, t1, a1, t2, a2, t3, retarg ) \
9786 +type name( t1 a1, t2 a2, t3 retarg ) \
9787 + _oc_head( dreg(r6), dreg(r7) ) \
9788 + __oc_r6 = (ulong)a1; \
9789 + __oc_r7 = (ulong)a2; \
9790 + _oc_syscall( number, rr(r4), rr(r5), rr(r6), rr(r7) ) \
9791 + _oc_input( ir(r6), ir(r7) ) \
9792 + ((ulong*)retarg)[0] = __oc_r4; \
9793 + ((ulong*)retarg)[1] = __oc_r5; \
9794 + ((ulong*)retarg)[2] = __oc_r6; \
9795 + ((ulong*)retarg)[3] = __oc_r7; \
9798 +#ifdef SHORT_REGLIST
9799 +/* r4-r9 returned in retarg pointer */
9800 +#define _osi_call2_w6( type, name, number, t1, a1, t2, a2, t3, retarg ) \
9801 +type name( t1 a1, t2 a2, t3 retarg ) \
9802 + _oc_head( dreg(r6), dreg(r7), dreg(r10) ) \
9803 + __oc_r6 = (ulong)a1; \
9804 + __oc_r7 = (ulong)a2; \
9805 + __oc_r10 = (ulong)retarg; \
9806 + _oc_syscall_r10w6( number, ir(r6), ir(r7) ) \
9809 +#else /* SHORT_REGLIST */
9811 +/* r4-r9 returned in retarg pointer */
9812 +#define _osi_call2_w6( type, name, number, t1, a1, t2, a2, t3, retarg ) \
9813 +type name( t1 a1, t2 a2, t3 retarg ) \
9814 + _oc_head( dreg(r6), dreg(r7), dreg(r8), dreg(r9) ) \
9815 + __oc_r6 = (ulong)a1; \
9816 + __oc_r7 = (ulong)a2; \
9817 + _oc_syscall( number, rr(r4), rr(r5), rr(r6), rr(r7), rr(r8), rr(r9) ) \
9818 + _oc_input( ir(r6), ir(r7) ) \
9819 + ((ulong*)retarg)[0] = __oc_r4; \
9820 + ((ulong*)retarg)[1] = __oc_r5; \
9821 + ((ulong*)retarg)[2] = __oc_r6; \
9822 + ((ulong*)retarg)[3] = __oc_r7; \
9823 + ((ulong*)retarg)[4] = __oc_r8; \
9824 + ((ulong*)retarg)[5] = __oc_r9; \
9827 +#endif /* SHORT_REGLIST */
9830 +/************************************************************************/
9831 +/* OSI call inlines */
9832 +/************************************************************************/
9834 +static inline _osi_call1( int, OSI_CallAvailable, OSI_CALL_AVAILABLE, int, osi_num );
9836 +static inline _osi_call1( int, OSI_PutC, OSI_LOG_PUTC, int, ch );
9838 +static inline _osi_call1( int, OSI_Debugger, OSI_DEBUGGER, int, num );
9839 +static inline _osi_call0( int, OSI_Exit, OSI_EXIT );
9842 +static inline _osi_call0( ulong, OSI_GetLocalTime, OSI_GET_LOCALTIME );
9843 +static inline _osi_call0( ulong, OSI_GetGMTTime, OSI_GET_GMT_TIME );
9844 +static inline _osi_call1( int, OSI_USleep, OSI_USLEEP, int, usecs );
9847 +static inline _osi_call0( int, OSI_NVRamSize, OSI_NVRAM_SIZE );
9848 +static inline _osi_call1( int, OSI_ReadNVRamByte, OSI_READ_NVRAM_BYTE, int, offs );
9849 +static inline _osi_call2( int, OSI_WriteNVRamByte, OSI_WRITE_NVRAM_BYTE, int, offs,
9850 + unsigned char, ch );
9852 +/* keyboard stuff */
9853 +static inline _osi_call0_w1( int, OSI_GetAdbKey2, OSI_GET_ADB_KEY, int *, raw_key );
9854 +static inline _osi_call1( int, OSI_KbdCntrl, OSI_KBD_CNTRL, int, cmd );
9856 +static inline int OSI_GetAdbKey( void )
9857 + { int dummy_raw_key; return OSI_GetAdbKey2( &dummy_raw_key ); }
9858 +static inline _osi_call2( int, OSI_MapAdbKey, OSI_MAP_ADB_KEY, int, keycode, int, adbkey )
9859 +static inline _osi_call1( int, OSI_KeycodeToAdb, OSI_KEYCODE_TO_ADB, int, keycode );
9860 +static inline _osi_call0( int, OSI_SaveKeymapping, OSI_SAVE_KEYMAPPING );
9862 +/* mouse support */
9864 +static inline _osi_call0_w5( int, OSI_GetMouse, OSI_GET_MOUSE, struct osi_mouse *, ret );
9865 +static inline _osi_call0( int, OSI_GetMouseDPI, OSI_GET_MOUSE_DPI );
9868 +static inline _osi_call2( int, OSI_SetVMode_, OSI_SET_VMODE, int, mode, int, depth_mode );
9869 +struct osi_get_vmode_info;
9870 +static inline _osi_call2_w6( int, OSI_GetVModeInfo_, OSI_GET_VMODE_INFO, int, mode, int, depth_mode,
9871 + struct osi_get_vmode_info *, ret );
9872 +static inline _osi_call1( int, OSI_SetVPowerState, OSI_SET_VIDEO_POWER, int, power_state );
9873 +static inline _osi_call2( int, OSI_SetColor, OSI_SET_COLOR, int, index, int, rgb );
9874 +static inline _osi_call0_w1( int, OSI_VideoAckIRQ, OSI_VIDEO_ACK_IRQ, int *, events );
9876 +static inline void OSI_RefreshPalette( void ) { OSI_SetColor(-1,0); }
9878 +/* PIC (mac-io replacement) */
9879 +static inline _osi_call1( int, OSI_PICMaskIRQ, OSI_PIC_MASK_IRQ, int, irq );
9880 +static inline _osi_call1( int, OSI_PICUnmaskIRQ, OSI_PIC_UNMASK_IRQ, int, irq );
9881 +static inline _osi_call2( int, OSI_PICAckIRQ, OSI_PIC_ACK_IRQ, int, irq, int, mask_it );
9882 +static inline _osi_call0( int, OSI_PICGetActiveIRQ, OSI_PIC_GET_ACTIVE_IRQ );
9885 +static inline _osi_call1( int, OSI_SoundCntl, OSI_SOUND_CNTL, int, cmd );
9886 +static inline _osi_call2( int, OSI_SoundCntl1, OSI_SOUND_CNTL, int, cmd, int, p1 );
9887 +static inline _osi_call3( int, OSI_SoundCntl2, OSI_SOUND_CNTL, int, cmd, int, p1, int, p2 );
9888 +static inline _osi_call0_w2( int, OSI_SoundIRQAck, OSI_SOUND_IRQ_ACK, ulong *, timestamp );
9889 +static inline _osi_call3( int, OSI_SoundWrite, OSI_SOUND_WRITE, int, physbuf, int, len, int, restart );
9890 +static inline _osi_call3( int, OSI_SoundSetVolume, OSI_SOUND_SET_VOLUME, int, hwvol, int, speakervol, int, mute );
9892 +/* async block driver */
9893 +struct ablk_disk_info;
9894 +static inline _osi_call2_w4( int, OSI_ABlkDiskInfo, OSI_ABLK_DISK_INFO, int, channel, int, unit,
9895 + struct ablk_disk_info *, retinfo );
9896 +static inline _osi_call1( int, OSI_ABlkKick, OSI_ABLK_KICK, int, channel );
9897 +static inline _osi_call1_w1w1w1( int, OSI_ABlkIRQAck, OSI_ABLK_IRQ_ACK, int, channel, int *, req_count,
9898 + int *, active, int *, events );
9899 +static inline _osi_call3( int, OSI_ABlkRingSetup, OSI_ABLK_RING_SETUP, int, channel, int, mphys, int, n_el );
9900 +static inline _osi_call2( int, OSI_ABlkCntrl, OSI_ABLK_CNTRL, int, channel, int, cmd );
9901 +static inline _osi_call3( int, OSI_ABlkCntrl1, OSI_ABLK_CNTRL, int, channel, int, cmd, int, param );
9902 +static inline _osi_call5( int, OSI_ABlkSyncRead, OSI_ABLK_SYNC_READ, int, channel, int, unit,
9903 + int, blk, ulong, mphys, int, size );
9904 +static inline _osi_call5( int, OSI_ABlkSyncWrite, OSI_ABLK_SYNC_WRITE, int, channel, int, unit,
9905 + int, blk, ulong, mphys, int, size );
9906 +static inline _osi_call2( int, OSI_ABlkBlessDisk, OSI_ABLK_BLESS_DISK, int, channel, int, unit );
9908 +static inline _osi_call0( int, OSI_CMountDrvVol, OSI_CMOUNT_DRV_VOL );
9911 +static inline _osi_call0( int, OSI_Enet2Open, OSI_ENET2_OPEN );
9912 +static inline _osi_call0( int, OSI_Enet2Close, OSI_ENET2_CLOSE );
9913 +static inline _osi_call3( int, OSI_Enet2RingSetup, OSI_ENET2_RING_SETUP, int, which_ring,
9914 + int, ring_mphys, int, n_el );
9915 +static inline _osi_call2( int, OSI_Enet2Cntrl1, OSI_ENET2_CNTRL, int, cmd, int, param );
9916 +static inline _osi_call1( int, OSI_Enet2Cntrl, OSI_ENET2_CNTRL, int, cmd );
9917 +static inline _osi_call0( int, OSI_Enet2Kick, OSI_ENET2_KICK );
9919 +static inline _osi_call0_w2( int, OSI_Enet2GetHWAddr__, OSI_ENET2_GET_HWADDR, ulong *, retbuf );
9920 +static inline int OSI_Enet2GetHWAddr( unsigned char *addr ) {
9924 + ret = OSI_Enet2GetHWAddr__( buf );
9926 + ((ulong*)addr)[0] = buf[0];
9927 + ((ushort*)addr)[2] = (buf[1] >> 16);
9930 +static inline _osi_call2( int, OSI_Enet2IRQAck, OSI_ENET2_IRQ_ACK, int, irq_enable, int, rx_head );
9932 +/* PROM (device-tree) */
9933 +static inline _osi_call2( int, OSI_PromIface, OSI_PROM_IFACE, int, what, int, ph );
9934 +static inline _osi_call3( int, OSI_PromIface1, OSI_PROM_IFACE, int, what, int, ph, int, p1 );
9935 +static inline _osi_call4( int, OSI_PromIface2, OSI_PROM_IFACE, int, what, int, ph, int, p1, int, p2 );
9936 +static inline _osi_call5( int, OSI_PromIface3, OSI_PROM_IFACE, int, what, int, ph, int, p1, int, p2, int, p3 );
9937 +static inline _osi_call2( int, OSI_PromPathIface, OSI_PROM_PATH_IFACE, int, what, const char *, p );
9939 +/* emulation acceleration */
9940 +static inline _osi_call1( int, OSI_MapinMregs, OSI_MAPIN_MREGS, ulong, mphys );
9941 +static inline _osi_call3( int, OSI_EmuAccel, OSI_EMUACCEL, int, emuaccel_flags, int, param, int, inst_addr );
9943 +/* timer frequency */
9944 +static inline _osi_call1( int, OSI_MticksToUsecs, OSI_MTICKS_TO_USECS, ulong, mticks );
9945 +static inline _osi_call1( int, OSI_UsecsToMticks, OSI_USECS_TO_MTICKS, ulong, usecs );
9948 +struct osi_fb_info;
9949 +static inline _osi_call0_w5( int, OSI_GetFBInfo, OSI_GET_FB_INFO, struct osi_fb_info *, retinfo );
9952 +static inline _osi_call0( int, OSI_SCSIAck, OSI_SCSI_ACK );
9953 +static inline _osi_call1( int, OSI_SCSISubmit, OSI_SCSI_SUBMIT, int, req_mphys );
9954 +static inline _osi_call2( int, OSI_SCSIControl, OSI_SCSI_CNTRL, int, sel, int, param );
9957 +static inline _osi_call0( int, OSI_TTYGetc, OSI_TTY_GETC );
9958 +static inline _osi_call1( int, OSI_TTYPutc, OSI_TTY_PUTC, int, ch );
9959 +static inline _osi_call0( int, OSI_TTYIRQAck, OSI_TTY_IRQ_ACK );
9961 +#endif /* _H_OSI_CALLS */
9963 +++ b/drivers/macintosh/mol/include/performance.h
9966 + * Creation Date: <2001/04/01 00:44:40 samuel>
9967 + * Time-stamp: <2003/01/27 02:42:03 samuel>
9971 + * performance counters
9973 + * Copyright (C) 2001, 2002 Samuel Rydh (samuel@ibrium.se)
9975 + * This program is free software; you can redistribute it and/or
9976 + * modify it under the terms of the GNU General Public License
9977 + * as published by the Free Software Foundation
9981 +#ifndef _H_PERFORMANCE
9982 +#define _H_PERFORMANCE
9986 + unsigned long *ctrptr;
9989 +extern perf_info_t g_perf_info_table[];
9991 +#if defined(PERFORMANCE_INFO) && !defined(PERFORMANCE_INFO_LIGHT)
9992 +#define BUMP(x) do { extern int gPerf__##x; gPerf__##x++; } while(0)
9993 +#define BUMP_N(x,n) do { extern int gPerf__##x; gPerf__##x+=(n); } while(0)
9995 +#define BUMP(x) do {} while(0)
9996 +#define BUMP_N(x,n) do {} while(0)
10000 +/************************************************************************/
10001 +/* tick counters */
10002 +/************************************************************************/
10004 +#ifdef PERFORMANCE_INFO
10006 +#define TICK_CNTR_PUSH( kv ) do { \
10007 + int ind = (kv)->num_acntrs; \
10008 + acc_counter_t *c = &(kv)->acntrs[ind]; \
10009 + if( ind < MAX_ACC_CNTR_DEPTH ) { \
10011 + (kv)->num_acntrs++; \
10012 + asm volatile( "mftb %0" : "=r" (c->stamp) : ); \
10016 +#define TICK_CNTR_POP( kv, name ) do { \
10017 + int ind = (kv)->num_acntrs; \
10018 + ulong now, ticks; \
10019 + asm volatile( "mftb %0" : "=r" (now) : ); \
10020 + if( --ind >= 0 ) { \
10021 + acc_counter_t *c = &(kv)->acntrs[ind]; \
10022 + (kv)->num_acntrs = ind; \
10023 + ticks = now - c->stamp - c->subticks; \
10024 + BUMP_N( name##_ticks, ticks ); \
10026 + (kv)->acntrs[ind-1].subticks += ticks; \
10031 +#define TICK_CNTR_PUSH( kv ) do {} while(0)
10032 +#define TICK_CNTR_POP( kv, name ) do {} while(0)
10035 +#endif /* _H_PERFORMANCE */
10037 +++ b/drivers/macintosh/mol/include/platform.h
10040 + * Creation Date: <2001/12/29 19:46:46 samuel>
10041 + * Time-stamp: <2004/02/07 16:51:57 samuel>
10045 + * Misc definitions needed on certain platforms
10047 + * Copyright (C) 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
10049 + * This program is free software; you can redistribute it and/or
10050 + * modify it under the terms of the GNU General Public License
10051 + * as published by the Free Software Foundation
10055 +#ifndef _H_PLATFORM
10056 +#define _H_PLATFORM
10062 +typedef unsigned long long ullong;
10063 +typedef long long llong;
10065 +typedef signed char s8;
10066 +typedef unsigned char u8;
10067 +typedef signed short s16;
10068 +typedef unsigned short u16;
10069 +typedef signed int s32;
10070 +typedef unsigned int u32;
10071 +typedef signed long long s64;
10072 +typedef unsigned long long u64;
10074 +#define TO_ULLONG( hi, lo ) (((ullong)(hi)<< 32 ) | (lo) )
10075 +#define TO_LLONG( hi, lo ) (((llong)(hi)<< 32 ) | (lo) )
10077 +#ifndef TEMP_FAILURE_RETRY
10078 +# define TEMP_FAILURE_RETRY(expression) \
10080 + ({ long int __result; \
10081 + do __result = (long int) (expression); \
10082 + while (__result == -1L && errno == EINTR); \
10087 + * Allow us to mark functions as 'deprecated' and have gcc emit a nice
10088 + * warning for each use, in hopes of speeding the functions removal.
10090 + * int __deprecated foo(void)
10092 +#if __GNUC__ == 2 && __GNUC_MINOR__ < 96
10093 +#define __builtin_expect(x, expected_value) (x)
10096 +#define likely(x) __builtin_expect((x),1)
10097 +#define unlikely(x) __builtin_expect((x),0)
10099 +#ifndef HAVE_CLEARENV
10100 +static inline int clearenv( void ) { extern char **environ; environ=NULL; return 0; }
10104 +#define ARCH_STR "osx"
10108 +#define ARCH_STR "linux"
10111 +#endif /* _H_PLATFORM */
10113 +++ b/drivers/macintosh/mol/include/processor.h
10116 + * Creation Date: <2000/10/29 01:43:29 samuel>
10117 + * Time-stamp: <2003/07/27 22:37:49 samuel>
10121 + * Extract from <asm/processor.h>
10124 + * This program is free software; you can redistribute it and/or
10125 + * modify it under the terms of the GNU General Public License
10126 + * as published by the Free Software Foundation
10130 +#ifndef _H_PROCESSOR
10131 +#define _H_PROCESSOR
10134 +#define PTE0_VSID(s) (((s)>>7) & 0xffffff)
10135 +#define PTE0_V BIT(0)
10136 +#define PTE0_H BIT(25)
10137 +#define PTE0_API 0x3f
10139 +#define PTE1_R BIT(23)
10140 +#define PTE1_C BIT(24)
10141 +#define PTE1_W BIT(25)
10142 +#define PTE1_I BIT(26)
10143 +#define PTE1_M BIT(27)
10144 +#define PTE1_G BIT(28)
10145 +#ifdef CONFIG_AMIGAONE
10146 +/* Memory coherence locks up A1 compatible systems. */
10147 +#define PTE1_WIMG (PTE1_W | PTE1_I | PTE1_G)
10149 +#define PTE1_WIMG (PTE1_W | PTE1_I | PTE1_M | PTE1_G)
10151 +#define PTE1_PP 0x3
10152 +#define PTE1_RPN (~0xfffUL)
10154 +#define VSID_Ks BIT(1)
10155 +#define VSID_Kp BIT(2)
10156 +#define VSID_N BIT(3)
10162 +#define MSR_VEC (1<<25) /* 6: Enable AltiVec */
10163 +#define MSR_POW (1<<18) /* 13: Enable Power Management */
10164 +#define MSR_TGPR (1<<17) /* 14: TLB Update registers in use */
10165 +#define MSR_ILE (1<<16) /* 15: Interrupt Little Endian */
10166 +#define MSR_EE (1<<15) /* 16: External Interrupt Enable */
10167 +#define MSR_PR (1<<14) /* 17: Privilege Level */
10168 +#define MSR_FP (1<<13) /* 18: Floating Point enable */
10169 +#define MSR_ME (1<<12) /* 19: Machine Check Enable */
10170 +#define MSR_FE0 (1<<11) /* 20: Floating Exception mode 0 */
10171 +#define MSR_SE (1<<10) /* 21: Single Step */
10172 +#define MSR_BE (1<<9) /* 22: Branch Trace */
10173 +#define MSR_FE1 (1<<8) /* 23: Floating Exception mode 1 */
10174 +#define MSR_IP (1<<6) /* 25: Exception prefix 0x000/0xFFF */
10175 +#define MSR_IR (1<<5) /* 26: Instruction Relocate */
10176 +#define MSR_DR (1<<4) /* 27: Data Relocate */
10177 +#define MSR_PE (1<<2) /* 29: Performance Monitor Flag */
10178 +#define MSR_RI (1<<1) /* 30: Recoverable Exception */
10179 +#define MSR_LE (1<<0) /* 31: Little Endian */
10181 +#endif /* MSR_VEC */
10185 +#define NUM_SPRS 1024
10187 +#define S_RTCU_R 4 /* 601 RTC Upper/Lower (Reading) */
10188 +#define S_RTCL_R 5
10191 +#define S_DSISR 18 /* Source Instruction Service Register */
10192 +#define S_DAR 19 /* Data Address Register */
10193 +#define S_RTCU_W 20 /* 601 RTC Upper/Lower (Writing) */
10194 +#define S_RTCL_W 21
10195 +#define S_DEC 22 /* Decrementer Register */
10196 +#define S_SDR1 25 /* Table Search Description Register */
10197 +#define S_SRR0 26 /* Save and Restore Register 0 */
10198 +#define S_SRR1 27 /* Save and Restore Register 1 */
10199 +#define S_VRSAVE 256 /* (AltiVec) Vector Register Save Register */
10200 +#define S_TBRL 268 /* Time base Upper/Lower (Reading) */
10201 +#define S_TBRU 269
10202 +#define S_SPRG0 272 /* SPR General 0-3 */
10203 +#define S_SPRG1 273
10204 +#define S_SPRG2 274
10205 +#define S_SPRG3 275
10206 +#define S_SPRG4 276 /* SPR General 4-7 (7445/7455) */
10207 +#define S_SPRG5 277
10208 +#define S_SPRG6 278
10209 +#define S_SPRG7 279
10210 +#define S_EAR 282 /* External Access Register */
10211 +#define S_TBWL 284 /* Time base Upper/Lower (Writing) */
10212 +#define S_TBWU 285
10213 +#define S_PVR 287 /* Processor Version Register */
10214 +#define S_IBAT0U 528
10215 +#define S_IBAT0L 529
10216 +#define S_IBAT1U 530
10217 +#define S_IBAT1L 531
10218 +#define S_IBAT2U 532
10219 +#define S_IBAT2L 533
10220 +#define S_IBAT3U 534
10221 +#define S_IBAT3L 535
10222 +#define S_DBAT0U 536
10223 +#define S_DBAT0L 537
10224 +#define S_DBAT1U 538
10225 +#define S_DBAT1L 539
10226 +#define S_DBAT2U 540
10227 +#define S_DBAT2L 541
10228 +#define S_DBAT3U 542
10229 +#define S_DBAT3L 543
10230 +#define S_UMMCR2 928
10231 +#define S_UPMC5 929 /* User Performance Monitor Counter Register */
10232 +#define S_UPMC6 930
10233 +#define S_UBAMR 935
10234 +#define S_UMMCR0 936 /* User Monitor Mode Control Register */
10235 +#define S_UPMC1 937
10236 +#define S_UPMC2 938
10237 +#define S_USIAR 939 /* User Sampled Instruction Address Register */
10238 +#define S_UMMCR1 940
10239 +#define S_UPMC3 941
10240 +#define S_UPMC4 942 /* User Performance Monitor Counter Register 4 */
10241 +#define S_USDAR 943 /* User Sampled Data Address Register */
10242 +#define S_MMCR2 944 /* Monitor Mode Control Register */
10243 +#define S_PMC5 945
10244 +#define S_PMC6 946
10245 +#define S_BAMR 951 /* Breakpoint Address Mask Register (74xx) */
10246 +#define S_MMCR0 952 /* Monitor Mode Control Register 0 */
10247 +#define S_PMC1 953 /* Performance Counter Register */
10248 +#define S_PMC2 954
10249 +#define S_SIAR 955 /* Sampled Instruction Address Register */
10250 +#define S_MMCR1 956
10251 +#define S_PMC3 957
10252 +#define S_PMC4 958
10253 +#define S_SDAR 959 /* Sampled Data Address Register */
10254 +#define S_DMISS 976 /* 603 */
10255 +#define S_DCMP 977 /* 603 */
10256 +#define S_HASH1 978 /* 603 */
10257 +#define S_HASH2 979 /* 603 */
10258 +#define S_IMISS 980 /* 603 */
10259 +#define S_TLBMISS 980 /* 7445/7455 */
10260 +#define S_ICMP 981 /* 603 */
10261 +#define S_PTEHI 981 /* 7445/7455 */
10262 +#define S_RPA 982 /* 603 */
10263 +#define S_PTELO 982 /* 7445/7455 */
10264 +#define S_L3PM 983 /* L3 Private Memory Address Control Register */
10265 +#define S_L3ITCR0 984 /* ??? */
10266 +#define S_L3OHCR 1000 /* ??? */
10267 +#define S_L3ITCR1 1001 /* ??? */
10268 +#define S_L3ITCR2 1002 /* ??? */
10269 +#define S_L3ITCR3 1003 /* ??? */
10270 +#define S_HID0 1008 /* Hardware Implementation Registers */
10271 +#define S_HID1 1009
10272 +#define S_HID2 1010
10273 +#define S_IABR S_HID2 /* HID2 - Instruction Address Breakpoint Register */
10274 +#define S_ICTRL 1011 /* HID3 - Instruction Cache & Interrupt control reg */
10275 +#define S_HID4 1012 /* HID4 - Instruction Address Compare 1 (?) */
10276 +#define S_HID5 1013
10277 +#define S_DABR S_HID5 /* HID5 - Data Address Breakpoint */
10278 +#define S_MSSCR0 1014 /* HID6 - Memory Subsystem Control Register 0 */
10279 +#define S_MSSCR1 1015 /* HID7 - Memory Subsystem Control Register 1 */
10280 +#define S_LDSTCR 1016 /* HID8 - Load/Store Control Register */
10281 +#define S_L2CR 1017 /* HID9 - Level 2 Cache Control Regsiter */
10282 +#define S_L3CR 1018 /* HID10 - Level 3 Cache Control Regsiter (7450) */
10283 +#define S_HID11 1019
10284 +#define S_ICTC S_HID11 /* HID11 - Instruction Cache Throttling Control Reg */
10285 +#define S_ICCR S_HID11 /* Instruction Cache Cacheability Reigster */
10286 +#define S_THRM1 1020 /* HID12 - Thermal Management Register 1 */
10287 +#define S_THRM2 1021 /* HID13 - Thermal Management Register 2 */
10288 +#define S_THRM3 1022 /* HID14 - Thermal Management Register 3 */
10289 +#define S_HID15 1023
10290 +#define S_PIR S_HID15 /* HID15 - Processor Identification Register */
10292 +#endif /* S_SPRG0 */
10294 +/* the kernel might define these too... */
10295 +#if !defined(__KERNEL__) || defined(__ASSEMBLY__)
10297 +/* Floating Point Status and Control Register (FPSCR) Fields */
10298 +#define FPSCR_FX 0x80000000 /* FPU exception summary */
10299 +#define FPSCR_FEX 0x40000000 /* FPU enabled exception summary */
10300 +#define FPSCR_VX 0x20000000 /* Invalid operation summary */
10301 +#define FPSCR_OX 0x10000000 /* Overflow exception summary */
10302 +#define FPSCR_UX 0x08000000 /* Underflow exception summary */
10303 +#define FPSCR_ZX 0x04000000 /* Zero-devide exception summary */
10304 +#define FPSCR_XX 0x02000000 /* Inexact exception summary */
10305 +#define FPSCR_VXSNAN 0x01000000 /* Invalid op for SNaN */
10306 +#define FPSCR_VXISI 0x00800000 /* Invalid op for Inv - Inv */
10307 +#define FPSCR_VXIDI 0x00400000 /* Invalid op for Inv / Inv */
10308 +#define FPSCR_VXZDZ 0x00200000 /* Invalid op for Zero / Zero */
10309 +#define FPSCR_VXIMZ 0x00100000 /* Invalid op for Inv * Zero */
10310 +#define FPSCR_VXVC 0x00080000 /* Invalid op for Compare */
10311 +#define FPSCR_FR 0x00040000 /* Fraction rounded */
10312 +#define FPSCR_FI 0x00020000 /* Fraction inexact */
10313 +#define FPSCR_FPRF 0x0001f000 /* FPU Result Flags */
10314 +#define FPSCR_FPCC 0x0000f000 /* FPU Condition Codes */
10315 +#define FPSCR_VXSOFT 0x00000400 /* Invalid op for software request */
10316 +#define FPSCR_VXSQRT 0x00000200 /* Invalid op for square root */
10317 +#define FPSCR_VXCVI 0x00000100 /* Invalid op for integer convert */
10318 +#define FPSCR_VE 0x00000080 /* Invalid op exception enable */
10319 +#define FPSCR_OE 0x00000040 /* IEEE overflow exception enable */
10320 +#define FPSCR_UE 0x00000020 /* IEEE underflow exception enable */
10321 +#define FPSCR_ZE 0x00000010 /* IEEE zero divide exception enable */
10322 +#define FPSCR_XE 0x00000008 /* FP inexact exception enable */
10323 +#define FPSCR_NI 0x00000004 /* FPU non IEEE-Mode */
10324 +#define FPSCR_RN 0x00000003 /* FPU rounding control */
10327 +#define HID0_EMCP (1<<31) /* Enable Machine Check pin */
10328 +#define HID0_EBA (1<<29) /* Enable Bus Address Parity */
10329 +#define HID0_EBD (1<<28) /* Enable Bus Data Parity */
10330 +#define HID0_SBCLK (1<<27)
10331 +#define HID0_EICE (1<<26)
10332 +#define HID0_ECLK (1<<25)
10333 +#define HID0_PAR (1<<24)
10334 +#define HID0_DOZE (1<<23)
10335 +#define HID0_NAP (1<<22)
10336 +#define HID0_SLEEP (1<<21)
10337 +#define HID0_DPM (1<<20)
10338 +#define HID0_NHR (1<<16) /* Not Hard Reset */
10339 +#define HID0_ICE (1<<15) /* Instruction Cache Enable */
10340 +#define HID0_DCE (1<<14) /* Data Cache Enable */
10341 +#define HID0_ILOCK (1<<13) /* Instruction Cache Lock */
10342 +#define HID0_DLOCK (1<<12) /* Data Cache Lock */
10343 +#define HID0_ICFI (1<<11) /* Instr. Cache Flash Invalidate */
10344 +#define HID0_DCFI (1<<10) /* Data Cache Flash Invalidate */
10345 +#define HID0_SPD (1<<9) /* Speculative disable */
10346 +#define HID0_SGE (1<<7) /* Store Gathering Enable */
10347 +#define HID0_SIED (1<<7) /* Serial Instr. Execution [Disable] */
10348 +#define HID0_BTIC (1<<5) /* Branch Target Instruction Cache Enable */
10349 +#define HID0_ABE (1<<3) /* Address Broadcast Enable */
10350 +#define HID0_BHT (1<<2) /* Branch History Table Enable */
10351 +#define HID0_BTCD (1<<1) /* Branch target cache disable */
10353 +#define L2CR_L2E BIT(0) /* L2 enable */
10354 +#define L2CR_L2PE BIT(1) /* L2 data parity generation and checking */
10355 +#define L2CR_L2SIZ_512K BIT(2)
10356 +#define L2CR_L2SIZ_256K BIT(3)
10357 +#define L2CR_L2SIZ_1MB (BIT(2)|BIT(3))
10358 +#define L2CR_L2CLK_1 BIT(6) /* L2 clock ration */
10359 +#define L2CR_L2CLK_15 (BIT(6)*2)
10360 +#define L2CR_L2CLK_2 (BIT(6)*4)
10361 +#define L2CR_L2CLK_25 (BIT(6)*5)
10362 +#define L2CR_L2CLK_3 (BIT(6)*6)
10363 +#define L2CR_L2RAM_FT 0 /* flow-through (reg-buf) synchronous SRAM */
10364 +#define L2CR_L2RAM_PB BIT(7) /* Piplined (reg-reg) synchronous burst SRAM */
10365 +#define L2CR_L2RAM_PLW (BIT(7)|BIT(8)) /* Piplined (reg-reg) synchronous late-write */
10366 +#define L2CR_L2DO BIT(9) /* L2 data-only */
10367 +#define L2CR_L2I BIT(10) /* L2 global invalidate */
10368 +#define L2CR_L2CTL BIT(11) /* L2 RAM control (ZZ enable, low-power mode) */
10369 +#define L2CR_L2WT BIT(12) /* L2 write-through */
10370 +#define L2CR_L2TS BIT(13) /* L2 test support */
10371 +#define L2CR_L2OH_05 0 /* L2 output hold 0.5 nS */
10372 +#define L2CR_L2OH_10 BIT(15) /* L2 output hold 1.0 nS */
10373 +#define L2CR_L2SL BIT(16) /* L2 DLL slow (use if bus freq < 150 MHz) */
10374 +#define L2CR_L2DF BIT(17) /* L2 differential clock */
10375 +#define L2CR_L2BYP BIT(18) /* L2 DLL bypass */
10376 +#define L2CR_L2IP BIT(31) /* L2 global invalidate in progress */
10379 +#define THRM1_TIN (1 << 31)
10380 +#define THRM1_TIV (1 << 30)
10381 +#define THRM1_THRES(x) ((x&0x7f)<<23)
10382 +#define THRM3_SITV(x) ((x&0x3fff)<<1)
10383 +#define THRM1_TID (1<<2)
10384 +#define THRM1_TIE (1<<1)
10385 +#define THRM1_V (1<<0)
10388 +#define THRM3_E (1<<0)
10390 +/* Processor Version Numbers */
10392 +#define PVR_VER(pvr) (((pvr) >> 16) & 0xFFFF) /* Version field */
10393 +#define PVR_REV(pvr) (((pvr) >> 0) & 0xFFFF) /* Revison field */
10395 +#define PVR_403GA 0x00200000
10396 +#define PVR_403GB 0x00200100
10397 +#define PVR_403GC 0x00200200
10398 +#define PVR_403GCX 0x00201400
10399 +#define PVR_405GP 0x40110000
10400 +#define PVR_601 0x00010000
10401 +#define PVR_602 0x00050000
10402 +#define PVR_603 0x00030000
10403 +#define PVR_603e 0x00060000
10404 +#define PVR_603ev 0x00070000
10405 +#define PVR_603r 0x00071000
10406 +#define PVR_604 0x00040000
10407 +#define PVR_604e 0x00090000
10408 +#define PVR_604r 0x000A0000
10409 +#define PVR_620 0x00140000
10410 +#define PVR_740 0x00080000
10411 +#define PVR_750 PVR_740
10412 +#define PVR_740P 0x10080000
10413 +#define PVR_750P PVR_740P
10414 +#define PVR_821 0x00500000
10415 +#define PVR_823 PVR_821
10416 +#define PVR_850 PVR_821
10417 +#define PVR_860 PVR_821
10418 +#define PVR_7400 0x000C0000
10419 +#define PVR_8240 0x00810100
10420 +#define PVR_8260 PVR_8240
10422 +/* Vector VSCR register */
10423 +#define VSCR_NJ 0x10000
10424 +#define VSCR_SAT 0x1
10426 +#endif /* __KERNEL__ */
10429 +#ifdef __ASSEMBLY__
10431 +#define CTR S_CTR /* Counter Register */
10432 +#define DAR S_DAR /* Data Address Register */
10433 +#define DABR S_DABR /* Data Address Breakpoint Register */
10434 +#define DBAT0L S_DBAT0L /* Data BAT 0 Lower Register */
10435 +#define DBAT0U S_DBAT0U /* Data BAT 0 Upper Register */
10436 +#define DBAT1L S_DBAT1L /* Data BAT 1 Lower Register */
10437 +#define DBAT1U S_DBAT1U /* Data BAT 1 Upper Register */
10438 +#define DBAT2L S_DBAT2L /* Data BAT 2 Lower Register */
10439 +#define DBAT2U S_DBAT2U /* Data BAT 2 Upper Register */
10440 +#define DBAT3L S_DBAT3L /* Data BAT 3 Lower Register */
10441 +#define DBAT3U S_DBAT3U /* Data BAT 3 Upper Register */
10442 +#define DCMP S_DCMP /* Data TLB Compare Register */
10443 +#define DEC S_DEC /* Decrement Register */
10444 +#define DMISS S_DMISS /* Data TLB Miss Register */
10445 +#define DSISR S_DSISR /* Data Storage Interrupt Status Register */
10446 +#define EAR S_EAR /* External Address Register */
10447 +#define HASH1 S_HASH1 /* Primary Hash Address Register */
10448 +#define HASH2 S_HASH2 /* Secondary Hash Address Register */
10449 +#define HID0 S_HID0 /* Hardware Implementation Register 0 */
10450 +#define HID1 S_HID1 /* Hardware Implementation Register 1 */
10451 +#define IABR S_IABR /* Instruction Address Breakpoint Register */
10452 +#define IBAT0L S_IBAT0L /* Instruction BAT 0 Lower Register */
10453 +#define IBAT0U S_IBAT0U /* Instruction BAT 0 Upper Register */
10454 +#define IBAT1L S_IBAT1L /* Instruction BAT 1 Lower Register */
10455 +#define IBAT1U S_IBAT1U /* Instruction BAT 1 Upper Register */
10456 +#define IBAT2L S_IBAT2L /* Instruction BAT 2 Lower Register */
10457 +#define IBAT2U S_IBAT2U /* Instruction BAT 2 Upper Register */
10458 +#define IBAT3L S_IBAT3L /* Instruction BAT 3 Lower Register */
10459 +#define IBAT3U S_IBAT3U /* Instruction BAT 3 Upper Register */
10460 +#define ICMP S_ICMP /* Instruction TLB Compare Register */
10461 +#define IMISS S_IMISS /* Instruction TLB Miss Register */
10462 +#define IMMR S_IMMR /* PPC 860/821 Internal Memory Map Register */
10463 +#define L2CR S_L2CR /* PPC 750 L2 control register */
10464 +#define PVR S_PVR /* Processor Version */
10465 +#define RPA S_RPA /* Required Physical Address Register */
10466 +#define SDR1 S_SDR1 /* MMU hash base register */
10467 +#define SPR0 S_SPRG0 /* Supervisor Private Registers */
10468 +#define SPR1 S_SPRG1
10469 +#define SPR2 S_SPRG2
10470 +#define SPR3 S_SPRG3
10471 +#define SPRG0 S_SPRG0
10472 +#define SPRG1 S_SPRG1
10473 +#define SPRG2 S_SPRG2
10474 +#define SPRG3 S_SPRG3
10475 +#define SRR0 S_SRR0 /* Save and Restore Register 0 */
10476 +#define SRR1 S_SRR1 /* Save and Restore Register 1 */
10477 +#define TBRL S_STBRL /* Time Base Read Lower Register */
10478 +#define TBRU S_TBRU /* Time Base Read Upper Register */
10479 +#define TBWL S_TBWL /* Time Base Write Lower Register */
10480 +#define TBWU S_TBWU /* Time Base Write Upper Register */
10481 +#define ICTC S_ICTC
10482 +#define THRM1 S_THRM1 /* Thermal Management Register 1 */
10483 +#define THRM2 S_THRM2 /* Thermal Management Register 2 */
10484 +#define THRM3 S_THRM3 /* Thermal Management Register 3 */
10485 +#define SIAR S_SIAR
10486 +#define SDAR S_SDAR
10489 +#define SR0 0 /* Segment registers */
10506 +#endif /* __ASSEMBLY__ */
10508 +/* opcode macros */
10510 +#define OPCODE_PRIM(n) ( ((ulong)(n)) >> 26 )
10511 +#define OPCODE_EXT(n) ( (((ulong)(n)) >> 1) & 0x3ff )
10512 +#define OPCODE(op,op_ext) ( ((op)<<10) + op_ext )
10514 +#define B1(n) ( (((ulong)(n)) >> 21) & 0x1f )
10515 +#define B2(n) ( (((ulong)(n)) >> 16) & 0x1f )
10516 +#define B3(n) ( (((ulong)(n)) >> 11) & 0x1f )
10518 +#define BD(n) ((ulong)((n) & 0x7fff) + (((n) & 0x8000) ? (ulong)0xffff8000 : 0))
10520 +#define SPRNUM_FLIP( v ) ( (((v)>>5) & 0x1f) | (((v)<<5) & 0x3e0) )
10522 +#endif /* _H_PROCESSOR */
10525 +++ b/drivers/macintosh/mol/include/prom.h
10528 + * Creation Date: <1999/02/22 23:22:17 samuel>
10529 + * Time-stamp: <2003/06/02 16:17:36 samuel>
10533 + * OF device tree structs
10535 + * Copyright (C) 1999, 2000, 2002, 2003 Samuel Rydh (samuel@ibrium.se)
10537 + * This program is free software; you can redistribute it and/or
10538 + * modify it under the terms of the GNU General Public License
10539 + * as published by the Free Software Foundation
10546 +typedef void *p_phandle_t;
10551 + unsigned long controller[5];
10554 +typedef struct p_property {
10557 + unsigned char *value;
10558 + struct p_property *next;
10561 +typedef struct mol_device_node {
10562 + p_phandle_t node;
10563 + struct p_property *properties;
10564 + struct mol_device_node *parent;
10565 + struct mol_device_node *child;
10566 + struct mol_device_node *sibling;
10567 + struct mol_device_node *next; /* next device of same type */
10568 + struct mol_device_node *allnext; /* next in list of all nodes */
10569 + char *unit_string;
10570 +} mol_device_node_t;
10572 +#endif /* _H_PROM */
10574 +++ b/drivers/macintosh/mol/include/rvec.h
10577 + * Creation Date: <2001/01/26 21:33:45 samuel>
10578 + * Time-stamp: <2004/02/08 20:08:20 samuel>
10580 + * <return_vectors.h>
10582 + * Possible mac-return vectors (see mainloop.S)
10584 + * Copyright (C) 2000, 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
10586 + * This program is free software; you can redistribute it and/or
10587 + * modify it under the terms of the GNU General Public License
10588 + * as published by the Free Software Foundation
10596 +/* ---------------------------------------------------------------------------- */
10598 +#define NRVECS_LOG2 6
10599 +#define NUM_RVECS 64 /* = 2 ^ NRVECS_LOG2 */
10600 +#define RVEC_MASK (NUM_RVECS-1)
10602 +/* ---------------------------------------------------------------------------- */
10604 +#define RVEC_NOP 0 /* Must be zero */
10606 +#define RVEC_CALL_KERNEL 1 /* call kernel */
10608 +#define RVEC_ENABLE_FPU 3 /* Load up FPU */
10610 +#define RVEC_TRACE_TRAP 6
10611 +#define RVEC_ISI_TRAP 7 /* r4=nip, r5=srr1 */
10612 +#define RVEC_DSI_TRAP 8 /* r4=dar, r5=srr1 */
10613 +#define RVEC_ALIGNMENT_TRAP 9 /* r4=dar, r5=srr1 */
10614 +#ifdef EMULATE_603
10615 +#define RVEC_DMISS_LOAD_TRAP 10
10616 +#define RVEC_DMISS_STORE_TRAP 11
10617 +#define RVEC_IMISS_TRAP 12
10620 +#define RVEC_SPR_READ 13 /* r4=spr#, r5=gprnum */
10621 +#define RVEC_SPR_WRITE 14 /* r4=spr#, r5=value */
10622 +#define RVEC_PRIV_INST 15 /* r4=opcode */
10623 +#define RVEC_ILLEGAL_INST 16 /* r4=opcode */
10625 +#define RVEC_UNUSUAL_PROGRAM_EXCEP 17 /* r4=opcode, r5=srr1 */
10627 +#define RVEC_ALTIVEC_UNAVAIL_TRAP 18
10628 +#define RVEC_ALTIVEC_ASSIST 19 /* r4=srr1 */
10629 +#define RVEC_ENABLE_ALTIVEC 20
10631 +#define RVEC_EXIT 21
10632 +/* 22 was RVEC_INTERRUPT */
10633 +#define RVEC_OSI_SYSCALL 23
10634 +#define RVEC_TIMER 24
10636 +#define RVEC_IO_READ 25
10637 +#define RVEC_IO_WRITE 26
10639 +#define RVEC_MSR_POW 27 /* (MSR_POW 0->1) => doze */
10642 +#define RVEC_UNUSUAL_DSISR_BITS 28 /* dar, dsisr (bit 0,5,9 or 11 was set) */
10643 +#define RVEC_MMU_IO_SEG_ACCESS 29 /* IO segment access (more or less unused) */
10644 +#define RVEC_INTERNAL_ERROR 30
10645 +#define RVEC_DEBUGGER 31
10646 +#define RVEC_BREAK 32 /* r4 = break_flag */
10647 +#define RVEC_BAD_NIP 33 /* r4 = phys_nip */
10648 +#define RVEC_OUT_OF_MEMORY 34 /* fatal out of memory... */
10650 +#define RVEC_CHECK_IRQS 35 /* check interrupts */
10653 +/************************************************************************/
10654 +/* MOL kernel/emulator switch magic */
10655 +/************************************************************************/
10657 +/* magic to be loaded into r4/r5 before the illegal instruction is issued */
10658 +#define MOL_ENTRY_R4_MAGIC 0x7ba5
10659 +#define MOL_INITIALIZE_FLAG 0x8000
10660 +#define MOL_KERNEL_ENTRY_MAGIC mfmsr r0 /* any privileged instruction will do */
10663 +/************************************************************************/
10664 +/* Kernel definitions */
10665 +/************************************************************************/
10667 +#if defined(__KERNEL__) && !defined( __ASSEMBLY__ )
10669 +#define RVEC_RETURN_1( mregsptr, rvec, arg1 ) \
10670 + ({ (mregsptr)->rvec_param[0] = (ulong)(arg1); \
10673 +#define RVEC_RETURN_2( mregsptr, rvec, arg1, arg2 ) \
10674 + ({ (mregsptr)->rvec_param[0] = (ulong)(arg1); \
10675 + (mregsptr)->rvec_param[1] = (ulong)(arg2); \
10678 +#define RVEC_RETURN_3( mregsptr, rvec, arg1, arg2, arg3 ) \
10679 + ({ (mregsptr)->rvec_param[0] = (ulong)(arg1); \
10680 + (mregsptr)->rvec_param[1] = (ulong)(arg2); \
10681 + (mregsptr)->rvec_param[2] = (ulong)(arg3); \
10684 +#endif /* !__ASSEMBLY__ && __KERNEL__ */
10687 +/************************************************************************/
10688 +/* userspace definitions */
10689 +/************************************************************************/
10691 +#if !defined(__KERNEL__) || defined(__MPC107__)
10693 +#if !defined(__ASSEMBLY__)
10694 +#if !defined(__KERNEL__)
10699 + const char *name;
10702 +extern void rvec_init( void );
10703 +extern void rvec_cleanup( void );
10704 +extern void set_rvector( uint vnum, void *vector, const char *vector_name );
10705 +extern void set_rvecs( rvec_entry_t *table, int tablesize );
10708 +/* this struct is private to rvec.c/mainloop.S (offsets are HARDCODED) */
10710 + int (*rvec)( int rvec /*, arguments */ );
10712 + const char *name;
10714 +} priv_rvec_entry_t;
10715 +#endif /* __ASSEMBLY__ */
10717 +#define RVEC_ESIZE_LOG2 4 /* 2^n = sizeof(priv_rvec_entry_t) */
10718 +#define RVEC_ESIZE 16 /* sizeof(priv_rvec_entry_t) */
10720 +#endif /* __KERNEL__ || __MPC107__ */
10722 +#endif /* _H_RVEC */
10724 +++ b/drivers/macintosh/mol/include/skiplist.h
10727 + * Creation Date: <2003/03/03 22:59:04 samuel>
10728 + * Time-stamp: <2004/02/21 12:17:38 samuel>
10732 + * Skiplist implementation
10734 + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
10736 + * This program is free software; you can redistribute it and/or
10737 + * modify it under the terms of the GNU General Public License
10738 + * as published by the Free Software Foundation
10742 +#ifndef _H_SKIPLIST
10743 +#define _H_SKIPLIST
10745 +#define SKIPLIST_MAX_HEIGHT 16
10747 +typedef struct skiplist_el skiplist_el_t;
10751 + ulong next_phys; /* for usage from assembly */
10753 + skiplist_el_t *next;
10754 +} skiplist_level_t;
10756 +/* data (of datasize) is stored before the skiplist_el */
10757 +typedef struct skiplist_el {
10759 + skiplist_level_t level[1]; /* level 0 */
10760 + /* level 1..n are optionally stored here */
10761 +} *skiplist_iter_t;
10765 + int slevel; /* start level */
10766 + int datasize; /* size of data (stored before each key) */
10768 + skiplist_level_t root[SKIPLIST_MAX_HEIGHT];
10769 + skiplist_el_t nil_el;
10771 + skiplist_level_t freelist; /* key = level, linked list in next[0] */
10775 +skiplist_getnext( skiplist_t *sl, skiplist_iter_t *iterator, char **data )
10777 + skiplist_el_t *el = *iterator;
10778 + *data = (char*)el - sl->datasize;
10779 + *iterator = el->level[0].next;
10780 + return el != &sl->nil_el;
10784 +skiplist_iter_getkey( skiplist_t *sl, char *data )
10786 + return ((skiplist_el_t*)(data + sl->datasize))->key;
10789 +static inline skiplist_iter_t
10790 +skiplist_iterate( skiplist_t *sl )
10792 + return sl->root[0].next;
10796 +skiplist_needalloc( skiplist_t *sl )
10798 + return !sl->freelist.next;
10801 +typedef void (*skiplist_el_callback)( char *data, int ind, int n, void *usr1, void *usr2 );
10803 +extern void skiplist_init( skiplist_t *sl, int datasize );
10804 +extern int skiplist_prealloc( skiplist_t *sl, char *buf, unsigned int size,
10805 + skiplist_el_callback callback, void *usr1, void *usr2 );
10807 +extern char *skiplist_insert( skiplist_t *sl, int key );
10808 +extern char *skiplist_delete( skiplist_t *sl, int key );
10809 +extern char *skiplist_lookup( skiplist_t *sl, int key );
10812 +#endif /* _H_SKIPLIST */
10814 +++ b/drivers/macintosh/mol/include/tlbie.h
10817 + * Creation Date: <2003/05/27 16:56:10 samuel>
10818 + * Time-stamp: <2003/08/16 16:55:31 samuel>
10822 + * tlbie and PTE operations
10824 + * Copyright (C) 2003 Samuel Rydh (samuel@ibrium.se)
10826 + * This program is free software; you can redistribute it and/or
10827 + * modify it under the terms of the GNU General Public License
10837 +extern void (*xx_tlbie_lowmem)( void /* special */ );
10838 +extern void (*xx_store_pte_lowmem)( void /* special */ );
10839 +extern int compat_hash_table_lock;
10841 +static inline void
10844 + register ulong _ea __asm__ ("r3");
10845 + register ulong _lock __asm__ ("r7");
10846 + register ulong _func __asm__ ("r9");
10848 + _func = (ulong)xx_tlbie_lowmem;
10849 + _lock = (ulong)&compat_hash_table_lock;
10854 + "li 8,0x1235 \n" /* lock value */
10856 + "rlwinm 0,10,0,17,15 \n" /* clear MSR_EE */
10858 + "bctrl \n" /* modifies r0 */
10861 + : "r" (_ea), "r" (_lock), "r" (_func)
10862 + : "ctr", "lr", "cc", "r8", "r0", "r10"
10866 +static inline void
10867 +__store_PTE( int ea, unsigned long *slot, int pte0, int pte1 )
10869 + register ulong _ea __asm__ ("r3");
10870 + register ulong _pte_slot __asm__ ("r4");
10871 + register ulong _pte0 __asm__ ("r5");
10872 + register ulong _pte1 __asm__ ("r6");
10873 + register ulong _lock __asm__ ("r7");
10874 + register ulong _func __asm__ ("r9");
10876 + _func = (ulong)xx_store_pte_lowmem;
10878 + _pte_slot = (ulong)slot;
10881 + _lock = (ulong)&compat_hash_table_lock;
10885 + "li 8,0x1234 \n" /* lock value */
10887 + "rlwinm 0,10,0,17,15 \n" /* clear MSR_EE */
10889 + "bctrl \n" /* modifies r0 */
10892 + : "r" (_ea), "r" (_pte_slot), "r" (_pte0), "r" (_pte1), "r" (_lock), "r" (_func)
10893 + : "ctr", "lr", "cc", "r0", "r8", "r10"
10897 +#else /* CONFIG_SMP */
10898 +extern void (*xx_store_pte_lowmem)( unsigned long *slot, int pte0, int pte1 );
10900 +static inline void __tlbie( int ea ) {
10901 + asm volatile ("tlbie %0" : : "r"(ea));
10904 +static inline void
10905 +__store_PTE( int ea, unsigned long *slot, int pte0, int pte1 )
10908 + local_irq_save(flags);
10909 + (*xx_store_pte_lowmem)( slot, pte0, pte1 );
10910 + local_irq_restore(flags);
10914 +#endif /* CONFIG_SMP */
10917 +#endif /* _H_TLBIE */
10919 +++ b/drivers/macintosh/mol/include/uaccess.h
10922 + * Creation Date: <2004/02/01 20:02:11 samuel>
10923 + * Time-stamp: <2004/02/01 20:02:11 samuel>
10929 + * Copyright (C) 2004 Samuel Rydh (samuel@ibrium.se)
10931 + * This program is free software; you can redistribute it and/or
10932 + * modify it under the terms of the GNU General Public License
10937 +#ifndef _H_UACCESS
10938 +#define _H_UACCESS
10941 +static inline unsigned int copy_to_user_mol( void *to, const void *from, ulong len ) {
10942 + return copy_to_user( to, from, len );
10944 +static inline unsigned int copy_from_user_mol( void *to, const void *from, ulong len ) {
10945 + return copy_from_user( to, from, len );
10948 +static inline unsigned int copy_int_to_user( int *to, int val ) {
10949 + return copy_to_user_mol( to, &val, sizeof(int) );
10951 +static inline unsigned int copy_int_from_user( int *retint, int *userptr ) {
10952 + return copy_from_user_mol( retint, userptr, sizeof(int) );
10956 +#endif /* _H_UACCESS */
10958 +++ b/drivers/macintosh/mol/include/vector.h
10961 + * Creation Date: <2003/05/26 00:00:28 samuel>
10962 + * Time-stamp: <2004/03/07 14:44:50 samuel>
10968 + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
10970 + * This program is free software; you can redistribute it and/or
10971 + * modify it under the terms of the GNU General Public License
10979 +#define MOL_SPRG2_MAGIC 0x1779
10982 +#include "mpcvector.h"
10985 +#define PERFMON_VECTOR 0xf00
10988 +/************************************************************************/
10989 +/* Vector entry point definitions */
10990 +/************************************************************************/
10993 + * This code uses the dynamic linkage/action symbol functionality of
10994 + * the MOL kernel loader to automatically install the hooks. Refer to
10995 + * hook.c for the actual implementation.
10998 +/* Description of ACTION_RELOC_HOOK:
11000 + * .long ACTION_RELOC_HOOK
11002 + * .long #bytes to copy to lowmem
11003 + * .long offset to vret function
11004 + * -- offsets are calculated from here --
11007 +mDEFINE(VECTOR_HOOK, [v], [
11009 + ACTION_PB( ACTION_RELOC_HOOK )
11011 + .long vhook_end_[]_v - vhook_[]_v
11012 + .long vret_[]_v - vhook_[]_v
11015 + addis r3,0,0 /* [1] hook address inserted */
11017 + ori r3,r3,0 /* [3] at module initialization */
11023 + nop /* overwritten instruction is inserted here */
11031 +/* these macros are to be used from the not_mol vector hook */
11032 +#define CONTINUE_TRAP( v ) \
11034 + fix_sprg2 /**/ R1 /* sprg2 == sprg_a0 */ ; \
11036 + ACTION_1( ACTION_VRET, v ) /* ba vret_xxx */
11038 +#define ABORT_TRAP( dummy_v ) \
11040 + fix_sprg2 /**/ R1 /* sprg2 == sprg_a0 */ ; \
11044 +/* SPRG0,1 = saved r3,r1, r1 = saved lr */
11045 +mDEFINE(VECTOR_, [v, dummy_str, secondary, not_mol_label], [
11049 + CONTINUE_TRAP( _v )
11051 +secondary_int_[]_v:
11055 + VECTOR_HOOK( _v )
11061 + cmpwi r1,MOL_SPRG2_MAGIC
11062 + bne- _not_mol_label
11063 +soft_603_entry_[]_v:
11065 + andi. r1,r1,MSR_PR /* MSR_PR set? */
11067 + beq- secondary_int_[]_v /* if not, take a secondary trap? */
11070 +#define VECTOR(v, dummy_str, secondary) \
11071 + VECTOR_(v, dummy_str, secondary, not_mol_##v )
11073 +/* this macro takes an exception from mac mode (call save_middle_regs first) */
11074 +#define TAKE_EXCEPTION( v ) \
11075 + bl take_exception ; \
11076 + ACTION_1( ACTION_VRET, v )
11078 +/* no need to relocate the 0xf00 trap */
11079 +#define PERFMON_VECTOR_RELOCATION( newvec )
11082 +/************************************************************************/
11083 +/* 603 vector HOOKs (r0-r3, cr0 saved by hardware) */
11084 +/************************************************************************/
11086 +mDEFINE(VECTOR_603, [v, dummy_str], [
11088 + ACTION_PB( ACTION_RELOC_HOOK )
11090 + .long vhook_end_[]_v - vhook_[]_v
11091 + .long vret_[]_v - vhook_[]_v
11094 + addis r3,0,0 /* [1] hook address inserted */
11095 + cmpwi r1,MOL_SPRG2_MAGIC
11096 + ori r3,r3,0 /* [3] at module initialization */
11103 + nop /* overwritten instruction is inserted here */
11112 +/* all register are assumed to be unmodified */
11113 +mDEFINE(SOFT_VECTOR_ENTRY_603, [v], [
11117 + b soft_603_entry_[]_v
11121 +/************************************************************************/
11122 +/* FUNCTION_HOOK */
11123 +/************************************************************************/
11125 +mDEFINE(FHOOK, [symind], [
11126 + ACTION_PB( ACTION_HOOK_FUNCTION )
11128 + .long fhook_end_[]_symind - fhook_[]_symind
11129 + .long fret_[]_symind - fhook_[]_symind
11132 + addis r9,0,0 /* [1] address inserted */
11133 + ori r9,r9,0 /* [2] at runtime */
11138 + nop /* overwritten instruction is inserted here */
11139 + nop /* return (through a relative branch) */
11140 +fhook_end_[]_symind:
11143 + /* hook goes here */
11147 +#endif /* MOLMPC */
11148 +#endif /* _H_VECTOR */
11150 +++ b/drivers/macintosh/mol/include/version.h
11153 +#ifndef _H_VERSION
11154 +#define _H_VERSION
11156 +#include "molversion.h"
11158 +#define MOL_VERSION ((MOL_MAJOR_VERSION << 16) \
11159 + + (MOL_MINOR_VERSION << 8) \
11160 + + MOL_PATCHLEVEL )
11162 +#endif /* _H_VERSION */
11164 +++ b/drivers/macintosh/mol/include/weaksym.h
11167 + * Creation Date: <2001/08/02 23:53:57 samuel>
11168 + * Time-stamp: <2001/08/03 00:30:23 samuel>
11172 + * Support of weak symbols (extract, stolen from glibc)
11174 + * This program is free software; you can redistribute it and/or
11175 + * modify it under the terms of the GNU General Public License
11176 + * as published by the Free Software Foundation
11180 +#ifndef _H_WEAKSYM
11181 +#define _H_WEAKSYM
11184 +/* Define ALIASNAME as a strong alias for NAME. */
11185 +#define strong_alias(name, aliasname) _strong_alias(name, aliasname)
11186 +#define _strong_alias(name, aliasname) \
11187 + extern __typeof (name) aliasname __attribute__ ((alias (#name)));
11189 +/* This comes between the return type and function name in
11190 + a function definition to make that definition weak. */
11191 +#define weak_function __attribute__ ((weak))
11192 +#define weak_const_function __attribute__ ((weak, __const__))
11194 +/* Define ALIASNAME as a weak alias for NAME. */
11195 +#define weak_alias(name, aliasname) _weak_alias (name, aliasname)
11196 +#define _weak_alias(name, aliasname) \
11197 + extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
11199 +/* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
11200 +#define weak_extern(symbol) _weak_extern (symbol)
11201 +# define _weak_extern(symbol) asm (".weak " #symbol);
11204 +#endif /* _H_WEAKSYM */
11206 +++ b/drivers/macintosh/mol/init.c
11209 + * Creation Date: <2002/01/13 20:45:37 samuel>
11210 + * Time-stamp: <2004/02/14 14:01:09 samuel>
11214 + * Kernel module initialization
11216 + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
11218 + * This program is free software; you can redistribute it and/or
11219 + * modify it under the terms of the GNU General Public License
11220 + * as published by the Free Software Foundation
11224 +#include "archinclude.h"
11225 +#include "alloc.h"
11226 +#include "kernel_vars.h"
11229 +#include "asmfuncs.h"
11230 +#include "performance.h"
11231 +#include "mol-ioctl.h"
11232 +#include "version.h"
11236 +session_table_t *g_sesstab;
11237 +int g_num_sessions;
11240 +/************************************************************************/
11241 +/* init/cleanup kernel module */
11242 +/************************************************************************/
11245 +common_init( void )
11247 + if( init_hash() )
11250 + if( !(g_sesstab=kmalloc_cont_mol(sizeof(*g_sesstab))) ) {
11255 + memset( g_sesstab, 0, sizeof(*g_sesstab) );
11256 + init_MUTEX_mol( &g_sesstab->lock );
11258 + if( arch_common_init() ) {
11259 + free_MUTEX_mol( &g_sesstab->lock );
11260 + kfree_cont_mol( g_sesstab );
11268 +common_cleanup( void )
11270 + arch_common_cleanup();
11272 + free_MUTEX_mol( &g_sesstab->lock );
11273 + kfree_cont_mol( g_sesstab );
11274 + g_sesstab = NULL;
11280 +/************************************************************************/
11281 +/* initialize / destroy session */
11282 +/************************************************************************/
11285 +initialize_session_( uint index )
11287 + kernel_vars_t *kv;
11290 + if( g_sesstab->magic == 1 )
11291 + return -EMOLSECURITY;
11293 + /* printk("initialize_session\n" ); */
11294 + if( g_sesstab->kvars[index] )
11295 + return -EMOLINUSE;
11297 + if( !g_num_sessions && perform_actions() )
11298 + return -EMOLGENERAL;
11300 + if( !(kv=alloc_kvar_pages()) )
11303 + memset( kv, 0, NUM_KVARS_PAGES * 0x1000 );
11304 + kv->session_index = index;
11305 + kv->kvars_virt = kv;
11306 + kv_phys = tophys_mol(kv);
11307 + kv->kvars_tophys_offs = kv_phys - (ulong)kv;
11309 + if( init_mmu(kv) )
11312 + init_host_irqs(kv);
11313 + initialize_spr_table( kv );
11315 + msr_altered( kv );
11317 + g_num_sessions++;
11319 + g_sesstab->kvars_ph[index] = kv_phys;
11320 + g_sesstab->kvars[index] = kv;
11324 + if( !g_num_sessions )
11325 + cleanup_actions();
11327 + free_kvar_pages( kv );
11328 + return -EMOLGENERAL;
11332 +initialize_session( uint index )
11335 + if( index >= MAX_NUM_SESSIONS )
11336 + return -EMOLINVAL;
11339 + ret = initialize_session_( index );
11346 +destroy_session( uint index )
11348 + kernel_vars_t *kv;
11350 + if( index >= MAX_NUM_SESSIONS )
11353 + if( g_sesstab->magic == 1 ) {
11354 + printk("Security alert! Somebody other than MOL has tried to invoke\n"
11355 + "the MOL switch magic. The MOL infrastructure has been disabled.\n"
11356 + "Reboot in order to get MOL running again\n");
11357 + /* make it impossible to unload the module */
11358 + prevent_mod_unload();
11362 + if( (kv=g_sesstab->kvars[index]) ) {
11364 + g_sesstab->kvars[index] = NULL;
11365 + g_sesstab->kvars_ph[index] = 0;
11367 + /* decrease before freeing anything (simplifies deallocation of shared resources) */
11368 + g_num_sessions--;
11369 + cleanup_host_irqs(kv);
11370 + cleanup_mmu( kv );
11372 + if( kv->emuaccel_page )
11373 + free_page_mol( kv->emuaccel_page );
11375 + memset( kv, 0, NUM_KVARS_PAGES * 0x1000 );
11376 + free_kvar_pages( kv );
11378 + if( !g_num_sessions )
11379 + cleanup_actions();
11385 +get_session_magic( uint random_magic )
11387 + if( random_magic < 2 )
11388 + random_magic = 2;
11389 + /* negative return values are interpreted as errors */
11390 + random_magic &= 0x7fffffff;
11393 + if( !g_sesstab->magic )
11394 + g_sesstab->magic = random_magic;
11397 + return g_sesstab->magic;
11400 +++ b/drivers/macintosh/mol/misc.c
11403 + * Creation Date: <2003/06/06 20:00:52 samuel>
11404 + * Time-stamp: <2004/03/06 13:54:26 samuel>
11410 + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
11412 + * This program is free software; you can redistribute it and/or
11413 + * modify it under the terms of the GNU General Public License
11418 +#include "archinclude.h"
11419 +#include "mol-ioctl.h"
11421 +#include "mtable.h"
11422 +#include "constants.h"
11423 +#include "asmfuncs.h"
11424 +#include "performance.h"
11427 +#include "alloc.h"
11428 +#include "uaccess.h"
11431 +/************************************************************************/
11432 +/* Performance Info */
11433 +/************************************************************************/
11435 +#ifdef PERFORMANCE_INFO
11438 +clear_performance_info( kernel_vars_t *kv )
11440 + perf_info_t *p = g_perf_info_table;
11443 + for( ; p->name ; p++ )
11445 + for( i=0; i<NUM_ASM_BUMP_CNTRS; i++ )
11446 + kv->asm_bump_cntr[i] = 0;
11447 + kv->num_acntrs = 0;
11451 +get_performance_info( kernel_vars_t *kv, uint ind, perf_ctr_t *r )
11457 + for( p=g_perf_info_table; p->name && ind; p++, ind-- )
11460 + extern int __start_bumptable[], __end_bumptable[];
11461 + if( ind >= __end_bumptable - __start_bumptable )
11463 + name = (char*)__start_bumptable + __start_bumptable[ind];
11464 + r->ctr = kv->asm_bump_cntr[ind];
11467 + r->ctr = *p->ctrptr;
11470 + if( (len=strlen(name)+1) > sizeof(r->name) )
11471 + len = sizeof(r->name);
11472 + memcpy( r->name, name, len );
11476 +#else /* PERFORMANCE_INFO */
11479 +clear_performance_info( kernel_vars_t *kv )
11484 +get_performance_info( kernel_vars_t *kv, uint ind, perf_ctr_t *r )
11489 +#endif /* PERFORMANCE_INFO */
11493 +/************************************************************************/
11495 +/************************************************************************/
11498 +do_debugger_op( kernel_vars_t *kv, dbg_op_params_t *pb )
11502 + switch( pb->operation ) {
11503 + case DBG_OP_EMULATE_TLBIE:
11504 + flush_ea_range( kv, (pb->ea & ~0xf0000000), 0x1000 );
11507 + case DBG_OP_EMULATE_TLBIA:
11508 + clear_all_vsids( kv );
11511 + case DBG_OP_GET_PTE:
11512 + ret = dbg_get_PTE( kv, pb->context, pb->ea, &pb->ret.pte );
11515 + case DBG_OP_BREAKPOINT_FLAGS:
11516 + kv->break_flags = pb->param;
11517 + kv->mregs.flag_bits &= ~fb_DbgTrace;
11518 + kv->mregs.flag_bits |= (pb->param & BREAK_SINGLE_STEP)? fb_DbgTrace : 0;
11519 + msr_altered( kv );
11522 + case DBG_OP_TRANSLATE_EA:
11523 + /* param == is_data_access */
11524 + ret = dbg_translate_ea( kv, pb->context, pb->ea, &pb->ret.phys, pb->param );
11528 + printk("Unimplemended debugger operation %d\n", pb->operation );
11529 + ret = -ENOSYS_MOL;
11536 +tune_spr( kernel_vars_t *kv, uint spr, int action )
11538 + extern int r__spr_illegal[], r__spr_read_only[], r__spr_read_write[];
11539 + int hook, newhook=0;
11541 + if( spr >= 1024 )
11544 + hook = kv->_bp.spr_hooks[spr];
11546 + /* LSB of hook specifies whether the SPR is privileged */
11547 + switch( action ) {
11548 + case kTuneSPR_Illegal:
11549 + newhook = (int)r__spr_illegal;
11553 + case kTuneSPR_Privileged:
11557 + case kTuneSPR_Unprivileged:
11561 + case kTuneSPR_ReadWrite:
11562 + newhook = (int)r__spr_read_write;
11565 + case kTuneSPR_ReadOnly:
11566 + newhook = (int)r__spr_read_only;
11570 + hook = (hook & 1) | tophys_mol( (char*)reloc_ptr(newhook) );
11571 + kv->_bp.spr_hooks[spr] = hook;
11574 +/* return value: <0: system error, >=0: ret value */
11576 +handle_ioctl( kernel_vars_t *kv, int cmd, int arg1, int arg2, int arg3 )
11578 + struct mmu_mapping map;
11583 + case MOL_IOCTL_GET_SESSION_MAGIC:
11584 + ret = get_session_magic( arg1 );
11587 + case MOL_IOCTL_IDLE_RECLAIM_MEMORY:
11588 + mtable_reclaim( kv );
11591 + case MOL_IOCTL_SPR_CHANGED:
11596 + case MOL_IOCTL_ADD_IORANGE: /* void ( ulong mbase, int size, void *usr_data )*/
11597 + add_io_trans( kv, arg1, arg2, (void*)arg3 );
11599 + case MOL_IOCTL_REMOVE_IORANGE: /* void ( ulong mbase, int size ) */
11600 + remove_io_trans( kv, arg1, arg2 );
11603 + case MOL_IOCTL_ALLOC_EMUACCEL_SLOT: /* EMULATE_xxx, param, ret_addr -- mphys */
11604 + ret = alloc_emuaccel_slot( kv, arg1, arg2, arg3 );
11606 + case MOL_IOCTL_MAPIN_EMUACCEL_PAGE: /* arg1 = mphys */
11607 + ret = mapin_emuaccel_page( kv, arg1 );
11610 + case MOL_IOCTL_SETUP_FBACCEL: /* lvbase, bytes_per_row, height */
11611 + setup_fb_acceleration( kv, (char*)arg1, arg2, arg3 );
11613 + case MOL_IOCTL_TUNE_SPR: /* spr#, action */
11614 + tune_spr( kv, arg1, arg2 );
11617 + case MOL_IOCTL_MMU_MAP: /* arg1=struct mmu_mapping *m, arg2=map/unmap */
11618 + if( copy_from_user_mol(&map, (struct mmu_mapping*)arg1, sizeof(map)) )
11621 + mmu_add_map( kv, &map );
11623 + mmu_remove_map( kv, &map );
11624 + if( copy_to_user_mol((struct mmu_mapping*)arg1, &map, sizeof(map)) )
11625 + ret = -EFAULT_MOL;
11628 + case MOL_IOCTL_GET_PERF_INFO:
11629 + ret = get_performance_info( kv, arg1, &pctr );
11630 + if( copy_to_user_mol((perf_ctr_t*)arg2, &pctr, sizeof(pctr)) )
11631 + ret = -EFAULT_MOL;
11635 + case MOL_IOCTL_TRACK_DIRTY_RAM:
11636 + ret = track_lvrange( kv );
11638 + case MOL_IOCTL_GET_DIRTY_RAM:
11639 + ret = get_track_buffer( kv, (char*)arg1 );
11641 + case MOL_IOCTL_SET_DIRTY_RAM:
11642 + set_track_buffer( kv, (char*)arg1 );
11645 + /* ---------------- performance statistics ------------------ */
11647 + case MOL_IOCTL_CLEAR_PERF_INFO:
11648 + clear_performance_info( kv );
11652 + printk("unsupported MOL ioctl %d\n", cmd );
11653 + ret = -ENOSYS_MOL;
11658 +++ b/drivers/macintosh/mol/mmu.c
11661 + * Creation Date: <1998-11-11 11:56:45 samuel>
11662 + * Time-stamp: <2004/03/13 14:25:26 samuel>
11666 + * Handles page mappings and the mac MMU
11668 + * Copyright (C) 1998-2004 Samuel Rydh (samuel@ibrium.se)
11670 + * This program is free software; you can redistribute it and/or
11671 + * modify it under the terms of the GNU General Public License
11672 + * as published by the Free Software Foundation
11676 +#include "archinclude.h"
11677 +#include "alloc.h"
11678 +#include "kernel_vars.h"
11680 +#include "mmu_contexts.h"
11681 +#include "asmfuncs.h"
11684 +#include "mtable.h"
11685 +#include "performance.h"
11686 +#include "context.h"
11690 +#define MREGS (kv->mregs)
11691 +#define MMU (kv->mmu)
11694 +/************************************************************************/
11695 +/* init / cleanup */
11696 +/************************************************************************/
11699 +init_mmu( kernel_vars_t *kv )
11704 + !arch_mmu_init( kv ) &&
11705 + !init_contexts( kv ) &&
11706 + !init_mtable( kv ) &&
11707 + !init_mmu_io( kv ) &&
11708 + !init_mmu_fb( kv ) &&
11709 + !init_mmu_tracker( kv );
11712 + cleanup_mmu( kv );
11716 + clear_vsid_refs( kv );
11718 + /* SDR1 is set from fStartEmulation */
11723 +cleanup_mmu( kernel_vars_t *kv )
11725 + /* We have to make sure the flush thread are not using the mtable
11726 + * facilities. The kvars entry has been clear so we just have
11727 + * to wait around until no threads are using it.
11729 + while( atomic_read_mol(&g_sesstab->external_thread_cnt) )
11732 + cleanup_mmu_tracker( kv );
11733 + cleanup_mmu_fb( kv );
11734 + cleanup_mmu_io( kv );
11735 + cleanup_mtable( kv );
11736 + cleanup_contexts( kv );
11738 + if( MMU.pthash_inuse_bits )
11739 + kfree_cont_mol( MMU.pthash_inuse_bits );
11740 + if( MMU.hash_base )
11741 + unmap_emulated_hash( kv );
11743 + memset( &MMU, 0, sizeof(mmu_vars_t) );
11747 +/************************************************************************/
11749 +/************************************************************************/
11751 +/* All vsid entries have been flushed; clear dangling pointers */
11753 +clear_vsid_refs( kernel_vars_t *kv )
11756 + for( i=0; i<16; i++ ) {
11757 + MMU.vsid[i] = NULL;
11758 + MMU.unmapped_vsid[i] = NULL;
11760 + MMU.user_sr[i] = MMU.illegal_sr;
11761 + MMU.sv_sr[i] = MMU.illegal_sr;
11762 + MMU.unmapped_sr[i] = MMU.illegal_sr;
11763 + MMU.split_sr[i] = MMU.illegal_sr;
11765 + invalidate_splitmode_sr( kv );
11769 + * This function is called whenever the mac MMU-registers have
11770 + * been manipulated externally.
11773 +mmu_altered( kernel_vars_t *kv )
11777 + for( i=0; i<16; i++ ) {
11778 + MMU.vsid[i] = NULL;
11779 + MMU.user_sr[i] = MMU.illegal_sr;
11780 + MMU.sv_sr[i] = MMU.illegal_sr;
11782 + invalidate_splitmode_sr( kv );
11784 + do_mtsdr1( kv, MREGS.spr[S_SDR1] );
11786 + for( i=0; i<16; i++ )
11787 + do_mtbat( kv, S_IBAT0U+i, MREGS.spr[ S_IBAT0U+i ], 1 );
11791 + * A page we might be using is about to be destroyed (e.g. swapped out).
11792 + * Any PTEs referencing this page must be flushed. The context parameter
11798 +do_flush( ulong context, ulong va, ulong *dummy, int n )
11801 + kernel_vars_t *kv;
11802 + BUMP( do_flush );
11804 + atomic_inc_mol( &g_sesstab->external_thread_cnt );
11806 + for( i=0; i<MAX_NUM_SESSIONS; i++ ) {
11807 + if( !(kv=g_sesstab->kvars[i]) || context != kv->mmu.emulator_context )
11810 + BUMP_N( block_destroyed_ctr, n );
11811 + for( ; n-- ; va += 0x1000 )
11812 + flush_lvptr( kv, va );
11816 + atomic_dec_mol( &g_sesstab->external_thread_cnt );
11820 +/************************************************************************/
11821 +/* Debugger functions */
11822 +/************************************************************************/
11825 +dbg_get_PTE( kernel_vars_t *kv, int context, ulong va, mPTE_t *retptr )
11827 + ulong base, mask;
11828 + ulong vsid, ptmp, stmp, *pteg, *steg;
11830 + ulong *uret = (ulong*)retptr;
11831 + int i, num_match=0;
11833 + switch( context ) {
11834 + case kContextUnmapped:
11835 + vsid = MMU.unmapped_sr[va>>28];
11837 + case kContextMapped_S:
11838 + vsid = MMU.sv_sr[va>>28];
11840 + case kContextMapped_U:
11841 + vsid = MMU.user_sr[va>>28];
11843 + case kContextEmulator:
11844 + vsid = (MUNGE_CONTEXT(MMU.emulator_context) + ((va>>28) * MUNGE_ESID_ADD)) & 0xffffff;
11846 + case kContextKernel:
11850 + printk("get_PTE: no such context: %d\n", context );
11854 + /* mask vsid and va */
11855 + vsid &= 0xffffff;
11856 + va &= 0x0ffff000;
11858 + /* get hash base and hash mask */
11859 + base = (ulong)ptehash.base;
11860 + mask = ptehash.pteg_mask >> 6;
11862 + /* hash function */
11863 + ptmp = (vsid ^ (va>>12)) & mask;
11864 + stmp = mask & ~ptmp;
11865 + pteg = (ulong*)((ptmp << 6) + base);
11866 + steg = (ulong*)((stmp << 6) + base);
11868 + /* construct compare word */
11869 + cmp = 0x80000000 | (vsid <<7) | (va>>22);
11871 + /* look in primary PTEG */
11872 + for( i=0; i<8; i++ ) {
11873 + if( cmp == pteg[i*2] ) {
11874 + if( !num_match++ && uret ) {
11875 + uret[0] = pteg[i*2];
11876 + uret[1] = pteg[i*2+1];
11878 + if( num_match == 2 ) {
11879 + printk("Internal ERROR: duplicate PTEs!\n");
11880 + printk("p-hash: low_pte: %08lX high_pte: %08lX\n",
11881 + uret ? uret[0]:0, retptr? uret[1]:0 );
11883 + if( num_match >= 2 ) {
11884 + printk("p-hash: low_pte: %08lX high_pte: %08lX\n",
11885 + pteg[i*2], pteg[i*2+1] );
11890 + /* look in secondary PTEG */
11892 + for( i=0; i<8; i++ ) {
11893 + if( cmp == steg[i*2] ) {
11894 + if( !num_match++ && uret ) {
11895 + uret[0] = steg[i*2];
11896 + uret[1] = steg[i*2+1];
11898 + if( num_match == 2 ) {
11899 + printk("Internal ERROR: duplicate PTEs!\n");
11900 + printk("?-hash: low_pte: %08lX high_pte: %08lX\n",
11901 + uret? uret[0]:0, uret? uret[1]:0 );
11903 + if( num_match >= 2 ) {
11904 + printk("s-hash: low_pte: %08lX high_pte: %08lX\n",
11905 + steg[i*2], steg[i*2+1] );
11909 + return num_match;
11912 +++ b/drivers/macintosh/mol/mmu_fb.c
11915 + * Creation Date: <1999-12-28 14:03:18 samuel>
11916 + * Time-stamp: <2004/02/14 14:52:52 samuel>
11920 + * Offscreen framebuffer acceleration
11922 + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
11924 + * This program is free software; you can redistribute it and/or
11925 + * modify it under the terms of the GNU General Public License
11926 + * as published by the Free Software Foundation
11930 +#include "archinclude.h"
11931 +#include "alloc.h"
11932 +#include "uaccess.h"
11934 +#include "asmfuncs.h"
11935 +#include "performance.h"
11938 +typedef struct line_entry {
11947 +typedef struct fb_data {
11948 + line_entry_t *line_table;
11950 + char *lv_base; /* linux virtual of first entry in table */
11953 +#define MMU (kv->mmu)
11954 +#define DECLARE_FB fb_data_t *fb = MMU.fb_data
11957 +static inline void
11958 +__put_user( short val, short *destptr )
11960 + copy_to_user_mol( destptr, &val, sizeof(short) );
11966 +init_mmu_fb( kernel_vars_t *kv )
11968 + /* setup_fb_acceleration does the initialization */
11973 +cleanup_mmu_fb( kernel_vars_t *kv )
11978 + if( fb->line_table )
11979 + vfree_mol( fb->line_table );
11982 + MMU.fb_data = NULL;
11986 +video_pte_inserted( kernel_vars_t *kv, ulong lvptr, ulong *slot, ulong pte0, ulong pte1, ulong ea )
11994 + i = (lvptr - (ulong)fb->lv_base) >> 12;
11995 + if( i >= 0 && i < fb->nrec ) {
11996 + line_entry_t *p = &fb->line_table[i];
11998 + /* allow at most one video PTE to be mapped at any time */
11999 + if( p->slot && (p->slot != slot || p->pte0 != pte0) ) {
12000 + BUMP( video_pte_reinsert );
12001 + if( p->slot != slot )
12009 + p->pte1 = pte1 & ~PTE1_C;
12012 + printk("Warning: video_page outside range, %lx %p\n", lvptr, fb->lv_base );
12016 +/* setup/remove framebuffer acceleration */
12018 +setup_fb_acceleration( kernel_vars_t *kv, char *lvbase, int bytes_per_row, int height )
12021 + int i, offs = (ulong)lvbase & 0xfff;
12025 + cleanup_mmu_fb( kv );
12028 + if( !(fb=kmalloc_mol(sizeof(fb_data_t))) )
12030 + memset( fb, 0, sizeof(fb_data_t) );
12031 + MMU.fb_data = fb;
12033 + fb->nrec = (bytes_per_row * height + offs + 0xfff) >> 12;
12034 + if( !(p=(line_entry_t*)vmalloc_mol(sizeof(line_entry_t) * fb->nrec)) ) {
12035 + cleanup_mmu_fb( kv );
12038 + memset( p, 0, sizeof(line_entry_t) * fb->nrec );
12039 + fb->line_table = p;
12041 + fb->lv_base = (char*)((ulong)lvbase & ~0xfff);
12042 + for( i=0; i<fb->nrec; i++, p++ ){
12043 + p->y1 = (0x1000*i - offs) / bytes_per_row;
12044 + p->y2 = (0x1000*(i+1)-1 -offs) / bytes_per_row;
12047 + if( p->y2 >= height )
12048 + p->y2 = height-1;
12050 + /* we should make sure the page is really unmapped here! */
12055 +/* return format is {startline,endline} pairs */
12057 +get_dirty_fb_lines( kernel_vars_t *kv, short *userbuf, int num_bytes )
12060 + int i, n, s, start;
12063 + s = num_bytes/sizeof(short[2]) - 1;
12065 + if( !fb || (uint)s <= 0 )
12068 + p = fb->line_table;
12069 + for( start=-1, n=0, i=0; i<fb->nrec; i++, p++ ) {
12071 + if( p->slot[0] != p->pte0 ) {
12072 + /* evicted FB PTE */
12075 + __tlbie( p->ea );
12076 + } else if( p->slot[1] & BIT(24) ) { /* C-BIT */
12078 + __store_PTE( p->ea, p->slot, p->pte0, p->pte1 );
12079 + BUMP(fb_ptec_flush);
12082 + if( p->dirty && start < 0 )
12084 + else if( !p->dirty && start >= 0 ) {
12085 + __put_user( start, userbuf++ );
12086 + __put_user( p->y2, userbuf++ );
12093 + if( start >= 0 ) {
12094 + __put_user( start, userbuf++ );
12095 + __put_user( fb->line_table[fb->nrec-1].y2, userbuf++ );
12101 +++ b/drivers/macintosh/mol/mmu_io.c
12104 + * Creation Date: <1998-12-02 03:23:31 samuel>
12105 + * Time-stamp: <2004/03/13 16:57:31 samuel>
12109 + * Translate mac_phys to whatever has been mapped in at
12110 + * a particular address (linux ram, framebuffer, ROM, etc.)
12112 + * Copyright (C) 1998-2004 Samuel Rydh (samuel@ibrium.se)
12114 + * This program is free software; you can redistribute it and/or
12115 + * modify it under the terms of the GNU General Public License
12116 + * as published by the Free Software Foundation
12120 +#include "archinclude.h"
12121 +#include "alloc.h"
12122 +#include "kernel_vars.h"
12125 +#include "mtable.h"
12126 +#include "performance.h"
12127 +#include "processor.h"
12129 +#define MAX_BLOCK_TRANS 6
12131 +/* Block translations are used for ROM, RAM, VRAM and similar things.
12133 + * IO-translations are a different type of mappings. Whenever an IO-area
12134 + * is accessed, a page fault occurs. If there is a page present (although
12135 + * r/w prohibited), then the low-level exception handler examines if the
12136 + * page has a magic signature in the first 8 bytes. If there is a match,
12137 + * then the page is of the type io_page_t and contains the information
12138 + * necessary to emulate the IO. If no page is present, then the corresponding
12139 + * IO-page is looked up and hashed.
12145 + pte_lvrange_t *lvrange;
12153 +typedef struct io_data {
12154 + block_trans_t btable[MAX_BLOCK_TRANS];
12156 + int next_free_id;
12157 + io_page_t *io_page_head;
12160 +static char *scratch_page;
12162 +#define MMU (kv->mmu)
12163 +#define DECLARE_IOD io_data_t *iod = kv->mmu.io_data
12168 +init_mmu_io( kernel_vars_t *kv )
12170 + if( !(MMU.io_data=kmalloc_mol(sizeof(io_data_t))) )
12172 + memset( MMU.io_data, 0, sizeof(io_data_t) );
12177 +cleanup_mmu_io( kernel_vars_t *kv )
12180 + io_page_t *next2, *p2;
12186 + for( p2=iod->io_page_head; p2; p2=next2 ) {
12187 + next2 = p2->next;
12188 + free_page_mol( (ulong)p2 );
12190 + iod->io_page_head = 0;
12192 + /* release the scratch page (not always allocated) */
12193 + if( !g_num_sessions && scratch_page ) {
12194 + free_page_mol( (int)scratch_page );
12195 + scratch_page = 0;
12198 + /* release any lvranges */
12199 + for( i=0; i<iod->num_btrans; i++ )
12200 + if( iod->btable[i].lvrange )
12201 + free_lvrange( kv, iod->btable[i].lvrange );
12203 + kfree_mol( iod );
12204 + MMU.io_data = NULL;
12208 +/* This is primarily intended for framebuffers */
12210 +bat_align( int flags, ulong ea, ulong lphys, ulong size, ulong bat[2] )
12213 + ulong offs1, offs2;
12215 + s=0x20000; /* 128K */
12218 + /* Limit to 128MB in order not to cross segments (256MB is bat-max) */
12219 + if( size > 0x10000000 )
12220 + size = 0x10000000;
12221 + for( ; s<size ; s = (s<<1) )
12223 + offs1 = ea & (s-1);
12224 + offs2 = lphys & (s-1);
12225 + if( offs1 != offs2 ) {
12226 + printk("Can't use DBAT since offsets differ (%ld != %ld)\n", offs1, offs2 );
12229 + /* BEPI | BL | VS | VP */
12230 + bat[0] = (ea & ~(s-1)) | (((s-1)>>17) << 2) | 3;
12231 + bat[1] = (lphys & ~(s-1)) | 2; /* pp=10, R/W */
12233 +#ifndef CONFIG_AMIGAONE
12234 + bat[1] |= BIT(27); /* [M] (memory coherence) */
12237 + if( !(flags & MAPPING_FORCE_CACHE) ) {
12238 + bat[1] |= BIT(26); /* [I] (inhibit cache) */
12240 + bat[1] |= BIT(25); /* [W] (write through) */
12247 + * Handle block translations (translations of mac-physical
12248 + * blocks to linux virtual physical addresses)
12251 +add_block_trans( kernel_vars_t *kv, ulong mbase, char *lvbase, ulong size, int flags )
12254 + block_trans_t *bt;
12255 + pte_lvrange_t *lvrange = NULL;
12258 + /* warn if things are not aligned properly */
12259 + if( (size & 0xfff) || ((int)lvbase & 0xfff) || (mbase & 0xfff) )
12260 + printk("Bad block translation alignement\n");
12262 + /* we keep an unsorted list - RAM should be added first, then ROM, then VRAM etc */
12263 + if( iod->num_btrans >= MAX_BLOCK_TRANS ) {
12264 + printk("Maximal number of block translations exceeded!\n");
12268 + /* remove illegal combinations */
12269 + flags &= ~MAPPING_IO;
12270 + if( (flags & MAPPING_DBAT) && !(flags & MAPPING_PHYSICAL) )
12271 + flags &= ~MAPPING_DBAT;
12273 + /* scratch pages are always physical - lvbase isn't used */
12274 + if( (flags & MAPPING_SCRATCH) ) {
12276 + flags |= MAPPING_PHYSICAL;
12277 + flags &= ~MAPPING_DBAT;
12280 + /* IMPORTANT: DBATs can _only_ be used when we KNOW that ea == mphys. */
12281 + if( (flags & MAPPING_DBAT) ) {
12283 + if( !bat_align(flags, mbase, (ulong)lvbase, size, bat) ) {
12284 + /* printk("BATS: %08lX %08lX\n", bat[0], bat[1] ); */
12285 + MMU.transl_dbat0.word[0] = bat[0];
12286 + MMU.transl_dbat0.word[1] = bat[1];
12290 + if( !(flags & MAPPING_PHYSICAL) )
12291 + if( !(lvrange=register_lvrange(kv, lvbase, size)) )
12294 + /* Determine where to insert the translation in the table.
12295 + * RAM should go right efter entries marked with MAPPING_PUT_FIRST.
12296 + * The MAPPING_PUT_FIRST flag is used to do magic things like
12297 + * embedding a copy of mregs in RAM.
12299 + ind = (!mbase || (flags & MAPPING_PUT_FIRST)) ? 0 : iod->num_btrans;
12300 + for( i=0; i<iod->num_btrans && ind <= i; i++ )
12301 + if( iod->btable[i].flags & MAPPING_PUT_FIRST )
12303 + bt = &iod->btable[ind];
12304 + if( ind < iod->num_btrans )
12305 + memmove( &iod->btable[ind+1], bt, sizeof(iod->btable[0]) * (iod->num_btrans - ind) );
12306 + iod->num_btrans++;
12307 + memset( bt, 0, sizeof(block_trans_t) );
12309 + bt->mbase = mbase;
12310 + bt->lvbase = lvbase;
12311 + bt->lvrange = lvrange;
12313 + bt->flags = flags | MAPPING_VALID;
12314 + bt->id = ++iod->next_free_id;
12316 + /* flush everything if we a translation was overridden */
12317 + if( flags & MAPPING_PUT_FIRST )
12318 + clear_pte_hash_table( kv );
12324 +remove_block_trans( kernel_vars_t *kv, int id )
12327 + block_trans_t *p;
12330 + /* Remove all mappings in the TLB table...
12331 + * (too difficult to find the entries we need to flush)
12333 + BUMP(remove_block_trans);
12334 + clear_pte_hash_table( kv );
12336 + for( p=iod->btable, i=0; i<iod->num_btrans; i++, p++ ) {
12337 + if( id == p->id ) {
12338 + if( p->flags & MAPPING_DBAT ) {
12339 + MMU.transl_dbat0.word[0] = 0;
12340 + MMU.transl_dbat0.word[1] = 0;
12343 + free_lvrange( kv, p->lvrange );
12345 + memmove( p,p+1, (iod->num_btrans-1-i)*sizeof(block_trans_t) );
12346 + iod->num_btrans--;
12350 + printk("Trying to remove nonexistent block mapping!\n");
12353 +/* adds an I/O-translation. It is legal to add the same
12354 + * range multiple times (for instance, to alter usr_data)
12357 +add_io_trans( kernel_vars_t *kv, ulong mbase, int size, void *usr_data )
12360 + io_page_t *ip, **pre_next;
12364 + /* align mbase and size to double word boundarys */
12365 + size += mbase & 7;
12366 + mbase -= mbase & 7;
12367 + size = (size+7) & ~7;
12369 + while( size > 0 ) {
12370 + mb = mbase & 0xfffff000;
12372 + pre_next = &iod->io_page_head;
12373 + for( ip=iod->io_page_head; ip && ip->mphys < mb; ip=ip->next )
12374 + pre_next = &ip->next;
12376 + if( !ip || ip->mphys != mb ) {
12377 + /* create new page */
12378 + if( !(ip=(io_page_t*)alloc_page_mol()) ) {
12379 + printk("Failed allocating IO-page\n");
12382 + ip->next = *pre_next;
12385 + /* setup block */
12386 + ip->magic = IO_PAGE_MAGIC_1;
12387 + ip->magic2 = IO_PAGE_MAGIC_2;
12388 + ip->me_phys = tophys_mol(ip);
12393 + i = (mbase & 0xfff) >> 3;
12394 + if( i+num > 512 )
12399 + ip->usr_data[i++] = usr_data;
12405 +remove_io_trans( kernel_vars_t *kv, ulong mbase, int size )
12408 + io_page_t *ip, **pre_next;
12412 + /* To remove an unused IO-page, we must make sure there are no
12413 + * dangling references to it. Hence we must search the PTE hash
12414 + * table and remove all references. We must also issue a
12415 + * tlbia to make sure it is not in the on-chip DTLB/ITLB cashe.
12417 + * XXX: Instead of seraching the hash, we simply make sure the magic
12418 + * constants are invalid. This is perfectly safe since the exception
12419 + * handler doesn't write to the page in question - and the physical
12420 + * page always exists even if it is allocated by somebody else.
12421 + * It is better to make sure there are no references of it though.
12423 + * XXX: This needs to be fixed... commonly, we reallocate
12424 + * the page ourselves for I/O so the magic constants might
12428 + /* align mbase and size to double word boundarys */
12429 + size += mbase & 7;
12430 + mbase -= mbase & 7;
12431 + size = (size+7) & ~7;
12433 + while( size > 0 ) {
12434 + mb = mbase & 0xfffff000;
12436 + pre_next = &iod->io_page_head;
12437 + for( ip=iod->io_page_head; ip && ip->mphys < mb; ip=ip->next )
12438 + pre_next = &ip->next;
12440 + if( !ip || ip->mphys != mb ) {
12442 + size -= 0x1000 - (mbase & 0xfff);
12443 + mbase += 0x1000 - (mbase & 0xfff);
12448 + i = (mbase & 0xfff) >> 3;
12449 + if( i+num > 512 )
12454 + ip->usr_data[i++] = 0;
12456 + /* May we free the page? */
12457 + for( i=0; i<512 && !ip->usr_data[i]; i++ )
12460 + /* Free page (XXX: Remove page fram hash, see above ) */
12461 + *pre_next = ip->next;
12462 + ip->magic2 = ip->magic = 0; /* IMPORTANT */
12463 + free_page_mol( (ulong)ip );
12471 +/* Translate a mac-physical address (32 bit, not page-index)
12472 + * and fill in rpn (and _possibly_ other fields) of the pte.
12473 + * The WIMG bits are not modified after this call.
12474 + * The calling function is not supposed to alter the pte after
12475 + * this function call.
12478 + * 0 no translation found
12479 + * block_flags translation found
12483 +mphys_to_pte( kernel_vars_t *kv, ulong mphys, ulong *the_pte1, int is_write, pte_lvrange_t **lvrange )
12486 + int i, num_btrans;
12487 + block_trans_t *p;
12489 + int pte1 = *the_pte1;
12491 + num_btrans = iod->num_btrans;
12494 + /* check for emuaccel page */
12495 + if( mphys == kv->emuaccel_mphys && kv->emuaccel_page_phys ) {
12496 + /* printk("emuaccel - PTE-insert\n"); */
12497 + pte1 |= kv->emuaccel_page_phys;
12498 + /* supervisor r/w, no user access */
12499 + pte1 &= ~(PTE1_W | PTE1_I | PTE1_PP);
12501 + *the_pte1 = pte1;
12502 + return MAPPING_VALID | MAPPING_PHYSICAL;
12505 + /* check for a block mapping. */
12506 + for( p=iod->btable, i=0; i<num_btrans; i++,p++ ) {
12507 + if( mphys - p->mbase < (ulong)p->size ) {
12508 + if( (p->flags & MAPPING_SCRATCH) ) {
12509 + /* it is OK to return silently if we run out of memory */
12510 + if( !scratch_page && !(scratch_page=(char*)alloc_page_mol()) )
12512 + pte1 |= tophys_mol(scratch_page);
12514 + pte1 |= (mphys - p->mbase + (ulong)p->lvbase) & PTE1_RPN;
12516 + if( p->flags & MAPPING_FORCE_CACHE ) {
12517 + /* use write through for now */
12520 + } else if( !(p->flags & MAPPING_MACOS_CONTROLS_CACHE) )
12521 + pte1 &= ~(PTE1_W | PTE1_I);
12523 + /* well, just a try... */
12524 + if ( p->flags & MAPPING_FORCE_WRITABLE ) {
12525 + /* printk("forcing mphys page %lx writable\n", mphys); */
12526 + pte1 = (pte1 & ~3) | 2;
12529 + *lvrange = p->lvrange;
12530 + *the_pte1 = pte1;
12535 + /* check for an I/O mapping. */
12536 + for( p2=iod->io_page_head; p2 && p2->mphys<=mphys; p2=p2->next ) {
12537 + if( p2->mphys != mphys )
12539 + pte1 |= p2->me_phys;
12540 + /* supervisor R/W */
12541 + pte1 &= ~(PTE1_PP | PTE1_W | PTE1_I);
12543 + *the_pte1 = pte1;
12544 + return MAPPING_VALID | MAPPING_IO | MAPPING_PHYSICAL;
12550 +mmu_add_map( kernel_vars_t *kv, struct mmu_mapping *m )
12552 + if( m->flags & MAPPING_MREGS ) {
12553 + char *start = (char*)tophys_mol(&kv->mregs);
12554 + uint offs = (uint)m->lvbase;
12555 + m->flags &= ~MAPPING_MREGS;
12556 + m->flags |= MAPPING_PHYSICAL;
12557 + m->lvbase = start + offs;
12559 + if( offs + (uint)m->size > NUM_MREGS_PAGES * 0x1000 ) {
12560 + printk("Invalid mregs mapping\n");
12564 + m->id = add_block_trans( kv, m->mbase, m->lvbase, m->size, m->flags );
12568 +mmu_remove_map( kernel_vars_t *kv, struct mmu_mapping *m )
12570 + remove_block_trans( kv, m->id );
12574 +++ b/drivers/macintosh/mol/mmu_tracker.c
12577 + * Creation Date: <2000/09/07 20:36:54 samuel>
12578 + * Time-stamp: <2004/02/14 14:45:33 samuel>
12580 + * <mmu_tracker.c>
12582 + * Keeps track of dirty RAM pages
12584 + * Copyright (C) 2000, 2001, 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
12586 + * This program is free software; you can redistribute it and/or
12587 + * modify it under the terms of the GNU General Public License
12588 + * as published by the Free Software Foundation
12592 +#include "archinclude.h"
12593 +#include "alloc.h"
12594 +#include "uaccess.h"
12598 +typedef struct tracker_data {
12600 + size_t table_size;
12606 +#define MMU (kv->mmu)
12607 +#define DECLARE_TS tracker_data_t *ts = MMU.tracker_data
12612 +init_mmu_tracker( kernel_vars_t *kv )
12614 + /* track_lvrange does the initialization */
12619 +cleanup_mmu_tracker( kernel_vars_t *kv )
12626 + vfree_mol( ts->table );
12629 + MMU.tracker_data = NULL;
12633 +track_lvrange( kernel_vars_t *kv )
12635 + ulong lvbase = MMU.userspace_ram_base;
12636 + int size = MMU.ram_size;
12640 + cleanup_mmu_tracker( kv );
12644 + if( !(ts=kmalloc_mol(sizeof(tracker_data_t))) )
12646 + memset( ts, 0, sizeof(tracker_data_t) );
12647 + MMU.tracker_data = ts;
12649 + ts->npages = size >> 12;
12650 + ts->table_size = (ts->npages+7)/8;
12651 + ts->lvbase = lvbase;
12652 + if( !(ts->table=vmalloc_mol(ts->table_size)) ) {
12653 + cleanup_mmu_tracker( kv );
12656 + memset( ts->table, 0, ts->table_size );
12661 +lvpage_dirty( kernel_vars_t *kv, ulong lvbase )
12669 + pgindex = (lvbase - ts->lvbase) >> 12;
12671 + if( pgindex >=0 && pgindex < ts->npages )
12672 + ts->table[pgindex >> 3] |= (1 << (pgindex & 7));
12677 +get_track_buffer( kernel_vars_t *kv, char *retbuf )
12684 + return ts->table_size;
12686 + if( copy_to_user_mol(retbuf, ts->table, ts->table_size) )
12688 + return ts->table_size;
12692 +set_track_buffer( kernel_vars_t *kv, char *buf )
12696 + if( !ts || !buf ) {
12697 + printk("set_track_buffer: error\n");
12700 + if( copy_from_user_mol(ts->table, buf, ts->table_size) ) {
12701 + printk("set_track_buffer: Bad access\n");
12705 +++ b/drivers/macintosh/mol/mtable.c
12708 + * Creation Date: <2002/05/26 14:46:42 samuel>
12709 + * Time-stamp: <2004/02/28 19:33:21 samuel>
12713 + * Keeps track of all PTEs MOL uses.
12715 + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
12717 + * This program is free software; you can redistribute it and/or
12718 + * modify it under the terms of the GNU General Public License
12719 + * as published by the Free Software Foundation
12724 +#include "mtable_dbg.c"
12726 +#include "archinclude.h"
12727 +#include "alloc.h"
12728 +#include "kernel_vars.h"
12729 +#include "asmfuncs.h"
12731 +#include "performance.h"
12733 +#include "mtable.h"
12736 +/* #define DEBUG */
12739 + * Implementation notes:
12741 + * - It is assumed bit the ITLB/DTLB is addressed by ea bits 14-19.
12742 + * This holds true for all CPUs at the moment (603, 604, 750, 7400,
12743 + * 7410, 7450) except the 601 (which uses bits 13-19).
12746 +typedef struct pterec pterec_t;
12749 + pterec_t *ea_next; /* ea ring (MUST GO FIRST) */
12750 + pterec_t *lv_next; /* lv ring */
12751 + uint pent; /* defined below */
12754 +#define PENT_LV_HEAD BIT(0) /* Resident - do not put on free list */
12755 +#define PENT_UNUSED BIT(1) /* (lvhead) PTE index is not valid */
12756 +#define PENT_EA_BIT14 BIT(2) /* for the partial ea used by tlbie */
12757 +#define PENT_EA_LAST BIT(3) /* next entry is the pelist pointer */
12758 +#define PENT_TOPEA_MASK 0x0f800000 /* bit 4-8 of ea */
12759 +#define PENT_SV_BIT 0x00400000 /* PTE uses vsid_sv */
12760 +#define PENT_INDEX_MASK 0x003fffff /* PTE index (there can be at most 2^22 PTEs) */
12761 +#define PENT_CMP_MASK (PENT_TOPEA_MASK | PENT_SV_BIT)
12763 +/* The index below corresponds to bit 15-19 of the ea. Bit 14 of the ea
12764 + * is stored in the pent field. Thus bits 14-19 of the ea can hence always
12765 + * be reconstructed (this struct is always properly aligned). Note that the
12766 + * pelist forms a ring (this is the reason why ea_next must be
12767 + * the first element in the pterec struct).
12771 + pterec_t *pelist[32]; /* always NULL if ring is empty */
12774 +struct vsid_ent { /* record which describes a mac vsid */
12775 + vsid_ent_t *myself_virt; /* virtual address of this struct */
12776 + int linux_vsid; /* munged mac context | VSID(Kp) */
12777 + int linux_vsid_sv; /* munged privileged mac context | VSID(Kp) */
12778 + pent_table_t *lev2[64]; /* bit 9-14 of ea */
12781 +#define LEV2_MASK 0x0001ffff /* bit 15-31 */
12783 +#define LEV2_IND(ea) (((ea) >> (12+5)) & 0x3f) /* lev2 index is bit 9-14 */
12784 +#define PELIST_IND(ea) (((ea) >> 12) & 0x1f) /* pelist index is 15-19 */
12786 +#define PTE_TO_IND(pte) ((((int)pte - (int)ptehash.base) & ptehash.pte_mask) >> 3)
12788 +#define ZERO_PTE(pent) *((ulong*)ptehash.base + ((pent & PENT_INDEX_MASK) << 1)) = 0
12791 +struct pte_lvrange {
12793 + ulong base; /* we want to do unsigned compares */
12795 + pte_lvrange_t *next; /* linked list */
12798 +typedef struct alloc_ent {
12799 + struct alloc_ent *next;
12801 + int what; /* ALLOC_CONTENTS_XXX */
12804 +struct vsid_info {
12805 + mol_spinlock_t lock; /* lvrange and pent ring lock */
12807 + pte_lvrange_t *lvrange_head;
12808 + pterec_t *free_pents; /* free list (lv_next is used) */
12809 + pent_table_t *free_pent_tables; /* pelist[0] is used for the linked list */
12811 + alloc_ent_t *allocations; /* the allocations we have performed */
12812 + int alloc_size; /* total size of allocations */
12813 + int alloc_limit; /* imposed limit */
12816 +/* don't change the CHUNK_SIZE unless you know what you are doing... */
12817 +#define CHUNK_SIZE (0x1000 - sizeof(alloc_ent_t))
12819 +#define ALLOC_CONT_ANY 0
12820 +#define ALLOC_CONT_VSID 1
12821 +#define ALLOC_CONT_PENT 2
12822 +#define ALLOC_CONT_LEV2 3
12824 +#define MMU (kv->mmu)
12826 +#define LOCK spin_lock_mol( &vi->lock )
12827 +#define UNLOCK spin_unlock_mol( &vi->lock )
12830 + * Remarks about locking: There is one asynchronous entrypoint
12831 + * (flush_lvptr). This function touches the lvranges as well
12832 + * as all pent rings. It will not free vsids or unlink
12833 + * level2 tables (but pents are put on the free list).
12837 +/************************************************************************/
12838 +/* Table Flushing */
12839 +/************************************************************************/
12841 +#define vsid_ent_lookup( kv, mvsid ) ((vsid_ent_t*)skiplist_lookup( &kv->mmu.vsid_sl, mvsid ))
12844 +flush_vsid_ea_( vsid_info_t *vi, vsid_ent_t *r, ulong ea )
12846 + pent_table_t *t = r->lev2[LEV2_IND(ea)];
12847 + pterec_t **pp, **headp, *pr, *next, *lvp;
12848 + uint topea, pent;
12851 + if( !t || !(*(pp=&t->pelist[PELIST_IND(ea)])) )
12854 + topea = (ea & PENT_TOPEA_MASK);
12860 + next = pr->ea_next;
12862 + if( (pent & PENT_TOPEA_MASK) == topea ) {
12865 + *pp = pr->ea_next;
12867 + /* unlink it from lv ring (unless it is the lv-head) */
12868 + if( pent & PENT_LV_HEAD ) {
12869 + pr->pent = PENT_UNUSED | PENT_LV_HEAD;
12871 + /* it is not certain it belong to a lv ring at all... */
12872 + if( pr->lv_next ) {
12873 + for( lvp=pr->lv_next ; lvp->lv_next != pr ; lvp=lvp->lv_next )
12875 + lvp->lv_next = pr->lv_next;
12877 + /* ...and put it on the free list */
12878 + //printk("pent released\n");
12879 + pr->lv_next = vi->free_pents;
12880 + vi->free_pents = pr;
12882 + ZERO_PTE( pent );
12884 + if( pent & PENT_EA_LAST ) {
12885 + if( pp == headp ) {
12886 + /* ring empty, set pelist pointer to NULL */
12889 + /* put marker on previous entry */
12890 + ((pterec_t*)pp)->pent |= PENT_EA_LAST;
12894 + pp = &pr->ea_next;
12897 + } while( !(pent & PENT_EA_LAST) );
12904 +flush_vsid_ea( kernel_vars_t *kv, int mac_vsid, ulong ea )
12906 + vsid_info_t *vi = MMU.vsid_info;
12910 + if( (r=vsid_ent_lookup(kv, mac_vsid)) )
12911 + flush_vsid_ea_( vi, r, ea );
12917 +pent_flush_unlink_ea( pterec_t *pr )
12919 + pterec_t **head, *prev;
12922 + //BUMP( pent_flush_unlink_ea );
12924 + if( pr->pent & PENT_UNUSED )
12925 + printk("pent_flush_unlink_ea: Internal error\n");
12927 + /* find head and previous pent in ea ring */
12928 + for( prev=pr; !(prev->pent & PENT_EA_LAST); prev=prev->ea_next )
12930 + head = (pterec_t**)prev->ea_next;
12931 + for( ; prev->ea_next != pr ; prev=prev->ea_next )
12934 + if( (pr->pent & PENT_EA_LAST) ) {
12935 + /* just a single entry in the ea ring? */
12936 + if( prev == (pterec_t*)head ) {
12937 + pr->ea_next = NULL; /* prev->ea_next is set to this below */
12939 + prev->pent |= PENT_EA_LAST;
12942 + prev->ea_next = pr->ea_next;
12944 + /* OK... it is unlinked. Reconstruct EA and flush it */
12945 + ZERO_PTE( pr->pent );
12946 + ea = ((uint)head >> 2) & 0x1f; /* Bits 15-19 of ea */
12947 + if( pr->pent & PENT_EA_BIT14 )
12950 + __tlbie(ea); /* Bits 14-19 used */
12952 + // printk("lvflush: ea (bit 14-19) %08X (pent %08X)\n", ea, pr->pent );
12954 + /* caller's responsibility to free the pent */
12958 +flush_lvptr_( vsid_info_t *vi, ulong lvptr )
12960 + pterec_t *head, *last, *first;
12961 + pte_lvrange_t *lvr;
12963 + //BUMP( pent_flush_lvptr );
12965 + for( lvr=vi->lvrange_head; lvr && lvptr - lvr->base >= lvr->size ; lvr=lvr->next )
12969 + // printk("flush_lvptr: %08lX\n", lvptr );
12971 + head = lvr->pents + ((lvptr - lvr->base) >> 12);
12973 + if( !(head->pent & PENT_LV_HEAD) ) {
12974 + printk("flush: Internal error\n");
12978 + /* first pent to be put on the free list */
12979 + first = head->lv_next;
12981 + /* not just a single entry? */
12982 + if( first != head ) {
12985 + last = last->lv_next;
12986 + pent_flush_unlink_ea( last );
12987 + } while( last->lv_next != head );
12989 + last->lv_next = vi->free_pents;
12990 + vi->free_pents = first;
12992 + if( !(head->pent & PENT_UNUSED) )
12993 + pent_flush_unlink_ea( head );
12995 + //head->ea_next = NULL;
12996 + head->lv_next = head;
12997 + head->pent = PENT_UNUSED | PENT_LV_HEAD;
13000 +/* asynchronous entrypoint (caused e.g. a swapout) */
13002 +flush_lvptr( kernel_vars_t *kv, ulong lvptr )
13004 + vsid_info_t *vi = MMU.vsid_info;
13006 + if( (char*)lvptr == MMU.lvptr_reservation )
13007 + MMU.lvptr_reservation_lost = 1;
13008 + flush_lvptr_( vi, lvptr );
13014 +flush_lv_range( kernel_vars_t *kv, ulong lvbase, int size )
13016 + vsid_info_t *vi = MMU.vsid_info;
13018 + /* this is quite inefficient but the function is seldom used */
13019 + for( ; size > 0 ; lvbase += 0x1000, size -= 0x1000 )
13020 + flush_lvptr_( vi, lvbase );
13025 +flush_ea_range( kernel_vars_t *kv, ulong org_ea, int size )
13027 + vsid_info_t *vi = MMU.vsid_info;
13028 + skiplist_iter_t iter;
13034 + //BUMP( flush_ea_range );
13035 + //printk("flush_ea_range\n");
13039 + if( size > 0x10000000 || org_ea & 0xf0000000 ) {
13040 + printk("flush_ea_range: Bad parameters %08lX %08X\n", org_ea, size);
13045 + end = org_ea + size;
13047 + /* XXX: This is horribly inefficient */
13048 + iter = skiplist_iterate( &MMU.vsid_sl );
13049 + while( skiplist_getnext(&MMU.vsid_sl, &iter, &userdata) ) {
13050 + vsid_ent_t *r = (vsid_ent_t*)userdata;
13052 + while( ea < end ) {
13053 + if( !(t=r->lev2[LEV2_IND(ea)]) ) {
13054 + ea = (ea & ~LEV2_MASK) + LEV2_MASK + 1;
13057 + for( i=PELIST_IND(ea); i<32 && ea < end; i++, ea += 0x1000 ) {
13058 + if( t->pelist[i] )
13059 + flush_vsid_ea_( vi, r, ea );
13066 +/* clear all pte entries belonging to this vsid */
13068 +flush_vsid( vsid_info_t *vi, vsid_ent_t *r )
13074 + //BUMP( flush_vsid );
13076 + /* not very efficient */
13077 + while( ea < 0x10000000 ) {
13078 + if( !(t=r->lev2[LEV2_IND(ea)]) ) {
13079 + ea = (ea & ~LEV2_MASK) + LEV2_MASK + 1;
13082 + for( i=PELIST_IND(ea); i<32; i++, ea += 0x1000 ) {
13083 + if( t->pelist[i] )
13084 + flush_vsid_ea_( vi, r, ea );
13087 + /* free level2 tables */
13088 + for( i=0; i<64; i++ ) {
13089 + pent_table_t *t = r->lev2[i];
13090 + r->lev2[i] = NULL;
13092 + /* XXX: The lev2 table _should_ be empty but we
13093 + * might want to verify this...
13096 + t->pelist[0] = (void*)vi->free_pent_tables;
13097 + vi->free_pent_tables = t;
13103 +/************************************************************************/
13105 +/************************************************************************/
13107 +/* this function allocates 0x1000 - sizeof(alloc_ent_t) zeroed bytes */
13109 +do_chunk_kmalloc( vsid_info_t *vi, int what )
13114 + if( vi->alloc_size > vi->alloc_limit )
13116 + if( !(ptr=(char*)alloc_page_mol()) )
13118 + mp = (alloc_ent_t*)((char*)ptr + 0x1000 - sizeof(alloc_ent_t));
13120 + mp->next = vi->allocations;
13123 + vi->allocations = mp;
13125 + vi->alloc_size += 0x1000;
13126 + BUMP_N( alloced, 0x1000 );
13131 +do_kfree( vsid_info_t *vi, int what )
13133 + alloc_ent_t *p, **mp = &vi->allocations;
13137 + if( p->what == what || what == ALLOC_CONT_ANY ) {
13139 + free_page_mol( (ulong)p->ptr );
13141 + vi->alloc_size -= 0x1000;
13142 + BUMP_N( released, 0x1000 );
13149 +/* Note: mtable_memory_check() must have been called previously */
13150 +static inline pent_table_t *
13151 +get_free_lev2( vsid_info_t *vi )
13153 + pent_table_t *t = vi->free_pent_tables;
13155 + vi->free_pent_tables = (pent_table_t*)vi->free_pent_tables->pelist[0];
13156 + t->pelist[0] = NULL;
13160 +/* this function is responsible for setting PENT_LV_HEAD and lv_next */
13162 +get_free_pent( vsid_info_t *vi, pte_lvrange_t *lvrange, char *lvptr )
13164 + pterec_t *pr, *pr2;
13169 + ind = (((int)lvptr - lvrange->base) >> 12);
13170 + pr2 = &lvrange->pents[ind];
13172 + if( (pr2->pent & PENT_UNUSED) ) {
13174 + pent = PENT_LV_HEAD;
13176 + /* alloc new entry */
13177 + pr = vi->free_pents;
13178 + vi->free_pents = pr->lv_next;
13180 + /* add to lv ring (after the head element) */
13181 + pr->lv_next = pr2->lv_next;
13182 + pr2->lv_next = pr;
13185 + /* alloc new entry */
13186 + pr = vi->free_pents;
13187 + vi->free_pents = pr->lv_next;
13189 + pr->lv_next = NULL;
13192 + /* allocate pterec_t and insert into the lv ring */
13198 +lev2_alloc( vsid_info_t *vi )
13200 + const int m = sizeof(pent_table_t) - 1;
13202 + int i, n = CHUNK_SIZE/sizeof(pent_table_t);
13204 + //BUMP( lev2_alloc );
13206 + if( !(t=do_chunk_kmalloc(vi, ALLOC_CONT_LEV2)) )
13209 + /* the alignment must be correct (the ea calculation will fail otherwise) */
13210 + if( (int)t & m ) {
13211 + t = (pent_table_t*)((int)t + m + 1 - ((int)t & m));
13215 + memset( t, 0, n*sizeof(pent_table_t) );
13216 + for( i=0; i<n-1; i++ )
13217 + t[i].pelist[0] = (void*)&t[i+1];
13219 + t[i].pelist[0] = (void*)vi->free_pent_tables;
13220 + vi->free_pent_tables = &t[0];
13226 +pent_alloc( vsid_info_t *vi )
13228 + const int n = CHUNK_SIZE/sizeof(pterec_t);
13232 + //BUMP( pent_alloc );
13234 + if( !(pr=do_chunk_kmalloc(vi, ALLOC_CONT_PENT)) )
13236 + memset( pr, 0, CHUNK_SIZE );
13238 + for( i=0; i<n-1; i++ )
13239 + pr[i].lv_next = &pr[i+1];
13241 + pr[i].lv_next = vi->free_pents;
13242 + vi->free_pents = &pr[0];
13248 +/* This function is to be called at a safe time (it might allocate
13249 + * memory). It ensures the next pte_inserted call will succeed.
13252 +mtable_memory_check( kernel_vars_t *kv )
13254 + vsid_info_t *vi = MMU.vsid_info;
13256 + /* optimize the common case */
13257 + if( vi->free_pents && vi->free_pent_tables )
13260 + if( !vi->free_pent_tables )
13262 + if( !vi->free_pents )
13265 + if( !vi->free_pents || !vi->free_pent_tables ) {
13266 + clear_all_vsids( kv );
13273 +/************************************************************************/
13275 +/************************************************************************/
13277 +static inline void
13278 +relink_lv( vsid_info_t *vi, pterec_t *pr, pte_lvrange_t *lvrange, char *lvptr )
13280 + int ind = (((int)lvptr - lvrange->base) >> 12);
13281 + pterec_t *pnew, *p, *lv_head = &lvrange->pents[ind];
13283 + if( !pr->lv_next ) {
13284 + //printk("Not previously on lvlist\n");
13285 + pr->lv_next = lv_head->lv_next;
13286 + lv_head->lv_next = pr;
13290 + if( pr->pent & PENT_LV_HEAD ) {
13291 + if( pr == lv_head ) {
13292 + //printk("lvptr is head (correct lv ring)\n");
13296 + /* unlink from ea ring and add new pent */
13297 + for( p=pr->ea_next; p->ea_next != pr ; p=p->ea_next )
13299 + pnew = get_free_pent( vi, lvrange, lvptr );
13300 + pnew->ea_next = pr->ea_next;
13301 + p->ea_next = pnew;
13303 + pnew->pent |= (pr->pent & ~(PENT_UNUSED | PENT_LV_HEAD));
13305 + /* clear old lvhead */
13306 + // pr->ea_next = NULL;
13307 + pr->pent = PENT_LV_HEAD | PENT_UNUSED;
13309 + //printk("lvptr is head\n");
13312 + for( p=pr->lv_next; !(p->pent & PENT_LV_HEAD) ; p=p->lv_next )
13314 + if( p == lv_head ) {
13315 + //printk("lvptr is on the correct lv ring\n");
13319 + /* lvptr has chagned, unlink */
13320 + for( ; p->lv_next != pr ; p=p->lv_next )
13322 + p->lv_next = pr->lv_next;
13324 + /* add to lv ring */
13325 + pr->lv_next = lv_head->lv_next;
13326 + lv_head->lv_next = pr;
13330 +/* Note: If lvrange is NULL then lvptr should be ignored */
13332 +pte_inserted( kernel_vars_t *kv, ulong ea, char *lvptr, pte_lvrange_t *lvrange,
13333 + ulong *pte, vsid_ent_t *r, int segreg )
13335 + vsid_info_t *vi = MMU.vsid_info;
13336 + int pl_ind = PELIST_IND(ea);
13337 + uint pent, pent_cmp;
13338 + pterec_t *pr, **pp;
13339 + pent_table_t **tt;
13342 + if( lvrange && MMU.lvptr_reservation_lost ) {
13343 + printk("mtable: lvptr reservation lost %08x\n", (int)lvptr );
13349 + tt = &r->lev2[ LEV2_IND(ea) ];
13351 + pent_cmp = (ea & PENT_TOPEA_MASK);
13352 + if( (r->linux_vsid_sv & VSID_MASK) == (segreg & VSID_MASK) )
13353 + pent_cmp |= PENT_SV_BIT;
13356 + *tt = get_free_lev2(vi);
13358 + pp = &(**tt).pelist[ pl_ind ];
13362 + if( (pent & PENT_CMP_MASK) == pent_cmp ) {
13363 + pent &= ~PENT_INDEX_MASK;
13364 + pent |= PTE_TO_IND(pte);
13367 + /* the lvptr might have changed */
13369 + relink_lv( vi, pr, lvrange, lvptr );
13371 + /* The pent might belong to a lvring unnecessarily.
13372 + * It is not worth the extra overhead addressing this
13373 + * (uncommon) case
13376 + //printk("PTE entry reused\n");
13380 + } while( !(pent & PENT_EA_LAST) );
13382 + /* get_free_pent inserts the entry into the lvring and sets a few pent bits */
13383 + pr = get_free_pent(vi, lvrange, lvptr);
13384 + pr->pent |= PTE_TO_IND(pte) | pent_cmp | ((ea & BIT(14)) ? PENT_EA_BIT14 : 0);
13386 + /* insert in (non-empty) ea ring */
13387 + pr->ea_next = *pp;
13390 + /* ea ring was empty */
13391 + pr = *pp = get_free_pent(vi, lvrange, lvptr);
13392 + pr->pent |= PENT_EA_LAST | PTE_TO_IND(pte) | pent_cmp
13393 + | ((ea & BIT(14)) ? PENT_EA_BIT14 : 0);
13394 + pr->ea_next = (pterec_t*)pp;
13401 +/************************************************************************/
13402 +/* VSID allocation */
13403 +/************************************************************************/
13405 +/* initialize vsid element callback (ind loops from 0 to n-1) */
13407 +_vsid_el_callback( char *data, int ind, int n, void *usr1_kv, void *dummy )
13409 + kernel_vars_t *kv = (kernel_vars_t*)usr1_kv;
13410 + vsid_ent_t *r = (vsid_ent_t*)data;
13412 + r->linux_vsid = alloc_context(kv) | VSID_Kp;
13413 + r->linux_vsid_sv = alloc_context(kv) | VSID_Kp;
13414 + r->myself_virt = r;
13417 +/* mac_vsid might be negative (used as vsid for unmapped access).
13418 + * Thus, do not apply this VSID mask anywhere...
13420 +static vsid_ent_t *
13421 +alloc_vsid_ent( kernel_vars_t *kv, int mac_vsid )
13425 + if( skiplist_needalloc(&MMU.vsid_sl) ) {
13426 + /* this check might invoke clear_all_vsids() */
13427 + handle_context_wrap( kv, CHUNK_SIZE/sizeof(vsid_ent_t)*2 );
13429 + if( !(buf=do_chunk_kmalloc(MMU.vsid_info, ALLOC_CONT_VSID)) )
13431 + memset( buf, 0, CHUNK_SIZE );
13433 + (void) skiplist_prealloc( &MMU.vsid_sl, buf, CHUNK_SIZE, _vsid_el_callback, kv, NULL );
13435 + return (vsid_ent_t*)skiplist_insert( &MMU.vsid_sl, mac_vsid );
13438 +/* flushes all vsids (including the fake no-MMU vsids) */
13440 +clear_all_vsids( kernel_vars_t *kv )
13442 + vsid_info_t *vi = MMU.vsid_info;
13443 + skiplist_iter_t iter;
13447 + iter = skiplist_iterate( &MMU.vsid_sl );
13448 + while( skiplist_getnext(&MMU.vsid_sl, &iter, &userdata) )
13449 + flush_vsid( vi, (vsid_ent_t*)userdata );
13451 + skiplist_init( &MMU.vsid_sl, sizeof(vsid_ent_t) );
13453 + /* flush any dangling pointers */
13454 + clear_vsid_refs( kv );
13456 + /* all vsids cleared -> all lev2 cleared -> no pents in use */
13457 + vi->free_pents = NULL;
13458 + vi->free_pent_tables = NULL;
13460 + do_kfree( vi, ALLOC_CONT_ANY );
13462 + BUMP(clear_all_vsids);
13465 +/* This function flushes *ALL* PTEs inserted by MOL. It is primarily
13466 + * used when it is too difficult to make a more specific invalidation.
13469 +clear_pte_hash_table( kernel_vars_t *kv )
13471 + /* this will free the vsids too... */
13472 + clear_all_vsids( kv );
13476 +vsid_get_user_sv( kernel_vars_t *kv, int mac_vsid, ulong *user_ret, ulong *sv_ret )
13478 + vsid_ent_t *r = vsid_ent_lookup( kv, mac_vsid );
13480 + if( !r && !(r=alloc_vsid_ent(kv, mac_vsid)) ) {
13481 + clear_all_vsids( kv );
13482 + if( !(r=alloc_vsid_ent(kv, mac_vsid)) ) {
13483 + printk("VSID allocation failure\n");
13487 + *user_ret = r->linux_vsid;
13488 + *sv_ret = r->linux_vsid_sv;
13492 +/************************************************************************/
13493 +/* resource reclaiming */
13494 +/************************************************************************/
13497 +mtable_reclaim( kernel_vars_t *kv )
13499 + vsid_info_t *vi = MMU.vsid_info;
13500 + skiplist_iter_t iter;
13505 + /* This thread runs on the main thread, thus the skiplist stuff does
13506 + * not need locking. In fact, it is only the free_pent_tables
13507 + * list that needs spinlock protection.
13510 + iter = skiplist_iterate( &MMU.vsid_sl );
13511 + while( skiplist_getnext(&MMU.vsid_sl, &iter, &userdata) ) {
13512 + vsid_ent_t *r = (vsid_ent_t*)userdata;
13513 + const int n1 = sizeof(r->lev2)/sizeof(r->lev2[0]);
13514 + const int n2 = sizeof(t->pelist)/sizeof(t->pelist[0]);
13516 + for( i=0; i<n1; i++ ) {
13517 + if( !(t=r->lev2[i]) )
13519 + for( j=0; j<n2 && !(t->pelist[j]) ; j++ )
13523 + /* level2 empty... */
13524 + r->lev2[i]->pelist[0] = (void*)vi->free_pent_tables;
13525 + vi->free_pent_tables = r->lev2[i];
13526 + r->lev2[i] = NULL;
13528 + BUMP(lev2_reclaim);
13531 + int vsid = skiplist_iter_getkey( &MMU.vsid_sl, (char*)r );
13533 + /* the segment might be in use... */
13534 + for( i=0; i<16 && MMU.vsid[i] != r; i++ )
13536 + if( i != 16 || (uint)vsid > VSID_MASK )
13538 + skiplist_delete( &MMU.vsid_sl, vsid );
13539 + BUMP(vsid_reclaim);
13545 +/************************************************************************/
13546 +/* lvrange allocation */
13547 +/************************************************************************/
13550 +register_lvrange( kernel_vars_t *kv, char *lvbase, int size )
13552 + vsid_info_t *vi = MMU.vsid_info;
13553 + pte_lvrange_t *lvr;
13554 + int i, nel = (size >> 12);
13555 + int s = sizeof(pterec_t) * nel;
13557 + /* printk("register_lvrange\n"); */
13559 + if( !(lvr=kmalloc_mol(sizeof(pte_lvrange_t))) )
13561 + memset( lvr, 0, sizeof(pte_lvrange_t) );
13563 + if( !(lvr->pents=vmalloc_mol(s)) ) {
13564 + kfree_mol( lvr );
13567 + /* setup empty lvrings */
13568 + for( i=0; i<nel; i++ ) {
13569 + lvr->pents[i].pent = PENT_LV_HEAD | PENT_UNUSED;
13570 + lvr->pents[i].lv_next = &lvr->pents[i];
13571 + lvr->pents[i].ea_next = NULL;
13573 + lvr->base = (ulong)lvbase;
13574 + lvr->size = size;
13577 + /* add to linked list */
13578 + lvr->next = vi->lvrange_head;
13579 + vi->lvrange_head = lvr;
13586 +free_lvrange( kernel_vars_t *kv, pte_lvrange_t *lvrange )
13588 + vsid_info_t *vi = MMU.vsid_info;
13589 + pte_lvrange_t **lvr;
13591 + lvr = &vi->lvrange_head;
13592 + for( ; *lvr && *lvr != lvrange; lvr=&(**lvr).next )
13595 + printk("free_lvrange: Internal error\n");
13598 + flush_lv_range( kv, (**lvr).base, (**lvr).size );
13600 + *lvr = (**lvr).next;
13603 + vfree_mol( lvrange->pents );
13604 + kfree_mol( lvrange );
13607 +/************************************************************************/
13608 +/* init / cleanup */
13609 +/************************************************************************/
13612 +mtable_tune_alloc_limit( kernel_vars_t *kv, int ramsize_mb )
13614 + vsid_info_t *vi = MMU.vsid_info;
13615 + vi->alloc_limit = (ramsize_mb + 160) * 4096;
13616 + /* printk("alloc_limit: %d K\n", vi->alloc_limit/1024 ); */
13620 +init_mtable( kernel_vars_t *kv )
13622 + vsid_info_t *vi = kmalloc_mol( sizeof(vsid_info_t) );
13624 + MMU.vsid_info = vi;
13627 + memset( vi, 0, sizeof(vsid_info_t) );
13628 + spin_lock_init_mol( &vi->lock );
13630 + /* will be tuned when we know how much RAM we have */
13631 + vi->alloc_limit = 2 * 1024 * 1024;
13633 + skiplist_init( &MMU.vsid_sl, sizeof(vsid_ent_t) );
13635 + if( !VSID_OFFSETS_OK ) {
13636 + printk("VSID offsets are BAD (fix offset in source)!\n");
13643 +cleanup_mtable( kernel_vars_t *kv )
13645 + vsid_info_t *vi = MMU.vsid_info;
13648 + while( vi->lvrange_head ) {
13649 + printk("Bug: lvrange unreleased!\n");
13650 + free_lvrange( kv, vi->lvrange_head );
13652 + do_kfree( vi, ALLOC_CONT_ANY );
13655 + memset( &MMU.vsid_sl, 0, sizeof(MMU.vsid_sl) );
13656 + MMU.vsid_info = NULL;
13660 +/************************************************************************/
13661 +/* userland debug */
13662 +/************************************************************************/
13665 +#include "mtable_dbg.c"
13668 +++ b/drivers/macintosh/mol/ptaccess.c
13671 + * Creation Date: <2001/03/25 18:04:45 samuel>
13672 + * Time-stamp: <2002/08/03 17:43:10 samuel>
13676 + * Handle stores to the (emulated) page table
13678 + * Copyright (C) 2001, 2002 Samuel Rydh (samuel@ibrium.se)
13680 + * This program is free software; you can redistribute it and/or
13681 + * modify it under the terms of the GNU General Public License
13682 + * as published by the Free Software Foundation
13686 +#include "archinclude.h"
13689 +#include "mtable.h"
13691 +#include "performance.h"
13693 +extern int do_intercept_tlbie( kernel_vars_t *kv, ulong pte0, ulong pte1, ulong pteoffs );
13694 +extern int do_intercept_tlbie_block( kernel_vars_t *kv, ulong pteoffs, ulong length );
13696 +#define MMU (kv->mmu)
13697 +#define MREGS (kv->mregs)
13700 +do_intercept_tlbie( kernel_vars_t *kv, ulong pte0, ulong pte1, ulong pteoffs )
13702 + int vsid = (pte0 >> 7) & VSID_MASK;
13705 + BUMP( do_intercept_tlbie );
13707 + if( MMU.pthash_inuse_bits )
13708 + clear_bit_mol( pteoffs >> 3, MMU.pthash_inuse_bits );
13710 + v = (pteoffs >> 6);
13711 + if( pte0 & BIT(25) ) /* secondary hash? */
13713 + v ^= (pte0 >> 7);
13714 + v = ((pte0 << 10) & 0xfc00) | (v & 0x3ff);
13716 + //printk("do_intercept_tlbie: vsid %08lX, ea %08lX\n", vsid, (v<<12) );
13717 + flush_vsid_ea( kv, vsid, (v<<12) );
13723 +do_intercept_tlbie_block( kernel_vars_t *kv, ulong pteoffs, ulong length )
13725 + unsigned int finish;
13727 + //printk("do_intercept_tlbie_block: pteoffs %08lX length %08lX\n", pteoffs, length);
13729 + if (pteoffs + length > MMU.hash_mask) {
13730 + printk("do_intercept_tlbie_block: length exceeding hash!\n");
13731 + finish = MMU.hash_mask + 1;
13733 + finish = pteoffs + length;
13735 + if (MMU.pthash_inuse_bits == NULL)
13738 + while (pteoffs < finish) {
13739 + if (check_bit_mol(pteoffs >> 3, MMU.pthash_inuse_bits)) {
13740 + ulong pte0, pte1;
13742 + pte0 = *((unsigned int *) (MMU.hash_base + pteoffs));
13743 + pte1 = *((unsigned int *) (MMU.hash_base + pteoffs + 4));
13744 + do_intercept_tlbie(kv, pte0, pte1, pteoffs);
13753 +#ifdef EMULATE_603
13755 +extern int do_tlbli( kernel_vars_t *kv, ulong ea );
13756 +extern int do_tlbld( kernel_vars_t *kv, ulong ea );
13759 +do_tlbli( kernel_vars_t *kv, ulong ea )
13761 + int ind = (ea >> 12) & 0x1f;
13764 + //printk("do_tlbli %08lX : %08lX %08lX\n", ea, MREGS.spr[S_ICMP], MREGS.spr[S_RPA] );
13765 + if( MREGS.spr[S_SRR1] & BIT(14) )
13768 + p = &MMU.ptes_i_603[ind];
13770 + flush_vsid_ea( kv, p->vsid, MMU.ptes_i_ea_603[ind] );
13771 + MMU.ptes_i_ea_603[ind] = ea & 0x0ffff000;
13772 + *(ulong*)p = MREGS.spr[ S_ICMP ];
13773 + *((ulong*)p+1) = MREGS.spr[ S_RPA ];
13779 +do_tlbld( kernel_vars_t *kv, ulong ea )
13781 + int ind = (ea >> 12) & 0x1f;
13784 + //printk("do_tlbld %08lX\n", ea );
13786 + if( MREGS.spr[S_SRR1] & BIT(14) )
13789 + p = &MMU.ptes_d_603[ind];
13791 + flush_vsid_ea( kv, p->vsid, MMU.ptes_d_ea_603[ind] );
13792 + MMU.ptes_d_ea_603[ind] = ea & 0x0ffff000;
13793 + *(ulong*)p = MREGS.spr[ S_DCMP ];
13794 + *((ulong*)p+1) = MREGS.spr[ S_RPA ];
13800 +do_tlbie( kernel_vars_t *kv, ulong ea )
13802 + int ind = (ea >> 12) & 0x1f;
13804 + ulong *iea, *dea;
13806 + pi = &MMU.ptes_i_603[ind];
13807 + pd = &MMU.ptes_d_603[ind];
13808 + iea = &MMU.ptes_i_ea_603[ind];
13809 + dea = &MMU.ptes_d_ea_603[ind];
13810 + for( ; ind < 64; ind +=32, pd += 32, pi += 32, iea += 32, dea +=32 ) {
13812 + flush_vsid_ea( kv, pi->vsid, *iea );
13814 + flush_vsid_ea( kv, pd->vsid, *dea );
13821 +#endif /* EMULATE_603 */
13824 +++ b/drivers/macintosh/mol/sheep.c
13827 + * sheep_net.c - Linux driver for SheepShaver/Basilisk II networking (access to raw Ethernet packets)
13829 + * SheepShaver (C) 1997-1999 Mar"c" Hellwig and Christian Bauer
13830 + * Basilisk II (C) 1997-1999 Christian Bauer
13832 + * Ported to 2.4 and reworked, Samuel Rydh 1999-2003
13835 +#include <linux/kernel.h>
13836 +#include <linux/module.h>
13837 +#include <linux/version.h>
13838 +#include <linux/miscdevice.h>
13839 +#include <linux/netdevice.h>
13840 +#include <linux/etherdevice.h>
13841 +#include <linux/if_ether.h>
13842 +#include <linux/if_arp.h>
13843 +#include <linux/fs.h>
13844 +#include <linux/poll.h>
13845 +#include <linux/init.h>
13846 +#include <net/sock.h>
13847 +#include <asm/uaccess.h>
13848 +#include <net/arp.h>
13849 +#include <net/ip.h>
13850 +#include <linux/in.h>
13851 +#include <linux/wait.h>
13853 +MODULE_AUTHOR("Marc Hellwig and Christian Bauer");
13854 +MODULE_DESCRIPTION("SheepShaver/Basilisk II networking");
13855 +MODULE_LICENSE("GPL");
13857 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
13861 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)
13862 +#define ETH_HDR(skb) eth_hdr((skb))
13864 +#define ETH_HDR(skb) (skb)->mac.ethernet
13869 +#define bug printk
13876 +#define SHEEP_NET_MINOR 198 // Driver minor number
13877 +#define MAX_QUEUE 32 // Maximum number of packets in queue
13878 +#define PROT_MAGIC 1520 // Our "magic" protocol type
13880 +#define ETH_ADDR_MULTICAST 0x1
13881 +#define ETH_ADDR_LOCALLY_DEFINED 0x2
13883 +#define SIOC_MOL_GET_IPFILTER SIOCDEVPRIVATE
13884 +#define SIOC_MOL_SET_IPFILTER (SIOCDEVPRIVATE + 1)
13886 +struct SheepVars {
13887 + /* IMPORTANT: the packet_type struct must go first. It no longer (2.6) contains
13888 + * a data field so we typecast to get the SheepVars struct
13890 + struct packet_type pt; // Receiver packet type
13891 + struct net_device *ether; // The Ethernet device we're attached to
13892 + struct sock *skt; // Socket for communication with Ethernet card
13893 + struct sk_buff_head queue; // Receiver packet queue
13894 + wait_queue_head_t wait; // Wait queue for blocking read operations
13895 + unsigned long ipfilter; // only receive ip packets destined for this address
13896 + char fake_addr[6];
13900 + * How various hosts address MOL
13902 + * External hosts: eth_addr, MOL_IP
13903 + * Local host: fake_addr, MOL_IP
13904 + * MOL: fake_addr, MOL_IP
13909 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
13910 +#define compat_sk_alloc(a,b,c) sk_alloc( (a), (b), &mol_proto, 1 )
13912 +#define compat_sk_alloc(a,b,c) sk_alloc( (a), (b), (c), NULL )
13915 +#define skt_set_dead(skt) do {} while(0)
13916 +#define wmem_alloc sk_wmem_alloc
13918 +#define compat_sk_alloc sk_alloc
13919 +#define skt_set_dead(skt) (skt)->dead = 1
13922 +/************************************************************************/
13923 +/* ethernet address masquerading */
13924 +/************************************************************************/
13927 +addrcmp( const char *a1, const char *a2 )
13929 + if( *(u32*)a1 != *(u32*)a2 )
13931 + return *((u16*)a1+2) != *((u16*)a2+2);
13934 +/* Outgoing packet. Replace the fake enet addr with the real one. */
13935 +static inline void
13936 +cpyaddr( char *d, const char *s )
13938 + *(u32*)d = *(u32*)s;
13939 + *(u16*)&d[4] = *(u16*)&s[4];
13943 +demasquerade( struct sk_buff *skb, struct SheepVars *v )
13945 + const char *local_addr = v->ether->dev_addr;
13946 + const char *fake_addr = v->fake_addr;
13947 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,21))
13948 + char *p = skb_mac_header(skb);
13950 + char *p = skb->mac.raw;
13952 + int proto = *(short*)&p[12];
13954 + cpyaddr( &p[6], local_addr ); // Source address
13956 + // Need to fix ARP packets
13957 + if( proto == htons(ETH_P_ARP) )
13958 + if( !addrcmp(&p[14+8], fake_addr) ) // sender HW-addr
13959 + cpyaddr( &p[14+8], local_addr );
13961 + // ...and AARPs (snap code: 0x00,0x00,0x00,0x80,0xF3)
13962 + if( !p[17] && *(u32*)&p[18] == 0x000080F3 ){
13963 + // XXX: we should perhaps look for the 802 frame too
13964 + if( !addrcmp(&p[30], fake_addr) )
13965 + cpyaddr( &p[30], local_addr ); // sender HW-addr
13970 +/************************************************************************/
13971 +/* receive filter (also intercepts outgoing packets) */
13972 +/************************************************************************/
13974 +/* This function filters both outgoing and incoming traffic.
13976 + * - Outgoing PROT_MAGIC packets are outgoing mol packets
13977 + * addressed to the world (not to the local host).
13979 + * - Outgoing packets addressed to the fake address
13980 + * are incoming MOL packets (from the local host).
13981 + * These packets will be seen on the wire, since we can't
13984 + * - Incoming packets which originate from the fake address
13985 + * are MOL packets addressed to the local host.
13987 + * - Incomming external traffic to the MOL IP address are incoming
13988 + * MOL packets. Linux will see these packets too. (Hmm... if
13989 + * we change protocol to PROT_MAGIC then linux ought to ignore
13990 + * them; currently linux responds to ICMP packets even though
13991 + * the IP address is wrong.)
13995 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14))
13997 +sheep_net_receiver( struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev )
14000 +sheep_net_receiver( struct sk_buff *skb, struct net_device *dev, struct packet_type *pt )
14003 + int multicast = (ETH_HDR(skb)->h_dest[0] & ETH_ADDR_MULTICAST);
14004 + const char *laddr = dev->dev_addr;
14005 + struct sk_buff *skb2;
14006 + struct SheepVars *v = (struct SheepVars*)pt;
14008 + D(bug("sheep_net: packet received\n"));
14010 + if( skb->pkt_type == PACKET_OUTGOING ) {
14011 + // Is this an MOL packet to the world?
14012 + if( skb->protocol == PROT_MAGIC )
14015 + if( !multicast ) {
14016 + // Drop, unless this is a localhost -> MOL transmission */
14017 + if( addrcmp((char*)Ð_HDR(skb)->h_dest, v->fake_addr) )
14020 + /* XXX: If it were possible, we would prevent the packet from beeing sent out
14021 + * on the wire (after having put it on our packet reception queue).
14022 + * A transmission to a non-existent mac address will unfortunately
14023 + * be subnet-visible (having a switched network doesn't help). As a
14024 + * workaround, we change the destination address to the address of
14025 + * the controller. This way, the packet ought to be discarded by
14028 + cpyaddr( Ð_HDR(skb)->h_dest[0], laddr );
14031 + // is this a packet to the local host from MOL?
14032 + if( !addrcmp((char*)Ð_HDR(skb)->h_source, v->fake_addr) )
14035 + if( !multicast ) {
14036 + // if the packet is not meant for this host, discard it
14037 + if( addrcmp((char*)Ð_HDR(skb)->h_dest, laddr) )
14040 + // filter IP-traffic
14041 + if( (skb->protocol == htons(ETH_P_IP)) ) {
14042 + // drop if not addreesed to MOL?
14043 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,21))
14044 + if( !v->ipfilter || (ipip_hdr(skb)->daddr != v->ipfilter) )
14046 + if( !v->ipfilter || (skb->h.ipiph->daddr != v->ipfilter) )
14049 + // we don't want this packet interpreted by linux...
14050 + skb->protocol = PROT_MAGIC;
14054 + // Discard packets if queue gets too full
14055 + if( skb_queue_len(&v->queue) > MAX_QUEUE )
14058 + /* masquerade. The skb is typically has a refcount != 1 so we play safe
14059 + * and make a copy before modifying it. This also takes care of fragmented
14060 + * skbuffs (we might receive those if we are attached to a device with support
14063 + if( !(skb2=skb_copy(skb, GFP_ATOMIC)) )
14065 + kfree_skb( skb );
14069 + cpyaddr( Ð_HDR(skb)->h_dest[0], v->fake_addr );
14071 + // We also want the Ethernet header
14072 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,21))
14073 + skb_push( skb, skb->data - skb_mac_header(skb) );
14075 + skb_push( skb, skb->data - skb->mac.raw );
14078 + // Enqueue packet
14079 + skb_queue_tail( &v->queue, skb );
14081 + // Unblock blocked read
14082 + wake_up_interruptible( &v->wait );
14086 + kfree_skb( skb );
14091 +/************************************************************************/
14092 +/* misc device ops */
14093 +/************************************************************************/
14094 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
14095 +static struct proto mol_proto =
14098 + .owner = THIS_MODULE,
14099 + .obj_size = sizeof(struct sock)
14105 +sheep_net_open( struct inode *inode, struct file *f )
14107 + static char fake_addr_[6] = { 0xFE, 0xFD, 0xDE, 0xAD, 0xBE, 0xEF };
14108 + struct SheepVars *v;
14109 + D(bug("sheep_net: open\n"));
14111 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
14112 + if (proto_register(&mol_proto,0) < 0)
14114 + printk(KERN_INFO "Unable to register protocol type\n");
14119 + // Must be opened with read permissions
14120 + if( (f->f_flags & O_ACCMODE) == O_WRONLY )
14123 + // Allocate private variables
14124 + f->private_data = kmalloc(sizeof(struct SheepVars), GFP_USER);
14125 + if( f->private_data == NULL)
14128 + v = (struct SheepVars *) f->private_data;
14130 + memset( v, 0, sizeof(*v) );
14131 + memcpy( v->fake_addr, fake_addr_, 6 );
14133 + skb_queue_head_init( &v->queue );
14134 + init_waitqueue_head( &v->wait );
14140 +sheep_net_release( struct inode *inode, struct file *f )
14142 + struct SheepVars *v = (struct SheepVars *)f->private_data;
14143 + struct sk_buff *skb;
14144 + D(bug("sheep_net: close\n"));
14146 + // Detach from Ethernet card
14148 + dev_remove_pack( &v->pt );
14149 + sk_free( v->skt );
14151 + dev_put( v->ether );
14155 + // Empty packet queue
14156 + while( (skb=skb_dequeue(&v->queue)) )
14159 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
14160 + proto_unregister(&mol_proto);
14163 + // Free private variables
14169 +get_iovsize( const struct iovec *iv, int count )
14172 + for( s=0; count-- ; iv++ )
14173 + s += iv->iov_len;
14178 +memcpy_tov( const struct iovec *iv, const char *buf, int s )
14181 + int len = min_t( unsigned int, iv->iov_len, s );
14183 + if( copy_to_user(iv->iov_base, buf, len) )
14193 +memcpy_fromv( char *buf, const struct iovec *iv, int s )
14196 + int len = min_t( unsigned int, iv->iov_len, s );
14198 + if( copy_from_user(buf, iv->iov_base, len) )
14208 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
14209 +sheep_net_aio_read(struct kiocb *iocb, const struct iovec *iv, unsigned long count, loff_t pos)
14211 + struct file *f = iocb->ki_filp;
14212 +#else /* Linux 2.6.18 or older */
14213 +sheep_net_readv( struct file *f, const struct iovec *iv, unsigned long count, loff_t *pos )
14216 + struct SheepVars *v = (struct SheepVars *)f->private_data;
14217 + struct sk_buff *skb;
14218 + int size = get_iovsize( iv, count );
14220 + D(bug("sheep_net: read\n"));
14222 + while( !(skb=skb_dequeue(&v->queue)) ) {
14223 + // wait around...
14224 + if( (f->f_flags & O_NONBLOCK))
14227 + interruptible_sleep_on( &v->wait );
14229 + if( signal_pending(current) )
14233 + // Pass packet to caller
14234 + if( size > skb->len )
14236 + if( memcpy_tov(iv, skb->data, size) )
14239 + kfree_skb( skb );
14244 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
14245 +sheep_net_aio_write(struct kiocb *iocb, const struct iovec *iv, unsigned long count, loff_t off)
14247 + struct file *f = iocb->ki_filp;
14248 +#else /* Linux 2.6.18 or older */
14249 +sheep_net_writev( struct file *f, const struct iovec *iv, unsigned long count, loff_t *off )
14252 + struct SheepVars *v = (struct SheepVars *)f->private_data;
14253 + struct sk_buff *skb;
14254 + int size = get_iovsize( iv, count );
14256 + D(bug("sheep_net: write\n"));
14258 + // Check packet size
14259 + if( size < sizeof(struct ethhdr) )
14261 + if( size > 1514 ) {
14262 + printk("sheep_net_write: packet > 1514!\n");
14266 + // Interface active?
14269 + laddr = v->ether->dev_addr;
14271 + // Allocate buffer for packet
14272 + if( !(skb=dev_alloc_skb(size)) )
14275 + // Stuff packet in buffer
14276 + p = skb_put( skb, size );
14277 + if( memcpy_fromv(p, iv, size) ) {
14282 + // Transmit packet
14283 + atomic_add( skb->truesize, &v->skt->wmem_alloc );
14284 + skb->sk = v->skt;
14285 + skb->dev = v->ether;
14286 + skb->priority = 0;
14287 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,21))
14288 + skb_set_network_header(skb, v->ether->hard_header_len);
14289 + skb_set_transport_header(skb, v->ether->hard_header_len);
14290 + skb_reset_mac_header(skb);
14292 + skb->nh.raw = skb->h.raw = skb->data + v->ether->hard_header_len;
14293 + skb->mac.raw = skb->data;
14296 + // Base the IP-filter on the IP address of outgoing ARPs
14297 + if( ETH_HDR(skb)->h_proto == htons(ETH_P_ARP) ) {
14298 + char *s = &skb->data[14+14]; /* source IP-address */
14300 + if( *(long*)s != v->ipfilter ) {
14301 + v->ipfilter = *(long*)s;
14302 + n[0]=s[0], n[1]=s[1], n[2]=s[2], n[3]=s[3];
14303 + printk("IP-filter: %d.%d.%d.%d\n", n[0], n[1], n[2], n[3] );
14307 + // Is this package addressed solely to the local host?
14308 + if( !addrcmp(skb->data, laddr) && !(skb->data[0] & ETH_ADDR_MULTICAST) ) {
14309 + skb->protocol = eth_type_trans( skb, v->ether );
14310 + netif_rx_ni( skb );
14313 + if( skb->data[0] & ETH_ADDR_MULTICAST ) {
14314 + // We can't clone the skb since we will manipulate the data below
14315 + struct sk_buff *lskb = skb_copy( skb, GFP_ATOMIC );
14317 + lskb->protocol = eth_type_trans( lskb, v->ether );
14318 + netif_rx_ni( lskb );
14321 + // Outgoing packet (will be seen on the wire)
14322 + demasquerade( skb, v );
14324 + skb->protocol = PROT_MAGIC; // Magic value (we can recognize the packet in sheep_net_receiver)
14325 + dev_queue_xmit( skb );
14329 +/* We take care of this using do_sync_* instead in 2.6.19 and newer */
14330 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
14332 +sheep_net_read( struct file *f, char *buf, size_t count, loff_t *off )
14335 + iv.iov_base = buf;
14336 + iv.iov_len = count;
14337 + return sheep_net_readv( f, &iv, 1, off );
14341 +sheep_net_write( struct file *f, const char *buf, size_t count, loff_t *off )
14344 + iv.iov_len = count;
14345 + iv.iov_base = (char *)buf;
14346 + return sheep_net_writev( f, &iv, 1, off );
14350 +static unsigned int
14351 +sheep_net_poll( struct file *f, struct poll_table_struct *wait )
14353 + struct SheepVars *v = (struct SheepVars *)f->private_data;
14354 + D(bug("sheep_net: poll\n"));
14356 + poll_wait( f, &v->wait, wait );
14358 + if( !skb_queue_empty(&v->queue) )
14359 + return POLLIN | POLLRDNORM;
14364 +sheep_net_ioctl( struct inode *inode, struct file *f, unsigned int code, unsigned long arg )
14366 + struct SheepVars *v = (struct SheepVars *)f->private_data;
14367 + D(bug("sheep_net: ioctl %04x\n", code));
14370 + // Attach to Ethernet card
14371 + // arg: pointer to name of Ethernet device (char[20])
14372 + case SIOCSIFLINK: {
14376 + // Already attached?
14380 + // Get Ethernet card name
14381 + if( copy_from_user(name, (void *)arg, 20) )
14386 + if( !(v->ether=dev_get_by_name(name)) )
14389 + // Is it Ethernet?
14390 + if( v->ether->type != ARPHRD_ETHER) {
14395 + // Allocate socket
14396 + if( !(v->skt=compat_sk_alloc(0, GFP_USER, 1)) ) {
14400 + skt_set_dead( v->skt );
14402 + // Attach packet handler
14403 + v->pt.type = htons(ETH_P_ALL);
14404 + v->pt.dev = v->ether;
14405 + v->pt.func = sheep_net_receiver;
14406 + //v->pt.data = v;
14407 + dev_add_pack( &v->pt );
14411 + dev_put( v->ether );
14416 + // Get hardware address of Ethernet card
14417 + // arg: pointer to buffer (6 bytes) to store address
14418 + case SIOCGIFADDR:
14419 + if( copy_to_user((void *)arg, v->fake_addr, 6))
14423 + // Set the fake HW-address the client will see
14424 + case SIOCSIFADDR:
14425 + if( copy_from_user(v->fake_addr, (void*)arg, 6 ))
14429 + // Add multicast address
14430 + // arg: pointer to address (6 bytes)
14431 + case SIOCADDMULTI: {
14436 + if( copy_from_user(addr, (void *)arg, 6))
14438 + ret = dev_mc_add(v->ether, addr, 6, 0);
14442 + // Remove multicast address
14443 + // arg: pointer to address (6 bytes)
14444 + case SIOCDELMULTI: {
14448 + if( copy_from_user(addr, (void *)arg, 6))
14450 + return dev_mc_delete(v->ether, addr, 6, 0);
14454 + // Return size of first packet in queue
14457 + struct sk_buff *skb;
14459 + spin_lock_irqsave(&v->queue.lock, flags );
14461 + skb = skb_peek(&v->queue);
14463 + count = skb->len;
14465 + spin_unlock_irqrestore(&v->queue.lock, flags );
14466 + return put_user(count, (int *)arg);
14469 + case SIOC_MOL_GET_IPFILTER:
14470 + return put_user(v->ipfilter, (int *)arg );
14472 + case SIOC_MOL_SET_IPFILTER:
14473 + v->ipfilter = arg;
14476 + return -ENOIOCTLCMD;
14480 +/************************************************************************/
14481 +/* init / cleanup */
14482 +/************************************************************************/
14484 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
14485 +static struct file_operations sheep_net_fops = {
14486 + .owner = THIS_MODULE,
14487 + .read = do_sync_read,
14488 + .aio_read = sheep_net_aio_read,
14489 + .write = do_sync_write,
14490 + .aio_write = sheep_net_aio_write,
14491 + .poll = sheep_net_poll,
14492 + .ioctl = sheep_net_ioctl,
14493 + .open = sheep_net_open,
14494 + .release = sheep_net_release,
14497 +static struct file_operations sheep_net_fops = {
14498 + .owner = THIS_MODULE,
14499 + .read = sheep_net_read,
14500 + .write = sheep_net_write,
14501 + .readv = sheep_net_readv,
14502 + .writev = sheep_net_writev,
14503 + .poll = sheep_net_poll,
14504 + .ioctl = sheep_net_ioctl,
14505 + .open = sheep_net_open,
14506 + .release = sheep_net_release,
14510 +static struct miscdevice sheep_net_device = {
14511 + .minor = SHEEP_NET_MINOR,
14512 + .name = "sheep_net",
14513 + .fops = &sheep_net_fops
14517 +init_module( void )
14519 + return misc_register( &sheep_net_device );
14523 +cleanup_module( void )
14525 + (void) misc_deregister( &sheep_net_device );
14528 +++ b/drivers/macintosh/mol/skiplist.c
14531 + * Creation Date: <2003/03/03 23:19:47 samuel>
14532 + * Time-stamp: <2004/02/21 16:24:56 samuel>
14536 + * Skiplist implementation
14538 + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
14540 + * This program is free software; you can redistribute it and/or
14541 + * modify it under the terms of the GNU General Public License
14542 + * as published by the Free Software Foundation
14546 +#include "archinclude.h"
14547 +#include "skiplist.h"
14548 +#include "alloc.h"
14550 +#define SKIPLIST_END INT_MAX /* this key is reserved */
14553 + * Skiplist Example:
14555 + * level 0 -> el1 -> el2 -> el3 --> el4 --> null_el
14556 + * level 1 --> el2 -> el3 --> el4 --> null_el
14557 + * level 2 --> el2 --> el4 --> null_el
14558 + * level 3 --> el2 -----> null_el
14559 + * level 4 ------------> null_el
14561 + * SKIPLIST_MAX_HEIGHT-1 ------------> null_el
14564 +static unsigned int mol_rand_seed = 152;
14570 + asm volatile("cntlzw %0,%1" : "=r" (ret) : "r"(val) );
14574 +static unsigned long
14575 +mol_random( void )
14578 + asm( "mftb %0" : "=r"(t) : );
14579 + mol_rand_seed = mol_rand_seed*69069L+1;
14580 + return mol_rand_seed^t;
14584 +mol_random_entropy( void )
14586 + unsigned int entropy;
14587 + asm( "mftb %0" : "=r" (entropy) : );
14588 + mol_rand_seed ^= entropy;
14591 +static inline void
14592 +set_level_next( skiplist_level_t *level, skiplist_el_t *el )
14594 + level->next = el;
14596 + level->next_phys = el ? tophys_mol(el) : 0;
14601 +/************************************************************************/
14602 +/* skiplist operations */
14603 +/************************************************************************/
14606 +skiplist_prealloc( skiplist_t *sl, char *buf, unsigned int size,
14607 + skiplist_el_callback callback, void *usr1, void *usr2 )
14609 + skiplist_el_t *p, *head;
14614 + for( count=0 ;; size -= s, buf += s, count++ ) {
14615 + for( n=0; n<SKIPLIST_MAX_HEIGHT-1 && (mol_random() & 0x40) ; n++ )
14617 + s = sl->datasize + sizeof(skiplist_t) + n*sizeof(skiplist_level_t);
14620 + p = (skiplist_el_t*)(buf + sl->datasize);
14622 + set_level_next( &p->level[0], head );
14626 + /* note: the callback is allowed to manipulate the skiplist */
14627 + for( n=0, p=head; p; p=p->level[0].next, n++ ) {
14629 + (*callback)( (char*)p - sl->datasize, n, count, usr1, usr2 );
14630 + if( !p->level[0].next ) {
14631 + p->level[0] = sl->freelist;
14632 + set_level_next( &sl->freelist, head );
14640 +skiplist_insert( skiplist_t *sl, int key )
14642 + skiplist_el_t *pleft = (skiplist_el_t*)((char*)&sl->root[0] - offsetof(skiplist_el_t, level));
14643 + skiplist_level_t el = sl->freelist;
14644 + skiplist_el_t *p = el.next;
14649 + sl->freelist = p->level[0];
14653 + /* pick a good search level (the -3 is benchmarked) */
14655 + slev = 31 - _cntlz(sl->nel) - 3;
14656 + if( slev > SKIPLIST_MAX_HEIGHT-1 )
14657 + slev = SKIPLIST_MAX_HEIGHT-1;
14658 + else if( slev < 0 )
14660 + sl->slevel = slev;
14662 + /* insert element */
14665 + for( ; slev >= 0; slev-- ) {
14666 + for( ; pleft->level[slev].next->key < key ; pleft=pleft->level[slev].next )
14668 + if( slev <= n ) {
14669 + p->level[slev] = pleft->level[slev];
14670 + pleft->level[slev] = el;
14674 + return (char*)p - sl->datasize;
14678 +skiplist_delete( skiplist_t *sl, int key )
14680 + skiplist_el_t *p = (skiplist_el_t*)((char*)&sl->root[0] - offsetof(skiplist_el_t, level));
14681 + skiplist_level_t delptr;
14682 + int n, level = -1;
14686 + for( n=SKIPLIST_MAX_HEIGHT-1; n>=0; n-- ) {
14687 + for( ; p->level[n].next->key < key ; p=p->level[n].next )
14689 + if( p->level[n].next->key != key )
14692 + if( level < 0 ) {
14693 + delptr = p->level[n];
14696 + p->level[n] = delptr.next->level[n];
14701 + /* put on freelist */
14704 + p->level[0] = sl->freelist;
14705 + sl->freelist = delptr;
14708 + return (char*)p - sl->datasize;
14712 +skiplist_lookup( skiplist_t *sl, int key )
14714 + skiplist_el_t *p = (skiplist_el_t*)((char*)&sl->root[0] - offsetof(skiplist_el_t, level));
14715 + int n = sl->slevel;
14718 + if( p->level[n].next->key < key ) {
14719 + p = p->level[n].next;
14722 + if( p->level[n].next->key > key ) {
14727 + return (char*)p->level[n].next - sl->datasize;
14733 +skiplist_init( skiplist_t *sl, int datasize )
14735 + skiplist_level_t nilptr;
14738 + mol_random_entropy();
14740 + memset( sl, 0, sizeof(*sl) );
14742 + sl->nil_el.key = SKIPLIST_END;
14743 + sl->datasize = datasize;
14745 + /* remember: the nil element is of level 0 */
14746 + set_level_next( &nilptr, &sl->nil_el );
14747 + sl->nil_el.level[0] = nilptr;
14749 + for( i=0; i < SKIPLIST_MAX_HEIGHT ; i++ )
14750 + sl->root[i] = nilptr;