HyperDbg Debugger
Loading...
Searching...
No Matches
uartio.c File Reference
#include "common.h"

Macros

#define MAX_REGISTER_WIDTH   32
 

Functions

BOOLEAN UartpSetAccess (_Inout_ PCPPORT Port, const BOOLEAN MemoryMapped, const UCHAR AccessSize, const UCHAR BitWidth)
 

Macro Definition Documentation

◆ MAX_REGISTER_WIDTH

#define MAX_REGISTER_WIDTH   32

Function Documentation

◆ UartpSetAccess()

BOOLEAN UartpSetAccess ( _Inout_ PCPPORT Port,
const BOOLEAN MemoryMapped,
const UCHAR AccessSize,
const UCHAR BitWidth )
255{
256 UCHAR MinRegisterWidth;
257 BOOLEAN PowerOfTwo;
258 UART_HARDWARE_READ_INDEXED_UCHAR ReadFunction;
259 UART_HARDWARE_WRITE_INDEXED_UCHAR WriteFunction;
260
261 MinRegisterWidth = 8;
262
263 //
264 // Select the appropriate port access routines depending upon whether this
265 // serial port is mapped into memory or I/O space.
266 //
267
268 if (MemoryMapped == FALSE)
269 {
270 switch ((ACPI_GENERIC_ACCESS_SIZE)AccessSize)
271 {
272#if defined(_X86_) || defined(_AMD64_)
273
275 __fallthrough;
276
278 WriteFunction = WritePortWithIndex8;
279 ReadFunction = ReadPortWithIndex8;
280 break;
281
283 WriteFunction = WritePortWithIndex16;
284 ReadFunction = ReadPortWithIndex16;
285 MinRegisterWidth = 16;
286 break;
287
289 WriteFunction = WritePortWithIndex32;
290 ReadFunction = ReadPortWithIndex32;
291 MinRegisterWidth = 32;
292 break;
293
294 //
295 // The quad word access size isn't supported for port based I/O.
296 //
297
298#endif
299
300 default:
301 return FALSE;
302 }
303 }
304 else
305 {
306 switch ((ACPI_GENERIC_ACCESS_SIZE)AccessSize)
307 {
309 __fallthrough;
310
312 WriteFunction = WriteRegisterWithIndex8;
313 ReadFunction = ReadRegisterWithIndex8;
314 break;
315
317 WriteFunction = WriteRegisterWithIndex16;
318 ReadFunction = ReadRegisterWithIndex16;
319 MinRegisterWidth = 16;
320 break;
321
323 WriteFunction = WriteRegisterWithIndex32;
324 ReadFunction = ReadRegisterWithIndex32;
325 MinRegisterWidth = 32;
326 break;
327
328#if defined(_WIN64)
329
331 WriteFunction = WriteRegisterWithIndex64;
332 ReadFunction = ReadRegisterWithIndex64;
333 MinRegisterWidth = 64;
334 break;
335
336#endif
337
338 default:
339 return FALSE;
340 }
341 }
342
343 //
344 // Validate BitWidth parameter.
345 //
346
347 PowerOfTwo = ((BitWidth & (BitWidth - 1)) == 0);
348 if ((PowerOfTwo == FALSE) ||
349 (BitWidth < MinRegisterWidth) ||
350 (BitWidth > MAX_REGISTER_WIDTH))
351 {
352 return FALSE;
353 }
354
355 Port->ByteWidth = BitWidth / 8;
356 Port->Write = WriteFunction;
357 Port->Read = ReadFunction;
358 return TRUE;
359}
UCHAR BOOLEAN
Definition BasicTypes.h:39
unsigned char UCHAR
Definition BasicTypes.h:35
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
#define MAX_REGISTER_WIDTH
Definition uartio.c:32
enum _ACPI_GENERIC_ACCESS_SIZE ACPI_GENERIC_ACCESS_SIZE
@ AcpiGenericAccessSizeByte
Definition uartp.h:51
@ AcpiGenericAccessSizeLegacy
Definition uartp.h:50
@ AcpiGenericAccessSizeWord
Definition uartp.h:52
@ AcpiGenericAccessSizeQWord
Definition uartp.h:54
@ AcpiGenericAccessSizeDWord
Definition uartp.h:53