Mail Archives: djgpp/1998/12/17/10:10:20
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I have problem with one of my funtions that usually works fine but crashes
with a general protection-fault evertime when I call the random-function
before. The strange think is, that if I use a loop and put the random-function
in it behind my function it works, but if I try to execute it before I
get this general protection-fault. My function changes the ds-register
and es-registers because it uses "movsl" to copy memory-blocks. So could
anyone tell me if the random function changes something which causes the
crash of my program ?
<br>PS: What my function does is to try to copy an image to the vesa framebuffer.
<br>
<p> void prot_putsprite(unsigned short X1,unsigned short Y1,void *image)
<br>{
<br>unsigned long address;
<br>unsigned short heigth,width,Y=0;
<br>
<p>width=*(unsigned short *)image;
<br>heigth=*(unsigned short *)((unsigned char *)image+2);
<br>(unsigned char *)image+=4; /* update pointer so that it points to the
<br>
image-information*/
<br>address=Y1*infomode.BytesPerScanline+X1;
<br>asm("cld");/*clear direction flag so that esi and edi are increased*/
<br>do
<br>{
<br>asm("pushb %ds");/*save data-segment*/
<br>asm("movw %0,%%es":
<br>
:"r"((unsigned short) vesa_framebuffer) );/*selector for framebuffer*/
<br>asm("movl %0,%%edi" :
<br>
:"r"(address) ); /*address in framebuffer*/
<br>asm("movl %0,%%esi":
<br>
:"r"(image) ); /*pointer to image*/
<br>asm("movw %0,%%cx" :
<br>
:"r"(width) ); /*count of bytes to move*/
<br>asm("movw %0,%%ds":
<br>
:"r"(program-selector) ); /*same as _my_ds() */
<br>asm("movb %cl,%bl ");/* get the number of bytes which aren't
completely
<br>
divisible by 4*/
<br>asm("shr $2,%ecx ");/* calculate count of dword-movement*/
<br>asm("and $3,%bl ");
<br>asm("rep\n\t"
<br>
"movsl":
<br>
:
<br>
:"%ecx","%esi","%edi"); /* move 4-bytes at one time*/
<br>asm("movb %bl,%cl");
<br>asm("rep\n\t"
<br>
"movsb":
<br>
:
<br>
:"%ecx","%esi","%edi");/*move the bytes which aren't completely
<br>
divisible by 4*/
<br>asm("popb %ds");/*restore data-segment*/
<br>(unsigned char *)image+=width;/* update pointer*/
<br>address+=infomode.BytesPerScanline;/* update address in framebuffer*/
<br>Y++;
<br>}while(Y<=heigth);
<p>}
<br>
<p>PPS: I have written it in assembler because so I can move 4 bytes at
one time without making a conditionel jump and reloading all needed registers
if the width of the image isn't completely divisible by 4.
<br>PPPS: Propably this discription won't help you much.
<br> </html>
- Raw text -