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