summaryrefslogtreecommitdiff
path: root/viengoos/output.h
blob: 6e74b767bee07f00873443a8566ea888aeefebdd (plain)
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
/* output.h - Output routines interfaces.
   Copyright (C) 2003, 2007 Free Software Foundation, Inc.
   Written by Marcus Brinkmann.

   This file is part of the GNU Hurd.

   The GNU Hurd is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   The GNU Hurd is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. */

#ifndef _OUTPUT_H
#define _OUTPUT_H	1

#include <stdint.h>
#include <stdbool.h>

/* Every architecture must define at least one output driver, but might
   define several.  For each output driver, the name and operations on
   the driver must be provided in the following structure.  */

struct output_driver
{
  const char *name;

  /* Initialize the output device.  */
  void (*init) (struct output_driver *device, const char *cfg);

  /* Deinitialize the output device.  */
  void (*deinit) (struct output_driver *device);

  /* Output a character.  */
  void (*putchar) (struct output_driver *device, int chr);

  /* Read a character.  */
  int (*getchar) (struct output_driver *device);

  uintptr_t cookie;
};


/* Every architecture must provide a list of all output drivers,
   terminated by a driver structure which has a null pointer as its
   name.  */
extern struct output_driver *output_drivers[];


#include <stdarg.h>

/* Activate the output device described by CONF.  CONF has the pattern
   NAME[,CONFIG...], for example "serial,uart2,speed=9600".  If CONF
   is NULL, then the default device is used.  Store the device
   instance in * the storage designated by *DEVICE.  If MAKE_DEFAULT
   is true, on success device configuration, make the device the
   default i/o device.  If there is already a default i/o device, that
   driver is first deinitialized.  Returns false if DRIVER is not a
   valid output driver specification, otherwise true on success.  */
bool output_init (struct output_driver *device, const char *conf,
		  bool make_default);


/* Deactivate the output driver.  Must be called after the last time
   putchar or any other output routine is called.  */
void output_deinit (struct output_driver *device);

#include <s-printf.h>

/* Print the single character CHR on the device DEVICE.  */
int device_putchar (struct output_driver *device, int chr);

/* Read a single character from the device DEVICE.  */
int device_getchar (struct output_driver *device);

int putchar (int chr);
int puts (const char *str);
int vprintf (const char *fmt, va_list ap);
int printf (const char *fmt, ...);

int getchar (void);

#endif	/* _OUTPUT_H */