segmentation fault when porting to linux - Linux

This is a discussion on segmentation fault when porting to linux - Linux ; I want to move to linux from DOS / Win98, and the piece of hardware communicates this way (see snippet below). This snippet works just fine in DOS / Win98, but in linux it fails with a segmentation fault. Any ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: segmentation fault when porting to linux

  1. segmentation fault when porting to linux

    I want to move to linux from DOS / Win98, and the piece of hardware
    communicates this way (see snippet below).

    This snippet works just fine in DOS / Win98, but in linux it fails
    with a segmentation fault. Any idea how to make it work?




    #include

    typedef unsigned long DWORD;
    typedef unsigned char BYTE;
    typedef unsigned short WORD;

    volatile WORD *memory_word_pointer;

    DWORD pmem_address = 0xD4000;


    void *return_address (DWORD address)
    {
    return (BYTE *) address;
    }


    int main()
    {
    memory_word_pointer = (WORD *)return_address (pmem_address);

    *memory_word_pointer = 0x1000;
    return 1;
    }



  2. Re: segmentation fault when porting to linux

    On Feb 26, 4:58 am, email7373...@kinglibrary.net wrote:
    > I want to move to linux from DOS / Win98, and the piece of hardware
    > communicates this way (see snippet below).
    >
    > This snippet works just fine in DOS / Win98, but in linux it fails
    > with a segmentation fault. Any idea how to make it work?
    >
    > #include
    >
    > typedef unsigned long DWORD;
    > typedef unsigned char BYTE;
    > typedef unsigned short WORD;
    >
    > volatile WORD *memory_word_pointer;
    >
    > DWORD pmem_address = 0xD4000;
    >
    > void *return_address (DWORD address)
    > {
    > return (BYTE *) address;
    >
    > }
    >
    > int main()
    > {
    > memory_word_pointer = (WORD *)return_address (pmem_address);
    >
    > *memory_word_pointer = 0x1000;
    > return 1;
    >
    > }


    Probably the best solution is to create a proper driver, but you might
    be okay just using '/dev/mem'. Type 'man 4 mem'.

    DS

  3. Re: segmentation fault when porting to linux

    email7373388@kinglibrary.net writes:

    > I want to move to linux from DOS / Win98, and the piece of hardware
    > communicates this way (see snippet below).
    >
    > This snippet works just fine in DOS / Win98, but in linux it fails
    > with a segmentation fault. Any idea how to make it work?


    You can't.

    Based on the variable names in the code, you seem to be assuming that
    you can get direct access to physical memory addresses. A program
    under Linux only sees virtual addresses.

    I assume there is something interesting at that physical address. If
    that's a device of some sort, there is almost certainly a device
    driver to control it; learn the driver. Alternatively, man mem.

    Note that the fact code like that works under DOS and 16-bit Windows
    is the reason a single application with a wild pointer can crash the
    system.

  4. Re: segmentation fault when porting to linux

    There are some hardware components involved but they are quite old and
    there aren't any drivers for linux.

    Creating an honest-to-goodness driver may be more that I need for this
    project, I'll research using mem. Thank you much for the replies!!

+ Reply to Thread