[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
VAX unimplemented instruction address generation broken
- To: bugs_(_at_)_openbsd_(_dot_)_org
- Subject: VAX unimplemented instruction address generation broken
- From: Jim Uhl <juhl_(_at_)_cscires_(_dot_)_mala_(_dot_)_bc_(_dot_)_ca>
- Date: Sun, 15 Jul 2001 17:34:44 -0700 (PDT)
- Cc: juhl_(_at_)_cscires_(_dot_)_mala_(_dot_)_bc_(_dot_)_ca
>Submitter-Id: net
>Originator: Jim Uhl
>Organization: Malaspina University-College, Nanaimo, BC, Canada
net
>Confidential: no
>Synopsis: broken addressing emulation for unimplemented instructions
>Severity: serious
>Priority: medium
>Category: vax
>Class: sw-bug
>Release: OPENBSD_2_9
>Environment:
System : OpenBSD 2.9
Architecture: OpenBSD.vax
Machine : vax
>Description:
The emulation code in sys/arch/vax/vax/arch/unimpl_emul.s
doesn't handle some instances of pc-relative addressing
emulation properly. Specifically, the routine getaddr_byte
appears to implement byte pc-relative addressing incorrectly
(trashes r4 and r5, doesn't account for possibility of
displacement mode using the PC [i.e., pc-relative
addressing]). Word displacement addressing isn't implemented
at all.
An important implication of this is that the inverse trig
functions in the math library, on machines that don't
implement the polyd instruction, do not work - generating
everything from garbage results to core dumps. This is
because the polynomial table in the math library is in the
text segment along with the atan2 routine, and byte
pc-relative addressing is generated for the polyd
instruction in this instance.
>How-To-Repeat:
The following program demonstrates the problem using the polyd
instruction - compile and run with:
cc -o polyd polyd.s
./polyd
The correct output is:
17.000000
---------------------------- polyd.s --------------------------------
#NO_APP
gcc2_compiled.:
___gnu_compiled_c:
.text
.align 2
_ptab:
.dfloat 0d3.00000000000000000000e+00
.dfloat 0d2.00000000000000000000e+00
.dfloat 0d1.00000000000000000000e+00
LC0:
.ascii "%f\12\0"
.globl _main
.type _main , @function
_main:
.word 0x3c0
calls $0,___main
movd $0d2.00000000000000000000e+00,r6
polyd r6,$2,_ptab
movd r0,-(sp)
pushab LC0
calls $3,_printf
clrl r0
ret
.size _main , . - _main
----------------------------------------------------------------------
>Fix:
The following patch to the OpenBSD 2.9 kernel (as found on the
2.9 CDROM), while not especially pretty, fixes byte
pc-relative and implements word displacement effective address
computation for instruction emulation (well, it seems to be
working for me, at least).
----------------------------------------------------------------------
*** sys/arch/vax/vax/unimpl_emul.s Tue Apr 17 11:34:58 2001
--- /home/juhl/unimpl_emul.s Sun Jul 15 16:20:15 2001
***************
*** 352,358 ****
.word 2f-0b # 9 autoincr deferred (missing)
.word 7f-0b # 10 byte disp
.word 2f-0b # 11 byte disp deferred (missing)
! .word 2f-0b # 12 word disp (missing)
.word 2f-0b # 13 word disp deferred (missing)
.word 1f-0b # 14 long disp
.word 2f-0b # 15 long disp deferred (missing)
--- 352,358 ----
.word 2f-0b # 9 autoincr deferred (missing)
.word 7f-0b # 10 byte disp
.word 2f-0b # 11 byte disp deferred (missing)
! .word 8f-0b # 12 word disp (IN TESTING)
.word 2f-0b # 13 word disp deferred (missing)
.word 1f-0b # 14 long disp
.word 2f-0b # 15 long disp deferred (missing)
***************
*** 381,397 ****
brw 4f
7:
! extzv $0, $4, (r3), r2 # get register
incl r3
! movl r3, S_PC
! ashl $2,r2,r2
! addl2 fp,r2
! movl (r2),r5
! movzbl (r3),r4
! movl S_PC, r3
incl r3
! addl3 r4, r5, r0
! brw 4f
6: extzv $0,$4,(r3),r2 # Get reg number
incl r3
--- 381,412 ----
brw 4f
7:
! extzv $0, $4, (r3), r2 # get register
incl r3
! movl (fp)[r2],r0 # Register contents
! pushl r4
! cvtbl (r3),r4
! addl2 r4,r0 # add displacement
! movl (sp)+,r4
! cmpl r2,$15 # pc?
! bneq 0f # no, skip
! addl2 $2,r0 # compensate for displacement size
! 0: incl r3 # increase pc
! brw 4f
!
! 8:
! extzv $0, $4, (r3), r2 # get register
incl r3
! movl (fp)[r2],r0 # Register contents
! pushl r4
! cvtwl (r3),r4
! addl2 r4,r0 # add displacement
! movl (sp)+,r4
! cmpl r2,$15 # pc?
! bneq 0f # no, skip
! addl2 $3,r0 # compensate for displacement size
! 0: addl2 $2,r3 # increase pc
! brw 4f
6: extzv $0,$4,(r3),r2 # Get reg number
incl r3
Visit your host, monkey.org