140 lines
2.9 KiB
C
140 lines
2.9 KiB
C
#include "multiboot.h"
|
|
#include "console.h"
|
|
#include "gdt.h"
|
|
#include "interrupts.h"
|
|
#include "memory.h"
|
|
#include "keyboard.h"
|
|
#include "ramdisk.h"
|
|
#include "sfs.h"
|
|
#include "pci.h"
|
|
#include "schedule.h"
|
|
#include "timer.h"
|
|
#include "syscalls.h"
|
|
#include "pata.h"
|
|
#include "mouse.h"
|
|
#include "fpu.h"
|
|
#include "ether.h"
|
|
#include "ipv4.h"
|
|
#include "string.h"
|
|
#include "serial.h"
|
|
|
|
extern struct task_t *current_task;
|
|
|
|
char *system_disk;
|
|
|
|
void abort(void) {
|
|
kprintf("Abort.\n");
|
|
while(1);
|
|
}
|
|
|
|
void abort_on_usage(void * m) {
|
|
kprintf("Abort on Usage error");
|
|
while(1);
|
|
}
|
|
|
|
void abort_on_corruption(void * m) {
|
|
kprintf("Abort on Corruption");
|
|
while(1);
|
|
}
|
|
|
|
void cli(void) {
|
|
__asm__ __volatile__("cli");
|
|
}
|
|
|
|
void sti(void) {
|
|
__asm__ __volatile__("sti");
|
|
}
|
|
|
|
void init(void) {
|
|
int ret;
|
|
char *sys_disk_env = (char *)malloc(strlen(system_disk) + 5);
|
|
char *init_cmd = (char *)malloc(strlen(system_disk) + 10);
|
|
strcpy(sys_disk_env, "SYS=");
|
|
strcat(sys_disk_env, system_disk);
|
|
|
|
strcpy(init_cmd, system_disk);
|
|
strcat(init_cmd, "/init.exe");
|
|
|
|
__asm__ volatile ("int $0x30" : "=a" (ret) : "0" (SYS_OPEN), "b" ("console:/"), "c" (O_RDWR), "d" (0));
|
|
__asm__ volatile ("int $0x30" : "=a" (ret) : "0" (SYS_OPEN), "b" ("console:/"), "c" (O_RDWR), "d" (0));
|
|
__asm__ volatile ("int $0x30" : "=a" (ret) : "0" (SYS_OPEN), "b" ("console:/"), "c" (O_RDWR), "d" (0));
|
|
static char *argv[] = {"init.exe", (void *)0};
|
|
static char *envp[4];
|
|
|
|
envp[0] = (char *)malloc(8);
|
|
strcpy(envp[0], "HOME=/");
|
|
envp[1] = (char *)malloc(8);
|
|
strcpy(envp[1], "PATH=/");
|
|
envp[2] = (char *)malloc(strlen(sys_disk_env) + 1);
|
|
strcpy(envp[2], sys_disk_env);
|
|
envp[3] = (void *)0;
|
|
|
|
__asm__ volatile ("int $0x30" : "=a" (ret) : "0" (11), "b" (init_cmd), "c" (argv),"d" (envp));
|
|
while (1);
|
|
}
|
|
|
|
extern struct vfs_device_t *consoletty;
|
|
|
|
void kmain(void) {
|
|
extern unsigned int magic;
|
|
extern void *mbd;
|
|
char *cmd_line;
|
|
multiboot_info_t *mbinfo = (multiboot_info_t *)mbd;
|
|
int ret;
|
|
struct vfs_device_t *rd;
|
|
int fs_type;
|
|
|
|
|
|
init_serial();
|
|
init_mem(mbinfo);
|
|
init_paging();
|
|
|
|
init_gdt();
|
|
init_idt();
|
|
init_isrs();
|
|
|
|
init_scheduler();
|
|
|
|
init_gui(mbinfo);
|
|
init_console();
|
|
|
|
if (magic != 0x2BADB002) {
|
|
kprintf("WARNING: Invalid Magic Number\n");
|
|
}
|
|
init_fpu();
|
|
init_irqs();
|
|
init_keyboard();
|
|
init_vfs();
|
|
init_pci();
|
|
init_pata();
|
|
init_timer();
|
|
init_ipv4();
|
|
init_ether();
|
|
init_mouse();
|
|
init_syscalls();
|
|
if (init_ramdisk(mbinfo) == 1) {
|
|
fs_type = 1;
|
|
|
|
rd = (void *)0;
|
|
|
|
while(rd == (void *)0 && fs_type < 4) {
|
|
rd = vfs_register_device(1, "ramdisk", fs_type);
|
|
fs_type++;
|
|
}
|
|
}
|
|
cmd_line = mbinfo->cmdline;
|
|
system_disk = (char *)malloc(strlen(cmd_line) + 1);
|
|
strcpy(system_disk, cmd_line);
|
|
consoletty = vfs_register_device(0, "console", 0);
|
|
kprintf("System Disk: %s\n", system_disk);
|
|
sti();
|
|
__asm__ volatile ("int $0x30" : "=a" (ret) : "0" (2));
|
|
if (!ret) {
|
|
init();
|
|
}
|
|
while (1) {
|
|
yield((void *)0);
|
|
__asm__ volatile ("hlt");
|
|
}
|
|
}
|