Wednesday, July 28, 2010

TLB Miss handler problem solved

I'll write about the details later, right now just show you current status.
This is the console log of RAMDISK kernel running on OCTEON simulator.
Simulator dies at starting /sbin/init.

U-Boot 1.1.1 (U-boot build #: 235) (SDK version: 1.9.0-312) (Build time: Apr 23 2009 - 19:30:08)


DRAM:  384 MB
Using default environment


Copying user supplied environment from file flash
Configuring boot bus for full 256meg access
Flash: 256 MB


ELF file is 64 bit
Attempting to allocate memory for ELF segment: addr: 0xffffffff81000000 (adjusted to: 0x0000000001000000), size 0x5c0f00
Allocated memory for ELF segment: addr: 0xffffffff81000000, size 0x5c0f00
Processing PHDR 0
  Loading 53c560 bytes at ffffffff81000000
  Clearing 849a0 bytes at ffffffff8153c560
## Loading Linux kernel with entry point: 0xffffffff81000000 ...
Bootloader: Done loading app on coremask: 0x1
cvmctl:b00043f0 cvmmemctl:46104
Boot Descriptor Ver: 7 -> 1/2  CPU clock: 700MHz  Core Mask: 0x1
  Dram: 384 MB  Board Type: 1  Revision: 1/0
  Octeon Chip: 0  Rev 0/0  Mac Address 00.DE.AD.BE.EF.00 (255)
l1icache size:65536 line:128 set:32768
l1dcache size:4096 line:128 set:2048
l2size:524288 l3size:0
Initial setup done, switching console.
Sysmap:0x98000000015cc000
Copyright (c) 1982, 1986, 1989, 1991, 1993
The Regents of the University of California.  All rights reserved.
Copyright (c) 1995-2010 OpenBSD. All rights reserved.  http://www.OpenBSD.org


pmap_init()
pmap_reference(815c03b0)
pmap_enter(0xffffffff815c03b0, 0xc00000000128c000, 0x25bc000, 0x7, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc00000000128c000 pa 0x25bc000
pmap_kenter_pa(0xc000000000000000, 0x5ffc000, 0x3)
pmap_kenter_pa(0xc000000000004000, 0x25b8000, 0x3)
OpenBSD 4.7-current (RAMDISK) #3: Fri Jul 16 04:16:39 MDT 2010
    syuu@noname.my.domain:/home/syuu/octeon/src/sys/arch/octeon/compile/RAMDISK
real mem = 77840384 (74MB)
pmap_reference(815c03b0)
pmap_kenter_pa(0xc000000000008000, 0x5ff8000, 0x3)
pmap_reference(815c03b0)
avail mem = 70860800 (67MB)
pmap_enter(0xffffffff815c03b0, 0xc000000001b8c000, 0x25b4000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b8c000 pa 0x25b4000
pmap_enter(0xffffffff815c03b0, 0xc000000001b88000, 0x5ff4000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b88000 pa 0x5ff4000
pmap_enter(0xffffffff815c03b0, 0xc000000001b84000, 0x25b0000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b84000 pa 0x25b0000
pmap_enter(0xffffffff815c03b0, 0xc000000001b80000, 0x5ff0000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b80000 pa 0x5ff0000
pmap_enter(0xffffffff815c03b0, 0xc000000001b7c000, 0x25ac000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b7c000 pa 0x25ac000
pmap_enter(0xffffffff815c03b0, 0xc000000001b78000, 0x5fec000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b78000 pa 0x5fec000
pmap_enter(0xffffffff815c03b0, 0xc000000001b74000, 0x25a8000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b74000 pa 0x25a8000
pmap_enter(0xffffffff815c03b0, 0xc000000001b70000, 0x5fe8000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b70000 pa 0x5fe8000
pmap_enter(0xffffffff815c03b0, 0xc000000001b6c000, 0x25a4000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b6c000 pa 0x25a4000
pmap_enter(0xffffffff815c03b0, 0xc000000001b68000, 0x5fe4000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b68000 pa 0x5fe4000
pmap_enter(0xffffffff815c03b0, 0xc000000001b64000, 0x25a0000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b64000 pa 0x25a0000
pmap_enter(0xffffffff815c03b0, 0xc000000001b60000, 0x5fe0000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b60000 pa 0x5fe0000
pmap_enter(0xffffffff815c03b0, 0xc000000001b5c000, 0x259c000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b5c000 pa 0x259c000
pmap_enter(0xffffffff815c03b0, 0xc000000001b58000, 0x5fdc000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b58000 pa 0x5fdc000
pmap_enter(0xffffffff815c03b0, 0xc000000001b54000, 0x2598000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b54000 pa 0x2598000
pmap_enter(0xffffffff815c03b0, 0xc000000001b50000, 0x5fd8000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b50000 pa 0x5fd8000
pmap_enter(0xffffffff815c03b0, 0xc000000001b4c000, 0x2594000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b4c000 pa 0x2594000
pmap_enter(0xffffffff815c03b0, 0xc000000001b48000, 0x5fd4000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b48000 pa 0x5fd4000
pmap_enter(0xffffffff815c03b0, 0xc000000001b44000, 0x2590000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b44000 pa 0x2590000
pmap_enter(0xffffffff815c03b0, 0xc000000001b40000, 0x5fd0000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b40000 pa 0x5fd0000
pmap_enter(0xffffffff815c03b0, 0xc000000001b3c000, 0x258c000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b3c000 pa 0x258c000
pmap_enter(0xffffffff815c03b0, 0xc000000001b38000, 0x5fcc000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b38000 pa 0x5fcc000
pmap_enter(0xffffffff815c03b0, 0xc000000001b34000, 0x2588000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b34000 pa 0x2588000
pmap_enter(0xffffffff815c03b0, 0xc000000001b30000, 0x5fc8000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b30000 pa 0x5fc8000
pmap_enter(0xffffffff815c03b0, 0xc000000001b2c000, 0x2584000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b2c000 pa 0x2584000
pmap_enter(0xffffffff815c03b0, 0xc000000001b28000, 0x5fc4000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b28000 pa 0x5fc4000
pmap_enter(0xffffffff815c03b0, 0xc000000001b24000, 0x2580000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b24000 pa 0x2580000
pmap_enter(0xffffffff815c03b0, 0xc000000001b20000, 0x5fc0000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b20000 pa 0x5fc0000
pmap_enter(0xffffffff815c03b0, 0xc000000001b1c000, 0x257c000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b1c000 pa 0x257c000
pmap_enter(0xffffffff815c03b0, 0xc000000001b18000, 0x5fbc000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b18000 pa 0x5fbc000
pmap_enter(0xffffffff815c03b0, 0xc000000001b14000, 0x2578000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b14000 pa 0x2578000
pmap_enter(0xffffffff815c03b0, 0xc000000001b10000, 0x5fb8000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b10000 pa 0x5fb8000
pmap_enter(0xffffffff815c03b0, 0xc000000001b0c000, 0x2574000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b0c000 pa 0x2574000
pmap_kenter_pa(0xc00000000000c000, 0x5fa8000, 0x3)
pmap_kenter_pa(0xc000000000010000, 0x5fac000, 0x3)
pmap_kenter_pa(0xc000000000014000, 0x5fb0000, 0x3)
pmap_kenter_pa(0xc000000000018000, 0x5fb4000, 0x3)
pmap_kenter_pa(0xc00000000001c000, 0x2564000, 0x3)
pmap_kenter_pa(0xc000000000020000, 0x2568000, 0x3)
pmap_kenter_pa(0xc000000000024000, 0x256c000, 0x3)
pmap_kenter_pa(0xc000000000028000, 0x2570000, 0x3)
pmap_kenter_pa(0xc00000000002c000, 0x5f98000, 0x3)
pmap_kenter_pa(0xc000000000030000, 0x5f9c000, 0x3)
pmap_kenter_pa(0xc000000000034000, 0x5fa0000, 0x3)
pmap_kenter_pa(0xc000000000038000, 0x5fa4000, 0x3)
pmap_kenter_pa(0xc00000000003c000, 0x2554000, 0x3)
pmap_kenter_pa(0xc000000000040000, 0x2558000, 0x3)
pmap_kenter_pa(0xc000000000044000, 0x255c000, 0x3)
pmap_kenter_pa(0xc000000000048000, 0x2560000, 0x3)
pmap_kenter_pa(0xc00000000004c000, 0x5f88000, 0x3)
pmap_kenter_pa(0xc000000000050000, 0x5f8c000, 0x3)
pmap_kenter_pa(0xc000000000054000, 0x5f90000, 0x3)
pmap_kenter_pa(0xc000000000058000, 0x5f94000, 0x3)
pmap_kenter_pa(0xc00000000005c000, 0x2544000, 0x3)
pmap_kenter_pa(0xc000000000060000, 0x2548000, 0x3)
pmap_kenter_pa(0xc000000000064000, 0x254c000, 0x3)
pmap_kenter_pa(0xc000000000068000, 0x2550000, 0x3)
pmap_kenter_pa(0xc00000000006c000, 0x5f78000, 0x3)
pmap_kenter_pa(0xc000000000070000, 0x5f7c000, 0x3)
pmap_kenter_pa(0xc000000000074000, 0x5f80000, 0x3)
pmap_kenter_pa(0xc000000000078000, 0x5f84000, 0x3)
pmap_kenter_pa(0xc00000000007c000, 0x2534000, 0x3)
pmap_kenter_pa(0xc000000000080000, 0x2538000, 0x3)
pmap_kenter_pa(0xc000000000084000, 0x253c000, 0x3)
pmap_kenter_pa(0xc000000000088000, 0x2540000, 0x3)
pmap_kenter_pa(0xc00000000008c000, 0x5f74000, 0x3)
pmap_kenter_pa(0xc000000000090000, 0x2530000, 0x3)
pmap_enter(0xffffffff815c03b0, 0xc000000001b08000, 0x5f70000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b08000 pa 0x5f70000
pmap_enter(0xffffffff815c03b0, 0xc000000001b04000, 0x252c000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b04000 pa 0x252c000
pmap_reference(815c03b0)
pmap_kenter_pa(0xc000000000094000, 0x5f6c000, 0x3)
pmap_kenter_pa(0xc000000000098000, 0x2528000, 0x3)
mainbus0 at root: Generic OCTEON
cpu0 at mainbus0: Unknown CPU type (0x6) rev 0.0 499 MHz, Unknown FPU type (0x6) rev 0.0
cpu0: cache L1-I 64KB D 4KB 2 way, L2 512KB direct
cpu0: Setsize 32768:2048
cpu0: Alias mask 0x4000
cpu0: Config Register 8000c48f
cpu0: Cache configuration 202
cpu0: Status Register 508000e4
clock0 at mainbus0: ticker on int5 using count register
pmap_kenter_pa(0xc00000000009c000, 0x5f68000, 0x3)
pmap_kenter_pa(0xc0000000000a0000, 0x2524000, 0x3)
Timecounters tick every 10.000 msec
pmap_kenter_pa(0xc0000000000a4000, 0x5f64000, 0x3)
rd0: fixed, 8192 blocks
pmap_enter(0xffffffff815c03b0, 0xc000000001b00000, 0x2520000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001b00000 pa 0x2520000
pmap_enter(0xffffffff815c03b0, 0xc000000002770000, 0x5f60000, 0x7, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000002770000 pa 0x5f60000
pmap_enter(0xffffffff815c03b0, 0xc000000001afc000, 0x251c000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001afc000 pa 0x251c000
pmap_enter(0xffffffff815c03b0, 0xc000000001af8000, 0x5f5c000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001af8000 pa 0x5f5c000
pmap_enter(0xffffffff815c03b0, 0xc000000001af4000, 0x2518000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001af4000 pa 0x2518000
pmap_enter(0xffffffff815c03b0, 0xc000000001af0000, 0x5f58000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001af0000 pa 0x5f58000
pmap_enter(0xffffffff815c03b0, 0xc000000001aec000, 0x2514000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001aec000 pa 0x2514000
pmap_create()
pmap_enter(0xffffffff815c03b0, 0xc000000001ae8000, 0x5f54000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001ae8000 pa 0x5f54000
pmap_zero_page(0x2510000)
pmap_extract(0xffffffff815c03b0, 0xc000000002770000)=0x5f60000(1)pmap_enter(0xffffffff815c03b0, 0xc000000002774000, 0x5f50000, 0x7, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000002774000 pa 0x5f50000
pmap_extract(0xffffffff815c03b0, 0xc000000002774000)=0x5f50000(1)pmap_enter(0xffffffff815c03b0, 0xc000000002778000, 0x250c000, 0x7, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000002778000 pa 0x250c000
pmap_extract(0xffffffff815c03b0, 0xc000000002778000)=0x250c000(1)pmap_enter(0xffffffff815c03b0, 0xc00000000277c000, 0x5f4c000, 0x7, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc00000000277c000 pa 0x5f4c000
pmap_extract(0xffffffff815c03b0, 0xc00000000277c000)=0x5f4c000(1)root on rd0a swap on rd0b dump on rd0b
pmap_enter(0xffffffff815c03b0, 0xc000000001ae4000, 0x2508000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001ae4000 pa 0x2508000
pmap_kenter_pa(0xc000000002010000, 0x5f48000, 0x3)
dev=0x800 chrdev=0x1600 rawdev=0x1602
pmap_enter(0xffffffff815c03b0, 0xc000000001ae0000, 0x2504000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001ae0000 pa 0x2504000
pmap_kenter_pa(0xc000000002020000, 0x5f44000, 0x3)
pmap_kenter_pa(0xc000000002030000, 0x2500000, 0x3)
pmap_kenter_pa(0xc000000002040000, 0x5f40000, 0x3)
pmap_kenter_pa(0xc000000002050000, 0x24fc000, 0x3)
WARNING: No TOD clock, believing file system.
WARNING: CHECK AND RESET THE DATE!
pmap_enter(0xffffffff815c03b0, 0xc000000001adc000, 0x5f3c000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001adc000 pa 0x5f3c000
pmap_kenter_pa(0xc000000002060000, 0x24f8000, 0x3)
pmap_enter(0xffffffff815c03b0, 0xc000000001ad8000, 0x5f38000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001ad8000 pa 0x5f38000
pmap_kenter_pa(0xc000000002070000, 0x24f4000, 0x3)
pmap_kenter_pa(0xc000000002080000, 0x5f34000, 0x3)
pmap_enter(0xffffffff815c03b0, 0xc000000002780000, 0x24f0000, 0x7, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000002780000 pa 0x24f0000
pmap_extract(0xffffffff815c03b0, 0xc000000002780000)=0x24f0000(1)pmap_enter(0xffffffff815c03b0, 0xc000000002784000, 0x5f30000, 0x7, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000002784000 pa 0x5f30000
pmap_extract(0xffffffff815c03b0, 0xc000000002784000)=0x5f30000(1)pmap_enter(0xffffffff815c03b0, 0xc000000002788000, 0x24ec000, 0x7, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000002788000 pa 0x24ec000
pmap_extract(0xffffffff815c03b0, 0xc000000002788000)=0x24ec000(1)pmap_enter(0xffffffff815c03b0, 0xc00000000278c000, 0x5f2c000, 0x7, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc00000000278c000 pa 0x5f2c000
pmap_extract(0xffffffff815c03b0, 0xc00000000278c000)=0x5f2c000(1)pmap_enter(0xffffffff815c03b0, 0xc000000002790000, 0x24e8000, 0x7, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000002790000 pa 0x24e8000
pmap_extract(0xffffffff815c03b0, 0xc000000002790000)=0x24e8000(1)pmap_alloc_tlbpid: curproc 0 'swapper' segtab 0x9800000002510000 tlbpid 2 pid 1 'swapper'
pmap_enter(0xffffffff815c03b0, 0xc000000001ad4000, 0x5f28000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001ad4000 pa 0x5f28000
pmap_kenter_pa(0xc000000002090000, 0x24e4000, 0x3)
pmap_kenter_pa(0xc0000000020a0000, 0x5f24000, 0x3)
pmap_enter(0xffffffff815c03b0, 0xc000000001ad0000, 0x24e0000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001ad0000 pa 0x24e0000
pmap_kenter_pa(0xc0000000020b0000, 0x5f20000, 0x3)
pmap_kenter_pa(0xc0000000020c0000, 0x24dc000, 0x3)
pmap_kenter_pa(0xc0000000020d0000, 0x5f1c000, 0x3)
pmap_enter(0xffffffff815c03b0, 0xc000000001acc000, 0x24d8000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001acc000 pa 0x24d8000
pmap_enter(0xffffffff815c03b0, 0xc000000001ac8000, 0x5f18000, 0x3, 0x13)
pmap_enter: first pv: pmap 0xffffffff815c03b0 va 0xc000000001ac8000 pa 0x5f18000
init: copying out path `/sbin/init' 11

Monday, July 19, 2010

tlb_flush needs patch, what the reason?

Without following #ifdef CPU_OCTEON, TLBWI throw MCHECK Exception.
According simulator trace log, in 2nd time of TLBWI va is zero.
Probably that means we need rewrite TLB_HI after TLBWI, but dmtc0 v0, COP_0_TLB_HI is not enough, addu v0, v0, 8 * 1024 is required.
Maybe same address on more than 2 entries is not allowed on OCTEON(or MIPS64R2)?
I just borrowed these codes from FreeBSD/mips, not quite sure the meaning...


LEAF(tlb_flush, 0)
mfc0 v1, COP_0_STATUS_REG # Save the status register.
ori v0, v1, SR_INT_ENAB
xori v0, v0, SR_INT_ENAB
mtc0 v0, COP_0_STATUS_REG # Disable interrupts
ITLBNOPFIX
mfc0 ta1, COP_0_TLB_WIRED


LA v0, CKSEG0_BASE # invalid address
dmfc0 ta0, COP_0_TLB_HI # Save the PID

dmtc0 v0, COP_0_TLB_HI # Mark entry high as invalid
dmtc0 zero, COP_0_TLB_LO0 # Zero out low entry0.
dmtc0 zero, COP_0_TLB_LO1 # Zero out low entry1.
mtc0 zero, COP_0_TLB_PG_MASK # Zero out mask entry.
/*
 * Align the starting value (ta1) and the upper bound (a0).
 */
1:
mtc0 ta1, COP_0_TLB_INDEX # Set the index register.
#ifdef CPU_OCTEON
ITLBNOPFIX
dmtc0 v0, COP_0_TLB_HI # Mark entry high as invalid
#endif
addu ta1, ta1, 1 # Increment index.
#ifdef CPU_OCTEON
addu v0, v0, 8 * 1024
#endif
nop
nop
nop
tlbwi # Write the TLB entry.
nop
nop
bne ta1, a0, 1b
nop

#ifdef CPU_LOONGSON2
li v0, COP_0_DIAG_ITLB_CLEAR | COP_0_DIAG_BTB_CLEAR | COP_0_DIAG_RAS_DISABLE
dmtc0 v0, COP_0_DIAG
#endif

dmtc0 ta0, COP_0_TLB_HI # Restore the PID
li a0, TLB_PAGE_MASK
mtc0 a0, COP_0_TLB_PG_MASK # Restore default mask value.
mtc0 v1, COP_0_STATUS_REG # Restore the status register
ITLBNOPFIX
j ra
nop
END(tlb_flush)