xsupport.c
2.97 KB
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
/*
* Copyright (C) 1996-1998 by the Board of Trustees
* of Leland Stanford Junior University.
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
/****************************************************************
* $File$
*
* $Author: blythe $
* $Date: 2002/05/29 01:09:09 $
*****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include "xsupport.h"
#include "checkpoint.h"
#include "startup.h"
#include "sim.h"
#include "simutil.h"
static int framebuf_fd, eventq_fd;
static CptCallback FrameCheckpointCB;
static CptCallback EventQCheckpointCB;
static int FrameCheckpointCB(CptDescriptor *cptd);
static int EventQCheckpointCB(CptDescriptor *cptd);
/*****************************************************************
* This is added for supporting an X-windows session on top of
* simos. The event queue needs a little bit of work.
*****************************************************************/
void
InitXSupport(int restoringCpt)
{
char *addr;
int framebuf_fd;
Simcpt_Register("framebuffer", FrameCheckpointCB, ALL_CPUS);
Simcpt_Register("eventqueue", EventQCheckpointCB, ALL_CPUS);
/*
* Create a region to store the frame buffer
*/
framebuf_fd = open("frame.simos", O_RDWR | O_CREAT, 0700);
if (framebuf_fd < 0) {
perror("Opening frame.simos");
Sim_Error("Simprom_start can't start");
}
addr = (char *)mmap((char *)SIMFRAMEBUFFER,
SIMFRAMEBUFFER_SZ,
PROT_WRITE,
MAP_SHARED, framebuf_fd, 0);
if (addr != (char *)SIMFRAMEBUFFER) {
perror("mapping frame buffer");
Sim_Error("Can't map frame buffer");
}
if (restoringCpt) {
Simcpt_Restore("framebuffer");
} else {
bzero((char *)SIMFRAMEBUFFER, SIMFRAMEBUFFER_SZ);
}
close(framebuf_fd);
/*
* Create a region to store the input event queue to the simulated x server
*/
eventq_fd = open("event.simos", O_RDWR | O_CREAT, 0777);
if (eventq_fd < 0) {
perror("Opening event.simos");
Sim_Error("Simprom_start can't start");
}
addr = (char *)mmap((char *)SIMEVENTQ, SIMEVENTQ_SZ,
PROT_WRITE, MAP_SHARED, eventq_fd, 0);
if (addr != (char *) SIMEVENTQ) {
perror("mapping event queue");
Sim_Error("Can't map event queue");
}
if (restoringCpt) {
Simcpt_Restore("eventqueue");
}
bzero((char *)SIMEVENTQ, SIMEVENTQ_SZ);
close(eventq_fd);
}
static int
FrameCheckpointCB(CptDescriptor *cptd)
{
Simcpt_CptBlock(cptd, "framebuffer", NO_INDEX, NO_INDEX,
(caddr_t)SIMFRAMEBUFFER, SIMFRAMEBUFFER_SZ, framebuf_fd);
return 0;
}
static int
EventQCheckpointCB(CptDescriptor *cptd)
{
Simcpt_CptBlock(cptd, "eventqueue", NO_INDEX, NO_INDEX,
(caddr_t)SIMEVENTQ, SIMEVENTQ_SZ, eventq_fd);
return 0;
}