Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 1 | /* |
| 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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "coreinfo.h" |
| 21 | |
| 22 | #ifdef CONFIG_MODULE_LAR |
| 23 | |
| 24 | static struct LAR *lar; |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 25 | static int lcount, selected; |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 26 | static char **lnames; |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 27 | static const char *compression_table[4] = {"none", "LZMA", "NRV2B", "zeroes"}; |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 28 | |
| 29 | static int lar_module_init(void) |
| 30 | { |
| 31 | int index = 0; |
| 32 | struct larent *larent; |
| 33 | |
| 34 | lar = openlar(NULL); |
| 35 | |
| 36 | if (lar == NULL) |
| 37 | return 0; |
| 38 | |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 39 | while ((larent = readlar(lar))) |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 40 | lcount++; |
| 41 | |
| 42 | lnames = malloc(lcount * sizeof(char *)); |
| 43 | |
| 44 | if (lnames == NULL) |
| 45 | return 0; |
| 46 | |
| 47 | rewindlar(lar); |
| 48 | |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 49 | while ((larent = readlar(lar))) |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 50 | lnames[index++] = strdup((const char *) larent->name); |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 55 | static int lar_module_redraw(WINDOW *win) |
| 56 | { |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 57 | int i, row = 2; |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 58 | struct larstat stat; |
| 59 | |
| 60 | print_module_title(win, "LAR Listing"); |
| 61 | |
| 62 | if (lar == 0) { |
Uwe Hermann | 695cff3 | 2008-08-07 14:35:39 +0000 | [diff] [blame] | 63 | mvwprintw(win, 11, 61 / 2, "Bad or missing LAR"); |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 64 | return 0; |
| 65 | } |
| 66 | |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 67 | /* Draw a line down the middle. */ |
| 68 | for (i = 2; i < 21; i++) |
Ulf Jordan | d133d9a | 2008-08-11 20:35:32 +0000 | [diff] [blame] | 69 | mvwaddch(win, i, 30, ACS_VLINE); |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 70 | |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 71 | /* Draw the names down the left side. */ |
| 72 | for (i = 0; i < lcount; i++) { |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 73 | if (i == selected) |
| 74 | wattrset(win, COLOR_PAIR(3) | A_BOLD); |
| 75 | else |
| 76 | wattrset(win, COLOR_PAIR(2)); |
| 77 | |
| 78 | mvwprintw(win, 2 + i, 1, "%.25s", lnames[i]); |
| 79 | } |
| 80 | |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 81 | /* Get the information for the LAR. */ |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 82 | if (larstat(lar, lnames[selected], &stat)) { |
| 83 | printf("larstat failed\n"); |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | wattrset(win, COLOR_PAIR(2)); |
| 88 | |
| 89 | mvwprintw(win, row++, 32, "Offset: 0x%x", stat.offset); |
| 90 | |
| 91 | if (stat.compression) { |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 92 | mvwprintw(win, row++, 32, "Compression: %s", |
| 93 | compression_table[stat.compression]); |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 94 | mvwprintw(win, row++, 32, "Compressed length: %d", stat.len); |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 95 | mvwprintw(win, row++, 32, "Compressed checksum: 0x%x", |
| 96 | stat.compchecksum); |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | mvwprintw(win, row++, 32, "Length: %d", stat.reallen); |
| 100 | mvwprintw(win, row++, 32, "Checksum: 0x%x", stat.checksum); |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 101 | mvwprintw(win, row++, 32, "Load address: 0x%llx", stat.loadaddress); |
| 102 | mvwprintw(win, row++, 32, "Entry point: 0x%llx", stat.entry); |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | static int lar_module_handle(int key) |
| 108 | { |
| 109 | int ret = 0; |
| 110 | |
| 111 | if (lar == NULL) |
| 112 | return 0; |
| 113 | |
| 114 | switch (key) { |
| 115 | case KEY_DOWN: |
| 116 | if (selected + 1 < lcount) { |
| 117 | selected++; |
| 118 | ret = 1; |
| 119 | } |
| 120 | break; |
| 121 | case KEY_UP: |
| 122 | if (selected > 0) { |
| 123 | selected--; |
| 124 | ret = 1; |
| 125 | } |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | struct coreinfo_module lar_module = { |
| 133 | .name = "LAR", |
| 134 | .init = lar_module_init, |
| 135 | .redraw = lar_module_redraw, |
| 136 | .handle = lar_module_handle |
| 137 | }; |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 138 | |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 139 | #else |
| 140 | |
| 141 | struct coreinfo_module lar_module = { |
| 142 | }; |
| 143 | |
| 144 | #endif |