diff --git a/init/main.c b/init/main.c index 71fe154..acab961 100644 --- a/init/main.c +++ b/init/main.c @@ -8,6 +8,7 @@ #include #include #include +#include typedef struct { char filename[100]; @@ -157,18 +158,22 @@ void test_vfs(char* path,uint32_t box,uint32_t fs_box) { free(msg.msg); } -int main(char* initrd, uint32_t initrd_sz) { +int main() { text_fb_info info; info.address=map_phys((void*)0xB8000,10); info.width=80; info.height=25; vga_init(info); vga_write_string("INIT\n"); + long size=initrd_sz(); + char* initrd=malloc(size); + initrd_get(initrd); uint32_t datapos=find_loc("vfs",initrd); load_task(datapos,initrd); yield(); // Bochs fails here datapos=find_loc("fsdrv",initrd); load_task(datapos,initrd); + free(initrd); yieldToPID(3); FILE* file; do { diff --git a/kernel/cpu/i386/isr.c b/kernel/cpu/i386/isr.c index 5a2c241..e92fa8f 100644 --- a/kernel/cpu/i386/isr.c +++ b/kernel/cpu/i386/isr.c @@ -4,7 +4,8 @@ #include #include "paging.h" #include "../halt.h" -#include "../..//vga_err.h" +#include "../../vga_err.h" +#include "../../kernel.h" #include "../tasking.h" #include "interrupt.h" #include "address_spaces.h" @@ -232,6 +233,12 @@ void isr_handler(registers_t r) { serial_write_string((char*)r.ebx); } else if (r.eax==17) { tasking_exit((uint8_t)r.ebx); + } else if (r.eax==18) { + serial_printf("Initrd size is %d bytes\n",initrd_sz); + r.ebx=initrd_sz; + } else if (r.eax==19) { + serial_printf("Copying initrd\n"); + memcpy((char*)r.ebx,initrd,initrd_sz); } break; } diff --git a/kernel/kernel.c b/kernel/kernel.c index b8bfd1c..2ad5eb9 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -20,8 +20,8 @@ typedef struct { char typeflag[1]; } tar_header; -static long initrd_sz; -static char* initrd; +long initrd_sz; +char* initrd; typedef int (*func_ptr)(); static struct multiboot_boot_header_tag* tags; @@ -102,10 +102,7 @@ void kmain(struct multiboot_boot_header_tag* hdr) { } copy_data(cr3,ptr,pheader.memsz,(void*)pheader.vaddr); } - char* initrd2=alloc_memory((initrd_sz/4096)+1); - memcpy(initrd2,initrd,initrd_sz); - initrd2=put_data(cr3,initrd2,initrd_sz); - createTaskCr3Param((void*)header.entry,cr3,(uint32_t)initrd2,initrd_sz); + createTaskCr3((void*)header.entry,cr3); exit(0); } } diff --git a/kernel/kernel.h b/kernel/kernel.h new file mode 100644 index 0000000..2a52c29 --- /dev/null +++ b/kernel/kernel.h @@ -0,0 +1,7 @@ +#ifndef KERNEL_H +#define KERNEL_H + +extern long initrd_sz; +extern char* initrd; + +#endif diff --git a/libc/initrd.c b/libc/initrd.c new file mode 100644 index 0000000..2c6f585 --- /dev/null +++ b/libc/initrd.c @@ -0,0 +1,15 @@ +long initrd_sz() { + long size; + asm volatile(" \ + mov $18, %%eax; \ + int $80; \ + ":"=b"(size)); + return size; +} + +void initrd_get(char* initrd) { + asm volatile(" \ + mov $19, %%eax; \ + int $80; \ + "::"b"(initrd)); +} diff --git a/sysroot/usr/include/initrd.h b/sysroot/usr/include/initrd.h new file mode 100644 index 0000000..f497047 --- /dev/null +++ b/sysroot/usr/include/initrd.h @@ -0,0 +1,7 @@ +#ifndef INITRD_H +#define INITRD_H + +long initrd_sz(); +void initrd_get(char* initrd); + +#endif