From 7aea8d20ec8816759c8439fc39d90579fc37e18b Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Wed, 27 Aug 2014 23:10:04 +0200 Subject: cleanup and switched logging to vesa mode console! --- kernel/floppy.c | 79 ++++++++++++++++++------------------- kernel/interrupts.c | 5 +++ kernel/kernel.c | 42 +++++++------------- kernel/kernel.h | 3 +- kernel/mem.c | 28 +++++--------- kernel/pci.c | 29 +++----------- kernel/shell.c | 12 ++---- kernel/timer.c | 5 ++- kernel/vesa.c | 109 ++++++++++++++++++++++++++++++++++------------------ kernel/vmem.c | 2 +- 10 files changed, 154 insertions(+), 160 deletions(-) (limited to 'kernel') diff --git a/kernel/floppy.c b/kernel/floppy.c index a373ec7..557df2a 100644 --- a/kernel/floppy.c +++ b/kernel/floppy.c @@ -17,6 +17,10 @@ #include "x86.h" +#include "../lib/logger/log.h" // logger facilities +#define FOOLOS_MODULE_NAME "floppy" + + #define FLPY_SECTORS_PER_TRACK 18 static volatile int _CurrentDrive=0; @@ -26,7 +30,6 @@ static volatile uint8_t _FloppyDiskIRQ = 0; //! initialize DMA to use phys addr 1k-64k void flpydsk_initialize_dma () { - scr_put_string_nl("dma: initialize direct memory access"); x86_outb (0x0a,0x06); //mask dma channel 2 x86_outb (0xd8,0xff); //reset master flip-flop @@ -39,15 +42,15 @@ void flpydsk_initialize_dma () { x86_outb (0x05, 0x23); x86_outb (0x80, 0); //external page register = 0 x86_outb (0x0a, 0x02); //unmask dma channel 2 + log("dma",FOOLOS_LOG_INFO,"initialized"); } //! prepare the DMA for read transfer void flpydsk_dma_read () { - x86_outb (0x0a, 0x06); //mask dma channel 2 x86_outb (0x0b, 0x56); //single transfer, address increment, autoinit, read, channel 2 x86_outb (0x0a, 0x02); //unmask dma channel 2 - scr_put_string_nl("dma: configured for reading"); + log("dma",FOOLOS_LOG_INFO,"configured for reading"); } //! prepare the DMA for write transfer @@ -56,7 +59,7 @@ void flpydsk_dma_write () { x86_outb (0x0a, 0x06); //mask dma channel 2 x86_outb (0x0b, 0x5a); //single transfer, address increment, autoinit, write, channel 2 x86_outb (0x0a, 0x02); //unmask dma channel 2 - scr_put_string_nl("dma: configured for writing"); + log("dma",FOOLOS_LOG_INFO,"configured for writing"); } // // @@ -157,7 +160,7 @@ void sleep(int i) void flpydsk_motor_on() { - scr_put_string("floppy: starting motor..."); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"starting motor..."); //x86_outb (FLPYDSK_DOR, FLPYDSK_DOR_MASK_DRIVE0_MOTOR | FLPYDSK_DOR_MASK_RESET); x86_outb (FLPYDSK_DOR, 0x1c); sleep(20); @@ -165,7 +168,7 @@ void flpydsk_motor_on() } void flpydsk_motor_off() { - scr_put_string("floppy: stopping motor..."); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"stopping motor..."); x86_outb (FLPYDSK_DOR, 0x0c); //x86_outb (FLPYDSK_DOR,FLPYDSK_DOR_MASK_RESET); scr_put_string_nl("ok"); @@ -178,7 +181,7 @@ int flpydsk_calibrate (uint32_t drive) { if (drive >= 4) { - scr_put_string_nl("floppy: ERROR"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"ERROR!"); return -2; } @@ -188,7 +191,7 @@ int flpydsk_calibrate (uint32_t drive) { int i; for (i = 0; i < 10; i++) { - scr_put_string_nl("floppy: calibrate"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"calibrating"); //! send command flpydsk_send_command ( FDC_CMD_CALIBRATE ); flpydsk_send_command ( drive ); @@ -198,14 +201,14 @@ int flpydsk_calibrate (uint32_t drive) { //! did we fine cylinder 0? if so, we are done if (!cyl) { if(st0 & 0xC0) { - scr_put_string_nl("floppy: calibration FAILED!"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"calibrating FAILED!"); } // flpydsk_control_motor (false); flpydsk_motor_off(); return 0; } } - scr_put_string_nl("floppy: calibration FAILED!"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"calibrating FAILED!"); // flpydsk_control_motor (false); flpydsk_motor_off(); @@ -239,7 +242,7 @@ uint8_t flpydsk_read_data () { if ( flpydsk_read_status () & FLPYDSK_MSR_MASK_DATAREG ) return x86_inb (FLPYDSK_FIFO); - scr_put_string_nl("floppy: read data fail!"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"reading data FAILED!"); } void flpydsk_send_command (uint8_t cmd) { @@ -251,7 +254,7 @@ void flpydsk_send_command (uint8_t cmd) { x86_outb(FLPYDSK_FIFO, cmd); return; } - scr_put_string_nl("floppy: write data fail!"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"writing data FAILED!"); } void flpydsk_drive_data (uint32_t stepr, uint32_t loadt, uint32_t unloadt, int dma ) { @@ -272,7 +275,7 @@ void flpydsk_reset() uint32_t st0, cyl; //! reset the controller - scr_put_string_nl("floppy: reset controller"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"reset controller"); flpydsk_disable_controller (); flpydsk_enable_controller (); flpydsk_wait_irq (); @@ -301,7 +304,7 @@ void int_floppy_handler() { X86_IRQ_BEGIN - scr_put_string_nl("floppy: inside interrupt handler."); +// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"handling interrupt"); _FloppyDiskIRQ=1; X86_IRQ_END @@ -309,10 +312,10 @@ void int_floppy_handler() void flpydsk_wait_irq() { - scr_put_string_nl("floppy: wait for irq6"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"waiting for irq6"); while ( _FloppyDiskIRQ == 0); _FloppyDiskIRQ = 0; - scr_put_string_nl("floppy: ok received "); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"irq6 received"); } void flpydsk_check_int (uint32_t* st0, uint32_t* cyl) { @@ -325,12 +328,12 @@ void flpydsk_check_int (uint32_t* st0, uint32_t* cyl) { void flpydsk_write_sector_imp (uint8_t head, uint8_t track, uint8_t sector) { - sector=1; + //sector=1; //! set the DMA for read transfer flpydsk_dma_write (); //flpydsk_drive_data (13, 1, 0xf, 0); - scr_put_string_nl("floppy: writing (head/track/sector)"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"writing head/track/sector"); uint32_t st0, cyl; @@ -372,7 +375,7 @@ void flpydsk_read_sector_imp (uint8_t head, uint8_t track, uint8_t sector) { flpydsk_dma_read (); //flpydsk_drive_data (13, 1, 0xf, 0); - scr_put_string_nl("floppy: reading (head/track/sector)"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"reading head/track/sector"); uint32_t st0, cyl; @@ -422,11 +425,7 @@ int flpydsk_seek ( uint32_t cyl, uint32_t head ) int i; for (i = 0; i < 10; i++ ) { - scr_put_string("floppy: seeking (cyl/head) : "); - scr_put_hex(cyl); - scr_put_string("/"); - scr_put_hex(head); - scr_put_string_nl(""); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"seeking cyl: %d, head: %d",cyl,head); //! send the command flpydsk_send_command (FDC_CMD_SEEK); @@ -462,9 +461,7 @@ void flpydsk_lba_to_chs (int lba,int *head,int *track,int *sector) { uint8_t* flpydsk_read_sector (int sectorLBA) { - scr_put_string("floppy: reading sector:"); - scr_put_hex(sectorLBA); - scr_put_string_nl("."); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"reading sector: %d",sectorLBA); if (_CurrentDrive >= 4) @@ -495,10 +492,7 @@ uint8_t* flpydsk_read_sector (int sectorLBA) { uint8_t* flpydsk_write_sector (int sectorLBA) { - scr_put_string("floppy: writing sector:"); - scr_put_hex(sectorLBA); - scr_put_string_nl("."); - + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"writing sector: %d",sectorLBA); if (_CurrentDrive >= 4) return 0; @@ -533,8 +527,8 @@ void floppy_init() _CurrentDrive=0; _FloppyDiskIRQ = 0; - - scr_put_string_nl("floppy: init floppy driver."); + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"driver init"); flpydsk_reset (); // flpydsk_drive_data (13, 1, 0xf, 0); @@ -543,18 +537,19 @@ void floppy_init() // // - scr_put_string_nl("floppy: test read (sector 0)."); - flpydsk_read_sector(64); //0x8000 here the data starts! - scr_put_string_nl("floppy: data: "); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test read (sector: 1)"); + flpydsk_read_sector(1); + uint16_t *dma=0xb000; + int i; for(i=0;i<10;i++) - scr_put_hex(dma[i]); - - scr_put_string_nl(""); - - /* - scr_put_string_nl("floppy: test write (sector 100)."); + { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test read 0x%04x ",dma[i]); + } + +/* + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test write (sector: 100)"); flpydsk_write_sector(100); */ diff --git a/kernel/interrupts.c b/kernel/interrupts.c index bac687b..b166669 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -1,6 +1,9 @@ #include "interrupts.h" #include "x86.h" +#include "../lib/logger/log.h" // logger facilities +#define FOOLOS_MODULE_NAME "interrupts" + // the interrupt descriptor table static struct int_desc { @@ -31,6 +34,7 @@ void int_disable() void int_enable() { __asm__("sti"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"up and running"); } @@ -76,6 +80,7 @@ void int_init(uint16_t sel) int_install_ir(i, 0b10001110, sel,&int_def_handler); } + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initializing..."); } void int_install() diff --git a/kernel/kernel.c b/kernel/kernel.c index c260e80..f4e440f 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -2,6 +2,9 @@ #include "console.h" // this will allow us to write to screen #include "x86.h" +#include "../lib/logger/log.h" // logger facilities +#define FOOLOS_MODULE_NAME "kernel" + // TODO: cleanup . how can i compile it without the includes!?? /////// @@ -22,7 +25,7 @@ void int_test_handler() { X86_IRQ_BEGIN - scr_put_string("inside software interrupt handler 88"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"inside interrupt handler 88"); sleep(30); X86_IRQ_END @@ -50,27 +53,24 @@ void kernel_main() // is integrated in the kernel image. // vesa_init(0x8300,0x8400,0x7200); - while(1); // never ending loop - // clear console -//! scr_clear(); - - // hello message -//! scr_put_string_nl(KERNEL_HELLO_MESSAGE); -//! scr_put_string_nl(""); + // + // Now Fool OS can say hello :) + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,KERNEL_HELLO_MESSAGE); - //pit config + // + // PIT config (timer) timer_init(); - // we know that here the bootloader placed the mamory map! -//! mem_init(0x7c00+0x400,*((uint16_t *)(0x7c00+0x600))); - mem_init(0x9000); - + // we know that here, the bootloader placed the mamory map! + mem_init(0x7c00+0x400,*((uint16_t *)(0x7c00+0x600))); + // paging (Todo) - vmem_init(); + //vmem_init(); // init and interrupt decriptor table int_init(0x08); + int_install(); // setup custom interrupts @@ -95,7 +95,6 @@ void kernel_main() // now we can enable interrupts back again int_enable(); -//! scr_put_string_nl("interrupts: Interrupts are up and running"); // pci pci_init(); @@ -103,22 +102,9 @@ void kernel_main() // floppy floppy_init(); -//! scr_put_string_nl(""); - - //init shell shell_init(); - // kernel main loop - -// while(1) - // { - //} - - // put some text on monitor! - - - while(1); // never ending loop diff --git a/kernel/kernel.h b/kernel/kernel.h index 5d10738..9f42fdf 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -3,7 +3,8 @@ #include //needed for uint16_t -#define KERNEL_HELLO_MESSAGE "FoolOs 0.0.5" +#define KERNEL_HELLO_MESSAGE "Welcome to FoolOs 0.0.6" + // #define DEBUG #endif diff --git a/kernel/mem.c b/kernel/mem.c index 68880be..b2e674e 100644 --- a/kernel/mem.c +++ b/kernel/mem.c @@ -1,6 +1,9 @@ #define MEM_PRINT_MEMORYMAP #include "kernel.h" +#include "../lib/logger/log.h" // logger facilities +#define FOOLOS_MODULE_NAME "mem" + //! 8 blocks per byte #define PMMNGR_BLOCKS_PER_BYTE 8 @@ -208,11 +211,10 @@ void mem_test(int start, int end, int steps) void mem_init(uint16_t *memmap,uint16_t entries) { - scr_put_string("mem: the memory map contains "); - scr_put_hex(entries); - scr_put_string_nl(" entries."); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"the memory map contains %d entries.",entries); // hardcoded memory bitmap!!??! + // todo: fix! _mmngr_memory_map=0x9000; mem_free_blocks=0; pmmngr_init (); @@ -229,21 +231,11 @@ void mem_init(uint16_t *memmap,uint16_t entries) #ifdef MEM_PRINT_MEMORYMAP - scr_put_hex(memmap[8]); - scr_put_string(" : "); - - - scr_put_hex(memmap[1]); - scr_put_string(" "); - scr_put_hex(memmap[0]); - scr_put_string(" "); - - scr_put_string(" - "); - scr_put_hex(memmap[5]); - scr_put_string(" "); - scr_put_hex(memmap[4]); - - scr_put_string_nl(""); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%x : 0x%08x - 0x%08x", + memmap[8], + (((uint32_t)memmap[1])<<16)+memmap[0], + (((uint32_t)memmap[1])<<16)+memmap[0] + +(((uint32_t)memmap[5])<<16)+memmap[4]); #endif diff --git a/kernel/pci.c b/kernel/pci.c index 8aa5eb9..c8bd95d 100644 --- a/kernel/pci.c +++ b/kernel/pci.c @@ -1,5 +1,7 @@ #include "kernel.h" #include "x86.h" +#include "../lib/logger/log.h" // logger facilities +#define FOOLOS_MODULE_NAME "pci" #define PCI_CONFIG_DATA 0xCFC #define PCI_CONFIG_ADDRESS 0xCF8 @@ -61,23 +63,8 @@ void test_bar(uint8_t bus, uint8_t slot, uint8_t offset) // restore original values pciConfigSet(bus,slot,0,offset,(bar_high<<16)+bar_low); - scr_put_string("e1000: BAR: "); - if(bar_low& 1)scr_put_string("i/o "); - else scr_put_string("mem "); - - - scr_put_hex(bar_high); - scr_put_hex(bar_low); - - scr_put_string(" size: "); - - scr_put_hex(size_high); - scr_put_hex(size_low); - scr_put_string(" => "); - scr_put_hex32(size); - - - scr_put_string_nl(";"); + + log("e1000",FOOLOS_LOG_INFO,"%s bar: (0x%x 0x%x) size: 0x%x" ,bar_low&1?"i/o":"mem",bar_high, bar_low, size); } @@ -91,11 +78,7 @@ uint16_t pciCheck(uint8_t bus, uint8_t slot) if ((vendor = pciConfigReadWord(bus,slot,0,0)) != 0xFFFF) { device = pciConfigReadWord(bus,slot,0,2); - scr_put_string("pci: "); - scr_put_hex(vendor); - scr_put_hex(device); - scr_put_string_nl(";"); - + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"[%d,%d]: vendor: 0x%x / device: 0x%x",bus,slot,vendor,device); // check for: E1000 (82540EM). PCI Ethernet Controller if(vendor==0x8086&&device==0x100e) @@ -126,7 +109,7 @@ uint16_t pciCheck(uint8_t bus, uint8_t slot) void pci_init() { - scr_put_string_nl("pci: scanning pci bus"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"scanning bus"); // todo: recurse on pci to pci bridges! // todo: support multiple pci host controllers! // (check more funcitons of device 0:0) diff --git a/kernel/shell.c b/kernel/shell.c index ebbeb51..2c7fc95 100644 --- a/kernel/shell.c +++ b/kernel/shell.c @@ -1,5 +1,7 @@ #include "kernel.h" #include "interrupts.h" +#include "../lib/logger/log.h" // logger facilities +#define FOOLOS_MODULE_NAME "shell" #define COMMAND_LENGTH 255 @@ -55,12 +57,7 @@ void shell_execute() if(1==strcmp(command,"TIME")) { - scr_put_hex(timer16); - scr_put_string(" seconds passed since system start."); - } - else if(1==strcmp(command,"INT")) - { - scr_put_hex(int_unhandled); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d seconds passed since system start.",timer16); } else if(1==strcmp(command,"EIGHT")) { @@ -72,11 +69,10 @@ void shell_execute() } else { - scr_put_string(" unsupported command, sorry!"); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"command unknown"); } pos=0; - scr_nextline(); scr_put_string("Command> "); diff --git a/kernel/timer.c b/kernel/timer.c index b4787b9..f2e512c 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -34,6 +34,9 @@ #include "kernel.h" #include "x86.h" +#include "../lib/logger/log.h" // logger facilities +#define FOOLOS_MODULE_NAME "timer" + static uint64_t timer64=0; static uint8_t timer8=0; uint16_t timer16=0; @@ -89,5 +92,5 @@ void timer_init() __asm__("popa"); - scr_put_string_nl("timer: Configured PIT Channel 0 : Mode 2 : 1/25 s."); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Configured PIT Channel 0 : Mode 2 : 1/25 s."); } diff --git a/kernel/vesa.c b/kernel/vesa.c index 43e0dfb..8bac363 100644 --- a/kernel/vesa.c +++ b/kernel/vesa.c @@ -1,6 +1,10 @@ //http://wiki.osdev.org/GUI +#include #include "kernel.h" +#include "../lib/logger/log.h" // logger facilities +#define FOOLOS_MODULE_NAME "vesa" + typedef struct vbeinfo_struct{ char VbeSignature[4]; // == "VESA" uint16_t VbeVersion; // == 0x0300 for VBE 3.0 @@ -42,57 +46,47 @@ typedef struct foolfont_struct }foolfont; - static foolfont *deffont; static vbemodeinfo *VbeModeInfoBlock; +static console_x; +static console_y; + +static console_lines; +static console_cols; + void vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont) { - //the only functionallu important 2 init lines! (rest is log) + //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; - PutString("Welcome to Fool OS 001",30,30,0xfff00); + // vesa info + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"setup complete. vbe version: 0x%x / video mode ptr: 0x%x 0x%x", + info->VbeVersion, info->VideoModePtr[1], info->VideoModePtr[0]); - int i=0; - scr_put_string("vesa: init vbe version: "); - scr_put_hex(info[i].VbeVersion); - scr_put_string(" / videomode ptr: "); - scr_put_hex(info[i].VideoModePtr[0]); - scr_put_hex(info[i].VideoModePtr[1]); - scr_put_string_nl(""); + // vesa info on selected mode: + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"res: %d * %d / banks: %d / attr: 0x%x / bpp: %d / physbase: 0x%x", + mode->Xres, mode->Yres, mode->banks, mode->attributes, mode->bpp,mode->physbase); - int *modeptr=info[i].VideoModePtr[0]; // todo: take segment from vbeinfo! + // vesa modes + // todo: take segment from vbeinfo! +#ifdef FOOLSOS_SHOW_VESAMODES + uint16_t *modeptr=info->VideoModePtr[0]; while(*modeptr!=0xffff&&*modeptr!=0) { - - scr_put_string("vesa: mode supported: "); - scr_put_hex(*modeptr); - scr_put_string_nl(""); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"mode supported : 0x%x", (*modeptr)); modeptr++; } - - scr_put_string("vesa: selected mode res: "); - scr_put_hex(mode->Xres); - scr_put_string(" x "); - scr_put_hex(mode->Yres); - scr_put_string_nl(""); - scr_put_string("vesa: selected mode banks: "); - scr_put_hex(mode->banks); - scr_put_string_nl(""); - scr_put_string("vesa: attribs: "); - scr_put_hex(mode->attributes); - scr_put_string_nl(""); - scr_put_string("vesa: physbase: "); - scr_put_hex32(mode->physbase); - scr_put_string_nl(""); - scr_put_string("vesa: bpp: "); - scr_put_hex(mode->bpp); - scr_put_string_nl(""); - - +#endif } @@ -116,11 +110,13 @@ void PutFont(char c, int x,int y, int color) if(c>='A'&&c<='Z')fnt=c-'A'+1; else if(c>='a'&&c<='z')fnt=c-'a'+1; else if(c>='0'&&c<='9')fnt=c-'0'+28; - else if(c=' ')fnt=27; + else if(c==' ')fnt=27; int posx, posy, sizex=8, sizey=10; for(posx=x;posxconsole_cols)PutConsoleNL(); + } + +} +void PutConsoleNL() +{ + console_x=0; + console_y++; + if(console_y>console_lines)console_y=1; + for(int i=0;i