blob: 2cfd76238d16d882ecb15947a5395fe9ff68ac1d [file] [log] [blame]
Jordan Crouseaa6e3782008-05-07 20:43:15 +00001/*
2 * This file is part of the coreinfo project.
3 *
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Jordan Crouseaa6e3782008-05-07 20:43:15 +000014 */
15
16#include "coreinfo.h"
17
Stefan Reinauer04fb7a82015-06-29 16:08:39 -070018#if IS_ENABLED(CONFIG_MODULE_LAR)
Jordan Crouseaa6e3782008-05-07 20:43:15 +000019
20static struct LAR *lar;
Uwe Hermann941aaee2008-07-18 14:08:18 +000021static int lcount, selected;
Jordan Crouseaa6e3782008-05-07 20:43:15 +000022static char **lnames;
Uwe Hermann941aaee2008-07-18 14:08:18 +000023static const char *compression_table[4] = {"none", "LZMA", "NRV2B", "zeroes"};
Jordan Crouseaa6e3782008-05-07 20:43:15 +000024
25static int lar_module_init(void)
26{
27 int index = 0;
28 struct larent *larent;
29
30 lar = openlar(NULL);
31
32 if (lar == NULL)
33 return 0;
34
Uwe Hermann941aaee2008-07-18 14:08:18 +000035 while ((larent = readlar(lar)))
Jordan Crouseaa6e3782008-05-07 20:43:15 +000036 lcount++;
37
38 lnames = malloc(lcount * sizeof(char *));
39
40 if (lnames == NULL)
41 return 0;
42
43 rewindlar(lar);
44
Uwe Hermann941aaee2008-07-18 14:08:18 +000045 while ((larent = readlar(lar)))
Jordan Crouseaa6e3782008-05-07 20:43:15 +000046 lnames[index++] = strdup((const char *) larent->name);
47
48 return 0;
49}
50
Jordan Crouseaa6e3782008-05-07 20:43:15 +000051static int lar_module_redraw(WINDOW *win)
52{
Uwe Hermann941aaee2008-07-18 14:08:18 +000053 int i, row = 2;
Jordan Crouseaa6e3782008-05-07 20:43:15 +000054 struct larstat stat;
55
56 print_module_title(win, "LAR Listing");
57
58 if (lar == 0) {
Uwe Hermann695cff32008-08-07 14:35:39 +000059 mvwprintw(win, 11, 61 / 2, "Bad or missing LAR");
Jordan Crouseaa6e3782008-05-07 20:43:15 +000060 return 0;
61 }
62
Uwe Hermann941aaee2008-07-18 14:08:18 +000063 /* Draw a line down the middle. */
64 for (i = 2; i < 21; i++)
Ulf Jordand133d9a2008-08-11 20:35:32 +000065 mvwaddch(win, i, 30, ACS_VLINE);
Jordan Crouseaa6e3782008-05-07 20:43:15 +000066
Uwe Hermann941aaee2008-07-18 14:08:18 +000067 /* Draw the names down the left side. */
68 for (i = 0; i < lcount; i++) {
Jordan Crouseaa6e3782008-05-07 20:43:15 +000069 if (i == selected)
70 wattrset(win, COLOR_PAIR(3) | A_BOLD);
71 else
72 wattrset(win, COLOR_PAIR(2));
73
74 mvwprintw(win, 2 + i, 1, "%.25s", lnames[i]);
75 }
76
Uwe Hermann941aaee2008-07-18 14:08:18 +000077 /* Get the information for the LAR. */
Jordan Crouseaa6e3782008-05-07 20:43:15 +000078 if (larstat(lar, lnames[selected], &stat)) {
79 printf("larstat failed\n");
80 return 0;
81 }
82
83 wattrset(win, COLOR_PAIR(2));
84
85 mvwprintw(win, row++, 32, "Offset: 0x%x", stat.offset);
86
87 if (stat.compression) {
Uwe Hermann941aaee2008-07-18 14:08:18 +000088 mvwprintw(win, row++, 32, "Compression: %s",
89 compression_table[stat.compression]);
Jordan Crouseaa6e3782008-05-07 20:43:15 +000090 mvwprintw(win, row++, 32, "Compressed length: %d", stat.len);
Uwe Hermann941aaee2008-07-18 14:08:18 +000091 mvwprintw(win, row++, 32, "Compressed checksum: 0x%x",
92 stat.compchecksum);
Jordan Crouseaa6e3782008-05-07 20:43:15 +000093 }
94
95 mvwprintw(win, row++, 32, "Length: %d", stat.reallen);
96 mvwprintw(win, row++, 32, "Checksum: 0x%x", stat.checksum);
Uwe Hermann941aaee2008-07-18 14:08:18 +000097 mvwprintw(win, row++, 32, "Load address: 0x%llx", stat.loadaddress);
98 mvwprintw(win, row++, 32, "Entry point: 0x%llx", stat.entry);
Jordan Crouseaa6e3782008-05-07 20:43:15 +000099
100 return 0;
101}
102
103static int lar_module_handle(int key)
104{
105 int ret = 0;
106
107 if (lar == NULL)
108 return 0;
109
110 switch (key) {
111 case KEY_DOWN:
112 if (selected + 1 < lcount) {
113 selected++;
114 ret = 1;
115 }
116 break;
117 case KEY_UP:
118 if (selected > 0) {
119 selected--;
120 ret = 1;
121 }
122 break;
123 }
124
125 return ret;
126}
127
128struct coreinfo_module lar_module = {
129 .name = "LAR",
130 .init = lar_module_init,
131 .redraw = lar_module_redraw,
132 .handle = lar_module_handle
133};
Uwe Hermann941aaee2008-07-18 14:08:18 +0000134
Jordan Crouseaa6e3782008-05-07 20:43:15 +0000135#else
136
137struct coreinfo_module lar_module = {
138};
139
140#endif