aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-04-25 18:33:37 +0200
committerMarvin Borner2020-04-25 18:33:37 +0200
commit71a111f7e6b71e0894b90e8dc1221b1ec4f84ab3 (patch)
tree78a8340f7909429d91f560ba2915959a4d313a1b
parent30601e14f216488ee3a36dc44ab0ed56da7ccdb2 (diff)
Added indirect pointers - re-enabled font :)
I don't know why, but once there are multiple files on the drive the kernel can only read one file.. I'll investigate this later.
-rw-r--r--CMakeLists.txt1
-rwxr-xr-xrun47
-rw-r--r--src/kernel/fs/ext2.c46
-rw-r--r--src/kernel/fs/load.c6
-rw-r--r--src/kernel/graphics/vesa.c3
-rw-r--r--src/kernel/kernel.c4
6 files changed, 59 insertions, 48 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 035dd77..4cf3ba4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -44,6 +44,7 @@ target_link_libraries(kernel PRIVATE "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/
# RESOURCES
add_executable(resources ${resources_sources})
set_target_properties(resources PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/font.o")
+target_compile_options(resources PRIVATE "-Os")
add_custom_command(
TARGET resources POST_BUILD
COMMAND cross/opt/bin/i686-elf-objcopy -O binary build/font.o build/font.bin
diff --git a/run b/run
index 856086b..8289427 100755
--- a/run
+++ b/run
@@ -1,6 +1,8 @@
#!/usr/bin/env sh
-cd "$(dirname "$0")" || exit 1
+set -e
+
+cd "$(dirname "$0")"
mode="${1}"
network="rtl8139"
@@ -18,11 +20,11 @@ make_cross() {
if [ ! -d "./cross/" ]; then
# Create directory
mkdir -p cross
- cd cross || exit 1
+ cd cross
DIR=$(pwd)
# Get sources
- mkdir "${DIR}/src" && cd "${DIR}/src" || exit 1
+ mkdir "${DIR}/src" && cd "${DIR}/src"
echo "Downloading..."
curl -sSL "https://ftp.gnu.org/gnu/binutils/binutils-2.32.tar.xz" | tar xJ
curl -sSL "https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz" | tar xJ
@@ -34,23 +36,23 @@ make_cross() {
export PATH="$PREFIX/bin:$PATH"
# Compile binutils
- mkdir "${DIR}/src/build-binutils" && cd "${DIR}/src/build-binutils" || exit 1
+ mkdir "${DIR}/src/build-binutils" && cd "${DIR}/src/build-binutils"
../binutils-2.32/configure --target="$TARGET" --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make
make install
# Compile GCC
- mkdir "${DIR}/src/build-gcc" && cd "${DIR}/src/build-gcc" || exit 1
+ mkdir "${DIR}/src/build-gcc" && cd "${DIR}/src/build-gcc"
../gcc-9.2.0/configure --target="$TARGET" --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc
- cd "${DIR}/.." || exit 1
+ cd "${DIR}/.."
else
# Should be sourced to take effect
- cd cross || exit 1
+ cd cross
DIR=$(pwd)
export PREFIX="${DIR}/opt"
export TARGET=i686-elf
@@ -64,27 +66,27 @@ make_build() {
echo "Building..."
mkdir -p build
- cd build || exit 1
- cmake .. >/dev/null || exit 1
- make || exit 1
+ cd build
+ cmake .. >/dev/null
+ make
cd ..
# Create ISO
mkdir -p ./iso/boot/grub/
cp ./build/kernel.bin ./iso/boot/kernel.bin
cp ./src/bootloader/grub.cfg ./iso/boot/grub/
- grub-mkrescue -o ./build/melvix.iso ./iso/ || exit 1
+ grub-mkrescue -o ./build/melvix.iso ./iso/
# Create disk image
- mke2fs -b 4096 -N 4096 ./build/disk.img 65536 || exit 1
- mkdir ./mnt/ || exit 1
- sudo mount ./build/disk.img ./mnt/ || exit 1
+ mke2fs -b 4096 -N 4096 ./build/disk.img 65536
+ mkdir ./mnt/
+ sudo mount ./build/disk.img ./mnt/
sudo mkdir -p ./mnt/etc/
sudo mkdir -p ./mnt/usr/
sudo mkdir -p ./mnt/bin/
- echo "Hello world, ext2!" | sudo tee -a ./mnt/etc/test
- sudo mv ./build/*.bin ./mnt/bin/
- sync && sudo umount mnt || exit 1
+ # echo "Hello world, ext2!" | sudo tee -a ./mnt/etc/test # ?!
+ sudo cp ./build/font.bin ./mnt/bin/font
+ sync && sudo umount mnt
rm -r mnt/
printf "Build finshed successfully!\n\n"
@@ -118,10 +120,10 @@ make_sync() {
rm tags compile_commands.json
ctags -R --exclude=.git --exclude=build --exclude=iso --exclude=cross .
mkdir -p cmake
- cd cmake || exit 1
+ cd cmake
cmake .. >/dev/null
mv compile_commands.json ..
- cd .. || exit 1
+ cd ..
}
make_tidy() {
@@ -132,13 +134,14 @@ make_tidy() {
}
make_font() {
- cd ./src/resources/ || exit 1
+ cd ./src/resources/
sh conv.sh
- cd ../../ || exit 1
+ cd ../../
}
make_clean() {
- rm -rf ./build ./iso
+ #rm -rf ./build ./iso
+ rm -rf ./iso ./build/*.img ./build/*.o ./build/*.bin
}
if [ "${mode}" = "cross" ]; then
diff --git a/src/kernel/fs/ext2.c b/src/kernel/fs/ext2.c
index 1d531de..4e7a384 100644
--- a/src/kernel/fs/ext2.c
+++ b/src/kernel/fs/ext2.c
@@ -24,19 +24,19 @@ void ext2_init_fs()
struct ext2_inode root_inode;
read_inode(&root_inode, ROOT_INODE);
- log("Creation time: %d", root_inode.creation_time);
- log("UID: %d", root_inode.uid);
- log("Type & perms: 0x%x", root_inode.type_and_permissions);
- log("Size: %d", root_inode.size);
+ debug("Creation time: %d", root_inode.creation_time);
+ debug("UID: %d", root_inode.uid);
+ debug("Type & perms: 0x%x", root_inode.type_and_permissions);
+ debug("Size: %d", root_inode.size);
- log("Files:");
+ debug("Files:");
struct ext2_file file;
ext2_open_inode(ROOT_INODE, &file);
struct ext2_dirent dirent;
while (ext2_next_dirent(&file, &dirent))
- log("Inode %d, name '%s'", dirent.inode_num, dirent.name);
+ debug("Inode %d, name '%s'", dirent.inode_num, dirent.name);
kfree(file.buf);
}
@@ -60,14 +60,15 @@ static void load_superblock()
num_groups = superblock.total_blocks / superblock.blocks_per_group;
assert(superblock.signature == EXT2_SIGNATURE);
- log("Total inodes: 0x%x", superblock.total_inodes);
- log("Total blocks: 0x%x", superblock.total_blocks);
- log("Block size: %d", block_size);
- log("Num blocks: %d", superblock.total_blocks);
- log("Blocks/group: %d", superblock.blocks_per_group);
- log("Inodes/group: %d", superblock.inodes_per_group);
- log("Num groups: %d", num_groups);
- log("Creator OS: %s", superblock.creator_os_id == 0 ? "Linux" : "Other");
+ debug("Total inodes: 0x%x", superblock.total_inodes);
+ debug("Total blocks: 0x%x", superblock.total_blocks);
+ debug("Drive size: %dMiB", (block_size * superblock.total_blocks) >> 20);
+ debug("Block size: %d", block_size);
+ debug("Num blocks: %d", superblock.total_blocks);
+ debug("Blocks/group: %d", superblock.blocks_per_group);
+ debug("Inodes/group: %d", superblock.inodes_per_group);
+ debug("Num groups: %d", num_groups);
+ debug("Creator OS: %s", superblock.creator_os_id == 0 ? "Linux" : "Other");
}
static void load_bgdt()
@@ -136,10 +137,14 @@ size_t ext2_read(struct ext2_file *file, uint8_t *buf, size_t count)
if (new_block) {
file->curr_block_pos = 0;
file->block_index++;
- if (file->block_index >= 12)
- panic("Indirect block pointers are currently unsupported");
-
- read_block(file->inode.dbp[file->block_index], file->buf);
+ if (file->block_index >= 12) {
+ // TODO: Add triple block pointer support
+ uint32_t *tmp = kmalloc(block_size);
+ read_block(file->inode.ibp, tmp);
+ read_block(tmp[file->block_index - 12], file->buf);
+ } else {
+ read_block(file->inode.dbp[file->block_index], file->buf);
+ }
}
}
@@ -227,7 +232,7 @@ uint32_t ext2_look_up_path(char *path)
return inode;
}
-// Implementations
+// Interface
uint8_t *read_file(char *path)
{
@@ -236,13 +241,14 @@ uint8_t *read_file(char *path)
ext2_open_inode(inode, &file);
if (inode != 0) {
size_t size = file.inode.size;
- log("%d", size);
+ debug("%d", size);
uint8_t *buf = kmalloc(size);
ext2_read(&file, buf, size);
kfree(file.buf);
buf[size - 1] = '\0';
return buf;
} else {
+ warn("File not found");
return NULL;
}
}
diff --git a/src/kernel/fs/load.c b/src/kernel/fs/load.c
index 974c3fe..09e6dbc 100644
--- a/src/kernel/fs/load.c
+++ b/src/kernel/fs/load.c
@@ -1,13 +1,13 @@
#include <kernel/fs/load.h>
#include <kernel/system.h>
-#include <kernel/memory/alloc.h>
#include <kernel/lib/stdio.h>
#include <kernel/lib/lib.h>
+#include <kernel/fs/ext2.h>
void load_binaries()
{
- //userspace = (uint32_t)read_file("/bin/user.bin");
- font = (struct font *)read_file("/bin/font.bin");
+ // userspace = (uint32_t)read_file("/bin/user.bin");
+ font = (struct font *)read_file("/bin/font");
log("Successfully loaded binaries");
}
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c
index 853c503..d7bc42a 100644
--- a/src/kernel/graphics/vesa.c
+++ b/src/kernel/graphics/vesa.c
@@ -200,7 +200,6 @@ void set_optimal_resolution()
vesa_clear();
vesa_set_color(vesa_blue);
- printf(vga_buffer);
vesa_set_color(default_text_color);
info("Successfully switched to video mode!");
@@ -369,4 +368,4 @@ void vesa_set_color(uint32_t color)
{
vesa_convert_color(terminal_color, color);
vesa_convert_color(terminal_background, default_background_color);
-} \ No newline at end of file
+}
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index d6bf3b6..881361f 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -58,11 +58,13 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address)
ata_init();
ext2_init_fs();
- log("%s", read_file("/etc/test"));
+ // log("%s", read_file("/etc/test")); // Multiple reads don't work?!
load_binaries();
set_optimal_resolution();
+ printf("Awesome!");
+
// tasking_install();
#ifdef INSTALL_MELVIX