Skip to content

Commit

Permalink
Fix some little bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and Jie Zheng committed Sep 4, 2018
1 parent 7f10b2c commit 88c8f82
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 12 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
include mk/Makefile.kernel


app:
@echo "[ACTION] start to compile application packages."; \
for _dir in `ls application`; \
Expand Down
8 changes: 6 additions & 2 deletions ZeldaDrive/hyrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ def string_to_array(arr, _str):
arr[_idx] = _byte
_idx = _idx + 1

#please refer to filesystem/include/zeldafs.h for the definition and
#memory layout to serialization and deserialization

def write_drive_file(_file_dst, _path):
name = bytearray(PATH_NAME)
size = os.path.getsize(_path)
string_to_array(name, _path)
string_to_array(name, _path.lstrip('.'))
_file_dst.write(name)
_file_dst.write(int32_to_array(size))
print('[File] Found file:%s size:%s' % (_path, size))
_file_dst.write(int32_to_array(0))
_file_dst.write(int32_to_array(0))
print('[File] Found file:%s size:%s' % (_path.lstrip('.'), size))
with open(_path, 'rb') as f:
while True:
context = f.read(512)
Expand Down
6 changes: 5 additions & 1 deletion filesystem/include/zeldafs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
#define _ZELDA_DRIVE_H
#if defined(KERNEL_CONTEXT)
#include <lib/include/types.h>
#include <lib/include/list.h>
#else
#include <stdint.h>
#error "Not Supported outside of kernel space."
#endif

struct zelda_file {
uint8_t path[256];
uint32_t length;
};
struct list_elem list;
uint8_t content[0];
}__attribute__((packed));

void zeldafs_init(void);
#endif
Expand Down
8 changes: 6 additions & 2 deletions filesystem/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ test_vfs(void)
ASSERT(!register_file_system((uint8_t *)"/home/jie", &fs0));

entry = search_mount_entry((uint8_t *)"//home/jied/../jie/./cute.txt");
LOG_DEBUG("Fount mount entry 0x%x(%s)\n", entry,
LOG_DEBUG("Found mount entry 0x%x(%s)\n", entry,
entry ? (char *)entry->mount_point : "");
}
dump_mount_entries();
Expand All @@ -220,9 +220,13 @@ test_vfs(void)
void
vfs_init(void)
{
memset(mount_entries, 0x0, sizeof(mount_entries));
#if defined(INLINE_TEST)
test_vfs();
#endif
}

__attribute__((constructor)) void
vfs_pre_init(void)
{
memset(mount_entries, 0x0, sizeof(mount_entries));
}
23 changes: 22 additions & 1 deletion filesystem/zeldafs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@
#include <filesystem/include/zeldafs.h>
#include <memory/include/physical_memory.h>
#include <kernel/include/printk.h>
#include <lib/include/list.h>

static uint32_t zelda_drive_start = (uint32_t)&_zelda_drive_start;
static uint32_t zelda_drive_end =(uint32_t)&_zelda_drive_end;

static struct list_elem head = {
.prev = NULL,
.next = NULL
};

void
dump_zedla_drives(void)
{
struct zelda_file * _file;
struct list_elem * _list;
LOG_INFO("Dump Zelda Drive:\n");
LIST_FOREACH_START(&head, _list) {
_file = CONTAINER_OF(_list, struct zelda_file, list);
LOG_INFO(" File name:%s size:%d\n", _file->path, _file->length);
}
LIST_FOREACH_END();
}


void
Expand All @@ -17,7 +35,9 @@ enumerate_files_in_zelda_drive(void)
uint32_t iptr = zelda_drive_start;
for(; iptr < zelda_drive_end;) {
_file = (struct zelda_file *)iptr;
printk("Found a zelda file:%s\n", _file->path);
_file->list.next = NULL;
_file->list.prev = NULL;
list_append(&head, &_file->list);
iptr += sizeof(struct zelda_file) + _file->length;
}
}
Expand All @@ -28,4 +48,5 @@ void
zeldafs_init(void)
{
enumerate_files_in_zelda_drive();
dump_zedla_drives();
}
13 changes: 13 additions & 0 deletions kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
#include <filesystem/include/zeldafs.h>

static struct multiboot_info * boot_info;
static void
pre_init(void)
{
uint32_t _start_addr = (uint32_t)&_kernel_constructor_start;
uint32_t _end_addr = (uint32_t)&_kernel_constructor_end;
uint32_t func_container = 0;
for(func_container = _start_addr;
func_container < _end_addr;
func_container += 4) {
((void (*)(void))*(uint32_t *)func_container)();
}
}

static void
init1(void)
Expand Down Expand Up @@ -81,6 +93,7 @@ post_init(void)
void kernel_main(struct multiboot_info * _boot_info, void * magicnum __used)
{
boot_info = _boot_info;
pre_init();
init1();
init2();
init3();
Expand Down
5 changes: 4 additions & 1 deletion lib/include/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#ifndef _LIST_H
#define _LIST_H
#include <lib/include/types.h>

/*
* CAVEATS: Do *NOT* modify the struct of list_elem, otherwise it may impact
* Zelda Drive serialization.
*/
struct list_elem {
struct list_elem * prev;
struct list_elem * next;
Expand Down
3 changes: 2 additions & 1 deletion memory/include/physical_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ extern uint8_t * _kernel_bss_start;
extern uint8_t * _kernel_bss_end;
extern uint8_t * _zelda_drive_start;
extern uint8_t * _zelda_drive_end;

extern uint8_t * _kernel_constructor_start;
extern uint8_t * _kernel_constructor_end;
#endif
2 changes: 1 addition & 1 deletion memory/physical_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void probe_physical_mmeory(struct multiboot_info * boot_info)
(struct multiboot_mmap*)(boot_info->mmap_addr + boot_info->mmap_length);
LOG_INFO("Probing physical memory with multiboot:0x%x... ...\n",boot_info);
for (idx = 0; mmap < mmap_end; mmap++, idx++) {
LOG_INFO("%d: type:%x baseaddr:0x%x length:0x%x %s\n",
LOG_INFO(" %d: type:%x baseaddr:0x%x length:0x%x %s\n",
idx, mmap->type, mmap->baseaddr_low, mmap->length_low,
LOW_MEMORY_DELIMITER == mmap->baseaddr_low? "(*system main memory)":
mmap->baseaddr_high? "(*not addressable in ia32)": "");
Expand Down
4 changes: 2 additions & 2 deletions mk/linker.ld.kernel
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ SECTIONS
_kernel_data_start = ALIGN(4096);
.data BLOCK(4K) : ALIGN(4K)
{
start_ctors = .;
_kernel_constructor_start = .;
KEEP(*( .init_array ));
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
end_ctors = .;
_kernel_constructor_end = .;
*(.data)
_zelda_drive_start = .;
KEEP(*(.zelda_drive))
Expand Down

0 comments on commit 88c8f82

Please sign in to comment.