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