/* Copyright (C) 2008 Emmanuel Varoquaux This file is part of XOS. 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, either version 3 of the License, or (at your option) any later version. 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, see <http://www.gnu.org/licenses/>. */ #include <console.h> #include <gdt.h> #include <asm.h> #include <config.h> #include <sprintf.h> /* printk() utilise en interne un tampon static, plutot qu'un tampon sur la * pile, afin d'eviter un debordement de celle-ci. Par consequent, pour * empecher tout acces concurrent, les interruptions doivent etre desactivees * dans printk(). */ void __attribute__ ((format (printf, 1, 2))) printk(const char *format, ...) { static char buf[PRINTK_BUFFER_SIZE]; int intr; va_list arg; int n; unsigned short fs; disable_intr(intr); va_start(arg, format); if ((n = vsnprintf(buf, PRINTK_BUFFER_SIZE, format, arg)) < 0) goto error; va_end(arg); get_fs(fs); load_fs(KERNEL_DATA_SEL); console_write(buf, n); load_fs(fs); restore_intr(intr); return; error: va_end(arg); restore_intr(intr); }