1 /* $OpenBSD: cmd_i386.c,v 1.2 2024/04/25 18:31:49 kn Exp $ */
2
3 /*
4 * Copyright (c) 1997-1999 Michael Shalayeff
5 * Copyright (c) 1997 Tobias Weingartner
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31 #include <sys/param.h>
32 #include <sys/reboot.h>
33 #include <machine/biosvar.h>
34 #include <sys/disklabel.h>
35 #include "disk.h"
36 #include "biosdev.h"
37 #include "libsa.h"
38 #include <cmd.h>
39
40 #include "efiboot.h"
41 #include "efidev.h"
42
43 extern const char version[];
44
45 int Xboot(void);
46 int Xcomaddr(void);
47 int Xdiskinfo(void);
48 int Xmemory(void);
49 int Xregs(void);
50
51 /* From gidt.S */
52 int bootbuf(void *, int);
53
54 const struct cmd_table cmd_machine[] = {
55 { "comaddr", CMDT_CMD, Xcomaddr },
56 { "diskinfo", CMDT_CMD, Xdiskinfo },
57 { "memory", CMDT_CMD, Xmemory },
58 { "video", CMDT_CMD, Xvideo_efi },
59 { "gop", CMDT_CMD, Xgop_efi },
60 { "exit", CMDT_CMD, Xexit_efi },
61 { "poweroff", CMDT_CMD, Xpoweroff_efi },
62 #ifdef DEBUG
63 { "regs", CMDT_CMD, Xregs },
64 #endif
65 #ifdef IDLE_POWEROFF
66 { "idle", CMDT_CMD, Xidle_efi },
67 #endif
68 { NULL, 0 }
69 };
70
71 int
Xdiskinfo(void)72 Xdiskinfo(void)
73 {
74 efi_dump_diskinfo();
75 return 0;
76 }
77
78 #ifdef DEBUG
79 int
Xregs(void)80 Xregs(void)
81 {
82 DUMP_REGS;
83 return 0;
84 }
85 #endif
86
87 int
Xmemory(void)88 Xmemory(void)
89 {
90 if (cmd.argc >= 2) {
91 int i;
92 /* parse the memory specs */
93
94 for (i = 1; i < cmd.argc; i++) {
95 char *p;
96 long long addr, size;
97
98 p = cmd.argv[i];
99
100 size = strtoll(p + 1, &p, 0);
101 /* Size the size */
102 switch (*p) {
103 case 'G':
104 case 'g':
105 size *= 1024;
106 case 'M':
107 case 'm':
108 size *= 1024;
109 case 'K':
110 case 'k':
111 size *= 1024;
112 p++;
113 }
114
115 /* Handle (possibly non-existent) address part */
116 switch (*p) {
117 case '@':
118 addr = strtoll(p + 1, NULL, 0);
119 break;
120
121 /* Adjust address if we don't need it */
122 default:
123 if (cmd.argv[i][0] == '=')
124 addr = -1;
125 else
126 addr = 0;
127 }
128
129 if (addr == 0 || size == 0) {
130 printf("bad language\n");
131 return 0;
132 } else {
133 switch (cmd.argv[i][0]) {
134 case '-':
135 mem_delete(addr, addr + size);
136 break;
137 case '+':
138 mem_add(addr, addr + size);
139 break;
140 case '=':
141 mem_limit(size);
142 break;
143 default :
144 printf("bad OP\n");
145 return 0;
146 }
147 }
148 }
149 }
150
151 dump_biosmem(NULL);
152
153 return 0;
154 }
155
156 int
Xcomaddr(void)157 Xcomaddr(void)
158 {
159 extern int com_addr;
160
161 if (cmd.argc >= 2)
162 com_addr = (int)strtol(cmd.argv[1], NULL, 0);
163
164 return 0;
165 }
166