1

I'm interested in writing my own microkernel with graphics support. However, as far as I know there is no way to change the graphics mode without interrupt 0x10, which requires Real Mode. How can I switch between Real and Protected Mode during the application's runtime? I have seen an article on osdev.org, but since I am new to assembly I cannot work out how to implement this.

Technical details:

  • Ubuntu 16.04.4 LTS
  • GCC 7.3.0 cross-compiler (i686-elf)
  • NASM 2.11.08 assembler, but inline GAS-style syntax is fine
Sky Wilshaw
  • 23
  • 1
  • 6
  • 2
    Ubuntu has nothing to do with this, your code will be running freestanding on your hardware or in a PC emulator like DOSBOX. Anyway, you don't have to use `int 0x10`, you could program the VGA hardware directly, assuming your hardware implements VGA I/O registers and not just the BIOS `int 0x10` interface. https://wiki.osdev.org/VGA_Resources – Peter Cordes Feb 27 '18 at 19:41
  • If you are talking about BIOS `int 0x10`, then you are talking about VGA card? There you can definitely set any mode you wish just by setting up the VGA card registers like you want (setting up mode is about 20-50 `out` instructions IIRC, setting up all timings, etc). So your premise is wrong. With modern gfx card you can of course also control it directly from PM, but you would need to write a driver for particular card, which is far from feasible for small project (and pointless, it's much easier to use linux/BSD ABI and driver architecture and open source drivers for Intel or ATI cards). – Ped7g Feb 27 '18 at 19:42
  • about "much easier" to use same ABI/architecture as other OS and "borrow" drivers... I mean much easier than writing the drivers yourself, it would be still quite complex a challenging project, to replicate linux or BSD OS environment from the point of view of driver, especially as modern drivers often contain also shader/cuda compilers and such, so they use considerable portion of POSIX API (as a bonus to the already complex driver API of particular OS). Wait, are you new to assembly? Then just learn how to set up VGA directly, or just copy that, no point to learn to fly when you can't walk. – Ped7g Feb 27 '18 at 19:45
  • Thanks for all the comments, I'm so grateful so many people want to help me! I eventually managed to get it working by adjusting values in my multiboot header with GRUB, so it turns out I didn't need to convert mode manually anyway. What should I do with the question - leave it open or provide an (accepted) answer myself? – Sky Wilshaw Feb 28 '18 at 17:50

1 Answers1

1

The very page you reference has a section that describes what needs to be done to transfer CPU from protected back to real mode. It even has an assembler snippet for that.

To get from real mode to protected mode, use Intel's recommendations given in the Intel SDM volume 3A, chapter 9. Section 9.10.2 given an example of assembly code that is meant to transfer CPU to protected mode.

That said, you are in fact not bound to use INT 10h in real mode. See comments for your question.

Grigory Rechistov
  • 2,104
  • 16
  • 25
  • This wasn't the solution I ended up using (see comments above) but since it is the most correct answer to my original question I've marked it as accepted. Thanks for all the help! – Sky Wilshaw Mar 01 '18 at 15:53