checkin if some disabled code that checks for interrupts being disabled when we take...
[newos.git] / kernel / console.c
blobdc753ceb67e5a1545e4f21a2d35a01730a13f829
1 /*
2 ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
5 #include <kernel/kernel.h>
6 #include <kernel/console.h>
7 #include <kernel/debug.h>
8 #include <kernel/int.h>
9 #include <kernel/smp.h>
10 #include <kernel/sem.h>
11 #include <kernel/vfs.h>
13 #include <stdarg.h>
14 #include <stdio.h>
16 // from con.h
17 enum {
18 CONSOLE_OP_WRITEXY = 2376
21 struct console_op_xy_struct {
22 int x;
23 int y;
24 char buf[256];
27 static int console_fd = -1;
29 int kprintf(const char *fmt, ...)
31 int ret = 0;
32 va_list args;
33 char temp[256];
35 if(console_fd >= 0) {
36 va_start(args, fmt);
37 ret = vsprintf(temp,fmt,args);
38 va_end(args);
40 sys_write(console_fd, temp, 0, ret);
42 return ret;
45 int kprintf_xy(int x, int y, const char *fmt, ...)
47 int ret = 0;
48 va_list args;
49 struct console_op_xy_struct buf;
51 if(console_fd >= 0) {
52 va_start(args, fmt);
53 ret = vsprintf(buf.buf,fmt,args);
54 va_end(args);
56 buf.x = x;
57 buf.y = y;
58 sys_ioctl(console_fd, CONSOLE_OP_WRITEXY, &buf, ret + sizeof(buf.x) + sizeof(buf.y));
60 return ret;
63 int con_init(kernel_args *ka)
65 dprintf("con_init: entry\n");
67 console_fd = sys_open("/dev/console", STREAM_TYPE_DEVICE, 0);
68 dprintf("console_fd = %d\n", console_fd);
70 return 0;