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

Macros

#define AUX_MU_IO_REG   0x40
 
#define AUX_MU_IER_REG   0x44
 
#define AUX_MU_LCR_REG   0x4C
 
#define AUX_MU_STAT_REG   0x64
 
#define AUX_MU_IER_TXE   0x00000001
 
#define AUX_MU_IER_RXNE   0x00000002
 
#define AUX_MU_LCR_8BIT   0x00000003
 
#define AUX_MU_STAT_RXNE   0x00000001
 
#define AUX_MU_STAT_TXNF   0x00000002
 

Functions

BOOLEAN Bcm2835RxReady (_Inout_ PCPPORT Port)
 
BOOLEAN Bcm2835InitializePort (_In_opt_ _Null_terminated_ PCHAR LoadOptions, _Inout_ PCPPORT Port, BOOLEAN MemoryMapped, UCHAR AccessSize, UCHAR BitWidth)
 
BOOLEAN Bcm2835SetBaud (_Inout_ PCPPORT Port, ULONG Rate)
 
UART_STATUS Bcm2835GetByte (_Inout_ PCPPORT Port, _Out_ PUCHAR Byte)
 
UART_STATUS Bcm2835PutByte (_Inout_ PCPPORT Port, UCHAR Byte, BOOLEAN BusyWait)
 

Variables

UART_HARDWARE_DRIVER Bcm2835HardwareDriver
 

Macro Definition Documentation

◆ AUX_MU_IER_REG

#define AUX_MU_IER_REG   0x44

◆ AUX_MU_IER_RXNE

#define AUX_MU_IER_RXNE   0x00000002

◆ AUX_MU_IER_TXE

#define AUX_MU_IER_TXE   0x00000001

◆ AUX_MU_IO_REG

#define AUX_MU_IO_REG   0x40

◆ AUX_MU_LCR_8BIT

#define AUX_MU_LCR_8BIT   0x00000003

◆ AUX_MU_LCR_REG

#define AUX_MU_LCR_REG   0x4C

◆ AUX_MU_STAT_REG

#define AUX_MU_STAT_REG   0x64

◆ AUX_MU_STAT_RXNE

#define AUX_MU_STAT_RXNE   0x00000001

◆ AUX_MU_STAT_TXNF

#define AUX_MU_STAT_TXNF   0x00000002

Function Documentation

◆ Bcm2835GetByte()

UART_STATUS Bcm2835GetByte ( _Inout_ PCPPORT Port,
_Out_ PUCHAR Byte )
189{
190 ULONG Value;
191
192 if ((Port == NULL) || (Port->Address == NULL))
193 {
194 return UartNotReady;
195 }
196
197 //
198 // Check to see if a byte is available.
199 //
200
201 if (Bcm2835RxReady(Port) != FALSE)
202 {
203 //
204 // Fetch the data byte and associated error information.
205 //
206
207 Value = READ_REGISTER_ULONG((PULONG)(Port->Address + AUX_MU_IO_REG));
208
209 //
210 // Cannot check for errors as the mini UART does not provide this
211 // information.
212 //
213
214 *Byte = Value & (UCHAR)0xFF;
215 return UartSuccess;
216 }
217
218 return UartNoData;
219}
unsigned char UCHAR
Definition BasicTypes.h:35
#define FALSE
Definition BasicTypes.h:54
unsigned long ULONG
Definition BasicTypes.h:37
BOOLEAN Bcm2835RxReady(_Inout_ PCPPORT Port)
Definition bcm2835.c:290
#define AUX_MU_IO_REG
Definition bcm2835.c:22
RequestedActionOfThePacket Value(0x1) 00000000
#define READ_REGISTER_ULONG
Definition uartp.h:41

◆ Bcm2835InitializePort()

BOOLEAN Bcm2835InitializePort ( _In_opt_ _Null_terminated_ PCHAR LoadOptions,
_Inout_ PCPPORT Port,
BOOLEAN MemoryMapped,
UCHAR AccessSize,
UCHAR BitWidth )
84{
85 UNREFERENCED_PARAMETER(LoadOptions);
86 UNREFERENCED_PARAMETER(AccessSize);
87 UNREFERENCED_PARAMETER(BitWidth);
88
89 ULONG IntEnable;
90
91 if (MemoryMapped == FALSE)
92 {
93 return FALSE;
94 }
95
96 Port->Flags = 0;
97
98 //
99 // We cannot set the baud rate since we do not have the UART's clock value.
100 // Moreover with Raspberry Pi 2 and 3, the UEFI firmware sets the baud rate
101 // to 921600 bps, while BCDEdit limits it to 115200 bps.
102 //
103
104 Port->BaudRate = 0;
105
106 //
107 // Disable interrupts
108 //
109
110 IntEnable = READ_REGISTER_ULONG((PULONG)(Port->Address + AUX_MU_IER_REG));
111 IntEnable &= ~(AUX_MU_IER_TXE | AUX_MU_IER_RXNE);
112 WRITE_REGISTER_ULONG((PULONG)(Port->Address + AUX_MU_IER_REG), IntEnable);
113
114 //
115 // Set 8 bit mode
116 //
117
118 WRITE_REGISTER_ULONG((PULONG)(Port->Address + AUX_MU_LCR_REG),
120
121 //
122 // Mini UART RX/TX are always enabled!
123 //
124
125 return TRUE;
126}
#define TRUE
Definition BasicTypes.h:55
#define AUX_MU_IER_TXE
Definition bcm2835.c:27
#define AUX_MU_LCR_8BIT
Definition bcm2835.c:36
#define AUX_MU_LCR_REG
Definition bcm2835.c:24
#define AUX_MU_IER_RXNE
Definition bcm2835.c:28
#define AUX_MU_IER_REG
Definition bcm2835.c:23
#define WRITE_REGISTER_ULONG
Definition uartp.h:42

◆ Bcm2835PutByte()

UART_STATUS Bcm2835PutByte ( _Inout_ PCPPORT Port,
UCHAR Byte,
BOOLEAN BusyWait )
248{
249 ULONG StatusReg;
250
251 if ((Port == NULL) || (Port->Address == NULL))
252 {
253 return UartNotReady;
254 }
255
256 //
257 // If BusyWait is set, wait for FIFO to be not full. Otherwise, only check
258 // one time.
259 //
260
261 if (BusyWait != FALSE)
262 {
263 do
264 {
265 StatusReg =
266 READ_REGISTER_ULONG((PULONG)(Port->Address + AUX_MU_STAT_REG));
267
268 } while ((StatusReg & AUX_MU_STAT_TXNF) == 0);
269 }
270 else
271 {
272 StatusReg =
273 READ_REGISTER_ULONG((PULONG)(Port->Address + AUX_MU_STAT_REG));
274
275 if ((StatusReg & AUX_MU_STAT_TXNF) == 0)
276 {
277 return UartNotReady;
278 }
279 }
280
281 //
282 // Send the byte
283 //
284
285 WRITE_REGISTER_ULONG((PULONG)(Port->Address + AUX_MU_IO_REG), (ULONG)Byte);
286 return UartSuccess;
287}
#define AUX_MU_STAT_REG
Definition bcm2835.c:25
#define AUX_MU_STAT_TXNF
Definition bcm2835.c:39

◆ Bcm2835RxReady()

BOOLEAN Bcm2835RxReady ( _Inout_ PCPPORT Port)
309{
310 ULONG StatusReg;
311
312 if ((Port == NULL) || (Port->Address == NULL))
313 {
314 return FALSE;
315 }
316
317 //
318 // Read the Flag Register to determine if there is any pending
319 // data to read.
320 //
321
322 StatusReg = READ_REGISTER_ULONG((PULONG)(Port->Address + AUX_MU_STAT_REG));
323
324 //
325 // Check the "receive FIFO not-empty" flag. If it is set, then at least
326 // one byte is available.
327 //
328
329 if ((StatusReg & AUX_MU_STAT_RXNE) != 0)
330 {
331 return TRUE;
332 }
333
334 return FALSE;
335}
#define AUX_MU_STAT_RXNE
Definition bcm2835.c:38

◆ Bcm2835SetBaud()

BOOLEAN Bcm2835SetBaud ( _Inout_ PCPPORT Port,
ULONG Rate )
152{
153 if ((Port == NULL) || (Port->Address == NULL))
154 {
155 return FALSE;
156 }
157
158 //
159 // Remember the baud rate.
160 //
161
162 Port->BaudRate = Rate;
163 return TRUE;
164}

Variable Documentation

◆ Bcm2835HardwareDriver

UART_HARDWARE_DRIVER Bcm2835HardwareDriver
Initial value:
= {
BOOLEAN Bcm2835SetBaud(_Inout_ PCPPORT Port, ULONG Rate)
Definition bcm2835.c:129
UART_STATUS Bcm2835PutByte(_Inout_ PCPPORT Port, UCHAR Byte, BOOLEAN BusyWait)
Definition bcm2835.c:222
UART_STATUS Bcm2835GetByte(_Inout_ PCPPORT Port, _Out_ PUCHAR Byte)
Definition bcm2835.c:167
BOOLEAN Bcm2835InitializePort(_In_opt_ _Null_terminated_ PCHAR LoadOptions, _Inout_ PCPPORT Port, BOOLEAN MemoryMapped, UCHAR AccessSize, UCHAR BitWidth)
Definition bcm2835.c:50