diff --git a/.gitignore b/.gitignore index f88e2a3f..4e6c1c00 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ toaruos-initrd bootloader/stage1.bin bootloader/stage2.bin initrd/boot +initrd/bin/* .gdb_history bootdisk.img *.log diff --git a/Makefile b/Makefile index a0aae953..998970a7 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ ECHO = `which echo` -e MODULES = $(patsubst %.c,%.o,$(wildcard kernel/core/*.c)) FILESYSTEMS = $(patsubst %.c,%.o,$(wildcard kernel/core/fs/*.c)) VIDEODRIVERS = $(patsubst %.c,%.o,$(wildcard kernel/core/video/*.c)) +BINARIES = initrd/bin/test EMU = qemu GENEXT = genext2fs DD = dd conv=notrunc @@ -66,11 +67,11 @@ kernel/start.o: kernel/start.s ################ # Ram disk # ################ -toaruos-initrd: initrd/boot/kernel initrd/boot/stage2 initrd/bs.bmp +toaruos-initrd: initrd/boot/kernel initrd/boot/stage2 initrd/bs.bmp ${BINARIES} @${ECHO} -n "\033[32m initrd Generating initial RAM disk\033[0m" @# Get rid of the old one @-rm -f toaruos-initrd - @${GENEXT} -d initrd -q -b 249 toaruos-initrd + @${GENEXT} -d initrd -q -b 1024 toaruos-initrd @${ECHO} "\r\033[32;1m initrd Generated initial RAM disk image\033[0m" @${ECHO} "\033[34;1m -- HDD image is ready!\033[0m" @@ -95,6 +96,26 @@ util/bin/mrboots-installer: util/mrboots-installer.c @${CC} ${NATIVEFLAGS} -o $@ $< @${ECHO} "\r\033[32;1m CC $<\033[0m" + +################ +# Userspace # +################ +loader/crtbegin.o: loader/crtbegin.s + @${ECHO} -n "\033[32m yasm $<\033[0m" + @${YASM} -f elf32 -o $@ $< + @${ECHO} "\r\033[32;1m yasm $<\033[0m" + +initrd/bin/test: loader/test.o loader/crtbegin.o + @${ECHO} -n "\033[32m LD $<\033[0m" + @${LD} -T loader/link.ld -o $@ $< + @${ECHO} "\r\033[32;1m LD $<\033[0m" + @${ECHO} "\033[34;1m -- Kernel is ready!\033[0m" + +loader/%.o: loader/%.c + @${ECHO} -n "\033[32m CC $<\033[0m" + @${CC} ${CFLAGS} -c -o $@ $< + @${ECHO} "\r\033[32;1m CC $<\033[0m" + ################ # Bootloader # ################ @@ -154,6 +175,8 @@ clean: @-rm -f bootloader/stage1/*.o @-rm -f bootloader/stage2.bin @-rm -f bootloader/stage2/*.o + @-rm -f initrd/bin/* + @-rm -f loader/*.o @-rm -f -r initrd/boot @-rm -f bootdisk.img @-rm -f docs/*.pdf docs/*.aux docs/*.log docs/*.out diff --git a/initrd/bin/.dummy b/initrd/bin/.dummy new file mode 100644 index 00000000..e69de29b diff --git a/kernel/core/multiboot.c b/kernel/core/multiboot.c index 1333ced1..942511fd 100644 --- a/kernel/core/multiboot.c +++ b/kernel/core/multiboot.c @@ -1,6 +1,9 @@ #include #include +char * ramdisk = NULL; +struct multiboot * mboot_ptr = NULL; + struct multiboot * copy_multiboot( struct multiboot *mboot_ptr diff --git a/kernel/core/shell.c b/kernel/core/shell.c index a83a58cf..64f13de2 100644 --- a/kernel/core/shell.c +++ b/kernel/core/shell.c @@ -20,6 +20,7 @@ */ #include #include +#include void start_shell() { @@ -240,6 +241,8 @@ start_shell() { } else if (!strcmp(cmd, "test-ansi")) { ansi_print("This is a \033[32mtest\033[0m of the \033[33mANSI\033[0m driver.\n"); ansi_print("This is a \033[32;1mte\033[34mst\033[0m of \033[1mthe \033[33mANSI\033[0m driver.\n"); + } else if (!strcmp(cmd, "multiboot")) { + dump_multiboot(mboot_ptr); } else { kprintf("Unrecognized command: %s\n", cmd); } diff --git a/kernel/include/elf.h b/kernel/include/elf.h new file mode 100644 index 00000000..a34ea89b --- /dev/null +++ b/kernel/include/elf.h @@ -0,0 +1,22 @@ +/* + * ELF Binary Executable headers + * + * vim:noexpandtab + * vim:tabstop=4 + */ + +/* + * Different bits of our build environment + * require different header files for definitions + */ +#ifdef _KERNEL_ +# include +#else +# ifdef BOOTLOADER +# include +# else +# include +# endif +#endif + + diff --git a/kernel/include/multiboot.h b/kernel/include/multiboot.h index a32dc759..50f069e4 100644 --- a/kernel/include/multiboot.h +++ b/kernel/include/multiboot.h @@ -47,5 +47,7 @@ struct multiboot struct multiboot *copy_multiboot(struct multiboot *mboot_ptr); void dump_multiboot(struct multiboot *mboot_ptr); +char * ramdisk; +struct multiboot * mboot_ptr; #endif diff --git a/kernel/main.c b/kernel/main.c index 3172d6fc..c6c1701e 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -56,21 +56,30 @@ * multiboot data from the bootloader. It will then proceed to print * out the contents of the initial ramdisk image. */ -int main(struct multiboot *mboot_ptr, uint32_t mboot_mag, uintptr_t esp) +int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) { initial_esp = esp; enum BOOTMODE boot_mode = unknown; /* Boot Mode */ - char * ramdisk = NULL; if (mboot_mag == MULTIBOOT_EAX_MAGIC) { /* * Multiboot (GRUB, native QEMU, PXE) */ boot_mode = multiboot; + + void * new_mboot = (void *)0x10000000; + memcpy(new_mboot, mboot, sizeof(struct multiboot)); + mboot_ptr = (struct multiboot *)new_mboot; + /* * Realign memory to the end of the multiboot modules */ - kmalloc_startat(0x200000); + uint32_t module_start = *((uint32_t *) mboot_ptr->mods_addr); /* Start address */ + uint32_t module_end = *(uint32_t *) (mboot_ptr->mods_addr + 4); /* End address */ + kmalloc_startat(module_end + 1024); + if (mboot_ptr->flags & (1 << 3)) { + ramdisk = (char *)module_start; +#if 0 /* * Mboot modules are available. */ @@ -83,6 +92,7 @@ int main(struct multiboot *mboot_ptr, uint32_t mboot_mag, uintptr_t esp) ramdisk = (char *)kmalloc(module_end - module_start); /* New chunk of ram for it. */ memcpy(ramdisk, (char *)module_start, module_end - module_start); /* Copy it over. */ } +#endif } } else { /* @@ -93,11 +103,12 @@ int main(struct multiboot *mboot_ptr, uint32_t mboot_mag, uintptr_t esp) } /* Initialize core modules */ + init_video(); /* VGA driver */ gdt_install(); /* Global descriptor table */ idt_install(); /* IDT */ isrs_install(); /* Interrupt service requests */ irq_install(); /* Hardware interrupt requests */ - init_video(); /* VGA driver */ + /* Hardware drivers */ timer_install(); /* PIC driver */ @@ -116,6 +127,9 @@ int main(struct multiboot *mboot_ptr, uint32_t mboot_mag, uintptr_t esp) kprintf("[%s %s]\n", KERNEL_UNAME, KERNEL_VERSION_STRING); if (boot_mode == multiboot) { + for (uintptr_t i = 0x10000000; i <= 0x10FF0000; i += 0x1000) { + dma_frame(get_page(i, 1, kernel_directory), 1, 0, i); + } /* Print multiboot information */ dump_multiboot(mboot_ptr); diff --git a/loader/crtbegin.s b/loader/crtbegin.s new file mode 100644 index 00000000..d4142ce1 --- /dev/null +++ b/loader/crtbegin.s @@ -0,0 +1,13 @@ +BITS 32 + +global _start +_start: + push 0 ; argc + push 0 ; argv + extern main + call main + mov eax, 0 + int 0x79 +_wait: + hlt + jmp _wait diff --git a/loader/link.ld b/loader/link.ld new file mode 100644 index 00000000..33df73a1 --- /dev/null +++ b/loader/link.ld @@ -0,0 +1,47 @@ +/* + * Userspace Application Linker Script + * 2011, ToAruOS + */ +OUTPUT_FORMAT(elf32-i386) +ENTRY(_start) +STARTUP(loader/crtbegin.o) +phys = 0x02000000; +SECTIONS +{ + /* + * Actual code + */ + .text phys : AT(phys) { + code = .; + *(.text) + *(.rodata) + . = ALIGN(4096); + } + /* + * Kernel data + */ + .data : AT(phys + (data - code)) + { + data = .; + *(.data) + . = ALIGN(4096); + } + /* + * Statically defined, uninitialized values + */ + .bss : AT(phys + (bss - code)) + { + bss = .; + *(.bss) + . = ALIGN(4096); + } + /* + * Get rid of unnecessary GCC bits. + */ + /DISCARD/ : + { + *(.comment) + *(.eh_frame) + *(.note.gnu.build-id) + } +} diff --git a/loader/test.c b/loader/test.c index bbc38eae..7eb8e7a8 100644 --- a/loader/test.c +++ b/loader/test.c @@ -1,3 +1,7 @@ void test(int * i) { - *i = 5; + *i = 5; +} + +int main(int argc, char ** argv) { + return 0; } diff --git a/util/readelf.c b/util/readelf.c new file mode 100644 index 00000000..614eb431 --- /dev/null +++ b/util/readelf.c @@ -0,0 +1,9 @@ +/* + * ToAruOS Miniature ELF Reader + * + * vim:noexpandtab + * vim:tabstop=4 + */ + +/* The Master ELF Header */ +#include "../kernel/include/elf.h"