Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2009 coresystems GmbH |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 5 | * |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 19 | * MA 02110-1301 USA |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 22 | #include <stdarg.h> |
Myles Watson | 5817078 | 2009-10-28 16:13:28 +0000 | [diff] [blame^] | 23 | #include <string.h> |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 24 | #include <smp/spinlock.h> |
| 25 | #include <console/vtxprintf.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 26 | |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 27 | static spinlock_t vsprintf_lock = SPIN_LOCK_UNLOCKED; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 28 | |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 29 | static char *str_buf; |
| 30 | |
| 31 | static void str_tx_byte(unsigned char byte) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 32 | { |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 33 | *str_buf = byte; |
| 34 | str_buf++; |
| 35 | } |
Patrick Georgi | 736221f1 | 2009-05-26 14:31:37 +0000 | [diff] [blame] | 36 | |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 37 | static int vsprintf(char *buf, const char *fmt, va_list args) |
| 38 | { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 39 | int i; |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 40 | |
| 41 | spin_lock(&vsprintf_lock); |
| 42 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 43 | str_buf = buf; |
| 44 | i = vtxprintf(str_tx_byte, fmt, args); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 45 | *str_buf = '\0'; |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 46 | |
| 47 | spin_unlock(&vsprintf_lock); |
| 48 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 49 | return i; |
| 50 | } |
| 51 | |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 52 | int sprintf(char *buf, const char *fmt, ...) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 53 | { |
| 54 | va_list args; |
| 55 | int i; |
| 56 | |
| 57 | va_start(args, fmt); |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 58 | i = vsprintf(buf, fmt, args); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 59 | va_end(args); |
Stefan Reinauer | 52fc6b1 | 2009-10-24 13:06:04 +0000 | [diff] [blame] | 60 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 61 | return i; |
| 62 | } |