From b8612cbda3625e27f109469a1f5416237c97fb41 Mon Sep 17 00:00:00 2001 From: Lisa Hsu Date: Fri, 14 Nov 2003 10:52:42 -0500 Subject: Import changeset --- system/alpha/console/printf.c | 298 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 298 insertions(+) create mode 100644 system/alpha/console/printf.c (limited to 'system/alpha/console/printf.c') diff --git a/system/alpha/console/printf.c b/system/alpha/console/printf.c new file mode 100644 index 000000000..e0dc0426b --- /dev/null +++ b/system/alpha/console/printf.c @@ -0,0 +1,298 @@ +/***************************************************************************** + + Copyright © 1993, 1994 Digital Equipment Corporation, + Maynard, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, provided +that the copyright notice and this permission notice appear in all copies +of software and supporting documentation, and that the name of Digital not +be used in advertising or publicity pertaining to distribution of the software +without specific, written prior permission. Digital grants this permission +provided that you prominently mark, as not part of the original, any +modifications made to this software or documentation. + +Digital Equipment Corporation disclaims all warranties and/or guarantees +with regard to this software, including all implied warranties of fitness for +a particular purpose and merchantability, and makes no representations +regarding the use of, or the results of the use of, the software and +documentation in terms of correctness, accuracy, reliability, currentness or +otherwise; and you rely on the software, documentation and results solely at +your own risk. + +******************************************************************************/ + +#ifndef LINT +static char *rcsid = "$Id: printf.c,v 1.1.1.1 1997/10/30 23:27:12 verghese Exp $"; +#endif + +/* + * $Log: printf.c,v $ + * Revision 1.1.1.1 1997/10/30 23:27:12 verghese + * current 10/29/97 + * + * Revision 1.1 1995/06/26 21:09:35 berc + * Initial revision + * + * Revision 1.8 1994/10/06 20:29:08 fdh + * Corrected unsigned long declaration. + * + * Revision 1.7 1994/08/05 20:16:23 fdh + * Updated Copyright header and RCS $Id: identifier. + * + * Revision 1.6 1994/06/21 15:41:54 rusling + * fixedup WNT compiler warnings + * + * Revision 1.5 1994/06/17 19:35:37 fdh + * Clean-up... + * + * Revision 1.4 1994/01/19 10:40:08 rusling + * Ported to Alpha Windows NT. + * + * Revision 1.3 1993/11/02 21:57:45 fdh + * Fixed sign extension problem introduced in version 1.2 + * + * Revision 1.2 1993/10/13 15:29:02 rusling + * Added floating point support in printf. This meant adding variable arguments to + * it and FormatItem() and including stdarg.h. + * + * Revision 1.1 1993/06/08 19:56:24 fdh + * Initial revision + * + */ + + + +/* printf.c + L. S. + Sun Feb 10 20:18:22 1985 + */ + +#include "system.h" +#include "lib.h" +#include + + + + + +/* The string s is terminated by a '\0' */ +void PutString(char *s) +{ + while (*s) PutChar(*s++); +} + +/* print c count times */ +void PutRepChar(char c, int count) +{ + while (count--) PutChar(c); +} + +/* put string reverse */ +void PutStringReverse(char *s, int index) +{ + while ((index--) > 0) PutChar(s[index]); +} + +/* prints value in radix, in a field width width, with fill + character fill + if radix is negative, print as signed quantity + if width is negative, left justify + if width is 0, use whatever is needed + if fill is 0, use ' ' + */ +void PutNumber(sl value, int radix, int width, char fill) +{ + char buffer[40]; + ui bufferindex = 0; + ul uvalue; + uw digit; + uw left = FALSE; + uw negative = FALSE; + + if (fill == 0) fill = ' '; + + if (width < 0) { + width = -width; + left = TRUE; + } + if (width < 0 || width > 80) width = 0; + + if (radix < 0) { + radix = -radix; + if (value < 0) { + negative = TRUE; + value = -value; + } + } + switch (radix) { + case 8: + case 10: + case 16: break; + default: { + PutString("****"); + return; + } + } + uvalue = value; + do { + if (radix != 16) + { + digit = (uw)(uvalue % radix); + uvalue /= radix; + } + else + { + digit = (uw)(uvalue & 0xf); + uvalue = uvalue >> 4; + } + buffer[bufferindex] = digit + ((digit <= 9) ? '0' : ('A' - 10)); + bufferindex += 1; + } while (uvalue != 0); + /* fill # ' ' and negative cannot happen at once */ + if (negative) { + buffer[bufferindex] = '-'; + bufferindex += 1; + } + if ((ui)width <= bufferindex) PutStringReverse(buffer, bufferindex); + else { + width -= bufferindex; + if (!left) PutRepChar(fill, width); + PutStringReverse(buffer, bufferindex); + if (left) PutRepChar(fill, width); + } +} + +ul power(long base, long n) +{ + ul p; + + for (p = 1; n > 0; --n) + p = p * base; + return p; +} + +void putFloat(double a, int fieldwidth, char fill) +{ + int i; + ul b; + +/* + * Put out everything before the decimal place. + */ + PutNumber(((ul) a), 10, fieldwidth, fill); +/* + * Output the decimal place. + */ + PutChar('.' & 0x7f); +/* + * Output the n digits after the decimal place. + */ + for (i = 1; i < 6; i++) { + b = (ul)(power(10, i) * (double)(a - (ul) a)); + PutChar((char)(b % 10) + '0'); + } +} +char *FormatItem(char *f, va_list *ap) +{ + char c; + int fieldwidth = 0; + int leftjust = FALSE; + int radix = 0; + char fill = ' '; + if (*f == '0') fill = '0'; + while (c = *f++) { + if (c >= '0' && c <= '9') { + fieldwidth = (fieldwidth * 10) + (c - '0'); + } + else switch (c) { + case '\000': return(--f); + case '%': PutChar('%'); + return(f); + case '-': leftjust = TRUE; + break; + case 'c': { + char a = va_arg(*ap, char); + + if (leftjust) PutChar(a & 0x7f); + if (fieldwidth > 0) PutRepChar(fill, fieldwidth - 1); + if (!leftjust) PutChar(a & 0x7f); + return(f); + } + case 's': { + char *a = va_arg(*ap, char *); + + if (leftjust) PutString((char *) a); + if (fieldwidth > strlen((char *) a)) + PutRepChar(fill, fieldwidth - strlen((char *)a)); + if (!leftjust) PutString((char *) a); + return(f); + } + case 'd': radix = -10; + break; + case 'u': radix = 10; + break; + case 'x': radix = 16; + break; + case 'X': radix = 16; + break; + case 'o': radix = 8; + break; + case 'f': { + double a = va_arg(*ap, double); + + putFloat(a, fieldwidth, fill); + return(f); + } + default: /* unknown switch! */ + radix = 3; + break; + } + if (radix) break; + } + if (leftjust) fieldwidth = -fieldwidth; + { + sl a = va_arg(*ap, sl); + PutNumber(a, radix, fieldwidth, fill); + } + return(f); +} + +void printf(char *f, ...) +{ + va_list ap; + + va_start(ap, f); + + while (*f) { + if (*f == '%') f = FormatItem(f + 1, &ap); + else PutChar(*f++); + } + + if (*(f-1)=='\n') { + /* add a line-feed (SimOS console output goes to shell */ + PutChar('\r'); + } + + va_end(ap); /* clean up */ +} + +void panic(char *f, ...) +{ + va_list ap; + + va_start(ap, f); + + printf("CONSOLE PANIC (looping): "); + while (*f) { + if (*f == '%') f = FormatItem(f + 1, &ap); + else PutChar(*f++); + } + + va_end(ap); /* clean up */ + while(1); +} + + -- cgit v1.2.3 From 492fa2ae5ee7ef9c3f3601ac611ebc9a43ff83eb Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Fri, 14 Nov 2003 12:32:52 -0500 Subject: Get the console code to compile correctly Add support for some thigns that M5 needs Make this better support Tru64 v5.1 console/Makefile: I couldn't figure out the old build system since I was missing a bunch of tools at the time, so I kinda rewrote it. console/console.c: Get the includes right, and make things compile little bit of cleanup along the way console/paljtokern.s: formatting junk console/printf.c: Formatting get const right h/lib.h: fiddle with the includes that we need console/console.c: Get the BOOTDEVICE_NAME right Add a bit of support for grabbing console environment variables --- system/alpha/console/printf.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'system/alpha/console/printf.c') diff --git a/system/alpha/console/printf.c b/system/alpha/console/printf.c index e0dc0426b..24efa802e 100644 --- a/system/alpha/console/printf.c +++ b/system/alpha/console/printf.c @@ -79,19 +79,22 @@ static char *rcsid = "$Id: printf.c,v 1.1.1.1 1997/10/30 23:27:12 verghese Exp $ /* The string s is terminated by a '\0' */ -void PutString(char *s) +void +PutString(const char *s) { while (*s) PutChar(*s++); } /* print c count times */ -void PutRepChar(char c, int count) +void +PutRepChar(char c, int count) { while (count--) PutChar(c); } /* put string reverse */ -void PutStringReverse(char *s, int index) +void +PutStringReverse(const char *s, int index) { while ((index--) > 0) PutChar(s[index]); } @@ -103,7 +106,8 @@ void PutStringReverse(char *s, int index) if width is 0, use whatever is needed if fill is 0, use ' ' */ -void PutNumber(sl value, int radix, int width, char fill) +void +PutNumber(sl value, int radix, int width, char fill) { char buffer[40]; ui bufferindex = 0; @@ -195,7 +199,8 @@ void putFloat(double a, int fieldwidth, char fill) PutChar((char)(b % 10) + '0'); } } -char *FormatItem(char *f, va_list *ap) +const char * +FormatItem(const char *f, va_list *ap) { char c; int fieldwidth = 0; @@ -222,12 +227,12 @@ char *FormatItem(char *f, va_list *ap) return(f); } case 's': { - char *a = va_arg(*ap, char *); + const char *a = va_arg(*ap, const char *); - if (leftjust) PutString((char *) a); - if (fieldwidth > strlen((char *) a)) - PutRepChar(fill, fieldwidth - strlen((char *)a)); - if (!leftjust) PutString((char *) a); + if (leftjust) PutString((const char *) a); + if (fieldwidth > strlen((const char *) a)) + PutRepChar(fill, fieldwidth - strlen((const char *)a)); + if (!leftjust) PutString((const char *) a); return(f); } case 'd': radix = -10; @@ -260,7 +265,8 @@ char *FormatItem(char *f, va_list *ap) return(f); } -void printf(char *f, ...) +int +printf(const char *f, ...) { va_list ap; @@ -277,9 +283,11 @@ void printf(char *f, ...) } va_end(ap); /* clean up */ + return 0; } -void panic(char *f, ...) +void +panic(const char *f, ...) { va_list ap; -- cgit v1.2.3 From 31ac4ce14032ee8bc3f44a9a600bd006f054077b Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Mon, 17 May 2004 17:49:19 -0400 Subject: console code now builds on zizzer console/Makefile: Updated to build on linux and removed lots of crud that compiled, disassembled, and then reassembled console/dbmentry.s: the assembler didn't like they comments, so I removed them console/printf.c: Gcc was very unhappy, so I fixed this line h/lib.h: time_t is defined in a std header, and this was causing some problems --- system/alpha/console/printf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/alpha/console/printf.c') diff --git a/system/alpha/console/printf.c b/system/alpha/console/printf.c index 24efa802e..21a449b2f 100644 --- a/system/alpha/console/printf.c +++ b/system/alpha/console/printf.c @@ -219,7 +219,7 @@ FormatItem(const char *f, va_list *ap) case '-': leftjust = TRUE; break; case 'c': { - char a = va_arg(*ap, char); + char a = va_arg(*ap, char *); if (leftjust) PutChar(a & 0x7f); if (fieldwidth > 0) PutRepChar(fill, fieldwidth - 1); -- cgit v1.2.3 From c5d815dc2d43062d4eeb036d528b0cc2ed281c5d Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Mon, 17 May 2004 19:23:48 -0400 Subject: Deleted a whole bunch of files that we didn't nede in the header directory console/dbmentry.s: console/printf.c: removed unneeded includes --- system/alpha/console/printf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/alpha/console/printf.c') diff --git a/system/alpha/console/printf.c b/system/alpha/console/printf.c index 21a449b2f..a26aa164b 100644 --- a/system/alpha/console/printf.c +++ b/system/alpha/console/printf.c @@ -70,7 +70,7 @@ static char *rcsid = "$Id: printf.c,v 1.1.1.1 1997/10/30 23:27:12 verghese Exp $ Sun Feb 10 20:18:22 1985 */ -#include "system.h" +//#include "system.h" #include "lib.h" #include -- cgit v1.2.3 From 8cefbc93cfa1ed52836b3b5e28e4c74581e06c9b Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Sat, 4 Jun 2005 18:59:06 -0400 Subject: HP copyrights console/Makefile: Added copyright added CROSS_COMPILE variable removed install target console/console.c: console/dbmentry.S: console/paljtokern.S: console/paljtoslave.S: console/printf.c: h/cia.h: h/cserve.h: h/dc21164FromGasSources.h: h/eb164.h: h/ev5_alpha_defs.h: h/ev5_defs.h: h/ev5_impure.h: h/ev5_osfalpha_defs.h: h/ev5_paldef.h: h/fromHudsonMacros.h: h/fromHudsonOsf.h: h/lib.h: h/platform.h: h/regdefs.h: h/rpb.h: palcode/Makefile: palcode/osfpal.S: palcode/osfpal_cache_copy.S: palcode/osfpal_cache_copy_unaligned.S: palcode/platform_m5.S: palcode/platform_tlaser.S: added hp and our copyright --- system/alpha/console/printf.c | 46 ++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'system/alpha/console/printf.c') diff --git a/system/alpha/console/printf.c b/system/alpha/console/printf.c index a26aa164b..9a92036aa 100644 --- a/system/alpha/console/printf.c +++ b/system/alpha/console/printf.c @@ -1,28 +1,24 @@ -/***************************************************************************** - - Copyright © 1993, 1994 Digital Equipment Corporation, - Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, provided -that the copyright notice and this permission notice appear in all copies -of software and supporting documentation, and that the name of Digital not -be used in advertising or publicity pertaining to distribution of the software -without specific, written prior permission. Digital grants this permission -provided that you prominently mark, as not part of the original, any -modifications made to this software or documentation. - -Digital Equipment Corporation disclaims all warranties and/or guarantees -with regard to this software, including all implied warranties of fitness for -a particular purpose and merchantability, and makes no representations -regarding the use of, or the results of the use of, the software and -documentation in terms of correctness, accuracy, reliability, currentness or -otherwise; and you rely on the software, documentation and results solely at -your own risk. - -******************************************************************************/ +/* +Copyright 1993, 1994 Hewlett-Packard Development Company, L.P. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ #ifndef LINT static char *rcsid = "$Id: printf.c,v 1.1.1.1 1997/10/30 23:27:12 verghese Exp $"; -- cgit v1.2.3 From 55e3b9f74391282bda18d90e05df78c331b59392 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Mon, 27 Jun 2005 17:25:54 -0400 Subject: Major system code cleanup and formatting remove unused code console/Makefile: cleanup Makefile. Remove unneeded -D options console/console.c: Major cleanup and formatting remove unused #ifdef code remove unused #includes rename xxm -> m5 rename simos -> m5 console/dbmentry.S: console/paljtokern.S: console/paljtoslave.S: console/printf.c: Major cleanup and formatting remove unused #ifdef code remove unused #includes rename __start -> _start to get rid of warning. h/cserve.h: h/dc21164FromGasSources.h: h/ev5_alpha_defs.h: h/ev5_defs.h: h/ev5_osfalpha_defs.h: h/ev5_paldef.h: h/fromHudsonMacros.h: h/fromHudsonOsf.h: h/rpb.h: Major cleanup and formatting h/ev5_impure.h: Major cleanup and formatting remove unused #ifdef code palcode/Makefile: cleanup Makefile remove unused -D options unify platform_tlaser.S and platform_tsunami.S into platform.S and generate multiple .o files using various #defines unify osfpal.S osfpal_cache_copy.S and osfpal_cache_copy_unaligned.S into osfpal.S and generate multiple .o files using various #defines palcode/osfpal.S: Major cleanup and formatting remove unused #defines remove unused #if code merge copy code into this file. palcode/platform.S: Major cleanup and formatting remove unused #defines remove unused #if code merge platform code into this file. --- system/alpha/console/printf.c | 484 ++++++++++++++++++++++-------------------- 1 file changed, 253 insertions(+), 231 deletions(-) (limited to 'system/alpha/console/printf.c') diff --git a/system/alpha/console/printf.c b/system/alpha/console/printf.c index 9a92036aa..0e665a434 100644 --- a/system/alpha/console/printf.c +++ b/system/alpha/console/printf.c @@ -1,302 +1,324 @@ /* -Copyright 1993, 1994 Hewlett-Packard Development Company, L.P. - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#ifndef LINT -static char *rcsid = "$Id: printf.c,v 1.1.1.1 1997/10/30 23:27:12 verghese Exp $"; -#endif - -/* - * $Log: printf.c,v $ - * Revision 1.1.1.1 1997/10/30 23:27:12 verghese - * current 10/29/97 - * - * Revision 1.1 1995/06/26 21:09:35 berc - * Initial revision - * - * Revision 1.8 1994/10/06 20:29:08 fdh - * Corrected unsigned long declaration. + * Copyright (c) 2003, 2004 + * The Regents of The University of Michigan + * All Rights Reserved * - * Revision 1.7 1994/08/05 20:16:23 fdh - * Updated Copyright header and RCS $Id: identifier. + * This code is part of the M5 simulator, developed by Nathan Binkert, + * Erik Hallnor, Steve Raasch, and Steve Reinhardt, with contributions + * from Ron Dreslinski, Dave Greene, Lisa Hsu, Ali Saidi, and Andrew + * Schultz. * - * Revision 1.6 1994/06/21 15:41:54 rusling - * fixedup WNT compiler warnings + * Permission is granted to use, copy, create derivative works and + * redistribute this software and such derivative works for any purpose, + * so long as the copyright notice above, this grant of permission, and + * the disclaimer below appear in all copies made; and so long as the + * name of The University of Michigan is not used in any advertising or + * publicity pertaining to the use or distribution of this software + * without specific, written prior authorization. * - * Revision 1.5 1994/06/17 19:35:37 fdh - * Clean-up... - * - * Revision 1.4 1994/01/19 10:40:08 rusling - * Ported to Alpha Windows NT. - * - * Revision 1.3 1993/11/02 21:57:45 fdh - * Fixed sign extension problem introduced in version 1.2 + * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE + * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND WITHOUT + * WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE REGENTS OF + * THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE FOR ANY DAMAGES, + * INCLUDING DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES, WITH RESPECT TO ANY CLAIM ARISING OUT OF OR IN CONNECTION + * WITH THE USE OF THE SOFTWARE, EVEN IF IT HAS BEEN OR IS HEREAFTER + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +/* + * Copyright 1993 Hewlett-Packard Development Company, L.P. * - * Revision 1.2 1993/10/13 15:29:02 rusling - * Added floating point support in printf. This meant adding variable arguments to - * it and FormatItem() and including stdarg.h. + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * Revision 1.1 1993/06/08 19:56:24 fdh - * Initial revision + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ - - -/* printf.c - L. S. - Sun Feb 10 20:18:22 1985 - */ - -//#include "system.h" -#include "lib.h" +#include #include - - - - /* The string s is terminated by a '\0' */ void PutString(const char *s) { - while (*s) PutChar(*s++); + while (*s) + PutChar(*s++); } /* print c count times */ void PutRepChar(char c, int count) { - while (count--) PutChar(c); + while (count--) + PutChar(c); } /* put string reverse */ void PutStringReverse(const char *s, int index) { - while ((index--) > 0) PutChar(s[index]); + while (index-- > 0) + PutChar(s[index]); } -/* prints value in radix, in a field width width, with fill - character fill - if radix is negative, print as signed quantity - if width is negative, left justify - if width is 0, use whatever is needed - if fill is 0, use ' ' +/* + * prints value in radix, in a field width width, with fill + * character fill + * if radix is negative, print as signed quantity + * if width is negative, left justify + * if width is 0, use whatever is needed + * if fill is 0, use ' ' */ void -PutNumber(sl value, int radix, int width, char fill) +PutNumber(long value, int radix, int width, char fill) { - char buffer[40]; - ui bufferindex = 0; - ul uvalue; - uw digit; - uw left = FALSE; - uw negative = FALSE; - - if (fill == 0) fill = ' '; - - if (width < 0) { - width = -width; - left = TRUE; - } - if (width < 0 || width > 80) width = 0; - - if (radix < 0) { - radix = -radix; - if (value < 0) { - negative = TRUE; - value = -value; - } + char buffer[40]; + uint bufferindex = 0; + ulong uvalue; + ushort digit; + ushort left = 0; + ushort negative = 0; + + if (fill == 0) + fill = ' '; + + if (width < 0) { + width = -width; + left = 1; } - switch (radix) { - case 8: - case 10: - case 16: break; - default: { - PutString("****"); - return; - } - } - uvalue = value; - do { - if (radix != 16) - { - digit = (uw)(uvalue % radix); - uvalue /= radix; + + if (width < 0 || width > 80) + width = 0; + + if (radix < 0) { + radix = -radix; + if (value < 0) { + negative = 1; + value = -value; + } } - else - { - digit = (uw)(uvalue & 0xf); - uvalue = uvalue >> 4; + + switch (radix) { + case 8: + case 10: + case 16: + break; + + default: + PutString("****"); + return; } - buffer[bufferindex] = digit + ((digit <= 9) ? '0' : ('A' - 10)); - bufferindex += 1; + + uvalue = value; + + do { + if (radix != 16) { + digit = (ushort)(uvalue % radix); + uvalue /= radix; + } else { + digit = (ushort)(uvalue & 0xf); + uvalue = uvalue >> 4; + } + buffer[bufferindex] = digit + ((digit <= 9) ? '0' : ('A' - 10)); + bufferindex += 1; } while (uvalue != 0); + /* fill # ' ' and negative cannot happen at once */ - if (negative) { - buffer[bufferindex] = '-'; - bufferindex += 1; + if (negative) { + buffer[bufferindex] = '-'; + bufferindex += 1; } - if ((ui)width <= bufferindex) PutStringReverse(buffer, bufferindex); - else { - width -= bufferindex; - if (!left) PutRepChar(fill, width); - PutStringReverse(buffer, bufferindex); - if (left) PutRepChar(fill, width); + + if ((uint)width <= bufferindex) { + PutStringReverse(buffer, bufferindex); + } else { + width -= bufferindex; + if (!left) + PutRepChar(fill, width); + PutStringReverse(buffer, bufferindex); + if (left) + PutRepChar(fill, width); } } -ul power(long base, long n) +ulong +power(long base, long n) { - ul p; + ulong p; - for (p = 1; n > 0; --n) - p = p * base; - return p; + for (p = 1; n > 0; --n) + p = p * base; + return p; } -void putFloat(double a, int fieldwidth, char fill) +void +putFloat(double a, int fieldwidth, char fill) { - int i; - ul b; - -/* - * Put out everything before the decimal place. - */ - PutNumber(((ul) a), 10, fieldwidth, fill); -/* - * Output the decimal place. - */ - PutChar('.' & 0x7f); -/* - * Output the n digits after the decimal place. - */ - for (i = 1; i < 6; i++) { - b = (ul)(power(10, i) * (double)(a - (ul) a)); - PutChar((char)(b % 10) + '0'); - } + int i; + ulong b; + + /* + * Put out everything before the decimal place. + */ + PutNumber(((ulong) a), 10, fieldwidth, fill); + + /* + * Output the decimal place. + */ + PutChar('.' & 0x7f); + + /* + * Output the n digits after the decimal place. + */ + for (i = 1; i < 6; i++) { + b = (ulong)(power(10, i) * (double)(a - (ulong) a)); + PutChar((char)(b % 10) + '0'); + } } + const char * FormatItem(const char *f, va_list *ap) { - char c; - int fieldwidth = 0; - int leftjust = FALSE; - int radix = 0; - char fill = ' '; - if (*f == '0') fill = '0'; - while (c = *f++) { - if (c >= '0' && c <= '9') { - fieldwidth = (fieldwidth * 10) + (c - '0'); - } - else switch (c) { - case '\000': return(--f); - case '%': PutChar('%'); - return(f); - case '-': leftjust = TRUE; - break; - case 'c': { - char a = va_arg(*ap, char *); - - if (leftjust) PutChar(a & 0x7f); - if (fieldwidth > 0) PutRepChar(fill, fieldwidth - 1); - if (!leftjust) PutChar(a & 0x7f); - return(f); - } - case 's': { - const char *a = va_arg(*ap, const char *); - - if (leftjust) PutString((const char *) a); - if (fieldwidth > strlen((const char *) a)) - PutRepChar(fill, fieldwidth - strlen((const char *)a)); - if (!leftjust) PutString((const char *) a); - return(f); + char c; + int fieldwidth = 0; + int leftjust = 0; + int radix = 0; + char fill = ' '; + + if (*f == '0') + fill = '0'; + + while (c = *f++) { + if (c >= '0' && c <= '9') { + fieldwidth = (fieldwidth * 10) + (c - '0'); + } else { + switch (c) { + case '\000': + return(--f); + case '%': + PutChar('%'); + return(f); + case '-': + leftjust = 1; + break; + case 'c': { + char a = (char)va_arg(*ap, int); + + if (leftjust) + PutChar(a & 0x7f); + if (fieldwidth > 0) + PutRepChar(fill, fieldwidth - 1); + if (!leftjust) + PutChar(a & 0x7f); + return(f); + } + case 's': { + const char *a = va_arg(*ap, const char *); + + if (leftjust) + PutString((const char *) a); + if (fieldwidth > strlen((const char *) a)) + PutRepChar(fill, fieldwidth - strlen((const char *)a)); + if (!leftjust) + PutString((const char *) a); + return(f); + } + case 'd': + radix = -10; + break; + case 'u': + radix = 10; + break; + case 'x': + radix = 16; + break; + case 'X': + radix = 16; + break; + case 'o': + radix = 8; + break; + case 'f': { + double a = va_arg(*ap, double); + + putFloat(a, fieldwidth, fill); + return(f); + } + default: /* unknown switch! */ + radix = 3; + break; + } } - case 'd': radix = -10; - break; - case 'u': radix = 10; - break; - case 'x': radix = 16; - break; - case 'X': radix = 16; - break; - case 'o': radix = 8; - break; - case 'f': { - double a = va_arg(*ap, double); - - putFloat(a, fieldwidth, fill); - return(f); - } - default: /* unknown switch! */ - radix = 3; - break; - } - if (radix) break; + + if (radix) + break; } - if (leftjust) fieldwidth = -fieldwidth; - { - sl a = va_arg(*ap, sl); - PutNumber(a, radix, fieldwidth, fill); - } - return(f); + + if (leftjust) + fieldwidth = -fieldwidth; + + long a = va_arg(*ap, long); + PutNumber(a, radix, fieldwidth, fill); + + return(f); } int printf(const char *f, ...) { - va_list ap; + va_list ap; - va_start(ap, f); + va_start(ap, f); - while (*f) { - if (*f == '%') f = FormatItem(f + 1, &ap); - else PutChar(*f++); - } + while (*f) { + if (*f == '%') + f = FormatItem(f + 1, &ap); + else + PutChar(*f++); + } - if (*(f-1)=='\n') { - /* add a line-feed (SimOS console output goes to shell */ - PutChar('\r'); - } + if (*(f - 1) == '\n') { + /* add a line-feed (SimOS console output goes to shell */ + PutChar('\r'); + } - va_end(ap); /* clean up */ - return 0; + va_end(ap); /* clean up */ + return 0; } void panic(const char *f, ...) { - va_list ap; + va_list ap; - va_start(ap, f); + va_start(ap, f); - printf("CONSOLE PANIC (looping): "); - while (*f) { - if (*f == '%') f = FormatItem(f + 1, &ap); - else PutChar(*f++); + printf("CONSOLE PANIC (looping): "); + while (*f) { + if (*f == '%') + f = FormatItem(f + 1, &ap); + else + PutChar(*f++); } - va_end(ap); /* clean up */ - while(1); + va_end(ap); /* clean up */ + while(1); } - - -- cgit v1.2.3 From 576196c13ccd4109d10fe98e957cef2f5422b795 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Tue, 28 Feb 2006 18:57:34 -0500 Subject: Add m5op to the build process use quiesceNs on other CPUs panic rather than spin on an error console/Makefile: Add m5op to the build process console/dbmentry.S: use quiesceNs on other CPUs console/printf.c: panic rather than spin on an error. --- system/alpha/console/printf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/alpha/console/printf.c') diff --git a/system/alpha/console/printf.c b/system/alpha/console/printf.c index 0e665a434..b958476fb 100644 --- a/system/alpha/console/printf.c +++ b/system/alpha/console/printf.c @@ -54,6 +54,8 @@ #include #include +#include +#include "m5op.h" /* The string s is terminated by a '\0' */ void @@ -320,5 +322,5 @@ panic(const char *f, ...) } va_end(ap); /* clean up */ - while(1); + m5_panic(); } -- cgit v1.2.3 From 4d1f6a8aca88b08b258ffaf17e192d19f860877e Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Wed, 16 Aug 2006 15:26:52 -0400 Subject: update our copyrights to the new format --- system/alpha/console/printf.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'system/alpha/console/printf.c') diff --git a/system/alpha/console/printf.c b/system/alpha/console/printf.c index b958476fb..98299c85e 100644 --- a/system/alpha/console/printf.c +++ b/system/alpha/console/printf.c @@ -3,10 +3,7 @@ * The Regents of The University of Michigan * All Rights Reserved * - * This code is part of the M5 simulator, developed by Nathan Binkert, - * Erik Hallnor, Steve Raasch, and Steve Reinhardt, with contributions - * from Ron Dreslinski, Dave Greene, Lisa Hsu, Ali Saidi, and Andrew - * Schultz. + * This code is part of the M5 simulator. * * Permission is granted to use, copy, create derivative works and * redistribute this software and such derivative works for any purpose, -- cgit v1.2.3 From 99e7e5e7efc7b0cac3229e1b16fb41350cdccd6b Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 16 Feb 2011 00:34:01 -0600 Subject: copyright: update copyright on alpha system files --- system/alpha/console/printf.c | 70 +++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 46 deletions(-) (limited to 'system/alpha/console/printf.c') diff --git a/system/alpha/console/printf.c b/system/alpha/console/printf.c index 98299c85e..3d8cb4108 100644 --- a/system/alpha/console/printf.c +++ b/system/alpha/console/printf.c @@ -1,52 +1,30 @@ /* - * Copyright (c) 2003, 2004 - * The Regents of The University of Michigan - * All Rights Reserved + * Copyright (c) 2003-2004 The Regents of The University of Michigan + * Copyright (c) 1993 The Hewlett-Packard Development Company + * All rights reserved. * - * This code is part of the M5 simulator. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * - * Permission is granted to use, copy, create derivative works and - * redistribute this software and such derivative works for any purpose, - * so long as the copyright notice above, this grant of permission, and - * the disclaimer below appear in all copies made; and so long as the - * name of The University of Michigan is not used in any advertising or - * publicity pertaining to the use or distribution of this software - * without specific, written prior authorization. - * - * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE - * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND WITHOUT - * WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE REGENTS OF - * THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE FOR ANY DAMAGES, - * INCLUDING DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL - * DAMAGES, WITH RESPECT TO ANY CLAIM ARISING OUT OF OR IN CONNECTION - * WITH THE USE OF THE SOFTWARE, EVEN IF IT HAS BEEN OR IS HEREAFTER - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ - -/* - * Copyright 1993 Hewlett-Packard Development Company, L.P. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -- cgit v1.2.3