2003-04-22 21:02:15 +02:00
|
|
|
/*
|
2009-10-24 15:06:04 +02:00
|
|
|
* This file is part of the coreboot project.
|
2010-04-27 08:56:47 +02:00
|
|
|
*
|
2009-10-24 15:06:04 +02:00
|
|
|
* Copyright (C) 2009 coresystems GmbH
|
2003-04-22 21:02:15 +02:00
|
|
|
*
|
2009-10-24 15:06:04 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; version 2 of
|
|
|
|
* the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301 USA
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
|
|
|
|
2009-10-28 17:13:28 +01:00
|
|
|
#include <string.h>
|
2009-10-24 15:06:04 +02:00
|
|
|
#include <smp/spinlock.h>
|
|
|
|
#include <console/vtxprintf.h>
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2009-11-12 17:38:03 +01:00
|
|
|
DECLARE_SPIN_LOCK(vsprintf_lock)
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2009-10-24 15:06:04 +02:00
|
|
|
static char *str_buf;
|
2009-05-26 16:31:37 +02:00
|
|
|
|
2009-10-24 15:06:04 +02:00
|
|
|
static void str_tx_byte(unsigned char byte)
|
|
|
|
{
|
|
|
|
*str_buf = byte;
|
|
|
|
str_buf++;
|
|
|
|
}
|
2009-05-26 16:31:37 +02:00
|
|
|
|
2009-10-24 15:06:04 +02:00
|
|
|
static int vsprintf(char *buf, const char *fmt, va_list args)
|
|
|
|
{
|
2003-04-22 21:02:15 +02:00
|
|
|
int i;
|
2009-10-24 15:06:04 +02:00
|
|
|
|
|
|
|
spin_lock(&vsprintf_lock);
|
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
str_buf = buf;
|
|
|
|
i = vtxprintf(str_tx_byte, fmt, args);
|
|
|
|
*str_buf = '\0';
|
2009-10-24 15:06:04 +02:00
|
|
|
|
|
|
|
spin_unlock(&vsprintf_lock);
|
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2009-10-24 15:06:04 +02:00
|
|
|
int sprintf(char *buf, const char *fmt, ...)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2009-10-24 15:06:04 +02:00
|
|
|
i = vsprintf(buf, fmt, args);
|
2003-04-22 21:02:15 +02:00
|
|
|
va_end(args);
|
2009-10-24 15:06:04 +02:00
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
return i;
|
|
|
|
}
|