Bochs VBE how to return to Text mode?

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.
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Bochs VBE how to return to Text mode?

Post by Octocontrabass »

fano1 wrote:The only way to drive BGA is using VBE right?
Wrong, you don't need INT 0x10 at all. You can write a native BGA driver using this information.
fano1 wrote:I don't think it is more slower emulating VBE but I have little hopes that using it natively it will have hardware accelerations to draw lines, rectangles and so on...
BGA doesn't have hardware acceleration.
fano1
Member
Member
Posts: 29
Joined: Sun May 01, 2016 7:24 am

Re: Bochs VBE how to return to Text mode?

Post by fano1 »

To be clear we have already a working driver in Cosmos that has been written using probably using that guide you linked all is working a part two things:
  • I wanted a Clear(Color) command and I've done it but it is really inefficient as for now our fill method is simply using a for() of words so it is doing 4'000'000 of times! I fear I'll have to resort to X# (that is assembler)
  • I wanted to have a way to return to Text Mode when I have finished to use the GraphicMode (as DOS did when you played a game and then when the game finished you returned to the DOS text mode prompt), it seems for now the only solutions would to have a real VBE driver (but is difficult to do this / impossible in protected mode) or to have an hybrid solution and set registers that in this driver should not exist. Probably the better way will be to fix the Bochs VBE extensions and add a way to return to text mode :mrgreen:
The idea to do the "text mode" all in graphic mode is securely a possibility I suspect that Linux does this or how Tux could be in the right corner of the screen? Using graphic mode will "magically" solve the UTF-16 support as using real fonts we could display characters of any language too!

On the other hand we would run Cosmos on headless devices too... well probably the switch between real text mode and "emulated" text mode could happen automatically in some way! But is the future probably :D
Last edited by fano1 on Mon Jan 09, 2017 3:40 pm, edited 1 time in total.
Member of the Cosmos OS CoreTeam
Cosmos Official Site
Do you to help us to develop it? Join our chat!
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Bochs VBE how to return to Text mode?

Post by SpyderTL »

I found a bug report from 2009 on sourceforge. It doesn't look like it's been addressed, as far as I can tell.

https://sourceforge.net/p/bochs/bugs/1080/
https://sourceforge.net/p/bochs/mailman ... /11181631/

The second link is a forum discussion about this bug from 2008, and includes a suggestion:
Looking at http://bochs.sourceforge.net/doc/docbook/user/x75.html it
tells you to use the LGPL'ed VGABIOS.
I may try playing around with that when I get a few minutes...
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Bochs VBE how to return to Text mode?

Post by Octocontrabass »

fano1 wrote:I wanted a Clear(Color) command and I've done it but it is really inefficient as for now our fill method is simply using a for() of words so it is doing 4'000'000 of times! I fear I'll have to resort to X# (that is assembler)
What kind of code is in that for loop? There are some potential optimizations that don't involve writing it in assembly.
fano1 wrote:it seems for now the only solutions would to have a real VBE driver (but is difficult to do this / impossible in protected mode)
There are different levels of difficulty...

The easiest is to write an x86 instruction interpreter and put together a small emulator. You can simulate INT 0x10 in your emulator to control the video card. As long as you are aware of the limitations (it only works with legacy BIOS, not UEFI; it needs to read/write the IVT and BDA) you'll be fine.
fano1 wrote:or to have an hybrid solution and set registers that in this driver should not exist.
It's not unusual for video cards to have standard VGA registers and extended non-VGA registers. The only difference is that Bochs puts the extended registers at a different I/O address. With SVGA cards like the Cirrus (which Bochs also supports), the extended registers are accessed the same way as the standard VGA registers.
fano1 wrote:Probably the better way will be to fix the Bochs VBE extensions and add a way to return to text mode :mrgreen:
They already do have a way to return to text mode: disable the extensions and set up text mode using the standard VGA registers. :roll:
fano1 wrote:The idea to do the "text mode" all in graphic mode is securely a possibility I suspect that Linux does this or how Tux could be in the right corner of the screen?
That's exactly how Linux does it.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Bochs VBE how to return to Text mode?

Post by Love4Boobies »

I added a link to the official documentation.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
fano1
Member
Member
Posts: 29
Joined: Sun May 01, 2016 7:24 am

Re: Bochs VBE how to return to Text mode?

Post by fano1 »

Octocontrabass wrote:
fano1 wrote:I wanted a Clear(Color) command and I've done it but it is really inefficient as for now our fill method is simply using a for() of words so it is doing 4'000'000 of times! I fear I'll have to resort to X# (that is assembler)
What kind of code is in that for loop? There are some potential optimizations that don't involve writing it in assembly.
The code is written in C# but is in an unsafe block so the de facto should be fast as C code:

Code: Select all

        public unsafe void Fill(UInt32 aStart, UInt32 aCount, UInt32 aData)
        {
            UInt32* xDest = (UInt32*)(this.Base + aStart);
            for (UInt32 i = 0; i < aCount; i++)
            {
                *xDest = aData;
                xDest++;
            }
        }
Indeed I suspect this code will not fast in C too... I'm unsure if C memset() is faster to fill a 9 MB array!

In Cosmos we use a lightweight abstraction called "MemoryBlock" to abstract the x86 IO Ports:
https://github.com/CosmosOS/Cosmos/blob ... ryBlock.cs
Octocontrabass wrote:
fano1 wrote:it seems for now the only solutions would to have a real VBE driver (but is difficult to do this / impossible in protected mode)
There are different levels of difficulty...

The easiest is to write an x86 instruction interpreter and put together a small emulator. You can simulate INT 0x10 in your emulator to control the video card. As long as you are aware of the limitations (it only works with legacy BIOS, not UEFI; it needs to read/write the IVT and BDA) you'll be fine.
OK for now our plan is to support Virtual Machines with this BGA/VBE driver we have covered Bochs, QEMU and Virtualbox already, we have a driver for the VmWare GPU too but need to be tested to see if it works.

The real VBE driver at that point could wait until will be ready to run Cosmos in real hardware.
Octocontrabass wrote:
fano1 wrote:The idea to do the "text mode" all in graphic mode is securely a possibility I suspect that Linux does this or how Tux could be in the right corner of the screen?
That's exactly how Linux does it.
Interesting... nevertheless UFT-8 not works in Linux a simply accented 'è' risk to appear as something weird never understood what they do of wrong I suspect that the problem are really in the fonts!
Member of the Cosmos OS CoreTeam
Cosmos Official Site
Do you to help us to develop it? Join our chat!
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Bochs VBE how to return to Text mode?

Post by Octocontrabass »

fano1 wrote:The code is written in C# but is in an unsafe block so the de facto should be fast as C code:

[...]

Indeed I suspect this code will not fast in C too... I'm unsure if C memset() is faster to fill a 9 MB array!
You may be able to gain some speed by unrolling the loop, especially if you mostly use this function to fill the entire screen. There are limits to what you can gain through loop unrolling, so do benchmarks if you don't see obvious speed differences.
fano1 wrote:Interesting... nevertheless UFT-8 not works in Linux a simply accented 'è' risk to appear as something weird never understood what they do of wrong I suspect that the problem are really in the fonts!
There's a lot more to Unicode than just fonts. There may be other reasons for your text being mangled.
fano1
Member
Member
Posts: 29
Joined: Sun May 01, 2016 7:24 am

Re: Bochs VBE how to return to Text mode?

Post by fano1 »

I've done the test in C++ using the function std::fill() and indeed the time to file a 9 MB array is negligible! Surely std::fill() is not using a for (or maybe is using bigger blocks than an Int32... maybe using C++ SSE intrinsic) but I'm thinking there is bigger difference too I'm writing to RAM not to a IOPort that could be slower... maybe an optimization could to do the for() in a byte[] and only at the end assign the array to our MemoryBlock. What do you think?

What do you mean to unroll the loop?
Member of the Cosmos OS CoreTeam
Cosmos Official Site
Do you to help us to develop it? Join our chat!
User avatar
matt11235
Member
Member
Posts: 286
Joined: Tue Aug 02, 2016 1:52 pm
Location: East Riding of Yorkshire, UK

Re: Bochs VBE how to return to Text mode?

Post by matt11235 »

fano1 wrote:What do you mean to unroll the loop?
To unroll the loop is to take everything out of the loop, example:

Code: Select all

// before loop unrolling
for (int i = 0; i < 3; i++)
   foo(i);

// after loop unrolling
foo(0);
foo(1);
foo(2);
There are advantages and disadvantages to unrolling loops, you shouldn't do it manually (let the compiler do it instead).
You can pass -funroll-loops to GCC to enable it for the whole compilation unit, or maybe apply it to your clear method only with attribute((optimize("unroll-loops"))).
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Bochs VBE how to return to Text mode?

Post by Octocontrabass »

fano1 wrote:but I'm thinking there is bigger difference too I'm writing to RAM not to a IOPort that could be slower...
You mean MMIO, not port IO, right? And yes, you may be right about MMIO being slower than RAM. That's why I said to benchmark your optimizations: they may not be faster than what you already have.
fano1 wrote:maybe an optimization could to do the for() in a byte[] and only at the end assign the array to our MemoryBlock. What do you think?
Generally, memcpy() is slower than memset(). In practice, the LFB may be too slow for that to make a difference.
fano1
Member
Member
Posts: 29
Joined: Sun May 01, 2016 7:24 am

Re: Bochs VBE how to return to Text mode?

Post by fano1 »

I'm unsure if is possible but I though to do this (metacode):

Code: Select all

int[MemoryBlock.Size] buffer;
UInt32* xDest = (UInt32*)(this.Base + aStart)

fixed {
      int *bufferPtr = buffer;
      for (UInt32 i = 0; i < aCount; i++)
      {
      *buffer = aData;
       buffer++;
      }
      xDest = buffer;
}
Probably not a good idea as then the Garbage Collector could never collect 'buffer' as now the MemoryBlock points to it...

@zenzizenzicube
In the trivial case (resolution of 320x240) the loop should be unrolled 307200 times... actually the MemoryBlock is 1920x1200 (HD 16:10 resolution) so I don't think GCC would unroll this loop in this case too... 'aCount' is neither a constant.

In any case Cosmos is written in C# (the metacode above is unsafe code obviously) and is using our compiler (IL2CPU) that in this phase does not a lot of optimization in the code (on purpose).
Member of the Cosmos OS CoreTeam
Cosmos Official Site
Do you to help us to develop it? Join our chat!
Post Reply