Menu

Create new LoLeOp data type

LoLeOp module includes these data types:

Io8, Io16, Io32, Io64, Mem8, Mem16, Mem32, Mem64, CpuId, Msr

These data types are based on LoleOp basic class

BitOp::_MemArray, BitOp::_MemCell,

BitOp::_CellCascade, rUnionOp::rUnionOp

To create LoLeOp new data type, this is the basic procedure.

  1. Define new class, which is inherit from _MemCell, input(MemSet) output(MemGet) function.

  2. create new data type by _MemArray instance.

Using LoLeOp.Mem.Mem8 as sample

from BitOp import _MemCell, _MemArray

#1. New class which is inherit from _MemCell.
class _Mem8 (_MemCell):

  # 1.1 Output function.
  def MemSet (self, Address, Value):
    a = EfiPy.UINT8.from_address (Address)
    a.value = Value & 0xFF

  # 1.2 Input function
  def MemGet (self, Address):
    a = EfiPy.UINT8.from_address (Address)
    return a.value

2. New data type.

Mem8  = _MemArray ("Mem8",   8,  CellClass = _Mem8)

Comments:

MemSet (self, Address, Value)
#
# INPUT:
# self _MemArray class instance
# Address Memory address in integer
# Value value to set
#
# OUTPUT: <<None>>
#

MemGet (self, Address)
#
# INPUT:
# self _MemArray class instance
# Address Memory address in integer
#
# OUTPUT:
# value to get
#

_MemArray::init (self, Name, Width = 8, args)
#
# INPUT:
# self _MemArray class instance
# Name String of new data type name
# Width new data type bit width
#
args: {
# CellExt: Reference from _MemCell
# DictKey: Direct item in _MemArray: default None
# CellClass: bit field operation class
# }
#

By MemSet and MemGet parameter, there can be another data type Io8, Io16, Io32, Io64.

# _IoBit is inherit from _MemCell, it is for override

# output string in _MemCell
class _IoBit8 (_IoBit):

  #
  # ; Intel assembly syntax
  # MOV   DX, port
  # IN    AL, DX    ; return value
  #
  def MemGet (self, port):
    IoParams.p1 = port
    ret = IoProc.execute(IoCodeGet8, params = IoParams, mode = 'int')
    return ret & 0xFF

  #
  # ; Intel assembly syntax
  # MOV   DX, port
  # MOV   AL, val
  # OUT   AL, DX
  #
  def MemSet (self, port, val):
    IoParams.p1 = port
    IoParams.p2 = val & 0xFF
    IoProc.execute(IoCodeSet8, params = IoParams, mode = 'int')

  # create Io8 data type.
  Io8   = _MemArray ("Io8",   8, CellClass = _IoBit8)
Posted by EfiPy 2018-01-13 Labels: LoLeOp

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.