~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to grub-core/term/arc/console.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-09-13 18:02:04 UTC
  • mfrom: (1.17.15 upstream)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: package-import@ubuntu.com-20120913180204-mojnmocbimlom4im
Tags: upstream-2.00
ImportĀ upstreamĀ versionĀ 2.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  GRUB  --  GRand Unified Bootloader
 
3
 *  Copyright (C) 2011  Free Software Foundation, Inc.
 
4
 *
 
5
 *  GRUB is free software: you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation, either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  GRUB is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include <grub/arc/arc.h>
 
20
#include <grub/arc/console.h>
 
21
#include <grub/term.h>
 
22
#include <grub/terminfo.h>
 
23
 
 
24
/* FIXME: use unicode.  */
 
25
 
 
26
static int
 
27
readkey (struct grub_term_input *term __attribute__ ((unused)))
 
28
{
 
29
  unsigned long count;
 
30
  char chr;
 
31
 
 
32
  if (GRUB_ARC_FIRMWARE_VECTOR->get_read_status (GRUB_ARC_STDIN))
 
33
    return -1;
 
34
 
 
35
  if (GRUB_ARC_FIRMWARE_VECTOR->read (GRUB_ARC_STDIN, &chr, 1, &count))
 
36
    return -1;
 
37
  if (!count)
 
38
    return -1;
 
39
  return chr;
 
40
}
 
41
 
 
42
static void
 
43
put (struct grub_term_output *term __attribute__ ((unused)), const int c)
 
44
{
 
45
  unsigned long count;
 
46
  char chr = c;
 
47
 
 
48
  GRUB_ARC_FIRMWARE_VECTOR->write (GRUB_ARC_STDOUT, &chr, 1, &count);
 
49
}
 
50
 
 
51
static struct grub_terminfo_output_state grub_console_terminfo_output;
 
52
 
 
53
static grub_err_t
 
54
grub_console_init_output (struct grub_term_output *term)
 
55
{
 
56
  struct grub_arc_display_status *info = NULL;
 
57
  if (GRUB_ARC_SYSTEM_PARAMETER_BLOCK->firmware_vector_length
 
58
      >= ((char *) (&GRUB_ARC_FIRMWARE_VECTOR->getdisplaystatus + 1)
 
59
          - (char *) GRUB_ARC_FIRMWARE_VECTOR)
 
60
      && GRUB_ARC_FIRMWARE_VECTOR->getdisplaystatus)
 
61
    info = GRUB_ARC_FIRMWARE_VECTOR->getdisplaystatus (GRUB_ARC_STDOUT);
 
62
  if (info)
 
63
    {
 
64
      grub_console_terminfo_output.width = info->w + 1;
 
65
      grub_console_terminfo_output.height = info->h + 1;
 
66
    }
 
67
  grub_terminfo_output_init (term);
 
68
 
 
69
  return 0;
 
70
}
 
71
 
 
72
static struct grub_terminfo_input_state grub_console_terminfo_input =
 
73
  {
 
74
    .readkey = readkey
 
75
  };
 
76
 
 
77
static struct grub_terminfo_output_state grub_console_terminfo_output =
 
78
  {
 
79
    .put = put,
 
80
    .width = 80,
 
81
    .height = 20
 
82
  };
 
83
 
 
84
static struct grub_term_input grub_console_term_input =
 
85
  {
 
86
    .name = "console",
 
87
    .init = grub_terminfo_input_init,
 
88
    .getkey = grub_terminfo_getkey,
 
89
    .data = &grub_console_terminfo_input
 
90
  };
 
91
 
 
92
static struct grub_term_output grub_console_term_output =
 
93
  {
 
94
    .name = "console",
 
95
    .init = grub_console_init_output,
 
96
    .putchar = grub_terminfo_putchar,
 
97
    .getxy = grub_terminfo_getxy,
 
98
    .getwh = grub_terminfo_getwh,
 
99
    .gotoxy = grub_terminfo_gotoxy,
 
100
    .cls = grub_terminfo_cls,
 
101
    .setcolorstate = grub_terminfo_setcolorstate,
 
102
    .setcursor = grub_terminfo_setcursor,
 
103
    .flags = GRUB_TERM_CODE_TYPE_ASCII,
 
104
    .data = &grub_console_terminfo_output,
 
105
    .normal_color = GRUB_TERM_DEFAULT_NORMAL_COLOR,
 
106
    .highlight_color = GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR,
 
107
  };
 
108
 
 
109
void
 
110
grub_console_init_early (void)
 
111
{
 
112
  grub_term_register_input ("console", &grub_console_term_input);
 
113
  grub_term_register_output ("console", &grub_console_term_output);
 
114
}
 
115
 
 
116
void
 
117
grub_console_init_lately (void)
 
118
{
 
119
  grub_terminfo_init ();
 
120
  grub_terminfo_output_register (&grub_console_term_output, "arc");
 
121
}