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. */
31 ; .section ".fixed_vectors","ax"
32 ; KLUDGE!!! we remove the executable bit to avoid relaxation
33 .section ".fixed_vectors","a"
36 ; we need to align these code sections to 32 bytes, which
37 ; means we must not use any assembler instructions that are relaxed
97 ; destroy arguments on stack
104 ; poke the result into the right slot
125 ; create mask of lowest bit in A
134 add ; accumulate in C
141 ; shift A right 1 bit
156 ; intSp must be 0 when we jump to _premain
169 .globl _zpu_interrupt_vector
170 _zpu_interrupt_vector:
175 /* instruction emulation code */
182 ; by not masking out bit 0, we cause a memory access error
183 ; on unaligned access
197 ; shift right addr&3 * 8
210 ; by not masking out bit 0, we cause a memory access error
211 ; on unaligned access
250 ; 0x80000000 will overflow when negated, so we need to mask
251 ; the result above with the compare positive to negative
261 ; handle case where we are comparing a negative number
262 ; and positve number. This can underflow. E.g. consider 0x8000000 < 0x1000
307 /* low: -1 if low bit dif is negative 0 otherwise: neg (not x&1 and (y&1))
308 x&1 y&1 neg (not x&1 and (y&1))
324 /* high: upper 31-bit diff is only wrong when diff is 0 and low=-1
325 high=x>>1 - y>>1 + low
330 low= neg(not 0 and 1) = 1111 (-1)
331 high=000+ neg(111) +low = 000 + 1001 + low = 1000
335 low=neg(not 1 and 0) = 0
336 high=111+neg(000) + low = 0111
355 ; if they are equal, then the last bit decides...
358 /* test if negative: result = flip(diff) & 1 */
363 ; destroy a&b which are on stack
443 ; handle signed value
449 not ; now we have an integer on the stack with the signed
450 ; bits in the right position
452 ; mask these bits with the signed bit.
463 ; stuff in the signed bits...
466 ; store result into correct stack slot
469 ; move up return value
483 ; store return address
489 pushsp ; flush internal stack
657 ; mask away destination
715 ; fetch boolean & neg mask
719 ; calc address & mask for branch
723 ; subtract 1 to find PC of branch instruction
770 ; fetch boolean & neg mask
774 ; calc address & mask for branch
778 ; find address of branch instruction
797 ; address of poppcrel
862 storesp 12 ; return address
864 pushsp ; this will flush the internal stack.
915 ; NB! this is not an EMULATE instruction. It is a varargs fn.
932 .byte (.LmoreMult-.Lbranch)&0x7f+0x80