3 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 #ifdef CONFIG_AMIGAONEG3SE
33 int console_changed = 0;
36 #ifdef CFG_CONSOLE_IS_IN_ENV
38 * if overwrite_console returns 1, the stdin, stderr and stdout
39 * are switched to the serial port, else the settings in the
40 * environment are used
42 #ifdef CFG_CONSOLE_OVERWRITE_ROUTINE
43 extern int overwrite_console (void);
45 int overwrite_console (void)
49 #endif /* CFG_CONSOLE_OVERWRITE_ROUTINE */
51 #endif /* CFG_CONSOLE_IS_IN_ENV */
53 static int console_setfile (int file, device_t * dev)
64 /* Start new device */
66 error = dev->start ();
67 /* If it's not started dont use it */
72 /* Assign the new device (leaving the existing one started) */
73 stdio_devices[file] = dev;
76 * Update monitor functions
77 * (to use the console stuff by other applications)
81 syscall_tbl[SYSCALL_GETC] = dev->getc;
82 syscall_tbl[SYSCALL_TSTC] = dev->tstc;
85 syscall_tbl[SYSCALL_PUTC] = dev->putc;
86 syscall_tbl[SYSCALL_PUTS] = dev->puts;
87 syscall_tbl[SYSCALL_PRINTF] = printf;
92 default: /* Invalid file ID */
98 /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/
100 void serial_printf (const char *fmt, ...)
104 char printbuffer[CFG_PBSIZE];
106 va_start (args, fmt);
108 /* For this to work, printbuffer must be larger than
109 * anything we ever want to print.
111 i = vsprintf (printbuffer, fmt, args);
114 serial_puts (printbuffer);
119 if (file < MAX_FILES)
120 return stdio_devices[file]->getc ();
127 if (file < MAX_FILES)
128 return stdio_devices[file]->tstc ();
133 void fputc (int file, const char c)
135 if (file < MAX_FILES)
136 stdio_devices[file]->putc (c);
139 void fputs (int file, const char *s)
141 if (file < MAX_FILES)
142 stdio_devices[file]->puts (s);
145 void fprintf (int file, const char *fmt, ...)
149 char printbuffer[CFG_PBSIZE];
151 va_start (args, fmt);
153 /* For this to work, printbuffer must be larger than
154 * anything we ever want to print.
156 i = vsprintf (printbuffer, fmt, args);
159 /* Send to desired file */
160 fputs (file, printbuffer);
163 /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/
167 DECLARE_GLOBAL_DATA_PTR;
169 if (gd->flags & GD_FLG_DEVINIT) {
170 /* Get from the standard input */
171 return fgetc (stdin);
174 /* Send directly to the handler */
175 return serial_getc ();
180 DECLARE_GLOBAL_DATA_PTR;
182 if (gd->flags & GD_FLG_DEVINIT) {
183 /* Test the standard input */
184 return ftstc (stdin);
187 /* Send directly to the handler */
188 return serial_tstc ();
191 void putc (const char c)
193 DECLARE_GLOBAL_DATA_PTR;
195 if (gd->flags & GD_FLG_DEVINIT) {
196 /* Send to the standard output */
199 /* Send directly to the handler */
204 void puts (const char *s)
206 DECLARE_GLOBAL_DATA_PTR;
208 if (gd->flags & GD_FLG_DEVINIT) {
209 /* Send to the standard output */
212 /* Send directly to the handler */
217 void printf (const char *fmt, ...)
221 char printbuffer[CFG_PBSIZE];
223 va_start (args, fmt);
225 /* For this to work, printbuffer must be larger than
226 * anything we ever want to print.
228 i = vsprintf (printbuffer, fmt, args);
231 /* Print the string */
235 /* test if ctrl-c was pressed */
236 static int ctrlc_disabled = 0; /* see disable_ctrl() */
237 static int ctrlc_was_pressed = 0;
240 DECLARE_GLOBAL_DATA_PTR;
242 if (!ctrlc_disabled && gd->have_console) {
245 case 0x03: /* ^C - Control C */
246 ctrlc_was_pressed = 1;
256 /* pass 1 to disable ctrlc() checking, 0 to enable.
257 * returns previous state
259 int disable_ctrlc (int disable)
261 int prev = ctrlc_disabled; /* save previous state */
263 ctrlc_disabled = disable;
269 return ctrlc_was_pressed;
272 void clear_ctrlc (void)
274 ctrlc_was_pressed = 0;
277 #ifdef CONFIG_MODEM_SUPPORT_DEBUG
279 char *cursor = screen;
281 inline void dbg(const char *fmt, ...)
285 char printbuffer[CFG_PBSIZE];
288 memset(screen, 0, sizeof(screen));
294 /* For this to work, printbuffer must be larger than
295 * anything we ever want to print.
297 i = vsprintf(printbuffer, fmt, args);
300 if ((screen + sizeof(screen) - 1 - cursor) < strlen(printbuffer)+1) {
301 memset(screen, 0, sizeof(screen));
304 sprintf(cursor, printbuffer);
305 cursor += strlen(printbuffer);
309 inline void dbg(const char *fmt, ...)
314 /** U-Boot INIT FUNCTIONS *************************************************/
316 int console_assign (int file, char *devname)
320 /* Check for valid file */
323 flag = DEV_FLAGS_INPUT;
327 flag = DEV_FLAGS_OUTPUT;
333 /* Check for valid device name */
335 for (i = 1; i <= ListNumItems (devlist); i++) {
336 device_t *dev = ListGetPtrToItem (devlist, i);
338 if (strcmp (devname, dev->name) == 0) {
339 if (dev->flags & flag)
340 return console_setfile (file, dev);
349 /* Called before relocation - use serial functions */
350 int console_init_f (void)
352 DECLARE_GLOBAL_DATA_PTR;
354 gd->have_console = 1;
358 #ifdef CFG_CONSOLE_IS_IN_ENV
359 /* search a device */
360 device_t *search_device (int flags, char *name)
363 device_t *dev = NULL;
365 items = ListNumItems (devlist);
369 for (i = 1; i <= items; i++) {
370 dev = ListGetPtrToItem (devlist, i);
371 if ((dev->flags & flags) && (strcmp (name, dev->name) == 0)) {
377 #endif /* CFG_CONSOLE_IS_IN_ENV */
379 #ifdef CFG_CONSOLE_IS_IN_ENV
380 /* Called after the relocation - use desired console functions */
381 int console_init_r (void)
383 char *stdinname, *stdoutname, *stderrname;
384 device_t *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
386 /* set default handlers at first */
387 syscall_tbl[SYSCALL_GETC] = serial_getc;
388 syscall_tbl[SYSCALL_TSTC] = serial_tstc;
389 syscall_tbl[SYSCALL_PUTC] = serial_putc;
390 syscall_tbl[SYSCALL_PUTS] = serial_puts;
391 syscall_tbl[SYSCALL_PRINTF] = serial_printf;
393 /* stdin stdout and stderr are in environment */
395 stdinname = getenv ("stdin");
396 stdoutname = getenv ("stdout");
397 stderrname = getenv ("stderr");
399 if (overwrite_console () == 0) { /* if not overwritten by config switch */
400 inputdev = search_device (DEV_FLAGS_INPUT, stdinname);
401 outputdev = search_device (DEV_FLAGS_OUTPUT, stdoutname);
402 errdev = search_device (DEV_FLAGS_OUTPUT, stderrname);
404 /* if the devices are overwritten or not found, use default device */
405 if (inputdev == NULL) {
406 inputdev = search_device (DEV_FLAGS_INPUT, "serial");
408 if (outputdev == NULL) {
409 outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
411 if (errdev == NULL) {
412 errdev = search_device (DEV_FLAGS_OUTPUT, "serial");
414 /* Initializes output console first */
415 if (outputdev != NULL) {
416 console_setfile (stdout, outputdev);
418 if (errdev != NULL) {
419 console_setfile (stderr, errdev);
421 if (inputdev != NULL) {
422 console_setfile (stdin, inputdev);
425 #ifndef CFG_CONSOLE_INFO_QUIET
426 /* Print information */
428 if (stdio_devices[stdin] == NULL) {
429 printf ("No input devices available!\n");
431 printf ("%s\n", stdio_devices[stdin]->name);
435 if (stdio_devices[stdout] == NULL) {
436 printf ("No output devices available!\n");
438 printf ("%s\n", stdio_devices[stdout]->name);
442 if (stdio_devices[stderr] == NULL) {
443 printf ("No error devices available!\n");
445 printf ("%s\n", stdio_devices[stderr]->name);
447 #endif /* CFG_CONSOLE_INFO_QUIET */
449 #ifdef CFG_CONSOLE_ENV_OVERWRITE
450 /* set the environment variables (will overwrite previous env settings) */
451 for (i = 0; i < 3; i++) {
452 setenv (stdio_names[i], stdio_devices[i]->name);
454 #endif /* CFG_CONSOLE_ENV_OVERWRITE */
457 /* If nothing usable installed, use only the initial console */
458 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
464 #else /* CFG_CONSOLE_IS_IN_ENV */
466 /* Called after the relocation - use desired console functions */
467 int console_init_r (void)
469 device_t *inputdev = NULL, *outputdev = NULL;
470 int i, items = ListNumItems (devlist);
472 /* Scan devices looking for input and output devices */
474 (i <= items) && ((inputdev == NULL) || (outputdev == NULL));
477 device_t *dev = ListGetPtrToItem (devlist, i);
479 if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
482 if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
487 /* Initializes output console first */
488 if (outputdev != NULL) {
489 console_setfile (stdout, outputdev);
490 console_setfile (stderr, outputdev);
493 /* Initializes input console */
494 if (inputdev != NULL) {
495 console_setfile (stdin, inputdev);
498 #ifndef CFG_CONSOLE_INFO_QUIET
499 /* Print information */
501 if (stdio_devices[stdin] == NULL) {
502 printf ("No input devices available!\n");
504 printf ("%s\n", stdio_devices[stdin]->name);
508 if (stdio_devices[stdout] == NULL) {
509 printf ("No output devices available!\n");
511 printf ("%s\n", stdio_devices[stdout]->name);
515 if (stdio_devices[stderr] == NULL) {
516 printf ("No error devices available!\n");
518 printf ("%s\n", stdio_devices[stderr]->name);
520 #endif /* CFG_CONSOLE_INFO_QUIET */
522 /* Setting environment variables */
523 for (i = 0; i < 3; i++) {
524 setenv (stdio_names[i], stdio_devices[i]->name);
528 /* If nothing usable installed, use only the initial console */
529 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
536 #endif /* CFG_CONSOLE_IS_IN_ENV */