I have just made a simple OS, with GRUB bootloader and a kernel in c.
It is in text mode at the moment and prints "Hello, world!"
How can I set it to graphics mode and display one pixel on the screen.
I would like, ideally, some code samples or links to code that will work, just to play around with.
My OS needs graphics, and does not need other functions yet as, at the moment, is is purely a graphical test, not a usable OS.
OS put pixel
Re: OS put pixel
That certainly gets me the pixel, so thanks.
But I am still stuck over getting from text mode into graphics mode, or getting the screen resolution to something higher than text mode
But I am still stuck over getting from text mode into graphics mode, or getting the screen resolution to something higher than text mode
Re: OS put pixel
Using Grub I cannot tell you. I don't use it nor have ever used it.
However, if I know it well enough, Grub has placed you in a protected mode state. If this is the case, you have two options:
1) Write a device driver for the installed video card, which now involves:
1a) A PCI driver, at least to enumerate the PCI to find the video card.
1b) Find information about the video card. This can be quite difficult some times.
1c) This only works on the single machine you try it on, unless the next has the exact same video card.
or
2) Go back to (un)real and use the BIOS to change to a graphics mode. However, this involves:
2a) returning to (un)real mode *or* using a virtual86 mode.
2b) calling a few BIOS calls to see what modes are available
2c) calling the BIOS to change to a found video mode.
2d) returning back to protected mode.
With this in mind, why use Grub to begin with? Also, with this in mind, I would think that there has to be a way to use Grub to change to a graphics mode...
Anyway, in my opinion, and it may be different that others, dump Grub and write your own boot and loader code. Reasons:
1) You learn how a boot loader is created
2) You learn to program in real mode (at least a little)
3) You learn how to use the BIOS
4) You learn how a file system works
5) You learn how to write in assembly
6) You learn...
7) You learn...
Did I mention, you learn things, not only to learn but because it is part of the whole package of writing an Operating System.
Anyway, just my opinion and opinions are like that thing you sit on, every one has one and it usually stinks...
Ben
- http://www.fysnet.net/osdesign_book_series.htm
However, if I know it well enough, Grub has placed you in a protected mode state. If this is the case, you have two options:
1) Write a device driver for the installed video card, which now involves:
1a) A PCI driver, at least to enumerate the PCI to find the video card.
1b) Find information about the video card. This can be quite difficult some times.
1c) This only works on the single machine you try it on, unless the next has the exact same video card.
or
2) Go back to (un)real and use the BIOS to change to a graphics mode. However, this involves:
2a) returning to (un)real mode *or* using a virtual86 mode.
2b) calling a few BIOS calls to see what modes are available
2c) calling the BIOS to change to a found video mode.
2d) returning back to protected mode.
With this in mind, why use Grub to begin with? Also, with this in mind, I would think that there has to be a way to use Grub to change to a graphics mode...
Anyway, in my opinion, and it may be different that others, dump Grub and write your own boot and loader code. Reasons:
1) You learn how a boot loader is created
2) You learn to program in real mode (at least a little)
3) You learn how to use the BIOS
4) You learn how a file system works
5) You learn how to write in assembly
6) You learn...
7) You learn...
Did I mention, you learn things, not only to learn but because it is part of the whole package of writing an Operating System.
Anyway, just my opinion and opinions are like that thing you sit on, every one has one and it usually stinks...
Ben
- http://www.fysnet.net/osdesign_book_series.htm
Re: OS put pixel
thanks, the only reason i was using grub was because i assumed it would have a way to do all this already, but i may try to write my own loader
i did something similar but figured it would be easier to use grub, so i ditched it.
how do i change to video mode in real mode?
is it the
or what ever mode?
i did something similar but figured it would be easier to use grub, so i ditched it.
how do i change to video mode in real mode?
is it the
Code: Select all
mov ah, 0
mov al, 13h
int 10h
Re: OS put pixel
Don't just ditch things like that, or trust me, you'll never get anywhere. It's a lot more work to create a decent bootloader than it is to set video mode with GRUB.Harri45 wrote:thanks, the only reason i was using grub was because i assumed it would have a way to do all this already, but i may try to write my own loader
i did something similar but figured it would be easier to use grub, so i ditched it.
how do i change to video mode in real mode?
is it theor what ever mode?Code: Select all
mov ah, 0 mov al, 13h int 10h
Grub has an example of drawing to screen in their docs: https://www.gnu.org/software/grub/manua ... 002ec.html
But yes, int 0x10 with ah=0 sets the video mode.
Also, I notice that you've been asking quite a bit of these questions, many of which are easily google-able. The ability to google problems is an important skill for any learner, so you might wanna try and practice that one (or DuckDuckGo, which I like. Whatever floats your boat)
Re: OS put pixel
If you are using GRUB, I assume you use multiboot compatible kernel image. If that's the case then feel free to use this piece of NASM code. I hope it's self explanatory. I you want to know more about it look here: http://www.gnu.org/software/grub/manual ... iboot.html
To determine the address of a framebuffer, you have to check section '3.3 Boot information format' of previously mentioned html. GRUB stores physical address of 'Multiboot information' structure in EBX register.
Code: Select all
%define MULTIBOOT_MAGIC 0x1BADB002
%define MULTIBOOT_FLAGS 0x00000007
%define VIDEO_USE_TEXT 0 ; 0 for graphics mode, 1 for text mode
%define VIDEO_WIDTH 1024 ; width (pixels for graphics and characters for text mode)
%define VIDEO_HEIGHT 768 ; height
%define VIDEO_BPP 32 ; bpp (ignored for text mode)
[bits 32]
segment .text
global _multiboot_header
align 4 ; multiboot header must be 4 bytes aligned and be contained in first 8k of the image file
_multiboot_header:
dd MULTIBOOT_MAGIC ; magic
dd MULTIBOOT_FLAGS ; flags
dd -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS) ; checksum
dd 0, 0, 0, 0, 0 ; header_addr, load_addr, load_end_addr, bss_end_addr, entry_addr (all 0 for i386 ELF images)
dd VIDEO_USE_TEXT, VIDEO_WIDTH, VIDEO_HEIGHT, VIDEO_BPP ; mode_type, width, height, depth
Re: OS put pixel
Thanks everyone, i have it working now. pvc's code worked to get the resolution and the osdev wiki helped with the pixel placing.