├── .github └── bors.toml ├── .gitignore ├── .travis.yml ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-CC-BY-SA ├── LICENSE-MIT ├── README.md ├── ci ├── install.sh └── script.sh ├── dummy ├── .cargo │ └── config ├── .gitignore ├── Cargo.toml └── src │ └── main.rs ├── macros ├── Cargo.toml └── src │ └── lib.rs ├── src ├── cfail.rs ├── export.rs └── lib.rs └── tools ├── .gitignore ├── Cargo.toml └── src └── bin ├── cargo-microamp.rs └── microamp-true.rs /.github/bors.toml: -------------------------------------------------------------------------------- 1 | delete_merged_branches = true 2 | status = [ 3 | "continuous-integration/travis-ci/push", 4 | ] -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.rs.bk 2 | .#* 3 | /target 4 | Cargo.lock 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | rust: nightly 3 | 4 | matrix: 5 | include: 6 | - env: TARGET=x86_64-unknown-linux-gnu 7 | 8 | - env: TARGET=thumbv7m-none-eabi 9 | 10 | before_install: set -e 11 | 12 | install: 13 | - bash ci/install.sh 14 | 15 | script: 16 | - bash ci/script.sh 17 | 18 | after_script: set +e 19 | 20 | cache: cargo 21 | 22 | before_cache: 23 | - chmod -R a+r $HOME/.cargo; 24 | 25 | branches: 26 | only: 27 | - staging 28 | - trying 29 | 30 | notifications: 31 | email: 32 | on_success: never 33 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = [ 3 | "The Real Time For the Masses developers", 4 | "Jorge Aparicio ", 5 | ] 6 | categories = ["concurrency", "embedded", "no-std"] 7 | description = "Asymmetric Multi-Processing on microcontrollers" 8 | documentation = "https://docs.rs/microamp" 9 | edition = "2018" 10 | keywords = ["AMP", "asymmetric"] 11 | license = "MIT OR Apache-2.0" 12 | name = "microamp" 13 | readme = "README.md" 14 | repository = "https://github.com/rtfm-rs/microamp" 15 | version = "0.1.0-alpha.7" 16 | 17 | [dependencies] 18 | microamp-macros = { version = "0.1.0-alpha.4", path = "macros" } 19 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-CC-BY-SA: -------------------------------------------------------------------------------- 1 | Attribution-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-ShareAlike 4.0 International Public 58 | License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-ShareAlike 4.0 International Public License ("Public 63 | License"). To the extent this Public License may be interpreted as a 64 | contract, You are granted the Licensed Rights in consideration of Your 65 | acceptance of these terms and conditions, and the Licensor grants You 66 | such rights in consideration of benefits the Licensor receives from 67 | making the Licensed Material available under these terms and 68 | conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. Share means to provide material to the public by any means or 126 | process that requires permission under the Licensed Rights, such 127 | as reproduction, public display, public performance, distribution, 128 | dissemination, communication, or importation, and to make material 129 | available to the public including in ways that members of the 130 | public may access the material from a place and at a time 131 | individually chosen by them. 132 | 133 | l. Sui Generis Database Rights means rights other than copyright 134 | resulting from Directive 96/9/EC of the European Parliament and of 135 | the Council of 11 March 1996 on the legal protection of databases, 136 | as amended and/or succeeded, as well as other essentially 137 | equivalent rights anywhere in the world. 138 | 139 | m. You means the individual or entity exercising the Licensed Rights 140 | under this Public License. Your has a corresponding meaning. 141 | 142 | 143 | Section 2 -- Scope. 144 | 145 | a. License grant. 146 | 147 | 1. Subject to the terms and conditions of this Public License, 148 | the Licensor hereby grants You a worldwide, royalty-free, 149 | non-sublicensable, non-exclusive, irrevocable license to 150 | exercise the Licensed Rights in the Licensed Material to: 151 | 152 | a. reproduce and Share the Licensed Material, in whole or 153 | in part; and 154 | 155 | b. produce, reproduce, and Share Adapted Material. 156 | 157 | 2. Exceptions and Limitations. For the avoidance of doubt, where 158 | Exceptions and Limitations apply to Your use, this Public 159 | License does not apply, and You do not need to comply with 160 | its terms and conditions. 161 | 162 | 3. Term. The term of this Public License is specified in Section 163 | 6(a). 164 | 165 | 4. Media and formats; technical modifications allowed. The 166 | Licensor authorizes You to exercise the Licensed Rights in 167 | all media and formats whether now known or hereafter created, 168 | and to make technical modifications necessary to do so. The 169 | Licensor waives and/or agrees not to assert any right or 170 | authority to forbid You from making technical modifications 171 | necessary to exercise the Licensed Rights, including 172 | technical modifications necessary to circumvent Effective 173 | Technological Measures. For purposes of this Public License, 174 | simply making modifications authorized by this Section 2(a) 175 | (4) never produces Adapted Material. 176 | 177 | 5. Downstream recipients. 178 | 179 | a. Offer from the Licensor -- Licensed Material. Every 180 | recipient of the Licensed Material automatically 181 | receives an offer from the Licensor to exercise the 182 | Licensed Rights under the terms and conditions of this 183 | Public License. 184 | 185 | b. Additional offer from the Licensor -- Adapted Material. 186 | Every recipient of Adapted Material from You 187 | automatically receives an offer from the Licensor to 188 | exercise the Licensed Rights in the Adapted Material 189 | under the conditions of the Adapter's License You apply. 190 | 191 | c. No downstream restrictions. You may not offer or impose 192 | any additional or different terms or conditions on, or 193 | apply any Effective Technological Measures to, the 194 | Licensed Material if doing so restricts exercise of the 195 | Licensed Rights by any recipient of the Licensed 196 | Material. 197 | 198 | 6. No endorsement. Nothing in this Public License constitutes or 199 | may be construed as permission to assert or imply that You 200 | are, or that Your use of the Licensed Material is, connected 201 | with, or sponsored, endorsed, or granted official status by, 202 | the Licensor or others designated to receive attribution as 203 | provided in Section 3(a)(1)(A)(i). 204 | 205 | b. Other rights. 206 | 207 | 1. Moral rights, such as the right of integrity, are not 208 | licensed under this Public License, nor are publicity, 209 | privacy, and/or other similar personality rights; however, to 210 | the extent possible, the Licensor waives and/or agrees not to 211 | assert any such rights held by the Licensor to the limited 212 | extent necessary to allow You to exercise the Licensed 213 | Rights, but not otherwise. 214 | 215 | 2. Patent and trademark rights are not licensed under this 216 | Public License. 217 | 218 | 3. To the extent possible, the Licensor waives any right to 219 | collect royalties from You for the exercise of the Licensed 220 | Rights, whether directly or through a collecting society 221 | under any voluntary or waivable statutory or compulsory 222 | licensing scheme. In all other cases the Licensor expressly 223 | reserves any right to collect such royalties. 224 | 225 | 226 | Section 3 -- License Conditions. 227 | 228 | Your exercise of the Licensed Rights is expressly made subject to the 229 | following conditions. 230 | 231 | a. Attribution. 232 | 233 | 1. If You Share the Licensed Material (including in modified 234 | form), You must: 235 | 236 | a. retain the following if it is supplied by the Licensor 237 | with the Licensed Material: 238 | 239 | i. identification of the creator(s) of the Licensed 240 | Material and any others designated to receive 241 | attribution, in any reasonable manner requested by 242 | the Licensor (including by pseudonym if 243 | designated); 244 | 245 | ii. a copyright notice; 246 | 247 | iii. a notice that refers to this Public License; 248 | 249 | iv. a notice that refers to the disclaimer of 250 | warranties; 251 | 252 | v. a URI or hyperlink to the Licensed Material to the 253 | extent reasonably practicable; 254 | 255 | b. indicate if You modified the Licensed Material and 256 | retain an indication of any previous modifications; and 257 | 258 | c. indicate the Licensed Material is licensed under this 259 | Public License, and include the text of, or the URI or 260 | hyperlink to, this Public License. 261 | 262 | 2. You may satisfy the conditions in Section 3(a)(1) in any 263 | reasonable manner based on the medium, means, and context in 264 | which You Share the Licensed Material. For example, it may be 265 | reasonable to satisfy the conditions by providing a URI or 266 | hyperlink to a resource that includes the required 267 | information. 268 | 269 | 3. If requested by the Licensor, You must remove any of the 270 | information required by Section 3(a)(1)(A) to the extent 271 | reasonably practicable. 272 | 273 | b. ShareAlike. 274 | 275 | In addition to the conditions in Section 3(a), if You Share 276 | Adapted Material You produce, the following conditions also apply. 277 | 278 | 1. The Adapter's License You apply must be a Creative Commons 279 | license with the same License Elements, this version or 280 | later, or a BY-SA Compatible License. 281 | 282 | 2. You must include the text of, or the URI or hyperlink to, the 283 | Adapter's License You apply. You may satisfy this condition 284 | in any reasonable manner based on the medium, means, and 285 | context in which You Share Adapted Material. 286 | 287 | 3. You may not offer or impose any additional or different terms 288 | or conditions on, or apply any Effective Technological 289 | Measures to, Adapted Material that restrict exercise of the 290 | rights granted under the Adapter's License You apply. 291 | 292 | 293 | Section 4 -- Sui Generis Database Rights. 294 | 295 | Where the Licensed Rights include Sui Generis Database Rights that 296 | apply to Your use of the Licensed Material: 297 | 298 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 299 | to extract, reuse, reproduce, and Share all or a substantial 300 | portion of the contents of the database; 301 | 302 | b. if You include all or a substantial portion of the database 303 | contents in a database in which You have Sui Generis Database 304 | Rights, then the database in which You have Sui Generis Database 305 | Rights (but not its individual contents) is Adapted Material, 306 | 307 | including for purposes of Section 3(b); and 308 | c. You must comply with the conditions in Section 3(a) if You Share 309 | all or a substantial portion of the contents of the database. 310 | 311 | For the avoidance of doubt, this Section 4 supplements and does not 312 | replace Your obligations under this Public License where the Licensed 313 | Rights include other Copyright and Similar Rights. 314 | 315 | 316 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 317 | 318 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 319 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 320 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 321 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 322 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 323 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 324 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 325 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 326 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 327 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 328 | 329 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 330 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 331 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 332 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 333 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 334 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 335 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 336 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 337 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 338 | 339 | c. The disclaimer of warranties and limitation of liability provided 340 | above shall be interpreted in a manner that, to the extent 341 | possible, most closely approximates an absolute disclaimer and 342 | waiver of all liability. 343 | 344 | 345 | Section 6 -- Term and Termination. 346 | 347 | a. This Public License applies for the term of the Copyright and 348 | Similar Rights licensed here. However, if You fail to comply with 349 | this Public License, then Your rights under this Public License 350 | terminate automatically. 351 | 352 | b. Where Your right to use the Licensed Material has terminated under 353 | Section 6(a), it reinstates: 354 | 355 | 1. automatically as of the date the violation is cured, provided 356 | it is cured within 30 days of Your discovery of the 357 | violation; or 358 | 359 | 2. upon express reinstatement by the Licensor. 360 | 361 | For the avoidance of doubt, this Section 6(b) does not affect any 362 | right the Licensor may have to seek remedies for Your violations 363 | of this Public License. 364 | 365 | c. For the avoidance of doubt, the Licensor may also offer the 366 | Licensed Material under separate terms or conditions or stop 367 | distributing the Licensed Material at any time; however, doing so 368 | will not terminate this Public License. 369 | 370 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 371 | License. 372 | 373 | 374 | Section 7 -- Other Terms and Conditions. 375 | 376 | a. The Licensor shall not be bound by any additional or different 377 | terms or conditions communicated by You unless expressly agreed. 378 | 379 | b. Any arrangements, understandings, or agreements regarding the 380 | Licensed Material not stated herein are separate from and 381 | independent of the terms and conditions of this Public License. 382 | 383 | 384 | Section 8 -- Interpretation. 385 | 386 | a. For the avoidance of doubt, this Public License does not, and 387 | shall not be interpreted to, reduce, limit, restrict, or impose 388 | conditions on any use of the Licensed Material that could lawfully 389 | be made without permission under this Public License. 390 | 391 | b. To the extent possible, if any provision of this Public License is 392 | deemed unenforceable, it shall be automatically reformed to the 393 | minimum extent necessary to make it enforceable. If the provision 394 | cannot be reformed, it shall be severed from this Public License 395 | without affecting the enforceability of the remaining terms and 396 | conditions. 397 | 398 | c. No term or condition of this Public License will be waived and no 399 | failure to comply consented to unless expressly agreed to by the 400 | Licensor. 401 | 402 | d. Nothing in this Public License constitutes or may be interpreted 403 | as a limitation upon, or waiver of, any privileges and immunities 404 | that apply to the Licensor or You, including from the legal 405 | processes of any jurisdiction or authority. 406 | 407 | 408 | ======================================================================= 409 | 410 | Creative Commons is not a party to its public 411 | licenses. Notwithstanding, Creative Commons may elect to apply one of 412 | its public licenses to material it publishes and in those instances 413 | will be considered the “Licensor.” The text of the Creative Commons 414 | public licenses is dedicated to the public domain under the CC0 Public 415 | Domain Dedication. Except for the limited purpose of indicating that 416 | material is shared under a Creative Commons public license or as 417 | otherwise permitted by the Creative Commons policies published at 418 | creativecommons.org/policies, Creative Commons does not authorize the 419 | use of the trademark "Creative Commons" or any other trademark or logo 420 | of Creative Commons without its prior written consent including, 421 | without limitation, in connection with any unauthorized modifications 422 | to any of its public licenses or any other arrangements, 423 | understandings, or agreements concerning use of licensed material. For 424 | the avoidance of doubt, this paragraph does not form part of the 425 | public licenses. 426 | 427 | Creative Commons may be contacted at creativecommons.org. 428 | 429 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 The Real Time For the Masses developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `μAMP` 2 | 3 | > A (micro) framework for building bare-metal AMP (Asymmetric Multi-Processing) applications 4 | 5 | ## Features 6 | 7 | - Lets you write single-source multi-core applications 8 | 9 | - Zero cost shared memory abstraction for Inter-Processor Communication. 10 | 11 | - Use the built-in conditional compilation feature (`#[cfg(core = "0")]` / 12 | `cfg!(core = "1")`) to partition your application between the cores. 13 | 14 | ## Planned features 15 | 16 | - Multi-target support. 17 | 18 | The framework currently uses the *same* compilation target for all the cores. 19 | This limits the supported systems to homogeneous multi-core devices (all cores 20 | use the exact same instruction set) and heterogeneous multi-core devices where 21 | the cores share a lowest common denominator instruction set (for example, both 22 | cores in a Cortex-M4 + Cortex-M0 device can run programs compiled for 23 | `thumbv6m-none-eabi`). 24 | 25 | We need to design (and test) a command line flag to specify, or override, a 26 | compilation target for each core. 27 | 28 | ## Known limitations 29 | 30 | - The framework currently only supports the ARM architecture. 31 | 32 | To lift this limitation we need to implement the functionality of the `strip` 33 | command in Rust. Namely this invocation needs to be ported to Rust: `strip -R 34 | '*' -R '!.shared' --strip-unneeded `. If you are aware of any crate that can do 35 | that please let me know in the issue tracker! 36 | 37 | ## Known issues 38 | 39 | - Sending / sharing a function pointer or trait object between the cores is 40 | potentially unsound, or at least a Very Bad idea but this is not *fully* 41 | rejected in the case of function pointers. 42 | 43 | The framework tries to prevent this operation at compile time. All trait objects 44 | are currently rejected, but only function pointers with 0 to 12 arguments are 45 | rejected. To reject *all* function pointers we would need the Variadic Generics 46 | (VG) language feature. 47 | 48 | ## Example 49 | 50 | Here's a program that runs on a homogeneous dual-core device (2x Cortex-R5 51 | cores). 52 | 53 | ``` rust, ignore 54 | #![no_main] 55 | #![no_std] 56 | 57 | use core::sync::atomic::{AtomicU8, Ordering}; 58 | 59 | use arm_dcc::dprintln; 60 | use microamp::shared; 61 | use panic_dcc as _; // panic handler 62 | use zup_rt::entry; 63 | 64 | // non-atomic variable 65 | #[shared] // <- means: same memory location on all the cores 66 | static mut SHARED: u64 = 0; 67 | 68 | // used to synchronize access to `SHARED` 69 | #[shared] 70 | static SEMAPHORE: AtomicU8 = AtomicU8::new(CORE0); 71 | 72 | // possible values for SEMAPHORE 73 | const CORE0: u8 = 0; 74 | const CORE1: u8 = 1; 75 | const LOCKED: u8 = 2; 76 | 77 | #[entry] 78 | fn main() -> ! { 79 | let (our_turn, next_core) = if cfg!(core = "0") { 80 | (CORE0, CORE1) 81 | } else { 82 | (CORE1, CORE0) 83 | }; 84 | 85 | dprintln!("START"); 86 | 87 | let mut done = false; 88 | while !done { 89 | // try to acquire the lock 90 | while SEMAPHORE 91 | .compare_exchange(our_turn, LOCKED, Ordering::AcqRel, Ordering::Relaxed) 92 | .is_err() 93 | { 94 | // busy wait if the lock is held by the other core 95 | } 96 | 97 | // we acquired the lock; now we have exclusive access to `SHARED` 98 | unsafe { 99 | if SHARED >= 10 { 100 | // stop at some arbitrary point 101 | done = true; 102 | } else { 103 | dprintln!("{}", SHARED); 104 | 105 | SHARED += 1; 106 | } 107 | } 108 | 109 | // release the lock & unblock the other core 110 | SEMAPHORE.store(next_core, Ordering::Release); 111 | } 112 | 113 | dprintln!("DONE"); 114 | 115 | loop {} 116 | } 117 | ``` 118 | 119 | In this example we have two static variables in shared memory and visible to 120 | both cores (\*). One of the variables, `SEMAPHORE`, is used to synchronize 121 | access to the non-atomic `SHARED` variable. Both cores will execute the `main` 122 | function at boot but they will execute slightly different code paths due to the 123 | use of the `cfg!` macro. 124 | 125 | To build the application we use the following command: 126 | 127 | ``` console 128 | $ cargo microamp --bin app --release 129 | Compiling zup-rtfm v0.1.0 (/tmp/firmware) 130 | Finished dev [unoptimized + debuginfo] target(s) in 0.32s 131 | Compiling zup-rtfm v0.1.0 (/tmp/firmware) 132 | Finished dev [unoptimized + debuginfo] target(s) in 0.12s 133 | Compiling zup-rtfm v0.1.0 (/tmp/firmware) 134 | Finished dev [unoptimized + debuginfo] target(s) in 0.12s 135 | ``` 136 | 137 | By default the command produces two images, one for each core. 138 | 139 | ``` console 140 | $ # image for first core 141 | $ size -Ax target/armv7r-none-eabi/release/examples/app-0 142 | target/armv7r-none-eabi/release/examples/app-0 : 143 | section size addr 144 | .text 0x360 0x0 145 | .local 0x0 0x20000 146 | .bss 0x0 0xfffc0000 147 | .data 0x0 0xfffc0000 148 | .rodata 0x40 0xfffc0000 149 | .shared 0x10 0xfffe0000 150 | 151 | $ # image for second core 152 | $ size -Ax target/armv7r-none-eabi/release/examples/app-1 153 | target/armv7r-none-eabi/release/examples/app-1 : 154 | section size addr 155 | .text 0x360 0x0 156 | .local 0x0 0x20000 157 | .bss 0x0 0xfffd0000 158 | .data 0x0 0xfffd0000 159 | .rodata 0x40 0xfffd0000 160 | .shared 0x10 0xfffe0000 161 | ``` 162 | 163 | If we run the image on core #0 we'll see: 164 | 165 | ``` console 166 | $ # on another terminal: load and run the program 167 | $ CORE=0 xsdb -interactive debug.tcl amp-shared-0 168 | 169 | $ # output of core #0 170 | $ tail -f dcc0.log 171 | START 172 | 0 173 | ``` 174 | 175 | That the program halts because it's waiting for the other core. Now, we run the 176 | other image on core #1. 177 | 178 | ``` console 179 | $ # on another terminal: load and run the program 180 | $ CORE=1 xsdb -interactive debug.tcl amp-shared-1 181 | 182 | $ # output of core #1 183 | $ tail -f dcc1.log 184 | START 185 | 1 186 | 3 187 | 5 188 | 7 189 | 9 190 | DONE 191 | ``` 192 | 193 | And we'll get new output from core #0. 194 | 195 | ``` console 196 | $ # output of core #0 197 | $ tail -f dcc0.log 198 | START 199 | 0 200 | 2 201 | 4 202 | 6 203 | 8 204 | DONE 205 | ``` 206 | 207 | (\*) **IMPORTANT** all static variables *not* marked as `#[shared]` will be 208 | *instantiated* for each core and very likely have different addresses (even if 209 | they have the same symbol name) due to compiler optimizations and linker script 210 | differences. For example, a non-`#[shared]` variable `static mut X: u32` may 211 | have address `0xffe20000` in one image and address `0xffeb0000` in the other 212 | image. 213 | 214 | ## Requirements 215 | 216 | The user, or a crate, must provide one linker script *per core*. The 217 | `cargo-microamp` tool will use these linker scripts to link the program for each 218 | core and expects them to be named `core0.x`, `core1.x`, etc. 219 | 220 | `cargo-microamp` will pass a file named `microamp-data.o` to the linker when 221 | linking each image. This object file contains all the `#[shared]` variables 222 | in a section named `.shared`. These variables must be placed in an output 223 | section named `.shared`. This section must be located at the *same* address on 224 | all images. For example: 225 | 226 | ``` console 227 | $ cat core0.x 228 | SECTIONS 229 | { 230 | /* .. */ 231 | 232 | .shared : ALIGN(4) 233 | { 234 | KEEP(microamp-data.o(.shared)); 235 | . = ALIGN(4); 236 | } > OCM0 237 | 238 | /* .. */ 239 | } 240 | ``` 241 | 242 | ``` console 243 | $ cat core1.x 244 | SECTIONS 245 | { 246 | /* .. */ 247 | 248 | /* NOTE(NOLOAD) core 0 will initialize this shared section */ 249 | .shared (NOLOAD) : ALIGN(4) 250 | { 251 | KEEP(microamp-data.o(.shared)); 252 | . = ALIGN(4); 253 | } > OCM0 254 | 255 | /* .. */ 256 | } 257 | ``` 258 | 259 | Furthermore care must be taken to *not* initialize this `.shared` link section 260 | *more than once*. In the above example, the shared variables are initialized 261 | when the *first* image is loaded into memory. 262 | 263 | ## License 264 | 265 | All source code (including code snippets) is licensed under either of 266 | 267 | - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or 268 | [https://www.apache.org/licenses/LICENSE-2.0][L1]) 269 | 270 | - MIT license ([LICENSE-MIT](LICENSE-MIT) or 271 | [https://opensource.org/licenses/MIT][L2]) 272 | 273 | [L1]: https://www.apache.org/licenses/LICENSE-2.0 274 | [L2]: https://opensource.org/licenses/MIT 275 | 276 | at your option. 277 | 278 | The written prose contained within the book is licensed under the terms of the 279 | Creative Commons CC-BY-SA v4.0 license ([LICENSE-CC-BY-SA](LICENSE-CC-BY-SA) or 280 | [https://creativecommons.org/licenses/by-sa/4.0/legalcode][L3]). 281 | 282 | [L3]: https://creativecommons.org/licenses/by-sa/4.0/legalcode 283 | 284 | ### Contribution 285 | 286 | Unless you explicitly state otherwise, any contribution intentionally submitted 287 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 288 | licensed as above, without any additional terms or conditions. 289 | -------------------------------------------------------------------------------- /ci/install.sh: -------------------------------------------------------------------------------- 1 | set -euxo pipefail 2 | 3 | main() { 4 | rustup target add $TARGET 5 | } 6 | 7 | main 8 | -------------------------------------------------------------------------------- /ci/script.sh: -------------------------------------------------------------------------------- 1 | set -euxo pipefail 2 | 3 | main() { 4 | ( cd tools && cargo install --path . --debug -f ) 5 | 6 | if [ $TARGET = x86_64-unknown-linux-gnu ]; then 7 | cargo test 8 | else 9 | ( cd dummy && cargo microamp --bin dummy --check ) 10 | fi 11 | } 12 | 13 | # fake Travis variables to be able to run this on a local machine 14 | if [ -z ${TARGET-} ]; then 15 | TARGET=$(rustc -Vv | grep host | cut -d ' ' -f2) 16 | fi 17 | 18 | main 19 | -------------------------------------------------------------------------------- /dummy/.cargo/config: -------------------------------------------------------------------------------- 1 | [build] 2 | target = "thumbv7m-none-eabi" -------------------------------------------------------------------------------- /dummy/.gitignore: -------------------------------------------------------------------------------- 1 | /target -------------------------------------------------------------------------------- /dummy/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dummy" 3 | version = "0.1.0" 4 | authors = ["Jorge Aparicio "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | microamp = { path = ".." } 9 | -------------------------------------------------------------------------------- /dummy/src/main.rs: -------------------------------------------------------------------------------- 1 | #![no_main] 2 | #![no_std] 3 | 4 | use core::{ 5 | panic::PanicInfo, 6 | sync::atomic::{AtomicBool, Ordering}, 7 | }; 8 | 9 | use microamp::shared; 10 | 11 | #[shared] 12 | static X: AtomicBool = AtomicBool::new(false); 13 | 14 | #[shared] 15 | static mut Y: u32 = 0; 16 | 17 | #[allow(dead_code)] 18 | fn main() { 19 | if cfg!(core = "0") { 20 | unsafe { Y += 1 } 21 | } else { 22 | unsafe { Y += 2 } 23 | } 24 | 25 | X.store(true, Ordering::Release); 26 | } 27 | 28 | #[panic_handler] 29 | fn panic(_: &PanicInfo) -> ! { 30 | loop {} 31 | } 32 | -------------------------------------------------------------------------------- /macros/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = [ 3 | "The Real Time For the Masses developers", 4 | "Jorge Aparicio ", 5 | ] 6 | categories = ["concurrency", "embedded", "no-std"] 7 | description = "μAMP's `#[shared]` attribute" 8 | documentation = "https://docs.rs/microamp-macros" 9 | edition = "2018" 10 | keywords = ["AMP", "asymmetric"] 11 | license = "MIT OR Apache-2.0" 12 | name = "microamp-macros" 13 | repository = "https://github.com/rtfm-rs/microamp" 14 | version = "0.1.0-alpha.5" 15 | 16 | [lib] 17 | proc-macro = true 18 | 19 | [dependencies] 20 | proc-macro2 = "1" 21 | quote = "1" 22 | 23 | [dependencies.syn] 24 | version = "1" 25 | features = ["full"] 26 | -------------------------------------------------------------------------------- /macros/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(rust_2018_compatibility)] 2 | #![deny(rust_2018_idioms)] 3 | #![deny(warnings)] 4 | #![recursion_limit = "128"] 5 | 6 | 7 | use core::sync::atomic::{AtomicUsize, Ordering}; 8 | use proc_macro::TokenStream; 9 | 10 | use proc_macro2::Span; 11 | use quote::quote; 12 | use syn::{parse, parse_macro_input, ItemStatic}; 13 | 14 | /// An attribute to place a static variable in shared memory 15 | /// 16 | /// This static variable will refer to the same memory location on all cores 17 | #[proc_macro_attribute] 18 | pub fn shared(args: TokenStream, input: TokenStream) -> TokenStream { 19 | static COUNT: AtomicUsize = AtomicUsize::new(0); 20 | 21 | if !args.is_empty() { 22 | return parse::Error::new(Span::call_site(), "`#[shared]` takes no arguments") 23 | .to_compile_error() 24 | .into(); 25 | } 26 | 27 | let item = parse_macro_input!(input as ItemStatic); 28 | 29 | let attrs = &item.attrs; 30 | let expr = &item.expr; 31 | let ident = &item.ident; 32 | let symbol = format!("{}.{}", ident, COUNT.fetch_add(1, Ordering::AcqRel)); 33 | let ty = &item.ty; 34 | let vis = &item.vis; 35 | if item.mutability.is_some() { 36 | quote!( 37 | #[cfg(not(target_arch = "arm"))] 38 | compile_error!("Only the ARM architecture is supported at the moment"); 39 | 40 | #(#attrs)* 41 | #[cfg(microamp)] 42 | #[link_section = ".shared"] 43 | #[export_name = #symbol] 44 | static mut #ident: #ty = { 45 | fn assert() { 46 | microamp::export::is_data::<#ty>(); 47 | } 48 | 49 | #expr 50 | }; 51 | 52 | #[cfg(not(microamp))] 53 | extern "C" { 54 | #[link_name = #symbol] 55 | #vis static mut #ident: #ty; 56 | } 57 | ) 58 | .into() 59 | } else { 60 | quote!( 61 | #[cfg(not(target_arch = "arm"))] 62 | compile_error!("Only the ARM architecture is supported at the moment"); 63 | 64 | #(#attrs)* 65 | #[cfg(microamp)] 66 | #[link_section = ".shared"] 67 | #[no_mangle] 68 | static #ident: #ty = { 69 | fn assert() { 70 | microamp::export::is_data::<#ty>(); 71 | } 72 | 73 | #expr 74 | }; 75 | 76 | #[cfg(not(microamp))] 77 | #vis struct #ident; 78 | 79 | #[cfg(not(microamp))] 80 | impl core::ops::Deref for #ident { 81 | type Target = #ty; 82 | 83 | fn deref(&self) -> &#ty { 84 | #[inline(always)] 85 | fn assert() where T: Sync {} 86 | assert::<#ty>(); 87 | 88 | extern "C" { 89 | static #ident: #ty; 90 | } 91 | 92 | unsafe { &#ident } 93 | } 94 | } 95 | ) 96 | .into() 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/cfail.rs: -------------------------------------------------------------------------------- 1 | //! ``` compile_fail 2 | //! microamp::export::is_data::(); 3 | //! ``` 4 | //! 5 | //! ``` compile_fail 6 | //! microamp::export::is_data:: !>(); 7 | //! ``` 8 | //! 9 | //! ``` compile_fail 10 | //! trait Foo {} 11 | //! microamp::export::is_data::(); 12 | //! ``` 13 | -------------------------------------------------------------------------------- /src/export.rs: -------------------------------------------------------------------------------- 1 | pub auto trait DataNotCode {} 2 | 3 | macro_rules! impl_ { 4 | ($($T:ident),*) => { 5 | impl !DataNotCode for fn($($T),*) -> R {} 6 | impl !DataNotCode for extern "C" fn($($T),*) -> R {} 7 | }; 8 | } 9 | 10 | macro_rules! impls { 11 | ($head:ident $(,$tail:ident)*) => { 12 | impls!($($tail),*); 13 | impl_!($head $(,$tail)*); 14 | }; 15 | 16 | () => { 17 | impl_!(); 18 | }; 19 | } 20 | 21 | // FIXME this should use Variadic Generics 22 | impls!(A, B, C, D, E, F, G, H, I, J, K, L); 23 | 24 | pub fn is_data() 25 | where 26 | T: DataNotCode + ?Sized, 27 | { 28 | } 29 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(rust_2018_compatibility)] 2 | #![deny(rust_2018_idioms)] 3 | #![doc = include_str!("../README.md")] 4 | #![deny(missing_docs)] 5 | #![feature(auto_traits)] 6 | #![feature(negative_impls)] 7 | #![no_std] 8 | 9 | pub use microamp_macros::shared; 10 | 11 | mod cfail; 12 | #[doc(hidden)] 13 | pub mod export; 14 | -------------------------------------------------------------------------------- /tools/.gitignore: -------------------------------------------------------------------------------- 1 | /target -------------------------------------------------------------------------------- /tools/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = [ 3 | "The Real Time For the Masses developers", 4 | "Jorge Aparicio ", 5 | ] 6 | categories = ["command-line-utilities", "concurrency", "embedded", "no-std"] 7 | description = "Build a μAMP application" 8 | edition = "2018" 9 | keywords = ["AMP", "asymmetric"] 10 | license = "MIT OR Apache-2.0" 11 | name = "microamp-tools" 12 | repository = "https://github.com/rtfm-rs/microamp" 13 | version = "0.1.0-alpha.3" 14 | 15 | [dependencies] 16 | cargo-project = "0.2.2" 17 | clap = "2.33.0" 18 | exitfailure = "0.5.1" 19 | failure = "0.1.5" 20 | filetime = "0.2.5" 21 | rustc_version = "0.2.3" 22 | tempdir = "0.3.7" 23 | walkdir = "2.2.7" 24 | xmas-elf = "0.6.2" 25 | -------------------------------------------------------------------------------- /tools/src/bin/cargo-microamp.rs: -------------------------------------------------------------------------------- 1 | //! Build a μAMP application 2 | 3 | #![deny(rust_2018_compatibility)] 4 | #![deny(rust_2018_idioms)] 5 | #![deny(warnings)] 6 | 7 | use core::{fmt, iter::FromIterator}; 8 | use std::{ 9 | collections::BTreeMap, 10 | env, fs, 11 | process::{self, Command}, 12 | time::SystemTime, 13 | }; 14 | 15 | use cargo_project::{Artifact, Profile, Project}; 16 | use clap::{App, Arg}; 17 | use exitfailure::ExitFailure; 18 | use failure::{bail, ensure, format_err}; 19 | use filetime::FileTime; 20 | use tempdir::TempDir; 21 | use walkdir::WalkDir; 22 | use xmas_elf::{sections::SectionData, symbol_table::Entry, ElfFile}; 23 | 24 | fn main() -> Result<(), ExitFailure> { 25 | process::exit(run()?) 26 | } 27 | 28 | fn run() -> Result { 29 | let matches = App::new("cargo-microamp") 30 | .version(env!("CARGO_PKG_VERSION")) 31 | .author("Jorge Aparicio ") 32 | .about("Build a μAMP application") 33 | // as this is used as a Cargo subcommand the first argument will be the name of the binary 34 | // we ignore this argument 35 | .arg(Arg::with_name("binary-name").hidden(true)) 36 | .arg( 37 | Arg::with_name("cores") 38 | .long("cores") 39 | .short("c") 40 | .takes_value(true) 41 | .value_name("N") 42 | .help("Number of cores to build this program for (default: 2)"), 43 | ) 44 | .arg( 45 | Arg::with_name("target") 46 | .long("target") 47 | .takes_value(true) 48 | .value_name("TRIPLE") 49 | .help("Comma separated list of target triples for which the code is compiled"), 50 | ) 51 | .arg( 52 | Arg::with_name("verbose") 53 | .long("verbose") 54 | .short("v") 55 | .help("Use verbose output"), 56 | ) 57 | .arg( 58 | Arg::with_name("example") 59 | .long("example") 60 | .takes_value(true) 61 | .value_name("NAME") 62 | .help("Build only the specified example"), 63 | ) 64 | .arg( 65 | Arg::with_name("bin") 66 | .long("bin") 67 | .takes_value(true) 68 | .value_name("BIN") 69 | .help("Build only the specified binary"), 70 | ) 71 | .arg( 72 | Arg::with_name("features") 73 | .long("features") 74 | .takes_value(true) 75 | .value_name("FEATURES") 76 | .help("Space-separated list of features to activate"), 77 | ) 78 | .arg( 79 | Arg::with_name("all-features") 80 | .long("all-features") 81 | .takes_value(false) 82 | .help("Activate all available features"), 83 | ) 84 | .arg( 85 | Arg::with_name("release") 86 | .long("release") 87 | .help("Build artifacts in release mode, with optimizations"), 88 | ) 89 | .arg( 90 | Arg::with_name("check") 91 | .long("check") 92 | .help("Do not link; only compile check"), 93 | ) 94 | .get_matches(); 95 | 96 | let targets = if let Some(target) = matches.value_of("target") { 97 | target 98 | .split(',') 99 | .map(|s| if s == "_" { None } else { Some(s) }) 100 | .collect() 101 | } else { 102 | vec![] 103 | }; 104 | 105 | let cores = if let Some(s) = matches.value_of("cores") { 106 | if matches.is_present("target") { 107 | bail!("can't specify both `--cores` and `--target`"); 108 | } 109 | 110 | s.parse()? 111 | } else if matches.is_present("target") { 112 | targets.len() 113 | } else { 114 | 2 115 | }; 116 | let check = matches.is_present("check"); 117 | let build_profile = if matches.is_present("release") { 118 | if check { 119 | bail!("can't specify both `--check` and `--release`"); 120 | } 121 | 122 | Profile::Release 123 | } else { 124 | Profile::Dev 125 | }; 126 | let verbose = matches.is_present("verbose"); 127 | 128 | let artifact = match (matches.value_of("bin"), matches.value_of("example")) { 129 | (Some(bin), None) => Artifact::Bin(bin), 130 | (None, Some(ex)) => Artifact::Example(ex), 131 | _ => bail!("please specify --example or --bin "), 132 | }; 133 | 134 | let meta = rustc_version::version_meta()?; 135 | let host = meta.host; 136 | let project = Project::query(env::current_dir()?)?; 137 | 138 | // "touch" some source file to trigger a rebuild 139 | let root = project.toml().parent().expect("UNREACHABLE"); 140 | let now = FileTime::from_system_time(SystemTime::now()); 141 | match artifact { 142 | Artifact::Bin(bin) => { 143 | if bin == project.name() { 144 | filetime::set_file_times(root.join("src/main.rs"), now, now)? 145 | } else { 146 | filetime::set_file_times(root.join(format!("src/bin/{}.rs", bin)), now, now)? 147 | } 148 | } 149 | 150 | Artifact::Example(ex) => { 151 | filetime::set_file_times(root.join(format!("examples/{}.rs", ex)), now, now)? 152 | } 153 | 154 | Artifact::Lib => filetime::set_file_times(root.join("src/lib.rs"), now, now)?, 155 | 156 | _ => { 157 | // look for some rust source file and "touch" it 158 | let src = root.join("src"); 159 | let haystack = if src.exists() { &src } else { root }; 160 | 161 | for entry in WalkDir::new(haystack) { 162 | let entry = entry?; 163 | let path = entry.path(); 164 | 165 | if path.extension().map(|ext| ext == "rs").unwrap_or(false) { 166 | filetime::set_file_times(path, now, now)?; 167 | break; 168 | } 169 | } 170 | } 171 | } 172 | 173 | let cargo = || { 174 | let mut c = Command::new("cargo"); 175 | c.arg("rustc"); 176 | match artifact { 177 | Artifact::Bin(bin) => { 178 | c.args(&["--bin", bin]); 179 | } 180 | Artifact::Example(ex) => { 181 | c.args(&["--example", ex]); 182 | } 183 | _ => {} 184 | } 185 | if build_profile.is_release() { 186 | c.arg("--release"); 187 | } 188 | if matches.is_present("all-features") { 189 | c.arg("--all-features"); 190 | } else if let Some(features) = matches.value_of("features") { 191 | c.args(&["--features", features]); 192 | } 193 | c 194 | }; 195 | 196 | if check { 197 | if targets.is_empty() { 198 | // data 199 | let mut c = cargo(); 200 | c.args(&[ 201 | "--", 202 | "--cfg", 203 | "microamp", 204 | "-C", 205 | "linker=microamp-true", 206 | "-A", 207 | "warnings", 208 | ]); 209 | if verbose { 210 | eprintln!("{:?}", c); 211 | } 212 | let status = c.status()?; 213 | if !status.success() { 214 | return Ok(status.code().unwrap_or(1)); 215 | } 216 | } 217 | 218 | for i in 0..cores { 219 | // data 220 | if !targets.is_empty() { 221 | let mut c = cargo(); 222 | if let Some(target) = targets.get(i).unwrap_or(&None) { 223 | c.args(&["--target", target]); 224 | } 225 | c.args(&[ 226 | "--", 227 | "--cfg", 228 | "microamp", 229 | "-C", 230 | "linker=microamp-true", 231 | "-A", 232 | "warnings", 233 | ]); 234 | if verbose { 235 | eprintln!("{:?}", c); 236 | } 237 | let status = c.status()?; 238 | if !status.success() { 239 | return Ok(status.code().unwrap_or(1)); 240 | } 241 | } 242 | 243 | // code 244 | let mut c = cargo(); 245 | if let Some(target) = targets.get(i).unwrap_or(&None) { 246 | c.args(&["--target", target]); 247 | } 248 | c.args(&["--", "--cfg"]); 249 | c.arg(&format!("core=\"{}\"", i)); 250 | c.args(&["-C", "linker=microamp-true"]); 251 | if verbose { 252 | eprintln!("{:?}", c); 253 | } 254 | let status = c.status()?; 255 | if !status.success() { 256 | return Ok(status.code().unwrap_or(1)); 257 | } 258 | } 259 | } else { 260 | // address -> (size, name) 261 | let mut base: Option<(String, Symbols)> = None; 262 | for i in 0..cores { 263 | let mut c = cargo(); 264 | if let Some(target) = targets.get(i).unwrap_or(&None) { 265 | c.args(&["--target", target]); 266 | } 267 | c.args(&[ 268 | "--", 269 | "-C", 270 | "lto", 271 | "--cfg", 272 | "microamp", 273 | "--emit=obj", 274 | "-A", 275 | "warnings", 276 | "-C", 277 | "linker=microamp-true", 278 | ]); 279 | if verbose { 280 | eprintln!("{:?}", c); 281 | } 282 | let status = c.status()?; 283 | if !status.success() { 284 | return Ok(status.code().unwrap_or(1)); 285 | } 286 | 287 | let path = project.path( 288 | artifact, 289 | build_profile, 290 | targets.get(i).and_then(|t| t.as_ref().map(|s| *s)), 291 | &host, 292 | )?; 293 | let parent = path.parent().expect("unreachable"); 294 | let (haystack, name) = match artifact { 295 | Artifact::Bin(bin) => (parent.join("deps"), bin), 296 | Artifact::Example(ex) => (parent.to_owned(), ex), 297 | _ => unreachable!(), 298 | }; 299 | 300 | let prefix = format!("{}-", name.replace('-', "_")); 301 | let mut so = None; 302 | // most recently modified 303 | let mut mrm = SystemTime::UNIX_EPOCH; 304 | for e in fs::read_dir(haystack)? { 305 | let e = e?; 306 | let p = e.path(); 307 | 308 | if p.extension().map(|ext| ext == "o").unwrap_or(false) 309 | && p.file_stem() 310 | .expect("unreachable") 311 | .to_str() 312 | .expect("unreachable") 313 | .starts_with(&prefix) 314 | { 315 | let modified = e.metadata()?.modified()?; 316 | if so.is_none() { 317 | so = Some(p); 318 | mrm = modified; 319 | } else { 320 | if modified > mrm { 321 | so = Some(p); 322 | mrm = modified; 323 | } 324 | } 325 | } 326 | } 327 | 328 | // strip '.text' sections from the shared object file 329 | let so = so.expect("UNREACHABLE"); 330 | let td = TempDir::new("cargo-microamp")?; 331 | let obj = td.path().join("microamp-data.o"); 332 | fs::copy(&so, &obj)?; 333 | 334 | // FIXME use a Rust library instead of shelling out to `strip` 335 | let mut c = Command::new("arm-none-eabi-strip"); 336 | c.args(&["-R", "*", "-R", "!.shared", "--strip-unneeded"]) 337 | .arg(&obj); 338 | if verbose { 339 | eprintln!("{:?}", c); 340 | } 341 | 342 | let status = c.status()?; 343 | if !status.success() { 344 | return Ok(status.code().unwrap_or(1)); 345 | } 346 | 347 | let mut c = cargo(); 348 | if let Some(target) = targets.get(i).unwrap_or(&None) { 349 | c.args(&["--target", target]); 350 | } 351 | c.args(&[ 352 | "--", 353 | "--cfg", 354 | &format!("core=\"{}\"", i), 355 | "-C", 356 | &format!("link-arg=-Tcore{}.x", i), 357 | "-C", 358 | &format!("link-arg={}", obj.display()), 359 | ]); 360 | if verbose { 361 | eprintln!("{:?}", c); 362 | } 363 | let status = c.status()?; 364 | 365 | if !status.success() { 366 | return Ok(status.code().unwrap_or(1)); 367 | } 368 | 369 | let filename = format!( 370 | "{}-{}", 371 | path.file_name() 372 | .expect("unreachable") 373 | .to_str() 374 | .expect("unreachable"), 375 | i 376 | ); 377 | let dst = parent.join(&filename); 378 | 379 | fs::rename(&path, &dst)?; 380 | 381 | let contents = fs::read(&dst)?; 382 | let elf = ElfFile::new(&contents).map_err(failure::err_msg)?; 383 | 384 | let mut shndx = None; 385 | for i in 1..elf.header.pt2.sh_count() { 386 | if let Ok(sh) = elf.section_header(i) { 387 | if sh.get_name(&elf) == Ok(".shared") { 388 | shndx = Some(i); 389 | break; 390 | } 391 | } 392 | } 393 | 394 | let shndx = 395 | shndx.ok_or_else(|| format_err!("({}) `.shared` section is missing", filename))?; 396 | 397 | if let Some(symtab) = elf.find_section_by_name(".symtab") { 398 | match symtab.get_data(&elf).map_err(failure::err_msg)? { 399 | SectionData::SymbolTable32(entries) => { 400 | if let Some((base_filename, base_symbols)) = &base { 401 | let symbols = entries 402 | .iter() 403 | .filter_map(|entry| { 404 | let size = entry.size(); 405 | if entry.shndx() == shndx && size != 0 { 406 | Some(( 407 | entry.value(), 408 | (size, entry.get_name(&elf).ok().map(String::from)), 409 | )) 410 | } else { 411 | None 412 | } 413 | }) 414 | .collect::(); 415 | 416 | ensure!( 417 | &symbols == base_symbols, 418 | "the layout of the `.shared` section doesn't match\n\ 419 | {}:\n{:#?}\n{}\n{:#?}", 420 | base_filename, 421 | base_symbols, 422 | filename, 423 | symbols, 424 | ); 425 | } else { 426 | base = Some(( 427 | filename, 428 | entries 429 | .iter() 430 | .filter_map(|entry| { 431 | let size = entry.size(); 432 | if entry.shndx() == shndx && size != 0 { 433 | Some(( 434 | entry.value(), 435 | (size, entry.get_name(&elf).ok().map(String::from)), 436 | )) 437 | } else { 438 | None 439 | } 440 | }) 441 | .collect(), 442 | )) 443 | } 444 | } 445 | 446 | SectionData::SymbolTable64(_) => { 447 | bail!("64-bit ELF files are not currently supported") 448 | } 449 | 450 | _ => bail!("malformed .symtab section"), 451 | } 452 | } 453 | } 454 | } 455 | 456 | Ok(0) 457 | } 458 | 459 | #[derive(PartialEq)] 460 | struct Symbols { 461 | entries: BTreeMap, 462 | } 463 | 464 | impl FromIterator<(u64, (u64, Option))> for Symbols { 465 | fn from_iter(iter: I) -> Self 466 | where 467 | I: IntoIterator))>, 468 | { 469 | Symbols { 470 | entries: iter 471 | .into_iter() 472 | .map(|(address, (size, name))| (address, Symbol { size, name })) 473 | .collect(), 474 | } 475 | } 476 | } 477 | 478 | impl fmt::Debug for Symbols { 479 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 480 | struct Hex(u64); 481 | 482 | impl fmt::Debug for Hex { 483 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 484 | write!(f, "{:#08x}", self.0) 485 | } 486 | } 487 | 488 | let mut s = f.debug_map(); 489 | for (address, symbol) in &self.entries { 490 | s.entry(&Hex(*address), symbol); 491 | } 492 | 493 | s.finish() 494 | } 495 | } 496 | 497 | #[derive(PartialEq)] 498 | struct Symbol { 499 | size: u64, 500 | name: Option, 501 | } 502 | 503 | impl fmt::Debug for Symbol { 504 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 505 | let mut s = f.debug_struct("Symbol"); 506 | s.field("size", &self.size); 507 | if let Some(name) = &self.name { 508 | s.field("name", name); 509 | } else { 510 | s.field("name", &"?"); 511 | } 512 | s.finish() 513 | } 514 | } 515 | -------------------------------------------------------------------------------- /tools/src/bin/microamp-true.rs: -------------------------------------------------------------------------------- 1 | //! A program that always exits successfully 2 | 3 | #![deny(rust_2018_compatibility)] 4 | #![deny(rust_2018_idioms)] 5 | #![deny(warnings)] 6 | 7 | fn main() {} 8 | --------------------------------------------------------------------------------