github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/smbios/smbios_legacy.go (about) 1 // Copyright 2016-2021 the u-root 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 package smbios 6 7 import ( 8 "bytes" 9 "fmt" 10 11 "github.com/mvdan/u-root-coreutils/pkg/memio" 12 ) 13 14 var memioRead = memio.Read 15 16 // getSMBIOSBase searches _SM_ or _SM3_ tag in the given memory range. 17 func getSMBIOSBase(start, end int64) (int64, int64, error) { 18 for base := start; base < end; base++ { 19 dat := memio.ByteSlice(make([]byte, 5)) 20 if err := memioRead(int64(base), &dat); err != nil { 21 return 0, 0, err 22 } 23 if bytes.Equal(dat[:4], []byte("_SM_")) { 24 return base, smbios2HeaderSize, nil 25 } 26 if bytes.Equal(dat[:], []byte("_SM3_")) { 27 return base, smbios3HeaderSize, nil 28 } 29 } 30 return 0, 0, fmt.Errorf("could not find _SM_ or _SM3_ via /dev/mem from %#08x to %#08x", start, end) 31 } 32 33 // SMBIOSBaseLegacy searches in SMBIOS entry point address in F0000 segment. 34 // NOTE: Legacy BIOS will store their SMBIOS in this region. 35 func SMBIOSBaseLegacy() (int64, int64, error) { 36 return getSMBIOSBase(0xf0000, 0x100000) 37 }