delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/17/10:10:20

Message-ID: <36791F45.28CC128@gmx.net>
Date: Thu, 17 Dec 1998 16:12:05 +0100
From: Christian Hofrichter <ChristianHofrichter AT gmx DOT net>
X-Mailer: Mozilla 4.5 [de]C-CCK-MCD QXW03201 (Win95; I)
X-Accept-Language: de,en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: problem with random-functions
Reply-To: djgpp AT delorie DOT com

<!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&nbsp; 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>&nbsp;
<p>&nbsp;void prot_putsprite(unsigned short X1,unsigned short Y1,void *image)
<br>{
<br>unsigned long address;
<br>unsigned short heigth,width,Y=0;
<br>&nbsp;
<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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
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&nbsp; %0,%%es":
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
:"r"((unsigned short) vesa_framebuffer) );/*selector for framebuffer*/
<br>asm("movl&nbsp; %0,%%edi" :
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
:"r"(address) ); /*address in framebuffer*/
<br>asm("movl&nbsp; %0,%%esi":
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
:"r"(image) ); /*pointer to image*/
<br>asm("movw&nbsp; %0,%%cx"&nbsp; :
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
:"r"(width) ); /*count of bytes to move*/
<br>asm("movw&nbsp; %0,%%ds":
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
:"r"(program-selector) ); /*same as _my_ds() */
<br>asm("movb&nbsp; %cl,%bl ");/* get the number of bytes which aren't
completely
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
divisible by&nbsp; 4*/
<br>asm("shr&nbsp;&nbsp; $2,%ecx ");/* calculate count of dword-movement*/
<br>asm("and&nbsp;&nbsp; $3,%bl ");
<br>asm("rep\n\t"
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"movsl":
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
:"%ecx","%esi","%edi"); /* move 4-bytes at one time*/
<br>asm("movb&nbsp; %bl,%cl");
<br>asm("rep\n\t"
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"movsb":
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
:"%ecx","%esi","%edi");/*move the bytes which aren't completely
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
divisible by&nbsp; 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&lt;=heigth);
<p>}
<br>&nbsp;
<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>&nbsp;</html>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019