|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# Cross Platform and Multi Architecture Advanced Binary Emulation Framework |
| 4 | +# |
| 5 | + |
| 6 | +import ctypes |
| 7 | + |
| 8 | +from qiling.core import Qiling |
| 9 | +from qiling.hw.peripheral import QlPeripheral |
| 10 | + |
| 11 | + |
| 12 | +class STM32F4xxSdio(QlPeripheral): |
| 13 | + class Type(ctypes.Structure): |
| 14 | + """ the structure available in : |
| 15 | + stm32f401xc |
| 16 | + stm32f401xe |
| 17 | + stm32f405xx |
| 18 | + stm32f407xx |
| 19 | + stm32f411xe |
| 20 | + stm32f412cx |
| 21 | + stm32f412rx |
| 22 | + stm32f412vx |
| 23 | + stm32f412zx |
| 24 | + stm32f413xx |
| 25 | + stm32f415xx |
| 26 | + stm32f417xx |
| 27 | + stm32f423xx |
| 28 | + stm32f427xx |
| 29 | + stm32f429xx |
| 30 | + stm32f437xx |
| 31 | + stm32f439xx |
| 32 | + stm32f446xx |
| 33 | + stm32f469xx |
| 34 | + stm32f479xx |
| 35 | + """ |
| 36 | + |
| 37 | + _fields_ = [ |
| 38 | + ("POWER" , ctypes.c_uint32), #SDIO power control register, Address offset: 0x00 |
| 39 | + ("CLKCR" , ctypes.c_uint32), #SDI clock control register, Address offset: 0x04 |
| 40 | + ("ARG" , ctypes.c_uint32), #SDIO argument register, Address offset: 0x08 |
| 41 | + ("CMD" , ctypes.c_uint32), #SDIO command register, Address offset: 0x0C |
| 42 | + ("RESPCMD" , ctypes.c_uint32), #SDIO command response register, Address offset: 0x10 |
| 43 | + ("RESP1" , ctypes.c_uint32), #SDIO response 1 register, Address offset: 0x14 |
| 44 | + ("RESP2" , ctypes.c_uint32), #SDIO response 2 register, Address offset: 0x18 |
| 45 | + ("RESP3" , ctypes.c_uint32), #SDIO response 3 register, Address offset: 0x1C |
| 46 | + ("RESP4" , ctypes.c_uint32), #SDIO response 4 register, Address offset: 0x20 |
| 47 | + ("DTIMER" , ctypes.c_uint32), #SDIO data timer register, Address offset: 0x24 |
| 48 | + ("DLEN" , ctypes.c_uint32), #SDIO data length register, Address offset: 0x28 |
| 49 | + ("DCTRL" , ctypes.c_uint32), #SDIO data control register, Address offset: 0x2C |
| 50 | + ("DCOUNT" , ctypes.c_uint32), #SDIO data counter register, Address offset: 0x30 |
| 51 | + ("STA" , ctypes.c_uint32), #SDIO status register, Address offset: 0x34 |
| 52 | + ("ICR" , ctypes.c_uint32), #SDIO interrupt clear register, Address offset: 0x38 |
| 53 | + ("MASK" , ctypes.c_uint32), #SDIO mask register, Address offset: 0x3C |
| 54 | + ("RESERVED0", ctypes.c_uint32 * 2), #Reserved, 0x40-0x44 |
| 55 | + ("FIFOCNT" , ctypes.c_uint32), #SDIO FIFO counter register, Address offset: 0x48 |
| 56 | + ("RESERVED1", ctypes.c_uint32 * 13), #Reserved, 0x4C-0x7C |
| 57 | + ("FIFO" , ctypes.c_uint32), #SDIO data FIFO register, Address offset: 0x80 |
| 58 | + ] |
| 59 | + |
| 60 | + def __init__(self, ql: Qiling, label: str): |
| 61 | + super().__init__(ql, label) |
| 62 | + |
| 63 | + self.sdio = self.struct() |
| 64 | + |
| 65 | + @QlPeripheral.monitor() |
| 66 | + def read(self, offset: int, size: int) -> int: |
| 67 | + buf = ctypes.create_string_buffer(size) |
| 68 | + ctypes.memmove(buf, ctypes.addressof(self.sdio) + offset, size) |
| 69 | + return int.from_bytes(buf.raw, byteorder='little') |
| 70 | + |
| 71 | + @QlPeripheral.monitor() |
| 72 | + def write(self, offset: int, size: int, value: int): |
| 73 | + data = (value).to_bytes(size, 'little') |
| 74 | + ctypes.memmove(ctypes.addressof(self.sdio) + offset, data, size) |
0 commit comments