diff --git a/include/asm/io.h b/include/asm/io.h new file mode 100644 index 0000000000000000000000000000000000000000..bc51561472e9d42e432f7cf9a635905fda7eabb9 --- /dev/null +++ b/include/asm/io.h @@ -0,0 +1,10 @@ +#ifndef _IO_H +#define _IO_H + +#define outb_p(value, port) \ +__asm__("outb %%al, %%dx\n" \ + "\tjmp 1f\n" \ + "1:\tjmp 1f\n" \ + "1:" :: "a"(value), "d"(port)) + +#endif diff --git a/include/asm/system.h b/include/asm/system.h new file mode 100644 index 0000000000000000000000000000000000000000..5090d22a20477335fcaa7cbe24ccb991099ed313 --- /dev/null +++ b/include/asm/system.h @@ -0,0 +1,9 @@ +#ifndef _SYSTEM_H +#define _SYSTEM_H + +#define sti() __asm__("sti"::) +#define cli() __asm__("cli"::) +#define nop() __asm__("nop"::) +#define iret() __asm__("iret"::) + +#endif diff --git a/include/linux/tty.h b/include/linux/tty.h index 542afc7114b77d81cd81eed95c787fd7c3a5e3db..7142292917fe985ece98114d4fe4bd020e645037 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -4,4 +4,6 @@ void con_init(); void tty_init(); +void con_write(); + #endif diff --git a/kernel/chr_drv/Makefile b/kernel/chr_drv/Makefile index afb3e4e0b1c1c2a837e890f62e4c942439d68c6e..56430e64557166f4bd422ee63bf123e3b2ab7380 100644 --- a/kernel/chr_drv/Makefile +++ b/kernel/chr_drv/Makefile @@ -1,7 +1,7 @@ AR := ar LD := ld GCC := gcc -CCFLAG := -m32 -I../../include -nostdinc -Wall -fomit-frame-pointer -c +CCFLAG := -m32 -I../../include -nostdinc -Wall -fomit-frame-pointer -fno-stack-protector -c OBJS := tty_io.o console.o tty_io.o : tty_io.c diff --git a/kernel/chr_drv/console.c b/kernel/chr_drv/console.c index 5cbd4f29ddbb47a6222d237d6b79bddaf8199f84..11dfbf2185351c24bb2c47195db2d955ed209eb8 100644 --- a/kernel/chr_drv/console.c +++ b/kernel/chr_drv/console.c @@ -1,5 +1,10 @@ #include +#include +#include + +#define ORIG_X (*(unsigned char *)0x90000) +#define ORIG_Y (*(unsigned char *)0x90001) #define ORIG_VIDEO_PAGE (*(unsigned short *)0x90004) #define ORIG_VIDEO_MODE ((*(unsigned short *)0x90006) & 0xff) #define ORIG_VIDEO_COLS (((*(unsigned short *)0x90006) & 0xff00) >> 8) @@ -23,6 +28,34 @@ static unsigned char video_page; /* Initial video page */ static unsigned short video_port_reg; /* Video register select port */ static unsigned short video_port_val; /* Video register value port */ +static unsigned long origin; +static unsigned long scr_end; +static unsigned long pos; +static unsigned long x, y; +static unsigned long top, bottom; +static unsigned long attr = 0x07; + +static char buf[8]; + + +static inline void gotoxy(int new_x,unsigned int new_y) { + if (new_x > video_num_columns || new_y >= video_num_lines) + return; + + x = new_x; + y = new_y; + pos = origin + y*video_size_row + (x << 1); +} + +static inline void set_cursor() { + cli(); + outb_p(14, video_port_reg); + outb_p(0xff&((pos-video_mem_base)>>9), video_port_val); + outb_p(15, video_port_reg); + outb_p(0xff&((pos-video_mem_base)>>1), video_port_val); + sti(); +} + void con_init() { char * display_desc = "????"; char * display_ptr; @@ -70,5 +103,30 @@ void con_init() { *display_ptr++ = *display_desc++; *display_ptr++; } + + origin = video_mem_base; + scr_end = video_mem_base + video_num_lines * video_size_row; + top = 0; + bottom = video_num_lines; + + gotoxy(ORIG_X, ORIG_Y); + set_cursor(); + con_write("hello", 5); +} + +void con_write(const char* buf, int nr) { + char* t = (char*)pos; + char* s = buf; + int i = 0; + + for (i = 0; i < nr; i++) { + *t++ = *(s++); + *t++ = 0xf; + x++; + } + + pos = t; + gotoxy(x, y); + set_cursor(); } diff --git a/kernel/chr_drv/tty_io.c b/kernel/chr_drv/tty_io.c index 724ec13dbcea2a9fd1cb14256a19ca7f737440ea..eeeb1c263180879a9ff7bf4184b661bc4bf1b0c1 100644 --- a/kernel/chr_drv/tty_io.c +++ b/kernel/chr_drv/tty_io.c @@ -4,3 +4,7 @@ void tty_init() { con_init(); } +void tty_write(unsigned channel, char* buf, int nr) { + con_write(buf, nr); +} + diff --git a/setup.S b/setup.S index a30a5dddefa27dd240c1ee8bb247b8d60b9186d0..33a28fc7532eed252363a6b868c51ee67e776754 100644 --- a/setup.S +++ b/setup.S @@ -40,6 +40,7 @@ _start_setup: movw %ax, (8) movw %bx, (10) movw %cx, (12) + movw $0x5019, (14) movw $0x0000, %ax movw %ax, %ds