From: Matthias Kruk Date: Fri, 1 May 2020 05:36:09 +0000 (+0900) Subject: corax/sys: Add initfs infrastructure X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=0b243cefe7c26a353572900487fb9eed22f81fc2;p=corax corax/sys: Add initfs infrastructure --- diff --git a/config.h b/config.h index ead8518..341b667 100644 --- a/config.h +++ b/config.h @@ -1,6 +1,6 @@ /* * This file is part of the Corax operating system. - * Copyright (C) 2016-2019 Matthias Kruk + * Copyright (C) 2016-2020 Matthias Kruk * * Corax is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -62,6 +62,9 @@ #define CONFIG_IO_MAXPROCFDS 16 #define CONFIG_ELF 0 +#define CONFIG_KBD 1 +#define CONFIG_VGA 0 + /* klibc configuration */ #define CONFIG_SNPRINTF_FLAG_MINUS 0 #define CONFIG_SNPRINTF_FLAG_APOS 0 /* not implemented */ diff --git a/include/corax/initfs.h b/include/corax/initfs.h new file mode 100644 index 0000000..3018b9f --- /dev/null +++ b/include/corax/initfs.h @@ -0,0 +1,32 @@ +/* + * This file is part of the Corax operating system. + * Copyright (C) 2016-2020 Matthias Kruk + * + * Corax is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Corax is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Corax. If not, see . + */ + +#ifndef __CORAX_INITFS_H + +struct initfs_entry { + const char * const ife_name; + const void * const ife_base; + const void * const ife_limit; +}; + +struct initfs { + struct initfs_entry *ifs_entries; + unsigned int ifs_num_entries; +}; + +#endif /* __CORAX_INITFS_H */ diff --git a/kernel/Makefile b/kernel/Makefile index b96b61f..eb275df 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -4,7 +4,8 @@ DEPS = arch core vga kbd klibc sched LDFLAGS = --oformat=elf32-i386 -b elf32-i386 -m elf_i386 CFLAGS = -m32 -Wall -nostdlib -nodefaultlibs -nostartfiles -ffreestanding -nostdinc \ -fno-builtin -fno-builtin-memcpy -LIBGCC = /usr/lib/gcc/i686-linux-gnu/8/libgcc.a +LIBGCC = /usr/lib/gcc-cross/i686-linux-gnu/8/libgcc.a +INITFS = ../sys/initfs.a PHONY = $(DEPS) clean OUTPUT = corax @@ -18,7 +19,7 @@ $(DEPS): # FIXME: Remove dependency on libgcc $(OUTPUT): $(DEPS) - ld -o $@ -T linker.ld $(LDFLAGS) $(OBJECTS) $(LIBGCC) + ld -o $@ -T linker.ld $(LDFLAGS) $(OBJECTS) $(LIBGCC) $(INITFS) clean: $(DEPS) rm -f $(OUTPUT) diff --git a/kernel/core/main.c b/kernel/core/main.c index 65f5177..fc3c472 100644 --- a/kernel/core/main.c +++ b/kernel/core/main.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,8 @@ extern void _net(void); extern int vga_main(int, char**); extern int kbd_main(int, char**); +extern struct initfs initfs; + void _print_mptbl(void *tbl) { u32_t *pmcp; @@ -51,7 +54,8 @@ void _print_mptbl(void *tbl) if(*pmcp == 0x504d4350 || *pmcp == 0x50434d50) { entries = *(u16_t*)(pmcp + 1); - dbg_printf("PMCP: 0x%08x, l: %hu, [0x%08x]\n", pmcp, entries, *pmcp); + dbg_printf("PMCP: 0x%08x, l: %hu, [0x%08x]\n", + pmcp, entries, *pmcp); tbl += 0x2c; while(entries) { @@ -70,7 +74,12 @@ void _print_mptbl(void *tbl) tbl += 8; break; case 3: /* IO Interrupt entry */ - dbg_printf("[INT] T: 0x%02hhx SRC: 0x%02hhx IRQ: 0x%02hhx DEST: 0x%02hhx DINT: 0x%02hhx\n", *((u8_t*)tbl + 1), *((u8_t*)tbl + 4), *((u8_t*)tbl + 5), *((u8_t*)tbl + 6), *((u8_t*)tbl + 7)); + dbg_printf("[INT] T: 0x%02hhx SRC: 0x%02hhx " + "IRQ: 0x%02hhx DEST: 0x%02hhx " + "DINT: 0x%02hhx\n", + *((u8_t*)tbl + 1), *((u8_t*)tbl + 4), + *((u8_t*)tbl + 5), *((u8_t*)tbl + 6), + *((u8_t*)tbl + 7)); tbl += 8; break; case 4: /* Local Interrupt assignment entry */ @@ -109,9 +118,10 @@ static void _init(void) int err; /* - * Instead of something like /sbin/init, this process will behave more like the process daemon - * found in the MINIX3 operating system. It will spawn the daemons necessary for basic system - * operation, and restart them in case they should die. + * Instead of something like /sbin/init, this process will behave more + * like the process daemon found in the MINIX3 operating system. It will + * spawn the daemons necessary for basic system operation, and restart + * them in case they should die. */ #if 0 pid = fork(); @@ -204,29 +214,15 @@ int corax(void *mb_info, u32_t magic) PANIC("Failed to initialize scheduler\n"); } -/* - for(ptr = (void*)0x9fc00; ptr < (void*)0x9fffc; ptr++) { - if(*(u32_t*)ptr == 0x5f504d5f) { - dbg_printf("MP Floating Pointer Structure @ 0x%08x\n", ptr); - break; - } else if(*(u32_t*)ptr == 0x5f4d505f) { - dbg_printf("MP Floating Pointer Structure @ 0x%08x LE\n", ptr); - break; - } - } + dbg_printf("initfs has %01u entries\n", initfs.ifs_num_entries); - if(ptr >= (void*)0x9fffc) { - for(ptr = (void*)0xf0000; ptr < (void*)0xffffc; ptr++) { - if(*(u32_t*)ptr == 0x5f504d5f) { - dbg_printf("MP Floating Pointer Structure @ 0x%08x\n", ptr); - break; - } else if(*(u32_t*)ptr == 0x5f4d505f) { - dbg_printf("MP Floating Pointer Structure @ 0x%08x LE\n", ptr); - break; - } - } + for(err = 0; err < initfs.ifs_num_entries; err++) { + dbg_printf("initfs[%01u] = { \"%s\", 0x%08x : 0x%08x }\n", + initfs.ifs_entries[err].ife_name, + initfs.ifs_entries[err].ife_base, + initfs.ifs_entries[err].ife_limit); } -*/ + err = process_create(&proc, PID_ANY, 0, (void*)_idle); if(err < 0) { diff --git a/sys/Makefile b/sys/Makefile new file mode 100644 index 0000000..d801164 --- /dev/null +++ b/sys/Makefile @@ -0,0 +1,22 @@ +DEPS = kbd +PHONY = $(DEPS) clean +OUTPUT = initfs.a +INCLUDES = -I.. -I../include +CFLAGS = -m32 -Wall -nostdlib -nodefaultlibs -nostartfiles -ffreestanding \ + -nostdinc -fno-builtin -fno-builtin-memcpy $(INCLUDES) + +all: $(OUTPUT) + +$(OUTPUT): initfs.o + ar r $@ $^ *.ko + +updateinitfs: + gcc -o initfs.o $(CFLAGS) initfs.c *.ko + +$(DEPS): + $(MAKE) -C $@ $(MAKECMDGOALS) + +clean: $(DEPS) + rm -f $(OUTPUT) + +.PHONY: $(PHONY) diff --git a/sys/initfs.c b/sys/initfs.c new file mode 100644 index 0000000..7273d77 --- /dev/null +++ b/sys/initfs.c @@ -0,0 +1,34 @@ +#include +#include + +#if FEATURE(KBD) +extern const char _binary_kbd_end[]; +extern const char _binary_kbd_start[]; +#endif /* FEATURE(KBD) */ + +#if FEATURE(VGA) +extern const char _binary_vga_end[]; +extern const char _binary_vga_start[]; +#endif /* FEATURE(VGA) */ + +static struct initfs_entry _ifs_entries[] = { +#if FEATURE(KBD) + { + .ife_name = "kbd", + .ife_base = &_binary_kbd_start, + .ife_limit = &_binary_kbd_end + }, +#endif +#if FEATURE(VGA) + { + .ife_name = "vga", + .ife_base = &_binary_vga_start, + .ife_limit = &_binary_vga_end + }, +#endif +}; + +struct initfs initfs = { + .ifs_entries = _ifs_entries, + .ifs_num_entries = sizeof(_ifs_entries) / sizeof(_ifs_entries[0]) +};