1 Target Definitions for R8C/M16C/M32C 2 Copyright (C) 2005-2022 Free Software Foundation, Inc. 3 Contributed by Red Hat. 4 5 This file is part of GCC. 6 7 GCC is free software; you can redistribute it and/or modify it 8 under the terms of the GNU General Public License as published 9 by the Free Software Foundation; either version 3, or (at your 10 option) any later version. 11 12 GCC is distributed in the hope that it will be useful, but WITHOUT 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 15 License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with GCC; see the file COPYING3. If not see 19 <http://www.gnu.org/licenses/>. 20 21 22 These are just some random notes I used during development of this 23 port. Please don't consider these to be "official" specifications, 24 just additional information to help make the code easier to 25 understand. 26 27 28 Frame 29 ===== 30 31 +-------------------- 32 | incoming args 33 +-------------------- 34 | return Address 35 osp -> +-------------------- 36 | saved fp 37 fp -> +-------------------- 38 | local data 39 +-------------------- 40 | saved regs 41 +-------------------- 42 | outgoing args (opt) 43 sp -> +-------------------- 44 45 Argument Passing 46 ================ 47 48 r8c, m16c 49 --------- 50 51 First arg may be passed in r1l or r1 if it (1) fits (QImode or 52 HImode), (2) is named, and (3) is an integer or pointer type (no 53 structs, floats, etc). Otherwise, it's passed on the stack. 54 55 Second arg may be passed in r2, same restrictions (but not QImode), 56 even if the first arg is passed on the stack. 57 58 Third and further args are passed on the stack. No padding is used, 59 stack "alignment" is 8 bits. 60 61 m32cm, m32c 62 ----------- 63 First arg may be passed in r0l or r0, same restrictions as above. 64 65 Second and further args are passed on the stack. Padding is used 66 after QImode parameters (i.e. lower-addressed byte is the value, 67 higher-addressed byte is the padding), stack "alignment" is 16 bits. 68 69 70 Return Value 71 ============ 72 73 r8c, m16c 74 --------- 75 76 QImode in r0l 77 HImode in r0 78 near pointer in r0 79 (desired) 80 SImode in r2r0 81 far pointer in r2r0 82 (actual) 83 Anything bigger than 16 bits is returned in memory, at mem0 (mem0 84 through mem15 are provided by libgcc.a) 85 86 Aggregate values (regardless of size) are returned by pushing a 87 pointer to a temporary area on the stack after the args are pushed. 88 The function fills in this area with the value. Note that this 89 pointer on the stack does not affect how register arguments, if any, 90 are configured. 91 92 m32cm, m32c 93 ----------- 94 Same. 95 96 97 Registers Preserved Across Calls 98 ================================ 99 100 r8c, m16c 101 --------- 102 sb, fb, sp (i.e. nearly all registers are call clobbered) 103 104 m32cm, m32c 105 ----------- 106 r1, r2, r3, a0, a1, sb, fb, sp 107 (except when used for return values) 108 109 110 Interrupt Handlers 111 ================== 112 113 The stack frame is slightly different for interrupt handlers, because 114 (1) we don't have a usable parent frame, and (2) we have to use 115 special instructions to return and thus must save/restore everything 116 differently. 117 118 +-------------------- 119 | program state 120 osp -> +-------------------- 121 | return address 122 +-------------------- 123 | saved r0..fp (pushm) 124 fp -> +-------------------- 125 | local data 126 +-------------------- 127 | saved regs mem0..mem15 128 +-------------------- 129 | outgoing args (opt) 130 sp -> +-------------------- 131 132