cp: revamp directory handling
[hvf.git] / cp / shell / cmd_store.c
blob1e6a976f9916d5c037d27ad3889176c1006f4674
1 /*
2 * (C) Copyright 2007-2010 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
5 * details.
6 */
8 /*
9 *!!! STORE STORAGE
10 *!! SYNTAX
11 *! \cbstart
12 *! \tok{\sc STOre} \tok{\sc STOrage} <address> <value>
13 *! \cbend
14 *!! XATNYS
15 *!! AUTH G
16 *!! PURPOSE
17 *! Sets a word in guest's storage at address to value
19 static int cmd_store_storage(struct virt_sys *sys, char *cmd, int len)
21 int ret;
22 u64 guest_addr, host_addr;
23 u64 val = 0;
25 SHELL_CMD_AUTH(sys, G);
27 cmd = parse_addrspec(&guest_addr, NULL, cmd);
28 if (IS_ERR(cmd)) {
29 con_printf(sys->con, "STORE: Invalid addr-spec\n");
30 return PTR_ERR(cmd);
33 /* consume any extra whitespace */
34 cmd = __consume_ws(cmd);
36 /* get the value */
37 cmd = __extract_hex(cmd, &val);
38 if (IS_ERR(cmd))
39 return PTR_ERR(cmd);
42 * round down to the nearest word
44 guest_addr &= ~((u64) 3ULL);
46 /* walk the page tables to find the real page frame */
47 ret = virt2phy_current(guest_addr, &host_addr);
48 if (ret) {
49 con_printf(sys->con, "STORE: Specified address is not part of "
50 "guest configuration\n");
51 return ret;
54 *((u32*) host_addr) = (u32) val;
56 con_printf(sys->con, "Store complete.\n");
58 return 0;
62 *!!! STORE GPR
63 *!! SYNTAX
64 *! \tok{\sc STOre} \tok{\sc Gpr} <gpr> <value>
65 *!! XATNYS
66 *!! AUTH G
67 *!! PURPOSE
68 *! Sets a guest's general purpose register to the specified value
70 static int cmd_store_gpr(struct virt_sys *sys, char *cmd, int len)
72 u64 *ptr = (u64*) &sys->task->cpu->regs.gpr;
73 u64 val, gpr;
75 SHELL_CMD_AUTH(sys, G);
77 cmd = __extract_dec(cmd, &gpr);
78 if (IS_ERR(cmd))
79 return PTR_ERR(cmd);
80 if (gpr > 15)
81 return -EINVAL;
83 cmd = __consume_ws(cmd);
85 cmd = __extract_hex(cmd, &val);
86 if (IS_ERR(cmd))
87 return PTR_ERR(cmd);
89 ptr[gpr] = val;
91 con_printf(sys->con, "Store complete.\n");
93 return 0;
97 *!!! STORE FPR
98 *!! SYNTAX
99 *! \tok{\sc STOre} \tok{\sc Fpr} <fpr> <value>
100 *!! XATNYS
101 *!! AUTH G
102 *!! PURPOSE
103 *! Sets a guest's floating point register to the specified value
105 static int cmd_store_fpr(struct virt_sys *sys, char *cmd, int len)
107 u64 *ptr = (u64*) &sys->task->cpu->regs.fpr;
108 u64 val, fpr;
110 SHELL_CMD_AUTH(sys, G);
112 cmd = __extract_dec(cmd, &fpr);
113 if (IS_ERR(cmd))
114 return PTR_ERR(cmd);
115 if (fpr > 15)
116 return -EINVAL;
118 cmd = __consume_ws(cmd);
120 cmd = __extract_hex(cmd, &val);
121 if (IS_ERR(cmd))
122 return PTR_ERR(cmd);
124 ptr[fpr] = val;
126 con_printf(sys->con, "Store complete.\n");
128 return 0;
132 *!!! STORE FPCR
133 *!! SYNTAX
134 *! \tok{\sc STOre} \tok{\sc FPCR} <value>
135 *!! XATNYS
136 *!! AUTH G
137 *!! PURPOSE
138 *! Sets a guest's floating point control register to the specified value
140 static int cmd_store_fpcr(struct virt_sys *sys, char *cmd, int len)
142 u64 val;
144 SHELL_CMD_AUTH(sys, G);
146 cmd = __extract_hex(cmd, &val);
147 if (IS_ERR(cmd))
148 return PTR_ERR(cmd);
149 if (val > 0xffffffffULL)
150 return -EINVAL;
152 sys->task->cpu->regs.fpcr = (u32) val;
154 con_printf(sys->con, "Store complete.\n");
156 return 0;
160 *!!! STORE CR
161 *!! SYNTAX
162 *! \tok{\sc STOre} \tok{\sc Cr} <cr> <value>
163 *!! XATNYS
164 *!! AUTH G
165 *!! PURPOSE
166 *! Sets a guest's control register to the specified value
168 static int cmd_store_cr(struct virt_sys *sys, char *cmd, int len)
170 u64 *ptr = (u64*) &sys->task->cpu->sie_cb.gcr;
171 u64 val, cr;
173 SHELL_CMD_AUTH(sys, G);
175 cmd = __extract_dec(cmd, &cr);
176 if (IS_ERR(cmd))
177 return PTR_ERR(cmd);
178 if (cr > 15)
179 return -EINVAL;
181 cmd = __consume_ws(cmd);
183 cmd = __extract_hex(cmd, &val);
184 if (IS_ERR(cmd))
185 return PTR_ERR(cmd);
187 ptr[cr] = val;
189 con_printf(sys->con, "Store complete.\n");
191 return 0;
195 *!!! STORE AR
196 *!! SYNTAX
197 *! \tok{\sc STOre} \tok{\sc Ar} <ar> <value>
198 *!! XATNYS
199 *!! AUTH G
200 *!! PURPOSE
201 *! Sets a guest's access register to the specified value
203 static int cmd_store_ar(struct virt_sys *sys, char *cmd, int len)
205 u32 *ptr = (u32*) &sys->task->cpu->regs.ar;
206 u64 val, ar;
208 SHELL_CMD_AUTH(sys, G);
210 cmd = __extract_dec(cmd, &ar);
211 if (IS_ERR(cmd))
212 return PTR_ERR(cmd);
213 if (ar > 15)
214 return -EINVAL;
216 cmd = __consume_ws(cmd);
218 cmd = __extract_hex(cmd, &val);
219 if (IS_ERR(cmd))
220 return PTR_ERR(cmd);
221 if (val > 0xffffffffULL)
222 return -EINVAL;
224 ptr[ar] = val;
226 con_printf(sys->con, "Store complete.\n");
228 return 0;
232 *!!! STORE PSW
233 *!! SYNTAX
234 *! \cbstart
235 *! \tok{\sc STOre} \tok{\sc PSW}
236 *! \begin{stack} \\
237 *! \begin{stack} \\
238 *! \begin{stack} \\ <hexword1>
239 *! \end{stack} <hexword2>
240 *! \end{stack} <hexword3>
241 *! \end{stack}
242 *! <hexword4>
243 *! \cbend
244 *!! XATNYS
245 *!! AUTH G
246 *!! PURPOSE
247 *! \cbstart
248 *! Alters all or a part of the PSW.
249 *! \cbend
250 *!! OPERANDS
251 *! \cbstart
252 *! \item[hexword...]
253 *! \textbf{For an ESA/390 guest:}
255 *! Alters all or part of the PSW with the data specified in hexword3
256 *! and hexword4. If only hexword4 is specified, it is stored to PSW bits
257 *! 32-63. If hexword3 and hexword4 are specified, hexword3 is stored to
258 *! PSW bits 0-31, and hexword4 to PSW bits 32-63.
260 *! If more than two values are specified, the PSW remains unchanged and an
261 *! message indicating an error is printed.
263 *! \textbf{For a z/Architecture guest:}
265 *! If only one hexword4 is specified, PSW bits 96-127 are set to it.
267 *! If hexword3 and hexword4 are specified, PSW bits 64-95 are set to
268 *! hexword3, and bits 96-127 are set to hexword4.
270 *! If hexword2, hexword3, and hexword4 are specified, PSW bits 32-63 are
271 *! set to hexword2, bits 64-95 are set to hexword3, and bits 96-127 are
272 *! set to hexword4.
274 *! If hexword1, hexword2, hexword3, and hexword4 are specified, PSW bits
275 *! 0-31 are set to hexword1, bits 32-63 are set to hexword2, bits 64-95
276 *! are set to hexword3, and bits 96-127 are set to hexword4.
277 *! \cbend
278 *!! SDNAREPO
280 static int cmd_store_psw(struct virt_sys *sys, char *cmd, int len)
282 u32 *ptr = (u32*) &sys->task->cpu->sie_cb.gpsw;
284 u64 new_words[4] = {0, 0, 0, 0};
285 int cnt;
287 SHELL_CMD_AUTH(sys, G);
289 for (cnt=0; cnt<4; cnt++) {
290 cmd = __extract_hex(cmd, &new_words[cnt]);
291 if (IS_ERR(cmd))
292 break;
294 cmd = __consume_ws(cmd);
297 if (!cnt)
298 return -EINVAL;
300 if (!VCPU_ZARCH(sys->task->cpu)) {
301 /* ESA/390 mode */
302 if (cnt > 2) {
303 con_printf(sys->con, "STORE: ERROR ESA/390 PSW USES ONLY TWO WORDS\n");
304 return -EINVAL;
308 * This is a simple "hack" to make the stores go into the
309 * right place. If he had a single word, we want it to go
310 * the the second word of the 16-byte PSW, not the 4th.
311 * Similarly, if we had two words, we want them to go into
312 * the first and second words of the 16-byte PSW.
314 cnt += 2;
317 switch(cnt) {
318 case 4:
319 ptr[0] = (u32) new_words[0];
320 ptr[1] = (u32) new_words[1];
321 ptr[2] = (u32) new_words[2];
322 ptr[3] = (u32) new_words[3];
323 break;
324 case 3:
325 ptr[1] = (u32) new_words[0];
326 ptr[2] = (u32) new_words[1];
327 ptr[3] = (u32) new_words[2];
328 break;
329 case 2:
330 ptr[2] = (u32) new_words[0];
331 ptr[3] = (u32) new_words[1];
332 break;
333 case 1:
334 ptr[3] = (u32) new_words[0];
335 break;
336 case 0:
337 return -EINVAL;
340 con_printf(sys->con, "Store complete.\n");
341 return 0;
344 static struct cpcmd cmd_tbl_store[] = {
345 {"AR", cmd_store_ar, NULL},
346 {"A", cmd_store_ar, NULL},
348 {"CR", cmd_store_cr, NULL},
349 {"C", cmd_store_cr, NULL},
351 {"FPCR", cmd_store_fpcr, NULL},
353 {"FPR", cmd_store_fpr, NULL},
354 {"FP", cmd_store_fpr, NULL},
355 {"F", cmd_store_fpr, NULL},
357 {"GPR", cmd_store_gpr, NULL},
358 {"GP", cmd_store_gpr, NULL},
359 {"G", cmd_store_gpr, NULL},
361 {"PSW", cmd_store_psw, NULL},
363 {"STORAGE", cmd_store_storage, NULL},
364 {"STORAG", cmd_store_storage, NULL},
365 {"STORA", cmd_store_storage, NULL},
366 {"STOR", cmd_store_storage, NULL},
367 {"STO", cmd_store_storage, NULL},
368 {"", NULL, NULL},