OpenBSD/sgi on octane2 - curprocpaddrをcurcpu()->ci_curprocpaddrへ移動

curprocpaddrというグローバル変数がある。
これはarch/sgi/sgi/machdep.cでこんな風に初期化され、

        /*
         * Allocate U page(s) for proc[0], pm_tlbpid 1.
         */
        proc0.p_addr = proc0paddr = curprocpaddr =
            (struct user *)pmap_steal_memory(USPACE, NULL, NULL);

以後こんなに沢山アセンブリから直にアクセスされている:

context.S.~1.20.~:      PTR_L   t3, curprocpaddr
context.S.~1.20.~:      PTR_S   t3, curprocpaddr
exception.S.~1.16.~:    PTR_L   k0, curprocpaddr
exception.S.~1.16.~:    PTR_L   t0, curprocpaddr
exception.S.~1.16.~:    PTR_L   t0, curprocpaddr
exception.S.~1.16.~:    PTR_L   k0, curprocpaddr
exception.S.~1.16.~:    PTR_L   k0, curprocpaddr
exception.S.~1.16.~:    PTR_L   t0, curprocpaddr
exception.S.~1.16.~:    PTR_L   t0, curprocpaddr
exception.S.~1.16.~:    PTR_L   k0, curprocpaddr
exception.S.~1.16.~:    PTR_L   k0, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_access.S.~1.16.~: PTR_L   t3, curprocpaddr
lcore_float.S.~1.15.~:  PTR_L   a0, curprocpaddr        # first arg is ptr to CPU regs
lcore_float.S.~1.15.~:  PTR_L   a3, curprocpaddr        # first arg is ptr to CPU regs
tlbhandler.S.~1.16.~:   PTR_L   k1, curprocpaddr
tlbhandler.S.~1.16.~:   PTR_L   k1, curprocpaddr
tlbhandler.S.~1.16.~:   PTR_L   k1, curprocpaddr

OpenBSD/sgiにはこういうシングルCPU前提なグローバル変数が沢山ある。
当然、現在実行中のプロセスがCPU分あるSMPなカーネルでこういうのを放置しておくと動かない。

で、取り合えず頑張って書き換えた。エラい、俺。

Index: context.S
===================================================================
RCS file: /cvs/src/sys/arch/mips64/mips64/context.S,v
retrieving revision 1.20
diff -r1.20 context.S
40,41d39
< #define curproc       (cpu_info_primary + CI_CURPROC)
<
106c104,105
<       PTR_L   t3, curprocpaddr
---
>       GET_CPU_INFO(t1, t3)
>       PTR_L   t3, CI_CURPROCPADDR(t1)
149,150c148,150
<       PTR_S   s0, curproc                     # set curproc
<       PTR_S   t3, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_S   s0, CI_CURPROC(t1)              # set curproc
>       PTR_S   t3, CI_CURPROCPADDR(t1)
Index: exception.S
===================================================================
RCS file: /cvs/src/sys/arch/mips64/mips64/exception.S,v
retrieving revision 1.16
diff -r1.16 exception.S
227c227,228
<       PTR_L   k0, curprocpaddr
---
>       GET_CPU_INFO(k1, k0)
>       PTR_L   k0, CI_CURPROCPADDR(k1)
251c252
<       PTR_L   t0, curprocpaddr
---
>       PTR_L   t0, CI_CURPROCPADDR(k1)
259c260
<       PTR_L   t0, curproc
---
>       PTR_L   t0, CI_CURPROC(k1)
284c285
<       PTR_L   t1, curproc             # set up rm7k.
---
>       PTR_L   t1, CI_CURPROC(k1)      # set up rm7k.
300c301
<       PTR_L   t0, curprocpaddr
---
>       PTR_L   t0, CI_CURPROCPADDR(k1)
317c318
<       PTR_L   k0, curprocpaddr
---
>       PTR_L   k0, CI_CURPROCPADDR(k1)
387c388,389
<       PTR_L   k0, curprocpaddr
---
>       GET_CPU_INFO(k1, k0)
>       PTR_L   k0, CI_CURPROCPADDR(k1)
406c408
<       PTR_L   t0, curproc
---
>       PTR_L   t0, CI_CURPROC(k1)
428c430
<       PTR_L   t0, curprocpaddr
---
>       PTR_L   t0, CI_CURPROCPADDR(k1)
434c436
<       PTR_L   t0, curprocpaddr
---
>       PTR_L   t0, CI_CURPROCPADDR(k1)
442c444
<       LOAD    t0, curproc             # set up rm7k.
---
>       LOAD    t0, CI_CURPROC(k1)      # set up rm7k.
468c470
<       PTR_L   k0, curprocpaddr
---
>       PTR_L   k0, CI_CURPROCPADDR(k1)
603a606,609
> #ifdef MULTIPROCESSOR
>       jal     _C_LABEL(proc_trampoline_mp)
>       nop
> #endif
666c672,673
<       PTR_L   k0, curprocpaddr
---
>       GET_CPU_INFO(k1, k0)
>       PTR_L   k0, CI_CURPROCPADDR(k1)
Index: lcore_access.S
===================================================================
RCS file: /cvs/src/sys/arch/mips64/mips64/lcore_access.S,v
retrieving revision 1.16
diff -r1.16 lcore_access.S
190a191
>       GET_CPU_INFO(t1, t0)
194c195
<       PTR_L   t3, curprocpaddr
---
>       PTR_L   t3, CI_CURPROCPADDR(t1)
199c200
<       PTR_L   t3, curprocpaddr
---
>       PTR_L   t3, CI_CURPROCPADDR(t1)
218a220
>       GET_CPU_INFO(t1, t0)
222c224
<       PTR_L   t3, curprocpaddr
---
>       PTR_L   t3, CI_CURPROCPADDR(t1)
227c229
<       PTR_L   t3, curprocpaddr
---
>       PTR_L   t3, CI_CURPROCPADDR(t1)
243a246
>       GET_CPU_INFO(t1, t0)
247c250
<       PTR_L   t3, curprocpaddr
---
>       PTR_L   t3, CI_CURPROCPADDR(t1)
252c255,256
<       PTR_L   t3, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t3, CI_CURPROCPADDR(t1)
268a273
>       GET_CPU_INFO(t1, t0)
272c277
<       PTR_L   t3, curprocpaddr
---
>       PTR_L   t3, CI_CURPROCPADDR(t1)
277c282,283
<       PTR_L   t3, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t3, CI_CURPROCPADDR(t1)
286c292
<       PTR_L   t3, curprocpaddr
---
>       PTR_L   t3, CI_CURPROCPADDR(t1)
297a304
>       GET_CPU_INFO(t1, t0)
299c306
<       PTR_L   t3, curprocpaddr
---
>       PTR_L   t3, CI_CURPROCPADDR(t1)
307c314,315
<       PTR_L   t3, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t3, CI_CURPROCPADDR(t1)
317c325
<       PTR_L   t3, curprocpaddr
---
>       PTR_L   t3, CI_CURPROCPADDR(t1)
331c339,340
<       PTR_L   t3, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t3, CI_CURPROCPADDR(t1)
345c354,355
<       PTR_L   t3, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t3, CI_CURPROCPADDR(t1)
Index: lcore_ddb.S
===================================================================
RCS file: /cvs/src/sys/arch/mips64/mips64/lcore_ddb.S,v
retrieving revision 1.8
diff -r1.8 lcore_ddb.S
45c45,46
<       PTR_L   t0, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t0, CI_CURPROCPADDR(t1)
64c65,66
<       PTR_L   t0, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t0, CI_CURPROCPADDR(t1)
82c84,85
<       PTR_L   t0, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t0, CI_CURPROCPADDR(t1)
99c102,103
<       PTR_L   t0, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t0, CI_CURPROCPADDR(t1)
114c118,119
<       PTR_L   t0, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t0, CI_CURPROCPADDR(t1)
134c139,140
<       PTR_L   t0, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t0, CI_CURPROCPADDR(t1)
152c158,159
<       PTR_L   t0, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t0, CI_CURPROCPADDR(t1)
168c175,176
<       PTR_L   t0, curprocpaddr
---
>       GET_CPU_INFO(t1, t0)
>       PTR_L   t0, CI_CURPROCPADDR(t1)
Index: lcore_float.S
===================================================================
RCS file: /cvs/src/sys/arch/mips64/mips64/lcore_float.S,v
retrieving revision 1.15
diff -r1.15 lcore_float.S
455c455,456
<       PTR_L   a0, curprocpaddr        # first arg is ptr to CPU regs
---
>       GET_CPU_INFO(t2, t3)
>       PTR_L   a0, CI_CURPROCPADDR(t2) # first arg is ptr to CPU regs
475c476,477
<       PTR_L   a3, curprocpaddr        # first arg is ptr to CPU regs
---
>       GET_CPU_INFO(t2, t3)
>       PTR_L   a3, CI_CURPROCPADDR(t2) # first arg is ptr to CPU regs
489c491,492
<       PTR_L   a0, curproc             # get current process
---
>       GET_CPU_INFO(t2, t3)
>       PTR_L   a0, CI_CURPROC(t2)      # get current process
Index: tlbhandler.S
===================================================================
RCS file: /cvs/src/sys/arch/mips64/mips64/tlbhandler.S,v
retrieving revision 1.16
diff -r1.16 tlbhandler.S
61a62,73
>       j       tlb_miss_handler
>       nop
>       .end    tlb_miss
>
>       .globl  e_tlb_miss
> e_tlb_miss:
>       .set    at
>
>       .globl  tlb_miss_handler
>       .set    noat
>       .ent    tlb_miss_handler, 0
> tlb_miss_handler:
85c97,98
<       PTR_L   k1, curprocpaddr
---
>       GET_CPU_INFO(k1, k0)
>       PTR_L   k1, CI_CURPROCPADDR(k1)
117,120c130,131
<       .end    tlb_miss
<
<       .globl  e_tlb_miss
< e_tlb_miss:
---
>       .end    tlb_miss_handler
>       .set    at
128a140,153
>       j       xtlb_miss_handler
>       nop
>       .end    xtlb_miss
>
>       .globl  e_xtlb_miss
> e_xtlb_miss:
>       .set    at
>
>       .globl  xtlb_miss_handler
>       .set    noat
>       .ent    xtlb_miss_handler, 0
> xtlb_miss_handler:
> /*****************************  End of code copied to exception vector */
>
143a169,173
>       nop
>       GET_CPU_INFO(k1, k0)
>       PTR_L   k1, CI_CURPROCPADDR(k1)
>       dmfc0   k0, COP_0_BAD_VADDR
>       PTR_SRL k0, k0, SEGSHIFT
145d174
<       PTR_L   k1, curprocpaddr
164,167c193
<       .end    xtlb_miss
<
<       .globl  e_xtlb_miss
< e_xtlb_miss:
---
>       .end    xtlb_miss_handler
169d194
< /*****************************  End of code copied to exception vector */
329c354,355
<       PTR_L   k1, curprocpaddr
---
>       GET_CPU_INFO(k1, k0)
>       PTR_L   k1, CI_CURPROCPADDR(k1)

動かしてみた。

Option? 5
Command Monitor.  Type "exit" to return to the menu.
>> bootp()192.168.3.1:bsd
Setting $netaddr to 192.168.3.2 (from server )
Obtaining bsd from server
5897904+492872 entry: 0xa800000020020000
ARCS64 Firmware Version 64.0
Found SGI-IP30, setting up.
Initial setup done, switching console.
cpu_id:0
Copyright (c) 1982, 1986, 1989, 1991, 1993
        The Regents of the University of California.  All rights reserved.
Copyright (c) 1995-2009 OpenBSD. All rights reserved.  http://www.OpenBSD.org

OpenBSD 4.5-current (OCTANE_RAMDISK_MP) #25: Tue May 12 23:09:58 JST 2009

real mem = 1073741824 (1024MB)
rsvd mem = 1064960 (1MB)
avail mem = 1013772288 (966MB)
mainbus0 at root
test1:0xa80000002060b5d0
test3:0
cpu_number():0
curcpu():0xa800000020633350
test2:0xa80000002060b5d0
cpu0 at mainbus0: MIPS R12000 CPU rev 3.5 400 MHz with R10000 FPU rev 0.0
cpu0: cache L1-I 32KB D 32KB 2 way, L2 2048KB 2 way
clock0 at mainbus0: ticker on int5 using count register
xbow0 at mainbus0: XBow revision 5
xheart0 at xbow0 widget 8: Heart revision 6
onewire0 at xheart0
owserial0 at onewire0 family 0x0b sn 0000004d74fa
owserial0: "PM20400MHZ" p/n 030-1476-001, serial KWL381
"Odyssey" revision 2 at xbow0 widget 11 not configured
xbridge0 at xbow0 widget 15: Bridge revision 4
pci0 at xbridge0 bus 0
isp0 at pci0 dev 0 function 0 "QLogic ISP1020" rev 0x05: irq 0
isp0: invalid NVRAM header
scsibus0 at isp0: 16 targets, initiator 0
sd0 at scsibus0 targ 1 lun 0: <QUANTUM, ATLAS_V__9_SCA, 0238> SCSI3 0/direct fixed
sd0: 8682MB, 512 bytes/sec, 17781964 sec total
isp1 at pci0 dev 1 function 0 "QLogic ISP1020" rev 0x05: irq 1
isp1: invalid NVRAM header
scsibus1 at isp1: 16 targets, initiator 0
ioc0 at pci0 dev 2 function 0 "SGI IOC3" rev 0x01
onewire1 at ioc0
owmac0 at onewire1 family 0x09 sn 000002d29696
owmac0: Ethernet Address 08:00:69:13:67:82
owserial1 at onewire1 family 0x0b sn 0000004d4ee4
owserial1: "FP1" p/n 030-0891-003, serial LMR447
owserial2 at onewire1 family 0x0b sn 0000004e12fb
owserial2: "PWR.SPPLY.ER" p/n 060-0035-002, serial AAE0420107
ioc0: superio irq 4, ethernet irq 2
com0 at ioc0 base 0x00020178: ns16550a, 16 byte fifo
com0: console
com1 at ioc0 base 0x00020170: ns16550a, 16 byte fifo
iockbc at ioc0 not configured
ef at ioc0 base 0x000000f0 not configured
dsrtc at ioc0 not configured
"SGI Rad1" rev 0xc0 at pci0 dev 3 function 0 not configured
rd0: fixed, 8192 blocks
boot device: sd0
root on rd0a swap on rd0b dump on rd0b
WARNING: No TOD clock, believing file system.
WARNING: CHECK AND RESET THE DATE!

Trap cause = 4 Frame 0xffffffffcffa3e78
Trap PC 0xa8000000200edfa0 RA 0xa80000002016246c fault 0x8e8d2f
0xa8000000200edfa0 ra 0x0 sp 0xffffffffcffa3fd0 (0xffffffffc9107008,0x8,0x0,0x0)
User-level: pid 1
stopped on non ddb fault
Stopped at      0xa8000000200edfa0:     lw      a1,24(v0)
ddb{0}>

落ちた。
0xa8000000200edfa0はobjdumpによるとufs_strategyの中らしい。
・・・どこが悪かったのかさっぱりだ。
traceも当てにならない:

ddb{0}> trace
0xa8000000200edf40 (ffffffffc9107008,8,0,0) sp ffffffffcffa3fd0 ra 0, sz 48
User-level: pid 1

また一ヶ所づつ当たっていくしかないか。
しかし、書き換えた量が多いから厄介だ。
ガンバレ、俺。負けんな、俺。