Loading [MathJax]/jax/input/TeX/config.js
CS350 COS
COS
All Data Structures Files Functions Variables Typedefs Macros
vgacons.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/kdebug.h>
#include <machine/amd64.h>
#include <machine/pmap.h>
#include "vgacons.h"
Include dependency graph for vgacons.c:

Go to the source code of this file.

Macros

#define VGA_BASE   0x370
 
#define VGA_ATC_INDEX   0x00 + VGA_BASE
 
#define VGA_ATC_DATA   0x01 + VGA_BASE
 
#define VGA_SEQ_INDEX   0x02 + VGA_BASE
 
#define VGA_SEQ_DATA   0x05 + VGA_BASE
 
#define VGA_PAL_RADDR   0x07 + VGA_BASE
 
#define VGA_PAL_WADDR   0x08 + VGA_BASE
 
#define VGA_PAL_DATA   0x09 + VGA_BASE
 
#define VGA_GDC_INDEX   0x0E + VGA_BASE
 
#define VGA_GDC_DATA   0x0F + VGA_BASE
 

Functions

void LockDisplay (void)
 
void UnlockDisplay (void)
 
void EnterFontMode (void)
 
void ExitFontMode (void)
 
void VGA_Init (void)
 
void VGA_LateInit (void)
 
void VGA_ScrollDisplay (void)
 
void VGA_Putc (short c)
 
void VGA_Puts (const char *str)
 
void Panic (const char *str)
 

Variables

static short * VideoBuffer = (short *)(0x000B8000 + MEM_DIRECTMAP_BASE)
 
static int CurrentX = 0
 
static int CurrentY = 0
 
static int SizeX = 80
 
static int SizeY = 25
 
static unsigned char TextAttribute = 0x70
 
static uint8_t ModeBuffer [6]
 

Macro Definition Documentation

◆ VGA_ATC_DATA

#define VGA_ATC_DATA   0x01 + VGA_BASE

Definition at line 26 of file vgacons.c.

◆ VGA_ATC_INDEX

#define VGA_ATC_INDEX   0x00 + VGA_BASE

Definition at line 25 of file vgacons.c.

◆ VGA_BASE

#define VGA_BASE   0x370

Definition at line 23 of file vgacons.c.

◆ VGA_GDC_DATA

#define VGA_GDC_DATA   0x0F + VGA_BASE

Definition at line 33 of file vgacons.c.

◆ VGA_GDC_INDEX

#define VGA_GDC_INDEX   0x0E + VGA_BASE

Definition at line 32 of file vgacons.c.

◆ VGA_PAL_DATA

#define VGA_PAL_DATA   0x09 + VGA_BASE

Definition at line 31 of file vgacons.c.

◆ VGA_PAL_RADDR

#define VGA_PAL_RADDR   0x07 + VGA_BASE

Definition at line 29 of file vgacons.c.

◆ VGA_PAL_WADDR

#define VGA_PAL_WADDR   0x08 + VGA_BASE

Definition at line 30 of file vgacons.c.

◆ VGA_SEQ_DATA

#define VGA_SEQ_DATA   0x05 + VGA_BASE

Definition at line 28 of file vgacons.c.

◆ VGA_SEQ_INDEX

#define VGA_SEQ_INDEX   0x02 + VGA_BASE

Definition at line 27 of file vgacons.c.

Function Documentation

◆ EnterFontMode()

void EnterFontMode ( void  )

Definition at line 45 of file vgacons.c.

46{
47 // Save VGA State
48 outb(VGA_SEQ_INDEX,0x02);
50
51 outb(VGA_SEQ_INDEX,0x04);
53
54 outb(VGA_GDC_INDEX,0x04);
56
57 outb(VGA_GDC_INDEX,0x05);
59
60 outb(VGA_GDC_INDEX,0x06);
62
63 outb(VGA_ATC_INDEX,0x10);
65
66 // Setup Font Mode
67}
static INLINE uint8_t inb(uint16_t port)
Definition: amd64op.h:452
static INLINE void outb(uint16_t port, uint8_t data)
Definition: amd64op.h:431
#define VGA_SEQ_DATA
Definition: vgacons.c:28
#define VGA_SEQ_INDEX
Definition: vgacons.c:27
#define VGA_GDC_DATA
Definition: vgacons.c:33
static uint8_t ModeBuffer[6]
Definition: vgacons.c:35
#define VGA_ATC_INDEX
Definition: vgacons.c:25
#define VGA_GDC_INDEX
Definition: vgacons.c:32
#define VGA_ATC_DATA
Definition: vgacons.c:26
Here is the call graph for this function:

◆ ExitFontMode()

void ExitFontMode ( void  )

Definition at line 69 of file vgacons.c.

70{
71 // Restore VGA State
72}

◆ LockDisplay()

void LockDisplay ( void  )

Definition at line 37 of file vgacons.c.

38{
39}

◆ Panic()

void Panic ( const char *  str)

Definition at line 164 of file vgacons.c.

165{
166 VGA_Puts(str);
167 __asm__("int3");
168 while (1)
169 {
170 __asm__("hlt");
171 }
172}
void VGA_Puts(const char *str)
Definition: vgacons.c:157
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnlockDisplay()

void UnlockDisplay ( void  )

Definition at line 41 of file vgacons.c.

42{
43}

◆ VGA_Init()

void VGA_Init ( void  )

Definition at line 75 of file vgacons.c.

76{
77 int i = 0;
78
79 for (i = 0;i < SizeX * SizeY;i++)
80 {
81 VideoBuffer[i] = (TextAttribute << 8) | ' ';
82 }
83
84 CurrentX = 0;
85 CurrentY = 0;
86
87 /*
88 * At initialization the video memory is located at 0xB8000.
89 * We will map the memory after memory management has been
90 * initialized.
91 */
92}
static short * VideoBuffer
Definition: vgacons.c:16
static int CurrentY
Definition: vgacons.c:18
static int SizeY
Definition: vgacons.c:20
static unsigned char TextAttribute
Definition: vgacons.c:21
static int SizeX
Definition: vgacons.c:19
static int CurrentX
Definition: vgacons.c:17
Here is the caller graph for this function:

◆ VGA_LateInit()

void VGA_LateInit ( void  )

Definition at line 94 of file vgacons.c.

95{
96 // Map in video memory
97 // Set VideoBuffer pointer
98}

◆ VGA_Putc()

void VGA_Putc ( short  c)

Definition at line 115 of file vgacons.c.

116{
117 c |= (TextAttribute << 8);
118 switch (c & 0xFF)
119 {
120 case '\b':
121 if (CurrentX > 0) {
122 CurrentX--;
123 VideoBuffer[CurrentX + CurrentY * SizeX] = 0x20 | (TextAttribute << 8);
124 }
125 break;
126 case '\n':
127 if (CurrentY >= (SizeY - 1)) {
129 } else {
130 CurrentY++;
131 }
132 CurrentX = 0;
133 break;
134 case '\r':
135 break;
136 case '\t':
137 VGA_Putc(' ');
138 VGA_Putc(' ');
139 VGA_Putc(' ');
140 VGA_Putc(' ');
141 break;
142 default:
144 CurrentX++;
145 if (CurrentX == SizeX) {
146 if (CurrentY >= (SizeY - 1)) {
148 } else {
149 CurrentY++;
150 }
151 CurrentX = 0;
152 }
153 break;
154 }
155}
void VGA_ScrollDisplay(void)
Definition: vgacons.c:100
void VGA_Putc(short c)
Definition: vgacons.c:115
Here is the call graph for this function:
Here is the caller graph for this function:

◆ VGA_Puts()

void VGA_Puts ( const char *  str)

Definition at line 157 of file vgacons.c.

158{
159 const char *p = str;
160 while (*p != '\0')
161 VGA_Putc(*p++);
162}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ VGA_ScrollDisplay()

void VGA_ScrollDisplay ( void  )

Definition at line 100 of file vgacons.c.

101{
102 int i,j;
103 for (i = 1; i < SizeY; i++)
104 {
105 for (j = 0; j < SizeX; j++)
106 {
107 VideoBuffer[(i-1)*SizeX+j] = VideoBuffer[i*SizeX+j];
108 }
109 }
110 for (j = 0; j < SizeX; j++)
111 VideoBuffer[(SizeY-1)*SizeX+j] = (TextAttribute << 8) | ' ';
112 return;
113}
Here is the caller graph for this function:

Variable Documentation

◆ CurrentX

int CurrentX = 0
static

Definition at line 17 of file vgacons.c.

◆ CurrentY

int CurrentY = 0
static

Definition at line 18 of file vgacons.c.

◆ ModeBuffer

uint8_t ModeBuffer[6]
static

Definition at line 35 of file vgacons.c.

◆ SizeX

int SizeX = 80
static

Definition at line 19 of file vgacons.c.

◆ SizeY

int SizeY = 25
static

Definition at line 20 of file vgacons.c.

◆ TextAttribute

unsigned char TextAttribute = 0x70
static

Definition at line 21 of file vgacons.c.

◆ VideoBuffer

short* VideoBuffer = (short *)(0x000B8000 + MEM_DIRECTMAP_BASE)
static

Definition at line 16 of file vgacons.c.