2 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 * This file is part of the lwIP TCP/IP stack.
29 * Author: Adam Dunkels <adam@sics.se>
43 static char http_output_buffer[1280];
45 /*-----------------------------------------------------------------------------------*/
47 void handle_regs(struct fs_file *file)
52 len = snprintf(http_output_buffer, sizeof(http_output_buffer), "<html><pre>");
54 for (i = 0; i < NUM_REGISTERS; i++) {
55 len += state_dump_reg(http_output_buffer + len, sizeof(http_output_buffer) - len, i);
59 file->data = http_output_buffer;
62 #define LEFT (sizeof(http_output_buffer) - len)
64 void handle_backtrace(struct fs_file *file)
71 int longmode = (get_operating_mode() == LONG_64BIT);
73 char * buf = http_output_buffer;
75 strcpy(buf, "<html><head><title>Backtrace</title></head><body><tt><pre>");
78 bp = state_get_reg(STATE_REG_RIP);
81 len += snprintf(buf + len, LEFT, "0x%08x%08x, from\n", (uint32_t)(bp >> 32), (uint32_t)bp);
83 len += snprintf(buf + len, LEFT, "0x%08x, from\n", (uint32_t)bp);
85 bp = state_get_reg(STATE_REG_RBP);
87 /* I never thought I'd do this again. */
88 while ((peip = demap(bp+(longmode?8:4))) != 0x0 && i--)
91 next = *(uint64_t *)peip;
92 len += snprintf(buf + len, LEFT, "0x%08x%08x, from\n", (uint32_t)(next >> 32), (uint32_t)next);
94 next = *(uint32_t *)peip;
95 len += snprintf(buf + len, LEFT, "0x%08x, from\n", (uint32_t)next);
102 len += snprintf(buf + len, LEFT, "<unreadable frame>\n");
107 next = *(uint64_t *)pebp;
109 next = *(uint32_t *)pebp;
111 if (bp >= next && next)
113 len += snprintf(buf + len, LEFT, "<recursive frame>\n");
121 len += snprintf(buf + len, LEFT, "...\n");
123 len += snprintf(buf + len, LEFT, "<root>");
125 len += snprintf(buf + len, LEFT, "</pre></tt></body></html>");
131 void handle_reboot(struct fs_file *file)
134 file->data = "So long!";
139 /*-----------------------------------------------------------------------------------*/
141 fs_open(const char *name, struct fs_file *file)
143 const struct fsdata_file *f;
145 /* /registers.html is CGI */
146 if (!strcmp(name, "/registers.html"))
151 if (!strcmp(name, "/backtrace.html"))
153 handle_backtrace(file);
156 if (!strcmp(name, "/reboot"))
165 if (!strcmp(name, (const char*)f->name)) {
166 file->data = f->data;
167 file->len = f->len-1;
171 file->data = "You clown...";
175 /*-----------------------------------------------------------------------------------*/