summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/hw/xfree86/int10/helper_mem.c
blob: ca61d6c9b10f76ffae58a949ec2943dccc08eadc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* $XFree86: xc/programs/Xserver/hw/xfree86/int10/helper_mem.c,v 1.11 2000/10/11 22:53:00 tsi Exp $ */
/*
 *                   XFree86 int10 module
 *   execute BIOS int 10h calls in x86 real mode environment
 *                 Copyright 1999 Egbert Eich
 */
#include "xf86.h"
#include "xf86str.h"
#include "xf86_OSproc.h"
#include "xf86_ansic.h"
#include "compiler.h"
#include "xf86Pci.h"
#define _INT10_PRIVATE
#include "int10Defines.h"
#include "xf86int10.h"

#define REG pInt

typedef enum {
    OPT_NOINT10
} INT10Opts;

static OptionInfoRec INT10Options[] = {
    {OPT_NOINT10,       "NoINT10",      OPTV_BOOLEAN,   {0},    FALSE },
    { -1,		NULL,		OPTV_NONE,	{0},	FALSE },
};

#define nINT10Options (sizeof(INT10Options) / sizeof(INT10Options[0]))

#ifdef DEBUG
void 
dprint(unsigned long start, unsigned long size)
{
    int i,j;
    char *c = (char *)start;

    for (j = 0; j < (size >> 4); j++) {
	char *d = c;
	ErrorF("\n0x%lx:  ",(unsigned long)c);
	for (i = 0; i<16; i++) 
	    ErrorF("%2.2x ",(unsigned char) (*(c++)));
	c = d;
	for (i = 0; i<16; i++) {
	    ErrorF("%c",((((CARD8)(*c)) > 32) && (((CARD8)(*c)) < 128)) ?
		   (unsigned char) (*(c)): '.');
	    c++;
	}
    }
    ErrorF("\n");
}
#endif


/*
 * here we are really paranoid about faking a "real"
 * BIOS. Most of this information was pulled from
 * dosemu.
 */
void
setup_int_vect(xf86Int10InfoPtr pInt)
{
    const CARD16 cs = 0xF000;
    const CARD16 ip = 0x0;
    int i;
    
    /* let the int vects point to the SYS_BIOS seg */
    for (i=0; i<0x80; i++) {
	MEM_WW(pInt,(i<<2),ip);
	MEM_WW(pInt,((i<<2)+2),cs);
    }
    /* video interrupts default location */
    MEM_WW(pInt,(0x42<<2),0xf065);
    MEM_WW(pInt,(0x10<<2),0xf065);
    MEM_WW(pInt,(0x6D<<2),0xf065);
    /* video param table default location (int 1d) */
    MEM_WW(pInt,(0x1d<<2),0xf0A4);
    /* font tables default location (int 1F) */
    MEM_WW(pInt,(0x1f<<2),0xfa6e);

    /* int 11 default location */
    MEM_WW(pInt,(0x11<<2),0xf84d);
    /* int 12 default location */
    MEM_WW(pInt,(0x12<<2),0xf841);
    /* int 15 default location */
    MEM_WW(pInt,(0x15<<2),0xf859);
    /* int 1A default location */
    MEM_WW(pInt,(0x1a<<2),0xff6e);
    /* int 05 default location */
    MEM_WW(pInt,(0x05<<2),0xff54);
    /* int 08 default location */
    MEM_WW(pInt,(0x08<<2),0xfea5);
    /* int 13 default location (fdd) */
    MEM_WW(pInt,(0x13<<2),0xec59);
    /* int 0E default location */
    MEM_WW(pInt,(0x0e<<2),0xef57);
    /* int 17 default location */
    MEM_WW(pInt,(0x17<<2),0xefd2);
    /* fdd table default location (int 1e) */
    MEM_WW(pInt,(0x1e<<2),0xefc7);
}

int
setup_system_bios(memType base_addr)
{
    char *date = "06/01/99";
    char *eisa_ident = "PCI/ISA";
    CARD16 *base = (CARD16*) base_addr;
    
    /*
     * we trap the "industry standard entry points" to the BIOS
     * and all other locations by filling them with "hlt"
     * TODO: implement hlt-handler for these
     */
    memset((void *)(base),0xf4,0x10000);

    /* set bios date */
    strcpy((((char *)base) + 0xFFF5),date);
    /* set up eisa ident string */
    strcpy((((char *)base) + 0xFFD9),eisa_ident);
    /* write system model id for IBM-AT */
    *(((unsigned char *)base) + 0xFFFE) = 0xfc;

    return 1;
}

void
reset_int_vect(xf86Int10InfoPtr pInt)
{
    MEM_WW(pInt,(0x10<<2),0xf065);    
    MEM_WW(pInt,((0x10<<2)+2),0xf000);
    MEM_WW(pInt,(0x42<<2),0xf065);
    MEM_WW(pInt,((0x42<<2)+2),0xf000);
    MEM_WW(pInt,(0x6D<<2),0xf065);
    MEM_WW(pInt,((0x6D<<2)+2),0xf000);
 }

void
set_return_trap(xf86Int10InfoPtr pInt)
{   
    /*
     * here we also set the exit condition:
     * we return when we encounter 'hlt' (^=0xf4) this
     * will be located at address 0x600 in x86 memory.
     */
    MEM_WB(pInt,0x600,0xf4);
}

Bool
int10skip(ScrnInfoPtr pScrn, int entityIndex)
{
    Bool noint10 = FALSE;
    EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
    
    if (pEnt->device && pEnt->device->options) {
	OptionInfoRec options[nINT10Options];

	(void)memcpy(options, INT10Options, sizeof(INT10Options));
	xf86ProcessOptions(pScrn->scrnIndex, pEnt->device->options, options);
	xf86GetOptValBool(options, OPT_NOINT10, &noint10);
    }
    xfree(pEnt);

    return noint10;
}


Bool
int10_read_bios(int scrnIndex, int codeSeg, unsigned char* vbiosMem)
{
    int size;

    if ((codeSeg & 0x1f) ||	/* Not 512-byte aligned otherwise */
        ((codeSeg << 4) < V_BIOS) ||
	((codeSeg << 4) >= SYS_SIZE))
        return FALSE;

    if ((codeSeg << 4) >= SYS_BIOS)
	return TRUE;

    if (xf86IsPc98())
        return FALSE;

    if (xf86ReadBIOS(codeSeg << 4, 0, vbiosMem, 0x10) < 0) {
	xf86DrvMsg(scrnIndex,X_WARNING,"Cannot read V_BIOS (1)\n");
	return FALSE;
    }
    
    if ((*vbiosMem != 0x55) || (*(vbiosMem+1) != 0xAA) || !*(vbiosMem+2) ||
	  (*(vbiosMem+2) > 0x80U))
	return FALSE;

    size = *(vbiosMem + 2) * 512;

    if ((size + (codeSeg << 4)) > SYS_SIZE)
	return FALSE;

    /* We might already have the tail end */
    if ((size + (codeSeg << 4)) > SYS_BIOS)
	size = SYS_BIOS - (codeSeg << 4);

    if (xf86ReadBIOS(codeSeg << 4,0,vbiosMem, size) < 0) {
	xf86DrvMsg(scrnIndex,X_ERROR,"Cannot read V_BIOS (2)\n");
	return FALSE;
    }
    if (bios_checksum(vbiosMem, size))
	xf86DrvMsg(scrnIndex, X_WARNING, "Bad V_BIOS checksum\n");

    return TRUE;
}