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
24
25static char *vidmem; /* The video buffer */
27
28#define VIDBUFFER 0xB8000
29
30static 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
40static 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
56static 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
65static 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;
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) {
98 video_line--;
99 }
100 // move the cursor
103}
104
105struct console_driver vga_console __console_driver = {
106 .putchar = vga_putc,
107 .disabled = CONSOLE_DISABLED,
108 .usage = CONSOLE_DIRECT_VGA,
109};
110
111struct init_fn video_init_fn __init_fn ( INIT_EARLY ) = {
112 .name = "video",
113 .initialise = video_init,
114};
Console configuration.
#define INIT_EARLY
Early initialisation.
Definition init.h:30
User interaction.
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition console.h:112
#define __console_driver
Mark a struct console_driver as being part of the console drivers table.
Definition console.h:134
iPXE I/O API
String functions.
void * memmove(void *dest, const void *src, size_t len) __nonnull
#define __init_fn(init_order)
Declare an initialisation functon.
Definition init.h:24
uint32_t ss
Definition librm.h:1
#define LINES(...)
Define inline lines.
A console driver.
Definition console.h:56
An initialisation function.
Definition init.h:15
#define CRTC_CURSOR_HI
Definition vga.h:116
#define u16
Definition vga.h:20
#define CRTC_CURSOR_LO
Definition vga.h:117
#define write_crtc(data, addr)
Definition vga.h:30
#define COLS
Definition vga.h:27
#define VGA_ATTR_CLR_WHT
Definition vga.h:157
static void video_scroll(void)
Definition video_subr.c:56
static int video_line
Definition video_subr.c:26
#define CONSOLE_DIRECT_VGA
Definition video_subr.c:20
static void video_init(void)
Definition video_subr.c:40
static int video_col
Definition video_subr.c:26
static char * vidmem
Definition video_subr.c:25
#define VIDBUFFER
Definition video_subr.c:28
static void memsetw(void *s, int c, unsigned int n)
Definition video_subr.c:30
static void vga_putc(int byte)
Definition video_subr.c:65