From 042e25e19b5fc0cec1d47440c26246c886cf39f6 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Sun, 17 May 2015 20:40:29 +0200 Subject: started big cleanup! --- Makefile | 3 +- driver/console.c | 195 ++++++++++++++++++++++++++++++++++ driver/console.h | 40 +++++++ driver/keyboard.c | 226 +++++++++++++++++++++++++++++++++++++++ driver/keyboard.h | 1 + fs/file.h | 4 +- kernel/kernel.c | 23 ++-- kernel/keyboard.c | 225 --------------------------------------- kernel/keyboard.h | 1 - lib/buffer/ringbuffer.c | 76 -------------- lib/buffer/ringbuffer.h | 3 - lib/logger/log.c | 94 ----------------- lib/logger/log.h | 14 --- lib/printf/printf.c | 250 -------------------------------------------- lib/printf/printf.h | 125 ---------------------- lib/string/string.c | 37 ------- lib/string/string.h | 3 - terminal/vt52.c | 8 +- terminal/vt52.h | 35 ++++++- video/console.c | 195 ---------------------------------- video/console.h | 40 ------- video/vesa.c | 249 ------------------------------------------- video/vesa.h | 47 --------- xxx/lib/buffer/ringbuffer.c | 76 ++++++++++++++ xxx/lib/buffer/ringbuffer.h | 3 + xxx/lib/logger/log.c | 94 +++++++++++++++++ xxx/lib/logger/log.h | 14 +++ xxx/lib/printf/printf.c | 250 ++++++++++++++++++++++++++++++++++++++++++++ xxx/lib/printf/printf.h | 125 ++++++++++++++++++++++ xxx/lib/string/string.c | 37 +++++++ xxx/lib/string/string.h | 3 + xxx/video/vesa.c | 249 +++++++++++++++++++++++++++++++++++++++++++ xxx/video/vesa.h | 47 +++++++++ 33 files changed, 1414 insertions(+), 1378 deletions(-) create mode 100644 driver/console.c create mode 100644 driver/console.h create mode 100644 driver/keyboard.c create mode 100644 driver/keyboard.h delete mode 100644 kernel/keyboard.c delete mode 100644 kernel/keyboard.h delete mode 100644 lib/buffer/ringbuffer.c delete mode 100644 lib/buffer/ringbuffer.h delete mode 100644 lib/logger/log.c delete mode 100644 lib/logger/log.h delete mode 100644 lib/printf/printf.c delete mode 100644 lib/printf/printf.h delete mode 100644 lib/string/string.c delete mode 100644 lib/string/string.h delete mode 100644 video/console.c delete mode 100644 video/console.h delete mode 100644 video/vesa.c delete mode 100644 video/vesa.h create mode 100644 xxx/lib/buffer/ringbuffer.c create mode 100644 xxx/lib/buffer/ringbuffer.h create mode 100644 xxx/lib/logger/log.c create mode 100644 xxx/lib/logger/log.h create mode 100644 xxx/lib/printf/printf.c create mode 100644 xxx/lib/printf/printf.h create mode 100644 xxx/lib/string/string.c create mode 100644 xxx/lib/string/string.h create mode 100644 xxx/video/vesa.c create mode 100644 xxx/video/vesa.h diff --git a/Makefile b/Makefile index 11a8d66..92b60e2 100644 --- a/Makefile +++ b/Makefile @@ -66,9 +66,8 @@ ASFLAGS+=-gstabs #kernel sources (asm and c) SOURCES= SOURCES+=$(wildcard ./kernel/*.c) -SOURCES+=$(wildcard ./video/*.c) -SOURCES+=$(wildcard ./lib/*/*.c) SOURCES+=$(wildcard ./fs/*.c) +SOURCES+=$(wildcard ./driver/*.c) SOURCES+=$(wildcard ./terminal/*.c) #derive kernel object files diff --git a/driver/console.c b/driver/console.c new file mode 100644 index 0000000..b6958c5 --- /dev/null +++ b/driver/console.c @@ -0,0 +1,195 @@ +#include "console.h" +#include "kernel/config.h" + +//#define FOOLOS_CONSOLE + +static int posx=0; +static int posy=0; + +static void scr_nextline(); + +void update_cursor(uint32_t col,uint32_t row) +{ + unsigned short position=(row*80) + col; + + // cursor LOW port to vga INDEX register + x86_outb(0x3D4, 0x0F); + x86_outb(0x3D5, (unsigned char)(position&0xFF)); + // cursor HIGH port to vga INDEX register + x86_outb(0x3D4, 0x0E); + x86_outb(0x3D5, (unsigned char )((position>>8)&0xFF)); + } + + +// helper_funcs +static void print_char_col(int x, int y, char c, char col) +{ + + #ifdef FOOLOS_CONSOLE + char* video_mem=(char *)SCR_VIDEOMEM+(x+y*SCR_REAL_WIDTH)*2; + video_mem[0]=c; + video_mem[1]=col; + #endif + +} + +// 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); +} +// +// +static void print_char(int x, int y, char c) +{ + print_char_col(x,y,c,SCR_WHITE); +} + +static void print_single_num(int i) +{ + if(i<10)print_char_col(posx,posy,'0'+i,SCR_GREEN); + else if(i<16)print_char_col(posx,posy,'A'+i-10,SCR_GREEN); + posx++; + if(posx>=SCR_WIDTH)scr_nextline(); + +} + +static void print_str_col(int x,int y,char *str, char col) +{ + + while(*str!=0) + { + print_char_col(x++,y,*(str++),col); + } + +} + +static void print_str(int x,int y,char *str) +{ + print_str_col(x,y,str,SCR_WHITE); +} + + +// +// +void scr_clear() +{ + int x,y; + + for(x=0;xSCR_HEIGHT-2) + { + for(i=1;i=SCR_WIDTH)scr_nextline(); +#endif + +} + +/* +void scr_put_hex(uint16_t val) +{ + + int i; + + scr_put_string("0x"); + + for(i=0;i<4;i++) + { + print_single_num((val&0xf000)>>12); + val=val << 4; + + } + + +} +*/ + +/* +void scr_put_hex32(uint32_t val) +{ + scr_put_string("["); + scr_put_hex(val>>16); + scr_put_string(","); + scr_put_hex(val&0xffff); + scr_put_string("]"); +} +*/ + +static void scr_put_string(char *str, char col) +{ + while(*str!=0) + { + scr_put_char(*(str++),col); + } +} + +static void scr_backspace() +{ + if(posx==0)return; + print_char_col(posx-1,posy,' ',SCR_LGREEN); + posx--; + +} diff --git a/driver/console.h b/driver/console.h new file mode 100644 index 0000000..819bd8d --- /dev/null +++ b/driver/console.h @@ -0,0 +1,40 @@ +#ifndef CONSOLEINT_H +#define CONSOLEINT_H + +// 80 x 24 ? + +#include + +#define SCR_VIDEOMEM 0xb8000 + +#define SCR_REAL_WIDTH 80 + +#define SCR_WIDTH 78 +#define SCR_HEIGHT 24 + +#define SCR_CTRL 0x3D4 +#define SCR_DATA 0x3D5 + +// colors +#define SCR_BLACK 0x0 +#define SCR_BLUE 0x1 +#define SCR_GREEN 0x2 +#define SCR_CYAN 0x3 +#define SCR_RED 0x4 +#define SCR_VIOLET 0x5 +#define SCR_BROWN 0x6 +#define SCR_GRAY1 0x7 +#define SCR_GRAY2 0x8 +#define SCR_LBLUE 0x9 +#define SCR_LGREEN 0xa +#define SCR_LCYAN 0xb +#define SCR_LRED 0xc +#define SCR_PINK 0xd +#define SCR_YELLOW 0xe +#define SCR_WHITE 0xf + +//autoscroll +void update_cursor(uint32_t col,uint32_t row); +void console_put_char(uint8_t c,uint8_t color, uint32_t x, uint32_t y); + +#endif diff --git a/driver/keyboard.c b/driver/keyboard.c new file mode 100644 index 0000000..4366127 --- /dev/null +++ b/driver/keyboard.c @@ -0,0 +1,226 @@ +#include + +#define FOOLOS_MODULE_NAME "keyboard" + +#include "x86.h" + +/// idiots keyboard driver //// +// http://www.computer-engineering.org/ps2keyboard/scancodes1.html + +static bool ctrl_l=false; +static bool shift_l=false; +static bool shift_r=false; +static bool capslock=false; + +static void (*put)(uint8_t c); + +void keyboard_init(void (*func)(uint8_t c)) +{ + put=func; +} + +void keyboard_handle(uint8_t in) +{ + + uint8_t make_alpha[]={ + 0x1e, // A + 0x30, // B + 0x2e, // C + 0x20, // D + 0x12, // E + 0x21, // F + 0x22, // G + 0x23, // H + 0x17, // I + 0x24, // J + 0x25, // K + 0x26, // L + 0x32, // M + 0x31, // N + 0x18, // O + 0x19, // P + 0x10, // Q + 0x13, // R + 0x1F, // S + 0x14, // T + 0x16, // U + 0x2F, // V + 0x11, // W + 0x2D, // X + 0x15, // Y + 0x2c, // Z + }; + + uint8_t break_alpha[]={ + 0x9e, // A + 0xb0, // B + 0xae, // C + 0xa0, // D + 0x92, // E + 0xa1, // F + 0xa2, // G + 0xa3, // H + 0x97, // I + 0xa4, // J + 0xa5, // K + 0xa6, // L + 0xb2, // M + 0xb1, // N + 0x98, // O + 0x99, // P + 0x90, // Q + 0x93, // R + 0x9F, // S + 0x94, // T + 0x96, // U + 0xaF, // V + 0x91, // W + 0xaD, // X + 0x95, // Y + 0xac, // Z + }; + + uint8_t break_num[]={ + + 0x8b, //0 + 0x82, + 0x83, + 0x84, + 0x85, + 0x86, + 0x87, + 0x88, + 0x89, + 0x8a, // 9 + + }; + + + + + + uint8_t break_key_enter=0x9c; + uint8_t break_key_space=0xb9; + uint8_t break_key_backspace=0x8e; + + uint8_t make_key_shift_l=0x2a; + uint8_t break_key_shift_l=0xaa; + + uint8_t make_key_shift_r=0x36; + uint8_t break_key_shift_r=0xb6; + + uint8_t break_caps_lock=0xba; + uint8_t break_slash=0xb5; + + uint8_t make_ctrl_l=0x1d; + uint8_t break_ctrl_l=0x9d; + + if(make_key_shift_l==in)shift_l=true; + if(break_key_shift_l==in)shift_l=false;; + + if(make_key_shift_r==in)shift_r=true; + if(break_key_shift_r==in)shift_r=false;; + + if(make_ctrl_l==in)ctrl_l=true; + if(break_ctrl_l==in)ctrl_l=false; + + if(break_caps_lock==in)capslock=!capslock; + + + char ascii; + + bool match=false; + // optimize this! + if(ctrl_l) + { + if(in==0xa0) + { + ascii=4; //end of transmission ctrl-d + match=true; + } + } + if(break_slash==in) + { + ascii='/'; + match=true; + } + else if(break_key_space==in) + { + ascii=' '; + match=true; + } + else if(in==0xB4) + { + ascii='.'; + match=true; + } + else if(in==0xB3) + { + ascii=','; + match=true; + } + else if(in==0x8D) + { + ascii='+'; + match=true; + } + else if(in==0x8C) + { + ascii='-'; + match=true; + } + else if(in==0x9A) + { + ascii='['; + match=true; + } + else if(in==0x9B) + { + ascii=']'; + match=true; + } + else if(break_key_backspace==in) + { + ascii=0x08; + match=true; + } + + else if(break_key_enter==in) + { + ascii='\n'; + match=true; + } + + else for(int i=0;i<26;i++) + { + if(match)break; + if(break_alpha[i]==in) + { + ascii=('a'+i); + + if(shift_l||shift_r||capslock) // capslock makes trouble :( + { + ascii=('A'+i); + } + match=true; + break; + } + } + + for(int i=0;i<10;i++) + { + if(break_num[i]==in) + { + ascii=('0'+i); + match=true; + break; + } + } + + + if(match) + { + put(ascii); + } + +} diff --git a/driver/keyboard.h b/driver/keyboard.h new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/driver/keyboard.h @@ -0,0 +1 @@ + diff --git a/fs/file.h b/fs/file.h index 481a173..e5a0664 100644 --- a/fs/file.h +++ b/fs/file.h @@ -5,9 +5,11 @@ typedef struct file_struct { - uint32_t file_id; + void (*read)(); + void (*write)(); + void (*seek)(); }file; diff --git a/kernel/kernel.c b/kernel/kernel.c index de435c5..098fc64 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -40,28 +40,27 @@ fool_os *get_fool() } +static void put_kb(uint8_t c) +{ + vt52_kb(get_fool()->tty1,c); +} + void kernel_main(uint32_t eax,uint32_t ebx) { // - // Setup terminal output + // Setup terminal output / input // term_out screen; screen.put_char=console_put_char; screen.update_cursor=update_cursor; - vt52_tty tty=vt52_init(&screen); - get_fool()->tty1=&tty; - // - // Setup terminal input - // - /* - term_in keyboard; - kb.get_char=console_put_char; - screen.update_cursor=update_cursor; - vt52_tty tty=vt52_init(&screen); + term_in input; + + vt52_tty tty=vt52_init(&screen,&input); get_fool()->tty1=&tty; - */ + + keyboard_init(put_kb); diff --git a/kernel/keyboard.c b/kernel/keyboard.c deleted file mode 100644 index b586d0f..0000000 --- a/kernel/keyboard.c +++ /dev/null @@ -1,225 +0,0 @@ -#define FOOLOS_MODULE_NAME "keyboard" - -#include "x86.h" - -#include "lib/buffer/ringbuffer.h" -#include "lib/logger/log.h" // logger facilities - -/// keyboard driver //// -// http://www.computer-engineering.org/ps2keyboard/scancodes1.html - -static bool ctrl_l=false; -static bool shift_l=false; -static bool shift_r=false; -static bool capslock=false; - -void keyboard_handle(uint8_t in) -{ - - uint8_t make_alpha[]={ - 0x1e, // A - 0x30, // B - 0x2e, // C - 0x20, // D - 0x12, // E - 0x21, // F - 0x22, // G - 0x23, // H - 0x17, // I - 0x24, // J - 0x25, // K - 0x26, // L - 0x32, // M - 0x31, // N - 0x18, // O - 0x19, // P - 0x10, // Q - 0x13, // R - 0x1F, // S - 0x14, // T - 0x16, // U - 0x2F, // V - 0x11, // W - 0x2D, // X - 0x15, // Y - 0x2c, // Z - }; - - uint8_t break_alpha[]={ - 0x9e, // A - 0xb0, // B - 0xae, // C - 0xa0, // D - 0x92, // E - 0xa1, // F - 0xa2, // G - 0xa3, // H - 0x97, // I - 0xa4, // J - 0xa5, // K - 0xa6, // L - 0xb2, // M - 0xb1, // N - 0x98, // O - 0x99, // P - 0x90, // Q - 0x93, // R - 0x9F, // S - 0x94, // T - 0x96, // U - 0xaF, // V - 0x91, // W - 0xaD, // X - 0x95, // Y - 0xac, // Z - }; - - uint8_t break_num[]={ - - 0x8b, //0 - 0x82, - 0x83, - 0x84, - 0x85, - 0x86, - 0x87, - 0x88, - 0x89, - 0x8a, // 9 - - }; - - - - - - uint8_t break_key_enter=0x9c; - uint8_t break_key_space=0xb9; - uint8_t break_key_backspace=0x8e; - - uint8_t make_key_shift_l=0x2a; - uint8_t break_key_shift_l=0xaa; - - uint8_t make_key_shift_r=0x36; - uint8_t break_key_shift_r=0xb6; - - uint8_t break_caps_lock=0xba; - uint8_t break_slash=0xb5; - - uint8_t make_ctrl_l=0x1d; - uint8_t break_ctrl_l=0x9d; - - if(make_key_shift_l==in)shift_l=true; - if(break_key_shift_l==in)shift_l=false;; - - if(make_key_shift_r==in)shift_r=true; - if(break_key_shift_r==in)shift_r=false;; - - if(make_ctrl_l==in)ctrl_l=true; - if(break_ctrl_l==in)ctrl_l=false; - - if(break_caps_lock==in)capslock=!capslock; - - - char ascii; - - bool match=false; - // optimize this! - if(ctrl_l) - { - if(in==0xa0) - { - ascii=4; //end of transmission ctrl-d - match=true; - } - } - if(break_slash==in) - { - ascii='/'; - match=true; - } - else if(break_key_space==in) - { - ascii=' '; - match=true; - } - else if(in==0xB4) - { - ascii='.'; - match=true; - } - else if(in==0xB3) - { - ascii=','; - match=true; - } - else if(in==0x8D) - { - ascii='+'; - match=true; - } - else if(in==0x8C) - { - ascii='-'; - match=true; - } - else if(in==0x9A) - { - ascii='['; - match=true; - } - else if(in==0x9B) - { - ascii=']'; - match=true; - } - else if(break_key_backspace==in) - { - ascii=0x08; - match=true; - } - - else if(break_key_enter==in) - { - ascii='\n'; - match=true; - } - - else for(int i=0;i<26;i++) - { - if(match)break; - if(break_alpha[i]==in) - { - ascii=('a'+i); - - if(shift_l||shift_r||capslock) // capslock makes trouble :( - { - ascii=('A'+i); - } - match=true; - break; - } - } - - for(int i=0;i<10;i++) - { - if(break_num[i]==in) - { - ascii=('0'+i); - match=true; - break; - } - } - - - if(match) - { - - if(!ringbuffer_put(ascii)) - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"ringbuffer full.."); - } - -} - - - diff --git a/kernel/keyboard.h b/kernel/keyboard.h deleted file mode 100644 index 8b13789..0000000 --- a/kernel/keyboard.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/buffer/ringbuffer.c b/lib/buffer/ringbuffer.c deleted file mode 100644 index a121df1..0000000 --- a/lib/buffer/ringbuffer.c +++ /dev/null @@ -1,76 +0,0 @@ -// can handle one buffer for a start. -// later make it reentrant and manage multiple buffers! -// todo: syncing access to buffer. - -#define FOOLOS_MODULE_NAME "ringbuffer" - -#include "ringbuffer.h" -#include "kernel/x86.h" -#include "lib/logger/log.h" -#include "kernel/spinlock.h" - -#define RINGBUFFER_SIZE 10 -static int size=RINGBUFFER_SIZE; -static volatile int front=RINGBUFFER_SIZE-1; -static volatile int back=RINGBUFFER_SIZE-1; -static volatile char buf[RINGBUFFER_SIZE]; - -static spinlock sl=9; - -bool ringbuffer_put(char c) -{ - - x86_int_disable(); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put wants lock"); - lock_spin(sl); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by put"); - - if((back-1+size)%size==front) - { - lock_release(sl); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put"); - x86_int_enable(); - return false; - } - - buf[back]=c; - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put %d %d (%c)", back, front,c); - back--; - back+=size; - back%=size; - - lock_release(sl); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put"); - x86_int_enable(); - - return true; -} - -bool ringbuffer_get(char *c) -{ - x86_int_disable(); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"get wants lock"); - lock_spin(sl); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by get"); - if(front==back) - { - lock_release(sl); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get"); - x86_int_enable(); - *c='_'; - return false; - } - - *c=buf[front]; - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"get %d %d (%c)", back, front,*c); - - front--; - front+=size; - front%=size; - - lock_release(sl); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get"); - x86_int_enable(); - - return true; -} diff --git a/lib/buffer/ringbuffer.h b/lib/buffer/ringbuffer.h deleted file mode 100644 index 038e33a..0000000 --- a/lib/buffer/ringbuffer.h +++ /dev/null @@ -1,3 +0,0 @@ -#include -bool ringbuffer_put(char c); -bool ringbuffer_get(char *c); diff --git a/lib/logger/log.c b/lib/logger/log.c deleted file mode 100644 index 430f982..0000000 --- a/lib/logger/log.c +++ /dev/null @@ -1,94 +0,0 @@ -#define FOOLOS_MODULE_NAME "log" - -#include -#include - -#include "log.h" -#include "kernel/config.h" -#include "terminal/vt52.h" -#include "lib/printf/printf.h" -#include "kernel/timer.h" - - -static char buffer[LOG_BUF_SIZE]; -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, ...) -{ - - #ifdef FOOLOS_LOG_OFF - return; - #endif - - if(log_level=LOG_BUF_SIZE)first=(first+1)%LOG_BUF_SIZE; - if(last>first)if(LOG_BUF_SIZE-last+first>=LOG_BUF_SIZE)first=(first+1)%LOG_BUF_SIZE; - } - - -} - -void panic(char *module_name, char *message) -{ - char buf_log[256]; - tfp_sprintf(buf_log,"KERNEL PANIC !! %s: %s\n",module_name,message); - //console_put_str_red(buf_log); - - while(1) - { - asm volatile("cli"); - asm volatile("hlt"); - } - -} - -// unused shit! -/* -static void log_log() -{ - #ifdef FOOLOS_LOG_OFF - return; - #endif - - char buf_log[256]; - tfp_sprintf(buf_log,"[ 0.00000] log: buffer state: first=%d, last=%d, buf_size=%d\n",first,last,LOG_BUF_SIZE); - console_put_str_gray(buf_log); - for(int i=first;i!=last;i++) - { - console_put_char_gray(buffer[i]); - - } - - init=true; -} -*/ diff --git a/lib/logger/log.h b/lib/logger/log.h deleted file mode 100644 index da27340..0000000 --- a/lib/logger/log.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef FOOLOS_LOG_H -#define FOOLOS_LOG_H - -#define FOOLOS_LOG_ERROR 5 -#define FOOLOS_LOG_WARNING 4 -#define FOOLOS_LOG_INFO 3 -#define FOOLOS_LOG_DEBUG 2 -#define FOOLOS_LOG_FINE 1 - -void log(char *module_name, int prio, char *format_string, ...); -void panic(char *module_name, char *format_string); -void log_log(); - -#endif diff --git a/lib/printf/printf.c b/lib/printf/printf.c deleted file mode 100644 index 23d3d46..0000000 --- a/lib/printf/printf.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (c) 2004,2012 Kustaa Nyholm / SpareTimeLabs - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this list - * of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * Neither the name of the Kustaa Nyholm or SpareTimeLabs nor the names of its - * contributors may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ - -#include "printf.h" - -typedef void (*putcf) (void*,char); -static putcf stdout_putf; -static void* stdout_putp; - - -#ifdef PRINTF_LONG_SUPPORT - -static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf) - { - int n=0; - unsigned int d=1; - while (num/d >= base) - d*=base; - while (d!=0) { - int dgt = num / d; - num%=d; - d/=base; - if (n || dgt>0|| d==0) { - *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10); - ++n; - } - } - *bf=0; - } - -static void li2a (long num, char * bf) - { - if (num<0) { - num=-num; - *bf++ = '-'; - } - uli2a(num,10,0,bf); - } - -#endif - -static void ui2a(unsigned int num, unsigned int base, int uc,char * bf) - { - int n=0; - unsigned int d=1; - while (num/d >= base) - d*=base; - while (d!=0) { - int dgt = num / d; - num%= d; - d/=base; - if (n || dgt>0 || d==0) { - *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10); - ++n; - } - } - *bf=0; - } - -static void i2a (int num, char * bf) - { - if (num<0) { - num=-num; - *bf++ = '-'; - } - ui2a(num,10,0,bf); - } - -static int a2d(char ch) - { - if (ch>='0' && ch<='9') - return ch-'0'; - else if (ch>='a' && ch<='f') - return ch-'a'+10; - else if (ch>='A' && ch<='F') - return ch-'A'+10; - else return -1; - } - -static char a2i(char ch, char** src,int base,int* nump) - { - char* p= *src; - int num=0; - int digit; - while ((digit=a2d(ch))>=0) { - if (digit>base) break; - num=num*base+digit; - ch=*p++; - } - *src=p; - *nump=num; - return ch; - } - -static void putchw(void* putp,putcf putf,int n, char z, char* bf) - { - char fc=z? '0' : ' '; - char ch; - char* p=bf; - while (*p++ && n > 0) - n--; - while (n-- > 0) - putf(putp,fc); - while ((ch= *bf++)) - putf(putp,ch); - } - -void tfp_format(void* putp,putcf putf,char *fmt, va_list va) - { - char bf[12]; - - char ch; - - - while ((ch=*(fmt++))) { - if (ch!='%') - putf(putp,ch); - else { - char lz=0; -#ifdef PRINTF_LONG_SUPPORT - char lng=0; -#endif - int w=0; - ch=*(fmt++); - if (ch=='0') { - ch=*(fmt++); - lz=1; - } - if (ch>='0' && ch<='9') { - ch=a2i(ch,&fmt,10,&w); - } -#ifdef PRINTF_LONG_SUPPORT - if (ch=='l') { - ch=*(fmt++); - lng=1; - } -#endif - switch (ch) { - case 0: - goto abort; - case 'u' : { -#ifdef PRINTF_LONG_SUPPORT - if (lng) - uli2a(va_arg(va, unsigned long int),10,0,bf); - else -#endif - ui2a(va_arg(va, unsigned int),10,0,bf); - putchw(putp,putf,w,lz,bf); - break; - } - case 'd' : { -#ifdef PRINTF_LONG_SUPPORT - if (lng) - li2a(va_arg(va, unsigned long int),bf); - else -#endif - i2a(va_arg(va, int),bf); - putchw(putp,putf,w,lz,bf); - break; - } - case 'x': case 'X' : -#ifdef PRINTF_LONG_SUPPORT - if (lng) - uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf); - else -#endif - ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf); - putchw(putp,putf,w,lz,bf); - break; - case 'c' : - putf(putp,(char)(va_arg(va, int))); - break; - case 's' : - putchw(putp,putf,w,0,va_arg(va, char*)); - break; - case '%' : - putf(putp,ch); - default: - break; - } - } - } - abort:; - } - - -void init_printf(void* putp,void (*putf) (void*,char)) - { - stdout_putf=putf; - stdout_putp=putp; - } - -void tfp_printf(char *fmt, ...) - { - va_list va; - va_start(va,fmt); - tfp_format(stdout_putp,stdout_putf,fmt,va); - va_end(va); - } - -static void putcp(void* p,char c) - { - *(*((char**)p))++ = c; - } - - - -void tfp_vsprintf(char* s,char *fmt, va_list va) - { - tfp_format(&s,putcp,fmt,va); - putcp(&s,0); - } - -void tfp_sprintf(char* s,char *fmt, ...) - { - va_list va; - va_start(va,fmt); - tfp_vsprintf(s,fmt,va); - va_end(va); - } - - diff --git a/lib/printf/printf.h b/lib/printf/printf.h deleted file mode 100644 index 0e65915..0000000 --- a/lib/printf/printf.h +++ /dev/null @@ -1,125 +0,0 @@ -/* -File: printf.h - -Copyright (c) 2004,2012 Kustaa Nyholm / SpareTimeLabs - -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this list -of conditions and the following disclaimer. - -Redistributions in binary form must reproduce the above copyright notice, this -list of conditions and the following disclaimer in the documentation and/or other -materials provided with the distribution. - -Neither the name of the Kustaa Nyholm or SpareTimeLabs nor the names of its -contributors may be used to endorse or promote products derived from this software -without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY -OF SUCH DAMAGE. - ----------------------------------------------------------------------- - -This library is realy just two files: 'printf.h' and 'printf.c'. - -They provide a simple and small (+200 loc) printf functionality to -be used in embedded systems. - -I've found them so usefull in debugging that I do not bother with a -debugger at all. - -They are distributed in source form, so to use them, just compile them -into your project. - -Two printf variants are provided: printf and sprintf. - -The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'. - -Zero padding and field width are also supported. - -If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the -long specifier is also -supported. Note that this will pull in some long math routines (pun intended!) -and thus make your executable noticably longer. - -The memory foot print of course depends on the target cpu, compiler and -compiler options, but a rough guestimate (based on a H8S target) is about -1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space. -Not too bad. Your milage may vary. By hacking the source code you can -get rid of some hunred bytes, I'm sure, but personally I feel the balance of -functionality and flexibility versus code size is close to optimal for -many embedded systems. - -To use the printf you need to supply your own character output function, -something like : - -void putc ( void* p, char c) - { - while (!SERIAL_PORT_EMPTY) ; - SERIAL_PORT_TX_REGISTER = c; - } - -Before you can call printf you need to initialize it to use your -character output function with something like: - -init_printf(NULL,putc); - -Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc', -the NULL (or any pointer) you pass into the 'init_printf' will eventually be -passed to your 'putc' routine. This allows you to pass some storage space (or -anything realy) to the character output function, if necessary. -This is not often needed but it was implemented like that because it made -implementing the sprintf function so neat (look at the source code). - -The code is re-entrant, except for the 'init_printf' function, so it -is safe to call it from interupts too, although this may result in mixed output. -If you rely on re-entrancy, take care that your 'putc' function is re-entrant! - -The printf and sprintf functions are actually macros that translate to -'tfp_printf' and 'tfp_sprintf'. This makes it possible -to use them along with 'stdio.h' printf's in a single source file. -You just need to undef the names before you include the 'stdio.h'. -Note that these are not function like macros, so if you have variables -or struct members with these names, things will explode in your face. -Without variadic macros this is the best we can do to wrap these -fucnction. If it is a problem just give up the macros and use the -functions directly or rename them. - -For further details see source code. - -regs Kusti, 23.10.2004 -*/ - - -#ifndef __TFP_PRINTF__ -#define __TFP_PRINTF__ - -#include - -void init_printf(void* putp,void (*putf) (void*,char)); - -void tfp_printf(char *fmt, ...); -void tfp_sprintf(char* s,char *fmt, ...); -void tfp_vsprintf(char* s,char *fmt, va_list va); - -void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va); - -#define printf tfp_printf -#define sprintf tfp_sprintf - -#endif - - - diff --git a/lib/string/string.c b/lib/string/string.c deleted file mode 100644 index 729c509..0000000 --- a/lib/string/string.c +++ /dev/null @@ -1,37 +0,0 @@ -#include - -//length 0 for null terminated strings; -bool strcmp(char *str1, char *str2, int length) -{ - int i=0; - while(true) - { - if(str1[i]!=str2[i])return false; - i++; - - if(i==length) return true; - if(str1[i]==0||str2[i]==0) - { - if(str1[i]==str2[i])return true; - return false; - } - } - -} - -void* memcpy(void* restrict dstptr, const void* restrict srcptr, int size) -{ - unsigned char* dst = (unsigned char*) dstptr; - const unsigned char* src = (const unsigned char*) srcptr; - for ( int i = 0; i < size; i++ ) - dst[i] = src[i]; - return dstptr; -} - -int strlen(const char* string) -{ - int result = 0; - while ( string[result] ) - result++; - return result; -} diff --git a/lib/string/string.h b/lib/string/string.h deleted file mode 100644 index a804de9..0000000 --- a/lib/string/string.h +++ /dev/null @@ -1,3 +0,0 @@ -#include -bool strcmp(char *str1, char *str2, int length); -void* memcpy(void* restrict dstptr, const void* restrict srcptr, int size); diff --git a/terminal/vt52.c b/terminal/vt52.c index 9ff1150..3fa4137 100644 --- a/terminal/vt52.c +++ b/terminal/vt52.c @@ -54,12 +54,13 @@ static void clear(vt52_tty *tty) } } -vt52_tty vt52_init(term_out *screen) +vt52_tty vt52_init(term_out *screen,term_in *input) { vt52_tty tty; tty.data=kballoc(1); tty.screen=screen; + tty.input=input; tty.x=0; tty.y=0; @@ -80,6 +81,11 @@ static void set_char(vt52_tty *tty, uint32_t x, uint32_t y, uint32_t c) static uint8_t escaping=0; +void vt52_kb(vt52_tty *tty, uint8_t c) +{ + vt52_put(tty,c); + tty->input->put_char(c); +} // send one ASCII character to the terminal void vt52_put(vt52_tty *tty, uint8_t c) { diff --git a/terminal/vt52.h b/terminal/vt52.h index cdc62bd..94502d1 100644 --- a/terminal/vt52.h +++ b/terminal/vt52.h @@ -4,8 +4,27 @@ #include -// REQUIREMENTS -// * kballoc // block wise in-kernel allocation +// +// Emulator of a vt52 terminal +// +// 1. pass a term_out and term_in struct to vt52_init(..). +// 2. use the vt52_kb function for terminal/user input (eg. keyboard). +// 3. use the vt52_put function for input from the host/programms. +// +// +// +// ________ +// vt52_put() ------> | | ----> (term_out_struct) +// | VT52 | +// (term_in_struct)<-- |_______| <---- vt52_kb() +// +// +// OTHER REQUIREMENTS +// +// Your also need to provide some memory allocation +// +// * uint32_t kballoc(uint32_t bloks); // block wise in-kernel allocation +// typedef struct term_out_struct { @@ -15,6 +34,13 @@ typedef struct term_out_struct }term_out; +typedef struct term_in_struct +{ + + void (*put_char)(uint8_t c); + +}term_in; + typedef struct vt52_tty_struct { @@ -23,11 +49,14 @@ typedef struct vt52_tty_struct uint32_t x; uint32_t y; uint32_t *data; // screen data + term_out *screen; + term_in *input; }vt52_tty; -vt52_tty vt52_init(term_out *screen); +vt52_tty vt52_init(term_out *screen,term_in *input); void vt52_put(vt52_tty *tty, uint8_t c); +void vt52_kb(vt52_tty *tty, uint8_t c); #endif diff --git a/video/console.c b/video/console.c deleted file mode 100644 index b6958c5..0000000 --- a/video/console.c +++ /dev/null @@ -1,195 +0,0 @@ -#include "console.h" -#include "kernel/config.h" - -//#define FOOLOS_CONSOLE - -static int posx=0; -static int posy=0; - -static void scr_nextline(); - -void update_cursor(uint32_t col,uint32_t row) -{ - unsigned short position=(row*80) + col; - - // cursor LOW port to vga INDEX register - x86_outb(0x3D4, 0x0F); - x86_outb(0x3D5, (unsigned char)(position&0xFF)); - // cursor HIGH port to vga INDEX register - x86_outb(0x3D4, 0x0E); - x86_outb(0x3D5, (unsigned char )((position>>8)&0xFF)); - } - - -// helper_funcs -static void print_char_col(int x, int y, char c, char col) -{ - - #ifdef FOOLOS_CONSOLE - char* video_mem=(char *)SCR_VIDEOMEM+(x+y*SCR_REAL_WIDTH)*2; - video_mem[0]=c; - video_mem[1]=col; - #endif - -} - -// 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); -} -// -// -static void print_char(int x, int y, char c) -{ - print_char_col(x,y,c,SCR_WHITE); -} - -static void print_single_num(int i) -{ - if(i<10)print_char_col(posx,posy,'0'+i,SCR_GREEN); - else if(i<16)print_char_col(posx,posy,'A'+i-10,SCR_GREEN); - posx++; - if(posx>=SCR_WIDTH)scr_nextline(); - -} - -static void print_str_col(int x,int y,char *str, char col) -{ - - while(*str!=0) - { - print_char_col(x++,y,*(str++),col); - } - -} - -static void print_str(int x,int y,char *str) -{ - print_str_col(x,y,str,SCR_WHITE); -} - - -// -// -void scr_clear() -{ - int x,y; - - for(x=0;xSCR_HEIGHT-2) - { - for(i=1;i=SCR_WIDTH)scr_nextline(); -#endif - -} - -/* -void scr_put_hex(uint16_t val) -{ - - int i; - - scr_put_string("0x"); - - for(i=0;i<4;i++) - { - print_single_num((val&0xf000)>>12); - val=val << 4; - - } - - -} -*/ - -/* -void scr_put_hex32(uint32_t val) -{ - scr_put_string("["); - scr_put_hex(val>>16); - scr_put_string(","); - scr_put_hex(val&0xffff); - scr_put_string("]"); -} -*/ - -static void scr_put_string(char *str, char col) -{ - while(*str!=0) - { - scr_put_char(*(str++),col); - } -} - -static void scr_backspace() -{ - if(posx==0)return; - print_char_col(posx-1,posy,' ',SCR_LGREEN); - posx--; - -} diff --git a/video/console.h b/video/console.h deleted file mode 100644 index 819bd8d..0000000 --- a/video/console.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef CONSOLEINT_H -#define CONSOLEINT_H - -// 80 x 24 ? - -#include - -#define SCR_VIDEOMEM 0xb8000 - -#define SCR_REAL_WIDTH 80 - -#define SCR_WIDTH 78 -#define SCR_HEIGHT 24 - -#define SCR_CTRL 0x3D4 -#define SCR_DATA 0x3D5 - -// colors -#define SCR_BLACK 0x0 -#define SCR_BLUE 0x1 -#define SCR_GREEN 0x2 -#define SCR_CYAN 0x3 -#define SCR_RED 0x4 -#define SCR_VIOLET 0x5 -#define SCR_BROWN 0x6 -#define SCR_GRAY1 0x7 -#define SCR_GRAY2 0x8 -#define SCR_LBLUE 0x9 -#define SCR_LGREEN 0xa -#define SCR_LCYAN 0xb -#define SCR_LRED 0xc -#define SCR_PINK 0xd -#define SCR_YELLOW 0xe -#define SCR_WHITE 0xf - -//autoscroll -void update_cursor(uint32_t col,uint32_t row); -void console_put_char(uint8_t c,uint8_t color, uint32_t x, uint32_t y); - -#endif diff --git a/video/vesa.c b/video/vesa.c deleted file mode 100644 index a5ee4e5..0000000 --- a/video/vesa.c +++ /dev/null @@ -1,249 +0,0 @@ -//http://wiki.osdev.org/GUI -#include -#include "kernel/mem.h" -#include "vesa.h" - -#include "lib/logger/log.h" // logger facilities -#include "lib/printf/printf.h" -#define FOOLOS_MODULE_NAME "vesa" - -#define FOOLSOS_SHOW_VESAMODES - - -static foolfont *deffont; -static vbemodeinfo *VbeModeInfoBlock; - -static int console_x; -static int console_y; - -static int console_lines; -static int console_cols; - -static uint8_t* buffer; -static uint8_t* physbase; - -void PutConsoleNL(); -void PutPixel(int x,int y, int color); - -void vesa_switch_buffers() -{ - for(int i=0;i<800*600*2;i++)physbase[i]=buffer[i]; - -} - -void vesa_put_rect(int x, int y, int w , int h, int color) -{ - for(int i=x;iXres, VbeModeInfoBlock->Yres, 0xffffff); -} - - -void vesa_set_physbase(uint32_t addr) -{ - VbeModeInfoBlock->physbase=addr; -} - - // - // We want to get output to the screen as fast as possible! - // - // Our Fool-Boot-Loader did set up VESA already for us. - // The desired VESA mode is hardcoded in [boot/mbr.asm]. - // - // The [vesa_init(...)] function requires: - // - // * the addresses of the vbeinfo struct - // * the address of the vbemodeinfo struct (for selected mode). - // * Fool Font loaded inside ramimage - // - // The first two paramters are hardcoded in [boot/mbr.asm], - // while the last one is set in the Makefile. The font binary - // is integrated in the kernel image. - // - // this function returns the physical base address of - // our video memory - // - -uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont) -{ - //the only functionallu important init lines! (rest is log) - VbeModeInfoBlock=mode; - deffont=rawfont; - console_x=0; - console_y=0; - - int line_height=12; - int col_width=10; - console_lines=mode->Yres/line_height; - console_cols=mode->Xres/col_width; - - // vesa info - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"vbe version: 0x%x / video mode ptr: 0x%x 0x%x", - info->VbeVersion, info->VideoModePtr[1], info->VideoModePtr[0]); - - // vesa info on selected mode: - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"colors r:%d 0x%x g:%d 0x%x b:%d 0x%x", - mode->red_position,mode->red_mask, - mode->green_position,mode->green_mask, - mode->blue_position,mode->blue_mask); - - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"res: %d * %d / banks: %d / attr: 0x%x", - mode->Xres, mode->Yres, mode->banks, mode->attributes); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"bpp: %d / physbase: 0x%x", - mode->bpp,mode->physbase); - - // vesa modes - // todo: take segment from vbeinfo! -#ifdef FOOLSOS_SHOW_VESAMODES - uint16_t *modeptr=info->VideoModePtr[0]; - - while(*modeptr!=0xffff&&*modeptr!=0) - { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"mode supported : 0x%X", (*modeptr)); - modeptr++; - } -#endif - - - return VbeModeInfoBlock->physbase; - -} - -void PutPixel(int x,int y, int color){ - - //do not write memory outside the screen buffer, check parameters against the VBE mode info - if (x<0 || x>VbeModeInfoBlock->Xres|| y<0 || y>VbeModeInfoBlock->Yres) return; - if (x) x = (x*(VbeModeInfoBlock->bpp>>3)); // get bytes (divide by 8) - if (y) y = (y*VbeModeInfoBlock->pitch); - uint8_t *cTemp=VbeModeInfoBlock->physbase; - - cTemp[x+y] = (uint8_t)(color & 0xff); - cTemp[x+y+1] = (uint8_t)((color>>8) & 0xff); - //cTemp[x+y+2] = (uint8_t)((color>>16) & 0xff); - - } - - -void PutFont(char c, int x,int y, int color) -{ - - int fnt=0x126-0x20; - - if(c>=0x20&&c<=0x126)fnt=c-0x20; - - int posx, posy, sizex=8, sizey=10; - - for(posx=x;posx=console_cols)PutConsoleNL(); - #endif -} - -void PutConsole(char *str, int color) -{ - - while((*str)!=0) - { - PutConsoleChar(*str,color); - str++; - } - -} -void PutConsoleNL() -{ - console_x=0; - console_y++; - if(console_y>=console_lines-5)console_y=0; - - for(int i=0;iXres-200,VbeModeInfoBlock->Yres-200,0xff); - vesa_put_rect(boxx-10,boxy-10,20,20,0x999999); - - boxx++; -// boxy+=boxx; - if(boxx>VbeModeInfoBlock->Xres-100)boxx=100; - // if(boxy>VbeModeInfoBlock->Yres-200)boxy=200; - - - vesa_switch_buffers(); -} - -/* -void vesa_init_doublebuff() -{ - boxx=300; - boxy=300; - - int blocks=800*600*2/4096+1; - physbase=VbeModeInfoBlock->physbase; - buffer=pmmngr_alloc_blocks(blocks); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Init buffer of %d blocks at 0x%08X",blocks,buffer); - - VbeModeInfoBlock->physbase=buffer; -} -*/ - - - diff --git a/video/vesa.h b/video/vesa.h deleted file mode 100644 index 371e944..0000000 --- a/video/vesa.h +++ /dev/null @@ -1,47 +0,0 @@ -#include - -typedef struct foolfont_struct -{ - uint8_t line[10]; //every single fool font consists of 10 lines a 8 bit - -}foolfont; - -typedef struct vbeinfo_struct{ - char VbeSignature[4]; // == "VESA" - uint16_t VbeVersion; // == 0x0300 for VBE 3.0 - uint16_t OemStringPtr[2]; // isa vbeFarPtr - uint8_t Capabilities[4]; - uint16_t VideoModePtr[2]; // isa vbeFarPtr - uint16_t TotalMemory; // as # of 64KB blocks -}vbeinfo; - - -typedef struct ModeInfoBlock { - uint16_t attributes; - uint8_t winA,winB; - uint16_t granularity; - uint16_t winsize; - uint16_t segmentA, segmentB; - uint16_t realFctPtr[2]; -// VBE_FAR(realFctPtr); - uint16_t pitch; // bytes per scanline - - uint16_t Xres, Yres; - uint8_t Wchar, Ychar, planes, bpp, banks; - uint8_t memory_model, bank_size, image_pages; - uint8_t reserved0; - - uint8_t red_mask, red_position; - uint8_t green_mask, green_position; - uint8_t blue_mask, blue_position; - uint8_t rsv_mask, rsv_position; - uint8_t directcolor_attributes; - - volatile uint32_t physbase; // your LFB (Linear Framebuffer) address ;) - uint32_t reserved1; - uint16_t reserved2; -}vbemodeinfo; - -uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont); -void PutConsoleChar(char c, int color); -void PutConsole(char *str, int color); diff --git a/xxx/lib/buffer/ringbuffer.c b/xxx/lib/buffer/ringbuffer.c new file mode 100644 index 0000000..a121df1 --- /dev/null +++ b/xxx/lib/buffer/ringbuffer.c @@ -0,0 +1,76 @@ +// can handle one buffer for a start. +// later make it reentrant and manage multiple buffers! +// todo: syncing access to buffer. + +#define FOOLOS_MODULE_NAME "ringbuffer" + +#include "ringbuffer.h" +#include "kernel/x86.h" +#include "lib/logger/log.h" +#include "kernel/spinlock.h" + +#define RINGBUFFER_SIZE 10 +static int size=RINGBUFFER_SIZE; +static volatile int front=RINGBUFFER_SIZE-1; +static volatile int back=RINGBUFFER_SIZE-1; +static volatile char buf[RINGBUFFER_SIZE]; + +static spinlock sl=9; + +bool ringbuffer_put(char c) +{ + + x86_int_disable(); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put wants lock"); + lock_spin(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by put"); + + if((back-1+size)%size==front) + { + lock_release(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put"); + x86_int_enable(); + return false; + } + + buf[back]=c; + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put %d %d (%c)", back, front,c); + back--; + back+=size; + back%=size; + + lock_release(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put"); + x86_int_enable(); + + return true; +} + +bool ringbuffer_get(char *c) +{ + x86_int_disable(); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"get wants lock"); + lock_spin(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by get"); + if(front==back) + { + lock_release(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get"); + x86_int_enable(); + *c='_'; + return false; + } + + *c=buf[front]; + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"get %d %d (%c)", back, front,*c); + + front--; + front+=size; + front%=size; + + lock_release(sl); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get"); + x86_int_enable(); + + return true; +} diff --git a/xxx/lib/buffer/ringbuffer.h b/xxx/lib/buffer/ringbuffer.h new file mode 100644 index 0000000..038e33a --- /dev/null +++ b/xxx/lib/buffer/ringbuffer.h @@ -0,0 +1,3 @@ +#include +bool ringbuffer_put(char c); +bool ringbuffer_get(char *c); diff --git a/xxx/lib/logger/log.c b/xxx/lib/logger/log.c new file mode 100644 index 0000000..430f982 --- /dev/null +++ b/xxx/lib/logger/log.c @@ -0,0 +1,94 @@ +#define FOOLOS_MODULE_NAME "log" + +#include +#include + +#include "log.h" +#include "kernel/config.h" +#include "terminal/vt52.h" +#include "lib/printf/printf.h" +#include "kernel/timer.h" + + +static char buffer[LOG_BUF_SIZE]; +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, ...) +{ + + #ifdef FOOLOS_LOG_OFF + return; + #endif + + if(log_level=LOG_BUF_SIZE)first=(first+1)%LOG_BUF_SIZE; + if(last>first)if(LOG_BUF_SIZE-last+first>=LOG_BUF_SIZE)first=(first+1)%LOG_BUF_SIZE; + } + + +} + +void panic(char *module_name, char *message) +{ + char buf_log[256]; + tfp_sprintf(buf_log,"KERNEL PANIC !! %s: %s\n",module_name,message); + //console_put_str_red(buf_log); + + while(1) + { + asm volatile("cli"); + asm volatile("hlt"); + } + +} + +// unused shit! +/* +static void log_log() +{ + #ifdef FOOLOS_LOG_OFF + return; + #endif + + char buf_log[256]; + tfp_sprintf(buf_log,"[ 0.00000] log: buffer state: first=%d, last=%d, buf_size=%d\n",first,last,LOG_BUF_SIZE); + console_put_str_gray(buf_log); + for(int i=first;i!=last;i++) + { + console_put_char_gray(buffer[i]); + + } + + init=true; +} +*/ diff --git a/xxx/lib/logger/log.h b/xxx/lib/logger/log.h new file mode 100644 index 0000000..da27340 --- /dev/null +++ b/xxx/lib/logger/log.h @@ -0,0 +1,14 @@ +#ifndef FOOLOS_LOG_H +#define FOOLOS_LOG_H + +#define FOOLOS_LOG_ERROR 5 +#define FOOLOS_LOG_WARNING 4 +#define FOOLOS_LOG_INFO 3 +#define FOOLOS_LOG_DEBUG 2 +#define FOOLOS_LOG_FINE 1 + +void log(char *module_name, int prio, char *format_string, ...); +void panic(char *module_name, char *format_string); +void log_log(); + +#endif diff --git a/xxx/lib/printf/printf.c b/xxx/lib/printf/printf.c new file mode 100644 index 0000000..23d3d46 --- /dev/null +++ b/xxx/lib/printf/printf.c @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2004,2012 Kustaa Nyholm / SpareTimeLabs + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * Neither the name of the Kustaa Nyholm or SpareTimeLabs nor the names of its + * contributors may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + */ + +#include "printf.h" + +typedef void (*putcf) (void*,char); +static putcf stdout_putf; +static void* stdout_putp; + + +#ifdef PRINTF_LONG_SUPPORT + +static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf) + { + int n=0; + unsigned int d=1; + while (num/d >= base) + d*=base; + while (d!=0) { + int dgt = num / d; + num%=d; + d/=base; + if (n || dgt>0|| d==0) { + *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10); + ++n; + } + } + *bf=0; + } + +static void li2a (long num, char * bf) + { + if (num<0) { + num=-num; + *bf++ = '-'; + } + uli2a(num,10,0,bf); + } + +#endif + +static void ui2a(unsigned int num, unsigned int base, int uc,char * bf) + { + int n=0; + unsigned int d=1; + while (num/d >= base) + d*=base; + while (d!=0) { + int dgt = num / d; + num%= d; + d/=base; + if (n || dgt>0 || d==0) { + *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10); + ++n; + } + } + *bf=0; + } + +static void i2a (int num, char * bf) + { + if (num<0) { + num=-num; + *bf++ = '-'; + } + ui2a(num,10,0,bf); + } + +static int a2d(char ch) + { + if (ch>='0' && ch<='9') + return ch-'0'; + else if (ch>='a' && ch<='f') + return ch-'a'+10; + else if (ch>='A' && ch<='F') + return ch-'A'+10; + else return -1; + } + +static char a2i(char ch, char** src,int base,int* nump) + { + char* p= *src; + int num=0; + int digit; + while ((digit=a2d(ch))>=0) { + if (digit>base) break; + num=num*base+digit; + ch=*p++; + } + *src=p; + *nump=num; + return ch; + } + +static void putchw(void* putp,putcf putf,int n, char z, char* bf) + { + char fc=z? '0' : ' '; + char ch; + char* p=bf; + while (*p++ && n > 0) + n--; + while (n-- > 0) + putf(putp,fc); + while ((ch= *bf++)) + putf(putp,ch); + } + +void tfp_format(void* putp,putcf putf,char *fmt, va_list va) + { + char bf[12]; + + char ch; + + + while ((ch=*(fmt++))) { + if (ch!='%') + putf(putp,ch); + else { + char lz=0; +#ifdef PRINTF_LONG_SUPPORT + char lng=0; +#endif + int w=0; + ch=*(fmt++); + if (ch=='0') { + ch=*(fmt++); + lz=1; + } + if (ch>='0' && ch<='9') { + ch=a2i(ch,&fmt,10,&w); + } +#ifdef PRINTF_LONG_SUPPORT + if (ch=='l') { + ch=*(fmt++); + lng=1; + } +#endif + switch (ch) { + case 0: + goto abort; + case 'u' : { +#ifdef PRINTF_LONG_SUPPORT + if (lng) + uli2a(va_arg(va, unsigned long int),10,0,bf); + else +#endif + ui2a(va_arg(va, unsigned int),10,0,bf); + putchw(putp,putf,w,lz,bf); + break; + } + case 'd' : { +#ifdef PRINTF_LONG_SUPPORT + if (lng) + li2a(va_arg(va, unsigned long int),bf); + else +#endif + i2a(va_arg(va, int),bf); + putchw(putp,putf,w,lz,bf); + break; + } + case 'x': case 'X' : +#ifdef PRINTF_LONG_SUPPORT + if (lng) + uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf); + else +#endif + ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf); + putchw(putp,putf,w,lz,bf); + break; + case 'c' : + putf(putp,(char)(va_arg(va, int))); + break; + case 's' : + putchw(putp,putf,w,0,va_arg(va, char*)); + break; + case '%' : + putf(putp,ch); + default: + break; + } + } + } + abort:; + } + + +void init_printf(void* putp,void (*putf) (void*,char)) + { + stdout_putf=putf; + stdout_putp=putp; + } + +void tfp_printf(char *fmt, ...) + { + va_list va; + va_start(va,fmt); + tfp_format(stdout_putp,stdout_putf,fmt,va); + va_end(va); + } + +static void putcp(void* p,char c) + { + *(*((char**)p))++ = c; + } + + + +void tfp_vsprintf(char* s,char *fmt, va_list va) + { + tfp_format(&s,putcp,fmt,va); + putcp(&s,0); + } + +void tfp_sprintf(char* s,char *fmt, ...) + { + va_list va; + va_start(va,fmt); + tfp_vsprintf(s,fmt,va); + va_end(va); + } + + diff --git a/xxx/lib/printf/printf.h b/xxx/lib/printf/printf.h new file mode 100644 index 0000000..0e65915 --- /dev/null +++ b/xxx/lib/printf/printf.h @@ -0,0 +1,125 @@ +/* +File: printf.h + +Copyright (c) 2004,2012 Kustaa Nyholm / SpareTimeLabs + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or other +materials provided with the distribution. + +Neither the name of the Kustaa Nyholm or SpareTimeLabs nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +OF SUCH DAMAGE. + +---------------------------------------------------------------------- + +This library is realy just two files: 'printf.h' and 'printf.c'. + +They provide a simple and small (+200 loc) printf functionality to +be used in embedded systems. + +I've found them so usefull in debugging that I do not bother with a +debugger at all. + +They are distributed in source form, so to use them, just compile them +into your project. + +Two printf variants are provided: printf and sprintf. + +The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'. + +Zero padding and field width are also supported. + +If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the +long specifier is also +supported. Note that this will pull in some long math routines (pun intended!) +and thus make your executable noticably longer. + +The memory foot print of course depends on the target cpu, compiler and +compiler options, but a rough guestimate (based on a H8S target) is about +1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space. +Not too bad. Your milage may vary. By hacking the source code you can +get rid of some hunred bytes, I'm sure, but personally I feel the balance of +functionality and flexibility versus code size is close to optimal for +many embedded systems. + +To use the printf you need to supply your own character output function, +something like : + +void putc ( void* p, char c) + { + while (!SERIAL_PORT_EMPTY) ; + SERIAL_PORT_TX_REGISTER = c; + } + +Before you can call printf you need to initialize it to use your +character output function with something like: + +init_printf(NULL,putc); + +Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc', +the NULL (or any pointer) you pass into the 'init_printf' will eventually be +passed to your 'putc' routine. This allows you to pass some storage space (or +anything realy) to the character output function, if necessary. +This is not often needed but it was implemented like that because it made +implementing the sprintf function so neat (look at the source code). + +The code is re-entrant, except for the 'init_printf' function, so it +is safe to call it from interupts too, although this may result in mixed output. +If you rely on re-entrancy, take care that your 'putc' function is re-entrant! + +The printf and sprintf functions are actually macros that translate to +'tfp_printf' and 'tfp_sprintf'. This makes it possible +to use them along with 'stdio.h' printf's in a single source file. +You just need to undef the names before you include the 'stdio.h'. +Note that these are not function like macros, so if you have variables +or struct members with these names, things will explode in your face. +Without variadic macros this is the best we can do to wrap these +fucnction. If it is a problem just give up the macros and use the +functions directly or rename them. + +For further details see source code. + +regs Kusti, 23.10.2004 +*/ + + +#ifndef __TFP_PRINTF__ +#define __TFP_PRINTF__ + +#include + +void init_printf(void* putp,void (*putf) (void*,char)); + +void tfp_printf(char *fmt, ...); +void tfp_sprintf(char* s,char *fmt, ...); +void tfp_vsprintf(char* s,char *fmt, va_list va); + +void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va); + +#define printf tfp_printf +#define sprintf tfp_sprintf + +#endif + + + diff --git a/xxx/lib/string/string.c b/xxx/lib/string/string.c new file mode 100644 index 0000000..729c509 --- /dev/null +++ b/xxx/lib/string/string.c @@ -0,0 +1,37 @@ +#include + +//length 0 for null terminated strings; +bool strcmp(char *str1, char *str2, int length) +{ + int i=0; + while(true) + { + if(str1[i]!=str2[i])return false; + i++; + + if(i==length) return true; + if(str1[i]==0||str2[i]==0) + { + if(str1[i]==str2[i])return true; + return false; + } + } + +} + +void* memcpy(void* restrict dstptr, const void* restrict srcptr, int size) +{ + unsigned char* dst = (unsigned char*) dstptr; + const unsigned char* src = (const unsigned char*) srcptr; + for ( int i = 0; i < size; i++ ) + dst[i] = src[i]; + return dstptr; +} + +int strlen(const char* string) +{ + int result = 0; + while ( string[result] ) + result++; + return result; +} diff --git a/xxx/lib/string/string.h b/xxx/lib/string/string.h new file mode 100644 index 0000000..a804de9 --- /dev/null +++ b/xxx/lib/string/string.h @@ -0,0 +1,3 @@ +#include +bool strcmp(char *str1, char *str2, int length); +void* memcpy(void* restrict dstptr, const void* restrict srcptr, int size); diff --git a/xxx/video/vesa.c b/xxx/video/vesa.c new file mode 100644 index 0000000..a5ee4e5 --- /dev/null +++ b/xxx/video/vesa.c @@ -0,0 +1,249 @@ +//http://wiki.osdev.org/GUI +#include +#include "kernel/mem.h" +#include "vesa.h" + +#include "lib/logger/log.h" // logger facilities +#include "lib/printf/printf.h" +#define FOOLOS_MODULE_NAME "vesa" + +#define FOOLSOS_SHOW_VESAMODES + + +static foolfont *deffont; +static vbemodeinfo *VbeModeInfoBlock; + +static int console_x; +static int console_y; + +static int console_lines; +static int console_cols; + +static uint8_t* buffer; +static uint8_t* physbase; + +void PutConsoleNL(); +void PutPixel(int x,int y, int color); + +void vesa_switch_buffers() +{ + for(int i=0;i<800*600*2;i++)physbase[i]=buffer[i]; + +} + +void vesa_put_rect(int x, int y, int w , int h, int color) +{ + for(int i=x;iXres, VbeModeInfoBlock->Yres, 0xffffff); +} + + +void vesa_set_physbase(uint32_t addr) +{ + VbeModeInfoBlock->physbase=addr; +} + + // + // We want to get output to the screen as fast as possible! + // + // Our Fool-Boot-Loader did set up VESA already for us. + // The desired VESA mode is hardcoded in [boot/mbr.asm]. + // + // The [vesa_init(...)] function requires: + // + // * the addresses of the vbeinfo struct + // * the address of the vbemodeinfo struct (for selected mode). + // * Fool Font loaded inside ramimage + // + // The first two paramters are hardcoded in [boot/mbr.asm], + // while the last one is set in the Makefile. The font binary + // is integrated in the kernel image. + // + // this function returns the physical base address of + // our video memory + // + +uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont) +{ + //the only functionallu important init lines! (rest is log) + VbeModeInfoBlock=mode; + deffont=rawfont; + console_x=0; + console_y=0; + + int line_height=12; + int col_width=10; + console_lines=mode->Yres/line_height; + console_cols=mode->Xres/col_width; + + // vesa info + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"vbe version: 0x%x / video mode ptr: 0x%x 0x%x", + info->VbeVersion, info->VideoModePtr[1], info->VideoModePtr[0]); + + // vesa info on selected mode: + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"colors r:%d 0x%x g:%d 0x%x b:%d 0x%x", + mode->red_position,mode->red_mask, + mode->green_position,mode->green_mask, + mode->blue_position,mode->blue_mask); + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"res: %d * %d / banks: %d / attr: 0x%x", + mode->Xres, mode->Yres, mode->banks, mode->attributes); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"bpp: %d / physbase: 0x%x", + mode->bpp,mode->physbase); + + // vesa modes + // todo: take segment from vbeinfo! +#ifdef FOOLSOS_SHOW_VESAMODES + uint16_t *modeptr=info->VideoModePtr[0]; + + while(*modeptr!=0xffff&&*modeptr!=0) + { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"mode supported : 0x%X", (*modeptr)); + modeptr++; + } +#endif + + + return VbeModeInfoBlock->physbase; + +} + +void PutPixel(int x,int y, int color){ + + //do not write memory outside the screen buffer, check parameters against the VBE mode info + if (x<0 || x>VbeModeInfoBlock->Xres|| y<0 || y>VbeModeInfoBlock->Yres) return; + if (x) x = (x*(VbeModeInfoBlock->bpp>>3)); // get bytes (divide by 8) + if (y) y = (y*VbeModeInfoBlock->pitch); + uint8_t *cTemp=VbeModeInfoBlock->physbase; + + cTemp[x+y] = (uint8_t)(color & 0xff); + cTemp[x+y+1] = (uint8_t)((color>>8) & 0xff); + //cTemp[x+y+2] = (uint8_t)((color>>16) & 0xff); + + } + + +void PutFont(char c, int x,int y, int color) +{ + + int fnt=0x126-0x20; + + if(c>=0x20&&c<=0x126)fnt=c-0x20; + + int posx, posy, sizex=8, sizey=10; + + for(posx=x;posx=console_cols)PutConsoleNL(); + #endif +} + +void PutConsole(char *str, int color) +{ + + while((*str)!=0) + { + PutConsoleChar(*str,color); + str++; + } + +} +void PutConsoleNL() +{ + console_x=0; + console_y++; + if(console_y>=console_lines-5)console_y=0; + + for(int i=0;iXres-200,VbeModeInfoBlock->Yres-200,0xff); + vesa_put_rect(boxx-10,boxy-10,20,20,0x999999); + + boxx++; +// boxy+=boxx; + if(boxx>VbeModeInfoBlock->Xres-100)boxx=100; + // if(boxy>VbeModeInfoBlock->Yres-200)boxy=200; + + + vesa_switch_buffers(); +} + +/* +void vesa_init_doublebuff() +{ + boxx=300; + boxy=300; + + int blocks=800*600*2/4096+1; + physbase=VbeModeInfoBlock->physbase; + buffer=pmmngr_alloc_blocks(blocks); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Init buffer of %d blocks at 0x%08X",blocks,buffer); + + VbeModeInfoBlock->physbase=buffer; +} +*/ + + + diff --git a/xxx/video/vesa.h b/xxx/video/vesa.h new file mode 100644 index 0000000..371e944 --- /dev/null +++ b/xxx/video/vesa.h @@ -0,0 +1,47 @@ +#include + +typedef struct foolfont_struct +{ + uint8_t line[10]; //every single fool font consists of 10 lines a 8 bit + +}foolfont; + +typedef struct vbeinfo_struct{ + char VbeSignature[4]; // == "VESA" + uint16_t VbeVersion; // == 0x0300 for VBE 3.0 + uint16_t OemStringPtr[2]; // isa vbeFarPtr + uint8_t Capabilities[4]; + uint16_t VideoModePtr[2]; // isa vbeFarPtr + uint16_t TotalMemory; // as # of 64KB blocks +}vbeinfo; + + +typedef struct ModeInfoBlock { + uint16_t attributes; + uint8_t winA,winB; + uint16_t granularity; + uint16_t winsize; + uint16_t segmentA, segmentB; + uint16_t realFctPtr[2]; +// VBE_FAR(realFctPtr); + uint16_t pitch; // bytes per scanline + + uint16_t Xres, Yres; + uint8_t Wchar, Ychar, planes, bpp, banks; + uint8_t memory_model, bank_size, image_pages; + uint8_t reserved0; + + uint8_t red_mask, red_position; + uint8_t green_mask, green_position; + uint8_t blue_mask, blue_position; + uint8_t rsv_mask, rsv_position; + uint8_t directcolor_attributes; + + volatile uint32_t physbase; // your LFB (Linear Framebuffer) address ;) + uint32_t reserved1; + uint16_t reserved2; +}vbemodeinfo; + +uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont); +void PutConsoleChar(char c, int color); +void PutConsole(char *str, int color); -- cgit v1.2.3