Drawing Using VESA

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
balthasar
Member
Member
Posts: 30
Joined: Mon Mar 31, 2008 8:39 pm
Contact:

Drawing Using VESA

Post by balthasar »

I was able to swich to 800x600@16 using Patched GRUB. Now how do i read the address from the Multiboot specification and begin drawing?

heres some files

multiboot.h (Multiboot Struct File)

Code: Select all

/*========================================================================================
                                 Odyssey Nyu Kernel Sources
(C) 2008 Odyssey-Nyu Technologies

IMPORTANT:  This Odyssey-Nyu software is supplied to you by Odyssey-Nyu Technologies.
("Odyssey-Nyu") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of this 
Odyssey-Nyu software constitutes acceptance of these terms.  If you do not agree 
with these terms, please do not use, install, modify or redistribute this Odyssey-Nyu software.

The Odyssey-Nyu Software is provided by Odyssey-Nyu on an "AS IS" basis.  ODYSSEY-NYU MAKES NO 
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES 
OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING 
THE ODYSSEY-NYU SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 

IN NO EVENT SHALL ODYSSEY-NYU BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT
OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE ODYSSEY-NYU SOFTWARE, HOWEVER
CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY
OR OTHERWISE, EVEN IF ODYSSEY-NYU HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================================*/

// multiboot.h -- Declares the multiboot info structure.

#ifndef MULTIBOOT_H
#define MULTIBOOT_H

#include "common.h"

#define MULTIBOOT_FLAG_MEM     0x001
#define MULTIBOOT_FLAG_DEVICE  0x002
#define MULTIBOOT_FLAG_CMDLINE 0x004
#define MULTIBOOT_FLAG_MODS    0x008
#define MULTIBOOT_FLAG_AOUT    0x010
#define MULTIBOOT_FLAG_ELF     0x020
#define MULTIBOOT_FLAG_MMAP    0x040
#define MULTIBOOT_FLAG_CONFIG  0x080
#define MULTIBOOT_FLAG_LOADER  0x100
#define MULTIBOOT_FLAG_APM     0x200
#define MULTIBOOT_FLAG_VBE     0x400

struct multiboot
{
    u32int flags;
    u32int mem_lower;
    u32int mem_upper;
    u32int boot_device;
    u32int cmdline;
    u32int mods_count;
    u32int mods_addr;
    u32int num;
    u32int size;
    u32int addr;
    u32int shndx;
    u32int mmap_length;
    u32int mmap_addr;
    u32int drives_length;
    u32int drives_addr;
    u32int config_table;
    u32int boot_loader_name;
    u32int apm_table;
    u32int vbe_control_info;
    struct vbeModeInfo *vbe_mode_info;
    u32int vbe_mode;
    u32int vbe_interface_seg;
    u32int vbe_interface_off;
    u32int vbe_interface_len;
}  __attribute__((packed));

struct vbeModeInfo {
  u16int attributes;
  u8int winA,winB;
  u16int granularity;
  u16int winsize;
  u32int segmentA, segmentB;
  u32int pitch; // bytes per scanline

  u16int Xres, Yres;
  u8int Wchar, Ychar, planes, bpp, banks;
  u8int memory_model, bank_size, image_pages;
  u8int reserved0;

  u8int red_mask, red_position;
  u8int green_mask, green_position;
  u8int blue_mask, blue_position;
  u8int rsv_mask, rsv_position;
  u8int directcolor_attributes;

  u32int physbase;  // your LFB address ;)
  u32int reserved1;
  short reserved2;
}  __attribute__((packed));


typedef struct multiboot_header multiboot_header_t;

#endif
drawing.c (My Drawing Code)

Code: Select all

/*========================================================================================
Odyssey Diclonius Kernel Sources
(C) 2008 Odyssey Technologies

IMPORTANT:  This Odyssey software is supplied to you by Odyssey Technologies.
("Odyssey") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of this 
Odyssey software constitutes acceptance of these terms.  If you do not agree 
with these terms, please do not use, install, modify or redistribute this Odyssey software.

The Odyssey Software is provided by Odyssey on an "AS IS" basis.  ODYSSEY MAKES NO 
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES 
OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING 
THE ODYSSEY SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 

IN NO EVENT SHALL ODYSSEY BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT
OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE ODYSSEY SOFTWARE, HOWEVER
CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY
OR OTHERWISE, EVEN IF ODYSSEY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================================*/

// drawing.c -- VESA Drawing commands for Workbench

#include "common.h"
#include "multiboot.h"
#include "drawing.h"

void putpixel(unsigned char* screen, int x,int y, int color)
{
	screen[x+(y<<8)+(y<<6)]=color; 
}

void fillrect(unsigned char *vram, unsigned char r, unsigned char g, unsigned   char b, unsigned char w, unsigned char h) 
{
  unsigned char *where = vram;
  int i,j;
  for (i=0;i<w;i++) 
  {
    for (j=0;j<h;j++) 
	{
      //putpixel(vram,64+j,64+i,(r<<16)+(g<<8)+b);
      where[j*4]=r;
      where[j*4+1]=g;
      where[j*4+2]=b;
    }
    where+=3200;
  }
}
the following here is just put cause thats where the multiboot info is from the init of the kernels C entry point

main.c

Code: Select all

/*========================================================================================
Odyssey Diclonius Kernel Sources
(C) 2008 Odyssey Technologies

IMPORTANT:  This Odyssey software is supplied to you by Odyssey Technologies.
("Odyssey") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of this 
Odyssey software constitutes acceptance of these terms.  If you do not agree 
with these terms, please do not use, install, modify or redistribute this Odyssey software.

The Odyssey Software is provided by Odyssey on an "AS IS" basis.  ODYSSEY MAKES NO 
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES 
OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING 
THE ODYSSEY SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 

IN NO EVENT SHALL ODYSSEY BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT
OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE ODYSSEY SOFTWARE, HOWEVER
CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY
OR OTHERWISE, EVEN IF ODYSSEY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================================*/

/*
 * <main.c>
 * The entry point for the Nyu Kernel
 *
 * 06-05-2008	LucyMeditation	Created
 */

#include <monitor.h>
#include <descriptor_tables.h>
#include <timer.h>
#include <paging.h>
#include <multiboot.h>
#include <fs.h>
#include <initrd.h>
#include <task.h>
#include <syscall.h>
#include <serial.h>
#include <dmode.h>
#include <keyboard.h>
#include <drawing.h>
#include <version.h>
#include <console.h>

extern u32int placement_address;
u32int initial_esp;

int main(struct multiboot *mboot_ptr, u32int initial_stack)
{
    mboot = mboot_ptr;

    isTextMode = 0;
    debugger = 1;

    initial_esp = initial_stack;
    // Initialise all the ISRs and segmentation
    init_descriptor_tables();

	monitor_clear();
	monitor_write("Odyssey Diclonius (Version: "); monitor_write(VERSION); monitor_write(" Build: "); monitor_write(BUILD); monitor_write(")\n");
	monitor_write("(C) 2008 Odyssey Technologies\n");
	monitor_write("1 Logical CPU [Total Physical Memory: "); monitor_write_dec(mboot_ptr->mem_upper); monitor_write("KB]\n\n");

	//Before ksetup set up any varibles that could be in the kernel's command line
		
	ksetup();
	initialise_syscalls();
    //switch_to_user_mode();
	scanpci();
    monitor_write("Welcome to Diclonius!\n\n");
	
	console = 1;
	console_main();
            
    return 0;
}

int ksetup()
{
    asm volatile("sti");
	
    //DO None of this untill were back in protected Mode. This is the inits for Protected mode
    init_timer(50);
    init_serial();
    
	/*
	drive_setup();
	write_sector(0,0xA0,"TESTOMG\0");
	read_sector(0,0xA0);*/
	
    scanpci();
	ASSERT(mboot->mods_count > 0);
    
	u32int initrd_location = *((u32int*)mboot->mods_addr);
    u32int initrd_end = *(u32int*)(mboot->mods_addr+4);
    
	placement_address = initrd_end;
    
	initialise_paging();
    if(debugger == 1) serial_write("Paging Initialised ... \n\r");
    initialise_tasking();
    if(debugger == 1) serial_write("Tasking Initialised ... \n\r");
    fs_root = initialise_initrd(initrd_location);
    if(debugger == 1) serial_write("initrd (System Brefcase) Initialised ... \n\r");
    init_keyboard();
    if(debugger == 1) serial_write("Keyboard Initialised ... \n\r");
    return 0;
}
boot.s

Code: Select all

;/*========================================================================================
;                                 Odyssey Nyu Kernel Sources
;(C) 2008 Odyssey-Nyu Technologies
;
;IMPORTANT:  This Odyssey-Nyu software is supplied to you by Odyssey-Nyu Technologies.
;("Odyssey-Nyu") in consideration of your agreement to the following
;terms, and your use, installation, modification or redistribution of this 
;Odyssey-Nyu software constitutes acceptance of these terms.  If you do not agree 
;with these terms, please do not use, install, modify or redistribute this Odyssey-Nyu software.
;
;The Odyssey-Nyu Software is provided by Odyssey-Nyu on an "AS IS" basis.  ODYSSEY-NYU MAKES NO 
;WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES 
;OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING 
;THE ODYSSEY-NYU SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 
;
;IN NO EVENT SHALL ODYSSEY-NYU BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL 
;DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
;SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT
;OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE ODYSSEY-NYU SOFTWARE, HOWEVER
;CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY
;OR OTHERWISE, EVEN IF ODYSSEY-NYU HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;========================================================================================*/

;
; boot.s -- Kernel start location. Also defines multiboot header.
;

MBOOT_PAGE_ALIGN    equ 1<<0    ; Load kernel and modules on a page boundary
MBOOT_MEM_INFO      equ 1<<1    ; Provide your kernel with memory info
MBOOT_HEADER_MAGIC  equ 0x1BADB002 ; Multiboot Magic value
; NOTE: We do not use MBOOT_AOUT_KLUDGE. It means that GRUB does not
; pass us a symbol table.
MBOOT_HEADER_FLAGS  equ MBOOT_PAGE_ALIGN | MBOOT_MEM_INFO
MBOOT_CHECKSUM      equ -(MBOOT_HEADER_MAGIC + MBOOT_HEADER_FLAGS)
	
[BITS 32]                       ; All instructions should be 32-bit.

[GLOBAL mboot]                  ; Make 'mboot' accessible from C.
[EXTERN code]                   ; Start of the '.text' section.
[EXTERN bss]                    ; Start of the .bss section.
[EXTERN end]                    ; End of the last loadable section.

mboot:
    dd  MBOOT_HEADER_MAGIC      ; GRUB will search for this value on each
                                ; 4-byte boundary in your kernel file
    dd  MBOOT_HEADER_FLAGS      ; How GRUB should load your file / settings
    dd  MBOOT_CHECKSUM          ; To ensure that the above values are correct
    
    dd  mboot                   ; Location of this descriptor
    dd  code                    ; Start of kernel '.text' (code) section.
    dd  bss                     ; End of kernel '.data' section.
    dd  end                     ; End of kernel.
    dd  start                   ; Kernel entry point (initial EIP).

[GLOBAL start]                  ; Kernel entry point.
[EXTERN main]                   ; This is the entry point of our C code

start:
    ; Load multiboot information:
    push esp
    push ebx

    ; Execute the kernel:
    cli                         ; Disable interrupts.
    call main                   ; call our main() function.
    jmp $                       ; Enter an infinite loop, to stop the processor
                                ; executing whatever rubbish is in the memory
                                ; after our kernel!
My OS: NasuTek Ensemble http://code.google.com/p/ensemble/
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Re: Drawing Using VESA

Post by lukem95 »

struct vbeModeInfo {
u16int attributes;
u8int winA,winB;
u16int granularity;
u16int winsize;
u32int segmentA, segmentB;
u32int pitch; // bytes per scanline

u16int Xres, Yres;
u8int Wchar, Ychar, planes, bpp, banks;
u8int memory_model, bank_size, image_pages;
u8int reserved0;

u8int red_mask, red_position;
u8int green_mask, green_position;
u8int blue_mask, blue_position;
u8int rsv_mask, rsv_position;
u8int directcolor_attributes;

u32int physbase; // your LFB address ;)
u32int reserved1;
short reserved2;
} __attribute__((packed));
that looks promising, although that's just a stab in the dark.

you could always scan the PCI bus, and get the BAR from there?
~ Lukem95 [ Cake ]
Release: 0.08b
Image
User avatar
balthasar
Member
Member
Posts: 30
Joined: Mon Mar 31, 2008 8:39 pm
Contact:

Re: Drawing Using VESA

Post by balthasar »

lukem95 wrote:you could always scan the PCI bus, and get the BAR from there?
How do i go about doing that?
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Re: Drawing Using VESA

Post by lukem95 »

Use the Wiki. There have been a lot of threads about it too, recently, so try looking here http://forum.osdev.org/search.php
~ Lukem95 [ Cake ]
Release: 0.08b
Image
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Drawing Using VESA

Post by Combuster »

you could always scan the PCI bus, and get the BAR from there?
That is a *very* nasty way around the standard.

And even then, getting the BAR is not a guarantuee for success. All cards I've tested have at least two BARs, some even four. And the size of the range doesn't guarantuee success either as I have seen one card having two ranges of the same size.

And of course, it fails miserably on pre-PCI hardware. The standard exists for a reason. If you can't use it, its IMNSHO a PEBKAC thing, period.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply