#include <linux/kernel.h>
#include <arch/mprot.h>
#include <rtl_conf.h>
#include <rtl_core.h>
#include <rtl_sync.h>
#include <rtl_printf.h>
#include <rtl_posixio.h>
#include <stdarg.h>
#include <asm/system.h>
#include <unistd.h>

#if CONFIG_RTL_PRINTF

#define MAX_PRINTKBUF 2000

static char in_printkbuf[MAX_PRINTKBUF]; /* please don't put this on my stack*/
static char *printkptr = &in_printkbuf[0];

int rtl_printf(const char * fmt, ...)
{
	unsigned long flags;
	int i;
	va_list args;
#if CONFIG_KERNEL_MEMORYPROT	
	mprot_t mprot;
#endif	
        int fd;

	STARTKERNELCODE(mprot);
	
	rtl_hard_savef_and_cli(flags);
        
	va_start(args, fmt);
	/* dangerous. Don't rtl_printk long strings */
	i=vsprintf(printkptr,fmt,args);
	va_end(args);
	
	write(STDOUT,printkptr,strlen(printkptr));
	
	rtl_hard_restore_flags(flags);
	
	ENDKERNELCODE(mprot);
	
	return i;
}
#endif //CONFIG_RTL_PRINTF
