Unable to read video memory?

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
shiz98
Posts: 10
Joined: Sun Jul 29, 2007 8:59 pm

Unable to read video memory?

Post by shiz98 »

I'm in the middle of writing my memory manager for my kernel, and I've been getting some errors, which I've tracked down to my video code. It's worked fine up to now, but once I have to scroll, I run into trouble. Virtual PC just resets (I guess I'm crashing the "system"), and bochs gives me a message about vetoing memory read from 0xB80A0. The call that causes the problem looks like this:

Code: Select all

memcpy((unsigned char*)VideoMemory, (unsigned char*)(VideoMemory + (80 * times)), ((25 * 80) - (80 * times)) * 2);
times is the number of lines to scroll.

This call to memcpy, as far as I can tell, is correct for what I'm trying to do (shift the text on the screen up [times] lines). This means that my problem lies with memcpy. I've written it correctly, though, with a simple implementation:

Code: Select all

unsigned char *memcpy(unsigned char *dest, const unsigned char *src, unsigned int count)
{
    unsigned char *ret = dest;
    while (count--)
          *dest++ = *src++;
    return ret;
}
So... can you guys offer me any clue as to what's going on here?
jzgriffin
Member
Member
Posts: 190
Joined: Tue Sep 26, 2006 1:40 pm
Libera.chat IRC: Nokurn
Location: Ontario, CA, USA
Contact:

Post by jzgriffin »

Paste the rest of your scroll code, e.g. how did you find times.
shiz98
Posts: 10
Joined: Sun Jul 29, 2007 8:59 pm

Post by shiz98 »

Right now I just set times =1. There's nothing else before the memcpy call. Since it's giving me a read problem from the memory address I'm reading from (eg, with times = 1, i'm copying FROM 0xB80A0 to 0xB8000), I'm thinking the problem lies not with my memcpy function (since it can't even read the first byte), but with something else.

It doesn't make much sense to me.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

do you use paging, if so did you correctly assign the 0xb8000 address space?
Author of COBOS
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Try this:

Code: Select all

// shift all the memory up a row
memcpy( (void*) (0xB8000 - 160), (char*) 0xB8000, ( 80 * 25 * 2 ) );

// framebuffer for last line
unsigned long long* fb = (unsigned long long*) (0xB8000 + ((80*24)*2));

// blank the last line
for( int z = 0; z < 20; z++ )
    fb[z] = 0x0720;
If that doesn't work, I don't know what will.

Note: I just noted some of the variable sizes seem a bit weird there... AFAIK it works though.
shiz98
Posts: 10
Joined: Sun Jul 29, 2007 8:59 pm

Post by shiz98 »

That didn't work either, and to be honest, I think my code's a little more efficient :P.

I'm thinking that it might be best just to make a buffer of whatever is written to the screen, and read from that instead of video memory. It would solve whatever problem I'm having.
User avatar
Candy
Member
Member
Posts: 3883
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

You may want to replace that memcpy call with a memmove call as memcpy isn't guaranteed to work on overlapping memory areas. This isn't the cause of the crash though.
Post Reply