blob: f3d707492e488e4c6ae1d1a8f64e8fcf48874455 [file] [log] [blame]
Luis Hector Chavezf7b20182018-10-28 21:39:32 -07001/* 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
17int main() {
Matt Delcodbb89482020-02-12 23:05:05 -080018 // 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 Chavezf7b20182018-10-28 21:39:32 -070020 std::cout << "{\n";
Matt Delcodbb89482020-02-12 23:05:05 -080021 std::cout << " \"arch_nr\": " << std::to_string(MINIJAIL_ARCH_NR) << ",\n";
Luis Hector Chavezf6f26252019-12-13 08:04:50 -080022 std::cout << " \"arch_name\": \"" << MINIJAIL_ARCH_NAME << "\",\n";
Matt Delcodbb89482020-02-12 23:05:05 -080023 std::cout << " \"bits\": " << std::to_string(MINIJAIL_ARCH_BITS) << ",\n";
Luis Hector Chavezf7b20182018-10-28 21:39:32 -070024 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 Delcodbb89482020-02-12 23:05:05 -080032 std::cout << " \"" << entry->name << "\": " << std::to_string(entry->nr);
Luis Hector Chavezf7b20182018-10-28 21:39:32 -070033 }
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 Delcodbb89482020-02-12 23:05:05 -080043 std::cout << " \"" << entry->name << "\": "
44 << std::to_string(entry->value);
Luis Hector Chavezf7b20182018-10-28 21:39:32 -070045 }
46 std::cout << "\n }\n";
47 std::cout << "}\n";
48
49 return 0;
50}