Giter VIP home page Giter VIP logo

riscv-go's Introduction

The Go Programming Language

RISC-V Go Port

This repository is home of the RISC-V port of the Go programming language.

The upstream Go project can be found at https://github.com/golang/go.

This port has been upstreamed in Go 1.14. Please refer to upstream for all RISC-V development. This repository is outdated and archived.

Quick Start

Setup:

$ git clone https://review.gerrithub.io/riscv/riscv-go riscv-go
$ cd riscv-go
$ git checkout riscvdev  # RISC-V work happens on this branch
$ export GOROOT_BOOTSTRAP=/path/to/prebuilt/go/tree
$ export PATH="$(pwd)/misc/riscv:$(pwd)/bin:$PATH"
$ cd src
$ ./make.bash

Compile and run in qemu-riscv64 (which is expected to be in PATH):

$ GOARCH=riscv GOOS=linux go run ../riscvtest/add.go

Build:

$ GOARCH=riscv GOOS=linux go build ../riscvtest/add.go

Test:

Our basic tests are in the riscvtest directory:

$ cd ../riscvtest
$ go run run.go

If this exits without error, all is well!

QEMU

Spike plus pk support only a small subset of Linux syscalls and will not be capable of supporting the full Go runtime.

The RISC-V QEMU port supports a much wider set of syscalls with its "User Mode Simulation". See Method 2 in the QEMU README for instructions.

Contributing

All contributors must sign the upstream Contributor License Agreement, as this port will be merged into upstream Go upon completion.

Code review occurs via our GerritHub project, rather than via GitHub Pull Requests.

The upstream contribution guidelines include a basic overview of using Gerrit. While the upstream Go Gerrit server is different from ours, codereview.cfg will configure git-codereview to send CLs to GerritHub.

riscv-go's People

Contributors

0intro avatar aclements avatar adg avatar agl avatar alexbrainman avatar ality avatar bradfitz avatar cherrymui avatar cixtor avatar crawshaw avatar davecheney avatar dsnet avatar dsymonds avatar dvyukov avatar griesemer avatar ianlancetaylor avatar josharian avatar ken avatar mdempsky avatar minux avatar mpvl avatar mundaym avatar mwhudson avatar niemeyer avatar nigeltao avatar prattmic avatar randall77 avatar remyoudompheng avatar robpike avatar rsc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

riscv-go's Issues

cmd/asm: TestRISCVEncoder fails on AUIPC

--- FAIL: TestRISCVEncoder (0.02s)
	endtoend_test.go:221: 00184 (testdata/riscvenc.s:59)	AUIPC	$0, TMP: have encoding 970f0000, want ef000000
	endtoend_test.go:221: 00196 (testdata/riscvenc.s:61)	AUIPC	$0, TMP: have encoding 970f0000, want 6f000000
FAIL
FAIL	cmd/asm/internal/asm	0.223s

cc @bbarenblat

MOV doesn't work with MaxInt32 immediate

This does not compile:

//go:noinline
func maxInt32() int {
        return 1<<31-1
}

The compiler splts out reasonably assembly, which the assembler chokes on:

genssa maxInt32
   	00000 (add.go:4)	TEXT	"".maxInt32(SB)
   	00001 (add.go:4)	FUNCDATA	$0, "".gcargs·0(SB)
   	00002 (add.go:4)	FUNCDATA	$1, "".gclocals·1(SB)
   	00003 (add.go:4)	TYPE	~r0(FP), type.int(SB)
v7	00004 (add.go:5)	VARDEF	"".~r0(FP)
v4	00005 (add.go:5)	MOV	$2147483647, GP
v8	00006 (add.go:5)	MOV	GP, "".~r0(FP)
b1	00007 (add.go:5)	RET
   	00008 (<unknown line number>)	END
add.go:17: 00000 (add.go:5)	LUI	$524288, GP	immediate in from position cannot be larger than 20 bits but got 524288

It looks like our 32-bit immediate LUI + ADDI split is subtlety broken.

Compiler not spilling/rematerializing block control values as expected.

@josharian was right after all on https://review.gerrithub.io/#/c/300193/. :)

typecheck.go is failing after attempting to do a merge from master, and the failure is as expected. The registers used for the control value are clobbered between when they are set and when they are used.

Before the merge, the generated code works:

b14: ← b7
  v56 = SUB <bool> v9 v9 : T0
  v49 = SEQZ <bool> v56 : T0
  v57 = ANDI <bool> [1] v49 : T0
  v63 = BNE <flags> v69 v57
BRANCH v63 → b16 b18 (likely)

b16: ← b14
  v53 = LoweredNilCheck <void> v6 v18
  v54 = MOVDload <Blue> {autotmp_1} v2 v18 : GP
Plain → b17

b17: ← b16 b18
  v81 = Phi <Blue> v54 v61 : GP
BRANCH v63 → b21 b22 (unlikely)

v56 00041 (typeswitch.go:15)	SUB	T0, T0, T0
v49 00042 (typeswitch.go:15)	SEQZ	T0, T0
v57 00043 (typeswitch.go:15)	ANDI	$1, T0, T0
b14 00044 (typeswitch.go:15)	BEQ	T2, T0, 57
v53 00045 (typeswitch.go:15)	MOVB	(GP), ZERO
v54 00046 (typeswitch.go:15)	MOV	"".autotmp_1-8(SP), GP
b17 00047 (typeswitch.go:15)	BNE	T2, T0, 53

The control value v63 is the comparison between T2 and T0. The branch at b17 is fine because the intermediate code only sets GP.

After the merge, the code looks like this:

b14: ← b7
  v79 = SUB <bool> v9 v9 : GP
  v48 = SEQZ <bool> v79 : GP
  v82 = ANDI <bool> [1] v48 : GP
  v83 = BNE <flags> v13 v82
BRANCH v83 → b16 b17 (likely)

b16: ← b14
  v51 = MOVDload <Blue> {.autotmp_1} v2 v18 : GP
Plain → b18

b18: ← b16 b17
  v52 = Phi <Blue> v51 v41 : GP
BRANCH v83 → b21 b22 (unlikely)

v79 00041 (typeswitch.go:15)	SUB	GP, GP, GP
v48 00042 (typeswitch.go:15)	SEQZ	GP, GP
v82 00043 (typeswitch.go:15)	ANDI	$1, GP, GP
b14 00044 (typeswitch.go:15)	BEQ	T1, GP, 56
v51 00045 (typeswitch.go:15)	MOV	""..autotmp_1-8(SP), GP
b18 00046 (typeswitch.go:15)	BNE	T1, GP, 52

Now the control value v83 is the comparison between T1 and GP. The intermediate code changes GP, so the branch at b18 is not correct.

doc/asm: add risc-v details

Reminder for later, once everything has stabilized.

Quoting/modifying golang/go#16362:

The assembler document has a section at the end summarizing architecture-dependent details.It needs one for the new RISC-V port.

Split stack checks

Some RISC-V implementations will be more dependent on static branch prediction. We can be friendlier to them by moving the morestack call to the end of the function, so that the initial ld; bgeu is a not-taken forward branch. Look at what cmd/internal/obj/x86.stacksplit is doing, there are subtleties with pcdata and stack adjustment that need to be handled to keep GC happy (just copying the original x86 commit is not enough).

obj.As requires int32 with RISC-V

RISC-V pushes the As constants over the 16-bit limit, which forced us to upgrade obj.As to int32. It would be nice to get back to int16.

Build not working on Go 1.10

What version of Go are you using (go version)?

go version go1.10.3 linux/amd64

What operating system and processor architecture are you using (go env)?

Ubuntu 18.04 GOARCH="amd64"

What did you do?

Follow quick start instructions: ./make.bash

What did you expect to see?

What did you see instead?

# runtime/internal/sys compile: unknown architecture "riscv"

cmd/internal/obj/riscv: document how to regenerate inst.go

inst.go says "// Automatically generated by parse-opcodes". It looks like parse-opcodes is probably https://github.com/riscv/riscv-opcodes, but I don't see a Go code generator there. At a minimum, we should document how to re-generate the file (including fixing riscv/riscv-opcodes#6).

Better would be if riscv/riscv-opcodes#7 got fixed, at which point the json and generation script could live in this repo, where it could be easily modified and re-run by developers, and where changes to both script and json would be tracked and code reviewed.

cc @bbarenblat (I don't seem to have github permissions to assign issues)

runtime signal structs need updating

Signal handling got refactored by Ian during the 1.8 cycle. The runtime defs need updating:

# runtime
runtime/os_linux.go:317: undefined: stackt
runtime/os_linux.go:387: undefined: stackt
runtime/os_linux.go:391: undefined: sigctxt
runtime/signal_sighandler.go:30: undefined: sigctxt
runtime/signal_sighandler.go:109: undefined: dumpregs
runtime/signal_unix.go:205: undefined: sigctxt
runtime/signal_unix.go:217: undefined: stackt
runtime/signal_unix.go:237: undefined: sigctxt
runtime/signal_unix.go:320: undefined: sigctxt
runtime/signal_unix.go:444: undefined: sigctxt
runtime/signal_unix.go:496: undefined: sigctxt
runtime/signal_unix.go:577: undefined: stackt
runtime/signal_unix.go:611: undefined: stackt
runtime/signal_unix.go:622: undefined: stackt
runtime/signal_unix.go:635: undefined: stackt

The status of this port

Hi,

I notice that this repo hasn't been updated for a while, and wonder what the porting progress into mainline is?

Actually I have a patch, aiming at completing the missing relocation types in current src/debug/elf/elf.go. But I am still trying to figure out the usage of GerritHub. :)

Thanks.

A typo in riscv.md

In the file riscv.md:

Setup:

```sh
$ export GOROOT_BOOTSRAP=/path/to/prebuilt/go/tree

The BOOTSRAP should be BOOTSTRAP.

cmd/asm: add convenience pseudo instructions

  • A real NOP (ADD $0, ZERO, ZERO), not the plan9 pseudo-op NOP. What should it be called?
  • SEQZ (SLTIU rs, $1, rd) and friends. Have to decide whether to try to match x86 names.
  • Read through the spec's commentary and look for others.

FP register is broken

Right now we assign REG_FP = REG_S0, though it is never initialized or updated, so attempts to use it segfault. Taking a quick look at the rest of the toolchain, it looks like other arches might actually treat it as a psuedo register that doesn't have a real assignment at all?

Does riscv-go support bare metal?

Dear community,

We want to build go programes for riscv, but we want it to run on bare metal.
However I am not able to find any document specifying explicitly whether bare metal (without OS) is supported or not.
Any reply would be much appreciated!

Best Regards,
Xiang

cmd/internal/obj/riscv: allow From3 to be nil

progedit starts with:

    // Ensure everything has a From3 to eliminate a ton of nil-pointer
    // checks later.
    if p.From3 == nil {
        p.From3 = &obj.Addr{Type: obj.TYPE_NONE}
    }

Past experience suggests that it's worth deal with the nil checks on From3 and avoiding the allocations, as a matter of performance.

Large constant generation broken (again)

Attempting to compile strconv/atof.go:

strconv/quote.go:533: 02193 (/Users/josh/go/riscv/src/strconv/atof.go:425)	MOV	$3407386240, T2: constant 3407386240 too large; see riscv.rules MOVQconst for how to make a 64 bit constant: immediate does not fit in 32-bits: 3407386240

That constant (conspicuously) is 32 bits long. Either the assembler or riscv.rules is wrong for this edge case.

Compilation of RISC-V target (CMake) is no more possible, after an update in libgo. Problems with matching arch. definition files

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

Not sure. Transition between pre-1.15 (uncertain) and 1.15.

What operating system and processor architecture are you using (go env)?

Host compiler (Clang) is on x86_64 Ubuntu

What did you do?

Nothing spectacular. Just tried to compile https://go.googlesource.com/gollvm/ - and it is no more compiling, after some files where removed, for libgo project.

I am not claiming that there where some direct support of RISC-V arch (gollvm language front-end wasn't ever compiled for running on RISC-V). However LLVM's backend could support it (I was able to generate debug and release builds, for that) and running llvm-goc, on Linux, could potentially target RISC-V arch.

What did you expect to see?

build.ninja would be generated.

What did you see instead?

CMake exit with an error.

Here is my detailed explanation: golang/go#40528 .
I don't think that the maintainers of that project has any bandwidth to deal with RISC-V support - so you might help with that.

Ivan

Assorted code review cleanups

As part of an effort to get @sorear's changes in, so we can all move forward, I'm going to note some codereview items here that can be reasonably done as follow-up changes instead of blocking submission.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.