Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The following table summarizes currently supported x86-64 targets
| AMD/Intel 64-bit | [Firecracker microvm](https://firecracker-microvm.github.io) | [amd64](https://github.com/usbarmory/tamago/tree/master/amd64) | [firecracker/microvm](https://github.com/usbarmory/tamago/tree/master/board/firecracker/microvm) |
| AMD/Intel 64-bit | [QEMU microvm](https://www.qemu.org/docs/master/system/i386/microvm.html) | [amd64](https://github.com/usbarmory/tamago/tree/master/amd64) | [qemu/microvm](https://github.com/usbarmory/tamago/tree/master/board/qemu/microvm) |
| AMD/Intel 64-bit | [UEFI](https://uefi.org/) | [amd64](https://github.com/usbarmory/tamago/tree/master/amd64) | [uefi/x64](https://github.com/usbarmory/go-boot/tree/main/uefi/x64) |
| AMD/Intel 64-bit | [Google Compute Engine](https://cloud.google.com/products/compute) | [amd64](https://github.com/usbarmory/tamago/tree/master/amd64) | [qemu/microvm](https://github.com/usbarmory/tamago/tree/master/board/qemu/microvm), [uefi/x64](https://github.com/usbarmory/go-boot/tree/main/uefi/x64) |
| AMD/Intel 64-bit | [Google Compute Engine](https://cloud.google.com/products/compute) | [amd64](https://github.com/usbarmory/tamago/tree/master/amd64) | [google/gcp](https://github.com/usbarmory/tamago/tree/master/board/google/gcp), [uefi/x64](https://github.com/usbarmory/go-boot/tree/main/uefi/x64) |

Supported ARM targets
=====================
Expand Down
1 change: 1 addition & 0 deletions amd64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Supported hardware
| AMD/Intel 64-bit | [cloud_hypervisor/vm](https://github.com/usbarmory/tamago/tree/master/board/cloud_hypervisor/vm) | [LAPIC](https://github.com/usbarmory/tamago/tree/master/amd64/lapic) | [KVM clock, VirtIO over PCI](https://github.com/usbarmory/tamago/tree/master/kvm), [IOAPIC, PCI, RTC, UART](https://github.com/usbarmory/tamago/blob/master/soc/intel) |
| AMD/Intel 64-bit | [qemu/microvm](https://github.com/usbarmory/tamago/tree/master/board/qemu/microvm) | [LAPIC](https://github.com/usbarmory/tamago/tree/master/amd64/lapic) | [KVM clock, VirtIO over MMIO](https://github.com/usbarmory/tamago/tree/master/kvm), [IOAPIC, RTC, UART](https://github.com/usbarmory/tamago/blob/master/soc/intel) |
| AMD/Intel 64-bit | [firecracker/microvm](https://github.com/usbarmory/tamago/tree/master/board/firecracker/microvm) | [LAPIC](https://github.com/usbarmory/tamago/tree/master/amd64/lapic) | [KVM clock, VirtIO over MMIO](https://github.com/usbarmory/tamago/tree/master/kvm), [IOAPIC, UART](https://github.com/usbarmory/tamago/blob/master/soc/intel) |
| AMD/Intel 64-bit | [google/gcp](https://github.com/usbarmory/tamago/tree/master/board/google/gcp) | [LAPIC](https://github.com/usbarmory/tamago/tree/master/amd64/lapic) | [KVM clock, VirtIO over PCI](https://github.com/usbarmory/tamago/tree/master/kvm), [IOAPIC, PCI, RTC, UART](https://github.com/usbarmory/tamago/blob/master/soc/intel) |
| AMD/Intel 64-bit | [uefi/x64](https://github.com/usbarmory/go-boot/tree/main/uefi/x64) | | [EFI Console I/O, Graphics, Boot and Runtime Services](https://github.com/usbarmory/go-boot/tree/main/uefi), [RTC, UART](https://github.com/usbarmory/tamago/blob/master/soc/intel) |

Build tags
Expand Down
1 change: 1 addition & 0 deletions board/cloud_hypervisor/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func Init() {

// initialize I/O APIC
IOAPIC0.Init()

// initialize serial console
UART0.Init()

Expand Down
147 changes: 147 additions & 0 deletions board/google/gcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
TamaGo - bare metal Go - Google Cloud Compute support
=====================================================

tamago | https://github.com/usbarmory/tamago

Copyright (c) The TamaGo Authors. All Rights Reserved.

![TamaGo gopher](https://github.com/usbarmory/tamago/wiki/images/tamago.svg?sanitize=true)

Authors
=======

Andrea Barisani
andrea@inversepath.com

Andrej Rosano
andrej@inversepath.com

Introduction
============

TamaGo is a framework that enables compilation and execution of unencumbered Go
applications on bare metal processors.

The [gcp](https://github.com/usbarmory/tamago/tree/master/board/google/gcp)
package provides support for [Google Compute Engine](https://cloud.google.com/products/compute)
paravirtualized Kernel-based Virtual Machine (KVM) configured with single or
multiple AMD64 cores and machine type `t2d-standard-?`.

Documentation
=============

[![Go Reference](https://pkg.go.dev/badge/github.com/usbarmory/tamago.svg)](https://pkg.go.dev/github.com/usbarmory/tamago)

For more information about TamaGo see its
[repository](https://github.com/usbarmory/tamago) and
[project wiki](https://github.com/usbarmory/tamago/wiki).

For the underlying driver support for this board see package
[amd64](https://github.com/usbarmory/tamago/tree/master/amd64) and
[gcp](https://github.com/usbarmory/tamago/tree/master/board/google/gcp).

The package API documentation can be found on
[pkg.go.dev](https://pkg.go.dev/github.com/usbarmory/tamago).

Supported hardware
==================

| CPU | Board | CPU package | Board package |
|------------------|---------------------------------------------------------------------------|----------------------------------------------------------------|------------------------------------------------------------------------------------|
| AMD/Intel 64-bit | [Google Compute Engine](https://cloud.google.com/products/compute) | [amd64](https://github.com/usbarmory/tamago/tree/master/amd64) | [google/gcp](https://github.com/usbarmory/tamago/tree/master/board/google/gcp) |

Compiling
=========

Go applications are simply required to import, the relevant board package to
ensure that hardware initialization and runtime support take place:

```golang
import (
_ "github.com/usbarmory/tamago/board/google/gcp"
)
```

Build the [TamaGo compiler](https://github.com/usbarmory/tamago-go)
(or use the [latest binary release](https://github.com/usbarmory/tamago-go/releases/latest)):

```
wget https://github.com/usbarmory/tamago-go/archive/refs/tags/latest.zip
unzip latest.zip
cd tamago-go-latest/src && ./all.bash
cd ../bin && export TAMAGO=`pwd`/go
```

Go applications can be compiled as usual, using the compiler built in the
previous step, but with the addition of the following flags/variables:

```
GOOS=tamago GOARCH=amd64 ${TAMAGO} build -ldflags "-T 0x10010000 -R 0x1000" main.go
```

An example application, targeting the Google Cloud Platform platform,
is [available](https://github.com/usbarmory/tamago-example).

Build tags
==========

The following build tags allow application to override the package own definition of
[external functions required by the runtime](https://pkg.go.dev/github.com/usbarmory/tamago/doc):

* `linkramsize`: exclude `ramSize` from `mem.go`
* `linkprintk`: exclude `printk` from `console.go`

Executing and debugging
=======================

The [example application](https://github.com/usbarmory/tamago-example) provides
reference usage and a Makefile target for automatic creation of an ELF image,
paravirtualized execution on Google Compute Engine can be accomplished through a
[boot disk image](https://github.com/usbarmory/tamago-example/tree/master/tools).

The [uefi/x64](https://github.com/usbarmory/go-boot/tree/main/uefi/x64) package
[can be used as an alternative](https://github.com/usbarmory/go-boot/wiki/Google-Compute-Engine).

The Google Cloud Compute instance machine type verified with this package is
`t2d-standard-?`.

QEMU
----

```
qemu-system-x86_64 \
-machine q35,pit=off,pic=off \
-enable-kvm -cpu host,invtsc=on,kvmclock=on -no-reboot \
-m 4G -nographic -monitor none -serial stdio \
-device pcie-root-port,port=0x10,chassis=1,id=pci.0,bus=pcie.0,multifunction=on,addr=0x3 \
-device virtio-net-device,netdev=net0,disable-modern=true -netdev tap,id=net0,ifname=tap0,script=no,downscript=no \
-kernel example
```

The paravirtualized target can be debugged with GDB by adding the `-S -s` flags
to the previous execution command, this will make qemu waiting for a GDB
connection that can be launched as follows:

```
gdb -ex "target remote 127.0.0.1:1234" example
```

Breakpoints can be set in the usual way:

```
b ecdsa.Verify
continue
```

License
=======

tamago | https://github.com/usbarmory/tamago
Copyright (c) The TamaGo Authors. All Rights Reserved.

These source files are distributed under the BSD-style license found in the
[LICENSE](https://github.com/usbarmory/tamago/blob/master/LICENSE) file.

The TamaGo logo is adapted from the Go gopher designed by Renee French and
licensed under the Creative Commons 3.0 Attributions license. Go Gopher vector
illustration by Hugo Arganda.
20 changes: 20 additions & 0 deletions board/google/gcp/console.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Google Compute Engine support for tamago/amd64
// https://github.com/usbarmory/tamago
//
// Copyright (c) The TamaGo Authors. All Rights Reserved.
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.

//go:build !linkprintk

package gcp

import (
_ "unsafe"
)

//go:linkname printk runtime.printk
func printk(c byte) {
UART0.Tx(c)
}
110 changes: 110 additions & 0 deletions board/google/gcp/gcp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Google Compute Engine support for tamago/amd64
// https://github.com/usbarmory/tamago
//
// Copyright (c) The TamaGo Authors. All Rights Reserved.
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.

// Package gcp provides hardware initialization, automatically on import, for a
// Google Compute Engine machine configured with one or more x86_64 cores.
//
// This package is only meant to be used with `GOOS=tamago GOARCH=amd64` as
// supported by the TamaGo framework for bare metal Go, see
// https://github.com/usbarmory/tamago.
package gcp

import (
"runtime"
_ "unsafe"

"github.com/usbarmory/tamago/amd64"
"github.com/usbarmory/tamago/dma"
"github.com/usbarmory/tamago/kvm/pvclock"
"github.com/usbarmory/tamago/soc/intel/ioapic"
"github.com/usbarmory/tamago/soc/intel/rtc"
"github.com/usbarmory/tamago/soc/intel/uart"
)

const (
dmaStart = 0x50000000
dmaSize = 0x10000000 // 256MB
)

// Peripheral registers
const (
// Communication port
COM1 = 0x3f8

// Intel I/O Programmable Interrupt Controllers
IOAPIC0_BASE = 0xfec00000

// VirtIO Networking
VIRTIO_NET_PCI_VENDOR = 0x1af4 // Red Hat, Inc.
VIRTIO_NET_PCI_DEVICE = 0x1000 // Virtio 1.0 network device
)

// Peripheral instances
var (
// CPU instance(s)
AMD64 = &amd64.CPU{
// required before Init()
TimerMultiplier: 1,
}

// I/O APIC - GSI 0-23
IOAPIC0 = &ioapic.IOAPIC{
Index: 0,
Base: IOAPIC0_BASE,
GSIBase: 0,
}

// Real-Time Clock
RTC = &rtc.RTC{}

// Serial port
UART0 = &uart.UART{
Index: 1,
Base: COM1,
DTR: true,
RTS: true,
}
)

//go:linkname nanotime1 runtime.nanotime1
func nanotime1() int64 {
return AMD64.GetTime()
}

// Init takes care of the lower level initialization triggered early in runtime
// setup (post World start).
//
//go:linkname Init runtime.hwinit1
func Init() {
// initialize BSP
AMD64.Init()

// initialize I/O APIC
IOAPIC0.Init()

// initialize serial console
UART0.Init()

runtime.Exit = func(_ int32) {
amd64.Fault()
}
}

func init() {
// trap CPU exceptions
AMD64.EnableExceptions()

// initialize APs
AMD64.InitSMP(-1)

// allocate global DMA region
dma.Init(dmaStart, dmaSize)

// initialize KVM pvclock as needed
pvclock.Init(AMD64)
}
23 changes: 23 additions & 0 deletions board/google/gcp/mem.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Google Compute Engine support for tamago/amd64
// https://github.com/usbarmory/tamago
//
// Copyright (c) The TamaGo Authors. All Rights Reserved.
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.

//go:build !linkramsize

package gcp

import (
_ "unsafe"
)

// Applications can override ramSize with the `linkramsize` build tag.
//
// This is useful when large DMA descriptors are required to re-initialize
// tamago `dma` package in external RAM.

//go:linkname ramSize runtime.ramSize
var ramSize uint64 = 0x40000000 // 1GB
6 changes: 0 additions & 6 deletions board/qemu/microvm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ b ecdsa.Verify
continue
```

Google Compute Engine
---------------------

The `microvm` target can be executed on [Google Compute Engine](https://cloud.google.com/products/compute), see
[tools](https://github.com/usbarmory/tamago-example/tree/master/tools) for more information.

License
=======

Expand Down
8 changes: 5 additions & 3 deletions internal/reg/port_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ TEXT ·Out8(SB),$0-3
TEXT ·In16(SB),$0-10
MOVW port+0(FP), DX
// in ax, dx
BYTE $0x66ed
BYTE $0x66
BYTE $0xed
MOVW AX, val+8(FP)
RET

// func Out16(port uint16, val uint16)
TEXT ·Out16(SB),$0-4
MOVW port+0(FP), DX
MOVW val+2(FP), AX
// out dx, al
BYTE $0x66ef
// out dx, ax
BYTE $0x66
BYTE $0xef
RET

// func In32(port uint16) (val uint32)
Expand Down
Loading