ReactOS  0.4.14-dev-552-g2fad488
font.c
Go to the documentation of this file.
1 /*
2 * PROJECT: ReactOS Setup Driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/setup/blue/font.c
5 * PURPOSE: Loading specific fonts into VGA
6 * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
7 * Colin Finck (mail@colinfinck.de)
8 * Christoph von Wittich (christoph_vw@reactos.org)
9 */
10 
11 /* INCLUDES ***************************************************************/
12 
13 #include "blue.h"
14 
15 #include <ntddk.h>
16 
17 #define NDEBUG
18 #include <debug.h>
19 
22 VOID LoadFont(PUCHAR Bitplane, PUCHAR FontBitfield);
23 
24 /* FUNCTIONS ****************************************************************/
25 
26 VOID
28  UINT32 CodePage)
29 {
31  PUCHAR Bitplane;
32  PUCHAR FontBitfield = NULL;
34 
35  FontBitfield = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, 2048, TAG_BLUE);
36  if (FontBitfield == NULL)
37  {
38  DPRINT1("ExAllocatePoolWithTag failed\n");
39  return;
40  }
41 
42  /* open bit plane for font table access */
43  OpenBitPlane();
44 
45  /* get pointer to video memory */
46  BaseAddress.QuadPart = BITPLANE_BASE;
47  Bitplane = (PUCHAR)MmMapIoSpace(BaseAddress, 0xFFFF, MmNonCached);
48 
49  Status = ExtractFont(CodePage, FontBitfield);
50  if (NT_SUCCESS(Status))
51  {
52  LoadFont(Bitplane, FontBitfield);
53  }
54  else
55  {
56  DPRINT1("ExtractFont failed with Status 0x%lx\n", Status);
57  }
58 
59  MmUnmapIoSpace(Bitplane, 0xFFFF);
60  ExFreePool(FontBitfield);
61 
62  /* close bit plane */
63  CloseBitPlane();
64 }
65 
66 /* PRIVATE FUNCTIONS *********************************************************/
67 
70  UINT32 CodePage,
71  PUCHAR FontBitField)
72 {
73  BOOLEAN bFoundFile = FALSE;
74  HANDLE Handle;
76  CHAR FileName[20];
79  UNICODE_STRING LinkName;
81  CFHEADER CabFileHeader;
82  CFFILE CabFile;
83  ULONG CabFileOffset = 0;
85  WCHAR SourceBuffer[MAX_PATH] = { L'\0' };
86  ULONG ReadCP;
87 
90 
91  RtlInitUnicodeString(&LinkName,
92  L"\\SystemRoot");
93 
95  &LinkName,
97  NULL,
98  NULL);
99 
103 
104  if (!NT_SUCCESS(Status))
105  {
106  DPRINT1("ZwOpenSymbolicLinkObject failed with Status 0x%lx\n", Status);
107  return Status;
108  }
109 
110  SourceName.Length = 0;
111  SourceName.MaximumLength = MAX_PATH * sizeof(WCHAR);
112  SourceName.Buffer = SourceBuffer;
113 
114  Status = ZwQuerySymbolicLinkObject(Handle,
115  &SourceName,
116  NULL);
117  ZwClose(Handle);
118 
119  if (!NT_SUCCESS(Status))
120  {
121  DPRINT1("ZwQuerySymbolicLinkObject failed with Status 0x%lx\n", Status);
122  return Status;
123  }
124 
125  Status = RtlAppendUnicodeToString(&SourceName, L"\\vgafonts.cab");
126  if (!NT_SUCCESS(Status))
127  {
128  DPRINT1("RtlAppendUnicodeToString failed with Status 0x%lx\n", Status);
129  return Status;
130  }
131 
133  &SourceName,
135  NULL,
136  NULL);
137 
138  Status = ZwCreateFile(&Handle,
139  GENERIC_READ,
141  &IoStatusBlock,
142  NULL,
144  0,
145  FILE_OPEN,
147  NULL,
148  0);
149  if (!NT_SUCCESS(Status))
150  {
151  DPRINT1("Error: Cannot open vgafonts.cab (0x%lx)\n", Status);
152  return Status;
153  }
154 
155  ByteOffset.QuadPart = 0;
156  Status = ZwReadFile(Handle,
157  NULL,
158  NULL,
159  NULL,
160  &IoStatusBlock,
161  &CabFileHeader,
162  sizeof(CabFileHeader),
163  &ByteOffset,
164  NULL);
165 
166  if (!NT_SUCCESS(Status))
167  {
168  DPRINT1("Error: Cannot read from file (0x%lx)\n", Status);
169  goto Exit;
170  }
171 
172  if (CabFileHeader.Signature != CAB_SIGNATURE)
173  {
174  DPRINT1("Invalid CAB signature: 0x%lx!\n", CabFileHeader.Signature);
176  goto Exit;
177  }
178 
179  // We have a valid CAB file!
180  // Read the file table now and decrement the file count on every file. When it's zero, we read the complete table.
181  ByteOffset.QuadPart = CabFileHeader.FileTableOffset;
182 
183  while (CabFileHeader.FileCount)
184  {
185  Status = ZwReadFile(Handle,
186  NULL,
187  NULL,
188  NULL,
189  &IoStatusBlock,
190  &CabFile,
191  sizeof(CabFile),
192  &ByteOffset,
193  NULL);
194 
195  if (NT_SUCCESS(Status))
196  {
197  ByteOffset.QuadPart += sizeof(CabFile);
198 
199  // We assume here that the file name is max. 19 characters (+ 1 NULL character) long.
200  // This should be enough for our purpose.
201  Status = ZwReadFile(Handle,
202  NULL,
203  NULL,
204  NULL,
205  &IoStatusBlock,
206  FileName,
207  sizeof(FileName),
208  &ByteOffset,
209  NULL);
210 
211  if (NT_SUCCESS(Status))
212  {
213  if (!bFoundFile)
214  {
215  Status = RtlCharToInteger(FileName, 0, &ReadCP);
216  if (NT_SUCCESS(Status) && ReadCP == CodePage)
217  {
218  // We got the correct file.
219  // Save the offset and loop through the rest of the file table to find the position, where the actual data starts.
220  CabFileOffset = CabFile.FileOffset;
221  bFoundFile = TRUE;
222  }
223  }
224 
225  ByteOffset.QuadPart += strlen(FileName) + 1;
226  }
227  }
228 
229  CabFileHeader.FileCount--;
230  }
231 
232  // 8 = Size of a CFFOLDER structure (see cabman). As we don't need the values of that structure, just increase the offset here.
233  ByteOffset.QuadPart += 8;
234  ByteOffset.QuadPart += CabFileOffset;
235 
236  // ByteOffset now contains the offset of the actual data, so we can read the RAW font
237  Status = ZwReadFile(Handle,
238  NULL,
239  NULL,
240  NULL,
241  &IoStatusBlock,
242  FontBitField,
243  2048,
244  &ByteOffset,
245  NULL);
246  if (!NT_SUCCESS(Status))
247  {
248  DPRINT1("ZwReadFile failed with Status 0x%lx\n", Status);
249  }
250 
251 Exit:
252 
253  ZwClose(Handle);
254  return Status;
255 }
256 
257 /* Font-load specific funcs */
258 VOID
260 {
261  /* disable interrupts */
262  _disable();
263 
264  /* sequence reg */
269 
270  /* graphic reg */
274 
275  /* enable interrupts */
276  _enable();
277 }
278 
279 VOID
281 {
282  /* disable interrupts */
283  _disable();
284 
285  /* sequence reg */
290 
291  /* graphic reg */
295 
296  /* enable interrupts */
297  _enable();
298 }
299 
300 VOID
302  PUCHAR Bitplane,
303  PUCHAR FontBitfield)
304 {
305  UINT32 i, j;
306 
307  for (i = 0; i < 256; i++)
308  {
309  for (j = 0; j < 8; j++)
310  {
311  *Bitplane = FontBitfield[i * 8 + j];
312  Bitplane++;
313  }
314 
315  // padding
316  for (j = 8; j < 32; j++)
317  {
318  *Bitplane = 0;
319  Bitplane++;
320  }
321  }
322 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSYSAPI NTSTATUS NTAPI RtlCharToInteger(PCSZ String, ULONG Base, PULONG Value)
Definition: unicode.c:261
#define TRUE
Definition: types.h:120
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
unsigned char * PUCHAR
Definition: retypes.h:3
char CHAR
Definition: xmlstorage.h:175
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define SEQ_COMMAND
Definition: blue.h:96
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS ExtractFont(UINT32 CodePage, PUCHAR FontBitField)
Definition: font.c:69
#define SEQ_DATA
Definition: blue.h:97
#define SEQ_MEM_MODE
Definition: blue.h:105
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT32
#define SEQ_ENABLE_WRT_PLANE
Definition: blue.h:104
VOID LoadFont(PUCHAR Bitplane, PUCHAR FontBitfield)
Definition: font.c:301
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define TAG_BLUE
Definition: blue.h:50
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
_In_ HANDLE Handle
Definition: extypes.h:390
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define SEQ_RESET
Definition: blue.h:103
#define GCT_DATA
Definition: blue.h:100
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static void Exit(void)
Definition: sock.c:1331
#define MAX_PATH
Definition: compat.h:26
Definition: fci.c:89
#define CAB_SIGNATURE
Definition: cabinet.c:47
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:124
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define GCT_RW_MODES
Definition: blue.h:109
VOID ScrLoadFontTable(UINT32 CodePage)
Definition: font.c:27
#define BITPLANE_BASE
Definition: blue.h:82
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
#define GCT_GRAPH_MODE
Definition: blue.h:110
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:193
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
WCHAR SourceName[256]
Definition: arping.c:28
Definition: fci.c:65
VOID OpenBitPlane()
#define DPRINT1
Definition: precomp.h:8
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
void __cdecl _disable(void)
Definition: intrin_arm.h:365
VOID CloseBitPlane()
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:532
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define GCT_COMMAND
Definition: blue.h:99
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define GCT_READ_PLANE
Definition: blue.h:108
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSYSAPI NTSTATUS NTAPI ZwOpenSymbolicLinkObject(_Out_ PHANDLE SymbolicLinkHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:716