From 55365e593c27b57c50a7369597bd14f110ba8cb6 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Wed, 22 Oct 2014 21:21:32 +0200 Subject: reading userprogramm from ext2 ramimage! --- Makefile | 9 ++-- fs/Makefile | 16 ------ fs/ext2.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++- fs/fs.c | 2 + kernel/kernel.c | 7 ++- kernel/mem.c | 2 +- userspace/Makefile | 24 +++++++-- userspace/linker.ld | 2 +- userspace/syscalls.c | 7 ++- 9 files changed, 178 insertions(+), 34 deletions(-) delete mode 100644 fs/Makefile diff --git a/Makefile b/Makefile index 7c8cc91..2eb2077 100644 --- a/Makefile +++ b/Makefile @@ -102,16 +102,16 @@ FoolOS.img: $(MBR) $(STAGE2) kernel.bin $(FILLUP) FoolData.img cp $(FILLUP) $@ dd if=$(MBR) of=$@ bs=512 seek=0 conv=notrunc dd if=$(STAGE2) of=$@ bs=512 seek=1 conv=notrunc - dd if=kernel.bin of=$@ bs=512 seek=10 conv=notrunc + dd if=kernel.bin of=$@ bs=512 seek=10 conv=notrunc #will end up at 0x18000 in ram dd if=FoolData.img of=$@ bs=512 seek=842 conv=notrunc binfont.img: binfont.bin cat $^ > $@ -FoolData.img: binfont.bin $(MP_BIN) userspace/userprog +FoolData.img: binfont.bin $(MP_BIN) userspace/ext2.img dd if=$(MP_BIN) of=$@ bs=512 seek=0 conv=notrunc dd if=binfont.bin of=$@ bs=512 seek=1 conv=notrunc - dd if=userspace/userprog of=$@ bs=512 seek=4 conv=notrunc + dd if=userspace/ext2.img of=$@ bs=512 seek=4 conv=notrunc #will end up at 0x80800 in ram ############ vm stuff ############ @@ -131,10 +131,9 @@ clean: release: all -rm *.bin FoolData.img binfont.img bochs.log $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) $(FILLUP) $(MBR) $(MP_BIN) bochs.out ne2k-tx.log ne2k-txdump.txt $(STAGE2) -userspace/userprog: +userspace/ext2.img: make -C userspace - ############ test stuff ############ stick: FoolOS.img cat FoolOS.img > $(USB_STICK) && sync diff --git a/fs/Makefile b/fs/Makefile deleted file mode 100644 index d339621..0000000 --- a/fs/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -run: a.out - ./a.out < ext2.img -a.out: ext2.c - gcc ext2.c -std=c11 -filesys: - dd if=/dev/zero of=ext2.img bs=512 count=10000 - sudo mkfs.ext2 -O none ext2.img - mkdir mnt - sudo mount ext2.img mnt - sudo chown miguel mnt - mkdir mnt/miguel - echo "hello one" > mnt/miguel/test1.txt - echo "hello two" > mnt/test2.txt - sync - - diff --git a/fs/ext2.c b/fs/ext2.c index bc83f55..bdfb80b 100644 --- a/fs/ext2.c +++ b/fs/ext2.c @@ -1,7 +1,10 @@ // ext2 minidriver // based on osdev wiki article: http://wiki.osdev.org/Ext2 +#define FOOLOS_MODULE_NAME "ext2" + #include "lib/int/stdint.h" +#include "lib/logger/log.h" typedef struct ext2_superblock_struct { @@ -95,13 +98,149 @@ typedef struct ext2_inode_struct }ext2_inode; +void ram_read(char *in,char *out,int size, int count) +{ + for(int i=0;i=block_size) + { + block++; + + if(block>=12) + { + int indirect_block=block-12; + uint32_t *indirect_ptr=ram+block_size*inode.indirect1; + ptr=ram+block_size*indirect_ptr[indirect_block]; + + } + else + { + ptr=ram+block_size*inode.direct_pointer[block]; + } + + block_counter=0; + } + + + + } +// if(block>=12)panic(FOOLOS_MODULE_NAME,"such big files unsupported yet"); + + +} + + + +int ext2_read_root_dir(uint8_t *ram) +{ + + ext2_inode inode=ext2_get_inode(ram,2); + + char buf[256]; + int block_size=1024; + uint8_t *ptr=ram+block_size*inode.direct_pointer[0]; //use other pointers in future! + + int pos=0; + while(pos mnt/miguel/test1.txt + echo "hello two" > mnt/test2.txt + cp userprog mnt/shell + sync + sudo umount mnt + rm mnt -rf + +userprog: foolshell.o crt0.o ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o userprog + clean: - -rm *.o *.out userprog + -rm *.o *.out userprog ext2.img + + + diff --git a/userspace/linker.ld b/userspace/linker.ld index bfaae93..1d10d3e 100644 --- a/userspace/linker.ld +++ b/userspace/linker.ld @@ -1,4 +1,4 @@ SECTIONS { - . = 0x80800; + . = 0x100000; } diff --git a/userspace/syscalls.c b/userspace/syscalls.c index f92541c..b514eab 100644 --- a/userspace/syscalls.c +++ b/userspace/syscalls.c @@ -13,9 +13,11 @@ easywrite(char *c); void syscalls_init() { preread=0; - alloc=0xff0000; + alloc=0x500000; } +// + int close(int file) { // easywrite("syscall: close\n"); @@ -43,8 +45,6 @@ int lseek(int file, int ptr, int dir) return preread; } - - int read(int file, char *ptr, int len) { int ebx; // will hold return value; @@ -158,7 +158,6 @@ caddr_t sbrk(int incr) return (caddr_t) prev_heap_end; */ } - // // helpers -- cgit v1.2.3