Weird? (VirtualPC)

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.
Post Reply
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Weird? (VirtualPC)

Post by neon »

Hey everyone,

I am kind of curious at what can cause this. I have the following code in my bootloader (for temporary debugging purposes):

Code: Select all

char* p = (char*)0x100000;

for (int i=0; i<30; i++)
	get_bios()->puts ("%c", p[i]);
If i<10 it works fine in Bochs and Virtual PC (It displays garbage as expected). if i<30 (in the above case) it works okay in Bochs, however VirtualPC stalls and beeps (A very long beep in fact). It continues soon after the beep.

However, if I have valid data there it works fine. Does anyone know why this can be? I never seen that happen before... :/

Its not a problem; its more of a curiosity question. Thanks for any input :)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Weird? (VirtualPC)

Post by Brendan »

Hi,

One of the ASCII characters is called "bell" (character 0x07). The when the BIOS "output a character" function sees this character it's meant to do a short beep on the PC speaker. If the BIOS outputs several beep characters they run together and sound like one long beep instead of many short beeps.

I'd assume that you're using the BIOS function, and there's several "bell" characters in the garbage you're displaying; and that either the garbage is different on Bochs or Bochs emulates a disconnected PC speaker.

Note: I honestly don't know if sound works in Bochs or not - I know it doesn't use the host PC speaker to emulate the guest PC speaker, but it might use the host sound card to emulate the guest PC speaker. My development machines/servers have always been "soundless" (no sound driver or speakers for my current machine and no sound card in the previous machine).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Zenith
Member
Member
Posts: 224
Joined: Tue Apr 10, 2007 4:42 pm

Re: Weird? (VirtualPC)

Post by Zenith »

Maybe there's a bunch of bell characters at that area in Virtual PC :D

Edit: Damn, I was beaten to it by Brendan. I thought phpBB3 warned if someone made a post before you submit yours?
"Sufficiently advanced stupidity is indistinguishable from malice."
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Weird? (VirtualPC)

Post by neon »

Brendan wrote:One of the ASCII characters is called "bell" (character 0x07). The when the BIOS "output a character" function sees this character it's meant to do a short beep on the PC speaker.
That is what I was originally thinking, it just seemed kind of strange for it to beep for as long as it did. I suppose its possible though. After I used memset() to clear the 30 bytes at that location before the for loop executed (in the original post) it worked fine. I just think its strange for a long series of beep characters to be in array within an area of garbage memory (Which is why I posted out of interest).

Thanks for your answers! :D
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Weird? (VirtualPC)

Post by Brendan »

Hi,
neon wrote:I just think its strange for a long series of beep characters to be in array within an area of garbage memory (Which is why I posted out of interest).
The bell characters don't need to be in series - if you've got a bell character, then 20 other characters, then another bell character, then the computer will display those other character so fast that you won't be able to notice the extremely tiny gap between the bell characters.

Statistically, the chance of getting 1 bell character in 30 random bytes is 30/256 (11.7% chance), and the chance of getting 2 bell characters in 30 random bytes is about 1.37%. Garbage memory isn't truly random though. For example, maybe the area of memory was previously used as a buffer for text mode video data, and every second byte is 0x07 (the attribute bytes were "light grey foreground with black background").

Lastly, different virtual machines handle time differently. For example, one "guest second" might actually be 4 "host seconds", so maybe there's only one bell character...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Weird? (VirtualPC)

Post by Love4Boobies »

Actually there's no such thing as "random" at all. There's pseudo-random, though (off-topic).

Anyway, you can check by putting bell characters there yourself and seeing what Virtual PC has to say about it.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply