⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os.c.virtual

📁 一款类linux的操作系统源码
💻 VIRTUAL
字号:
/*  *  Roadrunner/pk *    Copyright (C) 1989-2001  Cornfed Systems, Inc. * *  The Roadrunner/pk operating system is free software; you can *  redistribute and/or modify it under the terms of the GNU General *  Public License, version 2, as published by the Free Software *  Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public *  License along with this program; if not, write to the Free *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, *  MA 02111-1307 USA * *  More information about the Roadrunner/pk operating system of *  which this file is a part is available on the World-Wide Web *  at: http://www.cornfed.com. * */#if _PCI#include <bus/pci.h>#endif#include <dev.h>#include <dev/cons.h>#include <dev/fd.h>#include <dev/gd.h>#if _LANCE#include <dev/lnc.h>#endif#if _NE2000#include <dev/ne.h>#endif#if _SERIAL_PORTS#include <dev/serial.h>#endif#include <dev/wd.h>#include <event.h>#include <fcntl.h>#include <fs.h>#include <fs/devfs.h>#include <fs/rrfs.h>#include <fs/sysfs.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/boot.h>#include <sys/intr.h>#include <sys/mem.h>#include <sys/timer.h>#include <sys/utsname.h>extern char *initkstk;void cpuid();voidos(){    struct utsname name;    struct dev_ops devops;    struct fsops fsops;    fsops_t sysfsops, devfsops, rrfsops;    fs_t sysfs, devfs, rrfs;    file_t fdin = NULL, fdout = NULL, fderr = NULL;    int result;    intr_init();#if 0    gd_init();#endif    clear_screen();    uname(&name);    kprintf("%s %s.%s %s\n",	    name.sysname, name.version, name.release, COPYRIGHT);    get_boot_params();    cpuid();    mem_init();    vm_init();    isrtab_init();    eventtab_init();    proc_sysinit();    time_init();    timer_init();    devtab_init();    blkpool_init(PAGE_SIZE, BLKS);    bufpool_init(BUFS);    fstab_init();    /* Setup context for init process */    proctab[0].state = PS_RUN;    strcpy(proctab[0].cwd, "/");    /* Init process never leaves kernel mode */    ktssinit(proctab[0].context.tss, (u_long) initkstk, STACK_SIZE);    /* Attach a set of page tables to init process */    proctab[0].context.ptrec = pt_pop();    proctab[0].context.tss->cr3 = (u_long) proctab[0].context.ptrec->pd;    /* Setup page tables for init process */    vm_map_init((pt_t) proctab[0].context.tss->cr3);    vm_kmap((pt_t) proctab[0].context.tss->cr3);    /* Turn paging on */    vm_enable(proctab[0].context.tss->cr3);    /* Load task register with first TSS descriptor */    ltr((u_long) tssdesctab - (u_long) gdt);    /* Init process is made currently executing process */    current = &(proctab[0]);    kprintf("real mem %d\n", (int) memsize);    kprintf("kernel size %d\n", (int) kernsize);    {	region_t r;	size_t freemem = 0;	for (r = freelist; r != NULL; r = r->next)	    freemem += r->len;	kprintf("avail mem %d\n", (int) freemem);    }#if _PCI    /* Scan for PCI devices */    pci_init();#endif    /* Install console devices */    devops.init = cons0_init;    devops.shut = cons0_shut;    devops.ioctl = cons0_ioctl;    devops.specific.char_ops.get = cons0_get;    devops.specific.char_ops.put = cons0_put;    dev_inst("cons0", DEV_TYPE_CHAR, &devops);    dev_init("cons0");    devops.init = cons1_init;    devops.shut = cons1_shut;    devops.ioctl = cons1_ioctl;    devops.specific.char_ops.get = cons1_get;    devops.specific.char_ops.put = cons1_put;    dev_inst("cons1", DEV_TYPE_CHAR, &devops);    devops.init = cons2_init;    devops.shut = cons2_shut;    devops.ioctl = cons2_ioctl;    devops.specific.char_ops.get = cons2_get;    devops.specific.char_ops.put = cons2_put;    dev_inst("cons2", DEV_TYPE_CHAR, &devops);    devops.init = cons3_init;    devops.shut = cons3_shut;    devops.ioctl = cons3_ioctl;    devops.specific.char_ops.get = cons3_get;    devops.specific.char_ops.put = cons3_put;    dev_inst("cons3", DEV_TYPE_CHAR, &devops);#if _SERIAL_PORTS    /* Install primary serial device */    devops.init = s0_init;    devops.shut = s0_shut;    devops.ioctl = s0_ioctl;    devops.specific.char_ops.get = s0_get;    devops.specific.char_ops.put = s0_put;    dev_inst("s0", DEV_TYPE_CHAR, &devops);    dev_init("s0");    /* Install alternate serial device */    devops.init = s1_init;    devops.shut = s1_shut;    devops.ioctl = s1_ioctl;    devops.specific.char_ops.get = s1_get;    devops.specific.char_ops.put = s1_put;    dev_inst("s1", DEV_TYPE_CHAR, &devops);    dev_init("s1");#endif    /* Install floppy disk device */    devops.init = fd_init;    devops.shut = fd_shut;    devops.ioctl = fd_ioctl;    devops.specific.blk_ops.read = fd_read;    devops.specific.blk_ops.write = fd_write;    dev_inst("fd", DEV_TYPE_BLK, &devops);    /* Install hard disk device */    devops.init = wd_init;    devops.shut = wd_shut;    devops.ioctl = wd_ioctl;    devops.specific.blk_ops.read = wd_read;    devops.specific.blk_ops.write = wd_write;    dev_inst("wd0", DEV_TYPE_BLK, &devops);    result = dev_init("wd0");    if (result < 0) {#if _DEBUG	kprintf("os: wd0 init failed (%s)\n", strerror(result));#endif	dev_uninst("wd0");    }    /* Install and initialize /sys file system */    strcpy(fsops.name, "sysfs");    fsops.init = sysfs_init;    fsops.shut = sysfs_shut;    fsops.mount = sysfs_mount;    fsops.unmount = sysfs_unmount;    fsops.open = sysfile_open;    fsops.close = sysfile_close;    fsops.ioctl = sysfile_ioctl;    fsops.read = sysfile_read;    fsops.write = sysfile_write;    fsops.attr = sysfile_attr;    fsops.readdir = sysfile_readdir;    fsops.unlink = sysfile_unlink;    sysfsops = fsops_inst(&fsops);    fsops_init(sysfsops);    /* Install and initialize device file system */    strcpy(fsops.name, "devfs");    fsops.init = devfs_init;    fsops.shut = devfs_shut;    fsops.mount = devfs_mount;    fsops.unmount = devfs_unmount;    fsops.open = devfile_open;    fsops.close = devfile_close;    fsops.ioctl = devfile_ioctl;    fsops.read = devfile_read;    fsops.write = devfile_write;    fsops.attr = devfile_attr;    fsops.readdir = devfile_readdir;    fsops.unlink = devfile_unlink;    devfsops = fsops_inst(&fsops);    fsops_init(devfsops);    /* Install and initialize rrfs file system */    strcpy(fsops.name, "rrfs");    fsops.init = rrfs_init;    fsops.shut = rrfs_shut;    fsops.mount = rrfs_mount;    fsops.unmount = rrfs_unmount;    fsops.open = rrfile_open;    fsops.close = rrfile_close;    fsops.ioctl = rrfile_ioctl;    fsops.read = rrfile_read;    fsops.write = rrfile_write;    fsops.attr = rrfile_attr;    fsops.readdir = rrfile_readdir;    fsops.unlink = rrfile_unlink;    rrfsops = fsops_inst(&fsops);    fsops_init(rrfsops);    /* Mount /sys file system */    fs_mount(sysfsops, "/sys", (-1), &sysfs);    /* Mount device file system */    fs_mount(devfsops, "/dev", (-1), &devfs);    /* Initialize root device and mount root file system */    if (bootparams.drv & BP_DRV_WD) {	char s[8];	sprintf(s, "wd0%c", (char) (bootparams.part + 'a'));#if _DEBUG	kprintf("os: root file system on /dev/%s\n", s);#endif	fs_mount(rrfsops, "/", dev_open(s), &rrfs);    } else {	dev_init("fd");	fs_mount(rrfsops, "/", dev_open("fd"), &rrfs);    }    /* Setup stdpaths for init process */    result = file_open("/dev/cons0", O_RDONLY, &fdin);    if (result < 0) {#if _DEBUG	kprintf("os: open /dev/cons0 for stdin failed (%s)\n",		strerror(result));#endif    }    file_open("/dev/cons0", O_WRONLY, &fdout);    if (result < 0) {#if _DEBUG	kprintf("os: open /dev/cons0 for stdout failed (%s)\n",		strerror(result));#endif    }    file_open("/dev/cons0", O_WRONLY, &fderr);    if (result < 0) {#if _DEBUG	kprintf("os: open /dev/cons0 for stderr failed (%s)\n",		strerror(result));#endif    }    proctab[0].fd[PFD_STDIN] = fdin->slot;    proctab[0].fd[PFD_STDOUT] = fdout->slot;    proctab[0].fd[PFD_STDERR] = fderr->slot;    /* Initialize network protocols */    net_start();#if _LANCE    lnc_init();#endif#if _NE2000    ne_init();#endif    /* Start command shells for each console */    proc_exec("/bin/sh", 0, NULL);#if 0#if _SERIAL_PORTS    /* Start a command shell for the primary serial port */#define ARGS "/bin/sh -stdin /dev/s0 -stdout /dev/s0 -stderr /dev/s0"    if (vfork() == 0)	execve(ARGS, NULL, NULL);#endif#endif    enable;    for (;;);    /* Not reached */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -