From 32075c0a70c262faef86220b9f42db4836962f9e Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 16 Sep 2021 06:50:15 +0000 Subject: scaffolding for the initrd: init can read files appended to it currently this is just a text file, but it will be a tar archive later on --- Makefile | 6 +++++- fake_initrd.txt | 1 + src/init/linker.ld | 4 ++++ src/init/main.c | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 fake_initrd.txt diff --git a/Makefile b/Makefile index 9a758cf..def6452 100644 --- a/Makefile +++ b/Makefile @@ -44,10 +44,14 @@ out/fs/boot/kernel.bin: src/kernel/linker.ld $(call from_sources, src/kernel/) @$(CC) $(LFLAGS) -T $^ -o $@ grub-file --is-x86-multiboot $@ -out/fs/boot/init: src/init/linker.ld $(call from_sources, src/init/) +out/raw_init: src/init/linker.ld $(call from_sources, src/init/) @mkdir -p $(@D) @$(CC) $(LFLAGS) -T $^ -o $@ +out/fs/boot/init: out/raw_init fake_initrd.txt + @mkdir -p $(@D) + @cat $^ > $@ + out/fs/boot/grub/grub.cfg: grub.cfg @mkdir -p $(@D) @cp $< $@ diff --git a/fake_initrd.txt b/fake_initrd.txt new file mode 100644 index 0000000..77a9fda --- /dev/null +++ b/fake_initrd.txt @@ -0,0 +1 @@ +i am NOT a real initrd. diff --git a/src/init/linker.ld b/src/init/linker.ld index efb44fd..f2c9d24 100644 --- a/src/init/linker.ld +++ b/src/init/linker.ld @@ -17,6 +17,10 @@ SECTIONS { *(.data) } + + _initrd = .; /* is just appended onto the end of the binary */ + . += 2M; + _bss_start = .; .bss BLOCK(4K) : ALIGN(4K) { diff --git a/src/init/main.c b/src/init/main.c index 265379d..db94d4a 100644 --- a/src/init/main.c +++ b/src/init/main.c @@ -8,6 +8,7 @@ extern char _bss_start; // provided by the linker extern char _bss_end; +extern char _initrd; int tty_fd; @@ -24,6 +25,8 @@ int main(void) { _syscall_exit(argify("couldn't open tty")); fs_test(); + + _syscall_write(tty_fd, &_initrd, 23); _syscall_exit(argify("my job here is done.")); } -- cgit v1.2.3