iPXE
video_subr.c
Go to the documentation of this file.
1 /*
2  *
3  * modified from linuxbios code
4  * by Cai Qiang <rimy2000@hotmail.com>
5  *
6  */
7 
8 #include "stddef.h"
9 #include "string.h"
10 #include <ipxe/io.h>
11 #include <ipxe/console.h>
12 #include <ipxe/init.h>
13 #include "vga.h"
14 #include <config/console.h>
15 
16 /* Set default console usage if applicable */
17 #if ! ( defined ( CONSOLE_DIRECT_VGA ) && \
18  CONSOLE_EXPLICIT ( CONSOLE_DIRECT_VGA ) )
19 #undef CONSOLE_DIRECT_VGA
20 #define CONSOLE_DIRECT_VGA ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )
21 #endif
22 
23 struct console_driver vga_console __console_driver;
24 
25 static char *vidmem; /* The video buffer */
26 static int video_line, video_col;
27 
28 #define VIDBUFFER 0xB8000
29 
30 static void memsetw(void *s, int c, unsigned int n)
31 {
32  unsigned int i;
33  u16 *ss = (u16 *) s;
34 
35  for (i = 0; i < n; i++) {
36  ss[i] = ( u16 ) c;
37  }
38 }
39 
40 static void video_init(void)
41 {
42  static int inited=0;
43 
44  vidmem = (char *)phys_to_virt(VIDBUFFER);
45 
46  if (!inited) {
47  video_line = 0;
48  video_col = 0;
49 
50  memsetw(vidmem, VGA_ATTR_CLR_WHT, 2*1024); //
51 
52  inited=1;
53  }
54 }
55 
56 static void video_scroll(void)
57 {
58  int i;
59 
60  memmove(vidmem, vidmem + COLS * 2, (LINES - 1) * COLS * 2);
61  for (i = (LINES - 1) * COLS * 2; i < LINES * COLS * 2; i += 2)
62  vidmem[i] = ' ';
63 }
64 
65 static void vga_putc(int byte)
66 {
67  if (byte == '\n') {
68  video_line++;
69  video_col = 0;
70 
71  } else if (byte == '\r') {
72  video_col = 0;
73 
74  } else if (byte == '\b') {
75  video_col--;
76 
77  } else if (byte == '\t') {
78  video_col += 4;
79 
80  } else if (byte == '\a') {
81  //beep
82  //beep(500);
83 
84  } else {
85  vidmem[((video_col + (video_line *COLS)) * 2)] = byte;
86  vidmem[((video_col + (video_line *COLS)) * 2) +1] = VGA_ATTR_CLR_WHT;
87  video_col++;
88  }
89  if (video_col < 0) {
90  video_col = 0;
91  }
92  if (video_col >= COLS) {
93  video_line++;
94  video_col = 0;
95  }
96  if (video_line >= LINES) {
97  video_scroll();
98  video_line--;
99  }
100  // move the cursor
103 }
104 
105 struct console_driver vga_console __console_driver = {
106  .putchar = vga_putc,
107  .disabled = CONSOLE_DISABLED,
108  .usage = CONSOLE_DIRECT_VGA,
109 };
110 
111 struct init_fn video_init_fn __init_fn ( INIT_EARLY ) = {
113 };
#define u16
Definition: vga.h:20
uint16_t u16
Definition: stdint.h:21
static int video_col
Definition: video_subr.c:26
uint32_t c
Definition: md4.c:30
#define write_crtc(data, addr)
Definition: vga.h:30
static int video_line
Definition: video_subr.c:26
iPXE I/O API
void(* initialise)(void)
Definition: init.h:15
#define INIT_EARLY
Early initialisation.
Definition: init.h:28
struct init_fn video_init_fn __init_fn(INIT_EARLY)
static void memsetw(void *s, int c, unsigned int n)
Definition: video_subr.c:30
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
static void vga_putc(int byte)
Definition: video_subr.c:65
#define LINES(...)
Define inline lines.
Definition: linebuf_test.c:44
static __always_inline void * phys_to_virt(unsigned long phys_addr)
Convert physical address to a virtual address.
Definition: uaccess.h:299
#define VGA_ATTR_CLR_WHT
Definition: vga.h:157
An initialisation function.
Definition: init.h:14
void(* putchar)(int character)
Write a character to the console.
Definition: console.h:68
#define CRTC_CURSOR_HI
Definition: vga.h:116
static char * vidmem
Definition: video_subr.c:25
User interaction.
uint32_t ss
Definition: librm.h:250
#define COLS
Definition: curses.h:111
Console configuration.
void * memmove(void *dest, const void *src, size_t len) __nonnull
static void video_init(void)
Definition: video_subr.c:40
#define CONSOLE_DIRECT_VGA
Definition: video_subr.c:20
struct console_driver vga_console __console_driver
Definition: video_subr.c:23
#define VIDBUFFER
Definition: video_subr.c:28
static void video_scroll(void)
Definition: video_subr.c:56
unsigned int n
Definition: entropy.h:159
A console driver.
Definition: console.h:55
String functions.
#define CRTC_CURSOR_LO
Definition: vga.h:117