Luis Hector Chavez | f7b2018 | 2018-10-28 21:39:32 -0700 | [diff] [blame] | 1 | /* Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | */ |
| 5 | |
| 6 | // Generate a .json file with all the architecture-specific constants. |
| 7 | |
| 8 | #include <cstdint> |
| 9 | #include <iomanip> |
| 10 | #include <iostream> |
| 11 | #include <string> |
| 12 | |
| 13 | #include "arch.h" |
| 14 | #include "libconstants.h" |
| 15 | #include "libsyscalls.h" |
| 16 | |
| 17 | int main() { |
Matt Delco | dbb8948 | 2020-02-12 23:05:05 -0800 | [diff] [blame] | 18 | // Numeric values are passed to std::cout via std::to_string() to avoid |
| 19 | // the use of 'bextr' asm instruction (when compiled with -march=bdver4). |
Luis Hector Chavez | f7b2018 | 2018-10-28 21:39:32 -0700 | [diff] [blame] | 20 | std::cout << "{\n"; |
Matt Delco | dbb8948 | 2020-02-12 23:05:05 -0800 | [diff] [blame] | 21 | std::cout << " \"arch_nr\": " << std::to_string(MINIJAIL_ARCH_NR) << ",\n"; |
Luis Hector Chavez | f6f2625 | 2019-12-13 08:04:50 -0800 | [diff] [blame] | 22 | std::cout << " \"arch_name\": \"" << MINIJAIL_ARCH_NAME << "\",\n"; |
Matt Delco | dbb8948 | 2020-02-12 23:05:05 -0800 | [diff] [blame] | 23 | std::cout << " \"bits\": " << std::to_string(MINIJAIL_ARCH_BITS) << ",\n"; |
Luis Hector Chavez | f7b2018 | 2018-10-28 21:39:32 -0700 | [diff] [blame] | 24 | std::cout << " \"syscalls\": {\n"; |
| 25 | bool first = true; |
| 26 | for (const struct syscall_entry* entry = syscall_table; entry->name; |
| 27 | ++entry) { |
| 28 | if (first) |
| 29 | first = false; |
| 30 | else |
| 31 | std::cout << ",\n"; |
Matt Delco | dbb8948 | 2020-02-12 23:05:05 -0800 | [diff] [blame] | 32 | std::cout << " \"" << entry->name << "\": " << std::to_string(entry->nr); |
Luis Hector Chavez | f7b2018 | 2018-10-28 21:39:32 -0700 | [diff] [blame] | 33 | } |
| 34 | std::cout << "\n },\n"; |
| 35 | std::cout << " \"constants\": {\n"; |
| 36 | first = true; |
| 37 | for (const struct constant_entry* entry = constant_table; entry->name; |
| 38 | ++entry) { |
| 39 | if (first) |
| 40 | first = false; |
| 41 | else |
| 42 | std::cout << ",\n"; |
Matt Delco | dbb8948 | 2020-02-12 23:05:05 -0800 | [diff] [blame] | 43 | std::cout << " \"" << entry->name << "\": " |
| 44 | << std::to_string(entry->value); |
Luis Hector Chavez | f7b2018 | 2018-10-28 21:39:32 -0700 | [diff] [blame] | 45 | } |
| 46 | std::cout << "\n }\n"; |
| 47 | std::cout << "}\n"; |
| 48 | |
| 49 | return 0; |
| 50 | } |