1/*
2 * Copyright (c) 2017 Advanced Micro Devices, Inc.
3 * All rights reserved.
4 *
5 * For use for simulation and test purposes only
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * Author: Brandon Potter
34 */
35
36#include <elf.h>
37#include <stdio.h>
38
39int main(int argc, char **argv, char **envp)
40{
41    int i;
42
43    printf("%p: argc: [%d]\n", &argc, argc);
44    printf("\n");
45
46    for (i = 0; i < argc; i++)
47        printf("%p: argv[%d]: [%s]\n", &argv[i], i, argv[i]);
48    printf("\n");
49
50    i = 0;
51    while (envp[i] != NULL) {
52        printf("%p: envp[%d]: [%s]\n", &envp[i], i, envp[i]);
53        i++;
54    }
55    printf("\n");
56
57    Elf64_auxv_t *auxv = (Elf64_auxv_t*)&envp[--i];
58    while (auxv++) {
59        char *type;
60        switch(auxv->a_type) {
61            case AT_IGNORE:
62                type = "AT_IGNORE";
63                break;
64            case AT_EXECFD:
65                type = "AT_EXECFD";
66                break;
67            case AT_PHDR:
68                type = "AT_PHDR";
69                break;
70            case AT_PHENT:
71                type = "AT_PHENT";
72                break;
73            case AT_PHNUM:
74                type = "AT_PHNUM";
75                break;
76            case AT_PAGESZ:
77                type = "AT_PAGESZ";
78                break;
79            case AT_BASE:
80                type = "AT_BASE";
81                break;
82            case AT_FLAGS:
83                type = "AT_FLAGS";
84                break;
85            case AT_ENTRY:
86                type = "AT_ENTRY";
87                break;
88            case AT_NOTELF:
89                type = "AT_NOTELF";
90                break;
91            case AT_UID:
92                type = "AT_UID";
93                break;
94            case AT_EUID:
95                type = "AT_EUID";
96                break;
97            case AT_GID:
98                type = "AT_GID";
99                break;
100            case AT_EGID:
101                type = "AT_EGID";
102                break;
103            case AT_CLKTCK:
104                type = "AT_CLKTCK";
105                break;
106            case AT_PLATFORM:
107                type = "AT_PLATFORM";
108                break;
109            case AT_HWCAP:
110                type = "AT_HWCAP";
111                break;
112            case AT_FPUCW:
113                type = "AT_FPUCW";
114                break;
115            case AT_DCACHEBSIZE:
116                type = "AT_DCACHEBSIZE";
117                break;
118            case AT_ICACHEBSIZE:
119                type = "AT_ICACHEBSIZE";
120                break;
121            case AT_UCACHEBSIZE:
122                type = "AT_UCACHEBSIZE";
123                break;
124            case AT_IGNOREPPC:
125                type = "AT_IGNOREPPC";
126                break;
127            case AT_SECURE:
128                type = "AT_SECURE";
129                break;
130            case AT_BASE_PLATFORM:
131                type = "AT_BASE_PLATFORM";
132                break;
133            case AT_RANDOM:
134                type = "AT_RANDOM";
135                break;
136            case AT_EXECFN:
137                type = "AT_EXECFN";
138                break;
139            case AT_SYSINFO:
140                type = "AT_SYSINFO";
141                break;
142            case AT_SYSINFO_EHDR:
143                type = "AT_SYSINFO_EHDR";
144                break;
145            case AT_L1I_CACHESHAPE:
146                type = "AT_L1I_CACHESHAPE";
147                break;
148            case AT_L1D_CACHESHAPE:
149                type = "AT_L1D_CACHESHAPE";
150                break;
151            case AT_L2_CACHESHAPE:
152                type = "AT_L2_CACHESHAPE";
153                break;
154            case AT_L3_CACHESHAPE:
155                type = "AT_L3_CACHESHAPE";
156                break;
157            case AT_NULL:
158            default:
159                printf("\n");
160                return 0;
161        }
162        printf("%p: %s: [%lx]\n", auxv, type, auxv->a_un.a_val);
163    }
164}
165
166