2 NetWinder Floating Point Emulator
3 (c) Corel Computer Corporation, 1998
4 (c) Philip Blundell 1998-1999
6 Direct questions, comments to Scott Bambrough <scottb@corelcomputer.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* This is the kernel's entry point into the floating point emulator.
24 It is called from the kernel with code similar to this:
26 adrsvc al, r9, ret_from_exception @ r9 = normal FP return
27 adrsvc al, lr, fpundefinstr @ lr = undefined instr return
31 strb r8, [r10, #TSK_USED_MATH] @ set current->used_math
32 add r10, r10, #TSS_FPESAVE @ r10 = workspace
34 ldr pc, [r4] @ Call FP emulator entry point
36 The kernel expects the emulator to return via one of two possible
37 points of return it passes to the emulator. The emulator, if
38 successful in its emulation, jumps to ret_from_exception (passed in
39 r9) and the kernel takes care of returning control from the trap to
40 the user code. If the emulator is unable to emulate the instruction,
41 it returns via _fpundefinstr (passed via lr) and the kernel halts the
42 user program with a core dump.
44 On entry to the emulator r10 points to an area of private FP workspace
45 reserved in the thread structure for this process. This is where the
46 emulator saves its registers across calls. The first word of this area
47 is used as a flag to detect the first time a process uses floating point,
48 so that the emulator startup cost can be avoided for tasks that don't
51 This routine does three things:
53 1) It saves SP into a variable called userRegisters. The kernel has
54 created a struct pt_regs on the stack and saved the user registers
55 into it. See /usr/include/asm/proc/ptrace.h for details. The
56 emulator code uses userRegisters as the base of an array of words from
57 which the contents of the registers can be extracted.
59 2) It calls EmulateAll to emulate a floating point instruction.
60 EmulateAll returns 1 if the emulation was successful, or 0 if not.
62 3) If an instruction has been emulated successfully, it looks ahead at
63 the next instruction. If it is a floating point instruction, it
64 executes the instruction, without returning to user space. In this
65 way it repeatedly looks ahead and executes floating point instructions
66 until it encounters a non floating point instruction, at which time it
67 returns via _fpreturn.
69 This is done to reduce the effect of the trap overhead on each
70 floating point instructions. GCC attempts to group floating point
71 instructions to allow the emulator to spread the cost of the trap over
72 several floating point instructions. */
76 /* ?? Could put userRegisters and fpa11 into fixed regs during
77 emulation. This would reduce load/store overhead at the expense
78 of stealing two regs from the register allocator. Not sure if
80 ldr r4, =userRegisters
81 str sp, [r4] @ save pointer to user regs
83 str r10, [r4] @ store pointer to our state
84 mov r4, sp @ use r4 for local pointer
85 mov r10, lr @ save the failure-return addresses
87 ldr r5, [r4, #60] @ get contents of PC;
88 ldr r0, [r5, #-4] @ get actual instruction into r0
90 bl EmulateAll @ emulate the instruction
91 cmp r0, #0 @ was emulation successful
92 moveq pc, r10 @ no, return failure
95 __x1: ldrt r6, [r5], #4 @ get the next instruction and
98 and r2, r6, #0x0F000000 @ test for FP insns
100 teqne r2, #0x0D000000
101 teqne r2, #0x0E000000
102 movne pc, r9 @ return ok if not a fp insn
104 str r5, [r4, #60] @ update PC copy in regs
106 mov r0, r6 @ save a copy
107 ldr r1, [r4, #64] @ fetch the condition codes
108 bl checkCondition @ check the condition
109 cmp r0, #0 @ r0 = 0 ==> condition failed
111 @ if condition code failed to match, next insn
112 beq next @ get the next instruction;
114 mov r0, r6 @ prepare for EmulateAll()
115 b emulate @ if r0 != 0, goto EmulateAll
117 @ We need to be prepared for the instruction at __x1 to fault.
118 @ Emit the appropriate exception gunk to fix things up.
123 .section __ex_table,"a"