forked from publicres/xv6_gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
130 lines (121 loc) · 2.43 KB
/
init.c
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
// init: The initial user-level program
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
#include "guientity_attrvalue.h"
char *argv[] = { "sh", 0 };
uchar *readImg(char *fileName, uchar picMode) //0:3channel,1:4channel
{
int fd1 = open(fileName, 0);
if (fd1 < 0)
{
printf(1, "open file error\n");
return 0;
}
uchar w,h;
read(fd1, &w, 1);
read(fd1, &h, 1);
int size=(uint)w*(uint)h,i;
uchar *p=malloc(size*4+12);
uchar *q,*tp,*tq;
p[0]=w;
p[1]=h;
if (picMode==1)
{
read(fd1, p+2, size*4);
}
else if (picMode==0)
{
q=malloc(size*3+4);
read(fd1, q, size*3);
tp=p+2;
tq=q;
for (i=0;i<size;i++)
{
*(tp++)=*(q++);
*(tp++)=*(q++);
*(tp++)=*(q++);
*(tp++)=0;
}
free(tq);
}
close(fd1);
return p;
}
void initMouse()
{
contentStruct pic;
uchar *p=readImg("cursor.mx",1);
pic.pics=p;
pic.isRepeat=0;
setattr(GUIENT_IMG,0xfffffffe,GUIATTR_IMG_CONTENT,&pic);
free(p);
}
void initLetters()
{
char* cont="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM~!@#$%^&*()_-=+[];',./\\{}|:\"<>?";
int fd1 = open("letters.mx", 0);
uchar w,h;
uchar *p;
int size,num,i,j;
if (fd1 < 0)
{
printf(1, "open file error\n");
return;
}
read(fd1, &w, 1);
read(fd1, &h, 1);
num=strlen(cont);
size=(1+(uint)w*(uint)h)*num;
p=malloc(size+10);
size=(uint)w*(uint)h;
p[0]=0;
p[1]=w;
p[2]=h;
p[3]=(uchar)strlen(cont);
j=4;
for (i=0;i<num;i++)
{
p[j]=(uchar)cont[i];
read(fd1, p+j+1, size);
j=j+1+size;
}
close(fd1);
//SYSCALL HERE!
uint x=0;
setattr(GUIENT_TXT,x,GUIATTR_TXT_FONT,p);
free(p);
}
int
main(void)
{
int pid, wpid;
if(open("console", O_RDWR) < 0){
mknod("console", 1, 1);
open("console", O_RDWR);
}
dup(0); // stdout
dup(0); // stderr
initMouse();
initLetters();
for(;;){
printf(1, "init: starting sh\n");
pid = fork();
if(pid < 0){
printf(1, "init: fork failed\n");
exit();
}
if(pid == 0){
#ifdef I_WANNA_GUI
exec("indexpage", argv);
#else
exec("sh", argv);
#endif
printf(1, "init: exec sh failed\n");
exit();
}
while((wpid=wait()) >= 0 && wpid != pid)
printf(1, "zombie!\n");
}
}