Page 1 of 1

Unable to read video memory?

Posted: Sun Jul 29, 2007 9:11 pm
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?

Posted: Sun Jul 29, 2007 9:37 pm
by jzgriffin
Paste the rest of your scroll code, e.g. how did you find times.

Posted: Mon Jul 30, 2007 7:22 pm
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.

Posted: Tue Jul 31, 2007 12:58 am
by os64dev
do you use paging, if so did you correctly assign the 0xb8000 address space?

Posted: Tue Jul 31, 2007 1:11 am
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.

Posted: Wed Aug 01, 2007 6:49 pm
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.

Posted: Wed Aug 01, 2007 10:45 pm
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.