Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Aug 2002 00:50:58 +0200
From:      hal@telefonica.net
To:        freebsd-hackers@freebsd.org
Subject:   Memory below 1 MB
Message-ID:  <E17dIaT-0000Wi-00@ash.drims.net>

next in thread | raw e-mail | index | archive | help
Hello,

As I explained in another message, I am writing some graphics code (both for fun and educational purposes) and need to access memory below 1 MB. I have tried it by opening /dev/mem, calling mmap, i386_vm86 and even opening /dev/io to change permission levels. However, the program (and actually the physical terminal) hangs when doing the interruption call.

I attach the test program within this mail. If attachments are not part of this list's etiquette, sorry, it will not happen again. Compile with "gcc -o whatever vesainfo.c" if you want to have a look (you will need root privileges to execute it).

Well, I am completely desperate. I tried everything I could, but for some magical reasons, this low-level access does not work. Any ideas?


Thank you in advance,

Alex


vesastructs.h:
#ifndef __VESASTRUCTS_H
#define __VESASTRUCTS_H

typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned int dword;

struct VesaInfo
{
   byte signature[4];
   word version;
   char *oemName;
   dword capabilities;
   word *suppModes;
   word total64kBlocks;
   word oemSoftVersion;
   byte *vendorName;
   byte *productName;
   byte *productRev;
   word VBEAFVersion;
   word *accelSuppModes;
   byte reserved[216];
   byte oemStrings[256];
};


#endif


vesainfo.c:
#include <sys/types.h>
#include <sys/mman.h>
#include <machine/sysarch.h>
#include <machine/vm86.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "vesastructs.h"

int main (void)
{
   struct vm86_init_args vm86init;
   struct vm86_intcall_args intargs;
   struct VesaInfo *vbeInfo;
   char c;
   int f, io;
   unsigned int len=0x400;
   int ioperm=0;
   
   f=open("/dev/mem", O_RDWR);
   if (f==-1)
     {
	printf("Could Not Access Memory\n");
	return -1;
     }
   
   vbeInfo=(struct VesaInfo*)mmap((void*)0x10000, 0x1000, 
				  PROT_READ|PROT_WRITE|PROT_EXEC, 
				  MAP_FIXED|MAP_SHARED,
				  f, 0x10000);
   
   if (vbeInfo==MAP_FAILED)
     {
	printf("Peta mmap\n");
	return -1;
     }

   memset(&vm86init, 0, sizeof(struct vm86_init_args));
   memset(&intargs, 0, sizeof(struct vm86_intcall_args));
   memset(vbeInfo, 0, sizeof(struct VesaInfo));
   
   printf("vbeInfo = %p\n", vbeInfo);
   vbeInfo->signature[0]='V';
   vbeInfo->signature[1]='B';
   vbeInfo->signature[2]='E';
   vbeInfo->signature[3]='2';
   
   printf("vbeSig = %c%c%c%c\n",
	  vbeInfo->signature[0],
	  vbeInfo->signature[1],
	  vbeInfo->signature[2],
	  vbeInfo->signature[3]);
   
//   sleep(1);
   if (!i386_vm86(VM86_INIT, &vm86init))
     {
	printf("VM86_INIT successful\n");
     }
   
   intargs.intnum=0x10;
   intargs.vmf.vmf_ax=0x4f00;
   intargs.vmf.vmf_es=(((dword)vbeInfo)&0xf0000)>>4; /*0x1000;*/
   intargs.vmf.vmf_di=((dword)vbeInfo)&0xffff; /*0x0000;*/
   
   i386_set_ioperm(0, 0x400, 1);
   i386_get_ioperm(0, &len, &ioperm);
   printf("len=%x perm=%x\n", len, ioperm);
//   return -1;
   
   io=open("/dev/io", 0);
   if (io==-1)
     {
	printf("io pef\n");
	return -1;
     }
   
   
//   sleep(1);
   printf("INTCALL (0x%x, ax=0x%.04x, es:di=%.04x:%.04x)\n",
	  intargs.intnum, intargs.vmf.vmf_ax,
	  intargs.vmf.vmf_es, intargs.vmf.edi.r_ex);
   
   if (!i386_vm86(VM86_INTCALL, &intargs))
     {
	printf("VM86_INTCALL successful (ax=%.04x)\n", intargs.vmf.vmf_ax);
     }
//   sleep(1);
   
   printf("vbeVer\n");
//   sleep(1);
   
   printf("VESA signature: %c%c%c%c\nVESA Version: 0x%.04x\n",
	  vbeInfo->signature[0],
	  vbeInfo->signature[1],
	  vbeInfo->signature[2],
	  vbeInfo->signature[3],
	  vbeInfo->version);
   return 0;
}


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E17dIaT-0000Wi-00>