Mail Archives: djgpp/2000/12/05/14:36:36
"Alex Oleynikov" <alex AT compuweigh DOT com> wrote:
>For that matter I will use a 128K NVRAM chip, which is mapped into a UMB
>memory space through a 32K frame. The data I have to store there is
>organized as a set of structures.
>Now I have a problem - how can I neatly access that data from my program? As
>far as I understand, there is no way to tell the linker to use the physical
>address for relocation of the data structures, since it is below the 1MB
>limit. I have investigated different possibilities of accessing that data
>( through _farX functions, or using "Fat DS" trick ), but they all
>effectively limit my ability to use trivial "dot-style" variable access
>within the structures.
How about this:
#include <stdio.h> /* printf() */
#include <sys/nearptr.h> /* __djgpp_conventional_base, __djgpp_nearptr_enable() */
#include <crt0.h> /* crtNNN */
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
struct nvram_struct
{
volatile u8 byte __attribute__((packed));
volatile u16 word __attribute__((packed));
volatile u32 dword __attribute__((packed));
};
/*****************************************************************************
*****************************************************************************/
int main(void)
{
struct nvram_struct *foo;
if(!(_crt0_startup_flags & _CRT0_FLAG_NEARPTR))
{
if(!__djgpp_nearptr_enable())
{
printf("Could not enable nearptr access\n");
return 1;
}
}
/* the NVRAM is at linear address 000D0000 (real-mode address D000:0000) */
foo = (struct nvram_struct *)(0xD0000 + __djgpp_conventional_base);
/* write the 8-bit value */
foo->byte = 0;
/* read values */
printf("byte = 0x%X\n", foo->byte);
printf("word = 0x%X\n", foo->word);
printf("dword = 0x%lX\n", foo->dword);
return 0;
}
--
geezer@ | pmode tutorial, homebrew OS:
execpc.com | http://www.execpc.com/~geezer/os
- Raw text -