|
| 1 | +// Copyright 2021 The Go Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +//go:build tamago && riscv64 |
| 6 | + |
| 7 | +package testing |
| 8 | + |
| 9 | +import ( |
| 10 | + "runtime" |
| 11 | + _ "unsafe" |
| 12 | +) |
| 13 | + |
| 14 | +//go:linkname ramStart runtime.ramStart |
| 15 | +var ramStart uint64 = 0x80000000 |
| 16 | + |
| 17 | +//go:linkname ramSize runtime.ramSize |
| 18 | +var ramSize uint64 = 0x20000000 // 512MB |
| 19 | + |
| 20 | +//go:linkname ramStackOffset runtime.ramStackOffset |
| 21 | +var ramStackOffset uint64 = 0x100 |
| 22 | + |
| 23 | +// defined in testing_tamago_riscv64.s |
| 24 | +func sys_exit(code int32) |
| 25 | +func sys_write(c *byte) |
| 26 | +func sys_clock_gettime() (ns int64) |
| 27 | +func sys_getrandom(b []byte, n int) |
| 28 | + |
| 29 | +//go:linkname nanotime1 runtime.nanotime1 |
| 30 | +func nanotime1() int64 { |
| 31 | + return sys_clock_gettime() |
| 32 | +} |
| 33 | + |
| 34 | +//go:linkname initRNG runtime.initRNG |
| 35 | +func initRNG() {} |
| 36 | + |
| 37 | +//go:linkname getRandomData runtime.getRandomData |
| 38 | +func getRandomData(b []byte) { |
| 39 | + sys_getrandom(b, len(b)) |
| 40 | +} |
| 41 | + |
| 42 | +// preallocated memory to avoid malloc during panic |
| 43 | +var a [1]byte |
| 44 | + |
| 45 | +//go:linkname printk runtime.printk |
| 46 | +func printk(c byte) { |
| 47 | + a[0] = c |
| 48 | + sys_write(&a[0]) |
| 49 | +} |
| 50 | + |
| 51 | +//go:linkname hwinit runtime.hwinit |
| 52 | +func hwinit() { |
| 53 | + runtime.Bloc = uintptr(ramStart) |
| 54 | + runtime.Exit = sys_exit |
| 55 | +} |
0 commit comments