Support of thumb in golang

656 views
Skip to first unread message

Ben Shi

unread,
Feb 13, 2017, 1:05:47 AM2/13/17
to golan...@googlegroups.com
Go might be a good choice to substitude RTOS running on Cortex-m3/m4 chips. Each basic concept of a RTOS can be mapped to a golang's feature.
1. real time threads - go routines
2. synchronization - go channels
3. memory management - go has GC

and so on.

But first, is there any plan to support thumb-2 in the compiler?

Ben Shi

minux

unread,
Feb 13, 2017, 7:40:23 AM2/13/17
to Ben Shi, golang-dev
I wouldn't worry too much about Thumb-2 support because almost every ARM instruction could be mapped into (possibly a sequence of) Thumb-2 instructions, so we can have a rough Thumb-2 backend by adding a new cmd/internal/obj/thumb package alone and reuse the ARM backend.

The main obstacle, in my opinion, is the runtime. For example, the current gc runtime relies on a paged memory architecture and at least multiple MB of memory to run. On a system with at most a few hundreds of KB of memory, the gc needs to be completely rewritten.

I think you can start with gccgo in less effort and see if you can adapt the runtime to run in MCU-class environments.

Ian H

unread,
Aug 14, 2017, 1:10:19 PM8/14/17
to golang-dev, power...@163.com
I'd be interested in getting simple Go programs running on Cortex M-series microcontrollers. There are a number of boards on mbed.org which have 512K-2M flash, and 256-512K RAM; the Mbed OS seems to have threads and a network stack, so it's not out of the question.

As an experiment, I installed & ran gccgo 6.0 on an ARM Linux box, and it will compile simple .go files to Thumb code (using the -mthumb option, and in fact by default...) quite readily. So code generation itself isn't a big blocker. I think the issues are likely to be:
  1. The size of the runtime (as discussed in many places). How much stuff can we throw away (Unicode? reflection?) and still have a useful embedded system? Pretty hard to do anything without basic GC, and no goroutines or channels would make life very dull.
  2. Dependency of the runtime on Linux system calls. How many fancy properties of threads or memory management does it rely on?
  3. Floating point. Any chance of running the system without FP?
  4. Doing Useful Stuff without writing wrappers round the whole OS.

I might have a crack at getting the simplest Hello World going on an upscale mbed board, to see how awful it's likely to be.


Cheers

IH

Reply all
Reply to author
Forward
0 new messages