Segmentation fault (core dumped)
I'm compiling with gcc and with -O2 optimisation.
Here's the 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.
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- Ubuntu Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask cjones for more information if necessary.