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"
|
|
|
|
#include "CMOS.h"
|
2018-10-16 15:17:43 +03:00
|
|
|
#include "IDEDiskDevice.h"
|
2018-12-25 00:59:10 +03:00
|
|
|
#include "KSyms.h"
|
2018-10-16 15:33:16 +03:00
|
|
|
#include <VirtualFileSystem/NullDevice.h>
|
|
|
|
#include <VirtualFileSystem/ZeroDevice.h>
|
|
|
|
#include <VirtualFileSystem/FullDevice.h>
|
|
|
|
#include <VirtualFileSystem/RandomDevice.h>
|
2018-10-17 11:55:43 +03:00
|
|
|
#include <VirtualFileSystem/Ext2FileSystem.h>
|
2018-10-17 12:44:06 +03:00
|
|
|
#include <VirtualFileSystem/VirtualFileSystem.h>
|
2018-10-18 00:13:55 +03:00
|
|
|
#include "MemoryManager.h"
|
2018-10-23 12:57:38 +03:00
|
|
|
#include "ProcFileSystem.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"
|
2018-10-16 12:01:38 +03:00
|
|
|
|
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;
|
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-11-15 16:43:10 +03:00
|
|
|
auto vfs = make<VFS>();
|
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
|
|
|
|
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);
|
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();
|
2018-11-15 19:13:10 +03:00
|
|
|
auto e2fs = Ext2FS::create(dev_hd0.copyRef());
|
2018-10-22 12:15:16 +03:00
|
|
|
e2fs->initialize();
|
2018-10-17 11:55:43 +03:00
|
|
|
|
2018-11-15 17:10:12 +03:00
|
|
|
vfs->mount_root(e2fs.copyRef());
|
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");
|
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-09 00:28:11 +03:00
|
|
|
Process::create_user_process("/bin/sh", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0);
|
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-09 04:29:11 +03:00
|
|
|
extern void WindowComposer_main();
|
|
|
|
Process::create_kernel_process("WindowComposer", WindowComposer_main);
|
|
|
|
|
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();
|
|
|
|
|
2018-10-30 17:33:37 +03:00
|
|
|
keyboard = new Keyboard;
|
2019-01-11 04:28:53 +03:00
|
|
|
ps2mouse = new PS2MouseDevice;
|
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();
|
|
|
|
|
2018-11-15 17:10:12 +03:00
|
|
|
VFS::initialize_globals();
|
2018-12-21 04:10:45 +03:00
|
|
|
StringImpl::initialize_globals();
|
2018-10-22 14:10:08 +03:00
|
|
|
|
2018-10-22 12:15:16 +03:00
|
|
|
PIT::initialize();
|
|
|
|
|
|
|
|
memset(&system, 0, sizeof(system));
|
2018-10-25 18:29:49 +03:00
|
|
|
|
2018-11-17 02:11:08 +03:00
|
|
|
word base_memory = (CMOS::read(0x16) << 8) | CMOS::read(0x15);
|
|
|
|
word ext_memory = (CMOS::read(0x18) << 8) | CMOS::read(0x17);
|
2018-10-22 12:15:16 +03:00
|
|
|
|
|
|
|
kprintf("%u kB base memory\n", base_memory);
|
|
|
|
kprintf("%u kB extended memory\n", ext_memory);
|
|
|
|
|
2018-11-15 19:13:10 +03:00
|
|
|
auto procfs = ProcFS::create();
|
2018-10-26 18:42:12 +03:00
|
|
|
procfs->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);
|
|
|
|
}
|
|
|
|
});
|
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");
|
|
|
|
}
|
|
|
|
}
|