2018-10-16 12:01:38 +03:00
|
|
|
#include "types.h"
|
|
|
|
#include "kmalloc.h"
|
|
|
|
#include "i386.h"
|
|
|
|
#include "i8253.h"
|
2019-02-17 10:39:09 +03:00
|
|
|
#include "KeyboardDevice.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>
|
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-17 10:40:30 +03:00
|
|
|
#include "BXVGADevice.h"
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2019-02-17 13:31:52 +03:00
|
|
|
#define SPAWN_LAUNCHER
|
2019-02-08 01:13:47 +03:00
|
|
|
//#define SPAWN_GUITEST2
|
2019-02-28 03:43:50 +03:00
|
|
|
//#define SPAWN_FILE_MANAGER
|
2019-03-07 02:31:06 +03:00
|
|
|
//#define SPAWN_PROCESS_MANAGER
|
|
|
|
#define SPAWN_TEXT_EDITOR
|
2019-02-05 11:44:13 +03:00
|
|
|
//#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;
|
2019-02-17 10:39:09 +03:00
|
|
|
KeyboardDevice* keyboard;
|
2019-01-11 04:28:53 +03:00
|
|
|
PS2MouseDevice* ps2mouse;
|
2019-02-12 13:25:25 +03:00
|
|
|
NullDevice* dev_null;
|
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
|
2019-02-15 14:30:48 +03:00
|
|
|
[[noreturn]] static void spawn_stress()
|
2018-11-01 16:41:49 +03:00
|
|
|
{
|
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
|
|
|
|
2019-02-15 14:30:48 +03:00
|
|
|
[[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-10-16 15:33:16 +03:00
|
|
|
auto dev_full = make<FullDevice>();
|
|
|
|
auto dev_random = make<RandomDevice>();
|
2019-01-16 15:36:10 +03:00
|
|
|
auto dev_ptmx = make<PTYMultiplexer>();
|
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-10-30 17:33:37 +03:00
|
|
|
int error;
|
2019-02-12 12:19:52 +03:00
|
|
|
|
2019-02-17 02:21:26 +03:00
|
|
|
auto* window_server_process = Process::create_user_process("/bin/WindowServer", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2019-02-17 02:13:47 +03:00
|
|
|
if (error != 0) {
|
|
|
|
dbgprintf("error: %d\n", error);
|
2019-02-17 02:21:26 +03:00
|
|
|
hang();
|
2019-02-17 02:13:47 +03:00
|
|
|
}
|
2019-02-17 02:21:26 +03:00
|
|
|
window_server_process->set_priority(Process::HighPriority);
|
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-02-12 12:19:52 +03:00
|
|
|
Process::create_user_process("/bin/Terminal", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2019-01-25 17:52:55 +03:00
|
|
|
#ifdef SPAWN_GUITEST2
|
2019-02-12 12:19:52 +03:00
|
|
|
Process::create_user_process("/bin/guitest2", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2019-01-13 03:59:38 +03:00
|
|
|
#endif
|
2019-02-08 01:13:47 +03:00
|
|
|
#ifdef SPAWN_LAUNCHER
|
2019-02-12 12:19:52 +03:00
|
|
|
Process::create_user_process("/bin/Launcher", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2019-02-08 01:13:47 +03:00
|
|
|
#endif
|
2019-02-09 11:22:04 +03:00
|
|
|
#ifdef SPAWN_FILE_MANAGER
|
2019-02-12 12:19:52 +03:00
|
|
|
Process::create_user_process("/bin/FileManager", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2019-02-09 11:22:04 +03:00
|
|
|
#endif
|
2019-02-28 03:43:50 +03:00
|
|
|
#ifdef SPAWN_PROCESS_MANAGER
|
|
|
|
Process::create_user_process("/bin/ProcessManager", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
|
|
|
#endif
|
2019-03-07 02:31:06 +03:00
|
|
|
#ifdef SPAWN_TEXT_EDITOR
|
|
|
|
Process::create_user_process("/bin/TextEditor", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, 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
|
|
|
|
|
2018-11-08 01:13:38 +03:00
|
|
|
current->sys$exit(0);
|
|
|
|
ASSERT_NOT_REACHED();
|
2018-10-22 12:15:16 +03:00
|
|
|
}
|
|
|
|
|
2019-02-15 14:30:48 +03:00
|
|
|
[[noreturn]] void init()
|
2018-10-22 12:15:16 +03:00
|
|
|
{
|
|
|
|
cli();
|
|
|
|
|
|
|
|
kmalloc_init();
|
2019-01-01 04:20:01 +03:00
|
|
|
init_ksyms();
|
2018-10-22 12:15:16 +03:00
|
|
|
|
2019-02-17 12:38:07 +03:00
|
|
|
vfs = new VFS;
|
|
|
|
|
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-02-17 10:39:09 +03:00
|
|
|
keyboard = new KeyboardDevice;
|
2019-01-11 04:28:53 +03:00
|
|
|
ps2mouse = new PS2MouseDevice;
|
2019-02-12 13:25:25 +03:00
|
|
|
dev_null = new NullDevice;
|
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-17 10:40:30 +03:00
|
|
|
new BXVGADevice;
|
2019-02-06 12:17:26 +03:00
|
|
|
|
2019-02-25 14:43:52 +03:00
|
|
|
Retained<ProcFS> new_procfs = ProcFS::create();
|
2019-02-03 14:33:11 +03:00
|
|
|
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();
|
2019-02-17 17:18:20 +03:00
|
|
|
sleep(1 * TICKS_PER_SECOND);
|
2018-12-25 01:10:48 +03:00
|
|
|
}
|
|
|
|
});
|
2019-02-06 20:45:21 +03:00
|
|
|
Process::create_kernel_process("Finalizer", [] {
|
|
|
|
g_finalizer = current;
|
2019-02-07 14:21:17 +03:00
|
|
|
current->set_priority(Process::LowPriority);
|
2019-02-06 20:45:21 +03:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|