Mail Archives: djgpp/1996/06/14/01:16:56
The following code dies with this error:
[Exactly what I did]
D:\DJGPP2\PROJECTS\LIGHTS>make -ftestmake -W test.cc
gcc -Wall -O3 test.cc -o test
coff2exe test
D:\DJGPP2\PROJECTS\LIGHTS>test
Hello.
Exiting due to signal SIGSEGV
General Protection Fault at eip=000015a2
eax=76a1a69a ebx=00022080 ecx=00040000 edx=0000018a esi=002b9004
edi=001b8004
ebp=001b7fd8 esp=001b7fc4 cs=00a7 ds=00af es=00af fs=00af gs=00c7
ss=00af
Call frame traceback EIPs:
0x000015a2 _main+74
0x00001b03 ___crt1_startup+115
[End of What Got Me Into Trouble]
[The Code]
#include <stdlib.h>
#include <stdio.h>
#include <go32.h>
int main( void )
{
printf("Hello.\n");
char *buf1 = (char *)malloc(1024*1024);
char *buf2 = (char *)malloc(1024*1024);
int times = 1024*1024/4;
int stamp1, stamp2;
short _our_ds = _go32_my_ds();
asm("
movw %5,%%fs
cli
.byte 0x0f
.byte 0x31 #//RDTSC
movl %%eax, %0
movl %%fs:(,%2,4),%%eax
#// ^^This scale is the culprit.
#//Anything other than 1 for scale crashes.
#//The .S file looks okay, too.
.byte 0x0f
.byte 0x31 #//RDTSC
movl %%eax, %1
sti
"
:"=m" (stamp1),"=m" (stamp2)
:"D"(buf1),"S"(buf2)
,"c"(times)
,"m"(_our_ds),"m"(_our_ds)
:"%eax","%ecx"
);
int cycles;
if (stamp2 > stamp1)
cycles = stamp2 - stamp1;
else
cycles = stamp2 + (0xffffffff - stamp1) + 1;
printf("Cycles for #2 %-8i\n",cycles - 12);
}
[End Code]
[Relevant Lines from test.S]
.byte 0x0f
.byte 0x31 #//RDTSC
movl %eax, -16(%ebp)
movl %fs:(,%edi,4),%eax
.byte 0x0f
.byte 0x31 #//RDTSC
[End test.S]
This puzzles me. Why can't I scale by four? I've tried other index
registers, etc ... nothing works, except a scale of 1.
BTW, whats a better way to impliment RDTSC? My way seems ugly.
----
moskewicz AT mem DOT po DOT com
- Raw text -