2018-10-16 12:01:38 +03:00
|
|
|
#include "types.h"
|
|
|
|
#include "kmalloc.h"
|
|
|
|
#include "i386.h"
|
|
|
|
#include "i8253.h"
|
|
|
|
#include "Keyboard.h"
|
2018-11-01 15:15:46 +03:00
|
|
|
#include "Process.h"
|
2018-10-16 12:01:38 +03:00
|
|
|
#include "system.h"
|
|
|
|
#include "PIC.h"
|
2018-10-16 15:17:43 +03:00
|
|
|
#include "IDEDiskDevice.h"
|
2018-12-25 00:59:10 +03:00
|
|
|
#include "KSyms.h"
|
2019-01-23 07:13:17 +03:00
|
|
|
#include <Kernel/NullDevice.h>
|
|
|
|
#include <Kernel/ZeroDevice.h>
|
|
|
|
#include <Kernel/FullDevice.h>
|
|
|
|
#include <Kernel/RandomDevice.h>
|
|
|
|
#include <Kernel/Ext2FileSystem.h>
|
|
|
|
#include <Kernel/VirtualFileSystem.h>
|
2019-01-16 18:03:50 +03:00
|
|
|
#include "GUIEventDevice.h"
|
2018-10-18 00:13:55 +03:00
|
|
|
#include "MemoryManager.h"
|
2019-02-03 14:33:11 +03:00
|
|
|
#include "ProcFS.h"
|
2018-10-25 18:29:49 +03:00
|
|
|
#include "RTC.h"
|
2018-10-30 15:59:29 +03:00
|
|
|
#include "VirtualConsole.h"
|
2018-11-08 00:15:02 +03:00
|
|
|
#include "Scheduler.h"
|
2019-01-11 04:28:53 +03:00
|
|
|
#include "PS2MouseDevice.h"
|
2019-01-16 15:36:10 +03:00
|
|
|
#include "PTYMultiplexer.h"
|
2019-01-30 02:49:20 +03:00
|
|
|
#include "DevPtsFS.h"
|
2019-02-06 12:17:26 +03:00
|
|
|
#include "BochsVGADevice.h"
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2019-01-25 17:52:55 +03:00
|
|
|
//#define SPAWN_GUITEST
|
|
|
|
#define SPAWN_GUITEST2
|
2019-02-05 11:44:13 +03:00
|
|
|
#define SPAWN_CLOCK
|
|
|
|
//#define SPAWN_FONTEDITOR
|
2019-01-12 23:45:45 +03:00
|
|
|
//#define SPAWN_MULTIPLE_SHELLS
|
2018-10-23 16:41:55 +03:00
|
|
|
//#define STRESS_TEST_SPAWNING
|
2018-10-16 12:01:38 +03:00
|
|
|
|
|
|
|
system_t system;
|
|
|
|
|
2018-10-30 15:59:29 +03:00
|
|
|
VirtualConsole* tty0;
|
|
|
|
VirtualConsole* tty1;
|
|
|
|
VirtualConsole* tty2;
|
2018-10-31 02:27:34 +03:00
|
|
|
VirtualConsole* tty3;
|
2018-10-30 17:33:37 +03:00
|
|
|
Keyboard* keyboard;
|
2019-01-11 04:28:53 +03:00
|
|
|
PS2MouseDevice* ps2mouse;
|
2019-01-14 16:21:51 +03:00
|
|
|
GUIEventDevice* gui_event_device;
|
2019-01-16 19:20:58 +03:00
|
|
|
VFS* vfs;
|
2018-10-30 15:59:29 +03:00
|
|
|
|
2018-11-09 12:03:21 +03:00
|
|
|
#ifdef STRESS_TEST_SPAWNING
|
2018-11-01 16:41:49 +03:00
|
|
|
static void spawn_stress() NORETURN;
|
|
|
|
static void spawn_stress()
|
|
|
|
{
|
2018-12-27 00:02:24 +03:00
|
|
|
dword last_sum_alloc = sum_alloc;
|
2018-11-01 16:41:49 +03:00
|
|
|
|
2018-11-01 18:23:12 +03:00
|
|
|
for (unsigned i = 0; i < 10000; ++i) {
|
2018-11-01 16:41:49 +03:00
|
|
|
int error;
|
2019-01-09 00:28:11 +03:00
|
|
|
Process::create_user_process("/bin/true", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2018-12-27 00:02:24 +03:00
|
|
|
dbgprintf("malloc stats: alloc:%u free:%u eternal:%u !delta:%u\n", sum_alloc, sum_free, kmalloc_sum_eternal, sum_alloc - last_sum_alloc);
|
|
|
|
last_sum_alloc = sum_alloc;
|
2018-11-01 18:23:12 +03:00
|
|
|
sleep(60);
|
2018-11-01 16:41:49 +03:00
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
asm volatile("hlt");
|
|
|
|
}
|
|
|
|
}
|
2018-11-09 12:03:21 +03:00
|
|
|
#endif
|
2018-11-01 16:41:49 +03:00
|
|
|
|
2018-10-22 12:15:16 +03:00
|
|
|
static void init_stage2() NORETURN;
|
|
|
|
static void init_stage2()
|
2018-10-16 12:01:38 +03:00
|
|
|
{
|
|
|
|
Syscall::initialize();
|
|
|
|
|
2018-10-17 12:44:06 +03:00
|
|
|
auto dev_zero = make<ZeroDevice>();
|
2018-11-15 17:10:12 +03:00
|
|
|
vfs->register_character_device(*dev_zero);
|
2018-10-17 12:44:06 +03:00
|
|
|
|
2018-10-16 15:33:16 +03:00
|
|
|
auto dev_null = make<NullDevice>();
|
2018-11-15 17:10:12 +03:00
|
|
|
vfs->register_character_device(*dev_null);
|
2018-10-17 12:44:06 +03:00
|
|
|
|
2018-10-16 15:33:16 +03:00
|
|
|
auto dev_full = make<FullDevice>();
|
2018-11-15 17:10:12 +03:00
|
|
|
vfs->register_character_device(*dev_full);
|
2018-10-17 12:44:06 +03:00
|
|
|
|
2018-10-16 15:33:16 +03:00
|
|
|
auto dev_random = make<RandomDevice>();
|
2018-11-15 17:10:12 +03:00
|
|
|
vfs->register_character_device(*dev_random);
|
2018-10-30 15:59:29 +03:00
|
|
|
|
2019-01-16 15:36:10 +03:00
|
|
|
auto dev_ptmx = make<PTYMultiplexer>();
|
|
|
|
vfs->register_character_device(*dev_ptmx);
|
2019-01-15 08:30:19 +03:00
|
|
|
|
2018-11-15 17:10:12 +03:00
|
|
|
vfs->register_character_device(*keyboard);
|
2019-01-11 04:28:53 +03:00
|
|
|
vfs->register_character_device(*ps2mouse);
|
2019-01-14 16:21:51 +03:00
|
|
|
vfs->register_character_device(*gui_event_device);
|
2018-11-15 17:10:12 +03:00
|
|
|
vfs->register_character_device(*tty0);
|
|
|
|
vfs->register_character_device(*tty1);
|
|
|
|
vfs->register_character_device(*tty2);
|
|
|
|
vfs->register_character_device(*tty3);
|
2018-10-23 11:12:50 +03:00
|
|
|
|
2018-10-17 12:44:06 +03:00
|
|
|
auto dev_hd0 = IDEDiskDevice::create();
|
2019-01-31 19:31:23 +03:00
|
|
|
auto e2fs = Ext2FS::create(dev_hd0.copy_ref());
|
2018-10-22 12:15:16 +03:00
|
|
|
e2fs->initialize();
|
2018-10-17 11:55:43 +03:00
|
|
|
|
2019-01-31 19:31:23 +03:00
|
|
|
vfs->mount_root(e2fs.copy_ref());
|
2018-10-17 12:44:06 +03:00
|
|
|
|
2018-12-25 00:59:10 +03:00
|
|
|
load_ksyms();
|
2018-10-26 23:32:35 +03:00
|
|
|
|
2018-11-15 19:13:10 +03:00
|
|
|
vfs->mount(ProcFS::the(), "/proc");
|
2019-01-30 02:49:20 +03:00
|
|
|
vfs->mount(DevPtsFS::the(), "/dev/pts");
|
2018-10-17 12:47:14 +03:00
|
|
|
|
2018-11-11 17:36:40 +03:00
|
|
|
Vector<String> environment;
|
|
|
|
environment.append("TERM=ansi");
|
|
|
|
|
2018-10-30 17:33:37 +03:00
|
|
|
int error;
|
2019-01-14 16:21:51 +03:00
|
|
|
//Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0);
|
2019-01-15 06:30:55 +03:00
|
|
|
Process::create_user_process("/bin/Terminal", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0);
|
2019-01-25 17:52:55 +03:00
|
|
|
#ifdef SPAWN_GUITEST
|
2019-01-13 03:59:38 +03:00
|
|
|
Process::create_user_process("/bin/guitest", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0);
|
2019-01-25 17:52:55 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SPAWN_GUITEST2
|
2019-01-20 07:48:43 +03:00
|
|
|
Process::create_user_process("/bin/guitest2", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0);
|
2019-01-13 03:59:38 +03:00
|
|
|
#endif
|
2019-02-05 11:44:13 +03:00
|
|
|
#ifdef SPAWN_CLOCK
|
|
|
|
Process::create_user_process("/bin/Clock", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0);
|
|
|
|
#endif
|
2019-02-02 10:05:14 +03:00
|
|
|
#ifdef SPAWN_FONTEDITOR
|
|
|
|
Process::create_user_process("/bin/FontEditor", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0);
|
|
|
|
#endif
|
2018-11-01 13:30:48 +03:00
|
|
|
#ifdef SPAWN_MULTIPLE_SHELLS
|
2019-01-09 00:28:11 +03:00
|
|
|
Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty1);
|
|
|
|
Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty2);
|
|
|
|
Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty3);
|
2018-11-01 13:30:48 +03:00
|
|
|
#endif
|
2018-10-30 17:33:37 +03:00
|
|
|
|
2018-11-01 16:41:49 +03:00
|
|
|
#ifdef STRESS_TEST_SPAWNING
|
2018-12-26 22:57:51 +03:00
|
|
|
Process::create_kernel_process("spawn_stress", spawn_stress);
|
2018-11-01 16:41:49 +03:00
|
|
|
#endif
|
|
|
|
|
2019-01-15 23:16:04 +03:00
|
|
|
extern void WindowServer_main();
|
|
|
|
Process::create_kernel_process("WindowServer", WindowServer_main);
|
2019-01-09 04:29:11 +03:00
|
|
|
|
2018-11-08 01:13:38 +03:00
|
|
|
current->sys$exit(0);
|
|
|
|
ASSERT_NOT_REACHED();
|
2018-10-22 12:15:16 +03:00
|
|
|
}
|
|
|
|
|
2018-11-09 12:03:21 +03:00
|
|
|
void init() NORETURN;
|
2018-10-22 12:15:16 +03:00
|
|
|
void init()
|
|
|
|
{
|
|
|
|
cli();
|
|
|
|
|
|
|
|
kmalloc_init();
|
2019-01-01 04:20:01 +03:00
|
|
|
init_ksyms();
|
2018-10-22 12:15:16 +03:00
|
|
|
|
2018-10-31 01:01:48 +03:00
|
|
|
auto console = make<Console>();
|
|
|
|
|
2018-10-25 18:29:49 +03:00
|
|
|
RTC::initialize();
|
2018-10-22 12:15:16 +03:00
|
|
|
PIC::initialize();
|
|
|
|
gdt_init();
|
|
|
|
idt_init();
|
|
|
|
|
2019-01-16 19:20:58 +03:00
|
|
|
vfs = new VFS;
|
|
|
|
|
2018-10-30 17:33:37 +03:00
|
|
|
keyboard = new Keyboard;
|
2019-01-11 04:28:53 +03:00
|
|
|
ps2mouse = new PS2MouseDevice;
|
2019-01-14 16:21:51 +03:00
|
|
|
gui_event_device = new GUIEventDevice;
|
2018-10-30 17:33:37 +03:00
|
|
|
|
|
|
|
VirtualConsole::initialize();
|
|
|
|
tty0 = new VirtualConsole(0, VirtualConsole::AdoptCurrentVGABuffer);
|
|
|
|
tty1 = new VirtualConsole(1);
|
|
|
|
tty2 = new VirtualConsole(2);
|
2018-10-31 02:27:34 +03:00
|
|
|
tty3 = new VirtualConsole(3);
|
2018-11-01 16:09:21 +03:00
|
|
|
VirtualConsole::switch_to(0);
|
2018-10-30 17:33:37 +03:00
|
|
|
|
2018-10-31 22:10:39 +03:00
|
|
|
kprintf("Starting Serenity Operating System...\n");
|
|
|
|
|
2018-10-22 12:15:16 +03:00
|
|
|
MemoryManager::initialize();
|
|
|
|
PIT::initialize();
|
|
|
|
|
2019-02-06 12:17:26 +03:00
|
|
|
new BochsVGADevice;
|
|
|
|
|
2019-02-03 14:33:11 +03:00
|
|
|
auto new_procfs = ProcFS::create();
|
|
|
|
new_procfs->initialize();
|
2018-10-26 18:42:12 +03:00
|
|
|
|
2019-01-30 02:49:20 +03:00
|
|
|
auto devptsfs = DevPtsFS::create();
|
|
|
|
devptsfs->initialize();
|
|
|
|
|
2018-11-01 15:15:46 +03:00
|
|
|
Process::initialize();
|
2018-12-25 01:10:48 +03:00
|
|
|
Process::create_kernel_process("init_stage2", init_stage2);
|
|
|
|
Process::create_kernel_process("syncd", [] {
|
|
|
|
for (;;) {
|
|
|
|
Syscall::sync();
|
|
|
|
sleep(10 * TICKS_PER_SECOND);
|
|
|
|
}
|
|
|
|
});
|
2019-02-06 20:45:21 +03:00
|
|
|
Process::create_kernel_process("Finalizer", [] {
|
|
|
|
g_finalizer = current;
|
|
|
|
for (;;) {
|
|
|
|
Process::finalize_dying_processes();
|
|
|
|
current->block(Process::BlockedLurking);
|
|
|
|
Scheduler::yield();
|
|
|
|
}
|
|
|
|
});
|
2018-12-20 04:41:55 +03:00
|
|
|
|
2018-11-08 00:15:02 +03:00
|
|
|
Scheduler::pick_next();
|
2018-10-22 12:15:16 +03:00
|
|
|
|
|
|
|
sti();
|
|
|
|
|
2018-11-01 15:15:46 +03:00
|
|
|
// This now becomes the idle process :^)
|
2018-10-16 12:01:38 +03:00
|
|
|
for (;;) {
|
|
|
|
asm("hlt");
|
|
|
|
}
|
|
|
|
}
|