From da90bcc1649e6517f9e41d3372b34580fb8941fd Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 20 Jun 2005 22:00:00 -0400 Subject: [PATCH] Import backup from 2005-06-20 --- Makefile | 29 +++++++-------- build.txt | 2 ++ kernel/Makefile | 5 +-- kernel/Makefile.bak | 83 +++++++++++++++++++++++++++++++++++++++++++ kernel/devices.h | 5 +-- kernel/display/kout.c | 4 +-- kernel/fs/ext2.cpp | 31 ++++++++++++++++ kernel/fs/ext2.h | 9 ++--- kernel/fs/vfs.cpp | 54 ++++++++++++++++++++++++++-- kernel/fs/vfs.h | 9 +++++ kernel/kernel.c | 3 +- kernel/link.ld | 7 +--- 12 files changed, 204 insertions(+), 37 deletions(-) create mode 100644 build.txt create mode 100644 kernel/Makefile.bak diff --git a/Makefile b/Makefile index 856e798..b228031 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ UMOUNT=sudo umount # Do not print "Entering directory ..." MAKEFLAGS += --no-print-directory -.PHONY: all clean initrd apps grub_image install install_img +.PHONY: all clean initrd apps grub_image install install_img depend copy_image all: make -C kernel @@ -47,22 +47,16 @@ grub_image: rm grub_commands.tmp rm grub_image_device.map.tmp -install: - gzip -c $(INITRD) > $(INITRD).gz - -mkdir $(FLOPPY_MOUNT) - $(MOUNT) -t ext2 $(DEVICE) $(FLOPPY_MOUNT) - -cp kernel/kernel.bin $(FLOPPY_MOUNT) - -cp rmmod/rmmod.bin $(FLOPPY_MOUNT) - -cp menu.lst $(FLOPPY_MOUNT)/boot/grub - -cp $(INITRD).gz $(FLOPPY_MOUNT)/$(INITRD).gz - $(UMOUNT) $(FLOPPY_MOUNT) - -rmdir $(FLOPPY_MOUNT) - -install_img: - gzip -c $(INITRD) > $(INITRD).gz - -mkdir $(FLOPPY_MOUNT) +copy_image: cp $(GRUB_IMAGE) $(FLOPPY_IMAGE) - $(MOUNT) -t ext2 -o loop $(FLOPPY_IMAGE) $(FLOPPY_MOUNT) + +install: FDEV=$(FLOPPY) +install_img: FDEV=$(FLOPPY_IMAGE) +install_img: MOUNT_FLAGS=-o loop +install_img: copy_image +install install_img: + -mkdir $(FLOPPY_MOUNT) + $(MOUNT) -t ext2 $(MOUNT_FLAGS) $(FDEV) $(FLOPPY_MOUNT) -cp kernel/kernel.bin $(FLOPPY_MOUNT) -cp rmmod/rmmod.bin $(FLOPPY_MOUNT) -cp menu.lst $(FLOPPY_MOUNT)/boot/grub @@ -78,7 +72,10 @@ initrd: cp -Pr $(INITRD_DIR)/* $(INITRD_MOUNT) $(UMOUNT) $(INITRD_MOUNT) rm -rf $(INITRD_MOUNT) + gzip -c $(INITRD) > $(INITRD).gz +depend: + make -C kernel depend wordcount: find . -regex '\(.*\.[ch]\)\|\(.*\.asm\)\|\(.*\.inc\)\|\(.*\.cpp\)' | xargs cat | wc diff --git a/build.txt b/build.txt new file mode 100644 index 0000000..dc1841a --- /dev/null +++ b/build.txt @@ -0,0 +1,2 @@ +To build the HOS kernel, just run 'make' +To build a HOS floppy image for bochs, run 'make initrd' and 'make install_img' as root (root permissions needed to mount floppy image) diff --git a/kernel/Makefile b/kernel/Makefile index b232c9e..ccf42b9 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -70,8 +70,9 @@ char/keyboard.o: lang/conv.h display/kout.h display/display.h devices.h lang/lang.o: lang/lang.h hos_defines.h lang/string.o: lang/string.h lang/lang.h hos_defines.h lang/new.o: hos_defines.h mm/vmm.h multiboot.h -fs/vfs.o: hos_defines.h display/kout.h fs/vfs.h lang/vector.h lang/string.h -fs/vfs.o: devices.h +fs/vfs.o: hos_defines.h display/kout.h fs/vfs.h fs/ext2.h lang/vector.h +fs/vfs.o: lang/string.h devices.h +fs/ext2.o: fs/ext2.h fs/vfs.h char/misc_char.o: hos_defines.h devices.h char/misc_char.h sys/io.h block/ramdisk.o: functions.h hos_defines.h sys/io.h mm/vmm.h multiboot.h block/ramdisk.o: lang/lang.h block/ramdisk.h devices.h diff --git a/kernel/Makefile.bak b/kernel/Makefile.bak new file mode 100644 index 0000000..ccf42b9 --- /dev/null +++ b/kernel/Makefile.bak @@ -0,0 +1,83 @@ +# Makefile for HOS +# Josh Holtrop +# Created: 07/08/04 +# Modified: 06/13/05 + +# Assembler Information: +NASM=nasm +NASM_FLAGS=-f aout + +# C/C++ Information: +CPPFLAGS=-fleading-underscore -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -I. -Wall +CC=gcc +CXX=g++ +CXXFLAGS=-fno-rtti -fno-exceptions + +# Linker Information: +LD=ld +LDFLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld + +# Files +OBJS=boot.o kernel.o lang/lang_a.o mm/mm.o mm/vmm.o lang/conv.o \ + display/kout.o char/vconsole.o display/display.o devices.o \ + sys/pic.o char/keyboard.o block/ramdisk.o fs/vfs.o \ + lang/lang.o lang/string.o lang/new.o fs/ext2.o char/misc_char.o +CSRC=kernel.c mm/mm.c mm/vmm.c lang/conv.c display/kout.c display/display.c sys/pic.c char/keyboard.c lang/lang.c +CXXSRC=lang/string.cpp lang/new.cpp fs/vfs.cpp fs/ext2.cpp char/misc_char.cpp block/ramdisk.cpp char/vconsole.cpp devices.cpp + +.PHONY: all depend clean html + +all: $(OBJS) + $(LD) $(LDFLAGS) -Map kernel.map $(OBJS) -o kernel.bin + @echo ' Kernel built: ' `ls -sk kernel.bin | cut -d' ' -f1`kb + +depend: + makedepend -- $(CPPFLAGS) -- $(CSRC) $(CXXSRC) + +boot.o: boot.asm + $(NASM) $(NASM_FLAGS) -l boot.lst boot.asm -o boot.o + +lang/lang_a.o: lang/lang.asm + $(NASM) $(NASM_FLAGS) -l lang.lst lang/lang.asm -o lang/lang_a.o + +clean: + -rm -f $(OBJS) *.bin *.map *.lst *.out *~ fs/*~ sys/*~ block/*~ char/*~ lang/*~ mm/*~ display/*~ + +html: + -rm -rf html + -mkdir html + source-highlight --output-dir=html -f xhtml -n $(CSRC) $(CXXSRC) + +# The following is used by 'make' to automatically +# generate dependency information +# DO NOT DELETE + +kernel.o: kernel.h hos_defines.h multiboot.h module.h lang/lang.h functions.h +kernel.o: sys/io.h mm/mm.h mm/vmm.h lang/conv.h devices.h display/display.h +kernel.o: display/kout.h sys/pic.h char/keyboard.h block/ramdisk.h fs/vfs.h +kernel.o: fs/ext2.h fs/vfs.h +mm/mm.o: kernel.h hos_defines.h multiboot.h mm/mm.h +mm/vmm.o: hos_defines.h kernel.h multiboot.h mm/vmm.h lang/lang.h mm/mm.h +lang/conv.o: lang/conv.h hos_defines.h +display/kout.o: hos_defines.h display/kout.h lang/conv.h devices.h +display/kout.o: char/misc_char.h char/misc_char.h +display/display.o: devices.h hos_defines.h char/vconsole.h display/display.h +display/display.o: lang/lang.h kernel.h multiboot.h display/vesafb.h +display/display.o: char/keyboard.h display/kout.h +sys/pic.o: hos_defines.h sys/pic.h sys/io.h +char/keyboard.o: hos_defines.h char/keyboard.h sys/io.h functions.h +char/keyboard.o: lang/conv.h display/kout.h display/display.h devices.h +lang/lang.o: lang/lang.h hos_defines.h +lang/string.o: lang/string.h lang/lang.h hos_defines.h +lang/new.o: hos_defines.h mm/vmm.h multiboot.h +fs/vfs.o: hos_defines.h display/kout.h fs/vfs.h fs/ext2.h lang/vector.h +fs/vfs.o: lang/string.h devices.h +fs/ext2.o: fs/ext2.h fs/vfs.h +char/misc_char.o: hos_defines.h devices.h char/misc_char.h sys/io.h +block/ramdisk.o: functions.h hos_defines.h sys/io.h mm/vmm.h multiboot.h +block/ramdisk.o: lang/lang.h block/ramdisk.h devices.h +char/vconsole.o: hos_defines.h mm/vmm.h multiboot.h lang/lang.h +char/vconsole.o: display/display.h devices.h functions.h sys/io.h +char/vconsole.o: char/vconsole.h +devices.o: hos_defines.h devices.h char/misc_char.h char/misc_char.h +devices.o: char/vconsole.h block/ramdisk.h diff --git a/kernel/devices.h b/kernel/devices.h index b1e2eb7..4e2cc75 100644 --- a/kernel/devices.h +++ b/kernel/devices.h @@ -20,8 +20,9 @@ #define BLOCK_SIZE 512 #define BLOCK_SIZE_LOG 9 -#define DEV_MAJOR (x) (((x) >> 8) & 0xFF) -#define DEV_MINOR (x) ((x) & 0xFF) +#define DEV_MAJOR(x) (((x) >> 8) & 0xFF) +#define DEV_MINOR(x) ((x) & 0xFF) +#define DEV(x,y) ((x) << 8 | (y)) typedef short major_t; typedef short minor_t; diff --git a/kernel/display/kout.c b/kernel/display/kout.c index 1a3351a..5858233 100644 --- a/kernel/display/kout.c +++ b/kernel/display/kout.c @@ -14,9 +14,9 @@ char buffer[64]; // for hex/oct/dec/ascii conversion // print a character void putc(int c) { - #ifdef PARALLEL_DEBUG +#ifdef PARALLEL_DEBUG char_write(MAJOR_MISC_CHAR, MISC_CHAR_LP0, c); - #endif +#endif char_write(MAJOR_VCONSOLE, KERNEL_MSG_CONSOLE, c); // write to vconsole with minor 1, first allocated } diff --git a/kernel/fs/ext2.cpp b/kernel/fs/ext2.cpp index 19f11c9..35d8260 100644 --- a/kernel/fs/ext2.cpp +++ b/kernel/fs/ext2.cpp @@ -4,3 +4,34 @@ // Date: 05/10/05 // Modified: 05/10/05 +#define _HOS_CPP_ _HOS_CPP_ + +extern "C" { +#include "display/kout.h" +} + +#include "ext2.h" + +Ext2fs::Ext2fs(device_t dev) +{ + myDevice = dev; + if (block_read(DEV_MAJOR(dev), DEV_MINOR(dev), 2, 2, &mySuper) < 1024) + { + myError = -1; + return; + } + if (mySuper.s_magic != EXT2_MAGIC) + { + myError = -2; + return; + } + myError = 0; + mySuperDirty = 0; + kprintf("Device: %d\n", myDevice); +} + +Ext2fs::~Ext2fs() +{ + if (mySuperDirty) + block_write(DEV_MAJOR(myDevice), DEV_MINOR(myDevice), 2, 2, &mySuper); +} diff --git a/kernel/fs/ext2.h b/kernel/fs/ext2.h index 13a0e95..6187960 100644 --- a/kernel/fs/ext2.h +++ b/kernel/fs/ext2.h @@ -138,15 +138,16 @@ typedef struct char name[EXT2_NAME_LEN]; } ext2_dir_entry_t; - #ifdef _HOS_CPP_ -class Ext2 : public FileSystem +class Ext2fs : public FileSystem { protected: - + ext2_super_block_t mySuper; + int mySuperDirty; public: - + Ext2fs(device_t dev); + ~Ext2fs(); }; #endif diff --git a/kernel/fs/vfs.cpp b/kernel/fs/vfs.cpp index f896194..7cb51da 100644 --- a/kernel/fs/vfs.cpp +++ b/kernel/fs/vfs.cpp @@ -12,6 +12,7 @@ extern "C" { } #include "vfs.h" +#include "ext2.h" #include "lang/vector.h" #include "lang/string.h" #include "devices.h" @@ -29,10 +30,43 @@ int vfs_mount(device_t device, int fsType, char *mountPoint) { string mountPt(mountPoint); if (mountPt == "/") + { + if (mountPoints->size()) + { + kprintf("/ must be the first filesystem mounted!\n"); + return -1; + } + FileSystem *fs = vfs_attempt_mount(device, fsType); + if (fs == NULL) + return -2; + rootInode = fs->getRootInodeNumber(); + mountPoints->add(VFSMount(device, fs, mountPt, 0)); + return 0; + } + else { } - return 0; + return 500; +} + +FileSystem *vfs_attempt_mount(device_t device, int fsType) +{ + FileSystem *fs; + switch (fsType) + { + case FS_EXT2: + fs = new Ext2fs(device); + break; + default: + return NULL; + } + if (fs->check()) + { + delete fs; + return NULL; + } + return fs; } VFSMount::VFSMount(device_t dev, FileSystem *fs, string mountPoint, inode_num_t mountInode) @@ -47,7 +81,21 @@ VFSMount::VFSMount(device_t dev, FileSystem *fs, string mountPoint, inode_num_t VFSMount::~VFSMount() { if (myFS) + { delete myFS; - if (myRefs) - kprintf("Filesystem uncleanly mounted from %s\n", myMountPoint.data()); + if (myRefs) + kprintf("Filesystem uncleanly mounted from %s\n", myMountPoint.data()); + } } + +FileSystem::FileSystem() {myError = -10278;} +FileSystem::~FileSystem() {} +u32_t FileSystem::totalBlocks(){return 0;} +u32_t FileSystem::usedBlocks(){return 0;}; +u32_t FileSystem::freeBlocks(){return 0;}; +u32_t FileSystem::totalInodes(){return 0;}; +u32_t FileSystem::usedInodes(){return 0;}; +u32_t FileSystem::freeInodes(){return 0;}; +u32_t FileSystem::getRootInodeNumber(){return 0;}; +int FileSystem::check(){return myError;}; + diff --git a/kernel/fs/vfs.h b/kernel/fs/vfs.h index 6b76661..2fe4c51 100644 --- a/kernel/fs/vfs.h +++ b/kernel/fs/vfs.h @@ -8,6 +8,7 @@ #define __HOS_VFS_H__ __HOS_VFS_H__ #define FS_EXT2 1 +#define FS_MAX 5 #define VFS_FT_UNKNOWN 0 #define VFS_FT_FILE 1 @@ -52,7 +53,11 @@ int vfs_mount(device_t device, int fsType, char *mountPoint); class FileSystem { +protected: + int myError; + device_t myDevice; public: + FileSystem(); FileSystem(device_t dev); virtual ~FileSystem(); @@ -65,6 +70,8 @@ public: virtual u32_t freeInodes(); virtual u32_t getRootInodeNumber(); + + virtual int check(); }; class VFSMount @@ -81,6 +88,8 @@ public: ~VFSMount(); }; +FileSystem *vfs_attempt_mount(device_t device, int fsType); + #endif #endif diff --git a/kernel/kernel.c b/kernel/kernel.c index e2c4fbc..f2fe42e 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -12,7 +12,6 @@ #include "mm/mm.h" #include "mm/vmm.h" #include "lang/conv.h" -//#include "char/vconsole.h" #include "devices.h" #include "display/display.h" #include "display/kout.h" @@ -142,7 +141,7 @@ void k_init() // we found an initrd minor_t initrd_minor = ramdisk_register((void *)mb_modules[i].mod_start, mb_modules[i].mod_end - mb_modules[i].mod_start); kprintf("initrd (%dkb) loaded\n", (mb_modules[i].mod_end - mb_modules[i].mod_start) >> 10); - k_check(vfs_mount((MAJOR_RAMDISK << 8) | initrd_minor, FS_EXT2, "/"), "Could not mount initrd to /!"); + k_check(vfs_mount(DEV(MAJOR_RAMDISK, initrd_minor), FS_EXT2, "/"), "Could not mount initrd to /!"); } } diff --git a/kernel/link.ld b/kernel/link.ld index a9dafac..03e3617 100644 --- a/kernel/link.ld +++ b/kernel/link.ld @@ -5,7 +5,6 @@ SECTIONS .text 0xC0108000 : { code = .; _code = .; __code = .; *(.text) -/* . = ALIGN(4096); */ } .gnulinkonce : { *(.gnu.linkonce*) @@ -14,13 +13,9 @@ SECTIONS .data : { data = .; _data = .; __data = .; *(.data) -/* . = ALIGN(4096); */ - } - .rodata : { - rodata = .; _rodata = .; __rodata = .; *(.rodata) + . = ALIGN(4096); } - . = ALIGN(4096); .bss : { bss = .; _bss = .; __bss = .; *(.bss)