summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asm/int_syscall_handler.asm16
-rw-r--r--fs/ext2.c59
-rw-r--r--kernel/config.h2
-rw-r--r--kernel/kernel.c6
-rw-r--r--kernel/syscalls.c91
-rw-r--r--kernel/syscalls.h10
-rw-r--r--userspace/Makefile6
-rw-r--r--userspace/checker.c19
8 files changed, 127 insertions, 82 deletions
diff --git a/asm/int_syscall_handler.asm b/asm/int_syscall_handler.asm
index 3ffdd25..f90ba51 100644
--- a/asm/int_syscall_handler.asm
+++ b/asm/int_syscall_handler.asm
@@ -11,6 +11,8 @@ global int_syscall_handler
[extern syscall_isatty]
[extern syscall_lseek]
[extern syscall_sbrk]
+[extern syscall_stat]
+[extern syscall_lstat]
[extern syscall_unhandled]
[bits 32]
@@ -55,6 +57,12 @@ int_syscall_handler:
cmp eax, 70
je call_sbrk
+ cmp eax, 74
+ je call_stat
+
+ cmp eax, 79
+ je call_lstat
+
push eax
jmp call_unhandled
@@ -81,6 +89,14 @@ done_blocking:
iret ;Interrupt-Return
+call_stat:
+ call syscall_stat
+ jmp done
+
+call_lstat:
+ call syscall_lstat
+ jmp done
+
call_write:
call syscall_write
jmp done
diff --git a/fs/ext2.c b/fs/ext2.c
index 27fe31e..7322da2 100644
--- a/fs/ext2.c
+++ b/fs/ext2.c
@@ -153,6 +153,31 @@ ext2_inode ext2_get_inode(uint8_t *ram,int inode_num)
}
+void* ext2_get_blockstart(void* start, uint32_t block_size, uint32_t block_idx)
+{
+ return (start+block_size*block_idx);
+}
+
+void* ext2_get_indirectstart(void *start, uint32_t block_size, uint32_t indirect1_idx, uint32_t block_idx)
+{
+ uint32_t *indirect_ptr=ext2_get_blockstart(start,block_size,indirect1_idx);
+ void *ptr=ext2_get_blockstart(start,block_size,indirect_ptr[block_idx]);
+ return ptr;
+}
+
+void* ext2_get_indirectstart_double(void *start, uint32_t block_size, uint32_t indirect2_idx, uint32_t block_idx)
+{
+
+ //doubly indirect list
+ uint32_t *dil=ext2_get_blockstart(start,block_size,indirect2_idx);
+
+ int indirect1_idx=block_idx/(block_size/4);
+ int idx=block_idx%(block_size/4);
+
+ //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"bl: %d : %d / %d",block_idx,indirect1_idx, idx);
+
+ return ext2_get_indirectstart(start,block_size,dil[indirect1_idx],idx);
+}
int ext2_inode_content(char *ram,int inode_nr,uint8_t *ramdest,int max)
{
@@ -162,31 +187,48 @@ int ext2_inode_content(char *ram,int inode_nr,uint8_t *ramdest,int max)
int block=0;
int block_size=1024;
int block_counter=0;
- uint8_t *ptr=ram+block_size*inode.direct_pointer[0];
+ uint8_t *ptr=ext2_get_blockstart(ram,block_size,inode.direct_pointer[0]);
+ int sum=0;
+ int count=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?
+
+ while(pos<inode.size_low) // TODO: use size high!
{
ramdest[pos]=*ptr;
+
+ sum = (sum >> 1) + ((sum & 1) << 15);
+ sum+=(int)*ptr;
+ sum&=0xffff;
+ count++;
ptr++;
block_counter++;
pos++;
+
if(block_counter>=block_size)
{
block++;
- if(block>=12)
+ 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];
+ ptr=ext2_get_blockstart(ram,block_size,inode.direct_pointer[block]);
}
+ else if(block-12<block_size/4)
+ {
+ ptr=ext2_get_indirectstart(ram,block_size,inode.indirect1,block-12);
+ }
+
+ else if(block-12-block_size/4<1024/4*1024/4)
+ {
+ ptr=ext2_get_indirectstart_double(ram,block_size,inode.indirect2,block-12-block_size/4);
+ }
else
{
- ptr=ram+block_size*inode.direct_pointer[block];
+ panic(FOOLOS_MODULE_NAME,"Triplu Indirect Block Pointers not supported yet, file is too big to load, sorry!");
}
+
block_counter=0;
}
@@ -194,7 +236,8 @@ int ext2_inode_content(char *ram,int inode_nr,uint8_t *ramdest,int max)
}
-// if(block>=12)panic(FOOLOS_MODULE_NAME,"such big files unsupported yet");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Fool Check Sum: 0x%08X for %d bytes",sum,count);
+
}
int ext2_read_dir(uint8_t *ram, int inode_nr,fs_dirent *dirs,int max)
diff --git a/kernel/config.h b/kernel/config.h
index e48c63c..ef0fa71 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -6,7 +6,7 @@
//#define FOOLOS_COMPILE_FLOPPY // compile floppy drivers
#define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line
-#define FOOLOS_LOG_OFF // do not log anything
+//#define FOOLOS_LOG_OFF // do not log anything
#define FOOLOS_CONSOLE // otherwise VESA will be used!
#define MEM_PRINT_MEMORYMAP
#define LOG_BUF_SIZE 4069
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 6daa625..f788cee 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -5,7 +5,7 @@
*/
#ifdef __linux__
-#error "watchout! this is not linux but FoolOS. Use a cross-compiler"
+#error "Watchout! this is not Linux but FoolOS. Use a cross-compiler"
#endif
#define FOOLOS_MODULE_NAME "kernel"
@@ -36,10 +36,6 @@
#include "task.h"
-#ifdef FOOLOS_COMPILE_FLOPPY
-#include "floppy.h"
-#endif
-
//
// KERNEL MAIN
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 9ad07e2..0e4ee66 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -79,6 +79,20 @@ int syscall_unhandled(int nr)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"syscall: %d", nr);
panic(FOOLOS_MODULE_NAME,"unhandled syscall");
}
+
+int syscall_lseek(int file,int ptr,int dir)
+{
+
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"lseek (file=%d, ptr=%d, dir=%d)", file,ptr,dir);
+ #endif
+
+ panic(FOOLOS_MODULE_NAME,"unhandled syscall");
+
+ return 0;
+
+}
+
int syscall_write(int file, char *buf, int len)
{
@@ -86,6 +100,8 @@ int syscall_write(int file, char *buf, int len)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"write(file=%d, buf=0x%08X, len=%d)", file,buf,len);
#endif
+ if(file!=1&&file!=2) panic(FOOLOS_MODULE_NAME,"unhandled syscall");
+
// ALL output to stdout
for(int i=0;i<len;i++)
{
@@ -103,8 +119,9 @@ int syscall_read(int file, char *buf, int len)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"read(file=%d, buf=0x%08X, len=%d)", file,buf,len);
#endif
+ if(file!=0) panic(FOOLOS_MODULE_NAME,"unhandled syscall");
+
// stdin TODO: other descroptiors!
- if(file==1||file!=1)
{
char c;
@@ -127,7 +144,7 @@ int syscall_read(int file, char *buf, int len)
}
-
+//TODO: replace with dirent!
int syscall_readdir(const char *name,fs_dirent *dirs,int max)
{
#ifdef LOG_SYSCALLS
@@ -214,11 +231,16 @@ int syscall_execve(char *name, char **argv, char **env)
// iterate over section headers
for(int phidx=0;phidx<elf->e_phnum;phidx++)
{
+ Elf32_Phdr *phdr=0x800000+elf->e_phoff+phidx*elf->e_phentsize;
+
+ if(phidx==0)
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"text: 0x%08X-0x%08X",phdr->p_vaddr,phdr->p_vaddr+phdr->p_filesz);
+ }
if(phidx==1)
{
- Elf32_Phdr *phdr=0x800000+elf->e_phoff+phidx*elf->e_phentsize;
/*
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"-- PROGRAMM HEADER %d --",phidx+1);
@@ -229,6 +251,7 @@ int syscall_execve(char *name, char **argv, char **env)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"p-memsz: 0x%08X",phdr->p_memsz);
*/
+
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"data: 0x%08X-0x%08X",phdr->p_vaddr,phdr->p_vaddr+phdr->p_filesz);
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"bss: 0x%08X-0x%08X",phdr->p_vaddr+phdr->p_filesz,phdr->p_vaddr+phdr->p_memsz);
@@ -270,8 +293,8 @@ int syscall_open(char *name, int flags, int mode)
#ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"open (name=0x%08X(\"%s\"), flags=%d, mode=%d)",name, name,flags,mode);
#endif
+ panic(FOOLOS_MODULE_NAME,"unhandled syscall");
- return 99;
}
@@ -284,10 +307,13 @@ int syscall_close(int file,int none1,int none2)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"close (file=%d)", file);
#endif
+ if(file!=0&&file!=1&&file!=2)
+ panic(FOOLOS_MODULE_NAME,"unhandled syscall");
+
return -1;
}
-
+// TODO: check if file is termminal!
int syscall_isatty(int file,int none1,int none2)
{
#ifdef LOG_SYSCALLS
@@ -297,44 +323,9 @@ int syscall_isatty(int file,int none1,int none2)
return 1;
}
-
-int syscall_lseek(int file,int ptr,int dir)
-{
-
- #ifdef LOG_SYSCALLS
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"lseek (file=%d, ptr=%d, dir=%d)", file,ptr,dir);
- #endif
-/*
- if(dir==0)preread=ptr;
- else{ while(1);}
-*/
- return 0;
-
-}
-
-
uint32_t syscall_sbrk(int incr, int none1, int none2)
{
-
- // fool-os-convention to set bss_end:
- /*
- if(incr==0)
- {
- alloc=0;
- return 0;
- }
- if(alloc==0)
- {
- #ifdef LOG_SYSCALLS
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"sbrk RESET to 0x%08X", incr);
- #endif
-
- alloc=incr;
- return alloc;
- }
- */
-
uint32_t oldalloc=alloc;
alloc+=incr;
@@ -344,26 +335,6 @@ uint32_t syscall_sbrk(int incr, int none1, int none2)
return oldalloc;
- /*
-
- extern char end;
-// char _end;
- static char *heap_end;
- char *prev_heap_end;
-
- if (heap_end == 0) {
- heap_end = &end;
- }
- prev_heap_end = heap_end;
-
- if (heap_end + incr > stack_ptr) {
- write (1, "Heap and stack collision\n", 25);
- abort ();
- }
-
- heap_end += incr;
- return (caddr_t) prev_heap_end;
- */
}
diff --git a/kernel/syscalls.h b/kernel/syscalls.h
index f42a34b..432bd2c 100644
--- a/kernel/syscalls.h
+++ b/kernel/syscalls.h
@@ -18,20 +18,20 @@
#define SYSCALL_ISATTY 68
#define SYSCALL_LSEEK 69
#define SYSCALL_SBRK 70
+#define SYSCALL_STAT 74
+#define SYSCALL_LSTAT 79
// stubs only so far!
#define SYSCALL_GETTIMEOFDAY 71
#define SYSCALL_FORK 72
#define SYSCALL_KILL 73
#define SYSCALL_LINK 73
-#define SYSCALL_STAT 74
#define SYSCALL_TIMES 75
#define SYSCALL_UNLINK 76
#define SYSCALL_WAIT 77
#define SYSCALL_GETPID 78
-#define SYSCALL_LSTAT 79
-
+/*
int syscall_readdir(const char *name,struct fs_dirent *dirs,int max);
int syscall_exit(int ret, int none1, int none2);
@@ -43,6 +43,7 @@ int syscall_close(int file,int none1,int none2);
int syscall_fstat(int file, struct stat *st,int none);
int syscall_isatty(int file,int none1,int none2);
int syscall_lseek(int file,int ptr,int dir);
+int syscall_stat(char *file, struct stat *st);
int syscall_sbrk(int incr, int none1, int none2);
//
int syscall_gettimeofday(struct timeval *tv, struct timezone *tz);
@@ -50,7 +51,6 @@ int syscall_fork(void);
int syscall_getpid(void);
int syscall_kill(int pid, int sig);
int syscall_link(char *old, char *ne);
-int syscall_stat(char *file, struct stat *st);
int syscall_times(struct tms *buf);
int syscall_unlink(char *name);
int syscall_wait(int *status);
@@ -58,7 +58,7 @@ int syscall_wait(int *status);
int syscall_unhandled(int nr);
-
+*/
diff --git a/userspace/Makefile b/userspace/Makefile
index 7e35096..74ced40 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -1,7 +1,7 @@
CC=i686-foolos-gcc
CFLAGS=-w
-PROGS=shell simple brainfuck add
+PROGS=shell simple brainfuck add checker
ext2.img: $(PROGS)
dd if=/dev/zero of=ext2.img bs=512 count=5000
@@ -13,8 +13,7 @@ ext2.img: $(PROGS)
echo "hello one" > mnt/miguel/test1.txt
echo "hello two" > mnt/test2.txt
cp $^ mnt
- cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/elfedit mnt
-# cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/objdump mnt
+ cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/readelf mnt
sync
sudo umount mnt
rm mnt -rf
@@ -23,6 +22,7 @@ brainfuck: brainfuck.o
shell: shell.o
simple: simple.o
add: add.o
+checker: checker.o
clean:
-rm *.o $(PROGS) ext2.img
diff --git a/userspace/checker.c b/userspace/checker.c
new file mode 100644
index 0000000..e5352f6
--- /dev/null
+++ b/userspace/checker.c
@@ -0,0 +1,19 @@
+#include <stdio.h>
+
+int main()
+
+{
+FILE *fp; /* The file handle for input data */
+fp=stdin;
+int ch; /* Each character read. */
+int checksum = 0; /* The checksum mod 2^16. */
+int count=0;
+
+while ((ch = getc(fp)) != EOF) {
+ checksum = (checksum >> 1) + ((checksum & 1) << 15);
+ checksum +=(int) ch;
+ checksum &= 0xffff; /* Keep it within bounds. */
+ count++;
+}
+printf("checksum : 0x%08X for %i bytes\n",checksum,count);
+}