diff options
| author | Franklin Wei <frankhwei536@gmail.com> | 2015-03-02 21:37:09 -0500 |
|---|---|---|
| committer | Franklin Wei <frankhwei536@gmail.com> | 2015-03-02 21:37:09 -0500 |
| commit | 46e94578765d3d2f03b83421d752e5dfc3e56d34 (patch) | |
| tree | 0a7d4187e8e62e1fccdf0dc8ee89e4ffcdf7aac7 | |
| parent | 35d98182c5b86c25eb4e7fd18fc68f240683960b (diff) | |
| download | kappa-46e94578765d3d2f03b83421d752e5dfc3e56d34.zip kappa-46e94578765d3d2f03b83421d752e5dfc3e56d34.tar.gz kappa-46e94578765d3d2f03b83421d752e5dfc3e56d34.tar.bz2 kappa-46e94578765d3d2f03b83421d752e5dfc3e56d34.tar.xz | |
initrd support, not used yet
| -rw-r--r-- | docs/INITRD | 6 | ||||
| -rw-r--r-- | include/kernel/initrd.h | 4 | ||||
| -rw-r--r-- | initrd | bin | 0 -> 7154 bytes | |||
| -rw-r--r-- | kernel/initrd.c | 53 | ||||
| -rw-r--r-- | tools/mkinitrd.c | 34 |
5 files changed, 97 insertions, 0 deletions
diff --git a/docs/INITRD b/docs/INITRD new file mode 100644 index 0000000..228c717 --- /dev/null +++ b/docs/INITRD @@ -0,0 +1,6 @@ +struct file_t +{ +char name[32]; +int size; +char data[size]; +}; diff --git a/include/kernel/initrd.h b/include/kernel/initrd.h new file mode 100644 index 0000000..c7a368c --- /dev/null +++ b/include/kernel/initrd.h @@ -0,0 +1,4 @@ +#include "multiboot.h" + +void initrd_init(struct multiboot_info_t*); +void initrd_read(void); Binary files differdiff --git a/kernel/initrd.c b/kernel/initrd.c new file mode 100644 index 0000000..c34bcfa --- /dev/null +++ b/kernel/initrd.c @@ -0,0 +1,53 @@ +#include <stddef.h> +#include <stdio.h> +#include "heap.h" +#include "multiboot.h" +#include "panic.h" + +static struct multiboot_mod_t *modlist; +static unsigned int mods_count; + +void initrd_read(void) +{ + if(modlist && mods_count) + { + printf("Number of modules: %d\n", mods_count); + char *ptr = (char*)modlist[0].mod_start; + while(ptr < (char*)modlist[0].mod_end) + { + char *name = ptr; + ptr += 32; + uint32_t sz = *(uint32_t*)ptr; + ptr += 4; + printf("File name: \"%s\"\n", name); + printf("File length: %x\n", sz); + char *end = ptr + sz; + printf("Contents:\n"); + while(ptr < end) + { + putchar(*ptr++); + } + } + } + else + { + printf("No initrd loaded!\n"); + } +} + +void initrd_init(struct multiboot_info_t *hdr) +{ + if(hdr->flags & (1<<3)) + { + modlist = (struct multiboot_mod_t*)hdr->mods_addr; + mods_count = hdr->mods_count; + printf("Number of modules: %d\n", mods_count); + /* prevent kmalloc from overwriting the modules */ + kmalloc_set_addr(modlist[mods_count-1].mod_end); + } + else + { + modlist = NULL; + mods_count = 0; + } +} diff --git a/tools/mkinitrd.c b/tools/mkinitrd.c new file mode 100644 index 0000000..d61bbba --- /dev/null +++ b/tools/mkinitrd.c @@ -0,0 +1,34 @@ +#include <assert.h> +#include <stdio.h> +#include <stdint.h> +#include <unistd.h> +#include <fcntl.h> + +void write_le32(int fd, uint32_t n) +{ + write(fd, &n, 4); +} + +#define MIN(x,y) (x<y?x:y) + +int main(int argc, char* argv[]) +{ + int fd = open("initrd.img", O_APPEND | O_WRONLY | O_CREAT, 0666); + char buf[32]; + assert(strlen(argv[1]) < 32); + memset(buf, 0, 32); + memcpy(buf, argv[1], strlen(argv[1])); + write(fd, buf, 32); + int datafd = open(argv[1], O_RDONLY, 0666); + lseek(datafd, 0, SEEK_END); + FILE *f = fdopen(datafd, "rb"); + uint32_t len = ftell(f); + write_le32(fd, ftell(f)); + int ch; + lseek(datafd, 0, SEEK_SET); + do { + ch = getc(f); + if(ch != EOF) + write(fd, &ch, 1); + } while(ch != EOF); +} |