Hacked up ARMv4 support

344 views
Skip to first unread message

Taru Karttunen

unread,
Apr 30, 2014, 4:50:24 AM4/30/14
to golan...@googlegroups.com
Porting Go to ARMv4
===================

I am currently running Go produced code happily on ARMv4T. Would it be
ok to submit these as CLs after the Go 1.3 release?

Invidual items list their relevant patches, a combined patch is found on:
http://s.violetti.org/armv4_all.diff.txt


Patch: Supporting code for different ARM variants
-------------------------------------------------

Issue 7211: https://code.google.com/p/go/issues/detail?id=7211

Created a patch for build tags like "armv6". Currently it supports:
+ GOARM=N -> Build tag armvN
+ GO386=X -> Build tag X

http://s.violetti.org/go_build_gosubarch.diff.txt


Patch: Lack of CLZ
------------------

CLZ is available only on ARMv5, it is not generated by the compilers,
but present in udiv in runtime/vlop_arm.s and
math/big/arith_arm.s. Created armv4 specific versions of those files.

http://s.violetti.org/armv4_math_big_no_clz.diff.txt
http://s.violetti.org/armv4_runtime_no_clz.diff.txt


Patch: MULAWT (smlawt) in udiv assembler source
-----------------------------------------------

MULAWT (smlawt) is only present in ARMv5E and higher. Even plain ARMv5
and ARMvT lack it. Patched armv5 specific udiv source to emulate it.

http://s.violetti.org/armv5_runtime_mulawt_requires_armv5te.diff.txt


Patch: liblink do not generate indirect register calls as BLX on ARMv4
----------------------------------------------------------------------

BLX rX is written as MOVW PC, LR; MOVW rX. PC on ARMv4. This does not
support Thumb interworking (there are slower variants with
interworking), but Thumb interworking is not needed for calls inside
the toolchain.

In buildop the size of affected ABLS variants is bumped to 8 and in
asmout they are rewritten.

Alternative failed approaches were: rewriting the call in progedit
results in errors as it ceases to be considered a call. Adding a NOP
in progedit results in invalid jump offsets.

http://s.violetti.org/armv4_liblink_patch_blx.diff.txt


Patch: cgo support
------------------

Cgo assembler has BLX. Provide ARMv4 specific alternative.
This needs more testing.

http://s.violetti.org/armv4_runtime_cgo_no_blx.diff.txt


Note: runtime搓reakpoint broken - no BKPT
-----------------------------------------

Debugging with gdb works fine, but the runtime asm_arm.s has BKPT
in runtime搓reakpoint which is not supported.


Note: Thumb support
-------------------

There is currently commented out Thumb code in
pkg/runtime/rt0_linux_arm.s, if enabled it would need fixes for both
plain ARMv5 and ARMv4.


Note: 5c generates PLD
----------------------

PLD is an ARMv5E instruction, but it appears as a NOP on systems not
supporting it.


Note: Atomic ops for 64 bit types require Linux kernel >=3.1
------------------------------------------------------------

64 bit atomic operations are emulated on Linux on ARMv4 and ARMv5 with
__kuser_cmpxchg64 that is present from version 3.1 onwards. With older
kernels the assembler code containing ARMv6 specific things gets called.

This results in a SIGILL in check64 with older kernels when trying to
use 64 bit atomic operations.


ps. Thanks for Aram for help on #go-nuts


- Taru Karttunen

Russ Cox

unread,
May 2, 2014, 12:01:04 PM5/2/14
to Taru Karttunen, golang-dev
Please ping this thread after the Go 1.3 release is out. Thanks.

Nick Craig-Wood

unread,
May 2, 2014, 12:23:59 PM5/2/14
to Taru Karttunen, golan...@googlegroups.com
On 30/04/14 09:50, Taru Karttunen wrote:
> Porting Go to ARMv4
> ===================
>
> I am currently running Go produced code happily on ARMv4T. Would it be
> ok to submit these as CLs after the Go 1.3 release?

I can't speak for the core developers, but as someone interested in ARM
and Go your patches look very interesting!

> Patch: Supporting code for different ARM variants
> -------------------------------------------------
>
> Issue 7211: https://code.google.com/p/go/issues/detail?id=7211
>
> Created a patch for build tags like "armv6". Currently it supports:
> + GOARM=N -> Build tag armvN
> + GO386=X -> Build tag X
>
> http://s.violetti.org/go_build_gosubarch.diff.txt

Did you see this thread?

https://groups.google.com/forum/#!topic/golang-dev/1EERkkWgbrM

I don't think we finished discussing build tags for ARM.

> Patch: Lack of CLZ
> ------------------
>
> CLZ is available only on ARMv5, it is not generated by the compilers,
> but present in udiv in runtime/vlop_arm.s and
> math/big/arith_arm.s. Created armv4 specific versions of those files.
>
> http://s.violetti.org/armv4_math_big_no_clz.diff.txt
> http://s.violetti.org/armv4_runtime_no_clz.diff.txt

I see you hit https://code.google.com/p/go/issues/detail?id=5921 here
too. It would be nice to fix that!

> Patch: MULAWT (smlawt) in udiv assembler source
> -----------------------------------------------
>
> MULAWT (smlawt) is only present in ARMv5E and higher. Even plain ARMv5
> and ARMvT lack it. Patched armv5 specific udiv source to emulate it.
>
> http://s.violetti.org/armv5_runtime_mulawt_requires_armv5te.diff.txt

So this fixes a bug. Which probably goes to show that ARMv5 isn't that
popular since it hasn't been reported.

--
Nick Craig-Wood <ni...@craig-wood.com> -- http://www.craig-wood.com/nick
Reply all
Reply to author
Forward
0 new messages