[bin] Working on ELF binaries. Redid some multiboot stuff (larger ramdisks should work now)
This commit is contained in:
parent
148f1aa995
commit
9b3c3a1e60
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@ toaruos-initrd
|
||||
bootloader/stage1.bin
|
||||
bootloader/stage2.bin
|
||||
initrd/boot
|
||||
initrd/bin/*
|
||||
.gdb_history
|
||||
bootdisk.img
|
||||
*.log
|
||||
|
27
Makefile
27
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
|
||||
|
0
initrd/bin/.dummy
Normal file
0
initrd/bin/.dummy
Normal file
@ -1,6 +1,9 @@
|
||||
#include <system.h>
|
||||
#include <multiboot.h>
|
||||
|
||||
char * ramdisk = NULL;
|
||||
struct multiboot * mboot_ptr = NULL;
|
||||
|
||||
struct multiboot *
|
||||
copy_multiboot(
|
||||
struct multiboot *mboot_ptr
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
#include <system.h>
|
||||
#include <fs.h>
|
||||
#include <multiboot.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
22
kernel/include/elf.h
Normal file
22
kernel/include/elf.h
Normal file
@ -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 <types.h>
|
||||
#else
|
||||
# ifdef BOOTLOADER
|
||||
# include <types.h>
|
||||
# else
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
13
loader/crtbegin.s
Normal file
13
loader/crtbegin.s
Normal file
@ -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
|
47
loader/link.ld
Normal file
47
loader/link.ld
Normal file
@ -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)
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
void test(int * i) {
|
||||
*i = 5;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
9
util/readelf.c
Normal file
9
util/readelf.c
Normal file
@ -0,0 +1,9 @@
|
||||
/*
|
||||
* ToAruOS Miniature ELF Reader
|
||||
*
|
||||
* vim:noexpandtab
|
||||
* vim:tabstop=4
|
||||
*/
|
||||
|
||||
/* The Master ELF Header */
|
||||
#include "../kernel/include/elf.h"
|
Loading…
Reference in New Issue
Block a user