gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/cmds/core/io/cmos.go (about) 1 // Copyright 2012-2020 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 // +build amd64 386 6 7 package main 8 9 import ( 10 "fmt" 11 12 "github.com/u-root/u-root/pkg/cmos" 13 "github.com/u-root/u-root/pkg/memio" 14 ) 15 16 func init() { 17 usageMsg += `io (cr index)... # read from CMOS register index [14-127] 18 io (cw index value)... # write value to CMOS register index [14-127] 19 io (rtcr index)... # read from RTC register index [0-13] 20 io (rtcw index value)... # write value to RTC register index [0-13] 21 ` 22 addCmd(readCmds, "cr", &cmd{cmosRead, 7, 8}) 23 addCmd(readCmds, "rtcr", &cmd{rtcRead, 7, 8}) 24 addCmd(writeCmds, "cw", &cmd{cmosWrite, 7, 8}) 25 addCmd(writeCmds, "rtcw", &cmd{rtcWrite, 7, 8}) 26 } 27 28 func cmosRead(reg int64, data memio.UintN) error { 29 regVal := memio.Uint8(reg) 30 if regVal < 14 { 31 return fmt.Errorf("byte %d is inside the range 0-13 which is reserved for RTC", regVal) 32 } 33 return cmos.Read(regVal, data) 34 } 35 36 func cmosWrite(reg int64, data memio.UintN) error { 37 regVal := memio.Uint8(reg) 38 if regVal < 14 { 39 return fmt.Errorf("byte %d is inside the range 0-13 which is reserved for RTC", regVal) 40 } 41 return cmos.Write(regVal, data) 42 } 43 44 func rtcRead(reg int64, data memio.UintN) error { 45 regVal := memio.Uint8(reg) 46 if regVal > 13 { 47 return fmt.Errorf("byte %d is outside the range 0-13 reserved for RTC", regVal) 48 } 49 return cmos.Read(regVal, data) 50 } 51 52 func rtcWrite(reg int64, data memio.UintN) error { 53 regVal := memio.Uint8(reg) 54 if regVal > 13 { 55 return fmt.Errorf("byte %d is outside the range 0-13 reserved for RTC", regVal) 56 } 57 return cmos.Write(regVal, data) 58 }