@@ -5,25 +5,14 @@ import (
55 "embed"
66 "encoding/binary"
77 "encoding/hex"
8- "encoding/json"
98 "fmt"
109
1110 "github.com/oasisprotocol/oasis-core/go/runtime/bundle"
1211)
1312
14- //go:embed *.hex *.json
13+ //go:embed *.hex
1514var templates embed.FS
1615
17- // OffsetData is the offset data file format.
18- type OffsetData struct {
19- Memory MemoryOffsetData `json:"memory"`
20- }
21-
22- type MemoryOffsetData struct {
23- RangeMinimumOffset int `json:"range_minimum_offset"`
24- LengthOffset int `json:"length_offset"`
25- }
26-
2716// GenerateTablesQemu generates ACPI tables for the given TD configuration.
2817//
2918// Returns the raw ACPI tables, RSDP and QEMU table loader command blob.
@@ -40,28 +29,6 @@ func GenerateTablesQemu(resources *bundle.TDXResources) ([]byte, []byte, []byte,
4029 return nil , nil , nil , fmt .Errorf ("malformed ACPI table template" )
4130 }
4231
43- // Fetch corresponding offset data.
44- fn = fmt .Sprintf ("template_qemu_cpu%d.json" , resources .CPUCount )
45- offsetData , err := templates .ReadFile (fn )
46- if err != nil {
47- return nil , nil , nil , fmt .Errorf ("offset data for ACPI tables is not available" )
48- }
49-
50- var od OffsetData
51- if err = json .Unmarshal (offsetData , & od ); err != nil {
52- return nil , nil , nil , fmt .Errorf ("malformed ACPI table offset data" )
53- }
54-
55- // Handle memory split at 2816 MiB (0xB0000000).
56- if resources .Memory >= 2816 {
57- binary .LittleEndian .PutUint32 (tpl [od .Memory .RangeMinimumOffset :], 0x80000000 )
58- binary .LittleEndian .PutUint32 (tpl [od .Memory .LengthOffset :], 0x60000000 )
59- } else {
60- memSizeBytes := uint32 (resources .Memory * 1024 * 1024 ) //nolint: gosec
61- binary .LittleEndian .PutUint32 (tpl [od .Memory .RangeMinimumOffset :], memSizeBytes )
62- binary .LittleEndian .PutUint32 (tpl [od .Memory .LengthOffset :], 0xe0000000 - memSizeBytes )
63- }
64-
6532 // Generate RSDP.
6633 rsdp := append ([]byte {},
6734 0x52 , 0x53 , 0x44 , 0x20 , 0x50 , 0x54 , 0x52 , 0x20 , // Signature ("RSDP PTR ").
@@ -96,6 +63,19 @@ func GenerateTablesQemu(resources *bundle.TDXResources) ([]byte, []byte, []byte,
9663 return nil , nil , nil , err
9764 }
9865
66+ // Handle memory split at 2816 MiB (0xB0000000).
67+ lengthOffset := dsdtLen - 684 // Offset of the length field inside the DSDT table.
68+ rangeMinimumOffset := lengthOffset - 12 // Offset of the range minimum field inside the DSDT table.
69+
70+ if resources .Memory >= 2816 {
71+ binary .LittleEndian .PutUint32 (tpl [rangeMinimumOffset :], 0x80000000 )
72+ binary .LittleEndian .PutUint32 (tpl [lengthOffset :], 0x60000000 )
73+ } else {
74+ memSizeBytes := uint32 (resources .Memory * 1024 * 1024 ) //nolint: gosec
75+ binary .LittleEndian .PutUint32 (tpl [rangeMinimumOffset :], memSizeBytes )
76+ binary .LittleEndian .PutUint32 (tpl [lengthOffset :], 0xe0000000 - memSizeBytes )
77+ }
78+
9979 // Update RSDP with RSDT address.
10080 var rsdtAddress [4 ]byte
10181 binary .LittleEndian .PutUint32 (rsdtAddress [:], rsdtOffset )
0 commit comments