]> Joshua Wise's Git repositories - netwatch.git/blame_incremental - net/http/fs.c
Correct header from smram-ich2.c.
[netwatch.git] / net / http / fs.c
... / ...
CommitLineData
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"
36#include <io.h>
37#include <minilib.h>
38#include <paging.h>
39#include <demap.h>
40#include <output.h>
41#include <state.h>
42
43static char http_output_buffer[1280];
44
45/*-----------------------------------------------------------------------------------*/
46
47void handle_regs(struct fs_file *file)
48{
49 int i;
50 int len;
51
52 len = snprintf(http_output_buffer, sizeof(http_output_buffer), "<html><pre>");
53
54 for (i = 0; i < NUM_REGISTERS; i++) {
55 len += state_dump_reg(http_output_buffer + len, sizeof(http_output_buffer) - len, i);
56 }
57
58 file->len = len;
59 file->data = http_output_buffer;
60}
61
62#define LEFT (sizeof(http_output_buffer) - len)
63
64void handle_backtrace(struct fs_file *file)
65{
66 int i = 10;
67 int len;
68 void *pebp, *peip;
69 uint64_t bp, next;
70
71 int longmode = (get_operating_mode() == LONG_64BIT);
72
73 char * buf = http_output_buffer;
74
75 strcpy(buf, "<html><head><title>Backtrace</title></head><body><tt><pre>");
76 len = strlen(buf);
77
78 bp = state_get_reg(STATE_REG_RIP);
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);
84
85 bp = state_get_reg(STATE_REG_RBP);
86
87 /* I never thought I'd do this again. */
88 while ((peip = demap(bp+(longmode?8:4))) != 0x0 && i--)
89 {
90 if (longmode) {
91 next = *(uint64_t *)peip;
92 len += snprintf(buf + len, LEFT, "0x%08x%08x, from\n", (uint32_t)(next >> 32), (uint32_t)next);
93 } else {
94 next = *(uint32_t *)peip;
95 len += snprintf(buf + len, LEFT, "0x%08x, from\n", (uint32_t)next);
96 }
97
98 pebp = demap(bp);
99
100 if (!pebp)
101 {
102 len += snprintf(buf + len, LEFT, "&lt;unreadable frame&gt;\n");
103 break;
104 }
105
106 if (longmode)
107 next = *(uint64_t *)pebp;
108 else
109 next = *(uint32_t *)pebp;
110
111 if (bp >= next && next)
112 {
113 len += snprintf(buf + len, LEFT, "&lt;recursive frame&gt;\n");
114 break;
115 }
116
117 bp = next;
118 }
119
120 if (i == -1)
121 len += snprintf(buf + len, LEFT, "...\n");
122 else
123 len += snprintf(buf + len, LEFT, "&lt;root&gt;");
124
125 len += snprintf(buf + len, LEFT, "</pre></tt></body></html>");
126
127 file->data = buf;
128 file->len = len;
129}
130
131void handle_reboot(struct fs_file *file)
132{
133 outb(0xCF9, 0x4);
134 file->data = "So long!";
135 file->len = 8;
136}
137
138
139/*-----------------------------------------------------------------------------------*/
140int
141fs_open(const char *name, struct fs_file *file)
142{
143 const struct fsdata_file *f;
144
145 /* /registers.html is CGI */
146 if (!strcmp(name, "/registers.html"))
147 {
148 handle_regs(file);
149 return 1;
150 }
151 if (!strcmp(name, "/backtrace.html"))
152 {
153 handle_backtrace(file);
154 return 1;
155 }
156 if (!strcmp(name, "/reboot"))
157 {
158 handle_reboot(file);
159 return 1;
160 }
161
162 for(f = FS_ROOT;
163 f != NULL;
164 f = f->next) {
165 if (!strcmp(name, (const char*)f->name)) {
166 file->data = f->data;
167 file->len = f->len-1;
168 return 1;
169 }
170 }
171 file->data = "You clown...";
172 file->len = 9;
173 return 0;
174}
175/*-----------------------------------------------------------------------------------*/
This page took 0.028204 seconds and 4 git commands to generate.