VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TestPrintf.c@ 60302

Last change on this file since 60302 was 60291, checked in by vboxsync, 9 years ago

bs3kit: A bunch of changes to be able to test the effects of a GDT page being read-only or not-present.

  • Extended the GDT so we get a whole page to play paging tricks with.
  • Added syscall for restoring a context from ring-0 so we can safely get out of bogus test context that aren't in ring-0 (non-standard CS value causing trouble here). Implemented the string print syscall since the restore syscall forced me to sort out pointers.
  • Changed most string printers to do more than one char at a time (usually a line) to save context switches (screen priting is done via INT 10h in real mode).
  • Test the CS access bit handling during INT XXh.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1/* $Id: bs3-cmn-TestPrintf.c 60291 2016-04-01 20:51:29Z vboxsync $ */
2/** @file
3 * BS3Kit - BS3TestPrintf, BS3TestPrintfV
4 */
5
6/*
7 * Copyright (C) 2007-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "bs3kit-template-header.h"
32#include "bs3-cmn-test.h"
33
34#include <iprt/asm-amd64-x86.h>
35
36
37/*********************************************************************************************************************************
38* Structures and Typedefs *
39*********************************************************************************************************************************/
40/** Output buffering for Bs3TestPrintfV. */
41typedef struct BS3TESTPRINTBUF
42{
43 bool fNewCmd;
44 uint8_t cchBuf;
45 char achBuf[78];
46} BS3TESTPRINTBUF;
47
48
49/**
50 * @impl_callback_method{FNBS3STRFORMATOUTPUT, Prints to screen and VMMDev}
51 */
52static BS3_DECL_CALLBACK(size_t) bs3TestPrintfStrOutput(char ch, void BS3_FAR *pvUser)
53{
54 BS3TESTPRINTBUF BS3_FAR *pBuf = (BS3TESTPRINTBUF BS3_FAR *)pvUser;
55
56 /*
57 * VMMDev first. We do line by line processing to avoid running out of
58 * string buffer on the host side.
59 */
60 if (BS3_DATA_NM(g_fbBs3VMMDevTesting))
61 {
62 if (ch != '\n' && !pBuf->fNewCmd)
63 ASMOutU8(VMMDEV_TESTING_IOPORT_DATA, ch);
64 else if (ch != '\0')
65 {
66 if (pBuf->fNewCmd)
67 {
68 ASMOutU32(VMMDEV_TESTING_IOPORT_CMD, VMMDEV_TESTING_CMD_PRINT);
69 pBuf->fNewCmd = false;
70 }
71 ASMOutU8(VMMDEV_TESTING_IOPORT_DATA, ch);
72 if (ch == '\n')
73 {
74 ASMOutU8(VMMDEV_TESTING_IOPORT_DATA, '\0');
75 pBuf->fNewCmd = true;
76 }
77 }
78 }
79
80 /*
81 * Console next.
82 */
83 if (ch != '\0')
84 {
85 BS3_ASSERT(pBuf->cchBuf < RT_ELEMENTS(pBuf->achBuf));
86 pBuf->achBuf[pBuf->cchBuf++] = ch;
87
88 /* Whether to flush the buffer. We do line flushing here to avoid
89 dropping too much info when the formatter crashes on bad input. */
90 if ( pBuf->cchBuf < RT_ELEMENTS(pBuf->achBuf)
91 && ch != '\n')
92 return 1;
93 }
94 BS3_ASSERT(pBuf->cchBuf <= RT_ELEMENTS(pBuf->achBuf));
95 Bs3PrintStrN(&pBuf->achBuf[0], pBuf->cchBuf);
96 pBuf->cchBuf = 0;
97 return ch != '\0';
98}
99
100
101
102BS3_DECL(void) Bs3TestPrintfV(const char BS3_FAR *pszFormat, va_list va)
103{
104 BS3TESTPRINTBUF Buf;
105 Buf.fNewCmd = true;
106 Buf.cchBuf = 0;
107 Bs3StrFormatV(pszFormat, va, bs3TestPrintfStrOutput, &Buf);
108}
109
110
111
112BS3_DECL(void) Bs3TestPrintf(const char BS3_FAR *pszFormat, ...)
113{
114 va_list va;
115 va_start(va, pszFormat);
116 Bs3TestPrintfV(pszFormat, va);
117 va_end(va);
118}
119
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette