- Implement beginnings of Ramdisk Port Driver. Planning compatibility with ISO, SDI...
[reactos.git] / reactos / ntoskrnl / ke / arm / arm_kprintf.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/ke/arm/arm_kprintf.c
5 * PURPOSE: Early serial printf-style kernel debugging (ARM bringup)
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 /* GLOBALS ********************************************************************/
16
17 //
18 // UART Registers
19 //
20 #define UART_BASE (void*)0xe00f1000 /* HACK: freeldr mapped it here */
21
22 #define UART_PL01x_DR (UART_BASE + 0x00)
23 #define UART_PL01x_RSR (UART_BASE + 0x04)
24 #define UART_PL01x_ECR (UART_BASE + 0x04)
25 #define UART_PL01x_FR (UART_BASE + 0x18)
26 #define UART_PL011_IBRD (UART_BASE + 0x24)
27 #define UART_PL011_FBRD (UART_BASE + 0x28)
28 #define UART_PL011_LCRH (UART_BASE + 0x2C)
29 #define UART_PL011_CR (UART_BASE + 0x30)
30 #define UART_PL011_IMSC (UART_BASE + 0x38)
31
32 //
33 // LCR Values
34 //
35 #define UART_PL011_LCRH_WLEN_8 0x60
36 #define UART_PL011_LCRH_FEN 0x10
37
38 //
39 // FCR Values
40 //
41 #define UART_PL011_CR_UARTEN 0x01
42 #define UART_PL011_CR_TXE 0x100
43 #define UART_PL011_CR_RXE 0x200
44
45 //
46 // LSR Values
47 //
48 #define UART_PL01x_FR_RXFE 0x10
49 #define UART_PL01x_FR_TXFF 0x20
50
51 #define READ_REGISTER_ULONG(r) (*(volatile ULONG * const)(r))
52 #define WRITE_REGISTER_ULONG(r, v) (*(volatile ULONG *)(r) = (v))
53
54 /* FUNCTIONS ******************************************************************/
55
56 VOID
57 ArmVersaPutChar(IN INT Char)
58 {
59 //
60 // Properly support new-lines
61 //
62 if (Char == '\n') ArmVersaPutChar('\r');
63
64 //
65 // Wait for ready
66 //
67 while ((READ_REGISTER_ULONG(UART_PL01x_FR) & UART_PL01x_FR_TXFF) != 0);
68
69 //
70 // Send the character
71 //
72 WRITE_REGISTER_ULONG(UART_PL01x_DR, Char);
73 }
74
75 void arm_kprintf(const char *fmt, ...) {
76 char buf[1024], *s;
77 va_list args;
78
79 va_start(args, fmt);
80 _vsnprintf(buf,sizeof(buf),fmt,args);
81 va_end(args);
82 for (s = buf; *s; s++)
83 ArmVersaPutChar(*s);
84 }