My VGA driver prints garbage on screen

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.
mrfrustrationman
Posts: 13
Joined: Sun Jun 14, 2020 5:15 pm
Libera.chat IRC: mrfrust

Re: My VGA driver prints garbage on screen

Post by mrfrustrationman »

Octocontrabass wrote:

Code: Select all

objcopy -O binary -j .text kernel\kernel.out kernel\kernel.bin
Strings are usually stored in the .rodata section, but you're discarding everything except the .text section. Any particular reason you use objcopy here instead of passing "--oformat binary" to ld like the tutorial does?
if you mean using the "--oformat binary" in the ld cmd, it doesn't work, it gives the following error: "ld cannot perform pe operations on non pe output file 'kernel.bin'", and how do i include the .rodata section too?
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: My VGA driver prints garbage on screen

Post by MichaelPetch »

One other issue I see is that when you use objcopy you tell it to only include the `.text` section in the resulting binary. So if you properly link with `-Ttext 0x1000` nothing in any of your other sections will be emitted and likely that includes the string you want to print. Any reason you don't do:

Code: Select all

objcopy -O binary kernel\kernel.out kernel\kernel.bin
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: My VGA driver prints garbage on screen

Post by MichaelPetch »

It should be noted that for native windows applications (which is what your MinGW tool chain is generating) the read only data section is actually called .rdata instead of .rodata and it can be a number of sections that start with `.rdata` so it is more like `.rdata*`
Last edited by MichaelPetch on Mon Jun 15, 2020 8:56 am, edited 1 time in total.
mrfrustrationman
Posts: 13
Joined: Sun Jun 14, 2020 5:15 pm
Libera.chat IRC: mrfrust

Re: My VGA driver prints garbage on screen

Post by mrfrustrationman »

MichaelPetch wrote:One other issue I see is that when you use objcopy you tell it to only include the `.text` section in the resulting binary. So if you properly link with `-Ttext 0x1000` nothing in any of your other sections will be emitted and likely that includes the string you want to print. Any reason you don't do:

Code: Select all

objcopy -O binary kernel\kernel.out kernel\kernel.bin
It worked!!! Thanks! It was the objcopy, this was giving me a headache since saturday!
Octocontrabass
Member
Member
Posts: 5574
Joined: Mon Mar 25, 2013 7:01 pm

Re: My VGA driver prints garbage on screen

Post by Octocontrabass »

You might have an easier time if you use a proper cross-compiler, like everyone else does.

If you're using Windows 10, you might try installing WSL and build a cross-compiler there. (But it's tricky to get QEMU to launch from a build script, since you'd need to set up GUI support.)

If you're not using Windows 10, or if you want something slightly more "native" to Windows, try MSYS2. (The Windows version of QEMU works here.)
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: My VGA driver prints garbage on screen

Post by MichaelPetch »

Octocontrabass wrote:You might have an easier time if you use a proper cross-compiler, like everyone else does.

If you're using Windows 10, you might try installing WSL and build a cross-compiler there. (But it's tricky to get QEMU to launch from a build script, since you'd need to set up GUI support.)
. I agree with you on the cross compiler. I had commented about that on Stackoverflow where this question was cross posted.

Getting X Windows working on WSL isn't too difficult. Download Xming X11 server from: https://sourceforge.net/projects/xming/ . Then launch into a WSL prompt and modify ~/.bashrc by adding this line to the bottom:

Code: Select all

export DISPLAY=:0
. Exit out of the WSL shell and relaunch it. Then all you need to do is make sure the XMing server is running and the X11 output from WSL should appear. qemu should work as expected.
mrfrustrationman
Posts: 13
Joined: Sun Jun 14, 2020 5:15 pm
Libera.chat IRC: mrfrust

Re: My VGA driver prints garbage on screen

Post by mrfrustrationman »

MichaelPetch wrote:
Octocontrabass wrote:You might have an easier time if you use a proper cross-compiler, like everyone else does.

If you're using Windows 10, you might try installing WSL and build a cross-compiler there. (But it's tricky to get QEMU to launch from a build script, since you'd need to set up GUI support.)
. I agree with you on the cross compiler. I had commented about that on Stackoverflow where this question was cross posted.

Getting X Windows working on WSL isn't too difficult. Download Xming X11 server from: https://sourceforge.net/projects/xming/ . Then launch into a WSL prompt and modify ~/.bashrc by adding this line to the bottom:

Code: Select all

export DISPLAY=:0
. Exit out of the WSL shell and relaunch it. Then all you need to do is make sure the XMing server is running and the X11 output from WSL should appear. qemu should work as expected.
Wich stackoverflow question? I posted this just here...
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: My VGA driver prints garbage on screen

Post by MichaelPetch »

mrfrustrationman wrote:Wich stackoverflow question? I posted this just here...
I happened to ask if you were one in the same on the Stackoverflow question, but didn't get a response there. That question uses the same tutorial and had a problem with printing using the same vga driver, uses MinGW and BOCHS on Windows. That question was here: https://stackoverflow.com/questions/623 ... y#62378540 . The output they were getting is an identical screenshot as to the one you posted here: https://prnt.sc/szpyzt

Sorry if you are not the same person - you have my apologies. It is pretty coincidental that two users ask nearly the identical question in 48 hours. Maybe this is for a course and it was a classmate?
asos
Posts: 1
Joined: Wed Jun 17, 2020 5:47 pm

Re: My VGA driver prints garbage on screen

Post by asos »

You can execute regular windows .exe programs through WSL, including both Bochs and QEMU. You just have to point to its path on the C: drive i.e

$> /mnt/c/Program\ Files/qemu/qemu-system-i386.exe -s -S -kernel myos.bin

So no need to try and get X to work
Post Reply