From d85b6209f37b4d886f9e85fd9592c9d7cf25deb9 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Wed, 27 Aug 2014 15:56:52 +0200 Subject: further cleanup of bootloader --- boot/mbr.asm | 71 ++++++++++++++++++-------------------------------- boot/vesa_setup_16.asm | 47 +++++++++++++++++++++++++++++++++ kernel/kernel.c | 39 ++++++++++++++------------- kernel/textwindow.c | 33 +++++++++++++++++++++++ 4 files changed, 126 insertions(+), 64 deletions(-) create mode 100644 boot/vesa_setup_16.asm create mode 100644 kernel/textwindow.c diff --git a/boot/mbr.asm b/boot/mbr.asm index 2beac7b..83edefc 100644 --- a/boot/mbr.asm +++ b/boot/mbr.asm @@ -21,8 +21,12 @@ ; * the vesa mode specified by VESA_MODE_SELECT is set up ; (at VESA_MODES, and VESA_MODE_INFO additional info structs are available) ; +; * interrupts disabled +; ; * 32-bit protected mode was set up. ; +; * esp set to 0x90000 (Todo: take care of it!?) +; ; * A20 gate is open ; ; * PICs are configured @@ -31,6 +35,8 @@ ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;we want 16-bit instructions, before we switch to 32-bit protected mode. +[bits 16] ;define origin of boot record in memory: 0x7c00 ;this is where the BIOS per definition will put the first @@ -38,8 +44,10 @@ ;The Boot record is identified by the last 2 magic bytes: 0xaa55 (?) [org 0x7c00] -;define where we will load our kernel into memory and some +;define some constants +;where we will load our kernel into memory and some ;other memory locations + KERNEL_OFFSET equ 0x1000 MEMMAP_SIZE_OFFSET equ 0x7c00+0x600 MEMMAP_OFFSET equ 0x7c00+0x400 @@ -47,33 +55,36 @@ VESA_MODES equ 0x8300 VESA_MODE_INFO equ 0x8400 VESA_MODE_SELECT equ 0x4114 -;we want 16-bit instructions, before we switch to 32-bit protected mode. -[bits 16] jmp boot_16 ;start boot process -;SOME Global Data, mainly strings +;SOME Global Data, mainly info/error strings BOOT_DRIVE: db 0xff STR_VERSION: - db "v0.2~",0 - -VESA_CHECK: - db "vesa check.",0 + db "v0.3~",0 +VESA_CHECK1: + db "vesa1.",0 +VESA_CHECK2: + db "vesa2.",0 +VESA_CHECK3: + db "vesa3.",0 ;lets put our temporary GDT (Global Descriptor Table) here +;kernel should move this away %include "boot/GDT.asm" -;include 16-bit real mode routines (print_string, disk_load) +;include 16-bit real mode routines (print_string, disk_load, vesa_setup) %include "boot/disk_load_16.asm" %include "boot/print_string_16.asm" +%include "boot/vesa_setup_16.asm" ;include our routines for switching to 32-bit protected mode %include "boot/pm.asm" -;pic mapping +;pic_setup mapping routing %include "boot/pic.asm" -;get memory map +;get memory map routine %include "boot/memmap.asm" ;;;;;;;; BOOT 16-bit real ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -105,42 +116,9 @@ boot_16: mov di,MEMMAP_OFFSET call BiosGetMemoryMap ; this will also put the number of entries ; of the memory map at MEMMAP_SIZE_OFFSET - + ;VESA: also setup vesa stuff before entering 32 bit protected mode - ;VESA: get all available vesa modes! - mov ax,0 ; set target address in es:di (0:offset) - mov es,ax - mov di,VESA_MODES - mov ax,0x4f00 ;vesa function: Get Controller Info - int 0x10 ; call the interrupt to get the data from the bios! - vesa_err: - mov bx, VESA_CHECK - call print_string - cmp ax,0x004f - je vesa_ok - jmp vesa_err - vesa_ok: - ; - - ;VESA: get vesa info on mode of interest - mov ax,0 ; set target address in es:di (0:offset) - mov es,ax - mov di,VESA_MODE_INFO - mov ax,0x4f01 ;vesa function: Get Mode Info - mov cx,VESA_MODE_SELECT - int 0x10 ; call the interrupt to get the data from the bios! - vesa_err2: - mov bx, VESA_CHECK - call print_string - cmp ax,0x004f - je vesa_ok2 - jmp vesa_err2 - vesa_ok2: - - ;VESA: finally switch to the mode of choice! - mov ax,0x4f02 ;vesa function: Set Mode - mov bx,VESA_MODE_SELECT - int 0x10 + call VesaSetup ;finally lets enter Protected mode!!! call switch_to_pm @@ -154,6 +132,7 @@ boot_32_pm: ;enable A20 ;http://www.brokenthorn.com/Resources/OSDev9.html ;Method 3.1: Enables A20 through keyboard controller + ;todo: check if this has any effect at all !?!? mov al, 0xdd ; command 0xdd: enable a20 out 0x64, al ; send command to controller diff --git a/boot/vesa_setup_16.asm b/boot/vesa_setup_16.asm new file mode 100644 index 0000000..4f276b5 --- /dev/null +++ b/boot/vesa_setup_16.asm @@ -0,0 +1,47 @@ +VesaSetup: + + pusha + + ;VESA: get all available vesa modes! + mov ax,0 ; set target address in es:di (0:offset) + mov es,ax + mov di,VESA_MODES + mov ax,0x4f00 ;vesa function: Get Controller Info + int 0x10 ; call the interrupt to get the data from the bios! + vesa_err: + mov bx, VESA_CHECK1 + call print_string + cmp ax,0x004f + je vesa_ok + jmp vesa_err + vesa_ok: + ; + + ;VESA: get vesa info on mode of interest + mov ax,0 ; set target address in es:di (0:offset) + mov es,ax + mov di,VESA_MODE_INFO + mov ax,0x4f01 ;vesa function: Get Mode Info + mov cx,VESA_MODE_SELECT + int 0x10 ; call the interrupt to get the data from the bios! + vesa_err2: + mov bx, VESA_CHECK2 + call print_string + cmp ax,0x004f + je vesa_ok2 + jmp vesa_err2 + vesa_ok2: + + ;VESA: finally switch to the mode of choice! + mov ax,0x4f02 ;vesa function: Set Mode + mov bx,VESA_MODE_SELECT + int 0x10 + vesa_err3: + mov bx, VESA_CHECK3 + call print_string + cmp ax,0x004f + je vesa_ok3 + jmp vesa_err3 + vesa_ok3: + popa + ret diff --git a/kernel/kernel.c b/kernel/kernel.c index 05a4f9f..efa703b 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -5,7 +5,8 @@ // TODO: cleanup . how can i compile it without the includes!?? /////// - +// interrupt handler prototypes +// todo: move somewhere else!? void int_def_handler(); void int_clock_handler(); void int_kb_handler(); @@ -14,7 +15,9 @@ void int_floppy_handler(); ////////// KERNEL MAIN///// ///// // -// test handler +// just a test handler for software interrupt 88, todo: remove and +// implement some syscalls! +// void int_test_handler() { X86_IRQ_BEGIN @@ -26,22 +29,23 @@ void int_test_handler() } +// heart of our operating system void kernel_main() { // clear console - scr_clear(); +//! scr_clear(); // hello message - scr_put_string_nl(KERNEL_HELLO_MESSAGE); - scr_put_string_nl(""); +//! scr_put_string_nl(KERNEL_HELLO_MESSAGE); +//! scr_put_string_nl(""); //pit config - //timer_init(); + timer_init(); // we know that here the bootloader placed the mamory map! - mem_init(0x7c00+0x400,*((uint16_t *)(0x7c00+0x600))); - //mem_init(0x9000); +//! mem_init(0x7c00+0x400,*((uint16_t *)(0x7c00+0x600))); + mem_init(0x9000); // we know that here the bootloader placed the mamory map! vmem_init(); @@ -72,34 +76,33 @@ void kernel_main() // now we can enable interrupts back again int_enable(); - scr_put_string_nl("interrupts: Interrupts are up and running"); +//! scr_put_string_nl("interrupts: Interrupts are up and running"); // pci pci_init(); + // floppy + floppy_init(); + // vesa init vesa_init(0x8300,0x8400); - // floppy - floppy_init(); - scr_put_string_nl(""); +//! scr_put_string_nl(""); //init shell shell_init(); // kernel main loop - uint8_t t=0; - uint8_t o=0; // while(1) // { //} - //uint8_t rawfont[]={0xff,0xff,0xc3,0xc3,0xff,0xff,0xc3,0xc3}; - //uint8_t rawfont[]={0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xff,0xff,}; - uint8_t *rawfont=0xb000; // here the floppy_init puts first sector - // after 0x8000 (font data :)) + // put some text on monitor! + + uint8_t *rawfont=0xb000; // here the floppy_init puts first sector + // after 0x8000 (font data :)) PutString(rawfont,"Welcome to Fool OS 001",10,10,0xff00); PutString(rawfont,"Welcome to Fool OS 001",20,20,0xf00); diff --git a/kernel/textwindow.c b/kernel/textwindow.c new file mode 100644 index 0000000..77c0cbc --- /dev/null +++ b/kernel/textwindow.c @@ -0,0 +1,33 @@ +#define FOOLOS_TEXTWINDOW_BUFFER_SIZE 10000 +static char *buff; + +void textwin_init(int x,int y,int w,int h,char *title, int r,int g, int b) +{ + +} + +void textwin_move(int x,int y) +{ + +} + +void textwin_resize(int w,int h) +{ + +} + +void textwin_putchar(char c) +{ + +} + +void textwin_putline(char *str,...) +{ + +} + +void textwin_render() +{ + +} + -- cgit v1.2.3