blob: 97832afa0327111ce74460dda4c4f7eb82758888 [file] [log] [blame]
Lenny Komow3e745d72017-06-08 16:41:02 -06001/*
Lenny Komowf220ce62018-03-28 14:31:32 -06002 * Copyright (c) 2017-2018 The Khronos Group Inc.
3 * Copyright (c) 2017-2018 Valve Corporation
4 * Copyright (c) 2017-2018 LunarG, Inc.
Lenny Komow3e745d72017-06-08 16:41:02 -06005 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Lenny Komow <lenny@lunarg.com>
19 */
20
21// This code generates an assembly file which provides offsets to get struct members from assembly code.
22
23#include <stdio.h>
24#include "loader.h"
25
Lenny Komow30c1b8a2017-06-16 16:42:46 -060026#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
27#define SIZE_T_FMT "%-8zu"
28#else
29#define SIZE_T_FMT "%-8lu"
30#endif
31
32struct ValueInfo
33{
34 const char *name;
35 size_t value;
36 const char *comment;
37};
38
Lenny Komow3e745d72017-06-08 16:41:02 -060039int main(int argc, char **argv) {
40 const char *assembler = NULL;
41 for (int i = 0; i < argc; ++i) {
42 if (!strcmp(argv[i], "MASM")) {
43 assembler = "MASM";
Lenny Komow007319b2017-06-09 15:21:06 -060044 } else if (!strcmp(argv[i], "GAS")) {
45 assembler = "GAS";
Lenny Komow3e745d72017-06-08 16:41:02 -060046 }
47 }
48 if (assembler == NULL) {
49 return 1;
50 }
51
Lenny Komow30c1b8a2017-06-16 16:42:46 -060052 struct ValueInfo values[] = {
53 { .name = "VK_DEBUG_REPORT_ERROR_BIT_EXT", .value = (size_t) VK_DEBUG_REPORT_ERROR_BIT_EXT,
54 .comment = "The numerical value of the enum value 'VK_DEBUG_REPORT_ERROR_BIT_EXT'" },
55 { .name = "PTR_SIZE", .value = sizeof(void*),
56 .comment = "The size of a pointer" },
57 { .name = "HASH_SIZE", .value = sizeof(struct loader_dispatch_hash_entry),
58 .comment = "The size of a 'loader_dispatch_hash_entry' struct" },
Lenny Komowf220ce62018-03-28 14:31:32 -060059 { .name = "HASH_OFFSET_INSTANCE", .value = offsetof(struct loader_instance, phys_dev_ext_disp_hash),
Lenny Komow30c1b8a2017-06-16 16:42:46 -060060 .comment = "The offset of 'phys_dev_ext_disp_hash' within a 'loader_instance' struct" },
Lenny Komowf220ce62018-03-28 14:31:32 -060061 { .name = "PHYS_DEV_OFFSET_INST_DISPATCH", .value = offsetof(struct loader_instance_dispatch_table, phys_dev_ext),
Lenny Komow30c1b8a2017-06-16 16:42:46 -060062 .comment = "The offset of 'phys_dev_ext' within in 'loader_instance_dispatch_table' struct" },
Lenny Komowf220ce62018-03-28 14:31:32 -060063 { .name = "PHYS_DEV_OFFSET_PHYS_DEV_TRAMP", .value = offsetof(struct loader_physical_device_tramp, phys_dev),
Lenny Komow30c1b8a2017-06-16 16:42:46 -060064 .comment = "The offset of 'phys_dev' within a 'loader_physical_device_tramp' struct" },
Lenny Komowf220ce62018-03-28 14:31:32 -060065 { .name = "ICD_TERM_OFFSET_PHYS_DEV_TERM", .value = offsetof(struct loader_physical_device_term, this_icd_term),
Lenny Komow30c1b8a2017-06-16 16:42:46 -060066 .comment = "The offset of 'this_icd_term' within a 'loader_physical_device_term' struct" },
Lenny Komowf220ce62018-03-28 14:31:32 -060067 { .name = "PHYS_DEV_OFFSET_PHYS_DEV_TERM", .value = offsetof(struct loader_physical_device_term, phys_dev),
Lenny Komow30c1b8a2017-06-16 16:42:46 -060068 .comment = "The offset of 'phys_dev' within a 'loader_physical_device_term' struct" },
Lenny Komowf220ce62018-03-28 14:31:32 -060069 { .name = "INSTANCE_OFFSET_ICD_TERM", .value = offsetof(struct loader_icd_term, this_instance),
Lenny Komow30c1b8a2017-06-16 16:42:46 -060070 .comment = "The offset of 'this_instance' within a 'loader_icd_term' struct" },
Lenny Komowf220ce62018-03-28 14:31:32 -060071 { .name = "DISPATCH_OFFSET_ICD_TERM", .value = offsetof(struct loader_icd_term, phys_dev_ext),
Lenny Komow30c1b8a2017-06-16 16:42:46 -060072 .comment = "The offset of 'phys_dev_ext' within a 'loader_icd_term' struct" },
Lenny Komowf220ce62018-03-28 14:31:32 -060073 { .name = "FUNC_NAME_OFFSET_HASH", .value = offsetof(struct loader_dispatch_hash_entry, func_name),
Lenny Komow30c1b8a2017-06-16 16:42:46 -060074 .comment = "The offset of 'func_name' within a 'loader_dispatch_hash_entry' struct" },
Lenny Komowf220ce62018-03-28 14:31:32 -060075 { .name = "EXT_OFFSET_DEVICE_DISPATCH", .value = offsetof(struct loader_dev_dispatch_table, ext_dispatch),
Lenny Komow7e669d92017-06-29 15:26:20 -060076 .comment = "The offset of 'ext_dispatch' within a 'loader_dev_dispatch_table' struct" },
Lenny Komow30c1b8a2017-06-16 16:42:46 -060077 };
Lenny Komow3e745d72017-06-08 16:41:02 -060078
79 FILE *file = fopen("gen_defines.asm", "w");
Lenny Komow30c1b8a2017-06-16 16:42:46 -060080 fprintf(file, "\n");
Lenny Komow3e745d72017-06-08 16:41:02 -060081 if (!strcmp(assembler, "MASM")) {
Lenny Komow30c1b8a2017-06-16 16:42:46 -060082 for (size_t i = 0; i < sizeof(values)/sizeof(values[0]); ++i) {
83 fprintf(file, "%-32s equ " SIZE_T_FMT "; %s\n", values[i].name, values[i].value, values[i].comment);
84 }
Lenny Komow007319b2017-06-09 15:21:06 -060085 } else if (!strcmp(assembler, "GAS")) {
Lenny Komow007319b2017-06-09 15:21:06 -060086#ifdef __x86_64__
87 fprintf(file, ".set X86_64, 1\n");
88#endif // __x86_64__
Lenny Komowd3919b02017-06-29 11:11:16 -060089 for (size_t i = 0; i < sizeof(values)/sizeof(values[0]); ++i) {
90 fprintf(file, ".set %-32s, " SIZE_T_FMT "# %s\n", values[i].name, values[i].value, values[i].comment);
91 }
Lenny Komow3e745d72017-06-08 16:41:02 -060092 }
93 return fclose(file);
94}