1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/usr/console/daemon.C $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2014,2017 */
/* [+] Google Inc. */
/* [+] International Business Machines Corp. */
/* */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
/* You may obtain a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
/* implied. See the License for the specific language governing */
/* permissions and limitations under the License. */
/* */
/* IBM_PROLOG_END_TAG */
#include <stdio.h>
#include <sys/msg.h>
#include <sys/task.h>
#include <sys/time.h>
#include <initservice/taskargs.H>
#include <initservice/initserviceif.H>
#include "uart.H"
#include "daemon.H"
extern char hbi_ImageId[];
namespace CONSOLE
{
extern msg_q_t g_msgq;
/* Display characters one at a time from string. */
void _display(const char* str)
{
while(*str)
{
// UART uses DOS-style new lines. "\r\n"
if (*str == '\n')
{
Uart::g_device->putc('\r');
}
Uart::g_device->putc(*str);
str++;
}
}
void* consoleDaemon(void* unused)
{
// Detach and register daemon with shutdown path.
task_detach();
INITSERVICE::registerShutdownEvent(g_msgq, SYNC,
INITSERVICE::CONSOLE_PRIORITY);
// Create a default output UART device if there isn't already one.
// - Some devices are registered via the CONSOLE_UART_DEFINE_DEVICE
// macro and therefore don't need this.
if (NULL == Uart::g_device)
{
Uart::g_device = new Uart();
Uart::g_device->initialize();
}
// Display a banner denoting the hostboot version
char banner[256];
snprintf(banner, sizeof(banner),
"\n\n--== Welcome to Hostboot %s ==--\n\n",
hbi_ImageId);
_display(banner);
while(1)
{
msg_t* msg = msg_wait(g_msgq);
switch (msg->type)
{
case DISPLAY:
{
if (NULL != msg->extra_data)
{
char timestamp[11];
sprintf(timestamp, "%3d.%05d|",
msg->data[0],
// 5 Digits worth of ns.
(msg->data[1]*100000)/NS_PER_SEC);
_display(timestamp);
_display(
static_cast<const char*>(msg->extra_data));
free(msg->extra_data);
}
msg_free(msg);
break;
}
case SYNC:
{
msg_respond(g_msgq, msg);
break;
}
}
}
return NULL;
}
void consoleEntryPoint(errlHndl_t& o_errl)
{
task_create(&consoleDaemon, NULL);
}
}
TASK_ENTRY_MACRO(CONSOLE::consoleEntryPoint);
|