2019-04-06 14:29:29 +02:00
|
|
|
#include <AK/Types.h>
|
2018-10-16 11:01:38 +02:00
|
|
|
#include "kmalloc.h"
|
|
|
|
#include "i386.h"
|
|
|
|
#include "i8253.h"
|
2019-04-03 12:36:40 +02:00
|
|
|
#include <Kernel/Devices/KeyboardDevice.h>
|
2018-11-01 13:15:46 +01:00
|
|
|
#include "Process.h"
|
2018-10-16 11:01:38 +02:00
|
|
|
#include "PIC.h"
|
2019-04-03 12:36:40 +02:00
|
|
|
#include <Kernel/Devices/IDEDiskDevice.h>
|
2018-12-24 22:59:10 +01:00
|
|
|
#include "KSyms.h"
|
2019-04-03 12:36:40 +02:00
|
|
|
#include <Kernel/Devices/NullDevice.h>
|
|
|
|
#include <Kernel/Devices/ZeroDevice.h>
|
|
|
|
#include <Kernel/Devices/FullDevice.h>
|
|
|
|
#include <Kernel/Devices/RandomDevice.h>
|
2019-04-03 12:25:24 +02:00
|
|
|
#include <Kernel/FileSystem/Ext2FileSystem.h>
|
|
|
|
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
2019-04-03 15:13:07 +02:00
|
|
|
#include <Kernel/VM/MemoryManager.h>
|
2019-04-03 12:25:24 +02:00
|
|
|
#include <Kernel/FileSystem/ProcFS.h>
|
2018-10-25 17:29:49 +02:00
|
|
|
#include "RTC.h"
|
2019-04-03 12:28:45 +02:00
|
|
|
#include <Kernel/TTY/VirtualConsole.h>
|
2018-11-07 22:15:02 +01:00
|
|
|
#include "Scheduler.h"
|
2019-04-03 12:36:40 +02:00
|
|
|
#include <Kernel/Devices/PS2MouseDevice.h>
|
2019-04-03 12:28:45 +02:00
|
|
|
#include <Kernel/TTY/PTYMultiplexer.h>
|
2019-04-03 12:25:24 +02:00
|
|
|
#include <Kernel/FileSystem/DevPtsFS.h>
|
2019-04-03 12:36:40 +02:00
|
|
|
#include <Kernel/Devices/BXVGADevice.h>
|
2019-04-02 19:54:38 +02:00
|
|
|
#include <Kernel/Net/E1000NetworkAdapter.h>
|
|
|
|
#include <Kernel/Net/NetworkTask.h>
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2019-04-16 02:39:16 +02:00
|
|
|
#define SPAWN_TERMINAL
|
2019-04-11 14:27:31 +02:00
|
|
|
//#define SPAWN_LAUNCHER
|
2019-02-07 23:13:47 +01:00
|
|
|
//#define SPAWN_GUITEST2
|
2019-04-01 22:04:09 +02:00
|
|
|
//#define SPAWN_FILE_MANAGER
|
2019-03-10 20:59:23 +01:00
|
|
|
//#define SPAWN_PROCESS_MANAGER
|
2019-04-12 14:47:21 +02:00
|
|
|
//#define SPAWN_TEXT_EDITOR
|
2019-02-05 09:44:13 +01:00
|
|
|
//#define SPAWN_FONTEDITOR
|
2019-04-16 02:39:16 +02:00
|
|
|
//#define SPAWN_VISUAL_BUILDER
|
2019-01-12 21:45:45 +01:00
|
|
|
//#define SPAWN_MULTIPLE_SHELLS
|
2018-10-23 15:41:55 +02:00
|
|
|
//#define STRESS_TEST_SPAWNING
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2018-10-30 13:59:29 +01:00
|
|
|
VirtualConsole* tty0;
|
|
|
|
VirtualConsole* tty1;
|
|
|
|
VirtualConsole* tty2;
|
2018-10-31 00:27:34 +01:00
|
|
|
VirtualConsole* tty3;
|
2019-02-17 08:39:09 +01:00
|
|
|
KeyboardDevice* keyboard;
|
2019-01-11 02:28:53 +01:00
|
|
|
PS2MouseDevice* ps2mouse;
|
2019-02-12 11:25:25 +01:00
|
|
|
NullDevice* dev_null;
|
2019-01-16 17:20:58 +01:00
|
|
|
VFS* vfs;
|
2018-10-30 13:59:29 +01:00
|
|
|
|
2018-11-09 10:03:21 +01:00
|
|
|
#ifdef STRESS_TEST_SPAWNING
|
2019-02-15 12:30:48 +01:00
|
|
|
[[noreturn]] static void spawn_stress()
|
2018-11-01 14:41:49 +01:00
|
|
|
{
|
2018-12-26 22:02:24 +01:00
|
|
|
dword last_sum_alloc = sum_alloc;
|
2018-11-01 14:41:49 +01:00
|
|
|
|
2018-11-01 16:23:12 +01:00
|
|
|
for (unsigned i = 0; i < 10000; ++i) {
|
2018-11-01 14:41:49 +01:00
|
|
|
int error;
|
2019-01-08 22:28:11 +01:00
|
|
|
Process::create_user_process("/bin/true", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2018-12-26 22:02:24 +01: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 16:23:12 +01:00
|
|
|
sleep(60);
|
2018-11-01 14:41:49 +01:00
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
asm volatile("hlt");
|
|
|
|
}
|
|
|
|
}
|
2018-11-09 10:03:21 +01:00
|
|
|
#endif
|
2018-11-01 14:41:49 +01:00
|
|
|
|
2019-02-15 12:30:48 +01:00
|
|
|
[[noreturn]] static void init_stage2()
|
2018-10-16 11:01:38 +02:00
|
|
|
{
|
|
|
|
Syscall::initialize();
|
|
|
|
|
2018-10-17 11:44:06 +02:00
|
|
|
auto dev_zero = make<ZeroDevice>();
|
2018-10-16 14:33:16 +02:00
|
|
|
auto dev_full = make<FullDevice>();
|
|
|
|
auto dev_random = make<RandomDevice>();
|
2019-01-16 13:36:10 +01:00
|
|
|
auto dev_ptmx = make<PTYMultiplexer>();
|
2018-10-17 11:44:06 +02:00
|
|
|
auto dev_hd0 = IDEDiskDevice::create();
|
2019-01-31 17:31:23 +01:00
|
|
|
auto e2fs = Ext2FS::create(dev_hd0.copy_ref());
|
2018-10-22 11:15:16 +02:00
|
|
|
e2fs->initialize();
|
2018-10-17 10:55:43 +02:00
|
|
|
|
2019-01-31 17:31:23 +01:00
|
|
|
vfs->mount_root(e2fs.copy_ref());
|
2018-10-17 11:44:06 +02:00
|
|
|
|
2019-03-23 22:03:17 +01:00
|
|
|
dbgprintf("Load ksyms\n");
|
2018-12-24 22:59:10 +01:00
|
|
|
load_ksyms();
|
2019-03-23 22:03:17 +01:00
|
|
|
dbgprintf("Loaded ksyms\n");
|
2018-10-26 22:32:35 +02:00
|
|
|
|
2018-11-15 17:13:10 +01:00
|
|
|
vfs->mount(ProcFS::the(), "/proc");
|
2019-01-30 00:49:20 +01:00
|
|
|
vfs->mount(DevPtsFS::the(), "/dev/pts");
|
2018-10-17 11:47:14 +02:00
|
|
|
|
2018-10-30 15:33:37 +01:00
|
|
|
int error;
|
2019-02-12 10:19:52 +01:00
|
|
|
|
2019-03-20 04:26:30 +01:00
|
|
|
auto* dns_lookup_server_process = Process::create_user_process("/bin/LookupServer", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2019-03-20 01:15:22 +01:00
|
|
|
if (error != 0) {
|
2019-03-20 04:26:30 +01:00
|
|
|
dbgprintf("error spawning LookupServer: %d\n", error);
|
2019-03-20 01:15:22 +01:00
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
2019-02-17 00:21:26 +01: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 00:13:47 +01:00
|
|
|
if (error != 0) {
|
2019-03-20 01:15:22 +01:00
|
|
|
dbgprintf("error spawning WindowServer: %d\n", error);
|
2019-02-17 00:21:26 +01:00
|
|
|
hang();
|
2019-02-17 00:13:47 +01:00
|
|
|
}
|
2019-02-17 00:21:26 +01:00
|
|
|
window_server_process->set_priority(Process::HighPriority);
|
2019-04-04 20:19:07 +02:00
|
|
|
Process::create_user_process("/bin/Taskbar", (uid_t)100, (gid_t)100, (pid_t)0, error);
|
2019-01-14 14:21:51 +01:00
|
|
|
//Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0);
|
2019-04-11 14:27:31 +02:00
|
|
|
#ifdef SPAWN_TERMINAL
|
2019-02-12 10:19:52 +01:00
|
|
|
Process::create_user_process("/bin/Terminal", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2019-04-11 14:27:31 +02:00
|
|
|
#endif
|
2019-01-25 15:52:55 +01:00
|
|
|
#ifdef SPAWN_GUITEST2
|
2019-02-12 10:19:52 +01:00
|
|
|
Process::create_user_process("/bin/guitest2", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2019-01-13 01:59:38 +01:00
|
|
|
#endif
|
2019-02-07 23:13:47 +01:00
|
|
|
#ifdef SPAWN_LAUNCHER
|
2019-02-12 10:19:52 +01:00
|
|
|
Process::create_user_process("/bin/Launcher", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2019-04-11 14:27:31 +02:00
|
|
|
#endif
|
|
|
|
#ifdef SPAWN_VISUAL_BUILDER
|
|
|
|
Process::create_user_process("/bin/VisualBuilder", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2019-02-07 23:13:47 +01:00
|
|
|
#endif
|
2019-02-09 09:22:04 +01:00
|
|
|
#ifdef SPAWN_FILE_MANAGER
|
2019-02-12 10:19:52 +01:00
|
|
|
Process::create_user_process("/bin/FileManager", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0);
|
2019-02-09 09:22:04 +01:00
|
|
|
#endif
|
2019-02-28 01:43:50 +01: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 00:31:06 +01:00
|
|
|
#ifdef SPAWN_TEXT_EDITOR
|
2019-03-07 17:15:59 +01:00
|
|
|
Vector<String> text_editor_arguments;
|
|
|
|
text_editor_arguments.append("/bin/TextEditor");
|
|
|
|
text_editor_arguments.append("/home/anon/ReadMe.md");
|
|
|
|
Process::create_user_process("/bin/TextEditor", (uid_t)100, (gid_t)100, (pid_t)0, error, move(text_editor_arguments), { }, tty0);
|
2019-03-07 00:31:06 +01:00
|
|
|
#endif
|
2019-02-02 08:05:14 +01: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 11:30:48 +01:00
|
|
|
#ifdef SPAWN_MULTIPLE_SHELLS
|
2019-01-08 22:28:11 +01: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 11:30:48 +01:00
|
|
|
#endif
|
2018-10-30 15:33:37 +01:00
|
|
|
|
2018-11-01 14:41:49 +01:00
|
|
|
#ifdef STRESS_TEST_SPAWNING
|
2018-12-26 20:57:51 +01:00
|
|
|
Process::create_kernel_process("spawn_stress", spawn_stress);
|
2018-11-01 14:41:49 +01:00
|
|
|
#endif
|
|
|
|
|
2019-03-23 22:03:17 +01:00
|
|
|
current->process().sys$exit(0);
|
2018-11-07 23:13:38 +01:00
|
|
|
ASSERT_NOT_REACHED();
|
2018-10-22 11:15:16 +02:00
|
|
|
}
|
|
|
|
|
2019-04-01 21:43:07 +02:00
|
|
|
extern "C" [[noreturn]] void init()
|
2018-10-22 11:15:16 +02:00
|
|
|
{
|
|
|
|
cli();
|
|
|
|
|
2019-03-27 13:40:00 +01:00
|
|
|
sse_init();
|
|
|
|
|
2018-10-22 11:15:16 +02:00
|
|
|
kmalloc_init();
|
2019-01-01 02:20:01 +01:00
|
|
|
init_ksyms();
|
2018-10-22 11:15:16 +02:00
|
|
|
|
2019-02-17 10:38:07 +01:00
|
|
|
vfs = new VFS;
|
|
|
|
|
2018-10-30 23:01:48 +01:00
|
|
|
auto console = make<Console>();
|
|
|
|
|
2018-10-25 17:29:49 +02:00
|
|
|
RTC::initialize();
|
2018-10-22 11:15:16 +02:00
|
|
|
PIC::initialize();
|
|
|
|
gdt_init();
|
|
|
|
idt_init();
|
|
|
|
|
2019-02-17 08:39:09 +01:00
|
|
|
keyboard = new KeyboardDevice;
|
2019-01-11 02:28:53 +01:00
|
|
|
ps2mouse = new PS2MouseDevice;
|
2019-02-12 11:25:25 +01:00
|
|
|
dev_null = new NullDevice;
|
2018-10-30 15:33:37 +01:00
|
|
|
|
|
|
|
VirtualConsole::initialize();
|
|
|
|
tty0 = new VirtualConsole(0, VirtualConsole::AdoptCurrentVGABuffer);
|
|
|
|
tty1 = new VirtualConsole(1);
|
|
|
|
tty2 = new VirtualConsole(2);
|
2018-10-31 00:27:34 +01:00
|
|
|
tty3 = new VirtualConsole(3);
|
2018-11-01 14:09:21 +01:00
|
|
|
VirtualConsole::switch_to(0);
|
2018-10-30 15:33:37 +01:00
|
|
|
|
2018-10-31 20:10:39 +01:00
|
|
|
kprintf("Starting Serenity Operating System...\n");
|
|
|
|
|
2018-10-22 11:15:16 +02:00
|
|
|
MemoryManager::initialize();
|
|
|
|
PIT::initialize();
|
|
|
|
|
2019-02-17 08:40:30 +01:00
|
|
|
new BXVGADevice;
|
2019-02-06 10:17:26 +01:00
|
|
|
|
2019-03-10 15:25:33 +01:00
|
|
|
auto e1000 = E1000NetworkAdapter::autodetect();
|
|
|
|
|
2019-02-25 12:43:52 +01:00
|
|
|
Retained<ProcFS> new_procfs = ProcFS::create();
|
2019-02-03 12:33:11 +01:00
|
|
|
new_procfs->initialize();
|
2018-10-26 17:42:12 +02:00
|
|
|
|
2019-01-30 00:49:20 +01:00
|
|
|
auto devptsfs = DevPtsFS::create();
|
|
|
|
devptsfs->initialize();
|
|
|
|
|
2018-11-01 13:15:46 +01:00
|
|
|
Process::initialize();
|
2019-03-23 22:03:17 +01:00
|
|
|
Thread::initialize();
|
2018-12-24 23:10:48 +01:00
|
|
|
Process::create_kernel_process("init_stage2", init_stage2);
|
|
|
|
Process::create_kernel_process("syncd", [] {
|
|
|
|
for (;;) {
|
|
|
|
Syscall::sync();
|
2019-03-24 01:52:10 +01:00
|
|
|
current->sleep(1 * TICKS_PER_SECOND);
|
2018-12-24 23:10:48 +01:00
|
|
|
}
|
|
|
|
});
|
2019-02-06 18:45:21 +01:00
|
|
|
Process::create_kernel_process("Finalizer", [] {
|
|
|
|
g_finalizer = current;
|
2019-03-23 22:03:17 +01:00
|
|
|
current->process().set_priority(Process::LowPriority);
|
2019-02-06 18:45:21 +01:00
|
|
|
for (;;) {
|
2019-03-23 22:03:17 +01:00
|
|
|
Thread::finalize_dying_threads();
|
|
|
|
current->block(Thread::BlockedLurking);
|
2019-02-06 18:45:21 +01:00
|
|
|
Scheduler::yield();
|
|
|
|
}
|
|
|
|
});
|
2019-03-11 12:43:45 +01:00
|
|
|
Process::create_kernel_process("NetworkTask", NetworkTask_main);
|
2018-12-20 02:41:55 +01:00
|
|
|
|
2018-11-07 22:15:02 +01:00
|
|
|
Scheduler::pick_next();
|
2018-10-22 11:15:16 +02:00
|
|
|
|
|
|
|
sti();
|
|
|
|
|
2018-11-01 13:15:46 +01:00
|
|
|
// This now becomes the idle process :^)
|
2018-10-16 11:01:38 +02:00
|
|
|
for (;;) {
|
|
|
|
asm("hlt");
|
|
|
|
}
|
|
|
|
}
|