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
48 changes: 14 additions & 34 deletions build/measurement/acpi/acpi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@ import (
"embed"
"encoding/binary"
"encoding/hex"
"encoding/json"
"fmt"

"github.com/oasisprotocol/oasis-core/go/runtime/bundle"
)

//go:embed *.hex *.json
//go:embed *.hex
var templates embed.FS

// OffsetData is the offset data file format.
type OffsetData struct {
Memory MemoryOffsetData `json:"memory"`
}

type MemoryOffsetData struct {
RangeMinimumOffset int `json:"range_minimum_offset"`
LengthOffset int `json:"length_offset"`
}

// GenerateTablesQemu generates ACPI tables for the given TD configuration.
//
// Returns the raw ACPI tables, RSDP and QEMU table loader command blob.
Expand All @@ -40,28 +29,6 @@ func GenerateTablesQemu(resources *bundle.TDXResources) ([]byte, []byte, []byte,
return nil, nil, nil, fmt.Errorf("malformed ACPI table template")
}

// Fetch corresponding offset data.
fn = fmt.Sprintf("template_qemu_cpu%d.json", resources.CPUCount)
offsetData, err := templates.ReadFile(fn)
if err != nil {
return nil, nil, nil, fmt.Errorf("offset data for ACPI tables is not available")
}

var od OffsetData
if err = json.Unmarshal(offsetData, &od); err != nil {
return nil, nil, nil, fmt.Errorf("malformed ACPI table offset data")
}

// Handle memory split at 2816 MiB (0xB0000000).
if resources.Memory >= 2816 {
binary.LittleEndian.PutUint32(tpl[od.Memory.RangeMinimumOffset:], 0x80000000)
binary.LittleEndian.PutUint32(tpl[od.Memory.LengthOffset:], 0x60000000)
} else {
memSizeBytes := uint32(resources.Memory * 1024 * 1024) //nolint: gosec
binary.LittleEndian.PutUint32(tpl[od.Memory.RangeMinimumOffset:], memSizeBytes)
binary.LittleEndian.PutUint32(tpl[od.Memory.LengthOffset:], 0xe0000000-memSizeBytes)
}

// Generate RSDP.
rsdp := append([]byte{},
0x52, 0x53, 0x44, 0x20, 0x50, 0x54, 0x52, 0x20, // Signature ("RSDP PTR ").
Expand Down Expand Up @@ -96,6 +63,19 @@ func GenerateTablesQemu(resources *bundle.TDXResources) ([]byte, []byte, []byte,
return nil, nil, nil, err
}

// Handle memory split at 2816 MiB (0xB0000000).
lengthOffset := dsdtLen - 684 // Offset of the length field inside the DSDT table.
rangeMinimumOffset := lengthOffset - 12 // Offset of the range minimum field inside the DSDT table.

if resources.Memory >= 2816 {
binary.LittleEndian.PutUint32(tpl[rangeMinimumOffset:], 0x80000000)
binary.LittleEndian.PutUint32(tpl[lengthOffset:], 0x60000000)
} else {
memSizeBytes := uint32(resources.Memory * 1024 * 1024) //nolint: gosec
binary.LittleEndian.PutUint32(tpl[rangeMinimumOffset:], memSizeBytes)
binary.LittleEndian.PutUint32(tpl[lengthOffset:], 0xe0000000-memSizeBytes)
}

// Update RSDP with RSDT address.
var rsdtAddress [4]byte
binary.LittleEndian.PutUint32(rsdtAddress[:], rsdtOffset)
Expand Down
6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu1.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu10.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu11.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu12.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu13.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu14.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu15.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu16.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu2.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu3.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu4.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu5.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu6.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu7.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu8.json

This file was deleted.

6 changes: 0 additions & 6 deletions build/measurement/acpi/template_qemu_cpu9.json

This file was deleted.

Loading