xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/config/m32c/m32c.abi (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
136ac495dSmrg   Target Definitions for R8C/M16C/M32C
2*8feb0f0bSmrg   Copyright (C) 2005-2020 Free Software Foundation, Inc.
336ac495dSmrg   Contributed by Red Hat.
436ac495dSmrg
536ac495dSmrg   This file is part of GCC.
636ac495dSmrg
736ac495dSmrg   GCC is free software; you can redistribute it and/or modify it
836ac495dSmrg   under the terms of the GNU General Public License as published
936ac495dSmrg   by the Free Software Foundation; either version 3, or (at your
1036ac495dSmrg   option) any later version.
1136ac495dSmrg
1236ac495dSmrg   GCC is distributed in the hope that it will be useful, but WITHOUT
1336ac495dSmrg   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1436ac495dSmrg   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
1536ac495dSmrg   License for more details.
1636ac495dSmrg
1736ac495dSmrg   You should have received a copy of the GNU General Public License
1836ac495dSmrg   along with GCC; see the file COPYING3.  If not see
1936ac495dSmrg   <http://www.gnu.org/licenses/>.
2036ac495dSmrg
2136ac495dSmrg
2236ac495dSmrgThese are just some random notes I used during development of this
2336ac495dSmrgport.  Please don't consider these to be "official" specifications,
2436ac495dSmrgjust additional information to help make the code easier to
2536ac495dSmrgunderstand.
2636ac495dSmrg
2736ac495dSmrg
2836ac495dSmrgFrame
2936ac495dSmrg=====
3036ac495dSmrg
3136ac495dSmrg	+--------------------
3236ac495dSmrg	| incoming args
3336ac495dSmrg	+--------------------
3436ac495dSmrg	| return Address
3536ac495dSmrgosp ->	+--------------------
3636ac495dSmrg	| saved fp
3736ac495dSmrgfp ->	+--------------------
3836ac495dSmrg	| local data
3936ac495dSmrg	+--------------------
4036ac495dSmrg	| saved regs
4136ac495dSmrg	+--------------------
4236ac495dSmrg	| outgoing args (opt)
4336ac495dSmrgsp ->	+--------------------
4436ac495dSmrg
4536ac495dSmrgArgument Passing
4636ac495dSmrg================
4736ac495dSmrg
4836ac495dSmrgr8c, m16c
4936ac495dSmrg---------
5036ac495dSmrg
5136ac495dSmrgFirst arg may be passed in r1l or r1 if it (1) fits (QImode or
5236ac495dSmrgHImode), (2) is named, and (3) is an integer or pointer type (no
5336ac495dSmrgstructs, floats, etc).  Otherwise, it's passed on the stack.
5436ac495dSmrg
5536ac495dSmrgSecond arg may be passed in r2, same restrictions (but not QImode),
5636ac495dSmrgeven if the first arg is passed on the stack.
5736ac495dSmrg
5836ac495dSmrgThird and further args are passed on the stack.  No padding is used,
5936ac495dSmrgstack "alignment" is 8 bits.
6036ac495dSmrg
6136ac495dSmrgm32cm, m32c
6236ac495dSmrg-----------
6336ac495dSmrgFirst arg may be passed in r0l or r0, same restrictions as above.
6436ac495dSmrg
6536ac495dSmrgSecond and further args are passed on the stack.  Padding is used
6636ac495dSmrgafter QImode parameters (i.e. lower-addressed byte is the value,
6736ac495dSmrghigher-addressed byte is the padding), stack "alignment" is 16 bits.
6836ac495dSmrg
6936ac495dSmrg
7036ac495dSmrgReturn Value
7136ac495dSmrg============
7236ac495dSmrg
7336ac495dSmrgr8c, m16c
7436ac495dSmrg---------
7536ac495dSmrg
7636ac495dSmrgQImode in r0l
7736ac495dSmrgHImode in r0
7836ac495dSmrgnear pointer in r0
7936ac495dSmrg(desired)
8036ac495dSmrgSImode in r2r0
8136ac495dSmrgfar pointer in r2r0
8236ac495dSmrg(actual)
8336ac495dSmrgAnything bigger than 16 bits is returned in memory, at mem0 (mem0
8436ac495dSmrgthrough mem15 are provided by libgcc.a)
8536ac495dSmrg
8636ac495dSmrgAggregate values (regardless of size) are returned by pushing a
8736ac495dSmrgpointer to a temporary area on the stack after the args are pushed.
8836ac495dSmrgThe function fills in this area with the value.  Note that this
8936ac495dSmrgpointer on the stack does not affect how register arguments, if any,
9036ac495dSmrgare configured.
9136ac495dSmrg
9236ac495dSmrgm32cm, m32c
9336ac495dSmrg-----------
9436ac495dSmrgSame.
9536ac495dSmrg
9636ac495dSmrg
9736ac495dSmrgRegisters Preserved Across Calls
9836ac495dSmrg================================
9936ac495dSmrg
10036ac495dSmrgr8c, m16c
10136ac495dSmrg---------
10236ac495dSmrgsb, fb, sp (i.e. nearly all registers are call clobbered)
10336ac495dSmrg
10436ac495dSmrgm32cm, m32c
10536ac495dSmrg-----------
10636ac495dSmrgr1, r2, r3, a0, a1, sb, fb, sp
10736ac495dSmrg(except when used for return values)
10836ac495dSmrg
10936ac495dSmrg
11036ac495dSmrgInterrupt Handlers
11136ac495dSmrg==================
11236ac495dSmrg
11336ac495dSmrgThe stack frame is slightly different for interrupt handlers, because
11436ac495dSmrg(1) we don't have a usable parent frame, and (2) we have to use
11536ac495dSmrgspecial instructions to return and thus must save/restore everything
11636ac495dSmrgdifferently.
11736ac495dSmrg
11836ac495dSmrg	+--------------------
11936ac495dSmrg	| program state
12036ac495dSmrgosp ->	+--------------------
12136ac495dSmrg	| return address
12236ac495dSmrg	+--------------------
12336ac495dSmrg	| saved r0..fp (pushm)
12436ac495dSmrgfp ->	+--------------------
12536ac495dSmrg	| local data
12636ac495dSmrg	+--------------------
12736ac495dSmrg	| saved regs mem0..mem15
12836ac495dSmrg	+--------------------
12936ac495dSmrg	| outgoing args (opt)
13036ac495dSmrgsp ->	+--------------------
13136ac495dSmrg
132