amandude wrote:
Is there a "full" example or code that I could use to get in real or v86 mode, or is there an alternative way to display a bmp in long mode?
You're confusing "modes". First, there's CPU mode. This can be real mode, prot mode or long mode.
Second, there's video mode. This has nothing to do with the CPU mode. To display a bitmap, you'll need a framebuffer, and you can use that framebuffer from whatever CPU mode you'd like. In order to get the framebuffer, you have to use VESA BIOS, which only runs in real mode. Therefore you have the following options:
- if you're in real mode, then it's ok
- if you're in prot mode, then either you switch to real mode or you use V86 virtual mode
- if you're in long mode, then the only possibility is to switch to real mode.
There are other possibilities though: you could write your own video card driver (very hard), or you could use an x86 real mode emulator to interpret the VESA BIOS in long mode (several OS does this, not easy, but not particularly hard either, it is slow, but works.), and on modern machines there's no VESA BIOS at all, only UEFI GOP which is only accessible during boot.
Again, setting up the framebuffer has nothing to do with how you display a bitmap on it and from which CPU mode. You only set up the framebuffer once (so it okay if this is slow), and then you can use the framebuffer as many times and for as long as you want from long mode.
To set up the video, see the wiki:
VESA Video Bios ExtensionUEFI GOPUsing Multiboot to get a framebufferYou might consider
BOOTBOOT, which loads 64 bit kernels, executes them in long mode, and sets up the framebuffer for them too out-of-the-box.
For plotting a pixel (this is for prot mode, but works in long mode too, does not require VESA/GOP etc. to plot pixels, just a pointer to the framebuffer, no matter how and from where you got that pointer):
Drawing in a linear framebufferFor decoding and displaying bitmap files, see
Loading iconsI'd like to point out that TGA files are much better and much more portable than Windows BMP files, you probably want to aim for those. There's lots of confusion with Windows and OS/2 bitmaps. TGA is simple, and the wiki contains a small (~50 SLoC) code that can handle almost every variants. For PNG, I'd recommend Sean Barrett's stb_image.h header only library.
As for the "full" examples,
This code runs in long mode and uses GOP to get the framebuffer, then it displays a PNG image at the centre of the screen.
This also runs in long mode, it clears the screen then displays a TGA logo at the centre. Only supports 64 x 64 RLE-compressed paletted images, it's a very optimized code (for an implementation that can decode arbitrary TGA, see the wiki). It does not set the video mode, instead it relies on the
boot loader to do that (similar like if you were relying on Multiboot, but unlike Multiboot, this works
![Wink ;-)](./images/smilies/icon_wink.gif)
)
This code also runs in long mode, also relies on the boot loader for the set up, and it displays actual bitmaps (in this PSF2 font, every glyph is a 8 x 16 bitmap)
Cheers,
bzt