/
init.c
254 lines (172 loc) · 5.65 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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
* Copyright (C) 2012-2015 Leo Grange <grangeleo@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "arch/sh/7705_Casio.h"
#include "device/terminal/generic_early_term.h"
#include "arch/sh/interrupt.h"
#include "arch/sh/mmu.h"
#include "arch/sh/physical_memory.h"
#include "utils/log.h"
#include "sys/process.h"
#include "sys/scheduler.h"
#include "sys/time.h"
#include "sys/stimer.h"
#include "fs/casio_smemfs/file_system.h"
#include "fs/protofs/file_system.h"
#include "fs/vfs.h"
#include "fs/vfs_op.h"
#include "fs/vfs_file.h"
#include "device/device_registering.h"
#include "device/terminal/virtual_term.h"
#include "device/usb/usb_device_protocol.h"
#include "device/usb/cdc_acm/acm_device.h"
#include "device/usb/cdc_acm/cdc_acm.h"
#include "device/keyboard/fx9860/keyboard_device.h"
#include "device/keyboard/fx9860/keyboard.h"
#include "device/keyboard/fx9860/keymatrix.h"
#include "arch/sh/rtc.h"
#include "device/display/display.h"
#include "arch/sh/freq.h"
#include "tests.h"
#include "utils/strutils.h"
#include "sys/cmdline.h"
#include "sys/console.h"
#include "sys/sysctl.h"
#include "sys/mem_area.h"
#include "device/tty.h"
extern char cmdargs_begin;
extern char cmdargs_end;
volatile int _magic_lock = 0;
void print_usb_ep2(const char *str) {
int i;
for(i=0; str[i]!=0; i++);
usb_send(USB_EP_ADDR_EP2IN/*_epdesc2.b_endpoint_addr*/, str, i);
}
// Real entry point of the OS :
void init() {
unsigned int freq;
interrupt_init();
earlyterm_init();
earlyterm_clear();
kbd_init();
rtc_init();
time_init();
earlyterm_write("Kernel initialization...\n");
set_kernel_print(&earlyterm_write);
printk(LOG_INFO, "cmd args: '%s'\n", &cmdargs_begin);
cmdline_parse(&cmdargs_begin, 1024);
mmu_init();
pm_init_pages();
stimer_init();
hwkbd_start_periodic_update();
DBG_WAIT;
interrupt_inhibit_all(0);
// console initialisation as soon as possible
dev_init();
// add TTY device (on major 4)
ttydev_device.init();
dev_register_device(&ttydev_device, 4);
// add virtual terminal TTYs
vt_init();
// USB initialisation
usb_init();
// add usb-acm TTY
acm_usb_init();
DBG_WAIT;
// will be the last message displayed on early console
printk(LOG_INFO, "Switching screen to tty1...\n The display will be cleared.\n");
console_make_active();
// in all cases, Virtual Terminals should be made active (tty1)
DBG_WAIT;
vt_set_active(0);
// need to be changed for "overclocking" :
//freq_change(FREQ_STC_4, FREQ_DIV_1, FREQ_DIV_4);
freq_time_calibrate();
freq = freq_get_internal_hz();
printk(LOG_INFO, "CPU freq : %d.%dMHz\n", freq/1000000, (freq/100000)%10);
freq = freq_get_peripheral_hz();
printk(LOG_INFO, "Peripheral freq : %d.%dMHz\n", freq/1000000, (freq/100000)%10);
// initialize sysctl tables
ctl_init();
//test_keyboard_int();
//test_virtual_mem();
//asm volatile ("trapa #50");
//DBG_WAIT;
// Initializing VFS and device sub-sytems, mount platform filesystems,
// register platform devices...
vfs_init();
vfs_file_init();
vfs_register_fs(&smemfs_file_system, VFS_REGISTER_STATIC);
vfs_register_fs(&protofs_file_system, VFS_REGISTER_STATIC);
vfs_mount("protofs", NULL, VFS_MOUNT_ROOT);
vfs_create("/", "dev", INODE_TYPE_PARENT, INODE_FLAG_READ | INODE_FLAG_EXEC, 0);
vfs_create("/dev", "tty1", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00040000);
vfs_create("/dev", "tty2", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00040001);
vfs_create("/dev", "serial", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00030000);
vfs_create("/dev", "console", INODE_TYPE_DEV, INODE_FLAG_WRITE,
console_get_device());
DBG_WAIT;
// keyboard input for virtual terminals
kbd_set_kstroke_handler(&vt_key_stroke);
// mount additional filesystems
vfs_create("/", "mnt", INODE_TYPE_PARENT, INODE_FLAG_WRITE, 0);
vfs_create("/mnt", "smem", INODE_TYPE_PARENT, INODE_FLAG_WRITE, 0);
vfs_mount("smemfs", "/mnt/smem", VFS_MOUNT_NORMAL);
DBG_WAIT;
// set /dev/display device
_display_device.init();
dev_register_device(&_display_device, 0x20);
vfs_create("/dev", "display", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00200001);
// direct keyboard device on major 0x21
fxkeyboard_device.init();
dev_register_device(&fxkeyboard_device, 0x21);
vfs_create("/dev", "keyboard", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00210000);
DBG_WAIT;
//test_keymatrix();
// test_keyboard();
/*while(1) {
char c;
if(vfs_read(console, &c, 1) == 1) {
vfs_write(console, &c, 1);
}
}*/
DBG_WAIT;
//test_vfs();
//test_sdcard();
//test_sleep_funcs();
// EEPROM-related code commented to avoid useless write cycles ;)
//test_eeprom();
/*char mybuf[128];
int len;
len = usb_receive(USB_EP_ADDR_EP1OUT, mybuf, 10, 0);
printk(LOG_DEBUG, "usb_receive ret=%d\n", len);
if(len > 0) {
mybuf[len] = '\0';
printk(LOG_DEBUG, "content = '%s'\n", mybuf);
}
while(!_magic_lock);
set_kernel_print(&print_usb_ep2);
test_vfs();
*/
// memory area subsystem
mem_area_init();
process_init();
sched_init();
test_process();
printk(LOG_WARNING, "End of init job, sleeping...\n");
while(1)
printk(LOG_WARNING, "IER: 0x%x 0x%x\n", USB.IFR0.BYTE, USB.IFR1.BYTE);
}