* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / bootblocks / monitor.c
blob8e24cfff4a881c2d7de48e755ae0afce4d11dc7d
2 #include "monitor.h"
3 #include "version.h"
5 char command_buf[256];
7 typedef int (*proc)();
9 int cmd_quit(), cmd_dump(), cmd_seg(), cmd_rel(), cmd_bzimage(), cmd_help();
10 int cmd_nop(), cmd_memdump(), cmd_set_base(), cmd_dir(), cmd_type(), cmd_more();
11 int cmd_regs(), cmd_monhelp();
13 void init_prog();
15 extern struct t_cmd_list {
16 char * command;
17 proc func;
18 } cmd_list[];
20 unsigned int current_address;
21 int number_base = 16;
23 main()
25 static char minibuf[2] = " ";
26 int ch, i;
27 char *cmd, *args, *ptr;
28 struct t_cmd_list * cptr;
30 #ifdef __STANDALONE__
31 printf("\r\n");
32 #endif
34 init_prog();
36 if (!x86_test)
38 #ifdef __STANDALONE__
39 #ifndef NOCOMMAND
40 #if 0
41 /* First out of the way. */
42 relocator(3);
43 /* Then align DS to 64k boundry -> DMA is simple. */
44 relocator(0x1000-__get_ds()+__get_cs());
45 #else
46 relocator(-1); /* Top of available memory */
47 #endif
48 printf("Relocated to CS=$%04x DS=$%04x\n", __get_cs(), __get_ds());
49 #endif
51 disk_drive = __argr.h.dl;
52 #endif
53 #ifdef NOCOMMAND
54 cmd_type("help.txt");
55 #else
56 display_help(0);
57 #endif
58 cmd_bzimage((void*)0);
61 #ifdef NOCOMMAND
62 printf("Unable to boot, sorry\nreboot:");
63 fflush(stdout);
64 read(0, command_buf, sizeof(command_buf)-1) ;
65 #else
66 for (;;)
68 #ifdef COLOUR
69 printf("\033S \033R+\033Sa\033Rc");
70 #endif
71 printf(">");
72 fflush(stdout);
73 ch = read(0, command_buf, sizeof(command_buf)-1) ;
74 if( ch <= 0 ) break;
75 command_buf[ch] = '\0';
76 if( ch == 1 && command_buf[0] != '\n' )
78 putchar('\n');
79 help_key(command_buf[0]&0xFF);
80 continue;
82 if( command_buf[ch-1] == '\n' ) command_buf[ch-1] = 0;
84 for(ptr=command_buf; *ptr; ptr++)
86 if(*ptr=='"') do { ptr++; } while(*ptr && *ptr != '"');
87 if( isupper(*ptr) ) *ptr = tolower(*ptr);
90 cmd = command_buf;
91 while(*cmd == ' ') cmd++;
92 if( !isalpha(cmd[0]) || !isalpha(cmd[1]) )
94 minibuf[0] = cmd[0];
95 args = cmd+1;
96 cmd = minibuf;
98 else
100 args = strchr(cmd, ' ');
101 if( args ) *args++ = 0;
102 else args = cmd + strlen(cmd);
105 if( *cmd == 0 ) continue;
107 for(cptr = cmd_list; cptr->command; cptr++)
109 if( strcmp(cptr->command, cmd) == 0 )
110 break;
112 #ifdef COLOUR
113 printf("\033S \033Sa\033Rg");
114 #endif
115 fflush(stdout);
116 if( cptr->command )
117 (void) (*cptr->func)(args);
118 else
119 printf("Command not found.\n");
121 #endif
124 /****************************************************************************/
126 void init_prog()
128 char offt;
129 #ifdef COLOUR
130 vt52_putch(0);
131 printf("\033E\033Rg\033Sa\033J");
132 #endif
133 printf("Linux x86");
134 #ifdef NOCOMMAND
135 #ifdef TARFLOPPY
136 printf(" TAR floppy booter");
137 #else
138 #ifdef DOSFLOPPY
139 printf(" DOS floppy booter");
140 #else
141 printf(" floppy booter");
142 #endif
143 #endif
144 #else
145 printf(" boot monitor");
146 #endif
147 printf(", Version %s", VERSION);
148 printf(".\n");
150 cpu_check();
151 mem_check();
153 #ifndef NOMONITOR
154 printf("Processor: %s", x86_name);
155 if(x86_fpu) printf(" with FPU");
156 if(x86_emu) printf(" in protected mode");
157 printf("\n");
158 #endif
160 printf("There is %u bytes available", &offt-sbrk(0));
161 printf(", %dk of boot memory", boot_mem_top/64);
162 if( main_mem_top )
164 printf(", %d.%dM of main memory",
165 (int)(main_mem_top/1024),
166 (int)((10*main_mem_top)/1024%10));
168 printf(".\n");
171 /****************************************************************************/
174 getnum(numptr, valptr)
175 char ** numptr;
176 unsigned int * valptr;
178 char * ptr = *numptr;
179 unsigned int val = 0;
180 int base = number_base;
181 int flg = 0;
183 while( *ptr && *ptr <= ' ' ) ptr++;
184 switch(*ptr)
186 case '$': case '&': case 'X':
187 base=16; ptr++; break;
188 case '#':
189 base=10; ptr++; break;
190 case '%':
191 base=2; ptr++; break;
192 case '0':
193 if( ptr[1] == 'X' ) { base=16; ptr+=2; }
194 break;
195 case '-':
196 *numptr = ptr+1;
197 return 0;
200 while(*ptr)
202 int d = -1, ch;
203 ch = *ptr;
204 if( ch >= '0' && ch <= '9' ) d = ch - '0';
205 if( ch >= 'a' && ch <= 'z' ) d = ch - 'a' + 10;
206 if( ch >= 'A' && ch <= 'Z' ) d = ch - 'A' + 10;
208 if( d>=0 && d<base )
210 val = val * base + d;
211 ptr++;
212 flg=1;
214 else
215 break;
217 if( flg )
219 *numptr = ptr;
220 if(valptr) *valptr = val;
221 else return val;
223 return flg;
226 /****************************************************************************/
228 #ifndef NOCOMMAND
229 struct t_cmd_list cmd_list[] =
231 {"zimage", cmd_bzimage}, /* Load and run 386 zimage file */
232 {"bzimage",cmd_bzimage}, /* Load and run 386 bzimage file */
233 {"=", cmd_bzimage}, /* Load and run 386 bzimage file */
235 {"exit", cmd_quit}, {"quit", cmd_quit}, {"q", cmd_quit},
236 {"#", cmd_nop},
237 {"help", cmd_help}, /* Display from help.txt */
238 {"dir", cmd_dir}, /* Display directory */
239 {"cat", cmd_type}, /* Cat/Type a file to the screen */
240 {"type", cmd_type}, /* Cat/Type a file to the screen */
241 {"more", cmd_more}, /* More a file to the screen */
243 #ifndef NOMONITOR
244 /* Debugger/monitor commands */
245 {"?", cmd_monhelp}, /* Display builtin help */
247 {"memdump",cmd_memdump}, {"mem",cmd_memdump}, {"m", cmd_memdump},
248 /* Display bytes */
249 {"seg", cmd_seg}, /* Set default segment */
250 {"rel", cmd_rel}, /* Relocate self */
251 {"base", cmd_set_base},
252 {"n", cmd_set_base},
254 {"init", init_prog},
255 {"regs", cmd_regs},
256 {"reg", cmd_regs},
257 {"r", cmd_regs},
260 {"edit", cmd_edit}, Alter memory
261 {"move", cmd_move}, Move memory contents
263 {"load", cmd_load}, Load file of inode
264 {"stat", cmd_stat}, Stat info of inode
266 {"image", cmd_image}, Load and run 8086 image file
268 {"read", cmd_read}, Read sector
269 {"write", cmd_write}, Write sector
271 {"call", cmd_call}, load and run a bcc linux-8086 program.
273 #endif
275 {0,0}
277 #endif