diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..7ab80cbe
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,41 @@
+---
+BasedOnStyle: Google
+AlignAfterOpenBracket: Align
+AlignConsecutiveMacros: true
+AlignTrailingComments: true
+AllowShortBlocksOnASingleLine: true
+AllowShortFunctionsOnASingleLine: Empty
+AllowShortIfStatementsOnASingleLine: WithoutElse
+AlwaysBreakBeforeMultilineStrings: false
+BinPackArguments: false
+BinPackParameters: false
+BreakBeforeBraces: Attach
+BreakBeforeTernaryOperators: true
+BreakStringLiterals: true
+ColumnLimit: 100
+DerivePointerAlignment: false
+IncludeBlocks: Regroup
+IndentCaseLabels: true
+IndentPPDirectives: BeforeHash
+IndentWidth: 4
+IndentWrappedFunctionNames: true
+Language: Cpp
+MaxEmptyLinesToKeep: 2
+PointerAlignment: Middle
+ReflowComments: true
+SortIncludes: true
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesInAngles: false
+SpacesInCStyleCastParentheses: false
+SpacesInContainerLiterals: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+TabWidth: 4
+UseTab: Never
+
+...
diff --git a/.dir-locals.el b/.dir-locals.el
new file mode 100644
index 00000000..7de401d3
--- /dev/null
+++ b/.dir-locals.el
@@ -0,0 +1,20 @@
+((nil . ((eval . (let ((root (projectile-project-root)))
+ (let ((command (concat "arm-none-eabi-gdb -i=mi -ex \"target remote localhost:1234\" -ex \"symbol-file " root "src/kernel/build/kernel.sym\"")))
+ (setq-local gud-gud-gdb-command-name command)
+ (setq-local gud-gdb-command-name command)
+ (set (make-local-variable 'compile-command)
+ (concat "cd " (concat root "src") " && make test"))
+ (let ((map (make-sparse-keymap)))
+
+ (set-keymap-parent map (current-local-map))
+ (use-local-map map)
+ (local-set-key [f5] 'compile)
+ (local-set-key [f6] 'co/gdb)
+
+ (defun co/gdb ()
+ (interactive)
+ (async-shell-command (concat "cd "
+ (concat (projectile-project-root) "src")
+ " && "
+ "make debug") nil 0)
+ (gdb gud-gdb-command-name)))))))))
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 00000000..76af337a
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,18 @@
+.git
+.github
+.idea
+.vscode
+projet/build/
+project/kernel/build/
+
+src/toolchain/
+src/qemu/
+!src/toolchain/build.sh
+src/build/
+src/kernel/build
+!src/build/build.sh
+src/docs/
+src/html/
+src/latex
+src/course_os_docs.pdf
+
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00000000..8f5ed13c
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,11 @@
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 4
+charset = utf-8
+
+[*.yml]
+indent_size = 2
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..2935d2bd
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,4 @@
+# Sources
+*.c text diff=c
+*.h text diff=c
+*.h linguist-language=C
diff --git a/.github/workflows/os_test.yml b/.github/workflows/os_test.yml
new file mode 100644
index 00000000..3d2363be
--- /dev/null
+++ b/.github/workflows/os_test.yml
@@ -0,0 +1,16 @@
+name: course_os test suite
+
+on: [push]
+
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: build
+ run: docker build -t course_os .
+
+ - name: test
+ run: docker run course_os sh -c 'cd build && ninja run-test'
diff --git a/.gitignore b/.gitignore
index 8c2fa405..dac4cd06 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,32 +1,82 @@
-#these were not originally apart of the repo -- appeared after build
-/kernel/kernel.bin
-/kernel/flash.bin
-/kernel/boot-commands
-/kernel/card.sd
-/toolchain/target/
-/u-boot/u-boot-*
-/qemu/
-!/qemu/build.sh
+# Build files
+/build
+src/kernel/kernel.bin
+src/kernel/flash.bin
+src/kernel/boot-commands
+src/kernel/card.sd
+src/kernel/src/test_suite/test.c
+src/kernel/src/test_suite/generated/
+src/kernel/build
+src/kernel/build/kernel.sym
+build/
+.cache/
+builddir/
+# Toolchain dir, but not the build script
+src/toolchain/
+toolchain/
+!src/toolchain/build.sh
+project/scripts/qemu-*/
+*.bz2
+arm-none-eabi/
+
+# Qemu dir, again without its buildscript
+src/qemu/
+qemu/
+!src/qemu/build.sh
+
+# Generic build dirs
+src/build
+/cmake-build-*/
+
+# Generated docs
+src/docs/
+src/html/
+src/latex/
+src/course_os_docs.pdf
+docs/
+
+# Editor specific
.settings/
.cproject
.project
+.vs/
+/.idea/
+!/.idea/runConfigurations
+/.vscode/
+!/.vscode/launch.json
+!/.vscode/tasks.json
+*~
+*.swp
+[._]*.s[a-w][a-z]
+[._]s[a-w][a-z]
+*.un~
+Session.vim
+.netrwhist
+.cache/
+
+# CCLS files
+.ccls-cache/
+compile_commands.json
-#always exclude these from being pushed
+# Binary files
*.o
*.img
*.map
*.elf
*.bin
-*~
-*.swp
/user/hello/hello
+/user/hello/hello1
+/user/hello/hello2
/user/libc/libc.a
+kernel/build/kernel.sym
-[._]*.s[a-w][a-z]
-[._]s[a-w][a-z]
-*.un~
-Session.vim
-.netrwhist
+# Floobits (CLion collabrative editing plugin)
+.floo
+.flooignore
+# Misc
NOTES
+/server.PID
+*~
+#*
diff --git a/.idea/runConfigurations/attach_debugger.xml b/.idea/runConfigurations/attach_debugger.xml
new file mode 100644
index 00000000..b8ee3549
--- /dev/null
+++ b/.idea/runConfigurations/attach_debugger.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/debug.xml b/.idea/runConfigurations/debug.xml
new file mode 100644
index 00000000..1883a4ce
--- /dev/null
+++ b/.idea/runConfigurations/debug.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/test.xml b/.idea/runConfigurations/test.xml
new file mode 100644
index 00000000..d8d588b6
--- /dev/null
+++ b/.idea/runConfigurations/test.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 00000000..b4dab36f
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,41 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+
+ "name": "(gdb) Attach - C/C++",
+ "type": "cppdbg",
+ "request": "launch",
+ "program": "${workspaceFolder}/src/kernel/build/kernel.sym",
+ "cwd": "${workspaceFolder}/src/kernel/",
+ "miDebuggerPath": "${workspaceFolder}/src/toolchain/arm-none-eabi/bin/arm-none-eabi-gdb",
+ "setupCommands": [
+ {
+ "description": "Enable pretty-printing for gdb",
+ "text": "-enable-pretty-printing",
+ "ignoreFailures": true
+ }
+ ],
+ "linux": {
+ "MIMode": "gdb"
+ },
+ "miDebuggerServerAddress": "localhost:1234",
+ "preLaunchTask": "run_debug"
+
+ },
+ {
+ "name": "(gdb) Attach - Native",
+ "type": "gdb",
+ "request": "attach",
+ "gdbpath": "${workspaceFolder}/src/toolchain/arm-none-eabi/bin/arm-none-eabi-gdb",
+ "executable": "${workspaceFolder}/src/kernel/build/kernel.sym",
+ "target": ":1234",
+ "remote": true,
+ "cwd": "${workspaceRoot}",
+ "valuesFormatting": "prettyPrinters",
+ "preLaunchTask": "run_debug",
+ "postDebugTask": "stop_debug"
+ }
+ ]
+}
+
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 00000000..2ee84431
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,5 @@
+{
+ "files.associations": {
+ "*.h": "c"
+ }
+}
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644
index 00000000..86452dd7
--- /dev/null
+++ b/.vscode/tasks.json
@@ -0,0 +1,58 @@
+{
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
+ // for the documentation about the tasks.json format
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "label": "Set gdb_path",
+ "detail": "Adds generated toolchain to PATH variable. Will first load system and package binaries if available",
+ "type": "shell",
+ "command": "if [[ $(which arm-none-eabi-gdb) == *\"not\"* ]]; then export GDB_PATH=\"$(which arm-none-eabi-gdb)\"; else export GDB_PATH=\"${PWD}/src/arm-none-eabi/bin/\"; fi"
+ },
+ {
+ "label": "make test",
+ "detail": "Runs the course_os test suite",
+ "dependsOn": "set gdb_path",
+ "type": "shell",
+ "command": "make test",
+ "problemMatcher": "$gcc",
+ "group": {
+ "kind": "test",
+ "isDefault": true
+ }
+ },
+ {
+ "label": "run_debug",
+ "detail": "Runs qemu with gdbserver in the background",
+ "dependsOn": "set gdb_path",
+ "type": "shell",
+ "command": "cd ${workspaceFolder}/src/kernel && make debug",
+ "isBackground": true,
+ "presentation": {
+ "echo": true,
+ "reveal": "always",
+ "focus": true,
+ "panel": "shared",
+ "showReuseMessage": false,
+ "clear": false
+ },
+ "problemMatcher": {
+ "pattern": {
+ "regexp": "^.*$"
+ },
+ "background": {
+ "activeOnStart": true,
+ "beginsPattern": "make debug",
+ "endsPattern": "Configuring tools"
+ }
+ }
+ },
+ {
+ "label": "stop_debug",
+ "detail": "Stops the qemu emulator at port 1234",
+ "type": "shell",
+
+ "command": "kill $(sudo lsof -t -i:1234)"
+ }
+ ]
+}
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 00000000..bdcf5c47
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,32 @@
+########################################################################
+## WARNING: This cmake file does *NOT* work to compile the course OS ##
+## It is merely here to make clion detect all the source files ##
+## so it can do code inspection. Use the supplied makefile to compile ##
+########################################################################
+
+cmake_minimum_required(VERSION 3.6)
+
+project(course_os)
+
+set(CMAKE_SYSTEM_NAME linux)
+set(CMAKE_SYSTEM_PROCESSOR arm)
+set(CMAKE_C_COMPILER ${CMAKE_CURRENT_SOURCE_DIR}/project/toolchain/arm-none-eabi/bin/arm-none-eabi-gcc)
+set(CMAKE_C_LINK_EXECUTABLE ${CMAKE_CURRENT_SOURCE_DIR}/project/toolchain/arm-none-eabi/bin/arm-none-eabi-ld)
+
+file(GLOB_RECURSE kernel_sources ./project/kernel/src/*.c ./project/kernel/src/**/*.c ./project/kernel/src/**/*.s)
+file(GLOB_RECURSE kernel_include LIST_DIRECTORIES true ./project/kernel/src/**/include)
+
+set(SOURCE_FILES ${kernel_sources})
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
+
+add_compile_definitions(ENABLE_TESTS MEM_DEBUG)
+
+add_executable(course_os ${SOURCE_FILES})
+
+message(${kernel_include})
+
+include_directories(
+ ${kernel_include}
+)
+
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..3d4357a4
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,13 @@
+FROM fedora:33
+MAINTAINER Jan S. Rellermeyer
+
+RUN yum install -y arm-none-eabi-gcc-cs arm-none-eabi-binutils-cs arm-none-eabi-newlib qemu-system-arm-core python3 python3-jinja2 meson gcc
+
+WORKDIR /work
+COPY project .
+EXPOSE 1234
+
+# Since we installed the toolchain from the repositories we don't need
+# to install them separately. So we can just fake 'em.
+RUN meson build --cross-file cross_gcc.build && cd build && meson compile
+#VOLUME build /work/kernel/build
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..0f2ead82
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,29 @@
+BSD 3-Clause License
+
+Copyright (c) 2020, CourseOS Project
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Makefile b/Makefile
deleted file mode 100644
index ae3c04fa..00000000
--- a/Makefile
+++ /dev/null
@@ -1,33 +0,0 @@
-all: toolchain u-boot kernel
-
-toolchain:
- cd ./toolchain && ./build.sh
-.PHONY: toolchain
-
-u-boot:
- $(MAKE) -C u-boot
-.PHONY: u-boot
-
-libc:
- $(MAKE) -C user/libc
-
-kernel: libc
- $(MAKE) -C kernel
- $(MAKE) -C user/hello
-.PHONY: kernel
-
-clean:
- $(MAKE) -C u-boot clean
- $(MAKE) -C kernel clean
- $(MAKE) -C user/libc clean
- $(MAKE) -C user/hello clean
-.PHONY: clean
-build: u-boot kernel
-run:
- @$(MAKE) -C ./kernel run
-.PHONY: run
-
-docs:
- doxygen doxyfile
- $(MAKE) -C latex pdf
- mv ./latex/refman.pdf course_os_docs.pdf
diff --git a/README.md b/README.md
index 1478faef..42bfecec 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,92 @@
-course_os
-=========
+
-CS 439 course OS
+# Course OS
-Copyright (c) 2015,
- All rights reserved.
+This is a 'toy' kernel created by students from multiple universities.
+Currently it is mainly developed by students of the TU Delft.
+It is targeted to run on the raspberry pi zero, b+ and 2.
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+# Building
-1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+[Build parameters](kernel/README.md)
-2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+## Docker
+One option to run the project is to make use of the [Docker](https://www.docker.com/) image. To do so you first need to download Docker and Docker Compose for your operating system, after which you can run the follow commands to build and start the container:
-3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+```bash
+docker-compose build
+docker-compose up -d
+```
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+After this you can choose to open the shell to the container by running:
+```bash
+docker-compose run raspberry
+```
+After that you can follow the instructions starting at [Running](#running)
+You can find the directory with the built kernel at:`/var/lib/docker/course_os_kernel/_data`
+To run the kernel you can use the command:
+```base
+qemu-system-arm -kernel kernel.elf -m 1G -serial stdio -monitor none -M raspi2 -cpu cortex-a7 -nographic -append "-load 0x410000 0x14000" -semihosting
+```
+
+
+## Toolchain
+To build and run the project, you will need a cross compiler. Since the kernel is made to run on ARM, the compiler has to output ARM instructions.
+You can find in scripts to install known working versions of qemu and the compilation toolchain. Run those and add the generated bin directories to your PATH.
+
+## Running
+
+After you built the toolchain go into the project directory and generate a build directory.
+```bash
+cd project
+meson --cross-file cross_gcc.build build
+```
+
+Having generated the directory you can cd into the build directory and run the kernel with the following command.
+```bash
+ninja run-kernel
+```
+
+## Running tests
+
+To run the test suite for the kernel, execute:
+
+```bash
+ninja run-test
+```
+
+## Debugging
+
+To debug the kernel, you have to perform two steps. First you have to build and start the kernel with
+```bash
+ninja run-debug
+```
+
+This prepares qemu so it waits for a debugger to be attached.
+
+now, if you have CLion or VSCode you can run the supplied run configuration called `debug` which attaches a debugger, loads the sourcemap and runs the kernel. Now you can create breakpoints from within your IDE.
+
+If however you don't have either of those IDEs, or want to use gdb from a terminal, one can run the following command:
+```bash
+ninja run-gdb
+```
+
+# Creating tests
+
+To create tests for the kernel, please read [this](kernel/src/test/README.md) file.
+
+# Editors
+
+## CLion
+
+To open this project in CLion, you can simply create a new `c` project with the supplied `CMakeLists.txt` file.
+This file can *not* be used to actually run the kernel but it does give clion the right instructions to make code completion etc. work.
+
+## Emacs/Vim + CCLS
+
+You can use the `compile_commands.json` from the kernel build directory by creating a softlink from that file to this directory. Doing so will keep it up to date.
+
+## Emacs + GDB
+
+A small lisp script to set the correct GDB command is included in the `.dir-locals.el` file. This will run automatically when you open any file in the project directory. You may receive a prompt related to this. After you start a debug session with `make debug`, you should be able to run the `gdb` command in Emacs and the correct command should already be in the prompt.
diff --git a/config.mk b/config.mk
deleted file mode 100644
index d1924e66..00000000
--- a/config.mk
+++ /dev/null
@@ -1,12 +0,0 @@
-TOOLCHAIN_DIR=toolchain
-
-BARE_METAL_TUPLE=arm-none-eabi
-BARE_METAL_TARGET:=$(BARE_METAL_TUPLE)
-
-QEMU=qemu-system-arm
-
-#UBOOT_VERSION=2010.03
-UBOOT_VERSION=2014.10
-
-#CFLAGS = -mcpu=arm1136j-s
-CFLAGS = -mcpu=arm1176jz-s
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 00000000..bd860927
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,13 @@
+version: '3.8'
+
+services:
+ raspberry:
+ build: .
+ image: rellermeyer/course_os:1.0
+# volumes:
+# - kernel:/work/kernel/build
+ ports:
+ - "1234"
+
+volumes:
+ kernel:
diff --git a/kernel/.gdbinit b/kernel/.gdbinit
deleted file mode 100644
index 04a23b5e..00000000
--- a/kernel/.gdbinit
+++ /dev/null
@@ -1,3 +0,0 @@
-add-symbol-file kernel.elf 0x00010000
-add-symbol-file kernel.elf 0xf0000000
-target remote localhost:1234
diff --git a/kernel/Makefile b/kernel/Makefile
deleted file mode 100644
index 4bb6b9dd..00000000
--- a/kernel/Makefile
+++ /dev/null
@@ -1,104 +0,0 @@
-
-include $(CURDIR)/../config.mk
-
-TOOLCHAIN_PATH:=$(CURDIR)/../$(TOOLCHAIN_DIR)/$(BARE_METAL_TARGET)/bin
-CC:=$(TOOLCHAIN_PATH)/$(BARE_METAL_TUPLE)-gcc
-AS:=$(TOOLCHAIN_PATH)/$(BARE_METAL_TUPLE)-as
-LD:=$(TOOLCHAIN_PATH)/$(BARE_METAL_TUPLE)-gcc
-OBJCOPY:=$(TOOLCHAIN_PATH)/$(BARE_METAL_TUPLE)-objcopy
-MKIMAGE:=$(CURDIR)/../u-boot/u-boot-$(UBOOT_VERSION)/tools/mkimage
-GDB:=$(TOOLCHAIN_PATH)/$(BARE_METAL_TUPLE)-gdb
-
-PIOBJS = start.o pi_light.o startup.o drivers/uart_pi.o argparse.o klibc.o interrupt.o hw_handlers.o process.o elf.o loader.o memory/mem_alloc.o memory/allocator.o tests.o mmap.o vm/frame.o vm/vm.o drivers/timer.o data_structures/bitvector.o data_structures/array_list.o data_structures/priority_queue.o data_structures/linked_list.o data_structures/hash_map.o process/scheduler.o tests/test_mem_alloc.o tests/test_priority_queue.o tests/test_hash_map.o tests/test_vm.o fs/open_table.o fs/fat16/file.o tests/test_fs.o drivers/mmci.o
-
-OBJS=start.o drivers/uart.o startup.o argparse.o klibc.o interrupt.o hw_handlers.o process.o elf.o loader.o memory/mem_alloc.o memory/allocator.o tests.o mmap.o vm/frame.o vm/vm.o drivers/timer.o process/scheduler.o data_structures/bitvector.o data_structures/array_list.o data_structures/linked_list.o data_structures/priority_queue.o data_structures/hash_map.o tests/test_mem_alloc.o tests/test_priority_queue.o tests/test_hash_map.o tests/test_vm.o fs/open_table.o fs/fat16/file.o tests/test_fs.o drivers/mmci.o
-
-all: flash.bin card.sd
-
-make_Pi: kernelPi.img
-
-CFLAGS += -pipe
-CFLAGS += -std=gnu99
-CFLAGS += -ffreestanding
-CFLAGS += -nostdinc
-CFLAGS += -Wall
-CFLAGS += -Werror
-PFLAGS += -mfpu=vfp
-#PFLAGS += -mfloat-abi=hard
-PFLAGS += -march=armv6zk
-PFLAGS += -mtune=arm1176jzf-s
-PFLAGS += -nostartfiles
-CFLAGS += -g
-
-run: flash.bin card.sd
- ${QEMU} -M versatilepb -cpu arm1176 -sd card.sd -m 128M -nographic -kernel flash.bin -append "-load 0x410000 0x14000"
-
-run-debug: flash.bin card.sd
- ${QEMU} -S -s -M versatilepb -cpu arm1176 -sd card.sd -m 128M -nographic -kernel flash.bin -append "-load 0x410000 0x14000"
-
-gdb:
- ${GDB} -ex "target remote :1234" kernel.elf
-
-#boots the kernel at 0x210000
-flash.bin: kernel.img script.img
- dd if=/dev/zero of=flash.bin bs=4k count=1536
- dd if=../u-boot/u-boot-$(UBOOT_VERSION)/u-boot.bin of=flash.bin conv=notrunc bs=4k
- dd if=kernel.img of=flash.bin conv=notrunc bs=4k seek=512
- dd if=script.img of=flash.bin conv=notrunc bs=4k seek=575
-
-# 32678*4096 = 128MiB
-card.sd: fs-cmdline userhello
- dd if=/dev/zero of=card.sd conv=notrunc bs=4096 count=32768
- fs/cmdline/buildfs ../user/hello/
-
-userhello:
- make -C ../user/hello
-
-fs-cmdline:
- make -C fs/cmdline
-
-kernel.elf: $(OBJS)
- $(LD) -T kernel.ld -nostartfiles -Wl,-Map,kernel.map $(OBJS) -o kernel.elf
-
-kernel.bin: kernel.elf
- $(OBJCOPY) -O binary kernel.elf kernel.bin
-
-kernel.img: kernel.bin
- $(MKIMAGE) -A arm -C none -O linux -T kernel -d kernel.bin -a 0x00010000 -e 0x00010000 kernel.img
-
-# Begin Pi Make
-kernelPi.elf: $(PIOBJS)
- $(CC) -T kernelPi.ld -O2 $(PFLAGS) $(PIOBJS) -o kernelPi.elf
-
-kernelPi.img: kernelPi.elf
- $(OBJCOPY) kernelPi.elf -O binary kernelPi.img
-
-# End Pi Make
-
-script.img: uboot-commands.ubt
- $(MKIMAGE) -A arm -C none -T script -d uboot-commands.ubt -a 0x10000 -e 0x10000 script.img
-
-course_os.img: kernel.img
- cat ../u-boot/u-boot-$(UBOOT_VERSION)/u-boot.bin kernel.img > course_os.img
-
-startup.o: startup.s
- $(AS) -mcpu=arm1176jzf-s -g startup.s -o startup.o
-
-%.o: %.c
- $(CC) $(CFLAGS) -Iinclude -c $< -o $@
-
-clean:
- rm -f $(OBJS)
- rm -f *.img
- rm -f *.elf
- rm -f *.bin
- rm -f *.map
- rm -f drivers/*.o
- rm -f fs/cmdline/buildfs
- rm -f vm/*.o
- rm -f tests/*.o
- rm -f memory/*.o
- rm -f data_structures/*.o
- rm -f mq/*.o
- @echo "I'm persisting the SD card 'card.sd', you'll have to remove that yourself if you want to rebuild it."
- @echo "('rm sd.card')"
diff --git a/kernel/argparse.c b/kernel/argparse.c
deleted file mode 100644
index 6b2d0c4c..00000000
--- a/kernel/argparse.c
+++ /dev/null
@@ -1,171 +0,0 @@
-#include
-#include "global_defs.h"
-#include "argparse.h"
-#include "klibc.h"
-#include "tests.h"
-#include "process.h"
-#include "fs/file.h"
-
-static void argparse_parse(char *);
-
-/* Get the command-line arguments and run the functions to process them. */
-void argparse_process(uint32_t *p_bootargs)
-{
- for (atag_iterator(tag, p_bootargs))
- {
- os_printf("tag (+%d) %d\n",
- (((uint32_t) ((uint32_t*) tag)) - ((uint32_t) p_bootargs)),
- tag->header.tag);
- atag_print(tag);
- if (tag->header.tag == ATAG_CMDLINE)
- {
- argparse_parse((char*) &tag->content.cmdline.cmdline);
- }
- }
-}
-
-void atag_print(struct atag *t)
-{
- switch (t->header.tag)
- {
- case ATAG_CORE:
- if (t->header.size == 2)
- {
- os_printf("ATAG_CORE\n");
- }
- else
- {
- os_printf("ATAG_CORE (FLAGS=%d, PAGESIZE=%d, ROOTDEV=%d)\n",
- t->content.core.flags, t->content.core.pagesize,
- t->content.core.rootdev);
- }
- break;
- case ATAG_MEM:
- os_printf("ATAG_MEM (SIZE=%d, START=%d)\n", t->content.mem.size,
- t->content.mem.start);
- break;
- case ATAG_CMDLINE:
- os_printf("ATAG_CMDLINE (%s)\n", &t->content.cmdline.cmdline);
- break;
- }
-}
-
-/*
- Pulls name, start location, and size of file from command line
- Opens file for process, then moves the process from
- file to a location in memory.
- Creates a process using the start location of process,
- enables the VAS for the process, sets up the stack and heap,
- then executes it.
- @param Character pointer to command line
- @param char* cmdline
-
- */
-
-static void argparse_parse(char *cmdline)
-{
-
- char* token = os_strtok(cmdline, " ");
-
- while (token != NULL)
- {
- os_printf("token: %s\n", token);
-
- if (os_strcmp("-load", token) == 0)
- {
- char* name = os_strtok(NULL, " ");
-
- pcb* proc = process_create(name);
- assert(proc != NULL);
- process_execute(proc);
-
- }
- else if (os_strcmp("-test", token) == 0)
- {
- os_printf("RUNNING TESTS\n");
- os_printf("Running tests...\n");
- Test *tests[2];
- tests[0] = create_test("This passes", &test1);
- tests[1] = create_test("This fails", &test2);
- run_tests(tests, 2);
- }
-
- token = os_strtok(NULL, " ");
- }
-}
-
-/* We return a signed integer because we need a way to detect errors.
-
- Read a string of characters and interpret them as an unsigned integer.
- Return -1 if the string cannot be read as an unsigned integer.
- Return an integer representing the value of the string otherwise.
- */
-int string_to_unsigned_int(char *input, int base)
-{
- int i = os_strlen(input) - 1; // Index in the string
-
- if (hex_value_of_character(input[i]) == -1)
- {
- // Return -1 if the string cannot be read as an unsigned integer
- return -1;
- }
-
- int n = 0; // Number of digits
- int result = 0;
-
- // Starting from the end of the string, read each character
- while (i >= 0)
- {
- // Get the value of one character
- int digit = hex_value_of_character(input[i]);
-
- if (digit == -1)
- {
- // If we hit a non-digit character such as 'x', return
- return result;
- }
-
- // Add the digit's value to the integer
- result = result | (digit << (n * 4));
-
- i--;
- n++;
- }
- return result;
-}
-
-/* Return the hexidecimal value of the single character c */
-int hex_value_of_character(char c)
-{
- if (c >= '0' && c <= '9')
- {
- return (int) (c - '0');
- }
- else if (c >= 'A' && c <= 'F')
- {
- return (int) (c - 'A' + 10);
- }
- else if (c >= 'a' && c <= 'f')
- {
- return (int) (c - 'a' + 10);
- }
-
- // Return -1 if c was not a hex digit
- return -1;
-}
-
-uint32_t round_up(uint32_t c)
-{
-
- c--;
- c |= c >> 1;
-
- c |= c >> 2;
- c |= c >> 4;
- c |= c >> 8;
-
- c |= c >> 16;
- c++;
- return c;
-
-}
diff --git a/kernel/data_structures/array_list.c b/kernel/data_structures/array_list.c
deleted file mode 100644
index c09fd10e..00000000
--- a/kernel/data_structures/array_list.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * array_list.c
- *
- * Created on: Apr 21, 2015
- * Author: kittenRainbow
- */
-
-#include "data_structures/array_list.h"
-
-arrl_handle* arrl_create() {
- return arrl_create_fixed(DEFAULT_BUCKET_SIZE);
-}
-
-arrl_handle* arrl_create_fixed(uint32_t bucket_size) {
- arrl_handle* result = (arrl_handle *) kmalloc(sizeof(arrl_handle));
- void** bucket = kmalloc(bucket_size * sizeof(void*));
- llist_handle * l = llist_create(bucket);
- result->linked_list = l;
- result->size = 0;
- result->capacity = bucket_size;
- return result;
-}
-
-void arrl_append(arrl_handle* arrl, void* elem) {
- llist_node * curr_bucket;
- uint32_t list_size;
- uint32_t last_bucket_size;
-
- if (arrl->capacity == arrl->size) {
- void* data = kmalloc(arrl->bucket_size * sizeof(void*));
- llist_enqueue(arrl->linked_list, data);
- arrl->capacity += arrl->bucket_size;
- }
-
- curr_bucket = arrl->linked_list->head;
- list_size = arrl->size / arrl->bucket_size;
- last_bucket_size = arrl->size % arrl->bucket_size;
-
- for(uint32_t i=0; i < list_size; ++i) {
- curr_bucket= curr_bucket->next;
- }
- *(((int**)curr_bucket->data) + last_bucket_size) = (int*)elem;
-}
-
-void arrl_remove(arrl_handle* arrl, void* elem) {
- uint32_t bucket_size;
- uint32_t list_size;
- uint32_t bucket_index;
- uint32_t list_index;
- llist_node* curr_bucket;
- llist_node* tail;
-
- bucket_size = arrl->bucket_size;
- list_size = arrl->linked_list->count;
- curr_bucket = arrl->linked_list->head;
- tail = arrl->linked_list->tail;
-
- for (list_index = 0; list_index < list_size; ++list_index) {
- for (bucket_index = 0; bucket_index < bucket_size; ++bucket_index) {
- //if (elem == curr_bucket->data[bucket_index]) {
- kfree(elem);
- goto out;
- //}
- }
- curr_bucket = curr_bucket->next;
- }
-
- // Except the last bucket, shift each bucket up by one and copy first element of the next bucket to the last cell of the current bucket
- out: while (curr_bucket != tail) {
- os_memcpy(*(((uint32_t**)curr_bucket->data) + bucket_index + 1),
- *(((uint32_t**)curr_bucket->data) + bucket_index + 0),
- bucket_size - bucket_index - 1);
- bucket_index = 0;
- *(((int**)curr_bucket->data) + bucket_size - 1) = *((int**)curr_bucket->next->data);
- curr_bucket = curr_bucket->next;
- }
-
- --arrl->size;
-}
-
-uint32_t arrl_contains(arrl_handle* arrl, void* elem) {
- uint32_t bucket_size = arrl->bucket_size;
- uint32_t list_size = arrl->linked_list->count;
- llist_node* bucket = arrl->linked_list->head;
-
- for (uint32_t list_index = 0; list_index < list_size; ++list_index) {
- for (uint32_t bucket_index = 0; bucket_index < bucket_size;
- ++bucket_index) {
- //if (elem == bucket->data[bucket_index]) {
- return 1;
- //}
- }
- bucket = bucket->next;
- }
- return 0;
-}
-
-uint32_t arrl_index_of(arrl_handle* arrl, void* elem) {
- int bucket_size = arrl->bucket_size;
- int list_size = arrl->linked_list->count;
- llist_node* bucket = arrl->linked_list->head;
-
- for (int list_index = 0; list_index < list_size; ++list_index) {
- for (int bucket_index = 0; bucket_index < bucket_size;
- ++bucket_index) {
- //if (elem == bucket->data[bucket_index]) {
- return list_index * DEFAULT_BUCKET_SIZE + bucket_index;
- //}
- }
- bucket = bucket->next;
- }
- return -1;
-}
-
-uint32_t arrl_count(arrl_handle* arrl) {
- return arrl->size;
-}
-
diff --git a/kernel/data_structures/bin_tree.c b/kernel/data_structures/bin_tree.c
deleted file mode 100644
index cef924b4..00000000
--- a/kernel/data_structures/bin_tree.c
+++ /dev/null
@@ -1,287 +0,0 @@
-/********************************************************************
- * bin_tree.c
- *
- * Authors: Brandon Olivier, Collin Massey // any collaborators, please add name
- *
- * Created: 19 April 2014
- *
- * Last edit: 27 November 2015
- *
- * Purpose: Implement unbalanced binary trees for addresses
- *
- ********************************************************************/
-//#include "klibc.h"
-//#include "data_structures/bin_tree.h"
-#include
-#include
-
-
-typedef struct node {
- struct node *parent;
- struct node *left;
- struct node *right;
- void *data;
-} node;
-
-typedef struct tree {
- struct node *root;
- int size;
-} tree;
-
-
-struct tree *new_tree(node *root)
-{
- struct tree *t = (tree *)kmalloc(sizeof(struct tree)); // TODO: Needs to be fixed
- t->root = root;
- t->size = 0;
- return t;
-}
-
-struct tree *init_tree()
-{
- return new_tree(NULL);
-}
-
-// Compare 2 values
-int comparison(void *a, void *b)
-{
- int x = *(int *)a;
- int y = *(int *)b;
- if (x < y)
- return -1;
- if (x > y)
- return 1;
- return 0; // x = y (a = b)
-}
-
-// Insert a node into the tree if not already present
-// Returns 1 if inserted, 0 otherwise
-int insert(tree *t, void *val)
-{
- if (contains_node(t, val)) {
- return 0;
- }
-
- struct node *new_node = (node *)kmalloc(sizeof(struct node)); // TODO: Needs to be fixed
- new_node->left = new_node->right = NULL;
- new_node->parent = NULL;
- new_node->data = val;
-
- if (t->root == NULL) { // Empty tree
- t->root = new_node;
- t->size += 1;
- return 1;
- }
-
- node *parent = NULL; // Will be parent of new node
- node *temp = t->root; // Temporary node
- int comp = 0; // Comparison value, used in final step
-
- // Traverse tree
- while(temp) {
- parent = temp;
- switch (comparison(temp->data, val)) {
- case 1:
- comp = 1;
- temp = temp->left;
- break;
- case -1:
- comp = -1;
- temp = temp->right;
- break;
- case 0: // This should never hit, but just in case
- return 0;
- default:
- return 0; // Undefined behavior
- }
- }
-
- // Add node to tree
- if (comp == 1) {
- parent->left = new_node;
- } else { // comp = -1
- parent->right = new_node;
- }
-
- new_node->parent = parent; // Each node know its parent
- t->size += 1;
- return 1;
-}
-
-// Returns the node that has data = val if present, NULL otherwise
-node *find_node(tree *t, void *val)
-{
- node *current_node = t->root;
-
- while (current_node) {
- switch (comparison(¤t_node->data, val)) {
- case -1:
- current_node = current_node->right;
- break;
- case 1:
- current_node = current_node->left;
- break;
- case 0:
- return current_node;
- default:
- return NULL; // Undefined behavior
- }
- }
-
- // val not found
- return NULL;
-}
-
-// Returns 1 if the tree contains a node with data = val, 0 otherwise
-int contains_node(tree *t, void *val)
-{
- return find_node(t, val) != NULL ? 1 : 0;
-}
-
-// Returns the node with the minimum value in the tree provided
-// If tree is empty, returns NULL
-node *min_node(tree *t)
-{
- node *temp = t->root;
-
- while (temp->left != NULL) {
- temp = temp->left;
- }
-
- return temp;
-}
-
-// Returns the minimum value in the tree, or 0 if not present
-int min_val(tree *t)
-{
- node *n = min_node(t);
- return n != NULL ? *((int *)n->data) : 0;
-}
-
-// Returns the node with the maximum value in the tree provided
-// If tree is empty, returns NULL
-node *max_node(tree *t)
-{
- node *temp = t->root;
-
- while (temp->right != NULL) {
- temp = temp->right;
- }
-
- return temp;
-}
-
-// Returns the maximum value in the tree, or 0 if not present
-int max_val(tree *t)
-{
- node *n = max_node(t);
- return n != NULL ? *((int *)n->data) : 0;
-}
-
-// Remove node with data = val from tree if present
-// Returns 1 if removed, 0 if node not present
-int remove_node(tree *t, void *val)
-{
- node *n = find_node(t, val);
- if (n == NULL) // node not present
- return 0;
-
- node *parent = n->parent;
- int children = 0; // # of children n has
-
- if (n->left != NULL)
- children += 1;
- if (n->right != NULL)
- children += 1;
-
- if (children == 0) { // Most simple
- if (parent->left == n) {
- parent->left = NULL;
- } else {
- parent->right = NULL;
- }
-
- kfree(n);
- t->size -= 1;
- return 1;
- } else if (children == 1) { // Less simple
- if (parent->left == n) {
- if (n->left != NULL) {
- parent->left = n->left;
- } else {
- parent->left = n->right;
- }
- } else {
- if (n->left != NULL) {
- parent->right = n->left;
- } else {
- parent->right = n->right;
- }
- }
-
- kfree(n);
- t->size -= 1;
- return 1;
- } else { // children = 2, least simple
- // Need to replace n's data with the smallest value in its right subtree
- tree *right_subtree = new_tree(n->right);
- node *min = min_node(right_subtree);
- node *min_parent = min->parent; // Parent of min node
-
- n->data = min->data; // Move min node to where n was
-
- // Erase duplicate
- if (min_parent->left == min) {
- min_parent->left = NULL;
- } else {
- min_parent->right = min->right;
- }
-
- kfree(min);
- t->size -= 1;
- return 1;
- }
-}
-
-// Support method for delete_tree
-void delete(node *n)
-{
- if (n != NULL) {
- delete(n->left);
- delete(n->right);
- kfree(n);
- }
-}
-
-// Remove all node pointers and the tree pointer
-void delete_tree(tree *t)
-{
- if (t->root != NULL)
- delete(t->root);
-
- kfree(t);
-}
-
-// Returns 1 if the tree is empty, 0 otherwise
-int is_empty(tree *t)
-{
- return t->root == NULL ? 1 : 0;
-}
-
-// Support method for print_tree
-void print_nodes(node *n)
-{
- printf("%d\n", *((int *)n->data));
- if (n->left != NULL)
- print_nodes(n->left);
- if (n->right != NULL)
- print_nodes(n->right);
-}
-
-// Print an in-order traversal of the tree
-void print_tree(tree *t)
-{
- node *root = t->root;
- if (root != NULL)
- print_nodes(root);
-}
diff --git a/kernel/data_structures/bitvector.c b/kernel/data_structures/bitvector.c
deleted file mode 100644
index 5e23f289..00000000
--- a/kernel/data_structures/bitvector.c
+++ /dev/null
@@ -1,137 +0,0 @@
-#include
-#include "klibc.h"
-#include "data_structures/bitvector.h"
-
-uint32_t const WORD_SIZE = 32;
-
-/* return a pointer to a bit_vector struct of length size */
-bit_vector *make_vector(uint32_t size) {
- // make the array
- bit_vector *BV = (bit_vector*) kmalloc(sizeof(bit_vector));
- if((size % 32) == 0) {
- uint32_t array[size >> 5];
- uint32_t x;
- for(x = 0; (x < (size >> 5)); x++){
- array[x] = 0;
- }
- uint32_t *bit_vec = (uint32_t*) kmalloc(sizeof(array));
- BV->vector = bit_vec;
- BV->length = size;
- BV->actualLength = (size >> 5);
- return BV;
- } else {
- uint32_t array[(size >> 5) + 1];
- uint32_t y;
- for(y = 0; (y < ((size >> 5)+1)); y++){
- array[y] = 0;
- }
- uint32_t *bit_vec = (uint32_t*) kmalloc(sizeof(array));
- BV->vector = bit_vec;
- BV->length = size;
- BV->actualLength = (size >> 5) + 1;
- return BV;
- }
-}
-
-/* return a whatever number, 1 or 0 is at position index */
-int32_t bv_get (uint32_t index, bit_vector* bit_vec) {
-
- if(index < bit_vec->length && index >= 0) {
-
- uint32_t val = (index >> 5);
- uint32_t oneWord = bit_vec->vector[val];
- oneWord = oneWord >> (31 - (index % WORD_SIZE));
- uint32_t mask = 0x1;
- return oneWord & mask;
- } else {return -1;} // invalid index
-}
-
-/* toggles the bit a position index */
-int32_t bv_toggle (uint32_t index, bit_vector* bit_vec) {
-
- if(index < bit_vec->length && index >= 0) {
-
- uint32_t val = (index >> 5);
- uint32_t oneWord = bit_vec->vector[val];
- uint32_t mask = 0x1 << (31 - (index % WORD_SIZE));
- bit_vec->vector[val] = oneWord ^ mask;
- return 1;
- } else {return -1;} // invalid index
-}
-
-/* puts a 1 at the position index */
-int32_t bv_set (uint32_t index, bit_vector* bit_vec) {
-
- if(index < bit_vec->length && index >= 0) {
-
- uint32_t val = (index >> 5);
- uint32_t oneWord = bit_vec->vector[val];
- uint32_t mask = 0x1 << (31 - (index % WORD_SIZE));
- bit_vec->vector[val] = oneWord | mask;
- return 1;
- } else {return -1;} // invalid index
-}
-
-/* puts a 0 at the position index */
-int32_t bv_lower (uint32_t index, bit_vector* bit_vec) {
-
- if(index < bit_vec->length && index >= 0) {
-
- uint32_t val = (index >> 5);
- uint32_t oneWord = bit_vec->vector[val];
- uint32_t mask = ~(0x1 << (31 - (index % WORD_SIZE)));
- bit_vec->vector[val] = oneWord & mask;
- return 1;
- } else {return -1;} // invalid index
-}
-
-/* returns the first free index, if none are free return -1 */
-int32_t bv_firstFree (bit_vector* bit_vec) {
-
- uint32_t mask = 0x1;
- uint32_t returner = 0;
- uint32_t oneWord;
- uint32_t x;
- oneWord = bit_vec->vector[0];
-
- for(x = 0; x < bit_vec->actualLength; x++) {
-
- uint32_t index = 0;
- while(index < WORD_SIZE) {
-
- oneWord = bit_vec->vector[x];
- oneWord = (oneWord >> (31 - index)) & mask;
-
- if(!oneWord) {
- return returner += index;
- }
- index++;
- } returner += WORD_SIZE;
- }
- return -1; //no free spots
-}
-
-/* returns whether the given index is free; 1 - true, 0 - false, -1 - invalid index*/
-int32_t bv_isfree(uint32_t index, bit_vector* bit_vec)
-{
- uint32_t val;
- uint32_t word;
- if (index < bit_vec->length && index >= 0){
- val = (index >> 5);
- word = bit_vec->vector[val];
- word = (word >> (31 - index)) & 0x1;
- if (!word){
- return 1;
- }
- return 0;
- }
- return -1;
-}
-
-/* free the bv from memory */
-int32_t bv_free (bit_vector* bit_vec) {
-
- kfree(bit_vec->vector);
- kfree(bit_vec);
- return 1;
-}
diff --git a/kernel/data_structures/hash_map.c b/kernel/data_structures/hash_map.c
deleted file mode 100644
index b084ec04..00000000
--- a/kernel/data_structures/hash_map.c
+++ /dev/null
@@ -1,180 +0,0 @@
-#include "data_structures/hash_map.h"
-#include "klibc.h"
-
-/* this should be prime */
-#define TABLE_STARTSIZE 1021
-#define ACTIVE 1
-
-static unsigned long __hmap_is_prime(unsigned long val) {
- int i, p, exp, a;
-
- for (i = 9; i--;) {
- a = (rand() % (val - 4)) + 2;
- p = 1;
- exp = val - 1;
- while (exp) {
- if (exp & 1) {
- p = (p * a) % val;
- }
-
- a = (a * a) % val;
- exp >>= 1;
- }
-
- if (p != 1) {
- return 0;
- }
- }
-
- return 1;
-}
-
-static int __hmap_find_prime_greater_than(int val) {
- if (val & 1) {
- val += 2;
- } else {
- val++;
- }
-
- while (!__hmap_is_prime(val)) {
- val += 2;
- }
-
- return val;
-}
-
-static void __hmap_rehash(hmap_handle* hmap) {
- long size = hmap->size;
- hmap_entry* table = hmap->table;
-
- hmap->size = __hmap_find_prime_greater_than(size << 1);
- hmap->table = (hmap_entry*) kmalloc(sizeof(hmap_entry) * hmap->size);
- os_memset(hmap->table, 0, sizeof(hmap_entry) * hmap->size);
- hmap->count = 0;
-
- while (--size >= 0) {
- if (table[size].flags == ACTIVE) {
- hmap_put(hmap, table[size].key, table[size].data);
- }
- }
-
- kfree(table);
-}
-
-hmap_handle* hmap_create(){
- return hmap_create_fixed(TABLE_STARTSIZE);
-};
-
-hmap_handle* hmap_create_fixed(int startsize) {
- hmap_handle* hmap = (hmap_handle*) kmalloc(sizeof(hmap_handle));
-
- if (!startsize) {
- startsize = TABLE_STARTSIZE;
- } else {
- startsize = __hmap_find_prime_greater_than(startsize - 2);
- }
-
- hmap->table = (hmap_entry*) kmalloc(sizeof(hmap_entry) * startsize);
-
- os_memset(hmap->table, 0, startsize);
-
- hmap->size = startsize;
- hmap->count = 0;
-
- return hmap;
-}
-
-void hmap_put(hmap_handle* hmap, unsigned long key, const void* data) {
- long index, i, step;
-
- if (hmap->size <= hmap->count)
- __hmap_rehash(hmap);
-
- do {
- index = key % hmap->size;
- step = (key % (hmap->size - 2)) + 1;
-
- for (i = 0; i < hmap->size; i++) {
- if (hmap->table[index].flags & ACTIVE) {
- if (hmap->table[index].key == key) {
- hmap->table[index].data = (void*) data;
- return;
- }
- } else {
- hmap->table[index].flags |= ACTIVE;
- hmap->table[index].data = (void*) data;
- hmap->table[index].key = key;
- ++hmap->count;
- return;
- }
-
- index = (index + step) % hmap->size;
- }
-
- /* it should not be possible that we EVER come this far, but unfortunately
- not every generated prime number is prime (Carmichael numbers...) */
- __hmap_rehash(hmap);
- } while (1);
-}
-
-void* hmap_remove(hmap_handle* hmap, unsigned long key) {
- long index, i, step;
-
- index = key % hmap->size;
- step = (key % (hmap->size - 2)) + 1;
-
- for (i = 0; i < hmap->size; i++) {
- if (hmap->table[index].data) {
- if (hmap->table[index].key == key) {
- if (hmap->table[index].flags & ACTIVE) {
- hmap->table[index].flags &= ~ACTIVE;
- --hmap->count;
- return hmap->table[index].data;
- } else {
- /* in, but not active (i.e. deleted) */
- return 0;
- }
- }
- } else {
- /* found an empty place (can't be in) */
- return 0;
- }
-
- index = (index + step) % hmap->size;
- }
- /* everything searched through, but not in */
- return 0;
-}
-
-void* hmap_get(hmap_handle* hmap, unsigned long key) {
- if (hmap->count) {
- long index, i, step;
- index = key % hmap->size;
- step = (key % (hmap->size - 2)) + 1;
-
- for (i = 0; i < hmap->size; i++) {
- if (hmap->table[index].key == key) {
- if (hmap->table[index].flags & ACTIVE) {
- return hmap->table[index].data;
- }
- break;
- } else if (!hmap->table[index].data) {
- break;
- }
-
- index = (index + step) % hmap->size;
- }
- }
-
- return 0;
-}
-
-long hmap_count(hmap_handle* hash) {
- return hash->count;
-}
-
-void hmap_free(hmap_handle* hash) {
- kfree(hash->table);
- kfree(hash);
-}
-
diff --git a/kernel/data_structures/linked_list.c b/kernel/data_structures/linked_list.c
deleted file mode 100644
index 492fc921..00000000
--- a/kernel/data_structures/linked_list.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/********************************************************************
- * linked_list.c
- *
- * Author: Brandon Olivier // any collaborators, please add name
- *
- * Date: 14 April 2014
- *
- * Purpose: Provide basic linked list for CourseOS
- * Implementation file
- *
- * TODO: Use locks or atomic operations to ensure that
- * functions are safe
- *
- *
- *
- *
- *
- ********************************************************************/
-
-#include "klibc.h"
-#include "data_structures/linked_list.h"
-
-llist_node* llist_create_node(void *data) {
- llist_node *node = (llist_node*) kmalloc(sizeof(llist_node));
- node->data = data;
- return node;
-}
-
-llist_handle* llist_create(void *data) { /* create more space than needed -- less resizing */
- llist_handle *result = (llist_handle *) kmalloc(sizeof(llist_node));
- result->count = 0;
- llist_insert(result, llist_create_node(data), 0);
- return result;
-}
-
-void llist_enqueue(llist_handle * list, void * data) {
- llist_insert(list, data, 0);
-}
-
-void* llist_get_data(llist_handle *l, int index) {
- return llist_get_node(l, index)->data;
-}
-
-void* llist_dequeue(llist_handle * list) {
- void * data = llist_get_data(list, 0);
- llist_remove_at(list, 0);
- return data;
-}
-
-/* TODO: implmement free */
-void llist_free(llist_handle *l) { /* since free isn't really implemented, it's not going to do anything */
- llist_node *tmp = l->head;
- llist_node *next = tmp->next;
- while (tmp->next) {
- kfree(tmp);
- tmp = next;
- next = tmp->next;
- }
- kfree(l);
-}
-
-void llist_free_node(llist_node *node) {
- kfree(node->data);
- kfree(node);
-}
-
-void llist_insert(llist_handle *l, void *data, int index) {
- int i;
- llist_node *next = l->head;
- llist_node *prev;
- l->count++;
- for (i = 0; i < index; i++) {
- prev = next;
- next = next->next;
- }
- llist_node *new_node = llist_create_node(data);
- prev->next = prev ? new_node : 0;
- next->next = next ? new_node : 0;
- if (l->tail->next) {
- l->tail = l->tail->next;
- }
-}
-
-int llist_count(llist_handle *l)
-{
- return l->count;
-}
-
-void llist_remove_at(llist_handle *l, int index) {
- llist_node *prev = llist_get_node(l, index);
- llist_node *to_delete = prev->next;
- prev->next = to_delete->next;
- llist_free_node(to_delete);
-}
-
-
-
-llist_node* llist_get_node(llist_handle *l, int index) {
- int i;
- llist_node *tmp = l->head;
- for (i = 0; i < index; i++) {
- tmp = tmp->next;
- }
- return tmp;
-}
-
-void llist_set_data(llist_node *l, void *data) {
- l->data = data;
-}
diff --git a/kernel/data_structures/priority_queue.c b/kernel/data_structures/priority_queue.c
deleted file mode 100644
index 6a2118b2..00000000
--- a/kernel/data_structures/priority_queue.c
+++ /dev/null
@@ -1,156 +0,0 @@
-#include "klibc.h"
-#include "data_structures/priority_queue.h"
-
-#define AMORITIZED_CONSTANT 2
-#define DEFAULT_COUNT 10
-
-void __prq_shift_up(prq_handle * queue, int idx);
-void __prq_shift_down(prq_handle * queue, int idx);
-
-void __prq_shift_up(prq_handle * queue, int idx) {
- prq_node ** heap = queue->heap;
- prq_node * node, *parent;
- while (heap[idx]->priority < heap[idx / 2]->priority && idx > 1) {
- node = heap[idx];
- parent = heap[idx / 2];
- parent->index = idx;
- node->index = idx / 2;
- heap[idx] = parent;
- heap[idx / 2] = node;
- idx /= 2;
- }
-}
-
-void __prq_shift_down(prq_handle * queue, int idx) {
- int cidx; //index for child
- prq_node ** heap = queue->heap;
- prq_node * node, *child;
- for (;;) {
- cidx = idx * 2;
- if (cidx > queue->count) {
- break; //it has no child
- }
- if (cidx < queue->count) {
- if (heap[cidx]->priority > heap[cidx + 1]->priority) {
- ++cidx;
- }
- }
- //swap if necessary
- if (heap[cidx]->priority < heap[idx]->priority) {
- node = heap[cidx];
- child = heap[idx];
- node->index = idx;
- child->index = cidx;
- heap[cidx] = child;
- heap[idx] = node;
- idx = cidx;
- } else {
- break;
- }
- }
-}
-
-prq_node * prq_create_node() {
- return kmalloc(sizeof(prq_node));
-}
-
-void prq_free_node(prq_node * node) {
- if (node) {
- kfree(node);
- }
-}
-
-prq_node * prq_peek(prq_handle * queue) {
- if (queue) {
- if (queue->count > 0) {
- return queue->heap[1];
- }
- }
-
- return 0;
-}
-
-int prq_count(prq_handle * queue) {
- if (queue) {
- return queue->count;
- }
-
- return 0;
-}
-
-void __prq_amoritize(prq_handle * queue) {
- int new_heap_size = queue->heap_size * AMORITIZED_CONSTANT;
- prq_node** new_heap = (prq_node**) kmalloc(
- sizeof(prq_node*) * new_heap_size);
- os_memcpy((uint32_t *) queue->heap, (uint32_t *) new_heap,
- (os_size_t) queue->heap_size * sizeof(prq_node*));
- kfree(queue->heap);
- queue->heap = new_heap;
- queue->heap_size = new_heap_size;
-}
-
-void prq_enqueue(prq_handle * queue, prq_node * node) {
- prq_node ** heap = queue->heap;
- int index = (node->index = queue->count + 1);
- heap[index] = node;
- ++queue->count;
- __prq_shift_up(queue, index);
- if (queue->count + 1 == queue->heap_size) {
- __prq_amoritize(queue);
- }
-}
-
-void prq_remove(prq_handle * queue, prq_node * node) {
- if (!queue->count) {
- return;
- }
- prq_node ** heap = queue->heap;
- prq_node * end = heap[queue->count];
- int index = (end->index = node->index);
- if (index == -1) {
- return;
- }
- node->index = -1;
- heap[index] = end;
- heap[queue->count + 1] = 0;
- --queue->count;
- // FIXME optimize later
- __prq_shift_up(queue, index);
- __prq_shift_down(queue, index);
-}
-
-prq_node * prq_dequeue(prq_handle * queue) {
- if (!queue->count) {
- return 0;
- }
- prq_node ** heap = queue->heap;
- prq_node * top = heap[1];
- prq_node * end = heap[queue->count];
- end->index = 1;
- top->index = -1;
- heap[1] = end;
- heap[queue->count] = 0;
- --queue->count;
- __prq_shift_down(queue, 1);
- return top;
-}
-
-prq_handle * prq_create_fixed(int n) {
- n = MAX(1, n);
- prq_handle * queue = (prq_handle*) kmalloc(sizeof(prq_handle));
- queue->count = 0;
- queue->heap_size = n + 1;
- queue->heap = (prq_node**) kmalloc(sizeof(prq_node*) * queue->heap_size);
- return queue;
-}
-
-prq_handle * prq_create() {
- return prq_create_fixed(DEFAULT_COUNT);
-}
-
-void prq_free(prq_handle * queue) {
- if (queue) {
- kfree(queue->heap);
- kfree(queue);
- }
-}
diff --git a/kernel/data_structures/ring_buffer.c b/kernel/data_structures/ring_buffer.c
deleted file mode 100644
index c49eac1d..00000000
--- a/kernel/data_structures/ring_buffer.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/********************************************************************
- * ring_buffer.c
- *
- * Author: Brandon Olivier // any collaborators, please add name
- *
- * Date: 14 April 2014
- *
- * Purpose: Provide ring buffer implementation for CourseOS
- *
- * TODO: Add locks or mutexes or something
- *
- ********************************************************************/
-
-#include "ring_buffer.h"
-
-ring_buffer* create(int size)
-{
- ring_buffer* rb = (ring_buffer *) malloc(sizeof(ring_buffer) * size);
- rb->size_limit = size;
- return rb;
-}
-
-int put(ring_buffer *r, void *data)
-{ /* do a size check */
- if(r->size >= r->size_limit)
- return 0; // no space
- r->size++;
- rb_node* node = (rb_node *) malloc(sizeof(rb_node));
- node->data = data;
- r->head->next = node;
- r->head = node;
- node->next = r->tail;
- return 1;
-}
-
-rb_node* get(ring_buffer *r)
-{
- return r->tail;
-}
-
-void clear(ring_buffer *r)
-{
- rb_node* clear = r->tail;
- r->tail = clear->next;
- r->head->next = r->tail;
- //free(clear->data); // nots sure if good idea
- free(clear);
-}
-
-ring_buffer* increase_size(ring_buffer *r, int by)
-{
- int new_limit = r->size + by;
- ring_buffer *new = (ring_buffer *) malloc(sizeof(ring_buffer) * new_limit);
- new->size_limit = new_limit;
- new->size = r->size;
- new->tail = r->tail;
- new->head = r->head;
- free(r);
- return new;
-}
diff --git a/kernel/data_structures/swap_pqueue.c b/kernel/data_structures/swap_pqueue.c
deleted file mode 100644
index 8bd85b94..00000000
--- a/kernel/data_structures/swap_pqueue.c
+++ /dev/null
@@ -1,158 +0,0 @@
-#include
-#include "swap_pqueue.h"
-#include "swap_framework.h"
-#include "klibc.h"
-
-void pqueue_init(struct swap_space *ss)
-{
- head = (struct node*) kmalloc(sizeof(struct node));
- head->next = NULL;
- head->e_head = ss->e_head;
- head->lower_bits = ss->lower_bits;
- head->priority = ss->priority;
- head->store_func = ss->store_func;
- head->retrieve_func = ss->retrieve_func;
- path = head;
- s = 1;
-}
-
-void pqueue_push(struct swap_space *ss)
-{
- struct node *restore = path; int count=1;
- path = head;
- while (count<=pqueue_size()) {
- if (path->priority > ss->priority && count==1) { //set as new head
- head = (struct node*) kmalloc(sizeof(struct node));
- head->next = path;
- pqueue_set(head, ss);
- path = restore;
- break;
- }
- if (path->priority < ss->priority && path->next == NULL) { //set as new tail
- path = restore;
- path->next = (struct node*) kmalloc(sizeof(struct node));
- path = path->next;
- pqueue_set(path, ss);
- path->next = NULL;
- break;
- }
- if (path->priority < ss->priority && count!=pqueue_size() &&
- (path->next)->priority > ss->priority) { //set in between nodes
- struct node *temp = (struct node*) kmalloc(sizeof(struct node));
- pqueue_set(temp, ss);
- temp->next = path->next;
- path->next = temp;
- path = restore;
- break;
- }
- path = path->next;
- count++;
- }
- s++;
-}
-
-//set head to next node and delete previous node
-//pops from front
-void pqueue_pop_front()
-{
- struct node *temp = head;
- head = head->next;
- kfree(temp);
- s--;
-}
-
-void pqueue_pop_back()
-{
- kfree(path);
- path = head;
- while (path->next == NULL) {
- path = path->next;
- }
- s--;
-}
-
-void pqueue_pop_at(uint8_t ssid)
-{
- struct node *temp = head;
- int x;
- for (x = 0; xlower_bits == ssid) {
- break;
- }
- temp = temp->next;
- }
- if (x == 0) {
- pqueue_pop_front();
- } else if (x == pqueue_size()-1) {
- pqueue_pop_back();
- } else {
- struct node *temp2 = head;
- for (int y = 1; ynext;
- }
- temp2->next = temp->next;
- kfree(temp);
- }
-}
-
-void pqueue_set(struct node *h, struct swap_space *ss){
- h->lower_bits = ss->lower_bits;
- h->priority = ss->priority;
- h->store_func = ss->store_func;
- h->retrieve_func = ss->retrieve_func;
- h->e_head = ss->e_head;
-}
-
-struct node *pqueue_index(int i)
-{
- if (i == 0) {
- return head;
- }
- if (i == (pqueue_size()-1)) {
- return path;
- }
-
- struct node *restore = head;
- int x;
- for (x = 0; xnext;
- }
-
- return restore;
-}
-
-uint8_t pqueue_size()
-{
- return s;
-}
-
-// returns specified value from the head of list
-void *pqueue_peek(int type)
-{
- void *foo;
- switch (type) {
- case 0:
- foo = &(head->lower_bits);
- case 1:
- foo = &(head->priority);
- case 2:
- foo = head->e_head;
- }
- return foo;
-}
-
-struct node *pqueue_find(uint8_t ssid)
-{
- struct node *temp = head;
-
- while (temp != NULL) {
- if (temp->lower_bits == ssid) {
- return temp;
- }
- temp = temp->next;
- }
-
- return NULL;
-}
-
-
diff --git a/kernel/debug.sh b/kernel/debug.sh
deleted file mode 100755
index 638978e2..00000000
--- a/kernel/debug.sh
+++ /dev/null
@@ -1 +0,0 @@
-../toolchain/arm-none-eabi/bin/arm-none-eabi-gdb
diff --git a/kernel/drivers/clock.c b/kernel/drivers/clock.c
deleted file mode 100644
index 59d0c96e..00000000
--- a/kernel/drivers/clock.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include
-#include "clock.h"
-
-
-void get_time(){
- uint32_t temp_time = *CLOCK;
- os_printf("the time is? %x\n", temp_time);
- get_seconds(temp_time);
-
-}
-
-void get_seconds(uint32_t time_thing){
- uint32_t SECOND_MASK = 0xF;
- uint32_t TENS_OF_SECONDS_MASK = 0x7;
- uint32_t seconds = time_thing & SECOND_MASK;
- uint32_t tens_seconds = (time_thing >> 4) & TENS_OF_SECONDS_MASK;
- uint32_t total_seconds = seconds + 10 * tens_seconds;
- os_printf("seconds: %d\n", total_seconds);
-
-
-}
diff --git a/kernel/drivers/mmci.c b/kernel/drivers/mmci.c
deleted file mode 100644
index af4591a0..00000000
--- a/kernel/drivers/mmci.c
+++ /dev/null
@@ -1,359 +0,0 @@
-/**
- * @file MMCI (Multimedia Card Interface) Driver
- *
- * @author Joseph Bourque, Matt Davidson, Weston Selleck \n
- * QC and Support: Lane Kolbly
- *
- * @version 1.0
- *
- * @section DESCRIPTION
- *
- * The driver for the SD card; provides an interface between the
- * operating system and the SD card controller. Currently set up
- * to use FIFO for input and output
- *
- * TODO: Need to implement DMA support at some time in the future
- * (Not needed until multi-threading implemented)
- *
- * Completed On: 4/20/2015 Last Updated: 5/5/2015
- */
-#include "klibc.h"
-#include "drivers/mmci.h"
-
-// MMCI Definitions - Used to access SD card registers; DO NOT CHANGE!
-#define MMCI_BASE 0x10005000
-#define CMD 0x00C
-#define DCTRL 0x02C
-#define FIFO 0x080
-#define FIFO_CNT 0x048
-#define STATUS 0x34
-#define ARG 0x008
-#define CLR 0x038
-#define RESP_0 0x14
-#define RESP_1 0x18
-#define RESP_2 0x1C
-#define RESP_3 0x20
-#define DATA_LEN 0x028
-
-// bit shift definitions - Used to modify SD card registers; DO NOT CHANGE!
-#define EXE (1 << 10)
-#define RESP (1 << 6)
-#define LRESP (1 << 7)
-#define RCA_MASK 0xFFFF0000
-#define SET_WRITE 1 | (9 << 4)
-#define SET_READ 3 | (9 << 4)
-#define DISABLE 0x0 | (9 << 4)
-#define READ_CNT (read_mmci(STATUS) & (1 << 21))
-#define WRITE_CNT (read_mmci(FIFO_CNT) > 0)
-#define STATUS_ERR 0x3F
-
-
-
-
-
-/**
- * Initialize SD Card Method
- *
- * Initializes SD card putting it in the transfer state; this should
- * be called when the kernel boots up; readies the SD card for
- * data transfer. Right now this function chooses the first available
- * SD card.
- *
- * TODO: Add to/split up this function in order to work with multiple
- * SD cards i.e. let the user set up additional SD cards past
- * the first
- *
- * @return
- *
- * If the SD card was initialized correctly; this returns 0; otherwise
- * this will return a negative integer value based on the value stored
- * in the status register
- */
-
-int init_sd()
-{
- asm volatile("cpsie if");
- int rca = 0;
-
- // let the SD card know you're about to call one of the ACMD commands
- run_mmci(CMD, 55 | EXE);
-
- // Set up the argument register for the next command
- run_mmci(ARG, 123);
-
- // Set & Execute the ACMD set voltage command
- run_mmci(CMD, 41 | EXE);
-
- // Set & Execute the get card identifier command
- run_mmci(CMD, 2 | EXE | RESP | LRESP);
-
- // Set & execute the obtain RCA command; this will allow you
- // to identifiy and select a particular SD card to read/write
- // to in the event you have more than one card
- run_mmci(CMD, 3 | EXE | RESP);
-
- // obtain RCA address and mask out the status bits
- rca = (read_mmci(RESP_0) & RCA_MASK);
-
- // Load masked RCA address into the argument register
- run_mmci(ARG, rca);
-
- // Run the select card command and point it at the card loaded
- // in the argument register
- run_mmci(CMD, 7 | EXE | RESP);
-
- // Set the data length register to 512 to indicate the amount
- // amount of data to be moved is 512 bytes
- // Note: This sets the value of FIFO count as well
- run_mmci(DATA_LEN, SD_BLOCK_SIZE);
-
- // Eventually print some status message here if the SD card
- // failed to initialize properly but for now just print
- // that it was loaded OK
- os_printf("\nSD card ready for transfer\n");
-
- return status();
-}
-
-/**
- * SD Capacity Method
- *
- * Returns the maximum capacity of the SD card in bytes; for our
- * current needs it computes the size statically
- *
- * TODO: Eventually this needs to be set up to calculate the size
- * of the SD card dynamically to account for different sized
- * SD cards
- *
- * @return Returns the size of the SD card (in bytes)
- */
-uint32_t sd_capacity()
-{
- return 128*1024*1024;
-}
-
-/**
- * Transmit to SD Card Method
- *
- * Writes the contents of the FIFO buffer to the SD card; Writes
- * A single block at a time.
- *
- * @param
- *
- * void* buffer - Holds a single block of data and treats it as a
- bitstream
- * @param
- *
- * uint32_t address - Holds the address of the block of the SD card
- * to write to; the address is a multiple of the
- * block size
- * @return
- *
- * If the write was successful this returns 0; otherwise
- * this returns a negative integer based on the status
- * flags set
- */
-int sd_transmit(void* buffer, uint32_t address)
-{
- //Set the block length on the SD card
- run_mmci(ARG, SD_BLOCK_SIZE);
- run_mmci(CMD, 16 | EXE | RESP);
-
- //Set up the write command
- run_mmci(ARG, address);
- run_mmci(CMD, 24 | EXE | RESP);
- push_bytes(buffer);
-
- // Return that write succeeded for now
- return status();
-}
-
-/**
- * Receive from the SD Card Method
- *
- * Reads the contents of the FIFO buffer from the SD card; reads
- * a single block at a time from the passed address and stores it
- * in the passed buffer
- *
- * @param
- *
- * void* buffer - Serves a a recepticle to place the information
- * read from disk
- * @param
- *
- * uint32_t address - stores the address on disk to read from
- * disk addresses are a mulitple of block
- * size
- *
- * @return
- *
- * Returns 0 if the read was successful; otherwise returns a
- * negative integer based on the value stored in the status
- * register
- */
-int sd_receive(void* buffer, uint32_t address)
-{
- //Clear out FIFO and set to read
- run_mmci(DCTRL, DISABLE);
- run_mmci(DCTRL, SET_READ);
- //Set address to read from & send the command to read
- run_mmci(ARG, address);
- run_mmci(CMD, 17 | EXE | RESP);
-
- pull_bytes(buffer);
-
- // Return that read succeeded for now
- return status();
-}
-
-/**
- * Clear Method
- *
- * Resets all non-dynamic status flags
- *
- * @return
- *
- * Returns 0 if the clear was successful; otherwise returns a negative
- * integer based off the value stored in the status register
- */
-int clear()
-{
- // Return that the clear succeeded for now
- // Clear all status flags
- run_mmci(CLR, 0x2FF);
- return status() ;
-}
-
-
-///// Helper Functions ///// Helper Functions ///// Helper Functions /////
-
-
-/**
- * Push Bytes
- *
- * Helper method for the sd_transmit method; pushes bits into
- * the fifo buffer using the passed buffer space
- *
- * @param
- *
- * void* buffer - An address which represents 1 block of data;
- * provides a space for FIFO to interact with
- * when writing to the SD card
- *
- * @return
- *
- * Returns 0 if the write was successful; otherwise returns a
- * negative integer based on the value stored in the status
- * register
- */
-int push_bytes(void* buffer)
-{
- //Clear out FIFO and set to write
- run_mmci(DCTRL, DISABLE);
- run_mmci(DCTRL, SET_WRITE);
- int i = 0;
- while(WRITE_CNT){
- run_mmci(FIFO, ((uint32_t*)buffer)[i]);
- i++;
- }
-
- // Return that the push succeeded for now
- return status();
-}
-
-/**
- * Pull Bytes Method
- *
- * Helper function for the sd_recieve method; pulls bits out of
- * the FIFO buffer and stores them in the buffer passed into
- * the function (buffer represents 1 block of data)
- *
- * @param
- *
- * void* buffer - An address in memory representing 1 block
- * of data; provides a space for FIFO to store
- * the result of the read from the SD card
- *
- * @return
- *
- * Returns 0 if the read was successful; otherwise returns a
- * negative integer based on the value stored in the status
- * register
- */
-int pull_bytes(void* buffer)
-{
- int i = 0;
- while(READ_CNT){
- ((uint32_t*) buffer)[i] = read_mmci(FIFO);
- i++;
- }
-
- // Return that the pull succeeded for now
- return status();
-}
-
-/**
- * Run MMCI Method
- *
- * This method is primarily used to run the various mmci commands
- * and it does so by using ARM assembly to store a value in register
- * corresponding to an MMCI command
- *
- * @param
- *
- * uint32_t cmd - Stores the address offset based on the MMCI base
- * address for a MMCI command.
- *
- * @param
- *
- * uint32_t args - Represents the bits which will actually be set
- * on the register when running a specific command
- */
-void run_mmci(uint32_t cmd, uint32_t args)
-{
- uint32_t reg_address = MMCI_BASE+cmd;
- asm volatile("str %0,[%1]" : : "r" (args), "r" (reg_address));
-}
-
-/**
- * Read MMCI Method
- *
- * This method is primarily used for getting some response from a MMCI
- * register (response register, status register, etc.)
- *
- * @param
- *
- * uint32_t target - Passes in the target register to read; represented
- * as an offset to the MMCI base address
-
- * @return
- *
- * Returns the value stored in the target register as an integer value
- */
-uint32_t read_mmci(uint32_t target)
-{
- uint32_t response;
- uint32_t reg_address = MMCI_BASE + target;
- asm volatile("ldr %0,[%1]" : "=r" (response) : "r" (reg_address));
- return response;
-}
-
-/**
- * Status Method
- *
- * Helper method which handles error detection for the driver; because
- * multiple bits can be set due to multiple errors; combine bits where
- * neccessary to obtain error code
- *
- *@return
- *
- * if no error - will return 0
- * if -1 , error code 0
- * if -2 , error code 1
- * if -3 , error code 0 and 1
- */
-int status(){
-uint32_t stat = read_mmci(STATUS);
-int error= stat & STATUS_ERR;
-return (~error+1);
-}
diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c
deleted file mode 100644
index d9b1efcb..00000000
--- a/kernel/drivers/timer.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/* Device Driver for ARM Dual-Timer Module (SP804)
- Reference Manual can be found here : http://infocenter.arm.com/help/topic/com.arm.doc.ddi0271d/DDI0271.pdf*/
-//#include
-#include "klibc.h"
-#include "drivers/timer.h"
-#include "interrupt.h"
-
-rasp_pi_timer *timer_pointers[4];
-
-void timer_irq_handler(void* args);
-void (*handlers[4])(void *args);
-
-/* initializes timers as an array. Call this before
- * using any of the timer functions */
-void initialize_timers()
-{
- os_printf("initializing timers\n");
- volatile rasp_pi_timer *TIMER_0 = (rasp_pi_timer *) 0x101e2000;
- volatile rasp_pi_timer *TIMER_1 = (rasp_pi_timer *) 0x101e2020;
- volatile rasp_pi_timer *TIMER_2 = (rasp_pi_timer *) 0x101e3000;
- volatile rasp_pi_timer *TIMER_3 = (rasp_pi_timer *) 0x101e3020;
- timer_pointers[0] = (rasp_pi_timer*) TIMER_0;
- timer_pointers[1] = (rasp_pi_timer*) TIMER_1;
- timer_pointers[2] = (rasp_pi_timer*) TIMER_2;
- timer_pointers[3] = (rasp_pi_timer*) TIMER_3;
-
- handlers[0] = NULL;
- handlers[1] = NULL;
- handlers[2] = NULL;
- handlers[3] = NULL;
-
- interrupt_handler_t *tmr_handler = kmalloc(sizeof(interrupt_handler_t));
- tmr_handler->handler = timer_irq_handler;
- register_interrupt_handler(4, tmr_handler);
-}
-
-#define CHECK_TIMER_INDEX(index) { if (index < 0 || index > 4) return -1; }
-
-/* This function sets the value that the timer will begin at.
- * This operation also resets the timer to this new value.
- * if you want to keep the timer running with its current state
- * use set background load. */
-int set_load_value(int timer_index, int value)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- timer_pointers[timer_index]->timer_load_value = value;
- return 0;
-}
-
-//returns the current control register value (configuration of timer)
-int get_timer_control_value(int timer_index)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- return timer_pointers[timer_index]->control;
-}
-
-/* Sets the value for the timer to load the next time it reaches
- * 0 and loads the reset value. Does not affect current timer. */
-int set_background_load_value(int timer_index, int value)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- timer_pointers[timer_index]->background_timer_load_value = value;
- return 0;
-}
-
-/* Clear any interrupt data for the timer.
- * note: writing to the clear timer register clears
- * the interrupt status completely. */
-int clear_interrupt(int timer_index)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- timer_pointers[timer_index]->interrupt_clear = 0x1;
-
- return 0;
-}
-
-//enable 32 bit mode in the specified timer index
-int set_32_bit_mode(int timer_index)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- disable_timer(timer_index);
- timer_pointers[timer_index]->control |= 0x2;
- return 0;
-}
-
-int get_current_timer_value(int timer_index)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- return timer_pointers[timer_index]->timer_actual_value;
-}
-
-//enable periodic mode of specified timer index
-int set_periodic_mode(int timer_index)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- disable_timer(timer_index);
- timer_pointers[timer_index]->control &= 0xFFFFFFBE;
-
- return 0;
-}
-
-//converts ms into ticks
-//assumes modes are valid, if not, should return 0
-int conversion(int timer_index, int milliseconds)
-{
- int mode = (timer_pointers[timer_index]->control & 0xC) >> 2;
-
- int ticks = 0;
- if (mode == 0)
- {
- ticks = 32;
- }
- else if (mode == 1)
- {
- ticks = 256;
- }
- else if (mode == 2)
- {
- ticks = 1000;
- }
- return milliseconds * ticks;
-}
-
-//function to set timer to different timer clock rates... 0 -> 1 (default), 1 -> 16, 2 -> 256...
-//any other modes are invalid and will do nothing
-int set_prescale(int timer_index, int mode)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- disable_timer(timer_index);
- if (mode == 0)
- timer_pointers[timer_index]->control &= 0xFFFFFFF3;
- else if (mode == 1)
- {
- timer_pointers[timer_index]->control |= 0x4;
- timer_pointers[timer_index]->control &= 0xFFFFFFF7;
- }
- else if (mode == 2)
- {
- timer_pointers[timer_index]->control |= 0x8;
- timer_pointers[timer_index]->control &= 0xFFFFFFFB;
- }
- return 0;
-}
-
-//enables timer interrupt of the given timer index
-int enable_timer_interrupt(int timer_index)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- timer_pointers[timer_index]->control |= (1 << 5);
- return 0;
-}
-
-//disables timer interrupt of the given timer index
-int disable_timer_interrupt(int timer_index)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- timer_pointers[timer_index]->control &= 0xFFFFFFDF;
- return 0;
-}
-
-int set_free_running_mode(int timer_index)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- disable_timer(timer_index);
- timer_pointers[timer_index]->control |= 0x1;
- return 0;
-}
-
-//starts the timer, countdown from load value
-int enable_timer(int timer_index)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- timer_pointers[timer_index]->control |= (1 << 7);
- return 0;
-}
-
-//pauses the timer
-int disable_timer(int timer_index)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- timer_pointers[timer_index]->control &= 0xFFFFFF7F;
- return 0;
-}
-
-//prints the configuration of the control byte
-int print_control_status(int timer_index)
-{
- CHECK_TIMER_INDEX(timer_index);
-
- os_printf("control byte:%x", timer_pointers[timer_index]->control);
- return 0;
-}
-
-/*starts interrupts every start_val ticks */
-//You give it a vallut and the specific timer you want to star.
-// YOu have four timers just start with timer zero
-// The speed of counter or number ticks depends on qemu hertz speed
-// we don't know he start of it but it should be around 10 milliseconds
-// per proccess.
-// ex: start_timer_interrupts(0,10) which means start timer(0)
-// and interrupt every 10 clicks.
-int start_timer_interrupts(int timer_index, int milliseconds)
-{
-// conversion(timer_index, milliseconds);
- CHECK_TIMER_INDEX(timer_index);
-
- int clicks = conversion(timer_index, milliseconds);
-
- os_printf("CLICKS ARE %d\n", clicks);
-
- set_background_load_value(timer_index, clicks);
- set_periodic_mode(timer_index);
- enable_timer_interrupt(timer_index);
- enable_timer(timer_index);
- return 0;
-}
-
-int register_handler(int timer_index, void (*handler)(void *args))
-{
- CHECK_TIMER_INDEX(timer_index);
- handlers[timer_index] = handler;
- return 0;
-}
-
-int unregister_handler(int timer_index)
-{
- CHECK_TIMER_INDEX(timer_index);
- handlers[timer_index] = NULL;
- return 0;
-}
-
-void timer_irq_handler(void* args)
-{
- clear_interrupt(0);
-
- os_printf("@@@@@@ RECEIVED TIMER INTERRUPT\n");
-
- // TODO: find out which timer fired. For the moment, hard-code to 0
- if (handlers[0] != NULL)
- {
- handlers[0](args);
- }
-}
-
-void timer_test()
-{
-
-// enable_interrupt(ALL_INTERRUPT_MASK);
-
- /*interrupt_handler_t *tmr_handler = kmalloc(sizeof(interrupt_handler_t));
- tmr_handler->handler = simple_timer_handler;
- os_printf("fn ptr: %X\n", simple_timer_handler);
- register_interrupt_handler(4, tmr_handler);*/
-
- os_printf("FIQ status: %X\n", mmio_read(VIC_FIQ_STATUS));
- initialize_timers();
- start_timer_interrupts(0, 10);
- //print_control_status(1);
-
- // Wait forever...
- /* os_printf("\n");
- int cnt = 0;
- os_printf("Timer: %d\n", timer_pointers[0]->timer_actual_value);
- os_printf("Timer: %d\n", timer_pointers[0]->timer_actual_value);
- os_printf("Timer: %d\n", timer_pointers[0]->timer_actual_value);
- while (!(timer_pointers[0]->masked_interrupt_status&1)) {
- cnt++;
- //os_printf("%X\n", timer_pointers[1]->timer_actual_value);
- int i;
- for (i=0; i<1000; i++);
- }
- os_printf("%d\n", cnt);
- os_printf("%X\n", mmio_read(PIC_ADDRESS+0x8));
- os_printf("%X\n", mmio_read(VIC_IRQ_STATUS));
- os_printf("%X\n", mmio_read(VIC_FIQ_STATUS));
- os_printf("Timer: %d\n", timer_pointers[0]->timer_actual_value);
- os_printf("Timer: %d\n", timer_pointers[0]->timer_actual_value);
- os_printf("Timer: %d\n", timer_pointers[0]->timer_actual_value);
- while(1);
- */
- return;
-}
diff --git a/kernel/drivers/uart.c b/kernel/drivers/uart.c
deleted file mode 100644
index 3ce28b3e..00000000
--- a/kernel/drivers/uart.c
+++ /dev/null
@@ -1,105 +0,0 @@
-#include
-#include "drivers/uart.h"
-#include "mmap.h"
-
-void print_uart0(const char *s)
-{
- while (*s != '\0')
- {
- mmio_write(UART0_ADDRESS, *s);
- s++;
- }
-}
-
-void print_char_uart0(char c)
-{
- mmio_write(UART0_ADDRESS, c);
-}
-
-/* print the full 32 bits of a word at the given address */
-/* trailing newline... */
-void print_word_bits(uint32_t * c)
-{
- int i;
- for (i = 31; i >= 0; i--)
- *c & (1 << i) ? print_uart0("1") : print_uart0("0");
- print_uart0("\n");
-}
-
-/* print the full 8-digit hex code of a word at the given address */
-/* no '0x' prefix, NO trailing newline */
-void print_word_hex(uint32_t * c)
-{
- int i;
- uint32_t a;
- for (i = 0x7; i >= 0x0; i--)
- {
- a = *c & (0xf << (i * 0x4));
- a >>= (i * 0x4);
-
- if (a <= 9)
- mmio_write(UART0_ADDRESS, (uint32_t )(a + (uint32_t )'0'));
- else if (a <= 0xf)
- mmio_write(UART0_ADDRESS, (uint32_t )((a - 0xa) + (uint32_t )'a'));
- else
- mmio_write(UART0_ADDRESS, (uint32_t )('?'));
- }
-}
-
-/* display memory at given address */
-/* format is: "[address]: word1 word2 word3\n", etc. */
-/* displays 30 words (10 lines) */
-void md(uint32_t * start)
-{
- int i, j;
- uint32_t *addr = start;
- for (i = 0; i < 10; i++)
- {
- print_uart0("0x");
- print_word_hex((uint32_t *) &addr);
- print_uart0(": ");
- for (j = 0; j < 3; j++)
- {
- print_word_hex(addr);
- print_uart0(" ");
- addr++;
- }
- print_uart0("\n");
- }
-}
-
-/*void print_uart0(const char *s) {*/
-/*while (uart->dd->uart0_inter_val == 0) {}*/
-/*if(uart.UARTCR & RXE > 0) */
-/*{*/
-/*while(*s != '\0') */
-/*{*/
-/**UART0 = (uint32_t)(*s);*/
-/*s++;*/
-/*}*/
-/*}*/
-/*}*/
-
-/* We need to implement a lock here. klibc will be implementing the buffer
- * we just need to ensure the FIFO isn't read out of order.
- */
-/*char *read_uart0() */
-/*{*/
-/*uint32_t buffer[STD_IN_BUFFER_SIZE] = {0};*/
-/*while (uart->dd->uart0_inter_val == 0) {}*/
-/*uint32_t *iterator = buffer;*/
-/*do */
-/*{*/
-/*if(uart.UARTCR & TXE > 0) */
-/*{*/
-/*break;*/
-/*} */
-/*else */
-/*{*/
-/**iterator = uart.UARTDR;*/
-/*iterator++;*/
-/*}*/
-/*} while (*iterator != '\0');*/
-/*return buffer;*/
-/*}*/
-
diff --git a/kernel/drivers/uart_pi.c b/kernel/drivers/uart_pi.c
deleted file mode 100644
index 11d9464d..00000000
--- a/kernel/drivers/uart_pi.c
+++ /dev/null
@@ -1,151 +0,0 @@
-#include
-#include "drivers/uart.h"
-#include "mmap.h"
-
-#define UARTDR (UART0_ADDRESS_PI+0x00) // Data Register
-#define UARTRSR (UART0_ADDRESS_PI+0x04) //Recieve status register
-#define UARTFR (UART0_ADDRESS_PI+0x18) // Flag Register
-#define UARTILPR (UART0_ADDRESS_PI+0x20) //IrDA low power counter register
-#define UARTIBRD (UART0_ADDRESS_PI+0x24) // Integer baud rate
-#define UARTFBRD (UART0_ADDRESS_PI+0x28) //Fractional baud rate register
-#define UARTLCR_H (UART0_ADDRESS_PI+0x2C) // Line control register
-#define UARTCR (UART0_ADDRESS_PI+0x30) //Control Register
-#define UARTIFLS (UART0_ADDRESS_PI+0x34) // Interrupt FIFO level select register
-#define UARTIMSC (UART0_ADDRESS_PI+0x38) //Interrupt mask set/clear register
-#define UARTRIS (UART0_ADDRESS_PI+0x3C) //Raw interrupt status register
-#define UARTMIS (UART0_ADDRESS_PI+0x40) //masked interrupt status register
-#define UARTICR (UART0_ADDRESS_PI+0x44) // Interrupt clear register
-#define UARTDMACR (UART0_ADDRESS_PI+0x48) // DMA controlled register
-#define GPPUD (GPIO_ADDRESS_PI + 0x94) //Controls pull up/down on GPIO pins
-#define GPPUDCLK0 (GPIO_ADDRESS_PI + 0x98) //GPIO Clock
-
-
-void init_uart()
-{
- //Disable UART
- mmio_write(UARTCR, 0x00000000);
-
- mmio_write(GPPUD, 0x00000000);
- for(int i = 0;i<150;i++){
- asm volatile ("nop");
- }
-
- mmio_write(GPPUDCLK0, (1<<14) | (1<<15));
- for(int i = 0;i<150;i++){
- asm volatile ("nop");
- }
-
- mmio_write(GPPUDCLK0,0x00000000);
-
- mmio_write(UARTICR, 0x7FF);
- //Enable DMA memory reads & writes with UART
- //mmio_write(UARTDMACR, (1<<0) | (1<<1));
-
- //Enable FIFO and set word length to 8
- mmio_write(UARTLCR_H, (1<<4) | (1<<5) | (1<<6));
- //Set the baud transfer rate at 115200
- mmio_write(UARTIBRD, 1);
- mmio_write(UARTFBRD, 40);
-
- //Enable interrupts
- mmio_write(UARTIMSC, (1 << 1) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10));
- //Enable UART and UART transfer
- mmio_write(UARTCR, (1<<0) | (1<<8));
-}
-
-void print_char_uart0(char c) {
- //Wait for room in the FIFO queue
- while(mmio_read(UARTFR) & (1<<5)) {}
- mmio_write(UART0_ADDRESS_PI, c); //Changed
-}
-
-void print_uart0(const char *s) {
- while(*s != '\0') {
- while(mmio_read(UARTFR) & (1<<5)) {}
-
- print_char_uart0(*s); //Altering for testing purposes, don't kill me!
- s++;
- }
-}
-
-
-
-/* print the full 32 bits of a word at the given address */
-/* trailing newline... */
-void print_word_bits(uint32_t * c) {
- int i;
- for(i = 31; i >= 0; i--)
- *c & (1 << i) ? print_uart0("1") : print_uart0("0");
- print_uart0("\n");
-}
-
-/* print the full 8-digit hex code of a word at the given address */
-/* no '0x' prefix, NO trailing newline */
-void print_word_hex(uint32_t * c){
- int i;
- uint32_t a;
- for(i = 0x7; i >= 0x0; i--){
- a = *c & (0xf << (i*0x4));
- a >>= (i*0x4);
- while(mmio_read(UARTFR) & (1<<5)) {}
- if(a <= 9)
- mmio_write(UART0_ADDRESS_PI, (uint32_t)(a + (uint32_t )'0')); //Changed
- else if(a <= 0xf)
- mmio_write(UART0_ADDRESS_PI, (uint32_t)((a - 0xa) + (uint32_t )'a'));//Changed
- else
- mmio_write(UART0_ADDRESS_PI, (uint32_t)('?')); //Changed
- }
-}
-
-/* display memory at given address */
-/* format is: "[address]: word1 word2 word3\n", etc. */
-/* displays 30 words (10 lines) */
-void md(uint32_t * start){
- int i, j;
- uint32_t *addr = start;
- for(i = 0; i < 10; i++) {
- print_uart0("0x"); print_word_hex((uint32_t *)&addr); print_uart0(": ");
- for(j = 0; j < 3; j++) {
- print_word_hex(addr);
- print_uart0(" ");
- addr++;
- }
- print_uart0("\n");
- }
-}
-
-/*void print_uart0(const char *s) {*/
-/*while (uart->dd->uart0_inter_val == 0) {}*/
-/*if(uart.UARTCR & RXE > 0) */
-/*{*/
-/*while(*s != '\0') */
-/*{*/
-/**UART0 = (uint32_t)(*s);*/
-/*s++;*/
-/*}*/
-/*}*/
-/*}*/
-
-/* We need to implement a lock here. klibc will be implementing the buffer
- * we just need to ensure the FIFO isn't read out of order.
- */
-/*char *read_uart0() */
-/*{*/
-/*uint32_t buffer[STD_IN_BUFFER_SIZE] = {0};*/
-/*while (uart->dd->uart0_inter_val == 0) {}*/
-/*uint32_t *iterator = buffer;*/
-/*do */
-/*{*/
-/*if(uart.UARTCR & TXE > 0) */
-/*{*/
-/*break;*/
-/*} */
-/*else */
-/*{*/
-/**iterator = uart.UARTDR;*/
-/*iterator++;*/
-/*}*/
-/*} while (*iterator != '\0');*/
-/*return buffer;*/
-/*}*/
-
diff --git a/kernel/elf.c b/kernel/elf.c
deleted file mode 100644
index 8038efe6..00000000
--- a/kernel/elf.c
+++ /dev/null
@@ -1,259 +0,0 @@
-/* Worked on by Jeremy Wenzel, Kaelen Haag, and Sam Allen */
-#include "elf.h"
-#include "klibc.h"
-#include // Probably going to be removed
-
-unsigned char* filePointer;
-unsigned char* startPointer;
-//OVERHAUL TO MAKE EVERYTHING PASSED BY REFERENCE RATHER THAN VALUE.
-//I THINK WE SHOULD JUST COMMENT OUT ALL THE SECTION HEADER STUFF BECAUSE IT'S NOT USED AND WILL BE A PAINTO MESS WITH. NEED TO MAKE PROGRAM HEADER ARRAY PASS BY VALUE AND NEED TO FIX get_value to take in refernce rather than value. DO TONIGHT OR TOMORROW - KAELEN
-
-/* Gets the value of the bytes on a big endian system */
-uint32_t do_big_endian(uint32_t size)
-{
- uint32_t value = 0;
- while (size > 0)
- {
- value = value << 8;
- value = value + *filePointer;
- filePointer++;
- size--;
- }
- return value;
-}
-
-/* Gets the value of the bytes on a little endian system */
-uint32_t do_little_endian(uint32_t size)
-{
- uint32_t value = 0;
- uint32_t num = 0;
- int i = 0;
- while (i < size)
- {
- num = *filePointer;
- num = num << (8 * i);
- value = value + num;
- filePointer++;
- i++;
- }
- return value;
-
-}
-
-/* Gets value of bytes given a size of bytes */
-//Make this pass by reference
-uint32_t get_value(uint32_t size, Elf_Ehdr *h)
-{
- if (h->e_ident[EI_DATA] == 1)
- return do_little_endian(size);
- else
- return do_big_endian(size);
-}
-
-/* Checks if the file is even an elf file */
-/* Returns 1 if elf file, -1 if not */
-int32_t isElf(Elf_Ehdr *h)
-{
- // checks if elf file
- char ELFMAG0 = get_value(1, h);// 0x7f
- char ELFMAG1 = get_value(1, h);// 'E'
- char ELFMAG2 = get_value(1, h);// 'L'
- char ELFMAG3 = get_value(1, h);// 'F'
- if (ELFMAG0 != 127 || ELFMAG1 != 'E' || ELFMAG2 != 'L' || ELFMAG3 != 'F')
- return -1;
- h->e_ident[EI_MAG0] = ELFMAG1;
- h->e_ident[EI_MAG1] = ELFMAG2;
- h->e_ident[EI_MAG2] = ELFMAG3;
- return 1;
-}
-
-/* Parses elf header of ELF file and places into ELF struct header */
-/* CRITICAL: It is important to initialize the elf header before
- sending it into the function. Makes sure no data is lost */
-int32_t read_elf_header(Elf_Ehdr *h, unsigned char *pointer)
-{
- filePointer = startPointer = pointer;
- int32_t check = isElf(h);
- if (check == -1)
- {
- return -1;
- }
- //os_printf("Size of char: %d\n", sizeof(char));
- //os_printf("Size of get_value(1, h): %d\n", sizeof((char)get_value(1, h)));
- char temp = get_value(1, h);
- //os_printf("Size of temp: %d\n", sizeof(temp));
- h->e_ident[EI_CLASS] = temp; // get_value(1, h); // get class
-
- temp = get_value(1, h);
- h->e_ident[EI_DATA] = temp; //get_value(1, h); // endian
-
- temp = get_value(1, h);
- h->e_ident[EI_VERSION] = temp; //get_value(1, h); // original version of ELF
-
- temp = get_value(1, h);
- h->e_ident[EI_OSABI] = temp; //get_value(1, h); // Target operating system ABI
-
- temp = get_value(1, h);
- h->e_ident[EI_ABIVERSION] = temp; //get_value(1, h); // Don't really know?
-
- int32_t skip = 0; // skips the padding
- while (skip < 7)
- {
- get_value(1, h);
- skip++;
- }
- Elf_Half half_temp = get_value(2, h);
- h->e_type = half_temp; //get_value(2, h); // get type of file
-
- half_temp = get_value(2, h);
- h->e_machine = half_temp; //get_value(2, h); // gets machine type (should be arm in our case)
-
- Elf_Word word_temp = get_value(4, h);
- h->e_version = word_temp; //get_value(4, h); // version number (should be 1)
- if (h->e_ident[EI_CLASS] == 1) // get entry point
- {
- word_temp = get_value(4, h);
- h->e_entry = word_temp; //get_value(4, h);
- }
- else
- h->e_entry = get_value(8, h);
-
- if (h->e_ident[EI_CLASS] == 1) // get program header offset
- {
- word_temp = get_value(4, h);
- h->e_phoff = word_temp; //get_value(4, h);
- }
- else
- h->e_phoff = get_value(8, h);
-
- if (h->e_ident[EI_CLASS] == 1) // get section header offset
- {
- word_temp = get_value(4, h);
- h->e_shoff = word_temp; //get_value(4, h);
- }
- else
- h->e_shoff = get_value(8, h);
-
- word_temp = get_value(4, h);
- h->e_flags = word_temp; //get_value(4, h); // get flag number
-
- half_temp = get_value(2, h);
- h->e_ehsize = half_temp; //get_value(2, h); // get elf header size
-
- half_temp = get_value(2, h);
- h->e_phentsize = half_temp; //get_value(2, h); // get program header size
-
- half_temp = get_value(2, h);
- h->e_phnum = half_temp; //get_value(2, h); // number of program headers
-
- half_temp = get_value(2, h);
- h->e_shentsize = half_temp; //get_value(2, h); // section header size
-
- half_temp = get_value(2, h);
- h->e_shnum = half_temp; //get_value(2, h); // number of section headers
-
- half_temp = get_value(2, h);
- h->e_shstrndx = half_temp; //get_value(2, h); // section header string table index
-
- return 1; // return success
-}
-
-void read_program_header_table(Elf_Ehdr *eh, Elf_Phdr ph[],
- unsigned char *pointer)
-{
- filePointer = startPointer = pointer;
- filePointer = startPointer + eh->e_phoff;
- int i = 0;
- Elf_Word word_temp = 0;
- while (i < eh->e_phnum)
- {
- word_temp = get_value(4, eh);
- ph[i].p_type = word_temp; //get_value(4, eh);
- ph[i].p_offset = get_value(4, eh);
- ph[i].p_vaddr = get_value(4, eh);
- ph[i].p_paddr = get_value(4, eh);
- ph[i].p_filesz = get_value(4, eh);
- ph[i].p_memsz = get_value(4, eh);
- ph[i].p_flags = get_value(4, eh);
- ph[i].p_align = get_value(4, eh);
- i++;
- }
-
-}
-
-/* Reads the section header table and places it into the the section header array */
-/* CRITICAL: The section header must be initalized with the correct size,
- before put into the function */
-void read_section_header_table(Elf_Ehdr *eh, Elf_Shdr sh[], uint32_t *pointer)
-{
- filePointer = startPointer = (unsigned char*) pointer;
- int i = 0;
- filePointer = startPointer + eh->e_shoff;
- while (i < eh->e_shnum)
- {
- sh[i].sh_name = get_value(4, eh);// get name, which is index into string table
- sh[i].sh_type = get_value(4, eh); // type of section header
- sh[i].sh_flags = get_value(4, eh); // flags that partain to the header
- sh[i].sh_addr = get_value(4, eh);// address of header (don't know much yet)
- sh[i].sh_offset = get_value(4, eh); // offset from beginning of elf file
- sh[i].sh_size = get_value(4, eh); // size of this section
- sh[i].sh_link = get_value(4, eh); // link (don't know much yet)
- sh[i].sh_info = get_value(4, eh); // info (don't know much yet)
- sh[i].sh_addralign = get_value(4, eh);// address aligned (don't know much yet)
- sh[i].sh_entsize = get_value(4, eh);
- i++;
- }
-}
-
-/* Goes to the Section header that contains the section header string table */
-/* It then analyzes the table and puts them into each section header */
-/* This makes it easier to differentiate between sections when put into loader */
-void parse_section_header_names(Elf_Ehdr *eh, Elf_Shdr sh[], uint32_t *pointer)
-{
- filePointer = startPointer = (unsigned char*) pointer;
- filePointer = startPointer + sh[eh->e_shstrndx].sh_offset;// This pointer iterates through the section header
- int i = 1;
-
- filePointer++;
- while (i < eh->e_shnum)
- {
- if (os_strcmp(((char*) filePointer), ".symtab") == 0)
- { // checks if symbol table
- sh[i].sh_numname = SYMTAB;
- }
- else if (os_strcmp(((char*) filePointer), ".text") == 0)
- { // checks if .text table
- sh[i].sh_numname = TEXT;
- }
- else if (os_strcmp(((char*) filePointer), ".comment") == 0)
- { // checks if comment table
- sh[i].sh_numname = COMMENT;
- }
- else if (os_strcmp(((char*) filePointer), ".strtab") == 0)
- { // checks if string table
- sh[i].sh_numname = STRTAB;
- }
- else if (os_strcmp(((char*) filePointer), ".shstrtab") == 0)
- { // checks if section header string table
- sh[i].sh_numname = SHSTRTAB;
- }
- else if (os_strcmp(((char*) filePointer), ".rodata") == 0)
- { // checks if read only data
- sh[i].sh_numname = RODATA;
- }
- else if (os_strcmp(((char*) filePointer), ".data") == 0)
- { // checks if initialized data
- sh[i].sh_numname = DATA;
- }
- else if (os_strcmp(((char*) filePointer), ".bss") == 0)
- { // checks if unitialized data
- sh[i].sh_numname = BSS;
- }
- else
- ;
- while (*((char*) filePointer) != '\0')// move on to next sting in the list
- filePointer++;
- filePointer++;
- i++; // move on to next item in section header table
- }
-}
diff --git a/kernel/fs/cmdline/Documents b/kernel/fs/cmdline/Documents
deleted file mode 100644
index f8955934..00000000
--- a/kernel/fs/cmdline/Documents
+++ /dev/null
@@ -1,159 +0,0 @@
-#ifndef __FILE_H__
-#define __FILE_H__
-
-
-#include "bitvector.h"
-#include
-
-#define BLOCKSIZE 512
-#define MAX_NAME_LENGTH 32
-#define MAX_DATABLOCKS_PER_INODE 68
-#define DIR_ENTRY_SIZE 40
-#define MAX_NUM_INDIRECT_BLOCKS 50
-#define MAX_DATABLOCKS_PER_INDIRECT_BLOCK ((BLOCKSIZE/4)-2)
-#define MAX_DIR_ENTRIES_PER_DATA_BLOCK ((int)((BLOCKSIZE-4)/DIR_ENTRY_SIZE)-2)
-
-//IMPORTANT!! ---------------------------------------------------------------------------------------------------
-//all constants are in units of block NUMBER |
-//the indexes of arrays are also in units of block NUMBER relative to the starting offset of their cathegory. |
-//---------------------------------------------------------------------------------------------------------------
-
-//constants of file system, that wil be filled at boot time
-struct superblock
-{
- // char* fs_name; // 32 bytes (max length for this field abides by MAX_NAME_LENGTH)
- int fs_version; // 36 bytes
- int magic_num; // 40 bytes
- int sd_card_capacity; // 44 bytes
- int block_size; // 48 bytes
- int root_inum; // 52 bytes
- int max_inodes; // 56 bytes
- int inode_size;
- int max_data_blocks; // 66 bytes
- int inode_bitmap_loc; // 70 bytes
- int data_bitmap_loc; // 74 bytes
- // int indirect_blocks_bitmap_loc; //
- int start_inode_table_loc; // 78 bytes
- int start_data_blocks_loc; // 82 bytes, start_inode_table_loc + 200 b/c 200 inode bl
- // int start_indirect_block_table_loc; //
- // int max_indirect_blocks;
- // char spaceholder[???]; Might need this to make the cast from memory to superblock work...not sure??? Don't think we need this, but not sure
- // the rest of the superblock will be empty for now (BLOCKSIZE - 82 = 512 - 82 = 430 free/wasted bytes)
-};
-
-//metadata of each file or directory
-struct inode {
- int inum; //inum of the file (4bytes)
- int fd_refs; //how many times the file is referenced (=appears in the opentable) (4bytes)
- int size; // size of the whole file (4 bytes)
- int is_dir; // 1 if this is a directory, 0 if this is a file (4 bytes)
- int usr_id; // id of the user who created the file (4 bytes) ...not yet used!
- int direct_blocks_in_file; // how many direct block are being used (4 bytes)
- int data_blocks[MAX_DATABLOCKS_PER_INODE]; // array of data (now long 68)
- int indirect_blocks_in_file; // how many indirect block are being used (4 bytes)
- int indirect_blocks[MAX_NUM_INDIRECT_BLOCKS]; // 50*4 = 200 bytes ....50 indirect blocks right now
- bit_vector* perms; // permissions of the file (12 bytes)
-};
-
-struct indirect_block // total size is 1 block
-{
- int block_num;
- int blocks_in_file; //blocks actually used
- int data_blocks[MAX_DATABLOCKS_PER_INDIRECT_BLOCK]; // because this is just an array of ints, so it's BLOCKSIZE/4 bytes bc each int is 4 bytes
-};
-
-struct dir_entry
-{
- int inum;
- int name_length; //including null terminating string
- char name[MAX_NAME_LENGTH]; // 32 chars right now
-}; // 8 _ MAX_NAME_LENGTH bytes long...40 bytes right now
-
-struct dir_data_block
-{
- int block_num;
- int num_entries;
- struct dir_entry dir_entries[MAX_DIR_ENTRIES_PER_DATA_BLOCK];
-};
-
-struct data_block
-{
- char data[BLOCKSIZE];
-};
-
-struct dir_helper //used by helper functions in file.c
-{
- int dir_levels;
- char* truncated_path;
- char* last;
-};
-
-struct stats //statistics about the file
-{
- int size; //size of the file
- int fd_refs; //how many times it is open now
- int is_dir; //is this a directory
-};
-
-int kopen(char* filepath, char mode); //opens the file of filepath with permissions mode
-int kread(int fd, void* buf, int numBytes); //reads the open file corresponding to fd
-int kwrite(int fd, void* buf, int num_bytes); //writes the open file corresponding to fd
-int kclose(int fd); //closes the cpen file corresponding to fd
-int kseek(int fd, int num_bytes); //moves the offset of the open file fd
-int kdelete(char* filepath); //deletes the file or directory following filepath
-int kcreate(char* filepath, char mode, int is_this_a_dir); //creates and opens a file or directory with permissions mode in fielpath
-int kcopy(char* source, char* dest, char mode); //copies the contents of a file
-int kls(char* filepath); //shows contents of one directory
-int kfs_init(int inode_table_cache_size, int data_block_table_cache_size, int reformat);
-int kfs_shutdown();
-
-// // -------------------------------------------------------------------------------------------------------------------------------------------------------
-// /* HELPER FUNCTIONS */
-
-//from the index, gets the corresponding indirect block, either from cache or from disk
-void get_indirect_block(int index, struct indirect_block* cur_indirect_block);
-
-//from the inum, gets corresponding inode, either from cache or disk
-void get_inode(int inum, struct inode* result_inode);
-
-//gets the inum of nextpath (file or dir) looking at the direct data blocks of cur_inode
-int get_inum_from_direct_data_block(struct inode* cur_inode, char * next_path);
-
-//gets the inum of netxpath (file or dir) looking at the indirect data blocks of cur_inode
-int get_inum_from_indirect_data_block(struct inode * cur_inode, char * next_path);
-
-//finds the inode (will be result_inode) following filepath, going dir_levels down the path, starting from starting_inum
-int kfind_inode(char* filepath, int starting_inum, int dir_levels, struct inode* result_inode);
-
-//finds the name of the directory path (result->truncated_path) and the name of the ending part (result->last) and the number of levels (result->levels)
-//result has to be kmalloc-ed by and kfree-d by whoever calls this functinos. Also remember to free last and truncated_path.
-void kfind_dir(char* filepath, struct dir_helper* result);
-
-//transmits or receives the data block bitvector or the inode bitvecotr to and from disk
-// First parameter: TRANSMIT or RECEIVE (defined)
-// Second paramter: put pointer to bitvector (example: data_block_bitmap for data, inode_bitmap for inodes)
-// Third parameter: put where that bitvecotr starts in memory (example: FS->data_bitmap_loc for data, FS->inode_bitmap_loc for inode)
-// Fourth parameter: how many there are (example: FS->max_data_blocks for data, FS->max_inodes for inodes)
-// index = index you would put in the bitvector
-// all = 0 for only one index, 1 for all the bitvector
-int transmit_receive_bitmap(int t_or_r, bit_vector* vec, int starting_loc, int max, int bit_index, int all);
-
-/* Helper function to add a new dir_entry to a directory file and optinally write it out to disk.
- Updates the last data block of the cur_inode (directory) to add a dir_entry that stores the mapping of the new inode to its inum */
-int add_dir_entry(struct inode* cur_inode, int free_inode_loc, struct dir_helper* result);
-
-int get_block_address(struct inode *file_inode, int block_num);
-
-// Helper function for kread():
-int read_partial_block(struct inode *c_inode, int offset, void* buf_offset, int bytes_left, void* transfer_space);
-
-// Helper function for kread():
-int read_full_block(struct inode *c_inode, int offset, void* buf_offset, int bytesLeft, void* transfer_space);;
-
-int read_inode(struct inode *c_inode, int offset, void* buf, int num_bytes);
-
-struct stats * get_stats(char * filepath, struct stats * result);
-
-
-#endif
-
diff --git a/kernel/fs/cmdline/Makefile b/kernel/fs/cmdline/Makefile
deleted file mode 100755
index ee1f4b8e..00000000
--- a/kernel/fs/cmdline/Makefile
+++ /dev/null
@@ -1,39 +0,0 @@
-INCLUDES+=-Iinclude
-
-CC?=gcc
-
-CFLAGS+=-O0
-CFLAGS+=-g
-CFLAGS+=-D__HOST
-
-OBJS+=file.o
-OBJS+=fakelibs.o
-OBJS+=open_table.o
-OBJS+=bitvector.o
-OBJS+=main.o
-
-PROG:=buildfs
-
-all: $(PROG)
-
-$(PROG): $(OBJS)
- $(CC) $(CFLAGS) $(OBJS) -o $(PROG)
-
-file.o: ../fat16/file.c
- $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
-
-bitvector.o: ../../data_structures/bitvector.c
- $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
-
-open_table.o: ../open_table.c
- $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
-
-%.o: %.c
- $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
-
-card.sd:
- dd if=/dev/zero of=card.sd conv=notrunc bs=512 count=250000
-
-clean:
- rm -f $(OBJS)
- rm -f $(PROG)
diff --git a/kernel/fs/cmdline/fakelibs.c b/kernel/fs/cmdline/fakelibs.c
deleted file mode 100644
index 5594d094..00000000
--- a/kernel/fs/cmdline/fakelibs.c
+++ /dev/null
@@ -1,70 +0,0 @@
-#include
-#include
-#include
-#include
-
-/* Memory management */
-
-void *kmalloc(unsigned int len)
-{
- return malloc(len);
-}
-
-void kfree(void *ptr)
-{
- free(ptr);
-}
-
-/* klibc functions */
-
-// GAH src is the 1st argument.
-void *os_memcpy(void *src, void *dst, int len)
-{
- return memcpy(dst, src, len);
-}
-
-void *os_memset(void *ptr, char c, int len)
-{
- return memset(ptr, c, len);
-}
-
-int os_strcmp(char *s1, char *s2)
-{
- return strcmp(s1, s2);
-}
-
-char *os_strcpy(char *s1, char *s2)
-{
- return strcpy(s1, s2);
-}
-
-int os_strlen(char *s)
-{
- return strlen(s);
-}
-
-/* SD card */
-
-int init_sd()
-{
- // Noop
- return 0;
-}
-
-int sd_transmit(void *data, uint32_t addr)
-{
- FILE *f = fopen("card.sd", "r+");
- fseek(f, addr, SEEK_SET);
- fwrite(data, 1, 512, f);
- fclose(f);
- return 0;
-}
-
-int sd_receive(void *data, uint32_t addr)
-{
- FILE *f = fopen("card.sd", "r+");
- fseek(f, addr, SEEK_SET);
- fread(data, 1, 512, f);
- fclose(f);
- return 0;
-}
diff --git a/kernel/fs/cmdline/include/data_structures/bitvector.h b/kernel/fs/cmdline/include/data_structures/bitvector.h
deleted file mode 120000
index e4561579..00000000
--- a/kernel/fs/cmdline/include/data_structures/bitvector.h
+++ /dev/null
@@ -1 +0,0 @@
-../../../../include/data_structures/bitvector.h
\ No newline at end of file
diff --git a/kernel/fs/cmdline/include/data_structures/linked_list.h b/kernel/fs/cmdline/include/data_structures/linked_list.h
deleted file mode 120000
index 38507f21..00000000
--- a/kernel/fs/cmdline/include/data_structures/linked_list.h
+++ /dev/null
@@ -1 +0,0 @@
-../../../../include/data_structures/linked_list.h
\ No newline at end of file
diff --git a/kernel/fs/cmdline/include/drivers/mmci.h b/kernel/fs/cmdline/include/drivers/mmci.h
deleted file mode 120000
index 2a88fac5..00000000
--- a/kernel/fs/cmdline/include/drivers/mmci.h
+++ /dev/null
@@ -1 +0,0 @@
-../../../../include/drivers/mmci.h
\ No newline at end of file
diff --git a/kernel/fs/cmdline/include/fs b/kernel/fs/cmdline/include/fs
deleted file mode 120000
index 52616344..00000000
--- a/kernel/fs/cmdline/include/fs
+++ /dev/null
@@ -1 +0,0 @@
-../../../include/fs
\ No newline at end of file
diff --git a/kernel/fs/cmdline/include/global_defs.h b/kernel/fs/cmdline/include/global_defs.h
deleted file mode 120000
index 9e8e79ca..00000000
--- a/kernel/fs/cmdline/include/global_defs.h
+++ /dev/null
@@ -1 +0,0 @@
-../../../include/global_defs.h
\ No newline at end of file
diff --git a/kernel/fs/cmdline/include/klibc.h b/kernel/fs/cmdline/include/klibc.h
deleted file mode 120000
index bc34e179..00000000
--- a/kernel/fs/cmdline/include/klibc.h
+++ /dev/null
@@ -1 +0,0 @@
-../../../include/klibc.h
\ No newline at end of file
diff --git a/kernel/fs/cmdline/main.c b/kernel/fs/cmdline/main.c
deleted file mode 100644
index 0d627e03..00000000
--- a/kernel/fs/cmdline/main.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * @file
- *
- * Build FS (Bootstraps the File System)
- *
- * @author Lane Kolbly, Ginevra Gaudioso
- * @version 1.0
- *
- * @section NOTE ON CMDLINE FOLDER
- * SD card gets run automatically in the makefile, however
- * the .h files in the cmdline folder need to be manually updated and
- * are independent of the files in the include folder
- * > e.g. if someone changes include/file.h then fs/cmdline/file.h
- * needs to be updated
- *
- *
- * @section DESCRIPTION
- *
- * Takes a directory and creates an SD card image from
- * it
- *
- */
-#include "fs/file.h"
-#include
-#include
-#include
-#include
-
-#define BUF_SIZE 4096
-#define MAX_FILE_NAME_LEN 1024
-
-/**
- * Adds a specific file to the card.sd image
- *
- * Adds the file at the path specified by filename to the SD card
- * image indicated by dst_filename
- *
- * @param
- *
- * char *src_file_name - holds the path to the file to add to the SD
- * card image
- *
- * @param
- *
- * char *dst_file_name - holds the path to the SD card image to
- * add the file to
- */
-void addFile(const char *src_file_name, const char *dst_file_name)
-{
- FILE *f = fopen(src_file_name, "r");
- assert(f);
-
- // FIXME: should all be const char*
- kclose(kcreate((char*) dst_file_name, 'r', 0));
- int fd = kopen((char*) dst_file_name, 'w');
-
- char buf[BUF_SIZE];
- int nread;
-
- while ((nread = fread(buf, 1, BUF_SIZE, f)) > 0)
- {
- kwrite(fd, buf, nread);
- //printf("\t\t%d bytes\n", nread);
- }
-
- kclose(fd);
- fclose(f);
-}
-
-int main(int argc, char **argv)
-{
- int fd;
- int i;
- int l;
- DIR *dir;
- struct dirent *entry;
-
- char src_file[MAX_FILE_NAME_LEN];
- char dst_file[MAX_FILE_NAME_LEN];
-
- kfs_init(0, 0, 1);
-
- for (i = 1; i < argc; i++)
- {
- dir = opendir(argv[i]);
- if (dir == NULL)
- {
- printf("Could not find directory %s\n", argv[i]);
- printf("SAD :(\n");
- return -1;
- }
- printf("In %s\n", argv[i]);
-
- while ((entry = readdir(dir)))
- {
- if (entry->d_name[0] == '.')
- continue; // skip
-
- l = snprintf(src_file, MAX_FILE_NAME_LEN, "%s/%s", argv[i], entry->d_name);
- assert(l < MAX_FILE_NAME_LEN);
- l = snprintf(dst_file, MAX_FILE_NAME_LEN, "/%s", entry->d_name);
- assert(l < MAX_FILE_NAME_LEN);
-
- printf("\tAdding %s to %s ...\n", src_file, dst_file);
-
- addFile(src_file, dst_file);
- }
-
- closedir(dir);
- }
-
- return 0;
-}
diff --git a/kernel/fs/fat16/file.c b/kernel/fs/fat16/file.c
deleted file mode 100644
index 8bb6d31b..00000000
--- a/kernel/fs/fat16/file.c
+++ /dev/null
@@ -1,2237 +0,0 @@
-/**
- * @file
- *
- * Course OS FS
- *
- * @author
- *
- * Joel Iventosh, Ginevra Gaudioso, Weston Sellek, Charlie Cox
- * Matt Davidson, Joseph Bourque
- *
- * @version 1.0
- *
- * @section DESCRIPTION
- *
- * Course OS FS is a custom file system (started out as FAT 16 but changed into this).
- * The file system uses a superblock to initialize the file system as well as the SD card
- * on boot. Data blocks are stored as array of integers that indexes into the corresponding
- * block number on the SD card (note: some blocks are reserved, data blocks use an offset to
- * access blocks on the SD card) DO NOT FORGET TO ADD OFFSET TO BLOCK NUMBERS!; Each file or
- * directory is stored with an inode which contains metadata about the file as well as the
- * list of addresses on disk where the data the file holds is stored. Directories are indicated
- * with the is_dir flag and data blocks for directories are dir_entry structs;
- * Each file has 100 direct blocks and 20 indirect blocks; no methods are
- * currently implemented to keep data contiguous.
- *
- * CURRENTLY WORKING
- * - Have working directories and directory hierarchy
- * - Standardized error codes; defined in header file
- * - Open file table working
- * - Create working
- * - Open working
- * - Close working
- * - Read working
- * - Write working
- *
- * TO FIX
- * - Max number of files per directory currently limited to 700 due to error finding
- * and opening files; you can technically create more, but open will not find them
- * - indirect blocks do not seem to work
- * - ls, delete, and copy are untested; could work, but might not; TEST BEFORE USING!
- * - permissions
- *
- */
-#include
-#include "klibc.h"
-#include "data_structures/bitvector.h"
-#include "fs/open_table.h"
-#include "fs/file.h"
-#include "drivers/mmci.h"
-
-#define TRANSMIT 0
-#define RECEIVE 1
-
-//CONSTANTS:
-const int SUPERBLOCK = 1;
-// const int MAX_NAME_LENGTH = 32; moved this to a define
-int MAX_BLOCKS;
-// const int INODE_SIZE = 128; shouldn't need this...should be able to do sizeof(Inode)
-int MAX_MEMORY;
-int INODE_TABLE_CACHE_SIZE;
-int NUM_INODE_TABLE_BLOCKS_TO_CACHE;
-int INDIRECT_BLOCK_TABLE_CACHE_SIZE;
-int NUM_INDIRECT_BLOCK_TABLE_BLOCKS_TO_CACHE;
-int INODES_PER_BLOCK = 1;
-int DATA_BLOCK_TABLE_CACHE_SIZE;
-int NUM_DATA_BLOCK_TABLE_BLOCKS_TO_CACHE;
-
-
-struct superblock* FS;
-bit_vector* inode_bitmap;
-bit_vector* data_block_bitmap;
-
-struct inode** inode_table_cache; //is this right? we want an array of inode pointers...
-struct indirect_block** indirect_block_table_cache; // an array of pointers to indirect_blocks
-struct inode** inode_table_temp;
-struct data_block** data_block_table_cache;
-// void* data_table; not sure what this is or why we had/needed/wanted it...
-
-/**
- * Format the SD card for Course OS FS
- *
- * Creates the super block & metadata for the file system, creates the
- * root directory of the file system and writes the first block on the
- * SD card as empty.
- *
- */
-int kfs_format()
-{
- os_printf("In kfs_format\n");
- // Lay down the superblock to block 1
- struct superblock sblock;
- sblock.fs_version = 1;
- sblock.magic_num = 0xDEADBEAF;
- sblock.sd_card_capacity = 128000000;
- sblock.block_size = BLOCKSIZE;
- sblock.root_inum = 0;
- sblock.max_inodes = 4000;
- sblock.inode_size = BLOCKSIZE;
- sblock.max_data_blocks = 200000;
- sblock.inode_bitmap_loc = 10;
- sblock.data_bitmap_loc = 50;
- sblock.start_inode_table_loc = 1000;
- sblock.start_data_blocks_loc = 50000;
-
- void *block = kmalloc(BLOCKSIZE);
- os_memset(block, 0, BLOCKSIZE);
- os_memcpy((uint32_t*)&sblock, block, sizeof(struct superblock));
- sd_transmit(block, 1*BLOCKSIZE);
-
- // Lay down the root inode
- struct inode root_inode;
- root_inode.inum = 0; // Isn't this redundant?
- root_inode.fd_refs = 0;
- root_inode.size = 0;
- root_inode.is_dir = 1;
- root_inode.usr_id = 0;
- root_inode.direct_blocks_in_file = 1;
- // root_inode.data_blocks[0] = sblock.start_data_blocks_loc;
- root_inode.data_blocks[0] = 0;
- root_inode.indirect_blocks_in_file = 0;
- os_memset(block, 0, BLOCKSIZE);
- os_memcpy((uint32_t*)&root_inode, block, sizeof(struct inode));
- sd_transmit(block, sblock.start_inode_table_loc*BLOCKSIZE);
-
- // Lay down the first (empty...) data block for the directory.
- struct dir_data_block ddb;
- ddb.block_num = 0;
- ddb.num_entries = 0;
- os_memset(block, 0, BLOCKSIZE);
- os_memcpy((uint32_t*)&ddb, block, sizeof(struct dir_data_block));
- sd_transmit(block, sblock.start_data_blocks_loc*BLOCKSIZE);
-
- // Update the inode bitmap
- /*unsigned char i = 0x80;
- os_memset(block, 0, BLOCKSIZE);
- os_memcpy(&i, block, 1);
- sd_transmit(block, sblock.inode_bitmap_loc*BLOCKSIZE);*/
- kfree(block);
- return SUCCESS;
-}
-
-/**
- * Load file system into memory and initialize the SD card
- *
- * Initializes the SD card to set it up for data transfer, once the SD card
- * is initialized metadata for the file system is loaded into memory and used
- * to obtain the free list table and data block table.
- *
- * @param
- *
- * int inode_table_cache_size - no longer needed; should be removed
- *
- * @param
- *
- * int data_block_table_cache_size - no longer needed; should be removed
- *
- * @param
- *
- * int reformat - if this is set to a non-zero value; this formats the file
- * system before initialization; if set to 0; initialization occurs with no
- * format
- *
- * @return
- *
- * Returns 0 if initialization was successful; does not do any error checking
- * or reporting at current; will need to be added in at some point in the future
- */
-int kfs_init(int inode_table_cache_size, int data_block_table_cache_size, int reformat){
-
- INODE_TABLE_CACHE_SIZE = inode_table_cache_size;
- DATA_BLOCK_TABLE_CACHE_SIZE = data_block_table_cache_size;
- // TODO: Reading the root inode has weird issues (getting is_dir==0) with inode table block cache.
- NUM_INODE_TABLE_BLOCKS_TO_CACHE = 0;//((int) INODE_TABLE_CACHE_SIZE/BLOCKSIZE) + 1;
- NUM_DATA_BLOCK_TABLE_BLOCKS_TO_CACHE = 0;//((int) DATA_BLOCK_TABLE_CACHE_SIZE/BLOCKSIZE) + 1;
-
- //initialize the SD Card driver:
- if(!init_sd()){
- //initiallized successfully:
- os_printf("SD Card initiallized successfully!!!\n");
- }else{
- os_printf("FATAL ERROR!!!!! SD Card NOT initialized successfully!\n");
- //handle errors returned by SD Card...will implement this later...
- }//end else
-
- // Bootstrap the FS...
- if (reformat) {
- kfs_format();
- }
-
- //read in the super block from disk and store in memory:
- FS = (struct superblock*) kmalloc(BLOCKSIZE);
- sd_receive((void*)FS, (SUPERBLOCK*BLOCKSIZE)); // make all blocks addresses, like here
-
- INODES_PER_BLOCK = (FS->block_size/FS->inode_size);
-
- //initialize the free list by grabbing it from the SD Card:
- inode_bitmap = make_vector(FS->max_inodes);
- data_block_bitmap = make_vector(FS->max_data_blocks);
-
- //HACK...shouldn't need to do this, but do, so leave for now
- int m;
- for(m = 0; m < FS->max_inodes; m++){
- bv_lower(m, inode_bitmap);
- } //end HACK...shouldn't need to do this, but do, so leave for now
-
- bv_set(0, inode_bitmap);
- bv_set(0, data_block_bitmap);
-
-
- // initilize the inode_table_cache in memory:
- inode_table_temp = (struct inode**)kmalloc(NUM_INODE_TABLE_BLOCKS_TO_CACHE * BLOCKSIZE);
- inode_table_cache = (struct inode**) kmalloc((sizeof(struct inode*))* FS->max_inodes);
- int i;
- for(i = 0; i < FS->max_inodes; i++){
- if(i < NUM_INODE_TABLE_BLOCKS_TO_CACHE * INODES_PER_BLOCK){
- if(i % INODES_PER_BLOCK == 0){
- sd_receive((((void*)inode_table_temp) + ((i/INODES_PER_BLOCK)*BLOCKSIZE)), (FS->start_inode_table_loc + (i/INODES_PER_BLOCK)) * BLOCKSIZE);
- }
- inode_table_cache[i] = (struct inode*)((inode_table_temp + (((int)(i/INODES_PER_BLOCK))*BLOCKSIZE)) + ((i % INODES_PER_BLOCK)*FS->inode_size));
- }
- //each iteration through the loop will grab 1 inodes, since we can fit 1 inodes per block
- else{
- inode_table_cache[i] = NULL;
- }
- }//end for
- // inode_table_cache = (inode*) inode_table_temp; // cast the void pointer to an Inode pointer
-
- // initilize the data_block_table_cache in memory:
- void* data_block_table_temp = (void*) kmalloc(NUM_DATA_BLOCK_TABLE_BLOCKS_TO_CACHE * BLOCKSIZE);
- data_block_table_cache = (struct data_block**) kmalloc((sizeof(struct data_block*))* FS->max_data_blocks);
- for(i = 0; i < FS->max_data_blocks; i++){
- if(i < NUM_DATA_BLOCK_TABLE_BLOCKS_TO_CACHE){
- sd_receive(data_block_table_temp + (i*BLOCKSIZE), (FS->start_data_blocks_loc) + (i*BLOCKSIZE));
- data_block_table_cache[i] = (struct data_block*)(data_block_table_temp + (i*BLOCKSIZE));
- } else{
- data_block_table_cache[i] = NULL;
- }
- }//end for
-
- fs_table_init(); //initializes open_table stuff
-
- os_printf("Finished initializing table...\n");
- return SUCCESS;
-}//end fs_init() function
-
-/**
- * Removes the file system from memory
- *
- * Writes the filesystem metadata, the free block table and the data block table to disk
- * for persistant storage and then frees all memory which was being used to allocate those
- * resources
- *
- * @return
- *
- * Returns 0 if shutdown successfully loaded everything out of memory; no error handling or
- * recording is currently implemented; this needs to be implemented in the future so that
- * shutdown does not occur if this is called in the middle of a read or write
- */
-int kfs_shutdown(){
- int i;
- //TODO: write inodes pointed to by inode_table_cache back to disk to ensure it's up to date:
-
- //TODO: write indirect_blocks pointed to by data_block_table_cache back to disk to ensure it's up to date:
- transmit_receive_bitmap(TRANSMIT, inode_bitmap, FS->inode_bitmap_loc, FS->max_inodes, 0, 1); //transmit inode bitmap
- transmit_receive_bitmap(TRANSMIT, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, 0, 1); //transmit block bitmap
-
- //free inodes stored in inode_table_cache:
- for(i = 0; i < NUM_INODE_TABLE_BLOCKS_TO_CACHE; i++){
- if(inode_table_cache[i] != NULL){
- kfree(inode_table_cache[i]);
- }//end if
- }//end for
-
- //free inode_table_cache itself:
- kfree(inode_table_cache);
-
- //free indirect_blocks stored in data_block_table_cache:
- for(i = 0; i < NUM_DATA_BLOCK_TABLE_BLOCKS_TO_CACHE; i++){
- if(data_block_table_cache[i] != NULL){
- kfree(data_block_table_cache[i]);
- }//end if
- }//end for
-
- //free data_block_table_cache itself:
- kfree(data_block_table_cache);
- kfree(inode_table_temp);
- //TODO: free anything else that needs to be freed...
-
- fs_table_shutdown(); //frees open_table stuff
- return SUCCESS;
-}//end kfs_shutdown() function
-
-
-// -------------------------------------------------------------------------------------------------------------------------------------------------------
-/* HELPER FUNCTIONS */
-
-/**
- * Retrieves an indirect data block from the SD card
- *
- * Retrieves the specified indirect data block from the SD card using the passed index
- * and then sets it as the current indirect block
- *
- * @param
- *
- * struct inode* cur_inode - points to the file which we want to read the indirect block
- * index from
- *
- * @param
- *
- * int index - holds an index which corresponds to a location in the data block table
- *
- * @param
- *
- * struct indirect_block* cur_indirect_block - Holds the address of the current indirect
- * block
- *
- */
-void get_indirect_block(struct inode* cur_inode, int index, struct indirect_block* cur_indirect_block) {
- // indirect_block is not in the cache table, so get it from disk:
- if(cur_inode->indirect_blocks_in_file <= 0){
- transmit_receive_bitmap(RECEIVE, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, 0, 1);
- int new_indirect_block_loc = bv_firstFree(data_block_bitmap);
- bv_set(new_indirect_block_loc, data_block_bitmap);
- cur_inode->indirect_blocks[0] = new_indirect_block_loc;
- cur_inode->indirect_blocks_in_file++;
- transmit_receive_bitmap(TRANSMIT, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, new_indirect_block_loc, 0);
- sd_transmit((void*) cur_inode, (cur_inode->inum + FS->start_inode_table_loc) * BLOCKSIZE);
- os_memset(cur_indirect_block, 0, BLOCKSIZE);
- cur_indirect_block->block_num = new_indirect_block_loc;
- cur_indirect_block->blocks_in_file = 0;
- }//end if
- sd_receive((void*) cur_indirect_block, (index + FS->start_data_blocks_loc)*BLOCKSIZE); // the firs
-}//end get_indirect_block
-
-/**
- * gets corresponding inode, from the SD card
- *
- * Retrieves an inode from the SD card using specified inum storing
- * it into a specified address.
- *
- * @param
- *
- * int inum - corresponds to a location in the inode table i.e. it is an
- * index to a location in the inode table
- *
- * @param
- *
- * inode* result_inode - holds a specified address to store the retrieved
- * inode at
- *
- */
-//from the inum, gets corresponding inode, either from cache or disk
-void get_inode(int inum, struct inode* result_inode){
- // if(inode_table_cache[inum] != NULL){
- // // the inode is in the inode_cache_table, so get it:
- // result_inode = (inode_table_cache[inum]);
- // }else{
- // inode is not in the cache table, so get it from disk:
- // // struct inode* inode_spaceholder = (void*) kmalloc(BLOCKSIZE);
- // sd_receive((void*)inode_spaceholder, ((inum/INODES_PER_BLOCK)+FS->start_inode_table_loc)*BLOCKSIZE); // the firs
- // struct inode *block_of_inodes = inode_spaceholder;
- // result_inode = block_of_inodes[inum % INODES_PER_BLOCK];
- // kfree(inode_spaceholder);
- // need to implement an eviction policy/function to update the inode_table_cache...
- // this will function w/o it, but should be implemented for optimization
- // }//end if else
- sd_receive(result_inode, (inum + FS->start_inode_table_loc)*BLOCKSIZE);
-}//end get_inode() helper function
-
-/**
- * gets the inum of nextpath (file or dir) looking at the direct data blocks of cur_inode
- *
- * Uses the current file's inode in order to retrieve the nested directory's inode
- * and then return it
- *
- * @param
- *
- * struct inode* cur_inode - holds the inode for the current data block
- *
- * @param
- *
- * char * next_path - the path you are searching
- *
- * @return
- *
- * Returns the inode of a specific nested directory; at this time there is no error checking
- * or reporting on this function; needs to be added in at a later data
- */
-int get_inum_from_direct_data_block(struct inode* cur_inode, const char * next_path){
- int inum = -1;
- int i;
- int file_found = 0; // initialize to false (i.e. file not found)
- struct dir_data_block* cur_data_block = (struct dir_data_block*) kmalloc(BLOCKSIZE);
-
- for(i = 0; i < cur_inode->direct_blocks_in_file; i++){
- sd_receive(cur_data_block, (cur_inode->data_blocks[i] + FS->start_data_blocks_loc)*BLOCKSIZE);
-
- int j;
- for(j = 0; j < (cur_data_block->num_entries); j++){
- struct dir_entry file_dir = cur_data_block->dir_entries[j];
- if(!os_strcmp(file_dir.name, next_path)){
- file_found = 1; //we found the file, so break out of loop
- inum = file_dir.inum;
- break;
- }
- if(file_found){
- break;
- }
- }//inner for
- if(file_found){
- break;
- }
- }//outer for
- kfree(cur_data_block);
- return inum;
-}//end get_inum_from_direct_data_block() helper helper function
-
-/**
- * Returns the index to an inode by searching through an indirect block
- *
- * gets the inum of netxpath (file or dir) looking at the indirect
- * data blocks of cur_inode
- *
- * @param
- *
- * struct inode* cur_inode - holds the inode for the current data block
- *
- * @param
- *
- * char * next_path - the path you are searching
- *
- * @return
- *
- * Returns the inode of a specific nested directory; at this time there is no error checking
- * or reporting on this function; needs to be added in at a later data
-*/
-int get_inum_from_indirect_data_block(struct inode * cur_inode, const char * next_path) {
- int i;
- int inum = -1;
- int cur_indirect_block_num = -1;
- int file_found = 0; // initialize to false (i.e. file not found)
- struct indirect_block cur_indirect_block;
- for(i = 0; i < cur_inode->indirect_blocks_in_file; i++){
- cur_indirect_block_num = cur_inode->indirect_blocks[i];
-
- get_indirect_block(cur_inode, cur_indirect_block_num, &cur_indirect_block);
-
- void* dir_spaceholder = (void*) kmalloc(BLOCKSIZE);
- int j;
- int num_indirect_blocks = cur_inode->indirect_blocks_in_file;
- for(j = 0; j < num_indirect_blocks; j++){
- sd_receive(dir_spaceholder, (cur_indirect_block.data_blocks[j])*BLOCKSIZE);
- struct dir_data_block cur_data_block = *((struct dir_data_block*) dir_spaceholder);
- int k;
- for(k = 0; k < (cur_data_block.num_entries); k++){
- struct dir_entry file_dir = cur_data_block.dir_entries[k]; //
- if(!os_strcmp(file_dir.name, next_path)){
- file_found = 1; //we found the file, so break out of loop
- inum = file_dir.inum;
- break;
- }
- }//inner for
- if(file_found){
- break;
- }
- }//outer for
- kfree(dir_spaceholder);
- if(file_found){
- break;
- }
- }//end for
- return inum;
-}//end of get_inum_from_indirect_data_block
-
-/**
- * locates an inode using the file path and store it in the result_inode
- *
- * finds the inode (will be result_inode) following filepath, going
- * dir_levels down the path, starting from starting_inum
- *
- * @param
- *
- * char* filepath - holds the filepath leading to the inode
- *
- * @param
- *
- * int dir_levels - holds the number of directories the inode is nested
- * under
- *
- * @param
- *
- * struct inode* result_inode - Used to hold the inode once it has been
- * located
- *
- * @return
- *
- * Returns 0 if inode was successfully located and stored; otherwise
- * returns -1
- */
-int kfind_inode(const char* filepath, int starting_inum, int dir_levels, struct inode* result_inode) { //filepath and starting inum must correspond...
- int current_inum = starting_inum;
-
- int a = 0;
- for(a = 0; a < dir_levels-1; a++) {
- int k = 1;
- // int k = 0;
- char next_path[MAX_NAME_LENGTH] = {0};
-
- //get path of next inode
- while ((filepath[k] != '/') && (k <= MAX_NAME_LENGTH) && (filepath[k] != '\0')) {
- next_path[k-1] = filepath[k];
- k++;
- }//end of litte while to find next_path
-
- filepath += k;
-
- // Store inode with current_inum current_inum in result_inode
- get_inode(current_inum, result_inode);
-
- current_inum = get_inum_from_direct_data_block(result_inode, next_path);
-
- if(current_inum < 0){
- //current_inum not found in any direct blocks of result_inode
- //look for it in the indirect blocks now
- current_inum = get_inum_from_indirect_data_block(result_inode, next_path);
- }
-
- if(current_inum < 0){
- //next_path not found in current_inode
- os_printf("404 ERROR! File not found.\nPlease ensure full filepath is specified starting from root (/)\n");
- return ERR_404; //file not found
- }
- }//outer most for loop
- //current_inum of target inode found, store that inode in result_inode
-
- get_inode(current_inum, result_inode);
-
- return SUCCESS;
-}//end kfind_inode() helper function
-
-/**
- * Uses the file path to obtain information about a directory and stores it in result
- *
- * finds the name of the directory path (result->truncated_path) and the name of the
- * ending part (result->last) and the number of levels (result->levels) result has to
- * be kmalloc-ed by and kfree-d by whoever calls this functinos. Also remember to free
- * last and truncated_path.
- *
- * @param Description of method's or function's input parameter
- * @param ...
- * @return Description of the return value
- */
-void kfind_dir(const char* filepath, struct dir_helper* result){
- int dir_levels = 0;
- int total_chars = 0;
- char* iterator = (char*) filepath; //root still level 0, so start from what's next
- int index = 0;
- while(index < MAX_NAME_LENGTH){
- if(iterator[0] == '\0'){
- //index++;
- break;
- }
- else if(iterator[0] == '/'){
- dir_levels++;
- index = 0;
- }else{
- index++;
- }
- iterator++;
- total_chars++;
- }//end while
- total_chars -= index;
-
- char* truncated_path = (char*)kmalloc(total_chars+1); // do we need to kmalloc this?
- char* last = (char*)kmalloc(index+1);
- int i;
- for(i = 0; i < total_chars; i++){
- truncated_path[i] = filepath[i];
- }
- truncated_path[i] = 0;
- for (i=0; idir_levels = dir_levels;
- result->truncated_path = truncated_path;
- result->last = last;
- return; //caller of function is responsible for freeing memory for truncated_path and filepath
-}//end kfind_dir() function
-
-/**
- * Used to transmit a block to disk or recieve a block from disk
- *
- * transmits or receives the data block bitvector or the inode bitvecotr to and from disk
- *
- * @param
- *
- * int t_or_r - Determines whether operation is a TRANSMIT (0) to disk or a RECIEVE (1)
- * from disk
- *
- * @param
- *
- * bit_vector* vec - Pointer to a bitvector (either a data_block_bitmap for data or an
- * inode_bitmap for inodes)
- *
- * @param
- *
- * int starting_loc - holds the location where the bit vector starts in memory
- *
- * @param
- *
- * int max - holds the number of blocks to write to disk
- *
- * @param
- *
- * int all - Determines whether to only write 1 index (0) or whether to write the entire
- * bit vector (1) to disk
- *
- * @return
- *
- * Return 0 if the transmission/recieval was successful; otherwise returns an error code
- */
-int transmit_receive_bitmap(int t_or_r, bit_vector* vec, int starting_loc, int max, int bit_index, int all){
- int error = 0;
- int num_blocks = (max/(8 * BLOCKSIZE)) + 1;
- if (t_or_r != TRANSMIT || t_or_r != RECEIVE) {
- return ERR_INVALID;
- }
- if(all){ //transmit or receive all the bitvector
- int i;
- for(i = 0; i < num_blocks; i++){
- if (t_or_r == TRANSMIT) {
- error = sd_transmit((void*) (vec->vector + (i*BLOCKSIZE)), (starting_loc + i)*BLOCKSIZE);
- }
- else { //receive
- error = sd_receive((void*) (vec->vector + (i*BLOCKSIZE)), (starting_loc + i)*BLOCKSIZE);
- }
- if(error < 0){
- os_printf("ERROR! Failed to transmit or receive\n");
- return error;
- }
- }
- }else{ //transmit or reveive only the block corresponding to the index
- int block_to_change = (bit_index/8)/BLOCKSIZE;
- if (t_or_r == TRANSMIT) {
- error = sd_transmit((void*) (vec->vector + (block_to_change*BLOCKSIZE)), (starting_loc + block_to_change)*BLOCKSIZE);
- }
- else { //receive
- error = sd_receive((void*) (vec->vector + (block_to_change*BLOCKSIZE)), (starting_loc + block_to_change)*BLOCKSIZE);
- }
- if(error < 0){
- os_printf("ERROR! Failed to transmit or receive\n");
- return error;
- }
- }
- return error;
-}//end transmit_receive_bitmap helper function
-
-
-/**
- * Adds a new file to an existing directory
- *
- * Helper function to add a new dir_entry to a directory file and
- * optinally write it out to disk. Updates the last data block of
- * the cur_inode (directory) to add a dir_entry that stores the
- * mapping of the new inode to its inum
- *
- * @param
- *
- * struct inode* cur_inode - holds the inode for the current data block
- *
- * @param
- *
- * int free_inode_loc - points to a location in the free inode table
- *
- * @param
- *
- * struct dir_helper* result - holds information about the directory you
- * are trying to add to
- *
- * @return
- *
- * Returns 0 if the file was added successfully; otherwise returns an error
- */
-int add_dir_entry(struct inode* cur_inode, int free_inode_loc, struct dir_helper* result){
-
- int flag_free_cur_indirect_block = 0;
-
- //first get the appropriate data block, either from the array of direct data blocks from an indirect block:
- struct dir_data_block* dir_block = (struct dir_data_block*) kmalloc(BLOCKSIZE);
- struct indirect_block* cur_indirect_block;
- //if the cur_inode's array of direct data blocks has not reached max capacity, grab the last data block in the array to update:
- if((cur_inode->direct_blocks_in_file <= MAX_DATABLOCKS_PER_INODE) && (cur_inode->indirect_blocks_in_file == 0)) {
- sd_receive((void*) dir_block, (cur_inode->data_blocks[(cur_inode->direct_blocks_in_file)-1] + FS->start_data_blocks_loc)*BLOCKSIZE);
- }else{
- //all the direct data blocks are full, so grab the last indirect block in the array of indirect blocks:
- cur_indirect_block = (struct indirect_block*) kmalloc(BLOCKSIZE);
- get_indirect_block(cur_inode, (cur_inode->indirect_blocks_in_file - 1), cur_indirect_block);
- sd_receive((void*) dir_block, (cur_indirect_block->data_blocks[(cur_indirect_block->blocks_in_file)-1] + FS->start_data_blocks_loc)*BLOCKSIZE);
- flag_free_cur_indirect_block = 1;
- // kfree(cur_indirect_block);
- }
- /* dir_block is now a direct data block that holds the content of the last data block in the file
- either from cur_inode's array of direct data blocks or from its last indirect data block */
-
- //create the new dir_entry and populate it's fields:
- struct dir_entry new_dir_entry;
- new_dir_entry.inum = free_inode_loc;
- os_strcpy(new_dir_entry.name, result->last);
- new_dir_entry.name_length = os_strlen(result->last);
-
- //check to see if the data block we recieved above has room to add a new dir_entry to it; if not, create a new data block, if possible:
- if(dir_block->num_entries < MAX_DIR_ENTRIES_PER_DATA_BLOCK){
- //the data block has room to add the new dir_entry, so we add it:
- dir_block->dir_entries[dir_block->num_entries] = new_dir_entry;
- dir_block->num_entries++;
- cur_inode->size += sizeof(struct dir_entry);
-
- sd_transmit((void*) dir_block, (dir_block->block_num + FS->start_data_blocks_loc) * BLOCKSIZE);
- }else{
- /* the data block doesn't have room to add the new dir_entry, so we need to add a new data block....
- either by adding: (1) as a direct data block,
- (2) to the current indirect block or
- (3) add a new indirect block then add a new data block to that */
- //first kmalloc space for a new_dir_block:
- int new_data_block_loc = bv_firstFree(data_block_bitmap); //Consult the data_block_bitmap to find a free block to add the new data block at
- if(new_data_block_loc < 0){//disk is full
- os_printf("ERROR! Disk full\n");
- kfree(dir_block);
- if (cur_indirect_block != NULL) {
- kfree(cur_indirect_block);
- }
- return ERR_FULL;
- }
- bv_set(new_data_block_loc, data_block_bitmap);
- struct dir_data_block* new_dir_block = (struct dir_data_block*) kmalloc(BLOCKSIZE);
-
- new_dir_block->num_entries = 0;
- new_dir_block->block_num = new_data_block_loc;
-
- if(cur_inode->direct_blocks_in_file < MAX_DATABLOCKS_PER_INODE){
- //Case (1): add a direct data block to cur_inode:
- cur_inode->data_blocks[cur_inode->direct_blocks_in_file] = new_dir_block->block_num;
- cur_inode->direct_blocks_in_file++;
-
- new_dir_block->dir_entries[new_dir_block->num_entries] = new_dir_entry;
- new_dir_block->num_entries++;
- cur_inode->size += sizeof(struct dir_entry);
- sd_transmit((void*) new_dir_block, (new_dir_block->block_num + FS->start_data_blocks_loc) * BLOCKSIZE);
- transmit_receive_bitmap(TRANSMIT, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, new_dir_block->block_num, 0);
- }else{
- //get the current indirect block and check to see if it has room to add another data block:
- if(!flag_free_cur_indirect_block){
- //if we don't have the indirect block, we need to get it from disk:
- cur_indirect_block = (struct indirect_block*) kmalloc(BLOCKSIZE);
- flag_free_cur_indirect_block = 1;
- get_indirect_block(cur_inode, (cur_inode->indirect_blocks_in_file - 1), cur_indirect_block);
- sd_receive((void*) dir_block, (cur_indirect_block->data_blocks[(cur_indirect_block->blocks_in_file)-1] + FS->start_data_blocks_loc)*BLOCKSIZE);
- // kfree(cur_indirect_block);
- }
- if(cur_indirect_block->blocks_in_file < MAX_DATABLOCKS_PER_INDIRECT_BLOCK){
- //Case (2): add a new data block to to the current indirect block, then add the new_dir entry to the new data block:
- cur_indirect_block->data_blocks[cur_indirect_block->blocks_in_file] = new_dir_block->block_num;
- cur_indirect_block->blocks_in_file++;
-
- new_dir_block->dir_entries[new_dir_block->num_entries] = new_dir_entry;
- new_dir_block->num_entries++;
- cur_inode->size += sizeof(struct dir_entry);
-
- sd_transmit((void*) cur_indirect_block, (cur_indirect_block->block_num + FS->start_data_blocks_loc) * BLOCKSIZE);
- sd_transmit((void*) new_dir_block, (new_dir_block->block_num + FS->start_data_blocks_loc) * BLOCKSIZE);
- transmit_receive_bitmap(TRANSMIT, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, new_dir_block->block_num, 0);
- }else{
- if(cur_inode->indirect_blocks_in_file < MAX_NUM_INDIRECT_BLOCKS){
- /* Case (3): add a new indirect block to the cur_inode, then add a new data block to the new indirect block,
- then add the new dir_entry to the new data block: */
- int new_indirect_block_loc = bv_firstFree(data_block_bitmap); //Consult the data_block_bitmap to find a free block to add the new data block at
- if (new_indirect_block_loc < 0) { //no free blocks
- os_printf("disk space over \n");
- kfree(dir_block);
- if (cur_indirect_block != NULL) {
- kfree(cur_indirect_block);
- }
- return ERR_FULL;
- }
- struct indirect_block* new_indirect_block = (struct indirect_block*) kmalloc(BLOCKSIZE);
-
- new_indirect_block->blocks_in_file = 0;
- new_indirect_block->block_num = new_indirect_block_loc;
-
- new_indirect_block->data_blocks[new_indirect_block->blocks_in_file] = new_dir_block->block_num;
- new_indirect_block->blocks_in_file++;
- cur_inode->indirect_blocks[cur_inode->indirect_blocks_in_file] = new_indirect_block->block_num;
- cur_inode->indirect_blocks_in_file++;
-
- new_dir_block->dir_entries[new_dir_block->num_entries] = new_dir_entry;
- new_dir_block->num_entries++;
- cur_inode->size += sizeof(struct dir_entry);
-
- if(indirect_block_table_cache[new_indirect_block->block_num] == NULL){
- //TODO: implement eviction policy...add the cur_inode to the cache:
- }else{
- *(indirect_block_table_cache[new_indirect_block->block_num]) = *(new_indirect_block);
- }
- bv_set(new_indirect_block_loc, data_block_bitmap); //taken
- sd_transmit((void*) new_indirect_block, (new_indirect_block->block_num + FS->start_data_blocks_loc) * BLOCKSIZE);
- sd_transmit((void*) new_dir_block, (new_dir_block->block_num + FS->start_data_blocks_loc) * BLOCKSIZE);
- transmit_receive_bitmap(TRANSMIT, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, new_dir_block->block_num, 0);
- kfree(new_indirect_block);
-
- }else{
- //file has reached max allowable size:
- os_printf("ERROR! Operation failed because file has reached max allowable size\n");
- return ERR_FULL;
- }
- }
- }
- kfree(new_dir_block);
- }
- kfree(dir_block);
- if(flag_free_cur_indirect_block){
- kfree(cur_indirect_block);
- }
- return SUCCESS;
-}//end add_dir_entry() helper function
-
-/**
- * Obtains address on disk of a specific data block within a file
- *
- * Uses the passed block number to search through the file's metadata and
- * obtain a block address to read off the SD card
- *
- * @param
- *
- * inode *file_inode - points to the specific file in which the data block
- * resides
- *
- * @param
- *
- * int file_block_num - holds the specific data block of the file to
- * obtain the address from
- *
- * @return
- *
- * Returns 0 if address was successfully retrieved; otherwise returns -1
- */
-int get_block_address(struct inode *file_inode, int file_block_num){
- if(file_block_num < 0){
- os_printf("Invalid block number");
- return ERR_INVALID;
- }
- if(file_block_num < MAX_DATABLOCKS_PER_INODE){
- if (file_block_num >= file_inode->direct_blocks_in_file) {
- return ERR_GEN;
- }
- return (file_inode->data_blocks[file_block_num] + FS->start_data_blocks_loc) * BLOCKSIZE;
- }
- //Block must be stored in an indirect block of file_inode
-
- //Get the indirect block num that contain the target block
- int indirect_block_num = (file_block_num - MAX_DATABLOCKS_PER_INODE) / MAX_DATABLOCKS_PER_INDIRECT_BLOCK;
- if(indirect_block_num >= file_inode->indirect_blocks_in_file || indirect_block_num > (MAX_NUM_INDIRECT_BLOCKS - 1)){
- return ERR_GEN;
- }
-
- struct indirect_block* cur_indirect_block = (struct indirect_block*) kmalloc(sizeof(struct indirect_block));
- get_indirect_block(file_inode, file_inode->indirect_blocks[indirect_block_num], (struct indirect_block*) cur_indirect_block);
-
- int indirect_block_direct_block_num = (file_block_num - MAX_DATABLOCKS_PER_INODE) % MAX_DATABLOCKS_PER_INDIRECT_BLOCK;
- if (cur_indirect_block->blocks_in_file <= indirect_block_direct_block_num) {
- return ERR_GEN;
- }
- int block_address = cur_indirect_block->data_blocks[indirect_block_direct_block_num];
- block_address = (block_address + FS->start_data_blocks_loc) * BLOCKSIZE;
- kfree(cur_indirect_block);
- return block_address;
-}
-
-/**
- * Reads a partial portion of a block using the specified buffer size
- *
- * Reads a specified portion of a block from the passed file's inode
- * starting at the offset point and then store the results of that in
- * buf_offset
- *
- * @param
- *
- * struct inode *c_inode - The inode of the file we want to read
- *
- * @param
- *
- * int offset - starting point in the file to read from
- *
- * @param
- *
- * void* buf_offset - Holds the information read from the file
- *
- * @param
- *
- * int bytes_left - Holds the number of bytes to read from the file
- *
- * @param
- *
- * void* transfer_space - Used to hold data gotten from SD card block
- * however I don't think we need this
- * TODO: (maybe) replace transfer_space with buff_offset
- *
- * @return
- *
- * Returns the number of bytes which were transferred if successful;
- * otherwise returns an error code
- */
-int read_partial_block(struct inode *c_inode, int offset, void* buf_offset, int bytes_left, void* transfer_space) {
- int local_offset = offset % BLOCKSIZE; // local_offset is the leftmost point in the block
-
- // Actually get the data for 1 block (the SD Driver will put it in transferSpace for us)
- int file_block_num = offset / BLOCKSIZE;
- int block_address = get_block_address(c_inode, file_block_num);
- if (block_address < 0) {
- return block_address; //return same error
- }
-
- int success = sd_receive(transfer_space, block_address);
- if(success < 0){
- // failed on a block receive, therefore the whole kread fails; return failure error
- return ERR_SD;
- }//end if block_num
-
- if((local_offset == 0) && (bytes_left < BLOCKSIZE)) {
- /* ___________________
- |~~~~~~~~~| |
- --------------------- */
- // Actually move the data to the user's specified buffer...must first cast void pointers to uint32_t* pointers:
- // source is transfer_space
- // dest is users buffer
-
- // note, this updates the buf_offset pointer as it transfer the data
- // os_memcpy takes uint32_t* as arguments
- os_memcpy(transfer_space, buf_offset, (os_size_t) bytes_left);
- return bytes_left; // note, we are returning the number of bytes that were successfully transferred
-
- } else if((local_offset > 0) && (bytes_left >= (BLOCKSIZE - local_offset))) {
- /* _____________________
- | |~~~~~~~~|
- ---------------------- */
- // Actually move the data to the user's specified buffer...must first cast void pointers to uint32_t* pointers:
- // source is transferSpace
- // dest is users buffer
-
- os_memcpy((transfer_space + local_offset), buf_offset, (os_size_t) (BLOCKSIZE - local_offset)); // note, this updates the buf_offset pointer as it transfer the data
- // os_memcpy takes uint32_t* as arguments
- // reset transferSpace pointer
- // transfer_space -= BLOCKSIZE;
-
- return (BLOCKSIZE - local_offset); // note, we are returning the number of bytes that were successfully transferred
-
- } else if((local_offset > 0) && (bytes_left < (BLOCKSIZE - local_offset))){
- /* ______________________
- | |~~~~| |
- ----------------------- */
- // Actually move the data to the user's specified buffer...must first cast void pointers to uint32_t* pointers:
- // source is transferSpace
- // dest is users buffer
-
- os_memcpy((transfer_space + local_offset), buf_offset, (os_size_t) bytes_left); // note, this updates the buf_offset pointer as it transfer the data
- // os_memcpy takes uint32_t* as arguments
- // reset transferSpace pointer
- transfer_space -= (local_offset + bytes_left);
-
- return bytes_left; // note, we are returning the number of bytes that were successfully transferred
-
- }
- return ERR_GEN;
-}//end of read_partial_block() helper function
-
-
-/**
- * Reads a full block using the specified buffer size
- *
- * Reads a specified block from the passed file's inode
- * starting at the offset point and then store the results of that in
- * buf_offset
- *
- * @param
- *
- * struct inode *c_inode - The inode of the file we want to read
- *
- * @param
- *
- * int offset - starting point in the file to read from
- *
- * @param
- *
- * void* buf_offset - Holds the information read from the file
- *
- * @param
- *
- * int bytes_left - Holds the number of bytes to read from the file
- *
- * @param
- *
- * void* transfer_space - Used to hold data gotten from SD card block
- * however I don't think we need this
- * TODO: (maybe) replace transfer_space with buff_offset
- *
- * @return
- *
- * Returns the number of bytes which were transferred if successful;
- * otherwise returns an error code
- */
-int read_full_block(struct inode *c_inode, int offset, void* buf_offset, int bytesLeft, void* transfer_space) {
- // read BLOCKSIZE
- // Actually get the data for 1 block (the SD Driver will put it in transfer_space for us)
- int file_block_num = offset / BLOCKSIZE;
- int block_address = get_block_address(c_inode, file_block_num);
- if (block_address < 0) {
- return block_address; //return same error
- }
- int success = sd_receive(transfer_space, block_address);
- if(success < 0){
- // failed on a block receive, therefore the whole kread fails; return failure error
- os_printf("failed to receive block number %d\n", file_block_num);
- return ERR_SD;
- }//end if
- /* ______________________
- |~~~~~~~~~~~~~~~~~~~~~|
- ----------------------- */
- // Actually move the data to the user's specified buffer...must first cast void pointers to uint32_t* pointers:
- // source is transferSpace
- // dest is users buffer
- os_memcpy(transfer_space, buf_offset, (os_size_t) BLOCKSIZE); // note, this updates the buf_offset pointer as it transfer the data
- // os_memcpy takes uint32_t* as arguments
- // reset transferSpace pointer
- return BLOCKSIZE; // note, we are returning the number of bytes that were successfully transferred
-}//end read_full_block() helper function
-
-/**
- * Reads the number of bytes specified from the target inode
- *
- * Calls either read_partial_block or read_full_block based on the number
- * of bytes to read; will continue to call these functions until number of bytes
- * specified has been met
- *
- * @param Description of method's or function's input parameter
- * @param ...
- * @return Description of the return value
- */
-int read_inode(struct inode *c_inode, int offset, void* buf, int num_bytes){
- // Allocate space for and create a bitvector to be used repeatedly to transfer the data:
- uint32_t *transfer_space = kmalloc(BLOCKSIZE);
- int bytes_read = 0;
-
- if (num_bytes+offset > c_inode->size) {
- num_bytes = c_inode->size - offset;
- }
-
- // start of higher-level algo:
- if(num_bytes < BLOCKSIZE) {
- while(bytes_read < num_bytes) {
- int x = read_partial_block(c_inode, offset + bytes_read, buf, (num_bytes-bytes_read),transfer_space);
- bytes_read += x;
- }
-
- } else if(num_bytes >= BLOCKSIZE) {
- //Read in remainder of current block
- bytes_read += read_partial_block(c_inode, offset + bytes_read, buf, (num_bytes-bytes_read),transfer_space);
- //Read in maximum number of full blocks
- while((num_bytes - bytes_read) >= BLOCKSIZE) {
- bytes_read += read_full_block(c_inode, offset + bytes_read, buf+bytes_read, (num_bytes-bytes_read),transfer_space);
- }
- //If not completely read yet, read in remainder
- if(bytes_read < num_bytes) {
- bytes_read += read_partial_block(c_inode, offset + bytes_read, buf, (num_bytes-bytes_read),transfer_space);
- }
- }//end else if
-
- kfree(transfer_space);
- return bytes_read;
-}
-
-
-//end of helper functions
-// -----------------------------------------------------------------------------------------------------------------------------------------------------------
-
-/**
- * Kernel level open file; adds a new entry to the open file table
- *
- * Opens a file using the specified file path and sets it in either
- * read or write mode.
- *
- * @param
- *
- * char* filepath - holds the pathname to the file to be opened
- *
- * @param
- *
- * char mode - holds either r or w indicating whether the file
- * is to be opened in read or write mode
- *
- * @return
- *
- * Returns 0 if the file was opened correctly; otherwise returns
- * -1
- *
- */
-int kopen(const char* filepath, const char mode){
- if (filepath == NULL) {
- os_printf("no directory specified \n");
- return ERR_INVALID;
- }
- if (mode == 0) {
- os_printf("no mode specified \n");
- return ERR_INVALID;
- }
- int fd;
- int inum = 0;
- struct inode* cur_inode = (struct inode*) kmalloc(sizeof(struct inode));
- struct dir_helper* result = (struct dir_helper*) kmalloc(sizeof(struct dir_helper));
- kfind_dir(filepath, result);
- int error = kfind_inode(filepath, inum, (result->dir_levels + 1), cur_inode);
-
- //here we have the file we were looking for! it is cur_inode.
- if (error < 0 || cur_inode->is_dir) {
- if (error < 0) {
- os_printf("file not found, exiting kopen\n");
- }
- else {
- os_printf("cannot open a directory, make the path end to a file\n");
- error = ERR_INVALID;
- }
- kfree(cur_inode);
- kfree(result->truncated_path);
- kfree(result->last);
- kfree(result);
-
- return error; //return same error
- }
-
- // TODO: Permissions need some work, because the bitvector cannot be pulled out like this. :(
- /*bit_vector *p = cur_inode->perms;
- switch (mode){
- case 'r':
- if(bv_get(0, p) == 0){
- os_printf("File Cannot Be Read\n");
- return -1;
- }
- break;
- case 'w':
- if(bv_get(1, p) == 0){
- os_printf("File Cannot Be Written\n");
- return -1;
- }
- break;
- case 'a':
- if(bv_get(1, p) == 0){
- os_printf("File Cannot Be Appeneded To\n");
- return -1;
- }
- break;
- default:
- os_printf("Please specify permission as r to read, w to write and a to append\n");
- }*/
- fd = add_to_opentable(cur_inode, mode);
- kfree(result->truncated_path);
- kfree(result->last);
- kfree(result);
- return fd;
-}//end kopen()
-
-/**
- * Reads a specified number of bytes from the SD card
- *
- * read from fd, put it in buf, then return the number of bytes read
- * in numBytes
- *
- * @param
- *
- * int fd_int - index to a file descriptor in the open file table
- * @param
- *
- * void* buf - buffer to hold the data read from the SD card
- *
- * @param
- *
- * int num_bytes - holds the number of bytes to store in the buffer
- *
- * @return
- *
- * Returns the number of bytes read from the SD card if successful,
- * otherwise returns an error code
- */
-int kread(int fd_int, void* buf, int num_bytes) {
- if (fd_int < 0 || fd_int >= SYSTEM_SIZE) {
- os_printf("kread, fd not valid \n");
- return ERR_INVALID;
- }
- if (buf == NULL) {
- os_printf("no buffer \n");
- return ERR_INVALID;
- }
- if (num_bytes <= 0) {
- os_printf("invalid number of bytes \n");
- return ERR_INVALID;
- }
- int bytes_read = 0;
- uint32_t* buf_offset = buf; //this allows us to move data incrementally to user's buf via buf_offset
- //while retaining the original pointer to return back to the user
- struct file_descriptor* fd = get_descriptor(fd_int); // note, get_file_descriptor() function has not yet been implemented...will be in open_table.c
-
- if ((fd->permission != 'r') && (fd->permission != 'b')) {
- os_printf("no permission\n");
- return ERR_PERM;
- }
- bytes_read = read_inode(fd->linked_file, fd->offset, buf_offset, num_bytes);
-
- fd->offset += bytes_read;
- return bytes_read;
-} // end kread();
-
-
-/**
- * Write a specified number of bytes to the SD card
- *
- * write from fd, put it in buf, then return the number of bytes written in
- * numBytes
- *
- * @param
- *
- * int fd_int - holds the index of a file descriptor in the open file table
- *
- * @param
- *
- * void* buf - holds the data to be written out to disk
- *
- * @param
- *
- * int num_bytes - holds the number of bytes to write to disk
- *
- * @return
- * Returns the number of bytes written to disk if successful, otherwise
- * returns an error code
- */
-int kwrite(int fd_int, void* buf, int num_bytes) {
- if (fd_int < 0 || fd_int >= SYSTEM_SIZE) {
- os_printf("kwrite, fd not valid \n");
- return ERR_INVALID;
- }
- if (buf == NULL) {
- os_printf("no buffer \n");
- return ERR_INVALID;
- }
- if (num_bytes <= 0) {
- os_printf("invalid number of bytes \n");
- return ERR_INVALID;
- }
- struct file_descriptor* fd = get_descriptor(fd_int);
-
- if ((fd->permission != 'w' && fd->permission != 'a')){
- os_printf("ERROR! File was opened without write permissions.\nYou may or may not have permission to write to this file.\nTry opneing with 'w' permission\n");
- return ERR_PERM;
- }
-
- int total_bytes_left = num_bytes;
- int bytes_written = 0;
-
- struct indirect_block* cur_indirect_block;
- void* buf_offset = buf;
- void* transfer_space = kmalloc(BLOCKSIZE);
- // os_memcpy(transferSpace, buf_offset, (os_size_t) BLOCKSIZE);
- struct inode* cur_inode = fd->linked_file;
- // have offset in the file already, just need to move it and copy.
- // fd->offset is the offset in the file.
- //while(bytes_written < total_bytes_left){
- while (total_bytes_left > 0) {
- int file_block_num = fd->offset / BLOCKSIZE;
- // need to put things in transfer_space, move pointer back when done
- int offset_into_current_block = fd->offset % BLOCKSIZE;
- int bytes_left_in_block = BLOCKSIZE - offset_into_current_block;
- int block_address = get_block_address(cur_inode, file_block_num);
-
- //if get_block_address == -1, we know we need to allocate more space for the file
- if(block_address < 0){
- int new_data_block_loc = bv_firstFree(data_block_bitmap);
- if(new_data_block_loc < 0){//disk is completley full
- os_printf("ERROR! disk full\n");
- return ERR_FULL;
- }
- block_address = (new_data_block_loc + FS->start_data_blocks_loc) * BLOCKSIZE;
- bv_set(new_data_block_loc, data_block_bitmap);
-
- int flag_free_cur_indirect_block = 0;
- if(cur_inode->direct_blocks_in_file < MAX_DATABLOCKS_PER_INODE){
- //Case (1): add a direct data block to cur_inode:
- cur_inode->data_blocks[cur_inode->direct_blocks_in_file] = new_data_block_loc;
- cur_inode->direct_blocks_in_file++;
- transmit_receive_bitmap(TRANSMIT, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, new_data_block_loc, 0);
- }else{//(cur_inode->direct_blocks_in_file >= MAX_DATABLOCKS_PER_INODE
- //get the current indirect block and check to see if it has room to add another data block:
- cur_indirect_block = (struct indirect_block*) kmalloc(BLOCKSIZE);
- flag_free_cur_indirect_block = 1;
- get_indirect_block(cur_inode, cur_inode->indirect_blocks[cur_inode->indirect_blocks_in_file-1], cur_indirect_block);
-
- if(cur_indirect_block->blocks_in_file < MAX_DATABLOCKS_PER_INDIRECT_BLOCK && cur_inode->indirect_blocks_in_file != 0){
- //Case (2): add a new data block to to the current indirect block:
- cur_indirect_block->data_blocks[cur_indirect_block->blocks_in_file] = new_data_block_loc;
- cur_indirect_block->blocks_in_file++;
-
- // Causes data abort errors for some reason.
- /*if(indirect_block_table_cache[cur_indirect_block->block_num] == NULL){
- //TODO: implement eviction policy...add the cur_inode to the cache:
- }else{
- *(indirect_block_table_cache[cur_indirect_block->block_num]) = *(cur_indirect_block);
- }*/
-
- sd_transmit((void*) cur_indirect_block, (cur_indirect_block->block_num + FS->start_data_blocks_loc) * BLOCKSIZE);
- transmit_receive_bitmap(TRANSMIT, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, new_data_block_loc, 0);
- }else{ //last indirect block full
- if(cur_inode->indirect_blocks_in_file < MAX_NUM_INDIRECT_BLOCKS){
- /* Case (3): add a new indirect block to the cur_inode, then add a new data block to the new indirect block */
- int new_indirect_block_loc = bv_firstFree(data_block_bitmap); //Consult the data_block_bitmap to find a free block to add the new data block at
- if(new_indirect_block_loc < 0){
- os_printf("ERROR! Disk full\n");
- return ERR_FULL;
- }
- bv_set(new_indirect_block_loc, data_block_bitmap);
-
- struct indirect_block* new_indirect_block = (struct indirect_block*) kmalloc(BLOCKSIZE);
- new_indirect_block->blocks_in_file = 0;
- new_indirect_block->block_num = new_indirect_block_loc;
-
- new_indirect_block->data_blocks[new_indirect_block->blocks_in_file] = new_data_block_loc;
- new_indirect_block->blocks_in_file++;
- cur_inode->indirect_blocks[cur_inode->indirect_blocks_in_file] = new_indirect_block_loc;
- cur_inode->indirect_blocks_in_file++;
-
- /*if(indirect_block_table_cache[new_indirect_block->block_num] == NULL){
- //TODO: implement eviction policy...add the cur_inode to the cache:
- }else{
- *(indirect_block_table_cache[new_indirect_block->block_num]) = *(new_indirect_block);
- }*/
-
- void *buf = kmalloc(BLOCKSIZE);
- os_memcpy((uint32_t *) new_indirect_block, buf, sizeof(struct indirect_block));
- sd_transmit(buf, (new_indirect_block->block_num + FS->start_data_blocks_loc) * BLOCKSIZE);
- kfree(buf);
- transmit_receive_bitmap(TRANSMIT, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, new_indirect_block_loc, 0);
- kfree(new_indirect_block);
-
- }else{
- //file has reached max allowable size:
- os_printf("ERROR! Operation failed because file has reached max allowable size\n");
- return ERR_FULL;
- }
- }
- }
- if(flag_free_cur_indirect_block){
- kfree(cur_indirect_block);
- }
- }//end if(block_address == -1)
-
- //now we have added new blocks to the file if necessary (and possible), so actually execute the write:
- if(total_bytes_left <= bytes_left_in_block){
- //note, that here we are overwriting, but will never have to allocate new data blocks for the file
- /* --------------- -----------------
- |~~~~~~~| | OR | |~~~~~| |
- ---------------- -----------------
- */
- //Remaining bytes to write will fit in the current block
- //first read the block in, so that the first part of it doesn't get ovewritten:
- sd_receive(transfer_space, block_address);
- // write total_bytes_left
- os_memcpy(buf_offset, transfer_space + offset_into_current_block, (os_size_t) total_bytes_left);
- //transfer_space -= total_bytes_left; //Purpose of this?
- // pointer to start, block_num, where we are in file, length of write
- sd_transmit(transfer_space, block_address);
-
- bytes_written += total_bytes_left;
- fd->offset += total_bytes_left;
- cur_inode->size += total_bytes_left;
- total_bytes_left = 0; //at this point there is nothing left to write, so we're done
- }
- else{//(total_bytes_left > bytes_left_in_block) so...we might need to allocate new data blocks for the file...
- /*
- ------------
- | |~~~|
- ------------
- write to the end of the block
- */
-
- //Remaining bytes will not fit in current block, fill up remainder of block
- //first read the block in, so that the first part of it doesn't get ovewritten:
- sd_receive(transfer_space, block_address);
- // write total_bytes_left
- os_memcpy(buf_offset, transfer_space + offset_into_current_block, (os_size_t) bytes_left_in_block);
-
- //transfer_space -= bytes_left_in_block; //Purpose of this?
- // pointer to start, blockNum, where we are in file, lengh of write
- sd_transmit(transfer_space, block_address);
-
- bytes_written += bytes_left_in_block;
- total_bytes_left -= bytes_left_in_block;
- fd->offset += bytes_left_in_block;
- buf_offset += bytes_left_in_block;
- cur_inode->size += bytes_left_in_block;
- }
-
- }//end while
- //update the the cur_inode on disk:
- sd_transmit(cur_inode, (cur_inode->inum + FS->start_inode_table_loc) * BLOCKSIZE);
- return bytes_written;
-} // end kwrite();
-
-/**
- * Close the file
- *
- * Remove the file from the open file table and free the file's inode
- *
- * @param
- *
- * int fd - holds an index of a file descriptor in the open file table
- *
- * @return
- *
- * Returns 1 if the file was successfully closed, otherwise returns an error
- */
-int kclose(int fd) {
- if (fd < 0 || fd >= SYSTEM_SIZE) {
- os_printf("kclose, fd not valid \n");
- return ERR_INVALID;
- }
- int error;
- if(!file_is_open(fd)) {
- os_printf("file not open");
- return ERR_GEN;
- }
- error = delete_from_opentable(fd); //this also frees inode
- return error;
-} // end kclose();
-
-/**
- * Increment seek position within a file
- *
- * Increments the seek pointer of a specific file by a number of
- * specified bytes
- *
- * @param
- *
- * int fd_int - holds the index of a file descriptor in the open file table
- *
- * @param
- *
- * int num_bytes - holds the number of bytes to move the seek pointer by
- *
- * @return
- *
- * Returns 0 if the seek pointer was successfully moved; otherwise returns
- * an error code
- */
-int kseek(int fd_int, int num_bytes) {
- if (fd_int < 0 || fd_int >= SYSTEM_SIZE) {
- os_printf("kseek, fd not valid \n");
- return ERR_INVALID;
- }
- if (num_bytes <= 0) {
- os_printf("num of bytes not valid \n");
- return ERR_INVALID;
- }
- struct file_descriptor* fd = get_descriptor(fd_int);
- if (fd->permission != 'r' || fd->permission != 'w') {
- os_printf("no permission \n");
- return ERR_PERM;
- } else if ((num_bytes > 0) && ((fd->offset + num_bytes) > ((fd->linked_file)->size))){
- os_printf("Error! file offset exceeds file size \n");
- return ERR_GEN;
- } else if ((num_bytes < 0) && ((fd->offset + num_bytes) < 0)){
- os_printf("Error! file offset exceeds beginning of file \n");
- return ERR_GEN;
- }//end if else */
- fd->offset += num_bytes;
- return SUCCESS;
-} // end kseek();
-
-
-/**
- * Creates a new file or directory in the file system
- *
- * Creates a new file or directory and all metadata attached to that
- * file or directory and adds it to the open file table
- *
- * NOTE: File/Directory is not persistenly stored at this point!
- *
- * @param
- *
- * char* filepath - holds the path to the directory in which the
- * new file/directory is to be added
- *
- * @param
- *
- * char mode - not used at present, will eventually be used to
- * set file permissions
- *
- * @param
- *
- * int is_this_a_dir - set to 0 if the object to be created is
- * a file; set to 1 if the object to be created is a directory
- *
- * @return
- *
- * Returns 0 if the file/directory was created successfully
- * otherwise returns -1
- */
-int kcreate(const char* filepath, char mode, int is_this_a_dir) {
- if (filepath == NULL) {
- os_printf("filepath not valid \n");
- return ERR_INVALID;
- }
- if (mode == 0) {
- os_printf("filepath not valid \n");
- return ERR_INVALID;
- }
- int fd;
- int inum = 0;
- struct inode* cur_inode = (struct inode*) kmalloc(sizeof(struct inode));
- struct dir_helper* result = (struct dir_helper*) kmalloc(sizeof(struct dir_helper));
- kfind_dir(filepath, result);
- kfind_inode(result->truncated_path, inum, result->dir_levels, cur_inode);
-
- // at this point, the name of the file or dir to be created is “result->last” and it has to be added to cur_inode
- int free_inode_loc = bv_firstFree(inode_bitmap); //Consult the inode_bitmap to find a free space in the inode_table to add the new inode
-
- if (free_inode_loc < 0) {
- os_printf("Disk has reached max number of files allowed. \n");
- kfree(cur_inode);
- kfree(result->truncated_path);
- kfree(result->last);
- kfree(result);
- return ERR_FULL;
- }
- bv_set(free_inode_loc, inode_bitmap);
- struct inode * new_inode = (struct inode*) kmalloc(sizeof(struct inode)); // Create the new inode
-
- /* initialize all fields of inode...note, these next 5 fields are for
- all files, whether they are a dir or leaf */
- new_inode->inum = free_inode_loc;
- new_inode->fd_refs = 0; //will be incremented in add to opentable
- new_inode->size = 0;
- new_inode->usr_id = 0; //or something
- new_inode->indirect_blocks_in_file = 0;
-
- /* initialize the fields for new_indoe that are different for dirs and leaves */
- if(is_this_a_dir){
- new_inode->is_dir = 1;
- new_inode->direct_blocks_in_file = 1;
-
- // Lay down the first (empty...) data block for the new directory (NOT root).
-
- transmit_receive_bitmap(RECEIVE, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, 0, 1);
- int new_data_block_loc = bv_firstFree(data_block_bitmap);
- if(new_data_block_loc < 0){//disk is completley full
- os_printf("ERROR! disk full\n");
- return ERR_FULL;
- }//end if
- int block_address = (new_data_block_loc + FS->start_data_blocks_loc) * BLOCKSIZE;
- bv_set(new_data_block_loc, data_block_bitmap);
-
- //WILL THIS FIX IT??????????
- transmit_receive_bitmap(TRANSMIT, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, 0, 1);
-
- void *block = kmalloc(BLOCKSIZE);
- os_memset(block, 0, BLOCKSIZE);
- struct dir_data_block ddb;
- ddb.block_num = new_data_block_loc;
- ddb.num_entries = 0;
- os_memset(block, 0, BLOCKSIZE);
- os_memcpy((uint32_t*)&ddb, block, sizeof(struct dir_data_block));
- sd_transmit((void*)block, block_address);
- new_inode->data_blocks[0] = new_data_block_loc;
- kfree(block);
- }else{ /* initialize the fields for new_inode that are different for dirs and leaves */
- new_inode->is_dir = 0;
- new_inode->direct_blocks_in_file = 0;
- }//end if else
-
- //new_inode->data_blocks[MAX_DATABLOCKS_PER_INODE] = {0};
-
- //new_inode->indirect_blocks[MAX_NUM_INDIRECT_BLOCKS] = {0};
- // TODO: Investigate permissions, and bitvectors/FS in general.
- /*switch (mode){
- case 'r':
- bv_set(0, new_inode->perms);
- bv_lower(1, new_inode->perms);
- break;
- case 'w':
- bv_set(0, new_inode->perms);
- bv_set(1, new_inode->perms);
- break;
- default:
- os_printf("Wrong permission. Please insert r for read and w for write\n");
- return -1;
- }*/
- //UPDATE DISK by writing memory data structures to disk
-
- int error = add_dir_entry(cur_inode, new_inode->inum, result);
- if (error != 0) {
- return error;
- }
- void *block = kmalloc(BLOCKSIZE);
- os_memset(block, 0, BLOCKSIZE);
- os_memcpy((uint32_t*)cur_inode, block, sizeof(struct inode));
- sd_transmit(block, (cur_inode->inum + FS->start_inode_table_loc) * BLOCKSIZE);
-
- os_memset(block, 0, BLOCKSIZE);
- os_memcpy((uint32_t*)new_inode, block, sizeof(struct inode));
- sd_transmit(block, (FS->start_inode_table_loc + new_inode->inum * INODES_PER_BLOCK)*BLOCKSIZE); //if there are more than 1 inodeperblock need to change
- kfree(block);
- // See above... We can't just do this.
- //sd_transmit((void*)inode_bitmap, FS->inode_bitmap_loc);
- kfree(cur_inode);
- if (!is_this_a_dir) {
- fd = add_to_opentable(new_inode, mode);
- return fd;
- }else { //directories are not added to open table
- os_printf("Directory Successfully added\n");
- kfree(new_inode);
- return SUCCESS;
- }
-
-}//end of kcreate() function
-
-/**
- * Determines whether a directory is empty or not
- *
- * Determines whether a directory is empty, can also be used to
- * determine whether the object is a file instead of a directory as
- * well as if the file is not a valid Course OS FS file
- *
- * @param
- *
- * struct inode* cur_inode - holds the file/directory to check
- *
- * @return
- *
- * Return 1 if it is a directory, return 0 if it not a directory,
- * return an error code if something went wrong
- */
-int dir_empty(struct inode* cur_inode){
- if(!cur_inode->is_dir){
- os_printf("This file is not a directory\n");
- return FALSE;//return 0, because it's not a dir
- }//end else
- if((cur_inode->direct_blocks_in_file == 0) && (cur_inode->indirect_blocks_in_file == 0)){
- if(cur_inode->size == 0){
- return TRUE; //return true because the dir is empty
- } else {
- /* TODO: Remove after debugging */
- os_printf("LOGIC ERROR: File size does not sync with file properties");
- return ERR_GEN;//error bc we should never get here
- }
- }
- else {
- os_printf("Your current directory still has files in it\n");
- return FALSE;//return false, bc the dir is not empty
- }
-}
-
-/**
- * Helper function for kremove_dir_entry actually deletes file/directory
- *
- * Runs after entry for the file/directory has been removed from the parent
- * directory and physically deletes the file/directory
- *
- * @param
- *
- * struct inode* cur_inode - inode of the file to check
- *
- * @return
- *
- * Returns 0 if the file is OK to remove, otherwise returns an error code
- */
-int kdelete_single_helper(struct inode * cur_inode){
- if (cur_inode->is_dir){
- //we know it's a directory
- if(dir_empty(cur_inode)) {
-
- bv_lower(cur_inode->inum, inode_bitmap);
- return SUCCESS;//no error
- }
- else {
- os_printf("This file is a non-empty directory, so cannot be deleted");
- return ERR_GEN;//error
- }
- }
- //we know it is a file
- else{
- int d;
- for(d=0; ddirect_blocks_in_file; d++){
-
- int index = cur_inode->data_blocks[d];
- bv_lower(index, data_block_bitmap);
- }
- struct indirect_block* cur_inder_block = (struct indirect_block*)kmalloc(sizeof(struct indirect_block));
- int i;
- for(i=0; iindirect_blocks_in_file; i++){
- int z;
- int indy_index_add = (cur_inode->indirect_blocks[i] + FS->start_data_blocks_loc) * BLOCKSIZE;
- sd_receive((void*)cur_inder_block, indy_index_add);
- for(z=0; zblocks_in_file; z++){
-
- int index = cur_inder_block->data_blocks[z];
- bv_lower(index, data_block_bitmap);
- }
- bv_lower(cur_inder_block->block_num, data_block_bitmap);
- }
- kfree(cur_inder_block);
- bv_lower(cur_inode->inum, inode_bitmap);
- }
- return SUCCESS;
-} // end kdelete_single_helper();
-
-/**
- * Deletes a single entry in a directory
- *
- * Deletes a file or directory's entry from a specified directory's inode list
- * NOTE: May/May not use recursive delete; this is untested so proceed
- * with caution and test whether a recursive delete is done before
- * using this function for deleting sub-directories.
- *
- * @param
- *
- * struct inode* cur_inode - holds a pointer to the folder which contains the file
- * reference to remove
- *
- * @param
- *
- * int tgt_inum - Used to hold the index of the inode to be removed
- *
- * @return
- *
- * Returns 0 if the entry was successfully removed from the directory; otherwise
- * it returns an error code.
- */
-int kremove_dir_entry (struct inode* cur_inode, int tgt_inum) {//free_inode_loc = tgt_inum
- //first get the appropriate data block, either from the array of direct data blocks from an indirect block:
- struct dir_data_block* dir_block = (struct dir_data_block*) kmalloc(BLOCKSIZE);
- struct indirect_block* cur_indirect_block;
- //if the cur_inode's array of direct data blocks has not reached max capacity, grab the last data block in the array to update:
- int i, j, k;
- //search through direct data blocks:
- for(i = 0; i < cur_inode->direct_blocks_in_file; i++){
- sd_receive((void*) dir_block, (cur_inode->data_blocks[i] + FS->start_data_blocks_loc)*BLOCKSIZE);
- for(j = 0; j < dir_block->num_entries; j++){
- struct dir_entry dir_ent = (struct dir_entry) dir_block->dir_entries[j];
- if(dir_ent.inum == tgt_inum){
- /* remove dir_ent from dir_block, by moving the last dir_entry to this
- index in the array and decrementing dir_block->num_entries */
- dir_block->dir_entries[j] = dir_block->dir_entries[dir_block->num_entries-1];
- dir_block->num_entries--;
- if(dir_block->num_entries == 0){
- /* then this dir_data_block is empty, so we need to:
- remove it from the cur_inode->data_blocks[] at index i
- remove it from the data_blocks_bitmap */
- bv_lower(cur_inode->data_blocks[i], data_block_bitmap);
- cur_inode->data_blocks[i] = cur_inode->data_blocks[cur_inode->direct_blocks_in_file-1];
- cur_inode->direct_blocks_in_file--;
- }//end if
- cur_inode->size -= sizeof(struct dir_entry);
- sd_transmit((void*) dir_block, (cur_inode->data_blocks[i] + FS->start_data_blocks_loc)*BLOCKSIZE);
- kfree(dir_block);
- return SUCCESS;
- }//end if
- }//end for
- }//end outer for
- //search through indirect data blocks:
- cur_indirect_block = (struct indirect_block*) kmalloc(BLOCKSIZE);
- for(k = 0; k < cur_inode->indirect_blocks_in_file; k++){
- get_indirect_block(cur_inode, k, cur_indirect_block);
- for(i = 0; i < cur_indirect_block->blocks_in_file; i++){
- sd_receive((void*) dir_block, (cur_indirect_block->data_blocks[i] + FS->start_data_blocks_loc)*BLOCKSIZE);
- for(j = 0; j < dir_block->num_entries; j++){
- struct dir_entry dir_ent = (struct dir_entry) dir_block->dir_entries[j];
- if(dir_ent.inum == tgt_inum){
- /* remove dir_ent from dir_block, by moving the last dir_entry to this
- index in the array and decrementing dir_block->num_entries */
- dir_block->dir_entries[j] = dir_block->dir_entries[dir_block->num_entries-1];
- dir_block->num_entries--;
- if(dir_block->num_entries == 0){
- /* then this dir_data_block is empty, so we need to:
- remove it from the cur_inode->data_blocks[] at index i
- remove it from the data_blocks_bitmap */
- bv_lower(cur_indirect_block->data_blocks[i], data_block_bitmap);
- cur_indirect_block->data_blocks[i] = cur_indirect_block->data_blocks[cur_inode->direct_blocks_in_file-1];
- cur_indirect_block->blocks_in_file--;
-
- if(cur_indirect_block->blocks_in_file == 0){
- /* then this indirect_block is empty, so we need to:
- remove it from the cur_inode->indirect_blocks[] at index k
- remove it from the data_blocks_bitmap */
- bv_lower(cur_inode->indirect_blocks[k],data_block_bitmap);
- cur_inode->indirect_blocks[k] = cur_inode->indirect_blocks[cur_inode->indirect_blocks_in_file-1];
- cur_inode->indirect_blocks_in_file--;
- }//end if
- }//end if
- cur_inode->size -= sizeof(struct dir_entry);
- sd_transmit((void*) dir_block, (cur_indirect_block->data_blocks[i] + FS->start_data_blocks_loc)*BLOCKSIZE);
- kfree(dir_block);
- kfree(cur_indirect_block);
- return SUCCESS;
- }//end if
- }//end for
- }//end outer for
- }//end outer outer for
- kfree(dir_block);
- kfree(cur_indirect_block);
- return ERR_404;
-}//end kremove_dir_entry() function
-
-
-/**
- * Deletes a single file or from a directory
- *
- * call delete_single_helper, deletes the lowest level (ie target) file and
- * updates all bitmaps, but DOES NOT remove the dir_entry in levelup dir
- *
- * @param
- *
- * struct inode* cur_inode - Points to a specific file/directory to remove
- *
- * @param
- *
- * struct inode* level_up_inode - points to the directory in which the specifiied
- * file/directory resides
- *
- * @return
- *
- * Returns 0 if the the file was successfully deleted; returns -1 if the file
- * doesn't exist
- */
-int kdelete_single(struct inode* cur_inode, struct inode* level_up_inode) {
- /* call delete_single_helper, deletes the lowest level (ie target) file and
- updates all bitmaps, but DOES NOT remove the dir_entry in levelup dir */
- int error = kdelete_single_helper(cur_inode);
- if(!error){ //if kdeletesinglehelper was successful
- sd_transmit((void*) cur_inode, (cur_inode->inum + FS->start_inode_table_loc) * BLOCKSIZE);
- /* delete dir_entry in levelup dir) */
- error = kremove_dir_entry(level_up_inode, cur_inode->inum);
- if(error < 0){
- os_printf("ERROR! Could not find dir_entry in level_up_inode...BIG PROBLEM!!!\n");
- kfree(level_up_inode);
- return error;
- }//end inner if
- sd_transmit((void*) cur_inode, (level_up_inode->inum + FS->start_inode_table_loc) * BLOCKSIZE);
- }else{
- kfree(level_up_inode);
- return error; //return same error
- }
- kfree(level_up_inode);
- return SUCCESS;
-} // end kdelete_single()
-
-
-/**
- * Recursively deletes an entire directory
- *
- * Deletes a directory and any sub-directories and files contained within
- * freeing all blocks and metadata for each entry and then updates the
- * metadata for the directory which contained it
- *
- * The logic on this should be good, but still need to...
- * TODO: on each sd_recieve() check cache first AND figure out kmalloc
- * situation...will this cause heap overflow??? should we limit the
- * depth of filepaths to avoid this???
- *
- * @param
- *
- * struct inode* cur_inode - Points to a specific file/directory to remove
- *
- * @param
- *
- * struct inode* level_up_inode - points to the directory in which the specifiied
- * file/directory resides
- *
- * @return
- *
- * Returns 0 if the the directory was successfully deleted, otherwise returns
- * an error code
- */
-int krec_delete(struct inode * level_up_inode, struct inode * cur_inode){
- //base case
- int error;
- int status = dir_empty(cur_inode);
- if (status == TRUE){ //dir is empty
- error = kdelete_single(cur_inode, level_up_inode);
- //SHOULDN'T FREE IT kfree(level_up_inode);
- }else if(status < 0){ //WTF?
- return ERR_GEN;
- }
-
- if (error) {
- return error;
- }
-
- //recursive step
- else{ //status == 0, meaning is not empty
- int i;
- int direct_data_block_address;
- struct dir_data_block* dir_block = (struct dir_data_block*) kmalloc(sizeof(struct dir_data_block));
- for(i=0; i< cur_inode->direct_blocks_in_file; i++){
- direct_data_block_address = (cur_inode->data_blocks[i]+FS->start_data_blocks_loc) * BLOCKSIZE;
- sd_receive(dir_block, direct_data_block_address);
- int j;
- int inum;
- struct dir_entry cur_dir_entry;
- for(j = 0; j < dir_block->num_entries; j++){
- cur_dir_entry = dir_block->dir_entries[j];
- inum = cur_dir_entry.inum;
- struct inode* next_inode = (struct inode*) kmalloc(sizeof(struct inode));
- // struct inode* next_inode;
- get_inode(inum, next_inode);
- krec_delete(cur_inode,next_inode);
- kfree(next_inode);
- }//end
- }//end for
- int k;
- int indirect_data_block_address;
- struct indirect_block* cur_indirect_block = (struct indirect_block*) kmalloc(sizeof(struct indirect_block));
- for(k = 0; k < cur_inode->indirect_blocks_in_file; k++){
- indirect_data_block_address = (cur_inode->indirect_blocks[k]+FS->start_data_blocks_loc) * BLOCKSIZE;
- sd_receive(cur_indirect_block, indirect_data_block_address);
- for(i=0; i < cur_indirect_block->blocks_in_file; i++){
- direct_data_block_address = (cur_indirect_block->data_blocks[i]+FS->start_data_blocks_loc) * BLOCKSIZE;
- sd_receive(dir_block, direct_data_block_address);
- int j;
- int inum;
- struct dir_entry cur_dir_entry;
- for(j = 0; j < dir_block->num_entries; j++){
- cur_dir_entry = dir_block->dir_entries[j];
- inum = cur_dir_entry.inum;
- struct inode* next_inode = (struct inode*) kmalloc(sizeof(struct inode));
- // struct inode* next_inode;
- get_inode(inum, next_inode);
- krec_delete(cur_inode,next_inode);
- kfree(next_inode);
- }//end
- }//end
- }//end outer for
- kfree(cur_indirect_block);
- kfree(dir_block);
- }//end if else
- return SUCCESS;
-}//end krec_delete()
-
-//---------------------------------------------------
-
-/**
- * Deletes a file or directory at the specified filepath
- *
- * Can be used to delete a single file or directory; can delete
- * directories recursively
- *
- * NOTE: Recursive delete is untested; please test this function
- * to ensure it is working properly before using it
- *
- * @param
- *
- * char* filepath - Holds the path to the specified file/directory to delete
- *
- * @param
- *
- * int recursive - Holds 0 if the target is a single file or empty directory
- * holds 1 if the target is a full directory which needs to be deleted recursively
- *
- * @return
- *
- * Returns 0 if the file/directory was deleted successfully; otherwise returns an
- * error code
- */
-//delete the file or directory at filepath. Return -1 if the file does not exist
-int kdelete(const char* filepath, int recursive) {
- int error;
- int inum = 0;
-
- /* spaceholder for lowest inode */
- struct inode* cur_inode = (struct inode*) kmalloc(sizeof(struct inode));
- struct inode* level_up_inode = (struct inode*) kmalloc(sizeof(struct inode));
- /* spaceholder for helper struct */
- struct dir_helper* result = (struct dir_helper*) kmalloc(sizeof(struct dir_helper));
-
- /* find the helper struct */
- kfind_dir(filepath, result);
-
- /* find the lowest inode */
- error = kfind_inode(filepath, inum, (result->dir_levels + 1), cur_inode);
- if(error < 0){
- kfree(cur_inode);
- kfree(level_up_inode);
- kfree(result->truncated_path);
- kfree(result->last);
- kfree(result);
- return error;
- }
- /* Check to ensure the file is not currently open...if it is return an error and notify user */
- if(inode_is_open(cur_inode)){
- os_printf("File %d cannot be deleted, because it is currently open\n", cur_inode->inum);
- kfree(cur_inode);
- kfree(level_up_inode);
- kfree(result->truncated_path);
- kfree(result->last);
- kfree(result);
- return ERR_GEN;
- }
- error = kfind_inode(filepath, inum, (result->dir_levels), level_up_inode);
- if(recursive){
- error = krec_delete(level_up_inode,cur_inode);
- kfree(cur_inode);
- kfree(level_up_inode);
- kfree(result->truncated_path);
- kfree(result->last);
- kfree(result);
- transmit_receive_bitmap(TRANSMIT, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, 0, 1);
- transmit_receive_bitmap(TRANSMIT, inode_bitmap, FS->inode_bitmap_loc, FS->max_inodes, 0, 1);
- return error;
- }else{
- error = kdelete_single(cur_inode, level_up_inode);
- kfree(cur_inode);
- kfree(level_up_inode);
- kfree(result->truncated_path);
- kfree(result->last);
- kfree(result);
- transmit_receive_bitmap(TRANSMIT, data_block_bitmap, FS->data_bitmap_loc, FS->max_data_blocks, 0, 1);
- transmit_receive_bitmap(TRANSMIT, inode_bitmap, FS->inode_bitmap_loc, FS->max_inodes, 0, 1);
- return error;
- }//end if else
- os_printf("we should never reach this!!!\n");
- return ERR_GEN;
-} // end kdelete()
-
-
-//---------------------------------------------------
-
-/**
- * Copies contents of a file into a new file
- *
- * Creates a new file at the destination path and then copies
- * all data from the file pointed to by the source path
- *
- * @param
- *
- * char* source - holds the file path of the file to copy
- *
- * @param
- *
- * char* dest - holds the destination file path to copy to
- *
- * @param
- *
- * char mode - Mainly used for permissions; not implemented right
- * now however
- *
- * @return
- *
- * Retun 0 if the file was copied successfully; otherwise return
- * an error code
- */
-int kcopy(const char* source, const char* dest, const char mode) {
- int error = 0;
- int inum = 0; //start from root
-
- //1. find source
- struct dir_helper *source_dir_helper = (struct dir_helper *) kmalloc(sizeof(struct dir_helper));
- kfind_dir(source, source_dir_helper);
- struct inode *source_inode = (struct inode*) kmalloc(sizeof(struct inode));
- //find the source inode
- error = kfind_inode(source, inum, (source_dir_helper->dir_levels + 1), source_inode);
- if (error < 0) { //kfind_inode unsuccessful
- os_printf("kfind_inode unsuccessful \n");
- kfree(source_inode);
- kfree(source_dir_helper->truncated_path);
- kfree(source_dir_helper->last);
- kfree(source_dir_helper);
- return ERR_404;
- }
- //at this point source_inode is the inode of the source
- int copy_directory = source_inode->is_dir; //checks if we are copying a direcory or a file
-
- //2. cerate destination
- int dest_fd = 0;
- dest_fd = kcreate(dest, mode, copy_directory); //creates the new file or directory
- if (dest_fd < 0) { //some problem occurred in kcreate
- os_printf("kcreate unsuccessful \n");
- kfree(source_inode);
- kfree(source_dir_helper->truncated_path);
- kfree(source_dir_helper->last);
- kfree(source_dir_helper);
- return ERR_GEN;
- }
-
- //3. find destination
- struct file_descriptor *dest_fd_struct = get_descriptor(dest_fd);
- if (dest_fd_struct == NULL) { //get_descriptor had problems
- os_printf("get_descriptor unsuccessful \n");
- kfree(source_inode);
- kfree(source_dir_helper->truncated_path);
- kfree(source_dir_helper->last);
- kfree(source_dir_helper);
- return ERR_GEN;
- }
- //at this point dest_inode is the inode of the created destination
-
- void *buffer = (void*) kmalloc(source_inode->size);
- error = read_inode(source_inode, 0, buffer, source_inode->size);
- if (!error) {
- error = kwrite(dest_fd, buffer, source_inode->size);
- }
- kfree(buffer);
- kfree(source_inode);
- kfree(source_dir_helper->truncated_path);
- kfree(source_dir_helper->last);
- kfree(source_dir_helper);
- return error;
-}//end kcopy function
-
-
-/**
- * Prints the contents of a directory to the screen
- *
- * @param
- *
- * char* filepath - holds the filepath to the directory to display
- * the contents of
- *
- * @return
- * Returns 0 if the function was executed correctly, otherwise returns
- * an error code
- */
-int kls(const char* filepath) {
- int error = 0;
- int inum = 0; //starting from root
- struct dir_helper* result = (struct dir_helper *) kmalloc(sizeof(struct dir_helper));
- kfind_dir(filepath, result);
- struct inode* cur_inode = (struct inode*) kmalloc(sizeof(struct inode));
- error = kfind_inode(filepath, inum, (result->dir_levels + 1), cur_inode);
- if (error < 0 || cur_inode->is_dir == 0) { //kfind_inode unsuccessful or cannot ls
- if (error < 0) { //kfind
- os_printf("kfind_inode unsuccessful \n");
- }
- else { //cannot ls
- os_printf("this is not a directory but a file, cannot ls a file \n");
- error = ERR_INVALID;
- }
- kfree(cur_inode);
- kfree(result->truncated_path);
- kfree(result->last);
- kfree(result);
- return error; //return same error
- }
- //at this point, cur_inode is a directory and we need to print all the names of its contents.
- //1. print from direct blocks
- int i;
- void* dir_spaceholder = (void*) kmalloc(BLOCKSIZE);
- for(i = 0; i < cur_inode->direct_blocks_in_file; i++){
- sd_receive(dir_spaceholder, (cur_inode->data_blocks[i])*BLOCKSIZE);
- struct dir_data_block cur_data_block = *((struct dir_data_block*) dir_spaceholder);
- int j;
- for(j = 0; j < (cur_data_block.num_entries); j++){
- struct dir_entry file_dir = cur_data_block.dir_entries[j];
- os_printf("entry: %s \n", file_dir.name);
- }//inner for
- }//outer for
- //2. print from indirect blocks
- struct indirect_block *cur_indirect_block = (struct indirect_block *) kmalloc(sizeof(struct indirect_block));
- int cur_indirect_block_num;
- for(i = 0; i < cur_inode->indirect_blocks_in_file; i++){
- cur_indirect_block_num = cur_inode->indirect_blocks[i];
- get_indirect_block(cur_inode, cur_indirect_block_num, cur_indirect_block);
- int j;
- for(j = 0; j < cur_indirect_block->blocks_in_file; j++){
- sd_receive(dir_spaceholder, (cur_indirect_block->data_blocks[j])*BLOCKSIZE);
- struct dir_data_block cur_data_block = *((struct dir_data_block*) dir_spaceholder);
- int k;
- for(k = 0; k < (cur_data_block.num_entries); k++){
- struct dir_entry file_dir = cur_data_block.dir_entries[k];
- os_printf("entry: %s \n", file_dir.name);
- }//inner for
- }//outer for
- }//end for
- kfree(cur_indirect_block);
- kfree(dir_spaceholder);
- kfree(cur_inode);
- kfree(result->truncated_path);
- kfree(result->last);
- kfree(result);
- return SUCCESS;
-}
-
-/**
- * Used to obtain information about a specified file or directory
- *
- * Obtains various information about the file at the specified file
- * path including: size of the file, how many open copies of the
- * file there are, and whether the file is a directory
- *
- * @param
- *
- * char* filepath - The path to the file to obtain information from
- *
- * @param
- *
- * struct stats* result - Pointer to a location to store information
- * about the specified file
- *
- * @return
- * Returns 0 if information was successfully retrieved; otherwise
- * returns an error code
- */
-int get_stats(const char * filepath, struct stats * result) {
- int inum = 0;
- struct inode* cur_inode = (struct inode*) kmalloc(sizeof(struct inode));
- struct dir_helper* help_result = (struct dir_helper*) kmalloc(sizeof(struct dir_helper));
- kfind_dir(filepath, help_result);
- int error = kfind_inode(filepath, inum, (help_result->dir_levels + 1), cur_inode);
- if (error < 0) {
- os_printf("file not found, exiting kopen\n");
- kfree(cur_inode);
- kfree(help_result->truncated_path);
- kfree(help_result->last);
- kfree(help_result);
- return error; //return same error
- }
- result->size = cur_inode->size;
- result->fd_refs = cur_inode->fd_refs;
- result->is_dir = cur_inode->is_dir;
- kfree(cur_inode);
- kfree(help_result->truncated_path);
- kfree(help_result->last);
- kfree(help_result);
- return SUCCESS;
-}//end get_stats function
diff --git a/kernel/fs/fat16/test.c b/kernel/fs/fat16/test.c
deleted file mode 100644
index 5f002434..00000000
--- a/kernel/fs/fat16/test.c
+++ /dev/null
@@ -1,75 +0,0 @@
-#include
-#include
-#include
-#include
-
-
-int main(int argc, char *argv[]) {
- char cwd[1024];
- if (getcwd(cwd, sizeof(cwd)) != NULL)
- fprintf(stdout, "Current working dir: %s\n", cwd);
- else
- perror("getcwd() error");
-
- char* buf = (void*) malloc(sizeof(char) * 512);
- char* original_buf = buf;
- *buf = "courseOSfsaaaaaaaaaaaaaaaaaaaaa";
- buf +=32;
-
- *((int*)buf) = (int)1;
- buf +=4;
-
- buf = (int*)buf;
-
- *(buf) = (int)2;
- buf +=4;
-
- *(buf) = (int)512;
- buf +=4;
-
- *(buf) = (int)2;
- buf +=4;
-
- *(buf) = (int)100;
- buf +=4;
-
- *(buf) = (int)900;
- buf +=4;
-
- *(buf) = (int)11;
- buf +=4;
-
- *(buf) = (int)12;
- buf +=4;
-
- *(buf) = (int)333;
- buf +=4;
-
- *(buf) = (int)444;
- buf +=4;
-
- // 12 512000 512 2 100 900 11 12 333 444
- fprintf("TESTING***************\n")
- int fd = open("superblock_1.data", 'O_RDWR');
- write(fd, original_buf, 512);
- close(fd);
-
-
- // FILE *params_file = fopen("superblock_1.data", "w"); // write only
- // // test to ensure that the file was actually created and exists:
- // if (params_file == NULL){
- // printf("1. Error! Could not create file\n");
- // exit(-1); // must include stdlib.h
- // }//end if
-
- // fprintf(params_file, "PARAMS\n");
- // fprintf(params_file, "nx=%d,ny=%d,nz=%d\n", nx, ny, nz);
- // fprintf(params_file, "dx=%lg,dy=%lg,dz=%lg\n", dx, dy, dz);
- // fprintf(params_file, "numFiles=%d\n", numFiles);
- // fprintf(params_file, "numParticles=%d\n", numParticles);
- // fclose(params_file);
-
-
-
- return 0;
-}
diff --git a/kernel/fs/fat16/test_superblock.data b/kernel/fs/fat16/test_superblock.data
deleted file mode 100644
index cca4d90a..00000000
--- a/kernel/fs/fat16/test_superblock.data
+++ /dev/null
@@ -1 +0,0 @@
-courseOSfsaaaaaaaaaaaaaaaaaaaaaa1 2 512000 512 2 100 900 11 12 333 444
\ No newline at end of file
diff --git a/kernel/fs/fat16/test_superblock.txt b/kernel/fs/fat16/test_superblock.txt
deleted file mode 100644
index cca4d90a..00000000
--- a/kernel/fs/fat16/test_superblock.txt
+++ /dev/null
@@ -1 +0,0 @@
-courseOSfsaaaaaaaaaaaaaaaaaaaaaa1 2 512000 512 2 100 900 11 12 333 444
\ No newline at end of file
diff --git a/kernel/fs/open_table.c b/kernel/fs/open_table.c
deleted file mode 100644
index efa075ac..00000000
--- a/kernel/fs/open_table.c
+++ /dev/null
@@ -1,117 +0,0 @@
-//This file contains the table of open files, implemented as an array
-// with methods like add_to_opentable and delete_from_opentable to be called in open and close
-//Since methods are provided, other files should not touch neither the free LL or the arrray,
-// but just use the premade methods.
-
-#include "klibc.h"
-#include "fs/file.h"
-#include "fs/open_table.h"
-#include "data_structures/bitvector.h"
-#include
-
-
-//called by file.c initialization function, initializes free list and table
-void fs_table_init() {
- open_table_free_list = make_vector(SYSTEM_SIZE); //create bitvector of free indexes
- table = (struct file_descriptor**)kmalloc(SYSTEM_SIZE * (sizeof(struct file_descriptor*))); //malloc the table
- os_memset(table, 0, SYSTEM_SIZE * (sizeof(struct file_descriptor*)));
-}
-
-//at shutdown, memory with the free list is freed
-void fs_table_shutdown() {
- bv_free(open_table_free_list);
- int i;
- for (i = 0; i < SYSTEM_SIZE; i++) {
- if (table[i] != NULL) { //deal with users that forget to close files
- if (table[i]->linked_file != NULL) { //"if" added because we never know what can happen...
- kfree(table[i]->linked_file);
- }
- kfree(table[i]);
- }
- }
- kfree(table);
-}
-
-
-//returns struct of descriptor at index fd
-//if invalid, returns NULL.
-struct file_descriptor* get_descriptor(int fd){
- if (file_is_open(fd)) {
- return table[fd];
- }
- return NULL;
-}
-
-// this function can be used to insert a file in the table
-// and returns the requested index if successful, else -1
-int add_to_opentable(struct inode * f, char perm) {
- int fd = (int) bv_firstFree(open_table_free_list); //gets free index from bitvector
- if (fd == -1) {
- return ERR_FULL; //reached max num of files open
- }
- bv_set((uint32_t)fd, open_table_free_list); //index is now taken
- struct file_descriptor* to_add = (struct file_descriptor*) kmalloc(sizeof(struct file_descriptor)); //malloc new struct
- int inum = f->inum;
- int i;
- for (i=0; ilinked_file->inum == inum) {
- to_add->linked_file->fd_refs++; //increment the number of references
- to_add->linked_file = table[i]->linked_file; //point to same file
- to_add->permission = perm; //assign new permission
- to_add->offset = 0; //restart offset from 0
- table[fd] = to_add; //add to table
- return fd;
- }
- }
- to_add->linked_file = f;
- to_add->linked_file->fd_refs = 1;
- to_add->permission = perm;
- to_add->offset = 0;
- table[fd] = to_add; //add to table
- if (perm == 'a') { //append, need to move offset to very end
- table[fd]->offset = table[fd]->linked_file->size;
- }
- return fd;
-}
-
-
-//this function can be used to delete a file from the list
-//returns 0 if all ok, -1 if wrong
-int delete_from_opentable(int fd) {
- if (!file_is_open(fd)) {
- return ERR_INVALID; //invalid entry
- }
- table[fd]->linked_file->fd_refs--;
- if (table[fd]->linked_file->fd_refs == 0) { //free inode only if was referenced only once
- kfree(table[fd]->linked_file);
- }
- kfree(table[fd]); //free space in table
- bv_lower ((uint32_t)fd, open_table_free_list); //index is not taken anymore
- return SUCCESS;
-}
-
-
-//this function checks whether the file is open or not
-int file_is_open(int fd) {
- if (fd<0 || fd>=SYSTEM_SIZE) {
- return FALSE;
- }
- if (table[fd] == NULL) {
- return FALSE;
- }
- return TRUE;
-}
-
-//this function checks whether the file is open or not
-int inode_is_open(struct inode* cur_inode) {
- int i;
- for(i = 0; i < SYSTEM_SIZE; i++){
- if(table[i] != NULL){
- if((table[i]->linked_file)->inum == cur_inode->inum){
- return TRUE; // file is open
- }
- }
- }
- return FALSE;
-}
-
diff --git a/kernel/fs_aaa.txt b/kernel/fs_aaa.txt
deleted file mode 100644
index 8d56e64e..00000000
--- a/kernel/fs_aaa.txt
+++ /dev/null
@@ -1,122 +0,0 @@
-make -C fs/cmdline
-make[1]: Entering directory `/v/filer4b/v20q001/joeliven/Documents/2015sp/CS439_OS/Projects/Project_3/course_os_2/course_os/kernel/fs/cmdline'
-gcc -g -c main.c
-gcc -g -c fakelibs.c
-gcc -g -c -I. ../fat16/file.c -o file.o
-gcc -g -c -I. ../open_table.c -o open_table.o
-gcc -g -c -I. ../../data_structures/bitvector.c -o bv.o
-gcc -g main.o fakelibs.o file.o open_table.o bv.o -o buildfs
-make[1]: Leaving directory `/v/filer4b/v20q001/joeliven/Documents/2015sp/CS439_OS/Projects/Project_3/course_os_2/course_os/kernel/fs/cmdline'
-make -C ../user/hello
-make[1]: Entering directory `/v/filer4b/v20q001/joeliven/Documents/2015sp/CS439_OS/Projects/Project_3/course_os_2/course_os/user/hello'
-make[1]: `hello' is up to date.
-make[1]: Leaving directory `/v/filer4b/v20q001/joeliven/Documents/2015sp/CS439_OS/Projects/Project_3/course_os_2/course_os/user/hello'
-dd if=/dev/zero of=card.sd conv=notrunc bs=512 count=250000
-fs/cmdline/buildfs ../user/hello/
-SD Card initiallized successfully!!!
-Finished initializing table...
-Read: 'Hello, world!+'
-Adding Makefile...
-Adding hello.c...
-Adding hello.o...
-Adding hello...
-0
-fd: 0
-qemu-system-arm -M versatilepb -sd card.sd -m 128M -nographic -kernel flash.bin -append "-load 0x410000 0x14000"
-
-
-U-Boot 2014.10 (May 03 2015 - 17:00:52)
-
-DRAM: 128 MiB
-WARNING: Caches not enabled
-Using default environment
-
-In: serial
-Out: serial
-Err: serial
-Net: SMC91111-0
-Warning: SMC91111-0 using MAC address from net device
-
-Warning: Your board does not use generic board. Please read
-doc/README.generic-board and take action. Boards not
-upgraded by the late 2014 may break or be removed.
-Hit any key to stop autoboot: 2 1 0
-## Executing script at 0024f000
-## Booting kernel from Legacy Image at 00210000 ...
- Image Name:
- Image Type: ARM Linux Kernel Image (uncompressed)
- Data Size: 67476 Bytes = 65.9 KiB
- Load Address: 00010000
- Entry Point: 00010000
- Loading Kernel Image ... OK
-
-Starting kernel ...
-
-Enabling MMU...
-5
-Initialized VM datastructures.
-100
-first_level_pt=204000
-0x300402
-control reg: 0x2089107f
-Got here
-MMU enabled
-
-CourseOS!
-Bootargs: 5
-test_vm_1 ... asdf
-vm_l1pt_free_list=F0210000
-Got new vas at 0xF020000C
-Stack addr: 0xFFF00000
-Created page table w/ 0xFFF00000's entry = 0x7F00402
-Hey, I'm printing!
-F0200000 (FFFFBFA0)
-F0204000
-F0204000
-Entry: 200402
-402
-(deref: entry at 0x200000: 0x0)
-vm_l1pt_free_list=F0214000
-F020000C and F0200000 and F0200018
-ffffbf9c 24000000
-Testing shared memory...
-301012
-map_shared_memory returned 0
-You should see a data abort...
-DATA ABORT HANDLER
-HANDLER: pc=12b60, lr=12b58, sp=ffffafc0, fp=ffffaffc
-DSFR: 0x5
-603979776
-Freeing page at 24000000
-F0301000 F0302000
-PASSES
-There are 31742 free frames.
-There are 31742 free frames.
-test_prq_1 ... PASSES
-test_prq_2 ... PASSES
-test_prq_3 ... PASSES
-test_prq_4 ... PASSES
-test_prq_5 ... PASSES
-test_prq_6 ... PASSES
-
-SD card ready for transfer
-SD Card initiallized successfully!!!
-Finished initializing table...
-test_fs_1 ... file descriptor is: 1
-
-Opening file...
-file descriptor is: 0
-
-Writing string to file...
-
-Opening previous file...
-0
-
-Reading from file...
-Read 39 bytes from file.
-the buffer is: 'Hello, world I'm testing right now...!
-'
-PASSES
-done parsing atag list
-QEMU: Terminated
-
\ No newline at end of file
diff --git a/kernel/hw_handlers.c b/kernel/hw_handlers.c
deleted file mode 100644
index 20afe775..00000000
--- a/kernel/hw_handlers.c
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- *
- * Harware Handler Interface
- *
- */
-#include "hw_handlers.h"
-#include "mmap.h"
-#include "memory.h"
-#include "interrupt.h"
-#include "klibc.h"
-#include "vm.h"
-#include "fs/file.h"
-#include "process.h"
-
-/* copy vector table from wherever QEMU loads the kernel to 0x00 */
-void init_vector_table(void)
-{
- /* This doesn't seem to work well with virtual memory; reverting
- * to old method.
- extern uint32_t vector_table_start, vector_table_end;
- uint32_t *src = &vector_table_start;
- uint32_t *dst = (uint32_t *) HIVECTABLE;
-
- while(src < &vector_table_end)
- *dst++ = *src++;
- */
-
- /* Primary Vector Table */
- mmio_write(0x00, BRANCH_INSTRUCTION);
- mmio_write(0x04, BRANCH_INSTRUCTION);
- mmio_write(0x08, BRANCH_INSTRUCTION);
- mmio_write(0x0C, BRANCH_INSTRUCTION);
- mmio_write(0x10, BRANCH_INSTRUCTION);
- mmio_write(0x14, BRANCH_INSTRUCTION);
- mmio_write(0x18, BRANCH_INSTRUCTION);
- mmio_write(0x1C, BRANCH_INSTRUCTION);
-
- /* Secondary Vector Table */
- mmio_write(0x20, &reset_handler);
- mmio_write(0x24, &undef_instruction_handler);
- mmio_write(0x28, &software_interrupt_handler);
- mmio_write(0x2C, &prefetch_abort_handler);
- mmio_write(0x30, &data_abort_handler);
- mmio_write(0x34, &reserved_handler);
- mmio_write(0x38, &irq_handler);
- mmio_write(0x3C, &fiq_handler);
-
-}
-
-/* handlers */
-void reset_handler(void)
-{
- os_printf("RESET HANDLER\n");
- _Reset();
-}
-
-void __attribute__((interrupt("UNDEF"))) undef_instruction_handler(void)
-{
- int spsr, lr;
-
- asm volatile("mrs %0, spsr" : "=r"(spsr));
- asm volatile("mov %0, lr" : "=r" (lr));
-
- os_printf("UNDEFINED INSTRUCTION HANDLER\n");
-
- int thumb = spsr & 0x20;
- int pc = thumb ? lr - 0x2 : lr - 0x4;
-
- int copro = (*(int*)pc & 0xf00000) >> 24;
-
- if (spsr & 0x20) {
- os_printf("THUMB mode\n");
- } else {
- os_printf("ARM mode\n");
- }
- if (spsr & 0x1000000) {
- os_printf("JAZELLE enabled\n");
- }
-
- os_printf("COPRO: %x\n", copro);
- os_printf("violating instruction (at %x): %x\n", pc, *((int*) pc));
- if (pc >= V_KERNBASE && pc < V_KERNTOP)
- {
- os_printf("(instruction is in kernel address range)\n");
- }
-
- panic();
-}
-
-long __attribute__((interrupt("SWI"))) software_interrupt_handler(void)
-{
- int callNumber = 0, r0 = 0, r1 = 0, r2 = 0, r3 = 0;
-
- asm volatile ("MOV %0, r7":"=r"(callNumber)::);
- asm volatile ("MOV %0, r0":"=r"(r0)::);
- asm volatile ("MOV %0, r1":"=r"(r1)::);
- asm volatile ("MOV %0, r2":"=r"(r2)::);
- asm volatile ("MOV %0, r3":"=r"(r3)::);
-
- os_printf("SOFTWARE INTERRUPT HANDLER\n");
-
- // Print out syscall # for debug purposes
- os_printf("Syscall #: ");
- os_printf("%d\n", callNumber);
- os_printf("arg0=%d\n", r0);
- os_printf("arg1=%d\n", r1);
- os_printf("arg2=%d\n", r2);
- os_printf("arg3=%d\n", r3);
- os_printf("\n");
-
- // System Call Handler
- switch (callNumber)
- {
- case SYSCALL_EXIT:
- // TODO: remove current process from scheduler
- for (;;);
- break;
- case SYSCALL_DUMMY:
- return 0L;
-
- break;
- case SYSCALL_CREATE:
- os_printf("Create system call called!\n");
-
- return (long) kcreate((char*) r0, r1, 0);
- case SYSCALL_DELETE:
- os_printf("Delete system call called!\n");
-
- return (long) kdelete((char*) r0, 1);
- case SYSCALL_OPEN:
- os_printf("Open system call called!\n");
-
- return (long) kopen((char*) r0, r1);
- case SYSCALL_MKDIR:
- os_printf("Mkdir system call called!\n");
-
- return (long) kcreate((char*) r0, 'w', 1);
- case SYSCALL_READ:
- os_printf("Read system call called!\n");
-
- return (long) kread(r0, (void*) r1, r2);
- case SYSCALL_WRITE:
- os_printf("Write system call called!\n");
-
- return (long) kwrite(r0, (void*) r1, r2);
- case SYSCALL_CLOSE:
- os_printf("Close system call called!\n");
-
- return (long) kclose(r0);
- case SYSCALL_SEEK:
- os_printf("Seek system call called!\n");
-
- return (long) kseek(r0, r1);
- case SYSCALL_COPY:
- os_printf("Copy system call called!\n");
-
- return (long) kcopy((char*) r0, (char*) r1, r2);
- case SYSCALL_LS:
- os_printf("Ls system call called!\n");
-
- return (long) kls((char*) r0);
- case SYSCALL_SET_PERM:
- os_printf("Set permission system call called!\n");
- os_printf("Yet to be implemented\n");
- return -1;
- case SYSCALL_MEM_MAP:
- os_printf("Memory map system call called!\n");
- os_printf("Yet to be implemented\n");
- return -1;
-
- case SYSCALL_MALLOC:
- os_printf("malloc system call called!\n");
-
- void *ptr = umalloc(r0);
-
- os_printf("malloc is about to return %x\n", ptr);
-
- return (long) ptr;
- case SYSCALL_ALIGNED_ALLOC:
- os_printf("aligned_alloc system call called!\n");
- void *ptr2 = ualigned_alloc(r0, r1);
-
- os_printf("ualigned_alloc is about to return %x\n", ptr2);
-
- return (long) ptr2;
- case SYSCALL_FREE:
- os_printf("Free system call called!\n");
-
- ufree((void*) r0);
- return 0L;
- case SYSCALL_PRINTF:
- os_printf("Printf system call called!\n");
-
- os_printf((const char*) r0);
- return 0L;
- default:
- os_printf("That wasn't a syscall you knob!\n");
- return -1L;
- }
-}
-
-void __attribute__((interrupt("ABORT"))) prefetch_abort_handler(void)
-{
- int lr;
-
- asm volatile("mov %0, lr" : "=r" (lr));
-
- os_printf("PREFETCH ABORT HANDLER, violating address: %x\n", (lr - 4));
-
- panic();
-}
-
-void __attribute__((interrupt("ABORT"))) data_abort_handler(void)
-{
- int lr;
- asm volatile("mov %0, lr" : "=r" (lr));
- int pc = lr - 8;
-
- int far;
- asm volatile("mrc p15, 0, %0, c6, c0, 0" : "=r" (far));
-
- os_printf("DATA ABORT HANDLER (Page Fault)\n");
- os_printf("faulting address: 0x%x\n", far);
- if (far >= V_KDSBASE)
- {
- os_printf("(address is in kernel address range)\n");
- }
- os_printf("violating instruction (at 0x%x): %x\n", pc, *((int*) pc));
-
- // Get the DSFR
- int dsfr;
- asm volatile("MRC p15, 0, %0, c5, c0, 0" : "=r" (dsfr));
- //os_printf("DSFR: 0x%X\n", dsfr);
-
- switch (dsfr)
- {
- case 6: // Access bit.
- // Set it to 1 so we don't get notified again.
- // TODO: The eviction policy will listen to this.
- *((unsigned int*) (V_L1PTBASE + 2 * PAGE_TABLE_SIZE)) |= (1 << 4);
- break;
- default:
- break;
- };
-}
-
-void reserved_handler(void)
-{
- os_printf("RESERVED HANDLER\n");
-}
-
-// the attribute automatically saves and restores state
-void __attribute__((interrupt("IRQ"))) irq_handler(void)
-{
-
- os_printf("IRQ HANDLER\n");
- int cpsr = disable_interrupt_save(IRQ);
-// os_printf("disabled CSPR:%X\n",cpsr);
- // Discover source of interrupt
- int i = 0;
- // do a straight run through the VIC_INT_STATUS to determine
- // which interrupt lines need to be tended to
- for (i = 0; i < MAX_NUM_INTERRUPTS; i++)
- {
- // is the line active?
- if ((1 << i) & mmio_read(VIC_IRQ_STATUS))
- {
- // activate that specific handler
- handle_irq_interrupt(i);
- }
- }
- // we've gone through the VIC and handled all active interrupts
- restore_proc_status(cpsr);
-
- enable_interrupt(IRQ_MASK);
-
-}
-
-void __attribute__((interrupt("FIQ"))) fiq_handler(void)
-{
- os_printf("FIQ HANDLER\n");
-
- int cpsr = disable_interrupt_save(FIQ);
-
- int i = 0;
- // do a straight run through the VIC_INT_STATUS to determine
- // which interrupt lines need to be tended to
- for (i = 0; i < MAX_NUM_INTERRUPTS; i++)
- {
- // is the line active?
- if ((1 << i) & mmio_read(VIC_FIQ_STATUS))
- {
- // activate that specific handler
- handle_irq_interrupt(i);
- }
- }
-
-// FIQ handler returns from the interrupt by executing:
-// SUBS PC, R14_fiq, #4
-
- restore_proc_status(cpsr);
-}
diff --git a/kernel/include/.DS_Store b/kernel/include/.DS_Store
deleted file mode 100644
index b0f47a7f..00000000
Binary files a/kernel/include/.DS_Store and /dev/null differ
diff --git a/kernel/include/allocator.h b/kernel/include/allocator.h
deleted file mode 100644
index 27059e6d..00000000
--- a/kernel/include/allocator.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- Log
- 4/2: Adjusted bump allocation algorithm: Sean V, Faseeh A, John G, Taylor S
- 4/7: Fixed mem_alloc again works properly: Sean V, Faseeh A, Taylor S.
-
- */
-#ifndef __ALLOCATOR_H__
-#define __ALLOCATOR_H__
-
-#include
-#include
-
-#define MEM_START 0x500000
-
-typedef uint32_t (*heap_extend_handler)(uint32_t amount);
-
-typedef struct alloc_handle {
- uint32_t *heap;
- uint32_t heap_size;
- heap_extend_handler extend_handler;
-} alloc_handle;
-
-alloc_handle* alloc_create(uint32_t * heap, uint32_t size,
- heap_extend_handler extend_handler);
-alloc_handle* alloc_create_fixed(uint32_t * buffer, uint32_t buffer_size);
-void* alloc_allocate(alloc_handle * allocator, uint32_t size);
-void alloc_deallocate(alloc_handle* allocator, void* ptr);
-uint32_t* alloc_get_heap(alloc_handle* allocator);
-uint32_t alloc_get_heap_size(alloc_handle* allocator);
-int alloc_check(alloc_handle* allocator);
-
-#endif
diff --git a/kernel/include/argparse.h b/kernel/include/argparse.h
deleted file mode 100644
index 7225ebae..00000000
--- a/kernel/include/argparse.h
+++ /dev/null
@@ -1,66 +0,0 @@
-#ifndef __ARGPARSE_H__
-#define __ARGPARSE_H__
-
-
-
-#define ATAG_NONE 0x00000000
-#define ATAG_CORE 0x54410001
-
-struct atag_core {
- uint32_t flags;
- uint32_t pagesize;
- uint32_t rootdev;
-};
-
-#define ATAG_MEM 0x54410002
-
-struct atag_mem {
- uint32_t size;
- uint32_t start;
-};
-
-#define ATAG_VIDEOTEXT 0x54410003
-#define ATAG_RAMDISK 0x54410004
-#define ATAG_INITRD2 0x54420005
-#define ATAG_SERIAL 0x54410006
-#define ATAG_REVISION 0x54410007
-#define ATAG_VIDEOLFB 0x54410008
-#define ATAG_CMDLINE 0x54410009
-
-struct atag_cmdline {
- char cmdline[1];
-};
-
-struct atag_header {
- uint32_t size;
- uint32_t tag;
-};
-
-struct atag {
- struct atag_header header;
- union {
- struct atag_core core;
- struct atag_mem mem;
- struct atag_cmdline cmdline;
- } content;
-};
-
-static inline struct atag *atag_next_header(struct atag *t)
-{
- return (struct atag*) ((uint32_t*)(t) + t->header.size);
-}
-
-#define atag_iterator(tag, addr) struct atag* tag = (struct atag*) addr; tag->header.tag != ATAG_NONE; tag = atag_next_header(tag)
-
-void atag_print(struct atag *t);
-
-void argparse_process(uint32_t *p_bootargs);
-void parse_arguments(int argc, char **argv);
-int analyze_arguments(char **argv);
-char* read_cmdline_tag(uint32_t *tag_base);
-char** split_string(char *line, char **list);
-int number_of_words(char *line);
-int string_to_unsigned_int(char *input, int base);
-int hex_value_of_character(char c);
-
-#endif
diff --git a/kernel/include/bits/stdint.h b/kernel/include/bits/stdint.h
deleted file mode 100644
index d1b27121..00000000
--- a/kernel/include/bits/stdint.h
+++ /dev/null
@@ -1,20 +0,0 @@
-typedef int32_t int_fast16_t;
-typedef int32_t int_fast32_t;
-typedef uint32_t uint_fast16_t;
-typedef uint32_t uint_fast32_t;
-
-#define INT_FAST16_MIN INT32_MIN
-#define INT_FAST32_MIN INT32_MIN
-
-#define INT_FAST16_MAX INT32_MAX
-#define INT_FAST32_MAX INT32_MAX
-
-#define UINT_FAST16_MAX UINT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-
-#define INTPTR_MIN INT32_MIN
-#define INTPTR_MAX INT32_MAX
-#define UINTPTR_MAX UINT32_MAX
-#define PTRDIFF_MIN INT32_MIN
-#define PTRDIFF_MAX INT32_MAX
-#define SIZE_MAX UINT32_MAX
diff --git a/kernel/include/data_structures/array_list.h b/kernel/include/data_structures/array_list.h
deleted file mode 100644
index dc655603..00000000
--- a/kernel/include/data_structures/array_list.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * array_list.h
- *
- * Created on: Apr 21, 2015
- * Author: namaz89
- */
-
-#ifndef KERNEL_INCLUDE_ARRAY_LIST_H_
-#define KERNEL_INCLUDE_ARRAY_LIST_H_
-
-#include "data_structures/linked_list.h"
-#include "klibc.h"
-
-#define DEFAULT_BUCKET_SIZE 20
-
-typedef struct arrl_handle arrl_handle;
-
-struct arrl_handle {
- llist_handle * linked_list;
- int bucket_size;
- int size;
- int capacity;
-};
-
-arrl_handle* arrl_create();
-arrl_handle* arrl_create_fixed(uint32_t bucket_size);
-void arrl_append(arrl_handle* arrl, void* elem);
-void arrl_remove(arrl_handle* arrl, void* elem);
-void arrl_remove_all(arrl_handle* arrl, void* elem);
-uint32_t arrl_contains(arrl_handle* arrl, void* elem);
-uint32_t arrl_index_of(arrl_handle* arrl, void* elem);
-uint32_t arrl_count(arrl_handle* arrl);
-
-#endif /* KERNEL_INCLUDE_ARRAY_LIST_H_ */
diff --git a/kernel/include/data_structures/bin_tree.h b/kernel/include/data_structures/bin_tree.h
deleted file mode 100644
index 7827df5c..00000000
--- a/kernel/include/data_structures/bin_tree.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/********************************************************************
- * bin_tree.h
- *
- * Author: Brandon Olivier // any collaborators, please add name
- *
- * Date: 19 April 2014
- *
- * Purpose: Provide basis for b-trees for addresses
- *
- ********************************************************************/
-
-#ifndef __b_tree_
-#define __b_tree_
-
-typedef struct tree tree;
-typedef struct node node;
-
-struct tree
-{
- node *root;
- int size;
- int depth;
-};
-
-struct node
-{
- node *left;
- node *right;
- void *address;
-};
-
-tree* init_tree();
-void llist_insert(tree* t, void *d);
-void delete(tree *t, node *n);
-
-#endif
diff --git a/kernel/include/data_structures/bitvector.h b/kernel/include/data_structures/bitvector.h
deleted file mode 100644
index 20f2d330..00000000
--- a/kernel/include/data_structures/bitvector.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#ifndef BITVECTOR_H_
-#define BITVECTOR_H_
-
-#include
-
-typedef struct bit_vector {
- uint32_t length;
- uint32_t *vector;
- uint32_t actualLength;
-} bit_vector;
-
-/* creates butvector of "size" number of bits */
-bit_vector *make_vector(uint32_t size);
-
-/* gets the value of bit number "index" */
-int32_t bv_get(uint32_t index, bit_vector* bit_vec);
-
-/* flips the bit number "index" */
-int32_t bv_toggle(uint32_t index, bit_vector* bit_vec);
-
-/* sets the value of bit number "index" to 1 (meaning taken) */
-int32_t bv_set(uint32_t index, bit_vector* bit_vec);
-
-/* sets the value of bit number "index" to 0 (meaning free) */
-int32_t bv_lower(uint32_t index, bit_vector* bit_vec);
-
-/* returns the first free index (first 0 in the vector) */
-int32_t bv_firstFree(bit_vector* bit_vec);
-
-/* frees the memory used by the vector */
-int32_t bv_free(bit_vector* bit_vec);
-
-/* returns whether the given index is free - Noel*/
-int32_t bv_isfree(uint32_t index, bit_vector* bit_vec);
-
-/* transfer a bit_vector to disk */
-int32_t bv_serialize(bit_vector* bit_vec, uint32_t start_block, uint32_t end_block);
-
-/* transfer a bit_vector from disk */
-int32_t bv_unserialize(bit_vector* bit_vec, uint32_t start_block, uint32_t end_block);
-
-#endif
diff --git a/kernel/include/data_structures/hash_map.h b/kernel/include/data_structures/hash_map.h
deleted file mode 100644
index f55b8a0b..00000000
--- a/kernel/include/data_structures/hash_map.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * hash_map.h
- *
- * Created on: Apr 18, 2015
- * Author: mwkurian
- */
-
-#ifndef KERNEL_INCLUDE_HASH_MAP_H_
-#define KERNEL_INCLUDE_HASH_MAP_H_
-
-typedef struct {
- void* data;
- int flags;
- long key;
-} hmap_entry;
-
-typedef struct hmap_handle {
- hmap_entry* table;
- long size, count;
-} hmap_handle;
-
-hmap_handle* hmap_create();
-hmap_handle* hmap_create_fixed(int startsize);
-void* hmap_get(hmap_handle* hmap, unsigned long key);
-void hmap_put(hmap_handle* hmap, unsigned long key, const void* data);
-void* hmap_remove(hmap_handle* hmap, unsigned long key);
-long hmap_count(hmap_handle* hash);
-void hmap_free(hmap_handle* hash);
-
-#endif /* KERNEL_INCLUDE_HASH_MAP_H_ */
diff --git a/kernel/include/data_structures/linked_list.h b/kernel/include/data_structures/linked_list.h
deleted file mode 100644
index 913cc18a..00000000
--- a/kernel/include/data_structures/linked_list.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/********************************************************************
- * linked_list.h
- *
- * Author: Brandon Olivier // any collaborators, please add name
- *
- * Date: 14 April 2014
- *
- * Purpose: Provide linked lists for CourseOS
- * This header provides function skeletons
- * for linked_list.c
- *
- ********************************************************************/
-
-#ifndef __llist_h
-#define __llist_h
-
-typedef struct llist_node llist_node;
-
-struct llist_node {
- llist_node *next;
- void *data;
-};
-
-typedef struct {
- llist_node *head;
- llist_node *tail;
- int count;
-} llist_handle;
-
-/* prepend (because of speed) to the list. */
-llist_handle* llist_create(void *data);
-llist_node* create_node(void *data);
-void llist_free(llist_handle *l);
-void llist_free_node(llist_node *node);
-void llist_insert(llist_handle *l, void *data, int index);
-void llist_enqueue(llist_handle *l, void *data);
-void* llist_dequeue(llist_handle *l);
-void llist_remove_at(llist_handle *l, int index);
-void* llist_get_by_index(llist_handle *l, int index);
-llist_node* llist_get_node(llist_handle *l, int index);
-void llist_set_data(llist_node *l, void *data);
-int llist_count(llist_handle *l);
-
-#endif
diff --git a/kernel/include/data_structures/ring_buffer.h b/kernel/include/data_structures/ring_buffer.h
deleted file mode 100644
index 7687d580..00000000
--- a/kernel/include/data_structures/ring_buffer.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/********************************************************************
- * ring_buffer.h
- *
- * Author: Brandon Olivier // any collaborators, please add name
- *
- * Date: 14 April 2014
- *
- * Purpose: Provide ring buffer for CourseOS
- * Data gets PUT in at the head index
- * and it is GET at the tail index
- *
- ********************************************************************/
-#include "mem_alloc.h"
-
-typedef struct rb_node rb_node;
-typedef struct ring_buffer ring_buffer;
-
-struct rb_node
-{
- rb_node *next;
- rb_node *prev;
- void *data;
-};
-
-struct ring_buffer
-{
- rb_node *head;
- rb_node *tail;
- int size;
- int size_limit;
-};
-ring_buffer* create(int size);
-void free_ring_buffer(ring_buffer *r);
-
-int put(ring_buffer *r, void *data);
-rb_node* get(ring_buffer *r);
-void clear(ring_buffer *r);
-ring_buffer* increase_size(ring_buffer *r, int by); // as in increase by x
diff --git a/kernel/include/drivers/clock.h b/kernel/include/drivers/clock.h
deleted file mode 100644
index 817bbc98..00000000
--- a/kernel/include/drivers/clock.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef CLOCK_H
-#define CLOCK_H
-
-#include
-#include "../../include/mmap.h"
-
-#endif
diff --git a/kernel/include/drivers/timer.h b/kernel/include/drivers/timer.h
deleted file mode 100644
index 60fac356..00000000
--- a/kernel/include/drivers/timer.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef TIMER_H
-#define TIMER_H
-
-#include
-
-typedef struct {
- uint32_t timer_load_value; // read/write
- uint32_t timer_actual_value; // read only
- uint32_t control; // read/write
- uint32_t interrupt_clear; // write only
- uint32_t interrupt_status; // read only
- uint32_t masked_interrupt_status; // read only
- uint32_t background_timer_load_value; // read/write
-} rasp_pi_timer;
-
-_Static_assert (sizeof (rasp_pi_timer) == 28, "rasp_pi_timer check");
-
-void initialize_timers();
-int set_load_value(int timer_index, int value);
-int set_background_load_value(int timer_index, int value);
-int clear_interupt(int timer_index);
-int set_32_bit_mode(int timer_index);
-int get_current_timer_value(int timer_index);
-int set_periodic_mode(int timer_index);
-int set_free_running_mode(int timer_index);
-int start_timer(int timer_index);
-int set_prescale(int timer_index, int mode);
-int start_timer_interrupts( int timer_index, int star_val);
-int conversion(int timer_index, int milliseconds);
-int enable_timer_interrupt(int timer_index);
-int disable_timer(int timer_index);
-int register_handler(int timer_index, void (*handler)(void *args));
-int unregister_handler(int timer_index);
-
-
-#endif
diff --git a/kernel/include/drivers/uart.h b/kernel/include/drivers/uart.h
deleted file mode 100644
index 2de2a439..00000000
--- a/kernel/include/drivers/uart.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef UART_H
-#define UART_H
-
-void print_uart0(const char *);
-
-#endif // ifndef UART_H
diff --git a/kernel/include/elf.h b/kernel/include/elf.h
deleted file mode 100644
index 710047b2..00000000
--- a/kernel/include/elf.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/* Any confusion with what does what can be gotten from the
- following website. It defines all the values
- http://man7.org/linux/man-pages/man5/elf.5.html
-*/
-
-#ifndef _ELF_H_
-#define _ELF_H_
-
-#include
-#include "klibc.h"
-
-typedef uint32_t Elf_Addr; // Program Address
-typedef uint16_t Elf_Half; // 16 bit
-typedef uint32_t Elf_Off; // File Offset
-typedef int32_t Elf_Sword; // Signed 32 bit int
-typedef uint32_t Elf_Word; // Unsigned 32 bit int
-#define EI_NIDENT 16
-
-/* Elf Header */
-/* Note: The ELF Header should begin the following header
- EI_MAG0 = 0x7f
- EI_MAG1 = 'E'
- EI_MAG2 = 'L'
- EI_MAG3 = 'F'
-*/
-
-/* Magic Numbers and preliminary info about file */
-#define EI_MAG0 0 // 0x7f
-#define EI_MAG1 1 // 'E'
-#define EI_MAG2 2 // 'L'
-#define EI_MAG3 3 // 'F'
-#define EI_CLASS 4
-#define EI_DATA 5
-#define EI_VERSION 6
-#define EI_OSABI 7 // Targeted operating system
-#define EI_ABIVERSION 8
-
-/* ELF Header Flags */
-#define EF_ARM_ABIMASK 0xFF000000
-#define EF_ARM_BE8 0x00800000
-#define EF_ARM_GCCMASK 0x00400FFF
-#define EF_ARM_ABI_FLOAT_HARD 0x00000400
-#define EF_ARM_ABI_FLOAT_SOFT 0x00000200
-
-/* Defines what type of file it is */
-#define no_file_type 0
-#define relocatable 1
-#define executable 2
-#define shared_obj 3
-#define core 4
-
-/* Types of Program Headers */
-#define PT_NULL 0 // Indicates an unused program header
-#define PT_LOAD 1 // Indicates that this program header describes a segment to be loaded from the file.
-#define PT_DYNAMIC 2 // Indicates a segment where dynamic linking information can be found.
-#define PT_INTERP 3 // Indicates a segment where the name of the program interpreter may be found.
-#define PT_NOTE 4 // Indicates a segment holding note information.
-#define PT_SHLIB 5 // A reserved program header type, defined but not specified by the ELF ABI.
-#define PT_PHDR 6 // Indicates a segment where the program headers may be found.
-
-/* Program Flags */
-// 0: No access
-// 1: Just execute
-// 2: Write only
-// 3: Write, execute only
-// 4: Read only
-// 5: Read, execute only
-// 6: Read, write only
-// 7: Read, Write, and Execute
-
-typedef enum {TEXT, RODATA, DATA, SYMTAB, STRTAB, SHSTRTAB, BSS, COMMENT} Section;
-
-typedef struct {
- unsigned char e_ident[EI_NIDENT]; // How to interpret file
- Elf_Half e_type;
- Elf_Half e_machine;
- Elf_Word e_version;
- Elf_Addr e_entry;
- Elf_Off e_phoff;
- Elf_Off e_shoff;
- Elf_Word e_flags;
- Elf_Half e_ehsize;
- Elf_Half e_phentsize;
- Elf_Half e_phnum;
- Elf_Half e_shentsize;
- Elf_Half e_shnum;
- Elf_Half e_shstrndx;
-}Elf_Ehdr;
-
-/* Program header */
-typedef struct {
- Elf_Word p_type;
- Elf_Off p_offset;
- Elf_Addr p_vaddr;
- Elf_Addr p_paddr;
- Elf_Word p_filesz;
- Elf_Word p_memsz;
- Elf_Word p_flags;
- Elf_Word p_align;
-}Elf_Phdr;
-
-/* Section header */
-typedef struct {
- Elf_Word sh_name;
- Elf_Word sh_type;
- Elf_Word sh_flags;
- Elf_Addr sh_addr;
- Elf_Off sh_offset;
- Section sh_numname;
- Elf_Word sh_size;
- Elf_Word sh_link;
- Elf_Word sh_info;
- Elf_Word sh_addralign;
- Elf_Word sh_entsize;
-}Elf_Shdr;
-
-/* Symbol Table */
-typedef struct {
- Elf_Word st_name;
- Elf_Addr st_value;
- Elf_Word st_size;
- unsigned char st_info;
- unsigned char st_other;
- Elf_Half st_shndx;
-}Elf_Sym;
-
-/* Relocation without addend */
-typedef struct {
- Elf_Addr r_offset;
- Elf_Word r_info;
-}Elf_Rel;
-
-/* Relocation with addend */
-typedef struct {
- Elf_Addr r_offset;
- Elf_Word r_info;
- Elf_Sword r_addend;
-}Elf_Rela;
-
-/* Dynmaic Section header */
-typedef struct {
- Elf_Sword d_tag;
- union {
- Elf_Word d_val;
- Elf_Addr d_ptr;
- }d_un;
-} Elf_Dyn;
-
-int read_elf_header(Elf_Ehdr *h, unsigned char *pointer);
-void read_program_header_table(Elf_Ehdr *eh, Elf_Phdr ph[], unsigned char *pointer);
-void read_section_header_table(Elf_Ehdr *eh, Elf_Shdr sh[], uint32_t *pointer);
-void parse_section_header_names(Elf_Ehdr *eh, Elf_Shdr sh[], uint32_t *pointer);
-#endif
diff --git a/kernel/include/fs/file.h b/kernel/include/fs/file.h
deleted file mode 100644
index 078f3ebc..00000000
--- a/kernel/include/fs/file.h
+++ /dev/null
@@ -1,177 +0,0 @@
-#ifndef __FILE_H__
-#define __FILE_H__
-
-#include "global_defs.h"
-#include "data_structures/bitvector.h"
-#include "data_structures/linked_list.h"
-#include
-
-#define BLOCKSIZE 512
-#define MAX_NAME_LENGTH 32
-#define MAX_DATABLOCKS_PER_INODE 100
-#define DIR_ENTRY_SIZE 40
-#define MAX_NUM_INDIRECT_BLOCKS 20
-#define MAX_DATABLOCKS_PER_INDIRECT_BLOCK ((BLOCKSIZE/4)-2)
-#define MAX_DIR_ENTRIES_PER_DATA_BLOCK ((int)((BLOCKSIZE-4)/DIR_ENTRY_SIZE)-2)
-
-
-//error codes used in return:
-#define ERR_GEN -1 //general error
-#define ERR_FULL -2 //error signaling end of resources
-#define ERR_INVALID -3 //invalid parameter
-#define ERR_404 -4 //file not found
-#define ERR_SD -5 //sd card error
-#define ERR_PERM -6 //permission error
-#define SUCCESS 0 //no error
-
-
-//IMPORTANT!! ---------------------------------------------------------------------------------------------------
-//all constants are in units of block NUMBER |
-//the indexes of arrays are also in units of block NUMBER relative to the starting offset of their cathegory. |
-//---------------------------------------------------------------------------------------------------------------
-
-//constants of file system, that wil be filled at boot time
-struct superblock
-{
- // char* fs_name; // 32 bytes (max length for this field abides by MAX_NAME_LENGTH)
- int fs_version; // 36 bytes
- int magic_num; // 40 bytes
- int sd_card_capacity; // 44 bytes
- int block_size; // 48 bytes
- int root_inum; // 52 bytes
- int max_inodes; // 56 bytes
- int inode_size;
- int max_data_blocks; // 66 bytes
- int inode_bitmap_loc; // 70 bytes
- int data_bitmap_loc; // 74 bytes
- // int indirect_blocks_bitmap_loc; //
- int start_inode_table_loc; // 78 bytes
- int start_data_blocks_loc; // 82 bytes, start_inode_table_loc + 200 b/c 200 inode bl
- // int start_indirect_block_table_loc; //
- // int max_indirect_blocks;
- // char spaceholder[???]; Might need this to make the cast from memory to superblock work...not sure??? Don't think we need this, but not sure
- // the rest of the superblock will be empty for now (BLOCKSIZE - 82 = 512 - 82 = 430 free/wasted bytes)
-};
-
-//metadata of each file or directory
-struct inode {
- int inum; //inum of the file (4bytes)
- int fd_refs; //how many times the file is referenced (=appears in the opentable) (4bytes)
- int size; // size of the whole file (4 bytes)
- int is_dir; // 1 if this is a directory, 0 if this is a file (4 bytes)
- int usr_id; // id of the user who created the file (4 bytes) ...not yet used!
- int direct_blocks_in_file; // how many direct block are being used (4 bytes)
- int data_blocks[MAX_DATABLOCKS_PER_INODE]; // array of data (now long 70)
- int indirect_blocks_in_file; // how many indirect block are being used (4 bytes)
- int indirect_blocks[MAX_NUM_INDIRECT_BLOCKS]; // 50*4 = 200 bytes ....50 indirect blocks right now
- bit_vector* perms; // permissions of the file (4 bytes)
-};
-
-struct indirect_block // total size is 1 block
-{
- int block_num;
- int blocks_in_file; //blocks actually used
- int data_blocks[MAX_DATABLOCKS_PER_INDIRECT_BLOCK]; // because this is just an array of ints, so it's BLOCKSIZE/4 bytes bc each int is 4 bytes
-};
-
-struct dir_entry
-{
- int inum;
- int name_length; //including null terminating string
- char name[MAX_NAME_LENGTH]; // 32 chars right now
-}; // 8 _ MAX_NAME_LENGTH bytes long...40 bytes right now
-
-struct dir_data_block
-{
- int block_num;
- int num_entries;
- struct dir_entry dir_entries[MAX_DIR_ENTRIES_PER_DATA_BLOCK];
-};
-
-struct data_block
-{
- char data[BLOCKSIZE];
-};
-
-struct dir_helper //used by helper functions in file.c
-{
- int dir_levels;
- char* truncated_path;
- char* last;
-};
-
-struct stats //statistics about the file
-{
- int size; //size of the file
- int fd_refs; //how many times it is open now
- int is_dir; //is this a directory
-};
-
-int kopen(const char* filepath, const char mode); //opens the file of filepath with permissions mode
-int kread(int fd, void* buf, int numBytes); //reads the open file corresponding to fd
-int kwrite(int fd, void* buf, int num_bytes); //writes the open file corresponding to fd
-int kclose(int fd); //closes the cpen file corresponding to fd
-int kseek(int fd, int num_bytes); //moves the offset of the open file fd
-int kdelete(const char* filepath, int recursive); //deletes the file or directory following filepath
-int kcreate(const char* filepath, const char mode, int is_this_a_dir); //creates and opens a file or directory with permissions mode in fielpath
-int kcopy(const char* source, const char* dest, const char mode); //copies the contents of a file
-int kls(const char* filepath); //shows contents of one directory
-int kfs_init(int inode_table_cache_size, int data_block_table_cache_size, int reformat); // initialize the filesystem:
-int kfs_shutdown();
-
-// // -------------------------------------------------------------------------------------------------------------------------------------------------------
-// /* HELPER FUNCTIONS */
-int get_stats(const char * filepath, struct stats * result);
-
-int kdelete_single_helper(struct inode * cur_inode);
-
-//delete the file or directory at filepath. Return -1 if the file does not exist
-int kdelete_single(struct inode* cur_inode, struct inode* level_up_inode);
-
-/* deletes a single dir_entry */
-int kremove_dir_entry (struct inode* cur_inode, int tgt_inum);
-
-//from the index, gets the corresponding indirect block, either from cache or from disk
-void get_indirect_block(struct inode* cur_inode, int index, struct indirect_block* cur_indirect_block);
-
-//from the inum, gets corresponding inode, either from cache or disk
-void get_inode(int inum, struct inode* result_inode);
-
-//gets the inum of nextpath (file or dir) looking at the direct data blocks of cur_inode
-int get_inum_from_direct_data_block(struct inode* cur_inode, const char * next_path);
-
-//gets the inum of netxpath (file or dir) looking at the indirect data blocks of cur_inode
-int get_inum_from_indirect_data_block(struct inode * cur_inode, const char * next_path);
-
-//finds the inode (will be result_inode) following filepath, going dir_levels down the path, starting from starting_inum
-int kfind_inode(const char* filepath, int starting_inum, int dir_levels, struct inode* result_inode);
-
-//finds the name of the directory path (result->truncated_path) and the name of the ending part (result->last) and the number of levels (result->levels)
-//result has to be kmalloc-ed by and kfree-d by whoever calls this functinos. Also remember to free last and truncated_path.
-void kfind_dir(const char* filepath, struct dir_helper* result);
-
-//transmits or receives the data block bitvector or the inode bitvecotr to and from disk
-// First parameter: TRANSMIT or RECEIVE (defined)
-// Second paramter: put pointer to bitvector (example: data_block_bitmap for data, inode_bitmap for inodes)
-// Third parameter: put where that bitvecotr starts in memory (example: FS->data_bitmap_loc for data, FS->inode_bitmap_loc for inode)
-// Fourth parameter: how many there are (example: FS->max_data_blocks for data, FS->max_inodes for inodes)
-// index = index you would put in the bitvector
-// all = 0 for only one index, 1 for all the bitvector
-int transmit_receive_bitmap(int t_or_r, bit_vector* vec, int starting_loc, int max, int bit_index, int all);
-
-/* Helper function to add a new dir_entry to a directory file and optinally write it out to disk.
- Updates the last data block of the cur_inode (directory) to add a dir_entry that stores the mapping of the new inode to its inum */
-int add_dir_entry(struct inode* cur_inode, int free_inode_loc, struct dir_helper* result);
-
-int get_block_address(struct inode *file_inode, int block_num);
-
-// Helper function for kread():
-int read_partial_block(struct inode *c_inode, int offset, void* buf_offset, int bytes_left, void* transfer_space);
-
-// Helper function for kread():
-int read_full_block(struct inode *c_inode, int offset, void* buf_offset, int bytesLeft, void* transfer_space);;
-
-int read_inode(struct inode *c_inode, int offset, void* buf, int num_bytes);
-
-
-#endif
diff --git a/kernel/include/fs/open_table.h b/kernel/include/fs/open_table.h
deleted file mode 100644
index 3262cf9b..00000000
--- a/kernel/include/fs/open_table.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef __OPEN_TABLE_H__
-#define __OPEN_TABLE_H__
-
-//header for the open table file
-//that implements the open table for the file system
-//please use provided functinos to add/remove items
-
-#include "global_defs.h"
-#include "klibc.h"
-#include "fs/file.h"
-#include "data_structures/bitvector.h"
-
-#define SYSTEM_SIZE 512 //how many files can be open at the same time
-
-// Each cell of the array is a struct with infos about the file.
-// More fields can be added if necessary.
-struct file_descriptor {
- char permission;
- struct inode* linked_file; //pointer to inode struct
- int offset; //keeps track of where we are reading
-};
-
-// Array of open files
-struct file_descriptor** table;
-
-//list of free indexes
-bit_vector * open_table_free_list;
-
-
-void fs_table_init(); //initializes fs open table at boot up time
-void fs_table_shutdown(); //closes the open table at shutdown time
-
-int add_to_opentable(struct inode* f, char perm); //adds a file to the opentable, returns fd if successful and -1 if not
-
-int delete_from_opentable(int fd); //deletes a file from the opentable, returns 0 if successful, -1 if not
-
-int file_is_open(int fd); //checks if there is an entry corrensponding to that fd
-
-int inode_is_open(struct inode* cur_inode);
-
-struct file_descriptor* get_descriptor(int fd); //returns the filedescriptor struct linked to fd
-
-#endif
diff --git a/kernel/include/global_defs.h b/kernel/include/global_defs.h
deleted file mode 100644
index ad90d0a6..00000000
--- a/kernel/include/global_defs.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef _GLOBAL_DEFS_H_
-#define _GLOBAL_DEFS_H_
-
-#include
-
-#define TRUE 1
-#define FALSE 0
-
-#ifndef NULL
-#define NULL ((void*) 0)
-#endif
-
-typedef char *String;
-typedef short Boolean;
-
-#ifndef __HOST
-typedef uint32_t size_t;
-#endif
-
-#define UNUSED(x) (void)(x)
-
-#define NBBY 8
-
-#define STATUS_OK 0
-#define STATUS_FAIL -1
-
-#define TEST_OK 0
-#define TEST_FAIL -1
-
-#endif //defined _GLOBAL_DEFS_H_
diff --git a/kernel/include/hw_handlers.h b/kernel/include/hw_handlers.h
deleted file mode 100644
index 432f71b9..00000000
--- a/kernel/include/hw_handlers.h
+++ /dev/null
@@ -1,74 +0,0 @@
-#ifndef __HW_HANDLERS_H__
-#define __HW_HANDLERS_H__
-
-/*
- *
- * Hardware Handler Interface for course_os
- *
- *
- * A bit of background:
- * - The ARM architecture has 7 modes of operation:
- * + USR - user mode
- * + FIQ - processing "fast" interrupts
- * + IRQ - processing "normal" interrupts
- * + SVC - proctected mode for OS
- * + UND - processing an undefined instruction exception
- * + SYS - also protecteed mode for OS --if anyone wants to clarify, feel free--
- * These modes can be entered or exited by modifying the CPSR (status register)
- *
- * exceptions (e.g. software interrupts, system calls, etc.), Interrupts (IRQ, FIQ)
- * trigger the core to switch to an appropriate mode and the pc to jump to a
- * preset address (somewhere in the vector table) for a branch instruction to the
- * proper handler.
- *
- * When this happens the state of the machine must be preserved. The HW handler interface
- * centralizes the 'top half' exception/interrupt handling code and takes care of the dirty low-level
- * work so that the software handling interfaces for interrupts, system calls, and exceptions
- * can be written more clearly elsewhere.
- *
- * tl;dr - write your handlers as a separate module and call them from one
- * of the prototypes below.
- *
- */
-#include
-
-#define BRANCH_INSTRUCTION 0xe59ff018 // ldr pc, pc+offset
-
-// System Call Types
-#define SYSCALL_CREATE 0
-#define SYSCALL_SWITCH 1
-#define SYSCALL_DELETE 2
-#define SYSCALL_OPEN 3
-#define SYSCALL_READ 4
-#define SYSCALL_WRITE 5
-#define SYSCALL_CLOSE 6
-#define SYSCALL_SET_PERM 7
-#define SYSCALL_MEM_MAP 8
-#define SYSCALL_SEEK 9
-#define SYSCALL_MKDIR 10
-#define SYSCALL_COPY 11
-#define SYSCALL_LS 12
-#define SYSCALL_MALLOC 13
-#define SYSCALL_ALIGNED_ALLOC 14
-#define SYSCALL_FREE 15
-#define SYSCALL_PRINTF 16
-#define SYSCALL_DUMMY 99
-#define SYSCALL_EXIT 100
-#define SYSCALL_WRITEV 101
-#define SYSCALL_PAUSE 102
-
-void init_vector_table(void);
-
-// vector table handlers, should be loaded at 0x00 in this order!
-extern void _Reset();
-void reset_handler(void);
-void __attribute__((interrupt("UNDEF"))) undef_instruction_handler(void); // 0x04
-long __attribute__((interrupt("SWI"))) software_interrupt_handler(void); // 0x08
-void __attribute__((interrupt("ABORT"))) prefetch_abort_handler(void); // 0x0c
-void __attribute__((interrupt("ABORT"))) data_abort_handler(void); // 0x10
-void reserved_handler(void); // 0x14
-void __attribute__((interrupt("IRQ"))) irq_handler(void); // 0x18
-void __attribute__((interrupt("FIQ"))) fiq_handler(void); // 0x1c
-
-
-#endif
diff --git a/kernel/include/interrupt.h b/kernel/include/interrupt.h
deleted file mode 100644
index bd304a32..00000000
--- a/kernel/include/interrupt.h
+++ /dev/null
@@ -1,133 +0,0 @@
-#ifndef __INTERRUPT_H__
-#define __INTERRUPT_H__
-/*
- *
- * Interrupt handler for course_os
- *
- *
- * - ARM has two interrupt lines to the core: FIQ (fast interrupt), IRQ (normal interrupt)
- * - Our VIC multiplexes intterupts and feeds them to the processor as either FIQ or IRQ
- * Basic interrupt control flow (no vectored interrupts, no nested interrupts) is as follows:
- * Interrupt Occurs -> Core branches to FIQ or IRQ vector -> vector branches to hanlder \
- * handler interfaces with VIC to determine source of interrupt -> branch to service routine \
- *
- */
-
-#include
-#include "mmap.h"
-
-// general syscall function
-extern int syscall(int number);
-
-// the VIC has 32 bits to indicate a type of interrupt
-// currently we just pull a bit off the VIC and jump to that number handler
-// in the handler array
-// this may need to be expanded if we use the secondary controller
-#define MAX_NUM_INTERRUPTS 32
-
-typedef enum
-{
- IRQ_MASK, // (this is bit 0x8 on the CPSR)
- FIQ_MASK, // (this is bit 0x4 on the CPSR)
- ALL_INTERRUPT_MASK
-} interrupt_t;
-
-extern interrupt_t IRQ;
-extern interrupt_t FIQ;
-extern interrupt_t ALL;
-
-// this will tell if an interrupt mapping is an FIQ
-// HIGH bits are FIQs
-// extern char check_if_fiq[MAX_NUM_INTERRUPTS];
-
-typedef struct interrupt_handler_t
-{
- void (*handler)(void *args);
-// more may need to be added
-} interrupt_handler_t;
-
-/* these are what you should use to effect an
- interrupt status change! */
-
-#define enable_irq() \
- enable_interrupt(IRQ)
-#define enable_fiq() \
- enable_interrupt(FIQ)
-#define enable_interrupts() \
- enable_interrupt(ALL)
-#define disable_irq() \
- disable_interrupt(IRQ)
-#define disable_fiq() \
- disable_interrupt(FIQ)
-#define disable_irq_save() \
- disable_interrupt_save(IRQ)
-#define disable_fiq_save() \
- disable_interrupt_save(FIQ)
-#define disable_interrupts() \
- disable_interrupt(ALL);
-#define disable_interrupts_save() \
- disable_interrupt_save(ALL);
-
-/* functions (e.g. passing a bad parameter), so we'll
- refer to the macros above for adjusting specific interrupt status */
-void enable_interrupt(interrupt_t);
-int enable_interrupt_save(interrupt_t);
-
-void disable_interrupt(interrupt_t);
-int disable_interrupt_save(interrupt_t);
-
-int get_proc_status(void);
-void restore_proc_status(int);
-
-int register_interrupt_handler(int, interrupt_handler_t *);
-void handle_irq_interrupt(int);
-
-/* VIC Interrupt Mappings */
-#define VIC_IRQ_STATUS PIC_ADDRESS // status of pending irqs after masking (R)
-#define VIC_FIQ_STATUS (((volatile uint32_t *)(PIC_ADDRESS+0x004))) // status of pending fiqs after masking (R)
-#define VIC_RAW_STATUS (((volatile uint32_t *)(PIC_ADDRESS+0x008))) // pending irqs before masking by enable register (R)
-#define VIC_INT_SELECT (((volatile uint32_t *)(PIC_ADDRESS+0x00C))) // select whether source generates an IRQ or FIQ (R/W)
-#define VIC_INT_ENABLE (((volatile uint32_t *)(PIC_ADDRESS+0x010))) // actually enable interrupt lines (1 = YES) (R/W)
-#define VIC_INT_ENCLEAR (((volatile uint32_t *)(PIC_ADDRESS+0x014))) // clear enabled lines in VICINTENABLE (1=clear)
-//#define VIC_VECT_ADDR (*((volatile uint32_t *)(PIC_ADDRESS=0x030))) // the ISR of the currently active interrupt
-
-// these should be used in conjunction with the bit shift mappings below
-#define hw_interrupt_enable(n) mmio_write(VIC_INT_ENABLE, mmio_read(VIC_INT_ENABLE) | (1 << n))
-#define hw_interrupt_disable(n) mmio_write(VIC_INT_ENCLEAR, (1 << n));
-#define vic_select_fiq(n) mmio_write(VIC_INT_SELECT, (1 << n));
-
-// Primary Interrupt Controller (PIC)
-#define WATCHDOG_IRQ 0 /* watchdog controller */
-#define SWI_IRQ 1 /* software interrupt */
-#define COMMS_RX_IRQ 2 /* debug comms receive intercept */
-#define COMMS_TX_IRQ 3 /* debug comms transmit intercept */
-#define TIMER_A_IRQ 4 /* timer 0 or 1 */
-#define TIMER_B_IRQ 5 /* timer 2 or 3 */
-#define GPIO_A_IRQ 6 /* GPIO 0 */
-#define GPIO_B_IRQ 7 /* GPIO 1 */
-#define GPIO_C_IRQ 8 /* GPIO 2 */
-#define GPIO_D_IRQ 9 /* GPIO 3 */
-#define RTC_IRQ 10 /* Real Time Clock (RTC) */
-#define SSP_IRQ 11 /* synchronous serial port */
-#define UART0_IRQ 12 /* UART 0 */
-#define UART1_IRQ 13 /* UART 1 */
-#define UART2_IRQ 14 /* UART 2 */
-#define SCIO_IRQ 15 /* smart card interface */
-#define CLCD_IRQ 16 /* CLCD controller */
-#define DMA_IRQ 17 /* DMA controller */
-#define PWRFAIL_IRQ 18 /* power failure from FPGA */
-#define MBX_IRQ 19 /* graphics processor */
-// IRQ 20 is reserved by the architecture
-#define VICINTSOURCE_21 21 /* external interrupt signal from DiskOnChip flash device */
-#define VICINTSOURCE_22 22 /* external interrupt signal from MCIO A */
-// IRQ 23 is reserved by the architecture
-#define VICINTSOURCE_24 23 /* external interrupt signal from AACI */
-#define VICINTSOURCE_25 24 /* Ethernet */
-#define VICINTSOURCE_26 25 /* USB */
-#define VICINTSOURCE_27 26 /* external interrupt signal from expansion connector */
-#define VICINTSOURCE_28 27 /* external interrupt signal from expansion connector */
-// IRQ 29 is reserved by the architecture
-// IRQ 30 is reserved by the architecture
-#define VICINTSOURCE_31 31 /* secondary interrupt controller (SIC) */
-
-#endif //__INTERRUPT_H__
diff --git a/kernel/include/klibc.h b/kernel/include/klibc.h
deleted file mode 100644
index f46061e0..00000000
--- a/kernel/include/klibc.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/********************************************************************
- * libc.h
- *
- * (Any collaborators, please add your name)
- * Author: Jared McArthur, Taylor Smith, Sheldon Sandbekkhaug, Kaelen Haag
- *
- * Last edited: 20 April 2014
- *
- * Purpose: Provide basic libc funtionality for CourseOS
- * This header provides function skeletons
- * for libc.c
- *
- * Usage: Compile into kernel. Adaptations of normal libc functions
- * can be used by prepending os_ suffix.
- ********************************************************************/
-
-/* LOG:
- * 3/30 added os_printf function - Taylor Smith
- * 4/1 working more on os_printf - Taylor Smith
- * 4/20 Added os_memset, os_strchrnul, os_strcpy, os_strlen, os_strtok,
- * os_strspn, and os_strcspn from MUSL - Sheldon
- * 4/21 Added os_memcpy for loader - Kaelen
- * --------------Spring 2015---------------
- * 4/15/15: Added implementation of assert()
- */
-#ifndef __KLIBC_H__
-#define __KLIBC_H__
-
-#include
-#include
-#include "global_defs.h"
-
-#ifndef __NO_WFI
-#define SLEEP while (1) asm volatile("wfi")
-#else
-#define SLEEP for(;;)
-#endif
-
-typedef unsigned int os_size_t;
-
-// useful macros
-#define MAX(a, b) ((a) > (b) ? a : b)
-#define MIN(a, b) ((a) < (b) ? a : b)
-
-// basic constants
-#define M_E 2.71828182845904523536
-#define M_LOG2E 1.44269504088896340736
-#define M_LOG10E 0.434294481903251827651
-#define M_LN2 0.693147180559945309417
-#define M_LN10 2.30258509299404568402
-#define M_PI 3.14159265358979323846
-#define M_PI_2 1.57079632679489661923
-#define M_PI_4 0.785398163397448309616
-#define M_1_PI 0.318309886183790671538
-#define M_2_PI 0.636619772367581343076
-#define M_1_SQRTPI 0.564189583547756286948
-#define M_2_SQRTPI 1.12837916709551257390
-#define M_SQRT2 1.41421356237309504880
-#define M_SQRT_2 0.707106781186547524401
-
-#define os_printf(...) printf(__VA_ARGS__)
-
-/* string.h type functionality for comparing strings or mem blocks */
-int os_memcmp(const void *left, const void *right, os_size_t num);
-int os_strcmp(const char *left, const char *right);
-
-
-//4-17-15: Working assert implementation - Prakash
-#define assert(X){\
- if ( (X) || _assert_fail(__FILE__, __LINE__, #X));\
-}
-
-/**
- * Note: os_printf is restricted to printing only 256 characters.
- * Supported format string conversions:
- * X: upper-case hexadecimal print.
- * x: lower-case hexadecimal print.
- * d: signed integer.
- * u: unsigned integer.
- * c: ASCII character.
- * s: string.
- * %: the percent sign itself.
- *
- * Supported options:
- * 0: zero-pad the result (applies to X,x,d,u). For example:
- * os_printf("'%05d %05d %05u'\n", 15, -15, -15);
- * prints '00015 -0015 4294967281'
- */
-int os_vsnprintf(char *buf, int buflen, const char *str_buf, va_list args);
-int os_snprintf(char *buf, int buflen, const char *fmt_string, ...);
-int os_printf(const char *str_buf, ...);
-
-void *os_memset(void *dest, char c, os_size_t n);
-char *__strchrnul(const char *s, char c);
-char *os_strcpy(char *dest, const char *src);
-char *os_strncpy(char *dest, const char *src, os_size_t n);
-os_size_t os_strlen(const char *s);
-char *os_strtok(char *s, const char *sep);
-os_size_t os_strspn(const char *s, const char *accept);
-os_size_t os_strcspn(const char *s, const char *reject);
-
-void os_memcpy(uint32_t * source, uint32_t * dest, os_size_t size);
-/* TODO: create print function for kernel debugging purposes */
-
-void* kmalloc(uint32_t size);
-void* kmalloc_aligned(uint32_t size, uint32_t alignment);
-void kfree(void* ptr);
-uint32_t km_size();
-uint32_t kmcheck();
-
-/**
- * umalloc allocates memory on the user heap
- *
- * @param size of the block of memory allocated
- * @param uint32_t size
- * @return returns a pointer to the allocated block of memory
- */
-void* umalloc(uint32_t size); //does user level malloc work
-
-/**
- * ualigned alloc allocates memory on the user heap
- * according to a specified alignemnt
- *
- * @param size of the block of memory allocated, and alignment desired
- * @param uint32_t size, uint32_alignment
- * @return returns a pointer to the allocated block of memory
- * that is a multiple of the specified allignement
- */
-void* ualigned_alloc(uint32_t size, uint32_t alignment); //does user level aligned_alloc work
-
-/**
- * free's an allocated block of memory on the heap
- *
- * @param pointer to a block of memeory on the heap
- * @param void* ptr
- * @return nothing returned
- */
-void ufree(void*); //does user level free work
-
-int32_t abs(int32_t);
-unsigned int rand();
-
-// as the codebase grows, it is important to use these macros
-// so that we can filter out unnecessary messages esp. during
-// development
-#define LOG_LEVEL 5
-
-#define DEBUG(...) if(LOG_LEVEL >= 5) os_printf(__VA_ARGS__)
-#define LOG(...) if(LOG_LEVEL >= 4) os_printf(__VA_ARGS__)
-#define INFO(...) if(LOG_LEVEL >= 3) os_printf(__VA_ARGS__)
-#define WARN(...) if(LOG_LEVEL >= 2) os_printf(__VA_ARGS__)
-#define ERROR(...) if(LOG_LEVEL >= 1) os_printf(__VA_ARGS__)
-
-//4-17-15: Initial panic * assert_fail functions added
-void panic();
-int _assert_fail(char *_file, unsigned int _line, char *_func);
- //__attribute__ ((__noreturn__));
-
-void splash(void);
-
-#endif
diff --git a/kernel/include/kthread.h b/kernel/include/kthread.h
deleted file mode 100644
index a7efd61f..00000000
--- a/kernel/include/kthread.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * kthread.h
- *
- * Created on: Apr 23, 2015
- * Author: mwkurian
- */
-
-#ifndef KERNEL_INCLUDE_KTHREAD_H_
-#define KERNEL_INCLUDE_KTHREAD_H_
-
-typedef void (*kthread_callback_handler)();
-
-typedef struct kthread_handle {
- uint32_t parent_pid;
- int niceness;
- int state;
- kthread_callback_handler cb_handler;
-} kthread_handle;
-
-
-
-#endif /* KERNEL_INCLUDE_KTHREAD_H_ */
diff --git a/kernel/include/loader.h b/kernel/include/loader.h
deleted file mode 100644
index 79e38fc5..00000000
--- a/kernel/include/loader.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef __loader_h
-#define __loader_h
-#include "global_defs.h"
-#include "elf.h"
-#include "process.h"
-
-#define USER_PROC_STACK_SIZE 0x100000 //1 MB
-#define KERNEL_PROC_STACK_SIZE 0x1000 //4K
-#define USER_PROC_HEAP_SIZE 4096
-#define PADDING 0x1000
-
-Elf_Ehdr* load_file(pcb *, uint32_t *); //Needs to be of the type that's where ever our beginning of file is in mem
-
-#endif
diff --git a/kernel/include/mem_alloc.h b/kernel/include/mem_alloc.h
deleted file mode 100644
index 45358d11..00000000
--- a/kernel/include/mem_alloc.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-Log
-4/2: Adjusted bump allocation algorithm: Sean V, Faseeh A, John G, Taylor S
-4/7: Fixed mem_alloc again works properly: Sean V, Faseeh A, Taylor S.
-
-*/
-#ifndef __MEM_ALLOC_H__
-#define __MEM_ALLOC_H__
-
-#include "allocator.h"
-#include
-#include
-
-#define MEM_START 0x500000
-#define PROC_START 0x90000000
-
-
-uint32_t init_heap();
-void *allocate(uint32_t, uint32_t* /*unused*/, int32_t/*unused*/);
-void deallocate(void*, uint32_t*/*unused*/, int32_t/*unused*/);
-
-/**
- * Initializes a processes heap, in the same manner that the
- * kernel heap is initialized
- *
- * @param pointer to virtual address space (the process's VAS)
- * @param struct vas* vas
- * @return returns status code (for error or for ok)
- */
-uint32_t init_process_heap();
-
-/**
- * Allocates memory on the heap for a process
- *
- * @param size of allocated memory
- * @param uint32_t size
- * @return a pointer to allocated memory
- */
-void *proc_allocate(uint32_t);
-
-/**
- * Deallocates memory on the heap for a process
- *
- * @param pointer to allocated memory
- * @param void* ptr
- * @return nothing
- */
-void proc_deallocate(void*);
-alloc_handle* mem_get_allocator();
-int mem_check();
-uint32_t mem_get_heap_size();
-
-#endif
diff --git a/kernel/include/memory.h b/kernel/include/memory.h
deleted file mode 100644
index 55291475..00000000
--- a/kernel/include/memory.h
+++ /dev/null
@@ -1,31 +0,0 @@
-//Physical location of kernel
-#define P_KERNBASE 0x00010000
-#define P_KERNTOP 0x00200000
-//Virtual location of kernel
-#define V_KERNBASE 0xf0000000
-#define V_KERNTOP 0xf0200000
-
-//All static kernel data structures
-//Total space=1MB, currently used=44kB
-#define P_KDSBASE 0x07f00000
-#define P_L1PTBASE P_KERNTOP
-
-#define V_KDSBASE 0xfff00000
-#define V_L1PTBASE V_KERNTOP
-
-#define PERIPHBASE 0x10000000
-#define PERIPHTOP 0x20000000
-
-#define PCIBASE 0x41000000
-#define PCITOP 0x70000000
-
-//remapped physical memory for direct access
-#define PMAPBASE 0xf0200000
-#define PMAPTOP 0xf7f00000
-
-// Region where we use 4K pages.
-#define P_4K_BASE (P_L1PTBASE+0x200000)
-#define P_4K_TOP (PMAPTOP - 0xf0000000)
-
-//High vectors are enabled by setting V bit in the control register
-#define HIVECTABLE 0xffff0000
diff --git a/kernel/include/misc_defs.h b/kernel/include/misc_defs.h
deleted file mode 100644
index 40f0779b..00000000
--- a/kernel/include/misc_defs.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#include
-
-/*
- Contained within this file is the base addresses to many of the Rasberry Pi's peripherals,
- along with definitions for some of the important offsets from these case addresses.
-*/
-#define USB_BASE_ADDRESS 0x20980000
-
-#define USB_MDIO_CNTL (USB_BASE_ADDRESS +0x080) // MDIO interface control
-#define USB_MDIO_GEN (USB_BASE_ADDRESS + 0x084) // Datat for MDIO interface
-#define USB_VBUS_DRV (USB_BASE_ADDRESS + 0x088) // Vbus and other miscellaneous controls
-
-// BSC stands for Broadcom Serial Controller, from the documentation, it looks like its used for HDMI
-#define BSC_MASTER_0 0x20205000
-#define BSC_MASTER_1 0x20804000
-#define BSC_MASTER_2 0x20805000
-//Offsets can be used with any of the above three BSC register BSC register bases
-#define BSC_CONTROL 0x0
-#define BSC_STATUS 0x4
-#define BSC_DATA_LENGTH 0x8
-#define BSC_SLAVE_ADDRESS 0xC
-#define BSC_FIFO 0x10
-#define BSC_CLOCK_DIVIDER 0x14
-#define BSC_DATA_DELAY 0x18
-
diff --git a/kernel/include/mmap.h b/kernel/include/mmap.h
deleted file mode 100644
index 5706b161..00000000
--- a/kernel/include/mmap.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Memory Mapped I/O addresses
- */
-
-#ifndef __MMAP_H__
-#define __MMAP_H__
-
-#define mmio_read(address) (*((volatile uint32_t *)(address)))
-#define mmio_write(address, value) (*((volatile uint32_t *)(address)) = (volatile uint32_t)(value))
-
-void mmap(void *p_bootargs);
-
-#define PIC_ADDRESS ((volatile char *const) 0x10140000) /* interrupt controller peripheral */
-#define UART0_ADDRESS (volatile uint32_t *const) 0x101f1000 /* UART 0 base address */
-#define CLOCK_ADDRESS (volatile uint32_t *const) 0x101e8000 /* RTC base address */
-
-/* Physical Hardware Addresses */
-#define PERIPHERAL_BASE_PI (volatile uint32_t *const) 0x20000000
-#define PIC_ADDRESS_PI (volatile uint32_t *const) 0x2000B000 /* interrupt controller peripheral */
-#define UART0_ADDRESS_PI (volatile uint32_t *const) 0x20201000 /* UART 0 base address */
-#define CLOCK_ADDRESS_PI (volatile uint32_t *const) 0x20003000 /* RTC base address */
-#define GPIO_ADDRESS_PI (volatile uint32_t *const) 0x20200000
-
-#endif // __MMAP_H_
diff --git a/kernel/include/os_setjmp.h b/kernel/include/os_setjmp.h
deleted file mode 100644
index b13af54c..00000000
--- a/kernel/include/os_setjmp.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef _SETJMP_H
-#define _SETJMP_H
-
-#include
-
-typedef struct __jmp_buf_tag {
- __jmp_buf __jb;
- unsigned long __fl;
- unsigned long __ss[128/sizeof(long)];
-} jmp_buf[1];
-
-// typedef jmp_buf sigjmp_buf;
-// int sigsetjmp (sigjmp_buf, int);
-// _Noreturn void siglongjmp (sigjmp_buf, int);
-
-int setjmp (jmp_buf);
-_Noreturn void longjmp (jmp_buf, int);
-
-#define setjmp setjmp
-#define longjmp longjmp
-
-#endif
diff --git a/kernel/include/pi_light.h b/kernel/include/pi_light.h
deleted file mode 100644
index 0e292d66..00000000
--- a/kernel/include/pi_light.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#include "mmap.h"
-
-#define GPIO_BASE 0x20200000
-#define LED_PIN 16
-
-void set_up_LED();
-void light_on();
-void light_off();
\ No newline at end of file
diff --git a/kernel/include/pm.h b/kernel/include/pm.h
deleted file mode 100644
index c30c7e29..00000000
--- a/kernel/include/pm.h
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifndef _PM_H
-#define _PM_H
-#include "klibc.h"
-#include "global_defs.h"
-#include "stdint.h"
-#include "mmap.h"
-
-typedef struct
-{
-
- //CPU peripherals
- uint32_t PIC;
- uint32_t VFP;
- uint32_t PMU;
-
- //registers
- uint32_t R0;
- uint32_t R1;
- uint32_t R2;
- uint32_t R3;
- uint32_t R4;
- uint32_t R5;
- uint32_t R6;
- uint32_t R7;
- uint32_t R8;
- uint32_t R9;
- uint32_t R10;
- uint32_t R11;
- uint32_t R12;
- uint32_t R13;
- uint32_t R14;
- uint32_t R15;
-} cpu_state;
diff --git a/kernel/include/priorityQueue.h b/kernel/include/priorityQueue.h
deleted file mode 100644
index 4dd889c3..00000000
--- a/kernel/include/priorityQueue.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "process.h"
-#include "global_defs.h"
-
-#define NOT_SET -1
-
-/* Data Structure: Doubly Linked List */
-typedef struct {
- struct node *next;
- struct node *prev;
- pcb *PCB; // Pointer to the process control block
- int priority;
-} Node;
-
-
-void pqueue_init();
-int pqueue_add(void *PCB, int priority);
-pcb* pqueue_remove(pcb *PCB);
-void pqueue_join(pcb *other_PCB);
-void dispatch(pcb *PCB);
-void schedule();
-void task_yield();
-Boolean is_in_queue(int pid);
diff --git a/kernel/include/process.h b/kernel/include/process.h
deleted file mode 100644
index c663ccf7..00000000
--- a/kernel/include/process.h
+++ /dev/null
@@ -1,170 +0,0 @@
-#ifndef PROCESS_H
-#define PROCESS_H
-#include "global_defs.h"
-#include
-#include "vm.h"
-
-/* LOG:
- 3/15: Initial skeleton and comments by Josh Guan.
- 3/21: More research and comments by Faseeh Akhter and Josh Guan
- 3/31: Further research and beginning implementation of process initialization and creation by Faseeh Akhter, Taylor Smith, Sean Villars
- 4/2: Fixed mem_alloc and began initial pcb creation by Sean Villars, Faseeh Akhter, Josh Guan, Taylor Smith
- 4/7: Fixed mem_alloc and fixed pcb allocation. added a few utility functions as well. Sean V, Faseeh A, Taylor Smith
- 4/9: Added some more utility functions and changed process destroy. Sean V
- 4/14: Worked on save process state. Sean V, Faseeh A, Taylor Smith
- 4/15: Save state inline asm works, working on saving to pcb. Taylor s
- 4/16: Load state with inline asm, Sean V, Faseeh A, Taylor Smith
- *******************
- a work in progress
- memory boundaries?
- ********************
-
- process struct outline
- process id data
- PID -- must be unique
- User ID
- Group ID
- parent id ?
-
- processor state data
- pc
- CPU GPRs
- CPU status word
- SP, FP
-
- process control data
- location of eimage on disk
- location of user process kernel stack?
-
- process scheduling state
- priority value?
- amount of time running or suspended
- EFLAGs
- process structuring information
- process's child process ID
- other related processes via their IDs
- IPC info*
- process privileges*
- accounting info
- last run?, total CPU time accumulation
- what are the bare essentials for a PCB
- */
-typedef enum PROCESS_STATE
-{
- PROCESS_NEW, PROCESS_READY, PROCESS_RUNNING, PROCESS_BLOCKED, PROCESS_DYING
-} PROCESS_STATE;
-
-#define MAX_PROCESSES 32
-
-#define STACK_BASE 0x9f000000
-#define PROC_LOCATION 0x9ff00000
-#define STACK_SIZE (BLOCK_SIZE)
-#define STACK_TOP (STACK_BASE + STACK_SIZE)
-#define HEAP_BASE 0x90000000
-
-
-typedef struct pcb
-{
- //ID data
- char* name; /* for debugging purposes */
- uint32_t PID;
- uint32_t starting_address;
- uint32_t process_number; // is this a mapping to actual executable image? or does it describe total number of processes?
- uint32_t user_id;
- uint32_t group_id;
- uint32_t parent_id;
- uint32_t (*function)();
- uint32_t has_executed;
- struct vas* stored_vas;
- uint32_t start;
- uint32_t len;
- //CPU state data
- PROCESS_STATE current_state;
-
- /*
- * r0-r3 are the argument and scratch registers; r0-r1 are also the result registers
- * r4-r8 are callee-save registers
- * r9 might be a callee-save register or not (on some variants of AAPCS it is a special register)
- * r10-r11 are callee-save registers
- * r12-r15 are special registers
- * 37 REGISTERS IN TOTAL: 31 GPRs, 6 SRs
- */
-
- // WE ARE GOING TO TRY TO IMPLEMENT SETJMP/LONGJMP INSTEAD OF MANUALLY DEALING WITH THESE VALUES
- // uint32_t PC;
- // uint32_t SP;
- // uint32_t CPSR; //current prog status register
- // uint32_t SPSR; //saved prog status register when execption occurs
- //unbanked register
- uint32_t R0;
- uint32_t R1;
- uint32_t R2;
- uint32_t R3;
- uint32_t R4;
- uint32_t R5;
- uint32_t R6;
- uint32_t R7;
-
- //banked registers
- uint32_t R8;
- uint32_t R9;
- uint32_t R10;
- uint32_t R11;
- uint32_t R12;
- uint32_t R13; //corresponds to the SP; do we need both?
- uint32_t R14;
- uint32_t R15; //corresponds to the PC; do we need both?
-
- //Control data
- //int priority_value;
- //uint32_t elapsed_time;
- //uint32_t EFLAG;
- //uint32_t* process_relations
- //uint32_t total_cpu_time;
-
-//CPU state data
- uint32_t SPSR;
- uint32_t PC;
-
-//Control data
- int priority_value;
- uint32_t elapsed_time;
- uint32_t EFLAG;
- uint32_t* process_relations;
-
- uint32_t total_cpu_time;
-
- void* heap_p;
-
-} pcb;
-
-/* interface
- processes can
- be made (initialized)
- be terminated
- be duplicated
- be suspended
- be resumed
- */
-
-//input
-//1) address of where the program code is in memory; elf and loader
-//process
-//do we n eed to create the stack and the heap?
-//do we need to know where the data is?
-//output
-//create a corresponding pcb ds
-
-//Init process system
-void process_init();
-
-//Process API - start process from elf
-pcb* process_create(const char *name);
-int process_execute(pcb* pcb_p);
-int process_destroy(pcb* pcb_p);
-
-//Execution functions
-void process_load_state(pcb* pcb_p) __attribute__ ((noreturn));
-void process_save_state(pcb* pcb_p);
-
-#endif
diff --git a/kernel/include/scheduler.h b/kernel/include/scheduler.h
deleted file mode 100644
index c9723229..00000000
--- a/kernel/include/scheduler.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * scheduler.h
- *
- * Created on: Apr 16, 2015
- * Author: mwkurian
- */
-
-#include "process.h"
-#include "klibc.h"
-#include "data_structures/priority_queue.h"
-#include "data_structures/linked_list.h"
-#include "data_structures/array_list.h"
-
-#ifndef KERNEL_INCLUDE_SCHEDULER_H_
-#define KERNEL_INCLUDE_SCHEDULER_H_
-
-typedef void (*sched_callback_handler)(uint32_t src_pid, uint32_t event, char * data, int chunk_length, int remain_length);
-
-typedef struct sched_task {
- uint32_t parent_tid;
- uint32_t tid;
- uint32_t state;
- uint32_t type;
- int niceness;
- void * task;
- prq_node * node;
- arrl_handle * children_tids;
- sched_callback_handler cb_handler;
- llist_handle * message_queue;
-} sched_task;
-
-typedef struct sched_message_chunk {
- uint32_t src_pid;
- int chunk_length;
- int remain_length;
- uint32_t event;
- char * data;
-} sched_message_chunk;
-
-uint32_t sched_init(void);
-void sched_start(void);
-uint32_t sched_free();
-uint32_t sched_add_task(sched_task * task);
-uint32_t sched_set_niceness(uint32_t pid, uint32_t niceness);
-uint32_t shed_remove_task(uint32_t pid);
-uint32_t sched_get_active_pid();
-void sched_waitpid(uint32_t pid);
-sched_task* sched_create_task(uint32_t* file_p, int niceness);
-sched_task* sched_create_task_from_kthread(kthread_handle * kthread, int niceness);
-sched_task* sched_create_task_from_process(pcb * pcb_pointer, int niceness);
-sched_task* sched_get_active_task();
-uint32_t sched_post_message(uint32_t dest_pid, uint32_t event, char * data, int len);
-uint32_t sched_register_callback_handler(sched_callback_handler cb_handler);
-uint32_t sched_deregister_callback_handler();
-
-#endif /* KERNEL_INCLUDE_SCHEDULER_H_ */
diff --git a/kernel/include/signals.h b/kernel/include/signals.h
deleted file mode 100644
index 2e53203c..00000000
--- a/kernel/include/signals.h
+++ /dev/null
@@ -1,11 +0,0 @@
-//Contributors: Andrew Stepek, Michael Brennen, and Matthew Stromberg
-
-#include
-#include "include/mmap.h"
-#include "include/process.h"
-
-typedef struct signal
-{
- char * type;
-} sig;
-
diff --git a/kernel/include/stdarg.h b/kernel/include/stdarg.h
deleted file mode 100644
index 60d4e2af..00000000
--- a/kernel/include/stdarg.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef _STDARG_H
-#define _STDARG_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define __NEED_va_list
-
-#include
-
-#if __GNUC__ >= 3
-#define va_start(v,l) __builtin_va_start(v,l)
-#define va_end(v) __builtin_va_end(v)
-#define va_arg(v,l) __builtin_va_arg(v,l)
-#define va_copy(d,s) __builtin_va_copy(d,s)
-#else
-#include
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/kernel/include/stdint.h b/kernel/include/stdint.h
deleted file mode 100644
index ad6aaead..00000000
--- a/kernel/include/stdint.h
+++ /dev/null
@@ -1,117 +0,0 @@
-#ifndef _STDINT_H
-#define _STDINT_H
-
-#define __NEED_int8_t
-#define __NEED_int16_t
-#define __NEED_int32_t
-#define __NEED_int64_t
-
-#define __NEED_uint8_t
-#define __NEED_uint16_t
-#define __NEED_uint32_t
-#define __NEED_uint64_t
-
-#define __NEED_intptr_t
-#define __NEED_uintptr_t
-
-#define __NEED_intmax_t
-#define __NEED_uintmax_t
-
-#include
-
-typedef int8_t int_fast8_t;
-typedef int64_t int_fast64_t;
-
-typedef int8_t int_least8_t;
-typedef int16_t int_least16_t;
-typedef int32_t int_least32_t;
-typedef int64_t int_least64_t;
-
-typedef uint8_t uint_fast8_t;
-typedef uint64_t uint_fast64_t;
-
-typedef uint8_t uint_least8_t;
-typedef uint16_t uint_least16_t;
-typedef uint32_t uint_least32_t;
-typedef uint64_t uint_least64_t;
-
-#define INT8_MIN (-1-0x7f)
-#define INT16_MIN (-1-0x7fff)
-#define INT32_MIN (-1-0x7fffffff)
-#define INT64_MIN (-1-0x7fffffffffffffff)
-
-#define INT8_MAX (0x7f)
-#define INT16_MAX (0x7fff)
-#define INT32_MAX (0x7fffffff)
-#define INT64_MAX (0x7fffffffffffffff)
-
-#define UINT8_MAX (0xff)
-#define UINT16_MAX (0xffff)
-#define UINT32_MAX (0xffffffff)
-#define UINT64_MAX (0xffffffffffffffff)
-
-#define INT_FAST8_MIN INT8_MIN
-#define INT_FAST64_MIN INT64_MIN
-
-#define INT_LEAST8_MIN INT8_MIN
-#define INT_LEAST16_MIN INT16_MIN
-#define INT_LEAST32_MIN INT32_MIN
-#define INT_LEAST64_MIN INT64_MIN
-
-#define INT_FAST8_MAX INT8_MAX
-#define INT_FAST64_MAX INT64_MAX
-
-#define INT_LEAST8_MAX INT8_MAX
-#define INT_LEAST16_MAX INT16_MAX
-#define INT_LEAST32_MAX INT32_MAX
-#define INT_LEAST64_MAX INT64_MAX
-
-#define UINT_FAST8_MAX UINT8_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-#define UINT_LEAST8_MAX UINT8_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-#define INTMAX_MIN INT64_MIN
-#define INTMAX_MAX INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-#define WINT_MIN 0
-#define WINT_MAX UINT32_MAX
-
-#if L'\0'-1 > 0
-#define WCHAR_MAX (0xffffffffu+L'\0')
-#define WCHAR_MIN (0+L'\0')
-#else
-#define WCHAR_MAX (0x7fffffff+L'\0')
-#define WCHAR_MIN (-1-0x7fffffff+L'\0')
-#endif
-
-#define SIG_ATOMIC_MIN INT32_MIN
-#define SIG_ATOMIC_MAX INT32_MAX
-
-#include
-
-#define INT8_C(c) c
-#define INT16_C(c) c
-#define INT32_C(c) c
-
-#define UINT8_C(c) c
-#define UINT16_C(c) c
-#define UINT32_C(c) c ## U
-
-#if UINTPTR_MAX == UINT64_MAX
-#define INT64_C(c) c ## L
-#define UINT64_C(c) c ## UL
-#define INTMAX_C(c) c ## L
-#define UINTMAX_C(c) c ## UL
-#else
-#define INT64_C(c) c ## LL
-#define UINT64_C(c) c ## ULL
-#define INTMAX_C(c) c ## LL
-#define UINTMAX_C(c) c ## ULL
-#endif
-
-#endif
diff --git a/kernel/include/swap_framework.h b/kernel/include/swap_framework.h
deleted file mode 100644
index 9b44906c..00000000
--- a/kernel/include/swap_framework.h
+++ /dev/null
@@ -1,121 +0,0 @@
-#ifndef __VM_SWAP_FRAMEWORK_H
-#define __VM_SWAP_FRAMEWORK_H
-
-#include "klibc.h"
-#include
-
-// NOTE: SWAPPING CANNOT WORK UNTIL FILESYSTEMS CAN ALLOCATE MORE THAN 16 PAGES AT A TIME
-/* Contributors: Noel Negusse and Jesse Thaden
- * Last Update: 05/10/15
- */
-
-/* Function: swap_framework
- * Purpose: To present an API for swapping pages to various swap spaces
- * so that pages may be stored independently of other related operations
- *
- * EXAMPLE OF VIRTUAL MEMORY ID/ADDRESS FROM SWAP SPACE
- * _____________________________________________________________
- * || [24 bit] SWAP SPACE OFFSET |[8 bit] SWAP SPACE # ||
- * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
- * * Total: 32 Bit Address
- * therefore, there are 256 possible swap spaces possible
- * w/ 2^12 page entries each (Assuming 4kB pages)
- */
-
-#define SWAP_SPACES (1<<8)
-#define PAGE_ENTRIES (1<<12) // Assuming 4kB Pages right now
-#define PAGE_SIZE (1<<12) // May carry an if statement later to account for different page sis
-#define COMPRESSED_SIZE 10 // The size of compressing 16MiB of data
-
-typedef uint32_t *(*func)(void*, uint32_t*);
-
-struct swap_space {
- struct swap_entry *e_head; // currently only used for LZ swap
-// uint16_t pages_free;
- uint8_t lower_bits; // swap space ID [8-bits]
-// uint16_t flags; // swp_used (1000 or 1), swp_writeok (0010 or 2) or both (0011 or 3)
- uint8_t priority; // lower is better
- func store_func;
- func retrieve_func;
-}; // Total: 14 bytes
-
-struct swap_entry {
- uint16_t e_flags; // PRIVILEGED_RO = 1, USER_RO = 2, PRIVILEGED_RW = 4, USER_RW =
- uint16_t cmp_size; // size of compressed page
- void *cmp_page; // virtual address pointer used for resolving page faults; NULL = unusedi
-}; // Total: 8 bytes
-
-static struct swap_space *holder;
-static os_size_t memory_count;
-
-
-// Swap_init initializes swap framework
-void swap_init();
-//void swap_init(os_size_t); To be implemented... [specifies global page size]
-
-
-/* store_page will store a page to media - not main memory - storage, e.g. HDD
- * from the page*. ID parameter passed will change to appropriate index (i.e. return value)
- * void* page -> data to be paged
- * os_size_t pagesize: The size of a page in bytes, i.e. 4096 b
- * uint32_t* ID -> The page ID or address
- *
- * Returns: A pointer to a index value (from a bit vector) in memory
- * OR returns a NULL/0 on failure
- */
-uint32_t store_page(void*, uint32_t*);
-uint32_t store_page_LZ(void*, uint32_t*); // All LZ functions not yet working...
-// uint32_t *store_page(void*, os_size_t, uint32_t*); To be implemented... (will replace)
-// uint32_t *store_pageLZ(void*, os_size_t, uint32_t*); diddo
-
-
-/* retrieve_page will retrieve the page identified the ID pointer and
- * will store it back into main memory (specified by the void *page pointer)
- *
- * Returns: NULL on failure or simply passes back ID on success
- * NOTE: Page size was set by store_page
- */
-uint32_t retrieve_page(void*, uint32_t*);
-uint32_t retrieve_page_LZ(void*, uint32_t*);
-
-
-/* Returns: The total stored memory in bytes by function store_page(void*, uint32_t*) */
-os_size_t sum_stored();
-
-
-/* vm_swap_page will store a page from main memory (specified by void *page)
- * to a swap space either on disk or a compressed block in memory
- *
- * Returns: The ID pointer - bit vector index - of where the swap_space was stored and
- * changes the ID pointer that value as well. Returns NULL on failure
- */
-uint32_t vm_swapout_page(void*, uint32_t*); // store the page
-uint32_t vm_swapin_page(void*, uint32_t*); // retrieve the page
-
-
-/* vm_register/vm_deregister will activate/deactivate a swap space and set a priority
- * accordingly to it. This allows the swap spaces use as well as increasing it's efficiency
- * NOTE: deregister_swap_space will always deregister the lowest priority swap space first
- *
- * Returns: -1 or 1 whether the swap space registeration was a failure or success, respectively
- */
-int vm_register_swap_space(func, func, int, int16_t);
-void vm_deregister_swap_space(uint8_t);
-
-
-/* Resolves the page fault and updates the corresponding page table
- *
- * Returns: 0 if the page_fault could not be resolved
- * returns the new physical address of the loaded memory
- */
-uint32_t vm_page_fault_handler(void*);
-
-
-/* vm_scan_pages will scan through all pages for the corresponding page
- * to the given page
- *
- * Returns: The address of matching swapped page
- */
-//uint32_t* vm_scan_pages(void*);
-
-#endif
diff --git a/kernel/include/swap_fs.h b/kernel/include/swap_fs.h
deleted file mode 100644
index ddd64701..00000000
--- a/kernel/include/swap_fs.h
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef __VM_SWAP_FS_H
-#define __VM_SWAP_FS_H
-
-#include "bitvector.h"
-#include "swap_framework.h"
-
-
-/* Last Update: 05/11/15 */
-
-
-bit_vector *bv_arr[SWAP_SPACES];
-// bit_vector *free_bitvector;
-
-
-//helper function
-char *generate_filename(uint8_t);
-
-
-/* swapfs_init initializes swap file system framework for 'npages' number of pages
- *
- * Returns: -1 if failure, number of bytes written on success
- */
-int32_t swapfs_init(int, uint8_t);
-
-
-/* swapfs_store will store a page to media - not main memory - storage, e.g. HDD
- * from the page*
- * void* page -> data to be paged
- * os_size_t pagesize: The size of a page in bytes, i.e. 4096 b
- * uint32_t* ID -> The page ID or address
- *
- * Returns: The stored page's swap space ID, index OR -1 on failure
- * NOTE: Relying on the changed id pointer is safer than using the output (unless
- * for error checking) due to the int64_t type output
- */
-int64_t swapfs_store(void*, uint32_t*, uint8_t);
-
-
-/* swapfs_retrieve will retrieve the page identified by the ID pointer and
- * will store it back into main memory (specified by the void *page pointer)
- *
- * Returns: -1 on failure and 1 on success
- */
-int64_t swapfs_retrieve(void*, uint32_t*, uint8_t);
-
-
-/* Returns: -1 if failure, 1 if success */
-int32_t swapfs_disable(uint8_t);
-
-
-#endif
diff --git a/kernel/include/swap_pqueue.h b/kernel/include/swap_pqueue.h
deleted file mode 100644
index b2d5b406..00000000
--- a/kernel/include/swap_pqueue.h
+++ /dev/null
@@ -1,82 +0,0 @@
-#ifndef __VM_SWAP_PQUEUE_H
-#define __VM_SWAP_PQUEUE_H
-
-#include
-#include "swap_framework.h"
-
-
-/* Last Update: 05/10/15 */
-
-
-struct node{
- struct node *next;
- struct swap_entry *e_head;
- uint8_t lower_bits; // swap space ID [8-bits]
-// uint16_t flags; // SWP_USED (1000 or 1), SWP_WRITEOK (0010 or 2)
- uint8_t priority; // lower is better
- func store_func;
- func retrieve_func;
-}; // Total: 16 bytes
-
-static struct node *head;
-static struct node *path; //tail
-static uint8_t s;
-
-
-/* pqueue_init initializes the priority queue with a given
- * swap_space type struct
- */
-void pqueue_init(struct swap_space*);
-
-
-/* pqueue_set does a deep copy of the value of the second
- * struct to the front struct
- */
-void pqueue_set(struct node*, struct swap_space*);
-
-
-/* pqueue_push pushes the swap_space struct onto the proper
- * index based on the priority found in the struct
- */
-void pqueue_push(struct swap_space*);
-
-
-/* pqueue_pop_front & pqueue_pop_back pops a node from the head/back of the
- * pqueue_pop_front priority queue as well as freeing the given memory of the
- * head/back
- */
-void pqueue_pop_front();
-void pqueue_pop_back();
-void pqueue_pop_at(uint8_t); // Note: 'at' ssid not index
-
-/* pqueue_size returns the current size of the priority queue */
-uint8_t pqueue_size();
-
-
-/* pqueue_index finds the given index of the priority queue
- *
- * Returns: The struct of the given index in pqueue
- * NOTE: THIS IS NOT THE SAME AS THE SWAP_SPACE STRUCT
- */
-struct node *pqueue_index(int);
-
-
-/* It 'peeks' at the head of the list for a specified value
- *
- * Returns: The specified value from the head of the list
- * 0 - lower_bits
- * 1 - priority
- * 2 - e_head
- */
-void *pqueue_peek(int);
-
-
-/* pqueue_find finds the actual index of the swap space ID (lower_bit value)
- *
- * Returns: The found node specified or NULL if not found
- * NOTE: THIS IS NOT THE SAME AS THE SWAP_SPACE STRUCT
- */
-struct node *pqueue_find(uint8_t);
-
-
-#endif
diff --git a/kernel/include/tests.h b/kernel/include/tests.h
deleted file mode 100644
index 40a07760..00000000
--- a/kernel/include/tests.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef _TESTS_H_
-#define _TESTS_H_
-
-#include "global_defs.h"
-
-// Each test consists of a descriptor and function pointer to the test function.
-typedef struct Test {
- char *test_name;
- int (*testptr)();
-} Test;
-
-// Run_tests takes an array of tests which it runs and prints the results.
-void run_tests(Test *test_group[], int num_tests);
-void run_fs_tests();
-
-int test1();
-int test2();
-
-Test* create_test(char *name, int (*test_function)());
-
-#endif
diff --git a/kernel/include/tests/test_hash_map.h b/kernel/include/tests/test_hash_map.h
deleted file mode 100644
index 4a0d4e34..00000000
--- a/kernel/include/tests/test_hash_map.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * test_hash_map.h
- *
- * Created on: Apr 20, 2015
- * Author: kittenRainbow
- */
-
-#ifndef KERNEL_INCLUDE_TESTS_TEST_HASH_MAP_H_
-#define KERNEL_INCLUDE_TESTS_TEST_HASH_MAP_H_
-
-void run_hmap_tests();
-
-#endif /* KERNEL_INCLUDE_TESTS_TEST_HASH_MAP_H_ */
diff --git a/kernel/include/tests/test_mem_alloc.h b/kernel/include/tests/test_mem_alloc.h
deleted file mode 100644
index b7f93d17..00000000
--- a/kernel/include/tests/test_mem_alloc.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * test_hash_map.h
- *
- * Created on: Apr 20, 2015
- * Author: kittenRainbow
- */
-
-#ifndef KERNEL_INCLUDE_TESTS_TEST_MEM_ALLOC_H_
-#define KERNEL_INCLUDE_TESTS_TEST_MEM_ALLOC_H_
-
-void run_mem_alloc_tests();
-
-#endif /* KERNEL_INCLUDE_TESTS_TEST_MEM_ALLOC_H_ */
diff --git a/kernel/include/tests/test_priority_queue.h b/kernel/include/tests/test_priority_queue.h
deleted file mode 100644
index b177d57e..00000000
--- a/kernel/include/tests/test_priority_queue.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * test_priority_queue.h
- *
- * Created on: Apr 16, 2015
- * Author: mwkurian
- */
-
-#ifndef KERNEL_INCLUDE_TESTS_TEST_PRIORITY_QUEUE_H_
-#define KERNEL_INCLUDE_TESTS_TEST_PRIORITY_QUEUE_H_
-
-void run_prq_tests();
-
-#endif /* KERNEL_INCLUDE_TESTS_TEST_PRIORITY_QUEUE_H_ */
diff --git a/kernel/include/tests/test_vm.h b/kernel/include/tests/test_vm.h
deleted file mode 100644
index 41b2fd3c..00000000
--- a/kernel/include/tests/test_vm.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * test_vm.h
- *
- * Created on: Apr 23, 2015
- * Author: mwkurian
- */
-
-#ifndef KERNEL_INCLUDE_TESTS_TEST_VM_H_
-#define KERNEL_INCLUDE_TESTS_TEST_VM_H_
-
-void run_vm_tests();
-
-#endif /* KERNEL_INCLUDE_TESTS_TEST_VM_H_ */
diff --git a/kernel/include/vm.h b/kernel/include/vm.h
deleted file mode 100644
index 92228d41..00000000
--- a/kernel/include/vm.h
+++ /dev/null
@@ -1,193 +0,0 @@
-#ifndef __VM_H
-#define __VM_H 1
-
-#include "memory.h"
-#include
-#include "klibc.h"
-
-//#define BLOCK_SIZE (1<<20)
-#define BLOCK_SIZE (1<<12)
-
-#define PAGE_TABLE_SIZE (1<<14)
-#define L2_PAGE_TABLE_SIZE (1<<12)
-
-struct vas {
- // A pointer to the first level of the pagetable.
- unsigned int *l1_pagetable;
- unsigned int *l1_pagetable_phys; // The physical address to it
-
- // A pointer to the next VAS (it's a linked list)
- struct vas *next;
-};
-
-#define VM_ERR_BADV -1
-#define VM_ERR_BADP -2
-#define VM_ERR_MAPPED -3
-#define VM_ERR_BADPERM -4
-#define VM_ERR_UNKNOWN -5
-#define VM_ERR_NOT_MAPPED -6
-
-#define KERNEL_VAS ((struct vas*)V_L1PTBASE)
-
-/**
- * These permissions dictate who can access what pages. Note that you
- * cannot combine these arbitrarily. For example:
- * VM_PERM_PRIVILEGED_RO|VM_PERM_PRIVILEGED_RW
- * makes no sense. If the user mode is granted a given permission, then the
- * privileged mode is granted that permission as well, unless there is a
- * confliction. Some examples:
- * VM_PERM_USER_RO
- * grants RO status to both user and privileged modes.
- *
- * VM_PERM_USER_RO|VM_PERM_PRIVILEGED_RW
- * grants RO to the user, and RW to privileged modes.
- *
- * VM_PERM_USER_RW|VM_PERM_PRIVILEGED_RO
- * doesn't make sense. USER_RW grants RW to both user and privileged, but
- * PRIVILEGED_RO contradicts the USER_RW's implied grant.
- *
- * VM_ERR_BADPERM is returned if a bad permission is passed. Note that 0
- * is a valid permission, indicating that nobody may have access.
- *
- * (RO stands for Read-Only, RW for Read-Write)
- */
-#define VM_PERM_PRIVILEGED_RO 1
-#define VM_PERM_USER_RO 2
-#define VM_PERM_PRIVILEGED_RW 4
-#define VM_PERM_USER_RW 8
-
-void vm_init();
-
-/**
- * vm_allocate_page and vm_free_page allocate and free pages, and allow the
- * VAS to access them at the given virtual address (vptr).
- * Note that you cannot call free_page on a virtual address that was
- * mapped using set_mapping.
- * Return values:
- * 0 - success
- * VM_ERR_BADV - vptr was not a multiple of BLOCK_SIZE.
- * VM_ERR_MAPPED - vptr is already mapped in this VAS.
- * VM_ERR_BADPERM - permission is not valid (see above).
- *
- * free_page return values:
- * 0 - success
- * VM_ERR_BADV - vptr was not a multiple of BLOCK_SIZE.
- * VM_ERR_MAPPED - vptr was mapped using set_mapping, not allocate_page.
- * VM_ERR_NOT_MAPPED - vptr is not mapped in this VAS.
- */
-int vm_allocate_page(struct vas *vas, void *vptr, int permission);
-void *vm_allocate_pages(struct vas *vas, void *vptr, uint32_t nbytes, int permission);
-int vm_free_page(struct vas *vas, void *vptr);
-
-/**
- * vm_pin and vm_unpin currently do nothing. However, in the future, they will
- * prevent pages from being swapped out of physical memory.
- * Return values:
- * 0 - Success.
- */
-int vm_pin(struct vas *vas, void *vptr);
-int vm_unpin(struct vas *vas, void *vptr);
-
-/**
- * vm_set_mapping maps the given vptr to the given pptr.
- * Return values:
- * 0 - success
- * VM_ERR_BADV - vptr was not a multiple of BLOCK_SIZE.
- * VM_ERR_BADP - pptr was not a multiple of BLOCK_SIZE.
- * VM_ERR_MAPPED - vptr is already mapped in this VAS.
- * VM_ERR_BADPERM - permission is not valid.
- *
- * vm_free_mapping unmaps the vptr. Note that you may not call free_mapping
- * on a virtual address that was allocated using allocate_page.
- * Return values:
- * 0 - success
- * VM_ERR_BADV - vptr was not a multiple of BLOCK_SIZE.
- * VM_ERR_NOT_MAPPED - vptr was not mapped using set_mapping.
- */
-int vm_set_mapping(struct vas *vas, void *vptr, void *pptr, int permission);
-int vm_free_mapping(struct vas *vas, void *vptr);
-
-
-/* vm_swap_free_mapping is the spapping frameworks flavor on vm's vm_free_mapping
- * It takes in an extra paramter that will be set to the L2 page entry (instead of 0)
- * - Noel Negusse
- *
- * Returns: Same as vm_free_mapping
- */
-int vm_swap_free_mapping(struct vas*, void*, uint32_t*);
-
-
-/**
- * Will make the memory that accessible to other_vas at other_ptr
- * accessible to vas at this_ptr.
- * It can then be unmapped from either using a typical vm_free_mapping
- * or vm_free_page. The behavior of vm_free_mapping and vm_free_page
- * will be made equivalent.
- * For both, the behavior will be to free the frame if a frame was
- * allocated (via vm_allocate_page) and the page is not shared. If the
- * page is shared, then both will behave like vm_free_mapping.
- *
- * It is an error for other_ptr to point to an area not mapped in other_vas.
- *
- * For example, given vas1 and vas2:
- *
- * vm_allocate_page(vas2,0x10)
- * vm_map_shared_memory(vas1, 0x20, vas2, 0x10)
- * // Now vas1's 0x20 points to the same memory as vas2's 0x10
- * vm_free_page(vas2, 0x10)
- * // Now vas1 is the sole owner of the memory at vas1's 0x20
- * vm_free_mapping(vas1, 0x20)
- * // Now that frame has been freed
- *
- * All the pointers have to be a multiple of BLOCK_SIZE.
- *
- * Return values:
- * 0 - success
- * VM_ERR_BADV - this_ptr was not a multiple of BLOCK_SIZE.
- * VM_ERR_BADP - other_ptr was not a multiple of BLOCK_SIZE.
- * VM_ERR_NOT_MAPPED - other_ptr is not mapped in other_vas.
- * VM_ERR_MAPPED - this_ptr is already mapped in vas.
- * VM_ERR_BADPERM - permission is bad.
- */
-int vm_map_shared_memory(struct vas *vas, void *this_ptr, struct vas *other_vas, void *other_ptr, int permission);
-
-/**
- * This enabled the given VAS.
- */
-void vm_enable_vas(struct vas *vas);
-
-/**
- * Allocates a new VAS.
- *
- * Note that there is a limit of 4096 VASs in the system, including the
- * kernel's VAS.
- */
-struct vas *vm_new_vas();
-int vm_free_vas(struct vas *vas);
-
-/**
- * Retrieves a reference to the currently running VAS.
- */
-struct vas *vm_get_current_vas();
-
-/**
- * Switches to the kernel's VAS.
- */
-void vm_use_kernel_vas();
-
-static inline void ensure_kernel_vas()
-{
- assert (vm_get_current_vas() == KERNEL_VAS && "Must run in kernel VAS!");
-}
-
-void vm_test();
-
-static inline void vm_invalidate_tlb(void)
-{
- // Invalidate the TLB
- asm volatile("mcr p15, 0, %[r], c8, c5, 0" : : [r] "r" (0x0));
- asm volatile("mcr p15, 0, %[r], c8, c6, 0" : : [r] "r" (0x0));
- asm volatile("mcr p15, 0, %[r], c8, c7, 0" : : [r] "r" (0x0));
-}
-
-#endif
diff --git a/kernel/interrupt.c b/kernel/interrupt.c
deleted file mode 100644
index c33d1c2a..00000000
--- a/kernel/interrupt.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- *
- * Interrupts
- *
- */
-#include "interrupt.h"
-#include "klibc.h"
-#include "drivers/timer.h"
-
-// there are 32 kinds of interrupts on the VIC
-// this structure may need to be expanded if the secondary controller is incorporated
-static interrupt_handler_t *handlers[MAX_NUM_INTERRUPTS];
-
-static int initialized;
-
-// holds defined fiq interrupts
-static int check_if_fiq[MAX_NUM_INTERRUPTS];
-
-// define interrupt types
-interrupt_t IRQ = IRQ_MASK;
-interrupt_t FIQ = FIQ_MASK;
-interrupt_t ALL = ALL_INTERRUPT_MASK;
-
-// In a system with an interrupt controller, software is required to:
-// determine from the interrupt controller which interrupt source is requesting service
-// determine where the service routine for that interrupt source is loaded
-// mask or clear that interrupt source, before re-enabling processor interrupts to permit another interrupt to be taken.
-
-// Interrupts must be enabled in three places:
-// (1) the core (CPSR)
-// (2) the VIC (interrupt controller)
-// (3) (sometimes) in the device (this should be done in the device driver)
-
-// CLear Interrupts
-// Do not disable the VIC and the CSPR is disable in the hw_hanlders
-// you have to clear the interrupt from the register handler
-// Look At timer.c it has a great example of it.
-// Here's the Website to the VIC we are using http://infocenter.arm.com/help/topic/com.arm.doc.ddi0181e/DDI0181.pdf
-
-//They are three handlers you must use First is the (IRQ)interrupt handler its in hw_handlers.c (with attribute Irq)
-// second is the ISR routine handler which is the one in interrupt.c
-// third is the specific handler you created a great example is in the timer.c it is called timer_interrupt_handler.
-// If youre having an error it must be in the third handler not the first two.
-
-// Setup FIQ interrupts
-void init_fiqs()
-{
- check_if_fiq[11] = 1; // synchronous serial port
- check_if_fiq[17] = 1; // DMA controller
-}
-
-// when you register an interrupt handler it's line will be enabled in the VIC
-// telling the device itself to fire interrupts should be done in the driver
-//
-// also, since we don't really have a working malloc, the handler structure will
-// have to be built in the driver and passed to register_
-int register_interrupt_handler(int num, interrupt_handler_t *handler)
-{
- // lazy initialization
- if (initialized != -1)
- {
- os_printf("INITIALIZING THE INTERRUPT SYSTEM\n");
-
- for(int i=0; i MAX_NUM_INTERRUPTS) // bad irq number
- return -1;
- else if (handlers[num] != 0)
- { // something has already been registered there
- os_printf("Already registered\n");
- return -1;
- }
- else if (handler == 0) // we need a NULL macro
- return -1;
-
- // put the handler in the array
- handlers[num] = handler;
-
- // enable the specific interrupt in hardware on the VIC
- hw_interrupt_enable(num);
-
- // check to see if this is an FIQ
- if (check_if_fiq[num])
- // update the "select" register on the VIC
- vic_select_fiq(num);
-
- // return a success value
- return 0;
-}
-
-// handle_interrupt takes a number (the interrupt from the VIC), looks into
-// the table of registered handlers, and calls the appropriate handler
-void handle_irq_interrupt(int interrupt_vector)
-{
- os_printf("handling interrupt %d\n", interrupt_vector);
- // go to handler routine
- os_printf("Jumping to %X...\n", handlers[interrupt_vector]->handler);
- handlers[interrupt_vector]->handler((void *) interrupt_vector);
-
-}
-
-/* enable IRQ and/or FIQ */
-void enable_interrupt(interrupt_t mask)
-{
- get_proc_status();
-
- // enable interrupt on the core
- switch (mask)
- {
- case IRQ_MASK:
- asm volatile("cpsie i");
- break;
- case FIQ_MASK:
- asm volatile("cpsie f");
- break;
- case ALL_INTERRUPT_MASK:
- asm volatile("cpsie if");
- break;
- }
-}
-
-/* disable IRQ and/or FIQ */
-void disable_interrupt(interrupt_t mask)
-{
- // disable interrupts on the core
- switch (mask)
- {
- case IRQ_MASK:
- asm volatile("cpsid i");
- break;
- case FIQ_MASK:
- asm volatile("cpsid f");
- break;
- case ALL_INTERRUPT_MASK:
- asm volatile("cpsid if");
- break;
- }
-}
-
-/* disable IRQ and/or FIQ, but also return a copy of the CPSR */
-int disable_interrupt_save(interrupt_t mask)
-{
- /* get a copy of the current process status register */
- int cpsr;
- asm volatile("mrs %0, cpsr" : "=r"(cpsr));
- // disable interrupts on the core
- switch (mask)
- {
- case IRQ_MASK:
- asm volatile("cpsid i");
- break;
- case FIQ_MASK:
- asm volatile("cpsid f");
- break;
- case ALL_INTERRUPT_MASK:
- asm volatile("cpsid if");
- break;
- }
- return cpsr;
-}
-
-/* return a full 32-bit copy of the current process status register */
-int get_proc_status(void)
-{
- int cpsr;
- asm volatile("mrs %0, cpsr" : "=r"(cpsr));
- return cpsr;
-}
-
-/* restore control status (interrupt, mode bits) of the cpsr */
-/* (e.g. when we return from a handler, restore value from
- disable_interrupt_save */
-void restore_proc_status(int cpsr)
-{
- asm volatile("msr cpsr_c, %0" : : "r"(cpsr));
-}
-
diff --git a/kernel/kernel.ld b/kernel/kernel.ld
deleted file mode 100644
index 3670ea97..00000000
--- a/kernel/kernel.ld
+++ /dev/null
@@ -1,13 +0,0 @@
-ENTRY(_Reset)
-SECTIONS
-{
- . = 0x10000;
- .startup . : { startup.o(.text) }
- .text : { *(.text) }
- .data : { *(.data) }
- .bss : { *(.bss COMMON) }
- . = ALIGN(8);
- . = . + 0x1000;
- stack_top = .;
-}
-
diff --git a/kernel/kernelPi.ld b/kernel/kernelPi.ld
deleted file mode 100644
index 4b9b4529..00000000
--- a/kernel/kernelPi.ld
+++ /dev/null
@@ -1,12 +0,0 @@
-ENTRY(_Reset)
-SECTIONS
-{
- . = 0x8000;
- .startup . : { startup.o(.text) }
- .text : { *(.text) }
- .data : { *(.data) }
- .bss : { *(.bss COMMON) }
- . = ALIGN(8);
- . = . + 0x1000;
- stack_top = .;
-}
\ No newline at end of file
diff --git a/kernel/klibc.c b/kernel/klibc.c
deleted file mode 100644
index 889a1dae..00000000
--- a/kernel/klibc.c
+++ /dev/null
@@ -1,928 +0,0 @@
-/********************************************************************
- * klibc.c
- *
- * (Any collaborators, please add your name)
- * Author: Jared McArthur, Taylor Smith, Sheldon Sandbekkhaug, Kaelen Haag, Collin Massey
- *
- * Last edited: 4 December 2015
- *
- * Purpose: Provide basic libc funtionality for CourseOS
- * This file provides function implementations
- * for skels in libc.h
- *
- * Usage: Compile into kernel. Adaptations of normal libc functions
- * can be used by prepending os_ suffix.
- *
- * Notes: The following were adapted directly from musl-libc:
- * memcmp, memset, strcmp, strchrnul, strcpy, strlen, strtok
- ********************************************************************/
-#include
-#include
-
-#include "klibc.h"
-#include "global_defs.h"
-#include "mem_alloc.h"
-#include "interrupt.h"
-
-//FIXME: decouple
-#include "drivers/uart.h"
-
-#define LOWER_CASE 0
-#define UPPER_CASE 1
-#define NO_CASE 2
-
-// Helpers for MUSL String functions
-#define UCHAR_MAX 0xFF
-#define ALIGN (sizeof(os_size_t))
-#define ONES ((os_size_t)-1/UCHAR_MAX)
-#define HIGHS (ONES * (UCHAR_MAX/2+1))
-#define HASZERO(x) (((x)-ONES) & (~(x)) & HIGHS)
-
-static char lower_case_digits[16] = "0123456789abcdef";
-static char upper_case_digits[16] = "0123456789ABCDEF";
-
-/*4-17-15: - Prakash
- * panic() added
- - Currrently states the panic and stalls the machine
- */
-void panic()
-{
- disable_interrupts()
- ;
- //os_printf("Kernel panic!\n");
- os_printf("\n ) ( \n");
- os_printf(" ( /( ( )\\ ) \n");
- os_printf(" )\\()) ( ( ( )\\ (()/( ) ( \n");
- os_printf("|((_)\\ ))\\ )( ( ))((_) /(_)| /( ( )\\ ( \n");
- os_printf("|_ ((_)((_|()\\ )\\ ) /((_) (_)) )(_)) )\\ |(_) )\\ \n");
- os_printf("| |/ (_)) ((_)_(_/((_))| | | _ ((_)_ _(_/((_)((_) \n");
- os_printf(" ' -_)| '_| ' \\)) -_) | | _/ _` | ' \\)) / _| \n");
- os_printf(" _|\\_\\___||_| |_||_|\\___|_| |_| \\__,_|_||_||_\\__| ");
- SLEEP;
-}
-
-void splash()
-{
- os_printf(
- "\n\t ██████╗ ██████╗ ██╗ ██╗██████╗ ███████╗███████╗ ██████╗ ███████╗\n");
- os_printf(
- "\t██╔════╝██╔═══██╗██║ ██║██╔══██╗██╔════╝██╔════╝██╔═══██╗██╔════╝\n");
- os_printf(
- "\t██║ ██║ ██║██║ ██║██████╔╝███████╗█████╗ ██║ ██║███████╗\n");
- os_printf(
- "\t██║ ██║ ██║██║ ██║██╔══██╗╚════██║██╔══╝ ██║ ██║╚════██║\n");
- os_printf(
- "\t╚██████╗╚██████╔╝╚██████╔╝██║ ██║███████║███████╗╚██████╔╝███████║\n\n");
-}
-
-/*4-17-15: - Prakash
- _assert_fail() added
- - This is a helper function for the assert() macro
- */
-int _assert_fail(char *_file, unsigned int _line, char *_func)
-{
- os_printf("ASSERT FAILURE: %s:%u: %s\n", _file, _line, _func);
- panic();
- return 1;
-}
-
-/* string.h type functionality for comparing strings or mem blocks */
-int os_memcmp(const void *left, const void *right, os_size_t num)
-{
- const unsigned char *l = left, *r = right;
- for (; num && *l == *r; num--, l++, r++)
- ;
- return num ? *l - *r : 0;
-}
-
-int os_strcmp(const char *left, const char *right)
-{
- for (; *left == *right && *left; left++, right++)
- ;
- return *(unsigned char *) left - *(unsigned char *) right;
-}
-
-//memory copy
-//Responsibility is on the programmer to copy safely
-void os_memcpy(uint32_t * source, uint32_t * dest, os_size_t size)
-{
- int limit = size / sizeof(uint32_t);
-
- int i = 0;
- for (; i < limit; i += 1)
- {
- *(dest + i) = *(source + i);
- }
-
- char * d = (char*) (dest + i);
- char * s = (char*) (source + i);
-
- i *= sizeof(uint32_t);
-
- for (; i < size; i++)
- {
- *(d++) = *(s++);
- }
- source -= size;
- dest -= size;
-}
-
-// base is between 2 and 16, inclusive
-int print_int(char *buf, int buflen, int val, int base, int is_unsigned,
- int padding, char pad_char, int is_uppercase)
-{
- int max_len = buflen;
- int orig_max_len = max_len;
- int negate = 0;
- if (val < 0 && !is_unsigned)
- {
- val = -val;
- negate = 1;
- }
- unsigned int temp = val;
-
- if (max_len == 0)
- return orig_max_len - max_len;
- if (negate)
- {
- *buf = '-';
- buf++;
- max_len--;
- if (max_len == 0)
- return orig_max_len - max_len;
- }
-
- char tmp_buf[64];
- int ndigits = 0;
- while (temp != 0)
- {
- if (is_uppercase)
- {
- tmp_buf[ndigits] = upper_case_digits[temp % base];
- }
- else
- {
- tmp_buf[ndigits] = lower_case_digits[temp % base];
- }
- temp = temp / base;
- ndigits++;
- }
-
- // Zero-pad the output
- int i;
- if (padding > 0)
- {
- for (i = 0; i < padding - ndigits - negate; i++)
- {
- *buf = pad_char;
- buf++;
- max_len--;
- if (max_len == 0)
- return orig_max_len;
- }
- }
-
- // Output the digits
- for (i = ndigits - 1; i >= 0; i--)
- {
- *buf = tmp_buf[i];
- buf++;
- max_len--;
- if (max_len == 0)
- return orig_max_len;
- }
- if (ndigits == 0 && padding <= 0)
- {
- *buf = '0';
- buf++;
- max_len--;
- if (max_len == 0)
- return orig_max_len;
- }
-
- return orig_max_len - max_len;
-}
-
-// args must already have been started
-int os_vsnprintf(char *buf, int buflen, const char *str_buf, va_list args)
-{
- if (buflen == 0)
- return 0;
- buflen--;
- if (buflen == 0)
- {
- buf[0] = 0;
- return 1;
- }
- int nwritten = 0;
- int t_arg;
- char* str_arg;
- int padding = -1;
- char pad_char = 0;
- while (*str_buf != '\0')
- {
- int n;
- if (*str_buf == '%')
- {
- str_buf++;
- // This label is where we go after we've read an option.
- reread_switch: ;
- switch (*str_buf)
- {
- case '0':
- // Zero-padding... Read all the numbers.
- // Then restart the switch statement.
- padding = 0;
- pad_char = '0';
- while (*str_buf <= '9' && *str_buf >= '0')
- {
- padding *= 10;
- padding += *str_buf - '0';
- str_buf++;
- }
- goto reread_switch;
- break;
- case 'X':
- t_arg = va_arg(args, int);
- n = print_int(buf, buflen, t_arg, 16, 1, padding, pad_char, 1);
- break;
- case 'x':
- t_arg = va_arg(args, int);
- n = print_int(buf, buflen, t_arg, 16, 1, padding, pad_char, 0);
- break;
- case 'd':
- t_arg = va_arg(args, int);
- n = print_int(buf, buflen, t_arg, 10, 0, padding, pad_char, 0);
- break;
- case 'u':
- t_arg = va_arg(args, int);
- n = print_int(buf, buflen, t_arg, 10, 1, padding, pad_char, 0);
- break;
- case 'c':
- t_arg = va_arg(args, int);
- *buf = t_arg;
- n = 1;
- break;
- case 's':
- str_arg = va_arg(args, char*);
- os_strncpy(buf, str_arg, buflen);
- n = os_strlen(str_arg);
- if (n > buflen)
- {
- n = buflen;
- }
- break;
- case '%':
- *buf = '%';
- n = 1;
- break;
- }
- // Reset all the options
- padding = -1;
- }
- else
- {
- *buf = *str_buf;
- n = 1;
- }
- buf += n;
- buflen -= n;
- nwritten += n;
- if (buflen <= 0)
- {
- //Return!
- break;
- }
- str_buf++;
- }
- buf[0] = 0;
- nwritten++;
-
- return nwritten;
-}
-
-int os_snprintf(char *buf, int buflen, const char *fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
- int n = os_vsnprintf(buf, buflen, fmt, args);
- va_end(args);
- return n;
-}
-
-int os_printf(const char *str_buf, ...){
-va_list args;
-va_start(args, str_buf);
-char buf[256];
-int n = os_vsnprintf(buf, 255, str_buf, args);
-va_end(args);
-print_uart0(buf);
-return n;
-}
-
-/* Set the first n bytes of dest to be the value c.*/
-void *os_memset(void *dest, char c, os_size_t n)
-{
- unsigned char *s = dest;
- os_size_t k;
-
- /* Fill head and tail with minimal branching. Each
- * conditional ensures that all the subsequently used
- * offsets are well-defined and in the dest region. */
-
- if (!n)
- return dest;
- s[0] = s[n - 1] = c;
- if (n <= 2)
- return dest;
- s[1] = s[n - 2] = c;
- s[2] = s[n - 3] = c;
- if (n <= 6)
- return dest;
- s[3] = s[n - 4] = c;
- if (n <= 8)
- return dest;
-
- /* Advance pointer to align it at a 4-byte boundary,
- * and truncate n to a multiple of 4. The previous code
- * already took care of any head/tail that get cut off
- * by the alignment. */
-
- k = -(uintptr_t) s & 3;
- s += k;
- n -= k;
- n &= -4;
-
-#ifdef __GNUC__
- typedef uint32_t __attribute__((__may_alias__)) u32;
- typedef uint64_t __attribute__((__may_alias__)) u64;
-
- u32 c32 = ((u32) -1) / 255 * (unsigned char) c;
-
- /* In preparation to copy 32 bytes at a time, aligned on
- * an 8-byte bounary, fill head/tail up to 28 bytes each.
- * As in the initial byte-based head/tail fill, each
- * conditional below ensures that the subsequent offsets
- * are valid (e.g. !(n<=24) implies n>=28). */
-
- *(u32 *) (s + 0) = c32;
- *(u32 *) (s + n - 4) = c32;
- if (n <= 8)
- return dest;
- *(u32 *) (s + 4) = c32;
- *(u32 *) (s + 8) = c32;
- *(u32 *) (s + n - 12) = c32;
- *(u32 *) (s + n - 8) = c32;
- if (n <= 24)
- return dest;
- *(u32 *) (s + 12) = c32;
- *(u32 *) (s + 16) = c32;
- *(u32 *) (s + 20) = c32;
- *(u32 *) (s + 24) = c32;
- *(u32 *) (s + n - 28) = c32;
- *(u32 *) (s + n - 24) = c32;
- *(u32 *) (s + n - 20) = c32;
- *(u32 *) (s + n - 16) = c32;
-
- /* Align to a multiple of 8 so we can fill 64 bits at a time,
- * and avoid writing the same bytes twice as much as is
- * practical without introducing additional branching. */
-
- k = 24 + ((uintptr_t) s & 4);
- s += k;
- n -= k;
-
- /* If this loop is reached, 28 tail bytes have already been
- * filled, so any remainder when n drops below 32 can be
- * safely ignored. */
-
- u64 c64 = c32 | ((u64) c32 << 32);
- for (; n >= 32; n -= 32, s += 32)
- {
- *(u64 *) (s + 0) = c64;
- *(u64 *) (s + 8) = c64;
- *(u64 *) (s + 16) = c64;
- *(u64 *) (s + 24) = c64;
- }
-#else
- /* Pure C fallback with no aliasing violations. */
- for (; n; n--, s++) *s = c;
-#endif
-
- return dest;
-}
-
-/* Returns a pointer to the first instance of c in s, like indexOf().
- If c is not found, then return a pointer to the NULL character at
- the end of String s.
- */
-char *__strchrnul(const char *s, char c)
-{
- os_size_t *w, k;
-
- if (!c)
- return (char *) s + os_strlen(s);
-
- for (; (uintptr_t) s % ALIGN; s++)
- if (!*s || *(unsigned char *) s == c)
- return (char *) s;
- k = ONES * c;
- for (w = (void *) s; !HASZERO(*w) && !HASZERO(*w ^ k); w++)
- ;
- for (s = (void *) w; *s && *(unsigned char *) s != c; s++)
- ;
- return (char *) s;
-}
-
-/* Copies the String src to dest */
-char *os_strcpy(char *dest, const char *src)
-{
- const unsigned char *s = (const unsigned char*) src;
- unsigned char *d = (unsigned char*) dest;
- while ((*d++ = *s++))
- ;
- return dest;
-}
-
-/* Copies the String src to dest */
-char *os_strncpy(char *dest, const char *src, os_size_t n)
-{
- const unsigned char *s = (const unsigned char*) src;
- unsigned char *d = (unsigned char*) dest;
- while ((*d++ = *s++) && n--)
- ;
- return dest;
-}
-
-/* Return the length of s */
-os_size_t os_strlen(const char *s)
-{
- const char *a = s;
- const os_size_t *w;
- for (; (uintptr_t) s % ALIGN; s++)
- if (!*s)
- return s - a;
- for (w = (const void *) s; !HASZERO(*w); w++)
- ;
- for (s = (const void *) w; *s; s++)
- ;
- return s - a;
-}
-
-/* A re-entrant function that returns a substring of s. The substring starts
- at the beginning of the string or the previous index of one of the
- delimiter characters (indicated by sep). The substring ends at the next
- delimeter character (indicated by sep).
- */
-char *os_strtok(char *s, const char *sep)
-{
- static char *p;
- if (!s && !(s = p))
- return NULL;
- s += os_strspn(s, sep);
- if (!*s)
- return p = 0;
- p = s + os_strcspn(s, sep);
- if (*p)
- *p++ = 0;
- else
- p = 0;
- return s;
-}
-
-/* Returns the length of the initial segment of s that only includes
- the characters in c.
- */
-os_size_t os_strspn(const char *s, const char *accept)
-{
- char c = s[0]; // The character in s being checked
- int length = 0;
-
- // Check each character in s
- while (c != 0)
- {
- Boolean ok = FALSE;
-
- // Check against each character in accept
- int i;
- for (i = 0; i < os_strlen(accept); i++)
- {
- if (c == accept[i])
- {
- ok = TRUE;
- }
- }
-
- if (ok == TRUE)
- {
- // If c matched any character in accept, continue
- length++;
- c = s[length];
- }
- else
- {
- // If did not match any character in accept, we are done
- return length;
- }
- }
- return length;
-}
-
-/* Returns the length of the initial segment of s that does not contain
- any characters in string c.
- */
-os_size_t os_strcspn(const char *s, const char *reject)
-{
- char c = s[0]; // The character in s being checked
- int length = 0;
-
- // Check each character in s
- while (c != 0)
- {
- // Check against each character in reject
- int i;
- for (i = 0; i < os_strlen(reject); i++)
- {
- if (c == reject[i])
- {
- return length;
- }
- }
-
- // If c did not match any reject characters, continue
- length++;
- c = s[length];
- }
- return length;
-}
-
-int32_t abs(int32_t val)
-{
- const int32_t mask = val >> sizeof(int32_t) * (NBBY - 1);
- return (val + mask) ^ mask;
-}
-
-// Return string converted to int form, or 0 if not applicable
-// Necessary comments provided in atof() (next function)
-int katoi(const char *string)
-{
- if (!string)
- return 0;
-
- int integer = 0;
- int sign = 1;
-
- if (*string == '-')
- {
- sign = -1;
- string++;
- }
- else if (*string == '+')
- {
- string++;
- }
-
- while (*string != '\0')
- {
- if (*string >= '0' && *string <= '9')
- {
- integer *= 10;
- integer += (*string - '0');
- }
- else
- {
- return 0;
- }
- }
- return sign * integer;
-}
-
-// Return string converted to double form, or 0 if not applicable
-double katof(const char *string)
-{
- if (!string)
- return 0.0;
-
- double integer = 0.0; // before decimal
- double fraction = 0.0; // after decimal
- int sign = 1; // positive or negative?
- int divisor = 1; // used to push fraction past decimal point
- Boolean after_decimal = FALSE; // decimal point reached?
-
- // Check if string includes sign (including a "+")
- if (*string == '-')
- {
- sign = -1;
- string++; // progress to next char
- }
- else if (*string == '+')
- {
- string++;
- }
-
- while (*string != '\0')
- {
- if (*string >= '0' && *string <= '9')
- {
- if (after_decimal)
- {
- fraction *= 10; // progress to next position in integer
- fraction += (*string - '0'); // add integer form of current number in string
- divisor *= 10;
- }
- else
- {
- integer *= 10; // progress to next position in integer
- integer += (*string - '0'); // add integer form of current number in string
- }
- }
- else if (*string == '.')
- {
- if (after_decimal)
- return 0.0; // more than one '.'
- after_decimal = TRUE;
- }
- else
- {
- return 0.0; // current char in string is not a number or '.'
- }
- string++;
- }
- return sign * (integer + (fraction / divisor));
-}
-
-// Return string converted to long int form, or 0 if not applicable
-long int katol(const char *string)
-{
- return (long int) katoi(string);
-}
-
-/*
-// Same as katof, but makes endptr point to the string which comes after the number
-double kstrtod(const char *string, char **endptr)
-{
- if (!string)
- return 0.0;
-
- double integer = 0.0;
- double fraction = 0.0;
- int sign = 1;
- int divisor = 1;
- Boolean after_decimal = FALSE;
- Boolean result_found = FALSE;
- double result = 0.0;
-
- if (*string == '-')
- {
- sign = -1;
- string++;
- }
- else if (*string == '+')
- string++;
-}
-
-while (!result_found)
-{
- if (*string >= '0' && *string <= '9')
- {
- if (after_decimal)
- {
- fraction *= 10;
- fraction += (*string - '0');
- divisor *= 10;
- }
- else
- {
- integer *= 10;
- integer += (*string - '0');
- }
- string++;
- }
- else if (*string == '.')
- {
- if (after_decimal)
- return 0.0;
- after_decimal = true;
- string++;
- }
- else
- {
- result = sign * (integer + (fraction/divisor));
- result_found = true;
- }
-}
-
-*endptr = string;
-
-return result;
-}
-*/
-
-//Same as katol, but makes endptr point to the string which comes after the number
-long int kstrtol(const char *string, char **endptr)
-{
-if (!string)
- return 0;
-
-long int integer = 0;
-long int result = 0;
-Boolean result_found = FALSE;
-int sign = 1;
-
-if (*string == '-')
-{
- sign = -1;
- string++;
-}
-else if (*string == '+')
-{
- string++;
-}
-
-while (!result_found)
-{
- if (*string >= '0' && *string <= '9')
- {
- integer *= 10;
- integer += (*string - '0');
- string++;
- }
- else
- {
- result = sign * integer;
- result_found = TRUE;
- }
-}
-*endptr = (char*) string;
-
-return result;
-}
-
-void *kmalloc(uint32_t size)
-{
-void* block = (void*) allocate(size, 0 /* unused */, 0 /* unused */);
-return block;
-}
-
-// Allocates n * size portion of memory (set to 0) and returns it
-void *kcalloc(uint32_t n, uint32_t size)
-{
-uint32_t total_size = n * size;
-void* block = kmalloc(total_size);
-
-return block ? os_memset(block, 0, total_size) : NULL;
-}
-
-uint32_t kmcheck()
-{
-return mem_check();
-}
-
-// NOTE potentially expand these features. offer more
-// memory stats
-uint32_t km_size()
-{
-return mem_get_heap_size();
-}
-
-void* kmalloc_aligned(uint32_t size, uint32_t alignment)
-{
-void* block;
-void* ptr;
-
-switch (alignment)
-{
-case 4:
- block = kmalloc(size + 4);
- ptr = (void*) (((uint32_t) block + 4) & ~0x3);
- return ptr;
-case 1024:
- block = kmalloc(size + 1024);
- ptr = (void*) (((uint32_t) block + 1024) & ~0x1ff);
- return ptr;
-case 4096:
- block = kmalloc(size + 4096);
- ptr = (void*) (((uint32_t) block + 4096) & ~0x7ff);
- return ptr;
-case 16 * 1024:
- block = kmalloc(size + 16 * 1024);
- ptr = (void*) (((uint32_t) block + 16 * 1024) & ~0x1fff);
- return ptr;
-default:
- return kmalloc(size);
-}
-}
-
-void kfree(void* ptr)
-{
-deallocate((uint32_t*) ptr, 0 /* unused */, 0 /* unused */);
-}
-
-// FIXME: Implement kmalloc_size() (or something like it)
-// Resize memory pointed to by ptr to new size
-void *krealloc(void *ptr, uint32_t size)
-{
-if (!ptr)
- return kmalloc(size);
-
-if (size == 0)
-{
- kfree(ptr);
- return NULL;
-}
-
-/* I'm not sure how to implement kmalloc_size(),
- * which returns the size of the block pointed
- * to by a pointer, without keeping track of
- * the size of the block pointed to whenever
- * kmalloc() is called, or by defining it
-
- uint32_t msize = kmalloc_size(ptr);
- if (msize >= size)
- return ptr;
-
-
- void *new_ptr = kmalloc(size);
- os_memcpy(new_ptr, ptr, msize);
- return new_ptr; */
-
-return ptr;
-}
-
-unsigned int rand()
-{
-static unsigned int z1 = 12345, z2 = 67891, z3 = 11121, z4 = 31415;
-unsigned int b;
-b = ((z1 << 6) ^ z1) >> 13;
-z1 = ((z1 & 4294967294U) << 18) ^ b;
-b = ((z2 << 2) ^ z2) >> 27;
-z2 = ((z2 & 4294967288U) << 2) ^ b;
-b = ((z3 << 13) ^ z3) >> 21;
-z3 = ((z3 & 4294967280U) << 7) ^ b;
-b = ((z4 << 3) ^ z4) >> 12;
-z4 = ((z4 & 4294967168U) << 13) ^ b;
-return (z1 ^ z2 ^ z3 ^ z4);
-}
-
-/**
- * umalloc allocates memory on the user heap
- *
- * @param size of the block of memory allocated
- * @param uint32_t size
- * @return returns a pointer to the allocated block of memory
- */
-void* umalloc(uint32_t size)
-{
-void* block = (void*) proc_allocate(size);
-return block;
-}
-
-/**
- * ualigned alloc allocates memory on the user heap
- * according to a specified alignemnt
- *
- * @param size of the block of memory allocated, and alignment desired
- * @param uint32_t size, uint32_alignment
- * @return returns a pointer to the allocated block of memory
- * that is a multiple of the specified allignement
- */
-
-void* ualigned_alloc(uint32_t size, uint32_t alignment)
-{
-void* block;
-void* ptr;
-
-switch (alignment)
-{
-case 4:
- block = umalloc(size + 4);
- ptr = (void*) (((uint32_t) block + 4) & ~0x3);
- return ptr;
-case 1024:
- block = umalloc(size + 1024);
- ptr = (void*) (((uint32_t) block + 1024) & ~0x1ff);
- return ptr;
-case 4096:
- block = umalloc(size + 4096);
- ptr = (void*) (((uint32_t) block + 4096) & ~0x7ff);
- return ptr;
-case 16 * 1024:
- block = umalloc(size + 16 * 1024);
- ptr = (void*) (((uint32_t) block + 16 * 1024) & ~0x1fff);
- return ptr;
-default:
- return umalloc(size);
-}
-}
-
-/**
- * free's an allocated block of memory on the heap
- *
- * @param pointer to a block of memeory on the heap
- * @param void* ptr
- * @return nothing returned
- */
-void ufree(void* ptr)
-{
-proc_deallocate((uint32_t*) ptr);
-}
diff --git a/kernel/loader.c b/kernel/loader.c
deleted file mode 100644
index 0f4ad1f7..00000000
--- a/kernel/loader.c
+++ /dev/null
@@ -1,76 +0,0 @@
-#include
-#include "loader.h"
-#include "mem_alloc.h"
-#include "klibc.h"
-#include "process.h"
-#include "elf.h"
-
-//Worked on by Kaelen Haag and Jeremy Wenzel
-//We determine what the size of our process is going to be
-//Determine the size of the segments that need to be loaded in (has p_type == PT_LOAD)
-//Account for the other stuff we'll need (Stack, Heap, spacing)
-os_size_t det_proc_size(Elf_Ehdr *h, Elf_Phdr ph[])
-{
- os_size_t process_size = 0;
- int i = 0;
- //Add up the size of all the necessary sections that
- for (; i < (h->e_phnum); i++)
- {
- if (ph[i].p_type == PT_LOAD)
- {
- process_size += ph[i].p_memsz;
- }
- }
-
- process_size += USER_PROC_STACK_SIZE;
- process_size += USER_PROC_HEAP_SIZE; //This is going to be the heap size (need to determine what this should be
-
- //Padding we want to be able to have some padding between certain sections of the program
- //mainly the stack from the other parts
- process_size += PADDING;
-
- return process_size;
-
-}
-
-//Probably want to return a memory address rather than nothing.
-//Take a process control block and pointer to the start of an ELF file in memory.
-Elf_Ehdr* load_file(pcb * pcb_p, uint32_t * file_pointer)
-{
- Elf_Ehdr *h = (Elf_Ehdr *) kmalloc(sizeof(Elf_Ehdr)); // Get elf header
- os_printf("elf header= %x\n", h);
- int i = read_elf_header(h, (unsigned char *) file_pointer);
-
- if (i == -1)
- {
- os_printf("File is Not an ELF File. Exiting\n");
- return 0;
- }
-
- if (h->e_phnum == 0)
- {
- os_printf("No Program headers in ELF file. Exiting\n");
- return 0;
- }
-
- Elf_Phdr * ph = (Elf_Phdr *) kmalloc(h->e_phnum * sizeof(Elf_Phdr));
- Elf_Shdr * sh = (Elf_Shdr *) kmalloc(h->e_shnum * sizeof(Elf_Shdr));
- // FIXME: why is sh not used?
- UNUSED(sh);
- read_program_header_table(h, ph, (unsigned char *) file_pointer);
-
- //allocate pages for the read only segment
-
- //allocate pages for text section
-
- //assert(1 == 2 && "load_file");
-
- //read_section_header_table(h, sh, (uint32_t*)file_pointer);
- // /vm_enable_vas(pcb_p->stored_vas);
-
- //allocate_process_memory(pcb_p, h, ph, file_pointer);
-
- //vm_use_kernel_vas();
- return h;
-}
-
diff --git a/kernel/memory/allocator.c b/kernel/memory/allocator.c
deleted file mode 100644
index e665f193..00000000
--- a/kernel/memory/allocator.c
+++ /dev/null
@@ -1,324 +0,0 @@
-#include "global_defs.h"
-#include "klibc.h"
-#include "allocator.h"
-
-uint32_t* __alloc_extend_heap(alloc_handle*allocator, uint32_t amount);
-
-/*
- * The kernel heap is organized in blocks. Each block has a header and a
- * footer each a 4 byte integer, at the beginning and end of the block.
- * The header and footer both specify the size of the block in question.
- * Used blocks are indicated by the heap header and the heap footer being
- * negative.
- *
- * To allocate a block, we start at the first block and walk through each
- * one, finding the first free block large enough to support a header,
- * footer, and the size requested.
- *
- * To free a block, we do a bunch of merging stuff to check to see if we
- * should merge with the blocks on the left or right of us, respectively.
- */
-alloc_handle* alloc_create(uint32_t * buffer, uint32_t buffer_size,
- heap_extend_handler extend_handler) {
-
- if (buffer_size <= sizeof(alloc_handle)) {
- return 0;
- }
-
- alloc_handle* alloc_handle_ptr = (alloc_handle*) buffer;
-
- // storing the alloc_handle struct
- // inside the heading of the buffer
- alloc_handle_ptr->heap = ((void*) buffer) + sizeof(alloc_handle);
- alloc_handle_ptr->heap_size = buffer_size - sizeof(alloc_handle);
- alloc_handle_ptr->extend_handler = extend_handler;
-
- uint32_t* heap_header = alloc_handle_ptr->heap;
- uint32_t* heap_footer = (uint32_t*) ((void*) alloc_handle_ptr->heap
- + alloc_handle_ptr->heap_size - sizeof(int));
-
- *heap_header = alloc_handle_ptr->heap_size - 2 * sizeof(uint32_t);
- *heap_footer = alloc_handle_ptr->heap_size - 2 * sizeof(uint32_t);
-
- return alloc_handle_ptr;
-}
-
-alloc_handle* alloc_create_fixed(uint32_t * buffer, uint32_t buffer_size) {
- return alloc_create(buffer, buffer_size, NULL);
-}
-
-// TODO: what if there's an error allocating the page?
-// Returns a pointer to the new (big) free block's header
-uint32_t* __alloc_extend_heap(alloc_handle*allocator, uint32_t amount) {
- if(!allocator->extend_handler) {
- return 0;
- }
-
- uint32_t start_size = allocator->heap_size;
- uint32_t amount_added = allocator->extend_handler(amount);
-
- if (amount_added <= 0) {
- return 0;
- }
-
- // Now extend the footer block
- int32_t *orig_footer = (int32_t*) ((void*) allocator->heap + start_size
- - sizeof(uint32_t));
-
- allocator->heap_size += amount_added;
-
- // If it's free, simply move it (and update the header)
- // If it's used, add a free block to the end
- if (*orig_footer > 0) {
- uint32_t *orig_header = (uint32_t*) ((void*) allocator->heap
- + start_size - 2 * sizeof(uint32_t) - *orig_footer);
- uint32_t *new_footer = (uint32_t*) ((void*) allocator->heap
- + allocator->heap_size - sizeof(uint32_t));
-
- *new_footer = *orig_footer + amount_added;
- *orig_header += amount_added;
- return orig_header;
- } else {
-
- uint32_t *new_header = (uint32_t*) ((void*) allocator->heap + start_size);
- uint32_t *new_footer = (uint32_t*) ((void*) allocator->heap
- + allocator->heap_size - sizeof(uint32_t));
- *new_header = amount_added - 2 * sizeof(uint32_t);
- *new_footer = amount_added - 2 * sizeof(uint32_t);
- return new_header;
- }
-
- return 0x0;
-}
-
-void* alloc_allocate(alloc_handle * allocator, uint32_t size) {
- int32_t i, ret_ptr;
-
- for (i = 0; i < allocator->heap_size;) {
- uint32_t* header_addr = (uint32_t*) ((void*) allocator->heap + i);
- int32_t header = *header_addr;
-
- uint32_t* footer_addr = (uint32_t*) ((void*) allocator->heap + i
- + sizeof(int32_t) + size);
-
- //free and >= request
- if (header > 0 && header >= size) {
- //cannot split this block
- if (header < (size + 2 * sizeof(int32_t) + sizeof(char))) {
- footer_addr = (uint32_t*) ((void*) allocator->heap + i
- + sizeof(int32_t) + abs(header));
-
- ret_ptr = i + sizeof(int32_t);
- //mark header as used
- *header_addr = header * (-1);
- //insert a footer at end of block
- *footer_addr = header * (-1);
- return (uint32_t*) ((void*) allocator->heap + ret_ptr);
-
- }
-
- //can split this block
- else {
- ret_ptr = i + sizeof(int32_t);
-
- int32_t old_space = header;
- int32_t occ_space = size + 2 * sizeof(int32_t);
- //mark header as used
- *header_addr = size * (-1);
- //insert footer
- *footer_addr = size * (-1);
-
- //insert new free block header
- uint32_t* new_header = (uint32_t*) ((void*) allocator->heap + i
- + 2 * sizeof(int32_t) + size);
- *new_header = old_space - occ_space;
- //insert new free block footer
- uint32_t* new_footer = (uint32_t*) ((void*) allocator->heap + i
- + sizeof(int32_t) + old_space);
- *new_footer = old_space - occ_space;
-
- return (uint32_t*) ((void*) allocator->heap + ret_ptr);
- }
- }
- //jump to the next block
- else {
- i = i + abs(header) + 2 * sizeof(int32_t);
- }
- }
-
- // Allocate some more memory.
- uint32_t new_amt = size + 2 * sizeof(uint32_t);
- uint32_t *header = __alloc_extend_heap(allocator, new_amt);
-
- if (header == 0) {
- return 0;
- }
-
- // Recursive call. TODO: (relatively) Inefficient
- return alloc_allocate(allocator, size);
-}
-
-void alloc_deallocate(alloc_handle* allocator, void* ptr) {
- uint32_t first_block = 0;
- uint32_t last_block = 0;
-
- uint32_t* header_addr = (uint32_t*) ((void*) ptr - sizeof(int32_t));
- uint32_t size = abs(*header_addr);
-
- uint32_t* footer_addr = (uint32_t*) ((void*) ptr + size);
-
- if (header_addr == allocator->heap) {
- first_block = 1;
- }
-
- if (footer_addr + sizeof(int32_t)
- == (void*) allocator->heap + allocator->heap_size) {
- last_block = 1;
- }
-
- //os_printf("Freeing %d-sized block at %X. first/last=%d/%d\n", size, header_addr, first_block,last_block);
-
- //only check and coalesce right block
- if (first_block) {
- uint32_t* right_header_addr = (uint32_t*) ((void*) footer_addr
- + sizeof(int32_t));
- int32_t right_block_size = *right_header_addr;
-
- //free right block
- if (right_block_size > 0) {
- //set new header at freed blocks header
- *header_addr = size + right_block_size + 2 * sizeof(int32_t);
- //set new footer at right blocks footer
- uint32_t* right_footer_addr = (uint32_t*) ((void*) footer_addr
- + 2 * sizeof(int32_t) + right_block_size);
- *right_footer_addr = size + right_block_size + 2 * sizeof(int32_t);
- } else {
- //make freed blocks header and footer positive
- *header_addr = size;
- *footer_addr = size;
- }
- }
-
- //only check and coalesce left block
- if (last_block) {
- uint32_t* left_block_header = (uint32_t*) ((void*) header_addr
- - sizeof(int32_t));
- int32_t left_block_size = *left_block_header;
-
- //free left block
- if (left_block_size > 0) {
- //set new header at left blocks header
- uint32_t* left_header_addr = (uint32_t*) ((void*) header_addr
- - 2 * sizeof(int32_t) - left_block_size);
- *left_header_addr = size + left_block_size + 2 * sizeof(int32_t);
- //set new footer at freed blocks footer
- *footer_addr = size + left_block_size + 2 * sizeof(int32_t);
- } else {
- *header_addr = size;
- *footer_addr = size;
- }
- }
-
- //check and coalesce both adjacent blocks
- if (!first_block && !last_block) {
- uint32_t* right_block_header = (uint32_t*) ((void*) footer_addr
- + sizeof(int32_t));
- int32_t right_block_size = *right_block_header;
-
- uint32_t* left_block_header = (uint32_t*) ((void*) header_addr
- - sizeof(int32_t));
- int32_t left_block_size = *left_block_header;
- //os_printf("left/right sizes are %d/%d, size=%d\n", left_block_size, right_block_size, size);
-
- //both adjacent blocks are free
- if (right_block_size > 0 && left_block_size > 0) {
- int32_t new_size = size + right_block_size + left_block_size
- + 4 * sizeof(int32_t);
-
- //set new header at left blocks header
- uint32_t* left_header_addr = (uint32_t*) ((void*) header_addr
- - 2 * sizeof(int32_t) - left_block_size);
- *left_header_addr = new_size;
- //set new footer at right blocks footer
- uint32_t* right_footer_addr = (uint32_t*) ((void*) footer_addr
- + 2 * sizeof(int32_t) + right_block_size);
- *right_footer_addr = new_size;
- }
-
- //only right free block
- else if (right_block_size > 0 && left_block_size < 0) {
- //set new header at freed blocks header
- *header_addr = size + right_block_size + 2 * sizeof(int32_t);
- //set new footer at right blocks footer
- uint32_t* right_footer_addr = (uint32_t*) ((void*) footer_addr
- + 2 * sizeof(int32_t) + right_block_size);
- *right_footer_addr = size + right_block_size + 2 * sizeof(int32_t);
- }
- //only left free block
- else if (left_block_size > 0 && right_block_size < 0) {
- //set new header at left blocks header
- uint32_t* left_header_addr = (uint32_t*) ((void*) header_addr
- - 2 * sizeof(int32_t) - left_block_size);
- *left_header_addr = size + left_block_size + 2 * sizeof(int32_t);
- //set new footer at freed blocks footer
- *footer_addr = size + left_block_size + 2 * sizeof(int32_t);
- } else {
- *header_addr = size;
- *footer_addr = size;
- }
-
- }
-}
-
-/**
- * Returns 0 on success. -1 on error.
- */
-int alloc_check(alloc_handle* allocator) {
- char* ptr = (char*) allocator->heap;
- uint32_t* end_ptr = (uint32_t*) ((void*) allocator->heap
- + allocator->heap_size);
- int i, block = 0;
-
- LOG("Checking memory...\n");
- for (i = 0; i < allocator->heap_size; i += 0) {
- uint32_t* block_addr = (uint32_t*) (ptr + sizeof(int32_t));
-
- uint32_t* header_addr = (uint32_t*) ptr;
- int32_t block_header = *header_addr;
- int32_t block_size = abs(block_header);
-
- uint32_t* footer_addr = (uint32_t*) (ptr + sizeof(int32_t) + block_size);
- int32_t block_footer = *footer_addr;
-
- if (block_header == block_footer && block_header <= 0) {
- LOG("Block %d Allocated:", block);
- LOG("\tsize = %d, address = %x\n", block_size, block_addr);
- } else if (block_header == block_footer && block_header > 0) {
- LOG("Block %d Free:", block);
- LOG("\tsize = %d, address = %x\n", block_size, block_addr);
- } else {
- ERROR("INCONSISTENT HEAP\n");
- ERROR("block_header = %d\n", block_header);
- ERROR("block_footer = %d\n", block_footer);
- ERROR("header addr = %x\n", header_addr);
- ERROR("footer addr = %x\n", footer_addr);
- return -1;
- }
-
- ptr = ptr + block_size + 2 * sizeof(int32_t);
- block++;
- if ((uint32_t*) ptr == end_ptr) {
- return 0;
- }
- }
-
- return 0;
-}
-
-uint32_t* alloc_get_heap(alloc_handle* allocator) {
- return allocator->heap;
-}
-
-uint32_t alloc_get_heap_size(alloc_handle* allocator) {
- return allocator->heap_size;
-}
diff --git a/kernel/memory/mem_alloc.c b/kernel/memory/mem_alloc.c
deleted file mode 100644
index ab9a20bf..00000000
--- a/kernel/memory/mem_alloc.c
+++ /dev/null
@@ -1,151 +0,0 @@
-#include "klibc.h"
-#include "mem_alloc.h"
-#include "vm.h"
-#include "allocator.h"
-
-uint32_t *nextBlock = (uint32_t*) MEM_START;
-uint32_t buffer_size;
-alloc_handle * allocator;
-uint32_t __mem_extend_heap(uint32_t amt);
-
-alloc_handle * proc_allocator;
-uint32_t proc_buffer_size;
-uint32_t __mem_extend_proc_heap(uint32_t amt);
-
-//bump pointer allocation
-void *mem_alloc(uint32_t size)
-{
- uint32_t temp = size / 4;
-
- if ((size % 4) > 0)
- {
- temp++;
- }
- uint32_t* allocBlock = nextBlock;
- nextBlock = nextBlock + size;
-
- return allocBlock;
-}
-
-/*
- * The kernel heap is organized in blocks. Each block has a header and a
- * footer each a 4 byte integer, at the beginning and end of the block.
- * The header and footer both specify the size of the block in question.
- * Used blocks are indicated by the heap header and the heap footer being
- * negative.
- *
- * To allocate a block, we start at the first block and walk through each
- * one, finding the first free block large enough to support a header,
- * footer, and the size requested.
- *
- * To free a block, we do a bunch of merging stuff to check to see if we
- * should merge with the blocks on the left or right of us, respectively.
- */
-
-// TODO: what if there's an error allocating the page?
-// Returns a pointer to the new (big) free block's header
-uint32_t __mem_extend_heap(uint32_t amt)
-{
- uint32_t amt_added = 0;
- while (amt_added < amt) {
- int retval = vm_allocate_page(KERNEL_VAS,
- (void*) (MEM_START + buffer_size), VM_PERM_PRIVILEGED_RW);
- if (retval) {
- os_printf("ERROR: vm_allocate_page(,%d,) returned %d\n",
- MEM_START + amt_added, retval);
- break;
- }
- amt_added += BLOCK_SIZE;
- buffer_size += BLOCK_SIZE;
- }
-
- return amt_added;
-}
-
-uint32_t init_heap()
-{
- int retval = vm_allocate_page(KERNEL_VAS, (void*) MEM_START,
- VM_PERM_PRIVILEGED_RW);
- if (retval) {
- os_printf("ERROR: vm_allocate_page returned %d\n", retval);
- return STATUS_FAIL;
- }
-
- buffer_size = BLOCK_SIZE;
- allocator = alloc_create((uint32_t*) MEM_START, buffer_size, &__mem_extend_heap);
- return STATUS_OK;
-}
-
-uint32_t init_process_heap(struct vas* vas)
-{
- int retval = vm_allocate_page(vas, (void*) PROC_START, VM_PERM_USER_RW);
- vm_map_shared_memory(KERNEL_VAS, (void*)PROC_START, vas, (void*)PROC_START, VM_PERM_USER_RW);
- if (retval) {
- os_printf("ERROR: vm_allocate_page returned %d\n", retval);
- return STATUS_FAIL;
- }
- else{
- os_printf("Page allocated for process heap at %x:\n",PROC_START);
- }
-
- proc_buffer_size = BLOCK_SIZE;
- proc_allocator = alloc_create((uint32_t*) PROC_START, proc_buffer_size, &__mem_extend_proc_heap);
- vm_free_mapping(KERNEL_VAS,(void*)PROC_START);
- return STATUS_OK;
-}
-
-uint32_t __mem_extend_proc_heap(uint32_t amt)
-{
- struct vas* pvas = vm_get_current_vas();
-
- uint32_t amt_added = 0;
- while (amt_added < amt)
- {
- int retval = vm_allocate_page(pvas, (void*) PROC_START, VM_PERM_USER_RW);
- vm_map_shared_memory(KERNEL_VAS, (void*)PROC_START, pvas, (void*)PROC_START, VM_PERM_USER_RW);
- if (retval) {
- os_printf("ERROR: vm_allocate_page returned %d\n", retval);
- return STATUS_FAIL;
- }
- else{
- os_printf("Page allocated for process heap at %x:\n",PROC_START);
- }
- amt_added += BLOCK_SIZE;
- proc_buffer_size += BLOCK_SIZE;
- }
-
- vm_free_mapping(KERNEL_VAS,(void*)PROC_START);
- return amt_added;
-}
-
-void* proc_allocate(uint32_t size)
-{
- return alloc_allocate(proc_allocator, size);
-}
-
-void proc_deallocate(void* ptr)
-{
- return alloc_deallocate(proc_allocator, ptr);
-}
-
-void* allocate(uint32_t size, uint32_t* heap, int32_t heap_size)
-{
- return alloc_allocate(allocator, size);
-}
-
-void deallocate(void* ptr, uint32_t* heap, int32_t heap_size)
-{
- return alloc_deallocate(allocator, ptr);
-}
-
-alloc_handle * mem_get_allocator(){
- return allocator;
-}
-
-int mem_check(){
- return alloc_check(allocator);
-}
-
-uint32_t mem_get_heap_size(){
- return alloc_get_heap_size(allocator);
-}
diff --git a/kernel/mmap.c b/kernel/mmap.c
deleted file mode 100644
index ee8341ab..00000000
--- a/kernel/mmap.c
+++ /dev/null
@@ -1,180 +0,0 @@
-#include "mmap.h"
-#include "memory.h"
-#include "klibc.h"
-#include "drivers/uart.h"
-#include "vm.h"
-
-/*
- * APX AP Privileged Unprivileged
- * 1 11 (0x8c00) = read-only read-only
- * 1 01 (0x8400) = read-only no access
- * 0 10 (0x0800) = read-write read-only
- * 0 01 (0x0400) = read-write no-access
- * See http://infocenter.arm.com/help/topic/com.arm.doc.ddi0333h/Caceaije.html
-
- * Bits 0 and 1 identify the table entry type
- * 0 = translation fault
- * 1 = course page table
- * 2 = section or supersection
- */
-
-int vm_build_free_frame_list(void *start, void *end);
-
-unsigned int * first_level_pt = (unsigned int*) P_L1PTBASE;
-extern struct vm_free_list *vm_vas_free_list;
-extern struct vm_free_list *vm_l1pt_free_list;
-extern struct vm_free_list *vm_l2pt_free_list;
-
-void mmap(void *p_bootargs)
-{
- //char *cmdline_args = read_cmdline_tag(p_bootargs);
- //print_uart0(cmdline_args);
- //print_uart0("\n");
- asm volatile("cpsid if");
-
- //stash register state on the stack
- asm volatile("push {r0-r11}");
-
- os_printf("%X\n", p_bootargs);
-
- /*
- int pte;
- unsigned int mb_addr = 0;
- for(pte = 0; pte < 4096; pte++){
-
- //one-to-one mapping
- first_level_pt[pte] = mb_addr | 0x0400 | 2;
- mb_addr += (1024*1024);
-
- }
- */
- //TODO:. Collin LOOOK HERE
- first_level_pt = (unsigned int *) (P_L1PTBASE + PAGE_TABLE_SIZE);
- //first_level_pt = 0x00200000 + 0x4000 = 0x00204000
- os_printf("first_level_pt=%X\n", first_level_pt);
-
- int i;
- for (i = 0; i < PAGE_TABLE_SIZE >> 2; i++)
- {
- first_level_pt[i] = 0;
- }
-
- //temporarily map where it is until we copy it in VAS
- first_level_pt[P_KDSBASE >> 20] = P_KDSBASE | 0x0400 | 2;
- //first_level_pt[0x07f00000>>20] = first_level_pt[7F] = 0x07f00000 = 0x07f04010
- // 0x00004000
- // 0x00000010
-
- //1MB for static kernel data structures (stacks and l1 pt)
- first_level_pt[V_KDSBASE >> 20] = P_KDSBASE | 0x0400 | 2;
- //first_level_pt[0xfff00000>>20] = first_level_pt[0xfff] = 0x0x7f04010
-
- //map the kernel where its currently loaded in the same location temporarily
- //should be less than a MB
- first_level_pt[P_KERNBASE >> 20] = 0 << 20 | 0x0400 | 2;
-
- //also map it to high memory at 0xf0000000 (vpn = 3840)
- first_level_pt[V_KERNBASE >> 20] = 0 << 20 | 0x0400 | 2;
- first_level_pt[(V_KERNBASE + 0x100000) >> 20] = 0x100000 | 0x0400 | 2;
-
- //map ~2MB of peripheral registers one-to-one
- first_level_pt[PERIPHBASE >> 20] = PERIPHBASE | 0x0400 | 2;
- first_level_pt[(PERIPHBASE + 0x100000) >> 20] = (PERIPHBASE + 0x100000)
- | 0x0400 | 2;
-
- //map 752MB of PCI interface one-to-one
- unsigned int pci_bus_addr = PCIBASE;
- for (i = (PCIBASE >> 20); i < (PCITOP >> 20); i++)
- {
- first_level_pt[i] = pci_bus_addr | 0x0400 | 2;
- pci_bus_addr += 0x100000;
- }
-
- // Quick coarse page table address
- //unsigned int coarse_page_table_address = P_L1PTBASE + 2*PAGE_TABLE_SIZE;
- //os_printf("coarse pt: 0x%X\n", coarse_page_table_address);
-
- //remap 62MB of physical memory after the kernel
- // (KERNTOP to end of physical RAM (PMAPTOP))
- // This is where we allocate frames from. Except for the first one.
- unsigned int phys_addr = P_KERNTOP;
- // +1 to skip L1PTBASE
- for (i = (PMAPBASE >> 20); i < (PMAPTOP >> 20); i++)
- {
- first_level_pt[i] = phys_addr | 0x0400 | 2;
- phys_addr += 0x100000;
- }
-
- // Fill in the coarse page table
- // (TODO: How do we handle 64kB pages? Do they take up 16 entries?)
- //os_memset((void*)coarse_page_table_address, 0, L2_PAGE_TABLE_SIZE);
- // Set the first page to phys_addr
- //*(unsigned int*)coarse_page_table_address = phys_addr | 0x20 | 2;
- //os_printf("0x%X\n", *(unsigned int*)coarse_page_table_address);
-
- first_level_pt[V_L1PTBASE >> 20] = P_L1PTBASE | 0x0400 | 2;
-
- // We have to empty out the first MB of that, so we can use it as an array of VASs
- // The first slot is actually the kernel's VAS
- ((struct vas*) P_L1PTBASE)->l1_pagetable = (unsigned int*) (V_L1PTBASE
- + PAGE_TABLE_SIZE); //first_level_pt;
- ((struct vas*) P_L1PTBASE)->l1_pagetable_phys = first_level_pt;
- ((struct vas*) P_L1PTBASE)->next = 0x0;
- vm_vas_free_list = (struct vm_free_list*) ((void*) vm_vas_free_list
- + sizeof(struct vas));
- vm_l1pt_free_list = (struct vm_free_list*) ((void*) vm_l1pt_free_list
- + PAGE_TABLE_SIZE);
-
- unsigned int pt_addr = (unsigned int) first_level_pt;
-
- os_printf("0x%X\n", first_level_pt[(PMAPBASE + 0x100000) >> 20]);
-
- //TTBR0
- asm volatile("mcr p15, 0, %[addr], c2, c0, 0" : : [addr] "r" (pt_addr));
- // Translation table 1
- //asm volatile("mcr p15, 0, %[addr], c2, c0, 1" : : [addr] "r" (pt_addr));
- //asm volatile("mcr p15, 0, %[n], c2, c0, 2" : : [n] "r" (0));
-
- //Set Domain Access Control to enforce out permissions
- //b01 = Client. Accesses are checked against the access permission bits in the TLB entry.
- asm volatile("mcr p15, 0, %[r], c3, c0, 0" : : [r] "r" (0x1));
-
- /*CONTROL REGISTER
- * Enable MMU by setting 0
- * Alignment bit 1
- * D-cache bit 2
- * I-cache bit 12
- * V bit 13 (1=high vectors 0xffff0000)
- * We disable high vectors, since low vectors work just fine.
- */
- unsigned int control;
-
- //Read contents into control
- asm volatile("mrc p15, 0, %[control], c1, c0, 0" : [control] "=r" (control));
- //Set bit 0,1,2,12,13
- //control |= 0x3007; //0b11000000000111
- control |= 0x1007; //0b01000000000111 (No high vectors)
- control |= 1 << 23; // Enable ARMv6
- //control |= 1<<29; // Enable ForceAP
- os_printf("control reg: 0x%x\n", control);
- //Write back value into the register
- asm volatile("mcr p15, 0, %[control], c1, c0, 0" : : [control] "r" (control));
-
- os_printf("Got here\n");
-
- // Build the free frame list
- vm_build_free_frame_list((void*) PMAPBASE + 0x100000, (void*) PMAPTOP); //(void*)PMAPBASE+(unsigned int)((PMAPTOP)-(PMAPBASE)));
-
- //restore register state
- asm volatile("pop {r0-r11}");
-
- // Except for r0, which is p_bootargs. stacks.s needs to know it.
- asm volatile("mov r0, %[args]" : : [args] "r" (p_bootargs));
-
- asm volatile("cpsie if");
- asm volatile (".include \"stacks.s\"");
-
- //branch to proper kernel at start
- asm volatile("bl start2");
-
-}
diff --git a/kernel/offset.sh b/kernel/offset.sh
deleted file mode 100755
index 20932776..00000000
--- a/kernel/offset.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-
-if [ "$(uname)" == "Darwin" ]; then
- printf "bootm 0x%X\n" $(expr $(stat -f%z ../u-boot/u-boot-$1/u-boot.bin) + 65536)
-else
- printf "bootm 0x%X\n" $(expr $(stat -c%s ../u-boot/u-boot-$1/u-boot.bin) + 65536)
-fi
-
diff --git a/kernel/os_longjmp.s b/kernel/os_longjmp.s
deleted file mode 100644
index aff15fbd..00000000
--- a/kernel/os_longjmp.s
+++ /dev/null
@@ -1,37 +0,0 @@
-.global _longjmp
-.global longjmp
-.type _longjmp,%function
-.type longjmp,%function
-_longjmp:
-longjmp:
- mov ip,r0
- movs r0,r1
- moveq r0,#1
- ldmia ip!, {v1,v2,v3,v4,v5,v6,sl,fp,sp,lr}
-
- adr r1,1f
- ldr r2,1f
- ldr r1,[r1,r2]
-
- tst r1,#0x260
- beq 3f
- tst r1,#0x20
- beq 2f
- ldc p2, cr4, [ip], #48
-2: tst r1,#0x40
- beq 2f
- ldc p11, cr8, [ip], #64
-2: tst r1,#0x200
- beq 3f
- ldcl p1, cr10, [ip], #8
- ldcl p1, cr11, [ip], #8
- ldcl p1, cr12, [ip], #8
- ldcl p1, cr13, [ip], #8
- ldcl p1, cr14, [ip], #8
- ldcl p1, cr15, [ip], #8
-3: tst lr,#1
- moveq pc,lr
- bx lr
-
-.hidden __hwcap
-1: .word __hwcap-1b
diff --git a/kernel/os_setjmp.s b/kernel/os_setjmp.s
deleted file mode 100644
index b74dfc68..00000000
--- a/kernel/os_setjmp.s
+++ /dev/null
@@ -1,39 +0,0 @@
-.global __setjmp
-.global _setjmp
-.global setjmp
-.type __setjmp,%function
-.type _setjmp,%function
-.type setjmp,%function
-__setjmp:
-_setjmp:
-setjmp:
- mov ip,r0
- stmia ip!,{v1,v2,v3,v4,v5,v6,sl,fp,sp,lr}
- mov r0,#0
-
- adr r1,1f
- ldr r2,1f
- ldr r1,[r1,r2]
-
- tst r1,#0x260
- beq 3f
- tst r1,#0x20
- beq 2f
- stc p2, cr4, [ip], #48
-2: tst r1,#0x40
- beq 2f
- stc p11, cr8, [ip], #64
-2: tst r1,#0x200
- beq 3f
- stcl p1, cr10, [ip], #8
- stcl p1, cr11, [ip], #8
- stcl p1, cr12, [ip], #8
- stcl p1, cr13, [ip], #8
- stcl p1, cr14, [ip], #8
- stcl p1, cr15, [ip], #8
-3: tst lr,#1
- moveq pc,lr
- bx lr
-
-.hidden __hwcap
-1: .word __hwcap-1b
diff --git a/kernel/pi_light.c b/kernel/pi_light.c
deleted file mode 100644
index 1ffa6d9b..00000000
--- a/kernel/pi_light.c
+++ /dev/null
@@ -1,50 +0,0 @@
-
-#include "mmap.h"
-#include
-#include "pi_light.h"
-
-//#define GPIO_BASE 0x20200000
-//#define LED_PIN 16
-
-volatile unsigned int* gpio;
-void set_up_LED()
-{
- //Initialize the LED
- gpio = (unsigned int*) GPIO_BASE;
- gpio[1] |= (1 << 18);
-}
-void light_on()
-{
- gpio[10] = (1 << LED_PIN);
-}
-void light_off()
-{
- gpio[7] = (1 << LED_PIN);
-}
-void on_off()
-{
- light_on();
- for (int i = 0; i < 250000; ++i)
- {
- }
- light_off();
- for (int i = 0; i < 250000; ++i)
- {
- }
-}
-void LED_alternate()
-{
-
- for (int i = 0; i < 20; ++i)
- {
- on_off();
- }
-}
-void LED_alternate2(int numFlash)
-{
- //Flash the ACT LED numFlash number of times
- for (int i = 0; i < numFlash; ++i)
- {
- on_off();
- }
-}
diff --git a/kernel/pm.c b/kernel/pm.c
deleted file mode 100644
index 14c905bc..00000000
--- a/kernel/pm.c
+++ /dev/null
@@ -1,90 +0,0 @@
-#include "pm.h"
-#include "stdint.h"
-#include "stdarg.h"
-#include "interrupt.h"
-#include "klibc.h"
-#include "stack.h"
-
-stack *stack = create_stack();
-
-//method to set CPU to idle
-int cpu_idle(int *fp)
-{
- save_registers();
- clear_cache();
- return 0;
-}
-
-//method to return CPU to regular operation
-int cpu_resume(int *fp)
-{
- enable_cache();
- return 0;
-}
-
-//method to save registers on stack
-void save_registers()
-{
-push(stack, asm volatile ("r0"));
-push(stack, asm volatile ("r1"));
-push(stack, asm volatile ("r2"));
-push(stack, asm volatile ("r3"));
-push(stack, asm volatile ("r4"));
-push(stack, asm volatile ("r5"));
-push(stack, asm volatile ("r6"));
-push(stack, asm volatile ("r7"));
-push(stack, asm volatile ("r8"));
-push(stack, asm volatile ("r9"));
-push(stack, asm volatile ("r10"));
-push(stack, asm volatile ("r11"));
-push(stack, asm volatile ("r12"));
-
-push(stack, asm volatile ("ip"));
-push(stack, asm volatile ("lr"));
-push(stack, asm volatile ("pc"));
-push(stack, asm volatile ("sp"));
-
-}
-
-void restore_registers()
-{
-
-}
-
-//method to clear L1
-void clear_cache()
-{
-/* still need to push & pop the stack */
-/* disable cache */
-asm volatile("mov r0, #0");
-//clear r0
-asm volatile("mrc p15, 0, r0, c1, c0, 0");
-//mv control register to r0
-asm volatile("bic r0, #4");
-//!& with 4 - clears bit 2, cache bit
-asm volatile("mcr p15, 0, r0, c1, c0, 0");
-//write r0 to control register
-
-/* clean and flush cache */
-asm volatile("mov r2, #0");
-//clear r2
-asm volatile("mcr p15, 0, r2, c7, c14, 0");
-//clean and flush data cache
-asm volatile("mov r2, #0");
-//clear r2
-asm volatile("mcr p15, 0, r2, c7, c5, 0");
-//clean and flush instruction cache
-}
-
-void enable_cache()
-{
-/* enable cache */
-asm volatile("mov r0, #0");
-//clear r0
-asm volatile("mrc p15, 0, r0, c1, c0, 0");
-//mv control register to r0
-asm volatile("bic r0, #4");
-//!& with 4 - enables bit 2, cache bit
-asm volatile("mcr p15, 0, r0, c1, c0, 0");
-//write r0 to control register
-}
diff --git a/kernel/priorityQueue.c b/kernel/priorityQueue.c
deleted file mode 100644
index c37fa7f9..00000000
--- a/kernel/priorityQueue.c
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- Spring 2015 pcb_exec subteam: Sathya Sankaran, Jason Sim, Rakan Stanbouly
- */
-
-#include "priorityQueue.h"
-#include "global_defs.h"
-#include "vm.h"
-
-/* Global Variables */
-Node *head;
-Node *currentNode;
-/********************/
-
-/* Initializes all the global variables */
-void pqueue_init()
-{
- head = (Node *) mem_alloc(sizeof(Node));
- head->next = NULL;
- head->prev = NULL;
- head->PCB = NULL;
- head->priority = NOT_SET;
- head->PCB->current_state = NOT_SET;
- currentNode = head;
-}
-
-/* Add a PCB to the queue with a given priority.
- Return 1 if successful.
- */
-int pqueue_add(void *PCB, int priority)
-{
- if (head == NULL)
- {
- init();
- }
-
- Node *newTask = (Node *) mem_alloc(sizeof(Node));
- newTask->next = NULL;
- newTask->prev = NULL;
- newTask->PCB = PCB;
- newTask->priority = priority;
- newTask->priority = PROCESS_READY;
-
- if (head->next == NULL)
- {
- head->next = (struct node *) newTask;
- newTask->next = (struct node *) head;
- newTask->prev = (struct node *) head;
- head->prev = (struct node *) newTask;
- }
- else
- {
- // Add the new task into the correct position based on priority
- currentNode = head;
- while ((currentNode->next != (struct node *) head)
- && (currentNode->next->priority > newTask->priority))
- {
- currentNode = (Node *) currentNode->next;
- }
- newTask->next = currentNode->next;
- newTask->prev = (struct node *) currentNode;
- currentNode->next->prev = newTask;
- currentNode->next = (struct node *) newTask;
- }
-
- return 1; // Change if there should be a condition for not adding a PCB to the priority queue.
-}
-
-/* Remove the node with the same PID as the process in the given process
- control block.
-
- Return a pointer to the PCB removed.
- */
-pcb* pqueue_remove(pcb *PCB)
-{
- //PCB abstraction will change the parameters, can search for processes by PID.
- currentNode = head;
- while (currentNode->next->PCB->PID != PCB->PID)
- {
- currentNode = (Node *) currentNode->next;
- }
- Node *nodeToRemove = (Node *) currentNode->next;
- currentNode->next = nodeToRemove->next;
- currentNode->next->prev = currentNode;
- nodeToRemove->next = nodeToRemove->prev = NULL;
- return nodeToRemove->PCB;
-}
-
-/* Wait for a task to finish. Then set the current task's state to READY */
-void pqueue_join(pcb *other_PCB)
-{
- // TODO: Do we need to store which task(s) we are blocked on?
- currentNode->PCB->current_state = PROCESS_BLOCKED;
-
- // Wait for the other thread to exit
- while (other_PCB->current_state != PROCESS_DYING
- || is_in_queue(other_PCB->PID))
- {
- task_yield();
- }
- currentNode->PCB->current_state = PROCESS_RUNNING;
-}
-
-/* If the task has not been started yet, start it.
- Else if the task was previously started, restore its state.
- */
-void dispatch(pcb *PCB)
-{
- //4-15-15: Dispatch deals with both new and old processes
- if (!PCB->current_state || PCB->current_state == PROCESS_NEW) // TODO: not sure if this is correct
- {
- PCB->current_state = PROCESS_RUNNING;
- execute_process(PCB); // Found in process.c
- }
- else
- {
- //4-15-15: This will load the VAS and jump to the location the state was saved in task_yield()
- //TODO: is this all that needs to be done here to switch into the process?
- vm_enable_vas(PCB->stored_vas);
- load_process_state(PCB); // From process.c
- ///execute_process(PCB); //This is incorrect
- }
-}
-
-/* Schedule a new task and call dispatch() to run it. */
-void schedule()
-{
- // When dispatch() returns, we must schedule again, so we have use "while"
- while (head->next != NULL)
- {
- Node *nodeToDispatch = (Node *) head->next;
-
- if (nodeToDispatch->PCB->current_state == PROCESS_READY)
- {
- nodeToDispatch->PCB->current_state = PROCESS_RUNNING;
- dispatch(nodeToDispatch->PCB);
- }
- else
- {
- // If the task isn't ready, schedule another.
- head = (Node *) head->next;
- }
-
- head = head->next;
- }
-
- // If we ever reach this part, we are out of things to schedule
-}
-
-/* I heard we wanted voluntary yielding to start. Tasks should call this
- function every so often.
- */
-void task_yield()
-{
- /* Save the state of the task that is currently running. We'll jump
- back to here later.
- */
- currentNode->PCB->current_state = PROCESS_READY;
- //4-15-15: also save the VAS for the process. Hopefully this is all we need to do.
- currentNode->PCB->stored_vas = vm_get_current_vas();
- int has_jumped = save_process_state(currentNode->PCB);
-
- if (has_jumped == FALSE)
- {
- // If the jump has NOT happened, schedule()
- schedule();
- }
- else
- {
- // If the jump has happened, return to the task
- //4-15-15: and restore the VAS
- vm_enable_vas(currentNode->PCB->stored_vas);
- currentNode->PCB->current_state = PROCESS_RUNNING;
- return;
- }
-}
-
-/* Return TRUE if a process with a PID of pid is in the queue.
- Return FALSE otherwise.
- */
-Boolean is_in_queue(int pid)
-{
- Node *node_ptr = head;
-
- // Iterate through the list
- while ((Node *) node_ptr->next != head)
- {
- if (node_ptr->PCB->PID == pid)
- {
- return TRUE;
- }
-
- node_ptr = (Node *) node_ptr->next;
- }
-
- return FALSE;
-}
diff --git a/kernel/process.c b/kernel/process.c
deleted file mode 100644
index ff84825d..00000000
--- a/kernel/process.c
+++ /dev/null
@@ -1,283 +0,0 @@
-#include "global_defs.h"
-#include "process.h"
-#include "klibc.h"
-#include "mem_alloc.h"
-#include "loader.h"
-#include "vm.h"
-#include "elf.h"
-#include "drivers/timer.h"
-#include "fs/file.h"
-#include "data_structures/bitvector.h"
-
-static pcb** pcb_table;
-static bit_vector* pcb_map;
-
-
-pcb* __process_create();
-void __process_elf_init(pcb* pcb_p, const char* name);
-void __process_stack_init(pcb* pcb_p);
-void __process_heap_init(pcb* pcb_p);
-
-void process_init()
-{
- pcb_table = kmalloc(MAX_PROCESSES * sizeof(pcb*));
- pcb_map = make_vector(MAX_PROCESSES);
-}
-
-pcb* process_create(const char *name)
-{
- pcb* pcb_p = __process_create();
- if(!pcb_p) {
- return NULL;
- }
-
- __process_elf_init(pcb_p, name);
- __process_stack_init(pcb_p);
- __process_heap_init(pcb_p);
- return pcb_p;
-}
-
-int process_execute(pcb* pcb_p)
-{
- //Copy the current process's program counter to the new process's return register
- //The new process will use R14 to return to the parent function
- asm("MOV %0, r15":"=r"(pcb_p->R14)::);
-
- pcb_p->current_state = PROCESS_RUNNING;
-
- vm_enable_vas(pcb_p->stored_vas);
- process_load_state(pcb_p);
- return 0;
-}
-
-int process_destroy(pcb* pcb_p){
- bv_lower(pcb_p->PID, pcb_map);
- kfree(pcb_p);
- return 0;
-}
-
-/*Spring 2015 course_os: Sathya Sankaran, Rakan Stanbouly, Jason Sim
-
- creates a process and initializes the PCB
- @param file pointer to location in memory of file
- @return pcb pointer upon success
- @return 0 if there is no more room in pcb table */
-pcb* __process_create()
-{
- int32_t pcb_index = bv_firstFree(pcb_map);
- if (pcb_index < 0) {
- return NULL;
- }
- pcb* pcb_p = (pcb*) kmalloc(sizeof(pcb));
- if (!pcb_p) {
- return NULL;
- }
- //initialize PCB
- pcb_p->stored_vas = vm_new_vas();
- pcb_p->PID = pcb_index;
- //4-13-15: function pointer should point to main() of file pointer.
- // TODO: Eventually should be able to pass parameters. Put them on the stack (argv/argc)
- pcb_p->current_state = PROCESS_NEW;
- pcb_p->has_executed = 0;
-
- pcb_table[pcb_index] = pcb_p;
- bv_set(pcb_index, pcb_map);
- return pcb_p;
-}
-
-void __process_elf_init(pcb* pcb_p, const char* name) {
- int fd = kopen(name, 'r');
- uint32_t start = PROC_LOCATION;
- uint32_t len = 0;
-
- struct stats fstats;
- get_stats(name, &fstats);
- len = fstats.size;
- os_printf("LOADING PROCESS <<%s>>, start address %X\n",
- name, start, len);
-
- for (int i = 0; i < (len / BLOCK_SIZE) + 1; i++)
- {
- uint32_t *v = (uint32_t*) (start + (i * BLOCK_SIZE));
- int x = vm_allocate_page(pcb_p->stored_vas, (void*) v, VM_PERM_USER_RW);
- assert(x == 0);
- vm_map_shared_memory(KERNEL_VAS, (void*) v,
- pcb_p->stored_vas,(void*) v,
- VM_PERM_USER_RW);
- }
-
- int* location = (int*) start;
- int counter = 0;
- while (counter < len)
- {
- kread(fd, location, 4);
- location += 1;
- counter += 4;
- }
-
- Elf_Ehdr* success = (Elf_Ehdr*) load_file(pcb_p, (uint32_t*) start);
- pcb_p->R15 = success->e_entry;
- for (int i = 0; i < (len / BLOCK_SIZE) + 1; i++)
- {
- uint32_t *v = (uint32_t *) (start + (i * BLOCK_SIZE));
- vm_free_mapping(KERNEL_VAS, (void*) v);
- }
-}
-
-/*
- Allocated memory for the process stack
- Moves arguments for argc, argv, envp, and auxp
- into stack_top
-
- Points stack pointer to location where stack_top would begin
- @param pointer to process control block
- @param pcb* pcb_p
-
- */
-void __process_stack_init(pcb * pcb_p)
-{
- int retval = 0;
- for (int i = 0; i < (STACK_SIZE / BLOCK_SIZE); i++)
- {
- retval = vm_allocate_page(pcb_p->stored_vas,
- (void*) (STACK_BASE + (i * BLOCK_SIZE)), VM_PERM_USER_RW);
- if (retval)
- {
- os_printf("vm_allocate_page error code: %d\n", retval);
- break;
- }
- else
- {
- os_printf(
- "A page have been allocated for process stack at vptr: 0x%x\n",
- (STACK_BASE + (i * BLOCK_SIZE)));
- }
- vm_map_shared_memory(KERNEL_VAS,
- (void*) (STACK_BASE + (i * BLOCK_SIZE)), pcb_p->stored_vas,
- (void*) (STACK_BASE + (i * BLOCK_SIZE)), VM_PERM_USER_RW);
- }
-
- // Stick a NULL at STACK_TOP-sizeof(int*)
- uint32_t *stack_top = (uint32_t*) STACK_TOP;
- stack_top[-1] = 0;
- stack_top[-2] = 0;
- stack_top[-3] = 0;
- stack_top[-4] = 0;
- stack_top[-5] = STACK_BASE;
- stack_top[-6] = 1;
-
- os_strcpy((char*) STACK_BASE, pcb_p->name);
-
- // We need to set sp (r13) to stack_top - 12
- pcb_p->R13 = STACK_TOP - 4 * 6;
- for (int i = 0; i < (STACK_SIZE / BLOCK_SIZE); i++)
- {
- vm_free_mapping(KERNEL_VAS, (void*) (STACK_BASE + (i * BLOCK_SIZE)));
- }
-}
-void __process_heap_init(pcb* pcb_p)
-{
- //from mem_alloc.c
- init_process_heap(pcb_p->stored_vas);
- os_printf("User Level Heap for Process PID %d initialized\n", pcb_p->PID);
-}
-/*
- Saves all of the Registers on the machine to the PCB
- @param Process ID
- @return 0 if failed
- @return 1 for success
- */
-void process_save_state(pcb* pcb_p)
-{
- assert(pcb_p);
-
- asm("MOV %0, r0":"=r"(pcb_p->R0)::);
- asm("MOV %0, r1":"=r"(pcb_p->R1)::);
- asm("MOV %0, r2":"=r"(pcb_p->R2)::);
- asm("MOV %0, r3":"=r"(pcb_p->R3)::);
- asm("MOV %0, r4":"=r"(pcb_p->R4)::);
- asm("MOV %0, r5":"=r"(pcb_p->R5)::);
- asm("MOV %0, r6":"=r"(pcb_p->R6)::);
- asm("MOV %0, r7":"=r"(pcb_p->R7)::);
- asm("MOV %0, r8":"=r"(pcb_p->R8)::);
- asm("MOV %0, r9":"=r"(pcb_p->R9)::);
- asm("MOV %0, r10":"=r"(pcb_p->R10)::);
- asm("MOV %0, r11":"=r"(pcb_p->R11)::);
- asm("MOV %0, r12":"=r"(pcb_p->R12)::);
- asm("MOV %0, r13":"=r"(pcb_p->R13)::);
- asm("MOV %0, r14":"=r"(pcb_p->R14)::);
- asm("MOV %0, r15":"=r"(pcb_p->R15)::);
-}
-
-#define offsetof(st, m) __builtin_offsetof(st, m)
-
-__attribute((naked)) void process_load_state(pcb* pcb_p)
-{
- asm volatile(
- "mov ip, r0 \n\t" \
- "ldr r0, [ip, %0] \n\t " \
- "ldr r1, [ip, %1] \n\t " \
- "ldr r2, [ip, %3] \n\t " \
- "ldr r4, [ip, %4] \n\t " \
- "ldr r5, [ip, %5] \n\t " \
- "ldr r6, [ip, %6] \n\t " \
- "ldr r7, [ip, %7] \n\t " \
- "ldr r8, [ip, %8] \n\t " \
- "ldr r9, [ip, %9] \n\t " \
- "ldr r10, [ip, %10] \n\t " \
- "ldr r11, [ip, %11] \n\t " \
- "ldr r13, [ip, %12] \n\t " \
- "ldr r14, [ip, %13] \n\t " \
- "ldr ip, [ip, %14] \n\t " \
- "mcr p15, 0, r0, c8, c7, 0 \n\t" \
- "mov r15, ip \n\t"
- :: "i" (offsetof(pcb, R0)),
- "i" (offsetof(pcb, R1)),
- "i" (offsetof(pcb, R2)),
- "i" (offsetof(pcb, R3)),
- "i" (offsetof(pcb, R4)),
- "i" (offsetof(pcb, R5)),
- "i" (offsetof(pcb, R6)),
- "i" (offsetof(pcb, R7)),
- "i" (offsetof(pcb, R8)),
- "i" (offsetof(pcb, R9)),
- "i" (offsetof(pcb, R10)),
- "i" (offsetof(pcb, R11)),
- "i" (offsetof(pcb, R13)),
- "i" (offsetof(pcb, R14)),
- "i" (offsetof(pcb, R15)) :
- );
-}
-/*
- Loads registers using values in pcb
- @param Process ID
- */
-/*
-void process_load_state(pcb* pcb_p)
-{
- asm("MOV r0, %0"::"r"(pcb_p->R0):);
- asm("MOV r1, %0"::"r"(pcb_p->R1):);
- asm("MOV r2, %0"::"r"(pcb_p->R2):);
- asm("MOV r3, %0"::"r"(pcb_p->R3):);
- asm("MOV r4, %0"::"r"(pcb_p->R4):);
- asm("MOV r5, %0"::"r"(pcb_p->R5):);
- asm("MOV r6, %0"::"r"(pcb_p->R6):);
- asm("MOV r7, %0"::"r"(pcb_p->R7):);
- asm("MOV r8, %0"::"r"(pcb_p->R8):);
- asm("MOV r9, %0"::"r"(pcb_p->R9):);
- asm("MOV r10, %0"::"r"(pcb_p->R10):);
- asm("MOV r12, %0"::"r"(pcb_p->R12):);
- asm("MOV r13, %0"::"r"(pcb_p->R13):);
- asm("MOV r14, %0"::"r"(pcb_p->R14):);
-
- // move pc to process stack
- *((uint32_t*)(PROC_START+4)) = pcb_p->R15;
-
- vm_invalidate_tlb();
-
- asm("MOV r12, %0":: "i" ((PROC_START+4)):);
- asm("ldr r15, [r12]" :::);
-
- __builtin_unreachable();
-}
-*/
diff --git a/kernel/process/process_api.c b/kernel/process/process_api.c
deleted file mode 100644
index e021bf31..00000000
--- a/kernel/process/process_api.c
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "scheduler.h"
-#include "klibc.h"
-
-// Process / Scheduler API
-
-uint32_t prcs_exec(uint32_t file_p, int niceness) {
- sched_task * task = sched_create_task(file_p, niceness);
- return sched_add_task(task);
-}
-
-// kill the process and its subprocesses
-// can only be called if the process tree contains
-// the request pid
-uint32_t prcs_kill(uint32_t pid) {
- return sched_remove_task(pid);
-}
-
-// sends a message to a process (ipc)
-uint32_t prcs_send_message(uint32_t dest_pid, uint32_t event, char * data, int len) {
- return sched_send_message(dest_pid, event, data, len);
-}
-
-// receives messages from processes
-uint32_t prcs_register_message_callback_handler(sched_callback_handler cb_handler) {
- return sched_register_callback_handler(cb_handler);
-}
-
-// receives messages from processes
-uint32_t prcs_deregister_message_callback_handler() {
- return sched_deregister_callback_handler();
-}
-
-// set the niceness of a process
-uint32_t prcs_set_niceness(uint32_t pid) {
- return sched_set_niceness(pid);
-}
-
-uint32_t prcs_fork(); // under construction
diff --git a/kernel/process/scheduler.c b/kernel/process/scheduler.c
deleted file mode 100644
index b3cae6dc..00000000
--- a/kernel/process/scheduler.c
+++ /dev/null
@@ -1,513 +0,0 @@
-#include "global_defs.h"
-#include "kthread.h"
-#include "scheduler.h"
-#include "vm.h"
-#include "klibc.h"
-#include "process.h"
-#include "data_structures/linked_list.h"
-#include "data_structures/hash_map.h"
-#include "data_structures/array_list.h"
-#include "drivers/timer.h"
-
-#define MAX_TASKS 100 // in the future, cap will be removed
-#define MAX_ACTIVE_TASKS 4 // in the future, will dynamically change based on load
-#define MAX_NICENESS -20
-#define MIN_NICENESS 20
-#define TASK_STATE_FINISHED 3 // task has run by the scheduler and finished
-#define TASK_STATE_INACTIVE 2 // task is in the wait queue (about to be executed)
-#define TASK_STATE_ACTIVE 1 // task is part of the running tasks; it is being interleaved and executed atm
-#define TASK_STATE_NONE 0 // task is just created (no real state)
-#define SAFE_NICE(n) MAX(MIN(MAX_NICENESS, n), n)
-#define KTHREAD 0
-#define PROCESS 1
-
-#define AS_PROCESS(a) ((pcb*) a->task)
-#define AS_KTHREAD(a) ((kthread_handle*) a->task)
-#define IS_PROCESS(a) (a->type == PROCESS)
-#define IS_KTHREAD(a) (a->type == KTHREAD)
-
-static char *last_err;
-static prq_handle * inactive_tasks;
-static prq_handle * active_tasks;
-static sched_task * active_task;
-static hmap_handle * all_tasks_map;
-
-static uint32_t sched_tid;
-
-// NOTE
-// scheduler logic only. not tested
-
-// scheduler
-// ---------
-// round-robin timer-enabled scheduler that runs tasks in descending priority
-// with the help of a heap-based priority queue
-
-// supported syscalls
-// ---------
-// create: create a process (not execute)
-// exec: start a process which you created before
-// waitpid: wait for a process (i.e. child) to finish
-// kill: kill a process and its children processes
-//
-#define SCHEDULER_TIMER 0
-
-void __sched_dispatch(void);
-
-void timer_handler(void *args)
-{
- os_printf("scheduler received timer interrupt, need to switch tasks...\n");
-}
-
-void __sched_register_timer_irq(void)
-{
- register_handler(SCHEDULER_TIMER, timer_handler);
-}
-
-void __sched_deregister_timer_irq()
-{
- unregister_handler(SCHEDULER_TIMER);
-}
-
-void __sched_pause_timer_irq()
-{
- // TODO: suspend the timer here
-}
-
-void __sched_resume_timer_irq()
-{
- // TODO: resume the timer here
-}
-
-// get the current process id
-uint32_t sched_get_active_tid() {
- if (active_task) {
- return active_task->tid;
- }
-
- return (uint32_t) STATUS_FAIL;
-}
-
-// Initialize the scheduler. Should be called by the kernel ONLY
-uint32_t sched_init(void) {
- ensure_kernel_vas();
-
- sched_tid = 0;
-
- os_printf("Initializing scheduler\n");
- last_err = "No error";
- inactive_tasks = prq_create_fixed(MAX_TASKS);
- active_tasks = prq_create_fixed(MAX_ACTIVE_TASKS);
- active_task = 0;
-
- all_tasks_map = hmap_create();
-
- __sched_register_timer_irq();
-
- return STATUS_OK;
-}
-
-// initial call that causes the scheduler to start
-void sched_start(void)
-{
- __sched_dispatch();
-}
-
-uint32_t sched_register_callback_handler(sched_callback_handler cb_handler) {
- sched_task * task = hmap_get(all_tasks_map, sched_get_active_tid());
- task->cb_handler = cb_handler;
- return STATUS_OK;
-}
-
-uint32_t sched_deregister_callback_handler() {
- sched_task * task = hmap_get(all_tasks_map, sched_get_active_tid());
- task->cb_handler = 0;
-
- return STATUS_OK;
-}
-
-// Free the resources used the scheduler
-uint32_t sched_free() {
- ensure_kernel_vas();
-
- // FIXME kill active tasks
-
- __sched_deregister_timer_irq();
-
- prq_free(inactive_tasks);
- prq_free(active_tasks);
-
- return STATUS_OK;
-}
-
-// issue messages for the active task
-void __sched_emit_messages(void) {
- if (active_task->cb_handler) {
- sched_message_chunk * chunk;
- while ((chunk = llist_dequeue(active_task->message_queue)) != 0) {
- active_task->cb_handler(chunk->src_pid, chunk->event, chunk->data,
- chunk->chunk_length, chunk->remain_length);
- if (chunk) {
- kfree(chunk);
- }
- }
- }
-}
-
-sched_task* __sched_create_task(void * task_data, int niceness, uint32_t type) {
- if (prq_count(inactive_tasks) >= MAX_TASKS) {
- last_err = "Too many tasks";
- return (sched_task*) STATUS_FAIL;
- }
-
- __sched_pause_timer_irq();
-
- sched_task * task = (sched_task*) kmalloc(sizeof(sched_task));
-
- niceness = SAFE_NICE(niceness);
-
- task->tid = ++sched_tid;
- task->niceness = niceness;
- task->task = task_data;
- task->type = type;
- task->state = TASK_STATE_NONE;
- task->node = 0;
- task->parent_tid = 0;
- task->children_tids = arrl_create();
- task->cb_handler = 0;
-
- if (active_task) {
- task->parent_tid = active_task->tid;
- arrl_append(active_task->children_tids, (void*) task->tid);
- }
-
- __sched_resume_timer_irq();
-
- return task;
-
-}
-
-sched_task* sched_create_task_from_kthread(kthread_handle * kthread,
- int niceness) {
- return __sched_create_task(kthread, niceness, KTHREAD);
-}
-
-sched_task* sched_create_task_from_process(pcb * pcb_pointer, int niceness) {
- return __sched_create_task(pcb_pointer, niceness, PROCESS);
-}
-
-
-// Helper function used by the scheduler internally. It will traverse the parent/child
-// list to find a subtask.
-#if 0
-sched_task* __sched_find_subtask(sched_task * parent_task, uint32_t tid) {
- if (parent_task && parent_task->tid == tid) {
- return parent_task;
- }
-
- int i = 0;
- for (; i < arrl_count(parent_task->children_tids); i++) {
- uint32_t child_tid = arrl_count(parent_task, i);
- sched_task * child_task = hmap_get(all_tasks_map, child_tid);
- if ((child_task = __sched_find_subtask(child_task, tid))) {
- return child_task;
- }
- }
-
- return 0;
-}
-#endif
-
-//
-// NOTE expecting access to kernel global vars
-void sched_waittid(uint32_t tid) {
- // FIXME: broken!
- while (1) {
- sched_task * task = (sched_task*) hmap_get(all_tasks_map, (unsigned long) tid);
- if (task == 0 || task->state == TASK_STATE_FINISHED) {
- break;
- }
-
- //sleep(500);
- }
-}
-
-// contract
-// --------
-// must disable timer_interrupt
-uint32_t __sched_remove_task(sched_task * task) {
- if (task == NULL) {
- return (uint32_t) STATUS_FAIL;
- }
-
- switch (task->state) {
- case TASK_STATE_INACTIVE: {
- __sched_pause_timer_irq();
- prq_remove(inactive_tasks, task->node);
- prq_free_node(task->node);
- __sched_resume_timer_irq();
- break;
- }
- case TASK_STATE_ACTIVE: {
- __sched_pause_timer_irq();
-
- task->state = TASK_STATE_FINISHED;
-
- if (IS_PROCESS(task)) {
- process_destroy(AS_PROCESS(task));
- } else if (IS_KTHREAD(task)) {
- // FIXME add later
- }
-
- hmap_remove(all_tasks_map, task->tid);
- prq_remove(active_tasks, task->node);
- prq_free_node(task->node);
-
- int i = 0;
- for (; i < arrl_count(task->children_tids); i++) {
- // FIXME: this API does not exist anymore
- // sched_remove_task(arrl_get(task->children_tids, i));
- }
-
- __sched_resume_timer_irq();
- break;
- }
- case TASK_STATE_FINISHED: {
- // ignore
- break;
- }
- }
-
- __sched_resume_timer_irq();
-
- return task->state;
-}
-
-
-// essentially a kill process
-uint32_t sched_remove_task(uint32_t tid) {
- sched_task * task = (sched_task*) hmap_get(all_tasks_map, tid);
- if (task) {
- __sched_pause_timer_irq();
- uint32_t status = __sched_remove_task(task);
- __sched_resume_timer_irq();
- return status;
- }
-
- return STATUS_FAIL;
-}
-
-void __sched_dispatch(void) {
- // prevent interrupts while handling another interrupt
- __sched_pause_timer_irq();
-
- // use the kernel memory
- vm_use_kernel_vas();
-
- if (prq_count(active_tasks) < MAX_ACTIVE_TASKS) {
- if (prq_count(inactive_tasks) > 0) {
- prq_enqueue(active_tasks, prq_dequeue(inactive_tasks)); // add to active_tasks if the task
- }
- }
-
- if (prq_count(active_tasks) == 0) {
- __sched_resume_timer_irq();
- return;
- }
-
- sched_task * last_task;
-
- // check if there is active task
- if (active_task) {
- last_task = active_task;
- } else {
- prq_node * node = prq_peek(active_tasks);
- last_task = (sched_task*) node->data;
- }
-
- switch (last_task->state) {
- case TASK_STATE_INACTIVE: {
- active_task = last_task;
- active_task->state = TASK_STATE_ACTIVE;
-
- if (IS_PROCESS(active_task)) {
- __sched_resume_timer_irq();
- process_execute(AS_PROCESS(active_task));
- } else if (IS_KTHREAD(active_task)) {
- AS_KTHREAD(active_task)->cb_handler();
- }
-
- __sched_pause_timer_irq();
- sched_remove_task(active_task->tid);
- active_task = 0;
-
- // NOTE next interrupt will get the start the process
-
- break;
- }
- case TASK_STATE_ACTIVE: {
- if (prq_count(active_tasks) > 1) {
- prq_remove(active_tasks, active_task->node);
- prq_enqueue(active_tasks, active_task->node);
- sched_task * next_task = (sched_task*) prq_peek(active_tasks)->data;
-
- // old task
- if (IS_PROCESS(active_task)) {
- if (active_task == next_task) {
- vm_enable_vas(AS_PROCESS(active_task)->stored_vas);
- break;
- }
-
- process_save_state(AS_PROCESS(last_task));
- } else if (IS_KTHREAD(active_task)) {
- if (active_task == next_task) {
- break;
- }
-
- // FIXME: implement
- // kthread_save_state(AS_KTHREAD(active_task));
- }
-
- active_task = next_task;
-
- // new task
- if (IS_PROCESS(active_task)){
- vm_enable_vas(AS_PROCESS(active_task)->stored_vas);
- __sched_emit_messages();
- process_load_state(AS_PROCESS(active_task)); // continue with the next process
- } else if (IS_KTHREAD(active_task)) {
- __sched_emit_messages();
-
- // FIXME: implement
- // kthread_load_state(AS_KTHREAD(active_task));
- }
- }
- break;
- }
- }
-
- __sched_resume_timer_irq();
-}
-
-// start process
-uint32_t sched_add_task(sched_task * task) {
- if (task) {
- if (task->state != TASK_STATE_NONE) {
- last_err = "Reusing task object not allowed";
- return (uint32_t) STATUS_FAIL;
- }
-
- ensure_kernel_vas();
-
- prq_node * new_node = (prq_node*) kmalloc(sizeof(prq_node));
- new_node->data = task;
- new_node->priority = task->niceness;
-
- task->state = TASK_STATE_INACTIVE;
- task->node = new_node;
- prq_enqueue(inactive_tasks, new_node);
-
- hmap_put(all_tasks_map, active_task->tid, active_task);
-
- return active_task->tid;
- }
-
- last_err = "Invalid sched_task pointer";
- return (uint32_t) STATUS_FAIL;
-}
-
-
-const char * sched_last_err() {
- return last_err;
-}
-
-uint32_t sched_set_niceness(uint32_t pid, uint32_t niceness) {
-
- sched_task * task;
-
- if (!(task = hmap_get(all_tasks_map, pid))) {
- return STATUS_FAIL;
- }
-
- __sched_pause_timer_irq();
-
- prq_handle * tasks;
-
- switch (task->state) {
- case TASK_STATE_ACTIVE:
- tasks = active_tasks;
- break;
- case TASK_STATE_INACTIVE:
- tasks = inactive_tasks;
- break;
- case TASK_STATE_FINISHED:
- break;
- }
-
- if (tasks) {
- prq_remove(tasks, task->node); // remove the running task from queue
- task->node->priority = SAFE_NICE(niceness);
- prq_enqueue(tasks, task->node); // add it again to see if its position in the queue
-
- }
-
- __sched_resume_timer_irq();
-
- return STATUS_OK;
-}
-
-uint32_t sched_post_message(uint32_t dest_pid, uint32_t event, char * data,
- int len)
-{
- /*sched_task * dest_task;
-
- if (!(dest_task = hmap_get(&all_tasks_map, dest_pid))) {
- return STATUS_FAIL;
- }
- __sched_pause_timer_irq();
-
- vm_use_kernel_vas();
-
- // create space on kernel stack
- char data_cpy[512];
- while (len > 0) {
- // get length to cpy
- int cpy_len = MIN(len, 512);
- // enable orignal struct
- vm_enable_vas(active_task->pcb->stored_vas);
- // copy to stack
- os_memcpy(data, data_cpy, cpy_len);
- // remaining bytes
- len -= cpy_len;
- // increment data pointer
- data = (char*) (data + cpy_len / 4);
- // get the dest_task
- sched_task * dest_task = hmap_get(&all_tasks_map, dest_pid);
- // switch to dest vas
- vm_enable_vas(dest_task->pcb->stored_vas);
- // copy from global kernel stack to process heap
- char* task_mem_data_cpy = kmalloc(cpy_len);
- os_memcpy(data_cpy, task_mem_data_cpy, cpy_len);
-
- vm_use_kernel_vas();
-
- // FIXME create the message object and pass it in
- // messages will be broken up into chunks since we have to
- // copy into kernel stack first.
- sched_message_chunk * chunk = kmalloc(sizeof(sched_message_chunk));
- chunk->data = task_mem_data_cpy;
- chunk->chunk_length = cpy_len;
- chunk->remain_length = len;
- chunk->event = event;
- chunk->src_pid = active_task ? active_task->pcb->PID : 0;
-
- llist_enqueue(dest_task->message_queue, chunk);
- }
-
- if (active_task) {
- vm_enable_vas(active_task->pcb->stored_vas);
- }
-
- __sched_resume_timer_irq();*/
-
- return STATUS_OK;
-}
diff --git a/kernel/sampleFile.c b/kernel/sampleFile.c
deleted file mode 100644
index ac8d11a1..00000000
--- a/kernel/sampleFile.c
+++ /dev/null
@@ -1,10 +0,0 @@
-#include
-
-uint32_t functionYO(uint32_t x, uint32_t y)
-{
- int a = 100;
- int b = 40000;
- os_printf("%d\n", x + y);
- return x + y;
-
-}
diff --git a/kernel/signals.c b/kernel/signals.c
deleted file mode 100644
index a299f487..00000000
--- a/kernel/signals.c
+++ /dev/null
@@ -1,20 +0,0 @@
-//Contributors: Andrew Stepek, Michael Brennen, and Matthew Stromberg
-
-/*
- Signals
- */
-/*
- SIGKILL
- SIGUSR
- SIGTERM
- */
-
-#include "signals.h"
-#include "process.h"
-
-void signal_mask(char * type, int index, uint32_t PID)
-{
- pcb* pcb_t = get_PCB(PID);
- pcb_t.mask[index]->type = type;
-}
-
diff --git a/kernel/stacks.s b/kernel/stacks.s
deleted file mode 100644
index e0768994..00000000
--- a/kernel/stacks.s
+++ /dev/null
@@ -1,52 +0,0 @@
-.equ stack_size, 0x1000
-.equ stack_base, 0xfffff000
-
-.equ Mode_USR, 0x10
-.equ Mode_FIQ, 0x11
-.equ Mode_IRQ, 0x12
-.equ Mode_SVC, 0x13
-.equ Mode_MON, 0x16
-.equ Mode_ABT, 0x17
-.equ Mode_UND, 0x1B
-.equ Mode_SYS, 0x1F
-
- MOV R1, R0 // R0 has p_bootargs, which we need to hang onto
- LDR R0, =stack_base
- MSR CPSR_c, #Mode_FIQ
- MOV sp, R0
- SUB R0, R0, #stack_size
-
- MSR CPSR_c, #Mode_IRQ
- MOV sp, R0
- SUB R0, R0, #stack_size
-
- MSR CPSR_c, #Mode_SVC
- MOV sp, R0
- SUB R0, R0, #stack_size
-
- MSR CPSR_c, #Mode_MON
- MOV sp, R0
- SUB R0, R0, #stack_size
-
- MSR CPSR_c, #Mode_ABT
- MOV sp, R0
- SUB R0, R0, #stack_size
-
- MSR CPSR_c, #Mode_UND
- MOV sp, R0
- SUB R0, R0, #stack_size
-
- MSR CPSR_c, #Mode_SYS
- MOV sp, R0
-
- MSR CPSR_c, #Mode_SVC
- ADD fp, sp, #0
-
- EOR R0, R0
- ADD R0, pc, #0xf0000000
- MOV pc, R0
-
- EOR R0, R0
- ADD R0, lr, #0xf0000000
- MOV lr, R0
- MOV R0, R1
diff --git a/kernel/start.c b/kernel/start.c
deleted file mode 100644
index 39e960a9..00000000
--- a/kernel/start.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * A bit of background:
- * - The ARM architecture has 7 modes of operation:
- * + USR - user mode
- * + FIQ - processing "fast" interrupts
- * + IRQ - processing "normal" interrupts
- * + SVC - proctected mode for OS
- * + UND - processing an undefined instruction exception
- * + SYS - also protecteed mode for OS --if anyone wants to clarify, feel free--
- *
- * - These modes can be entered or exited by modifying the CPSR (status register), first 5 bits
- * + 0b10000 = user mode
- * + 0b10001 = FIQ (fast interrupt) mode
- * + 0b10010 = IRQ (normal interrupt) mode
- * + 0b10011 = SVC (supervisor, or, OS) mode
- * (others...)
- */
-
-#include
-#include "hw_handlers.h"
-#include "global_defs.h"
-#include "argparse.h"
-#include "interrupt.h"
-#include "mmap.h"
-#include "process.h"
-#include "memory.h"
-#include "drivers/uart.h"
-#include "drivers/mmci.h"
-#include "klibc.h"
-#include "vm.h"
-#include "fs/open_table.h" //to initialize fs opentable
-#include "mem_alloc.h"
-#include "tests.h"
-#include "drivers/timer.h"
-#include "kthread.h"
-#include "scheduler.h"
-
-// Tests
-#include "tests/test_klibc.h"
-#include "tests/test_hash_map.h"
-#include "tests/test_mem_alloc.h"
-#include "tests/test_vm.h"
-#include "tests/test_priority_queue.h"
-
-#define UART0_IMSC (*((volatile uint32_t *)(UART0_ADDRESS + 0x038)))
-
-void uart_handler(void *null)
-{
- print_uart0("uart0!\n");
-}
-
-// This start is what u-boot calls. It's just a wrapper around setting up the
-// virtual memory for the kernel.
-void start(uint32_t *p_bootargs)
-{
- // Initialize the virtual memory
- print_uart0("Enabling MMU...\n");
- vm_init();
- os_printf("Initialized VM datastructures.\n");
- mmap(p_bootargs);
-}
-
-
-
-// This start is what starts the kernel. Note that virtual memory is enabled
-// at this point (And running, also, in the kernel's VAS).
-void start2(uint32_t *p_bootargs)
-{
- // Setup all of the exception handlers... (hrm, interaction with VM?)
- init_vector_table();
-
- // Setup kmalloc...
- init_heap();
-
- //print_uart0("\nCourseOS!\n");
-
- splash();
-
- // Test stuff...
- /*int *p = (int*)0xFFFFFFF0;
- p[0] = 1;
- os_printf("0x%x == 1?\n", p[0]);*/
-
- //run_vm_tests();
- //INFO("There are %d free frames.\n", vm_count_free_frames());
- //run_mem_alloc_tests();
- //INFO("There are %d free frames.\n", vm_count_free_frames());
- //run_prq_tests();
- //run_hmap_tests();
-
- kfs_init(0, 0, 0);
-
-
- /*
- 4-15-15: #Prakash: What happens if we let the program load here?
- Let's make argparse_process() do its thing
-
- Note: As of 4-15-15 this fails horribly with hello.o not being
- recognized as an ELF file and DATA ABORT HANDLER being syscalled
- */
-
- // enable interrupt handling
- enable_interrupts();
-
- // initialize the timers
- initialize_timers();
-
- //assert(1==2 && "Test assert please ignore");
- process_init();
-
- sched_init();
-
- // FIXME: temporary
- os_printf("Programming the timer interrupt\n");
- start_timer_interrupts(0, 10);
-
- argparse_process(p_bootargs);
-
- print_uart0("done parsing atag list\n");
-
- //init_kheap(31 * 0x100000);
- //init_uheap(0x100000);
-
- //initialize pcb table and PID
- /* init_all_processes(); */
- //print_process_state(0);
- //run_process_tests();
- //print_PID();
- // init_q();
- //main();
-
-
- SLEEP;
-}
diff --git a/kernel/startup.s b/kernel/startup.s
deleted file mode 100644
index d0d05445..00000000
--- a/kernel/startup.s
+++ /dev/null
@@ -1,9 +0,0 @@
-.global _Reset
-
-_Reset:
- LDR sp, =stack_top
- MOV R0, R2
- BL start
-loop:
- WFI
- B loop
diff --git a/kernel/tests.c b/kernel/tests.c
deleted file mode 100644
index addc9729..00000000
--- a/kernel/tests.c
+++ /dev/null
@@ -1,42 +0,0 @@
-#include "global_defs.h"
-#include "tests.h"
-#include "klibc.h"
-#include "mem_alloc.h"
-
-//This function executes and displays results of test set given to it.
-void run_tests(Test *tests[], int num_tests)
-{
- int i;
- for (i = 0; i < num_tests; i++)
- {
- os_printf("Running test: %s", tests[i]->test_name);
- os_printf(" ... \n");
- //evaluates test here, if it passes prints PASSES else FAILS
- if (!(tests[i]->testptr)())
- {
- os_printf(":-D\n\n");
- }
- else
- {
- os_printf("=(\n\n");
- }
- }
-}
-
-Test* create_test(char *name, int (*test_function)(void*))
-{
- Test *test = (Test*) kmalloc(sizeof(Test));
- test->test_name = name;
- test->testptr = test_function;
- return test;
-}
-
-int test1()
-{
- return TRUE;
-}
-
-int test2()
-{
- return FALSE;
-}
diff --git a/kernel/tests/Makefile b/kernel/tests/Makefile
deleted file mode 100644
index 0006c0c7..00000000
--- a/kernel/tests/Makefile
+++ /dev/null
@@ -1,40 +0,0 @@
-include $(CURDIR)/../../config.mk
-
-TOOLCHAIN_PATH:=$(CURDIR)/../../$(TOOLCHAIN_DIR)/$(BARE_METAL_TARGET)/bin
-CC:=$(TOOLCHAIN_PATH)/$(BARE_METAL_TUPLE)-gcc
-INCL:=$(CURDIR)/../include/
-MAKE:=$(CURDIR)/../
-CFLAGS = -pipe -std=c99 -ffreestanding
-
-default: tests
-
-tests: test_vm.o test_hash_map.o test_mem_alloc.o test_priority_queue.o test_fs.o
- $(MAKE)Makefile
- $(CC) $(CFLAGS) -lc -o tests test_hash_map.o test_mem_alloc.o test_priority_queue.o test_vm.o test_fs.o
-
-test_fs.o: test_fs.c $(INCL)/tests.h $(INCL)/file.h ../fs/cmdline/file.h
- $(CC) $(CFLAGS) -lc -o test_fs test_fs.c
-
-test_hash_map.o: test_hash_map.c $(INCL)/tests.h $(INCL)/tests/test_hash_map.h $(INCL)hash_map.h $(INCL)/klibc.h
- $(CC) $(CFLAGS) -lc -o test_hash_map test_hash_map.c
-
-test_mem_alloc.o: test_mem_alloc.c $(INCL)/tests.h $(INCL)/tests/test_mem_alloc.h $(INCL)/klibc.h $(INCL)/vm.h
- $(CC) $(CFLAGS) -lc -o test_mem_alloc test_mem_alloc.c
-
-test_priority_queue.o: test_priority_queue.c $(INCL)/tests.h $(INCL)/tests/test_priority_queue.h $(INCL)/priority_queue.h $(INCL)/klibc.h
- $(CC) $(CFLAGS) -lc -o test_priority_queue test_priority_queue.c
-
-test_vm.o: test_vm.c $(INCL)/tests.h $(INCL)/klibc.h $(INCL)/memory.h $(INCL)/vm.h
- $(CC) $(CFLAGS) -lc -o test_vm test_vm.c
-
-%.o: %.c
- $(CC) $(CFLAGS) -c -mcpu=arm1176jzf-s $< -o $@
-
-clean:
- rm -f *.o
- rm -f tests
- rm -f test_fs
- rm -f test_vm
- rm -f test_hash_map
- rm -f test_mem_alloc
- rm -f test_priority_queue
\ No newline at end of file
diff --git a/kernel/tests/a.out b/kernel/tests/a.out
deleted file mode 100755
index 6d219ccb..00000000
Binary files a/kernel/tests/a.out and /dev/null differ
diff --git a/kernel/tests/test_fs.c b/kernel/tests/test_fs.c
deleted file mode 100644
index 6230a4ea..00000000
--- a/kernel/tests/test_fs.c
+++ /dev/null
@@ -1,107 +0,0 @@
-#include "tests.h"
-#include "klibc.h"
-#include "fs/file.h"
-
-
-
-int test_fs_1()
-{
- os_printf("\nCREATING /foo\n");
- int fd1 = kcreate("/foo", 'w', 1);
-
- os_printf("\nCREATING /bar\n");
- int fd2 = kcreate("/bar", 'w', 1);
-
- os_printf("\nCREATING /foo/baz.txt\n");
- int fd3 = kcreate("/foo/baz.txt", 'w', 0);
-
- os_printf("closing /foo/baz.txt \n");
- kclose(fd3);
-
- os_printf("\nnow opening file: /foo/baz.txt\n");
- int fd_new = kopen("/foo/baz.txt", 'w');
- os_printf("file descriptor is: %d\n", fd_new);
- os_printf("closing /foo/baz.txt \n");
- kclose(fd_new);
-
- os_printf("\nnow opening file: /foo/baz.txt again to write to it\n");
- fd_new = kopen("/foo/baz.txt", 'w');
- char *s = "Hellooooooooooooooooooooooolllllllllllll world!!!";
- kwrite(fd_new, s, os_strlen(s));
- kclose(fd_new);
- os_printf("closing /foo/baz.txt \n");
-
- os_printf("\nnow opening file: /foo/baz.txt to read from it\n");
- fd_new = kopen("/foo/baz.txt", 'r');
- char buf[256];
- os_memset(&buf, 0, 256);
- int nbytes = kread(fd_new, buf, 256);
- os_printf("Read %d bytes from file.\n", nbytes);
- os_printf("the buffer is: '%s'\n", buf);
- kclose(fd_new);
- kclose (fd1);
- kclose (fd2);
- kclose (fd3);
-
- return 0;
-}//end test_fs_1()
-
-int test_fs_1_old()
-{
-
- return 0;
-}//end test_fs1()
-
-
-
-
-int test_fs_2() {
- LOG("\nWriting a lot of data to /foobar2...\n");
-
- int fd = kcreate("/foobar2", 'w', 0);
- kclose(fd);
-
- // Okay, let's try making /foobar really big.
- fd = kopen("/foobar2", 'w');
- int buf[256];
- int i;
- for (i=0; i<256; i++) {
- buf[i] = i*3;
- }
- // Write buf out 128 times
-#define CNT 64
- for (i=0; iis_dir);
- return 0;
-}
-
-void run_fs_tests() {
- Test *tests[1];
- tests[0] = create_test("test_fs_1", &test_fs_1);
- //tests[1] = create_test("test_fs_2", &test_fs_2);
- //run_tests(tests, 2);
- // tests[1] = create_test("test_fs_2", &test_fs_2);
- run_tests(tests, 1);
-}
diff --git a/kernel/tests/test_hash_map.c b/kernel/tests/test_hash_map.c
deleted file mode 100644
index 9d76fda6..00000000
--- a/kernel/tests/test_hash_map.c
+++ /dev/null
@@ -1,187 +0,0 @@
-#include "tests.h"
-#include "tests/test_hash_map.h"
-#include "data_structures/hash_map.h"
-#include "klibc.h"
-
-#define NUM_TESTS 4
-
-#define new(a) ((a*) kmalloc(sizeof(a)))
-
-//This is where you define the tests you want to run. They return 1 on success and 0 on failure.
-
-//Tests the create function
-int test_hmap_1() {
- hmap_handle* hmap1 = hmap_create();
- hmap_handle* hmap2 = hmap_create_fixed(3);
-
- if (!hmap1) {
- os_printf("expected value");
- return TEST_FAIL;
- }
-
- if (!hmap2) {
- os_printf("expected value");
- return TEST_FAIL;
- }
-
- return TEST_OK;
-}
-
-// Test put and get functions
-int test_hmap_2() {
- hmap_handle* hmap;
- hmap = hmap_create();
-
- int* data1;
- int* data2;
- int* data3;
-
- data1 = new(int);
- *data1 = 0;
- hmap_put(hmap, (long) (*data1), data1);
-
- data2 = new(int);
- *data2 = 1;
- hmap_put(hmap, (long) (*data2), data2);
-
- data3 = new(int);
- *data3 = 2;
- hmap_put(hmap, (long) (*data3), data3);
-
- if (hmap_get(hmap, (long) (*data1)) != data1
- || hmap_get(hmap, (long) (*data2)) != data2
- || hmap_get(hmap, (long) (*data3)) != data3) {
- kfree(data1);
- kfree(data2);
- kfree(data3);
- hmap_free(hmap);
- return TEST_FAIL;
- }
-
- return TEST_OK;
-}
-
-// Test remove function
-int test_hmap_3() {
- hmap_handle* hmap;
- hmap = hmap_create();
-
- int* data1;
- int* data2;
- int* data3;
-
- data1 = new(int);
- *data1 = 0;
- hmap_put(hmap, (long) (*data1), data1);
-
- data2 = new(int);
- *data2 = 1;
- hmap_put(hmap, (long) (*data2), data2);
-
- data3 = new(int);
- *data3 = 2;
- hmap_put(hmap, (long) (*data3), data3);
-
- int* tmp1 = hmap_remove(hmap, (long) (*data1));
- int* tmp2 = hmap_remove(hmap, (long) (*data2));
- int* tmp3 = hmap_remove(hmap, (long) (*data3));
-
- if (tmp1 != data1 || tmp2 != data2 || tmp3 != data3
- || hmap_count(hmap) != 0) {
- kfree(tmp1);
- kfree(tmp2);
- kfree(tmp3);
- hmap_free(hmap);
- return TEST_FAIL;
- }
-
- kfree(tmp1);
- kfree(tmp2);
- kfree(tmp3);
- hmap_free(hmap);
- return TEST_OK;
-}
-
-// Test count function
-int test_hmap_4() {
- hmap_handle* hmap;
- hmap = hmap_create();
-
- int* data1;
- int* data2;
- int* data3;
- int* data4;
-
- data1 = new(int);
- *data1 = 0;
- hmap_put(hmap, (long) (*data1), data1);
-
- if (hmap_count(hmap) != 1) {
- kfree(data1);
- hmap_free(hmap);
- return TEST_FAIL;
- }
-
- data2 = new(int);
- *data2 = 1;
- hmap_put(hmap, (long) (*data2), data2);
-
- if (hmap_count(hmap) != 2) {
- kfree(data1);
- kfree(data2);
- hmap_free(hmap);
- return TEST_FAIL;
- }
-
- data3 = new(int);
- *data3 = 2;
- hmap_put(hmap, (long) (*data3), data3);
-
- if (hmap_count(hmap) != 3) {
- kfree(data1);
- kfree(data2);
- kfree(data3);
- hmap_free(hmap);
- return TEST_FAIL;
- }
-
- kfree(hmap_remove(hmap, (long) (*data2)));
-
- if (hmap_count(hmap) != 2) {
- kfree(data1);
- kfree(data3);
- hmap_free(hmap);
- return TEST_FAIL;
- }
-
- data4 = new(int);
- *data4 = 3;
- hmap_put(hmap, (long) (*data4), data4);
-
- if (hmap_count(hmap) != 3) {
- kfree(data1);
- kfree(data3);
- kfree(data4);
- hmap_free(hmap);
- return TEST_FAIL;
- }
-
- kfree(data1);
- kfree(data2);
- kfree(data3);
- kfree(data4);
- hmap_free(hmap);
- return TEST_OK;
-}
-
-//function running tests
-void run_hmap_tests() {
- Test *tests[NUM_TESTS];
- tests[0] = create_test("test_hmap_1", &test_hmap_1);
- tests[1] = create_test("test_hmap_2", &test_hmap_2);
- tests[2] = create_test("test_hmap_3", &test_hmap_3);
- tests[3] = create_test("test_hmap_4", &test_hmap_4);
-
- run_tests(tests, NUM_TESTS);
-}
-
diff --git a/kernel/tests/test_klibc.h b/kernel/tests/test_klibc.h
deleted file mode 100644
index ac6eb649..00000000
--- a/kernel/tests/test_klibc.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#include "tests.h"
-#include "klibc.h"
-
-#define NUM_TESTS 3
-
-int test_os_memcmp_1() {
- char buffer1[] = "DWgaOtP12df0";
- char buffer2[] = "DWGAOTP12DF0";
-
- int i = os_memcmp(buffer1, buffer2, sizeof(buffer1));
-
- if (i > 0) {
- return TEST_OK;
- } else {
- return TEST_FAIL;
- }
-}
-
-int test_os_memcmp_2() {
- char buffer1[] = "DWgaOtP12df0";
- char buffer2[] = "DWgaOtP12df0";
-
- int i = os_memcmp(buffer1, buffer2, sizeof(buffer1));
-
- if (i == 0) {
- return TEST_OK;
- } else {
- return TEST_FAIL;
- }
-}
-
-int test_os_memcmp_3() {
- char buffer1[] = "DWGAOTP12DF0";
- char buffer2[] = "DWgaOtP12df0";
-
- int i = os_memcmp(buffer1, buffer2, sizeof(buffer1));
-
- if (i < 0) {
- return TEST_OK;
- } else {
- return TEST_FAIL;
- }
-}
-
-void run_klibc_tests() {
- Test *tests[NUM_TESTS];
- tests[0] = create_test("test_os_memcmp_1", &test_os_memcmp_1);
- tests[1] = create_test("test_os_memcmp_2", &test_os_memcmp_2);
- tests[2] = create_test("test_os_memcmp_3", &test_os_memcmp_3);
-
- run_tests(tests, NUM_TESTS);
-}
diff --git a/kernel/tests/test_mem_alloc.c b/kernel/tests/test_mem_alloc.c
deleted file mode 100644
index 62b11ecb..00000000
--- a/kernel/tests/test_mem_alloc.c
+++ /dev/null
@@ -1,99 +0,0 @@
-#include "tests.h"
-#include "tests/test_mem_alloc.h"
-#include "klibc.h"
-#include "vm.h"
-
-#define NUM_TESTS 1
-
-/*
-objects += .o files of testthen make blah blah blah of build targetof upper make file, will make kernel with tests
-*/
-
-int vm_count_free_frames();
-
-//nbits is 0-22
-uint32_t gen_rand(uint64_t *state, int nbits) {
- *state = *state * 41 + (*state >> 5);
- uint32_t mask = ((1 << nbits) - 1) << 10;
- uint32_t v = (*state & mask);
- return v >> 10;
-}
-
-//Tests the create function
-int test_mem_alloc_1() {
- if (kmcheck()) {
- ERROR("Inconsistent memory to begin with...\n");
- return TEST_FAIL;
- }
-
- // Allocate some memory
- char *p = kmalloc(15);
- p = kmalloc(15);
- os_strcpy(p, "Hello!");
-
- DEBUG("%s\n", p);
-
- if (kmcheck()) {
- ERROR("allocate(15) failed.\n\n");
- return TEST_FAIL;
- }
-
- // Allocate a bunch of blocks of "random" size
- uint64_t rng = 1234567891;
-
- char *pntrs[256];
- uint32_t alloced = 0;
- int i;
- DEBUG("Starting out w/ %u bytes of heap\n", km_size());
-
- for (i = 0; i < 256; i++) {
- uint32_t size = gen_rand(&rng, 15);
- pntrs[i] = kmalloc(size);
- alloced += size;
- DEBUG("%u %u %u %u %d\n", i, km_size(), size, alloced,
- vm_count_free_frames());
- }
-
- // Test one of them
- pntrs[230][0] = 1;
-
- if(pntrs[230][0] != 1){
- ERROR("%d != 1\n", pntrs[230][0]);
- return TEST_FAIL;
- }
-
- if (kmcheck()) {
- ERROR("Memory is inconsistent :-(\n");
- return TEST_FAIL;
- }
-
- // Free all the pntrs
- for (i = 0; i < 256; i++) {
- if (pntrs[i]) {
- kfree(pntrs[i]);
- }
- }
-
- kfree(p);
-
- if (kmcheck()) {
- ERROR("Memory is inconsistent :-(\n");
- return TEST_FAIL;
- }
-
- DEBUG("heap_size = %d bytes\n", km_size());
-
- return TEST_OK;
-}
-
-//function running tests
-void run_mem_alloc_tests() {
- Test *tests[NUM_TESTS];
- Test a; // We can't rely on kmalloc for a kmalloc test.
- a.test_name = "test_mem_alloc_1";
- a.testptr = &test_mem_alloc_1;
- tests[0] = &a;
- //tests[0] = create_test("test_mem_alloc_1", &test_mem_alloc_1);
- os_printf("asdf\n");
- run_tests(tests, NUM_TESTS);
-}
diff --git a/kernel/tests/test_priority_queue.c b/kernel/tests/test_priority_queue.c
deleted file mode 100644
index 2dad0562..00000000
--- a/kernel/tests/test_priority_queue.c
+++ /dev/null
@@ -1,309 +0,0 @@
-#include "tests.h"
-#include "tests/test_priority_queue.h"
-#include "data_structures/priority_queue.h"
-#include "klibc.h"
-
-#define NUM_TESTS 6
-#define DEFAULT_COUNT 10
-#define MIN_PRIORITY 20
-#define MAX_PRIORITY -20
-
-#define new(a) ((a*) kmalloc(sizeof(a)))
-#define del(a) {if(a) kfree(a); a = 0;}
-#define ret(q, e) {prq_free(q); return e;}
-
-//This is where you define the tests you want to run. They return 1 on success and 0 on failure.
-
-//Tests the create function
-int test_prq_1() {
- prq_handle * queue;
- queue = prq_create();
- if (!queue) {
- ERROR("expected value");
- ret(queue, TEST_FAIL);
- }
-
- ret(queue, TEST_OK);
-
-}
-
-//Tests the enqueue and dequeue functions
-int test_prq_2() {
-
- prq_handle * queue;
- prq_node * hn;
- int i;
-
- queue = prq_create();
-
- // Add reverse
- for (i = MIN_PRIORITY; i >= MAX_PRIORITY; i--) {
- hn = new(prq_node);
- hn->priority = i;
- prq_enqueue(queue, hn);
- }
-
- // Add forward
- for (i = MAX_PRIORITY; i <= MIN_PRIORITY; i++) {
- hn = new(prq_node);
- hn->priority = i;
- prq_enqueue(queue, hn);
- }
-
- for (i = MAX_PRIORITY; i <= MIN_PRIORITY; i++) {
-
- hn = prq_dequeue(queue);
- int priority_1 = hn->priority;
- del(hn);
-
- hn = prq_dequeue(queue);
- int priority_2 = hn->priority;
- del(hn);
-
- if (priority_1 != priority_2) {
- ERROR("[%d]: expected [%d]\n", priority_1, priority_2);
- ret(queue, TEST_FAIL);
- }
- if (priority_1 != i) {
- ERROR("[%d]: expected [%d]\n", priority_1, i);
- ret(queue, TEST_FAIL);
- }
- if (priority_2 != i) {
- ERROR("[%d]: expected [%d]\n", priority_2, i);
- ret(queue, TEST_FAIL);
- }
- }
-
- ret(queue, TEST_OK);
-}
-
-//Tests the enqueue and dequeue functions
-int test_prq_3() {
- prq_handle * queue;
- prq_node * hn;
- int p;
-
- queue = prq_create();
-
- hn = new(prq_node);
- hn->priority = 0;
- prq_enqueue(queue, hn);
-
- hn = new(prq_node);
- hn->priority = -2;
- prq_enqueue(queue, hn);
-
- hn = new(prq_node);
- hn->priority = 1;
- prq_enqueue(queue, hn);
-
- hn = new(prq_node);
- hn->priority = -10;
- prq_enqueue(queue, hn);
-
- hn = new(prq_node);
- hn->priority = 30;
- prq_enqueue(queue, hn);
-
- hn = prq_dequeue(queue);
- p = hn->priority;
- del(hn);
-
- if (p != -10) {
- ERROR("[%d]: expected [%d]\n", p, -10);
- ret(queue, TEST_FAIL);
- }
-
- hn = prq_dequeue(queue);
- p = hn->priority;
- del(hn);
-
- if (p != -2) {
- ERROR("[%d]: expected [%d]\n", p, -2);
- ret(queue, TEST_FAIL);
- }
-
- hn = new(prq_node);
- hn->priority = 2;
- prq_enqueue(queue, hn);
-
- hn = prq_dequeue(queue);
- p = hn->priority;
- del(hn);
-
- if (p != 0) {
- ERROR("[%d]: expected [%d]\n", p, 0);
- ret(queue, TEST_FAIL);
- }
-
- prq_dequeue(queue);
-
- hn = prq_dequeue(queue);
- p = hn->priority;
- del(hn);
-
- if (p != 2) {
- ERROR("[%d]: expected [%d]\n", p, 2);
- ret(queue, TEST_FAIL);
- }
-
- hn = prq_dequeue(queue);
- p = hn->priority;
- del(hn);
-
- if (p != 30) {
- ERROR("[%d]: expected [%d]\n", p, 30);
- ret(queue, TEST_FAIL);
- }
-
- ret(queue, TEST_OK);
-
-}
-
-//testing peek function
-int test_prq_4() {
- prq_handle * queue;
- prq_node * hn;
- queue = prq_create();
-
- if (prq_peek(queue) && queue->count < 1) {
- ERROR("expected [%d]\n", 0);
- ret(queue, TEST_FAIL);
- }
-
- hn = new(prq_node);
- hn->priority = 0;
- prq_enqueue(queue, hn);
-
- hn = new(prq_node);
- hn->priority = 1;
- prq_enqueue(queue, hn);
-
- hn = new(prq_node);
- hn->priority = 3;
- prq_enqueue(queue, hn);
-
- hn = prq_dequeue(queue);
- del(hn);
-
- hn = prq_dequeue(queue);
- del(hn);
-
- hn = prq_dequeue(queue);
- del(hn);
-
- if (prq_peek(queue) && queue->count < 1) {
- ERROR("expected [%d]\n", 0);
- ret(queue, TEST_FAIL);
- }
-
- ret(queue, TEST_OK);
-
-}
-
-//testing functionality of prq_create vs prq_fixed_create
-int test_prq_5() {
- prq_handle * queue1;
- prq_node * hn1;
- queue1 = prq_create();
-
- hn1 = new(prq_node);
- hn1->priority = 0;
- prq_enqueue(queue1, hn1);
-
- prq_handle * queue2;
- prq_node * hn2;
- queue2 = prq_create_fixed(DEFAULT_COUNT);
-
- hn2 = new(prq_node);
- hn2->priority = 0;
- prq_enqueue(queue2, hn2);
-
- if (queue1->heap_size != queue2->heap_size) {
- ERROR("expected equal heap_size");
- ret(queue1, TEST_FAIL);
- }
-
- ret(queue1, TEST_OK);
-}
-
-// Test remove function
-int test_prq_6() {
- prq_handle * queue1;
- prq_handle * queue2;
- prq_node * hn1;
- prq_node * hn2;
- prq_node * hn3;
- prq_node * hn4;
- prq_node * tmp1;
- prq_node * tmp2;
-
- queue1 = prq_create();
- queue2 = prq_create();
-
- hn1 = new(prq_node);
- hn1->priority = 1;
-
- hn2 = new(prq_node);
- hn2->priority = 2;
-
- hn3 = new(prq_node);
- hn3->priority = 3;
-
- hn4 = new(prq_node);
- hn4->priority = 4;
-
- prq_enqueue(queue1, hn1);
- prq_enqueue(queue1, hn2);
- prq_enqueue(queue1, hn3);
- prq_enqueue(queue1, hn4);
- prq_remove(queue1, hn1);
- prq_remove(queue1, hn3);
- // Double remove
- prq_remove(queue1, hn3);
-
- prq_enqueue(queue2, hn2);
- prq_enqueue(queue2, hn4);
-
-
- if (queue1->count != queue2->count) {
- ERROR("expected equal heap_size");
- for(int i = 0; i < queue1->count; ++i) {
- prq_node * tmp = prq_dequeue(queue1);
- del(tmp);
- }
- del(queue2);
- ret(queue1, TEST_FAIL);
- }
-
- for (int size = 0; size < queue1->count; ++size) {
- tmp1 = prq_dequeue(queue1);
- tmp2 = prq_dequeue(queue2);
- if (tmp1->priority != tmp2->priority) {
- del(tmp1);
- for(int i = 0; i < queue1->count; ++i) {
- prq_node * tmp = prq_dequeue(queue1);
- del(tmp);
- }
- del(queue2);
- ret(queue1, TEST_FAIL);
- }
- del(tmp1);
- }
- del(queue2);
- ret(queue1, TEST_OK);
-}
-
-//function running tests
-void run_prq_tests() {
- Test *tests[NUM_TESTS];
- tests[0] = create_test("test_prq_1", &test_prq_1);
- tests[1] = create_test("test_prq_2", &test_prq_2);
- tests[2] = create_test("test_prq_3", &test_prq_3);
- tests[3] = create_test("test_prq_4", &test_prq_4);
- tests[4] = create_test("test_prq_5", &test_prq_5);
- tests[5] = create_test("test_prq_6", &test_prq_6);
-
- run_tests(tests, NUM_TESTS);
-}
-
diff --git a/kernel/tests/test_vm.c b/kernel/tests/test_vm.c
deleted file mode 100644
index 6bec6944..00000000
--- a/kernel/tests/test_vm.c
+++ /dev/null
@@ -1,160 +0,0 @@
-#include "tests.h"
-#include "klibc.h"
-#include "memory.h"
-#include "vm.h"
-
-#define NUM_TESTS 1
-
-int test_vm_1() {
- os_printf("asdf\n");
-
- struct vas *vas1 = vm_new_vas();
- LOG("Got new vas at 0x%X\n", vas1);
-
- // We're part of the kernel, which is already mapped into vas1.
- // But our stack isn't, so let's add that mapping.
- unsigned int mystack = (unsigned int) &vas1;
- mystack &= 0xFFF00000; // Round down to nearest MB
- LOG("Stack addr: 0x%X\n", mystack);
- LOG("Created page table w/ 0xFFF00000's entry = 0x%X\n",
- vas1->l1_pagetable[V_KDSBASE>>20]);
-
- vm_enable_vas(vas1);
-
- // Can we still print?
- INFO("Hey, I'm printing!\n");
-
- // Do we still have the stack?
- // FIXME Update constant as necessary
-#define STACK_ADDR 0xF020000C
- if (((int) vas1) != STACK_ADDR) {
- ERROR("Invalid stack");
- return TEST_FAIL;
- }
-
- struct vas *vas2 = (struct vas*) V_L1PTBASE;
- INFO("%X (%X)\n", vas2, &vas2);
- INFO("%X\n", *((unsigned int* ) vas2));
- INFO("%X\n", vas2->l1_pagetable);
- INFO("Entry: %x\n",
- vas1->l1_pagetable[(unsigned int ) vas2->l1_pagetable >> 20]);
- INFO("%X\n", vas2->l1_pagetable[0]);
- INFO("(deref: entry at 0x200000: 0x%X)\n",
- vas2->l1_pagetable[0x200000 >> 20]);
-
- // Test making a thing in this thing
- struct vas *vas3 = vm_new_vas();
- vm_enable_vas(vas3);
- INFO("%X and %X and %X\n", vas1, vas2, vas3);
-
- // Test allocating frames...
-#define P3_BASE 0x24000000
- int retval = vm_allocate_page(vas3, (void*) P3_BASE,
- VM_PERM_PRIVILEGED_RW);
-
- if (retval) {
- ERROR("ERROR: vm_allocate_page returned %x\n", retval);
- return TEST_FAIL;
- }
-
- int *p = (int*) 0xFFFFFFF0;
- p[0] = 1;
-
- if (p[0] != 1) {
- ERROR("0x%x == 1?\n", p[0]);
- return TEST_FAIL;
- }
-
- // Oh man! We should be able to write to there!
- p = (int*) P3_BASE;
- p[0] = 1;
-
- LOG("%x %x\n", &p, p);
-
- if (p[0] != 1) {
- ERROR("0x%x == 1?\n", p[0]);
- return TEST_FAIL;
- }
-
- // Test shared memory...
- LOG("Testing shared memory...\n");
- int *p_3 = (int*) P3_BASE;//0x24000000;
- int *p_1 = (int*) 0x31000000;
- retval = vm_map_shared_memory(vas1, p_1, vas3, p_3, VM_PERM_PRIVILEGED_RW);
- LOG("map_shared_memory returned %d\n", retval);
-
- p_3[0] = 321;
- vm_enable_vas(vas1);
- if (p_1[0] != 321) {
- ERROR("0x%x == 321?", p_1[0]);
- return TEST_FAIL;
- }
- p_1[1] = 456;
-
- vm_enable_vas(vas3);
- if (p_3[1] != 456) {
- ERROR("0x%x == 456?", p_3[1]);
- return TEST_FAIL;
- }
-
- // Test allocating many frames...
- /*p += BLOCK_SIZE;
- while (!vm_allocate_page(vas3, (void*) p, 0)) {
- //LOG("Allocated memory...\n");
- p += BLOCK_SIZE;
- }
-
- p -= BLOCK_SIZE;
- LOG("Highest frame allocated: 0x%X\n", p);
-
- while ((unsigned int) p > P3_BASE) {
- //LOG("Freed memory...\n");
- vm_free_page(vas3, p);
- p -= BLOCK_SIZE;
- }*/
-
- // Test the data abort...
- WARN("You should see a data abort...\n");
- int i = p[-1];
- LOG("%d\n", i);
-
- // Free the page!
- LOG("Freeing page at %X\n", p);
- vm_free_page(vas3, p);
-
- // Clean up & switch back to the kernel's VAS before we return.
- vm_enable_vas((struct vas*) KERNEL_VAS);
-
- return TEST_OK;
-}
-
-void vm_test_early() {
- os_printf("Test code for VM (early).\n");
-
-#if 0
- // Test 4KB pages
- os_printf("0x%X\n", ((unsigned int *)(V_L1PTBASE + PAGE_TABLE_SIZE))[(PMAPBASE+0x100000)>>20]);
- os_printf("entry at the address: 0x%X\n", ((unsigned int *)(V_L1PTBASE + PAGE_TABLE_SIZE))[(PMAPBASE+0x100000)>>20]);
- unsigned int *p2 = (unsigned int*)(PMAPBASE+0x100000);
- os_printf("0x%X\n",p2);
- p2[1]++;
- p2[1023]++;
- os_printf("Should not have seen a page fault, should see one now.\n");
- p2[1024]++;
-
- // Hey, let's check the access bit now.
- p2 = ((unsigned int *)(V_L1PTBASE + PAGE_TABLE_SIZE));
- os_printf("Entry is the address: 0x%X\n", ((unsigned int *)(V_L1PTBASE + PAGE_TABLE_SIZE))[(PMAPBASE+0x100000)>>20]);
-#endif
-
- os_printf("Leaving early test code for VM.\n");
- //while (1);
-}
-
-void run_vm_tests() {
- Test *tests[NUM_TESTS];
- tests[0] = create_test("test_vm_1", &test_vm_1);
- run_tests(tests, NUM_TESTS);
- // Just in case it returned in error...
- //vm_enable_vas((struct vas*) KERNEL_VAS);
-}
diff --git a/kernel/tests/testingsuite_example/.DS_Store b/kernel/tests/testingsuite_example/.DS_Store
deleted file mode 100644
index fb0c2723..00000000
Binary files a/kernel/tests/testingsuite_example/.DS_Store and /dev/null differ
diff --git a/kernel/tests/testingsuite_example/arrayfill/a.out b/kernel/tests/testingsuite_example/arrayfill/a.out
deleted file mode 100755
index 1be2cdbf..00000000
Binary files a/kernel/tests/testingsuite_example/arrayfill/a.out and /dev/null differ
diff --git a/kernel/tests/testingsuite_example/arrayfill/arrayfill.c b/kernel/tests/testingsuite_example/arrayfill/arrayfill.c
deleted file mode 100644
index b811254b..00000000
--- a/kernel/tests/testingsuite_example/arrayfill/arrayfill.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "arrayfill.h"
-
-void arrfill(int n) {
- int i;
- int temp = 1;
- for (i = 0; i < n; i++) {
- arr[i] = temp;
- temp++;
- }
-}
-
-int main () {
- arrfill(5);
- int i;
- int size = 5;
- for (i = 0; i < size; ++i) {
- printf("%d ", arr[i]);
- }
- printf("\n");
- return 0;
-}
\ No newline at end of file
diff --git a/kernel/tests/testingsuite_example/arrayfill/arrayfill.h b/kernel/tests/testingsuite_example/arrayfill/arrayfill.h
deleted file mode 100644
index 9f0833f3..00000000
--- a/kernel/tests/testingsuite_example/arrayfill/arrayfill.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#include
-#include
-#define SIZEARRAY(x) (sizeof(x) / sizeof ((x[0]))
-
-int arr[100];
-
-void arrfill(int);
-
-void print();
\ No newline at end of file
diff --git a/kernel/tests/testingsuite_example/arrayfill/tap.c b/kernel/tests/testingsuite_example/arrayfill/tap.c
deleted file mode 100755
index 37f509e8..00000000
--- a/kernel/tests/testingsuite_example/arrayfill/tap.c
+++ /dev/null
@@ -1,369 +0,0 @@
-/*
-libtap - Write tests in C
-Copyright 2012 Jake Gelbman
-This file is licensed under the GPLv2 or any later version
-*/
-
-#define _DEFAULT_SOURCE 1
-
-#include
-#include
-#include
-#include
-#include "tap.h"
-
-static int expected_tests = NO_PLAN;
-static int failed_tests;
-static int current_test;
-static char *todo_mesg;
-
-static char *
-vstrdupf (const char *fmt, va_list args) {
- char *str;
- int size;
- va_list args2;
- va_copy(args2, args);
- if (!fmt)
- fmt = "";
- size = vsnprintf(NULL, 0, fmt, args2) + 2;
- str = malloc(size);
- if (!str) {
- perror("malloc error");
- exit(1);
- }
- vsprintf(str, fmt, args);
- va_end(args2);
- return str;
-}
-
-void
-tap_plan (int tests, const char *fmt, ...) {
- expected_tests = tests;
- if (tests == SKIP_ALL) {
- char *why;
- va_list args;
- va_start(args, fmt);
- why = vstrdupf(fmt, args);
- va_end(args);
- printf("1..0 ");
- note("SKIP %s\n", why);
- exit(0);
- }
- if (tests != NO_PLAN) {
- printf("1..%d\n", tests);
- }
-}
-
-int
-vok_at_loc (const char *file, int line, int test, const char *fmt,
- va_list args)
-{
- char *name = vstrdupf(fmt, args);
- if (!test)
- printf("not ");
- printf("ok %d", ++current_test);
- if (*name)
- printf(" - %s", name);
- if (todo_mesg) {
- printf(" # TODO");
- if (*todo_mesg)
- printf(" %s", todo_mesg);
- }
- printf("\n");
- if (!test) {
- fprintf(stderr, "# Failed ");
- if (todo_mesg)
- fprintf(stderr, "(TODO) ");
- fprintf(stderr, "test ");
- if (*name)
- fprintf(stderr, "'%s'\n# ", name);
- fprintf(stderr, "at %s line %d.\n", file, line);
- if (!todo_mesg)
- failed_tests++;
- }
- free(name);
- return test;
-}
-
-int
-ok_at_loc (const char *file, int line, int test, const char *fmt, ...) {
- va_list args;
- va_start(args, fmt);
- vok_at_loc(file, line, test, fmt, args);
- va_end(args);
- return test;
-}
-
-static int
-mystrcmp (const char *a, const char *b) {
- return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
-}
-
-#define eq(a, b) (!mystrcmp(a, b))
-#define ne(a, b) (mystrcmp(a, b))
-
-int
-is_at_loc (const char *file, int line, const char *got, const char *expected,
- const char *fmt, ...)
-{
- int test = eq(got, expected);
- va_list args;
- va_start(args, fmt);
- vok_at_loc(file, line, test, fmt, args);
- va_end(args);
- if (!test) {
- diag(" got: '%s'", got);
- diag(" expected: '%s'", expected);
- }
- return test;
-}
-
-int
-isnt_at_loc (const char *file, int line, const char *got, const char *expected,
- const char *fmt, ...)
-{
- int test = ne(got, expected);
- va_list args;
- va_start(args, fmt);
- vok_at_loc(file, line, test, fmt, args);
- va_end(args);
- if (!test) {
- diag(" got: '%s'", got);
- diag(" expected: anything else");
- }
- return test;
-}
-
-int
-cmp_ok_at_loc (const char *file, int line, int a, const char *op, int b,
- const char *fmt, ...)
-{
- int test = eq(op, "||") ? a || b
- : eq(op, "&&") ? a && b
- : eq(op, "|") ? a | b
- : eq(op, "^") ? a ^ b
- : eq(op, "&") ? a & b
- : eq(op, "==") ? a == b
- : eq(op, "!=") ? a != b
- : eq(op, "<") ? a < b
- : eq(op, ">") ? a > b
- : eq(op, "<=") ? a <= b
- : eq(op, ">=") ? a >= b
- : eq(op, "<<") ? a << b
- : eq(op, ">>") ? a >> b
- : eq(op, "+") ? a + b
- : eq(op, "-") ? a - b
- : eq(op, "*") ? a * b
- : eq(op, "/") ? a / b
- : eq(op, "%") ? a % b
- : diag("unrecognized operator '%s'", op);
- va_list args;
- va_start(args, fmt);
- vok_at_loc(file, line, test, fmt, args);
- va_end(args);
- if (!test) {
- diag(" %d", a);
- diag(" %s", op);
- diag(" %d", b);
- }
- return test;
-}
-
-static int
-find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
- size_t i;
- if (a == b)
- return 0;
- if (!a || !b)
- return 2;
- for (i = 0; i < n; i++) {
- if (a[i] != b[i]) {
- *offset = i;
- return 1;
- }
- }
- return 0;
-}
-
-int
-cmp_mem_at_loc (const char *file, int line, const void *got,
- const void *expected, size_t n, const char *fmt, ...)
-{
- size_t offset;
- int diff = find_mem_diff(got, expected, n, &offset);
- va_list args;
- va_start(args, fmt);
- vok_at_loc(file, line, !diff, fmt, args);
- va_end(args);
- if (diff == 1) {
- diag(" Difference starts at offset %d", offset);
- diag(" got: 0x%02x", ((unsigned char *)got)[offset]);
- diag(" expected: 0x%02x", ((unsigned char *)expected)[offset]);
- }
- else if (diff == 2) {
- diag(" got: %s", got ? "not NULL" : "NULL");
- diag(" expected: %s", expected ? "not NULL" : "NULL");
- }
- return !diff;
-}
-
-static void
-vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
- char *mesg, *line;
- int i;
- if (!fmt)
- return;
- mesg = vstrdupf(fmt, args);
- line = mesg;
- for (i = 0; *line; i++) {
- char c = mesg[i];
- if (!c || c == '\n') {
- mesg[i] = '\0';
- fprintf(fh, "# %s\n", line);
- if (!c)
- break;
- mesg[i] = c;
- line = mesg + i + 1;
- }
- }
- free(mesg);
- return;
-}
-
-int
-diag (const char *fmt, ...) {
- va_list args;
- va_start(args, fmt);
- vdiag_to_fh(stderr, fmt, args);
- va_end(args);
- return 0;
-}
-
-int
-note (const char *fmt, ...) {
- va_list args;
- va_start(args, fmt);
- vdiag_to_fh(stdout, fmt, args);
- va_end(args);
- return 0;
-}
-
-int
-exit_status () {
- int retval = 0;
- if (expected_tests == NO_PLAN) {
- printf("1..%d\n", current_test);
- }
- else if (current_test != expected_tests) {
- diag("Looks like you planned %d test%s but ran %d.",
- expected_tests, expected_tests > 1 ? "s" : "", current_test);
- retval = 2;
- }
- if (failed_tests) {
- diag("Looks like you failed %d test%s of %d run.",
- failed_tests, failed_tests > 1 ? "s" : "", current_test);
- retval = 1;
- }
- return retval;
-}
-
-int
-bail_out (int ignore, const char *fmt, ...) {
- va_list args;
- va_start(args, fmt);
- printf("Bail out! ");
- vprintf(fmt, args);
- printf("\n");
- va_end(args);
- exit(255);
- return 0;
-}
-
-void
-tap_skip (int n, const char *fmt, ...) {
- char *why;
- va_list args;
- va_start(args, fmt);
- why = vstrdupf(fmt, args);
- va_end(args);
- while (n --> 0) {
- printf("ok %d ", ++current_test);
- note("skip %s\n", why);
- }
- free(why);
-}
-
-void
-tap_todo (int ignore, const char *fmt, ...) {
- va_list args;
- va_start(args, fmt);
- todo_mesg = vstrdupf(fmt, args);
- va_end(args);
-}
-
-void
-tap_end_todo () {
- free(todo_mesg);
- todo_mesg = NULL;
-}
-
-#ifndef _WIN32
-#include
-#include
-#include
-
-#if defined __APPLE__ || defined BSD
-#define MAP_ANONYMOUS MAP_ANON
-#endif
-
-/* Create a shared memory int to keep track of whether a piece of code executed
-dies. to be used in the dies_ok and lives_ok macros. */
-int
-tap_test_died (int status) {
- static int *test_died = NULL;
- int prev;
- if (!test_died) {
- test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_ANONYMOUS, -1, 0);
- *test_died = 0;
- }
- prev = *test_died;
- *test_died = status;
- return prev;
-}
-
-int
-like_at_loc (int for_match, const char *file, int line, const char *got,
- const char *expected, const char *fmt, ...)
-{
- int test;
- regex_t re;
- va_list args;
- int err = regcomp(&re, expected, REG_EXTENDED);
- if (err) {
- char errbuf[256];
- regerror(err, &re, errbuf, sizeof errbuf);
- fprintf(stderr, "Unable to compile regex '%s': %s at %s line %d\n",
- expected, errbuf, file, line);
- exit(255);
- }
- err = regexec(&re, got, 0, NULL, 0);
- regfree(&re);
- test = for_match ? !err : err;
- va_start(args, fmt);
- vok_at_loc(file, line, test, fmt, args);
- va_end(args);
- if (!test) {
- if (for_match) {
- diag(" '%s'", got);
- diag(" doesn't match: '%s'", expected);
- }
- else {
- diag(" '%s'", got);
- diag(" matches: '%s'", expected);
- }
- }
- return test;
-}
-#endif
-
diff --git a/kernel/tests/testingsuite_example/arrayfill/tap.h b/kernel/tests/testingsuite_example/arrayfill/tap.h
deleted file mode 100755
index 302e6d85..00000000
--- a/kernel/tests/testingsuite_example/arrayfill/tap.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
-libtap - Write tests in C
-Copyright 2012 Jake Gelbman
-This file is licensed under the GPLv2 or any later version
-*/
-
-#ifndef __TAP_H__
-#define __TAP_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef va_copy
-#ifdef __va_copy
-#define va_copy __va_copy
-#else
-#define va_copy(d, s) ((d) = (s))
-#endif
-#endif
-
-#include
-#include
-#include
-
-int vok_at_loc (const char *file, int line, int test, const char *fmt,
- va_list args);
-int ok_at_loc (const char *file, int line, int test, const char *fmt,
- ...);
-int is_at_loc (const char *file, int line, const char *got,
- const char *expected, const char *fmt, ...);
-int isnt_at_loc (const char *file, int line, const char *got,
- const char *expected, const char *fmt, ...);
-int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
- int b, const char *fmt, ...);
-int cmp_mem_at_loc (const char *file, int line, const void *got,
- const void *expected, size_t n, const char *fmt, ...);
-int bail_out (int ignore, const char *fmt, ...);
-void tap_plan (int tests, const char *fmt, ...);
-int diag (const char *fmt, ...);
-int note (const char *fmt, ...);
-int exit_status (void);
-void tap_skip (int n, const char *fmt, ...);
-void tap_todo (int ignore, const char *fmt, ...);
-void tap_end_todo (void);
-
-#define NO_PLAN -1
-#define SKIP_ALL -2
-#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
-#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
-#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
-#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
-#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL);
-#define plan(...) tap_plan(__VA_ARGS__, NULL)
-#define done_testing() return exit_status()
-#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
-#define pass(...) ok(1, "" __VA_ARGS__)
-#define fail(...) ok(0, "" __VA_ARGS__)
-
-#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
-#define end_skip } while (0)
-
-#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
-#define end_todo tap_end_todo()
-
-#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
-#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
-
-#ifdef _WIN32
-#define like(...) tap_skip(1, "like is not implemented on Windows")
-#define unlike tap_skip(1, "unlike is not implemented on Windows")
-#define dies_ok_common(...) \
- tap_skip(1, "Death detection is not supported on Windows")
-#else
-#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
-#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
-int like_at_loc (int for_match, const char *file, int line,
- const char *got, const char *expected,
- const char *fmt, ...);
-#include
-#include
-#include
-int tap_test_died (int status);
-#define dies_ok_common(for_death, code, ...) \
- do { \
- int cpid; \
- int it_died; \
- tap_test_died(1); \
- cpid = fork(); \
- switch (cpid) { \
- case -1: \
- perror("fork error"); \
- exit(1); \
- case 0: \
- close(1); \
- close(2); \
- code \
- tap_test_died(0); \
- exit(0); \
- } \
- if (waitpid(cpid, NULL, 0) < 0) { \
- perror("waitpid error"); \
- exit(1); \
- } \
- it_died = tap_test_died(0); \
- if (!it_died) \
- {code} \
- ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
- } while (0)
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/kernel/tests/testingsuite_example/arrayfill/testarrayfill.c b/kernel/tests/testingsuite_example/arrayfill/testarrayfill.c
deleted file mode 100644
index 1426bf18..00000000
--- a/kernel/tests/testingsuite_example/arrayfill/testarrayfill.c
+++ /dev/null
@@ -1,28 +0,0 @@
-// #include
-// #include "arrayfill.h"
-
-// int first_element() {
-// if (arr[0] == 1) {
-// return 1;
-// }
-// else {
-// return 0;
-// }
-// }
-
-// int main() {
-// plan(1);
-// ok(first_element(), "checks the first element");
-// done_testing();
-// }
-
-#include "tap.h"
-int main() {
- plan(1);
- ok(3 == 3);
- done_testing();
-}
-
-
-
-
diff --git a/kernel/threads/kthreads.c b/kernel/threads/kthreads.c
deleted file mode 100644
index 420148b8..00000000
--- a/kernel/threads/kthreads.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * kthreads.c
- *
- * Created on: Apr 23, 2015
- * Author: mwkurian
- */
-
-#include "kthread.h"
-#include
-
-kthread_handle* kthread_create(kthread_callback_handler cb_handler)
-{
- kthread_handle * kthread = kmalloc(sizeof(kthread_handle));
- kthread->cb_handler = cb_handler;
- return kthread;
-}
-
-uint32_t kthread_start(kthread_handle * kthread)
-{
- sched_task * task = sched_create_task(kthread);
- sched_add_task(task);
-}
-
diff --git a/kernel/uboot-commands.ubt b/kernel/uboot-commands.ubt
deleted file mode 100644
index c6945626..00000000
--- a/kernel/uboot-commands.ubt
+++ /dev/null
@@ -1,2 +0,0 @@
-setenv bootargs root=/dev/ram mem=128M -load /hello
-bootm 0x210000
diff --git a/kernel/vm/fastlz/6pack.c b/kernel/vm/fastlz/6pack.c
deleted file mode 100644
index 89a1128d..00000000
--- a/kernel/vm/fastlz/6pack.c
+++ /dev/null
@@ -1,636 +0,0 @@
-/*
- 6PACK - file compressor using FastLZ (lightning-fast compression library)
-
- Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-*/
-
-#include
-#include
-#include
-
-#define SIXPACK_VERSION_MAJOR 0
-#define SIXPACK_VERSION_MINOR 1
-#define SIXPACK_VERSION_REVISION 0
-#define SIXPACK_VERSION_STRING "snapshot 20070615"
-
-#include "fastlz.h"
-
-#undef PATH_SEPARATOR
-
-#if defined(MSDOS) || defined(__MSDOS__) || defined(MSDOS)
-#define PATH_SEPARATOR '\\'
-#endif
-
-#if defined(WIN32) || defined(__NT__) || defined(_WIN32) || defined(__WIN32__)
-#define PATH_SEPARATOR '\\'
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define inline __inline
-#endif
-#endif
-
-#ifndef PATH_SEPARATOR
-#define PATH_SEPARATOR '/'
-#endif
-
-#undef SIXPACK_BENCHMARK_WIN32
-#if defined(WIN32) || defined(__NT__) || defined(_WIN32) || defined(__WIN32__)
-#if defined(_MSC_VER) || defined(__GNUC__)
-#define SIXPACK_BENCHMARK_WIN32
-#include
-#endif
-#endif
-
-/* magic identifier for 6pack file */
-static unsigned char sixpack_magic[8] = {137, '6', 'P', 'K', 13, 10, 26, 10};
-
-#define BLOCK_SIZE (2*64*1024)
-
-/* prototypes */
-static inline unsigned long update_adler32(unsigned long checksum, const void *buf, int len);
-void usage(void);
-int detect_magic(FILE *f);
-void write_magic(FILE *f);
-void write_chunk_header(FILE* f, int id, int options, unsigned long size,
-unsigned long checksum, unsigned long extra);
-unsigned long block_compress(const unsigned char* input, unsigned long length, unsigned char* output);
-int pack_file_compressed(const char* input_file, int method, int level, FILE* f);
-int pack_file(int compress_level, const char* input_file, const char* output_file);
-
-/* for Adler-32 checksum algorithm, see RFC 1950 Section 8.2 */
-#define ADLER32_BASE 65521
-static inline unsigned long update_adler32(unsigned long checksum, const void *buf, int len)
-{
- const unsigned char* ptr = (const unsigned char*)buf;
- unsigned long s1 = checksum & 0xffff;
- unsigned long s2 = (checksum >> 16) & 0xffff;
-
- while(len>0)
- {
- unsigned k = len < 5552 ? len : 5552;
- len -= k;
-
- while(k >= 8)
- {
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- k -= 8;
- }
-
- while(k-- > 0)
- {
- s1 += *ptr++; s2 += s1;
- }
- s1 = s1 % ADLER32_BASE;
- s2 = s2 % ADLER32_BASE;
- }
- return (s2 << 16) + s1;
-}
-
-void usage(void)
-{
- printf("6pack: high-speed file compression tool\n");
- printf("Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)\n");
- printf("\n");
- printf("Usage: 6pack [options] input-file output-file\n");
- printf("\n");
- printf("Options:\n");
- printf(" -1 compress faster\n");
- printf(" -2 compress better\n");
- printf(" -v show program version\n");
-#ifdef SIXPACK_BENCHMARK_WIN32
- printf(" -mem check in-memory compression speed\n");
-#endif
- printf("\n");
-}
-
-/* return non-zero if magic sequence is detected */
-/* warning: reset the read pointer to the beginning of the file */
-int detect_magic(FILE *f)
-{
- unsigned char buffer[8];
- size_t bytes_read;
- int c;
-
- fseek(f, SEEK_SET, 0);
- bytes_read = fread(buffer, 1, 8, f);
- fseek(f, SEEK_SET, 0);
- if(bytes_read < 8)
- return 0;
-
- for(c = 0; c < 8; c++)
- if(buffer[c] != sixpack_magic[c])
- return 0;
-
- return -1;
-}
-
-void write_magic(FILE *f)
-{
- fwrite(sixpack_magic, 8, 1, f);
-}
-
-void write_chunk_header(FILE* f, int id, int options, unsigned long size,
- unsigned long checksum, unsigned long extra)
-{
- unsigned char buffer[16];
-
- buffer[0] = id & 255;
- buffer[1] = id >> 8;
- buffer[2] = options & 255;
- buffer[3] = options >> 8;
- buffer[4] = size & 255;
- buffer[5] = (size >> 8) & 255;
- buffer[6] = (size >> 16) & 255;
- buffer[7] = (size >> 24) & 255;
- buffer[8] = checksum & 255;
- buffer[9] = (checksum >> 8) & 255;
- buffer[10] = (checksum >> 16) & 255;
- buffer[11] = (checksum >> 24) & 255;
- buffer[12] = extra & 255;
- buffer[13] = (extra >> 8) & 255;
- buffer[14] = (extra >> 16) & 255;
- buffer[15] = (extra >> 24) & 255;
-
- fwrite(buffer, 16, 1, f);
-}
-
-int pack_file_compressed(const char* input_file, int method, int level, FILE* f)
-{
- FILE* in;
- unsigned long fsize;
- unsigned long checksum;
- const char* shown_name;
- unsigned char buffer[BLOCK_SIZE];
- unsigned char result[BLOCK_SIZE*2]; /* FIXME twice is too large */
- unsigned char progress[20];
- int c;
- unsigned long percent;
- unsigned long total_read;
- unsigned long total_compressed;
- int chunk_size;
-
- /* sanity check */
- in = fopen(input_file, "rb");
- if(!in)
- {
- printf("Error: could not open %s\n", input_file);
- return -1;
- }
-
- /* find size of the file */
- fseek(in, 0, SEEK_END);
- fsize = ftell(in);
- fseek(in, 0, SEEK_SET);
-
- /* already a 6pack archive? */
- if(detect_magic(in))
- {
- printf("Error: file %s is already a 6pack archive!\n", input_file);
- fclose(in);
- return -1;
- }
-
- /* truncate directory prefix, e.g. "foo/bar/FILE.txt" becomes "FILE.txt" */
- shown_name = input_file + strlen(input_file) - 1;
- while(shown_name > input_file)
- if(*(shown_name-1) == PATH_SEPARATOR)
- break;
- else
- shown_name--;
-
- /* chunk for File Entry */
- buffer[0] = fsize & 255;
- buffer[1] = (fsize >> 8) & 255;
- buffer[2] = (fsize >> 16) & 255;
- buffer[3] = (fsize >> 24) & 255;
-#if 0
- buffer[4] = (fsize >> 32) & 255;
- buffer[5] = (fsize >> 40) & 255;
- buffer[6] = (fsize >> 48) & 255;
- buffer[7] = (fsize >> 56) & 255;
-#else
- /* because fsize is only 32-bit */
- buffer[4] = 0;
- buffer[5] = 0;
- buffer[6] = 0;
- buffer[7] = 0;
-#endif
- buffer[8] = (strlen(shown_name)+1) & 255;
- buffer[9] = (strlen(shown_name)+1) >> 8;
- checksum = 1L;
- checksum = update_adler32(checksum, buffer, 10);
- checksum = update_adler32(checksum, shown_name, strlen(shown_name)+1);
- write_chunk_header(f, 1, 0, 10+strlen(shown_name)+1, checksum, 0);
- fwrite(buffer, 10, 1, f);
- fwrite(shown_name, strlen(shown_name)+1, 1, f);
- total_compressed = 16 + 10 + strlen(shown_name)+1;
-
- /* for progress status */
- memset(progress, ' ', 20);
- if(strlen(shown_name) < 16)
- for(c = 0; c < (int)strlen(shown_name); c++)
- progress[c] = shown_name[c];
- else
- {
- for(c = 0; c < 13; c++)
- progress[c] = shown_name[c];
- progress[13] = '.';
- progress[14] = '.';
- progress[15] = ' ';
- }
- progress[16] = '[';
- progress[17] = 0;
- printf("%s", progress);
- for(c = 0; c < 50; c++)
- printf(".");
- printf("]\r");
- printf("%s", progress);
-
- /* read file and place in archive */
- total_read = 0;
- percent = 0;
- for(;;)
- {
- int compress_method = method;
- int last_percent = (int)percent;
- size_t bytes_read = fread(buffer, 1, BLOCK_SIZE, in);
- if(bytes_read == 0)
- break;
- total_read += bytes_read;
-
- /* for progress */
- if(fsize < (1<<24))
- percent = total_read * 100 / fsize;
- else
- percent = total_read/256 * 100 / (fsize >>8);
- percent >>= 1;
- while(last_percent < (int)percent)
- {
- printf("#");
- last_percent++;
- }
-
- /* too small, don't bother to compress */
- if(bytes_read < 32)
- compress_method = 0;
-
- /* write to output */
- switch(compress_method)
- {
- /* FastLZ */
- case 1:
- chunk_size = fastlz_compress_level(level, buffer, bytes_read, result);
- checksum = update_adler32(1L, result, chunk_size);
- write_chunk_header(f, 17, 1, chunk_size, checksum, bytes_read);
- fwrite(result, 1, chunk_size, f);
- total_compressed += 16;
- total_compressed += chunk_size;
- break;
-
- /* uncompressed, also fallback method */
- case 0:
- default:
- checksum = 1L;
- checksum = update_adler32(checksum, buffer, bytes_read);
- write_chunk_header(f, 17, 0, bytes_read, checksum, bytes_read);
- fwrite(buffer, 1, bytes_read, f);
- total_compressed += 16;
- total_compressed += bytes_read;
- break;
- }
- }
-
- fclose(in);
- if(total_read != fsize)
- {
- printf("\n");
- printf("Error: reading %s failed!\n", input_file);
- return -1;
- }
- else
- {
- printf("] ");
- if(total_compressed < fsize)
- {
- if(fsize < (1<<20))
- percent = total_compressed * 1000 / fsize;
- else
- percent = total_compressed/256 * 1000 / (fsize >>8);
- percent = 1000 - percent;
- printf("%2d.%d%% saved", (int)percent/10, (int)percent%10);
- }
- printf("\n");
- }
-
- return 0;
-}
-
-int pack_file(int compress_level, const char* input_file, const char* output_file)
-{
- FILE* f;
- int result;
-
- f = fopen(output_file, "rb");
- if(f)
- {
- fclose(f);
- printf("Error: file %s already exists. Aborted.\n\n", output_file);
- return -1;
- }
-
- f = fopen(output_file, "wb");
- if(!f)
- {
- printf("Error: could not create %s. Aborted.\n\n", output_file);
- return -1;
- }
-
- write_magic(f);
-
- result = pack_file_compressed(input_file, 1, compress_level, f);
- fclose(f);
-
- return result;
-}
-
-#ifdef SIXPACK_BENCHMARK_WIN32
-int benchmark_speed(int compress_level, const char* input_file);
-
-int benchmark_speed(int compress_level, const char* input_file)
-{
- FILE* in;
- unsigned long fsize;
- unsigned long maxout;
- const char* shown_name;
- unsigned char* buffer;
- unsigned char* result;
- size_t bytes_read;
-
- /* sanity check */
- in = fopen(input_file, "rb");
- if(!in)
- {
- printf("Error: could not open %s\n", input_file);
- return -1;
- }
-
- /* find size of the file */
- fseek(in, 0, SEEK_END);
- fsize = ftell(in);
- fseek(in, 0, SEEK_SET);
-
- /* already a 6pack archive? */
- if(detect_magic(in))
- {
- printf("Error: no benchmark for 6pack archive!\n");
- fclose(in);
- return -1;
- }
-
- /* truncate directory prefix, e.g. "foo/bar/FILE.txt" becomes "FILE.txt" */
- shown_name = input_file + strlen(input_file) - 1;
- while(shown_name > input_file)
- if(*(shown_name-1) == PATH_SEPARATOR)
- break;
- else
- shown_name--;
-
- maxout = 1.05 * fsize;
- maxout = (maxout < 66) ? 66 : maxout;
- buffer = (unsigned char*)malloc(fsize);
- result = (unsigned char*)malloc(maxout);
- if(!buffer || !result)
- {
- printf("Error: not enough memory!\n");
- free(buffer);
- free(result);
- fclose(in);
- return -1;
- }
-
- printf("Reading source file....\n");
- bytes_read = fread(buffer, 1, fsize, in);
- if(bytes_read != fsize)
- {
- printf("Error reading file %s!\n", shown_name);
- printf("Read %d bytes, expecting %d bytes\n", bytes_read, fsize);
- free(buffer);
- free(result);
- fclose(in);
- return -1;
- }
-
-/* shamelessly copied from QuickLZ 1.20 test program */
- {
- unsigned int j, y;
- size_t i, u = 0;
- double mbs, fastest;
- unsigned long compressed_size;
-
- printf("Setting HIGH_PRIORITY_CLASS...\n");
- SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
-
- printf("Benchmarking FastLZ Level %d, please wait...\n", compress_level);
-
- i = bytes_read;
- fastest = 0.0;
- for (j = 0; j < 3; j++)
- {
- y = 0;
- mbs = GetTickCount();
- while(GetTickCount() == mbs);
- mbs = GetTickCount();
- while(GetTickCount() - mbs < 3000) /* 1% accuracy with 18.2 timer */
- {
- u = fastlz_compress_level(compress_level, buffer, bytes_read, result);
- y++;
- }
-
- mbs = ((double)i*(double)y)/((double)(GetTickCount() - mbs)/1000.)/1000000.;
- /*printf(" %.1f Mbyte/s ", mbs);*/
- if (fastest < mbs)
- fastest = mbs;
- }
-
- printf("\nCompressed %d bytes into %d bytes (%.1f%%) at %.1f Mbyte/s.\n", (unsigned int)i, (unsigned int)u, (double)u/(double)i*100., fastest);
-
-#if 1
- fastest = 0.0;
- compressed_size = u;
- for (j = 0; j < 3; j++)
- {
- y = 0;
- mbs = GetTickCount();
- while(GetTickCount() == mbs);
- mbs = GetTickCount();
- while(GetTickCount() - mbs < 3000) /* 1% accuracy with 18.2 timer */
- {
- u = fastlz_decompress(result, compressed_size, buffer, bytes_read);
- y++;
- }
-
- mbs = ((double)i*(double)y)/((double)(GetTickCount() - mbs)/1000.)/1000000.;
- /*printf(" %.1f Mbyte/s ", mbs);*/
- if (fastest < mbs)
- fastest = mbs;
- }
-
- printf("\nDecompressed at %.1f Mbyte/s.\n\n(1 MB = 1000000 byte)\n", fastest);
-#endif
- }
-
- fclose(in);
- return 0;
-}
-#endif /* SIXPACK_BENCHMARK_WIN32 */
-
-
-int main(int argc, char** argv)
-{
- int i;
- int compress_level;
- int benchmark;
- char* input_file;
- char* output_file;
-
- /* show help with no argument at all*/
- if(argc == 1)
- {
- usage();
- return 0;
- }
-
- /* default compression level, not the fastest */
- compress_level = 2;
-
- /* do benchmark only when explicitly specified */
- benchmark = 0;
-
- /* no file is specified */
- input_file = 0;
- output_file = 0;
-
- for(i = 1; i <= argc; i++)
- {
- char* argument = argv[i];
-
- if(!argument)
- continue;
-
- /* display help on usage */
- if(!strcmp(argument, "-h") || !strcmp(argument, "--help"))
- {
- usage();
- return 0;
- }
-
- /* check for version information */
- if(!strcmp(argument, "-v") || !strcmp(argument, "--version"))
- {
- printf("6pack: high-speed file compression tool\n");
- printf("Version %s (using FastLZ %s)\n",
- SIXPACK_VERSION_STRING, FASTLZ_VERSION_STRING);
- printf("Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)\n");
- printf("\n");
- return 0;
- }
-
- /* test compression speed? */
- if(!strcmp(argument, "-mem"))
- {
- benchmark = 1;
- continue;
- }
-
- /* compression level */
- if(!strcmp(argument, "-1") || !strcmp(argument, "--fastest"))
- {
- compress_level = 1;
- continue;
- }
- if(!strcmp(argument, "-2"))
- {
- compress_level = 2;
- continue;
- }
-
- /* unknown option */
- if(argument[0] == '-')
- {
- printf("Error: unknown option %s\n\n", argument);
- printf("To get help on usage:\n");
- printf(" 6pack --help\n\n");
- return -1;
- }
-
- /* first specified file is input */
- if(!input_file)
- {
- input_file = argument;
- continue;
- }
-
- /* next specified file is output */
- if(!output_file)
- {
- output_file = argument;
- continue;
- }
-
- /* files are already specified */
- printf("Error: unknown option %s\n\n", argument);
- printf("To get help on usage:\n");
- printf(" 6pack --help\n\n");
- return -1;
- }
-
- if(!input_file)
- {
- printf("Error: input file is not specified.\n\n");
- printf("To get help on usage:\n");
- printf(" 6pack --help\n\n");
- return -1;
- }
-
- if(!output_file && !benchmark)
- {
- printf("Error: output file is not specified.\n\n");
- printf("To get help on usage:\n");
- printf(" 6pack --help\n\n");
- return -1;
- }
-
-#ifdef SIXPACK_BENCHMARK_WIN32
- if(benchmark)
- return benchmark_speed(compress_level, input_file);
- else
-#endif
- return pack_file(compress_level, input_file, output_file);
-
- /* unreachable */
- return 0;
-}
diff --git a/kernel/vm/fastlz/6unpack.c b/kernel/vm/fastlz/6unpack.c
deleted file mode 100644
index b0215f9f..00000000
--- a/kernel/vm/fastlz/6unpack.c
+++ /dev/null
@@ -1,478 +0,0 @@
-/*
- 6PACK - file compressor using FastLZ (lightning-fast compression library)
-
- Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-*/
-
-#include
-#include
-#include
-
-#define SIXPACK_VERSION_MAJOR 0
-#define SIXPACK_VERSION_MINOR 1
-#define SIXPACK_VERSION_REVISION 0
-#define SIXPACK_VERSION_STRING "0.1.0"
-
-#include "fastlz.h"
-
-#if defined(WIN32) || defined(__NT__) || defined(_WIN32) || defined(__WIN32__)
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define inline __inline
-#endif
-#endif
-
-/* magic identifier for 6pack file */
-static unsigned char sixpack_magic[8] = {137, '6', 'P', 'K', 13, 10, 26, 10};
-
-#define BLOCK_SIZE 65536
-
-/* prototypes */
-static inline unsigned long update_adler32(unsigned long checksum, const void *buf, int len);
-void usage(void);
-int detect_magic(FILE *f);
-static inline unsigned long readU16(const unsigned char* ptr);
-static inline unsigned long readU32(const unsigned char* ptr);
-void read_chunk_header(FILE* f, int* id, int* options, unsigned long* size,
-unsigned long* checksum, unsigned long* extra);
-int unpack_file(const char* archive_file);
-
-/* for Adler-32 checksum algorithm, see RFC 1950 Section 8.2 */
-#define ADLER32_BASE 65521
-static inline unsigned long update_adler32(unsigned long checksum, const void *buf, int len)
-{
- const unsigned char* ptr = (const unsigned char*)buf;
- unsigned long s1 = checksum & 0xffff;
- unsigned long s2 = (checksum >> 16) & 0xffff;
-
- while(len>0)
- {
- unsigned k = len < 5552 ? len : 5552;
- len -= k;
-
- while(k >= 8)
- {
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- s1 += *ptr++; s2 += s1;
- k -= 8;
- }
-
- while(k-- > 0)
- {
- s1 += *ptr++; s2 += s1;
- }
- s1 = s1 % ADLER32_BASE;
- s2 = s2 % ADLER32_BASE;
- }
- return (s2 << 16) + s1;
-}
-
-void usage(void)
-{
- printf("6unpack: uncompress 6pack archive\n");
- printf("Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)\n");
- printf("\n");
- printf("Usage: 6unpack archive-file\n");
- printf("\n");
-}
-
-/* return non-zero if magic sequence is detected */
-/* warning: reset the read pointer to the beginning of the file */
-int detect_magic(FILE *f)
-{
- unsigned char buffer[8];
- size_t bytes_read;
- int c;
-
- fseek(f, SEEK_SET, 0);
- bytes_read = fread(buffer, 1, 8, f);
- fseek(f, SEEK_SET, 0);
- if(bytes_read < 8)
- return 0;
-
- for(c = 0; c < 8; c++)
- if(buffer[c] != sixpack_magic[c])
- return 0;
-
- return -1;
-}
-
-static inline unsigned long readU16( const unsigned char* ptr )
-{
- return ptr[0]+(ptr[1]<<8);
-}
-
-static inline unsigned long readU32( const unsigned char* ptr )
-{
- return ptr[0]+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24);
-}
-
-void read_chunk_header(FILE* f, int* id, int* options, unsigned long* size,
-unsigned long* checksum, unsigned long* extra)
-{
- unsigned char buffer[16];
- fread(buffer, 1, 16, f);
-
- *id = readU16(buffer) & 0xffff;
- *options = readU16(buffer+2) & 0xffff;
- *size = readU32(buffer+4) & 0xffffffff;
- *checksum = readU32(buffer+8) & 0xffffffff;
- *extra = readU32(buffer+12) & 0xffffffff;
-}
-
-int unpack_file(const char* input_file)
-{
- FILE* in;
- unsigned long fsize;
- int c;
- unsigned long percent;
- unsigned char progress[20];
- int chunk_id;
- int chunk_options;
- unsigned long chunk_size;
- unsigned long chunk_checksum;
- unsigned long chunk_extra;
- unsigned char buffer[BLOCK_SIZE];
- unsigned long checksum;
-
- unsigned long decompressed_size;
- unsigned long total_extracted;
- int name_length;
- char* output_file;
- FILE* f;
-
- unsigned char* compressed_buffer;
- unsigned char* decompressed_buffer;
- unsigned long compressed_bufsize;
- unsigned long decompressed_bufsize;
-
- /* sanity check */
- in = fopen(input_file, "rb");
- if(!in)
- {
- printf("Error: could not open %s\n", input_file);
- return -1;
- }
-
- /* find size of the file */
- fseek(in, 0, SEEK_END);
- fsize = ftell(in);
- fseek(in, 0, SEEK_SET);
-
- /* not a 6pack archive? */
- if(!detect_magic(in))
- {
- fclose(in);
- printf("Error: file %s is not a 6pack archive!\n", input_file);
- return -1;
- }
-
- printf("Archive: %s", input_file);
-
- /* position of first chunk */
- fseek(in, 8, SEEK_SET);
-
- /* initialize */
- output_file = 0;
- f = 0;
- total_extracted = 0;
- decompressed_size = 0;
- percent = 0;
- compressed_buffer = 0;
- decompressed_buffer = 0;
- compressed_bufsize = 0;
- decompressed_bufsize = 0;
-
- /* main loop */
- for(;;)
- {
- /* end of file? */
- size_t pos = ftell(in);
- if(pos >= fsize)
- break;
-
- read_chunk_header(in, &chunk_id, &chunk_options,
- &chunk_size, &chunk_checksum, &chunk_extra);
-
- if((chunk_id == 1) && (chunk_size > 10) && (chunk_size < BLOCK_SIZE))
- {
- /* close current file, if any */
- printf("\n");
- free(output_file);
- output_file = 0;
- if(f)
- fclose(f);
-
- /* file entry */
- fread(buffer, 1, chunk_size, in);
- checksum = update_adler32(1L, buffer, chunk_size);
- if(checksum != chunk_checksum)
- {
- free(output_file);
- output_file = 0;
- fclose(in);
- printf("\nError: checksum mismatch!\n");
- printf("Got %08lX Expecting %08lX\n", checksum, chunk_checksum);
- return -1;
- }
-
- decompressed_size = readU32(buffer);
- total_extracted = 0;
- percent = 0;
-
- /* get file to extract */
- name_length = (int)readU16(buffer+8);
- if(name_length > (int)chunk_size - 10)
- name_length = chunk_size - 10;
- output_file = (char*)malloc(name_length+1);
- memset(output_file, 0, name_length+1);
- for(c = 0; c < name_length; c++)
- output_file[c] = buffer[10+c];
-
- /* check if already exists */
- f = fopen(output_file, "rb");
- if(f)
- {
- fclose(f);
- printf("File %s already exists. Skipped.\n", output_file);
- free(output_file);
- output_file = 0;
- f = 0;
- }
- else
- {
- /* create the file */
- f = fopen(output_file, "wb");
- if(!f)
- {
- printf("Can't create file %s. Skipped.\n", output_file);
- free(output_file);
- output_file = 0;
- f = 0;
- }
- else
- {
- /* for progress status */
- printf("\n");
- memset(progress, ' ', 20);
- if(strlen(output_file) < 16)
- for(c = 0; c < (int)strlen(output_file); c++)
- progress[c] = output_file[c];
- else
- {
- for(c = 0; c < 13; c++)
- progress[c] = output_file[c];
- progress[13] = '.';
- progress[14] = '.';
- progress[15] = ' ';
- }
- progress[16] = '[';
- progress[17] = 0;
- printf("%s", progress);
- for(c = 0; c < 50; c++)
- printf(".");
- printf("]\r");
- printf("%s", progress);
- }
- }
- }
-
- if((chunk_id == 17) && f && output_file && decompressed_size)
- {
- unsigned long remaining;
-
- /* uncompressed */
- switch(chunk_options)
- {
- /* stored, simply copy to output */
- case 0:
- /* read one block at at time, write and update checksum */
- total_extracted += chunk_size;
- remaining = chunk_size;
- checksum = 1L;
- for(;;)
- {
- unsigned long r = (BLOCK_SIZE < remaining) ? BLOCK_SIZE: remaining;
- size_t bytes_read = fread(buffer, 1, r, in);
- if(bytes_read == 0)
- break;
- fwrite(buffer, 1, bytes_read, f);
- checksum = update_adler32(checksum, buffer, bytes_read);
- remaining -= bytes_read;
- }
-
- /* verify everything is written correctly */
- if(checksum != chunk_checksum)
- {
- fclose(f);
- f = 0;
- free(output_file);
- output_file = 0;
- printf("\nError: checksum mismatch. Aborted.\n");
- printf("Got %08lX Expecting %08lX\n", checksum, chunk_checksum);
- }
- break;
-
- /* compressed using FastLZ */
- case 1:
- /* enlarge input buffer if necessary */
- if(chunk_size > compressed_bufsize)
- {
- compressed_bufsize = chunk_size;
- free(compressed_buffer);
- compressed_buffer = (unsigned char*)malloc(compressed_bufsize);
- }
-
- /* enlarge output buffer if necessary */
- if(chunk_extra > decompressed_bufsize)
- {
- decompressed_bufsize = chunk_extra;
- free(decompressed_buffer);
- decompressed_buffer = (unsigned char*)malloc(decompressed_bufsize);
- }
-
- /* read and check checksum */
- fread(compressed_buffer, 1, chunk_size, in);
- checksum = update_adler32(1L, compressed_buffer, chunk_size);
- total_extracted += chunk_extra;
-
- /* verify that the chunk data is correct */
- if(checksum != chunk_checksum)
- {
- fclose(f);
- f = 0;
- free(output_file);
- output_file = 0;
- printf("\nError: checksum mismatch. Skipped.\n");
- printf("Got %08lX Expecting %08lX\n", checksum, chunk_checksum);
- }
- else
- {
- /* decompress and verify */
- remaining = fastlz_decompress(compressed_buffer, chunk_size, decompressed_buffer, chunk_extra);
- if(remaining != chunk_extra)
- {
- fclose(f);
- f = 0;
- free(output_file);
- output_file = 0;
- printf("\nError: decompression failed. Skipped.\n");
- }
- else
- fwrite(decompressed_buffer, 1, chunk_extra, f);
- }
- break;
-
- default:
- printf("\nError: unknown compression method (%d)\n", chunk_options);
- fclose(f);
- f = 0;
- free(output_file);
- output_file = 0;
- break;
- }
-
- /* for progress, if everything is fine */
- if(f)
- {
- int last_percent = (int)percent;
- if(decompressed_size < (1<<24))
- percent = total_extracted * 100 / decompressed_size;
- else
- percent = total_extracted / 256 * 100 / (decompressed_size >>8);
- percent >>= 1;
- while(last_percent < (int)percent)
- {
- printf("#");
- last_percent++;
- }
- }
- }
-
- /* position of next chunk */
- fseek(in, pos + 16 + chunk_size, SEEK_SET);
- }
- printf("\n\n");
-
- /* free allocated stuff */
- free(compressed_buffer);
- free(decompressed_buffer);
- free(output_file);
-
- /* close working files */
- if(f)
- fclose(f);
- fclose(in);
-
- /* so far so good */
- return 0;
-}
-
-int main(int argc, char** argv)
-{
- int i;
- const char* archive_file;
-
- /* show help with no argument at all*/
- if(argc == 1)
- {
- usage();
- return 0;
- }
-
- /* check for help on usage */
- for(i = 1; i <= argc; i++)
- if(argv[i])
- if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
- {
- usage();
- return 0;
- }
-
- /* check for version information */
- for(i = 1; i <= argc; i++)
- if(argv[i])
- if(!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version"))
- {
- printf("6unpack: high-speed file compression tool\n");
- printf("Version %s (using FastLZ %s)\n",
- SIXPACK_VERSION_STRING, FASTLZ_VERSION_STRING);
- printf("Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)\n");
- printf("\n");
- return 0;
- }
-
- /* needs at least two arguments */
- if(argc <= 1)
- {
- usage();
- return 0;
- }
-
- archive_file = argv[1];
-
- return unpack_file(archive_file);
-}
diff --git a/kernel/vm/fastlz/README.TXT b/kernel/vm/fastlz/README.TXT
deleted file mode 100644
index 581e9e8a..00000000
--- a/kernel/vm/fastlz/README.TXT
+++ /dev/null
@@ -1,75 +0,0 @@
-FastLZ - lightning-fast lossless compression library
-
-Author: Ariya Hidayat
-Official website: http://www.fastlz.org
-
-FastLZ is distributed using the MIT license, see file LICENSE
-for details.
-
-FastLZ consists of two files: fastlz.h and fastlz.c. Just add these
-files to your project in order to use FastLZ. For information on
-compression and decompression routines, see fastlz.h.
-
-A simple file compressor called 6pack is included as an example
-on how to use FastLZ. The corresponding decompressor is 6unpack.
-
-To compile using GCC:
-
- gcc -o 6pack 6pack.c fastlz.c
- gcc -o 6unpack 6unpack.c fastlz.c
-
-To compile using MinGW:
-
- mingw32-gcc -o 6pack 6pack.c fastlz.c
- mingw32-gcc -o 6unpack 6unpack.c fastlz.c
-
-To compile using Microsoft Visual C++:
-
- cl 6pack.c fastlz.c
- cl 6unpack.c fastlz.c
-
-To compile using Borland C++:
-
- bcc32 6pack.c fastlz.c
- bcc32 6unpack.c fastlz.c
-
-To compile using OpenWatcom C/C++:
-
- cl386 6pack.c fastlz.c
- cl386 6unpack.c fastlz.c
-
-To compile using Intel C++ compiler for Windows:
-
- icl 6pack.c fastlz.c
- icl 6unpack.c fastlz.c
-
-To compile using Intel C++ compiler for Linux:
-
- icc -o 6pack 6pack.c fastlz.c
- icc -o 6unpack 6unpack.c fastlz.c
-
-To compile 6pack using LCC-Win32:
-
- lc 6pack.c fastlz.c
- lc 6unpack.c fastlz.c
-
-To compile 6pack using Pelles C:
-
- pocc 6pack.c
- pocc 6unpack.c
- pocc fastlz.c
- polink 6pack.obj fastlz.obj
- polink 6unpack.obj fastlz.obj
-
-For speed optimization, always use proper compile flags for optimization options.
-Typical compiler flags are given below:
-
-* GCC (pre 4.2): -march=pentium -O3 -fomit-frame-pointer -mtune=pentium
-* GCC 4.2 or later: -march=pentium -O3 -fomit-frame-pointer -mtune=generic
-* Digital Mars C/C++: -o+all -5
-* Intel C++ (Windows): /O3 /Qipo
-* Intel C++ (Linux): -O2 -march=pentium -mtune=pentium
-* Borland C++: -O2 -5
-* LCC-Win32: -O
-* Pelles C: /O2
-
diff --git a/kernel/vm/fastlz/fastlz.c b/kernel/vm/fastlz/fastlz.c
deleted file mode 100644
index 3c9d6f6f..00000000
--- a/kernel/vm/fastlz/fastlz.c
+++ /dev/null
@@ -1,551 +0,0 @@
-/*
- FastLZ - lightning-fast lossless compression library
-
- Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
- Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
- Copyright (C) 2005 Ariya Hidayat (ariya@kde.org)
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-*/
-
-#if !defined(FASTLZ__COMPRESSOR) && !defined(FASTLZ_DECOMPRESSOR)
-
-/*
- * Always check for bound when decompressing.
- * Generally it is best to leave it defined.
- */
-#define FASTLZ_SAFE
-
-/*
- * Give hints to the compiler for branch prediction optimization.
- */
-#if defined(__GNUC__) && (__GNUC__ > 2)
-#define FASTLZ_EXPECT_CONDITIONAL(c) (__builtin_expect((c), 1))
-#define FASTLZ_UNEXPECT_CONDITIONAL(c) (__builtin_expect((c), 0))
-#else
-#define FASTLZ_EXPECT_CONDITIONAL(c) (c)
-#define FASTLZ_UNEXPECT_CONDITIONAL(c) (c)
-#endif
-
-/*
- * Use inlined functions for supported systems.
- */
-#if defined(__GNUC__) || defined(__DMC__) || defined(__POCC__) || defined(__WATCOMC__) || defined(__SUNPRO_C)
-#define FASTLZ_INLINE inline
-#elif defined(__BORLANDC__) || defined(_MSC_VER) || defined(__LCC__)
-#define FASTLZ_INLINE __inline
-#else
-#define FASTLZ_INLINE
-#endif
-
-/*
- * Prevent accessing more than 8-bit at once, except on x86 architectures.
- */
-#if !defined(FASTLZ_STRICT_ALIGN)
-#define FASTLZ_STRICT_ALIGN
-#if defined(__i386__) || defined(__386) /* GNU C, Sun Studio */
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(__i486__) || defined(__i586__) || defined(__i686__) /* GNU C */
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(_M_IX86) /* Intel, MSVC */
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(__386)
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(_X86_) /* MinGW */
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(__I86__) /* Digital Mars */
-#undef FASTLZ_STRICT_ALIGN
-#endif
-#endif
-
-/*
- * FIXME: use preprocessor magic to set this on different platforms!
- */
-typedef unsigned char flzuint8;
-typedef unsigned short flzuint16;
-typedef unsigned int flzuint32;
-
-/* prototypes */
-int fastlz_compress(const void* input, int length, void* output);
-int fastlz_compress_level(int level, const void* input, int length, void* output);
-int fastlz_decompress(const void* input, int length, void* output, int maxout);
-
-#define MAX_COPY 32
-#define MAX_LEN 264 /* 256 + 8 */
-#define MAX_DISTANCE 8192
-
-#if !defined(FASTLZ_STRICT_ALIGN)
-#define FASTLZ_READU16(p) *((const flzuint16*)(p))
-#else
-#define FASTLZ_READU16(p) ((p)[0] | (p)[1]<<8)
-#endif
-
-#define HASH_LOG 13
-#define HASH_SIZE (1<< HASH_LOG)
-#define HASH_MASK (HASH_SIZE-1)
-#define HASH_FUNCTION(v,p) { v = FASTLZ_READU16(p); v ^= FASTLZ_READU16(p+1)^(v>>(16-HASH_LOG));v &= HASH_MASK; }
-
-#undef FASTLZ_LEVEL
-#define FASTLZ_LEVEL 1
-
-#undef FASTLZ_COMPRESSOR
-#undef FASTLZ_DECOMPRESSOR
-#define FASTLZ_COMPRESSOR fastlz1_compress
-#define FASTLZ_DECOMPRESSOR fastlz1_decompress
-static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const void* input, int length, void* output);
-static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const void* input, int length, void* output, int maxout);
-#include "fastlz.c"
-
-#undef FASTLZ_LEVEL
-#define FASTLZ_LEVEL 2
-
-#undef MAX_DISTANCE
-#define MAX_DISTANCE 8191
-#define MAX_FARDISTANCE (65535+MAX_DISTANCE-1)
-
-#undef FASTLZ_COMPRESSOR
-#undef FASTLZ_DECOMPRESSOR
-#define FASTLZ_COMPRESSOR fastlz2_compress
-#define FASTLZ_DECOMPRESSOR fastlz2_decompress
-static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const void* input, int length, void* output);
-static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const void* input, int length, void* output, int maxout);
-#include "fastlz.c"
-
-int fastlz_compress(const void* input, int length, void* output)
-{
- /* for short block, choose fastlz1 */
- if(length < 65536)
- return fastlz1_compress(input, length, output);
-
- /* else... */
- return fastlz2_compress(input, length, output);
-}
-
-int fastlz_decompress(const void* input, int length, void* output, int maxout)
-{
- /* magic identifier for compression level */
- int level = ((*(const flzuint8*)input) >> 5) + 1;
-
- if(level == 1)
- return fastlz1_decompress(input, length, output, maxout);
- if(level == 2)
- return fastlz2_decompress(input, length, output, maxout);
-
- /* unknown level, trigger error */
- return 0;
-}
-
-int fastlz_compress_level(int level, const void* input, int length, void* output)
-{
- if(level == 1)
- return fastlz1_compress(input, length, output);
- if(level == 2)
- return fastlz2_compress(input, length, output);
-
- return 0;
-}
-
-#else /* !defined(FASTLZ_COMPRESSOR) && !defined(FASTLZ_DECOMPRESSOR) */
-
-static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const void* input, int length, void* output)
-{
- const flzuint8* ip = (const flzuint8*) input;
- const flzuint8* ip_bound = ip + length - 2;
- const flzuint8* ip_limit = ip + length - 12;
- flzuint8* op = (flzuint8*) output;
-
- const flzuint8* htab[HASH_SIZE];
- const flzuint8** hslot;
- flzuint32 hval;
-
- flzuint32 copy;
-
- /* sanity check */
- if(FASTLZ_UNEXPECT_CONDITIONAL(length < 4))
- {
- if(length)
- {
- /* create literal copy only */
- *op++ = length-1;
- ip_bound++;
- while(ip <= ip_bound)
- *op++ = *ip++;
- return length+1;
- }
- else
- return 0;
- }
-
- /* initializes hash table */
- for (hslot = htab; hslot < htab + HASH_SIZE; hslot++)
- *hslot = ip;
-
- /* we start with literal copy */
- copy = 2;
- *op++ = MAX_COPY-1;
- *op++ = *ip++;
- *op++ = *ip++;
-
- /* main loop */
- while(FASTLZ_EXPECT_CONDITIONAL(ip < ip_limit))
- {
- const flzuint8* ref;
- flzuint32 distance;
-
- /* minimum match length */
- flzuint32 len = 3;
-
- /* comparison starting-point */
- const flzuint8* anchor = ip;
-
- /* check for a run */
-#if FASTLZ_LEVEL==2
- if(ip[0] == ip[-1] && FASTLZ_READU16(ip-1)==FASTLZ_READU16(ip+1))
- {
- distance = 1;
- ip += 3;
- ref = anchor - 1 + 3;
- goto match;
- }
-#endif
-
- /* find potential match */
- HASH_FUNCTION(hval,ip);
- hslot = htab + hval;
- ref = htab[hval];
-
- /* calculate distance to the match */
- distance = anchor - ref;
-
- /* update hash table */
- *hslot = anchor;
-
- /* is this a match? check the first 3 bytes */
- if(distance==0 ||
-#if FASTLZ_LEVEL==1
- (distance >= MAX_DISTANCE) ||
-#else
- (distance >= MAX_FARDISTANCE) ||
-#endif
- *ref++ != *ip++ || *ref++!=*ip++ || *ref++!=*ip++)
- goto literal;
-
-#if FASTLZ_LEVEL==2
- /* far, needs at least 5-byte match */
- if(distance >= MAX_DISTANCE)
- {
- if(*ip++ != *ref++ || *ip++!= *ref++)
- goto literal;
- len += 2;
- }
-
- match:
-#endif
-
- /* last matched byte */
- ip = anchor + len;
-
- /* distance is biased */
- distance--;
-
- if(!distance)
- {
- /* zero distance means a run */
- flzuint8 x = ip[-1];
- while(ip < ip_bound)
- if(*ref++ != x) break; else ip++;
- }
- else
- for(;;)
- {
- /* safe because the outer check against ip limit */
- if(*ref++ != *ip++) break;
- if(*ref++ != *ip++) break;
- if(*ref++ != *ip++) break;
- if(*ref++ != *ip++) break;
- if(*ref++ != *ip++) break;
- if(*ref++ != *ip++) break;
- if(*ref++ != *ip++) break;
- if(*ref++ != *ip++) break;
- while(ip < ip_bound)
- if(*ref++ != *ip++) break;
- break;
- }
-
- /* if we have copied something, adjust the copy count */
- if(copy)
- /* copy is biased, '0' means 1 byte copy */
- *(op-copy-1) = copy-1;
- else
- /* back, to overwrite the copy count */
- op--;
-
- /* reset literal counter */
- copy = 0;
-
- /* length is biased, '1' means a match of 3 bytes */
- ip -= 3;
- len = ip - anchor;
-
- /* encode the match */
-#if FASTLZ_LEVEL==2
- if(distance < MAX_DISTANCE)
- {
- if(len < 7)
- {
- *op++ = (len << 5) + (distance >> 8);
- *op++ = (distance & 255);
- }
- else
- {
- *op++ = (7 << 5) + (distance >> 8);
- for(len-=7; len >= 255; len-= 255)
- *op++ = 255;
- *op++ = len;
- *op++ = (distance & 255);
- }
- }
- else
- {
- /* far away, but not yet in the another galaxy... */
- if(len < 7)
- {
- distance -= MAX_DISTANCE;
- *op++ = (len << 5) + 31;
- *op++ = 255;
- *op++ = distance >> 8;
- *op++ = distance & 255;
- }
- else
- {
- distance -= MAX_DISTANCE;
- *op++ = (7 << 5) + 31;
- for(len-=7; len >= 255; len-= 255)
- *op++ = 255;
- *op++ = len;
- *op++ = 255;
- *op++ = distance >> 8;
- *op++ = distance & 255;
- }
- }
-#else
-
- if(FASTLZ_UNEXPECT_CONDITIONAL(len > MAX_LEN-2))
- while(len > MAX_LEN-2)
- {
- *op++ = (7 << 5) + (distance >> 8);
- *op++ = MAX_LEN - 2 - 7 -2;
- *op++ = (distance & 255);
- len -= MAX_LEN-2;
- }
-
- if(len < 7)
- {
- *op++ = (len << 5) + (distance >> 8);
- *op++ = (distance & 255);
- }
- else
- {
- *op++ = (7 << 5) + (distance >> 8);
- *op++ = len - 7;
- *op++ = (distance & 255);
- }
-#endif
-
- /* update the hash at match boundary */
- HASH_FUNCTION(hval,ip);
- htab[hval] = ip++;
- HASH_FUNCTION(hval,ip);
- htab[hval] = ip++;
-
- /* assuming literal copy */
- *op++ = MAX_COPY-1;
-
- continue;
-
- literal:
- *op++ = *anchor++;
- ip = anchor;
- copy++;
- if(FASTLZ_UNEXPECT_CONDITIONAL(copy == MAX_COPY))
- {
- copy = 0;
- *op++ = MAX_COPY-1;
- }
- }
-
- /* left-over as literal copy */
- ip_bound++;
- while(ip <= ip_bound)
- {
- *op++ = *ip++;
- copy++;
- if(copy == MAX_COPY)
- {
- copy = 0;
- *op++ = MAX_COPY-1;
- }
- }
-
- /* if we have copied something, adjust the copy length */
- if(copy)
- *(op-copy-1) = copy-1;
- else
- op--;
-
-#if FASTLZ_LEVEL==2
- /* marker for fastlz2 */
- *(flzuint8*)output |= (1 << 5);
-#endif
-
- return op - (flzuint8*)output;
-}
-
-static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const void* input, int length, void* output, int maxout)
-{
- const flzuint8* ip = (const flzuint8*) input;
- const flzuint8* ip_limit = ip + length;
- flzuint8* op = (flzuint8*) output;
- flzuint8* op_limit = op + maxout;
- flzuint32 ctrl = (*ip++) & 31;
- int loop = 1;
-
- do
- {
- const flzuint8* ref = op;
- flzuint32 len = ctrl >> 5;
- flzuint32 ofs = (ctrl & 31) << 8;
-
- if(ctrl >= 32)
- {
-#if FASTLZ_LEVEL==2
- flzuint8 code;
-#endif
- len--;
- ref -= ofs;
- if (len == 7-1)
-#if FASTLZ_LEVEL==1
- len += *ip++;
- ref -= *ip++;
-#else
- do
- {
- code = *ip++;
- len += code;
- } while (code==255);
- code = *ip++;
- ref -= code;
-
- /* match from 16-bit distance */
- if(FASTLZ_UNEXPECT_CONDITIONAL(code==255))
- if(FASTLZ_EXPECT_CONDITIONAL(ofs==(31 << 8)))
- {
- ofs = (*ip++) << 8;
- ofs += *ip++;
- ref = op - ofs - MAX_DISTANCE;
- }
-#endif
-
-#ifdef FASTLZ_SAFE
- if (FASTLZ_UNEXPECT_CONDITIONAL(op + len + 3 > op_limit))
- return 0;
-
- if (FASTLZ_UNEXPECT_CONDITIONAL(ref-1 < (flzuint8 *)output))
- return 0;
-#endif
-
- if(FASTLZ_EXPECT_CONDITIONAL(ip < ip_limit))
- ctrl = *ip++;
- else
- loop = 0;
-
- if(ref == op)
- {
- /* optimize copy for a run */
- flzuint8 b = ref[-1];
- *op++ = b;
- *op++ = b;
- *op++ = b;
- for(; len; --len)
- *op++ = b;
- }
- else
- {
-#if !defined(FASTLZ_STRICT_ALIGN)
- const flzuint16* p;
- flzuint16* q;
-#endif
- /* copy from reference */
- ref--;
- *op++ = *ref++;
- *op++ = *ref++;
- *op++ = *ref++;
-
-#if !defined(FASTLZ_STRICT_ALIGN)
- /* copy a byte, so that now it's word aligned */
- if(len & 1)
- {
- *op++ = *ref++;
- len--;
- }
-
- /* copy 16-bit at once */
- q = (flzuint16*) op;
- op += len;
- p = (const flzuint16*) ref;
- for(len>>=1; len > 4; len-=4)
- {
- *q++ = *p++;
- *q++ = *p++;
- *q++ = *p++;
- *q++ = *p++;
- }
- for(; len; --len)
- *q++ = *p++;
-#else
- for(; len; --len)
- *op++ = *ref++;
-#endif
- }
- }
- else
- {
- ctrl++;
-#ifdef FASTLZ_SAFE
- if (FASTLZ_UNEXPECT_CONDITIONAL(op + ctrl > op_limit))
- return 0;
- if (FASTLZ_UNEXPECT_CONDITIONAL(ip + ctrl > ip_limit))
- return 0;
-#endif
-
- *op++ = *ip++;
- for(--ctrl; ctrl; ctrl--)
- *op++ = *ip++;
-
- loop = FASTLZ_EXPECT_CONDITIONAL(ip < ip_limit);
- if(loop)
- ctrl = *ip++;
- }
- }
- while(FASTLZ_EXPECT_CONDITIONAL(loop));
-
- return op - (flzuint8*)output;
-}
-
-#endif /* !defined(FASTLZ_COMPRESSOR) && !defined(FASTLZ_DECOMPRESSOR) */
diff --git a/kernel/vm/fastlz/fastlz.h b/kernel/vm/fastlz/fastlz.h
deleted file mode 100644
index f87bc7be..00000000
--- a/kernel/vm/fastlz/fastlz.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- FastLZ - lightning-fast lossless compression library
-
- Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
- Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
- Copyright (C) 2005 Ariya Hidayat (ariya@kde.org)
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-*/
-
-#ifndef FASTLZ_H
-#define FASTLZ_H
-
-#define FASTLZ_VERSION 0x000100
-
-#define FASTLZ_VERSION_MAJOR 0
-#define FASTLZ_VERSION_MINOR 0
-#define FASTLZ_VERSION_REVISION 0
-
-#define FASTLZ_VERSION_STRING "0.1.0"
-
-#if defined (__cplusplus)
-extern "C" {
-#endif
-
-/**
- Compress a block of data in the input buffer and returns the size of
- compressed block. The size of input buffer is specified by length. The
- minimum input buffer size is 16.
-
- The output buffer must be at least 5% larger than the input buffer
- and can not be smaller than 66 bytes.
-
- If the input is not compressible, the return value might be larger than
- length (input buffer size).
-
- The input buffer and the output buffer can not overlap.
-*/
-
-int fastlz_compress(const void* input, int length, void* output);
-
-/**
- Decompress a block of compressed data and returns the size of the
- decompressed block. If error occurs, e.g. the compressed data is
- corrupted or the output buffer is not large enough, then 0 (zero)
- will be returned instead.
-
- The input buffer and the output buffer can not overlap.
-
- Decompression is memory safe and guaranteed not to write the output buffer
- more than what is specified in maxout.
- */
-
-int fastlz_decompress(const void* input, int length, void* output, int maxout);
-
-/**
- Compress a block of data in the input buffer and returns the size of
- compressed block. The size of input buffer is specified by length. The
- minimum input buffer size is 16.
-
- The output buffer must be at least 5% larger than the input buffer
- and can not be smaller than 66 bytes.
-
- If the input is not compressible, the return value might be larger than
- length (input buffer size).
-
- The input buffer and the output buffer can not overlap.
-
- Compression level can be specified in parameter level. At the moment,
- only level 1 and level 2 are supported.
- Level 1 is the fastest compression and generally useful for short data.
- Level 2 is slightly slower but it gives better compression ratio.
-
- Note that the compressed data, regardless of the level, can always be
- decompressed using the function fastlz_decompress above.
-*/
-
-int fastlz_compress_level(int level, const void* input, int length, void* output);
-
-#if defined (__cplusplus)
-}
-#endif
-
-#endif /* FASTLZ_H */
diff --git a/kernel/vm/frame.c b/kernel/vm/frame.c
deleted file mode 100644
index 37616303..00000000
--- a/kernel/vm/frame.c
+++ /dev/null
@@ -1,63 +0,0 @@
-#include "vm.h"
-//#include "frame.h"
-#include "klibc.h"
-
-struct vm_free_frame
-{
- void *next; // Next free frame
-};
-
-struct vm_free_frame *vm_free_list = 0x0;
-
-int vm_build_free_frame_list(void *start, void *end)
-{
- vm_free_list = start;
- struct vm_free_frame *p = start;
- for (p = start; (void*) p < end; p = (void*) p + BLOCK_SIZE)
- {
- p->next = (void*) p + BLOCK_SIZE;
- if ((unsigned int) ((void*) p + BLOCK_SIZE) >= (unsigned int) end)
- {
- p->next = 0x0;
- }
- }
- return 0;
-}
-
-void *vm_get_free_frame()
-{
- // Check if there are no frames
- if (vm_free_list == 0x0)
- {
- return 0x0;
- }
- void *p = vm_free_list;
- vm_free_list = vm_free_list->next;
- return p - 0xf0000000; // Convert from VPTR to PPTR
-}
-
-void vm_release_frame(void *p)
-{
- // TODO: Check if p is actually a valid frame
- p += 0xf0000000; // Convert from PPTR to VPTR
- struct vm_free_frame *flist = p;
- flist->next = vm_free_list;
- os_printf("%X %X\n", flist, vm_free_list);
- vm_free_list = p;
-}
-
-int vm_count_free_frames()
-{
- int cnt = 0;
- struct vm_free_frame *p = vm_free_list;
- while ((p = p->next))
- {
- if (p == p->next)
- {
- ERROR("Fatal problem: The free frame list has a cycle.\n");
- return -1;
- }
- cnt++;
- }
- return cnt;
-}
diff --git a/kernel/vm/frame.h b/kernel/vm/frame.h
deleted file mode 100644
index 87f00fa5..00000000
--- a/kernel/vm/frame.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef __VM_FRAME_H
-#define __VM_FRAME_H
-
-int vm_build_free_frame_list(void *start, void *end);
-void *vm_get_free_frame();
-void vm_release_frame(void *p);
-int vm_count_free_frames();
-
-#endif
diff --git a/kernel/vm/memory-layout.svg b/kernel/vm/memory-layout.svg
deleted file mode 100644
index a6b75dc4..00000000
--- a/kernel/vm/memory-layout.svg
+++ /dev/null
@@ -1,652 +0,0 @@
-
-
-
-
diff --git a/kernel/vm/swap_framework.c b/kernel/vm/swap_framework.c
deleted file mode 100644
index 7fd9db76..00000000
--- a/kernel/vm/swap_framework.c
+++ /dev/null
@@ -1,259 +0,0 @@
-#include "vm.h"
-#include "memory.h"
-#include "klibc.h"
-#include
-#include "swap_framework.h"
-#include "swap_pqueue.h"
-#include "swap_fs.h"
-#include "fastlz/fastlz.h"
-
-// NOTE: SWAPPING CANNOT WORK UNTIL FILESYSTEMS CAN ALLOCATE MORE THAN 16 PAGES AT A TIME
-void swap_init()
-{
- // initialize a swap space struct to hold values to then pass
- // TODO: change to guarantee allocation in RAM
- holder = (struct swap_space*) kmalloc(sizeof(struct swap_space));
-}
-
-// INCOMPLETE
-uint32_t store_page_LZ(void *page, uint32_t *ID)
-{
- struct node *LZ_swap = (struct node*) pqueue_peek(2);
-
- // allocate this on RAM this is where you os_memcpy the given page!!
- // NOTE: THAT 1.05 DOESN'T MULTIPLY TO A CLEAN NUMBER
- void *e_page = kmalloc(PAGE_SIZE * 1.05); // output buffer needs to be at least 5% bigger than input
-
- int32_t cmp_size;
- cmp_size = fastlz_compress(page, PAGE_SIZE, e_page);
-
- /*if compressed size is greater than uncompressed size, input may not be
- compressible; return error */
- if (cmp_size > PAGE_SIZE)
- {
- return 0;
- }
-
- struct swap_entry *curr_ent = LZ_swap->e_head;
- int i = 0;
- while (curr_ent->cmp_page != NULL)
- {
- curr_ent += sizeof(struct swap_entry);
- i++;
- }
- *ID = i;
- curr_ent->cmp_size = cmp_size;
- curr_ent->e_flags = 1; //NOT CORRECT, put wherever it comes from here
- struct vas *kvas = KERNEL_VAS;
- int curr_add = 0x200000;
-
- // loop until free physical memory frame is found
- while (vm_allocate_page(kvas, curr_add, 4) == 0)
- {
- curr_add += PAGE_SIZE;
- }
-
- // after deciding physical memory location, store physical memory location in cmp_page
- curr_ent->cmp_page = curr_add;
- kfree(e_page); // after copying over relevant bits of cmp data in this oversized buffer
- if (curr_ent->cmp_page != NULL)
- {
- curr_ent += sizeof(struct swap_entry);
- curr_ent = (struct swap_entry*) kmalloc(sizeof(struct swap_entry));
- }
- memory_count += 4096;
- return *ID;
-}
-
-uint32_t store_page(void *page, uint32_t *ID)
-{
- uint8_t lowbits = *((uint32_t*) page) & 0x000000FF;
- if (swapfs_store(page, ID, lowbits) == -1)
- {
- return 0;
- }
- memory_count += 4096;
- return *ID;
-}
-
-// INCOMPLETE
-uint32_t retrieve_page_LZ(void *page, uint32_t *ID)
-{
- struct node *lz_swap = (struct node*) pqueue_peek(2);
- struct swap_entry *curr_ent = lz_swap->e_head;
- for (int i = 0; i < *ID; i++)
- {
- curr_ent += sizeof(struct swap_entry);
- }
- void *uncomp_page = kmalloc(PAGE_SIZE);
- int uncomp_size = fastlz_decompress(curr_ent->cmp_page, /*constant?*/
- COMPRESSED_SIZE / PAGE_ENTRIES, uncomp_page, PAGE_SIZE);
-
- /* if uncompressed size is not the size of a page or is 0
- (indicating corrupted data or a too small output buffer (the latter of
- which should never happen)), returns error */
- if (uncomp_size != PAGE_SIZE || uncomp_size == 0)
- {
- return 0;
- }
- // place the decompressed page back into memory.
- os_memcpy(page, uncomp_page, PAGE_SIZE);
- kfree(uncomp_page);
- struct vas* kvas = KERNEL_VAS;
- vm_free_page(kvas, curr_ent->cmp_page);
- curr_ent->e_flags = 0;
- curr_ent->cmp_page = NULL;
- memory_count -= 4096;
- return *ID;
-}
-
-uint32_t retrieve_page(void *page, uint32_t *ID)
-{
- uint8_t lowbits = *((uint32_t*) page) & 0x000000FF;
-// if (swapfs_retrieve(page, ID, lowbits) == -1) { // GIVES ERROR FOR SOME REASON??
-// return 0;
-// }
- memory_count -= 4096;
- return *ID;
-}
-
-os_size_t sum_stored()
-{
- return memory_count;
-}
-
-uint32_t vm_swapin_page(void *page, uint32_t *ID)
-{
- struct node *swap_area;
- uint8_t ssid = *((uint32_t*) page) & 0x000000FF;
-// uint32_t sse = *((uint32_t*)page) & 0xFFFFFF00;
-
- // check if swap space exists
- if ((swap_area = pqueue_find(ssid)) == NULL)
- {
- /// check if there's enough memory for LZ compression
- // NOTE: always false until store/retrieve_page_LZ works
- if (0/*vm_count_free_frames() > COMPRESSED_SIZE/PAGE_ENTRIES*/)
- {
- vm_register_swap_space(store_page_LZ, retrieve_page_LZ, 0, -1);
- swap_area = pqueue_find(-1);
- }
- else
- {
- vm_register_swap_space(store_page, retrieve_page, 1, ssid);
- swap_area = pqueue_find(ssid);
- }
- }
-
- return swap_area->store_func(page, ID);
-}
-
-uint32_t vm_swapout_page(void *page, uint32_t *ID)
-{
- uint8_t ssid = *((uint32_t*) page) & 0x000000FF;
- struct node *swap_area = pqueue_find(ssid);
- return swap_area->retrieve_func(page, ID);
-}
-
-int vm_register_swap_space(func store_p, func retrieve_p, int priority,
- int16_t ssid)
-{
- /* waiting on fs team to increase 16 page limit, parameters
- SHOULD be (PAGE_ENTRIES, ssid) or (sse, ssid) */
-
- if (priority == 1)
- {
- swapfs_init(PAGE_ENTRIES, ssid);
- holder->e_head = NULL;
- }
- if (priority == 0)
- {
- if (holder->e_head = (struct swap_entry*) kmalloc(
- sizeof(struct swap_entry)) == NULL)
- {
- return -1;
- }
-// holder->e_head->next = NULL;
- holder->e_head->e_flags = 0;
- holder->e_head->cmp_page = NULL;
- }
- holder->lower_bits = ssid;
- holder->priority = priority;
- holder->store_func = store_p;
- holder->retrieve_func = retrieve_p;
- pqueue_push(holder);
- return 1;
-}
-
-void vm_deregister_swap_space(uint8_t ssid)
-{
- pqueue_pop_at(ssid);
-}
-
-uint32_t vm_page_fault(void *page)
-{
- /* TODO:
- * check if memory is full and needs to evict a page from RAM
- * figure out which page to evict than evict that page
- * page in the new page (done.)
- */
-
- //TODO: eventually change from equaling page to an actual id by establishing a proper hash table
- uint32_t* id = (uint32_t*) page;
-
- int temp;
- if ((temp = vm_swap_free_mapping(KERNEL_VAS, page, id)) < 0)
- {
- if (temp == VM_ERR_BADV)
- {
- os_printf("Virtual pointer passed was invalid [page_fault]");
- }
- if (temp == VM_ERR_NOT_MAPPED)
- {
- os_printf(
- "Virtual pointer was not mapped using set_mapping [page_fault]");
- }
- return 0;
- }
-
- uint8_t ssid = *((uint32_t*) page) & 0x000000FF;
- uint32_t ss_entry = *((uint32_t*) page) & 0xFFFFFF00;
- struct node *swap_area = pqueue_find(ssid);
- // load memory back into RAM
- swap_area->retrieve_func(page, &ss_entry);
-
- // find a free frame to map
- void *pptr = vm_get_free_frame();
- // TODO: once hashtable is properly set change permission to proper value
- int perm = VM_PERM_USER_RW;
- if (vm_set_mapping(KERNEL_VAS, page, pptr, perm) < 0)
- {
- if (temp == VM_ERR_BADV)
- {
- os_printf("Virtual pointer passed was invalid [page_fault]");
- }
- if (temp == VM_ERR_BADP)
- {
- os_printf("Physical pointer passed was invalid [page_fault]");
- }
- if (temp == VM_ERR_MAPPED)
- {
- os_printf(
- "The virtual pointer passed has already been mapped [page_fault]");
- }
- return 0;
- }
- // Get level 2 page table
- uint32_t *l2pt = (uint32_t*) VM_ENTRY_GET_L2(
- (uint32_t) VM_L1_GET_ENTRY(vm_get_current_vas()->l1_pagetable,
- page));
-
- // confirm from @lkolby whether this will work for setting the page table
- uint32_t *tmp = (uint32_t*) VM_L2_ENTRY(l2pt, page);
- *tmp = (uint32_t*) page;
-
- return *((uint32_t*) pptr);
-}
-
-//uint32_t* vm_scan_pages(void *page, uint32_t *ID);
-
diff --git a/kernel/vm/swap_fs.c b/kernel/vm/swap_fs.c
deleted file mode 100644
index 74604d66..00000000
--- a/kernel/vm/swap_fs.c
+++ /dev/null
@@ -1,161 +0,0 @@
-#include "file.h"
-#include "bitvector.h"
-#include "vm.h"
-#include "klibc.h"
-#include "swap_fs.h"
-
-char *generate_filename(uint8_t ssid)
-{
- char *output;
- if (ssid < 10)
- { // single digit
- char swapfile[9] =
- { '/', 's', 'w', 'a', 'p', '0', '0', ssid + 48, 0 };
- output = swapfile;
- }
- else if (ssid < 100)
- { // double digit
- int tmp = ssid / 10;
- char swapfile[9] =
- { '/', 's', 'w', 'a', 'p', '0', tmp + 48, (ssid % 10) + 48, 0 };
- output = swapfile;
- }
- else
- { // triple digit
- int tmp = ssid / 10;
- int tmp2 = ssid / 100;
- char swapfile[9] =
- { '/', 's', 'w', 'a', 'p', tmp2 + 48, tmp + 48, ssid + 48, 0 };
- output = swapfile;
- }
- return output;
-}
-
-int32_t swapfs_init(int npages, uint8_t ssid)
-{
- int fd;
- int nbytes;
- // Initialize the free bitmap
-// free_bitvector = make_vector(npages);
- bv_arr[ssid] = make_vector(npages);
-
- // making new files instead of a tree b/c the FS can't do it
- char *swapfile = generate_filename(ssid);
-
- // The permissions parameter doesn't quite work right now (BUG?)
- if (kcreate(swapfile, 'w', 1) < 0)
- {
- return -1;
- }
-
- // For now, we have to fill the file with that much blank storage.
- if ((fd = kopen(swapfile, 'w')) < 0)
- {
- return -1;
- }
- void *empty_page = kmalloc(BLOCK_SIZE);
-
- // seems useless to me...?
- for (int i = 0; i < npages; i++)
- {
- if ((nbytes = kwrite(fd, empty_page, BLOCK_SIZE)) < 0)
- {
- return -1;
- }
- }
-
- kfree(empty_page);
- kclose(fd);
-
- return nbytes * npages; // success
-}
-
-int64_t swapfs_store(void *page, uint32_t *id, uint8_t ssid)
-{
- int32_t fd;
- char *swapfile;
- int32_t b;
- // Get the index to store the page into
- *id = *((uint32_t*) page) & 0xFFFFFF00;
-
- if ((b = bv_isfree(*id, bv_arr[ssid])) <= 0)
- {
- if (b == -1)
- {
- os_printf("invalid index [swapfs_store]");
- }
- else
- {
- os_printf("index not free [swapfs_store]");
- }
-
- return -1;
- }
-
- // Error if invalid index
- if (bv_set(*id, bv_arr[ssid]) < 0)
- {
- return -1;
- }
-
- swapfile = generate_filename(ssid);
- // Error if failed to open
- if ((fd = kopen(swapfile, 'w')) < 0)
- {
- return -1;
- }
-
- // Error if seeks beyond boundaries
- if (kseek(fd, (*id) * BLOCK_SIZE) < 0)
- {
- return -1;
- }
-
- if (kwrite(fd, page, BLOCK_SIZE) < 0)
- {
- return -1;
- }
- kclose(fd);
-
- return *id; // success
-}
-
-int64_t swapfs_retreive(void *page, uint32_t *id, uint8_t ssid)
-{
- int fd;
- char *swapfile;
- //checks if index is free
- if (!bv_get(*id, bv_arr[ssid]))
- {
- return -1;
- }
-
- swapfile = generate_filename(ssid);
-
- // not sure if I should make the index free here...
- bv_lower(*id, bv_arr[ssid]);
-
- if ((fd = kopen(swapfile, 'r')) < 0)
- {
- return -1;
- }
-
- kseek(fd, (*id) * BLOCK_SIZE);
- kread(fd, page, BLOCK_SIZE);
- kclose(fd);
-
- return 1; // success
-}
-
-int32_t swapfs_disable(uint8_t ssid)
-{
- char *swapfile;
- bv_free(bv_arr[ssid]);
- swapfile = generate_filename(ssid);
- if (kdelete(swapfile, 0) < 0)
- {
- return -1;
- }
-
- return 1; // success
-}
diff --git a/kernel/vm/vm.c b/kernel/vm/vm.c
deleted file mode 100644
index 3be3b78c..00000000
--- a/kernel/vm/vm.c
+++ /dev/null
@@ -1,464 +0,0 @@
-#include "vm.h"
-#include "memory.h"
-#include "klibc.h"
-#include "frame.h"
-
-#define CHECK_VPTR if ((unsigned int)vptr & (BLOCK_SIZE-1)) return VM_ERR_BADV;
-#define CHECK_PPTR if ((unsigned int)pptr & (BLOCK_SIZE-1)) return VM_ERR_BADP;
-
-static const int perm_mapping[16] =
-{ 0, // 0000 Nothing
- 5, // 0001 Privileged RO, nothing otherwise
- 6, // 0010 User RO, privileged RO.
- 6, // 0011 User RO, privileged RO.
- 1, // 0100 Privileged RW, nothing otherwise
- -1, // 0101 ???
- 2, // 0110 Privileged RW, user RO
- -1, // 0111 ???
- 3, // 1000 User RW, privileged RW
- -1, // 1001 ???
- -1, // 1010 ???
- -1, // 1011 ???
- 3, // 1100 User RW, privileged RW
- -1, // 1101 ???
- -1, // 1110 ???
- -1, // 1111 ???
- };
-
-static struct vas *vm_current_vas = (struct vas*) V_L1PTBASE;
-
-struct vm_free_list
-{
- struct vm_free_list *next;
-};
-
-struct vm_free_list *vm_vas_free_list = 0x0;
-struct vm_free_list *vm_l1pt_free_list = 0x0;
-struct vm_free_list *vm_l2pt_free_list = 0x0;
-
-void vm_init()
-{
- // Initialize the VAS structures. We allocate enough for 4096 VASs.
- struct vm_free_list *free_vas = (struct vm_free_list*) P_L1PTBASE;
- //vm_vas_free_list = free_vas;
- vm_vas_free_list = (struct vm_free_list*) ((void*) free_vas + V_L1PTBASE
- - P_L1PTBASE);
- struct vm_free_list *last = 0x0;
- while ((uint32_t) free_vas < P_L1PTBASE + sizeof(struct vas) * 4096)
- {
- free_vas->next = 0x0;
- if (last)
- {
- last->next = (struct vm_free_list*) ((void*) free_vas + V_L1PTBASE
- - P_L1PTBASE);
- }
- last = free_vas;
- free_vas =
- (struct vm_free_list*) ((void*) free_vas + sizeof(struct vas));
- }
-
- // Initialize the L1 page tables
- struct vm_free_list *free_l1pt = (struct vm_free_list*) (P_L1PTBASE
- + sizeof(struct vas) * 4096);
- vm_l1pt_free_list = (struct vm_free_list*) ((void*) free_l1pt + V_L1PTBASE
- - P_L1PTBASE);
- last = 0x0;
- while ((uint32_t) free_l1pt < P_L1PTBASE + (1 << 20) - ((1 << 20) >> 2))
- {
- free_l1pt->next = 0x0;
- if (last)
- {
- last->next = (struct vm_free_list*) ((void*) free_l1pt + V_L1PTBASE
- - P_L1PTBASE);
- }
- last = free_l1pt;
- free_l1pt =
- (struct vm_free_list*) ((void*) free_l1pt + PAGE_TABLE_SIZE);
- }
-
- // Initialize the L2 coarse page tables
- struct vm_free_list *free_l2pt = (struct vm_free_list*) (P_L1PTBASE
- + (1 << 19));
- vm_l2pt_free_list = (struct vm_free_list*) ((void*) free_l2pt + V_L1PTBASE
- - P_L1PTBASE);
- last = 0x0;
- while ((uint32_t) free_l2pt < P_L1PTBASE + (1 << 20))
- {
- free_l2pt->next = 0x0;
- if (last)
- {
- last->next = (struct vm_free_list*) ((void*) free_l2pt + V_L1PTBASE
- - P_L1PTBASE);
- }
- last = free_l2pt;
- free_l2pt = (struct vm_free_list*) ((void*) free_l2pt
- + L2_PAGE_TABLE_SIZE);
- }
-}
-
-uint32_t *vm_alloc_coarse_page_table()
-{
- // TODO: What if we run out?
- uint32_t *vptr = (uint32_t*) vm_l2pt_free_list;
- if (vptr == 0x0)
- {
- LOG(
- "Could not allocate a coarse page table, bad things will happen soon.\n");
- return NULL;
- }
- vm_l2pt_free_list = ((struct vm_free_list*) vptr)->next;
- os_memset((void*) vptr, 0, L2_PAGE_TABLE_SIZE);
- return vptr;
-}
-
-uint32_t *vm_vtop(struct vas *vas, uint32_t *vptr)
-{
- // Hack. Assume it's all linearly mapped, and vas == KERNEL_VAS
- if (vas != KERNEL_VAS)
- {
- os_printf("vas is not KERNEL_VAS in vm_vtop. :-(\n");
- while (1)
- ;
- }
- return (uint32_t*) ((void*) vptr - V_L1PTBASE + P_L1PTBASE);
-}
-
-uint32_t *vm_ptov(struct vas *vas, uint32_t *vptr)
-{
- // Hack. Assume it's all linearly mapped, and vas == KERNEL_VAS
- if (vas != KERNEL_VAS)
- {
- os_printf("vas is not KERNEL_VAS in vm_vtop. :-(\n");
- while (1)
- ;
- }
- return (uint32_t*) ((void*) vptr + V_L1PTBASE - P_L1PTBASE);
-}
-
-struct vas *vm_get_current_vas()
-{
- return vm_current_vas;
-}
-
-void vm_use_kernel_vas()
-{
- vm_enable_vas((struct vas*) V_L1PTBASE);
-}
-
-int vm_allocate_page(struct vas *vas, void *vptr, int permission)
-{
- CHECK_VPTR;
-
- // We have to save the current VAS and switch to the kernel VAS
- struct vas *prev_vas = vm_current_vas;
- vm_use_kernel_vas();
-
- // TODO: Check if the vas already has a mapping there.
- void *pptr = vm_get_free_frame();
- if (pptr == 0x0)
- {
- // We need to swap! (or something...)
- vm_enable_vas(prev_vas);
- return VM_ERR_UNKNOWN; // For now, just fail
- }
-
- os_printf("mapping VA %x to PA %x\n", vptr, pptr);
-
- //LOG("Free frame is at: %X\n", pptr);
- int retval = vm_set_mapping(vas, vptr, pptr, permission);
- if (retval)
- {
- // Release the frame to prevent a memory leak
- os_printf("vm_set_mapping returned %d for 0x%X\n", retval, vptr);
- vm_release_frame(pptr);
- vm_enable_vas(prev_vas);
- return retval;
- }
-
- vm_enable_vas(prev_vas);
- return 0;
-}
-
-void *vm_allocate_pages(struct vas *vas, void *vptr, uint32_t nbytes,
- int permission)
-{
- int rc;
- unsigned char *p = (unsigned char*) vptr;
- while (p - (unsigned char*) vptr < nbytes)
- {
- rc = vm_allocate_page(vas, p, permission);
- assert(rc == 0);
- p += BLOCK_SIZE;
- }
- return p;
-}
-
-#define VM_L1_GET_ENTRY(table,vptr) table[((unsigned int)vptr)>>20]
-#define VM_L1_SET_ENTRY(table,vptr,ent) (table[((unsigned int)vptr)>>20]=ent)
-#define VM_ENTRY_GET_FRAME(x) ((x)&~((PAGE_TABLE_SIZE<<1) - 1))
-#define VM_ENTRY_GET_L2(x) ((x)&~0x1FF)
-#define VM_L2_ENTRY(l2pt,vptr) ((uint32_t*)l2pt)[((unsigned int)vptr&0x000FF000)>>12]
-#define VM_L2ENTRY_GET_FRAME(x) ((x)&0xFFFFF000)
-
-int vm_free_page(struct vas *vas, void *vptr)
-{
- CHECK_VPTR;
-
- // We have to save the current VAS
- struct vas *prev_vas = vm_current_vas;
- vm_use_kernel_vas();
-
- // TODO: Check if it was actually allocated
- uint32_t entry = VM_L1_GET_ENTRY(vas->l1_pagetable, vptr);
-
- // Okay, it's a 4KB page. We need to walk the l2 page table.
- uint32_t *l2pt = vm_ptov(KERNEL_VAS, (uint32_t*) VM_ENTRY_GET_L2(entry));
- entry = VM_L2_ENTRY(l2pt, vptr);
- vm_release_frame((void*) VM_L2ENTRY_GET_FRAME(entry));
- //LOG("Releasing frame %X, l2pt=%X\n", VM_L2ENTRY_GET_FRAME(entry), l2pt);
- VM_L2_ENTRY(l2pt,vptr)= 0;
- //vas->l1_pagetable[(unsigned int)vptr>>20] = 0;
-
- vm_enable_vas(prev_vas);
- return 0;
-}
-
-int vm_pin(struct vas *vas, void *vptr)
-{
- // FIXME: unimplemented
- return 0;
-}
-
-int vm_unpin(struct vas *vas, void *vptr)
-{
- // FIXME: unimplemented
- return 0;
-}
-
-int vm_set_mapping(struct vas *vas, void *vptr, void *pptr, int permission)
-{
- CHECK_VPTR;
- CHECK_PPTR;
- int perm = perm_mapping[permission];
- if (perm == -1)
- return VM_ERR_BADPERM;
-
- uint32_t cur_entry = vas->l1_pagetable[(unsigned int) vptr >> 20];
- if ((cur_entry & 3) == 2)
- {
- return VM_ERR_MAPPED;
- }
- if ((cur_entry & 3) == 0)
- {
- // We need to allocate a coarse page table
- uint32_t *vptr_coarse_pt = vm_alloc_coarse_page_table();
- vas->l1_pagetable[(unsigned int) vptr >> 20] = (uint32_t) vm_vtop(
- KERNEL_VAS, vptr_coarse_pt) | 1;
- cur_entry = vas->l1_pagetable[(unsigned int) vptr >> 20];
- }
-
- uint32_t *l2_pagetable = vm_ptov(KERNEL_VAS,
- (uint32_t*) VM_ENTRY_GET_L2(cur_entry));
- int l2_idx = ((unsigned int) vptr & 0x000FF000) >> 12;
- if (l2_pagetable[l2_idx])
- {
- return VM_ERR_MAPPED;
- }
-
- //perm &= ~(1<<10); // Clear AP[0] so we get an access exception.
- //vas->l1_pagetable[(unsigned int)vptr>>20] = (unsigned int)pptr | (perm<<10) | 2;
- // TODO: Permissions!
- int lvl2_perm = perm; //perm_mapping[perm];
- int apx_bit = (lvl2_perm & 4) >> 2;
- int ap_bits = lvl2_perm & 3;
- l2_pagetable[l2_idx] = (unsigned int) pptr | (apx_bit << 9) | (ap_bits << 4)
- | 2;
- //os_printf("pptr: %X, idx=%d, l2pt=%X\n", pptr, l2_idx, l2_pagetable);
- //os_printf("permission=%d lvl2_perm=%X apx=%X ap=%X\n", permission, lvl2_perm, apx_bit, ap_bits);
- //l2_pagetable[l2_idx] = (unsigned int)pptr | (1<<4) | 2;
- return 0;
-}
-
-int vm_swap_free_mapping(struct vas *vas, void *vptr, uint32_t *ID)
-{
- CHECK_VPTR;
- // TODO: If this is a paged frame, then we need to throw an error
- if ((vas->l1_pagetable[(unsigned int) vptr >> 20] & 3) == 2)
- {
- vas->l1_pagetable[(unsigned int) vptr >> 20] = 0;
- }
- else if ((vas->l1_pagetable[(unsigned int) vptr >> 20] & 3) == 1)
- {
- // We have to free the mapping in the L2 page table
- uint32_t *l2pt = vm_ptov(KERNEL_VAS,
- (uint32_t*) VM_ENTRY_GET_L2(
- vas->l1_pagetable[(unsigned int )vptr >> 20]));
- VM_L2_ENTRY(l2pt, vptr)= (uint32_t) ID;
- }
- return 0;
-}
-
-int vm_free_mapping(struct vas *vas, void *vptr)
-{
- CHECK_VPTR;
- // TODO: If this is a paged frame, then we need to throw an error
- if ((vas->l1_pagetable[(unsigned int) vptr >> 20] & 3) == 2)
- {
- vas->l1_pagetable[(unsigned int) vptr >> 20] = 0;
- }
- else if ((vas->l1_pagetable[(unsigned int) vptr >> 20] & 3) == 1)
- {
- // We have to free the mapping in the L2 page table
- uint32_t *l2pt = vm_ptov(KERNEL_VAS,
- (uint32_t*) VM_ENTRY_GET_L2(
- vas->l1_pagetable[(unsigned int )vptr >> 20]));
- VM_L2_ENTRY(l2pt, vptr)= 0;
- }
- return 0;
-}
-
-// We're going to have to switch to the kernel's VAS, then copy it over.
-int vm_map_shared_memory(struct vas *vas, void *this_ptr, struct vas *other_vas,
- void *other_ptr, int permission)
-{
- if ((unsigned int) this_ptr & (BLOCK_SIZE - 1))
- return VM_ERR_BADV;
- if ((unsigned int) other_ptr & (BLOCK_SIZE - 1))
- return VM_ERR_BADP;
-
- struct vas *prev_vas = vm_current_vas;
- vm_enable_vas(KERNEL_VAS);
-
- if ((vas->l1_pagetable[(unsigned int) this_ptr >> 20] & 3) == 2)
- {
- return VM_ERR_MAPPED;
- }
- if (!other_vas->l1_pagetable[(unsigned int) other_ptr >> 20])
- {
- return VM_ERR_NOT_MAPPED;
- }
- if (!vas->l1_pagetable[(unsigned int) this_ptr >> 20])
- {
- // We need to allocate a coarse page table...
- uint32_t *vptr_coarse_pt = vm_alloc_coarse_page_table();
- vas->l1_pagetable[(unsigned int) this_ptr >> 20] = (uint32_t) vm_vtop(
- KERNEL_VAS, vptr_coarse_pt) | 1;
- //LOG("Allocated coarse page table.\n");
- //LOG("Should be zero: %X (%X)\n", vptr_coarse_pt[0], vptr_coarse_pt);
- }
- uint32_t *this_l2pt = vm_ptov(KERNEL_VAS,
- (uint32_t*) VM_ENTRY_GET_L2(
- vas->l1_pagetable[(unsigned int )this_ptr >> 20]));
- if (VM_L2_ENTRY(this_l2pt, this_ptr))
- {
- //LOG("Should be zero: %X (this_l2pt=%X, idx=%d)\n", VM_L2_ENTRY(this_l2pt, this_ptr), this_l2pt, ((unsigned int)this_ptr&0x000FF000)>>12);
- return VM_ERR_MAPPED;
- }
- uint32_t *other_l2pt = vm_ptov(KERNEL_VAS,
- (uint32_t*) VM_ENTRY_GET_L2(
- other_vas->l1_pagetable[(unsigned int )other_ptr >> 20]));
- if (!VM_L2_ENTRY(other_l2pt, other_ptr))
- {
- return VM_ERR_NOT_MAPPED;
- }
-
- int perm = perm_mapping[permission];
- if (perm == -1)
- return VM_ERR_BADPERM;
-
- // Well, this was remarkably easy.
- //unsigned int pptr = VM_ENTRY_GET_FRAME(other_vas->l1_pagetable[(unsigned int)other_ptr>>20]);
- unsigned int pptr = VM_L2ENTRY_GET_FRAME(
- VM_L2_ENTRY(other_l2pt, other_ptr));
- //os_printf("pptr: %X\n",pptr);
- //perm &= ~(1<<10); // Clear AP[0] so we get an access exception.
- //vas->l1_pagetable[(unsigned int)this_ptr>>20] = pptr | (perm<<10) | 2;
- VM_L2_ENTRY(this_l2pt, this_ptr)= pptr | (1<<4) | 2;
- LOG("%X\n", VM_L2_ENTRY(this_l2pt, this_ptr));
-
- vm_enable_vas(prev_vas);
- return 0;
-}
-
-void vm_enable_vas(struct vas *vas)
-{
- vm_current_vas = vas;
-
- // Clear the BTAC
- // Performed by cleaning the caches, below
- // asm volatile("mcr p15, 0, %[r], c7, c5, 6" : : [r] "r" (0x0));
-
- // Flush the write caches
- asm volatile("MCR p15, 0, %[r], c7, c10, 4" : : [r] "r" (0x0));
- // sync barrier
- asm volatile("MCR p15, 0, %[r], c7, c10, 5" : : [r] "r" (0x0));
- // memory barrier
-
- //TTBR0
- asm volatile("mcr p15, 0, %[addr], c2, c0, 0" : : [addr] "r" (vas->l1_pagetable_phys));
- // Translation table 1 is currently ignored
-
- // Clean the caches (data & instruction)
- asm volatile("mcr p15, 0, %[r], c7, c14, 0" : : [r] "r" (0x0));
-}
-
-struct vas *vm_new_vas()
-{
- if (!vm_vas_free_list)
- {
- return 0x0;
- }
- if (!vm_l1pt_free_list)
- {
- return 0x0;
- }
- struct vas *p = (struct vas*) vm_vas_free_list;
- vm_vas_free_list = vm_vas_free_list->next;
-
- os_printf("vm_l1pt_free_list=%X\n", vm_l1pt_free_list);
- p->l1_pagetable = (uint32_t*) vm_l1pt_free_list;
- vm_l1pt_free_list = vm_l1pt_free_list->next;
-
- p->l1_pagetable_phys = (unsigned int*) ((unsigned int) p->l1_pagetable
- - (V_L1PTBASE - P_L1PTBASE));
-
- // Zero out the page table
- os_memset(p->l1_pagetable, 0, PAGE_TABLE_SIZE);
-
- // Setup the static mappings...
- // The kernel (high & low addresses)
- //should be less than a MB
- p->l1_pagetable[P_KERNBASE >> 20] = 0 << 20 | 0x0400 | 2;
-
- //also map it to high memory at 0xf0000000
- p->l1_pagetable[V_KERNBASE >> 20] = 0 << 20 | 0x0400 | 2;
- p->l1_pagetable[(V_KERNBASE + 0x100000) >> 20] = 0x100000 | 0x0400 | 2;
-
- // Kernel datastructures
- //temporarily map where it is until we copy it in VAS
- p->l1_pagetable[P_KDSBASE >> 20] = P_KDSBASE | 0x0400 | 2;
-
- //1MB for static kernel data structures (stacks and l1 pt)
- p->l1_pagetable[V_KDSBASE >> 20] = P_KDSBASE | 0x0400 | 2;
-
- // Our 1MB page to store VAS datastructures
- p->l1_pagetable[V_L1PTBASE >> 20] = P_L1PTBASE | 0x0400 | 2;
-
- // 2MB of peripheral registers (so we get the serial port et. al.)
- p->l1_pagetable[PERIPHBASE >> 20] = PERIPHBASE | 0x0400 | 2;
- p->l1_pagetable[(PERIPHBASE + 0x100000) >> 20] = (PERIPHBASE + 0x100000)
- | 0x0400 | 2;
- return p;
-}
-
-int vm_free_vas(struct vas *vas)
-{
- struct vm_free_list *n = (struct vm_free_list*) vas->l1_pagetable;
- n->next = vm_l1pt_free_list;
- vm_l1pt_free_list = n;
-
- n = (struct vm_free_list*) vas;
- n->next = vm_vas_free_list;
- vm_vas_free_list = n;
- return 0;
-}
diff --git a/doxyfile b/project/Doxyfile
similarity index 79%
rename from doxyfile
rename to project/Doxyfile
index 706263ce..79283e15 100644
--- a/doxyfile
+++ b/project/Doxyfile
@@ -1,4 +1,4 @@
-# Doxyfile 1.8.6
+# Doxyfile 1.8.15
# This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project.
@@ -17,11 +17,11 @@
# Project related configuration options
#---------------------------------------------------------------------------
-# This tag specifies the encoding used for all characters in the config file
-# that follow. The default is UTF-8 which is also the encoding used for all text
-# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv
-# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv
-# for the list of possible encodings.
+# This tag specifies the encoding used for all characters in the configuration
+# file that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
+# https://www.gnu.org/software/libiconv/ for the list of possible encodings.
# The default value is: UTF-8.
DOXYFILE_ENCODING = UTF-8
@@ -46,10 +46,10 @@ PROJECT_NUMBER =
PROJECT_BRIEF = "Giving everyone a piece of the pi"
-# With the PROJECT_LOGO tag one can specify an logo or icon that is included in
-# the documentation. The maximum height of the logo should not exceed 55 pixels
-# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo
-# to the output directory.
+# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
+# in the documentation. The maximum height of the logo should not exceed 55
+# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
+# the logo to the output directory.
PROJECT_LOGO =
@@ -60,7 +60,7 @@ PROJECT_LOGO =
OUTPUT_DIRECTORY =
-# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub-
+# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
# directories (in 2 levels) under the output directory of each output format and
# will distribute the generated files over these directories. Enabling this
# option can be useful when feeding doxygen a huge amount of source files, where
@@ -68,7 +68,15 @@ OUTPUT_DIRECTORY =
# performance problems for the file system.
# The default value is: NO.
-CREATE_SUBDIRS = NO
+CREATE_SUBDIRS = YES
+
+# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII
+# characters to appear in the names of generated files. If set to NO, non-ASCII
+# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode
+# U+3044.
+# The default value is: NO.
+
+ALLOW_UNICODE_NAMES = YES
# The OUTPUT_LANGUAGE tag is used to specify the language in which all
# documentation generated by doxygen is written. Doxygen will use this
@@ -85,14 +93,22 @@ CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
-# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member
+# The OUTPUT_TEXT_DIRECTION tag is used to specify the direction in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all generated output in the proper direction.
+# Possible values are: None, LTR, RTL and Context.
+# The default value is: None.
+
+OUTPUT_TEXT_DIRECTION = None
+
+# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member
# descriptions after the members that are listed in the file and class
# documentation (similar to Javadoc). Set to NO to disable this.
# The default value is: YES.
BRIEF_MEMBER_DESC = YES
-# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief
+# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief
# description of a member or function before the detailed description
#
# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
@@ -110,7 +126,17 @@ REPEAT_BRIEF = YES
# the entity):The $name class, The $name widget, The $name file, is, provides,
# specifies, contains, represents, a, an and the.
-ABBREVIATE_BRIEF =
+ABBREVIATE_BRIEF = "The $name class" \
+ "The $name widget" \
+ "The $name file" \
+ is \
+ provides \
+ specifies \
+ contains \
+ represents \
+ a \
+ an \
+ the
# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
# doxygen will generate a detailed section even if there is only a brief
@@ -125,9 +151,9 @@ ALWAYS_DETAILED_SEC = NO
# operators of the base classes will not be shown.
# The default value is: NO.
-INLINE_INHERITED_MEMB = NO
+INLINE_INHERITED_MEMB = YES
-# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path
+# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
# before files name in the file list and in the header files. If set to NO the
# shortest path that makes the file name unique will be used
# The default value is: YES.
@@ -144,7 +170,7 @@ FULL_PATH_NAMES = YES
# will be relative from the directory where doxygen is started.
# This tag requires that the tag FULL_PATH_NAMES is set to YES.
-STRIP_FROM_PATH =
+STRIP_FROM_PATH = kernel/src/
# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
# path mentioned in the documentation of a class, which tells the reader which
@@ -169,7 +195,7 @@ SHORT_NAMES = NO
# description.)
# The default value is: NO.
-JAVADOC_AUTOBRIEF = NO
+JAVADOC_AUTOBRIEF = YES
# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
# line (until the first dot) of a Qt-style comment as the brief description. If
@@ -177,7 +203,7 @@ JAVADOC_AUTOBRIEF = NO
# requiring an explicit \brief command for a brief description.)
# The default value is: NO.
-QT_AUTOBRIEF = NO
+QT_AUTOBRIEF = YES
# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a
# multi-line C++ special comment block (i.e. a block of //! or /// comments) as
@@ -197,9 +223,9 @@ MULTILINE_CPP_IS_BRIEF = NO
INHERIT_DOCS = YES
-# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a
-# new page for each member. If set to NO, the documentation of a member will be
-# part of the file/class/namespace that contains it.
+# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new
+# page for each member. If set to NO, the documentation of a member will be part
+# of the file/class/namespace that contains it.
# The default value is: NO.
SEPARATE_MEMBER_PAGES = NO
@@ -218,7 +244,12 @@ TAB_SIZE = 4
# will allow you to put the command \sideeffect (or @sideeffect) in the
# documentation, which will result in a user-defined paragraph with heading
# "Side Effects:". You can put \n's in the value part of an alias to insert
-# newlines.
+# newlines (in the resulting output). You can put ^^ in the value part of an
+# alias to insert a newline as if a physical newline was in the original file.
+# When you need a literal { or } or , in the value part of an alias you have to
+# escape them by means of a backslash (\), this can lead to conflicts with the
+# commands \{ and \} for these it is advised to use the version @{ and @} or use
+# a double escape (\\{ and \\})
ALIASES =
@@ -234,7 +265,7 @@ TCL_SUBST =
# members will be omitted, etc.
# The default value is: NO.
-OPTIMIZE_OUTPUT_FOR_C = NO
+OPTIMIZE_OUTPUT_FOR_C = YES
# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or
# Python sources only. Doxygen will then generate output that is more tailored
@@ -256,16 +287,28 @@ OPTIMIZE_FOR_FORTRAN = NO
OPTIMIZE_OUTPUT_VHDL = NO
+# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice
+# sources only. Doxygen will then generate output that is more tailored for that
+# language. For instance, namespaces will be presented as modules, types will be
+# separated into more groups, etc.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_SLICE = NO
+
# Doxygen selects the parser to use depending on the extension of the files it
# parses. With this tag you can assign which parser to use for a given
# extension. Doxygen has a built-in mapping, but you can override or extend it
# using this tag. The format is ext=language, where ext is a file extension, and
# language is one of the parsers supported by doxygen: IDL, Java, Javascript,
-# C#, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL. For instance to make
-# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C
-# (default is Fortran), use: inc=Fortran f=C.
+# Csharp (C#), C, C++, D, PHP, md (Markdown), Objective-C, Python, Slice,
+# Fortran (fixed format Fortran: FortranFixed, free formatted Fortran:
+# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser
+# tries to guess whether the code is fixed or free formatted code, this is the
+# default for Fortran type files), VHDL, tcl. For instance to make doxygen treat
+# .inc files as Fortran files (default is PHP), and .f files as C (default is
+# Fortran), use: inc=Fortran f=C.
#
-# Note For files without extension you can use no_extension as a placeholder.
+# Note: For files without extension you can use no_extension as a placeholder.
#
# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
# the files are not read by doxygen.
@@ -274,7 +317,7 @@ EXTENSION_MAPPING =
# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
# according to the Markdown format, which allows for more readable
-# documentation. See http://daringfireball.net/projects/markdown/ for details.
+# documentation. See https://daringfireball.net/projects/markdown/ for details.
# The output of markdown processing is further processed by doxygen, so you can
# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in
# case of backward compatibilities issues.
@@ -282,10 +325,19 @@ EXTENSION_MAPPING =
MARKDOWN_SUPPORT = YES
+# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up
+# to that level are automatically included in the table of contents, even if
+# they do not have an id attribute.
+# Note: This feature currently applies only to Markdown headings.
+# Minimum value: 0, maximum value: 99, default value: 0.
+# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.
+
+TOC_INCLUDE_HEADINGS = 4
+
# When enabled doxygen tries to link words that correspond to documented
# classes, or namespaces to their corresponding documentation. Such a link can
-# be prevented in individual cases by by putting a % sign in front of the word
-# or globally by setting AUTOLINK_SUPPORT to NO.
+# be prevented in individual cases by putting a % sign in front of the word or
+# globally by setting AUTOLINK_SUPPORT to NO.
# The default value is: YES.
AUTOLINK_SUPPORT = YES
@@ -298,7 +350,7 @@ AUTOLINK_SUPPORT = YES
# diagrams that involve STL classes more complete and accurate.
# The default value is: NO.
-BUILTIN_STL_SUPPORT = NO
+BUILTIN_STL_SUPPORT = YES
# If you use Microsoft's C++/CLI language, you should set this option to YES to
# enable parsing support.
@@ -307,7 +359,7 @@ BUILTIN_STL_SUPPORT = NO
CPP_CLI_SUPPORT = NO
# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:
-# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen
+# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen
# will parse them like normal C++ but will assume all classes use public instead
# of private inheritance when no explicit protection keyword is present.
# The default value is: NO.
@@ -325,13 +377,20 @@ SIP_SUPPORT = NO
IDL_PROPERTY_SUPPORT = YES
# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
-# tag is set to YES, then doxygen will reuse the documentation of the first
+# tag is set to YES then doxygen will reuse the documentation of the first
# member in the group (if any) for the other members of the group. By default
# all members of a group must be documented explicitly.
# The default value is: NO.
DISTRIBUTE_GROUP_DOC = NO
+# If one adds a struct or class to a group and this option is enabled, then also
+# any nested class or struct is added to the same group. By default this option
+# is disabled and one has to add nested compounds explicitly via \ingroup.
+# The default value is: NO.
+
+GROUP_NESTED_COMPOUNDS = YES
+
# Set the SUBGROUPING tag to YES to allow class member groups of the same type
# (for instance a group of public functions) to be put as a subgroup of that
# type (e.g. under the Public Functions section). Set it to NO to prevent
@@ -371,7 +430,7 @@ INLINE_SIMPLE_STRUCTS = NO
# types are typedef'ed and only the typedef is referenced, never the tag name.
# The default value is: NO.
-TYPEDEF_HIDES_STRUCT = NO
+TYPEDEF_HIDES_STRUCT = YES
# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This
# cache is used to resolve symbols given their name and scope. Since this can be
@@ -390,7 +449,7 @@ LOOKUP_CACHE_SIZE = 0
# Build related configuration options
#---------------------------------------------------------------------------
-# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in
# documentation are documented, even if no documentation was available. Private
# class members and static file members will be hidden unless the
# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.
@@ -400,35 +459,35 @@ LOOKUP_CACHE_SIZE = 0
EXTRACT_ALL = YES
-# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will
+# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
# be included in the documentation.
# The default value is: NO.
-EXTRACT_PRIVATE = NO
+EXTRACT_PRIVATE = YES
-# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal
+# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
# scope will be included in the documentation.
# The default value is: NO.
-EXTRACT_PACKAGE = NO
+EXTRACT_PACKAGE = YES
-# If the EXTRACT_STATIC tag is set to YES all static members of a file will be
+# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be
# included in the documentation.
# The default value is: NO.
-EXTRACT_STATIC = NO
+EXTRACT_STATIC = YES
-# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined
-# locally in source files will be included in the documentation. If set to NO
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
+# locally in source files will be included in the documentation. If set to NO,
# only classes defined in header files are included. Does not have any effect
# for Java sources.
# The default value is: YES.
EXTRACT_LOCAL_CLASSES = YES
-# This flag is only useful for Objective-C code. When set to YES local methods,
+# This flag is only useful for Objective-C code. If set to YES, local methods,
# which are defined in the implementation section but not in the interface are
-# included in the documentation. If set to NO only methods in the interface are
+# included in the documentation. If set to NO, only methods in the interface are
# included.
# The default value is: NO.
@@ -453,21 +512,21 @@ HIDE_UNDOC_MEMBERS = NO
# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all
# undocumented classes that are normally visible in the class hierarchy. If set
-# to NO these classes will be included in the various overviews. This option has
-# no effect if EXTRACT_ALL is enabled.
+# to NO, these classes will be included in the various overviews. This option
+# has no effect if EXTRACT_ALL is enabled.
# The default value is: NO.
HIDE_UNDOC_CLASSES = NO
# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
-# (class|struct|union) declarations. If set to NO these declarations will be
+# (class|struct|union) declarations. If set to NO, these declarations will be
# included in the documentation.
# The default value is: NO.
HIDE_FRIEND_COMPOUNDS = NO
# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any
-# documentation blocks found inside the body of a function. If set to NO these
+# documentation blocks found inside the body of a function. If set to NO, these
# blocks will be appended to the function's detailed documentation block.
# The default value is: NO.
@@ -481,7 +540,7 @@ HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file
-# names in lower-case letters. If set to YES upper-case letters are also
+# names in lower-case letters. If set to YES, upper-case letters are also
# allowed. This is useful if you have classes or files whose names only differ
# in case and if your file system supports case sensitive file names. Windows
# and Mac users are advised to set this option to NO.
@@ -490,12 +549,19 @@ INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with
-# their full class and namespace scopes in the documentation. If set to YES the
+# their full class and namespace scopes in the documentation. If set to YES, the
# scope will be hidden.
# The default value is: NO.
HIDE_SCOPE_NAMES = NO
+# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will
+# append additional text to a page's title, such as Class Reference. If set to
+# YES the compound reference will be hidden.
+# The default value is: NO.
+
+HIDE_COMPOUND_REFERENCE= NO
+
# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of
# the files that are included by a file in the documentation of that file.
# The default value is: YES.
@@ -523,14 +589,14 @@ INLINE_INFO = YES
# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the
# (detailed) documentation of file and class members alphabetically by member
-# name. If set to NO the members will appear in declaration order.
+# name. If set to NO, the members will appear in declaration order.
# The default value is: YES.
SORT_MEMBER_DOCS = YES
# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
# descriptions of file, namespace and class members alphabetically by member
-# name. If set to NO the members will appear in declaration order. Note that
+# name. If set to NO, the members will appear in declaration order. Note that
# this will also influence the order of the classes in the class list.
# The default value is: NO.
@@ -575,27 +641,25 @@ SORT_BY_SCOPE_NAME = NO
STRICT_PROTO_MATCHING = NO
-# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the
-# todo list. This list is created by putting \todo commands in the
-# documentation.
+# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo
+# list. This list is created by putting \todo commands in the documentation.
# The default value is: YES.
GENERATE_TODOLIST = YES
-# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the
-# test list. This list is created by putting \test commands in the
-# documentation.
+# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test
+# list. This list is created by putting \test commands in the documentation.
# The default value is: YES.
GENERATE_TESTLIST = YES
-# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug
+# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug
# list. This list is created by putting \bug commands in the documentation.
# The default value is: YES.
GENERATE_BUGLIST = YES
-# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO)
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO)
# the deprecated list. This list is created by putting \deprecated commands in
# the documentation.
# The default value is: YES.
@@ -620,8 +684,8 @@ ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at
-# the bottom of the documentation of classes and structs. If set to YES the list
-# will mention the files that were used to generate the documentation.
+# the bottom of the documentation of classes and structs. If set to YES, the
+# list will mention the files that were used to generate the documentation.
# The default value is: YES.
SHOW_USED_FILES = YES
@@ -666,11 +730,10 @@ LAYOUT_FILE =
# The CITE_BIB_FILES tag can be used to specify one or more bib files containing
# the reference definitions. This must be a list of .bib files. The .bib
# extension is automatically appended if omitted. This requires the bibtex tool
-# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info.
+# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info.
# For LaTeX the style of the bibliography can be controlled using
# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the
-# search path. Do not use file names with spaces, bibtex cannot handle them. See
-# also \cite for info how to create references.
+# search path. See also \cite for info how to create references.
CITE_BIB_FILES =
@@ -686,7 +749,7 @@ CITE_BIB_FILES =
QUIET = NO
# The WARNINGS tag can be used to turn on/off the warning messages that are
-# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES
+# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES
# this implies that the warnings are on.
#
# Tip: Turn warnings on while writing the documentation.
@@ -694,7 +757,7 @@ QUIET = NO
WARNINGS = YES
-# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate
+# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate
# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag
# will automatically be disabled.
# The default value is: YES.
@@ -711,11 +774,18 @@ WARN_IF_DOC_ERROR = YES
# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that
# are documented, but have no documentation for their parameters or return
-# value. If set to NO doxygen will only warn about wrong or incomplete parameter
-# documentation, but not about the absence of documentation.
+# value. If set to NO, doxygen will only warn about wrong or incomplete
+# parameter documentation, but not about the absence of documentation. If
+# EXTRACT_ALL is set to YES then this flag will automatically be disabled.
+# The default value is: NO.
+
+WARN_NO_PARAMDOC = YES
+
+# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when
+# a warning is encountered.
# The default value is: NO.
-WARN_NO_PARAMDOC = NO
+WARN_AS_ERROR = NO
# The WARN_FORMAT tag determines the format of the warning messages that doxygen
# can produce. The string should contain the $file, $line, and $text tags, which
@@ -740,15 +810,15 @@ WARN_LOGFILE =
# The INPUT tag is used to specify the files and/or directories that contain
# documented source files. You may enter file names like myfile.cpp or
# directories like /usr/src/myproject. Separate the files or directories with
-# spaces.
+# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.
-INPUT =
+INPUT = README.md kernel/src/
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
# libiconv (or the iconv built into libc) for the transcoding. See the libiconv
-# documentation (see: http://www.gnu.org/software/libiconv) for the list of
+# documentation (see: https://www.gnu.org/software/libiconv/) for the list of
# possible encodings.
# The default value is: UTF-8.
@@ -756,14 +826,64 @@ INPUT_ENCODING = UTF-8
# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and
-# *.h) to filter out the source-files in the directories. If left blank the
-# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii,
-# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp,
-# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown,
-# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf,
-# *.qsf, *.as and *.js.
-
-FILE_PATTERNS =
+# *.h) to filter out the source-files in the directories.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# read by doxygen.
+#
+# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
+# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
+# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,
+# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08,
+# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, *.qsf and *.ice.
+
+FILE_PATTERNS = *.c \
+ *.s \
+ *.cc \
+ *.cxx \
+ *.cpp \
+ *.c++ \
+ *.java \
+ *.ii \
+ *.ixx \
+ *.ipp \
+ *.i++ \
+ *.inl \
+ *.idl \
+ *.ddl \
+ *.odl \
+ *.h \
+ *.hh \
+ *.hxx \
+ *.hpp \
+ *.h++ \
+ *.cs \
+ *.d \
+ *.php \
+ *.php4 \
+ *.php5 \
+ *.phtml \
+ *.inc \
+ *.m \
+ *.markdown \
+ *.md \
+ *.mm \
+ *.dox \
+ *.py \
+ *.pyw \
+ *.f90 \
+ *.f95 \
+ *.f03 \
+ *.f08 \
+ *.f \
+ *.for \
+ *.tcl \
+ *.vhd \
+ *.vhdl \
+ *.ucf \
+ *.qsf \
+ *.ice
# The RECURSIVE tag can be used to specify whether or not subdirectories should
# be searched for input files as well.
@@ -794,7 +914,7 @@ EXCLUDE_SYMLINKS = NO
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories for example use the pattern */test/*
-EXCLUDE_PATTERNS = */u-boot/* */toolchain/* */qemu/*
+EXCLUDE_PATTERNS =
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
# (namespaces, classes, functions, etc.) that should be excluded from the
@@ -818,7 +938,7 @@ EXAMPLE_PATH =
# *.h) to filter out the source-files in the directories. If left blank all
# files are included.
-EXAMPLE_PATTERNS =
+EXAMPLE_PATTERNS = *
# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
# searched for input files to be used with the \include or \dontinclude commands
@@ -847,6 +967,10 @@ IMAGE_PATH =
# Note that the filter must not add or remove lines; it is applied before the
# code is scanned, but not when the output code is generated. If lines are added
# or removed, the anchors will not be placed correctly.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# properly processed by doxygen.
INPUT_FILTER =
@@ -856,11 +980,15 @@ INPUT_FILTER =
# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how
# filters are used. If the FILTER_PATTERNS tag is empty or if none of the
# patterns match the file name, INPUT_FILTER is applied.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# properly processed by doxygen.
FILTER_PATTERNS =
# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
-# INPUT_FILTER ) will also be used to filter the input files that are used for
+# INPUT_FILTER) will also be used to filter the input files that are used for
# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).
# The default value is: NO.
@@ -879,7 +1007,7 @@ FILTER_SOURCE_PATTERNS =
# (index.html). This can be useful if you have a project on for instance GitHub
# and want to reuse the introduction page also for the doxygen output.
-USE_MDFILE_AS_MAINPAGE =
+USE_MDFILE_AS_MAINPAGE = README.md
#---------------------------------------------------------------------------
# Configuration options related to source browsing
@@ -892,35 +1020,35 @@ USE_MDFILE_AS_MAINPAGE =
# also VERBATIM_HEADERS is set to NO.
# The default value is: NO.
-SOURCE_BROWSER = NO
+SOURCE_BROWSER = YES
# Setting the INLINE_SOURCES tag to YES will include the body of functions,
# classes and enums directly into the documentation.
# The default value is: NO.
-INLINE_SOURCES = NO
+INLINE_SOURCES = YES
# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
# special comment blocks from generated source code fragments. Normal C, C++ and
# Fortran comments will always remain visible.
# The default value is: YES.
-STRIP_CODE_COMMENTS = YES
+STRIP_CODE_COMMENTS = NO
# If the REFERENCED_BY_RELATION tag is set to YES then for each documented
-# function all documented functions referencing it will be listed.
+# entity all documented functions referencing it will be listed.
# The default value is: NO.
-REFERENCED_BY_RELATION = NO
+REFERENCED_BY_RELATION = YES
# If the REFERENCES_RELATION tag is set to YES then for each documented function
# all documented entities called/used by that function will be listed.
# The default value is: NO.
-REFERENCES_RELATION = NO
+REFERENCES_RELATION = YES
# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set
-# to YES, then the hyperlinks from functions in REFERENCES_RELATION and
+# to YES then the hyperlinks from functions in REFERENCES_RELATION and
# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will
# link to the documentation.
# The default value is: YES.
@@ -940,12 +1068,12 @@ SOURCE_TOOLTIPS = YES
# If the USE_HTAGS tag is set to YES then the references to source code will
# point to the HTML generated by the htags(1) tool instead of doxygen built-in
# source browser. The htags tool is part of GNU's global source tagging system
-# (see http://www.gnu.org/software/global/global.html). You will need version
+# (see https://www.gnu.org/software/global/global.html). You will need version
# 4.8.6 or higher.
#
# To use it do the following:
# - Install the latest version of global
-# - Enable SOURCE_BROWSER and USE_HTAGS in the config file
+# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file
# - Make sure the INPUT points to the root of the source tree
# - Run doxygen as normal
#
@@ -997,7 +1125,7 @@ IGNORE_PREFIX =
# Configuration options related to the HTML output
#---------------------------------------------------------------------------
-# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output
+# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output
# The default value is: YES.
GENERATE_HTML = YES
@@ -1008,7 +1136,7 @@ GENERATE_HTML = YES
# The default directory is: html.
# This tag requires that the tag GENERATE_HTML is set to YES.
-HTML_OUTPUT = html
+HTML_OUTPUT = docs
# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each
# generated HTML page (for example: .htm, .php, .asp).
@@ -1035,7 +1163,7 @@ HTML_FILE_EXTENSION = .html
# of the possible markers and block names see the documentation.
# This tag requires that the tag GENERATE_HTML is set to YES.
-HTML_HEADER =
+HTML_HEADER = "doxygen_styles/html_header.html"
# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each
# generated HTML page. If the tag is left blank doxygen will generate a standard
@@ -1045,7 +1173,7 @@ HTML_HEADER =
# that doxygen normally uses.
# This tag requires that the tag GENERATE_HTML is set to YES.
-HTML_FOOTER =
+HTML_FOOTER = "doxygen_styles/html_footer.html"
# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style
# sheet that is used by each HTML page. It can be used to fine-tune the look of
@@ -1059,16 +1187,19 @@ HTML_FOOTER =
HTML_STYLESHEET =
-# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional user-
-# defined cascading style sheet that is included after the standard style sheets
+# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined
+# cascading style sheets that are included after the standard style sheets
# created by doxygen. Using this option one can overrule certain style aspects.
# This is preferred over using HTML_STYLESHEET since it does not replace the
-# standard style sheet and is therefor more robust against future updates.
-# Doxygen will copy the style sheet file to the output directory. For an example
-# see the documentation.
+# standard style sheet and is therefore more robust against future updates.
+# Doxygen will copy the style sheet files to the output directory.
+# Note: The order of the extra style sheet files is of importance (e.g. the last
+# style sheet in the list overrules the setting of the previous ones in the
+# list). For an example see the documentation.
# This tag requires that the tag GENERATE_HTML is set to YES.
-HTML_EXTRA_STYLESHEET =
+HTML_EXTRA_STYLESHEET = "doxygen_styles/custom.css" \
+ "doxygen_styles/custom_dark_theme.css"
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
# other source files which should be copied to the HTML output directory. Note
@@ -1081,9 +1212,9 @@ HTML_EXTRA_STYLESHEET =
HTML_EXTRA_FILES =
# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen
-# will adjust the colors in the stylesheet and background images according to
+# will adjust the colors in the style sheet and background images according to
# this color. Hue is specified as an angle on a colorwheel, see
-# http://en.wikipedia.org/wiki/Hue for more information. For instance the value
+# https://en.wikipedia.org/wiki/Hue for more information. For instance the value
# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300
# purple, and 360 is red again.
# Minimum value: 0, maximum value: 359, default value: 220.
@@ -1112,19 +1243,31 @@ HTML_COLORSTYLE_GAMMA = 80
# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
# page will contain the date and time when the page was generated. Setting this
-# to NO can help when comparing the output of multiple runs.
-# The default value is: YES.
+# to YES can help to show when doxygen was last run and thus if the
+# documentation is up to date.
+# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.
HTML_TIMESTAMP = YES
+# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML
+# documentation will contain a main index with vertical navigation menus that
+# are dynamically created via Javascript. If disabled, the navigation index will
+# consists of multiple levels of tabs that are statically embedded in every HTML
+# page. Disable this option to support browsers that do not have Javascript,
+# like the Qt help browser.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_DYNAMIC_MENUS = YES
+
# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
# documentation will contain sections that can be hidden and shown after the
# page has loaded.
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.
-HTML_DYNAMIC_SECTIONS = NO
+HTML_DYNAMIC_SECTIONS = YES
# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries
# shown in the various tree structured indices initially; the user can expand
@@ -1141,13 +1284,13 @@ HTML_INDEX_NUM_ENTRIES = 100
# If the GENERATE_DOCSET tag is set to YES, additional index files will be
# generated that can be used as input for Apple's Xcode 3 integrated development
-# environment (see: http://developer.apple.com/tools/xcode/), introduced with
-# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a
+# environment (see: https://developer.apple.com/xcode/), introduced with OSX
+# 10.5 (Leopard). To create a documentation set, doxygen will generate a
# Makefile in the HTML output directory. Running make will produce the docset in
# that directory and running make install will install the docset in
# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
-# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html
-# for more information.
+# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy
+# genXcode/_index.html for more information.
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.
@@ -1186,7 +1329,7 @@ DOCSET_PUBLISHER_NAME = Publisher
# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three
# additional HTML index files: index.hhp, index.hhc, and index.hhk. The
# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop
-# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on
+# (see: https://www.microsoft.com/en-us/download/details.aspx?id=21138) on
# Windows.
#
# The HTML Help Workshop contains a compiler that can convert all HTML output
@@ -1209,28 +1352,29 @@ GENERATE_HTMLHELP = NO
CHM_FILE =
# The HHC_LOCATION tag can be used to specify the location (absolute path
-# including file name) of the HTML help compiler ( hhc.exe). If non-empty
+# including file name) of the HTML help compiler (hhc.exe). If non-empty,
# doxygen will try to run the HTML help compiler on the generated index.hhp.
# The file has to be specified with full path.
# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
HHC_LOCATION =
-# The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# The GENERATE_CHI flag controls if a separate .chi index file is generated
+# (YES) or that it should be included in the master .chm file (NO).
# The default value is: NO.
# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
GENERATE_CHI = NO
-# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc)
+# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc)
# and project file content.
# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
CHM_INDEX_ENCODING =
-# The BINARY_TOC flag controls whether a binary table of contents is generated (
-# YES) or a normal table of contents ( NO) in the .chm file.
+# The BINARY_TOC flag controls whether a binary table of contents is generated
+# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it
+# enables the Previous and Next buttons.
# The default value is: NO.
# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
@@ -1261,7 +1405,7 @@ QCH_FILE =
# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
# Project output. For more information please see Qt Help Project / Namespace
-# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace).
+# (see: http://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace).
# The default value is: org.doxygen.Project.
# This tag requires that the tag GENERATE_QHP is set to YES.
@@ -1269,7 +1413,7 @@ QHP_NAMESPACE = org.doxygen.Project
# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt
# Help Project output. For more information please see Qt Help Project / Virtual
-# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual-
+# Folders (see: http://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-
# folders).
# The default value is: doc.
# This tag requires that the tag GENERATE_QHP is set to YES.
@@ -1278,7 +1422,7 @@ QHP_VIRTUAL_FOLDER = doc
# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom
# filter to add. For more information please see Qt Help Project / Custom
-# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-
+# Filters (see: http://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-
# filters).
# This tag requires that the tag GENERATE_QHP is set to YES.
@@ -1286,7 +1430,7 @@ QHP_CUST_FILTER_NAME =
# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the
# custom filter to add. For more information please see Qt Help Project / Custom
-# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-
+# Filters (see: http://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-
# filters).
# This tag requires that the tag GENERATE_QHP is set to YES.
@@ -1294,7 +1438,7 @@ QHP_CUST_FILTER_ATTRS =
# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
# project's filter section matches. Qt Help Project / Filter Attributes (see:
-# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes).
+# http://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes).
# This tag requires that the tag GENERATE_QHP is set to YES.
QHP_SECT_FILTER_ATTRS =
@@ -1343,7 +1487,7 @@ DISABLE_INDEX = NO
# index structure (just like the one that is generated for HTML Help). For this
# to work a browser that supports JavaScript, DHTML, CSS and frames is required
# (i.e. any modern browser). Windows users are probably better off using the
-# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can
+# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can
# further fine-tune the look of the index. As an example, the default style
# sheet generated by doxygen has an example that shows how to put an image at
# the root of the tree instead of the PROJECT_NAME. Since the tree basically has
@@ -1352,7 +1496,7 @@ DISABLE_INDEX = NO
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.
-GENERATE_TREEVIEW = NO
+GENERATE_TREEVIEW = YES
# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
# doxygen will group on one line in the generated HTML documentation.
@@ -1369,9 +1513,9 @@ ENUM_VALUES_PER_LINE = 4
# Minimum value: 0, maximum value: 1500, default value: 250.
# This tag requires that the tag GENERATE_HTML is set to YES.
-TREEVIEW_WIDTH = 250
+TREEVIEW_WIDTH = 350
-# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to
+# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to
# external symbols imported via tag files in a separate window.
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.
@@ -1387,7 +1531,7 @@ EXT_LINKS_IN_WINDOW = NO
FORMULA_FONTSIZE = 10
-# Use the FORMULA_TRANPARENT tag to determine whether or not the images
+# Use the FORMULA_TRANSPARENT tag to determine whether or not the images
# generated for formulas are transparent PNGs. Transparent PNGs are not
# supported properly for IE 6.0, but are supported on all modern browsers.
#
@@ -1399,8 +1543,8 @@ FORMULA_FONTSIZE = 10
FORMULA_TRANSPARENT = YES
# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see
-# http://www.mathjax.org) which uses client side Javascript for the rendering
-# instead of using prerendered bitmaps. Use this if you do not have LaTeX
+# https://www.mathjax.org) which uses client side Javascript for the rendering
+# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX
# installed or if you want to formulas look prettier in the HTML output. When
# enabled you may also need to install MathJax separately and configure the path
# to it using the MATHJAX_RELPATH option.
@@ -1426,11 +1570,11 @@ MATHJAX_FORMAT = HTML-CSS
# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax
# Content Delivery Network so you can quickly see the result without installing
# MathJax. However, it is strongly recommended to install a local copy of
-# MathJax from http://www.mathjax.org before deployment.
-# The default value is: http://cdn.mathjax.org/mathjax/latest.
+# MathJax from https://www.mathjax.org before deployment.
+# The default value is: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/.
# This tag requires that the tag USE_MATHJAX is set to YES.
-MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+MATHJAX_RELPATH = https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/
# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax
# extension names that should be enabled during MathJax rendering. For example
@@ -1470,11 +1614,11 @@ SEARCHENGINE = YES
# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
# implemented using a web server instead of a web client using Javascript. There
-# are two flavours of web server based searching depending on the
-# EXTERNAL_SEARCH setting. When disabled, doxygen will generate a PHP script for
-# searching and an index file used by the script. When EXTERNAL_SEARCH is
-# enabled the indexing and searching needs to be provided by external tools. See
-# the section "External Indexing and Searching" for details.
+# are two flavors of web server based searching depending on the EXTERNAL_SEARCH
+# setting. When disabled, doxygen will generate a PHP script for searching and
+# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing
+# and searching needs to be provided by external tools. See the section
+# "External Indexing and Searching" for details.
# The default value is: NO.
# This tag requires that the tag SEARCHENGINE is set to YES.
@@ -1486,9 +1630,9 @@ SERVER_BASED_SEARCH = NO
# external search engine pointed to by the SEARCHENGINE_URL option to obtain the
# search results.
#
-# Doxygen ships with an example indexer ( doxyindexer) and search engine
+# Doxygen ships with an example indexer (doxyindexer) and search engine
# (doxysearch.cgi) which are based on the open source search engine library
-# Xapian (see: http://xapian.org/).
+# Xapian (see: https://xapian.org/).
#
# See the section "External Indexing and Searching" for details.
# The default value is: NO.
@@ -1499,9 +1643,9 @@ EXTERNAL_SEARCH = NO
# The SEARCHENGINE_URL should point to a search engine hosted by a web server
# which will return the search results when EXTERNAL_SEARCH is enabled.
#
-# Doxygen ships with an example indexer ( doxyindexer) and search engine
+# Doxygen ships with an example indexer (doxyindexer) and search engine
# (doxysearch.cgi) which are based on the open source search engine library
-# Xapian (see: http://xapian.org/). See the section "External Indexing and
+# Xapian (see: https://xapian.org/). See the section "External Indexing and
# Searching" for details.
# This tag requires that the tag SEARCHENGINE is set to YES.
@@ -1537,10 +1681,10 @@ EXTRA_SEARCH_MAPPINGS =
# Configuration options related to the LaTeX output
#---------------------------------------------------------------------------
-# If the GENERATE_LATEX tag is set to YES doxygen will generate LaTeX output.
+# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.
# The default value is: YES.
-GENERATE_LATEX = YES
+GENERATE_LATEX = NO
# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
@@ -1553,22 +1697,35 @@ LATEX_OUTPUT = latex
# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
# invoked.
#
-# Note that when enabling USE_PDFLATEX this option is only used for generating
-# bitmaps for formulas in the HTML output, but not in the Makefile that is
-# written to the output directory.
-# The default file is: latex.
+# Note that when not enabling USE_PDFLATEX the default is latex when enabling
+# USE_PDFLATEX the default is pdflatex and when in the later case latex is
+# chosen this is overwritten by pdflatex. For specific output languages the
+# default can have been set differently, this depends on the implementation of
+# the output language.
# This tag requires that the tag GENERATE_LATEX is set to YES.
-LATEX_CMD_NAME = latex
+LATEX_CMD_NAME =
# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate
# index for LaTeX.
+# Note: This tag is used in the Makefile / make.bat.
+# See also: LATEX_MAKEINDEX_CMD for the part in the generated output file
+# (.tex).
# The default file is: makeindex.
# This tag requires that the tag GENERATE_LATEX is set to YES.
MAKEINDEX_CMD_NAME = makeindex
-# If the COMPACT_LATEX tag is set to YES doxygen generates more compact LaTeX
+# The LATEX_MAKEINDEX_CMD tag can be used to specify the command name to
+# generate index for LaTeX.
+# Note: This tag is used in the generated output file (.tex).
+# See also: MAKEINDEX_CMD_NAME for the part in the Makefile / make.bat.
+# The default value is: \makeindex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_MAKEINDEX_CMD = \makeindex
+
+# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX
# documents. This may be useful for small projects and may help to save some
# trees in general.
# The default value is: NO.
@@ -1586,9 +1743,12 @@ COMPACT_LATEX = NO
PAPER_TYPE = a4
# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names
-# that should be included in the LaTeX output. To get the times font for
-# instance you can specify
-# EXTRA_PACKAGES=times
+# that should be included in the LaTeX output. The package can be specified just
+# by its name or with the correct syntax as to be used with the LaTeX
+# \usepackage command. To get the times font for instance you can specify :
+# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times}
+# To use the option intlimits with the amsmath package you can specify:
+# EXTRA_PACKAGES=[intlimits]{amsmath}
# If left blank no extra packages will be included.
# This tag requires that the tag GENERATE_LATEX is set to YES.
@@ -1602,23 +1762,36 @@ EXTRA_PACKAGES =
#
# Note: Only use a user-defined header if you know what you are doing! The
# following commands have a special meaning inside the header: $title,
-# $datetime, $date, $doxygenversion, $projectname, $projectnumber. Doxygen will
-# replace them by respectively the title of the page, the current date and time,
-# only the current date, the version number of doxygen, the project name (see
-# PROJECT_NAME), or the project number (see PROJECT_NUMBER).
+# $datetime, $date, $doxygenversion, $projectname, $projectnumber,
+# $projectbrief, $projectlogo. Doxygen will replace $title with the empty
+# string, for the replacement values of the other commands the user is referred
+# to HTML_HEADER.
# This tag requires that the tag GENERATE_LATEX is set to YES.
LATEX_HEADER =
# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the
# generated LaTeX document. The footer should contain everything after the last
-# chapter. If it is left blank doxygen will generate a standard footer.
+# chapter. If it is left blank doxygen will generate a standard footer. See
+# LATEX_HEADER for more information on how to generate a default footer and what
+# special commands can be used inside the footer.
#
# Note: Only use a user-defined footer if you know what you are doing!
# This tag requires that the tag GENERATE_LATEX is set to YES.
LATEX_FOOTER =
+# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined
+# LaTeX style sheets that are included after the standard style sheets created
+# by doxygen. Using this option one can overrule certain style aspects. Doxygen
+# will copy the style sheet files to the output directory.
+# Note: The order of the extra style sheet files is of importance (e.g. the last
+# style sheet in the list overrules the setting of the previous ones in the
+# list).
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EXTRA_STYLESHEET =
+
# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or
# other source files which should be copied to the LATEX_OUTPUT output
# directory. Note that the files will be copied as-is; there are no commands or
@@ -1636,8 +1809,8 @@ LATEX_EXTRA_FILES =
PDF_HYPERLINKS = YES
-# If the LATEX_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
-# the PDF file directly from the LaTeX files. Set this option to YES to get a
+# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
+# the PDF file directly from the LaTeX files. Set this option to YES, to get a
# higher quality PDF documentation.
# The default value is: YES.
# This tag requires that the tag GENERATE_LATEX is set to YES.
@@ -1672,17 +1845,33 @@ LATEX_SOURCE_CODE = NO
# The LATEX_BIB_STYLE tag can be used to specify the style to use for the
# bibliography, e.g. plainnat, or ieeetr. See
-# http://en.wikipedia.org/wiki/BibTeX and \cite for more info.
+# https://en.wikipedia.org/wiki/BibTeX and \cite for more info.
# The default value is: plain.
# This tag requires that the tag GENERATE_LATEX is set to YES.
LATEX_BIB_STYLE = plain
+# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated
+# page will contain the date and time when the page was generated. Setting this
+# to NO can help when comparing the output of multiple runs.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_TIMESTAMP = NO
+
+# The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute)
+# path from which the emoji images will be read. If a relative path is entered,
+# it will be relative to the LATEX_OUTPUT directory. If left blank the
+# LATEX_OUTPUT directory will be used.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EMOJI_DIRECTORY =
+
#---------------------------------------------------------------------------
# Configuration options related to the RTF output
#---------------------------------------------------------------------------
-# If the GENERATE_RTF tag is set to YES doxygen will generate RTF output. The
+# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The
# RTF output is optimized for Word 97 and may not look too pretty with other RTF
# readers/editors.
# The default value is: NO.
@@ -1697,7 +1886,7 @@ GENERATE_RTF = NO
RTF_OUTPUT = rtf
-# If the COMPACT_RTF tag is set to YES doxygen generates more compact RTF
+# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF
# documents. This may be useful for small projects and may help to save some
# trees in general.
# The default value is: NO.
@@ -1717,9 +1906,9 @@ COMPACT_RTF = NO
RTF_HYPERLINKS = NO
-# Load stylesheet definitions from file. Syntax is similar to doxygen's config
-# file, i.e. a series of assignments. You only have to provide replacements,
-# missing definitions are set to their default value.
+# Load stylesheet definitions from file. Syntax is similar to doxygen's
+# configuration file, i.e. a series of assignments. You only have to provide
+# replacements, missing definitions are set to their default value.
#
# See also section "Doxygen usage" for information on how to generate the
# default style sheet that doxygen normally uses.
@@ -1728,17 +1917,27 @@ RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
# Set optional variables used in the generation of an RTF document. Syntax is
-# similar to doxygen's config file. A template extensions file can be generated
-# using doxygen -e rtf extensionFile.
+# similar to doxygen's configuration file. A template extensions file can be
+# generated using doxygen -e rtf extensionFile.
# This tag requires that the tag GENERATE_RTF is set to YES.
RTF_EXTENSIONS_FILE =
+# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code
+# with syntax highlighting in the RTF output.
+#
+# Note that which sources are shown also depends on other settings such as
+# SOURCE_BROWSER.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_SOURCE_CODE = NO
+
#---------------------------------------------------------------------------
# Configuration options related to the man page output
#---------------------------------------------------------------------------
-# If the GENERATE_MAN tag is set to YES doxygen will generate man pages for
+# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for
# classes and files.
# The default value is: NO.
@@ -1762,6 +1961,13 @@ MAN_OUTPUT = man
MAN_EXTENSION = .3
+# The MAN_SUBDIR tag determines the name of the directory created within
+# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by
+# MAN_EXTENSION with the initial . removed.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_SUBDIR =
+
# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it
# will generate one additional man file for each entity documented in the real
# man page(s). These additional files only source the real man page, but without
@@ -1775,7 +1981,7 @@ MAN_LINKS = NO
# Configuration options related to the XML output
#---------------------------------------------------------------------------
-# If the GENERATE_XML tag is set to YES doxygen will generate an XML file that
+# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that
# captures the structure of the code including all documentation.
# The default value is: NO.
@@ -1789,19 +1995,7 @@ GENERATE_XML = NO
XML_OUTPUT = xml
-# The XML_SCHEMA tag can be used to specify a XML schema, which can be used by a
-# validating XML parser to check the syntax of the XML files.
-# This tag requires that the tag GENERATE_XML is set to YES.
-
-XML_SCHEMA =
-
-# The XML_DTD tag can be used to specify a XML DTD, which can be used by a
-# validating XML parser to check the syntax of the XML files.
-# This tag requires that the tag GENERATE_XML is set to YES.
-
-XML_DTD =
-
-# If the XML_PROGRAMLISTING tag is set to YES doxygen will dump the program
+# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program
# listings (including syntax highlighting and cross-referencing information) to
# the XML output. Note that enabling this will significantly increase the size
# of the XML output.
@@ -1810,11 +2004,18 @@ XML_DTD =
XML_PROGRAMLISTING = YES
+# If the XML_NS_MEMB_FILE_SCOPE tag is set to YES, doxygen will include
+# namespace members in file scope as well, matching the HTML output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
+XML_NS_MEMB_FILE_SCOPE = NO
+
#---------------------------------------------------------------------------
# Configuration options related to the DOCBOOK output
#---------------------------------------------------------------------------
-# If the GENERATE_DOCBOOK tag is set to YES doxygen will generate Docbook files
+# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files
# that can be used to generate PDF.
# The default value is: NO.
@@ -1828,14 +2029,23 @@ GENERATE_DOCBOOK = NO
DOCBOOK_OUTPUT = docbook
+# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the
+# program listings (including syntax highlighting and cross-referencing
+# information) to the DOCBOOK output. Note that enabling this will significantly
+# increase the size of the DOCBOOK output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
+
+DOCBOOK_PROGRAMLISTING = NO
+
#---------------------------------------------------------------------------
# Configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
-# If the GENERATE_AUTOGEN_DEF tag is set to YES doxygen will generate an AutoGen
-# Definitions (see http://autogen.sf.net) file that captures the structure of
-# the code including all documentation. Note that this feature is still
-# experimental and incomplete at the moment.
+# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an
+# AutoGen Definitions (see http://autogen.sourceforge.net/) file that captures
+# the structure of the code including all documentation. Note that this feature
+# is still experimental and incomplete at the moment.
# The default value is: NO.
GENERATE_AUTOGEN_DEF = NO
@@ -1844,7 +2054,7 @@ GENERATE_AUTOGEN_DEF = NO
# Configuration options related to the Perl module output
#---------------------------------------------------------------------------
-# If the GENERATE_PERLMOD tag is set to YES doxygen will generate a Perl module
+# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module
# file that captures the structure of the code including all documentation.
#
# Note that this feature is still experimental and incomplete at the moment.
@@ -1852,7 +2062,7 @@ GENERATE_AUTOGEN_DEF = NO
GENERATE_PERLMOD = NO
-# If the PERLMOD_LATEX tag is set to YES doxygen will generate the necessary
+# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary
# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI
# output from the Perl module output.
# The default value is: NO.
@@ -1860,9 +2070,9 @@ GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
-# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be nicely
+# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely
# formatted so it can be parsed by a human reader. This is useful if you want to
-# understand what is going on. On the other hand, if this tag is set to NO the
+# understand what is going on. On the other hand, if this tag is set to NO, the
# size of the Perl module output will be much smaller and Perl will parse it
# just the same.
# The default value is: YES.
@@ -1882,14 +2092,14 @@ PERLMOD_MAKEVAR_PREFIX =
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
-# If the ENABLE_PREPROCESSING tag is set to YES doxygen will evaluate all
+# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all
# C-preprocessor directives found in the sources and include files.
# The default value is: YES.
ENABLE_PREPROCESSING = YES
-# If the MACRO_EXPANSION tag is set to YES doxygen will expand all macro names
-# in the source code. If set to NO only conditional compilation will be
+# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
+# in the source code. If set to NO, only conditional compilation will be
# performed. Macro expansion can be done in a controlled way by setting
# EXPAND_ONLY_PREDEF to YES.
# The default value is: NO.
@@ -1905,7 +2115,7 @@ MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
-# If the SEARCH_INCLUDES tag is set to YES the includes files in the
+# If the SEARCH_INCLUDES tag is set to YES, the include files in the
# INCLUDE_PATH will be searched if a #include is found.
# The default value is: YES.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
@@ -1947,9 +2157,9 @@ PREDEFINED =
EXPAND_AS_DEFINED =
# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
-# remove all refrences to function-like macros that are alone on a line, have an
-# all uppercase name, and do not end with a semicolon. Such function macros are
-# typically used for boiler-plate code, and will confuse the parser if not
+# remove all references to function-like macros that are alone on a line, have
+# an all uppercase name, and do not end with a semicolon. Such function macros
+# are typically used for boiler-plate code, and will confuse the parser if not
# removed.
# The default value is: YES.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
@@ -1969,7 +2179,7 @@ SKIP_FUNCTION_MACROS = YES
# where loc1 and loc2 can be relative or absolute paths or URLs. See the
# section "Linking to external documentation" for more information about the use
# of tag files.
-# Note: Each tag file must have an unique name (where the name does NOT include
+# Note: Each tag file must have a unique name (where the name does NOT include
# the path). If a tag file is not located in the directory in which doxygen is
# run, you must also specify the path to the tagfile here.
@@ -1981,20 +2191,21 @@ TAGFILES =
GENERATE_TAGFILE =
-# If the ALLEXTERNALS tag is set to YES all external class will be listed in the
-# class index. If set to NO only the inherited external classes will be listed.
+# If the ALLEXTERNALS tag is set to YES, all external class will be listed in
+# the class index. If set to NO, only the inherited external classes will be
+# listed.
# The default value is: NO.
ALLEXTERNALS = NO
-# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed in
-# the modules index. If set to NO, only the current project's groups will be
+# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will be
# listed.
# The default value is: YES.
EXTERNAL_GROUPS = YES
-# If the EXTERNAL_PAGES tag is set to YES all external pages will be listed in
+# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in
# the related pages index. If set to NO, only the current project's pages will
# be listed.
# The default value is: YES.
@@ -2011,7 +2222,7 @@ PERL_PATH = /usr/bin/perl
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
-# If the CLASS_DIAGRAMS tag is set to YES doxygen will generate a class diagram
+# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram
# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to
# NO turns the diagrams off. Note that this option also works with HAVE_DOT
# disabled, but it is recommended to install and use dot, since it yields more
@@ -2036,7 +2247,7 @@ MSCGEN_PATH =
DIA_PATH =
-# If set to YES, the inheritance and collaboration graphs will hide inheritance
+# If set to YES the inheritance and collaboration graphs will hide inheritance
# and usage relations if the target is undocumented or is not a class.
# The default value is: YES.
@@ -2049,7 +2260,7 @@ HIDE_UNDOC_RELATIONS = YES
# set to NO
# The default value is: NO.
-HAVE_DOT = NO
+HAVE_DOT = YES
# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
# to run in parallel. When set to 0 doxygen will base this on the number of
@@ -2061,7 +2272,7 @@ HAVE_DOT = NO
DOT_NUM_THREADS = 0
-# When you want a differently looking font n the dot files that doxygen
+# When you want a differently looking font in the dot files that doxygen
# generates you can specify the font name using DOT_FONTNAME. You need to make
# sure dot is able to find the font, which can be done by putting it in a
# standard location or by setting the DOTFONTPATH environment variable or by
@@ -2109,13 +2320,13 @@ COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
-# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
+# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and
# collaboration diagrams in a style similar to the OMG's Unified Modeling
# Language.
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.
-UML_LOOK = NO
+UML_LOOK = YES
# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
# class node. If there are many fields or methods and many nodes the graph may
@@ -2161,22 +2372,24 @@ INCLUDED_BY_GRAPH = YES
#
# Note that enabling this option will significantly increase the time of a run.
# So in most cases it will be better to enable call graphs for selected
-# functions only using the \callgraph command.
+# functions only using the \callgraph command. Disabling a call graph can be
+# accomplished by means of the command \hidecallgraph.
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.
-CALL_GRAPH = NO
+CALL_GRAPH = YES
# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
# dependency graph for every global function or class method.
#
# Note that enabling this option will significantly increase the time of a run.
# So in most cases it will be better to enable caller graphs for selected
-# functions only using the \callergraph command.
+# functions only using the \callergraph command. Disabling a caller graph can be
+# accomplished by means of the command \hidecallergraph.
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.
-CALLER_GRAPH = NO
+CALLER_GRAPH = YES
# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
# hierarchy of all classes instead of a textual one.
@@ -2195,15 +2408,19 @@ GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
-# generated by dot.
+# generated by dot. For an explanation of the image formats see the section
+# output formats in the documentation of the dot tool (Graphviz (see:
+# http://www.graphviz.org/)).
# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order
# to make the SVG files visible in IE 9+ (other browsers do not have this
# requirement).
-# Possible values are: png, jpg, gif and svg.
+# Possible values are: png, jpg, gif, svg, png:gd, png:gd:gd, png:cairo,
+# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and
+# png:gdiplus:gdiplus.
# The default value is: png.
# This tag requires that the tag HAVE_DOT is set to YES.
-DOT_IMAGE_FORMAT = png
+DOT_IMAGE_FORMAT = svg
# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
# enable generation of interactive SVG images that allow zooming and panning.
@@ -2215,7 +2432,7 @@ DOT_IMAGE_FORMAT = png
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.
-INTERACTIVE_SVG = NO
+INTERACTIVE_SVG = YES
# The DOT_PATH tag can be used to specify the path where the dot tool can be
# found. If left blank, it is assumed the dot tool can be found in the path.
@@ -2242,6 +2459,24 @@ MSCFILE_DIRS =
DIAFILE_DIRS =
+# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the
+# path where java can find the plantuml.jar file. If left blank, it is assumed
+# PlantUML is not used or called during a preprocessing step. Doxygen will
+# generate a warning when it encounters a \startuml command in this case and
+# will not generate output for the diagram.
+
+PLANTUML_JAR_PATH =
+
+# When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a
+# configuration file for plantuml.
+
+PLANTUML_CFG_FILE =
+
+# When using plantuml, the specified paths are searched for files specified by
+# the !include statement in a plantuml block.
+
+PLANTUML_INCLUDE_PATH =
+
# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes
# that will be shown in the graph. If the number of nodes in a graph becomes
# larger than this value, doxygen will truncate the graph, which is visualized
@@ -2278,7 +2513,7 @@ MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = NO
-# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
+# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output
# files in one run (i.e. multiple -o and -T options on the command line). This
# makes dot run faster, but since only newer versions of dot (>1.8.10) support
# this, this feature is disabled by default.
@@ -2295,7 +2530,7 @@ DOT_MULTI_TARGETS = YES
GENERATE_LEGEND = YES
-# If the DOT_CLEANUP tag is set to YES doxygen will remove the intermediate dot
+# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot
# files that are used to generate the various graphs.
# The default value is: YES.
# This tag requires that the tag HAVE_DOT is set to YES.
diff --git a/project/cross_gcc.build b/project/cross_gcc.build
new file mode 100644
index 00000000..bf7d57d8
--- /dev/null
+++ b/project/cross_gcc.build
@@ -0,0 +1,38 @@
+[binaries]
+c = 'arm-none-eabi-gcc'
+ld = 'arm-none-eabi-gcc'
+as = 'arm-none-eabi-as'
+objcopy = 'arm-none-eabi-objcopy'
+gdb = 'arm-none-eabi-gdb'
+
+[properties]
+c_args = ['-pipe', '-std=gnu99', '-ffreestanding', '-Wall',
+ '-Werror',
+ '-Wno-error=unused-function',
+ '-Wno-error=unused-label',
+ '-Wno-error=unused-parameter',
+ '-Wno-error=unused-variable',
+ '-Wno-error=unused-value',
+ '-Wno-error=unused-local-typedefs',
+ '-g', '-O0', '-mtune=arm1176jzf-s',
+ '-march=armv6zk', '-mfpu=vfp', '-fpic', '-mcpu=arm1176jz-s']
+
+c_link_args = ['-fcommon',
+ '-nostartfiles',
+ '-nolibc',
+ '-Wl,-Map,kernel.map',
+ '-T',
+ '../linker/kernel.ld']
+
+
+[target_machine]
+system = 'none'
+cpu_family = 'arm'
+cpu = 'cortex-a7'
+endian = 'little'
+
+[host_machine]
+system = 'none'
+cpu_family = 'arm'
+cpu = 'cortex-a7'
+endian = 'little'
diff --git a/kernel/vm/fastlz/LICENSE b/project/doxygen_styles/LICENSE
similarity index 76%
rename from kernel/vm/fastlz/LICENSE
rename to project/doxygen_styles/LICENSE
index 4a6abd6a..f671611b 100644
--- a/kernel/vm/fastlz/LICENSE
+++ b/project/doxygen_styles/LICENSE
@@ -1,8 +1,8 @@
-FastLZ - lightning-fast lossless compression library
+License for the doxygen styles:
+---
+MIT License
-Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
-Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
-Copyright (C) 2005 Ariya Hidayat (ariya@kde.org)
+Copyright (c) 2019 Tilen Majerle
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -11,14 +11,14 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/project/doxygen_styles/custom.css b/project/doxygen_styles/custom.css
new file mode 100644
index 00000000..ac39ccba
--- /dev/null
+++ b/project/doxygen_styles/custom.css
@@ -0,0 +1,338 @@
+div.fragment, pre.fragment {
+ margin: 0;
+ padding: 4px;
+}
+
+/*********************************************/
+/** Main content **/
+/*********************************************/
+.contents {
+ margin: 10px auto !important;
+ padding: 0 10px;
+ max-width: 1200px;
+}
+
+/*********************************************/
+/** Inline code **/
+/*********************************************/
+p code,
+li code,
+td code,
+dd code {
+ display: inline;
+ padding: 0px 6px;
+ -webkit-border-radius: 4px;
+ -moz-border-radius: 4px;
+ border-radius: 4px;
+
+ background-color: #CCCCCC;
+ border: 1px solid #333333;
+
+ color: #333333;
+}
+
+/*********************************************/
+/** Table of Contents (ToC) **/
+/*********************************************/
+div.toc {
+ margin: 0 !important;
+ border-radius: 4px !important;
+}
+
+div.toc h3 {
+ font-size: 150%;
+ color: inherit;
+}
+
+/*********************************************/
+/** Content table **/
+/*********************************************/
+.contents table.doxtable {
+ margin: 0 auto;
+}
+
+/*********************************************/
+/** Field table **/
+/*********************************************/
+.fieldtable {
+ box-shadow: none !important;
+ -webkit-box-shadow: none;
+ -moz-box-shadow: none;
+}
+
+/*********************************************/
+/** Memitem and memtitle **/
+/*********************************************/
+.memitem,
+.memproto,
+.memdoc {
+ box-shadow: none;
+ -webkit-box-shadow: none;
+ -moz-box-shadow: none;
+ background-image: none;
+}
+
+/*********************************************/
+/** TOP navigation **/
+/*********************************************/
+.tablist a:hover,
+.tablist li.current a {
+ text-shadow: none;
+ -moz-text-shadow: none;
+ -webkit-text-shadow: none;
+}
+
+/*********************************************/
+/** H1 in textblocks **/
+/*********************************************/
+.textblock h1 {
+ border-bottom: 1px solid #32363d;
+ border-left: 3px solid #32363d;
+ margin: 40px 0px 10px 0px;
+ padding-bottom: 10px;
+ padding-top: 10px;
+ padding-left: 5px;
+}
+
+.textblock h1:first-child {
+ margin-top: 10px;
+}
+
+/*********************************************/
+/** Note, warning **/
+/*********************************************/
+dl.note,
+dl.warning,
+dl.todo,
+dl.deprecated,
+dl.reflist {
+ border: 0;
+ padding: 0px;
+ margin: 4px 0px 4px 0px;
+ border-radius: 4px;
+}
+
+dl.note dt,
+dl.warning dt,
+dl.todo dt,
+dl.deprecated dt,
+dl.reflist dt {
+ margin: 0;
+ font-size: 14px;
+ padding: 2px 4px;
+
+ border: none;
+ border-top-left-radius: 0px;
+ border-top-right-radius:0px;
+
+ font-weight: bold;
+ text-transform: uppercase;
+ color: #FFFFFF !important;
+
+ box-shadow: none;
+ -webkit-box-shadow: none;
+ -moz-box-shadow: none;
+ text-shadow: none;
+}
+
+dl.note dd,
+dl.warning dd,
+dl.todo dd,
+dl.deprecated dd,
+dl.reflist dd {
+ margin: 0;
+ padding: 4px;
+ background: none;
+
+ color: #222222;
+
+ border: 1px solid;
+ border-bottom-left-radius: 0px;
+ border-bottom-right-radius: 0px;
+ border-top: none;
+
+ box-shadow: none;
+ -webkit-box-shadow: none;
+ -moz-box-shadow: none;
+ text-shadow: none;
+}
+
+dl.reflist dd {
+ margin-bottom: 15px;
+}
+
+/* Background colors */
+dl.note {}
+dl.warning {}
+dl.todo {}
+dl.deprecated {}
+dl.reflist {}
+
+/* Header */
+dl.note dt {
+ background-color: #cbc693;
+}
+
+dl.warning dt {
+ background-color: #bf5f82;
+}
+
+dl.todo dt {
+ background-color: #82b3c9;
+}
+
+dl.deprecated dt {
+ background-color: #af8eb5;
+}
+
+dl.reflist dt {
+ background-color: #cbae82;
+}
+
+/* Content */
+dl.note dd {
+ background-color: #fff9c4;
+ border-color: #cbc693;
+}
+
+dl.warning dd {
+ background-color: #f48fb1;
+ border-color: #bf5f82;
+}
+
+dl.todo dd {
+ background-color: #b3e5fc;
+ border-color: #82b3c9;
+}
+
+dl.deprecated dd {
+ background-color: #e1bee7;
+ border-color: #af8eb5;
+}
+
+dl.reflist dd {
+ background-color: #ffe0b2;
+ border-color: #cbae82;
+}
+
+/*********************************************/
+/** Reference list **/
+/**Similar to warning/note/todo/... messages**/
+/*********************************************/
+dl.reflist {
+
+}
+
+/*********************************************/
+/** Note, warning **/
+/*********************************************/
+#docs_list {
+ padding: 0 10px;
+}
+
+#docs_list ul {
+ margin: 0;
+ padding: 0;
+ list-style: none;
+}
+
+#docs_list ul li {
+ display: inline-block;
+ border-right: 1px solid #BFBFBF;
+}
+
+#docs_list ul li:last-child {
+ border-right: none;
+}
+
+#docs_list ul li a {
+ display: block;
+ padding: 8px 13px;
+ font-weight: bold;
+ font-size: 15px;
+}
+
+#docs_list ul li a:hover,
+#docs_list ul li a.docs_current {
+ text-decoration: underline;
+}
+
+/*********************************************/
+/** Resizable UI **/
+/*********************************************/
+.ui-resizable-e {
+ width: 3px;
+}
+
+/*********************************************/
+/** Download url **/
+/*********************************************/
+.download_url {
+ font-weight: bold;
+ font-size: 150%;
+ line-height: 150%;
+}
+
+/*********************************************/
+/** Syntax folor **/
+/*********************************************/
+div.line a {
+ text-decoration: underline;
+}
+
+span.lineno a {
+ text-decoration: none;
+}
+
+/*********************************************/
+/** Modules/Directory table **/
+/*********************************************/
+.directory .arrow {
+ height: initial;
+}
+
+.directory td.entry {
+ padding: 3px 6px;
+}
+
+/*********************************************/
+/** Mem items **/
+/*********************************************/
+.memproto table td {
+ font-family: monospace, fixed !important;
+}
+
+td.memItemLeft, td.memItemRight {
+ font-family: monospace, fixed;
+}
+
+.paramname, .paramname em {
+ font-style: italic;
+}
+
+.memdoc {
+ text-shadow: none;
+}
+
+.memItem {
+ font-family: monospace, fixed;
+}
+
+.memItem table {
+ font-family: inherit;
+}
+
+/*********************************************/
+/** Footer **/
+/*********************************************/
+img.footer {
+ height: 22px;
+}
+
+/*********************************************/
+/** Custom scrollbar **/
+/*********************************************/
+
+/*********************************************/
+/** Custom scrollbar **/
+/*********************************************/
diff --git a/project/doxygen_styles/custom_dark_theme.css b/project/doxygen_styles/custom_dark_theme.css
new file mode 100644
index 00000000..222adeeb
--- /dev/null
+++ b/project/doxygen_styles/custom_dark_theme.css
@@ -0,0 +1,425 @@
+/* Light background: #3 5 3 6 2 9; */
+/* New light dark background #3 2 3 6 3 d */
+/* Dark background: #d f e 5 f 2; */
+
+/* TOP MENU */
+.sm-dox {
+ background: #dfe5f2 !important;
+}
+
+.sm-dox a {
+ background: none;
+}
+
+body {
+ background: #282923;
+ background-image: none;
+ color: #D8D8D8;
+}
+
+div.fragment, pre.fragment {
+ border: 1px solid #000000;
+ background: #32363d;
+}
+
+a, a:link, a:visited {
+ color: #67d8ef !important;
+}
+
+.highlighted {
+ background: none !important;
+}
+
+a.highlighted {
+ background: none !important;
+}
+
+/*********************************************/
+/** Top main menu **/
+/*********************************************/
+#main-nav {
+ /* display: none; */
+ border-bottom: 1px solid #32363d;
+}
+
+#main-nav .sm-dox {
+ background: transparent !important;
+}
+
+.sm-dox a {
+ text-shadow: none !important;
+ background: transparent !important;
+}
+
+.sm-dox a:hover {
+ background: #282923 !important;
+}
+
+.sm-dox {
+ text-shadow: none !important;
+ box-shadow: none !important;
+}
+
+.sm-dox ul {
+ border: 1px solid #000000;
+ background: #32363d;
+}
+
+.directory tr.even {
+ background: #32363d;
+}
+
+
+/*********************************************/
+/** Top search **/
+/*********************************************/
+#MSearchSelectWindow {
+ border: 1px solid #000000;
+ background: #32363d;
+}
+
+a.selectItem {
+ padding: 3px;
+}
+
+a.SelectItem:hover {
+ background: #282923 !important;
+}
+
+#MSearchResultsWindow {
+ border: 1px solid #000000;
+ background: #32363d;
+ color: #67d8ef !important;;
+}
+
+/*********************************************/
+/** Main menu **/
+/*********************************************/
+#nav-tree {
+ background: transparent;
+}
+
+#nav-tree .selected {
+ background-image: none;
+ background: #32363d;
+}
+
+/*********************************************/
+/** Main content **/
+/*********************************************/
+
+/*********************************************/
+/** Inline code **/
+/*********************************************/
+p code,
+li code,
+td code,
+dd code {
+ background-color: #000000;
+ border: 1px solid #A8B8D9;
+
+ color: #D8D8D8;
+}
+
+/*********************************************/
+/** Table of Contents (ToC) **/
+/*********************************************/
+div.toc {
+ background: #32363d;
+ border: 1px solid #000000;
+}
+
+div.toc h3 {
+ font-size: 150%;
+ color: inherit;
+}
+
+/*********************************************/
+/** Content table **/
+/*********************************************/
+table.doxtable tr:nth-child(even) td {
+ background: #32363d;
+}
+
+div.header {
+ background: transparent;
+ border-bottom: 1px solid #32363d;
+}
+
+/*********************************************/
+/** Field table **/
+/*********************************************/
+.fieldtable th {
+ background: #282923;
+ color: inherit;
+}
+
+/*********************************************/
+/** Memitem and memtitle **/
+/*********************************************/
+.memdoc {
+ border: 1px solid #A8B8D9;
+}
+
+/*********************************************/
+/** TOP navigation **/
+/*********************************************/
+.tabs, .tabs2, .tabs3 {
+ background: #DDDDDD;
+}
+
+.tablist li {
+ background: transparent !important;
+}
+
+.tablist a {
+ background-image: none;
+ border-right: 1px solid #999999;
+
+ color: #32363d;
+}
+
+.tablist a:hover,
+.tablist li.current a {
+ text-decoration: none;
+ color: #000000;
+ background: #CCCCCC;
+ background-image: none;
+}
+
+/*********************************************/
+/** H1 in textblocks **/
+/*********************************************/
+
+/*********************************************/
+/** Note, warning **/
+/*********************************************/
+
+/*********************************************/
+/** Reference list **/
+/**Similar to warning/note/todo/... messages**/
+/*********************************************/
+dl.reflist {
+
+}
+
+
+/*********************************************/
+/** Note, warning **/
+/*********************************************/
+#docs_list {
+ background: #32363d;
+}
+
+#docs_list ul li {
+ border-right: 1px solid #BFBFBF;
+}
+
+#docs_list ul li a {
+ color: #1b1e21;
+}
+
+#docs_list ul li a:hover,
+#docs_list ul li a.docs_current {
+ background: #282923;
+}
+
+/*********************************************/
+/** Resizable UI **/
+/*********************************************/
+.ui-resizable-e {
+ background: #32363d;
+}
+
+/*********************************************/
+/** Download url **/
+/*********************************************/
+
+/*********************************************/
+/** Syntax folor **/
+/*********************************************/
+div.line {
+ background: transparent;
+ color: inherit;
+}
+
+div.line a {
+ color: inherit;
+}
+
+span.keyword {
+ color: #f92472;
+ font-style: italic;
+}
+
+span.keywordtype {
+ color: #67cfc1;
+ font-style: italic;
+}
+
+span.keywordflow {
+ color: #f92472;
+ font-style: italic;
+}
+
+span.comment {
+ color: #74705a;
+}
+
+span.preprocessor {
+ color: #a6e22b;
+}
+
+span.stringliteral {
+ color: #e7db74;
+}
+
+span.charliteral {
+ color: #e7db74;
+}
+
+span.vhdldigit {
+ color: #ff00ff;
+}
+
+span.vhdlchar {
+ color: #000000;
+}
+
+span.vhdlkeyword {
+ color: #700070;
+}
+
+span.vhdllogic {
+ color: #ff0000;
+}
+
+span.lineno {
+ background: transparent;
+}
+
+span.lineno a {
+ background: transparent;
+}
+
+/*********************************************/
+/** Modules/Directory table **/
+/*********************************************/
+.mdescLeft, .mdescRight, .memItemLeft, .memItemRight,
+.memTemplItemLeft, .memTemplItemRight, .memTemplParams {
+ background: #32363d;
+ color: inherit;
+}
+
+.memSeparator {
+ border: none;
+ background: transparent;
+}
+
+h2.groupheader {
+ color: #67d8ef;
+}
+
+/*********************************************/
+/** Mem items **/
+/*********************************************/
+.memtitle {
+ background: #32363d !important;
+ border-color: #000000;
+}
+
+.memitem {
+ background: #32363d !important;
+ color: inherit;
+ text-shadow: none;
+}
+
+.memproto {
+ background: inherit;
+ border-color: #000000;
+ color: inherit;
+ text-shadow: none;
+}
+
+.memproto table td {
+ font-family: monospace, fixed !important;
+}
+
+td.memItemLeft, td.memItemRight {
+ font-family: monospace, fixed;
+}
+
+.paramname, .paramname em {
+ color: #bf5f82;
+}
+
+.memdoc {
+ background: inherit;
+ border-color: #000000;
+}
+
+
+/*********************************************/
+/** Footer **/
+/*********************************************/
+.titlearea {
+ border-bottom: 1px solid #32363d;
+}
+
+/*********************************************/
+/** Footer **/
+/*********************************************/
+#nav-path {
+ background: transparent;
+}
+
+#nav-path ul {
+ background: transparent;
+ color: inherit;
+ border: none;
+ border-top: 1px solid #32363d;
+}
+
+.navpath li.footer {
+ color: inherit;
+}
+
+.navpath li.navelem a {
+ text-shadow: none;
+}
+
+/*********************************************/
+/** Custom scrollbar **/
+/*********************************************/
+::-webkit-scrollbar {
+ width: 10px;
+}
+
+/* Track */
+::-webkit-scrollbar-track {
+ border-radius: 10px;
+}
+
+/* Handle */
+::-webkit-scrollbar-thumb {
+ background: #234567;
+ border: none;
+}
+
+/* Handle on hover */
+::-webkit-scrollbar-thumb:hover {
+ background: #32363d;
+}
+
+/*********************************************/
+/** Custom scrollbar **/
+/*********************************************/
+h1.glow, h2.glow, h3.glow,
+h4.glow, h5.glow, h6.glow {
+ text-shadow: 0 0 15px #67d8ef;
+}
+
+
+iframe {
+ background-color: white;
+}
diff --git a/project/doxygen_styles/html_footer.html b/project/doxygen_styles/html_footer.html
new file mode 100644
index 00000000..5cb35229
--- /dev/null
+++ b/project/doxygen_styles/html_footer.html
@@ -0,0 +1,18 @@
+
+
+
+
+ $navpath
+
+ Generated on $datetime for $projectname by
+ $doxygenversion.
+ Dark theme by Tilen Majerle. All rights reserved.
+