2008-05-15 13:04:46 Undefined or illegal instruction
Laurent Winkler (SWITZERLAND)
Message: 55863
I am trying to compile uclinux for a blackfin processor. Here is one problem I run into.
While running certain scripts (even simple ones with a few 'if's and 'for's) with msh I get an error : see description below.
Some errors may come from the fact that I use vfork() instead of fork() as required by the hardware. I know vfork() should not exit with 'return' on the child process (you should use 'exit' instead).
My questions are :
What exactly should I changes, so that uc-linux uses vfork() ? For now I've just switched vfork() for fork() in portmap.c ?
How does uclinux handle a call to fork(), as found in many other files ?
Do you have any other clue why this error keeps happening ?
------------------the script :
for arg in $* ; do
if [ "$arg" = "2" ]; then
echo deux
fi
if [ "$arg" = "3" ]; then
echo trois
fi
if [ "$arg" = "4" ]; then
echo quatre
fi
done
------------------------- error ---------------------------------
Jan 1 09:23:27 blackfin user.notice kernel: Undefined instruction
Jan 1 09:23:27 blackfin user.notice kernel: - May be used to emulate instructions that are not defined for
Jan 1 09:23:27 blackfin user.notice kernel: a particular processor implementation.
Jan 1 09:23:27 blackfin user.notice kernel: Deferred Exception context
Jan 1 09:23:27 blackfin user.notice kernel: CURRENT PROCESS:
Jan 1 09:23:27 blackfin user.notice kernel: COMM=parocrun2 PID=349
Jan 1 09:23:27 blackfin user.notice kernel: TEXT = 0x03100040-0x031494a0 DATA = 0x031494a4-0x0315c494
Jan 1 09:23:27 blackfin user.notice kernel: BSS = 0x0315c494-0x0315df04 USER-STACK = 0x03167f40
Jan 1 09:23:27 blackfin user.notice kernel:
Jan 1 09:23:27 blackfin user.notice kernel: return address: [0x031271f4]; contents of:
Jan 1 09:23:27 blackfin user.notice kernel: 0x031271d0: 0000 0000 0005 0000 0000 0000 0018 2e04
Jan 1 09:23:27 blackfin user.notice kernel: 0x031271e0: 002e 1007 d015 000e 0000 0000 0006 0000
Jan 1 09:23:27 blackfin user.notice kernel: 0x031271f0: 0000 0000 [0018] 6504 6374 0100 d1b8 000e
Jan 1 09:23:27 blackfin user.notice kernel: 0x03127200: 0000 0000 0007 0000 0000 0000 0018 2e04
Jan 1 09:23:27 blackfin user.notice kernel:
Jan 1 09:23:27 blackfin user.notice kernel: SEQUENCER STATUS: Not tainted
Jan 1 09:23:27 blackfin user.notice kernel: SEQSTAT: 00060021 IPEND: 0030 SYSCFG: 0006
Jan 1 09:23:27 blackfin user.notice kernel: HWERRCAUSE: 0x18
Jan 1 09:23:27 blackfin user.notice kernel: EXCAUSE : 0x21
Jan 1 09:23:27 blackfin user.notice kernel: RETE: <0x00000000> { _run_init_process + 0xfffff000 }
Jan 1 09:23:27 blackfin user.notice kernel: RETN: <0x004c4000> /* unknown address */
Jan 1 09:23:27 blackfin user.notice kernel: RETX: <0x031271f4> [ parocrun2 + 0x271b4 ]
Jan 1 09:23:27 blackfin user.notice kernel: RETS: <0x0312710e> [ parocrun2 + 0x270ce ]
Jan 1 09:23:27 blackfin user.notice kernel: PC : <0x031271f4> [ parocrun2 + 0x271b4 ]
Jan 1 09:23:27 blackfin user.notice kernel: D
Jan 1 09:23:27 blackfin user.info kernel: CPLB_FAULT_ADDR: <0x03167be0> [ parocrun2 + 0x67be0 ]
Jan 1 09:23:27 blackfin user.notice kernel: ICPLB_FAULT_ADDR: <0x031271f4> [ parocrun2 + 0x271b4 ]
Jan 1 09:23:27 blackfin user.notice kernel:
Jan 1 09:23:27 blackfin user.notice kernel: PROCESSOR STATE:
Jan 1 09:23:27 blackfin user.notice kernel: R0 : 00000000 R1 : 00000000 R2 : 00000200 R3 : 40000000
Jan 1 09:23:27 blackfin user.notice kernel: R4 : 00000000 R5 : 00000001 R6 : 00000000 R7 : 03780394
Jan 1 09:23:27 blackfin user.notice kernel: P0 : 00000003 P1 : 037817e0 P2 : 0315bf54 P3 : 03167f48
Jan 1 09:23:27 blackfin user.notice kernel: P4 : 0378059c P5 : 03780390 FP : 03167c78 SP : 004c3f24
Jan 1 09:23:27 blackfin user.notice kernel: LB0: 0310cb21 LT0: 0310cb1e LC0: 00000000
Jan 1 09:23:27 blackfin user.notice kernel: LB1: 03112b65 LT1: 03112b5e LC1: 00000000
Jan 1 09:23:27 blackfin user.notice kernel: B0 : 00000000 L0 : 00000000 M0 : 00000000 I0 : 03167f9d
Jan 1 09:23:27 blackfin user.notice kernel: B1 : 00000000 L1 : 00000000 M1 : 00000000 I1 : 0068066d
Jan 1 09:23:27 blackfin user.notice kernel: B2 : 00000000 L2 : 00000000 M2 : 00000000 I2 : 00000000
Jan 1 09:23:27 blackfin user.notice kernel: B3 : 00000000 L3 : 00000000 M3 : 00000000 I3 : 00000000
Jan 1 09:23:27 blackfin user.notice kernel: A0.w: 00000000 A0.x: 00000000 A1.w: 00000000 A1.x: 00000000
Jan 1 09:23:27 blackfin user.notice kernel: USP : 03167be4 ASTAT: 02003025
Jan 1 09:23:27 blackfin user.notice kernel:
Jan 1 09:23:27 blackfin user.notice kernel: Hardware Trace:
Jan 1 09:23:27 blackfin user.notice kernel: 0 Target : <0x0000464c> { _trap_c + 0x0 }
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0xffa006c4> { _exception_to_level5 + 0
Jan 1 09:23:27 blackfin user.info kernel: xb4 }
Jan 1 09:23:27 blackfin user.notice kernel: 1 Target : <0xffa00610> { _exception_to_level5 + 0x0 }
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0xffa0056c> { _ex_trap_c + 0x5c }
Jan 1 09:23:27 blackfin user.notice kernel: 2 Target : <0xffa00510> { _ex_trap_c + 0x0 }
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0xffa00764> { _trap + 0x28 }
Jan 1 09:23:27 blackfin user.notice kernel: 3 Target : <0xffa0073c> { _trap + 0x0 }
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0x031271f2> [ parocrun2 + 0x271b2 ]
Jan 1 09:23:27 blackfin user.notice kernel: 4 Target : <0x031271f0> [ parocrun2 + 0x271b0 ]
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0x03127112> [ parocrun2 + 0x270d2 ]
Jan 1 09:23:27 blackfin user.notice kernel: 5 Target : <0x0312710e> [ parocrun2 + 0x270ce ]
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0x0311b10e> [ parocrun2 + 0x1b0ce ]
Jan 1 09:23:27 blackfin user.notice kernel: 6 Target : <0x0311b106> [ parocrun2 + 0x1b0c6 ]
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0x0311b0fc> [ parocrun2 + 0x1b0bc ]
Jan 1 09:23:27 blackfin user.notice kernel: 7 Target : <0x0311b0f8> [ parocrun2 + 0x1b0b8 ]
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0x03102888> [ parocrun2 + 0x2848 ]
Jan 1 09:23:27 blackfin user.notice kernel: 8 Target : <0x03102876> [ parocrun2 + 0x2836 ]
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0xffa00c58> { __common_int_entry + 0xd8 }
Jan 1 09:23:27 blackfin user.notice kernel: 9 Target : <0xffa00bf6> { __common_int_entry + 0x76 }
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0xffa00e1c> { _evt_system_call + 0x64 }
Jan 1 09:23:27 blackfin user.notice kernel: 10 Target : <0xffa00e1c> { _evt_system_
Jan 1 09:23:27 blackfin user.info kernel: call + 0x64 }
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0xffa008ec> { _system_call + 0xb8 }
Jan 1 09:23:27 blackfin user.notice kernel: 11 Target : <0xffa008e8> { _system_call + 0xb4 }
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0xffa008d8> { _system_call + 0xa4 }
Jan 1 09:23:27 blackfin user.notice kernel: 12 Target : <0xffa008d2> { _system_call + 0x9e }
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0xffa008c2> { _system_call + 0x8e }
Jan 1 09:23:27 blackfin user.notice kernel: 13 Target : <0xffa0089c> { _system_call + 0x68 }
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0x0003c63a> { _sys_read + 0x4e }
Jan 1 09:23:27 blackfin user.notice kernel: 14 Target : <0x0003c61e> { _sys_read + 0x32 }
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0x0003c29e> { _vfs_read + 0x22 }
Jan 1 09:23:27 blackfin user.notice kernel: 15 Target : <0x0003c296> { _vfs_read + 0x1a }
Jan 1 09:23:27 blackfin user.notice kernel: Source : <0x0003c2fa> { _vfs_read + 0x7e }
Jan 1 09:23:27 blackfin user.notice kernel: Stack from 004c3f04:
Jan 1 09:23:27 blackfin user.notice kernel: 00000000 ffa006c8 0015dc30 0015dc30 0015dc28 40000000 00000000 03102876
Jan 1 09:23:27 blackfin user.notice kernel: 031271f4 00000030 00060021 00000000 004c4000 031271f4 031271f4 0312710e
Jan 1 09:23:27 blackfin user.notice kernel: 00000000 02003025 03112b65 0310cb21 03112b5e 0310cb1e 00000000 00000000
Jan 1 09:23:27 blackfin user.notice kernel: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Jan 1 09:23:27 blackfin user.notice kernel: 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Jan 1 09:23:27 blackfin user.info kernel: 00000000
Jan 1 09:23:27 blackfin user.notice kernel: 00000000 00000000 0068066d 03167f9d 03167be4 03167c78 03780390 0378059c
Jan 1 09:23:27 blackfin user.notice kernel:
QuoteReplyEditDelete
2008-05-15 13:26:50 Re: Undefined or illegal instruction
Cameron Barfield (UNITED STATES)
Message: 55864
This is probably one of the best explanations of fork() vs. vfork() that I've come across:
fork() and vfork(), for those unfamiliar with these system calls, allow a process to split into two processes, a parent and a child. A process can split many times to create multiple children. When a process calls fork(), the child is a duplicate of the parent in all ways, but it shares nothing with the parent and can operate independently, as can the parent. With vfork() this is not the case. First, the parent is suspended and cannot continue executing until the child exits or calls exec(), the system call used to start a new application. The child, directly after returning from vfork(), is running on the parent's stack and is using the parent's memory and data. This means the child can corrupt the data structures or the stack in the parent, resulting in failure. This is avoided by ensuring that the child never returns from the current stack frame once vfork() has been called and that it calls _exit when finishing—exit cannot be called as it changes data structures in the parent. The child also must avoid changing any information in global data structures or variables, as such changes may break the execution of the parent.
Making an application use vfork instead of fork usually falls into the absolutely simple or incredibly difficult category. Generally, if the application does not fork and then exec() almost immediately, it needs to be checked carefully before fork() can be replaced with vfork().
The uClinux flat executable format, though it doesn't directly affect applications and their operations, does allow quite a few options that the usual ELF executables under Linux do not. Flat format executables come in two basic flavors, fully relocated and a variation of position-independent code (PIC). The fully relocated version has relocations for its code and data, while the PIC version generally needs only a few relocations for its data.
http://www.linuxjournal.com/article/7221
QuoteReplyEditDelete
2008-05-16 08:15:53 Re: Undefined or illegal instruction
Laurent Winkler (SWITZERLAND)
Message: 55924
Hi,
Thanks for your quick reply. I managed to to test fork and vfork on a small program. Actually, fork() returns a "-1" at execution if the program is run on the blackfin card. This means that it returns an error.
However, is there a patch or something to make uc-linux runs using vfork() instead of fork() ?
QuoteReplyEditDelete
2008-05-16 09:52:43 Re: Undefined or illegal instruction
Mike Frysinger (UNITED STATES)
Message: 55929
Linux doesnt care what userspace executes. it is up to userspace applications to execute fork() or vfork() accordingly.