From a822afc278e7855dea55bcd0de2e402d5bf43508 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Thu, 20 Nov 2014 23:28:17 +0100 Subject: fixed loading and runnnng progs (clear bss) --- userspace/Makefile | 8 ++++---- userspace/add.c | 39 +++++---------------------------------- userspace/crt0.S | 14 ++++++++++++++ userspace/linker.ld | 21 +++++++++++++++++++++ userspace/simple.c | 3 +-- userspace/syscalls.c | 2 +- 6 files changed, 46 insertions(+), 41 deletions(-) (limited to 'userspace') diff --git a/userspace/Makefile b/userspace/Makefile index 564ffe0..18b5ded 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -26,16 +26,16 @@ ext2.img: shell simple brainfuck add rm mnt -rf brainfuck: brainfuck.o crt0.o - ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o brainfuck + ${CC} -T linker.ld ${LDFLAGS} $< -o $@ shell: foolshell.o crt0.o - ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o shell + ${CC} -T linker.ld ${LDFLAGS} $< -o $@ simple: simple.o crt0.o - ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o simple + ${CC} -T linker.ld ${LDFLAGS} $< -o $@ add: add.o crt0.o - ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o add + ${CC} -T linker.ld ${LDFLAGS} $< -o $@ clean: -rm *.o *.out shell simple ext2.img brainfuck add diff --git a/userspace/add.c b/userspace/add.c index 8f1dc56..254ee35 100644 --- a/userspace/add.c +++ b/userspace/add.c @@ -6,47 +6,18 @@ int main(int argc, char **argv) { - sbrk(1024); - sbrk(1024); - sbrk(1024); - write(1,"dupa",4); - puts("started ADD"); + FILE *input; + input=fopen("input2.txt","r"); //stdin - while(1); -// FILE *input; -// input=fopen("input2.txt","r"); //stdin -/* int sum=0; int i=0; - while(1); - char *buf=malloc(256); - //printf("(buf= 0x%08X)\n",buf); - - - - while(1) - { - char *ret=gets(buf); - if(ret==NULL) - { - printf("returned NULL. ABORTING"); - break; - } - printf("entered %s: ",buf); - - //buf[strlen(buf)-1]=0; // remove \n - //process(buf); - } - - while(1) { - printf("enter numer %i: ",i+1); + printf("enter numer (or 'exit' to finish) %i: ",i+1); fgets(buf,255,input); - printf("entered %s: ",buf); if(buf[1]=='x')break; @@ -54,10 +25,10 @@ int main(int argc, char **argv) sum+=atoi(buf); } + printf("sum = %i \n",sum); printf("avg = %i \n\n",sum/i); -*/ - execve(15,0,0); + return 0; } diff --git a/userspace/crt0.S b/userspace/crt0.S index 9f7dab1..e3bfa3b 100644 --- a/userspace/crt0.S +++ b/userspace/crt0.S @@ -1,9 +1,23 @@ .global _start + .extern main .extern exit + _start: + +push $0 +call sbrk + +push $[_BSS_END_] +call sbrk + call main + + +push %eax call _exit + +# this should never be reached anyway! .wait: hlt jmp .wait diff --git a/userspace/linker.ld b/userspace/linker.ld index 9fe0ac2..4eee8eb 100644 --- a/userspace/linker.ld +++ b/userspace/linker.ld @@ -1,4 +1,25 @@ +OUTPUT_FORMAT(binary) + SECTIONS { . = 0x800000; + + .text : ALIGN(0x1000) { + _TEXT_START_ = .; + *(.text) + _TEXT_END_ = .; + } + + .data : ALIGN(0x1000) { + _DATA_START_ = .; + *(.data) + _DATA_END_ = .; + } + + .bss : ALIGN(0x1000) { + _BSS_START_ = .; + *(.bss) + _BSS_END_ = .; + } + } diff --git a/userspace/simple.c b/userspace/simple.c index e3bca65..6dcf766 100644 --- a/userspace/simple.c +++ b/userspace/simple.c @@ -11,8 +11,7 @@ int main(int argc, char **argv) } - // replace with foolshell after finishing! - execve(15,0,0); + return 0; } diff --git a/userspace/syscalls.c b/userspace/syscalls.c index fd9b5ba..8c8bfc9 100644 --- a/userspace/syscalls.c +++ b/userspace/syscalls.c @@ -12,7 +12,7 @@ char **environ={__env1,__env2,__env3}; void _exit(int ret) { - while(1); + return syscall(SYSCALL_EXIT,ret,0,0); } // generic syscall interface! -- cgit v1.2.3