summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--init.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/init.go b/init.go
index f8746c3..6f81bf3 100644
--- a/init.go
+++ b/init.go
@@ -126,6 +126,7 @@ func initConfig() {
 	viper.SetDefault("ListenPort", 9001)
 	viper.SetDefault("LogFile", "getwtxt.log")
 	viper.SetDefault("DatabasePath", "getwtxt.db")
+	viper.SetDefault("AssetsDirectory", "assets")
 	viper.SetDefault("DatabaseType", "leveldb")
 	viper.SetDefault("StdoutLogging", false)
 	viper.SetDefault("ReCacheInterval", "1h")
@@ -156,7 +157,7 @@ func initConfig() {
 	log.Printf("Using %v database: %v\n", confObj.DBType, confObj.DBPath)
 
 	if *flagAssets == "" {
-		confObj.AssetsDir = "assets"
+		confObj.AssetsDir = viper.GetString("AssetsDirectory")
 	} else {
 		confObj.AssetsDir = *flagAssets
 	}
@@ -352,12 +353,19 @@ func helpScreen() {
 
                  :: Command Line Options ::
 
-Command Line Options:
+    Command line options are used to explicitly override defaults,
+ or what has been specified in the configuration file.
+
     -h [--help]      Print this help screen.
     -m [--manual]    Print the manual.
     -v [--version]   Print the version information and quit.
     -c [--config]    Path to an alternate configuration file
                        to use. May be relative or absolute.
+    -a [--assets]    Path to the assets directory, containing
+                       style.css and tmpl/index.html
+    -d [--db]        Path getwtxt should use for the database.
+    -t [--dbtype]    Type of database to use.
+                       Options: leveldb
 
 `)
 }
@@ -414,11 +422,22 @@ func manualScreen() {
     ListenPort: Defines the port getwtxt should bind to.
         Default: 9001
 
+    DatabaseType: The type of back-end getwtxt should use
+        to store registry data. Currently, only leveldb
+        is available, with more options in development.
+        Default: leveldb
+
     DatabasePath: The location of the LevelDB structure
         used by getwtxt to back up registry data. This
         can be a relative or absolute path.
         Default: getwtxt.db
 
+    AssetsDirectory: This is the directory where getwtxt
+        can find style.css and tmpl/index.html -- the
+        stylesheet for the landing page and the landing
+        page template, respectively.
+        Default: assets
+
     StdoutLogging: Boolean used to determine whether
         getwtxt should send logging output to stdout.
         This is useful for debugging, but you should
ef='#n161'>161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
#include "screen.h"
#include "descriptortables.h"
#include "timer.h"
#include "multiboot.h"
#include "fs.h"
#include "syscalls.h"
#include "serial.h"
#include "isr.h"
#include "vmm.h"
#include "alloc.h"
#include "process.h"
#include "keyboard.h"
#include "ttydriver.h"
#include "devfs.h"
#include "systemfs.h"
#include "pipe.h"
#include "sharedmemory.h"
#include "random.h"
#include "null.h"
#include "elf.h"
#include "debugprint.h"
#include "ramdisk.h"
#include "fatfilesystem.h"
#include "vbe.h"
#include "fifobuffer.h"
#include "gfx.h"
#include "mouse.h"
#include "sleep.h"

extern uint32 _start;
extern uint32 _end;
uint32 gPhysicalKernelStartAddress = (uint32)&_start;
uint32 gPhysicalKernelEndAddress = (uint32)&_end;

static void* locateInitrd(struct Multiboot *mbi, uint32* size) {
    if (mbi->mods_count > 0) {
        uint32 startLocation = *((uint32*)mbi->mods_addr);
        uint32 endLocation = *(uint32*)(mbi->mods_addr + 4);

        *size = endLocation - startLocation;

        return (void*)startLocation;
    }

    return NULL;
}

void printUsageInfo() {
    char buffer[164];

    sprintf(buffer, "Used kheap:%d", getKernelHeapUsed());
    Screen_Print(0, 60, buffer);

    sprintf(buffer, "Pages:%d/%d       ", getUsedPageCount(), getTotalPageCount());
    Screen_Print(1, 60, buffer);

    sprintf(buffer, "Uptime:%d sec   ", getUptimeSeconds());
    Screen_Print(2, 60, buffer);

    Thread* p = getMainKernelThread();

    int line = 3;
    sprintf(buffer, "[idle]   cs:%d   ", p->totalContextSwitchCount);
    Screen_Print(line++, 60, buffer);
    p = p->next;
    while (p != NULL) {
        sprintf(buffer, "thread:%d cs:%d   ", p->threadId, p->totalContextSwitchCount);

        Screen_Print(line++, 60, buffer);

        p = p->next;
    }
}

int executeFile(const char *path, char *const argv[], char *const envp[], FileSystemNode* tty) {
    int result = -1;

    Process* process = getCurrentThread()->owner;
    if (process) {
        FileSystemNode* node = getFileSystemNodeAbsoluteOrRelative(path, process);
        if (node) {
            File* f = open_fs(node, 0);
            if (f) {
                void* image = kmalloc(node->length);

                int32 bytesRead = read_fs(f, node->length, image);

                if (bytesRead > 0) {
                    Process* newProcess = createUserProcessFromElfData("userProcess", image, argv, envp, process, tty);

                    if (newProcess) {
                        result = newProcess->pid;
                    }
                }
                close_fs(f);

                kfree(image);
            }

        }
    }

    return result;
}

void printAsciiArt() {
    printkf("     ________       ________      ________       ________     \n");
    printkf("    |\\   ____\\     |\\   __  \\    |\\   ____\\     |\\   __  \\    \n");
    printkf("    \\ \\  \\___|_    \\ \\  \\|\\  \\   \\ \\  \\___|_    \\ \\  \\|\\  \\   \n");
    printkf("     \\ \\_____  \\    \\ \\  \\\\\\  \\   \\ \\_____  \\    \\ \\  \\\\\\  \\  \n");
    printkf("      \\|____|\\  \\    \\ \\  \\\\\\  \\   \\|____|\\  \\    \\ \\  \\\\\\  \\ \n");
    printkf("        ____\\_\\  \\    \\ \\_______\\    ____\\_\\  \\    \\ \\_______\\\n");
    printkf("       |\\_________\\    \\|_______|   |\\_________\\    \\|_______|\n");
    printkf("       \\|_________|                 \\|_________|              \n");
    printkf("\n");
}

int kmain(struct Multiboot *mboot_ptr) {
    int stack = 5;

    initializeDescriptorTables();

    initializeSerial();

    uint32 memoryKb = mboot_ptr->mem_upper;//96*1024;
    initializeMemory(memoryKb);

    initializeVFS();
    initializeDevFS();

    if (MULTIBOOT_FRAMEBUFFER_TYPE_RGB == mboot_ptr->framebuffer_type) {
        Gfx_Initialize((uint32*)(uint32)mboot_ptr->framebuffer_addr, mboot_ptr->framebuffer_width, mboot_ptr->framebuffer_height, mboot_ptr->framebuffer_bpp / 32, mboot_ptr->framebuffer_pitch);

        initializeTTYs(TRUE);
    }
    else {
        initializeTTYs(FALSE);
    }
    //printkf works after TTY initialization

    printAsciiArt();

    printkf("Lower Memory: %d KB\n", mboot_ptr->mem_lower);
    printkf("Upper Memory: %d KB\n", mboot_ptr->mem_upper);
    printkf("Memory initialized for %d MB\n", memoryKb / 1024);
    printkf("Kernel start: %x - end:%x\n", gPhysicalKernelStartAddress, gPhysicalKernelEndAddress);
    printkf("Initial stack: %x\n", &stack);
    printkf("Video: %dx%dx%d Pitch:%d\n", mboot_ptr->framebuffer_width, mboot_ptr->framebuffer_height, mboot_ptr->framebuffer_bpp, mboot_ptr->framebuffer_pitch);

    initializeSystemFS();
    initializePipes();
    initializeSharedMemory();

    initializeTasking();

    initialiseSyscalls();

    initializeTimer();

    initializeKeyboard();
    initializeMouse();

    if (0 != mboot_ptr->cmdline) {
        printkf("Kernel cmdline:%s\n", (char*)mboot_ptr->cmdline);
    }

    Debug_initialize("/dev/tty9");

    Serial_PrintF("pitch:%d\n", mboot_ptr->framebuffer_pitch);

    initializeRandom();
    initializeNull();

    createRamdisk("ramdisk1", 20*1024*1024);

    initializeFatFileSystem();

    printkf("System started!\n");

    char* argv[] = {"shell", NULL};
    char* envp[] = {"HOME=/", "PATH=/initrd", NULL};

    uint32 initrdSize = 0;
    uint8* initrdLocation = locateInitrd(mboot_ptr, &initrdSize);
    if (initrdLocation == NULL) {
        PANIC("Initrd not found!\n");
    }
    else {
        printkf("Initrd found at %x (%d bytes)\n", initrdLocation, initrdSize);
        memcpy((uint8*)*(uint32*)getFileSystemNode("/dev/ramdisk1")->privateNodeData, initrdLocation, initrdSize);
        BOOL mountSuccess = mountFileSystem("/dev/ramdisk1", "/initrd", "fat", 0, 0);

        if (mountSuccess) {
            printkf("Starting shell on TTYs\n");

            executeFile("/initrd/init", argv, envp, getFileSystemNode("/dev/tty1"));
        }
        else {
            printkf("Mounting initrd failed!\n");
        }
    }

    enableScheduler();

    enableInterrupts();

    while(TRUE) {
        //Idle thread

        halt();
    }

    return 0;
}