summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-10-11 02:14:52 +0200
committerMiguel <m.i@gmx.at>2018-10-11 02:14:52 +0200
commit8b33f268b67455ded8d35f3c198425562173fa2e (patch)
tree947e9b5503c0447f12f6d8d2c00c3b177dddef72
parente2005fda57ea4da12754d67ba127b09508125395 (diff)
almost cross compliing c++
-rw-r--r--fs/elf.c18
-rw-r--r--interface/crt0.s30
-rw-r--r--kernel/exceptions.c4
-rw-r--r--userspace/cpp/Makefile11
-rw-r--r--userspace/cpp/prep.cpp8
-rw-r--r--userspace/cpp/testcpp.cpp33
-rw-r--r--userspace/fsh.c2
-rw-r--r--userspace/init.c2
-rw-r--r--userspace/reent.c10
9 files changed, 101 insertions, 17 deletions
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;phidx<elf->e_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 <reent.h>
+#include <cstring>
+
+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 <algorithm>
+#include <vector>
+#include <cstdio>
+#include <iostream>
+
+void prep();
+void myinit();
+
+int main()
+{
+ prep();
+ myinit();
+
+ int myints[] = {32,71,12,45,26,80,53,33};
+ std::vector<int> 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<int>::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 <iostream>
#include <vector>
#include <cstring>
@@ -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 <string.h>
#include <errno.h>
#include <string.h>
+#include <reent.h>
#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<argc;i++)
{
diff --git a/userspace/init.c b/userspace/init.c
index 1592d39..84c47a5 100644
--- a/userspace/init.c
+++ b/userspace/init.c
@@ -2,10 +2,12 @@
#include <time.h>
#include "put_pixel.h"
#include "newcalls.h"
+#include <reent.h>
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 <stdio.h>
+#include <reent.h>
+
+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);
+}