Fix bootmaker for amd64
[newos.git] / boot / sh4 / serial.c
blob289c5196ba4fd3a7792cbb0ddd496648402769db
1 /*
2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
5 #include <boot/stage2.h>
6 #include <stdio.h>
7 #include "serial.h"
9 int dprintf(const char *fmt, ...)
11 int ret = 0;
12 va_list args;
13 char temp[128];
15 va_start(args, fmt);
16 ret = vsprintf(temp, fmt, args);
17 va_end(args);
19 serial_puts(temp);
20 return ret;
23 int serial_init()
25 volatile unsigned short *scif16 = (unsigned short*)0xffe80000;
26 volatile unsigned char *scif8 = (unsigned char*)0xffe80000;
27 int x;
29 /* Disable interrupts, transmit/receive, and use internal clock */
30 scif16[8/2] = 0;
32 /* 8N1, use P0 clock */
33 scif16[0] = 0;
35 /* Set baudrate, N = P0/(32*B)-1 */
36 // scif8[4] = (50000000 / (32 * baud_rate)) - 1;
38 // scif8[4] = 80; // 19200
39 // scif8[4] = 40; // 38400
40 // scif8[4] = 26; // 57600
41 scif8[4] = 13; // 115200
43 /* Reset FIFOs, enable hardware flow control */
44 scif16[24/2] = 4; //12;
46 for(x = 0; x < 100000; x++);
47 scif16[24/2] = 0; //8;
49 /* Disable manual pin control */
50 scif16[32/2] = 0;
52 /* Clear status */
53 scif16[16/2] = 0x60;
54 scif16[36/2] = 0;
56 /* Enable transmit/receive */
57 scif16[8/2] = 0x30;
59 for(x = 0; x < 100000; x++);
61 serial_puts("serial initted\n");
63 return 0;
66 /* Flush all FIFO'd bytes out of the serial port buffer */
67 static void serial_flush() {
68 volatile unsigned short *ack = (unsigned short*)0xffe80010;
70 *ack &= 0xbf;
71 while (!(*ack & 0x40))
73 *ack &= 0xbf;
76 static void _serial_putch(const char c)
78 volatile unsigned short *ack = (unsigned short*)0xffe80010;
79 volatile unsigned char *fifo = (unsigned char*)0xffe8000c;
81 /* Wait until the transmit buffer has space */
82 while (!(*ack & 0x20))
84 /* Send the char */
85 *fifo = c;
87 /* Clear status */
88 *ack &= 0x9f;
91 char serial_putch(const char c)
93 if (c == '\n') {
94 _serial_putch('\r');
95 _serial_putch('\n');
96 } else if (c != '\r')
97 _serial_putch(c);
99 return c;
102 void serial_puts(const char *s)
104 while(*s != '\0') {
105 serial_putch(*s);
106 s++;