From 8b33f268b67455ded8d35f3c198425562173fa2e Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 11 Oct 2018 02:14:52 +0200 Subject: almost cross compliing c++ --- fs/elf.c | 18 ++++++++---------- interface/crt0.s | 30 ++++++++++++++++++++++++++---- kernel/exceptions.c | 4 ++-- userspace/cpp/Makefile | 11 ++++++++++- userspace/cpp/prep.cpp | 8 ++++++++ userspace/cpp/testcpp.cpp | 33 +++++++++++++++++++++++++++++++++ userspace/fsh.c | 2 ++ userspace/init.c | 2 ++ userspace/reent.c | 10 ++++++++++ 9 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 userspace/cpp/prep.cpp create mode 100644 userspace/reent.c diff --git a/fs/elf.c b/fs/elf.c index a01f7c6..d91da60 100644 --- a/fs/elf.c +++ b/fs/elf.c @@ -99,13 +99,12 @@ uint32_t load_elf(char *name, uint32_t *alloc) uint32_t pos=0; klog("loading %s",name); - ext2_read_inode(ext2_ramimage,inode_nr,vaddr,&pos,4096*64); // max ignored?? + ext2_read_inode(ext2_ramimage,inode_nr,vaddr,&pos,4096*VMEM_USER_PROG_PAGES); // max ignored?? klog("ELF File loaded to final destination."); Elf32_Ehdr *elf; elf=vaddr; - if(elf->e_ident[0]!=0x7f||elf->e_ident[1]!='E'||elf->e_ident[2]!='L'||elf->e_ident[3]!='F') kpanic("ELF mismatch!?"); @@ -138,6 +137,13 @@ uint32_t load_elf(char *name, uint32_t *alloc) for(int phidx=0;phidxe_phnum;phidx++) { Elf32_Phdr *phdr=vaddr+elf->e_phoff+phidx*elf->e_phentsize; + klog("-- PROGRAMM HEADER %d --",phidx+1); + klog("p-type: %d",phdr->p_type); + klog("p-offset: 0x%08X",phdr->p_offset); + klog("p-vaddr: 0x%08X",phdr->p_vaddr); + klog("p-filesz: 0x%08X",phdr->p_filesz); + klog("p-memsz: 0x%08X",phdr->p_memsz); + if(phidx==0) { @@ -148,14 +154,6 @@ uint32_t load_elf(char *name, uint32_t *alloc) { - /* - klog("-- PROGRAMM HEADER %d --",phidx+1); - klog("p-type: %d",phdr->p_type); - klog("p-offset: 0x%08X",phdr->p_offset); - klog("p-vaddr: 0x%08X",phdr->p_vaddr); - klog("p-filesz: 0x%08X",phdr->p_filesz); - klog("p-memsz: 0x%08X",phdr->p_memsz); - */ klog("data: 0x%08X-0x%08X",phdr->p_vaddr,phdr->p_vaddr+phdr->p_filesz); klog("bss: 0x%08X-0x%08X",phdr->p_vaddr+phdr->p_filesz,phdr->p_vaddr+phdr->p_memsz); diff --git a/interface/crt0.s b/interface/crt0.s index c24d2d9..65123b7 100644 --- a/interface/crt0.s +++ b/interface/crt0.s @@ -1,9 +1,12 @@ .global _start +.global myinit //temporary quickfix / test _start: -push %ebx -push %ecx +// ALIGN stack + +//push %ebx +//push %ecx //cmp $0,_impure_ptr //jne skipzero @@ -19,6 +22,7 @@ push %ecx //skipzero: +/* mov _impure_ptr,%eax mov $0xf5000000,%ebx @@ -30,19 +34,33 @@ add $4, %eax cmp $0xf5001000,%ebx jne copy +*/ + movl $0xf5000000, _impure_ptr -pop %ecx -pop %ebx +//call _init # environment adress was passed on stack pop %eax mov %eax, environ +pop %ecx +pop %ebx + +and $-16,%esp +sub $8,%esp + +push %ebx +push %ecx + # call main (argc and argv are on the stack) call main +// ALIGN stack +and $-16,%esp +sub $4,%esp + # push exit code and pass to _exit syscall push %eax call exit @@ -51,3 +69,7 @@ call exit .wait: hlt jmp .wait + +myinit: +call _init +ret diff --git a/kernel/exceptions.c b/kernel/exceptions.c index 4ad87e8..8cb64cb 100644 --- a/kernel/exceptions.c +++ b/kernel/exceptions.c @@ -21,8 +21,8 @@ static void show_selector_error(uint32_t err) { klog("Selector Error Details:"); klog("External Event: %x",err&0b1); - klog("Location: 0x%x (0-GDT/1-IDT/2-LDT/3-IDT)",err&0b110); - klog("Selector: 0x%x",err&0b1111111111111000); + klog("Location: 0x%x (0-GDT/1-IDT/2-LDT/3-IDT)",(err&0b110)>>1); + klog("Selector: 0x%x",(err&0b1111111111111000)>>3); } static void show_page_fault_error(uint32_t error_code) diff --git a/userspace/cpp/Makefile b/userspace/cpp/Makefile index 7623325..9f4b314 100644 --- a/userspace/cpp/Makefile +++ b/userspace/cpp/Makefile @@ -1,6 +1,15 @@ CXX=i686-foolos-g++ -testcpp: +CFLAGS= +CFLAGS+=-O0 +CFLAGS+=-gstabs + +LDLIBS+=-lgcc + +ASFLAGS= +ASFLAGS+=-gstabs + +testcpp: prep.cpp clean: rm -f testcpp diff --git a/userspace/cpp/prep.cpp b/userspace/cpp/prep.cpp new file mode 100644 index 0000000..a09adbe --- /dev/null +++ b/userspace/cpp/prep.cpp @@ -0,0 +1,8 @@ +#include +#include + +void prep() +{ +_REENT_INIT_PTR(_impure_ptr); +} + diff --git a/userspace/cpp/testcpp.cpp b/userspace/cpp/testcpp.cpp index 0e89276..53e3a3b 100644 --- a/userspace/cpp/testcpp.cpp +++ b/userspace/cpp/testcpp.cpp @@ -1,4 +1,35 @@ +#include +#include +#include +#include + +void prep(); +void myinit(); + +int main() +{ + prep(); + myinit(); + + int myints[] = {32,71,12,45,26,80,53,33}; + std::vector myvector (myints, myints+8); // 32 71 12 45 26 80 53 33 + + // using default comparison (operator <): + std::sort (myvector.begin(), myvector.begin()+4); //(12 32 45 71)26 80 53 33 + + for (std::vector::iterator it=myvector.begin(); it!=myvector.end(); ++it) + printf("%i\n",*it); + printf("hello\n"); + +// printf("reent struct size: %d bytes\n",sizeof(struct _reent)); + // printf("reent pointer : 0x%08x\n",_impure_ptr); + //printf("reent pointer : 0x%08x\n",_impure_ptr); + std::cout << "bye bye" << std::endl; + printf("hello\n"); +} + // constructing vectors +/* #include #include #include @@ -8,6 +39,7 @@ int main() { + std::cout << "hi" << std::endl; _REENT_INIT_PTR(_impure_ptr); @@ -32,3 +64,4 @@ int main() return 0; } +*/ diff --git a/userspace/fsh.c b/userspace/fsh.c index 0b3acfd..86184e9 100644 --- a/userspace/fsh.c +++ b/userspace/fsh.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "interface/fs.h" #include "newcalls.h" @@ -59,6 +60,7 @@ void prompt() int main(int argc, char **argv) { + _REENT_INIT_PTR(_impure_ptr); for(int i=0;i #include "put_pixel.h" #include "newcalls.h" +#include int main(int argc, char **argv) { + _REENT_INIT_PTR(_impure_ptr); char *argv1[]={"xterm","/bin/fsh",0}; char *env1[]={"HOME=/home/miguel","PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0}; diff --git a/userspace/reent.c b/userspace/reent.c new file mode 100644 index 0000000..9011b1e --- /dev/null +++ b/userspace/reent.c @@ -0,0 +1,10 @@ +#include +#include + +int main() +{ + _REENT_INIT_PTR(_impure_ptr); + printf("reent struct size: %d bytes\n",sizeof(struct _reent)); + printf("reent pointer : 0x%08x\n",_impure_ptr); + printf("reent pointer : 0x%08x\n",_impure_ptr); +} -- cgit v1.2.3