delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/22/10:27:10

Xref: news2.mv.net comp.os.msdos.djgpp:4130
From: rick AT efn DOT org (Rick Bronson)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Acessing DPMI memory without farptr
Date: 22 May 1996 03:45:46 GMT
Organization: Invivo Research Inc.
Lines: 69
Message-ID: <RICK.96May21204546@amazonia.efn.org>
References: <000000199912915529827 AT bryanston DOT co DOT uk>
NNTP-Posting-Host: 204.214.97.233
In-reply-to: Bryanston School's message of Tue, 21 May 1996 13:23:47 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <000000199912915529827 AT bryanston DOT co DOT uk> Bryanston School <MOLESWORTH DOT THOMAS AT bryanston DOT co DOT uk> writes:

> Is there a way to access memory allocated through the __dpmi functions
> through pointers? I would prefer to access it directly, rather than
> using things like _farpeekb and so on. It's annoying to have to use
> _farpeek functions when dumping 1 Mb to a file, for example. I am
> trying to capture an area of memory which is mapped into linear memory
> off a physical device to disk. I mapped this memory using the instructions
> in the FAQ (map physical memory, allocate descriptor, set limits and base),
> but I don't seem to be able to access it without using the _farpeek / =
> _farpoke
> functions. Is there a quick way to do fwrite(memory, sizeof(memory), =
> sizeof(int), filehandle) without doing it in a loop and transferring 4 =
> bytes to the disk at once?
> 
> Also, I have found that declaring a lot of local variables in
> main() sometimes gives errors, such as variables changing between
> one printf() and another. Is this a known feature/bug, and if so what
> should I do about it? I am currently declaring them global, which seems
> to work. I'll post the code if this sounds strange.
> 
> Thanks in advance,
> 
> Thomas Molesworth
> mailto:MOLESWORTH DOT THOMAS AT bryanston DOT co DOT uk

  Here is an example:

#include <sys/nearptr.h>
#include <crt0.h>
int _crt0_startup_flags = _CRT0_FLAG_NEARPTR | _CRT0_FLAG_NONMOVE_SBRK;

#define PAGE_SIZE 4096
#define PAGE_MASK (PAGE_SIZE - 1)
#define NON_PAGE_MASK ~(PAGE_MASK)

void *dpmi_mmap(uint32 phys_address, uint32 size)
  {
  void *our_addr;
  unsigned long addr_pg_align, rem_pg_align, size_pg_align;
  __dpmi_meminfo meminfo;
  uint32 base_address;
  uint32 old_DS_limit;
  uint32 linear_address;
  int ret_val;

  rem_pg_align = phys_address & PAGE_MASK;
  addr_pg_align = phys_address & NON_PAGE_MASK;
  size_pg_align = (size + rem_pg_align + PAGE_MASK) & NON_PAGE_MASK;

  meminfo.size = size_pg_align;
  meminfo.address = addr_pg_align;
  ret_val = __dpmi_physical_address_mapping(&meminfo);  /* DPMI 0.9 AX=0800 */
if (ret_val)
  printf ("800 %d 0x%x\n", ret_val, __dpmi_error);
  linear_address = (char *)(meminfo.address + __djgpp_conventional_base);  /* get linear address */
  return ((void *) (linear_address));
  }


                                                                       _
                                                                      | |
                                                                      / /__
..------------------------------------------------------------._______/ (___)
| Rick Bronson   rick AT efn DOT org   Tel 541-465-9008      _o_    |         (___)
| Invivo Research       http://www.efn.org/~rick      \|/    |_______  (___)
| 745 Foothill Drive       "Onde esta dinheiro?"     `---'   |       \_(___)
| Eugene, OR  97405-4651    -- Gal Costa          Disk | Golf|
`------------------------------------------------------------'

- Raw text -


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