aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rwxr-xr-xrun20
-rw-r--r--src/kernel/fs/ext2.c52
-rw-r--r--src/kernel/fs/ext2.h6
-rw-r--r--src/kernel/fs/load.c28
-rw-r--r--src/kernel/kernel.c1
6 files changed, 54 insertions, 57 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3612ddb..035dd77 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,7 +46,7 @@ add_executable(resources ${resources_sources})
set_target_properties(resources PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/font.o")
add_custom_command(
TARGET resources POST_BUILD
- COMMAND cross/opt/bin/i686-elf-objcopy -O binary build/font.o iso/font.bin
+ COMMAND cross/opt/bin/i686-elf-objcopy -O binary build/font.o build/font.bin
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
@@ -56,7 +56,7 @@ target_include_directories(user PUBLIC "src/userspace/")
set_target_properties(user PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/user.o")
add_custom_command(
TARGET user POST_BUILD
- COMMAND cross/opt/bin/i686-elf-objcopy -O binary build/user.o iso/user.bin
+ COMMAND cross/opt/bin/i686-elf-objcopy -O binary build/user.o build/user.bin
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
diff --git a/run b/run
index 68b0236..856086b 100755
--- a/run
+++ b/run
@@ -69,22 +69,24 @@ make_build() {
make || exit 1
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
+
# 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
- sudo mkdir -p ./mnt/abc/def/
- echo "Bananenkuchen" | sudo tee -a ./mnt/test
- echo "toll" | sudo tee -a ./mnt/abc/def/baum
+ 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
rm -r mnt/
- # 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
-
printf "Build finshed successfully!\n\n"
}
diff --git a/src/kernel/fs/ext2.c b/src/kernel/fs/ext2.c
index 3ab2f89..1d531de 100644
--- a/src/kernel/fs/ext2.c
+++ b/src/kernel/fs/ext2.c
@@ -24,10 +24,10 @@ 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);
+ 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);
log("Files:");
@@ -39,13 +39,6 @@ void ext2_init_fs()
log("Inode %d, name '%s'", dirent.inode_num, dirent.name);
kfree(file.buf);
-
- log("Looking for file '/test'...");
- uint32_t inode = ext2_look_up_path("/test");
- if (inode == 0)
- log("File not found");
- else
- log("Found: inode = %d", inode);
}
static void read_block(uint32_t block_num, void *buf)
@@ -67,13 +60,14 @@ 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("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");
}
static void load_bgdt()
@@ -208,7 +202,7 @@ uint32_t ext2_look_up_path(char *path)
path++;
uint32_t curr_dir_inode = ROOT_INODE;
- for (;;) {
+ while (1) {
size_t j;
for (j = 0; path[j] != '/' && path[j] != '\0'; j++)
;
@@ -232,3 +226,23 @@ uint32_t ext2_look_up_path(char *path)
return inode;
}
+
+// Implementations
+
+uint8_t *read_file(char *path)
+{
+ uint32_t inode = ext2_look_up_path(path);
+ struct ext2_file file;
+ ext2_open_inode(inode, &file);
+ if (inode != 0) {
+ size_t size = file.inode.size;
+ log("%d", size);
+ uint8_t *buf = kmalloc(size);
+ ext2_read(&file, buf, size);
+ kfree(file.buf);
+ buf[size - 1] = '\0';
+ return buf;
+ } else {
+ return NULL;
+ }
+}
diff --git a/src/kernel/fs/ext2.h b/src/kernel/fs/ext2.h
index f9c977c..7fbe493 100644
--- a/src/kernel/fs/ext2.h
+++ b/src/kernel/fs/ext2.h
@@ -33,12 +33,12 @@ struct ext2_superblock {
uint16_t mounts_since_fsck;
uint16_t max_mounts_since_fsck;
uint16_t signature;
- uint16_t state;
+ uint16_t state; // 1 clean; 2 errors
uint16_t error_action;
uint16_t minor_version;
uint32_t last_fsck_time;
uint32_t max_time_since_fsck;
- uint32_t creator_OS_id;
+ uint32_t creator_os_id;
uint32_t major_version;
uint16_t res_block_uid;
uint16_t res_block_gid;
@@ -137,4 +137,6 @@ bool ext2_next_dirent(struct ext2_file *file, struct ext2_dirent *dir);
uint32_t ext2_find_in_dir(uint32_t dir_inode, const char *name);
uint32_t ext2_look_up_path(char *path);
+uint8_t *read_file(char *path);
+
#endif
diff --git a/src/kernel/fs/load.c b/src/kernel/fs/load.c
index 9aca1c3..974c3fe 100644
--- a/src/kernel/fs/load.c
+++ b/src/kernel/fs/load.c
@@ -6,30 +6,8 @@
void load_binaries()
{
- userspace = (uint32_t)kmalloc(10000);
- font = (struct font *)kmalloc(100000); // High quality shit
+ //userspace = (uint32_t)read_file("/bin/user.bin");
+ font = (struct font *)read_file("/bin/font.bin");
- /*if (multiboot_header->boot_device != 0xE0FFFFFF) {
- panic("Unsupported boot drive!");
- } else {
- char *font_p[] = { "FONT.BIN" };
- struct iso9660_entity *font_e = ISO9660_get(font_p, 1);
- if (!font_e)
- panic("Font not found!");
- ATAPI_granular_read(1 + (font_e->length / 2048), font_e->lba, (uint8_t *)font);
- kfree(font_e);
-
- char *user_p[] = { "USER.BIN" };
- struct iso9660_entity *user_e = ISO9660_get(user_p, 1);
- if (!user_e)
- panic("Userspace binary not found!");
- ATAPI_granular_read(1 + (user_e->length / 2048), user_e->lba, (uint8_t *)userspace);
- kfree(user_e);
-
- if (font->magic != 0xf0f0f0f0) {
- warn("0x%x: WRONG FONT MAGIC!", font->magic);
- halt_loop();
- }
- }*/
log("Successfully loaded binaries");
-} \ No newline at end of file
+}
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index d4c7b93..d6bf3b6 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -58,6 +58,7 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address)
ata_init();
ext2_init_fs();
+ log("%s", read_file("/etc/test"));
load_binaries();
set_optimal_resolution();