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
158 ; intSp must be 0 when we jump to _premain
171 .globl _zpu_interrupt_vector
172 _zpu_interrupt_vector:
177 /* instruction emulation code */
184 ; by not masking out bit 0, we cause a memory access error
185 ; on unaligned access
199 ; shift right addr&3 * 8
212 ; by not masking out bit 0, we cause a memory access error
213 ; on unaligned access
252 ; 0x80000000 will overflow when negated, so we need to mask
253 ; the result above with the compare positive to negative
263 ; handle case where we are comparing a negative number
264 ; and positve number. This can underflow. E.g. consider 0x8000000 < 0x1000
309 /* low: -1 if low bit dif is negative 0 otherwise: neg (not x&1 and (y&1))
310 x&1 y&1 neg (not x&1 and (y&1))
326 /* high: upper 31-bit diff is only wrong when diff is 0 and low=-1
327 high=x>>1 - y>>1 + low
332 low= neg(not 0 and 1) = 1111 (-1)
333 high=000+ neg(111) +low = 000 + 1001 + low = 1000
337 low=neg(not 1 and 0) = 0
338 high=111+neg(000) + low = 0111
357 ; if they are equal, then the last bit decides...
360 /* test if negative: result = flip(diff) & 1 */
365 ; destroy a&b which are on stack
445 ; handle signed value
451 not ; now we have an integer on the stack with the signed
452 ; bits in the right position
454 ; mask these bits with the signed bit.
465 ; stuff in the signed bits...
468 ; store result into correct stack slot
471 ; move up return value
485 ; store return address
491 pushsp ; flush internal stack
659 ; mask away destination
717 ; fetch boolean & neg mask
721 ; calc address & mask for branch
725 ; subtract 1 to find PC of branch instruction
772 ; fetch boolean & neg mask
776 ; calc address & mask for branch
780 ; find address of branch instruction
799 ; address of poppcrel
864 storesp 12 ; return address
866 pushsp ; this will flush the internal stack.
917 ; NB! this is not an EMULATE instruction. It is a varargs fn.
934 .byte (.LmoreMult-.Lbranch)&0x7f+0x80