1 /* Startup code for ZPU
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
9 In addition to the permissions in the GNU General Public License, the
10 Free Software Foundation gives you unlimited permission to link the
11 compiled version of this file with other programs, and to distribute
12 those programs without any restriction coming from the use of this
13 file. (The General Public License restrictions do apply in other
14 respects; for example, they cover modification of the file, and
15 distribution when not linked into another program.)
17 This file is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; see the file COPYING. If not, write to
24 the Free Software Foundation, 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. */
28 .section ".fixed_vectors","ax"
58 ; destroy arguments on stack
65 ; poke the result into the right slot
97 .globl _zpu_unknown_instruction_vector
98 _zpu_unknown_instruction:
99 /* We have unsupported instruction * 4 on stack */
111 /* instruction emulation code */
118 ; by not masking out bit 0, we cause a memory access error
119 ; on unaligned access
133 ; shift right addr&3 * 8
146 ; by not masking out bit 0, we cause a memory access error
147 ; on unaligned access
186 ; 0x80000000 will overflow when negated, so we need to mask
187 ; the result above with the compare positive to negative
197 ; handle case where we are comparing a negative number
198 ; and positve number. This can underflow. E.g. consider 0x8000000 < 0x1000
243 /* low: -1 if low bit dif is negative 0 otherwise: neg (not x&1 and (y&1))
244 x&1 y&1 neg (not x&1 and (y&1))
260 /* high: upper 31-bit diff is only wrong when diff is 0 and low=-1
261 high=x>>1 - y>>1 + low
266 low= neg(not 0 and 1) = 1111 (-1)
267 high=000+ neg(111) +low = 000 + 1001 + low = 1000
271 low=neg(not 1 and 0) = 0
272 high=111+neg(000) + low = 0111
291 ; if they are equal, then the last bit decides...
294 /* test if negative: result = flip(diff) & 1 */
299 ; destroy a&b which are on stack
379 ; handle signed value
385 not ; now we have an integer on the stack with the signed
386 ; bits in the right position
388 ; mask these bits with the signed bit.
399 ; stuff in the signed bits...
402 ; store result into correct stack slot
405 ; move up return value
419 ; store return address
425 pushsp ; flush internal stack
593 ; mask away destination
651 ; fetch boolean & neg mask
655 ; calc address & mask for branch
659 ; subtract 1 to find PC of branch instruction
706 ; fetch boolean & neg mask
710 ; calc address & mask for branch
714 ; find address of branch instruction
733 ; address of poppcrel
798 storesp 12 ; return address
800 pushsp ; this will flush the internal stack.
851 ; NB! this is not an EMULATE instruction. It is a varargs fn.
868 .byte (.LmoreMult-.Lbranch)&0x7f+0x80
894 ; Pointers to emulated instructions