blob: c4c91115c2e1ddc3076f0c3dce855489a4f05adc [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001/*
Stefan Reinauer52fc6b12009-10-24 13:06:04 +00002 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2009 coresystems GmbH
Eric Biederman8ca8d762003-04-22 19:02:15 +00005 *
Stefan Reinauer52fc6b12009-10-24 13:06:04 +00006 * 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 Biederman8ca8d762003-04-22 19:02:15 +000020 */
21
Eric Biederman8ca8d762003-04-22 19:02:15 +000022#include <stdarg.h>
Myles Watson58170782009-10-28 16:13:28 +000023#include <string.h>
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000024#include <smp/spinlock.h>
25#include <console/vtxprintf.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000026
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000027static spinlock_t vsprintf_lock = SPIN_LOCK_UNLOCKED;
Eric Biederman8ca8d762003-04-22 19:02:15 +000028
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000029static char *str_buf;
30
31static void str_tx_byte(unsigned char byte)
Eric Biederman8ca8d762003-04-22 19:02:15 +000032{
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000033 *str_buf = byte;
34 str_buf++;
35}
Patrick Georgi736221f12009-05-26 14:31:37 +000036
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000037static int vsprintf(char *buf, const char *fmt, va_list args)
38{
Eric Biederman8ca8d762003-04-22 19:02:15 +000039 int i;
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000040
41 spin_lock(&vsprintf_lock);
42
Eric Biederman8ca8d762003-04-22 19:02:15 +000043 str_buf = buf;
44 i = vtxprintf(str_tx_byte, fmt, args);
Eric Biederman8ca8d762003-04-22 19:02:15 +000045 *str_buf = '\0';
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000046
47 spin_unlock(&vsprintf_lock);
48
Eric Biederman8ca8d762003-04-22 19:02:15 +000049 return i;
50}
51
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000052int sprintf(char *buf, const char *fmt, ...)
Eric Biederman8ca8d762003-04-22 19:02:15 +000053{
54 va_list args;
55 int i;
56
57 va_start(args, fmt);
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000058 i = vsprintf(buf, fmt, args);
Eric Biederman8ca8d762003-04-22 19:02:15 +000059 va_end(args);
Stefan Reinauer52fc6b12009-10-24 13:06:04 +000060
Eric Biederman8ca8d762003-04-22 19:02:15 +000061 return i;
62}