Segmentation Error

Hello everyone,

What does the following mean?

“Segmentation Fault”

The error occurs during execution of the following segment of the code under
the debugger.

We are trying to access the internal memory mapped registers of the 8260
processor.


// #define’s
#define IMM_PHYS_ADDR 0x04700000
#define IMM_SIZE (80 * 1024)

int main(void)
{
UWORD * pIMM;
UWORD tmp;

// map in the physical memory, 0x0470_0000

pIMM = (UWORD *) mmap_device_memory
(0, IMM_SIZE, PROT_READ|PROT_WRITE|PROT_NOCACHE, 0, IMM_PHYS_ADDR);

if ( pIMM == MAP_FAILED ) {
printf( “mmap_device_memory failed” );
exit( EXIT_FAILURE );
}
else {
printf( “pIMM = 0x%08x \r\n”, pIMM);
}

printf(“Thread return value = %d \r\n”, ThreadCtl_r (_NTO_TCTL_IO,
NULL) );


tmp=*pIMM; // this line
generates the “Segmentation Fault”

printf(“tmp=0x%08x\r\n”, tmp);

Regards and thanks,

Ben Strydom

“Deon Herbst” <datasyst@mweb.co.za> wrote in message
news:9sr9o4$d23$1@inn.qnx.com

Hello everyone,

What does the following mean?

“Segmentation Fault”

It means the program attempted to access memory outside its virtual memory
space.

The error occurs during execution of the following segment of the code
under
the debugger.

Does it run ok when NOT run under the debugger.

We are trying to access the internal memory mapped registers of the 8260
processor.

I can’t find anything wrong with this piece of code aside missing
the header files (I’m assuming you left them out of the post).

ThreadCTL is not necessary since you aren’t using in/out functions or
installing ISR.

I ran the code you posted without any problem.

// #define’s
#define IMM_PHYS_ADDR 0x04700000
#define IMM_SIZE (80 * 1024)

int main(void)
{
UWORD * pIMM;
UWORD tmp;

// map in the physical memory, 0x0470_0000

pIMM = (UWORD *) mmap_device_memory
(0, IMM_SIZE, PROT_READ|PROT_WRITE|PROT_NOCACHE, 0, IMM_PHYS_ADDR);

if ( pIMM == MAP_FAILED ) {
printf( “mmap_device_memory failed” );
exit( EXIT_FAILURE );
}
else {
printf( “pIMM = 0x%08x \r\n”, pIMM);
}

printf(“Thread return value = %d \r\n”, ThreadCtl_r (_NTO_TCTL_IO,
NULL) );


tmp=*pIMM; // this line
generates the “Segmentation Fault”

printf(“tmp=0x%08x\r\n”, tmp);

Regards and thanks,

Ben Strydom

Dear Mario,

Thank you for your speedy assistance.

The error also occurs when it is executed without the debugger. We are using
the Motorola 8260 ADS development board. Can you perhaps tell me which board
you tested the code on.

Attached please find the console memory dump and the complete source for the
program.

Thank you very much for your help

Regards,
Deon Herbst



“Deon Herbst” <datasyst@mweb.co.za> wrote in message
news:9sr9o4$d23$1@inn.qnx.com

Hello everyone,

What does the following mean?

“Segmentation Fault”

The error occurs during execution of the following segment of the code
under
the debugger.

We are trying to access the internal memory mapped registers of the 8260
processor.


// #define’s
#define IMM_PHYS_ADDR 0x04700000
#define IMM_SIZE (80 * 1024)

int main(void)
{
UWORD * pIMM;
UWORD tmp;

// map in the physical memory, 0x0470_0000

pIMM = (UWORD *) mmap_device_memory
(0, IMM_SIZE, PROT_READ|PROT_WRITE|PROT_NOCACHE, 0, IMM_PHYS_ADDR);

if ( pIMM == MAP_FAILED ) {
printf( “mmap_device_memory failed” );
exit( EXIT_FAILURE );
}
else {
printf( “pIMM = 0x%08x \r\n”, pIMM);
}

printf(“Thread return value = %d \r\n”, ThreadCtl_r (_NTO_TCTL_IO,
NULL) );


tmp=*pIMM; // this line
generates the “Segmentation Fault”

printf(“tmp=0x%08x\r\n”, tmp);

Regards and thanks,

Ben Strydom

begin 666 dPPregs.c
M+R@+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM("\O#0HO+R!0<F]G
M<F%M+BXZ(&104’)E9W,N8R @(" @(" @(" @(" @(" @(" @(" @(" @(" @
M(" @(" @(" @(" @(" @(" @(" @(" @(" @+R-“B\O(%9E<G-I;VXN+CH@
M,2XP,” @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @
M(" @(" @(" @(" @(" @(" @(" O+PT*+R@5&%R9V5T+BXN.B!13E@@<G5N
M;FEN9R!O;B!T:&4@35!#.#(V,&%D<R!D978@8F]A<F0N(" @(" @(" @(" @
M(" @(" @(" @(" @("\O#0HO+R!$871E+BXN+BXZ(#@@3F]V96UB97(@,C P
M,2 @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @
M(" @(" @+R-“B\O($%U=&AO<BXN+CH@0BX@4W1R>61O;2 @(” @(" @(" @
M(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" O
M+PT*+R@(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @
M(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @("\O( T*+R@
M1&ES8W)I<‘1I;VXZ(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @
M(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @("\O( T*+R@/3T]/3T]
M/3T]/3T](" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @
M(" @(" @(" @(" @(" @(" @(" @(" @("\O#0HO+R @(" @(" @(" @(" @
M(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @
M(" @(" @(" @(" @(" @(" @+R-“B\O($%C8V5S<R!A;B!I;G1E<FYA;”!M
M96UO<GD@;6%P<&5D(’)E9VES=&5R(“A)34U22!O9B!T:&4@35!#.#(V,"!P
M<F]C97-S;W(N(" O+PT
+R@(” @(" @(" @(" @(" @(" @(" @(" @(" @
M(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @(" @
M(" @("\O#0HO+R M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2T@+R-
M"@T*+R@(VEN8VQU9&4G<PT*(VEN8VQU9&4@/’-Y<R]N975T<FEN;RYH/@T*
M(VEN8VQU9&4@/’-Y<R]M;6%N+F@^#0HC:6YC;‘5D92 <‘1H<F5A9"YH/@T*
M(VEN8VQU9&4@/’-T9&EO+F@^(" O+R!&;W(@<’)I;G1F*“DN( T*(VEN8VQU
M9&4@/’-T9&QI8BYH/@T*#0HO+R C9&5F:6YE)W,-“B-D969I;F4@24U-7U!(
M65-?041$4B P># T-S P,# P#0HC9&5F:6YE($E-35]325I%(”@X,” J(#$P
M,C0I#0H-“FEN=”!M86EN*‘9O:60I#0I[#0H@(‘5N<VEG;F5D(&QO;F<@B!P
M24U-.R -“B @=6YS:6=N960@;&]N9R!T;7 [#0H@#0H@#0H@(”\O(&UA<"!I
M;B!T:&4@<&AY<VEC86P@;65M;W)Y+" P># T-S P,# P#0H@(" @#0H@(’!)
M34T@/2 H=6YS:6=N960@;&]N9R J
2!M;6%P7V1E=FEC95]M96UO<GD-“B @
M(” H,“P@24U-7U-)6D4L(%!23U1?4D5!1’Q04D]47U=2251%?%!23U1?3D]#
M04-(12P@,“P@24U-7U!(65-?041$4BD[#0H-“B @(” @(” @(” @(" @(" @
M(" @(" @(" @#0H@(&EF("@@<$E-32 ]/2!-05!?1D%)3$5$(“D@>PT*(” @
M(’!R:6YT9B@@(FUM87!?9&5V:6-E7VUE;6]R>2!F86EL960B(“D[#0H@(” @
M97AI="@@15A)5%]&04E,55)%(“D[(” -“B @?0T*(”!E;’-E(‘L-“B @(”!P
M<FEN=&8H(")P24U-(#T@,’@E,#AX(%QR7&XB+"!P24U-3L@#0H@('T-"@T
M("!T;7 ]G!)34T[#0H@( T("!P<FEN=&8H(G1M<#TP>“4P.'A<<EQN(BP@
8=&UP3L-"@T(”!R971U<FX@,#L@#0I]
`
end

begin 666 dPPregs.doc
MT,\1X*&Q&N$/@`#`/[_"0`&```````````````! M`````0``````````$ ```@````$```#^____``````````#_____________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M_______________________]_____O____[___\$````!0````8````'```` M" ````D```#^________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M_____________________________________________U(`;P!O`'0`( !% M`&X`= !R`'D````````````````````````````````````````````````` M```````````6``4`__________\!``````D"``````# ````````1@`````` M`````````'#XK-W<;,$!`P```, -````````5P!O`'(`9 !$`&\`8P!U`&T` M90!N`'0````````````````````````````````````````````````````` M`!H``@$"````__________\````````````````````````````````````` M`````````````````@T````````!`$,`;P!M`' `3P!B`&H````````````` M````````````````````````````````````````````````````$@`"`/__ M_____________P`````````````````````````````````````````````` M`#4```!N```````````````````````````````````````````````````` M````````````````````````````````````````````````____________ M____```````````````````````````````````````````````````````` M`````````0````(````#````! ````4````&````!P````@````)````"@`` M``L````,````#0````X````/````$ ```!$````2````$P```!0````5```` M%@```!<````8````&0```!H````;````' ```!T````>````'P```" ````A M````(@```",````D````)0```"8````G````* ```"D````J````*P```"P` M```M````+@```"\````P````,0```#(````S````- ```/[___\V````_O__ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M_______________________________<I64`(\ )! `````````````````` M```2`P``_08```(-````````````````````````ZP,````````````````` M````````````````````````````+ P``&P````L# ``; `````````````` M````````````````````````````````% P``!0
M``````````````````````````````````````PH````*# ``"@`````` M````````J@(``&@````H# ``! `````````````````````````````````` M````````````````````````````````````````````[ P(`````````
M``````````````````````````````````````````````````````````"8
M# 5 ```.X,```4```````````````````````````````````````````` M````````````````! `%$0`````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M````````````````````````````````````````: `5$ ````!4:6UE<R!. M97<@4F]M86X`#! ```(`4WEM8F]LL@$%R:6%L`!,@$U3(%-A
M;G,@4V5R:68#! ```(4WEM8F]L!40`````%1I;65S($YE=R!2;VUA;@!D M4%!R96=S#2,@9%!0<F5G<PUP24U-(#T@,'@X,#$P,# P, T-4VAU=&1O=VY; M,"PP72!3+T,O1CTQ,"\S+S,S($,O1#TP,# R,C@X8R\P,# V8C0W8PU;,%U0 M240M5$E$/3(X-C@R+3$@(% O5"!&3#TP,# P,# P,"\P,# P,# P," B9%!0 M<F5G<R(-<'!C8F4@8V]N=&5X=%LP,#)D,S0T,%TZ#3 P,# Z(# T-S V,6)A M(#0X,#-F964P(#0X,#0X-C0X(# P,# P,#$T(#0X,#0P-C,T(#=F9F9F9F9F M(#0X,#-F9&(X(#0X,#0P-C,T#3 P,C Z(# P,# P,# P(#0X,#0P,# P(#0X M,#-F9F,P(#<P,&$P,# Q(#0X,#0U-#DP(#0X,#0Y-S(P(# P,# P,# P(# P M,# P,# P#3 P-# Z(# P,# P,# P(# P,# P,# P(# P,# P,# P(# P,# P M,# P(#0X,#-F9C P(# P,# P,# Q(#0X,#-F9C$T(#0X,#-F9C%C#3 P-C Z M(#0X,#-F9C)C(# P,# P,# P(# P,# P,# P(# P,# P,# P(# P,C<X.#9C M(# P,# P,# P(# P,# P,# P(#0X,#-F964P#3 P.# Z(# P,# P,# P(#0X M,#0P-&4X(# P,#1D.3,P(#0X,#0P-&8X(#(T,# P,# P(#(P,# P,# Q(# P M,# P,# P(# P,# P,# P#3 P83 Z(# P,# P,# P#6EN<W1R=6-T:6]N6S0X M,#0P-&8X73H-,S@@-CD@,#8@,S@@.# @.68@,# @,&,@-&,@8S8@,S$@.#(@ M-#@@,# @,3(@-CD@,S@@-C @,# @,# @-#@@,# @,# @,#0@.#$@-C$-<W1A M8VM;-#@P,V9E93!=.@TP,# P.B T.# S9F8P," T.# T,#1E." X,#$P,# P M," P-#<P-C%B82!F93,S,34P." V9C<T,# P," P,# P,# P," P,#(W-C P M, TP,#(P.B P,# P,# P," T.# T,3<X8R P,# P,# P," P,# P,# P," P M,# P,# P,2 T.# S9F8X." P,# P,# P," T.# S9F8Y, TP,#0P.B T.# S M9F8Y8R T.# S9F9A-R P,# P,# P," P,# P,# P,R T.# T,# S-" P,# P M,# P-" P,# P,# R," P,# P,# P-0TP,#8P.B P,# P,# P-R P,# P,# P M.2 T.# T,#-F-" P,# P,# P-B P,# P,3 P," P,# P,# P-R!F93,P,# P M," P,# P,# R9 T-```````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M!(#9`P``&@,``",#DP``-0,``#8#```WP: ,&D#"?`P
MH ,+@#"YP``!@0```<$``!4! ``500``*($``"C! ``\ 0``/$$```^ M!0``/P4``$T%``!.!0``9 4``&4%``"R!0``LP4``,,%``#$!0``$08``!(& M``!?!@``8 8``*T&``"N!@``^P8``/P&``#]!@``_?OY]_7S\>_MZ^GGY>/A MW]W;V=?5T]'/S<O)Q\7#P;^]N[FWM;.QKP`````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M`````````````````````````````````````````````````UT%``-=!0#
M704UT%-=!0#704``UT%``-=!0#704UT%-=!0#704``UT%``-= M!0#704UT%-=!0#704``UT%``-=!0#704UT%-=!0#704``UT% M``-=!0#704UT%-=!0#704``UT%``-=!0#704UT%-=!0#704
MUT%``-=!0#704UT%```H$@,!H#D`P``-@,``#<#``!I`P``H ,` M`+D#’! 500*,$#Q! /P4$X%!E!0LP4,0%2!@`` M8 8``*X&``#\!@``_08``/T```````#[````````^0```````/<```````#U M````````\P```````/$```````#O````````[0```````.L```````#I```` M````YP```````.4```````#C````````X0```````-\```````#=```````` MVP```````-D```````#7````````U0`````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M`````````````````````````````````````````````````````0````$` M!0````$````!0$!0````$````!0 M$!`````0$!`````0$!`````!42`P``_08```0` M$@,``/T&```%``````#K`P#_____#_____%@D```X`#P`($2P/
M:``! \?\"`!H`!DYO<FUA; `"`````P!A"00````````````````` M````````(@!!0/+_H0`B`!9$969A=6QT(%!A<F%G<F%P:"!&;VYT```````` M````````````! ````````#0`@`````````````````````````````````` M```````````````````````````````````````````````````````````` M`/] % `````````````````````````````````````````````````````` M``````````````````````````````````````````````````````$`_O\# M"@``_____P`)`@``````P $8<````36EC<F]S;V9T(%=O<F0@-BXP
M($1O8W5M96YT``H!-4U=O<F1$;V,`$ %=O<F0N1&]C=6UE;G0N-@#T
M.;)Q````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
'````````````
`
end

“Deon Herbst” <datasyst@mweb.co.za> wrote in message
news:9st68p$jl0$1@inn.qnx.com

Dear Mario,

Thank you for your speedy assistance.

Your welcome.

The error also occurs when it is executed without the debugger. We are
using
the Motorola 8260 ADS development board. Can you perhaps tell me which
board
you tested the code on.

On a PC :wink:

Attached please find the console memory dump and the complete source for
the
program.

This is a kernel crash, that’s really really odd. Either reading the
memory address cause
some the hardware to go nuts or their is a bug in the kernel.

As Adam suggested in this thread try no using PROT_NOCACHE (I’ve had some
trouble with that).

Also try changing the address your mapping to point to existing memory and
see if that crashes. If it does crash, that really points toward a harware
issue.


Thank you very much for your help

Regards,
Deon Herbst



“Deon Herbst” <> datasyst@mweb.co.za> > wrote in message
news:9sr9o4$d23$> 1@inn.qnx.com> …
Hello everyone,

What does the following mean?

“Segmentation Fault”

The error occurs during execution of the following segment of the code
under
the debugger.

We are trying to access the internal memory mapped registers of the 8260
processor.


// #define’s
#define IMM_PHYS_ADDR 0x04700000
#define IMM_SIZE (80 * 1024)

int main(void)
{
UWORD * pIMM;
UWORD tmp;

// map in the physical memory, 0x0470_0000

pIMM = (UWORD *) mmap_device_memory
(0, IMM_SIZE, PROT_READ|PROT_WRITE|PROT_NOCACHE, 0, IMM_PHYS_ADDR);

if ( pIMM == MAP_FAILED ) {
printf( “mmap_device_memory failed” );
exit( EXIT_FAILURE );
}
else {
printf( “pIMM = 0x%08x \r\n”, pIMM);
}

printf(“Thread return value = %d \r\n”, ThreadCtl_r (_NTO_TCTL_IO,
NULL) );


tmp=*pIMM; // this line
generates the “Segmentation Fault”

printf(“tmp=0x%08x\r\n”, tmp);

Regards and thanks,

Ben Strydom

\

Also try changing the address your mapping to point to existing memory and
see if that crashes. If it does crash, that really points toward a
harware issue.

I got it backward :wink: If it does NOT crash it points to a hardware problem.

Thank you very much for your help

Regards,
Deon Herbst



“Deon Herbst” <> datasyst@mweb.co.za> > wrote in message
news:9sr9o4$d23$> 1@inn.qnx.com> …
Hello everyone,

What does the following mean?

“Segmentation Fault”

The error occurs during execution of the following segment of the code
under
the debugger.

We are trying to access the internal memory mapped registers of the
8260
processor.


// #define’s
#define IMM_PHYS_ADDR 0x04700000
#define IMM_SIZE (80 * 1024)

int main(void)
{
UWORD * pIMM;
UWORD tmp;

// map in the physical memory, 0x0470_0000

pIMM = (UWORD *) mmap_device_memory
(0, IMM_SIZE, PROT_READ|PROT_WRITE|PROT_NOCACHE, 0,
IMM_PHYS_ADDR);

if ( pIMM == MAP_FAILED ) {
printf( “mmap_device_memory failed” );
exit( EXIT_FAILURE );
}
else {
printf( “pIMM = 0x%08x \r\n”, pIMM);
}

printf(“Thread return value = %d \r\n”, ThreadCtl_r (_NTO_TCTL_IO,
NULL) );


tmp=*pIMM; // this line
generates the “Segmentation Fault”

printf(“tmp=0x%08x\r\n”, tmp);

Regards and thanks,

Ben Strydom



\

“Deon Herbst” <datasyst@mweb.co.za> wrote in message
news:9sr9o4$d23$1@inn.qnx.com

Hello everyone,

What does the following mean?

“Segmentation Fault”

The error occurs during execution of the following segment of the code
under
the debugger.

Does the problem occur if you don’t use the PROT_NOCACHE flag?

-Adam