]> Joshua Wise's Git repositories - netwatch.git/blame - net/http/fs.c
Remove some bogus and obsolete ich2 stuff from smi.c.
[netwatch.git] / net / http / fs.c
CommitLineData
6f9272bd
JW
1/*
2 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
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.
15 *
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
25 * OF SUCH DAMAGE.
26 *
27 * This file is part of the lwIP TCP/IP stack.
28 *
29 * Author: Adam Dunkels <adam@sics.se>
30 *
31 */
32#include "lwip/def.h"
33#include "fs.h"
34#include "fsdata.h"
35#include "fsdata.c"
923ea2c2 36#include <io.h>
9343e933
JW
37#include <minilib.h>
38#include <paging.h>
4e3ef36b 39#include <demap.h>
9343e933 40#include <output.h>
4e3ef36b 41#include <state.h>
6f9272bd 42
4e3ef36b 43static char http_output_buffer[1280];
db9fad13 44
6f9272bd
JW
45/*-----------------------------------------------------------------------------------*/
46
923ea2c2 47void handle_regs(struct fs_file *file)
6f9272bd 48{
4e3ef36b
JW
49 int i;
50 int len;
51
52 len = snprintf(http_output_buffer, sizeof(http_output_buffer), "<html><pre>");
53
8e7d9af0 54 for (i = 0; i < state_num_regs(); i++) {
4e3ef36b
JW
55 len += state_dump_reg(http_output_buffer + len, sizeof(http_output_buffer) - len, i);
56 }
57
58 file->len = len;
db9fad13 59 file->data = http_output_buffer;
923ea2c2
JW
60}
61
db9fad13
JAW
62#define LEFT (sizeof(http_output_buffer) - len)
63
9343e933
JW
64void handle_backtrace(struct fs_file *file)
65{
9343e933 66 int i = 10;
db9fad13 67 int len;
4e3ef36b
JW
68 void *pebp, *peip;
69 uint64_t bp, next;
70
71 int longmode = (get_operating_mode() == LONG_64BIT);
db9fad13
JAW
72
73 char * buf = http_output_buffer;
9343e933
JW
74
75 strcpy(buf, "<html><head><title>Backtrace</title></head><body><tt><pre>");
db9fad13 76 len = strlen(buf);
4e3ef36b 77
8e7d9af0 78 bp = state_get_reg(longmode ? STATE_REG_RIP : STATE_REG_EIP);
4e3ef36b
JW
79
80 if (longmode)
81 len += snprintf(buf + len, LEFT, "0x%08x%08x, from\n", (uint32_t)(bp >> 32), (uint32_t)bp);
82 else
83 len += snprintf(buf + len, LEFT, "0x%08x, from\n", (uint32_t)bp);
9343e933 84
8e7d9af0 85 bp = state_get_reg(longmode ? STATE_REG_RBP : STATE_REG_EBP);
9343e933 86
8e7d9af0
JW
87
88 outputf("Backtrace:");
4e3ef36b 89 while ((peip = demap(bp+(longmode?8:4))) != 0x0 && i--)
9343e933 90 {
4e3ef36b 91 if (longmode) {
8e7d9af0
JW
92 uint64_t rip;
93 rip = *(uint64_t *)peip;
94 len += snprintf(buf + len, LEFT, "0x%08x%08x, from\n", (uint32_t)(rip >> 32), (uint32_t)rip);
4e3ef36b 95 } else {
8e7d9af0 96 len += snprintf(buf + len, LEFT, "0x%08x, from\n", *(uint32_t *)peip);
4e3ef36b 97 }
8e7d9af0 98 outputf(" EIP: %08x", *(uint32_t *)peip);
4e3ef36b
JW
99
100 pebp = demap(bp);
8e7d9af0 101 if (!pebp || (bp & 3))
9343e933 102 {
4e3ef36b 103 len += snprintf(buf + len, LEFT, "&lt;unreadable frame&gt;\n");
9343e933
JW
104 break;
105 }
8e7d9af0 106 outputf(" *EBP: %08x", *(uint32_t *)pebp);
4e3ef36b
JW
107
108 if (longmode)
109 next = *(uint64_t *)pebp;
110 else
111 next = *(uint32_t *)pebp;
112
113 if (bp >= next && next)
9343e933 114 {
4e3ef36b 115 len += snprintf(buf + len, LEFT, "&lt;recursive frame&gt;\n");
9343e933
JW
116 break;
117 }
4e3ef36b
JW
118
119 bp = next;
9343e933 120 }
db9fad13 121
9343e933 122 if (i == -1)
db9fad13 123 len += snprintf(buf + len, LEFT, "...\n");
8e7d9af0
JW
124 else if (bp && !peip)
125 len += snprintf(buf + len, LEFT, "&lt;unreadable fp @ %08x&gt;\n", (uint32_t) bp);
9343e933 126 else
db9fad13
JAW
127 len += snprintf(buf + len, LEFT, "&lt;root&gt;");
128
129 len += snprintf(buf + len, LEFT, "</pre></tt></body></html>");
9343e933
JW
130
131 file->data = buf;
db9fad13 132 file->len = len;
9343e933
JW
133}
134
923ea2c2
JW
135void handle_reboot(struct fs_file *file)
136{
137 outb(0xCF9, 0x4);
138 file->data = "So long!";
139 file->len = 8;
6f9272bd
JW
140}
141
142
143/*-----------------------------------------------------------------------------------*/
144int
145fs_open(const char *name, struct fs_file *file)
146{
147 const struct fsdata_file *f;
148
149 /* /registers.html is CGI */
150 if (!strcmp(name, "/registers.html"))
151 {
923ea2c2
JW
152 handle_regs(file);
153 return 1;
154 }
9343e933
JW
155 if (!strcmp(name, "/backtrace.html"))
156 {
157 handle_backtrace(file);
158 return 1;
159 }
923ea2c2
JW
160 if (!strcmp(name, "/reboot"))
161 {
162 handle_reboot(file);
6f9272bd
JW
163 return 1;
164 }
165
166 for(f = FS_ROOT;
167 f != NULL;
168 f = f->next) {
169 if (!strcmp(name, (const char*)f->name)) {
170 file->data = f->data;
923ea2c2 171 file->len = f->len-1;
6f9272bd
JW
172 return 1;
173 }
174 }
175 file->data = "You clown...";
176 file->len = 9;
177 return 0;
178}
179/*-----------------------------------------------------------------------------------*/
This page took 0.047059 seconds and 4 git commands to generate.