Thread: Segmentation fault, core dumped

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    9

    Segmentation fault, core dumped

    I'm compiling with gcc and with -O2 optimisation.
    Here's the code:

    Code:
    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <sys/io.h>
    #define PORT1 0x3F8
    
    main()
    {
    
    if (ioperm(PORT1, 4, 1)) {perror("ioperm"); exit(1);}
    char a;
    outb_p(0 , PORT1 + 1); /* No interupts*/
    outb_p(0x80 , PORT1 + 3); /* DLab*/
    outb_p(0x02 , PORT1 + 0); /*Baud Rate--Low byte?*/
    outb_p(0x03 , PORT1 + 3); /* * 8 Bits, No Parity, 1 Stop Bit */
    /*outb_p(0x0B , PORT1 + 4); /* Turn on DTR, RTS, and OUT2 */
    
    /*Roomba Control*/
    printf("Roomba go!\n");
    
    outb_p(128, PORT1); /* Begin SCI*/
    outb_p(130, PORT1); /* Go To Safe Mode*/
    outb_p(132, PORT1); /* Go To Full Mode*/
    
    outb_p(137, PORT1);
    outb_p(255, PORT1);
    outb_p(56, PORT1);
    outb_p(128, PORT1);
    outb_p(0, PORT1);
    
    while(a != 'a')
    {
    a = getchar();
    }
    printf("Roomba stop!\n");
    
    outb_p(137, PORT1);
    outb_p(0, PORT1);
    outb_p(0, PORT1);
    outb_p(0, PORT1);
    outb_p(0, PORT1);
    return(0);
    }
    I have to use sudo to run it or the ioperm won't work. I get a segmentation fault (core dumped) error.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    Are you compiling as C++ Or C99?

    What line does the segfault happens? Could you remove all lines afterwards and explain the function you are calling in this line?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    Hmmm..... the coding style and question looks remarkably similar to the following

    http://www.roombareview.com/chat/viewtopic.php?t=5198

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What am I doing worng? Segmentation fault, core dump
    By cookie in forum C Programming
    Replies: 4
    Last Post: 06-08-2007, 09:59 AM
  2. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  3. Runtime error 'segmentation fault (core dumped)'
    By mikemccready in forum C Programming
    Replies: 2
    Last Post: 03-17-2003, 07:14 AM
  4. Segmantation Fault (core dumped) error
    By Vinnie66 in forum C Programming
    Replies: 6
    Last Post: 03-25-2002, 01:34 PM
  5. Segmentation fault (core dumped)
    By JYSN in forum C Programming
    Replies: 1
    Last Post: 02-21-2002, 03:24 AM