/
smbios_legacy.go
37 lines (31 loc) · 1.06 KB
/
smbios_legacy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2016-2021 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package smbios
import (
"bytes"
"fmt"
"github.com/u-root/u-root/pkg/memio"
)
var memioRead = memio.Read
// getSMBIOSBase searches _SM_ or _SM3_ tag in the given memory range.
func getSMBIOSBase(start, end int64) (int64, int64, error) {
for base := start; base < end; base++ {
dat := memio.ByteSlice(make([]byte, 5))
if err := memioRead(int64(base), &dat); err != nil {
return 0, 0, err
}
if bytes.Equal(dat[:4], []byte("_SM_")) {
return base, smbios2HeaderSize, nil
}
if bytes.Equal(dat[:], []byte("_SM3_")) {
return base, smbios3HeaderSize, nil
}
}
return 0, 0, fmt.Errorf("could not find _SM_ or _SM3_ via /dev/mem from %#08x to %#08x", start, end)
}
// SMBIOSBaseLegacy searches in SMBIOS entry point address in F0000 segment.
// NOTE: Legacy BIOS will store their SMBIOS in this region.
func SMBIOSBaseLegacy() (int64, int64, error) {
return getSMBIOSBase(0xf0000, 0x100000)
}