segmentation fault

This is a discussion on segmentation fault within the Linux Programming forums, part of the Platform Specific Boards category; Hi, I'm writing a C program in Linux to display memory content of BIOS data area at segement 0040h with ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    7

    Question segmentation fault

    Hi,

    I'm writing a C program in Linux to display memory content of BIOS data area at segement 0040h with offset 0013h. Below is my program:

    #include <stdio.h>

    int *ptr;

    int main(void)
    {
    ptr = 00400013
    printf("\nContent is %d\n", *ptr);
    return 0;
    }

    When I ran this program, I got this error "segmentation fault". Does it related to protected mode in Linux? If so, what can I do?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > Does it related to protected mode in Linux?
    Yes - you can't point at random bits of real memory anymore

    > If so, what can I do?
    State what it is you are actually trying to do.

    I'm not even sure if linux even bothers with the BIOS data area (as it is used from say DOS).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    7
    When a PC boots up, some memory areas are reserved to contain initialization data. I want to access and display information on these specific memory addresses. Any possible solution in Linux?

  4. #4
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    I am pretty sure you would have to write a kernel module. I don't think linux would let you do it any other way. I am going to have to ask my brother though. He'll know. He'll probably post next

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Muhahah <posting to prove linuxdude wrong>

    Why are you declaring the pointer as a global btw?

  6. #6
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    linux doesn't deal with BIOS data structures, like dos.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Well if you really want to go looking in physical memory, then start with reading
    man 4 mem
    Which tells you all about reading the /dev/mem file.

    But like I (and others) have said, I don't think the BIOS information will be there. Sure it may write some stuff there when the machine starts, but once Linux takes over, I don't think the BIOS plays any further part, so that memory gets claimed by the OS for it's own use.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Apr 2004
    Posts
    7
    Salem,

    Do you mean that Linux overwrites the contents of these memory areas?

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Download the source for the kernel and find out
    Write a program using /dev/mem and find out
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    Well, what the others have said, but I'd like to point out the errors in the program. When you're assigning 00400013 to the pointer, there is a problem with the base you're using.
    You want to use hexadecimal number base, and you're in fact using octal. Any number that starts with a 0 is treated as octal, and the actual memory location you're accessing is way off. You'd need to use 0x00400013. Any number that starts with 0x (that's a zero, same with octal) is treated as hexadecimal.
    I just thought I'd point that out.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault problem
    By odedbobi in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2008, 02:36 AM
  2. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 02:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 12:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21