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