summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2015-05-17 17:14:07 +0200
committerMichal Idziorek <m.i@gmx.at>2015-05-17 17:14:07 +0200
commit29ea3208b004f15dafa48ae29a75ba7f0c093a74 (patch)
treebc39ac9b187753e9a16dbac5bf9c2523b32097f9
parent819a4e871058f2dc4a2e255ecbe5a2c49cc8450c (diff)
working on vt52 layer
-rw-r--r--Makefile10
-rw-r--r--asm/helpers.s2
-rw-r--r--kernel/config.h2
-rw-r--r--kernel/console.h1
-rw-r--r--kernel/kernel.c30
-rw-r--r--kernel/kernel.h10
-rw-r--r--kernel/syscalls.c4
-rw-r--r--kernel/usermode.c5
-rw-r--r--lib/logger/log.c12
-rw-r--r--terminal/vt52.c92
-rw-r--r--terminal/vt52.h33
-rw-r--r--video/console.c15
-rw-r--r--video/console.h4
13 files changed, 153 insertions, 67 deletions
diff --git a/Makefile b/Makefile
index e8a2878..50083b4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,7 @@
+
+
#####################
# #
# FoolOS Build Sys. #
@@ -32,7 +34,7 @@ CFLAGS=
## CFLAGS+=-Werror-implicit-function-declaration
## CFLAGS+=-w
CFLAGS+=-ffreestanding
-CFLATS+=-Wall
+#CFLATS+=-Wall
CFLAGS+=-Wextra
#CFLAGS+=-O3
#CFLAGS+=-O0
@@ -159,13 +161,13 @@ run-bochs: all
~/opt/bochs-2.6.8/bin/bochs -q -f bochs/bochsrc -rc bochs/bochsdebug
# run in qemu
-run-qemu:
+run-qemu: all
qemu -enable-kvm disk.img -smp 4 -s
-run-qemu-debug:
+run-qemu-debug: all
# qemu -enable-kvm -s -S ~/temp/FoolOs/disk.img
# qemu -enable-kvm -s -singlestep disk.img
- qemu -enable-kvm -s -S -kernel foolos.img -smp 4 # -initrd ext2.img
+ qemu -enable-kvm -s -S -kernel foolos.img -smp 4 -initrd userspace/ext2.img
stop:
killall qemu
diff --git a/asm/helpers.s b/asm/helpers.s
index 6e89df6..e92b49f 100644
--- a/asm/helpers.s
+++ b/asm/helpers.s
@@ -30,7 +30,7 @@ setup_gdt:
tss_flush:
- movb $0x2B,%ax # Load the index of our TSS structure - The index is
+ movw $0x2B,%ax # Load the index of our TSS structure - The index is
# 0x28, as it is the 5th selector and each is 8 bytes
# long, but we set the bottom two bits (making 0x2B)
# so that it has an RPL of 3, not zero.
diff --git a/kernel/config.h b/kernel/config.h
index 8329457..74304d8 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -8,7 +8,7 @@
#define FOOLOS_CONFIG_H
#define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line
-//#define FOOLOS_LOG_OFF // do not log anything
+#define FOOLOS_LOG_OFF // do not log anything
#define FOOLOS_CONSOLE // otherwise VESA will be used!
#define FOOLSOS_SHOW_VESAMODES
#define MEM_PRINT_MEMORYMAP
diff --git a/kernel/console.h b/kernel/console.h
index e68a3b7..4c56a5a 100644
--- a/kernel/console.h
+++ b/kernel/console.h
@@ -4,6 +4,7 @@
#include <stdint.h>
uint32_t console_init();
+void console_put_char(uint8_t c,uint8_t color, uint32_t x, uint32_t y);
void console_put_char_white(char);
void console_put_char_red(char);
void console_put_char_green(char);
diff --git a/kernel/kernel.c b/kernel/kernel.c
index a3df0b3..0a4b863 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -28,14 +28,33 @@
#include "video/vesa.h"
#include "multiboot.h"
+#include "terminal/vt52.h"
+
+
+//
+// The Foolish structure of Fool OS!
+//
+static fool_os foolos;
+
+fool_os *get_fool()
+{
+ return &foolos;
+}
+
void kernel_main(uint32_t eax,uint32_t ebx)
{
+
//
- // Init Console
- //
- console_init();
+ // Setup main tty
+ //
+ scr_clear();
+ term_screen screen;
+ screen.put_char=console_put_char;
+ vt52_tty tty=vt52_init(&screen);
+ get_fool()->tty1=&tty;
+
//
// PR
@@ -43,13 +62,11 @@ void kernel_main(uint32_t eax,uint32_t ebx)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%s - compiled on %s at %s",KERNEL_VERSION,__DATE__,__TIME__);
-
//
// Configuring the PIT timer.
//
timer_init();
-
//
// GDT
//
@@ -98,6 +115,7 @@ void kernel_main(uint32_t eax,uint32_t ebx)
smp_start_aps(&procdata,"/boot/mp.bin"); //will be copied over mbr
+
//
// Activate Virtual Memory (paging)
//
@@ -112,13 +130,13 @@ void kernel_main(uint32_t eax,uint32_t ebx)
//pci_init();
+
//
// Initialize Multitasking
//
task_init(dir);
-
//
// Abvoe should never returon
//
diff --git a/kernel/kernel.h b/kernel/kernel.h
index 59e3d4c..b6eccb8 100644
--- a/kernel/kernel.h
+++ b/kernel/kernel.h
@@ -3,5 +3,15 @@
#define KERNEL_VERSION "FoolOs 0.2.1"
+#include "terminal/vt52.h";
+
+typedef struct fool_os_struct
+{
+ vt52_tty *tty1;
+
+}fool_os;
+
+fool_os *get_fool();
+
#endif
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index e9ef9d5..6bd51d1 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -5,7 +5,9 @@
#include "fs/fs.h"
#include "fs/ext2.h"
#include "kernel/console.h"
+#include "kernel/kernel.h"
#include "kernel/config.h"
+#include "terminal/vt52.h"
#include <sys/stat.h>
#include <stdbool.h>
#include <stddef.h>
@@ -43,7 +45,7 @@ int syscall_write(int file, char *buf, int len)
//stderr and stdout go to console
for(int i=0;i<len;i++)
{
- console_put_char_green(buf[i]);
+ vt52_put( get_fool()->tty1,buf[i]);
}
lock_release(2);
//x86_int_enable();
diff --git a/kernel/usermode.c b/kernel/usermode.c
index e4d22d3..745cef1 100644
--- a/kernel/usermode.c
+++ b/kernel/usermode.c
@@ -4,8 +4,9 @@
#include "syscalls.h"
+
tss_struct sys_tss; //Define the TSS as a global structure
-extern uint32_t stack_top[];
+
// generic syscall interface!
int syscall(int call, int p1, int p2, int p3)
@@ -46,7 +47,7 @@ void install_tss(int cpu_no){
// now fill each value
// set values necessary
sys_tss.ss0 = 0x10; //kernel data
- sys_tss.esp0 = stack_top; //kernel stack just under the kernel
+ sys_tss.esp0 = kballoc(4);
// now set the IO bitmap (not necessary, so set above limit)
// sys_tss.iomap = ( unsigned short ) sizeof( tss_struct );
diff --git a/lib/logger/log.c b/lib/logger/log.c
index bcfedf0..7d58458 100644
--- a/lib/logger/log.c
+++ b/lib/logger/log.c
@@ -6,6 +6,7 @@
#include "log.h"
#include "kernel/config.h"
#include "kernel/console.h"
+#include "terminal/vt52.h"
#include "lib/printf/printf.h"
#include "kernel/timer.h"
@@ -15,6 +16,10 @@ static int first=0;
static int last=0;
static bool init=true;//
+static void init_log()
+{
+}
+
void log(char *module_name, int log_level, char *format_string, ...)
{
@@ -68,8 +73,9 @@ void panic(char *module_name, char *message)
}
-
-void log_log()
+// unused shit!
+/*
+static void log_log()
{
#ifdef FOOLOS_LOG_OFF
return;
@@ -86,4 +92,4 @@ void log_log()
init=true;
}
-
+*/
diff --git a/terminal/vt52.c b/terminal/vt52.c
index 1dc7289..4a9cb0a 100644
--- a/terminal/vt52.c
+++ b/terminal/vt52.c
@@ -1,50 +1,39 @@
//
// http://en.wikipedia.org/wiki/VT52
//
-//
-//
-// ------------
-// PROG <---> | VT 52 | <--- Keyboard
-// | | ---> Screen
-// ------------
-
-// Interface:
-//
-// struct vt52_tty_struct; // TODO: check what is better to put in header!
-// vt52_tty vt52_init();
-// put(vt52_tty *tty, uint8_t c);
-//
-//
-
-// REQUIREMENTS
-// * kballoc // block wise in-kernel allocation
-#include <stdint.h>
+#include "vt52.h"
#include "kernel/kmalloc.h"
+
//TODO: check?
#define VT52_WIDTH 80
-#define VT52_HEIGHT 24
+#define VT52_HEIGHT 25
#define VT52_ESC 0x33
-typedef struct vt52_tty_struct
+static uint32_t index(vt52_tty *tty, uint32_t x, uint32_t y)
{
+ return tty->width*y+x;
+}
- uint32_t width;
- uint32_t height;
- uint32_t x;
- uint32_t y;
- uint32_t *data; // screen data
-
-}vt52_tty;
-
+static void clear(vt52_tty *tty)
+{
+ for(int x=0;x<tty->width;x++)
+ for(int y=0;y<tty->height;y++)
+ {
+ tty->data[index(tty,x,y)]='.';
+ tty->screen->put_char('.',0xf,x,y);
+ }
+}
-vt52_tty vt52_init()
+vt52_tty vt52_init(term_screen *screen)
{
+
vt52_tty tty;
tty.data=kballoc(1);
+ tty.screen=screen;
tty.x=0;
tty.y=0;
@@ -52,25 +41,34 @@ vt52_tty vt52_init()
tty.width=VT52_WIDTH;
tty.height=VT52_HEIGHT;
+ clear(&tty);
+
return tty;
}
-uint32_t index(vt52_tty *tty, uint32_t x, uint32_t y)
-{
- return tty->width*y+x;
-}
-void set_char(vt52_tty *tty, uint32_t x, uint32_t y, uint32_t c)
+static void set_char(vt52_tty *tty, uint32_t x, uint32_t y, uint32_t c)
{
tty->data[index(tty,x,y)]=c;
}
// send one ASCII character to the terminal
-void put(vt52_tty *tty, uint8_t c)
-{
- set_char(tty,tty->x,tty->y,c);
+void vt52_put(vt52_tty *tty, uint8_t c)
+{
+ if(c!='\n')
+ {
+ tty->data[index(tty,tty->x,tty->y)]=c;
+ tty->screen->put_char(c,0xf,tty->x,tty->y);
+ }
+ else
+ {
+ tty->y++;
+ tty->x=0;
+ }
+
+ tty->x++;
- if(tty->x>tty->width)
+ if(tty->x>=tty->width)
{
tty->x=0;
tty->y++;
@@ -80,17 +78,19 @@ void put(vt52_tty *tty, uint8_t c)
if(tty->y>=tty->height)
{
tty->y--;
- for(uint32_t l=tty->y; l>0; l--)
+ for(uint32_t y=0;y<tty->height;y++)
{
- for(uint32_t x=0;x<tty->width;x++)
+ for(uint32_t x=0;x<tty->width-1;x++)
{
- tty->data[index(tty,x,l-1)] = tty->data[index(tty,x,l)];
+ uint32_t c=tty->data[index(tty,x,y+1)];
+ tty->data[index(tty,x,y)] = c;
+ tty->screen->put_char(c,0xf,x,y);
}
}
- }
-}
-
-
-
+ for(uint32_t x=0;x<tty->width;x++)
+ {
+ }
+ }
+}
diff --git a/terminal/vt52.h b/terminal/vt52.h
new file mode 100644
index 0000000..557c247
--- /dev/null
+++ b/terminal/vt52.h
@@ -0,0 +1,33 @@
+#ifndef VT52_H
+#define VT52_H
+
+#include <stdint.h>
+
+
+// REQUIREMENTS
+// * kballoc // block wise in-kernel allocation
+
+
+typedef struct term_screen_struct
+{
+
+ void (*put_char)(uint8_t c,uint8_t color, uint32_t x, uint32_t y);
+
+}term_screen;
+
+typedef struct vt52_tty_struct
+{
+
+ uint32_t width;
+ uint32_t height;
+ uint32_t x;
+ uint32_t y;
+ uint32_t *data; // screen data
+ term_screen *screen;
+
+}vt52_tty;
+
+vt52_tty vt52_init(term_screen *screen);
+void vt52_put(vt52_tty *tty, uint8_t c);
+
+#endif
diff --git a/video/console.c b/video/console.c
index d53d2d7..c1b9c5c 100644
--- a/video/console.c
+++ b/video/console.c
@@ -6,15 +6,24 @@
static int posx=0;
static int posy=0;
-// helper_funcs
+// glue func for vt52 terminal
+void console_put_char(uint8_t c,uint8_t color, uint32_t x, uint32_t y)
+{
+
+ print_char_col(x,y,c, color);
+}
+
+// helper_funcs
void print_char_col(int x, int y, char c, char col)
{
-#ifdef FOOLOS_CONSOLE
+
+ #ifdef FOOLOS_CONSOLE
char* video_mem=(char *)SCR_VIDEOMEM+(x+y*SCR_REAL_WIDTH)*2;
video_mem[0]=c;
video_mem[1]=col;
-#endif
+ #endif
+
}
void print_char(int x, int y, char c)
diff --git a/video/console.h b/video/console.h
index e9eff29..a89e0f5 100644
--- a/video/console.h
+++ b/video/console.h
@@ -1,5 +1,6 @@
#ifndef CONSOLEINT_H
#define CONSOLEINT_H
+
// 80 x 24
// TODO: implement VT100
@@ -35,9 +36,12 @@
//autoscroll
void scr_clear();
+
+
void scr_nextline();
void scr_backspace();
void scr_put_char(char ch,char col);
void scr_put_string(char *str, char col);
+
#endif