diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-10-22 21:21:32 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-10-22 21:21:32 +0200 |
| commit | 55365e593c27b57c50a7369597bd14f110ba8cb6 (patch) | |
| tree | c88de36646fd9ebee7ed270fbd35285417715fe7 | |
| parent | 95450710a8b8290a110686d78c2357d3920bcda5 (diff) | |
reading userprogramm from ext2 ramimage!
| -rw-r--r-- | Makefile | 9 | ||||
| -rw-r--r-- | fs/Makefile | 16 | ||||
| -rw-r--r-- | fs/ext2.c | 143 | ||||
| -rw-r--r-- | fs/fs.c | 2 | ||||
| -rw-r--r-- | kernel/kernel.c | 7 | ||||
| -rw-r--r-- | kernel/mem.c | 2 | ||||
| -rw-r--r-- | userspace/Makefile | 24 | ||||
| -rw-r--r-- | userspace/linker.ld | 2 | ||||
| -rw-r--r-- | userspace/syscalls.c | 7 |
9 files changed, 178 insertions, 34 deletions
@@ -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 - - @@ -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<size*count;i++) + { + out[i]=in[i]; + } - /* -int main() +} + +int ext2_check(uint8_t *ram) { ext2_superblock super; ext2_superblock_ext super_ext; + uint8_t *ptr=ram+1024; + ram_read(ptr,&super,sizeof(super),1); + if(super.ext2_sig!=0xef53)log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"no ext2 signature found, where ram-image expected!"); + //check version and req features. + // +} + +ext2_inode ext2_get_inode(uint8_t *ram,int inode_num) +{ + + // get basic shit from superblock! + ext2_superblock super; + ext2_blockgroup_desc desc; + ext2_inode inode; + + uint8_t *ptr=ram+1024; + ram_read(ptr,&super,sizeof(super),1); + if(super.ext2_sig!=0xef53)log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"no ext2 signature found, where ram-image expected!"); + + int block_group=(inode_num-1)/super.inodes_per_group; + + // get descrtptor for our blockgroup! + //TODO: only correct for 1024bytes/block. read more than one!!! + int block_size=1024; + int descriptor_start_block=2; + + ptr=ram+block_size*descriptor_start_block; + ptr+=sizeof(desc)*block_group; // skip to our descriptor; + + ram_read(ptr,&desc,sizeof(desc),1); // read descriptor + + // read our inode; + ptr=ram+block_size*desc.addr_inode_table; + ptr+=128*((inode_num-1)%super.inodes_per_group); + + ram_read(ptr,&inode,sizeof(inode),1); //get inode 2 (rood-directory) + + return inode; + +} + + +int ext2_inode_content(char *ram,int inode_nr,uint8_t *ramdest,int max) +{ + ext2_inode inode=ext2_get_inode(ram,inode_nr); + + int pos=0; + int block=0; + int block_size=1024; + int block_counter=0; + uint8_t *ptr=ram+block_size*inode.direct_pointer[0]; + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Loading %d %d bytes",inode.size_high, inode.size_low); + while(pos<inode.size_low) // use size high? + { + ramdest[pos]=*ptr; + ptr++; + block_counter++; + pos++; + if(block_counter>=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<inode.size_low) // use size high? + { + + ext2_dir dir; + ram_read(ptr,&dir,sizeof(dir),1); + ptr+=sizeof(dir); + + /* + printf("inode: %i\n",dir.inode); + printf("total size: %i\n",dir.size); + printf("length low/high: %i/%i\n\n",dir.name_length_low,dir.name_length_high); + */ + +// int l=fread(buf,sizeof(char),dir.name_length_low,stdin); + ram_read(ptr,&buf,sizeof(char),dir.name_length_low); + ptr+=dir.name_length_low; + + buf[dir.name_length_low]=0; + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d %s",dir.inode,buf); + ptr+=dir.size-8-dir.name_length_low; + pos+=dir.size; + + } + +} + +/* +int main() +{ + ext2_superblock super; + ext2_superblock_ext super_ext; printf("ext2 fools driver\n"); printf("reading superblock...\n\n"); @@ -24,3 +24,5 @@ int fs_readdir(const char *name,fs_dirent *dirs,int max) } + + diff --git a/kernel/kernel.c b/kernel/kernel.c index 1500919..42a2da2 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -159,7 +159,6 @@ void kernel_main(uint32_t initial_stack, int mp) //smp_start_aps(&procdata,0x80000); // starts at 0x80000 // but it will be copied over mbr - // // Activate Virtual Memory (paging) // @@ -203,8 +202,12 @@ void kernel_main(uint32_t initial_stack, int mp) // //vesa_init_doublebuff(); + ext2_check(0x80800); + ext2_read_root_dir(0x80800); + ext2_inode_content(0x80800,15,0x100000,0x100000); + // autorun "user-space" prog - asm("push $0x80800"); + asm("push $0x100000"); asm("ret"); // Just hang around here, if its reached. diff --git a/kernel/mem.c b/kernel/mem.c index af58877..00b6a90 100644 --- a/kernel/mem.c +++ b/kernel/mem.c @@ -225,7 +225,7 @@ void mem_init(uint16_t *memmap,uint16_t entries) } // here is somewhere our kernel stuff ;) // todo!! better. - pmmngr_deinit_region(0x0,0xfffff); + pmmngr_deinit_region(0x0,0x300000); // and here is the memory map that we JUST created! pmmngr_deinit_region(_mmngr_memory_map,mem_array_size*4); diff --git a/userspace/Makefile b/userspace/Makefile index fc5e2dd..11eaa74 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -3,12 +3,30 @@ CC=i686-elf-gcc LD=i686-elf-ld -CFLAGS=-I/home/miguel/temp/fool-os-stuff/newlib-2.1.0/newlib/libc/include +CFLAGS=-I/home/miguel/temp/fool-os-stuff/newlib-2.1.0/newlib/libc/include LDFLAGS=-L/home/miguel/temp/fool-os-stuff/newlib-build-clean/i686-elf/newlib/ \ -L/home/miguel/temp/fool-os-stuff/newlib-build-clean/i686-elf/libgloss/libnosys/ \ -lnosys -all: foolshell.o crt0.o +ext2.img: userprog + dd if=/dev/zero of=ext2.img bs=512 count=200 + 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 + 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 |
