Hi, I'm having some trouble with the 4.9.2 M32C target.Problems start when trying to build the cross compiler. The m32cm multilib fails with:
configure: error: unable to detect exception model make[2]: *** [configure-target-libgcc] Error 1 Makefile:11635: recipe for target 'configure-target-libgcc' failedmake[2]: Leaving directory '/home/patrick/src/m16c/toolchain/build/gcc-4.9.2-stage2'
make[1]: *** [all] Error 2 Makefile:849: recipe for target 'all' failedmake[1]: Leaving directory '/home/patrick/src/m16c/toolchain/build/gcc-4.9.2-stage2' make: *** [/home/patrick/src/m16c/toolchain/build/gcc-4.9.2-stage2/.compiled] Error 2 gcc/gcc.mk:114: recipe for target '/home/patrick/src/m16c/toolchain/build/gcc-4.9.2-stage2/.compiled' failed
make gcc-stage2 596.96s user 37.86s system 87% cpu 12:01.42 total tee log 0.04s user 0.56s system 0% cpu 12:01.42 total (full build log attached if anyone is interested) I haven't investigated that issue and am hoping someone may be able to help.Given that I'm only interested in the m16c variant of the processor I disabled the m32cm multilib with a patch (m16c-multilib.patch attached) to temporarily work around the build issue.
I now had a working compiler which appears to be able to compile normal code, however there appear to be a few issues with the far memory support.
The following test case demonstrates one issue: extern char *src; extern char __far *far_src; extern char *dest; extern char __far *far_dest; void test(void) { *dest = *src; *dest = *far_src; *far_dest = *src; *far_dest = *far_src; } ./m32c-elf-gcc -mcpu=m16c -c -o test.o ~/src/patrick/m32c/bug.c /tmp/ccUMQwCN.s: Assembler messages:/tmp/ccUMQwCN.s:18: Error: unrecognized keyword/register name `ste.b [a1a0],r0l'
/tmp/ccUMQwCN.s:30: Error: Invalid literal `lde.b r0l,[a1a0]'/tmp/ccUMQwCN.s:41: Error: unrecognized keyword/register name `ste.b [a1a0],r0l'
/tmp/ccUMQwCN.s:44: Error: Invalid literal `lde.b r0l,[a1a0]'Looked like gcc was emitting some garbage instructions. In fact, the ste.b and lde.b are reversed. I spent some time trying to understand the issue and came up with m32c.patch (attached). The assembly output now looks ok, however I am not sure about the full side-effects of the patch.
There are now two issues which I have been unable to address: Issue 1: char x[1]; void __far *test(void) { return x; } ./m32c-elf-gcc -mcpu=m16c -c -o test.o ~/src/patrick/m32c/bug2.c /home/patrick/src/patrick/m32c/bug2.c: In function 'test': /home/patrick/src/patrick/m32c/bug2.c:6:1: error: unrecognizable insn: } ^ (insn 5 2 6 2 (set (reg:SI 28)(zero_extend:SI (symbol_ref:HI ("x") <var_decl 0x7f37210fa390 x>))) /home/patrick/src/patrick/m32c/bug2.c:5 -1
(nil))/home/patrick/src/patrick/m32c/bug2.c:6:1: internal compiler error: in extract_insn, at recog.c:2202
Issue 2: char __far x[1]; void __far *test(void) { return x; } ./m32c-elf-gcc -mcpu=m16c -c -o test.o ~/src/patrick/m32c/bug3.c /home/patrick/src/patrick/m32c/bug3.c: In function 'test':/home/patrick/src/patrick/m32c/bug3.c:6:1: internal compiler error: in elimination_costs_in_insn, at reload1.c:3638
Unfortunately I don't know enough about the internals of GCC to make a sane attempt at addressing either of these.
I started by reading https://gcc.gnu.org/onlinedocs/gccint/Machine-Desc.html to try to understand the first issue, but this document is a bit too low-level for me to digest at this time. I know what RTL *is*, but have no idea about the details of the operations GCC generates and how it expects the machine description to interpret them. Is there a high-level introduction of GCC internals available? I admit laziness on this point as I haven't had a chance to do much searching.
I haven't done any work towards understanding the second issue at all.For now, I have a compiler which I think will be useful for the short term, but I would like to have __far support working in the future as I have a large lookup table which should really go in flash memory (__far) on the m16c.
I would appreciate any help towards addressing the above issues. Thanks, Patrick
Attachment:
m32cm-multilib-failure.log.tar.xz
Description: application/xz
--- gcc/gcc/config/m32c/t-m32c 2014-01-03 09:23:26.000000000 +1100 +++ gcc/gcc/config/m32c/t-m32c 2014-12-23 14:21:55.836315100 +1100 @@ -37,6 +37,6 @@ # We support four CPU series, but R8C and M16C share one multilib, and # M32C and M32CM share another. -MULTILIB_OPTIONS = mcpu=m32cm -MULTILIB_DIRNAMES = m32cm -MULTILIB_MATCHES = mcpu?m32cm=mcpu?m32c mcpu?r8c=mcpu?m16c +MULTILIB_OPTIONS = mcpu=m16c +MULTILIB_DIRNAMES = +MULTILIB_MATCHES =
--- gcc/gcc/config/m32c/mov.md 2015-02-10 11:09:12.911665074 +1100 +++ gcc/gcc/config/m32c/mov.md 2015-02-11 08:03:44.008636811 +1100 @@ -57,8 +57,8 @@ "Rhi*Rmm,SF, iRqi*Rmm, iRqiSd*Rmm, >, Rqi*Rmm, SdSs, i"))] "m32c_mov_ok (operands, QImode)" "@ - lde.b\t%1,%0 ste.b\t%1,%0 + lde.b\t%1,%0 mov.b\t%1,%0 push.b\t%1 pop.b\t%0