diff --git a/libmaxsi/Makefile b/libmaxsi/Makefile
index 42dfe21f..1abc3d6c 100644
--- a/libmaxsi/Makefile
+++ b/libmaxsi/Makefile
@@ -2,8 +2,6 @@ ifndef CPU
CPU=x86
endif
-BINS=libc.a libg.a libmaxsi.a libmaxsi-sortix.a
-
ifeq ($(CPU),x86)
CPUDEFINES=-DPLATFORM_X86
CPUFLAGS=-m32
@@ -52,7 +50,6 @@ init.o \
signal.o \
$(CPU)/signal.o \
$(CPU)/fork.o \
-start.o \
time.o \
random.o \
abs.o \
@@ -165,6 +162,15 @@ putc.o \
rewind.o \
ungetc.o \
+CRTOBJ=\
+start.o \
+crt1.o \
+crti.o \
+crtn.o \
+
+MISCOBJ=\
+$(CRTOBJ) \
+
UNPROCHEADERDIRS:=$(shell find include -type d)
UNPROCHEADERS:=$(shell find include -type f)
HEADERDIRS:=$(patsubst include%,preproc%,$(UNPROCHEADERDIRS))
@@ -182,6 +188,8 @@ crc32.o \
SORTIXOBJS:=$(addprefix sortix/,$(SORTIXOBJS))
SORTIXCPPFLAGS:=-DSORTIX_KERNEL
+BINS=libc.a libg.a libmaxsi.a libmaxsi-sortix.a $(CRTOBJ)
+
all: $(BINS)
libmaxsi.a: $(OBJS)
@@ -206,7 +214,16 @@ libg.so: libc.so
ln -sf $< $@
start.o: $(CPU)/start.o
- ln -sf $< $@
+ ln -f $< $@
+
+crt1.o: $(CPU)/crt1.o
+ ln -f $< $@
+
+crti.o: $(CPU)/crti.o
+ ln -f $< $@
+
+crtn.o: $(CPU)/crtn.o
+ ln -f $< $@
# header preprocessing
$(HEADERDIRS):
@@ -246,10 +263,8 @@ install:
for D in $(UNPROCHEADERDIRS); do mkdir -p $(SYSROOT)/usr/$$D || exit $?; done
for SRC in $(HEADERS); do DEST=`echo $$SRC | sed 's/preproc/include/'`; cp $$SRC $(SYSROOT)/usr/$$DEST || exit $?; done
mkdir -p $(SYSROOT)/usr/include
- cp start.o $(SYSROOT)/usr/lib/crtbegin.o
touch deleteme.cpp
g++ $(CPUFLAGS) -c deleteme.cpp -o deleteme.o
- for F in crt0.o crtn.o crt1.o crtend.o crtbeginT.o crti.o; do cp deleteme.o $(SYSROOT)/usr/lib/$$F; done
for F in libgcc.so libm.so libstdc++.so; do ld $(CPULDFLAGS) -shared deleteme.o -o $(SYSROOT)/usr/lib/$$F; done
rm -f deleteme.o deleteme.cpp
diff --git a/libmaxsi/x64/crt1.s b/libmaxsi/x64/crt1.s
new file mode 100644
index 00000000..dfc7d244
--- /dev/null
+++ b/libmaxsi/x64/crt1.s
@@ -0,0 +1,54 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of LibMaxsi.
+
+ LibMaxsi is free software: you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with LibMaxsi. If not, see .
+
+ crt1.s
+ Implement the _start symbol at which execution begins which performs the
+ task of initializing the standard library and executing the main function.
+
+*******************************************************************************/
+
+/* NOTE: This is almost identical to what is in start.s. crt1.s is used when
+ compiling with the real cross compiler, while start.s is used when
+ using the older hacky way of building Sortix. Please try to keep these
+ files alike by doing changes both places until we only build Sortix
+ with real cross compilers. */
+
+.section .text
+
+.global _start
+.type _start, @function
+_start:
+ movq %rcx, environ # envp
+
+ # Prepare signals, memory allocation, stdio and such.
+ pushq %rsi
+ pushq %rdi
+ call initialize_standard_library
+
+ # Run the global constructors.
+ call _init
+
+ # Run main
+ popq %rdi
+ popq %rsi
+ call main
+
+ # Terminate the process with main's exit code.
+ movl %eax, %edi
+ call exit
diff --git a/libmaxsi/x64/crti.s b/libmaxsi/x64/crti.s
new file mode 100644
index 00000000..aeba7b1c
--- /dev/null
+++ b/libmaxsi/x64/crti.s
@@ -0,0 +1,39 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2012.
+
+ This file is part of LibMaxsi.
+
+ LibMaxsi is free software: you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with LibMaxsi. If not, see .
+
+ crti.s
+ Provides the header of the _init and _fini functions.
+
+*******************************************************************************/
+
+.section .init
+.global _init
+.type _init, @function
+_init:
+ push %rbp
+ movq %rsp, %rbp
+ /* gcc will nicely put the contents of crtbegin.o's .init section here. */
+
+.section .fini
+.global _fini
+.type _fini, @function
+_fini:
+ push %rbp
+ movq %rsp, %rbp
+ /* gcc will nicely put the contents of crtbegin.o's .fini section here. */
diff --git a/libmaxsi/x64/crtn.s b/libmaxsi/x64/crtn.s
new file mode 100644
index 00000000..345e495c
--- /dev/null
+++ b/libmaxsi/x64/crtn.s
@@ -0,0 +1,33 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2012.
+
+ This file is part of LibMaxsi.
+
+ LibMaxsi is free software: you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with LibMaxsi. If not, see .
+
+ crtn.s
+ Provides the tail of the _init and _fini functions.
+
+*******************************************************************************/
+
+.section .init
+ /* gcc will nicely put the contents of crtend.o's .init section here. */
+ popq %rbp
+ ret
+
+.section .fini
+ /* gcc will nicely put the contents of crtend.o's .fini section here. */
+ popq %rbp
+ ret
diff --git a/libmaxsi/x64/start.s b/libmaxsi/x64/start.s
index e6e6eedb..e2cd83ce 100644
--- a/libmaxsi/x64/start.s
+++ b/libmaxsi/x64/start.s
@@ -22,6 +22,12 @@
******************************************************************************/
+/* NOTE: This is almost identical to what is in crt1.s. crt1.s is used when
+ compiling with the real cross compiler, while start.s is used when
+ using the older hacky way of building Sortix. Please try to keep these
+ files alike by doing changes both places until we only build Sortix
+ with real cross compilers. */
+
.globl _start
.section .text
diff --git a/libmaxsi/x86/crt1.s b/libmaxsi/x86/crt1.s
new file mode 100644
index 00000000..48b3af29
--- /dev/null
+++ b/libmaxsi/x86/crt1.s
@@ -0,0 +1,54 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of LibMaxsi.
+
+ LibMaxsi is free software: you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with LibMaxsi. If not, see .
+
+ crt1.s
+ Implement the _start symbol at which execution begins which performs the
+ task of initializing the standard library and executing the main function.
+
+*******************************************************************************/
+
+/* NOTE: This is almost identical to what is in start.s. crt1.s is used when
+ compiling with the real cross compiler, while start.s is used when
+ using the older hacky way of building Sortix. Please try to keep these
+ files alike by doing changes both places until we only build Sortix
+ with real cross compilers. */
+
+.section .text
+
+.global _start
+.type _start, @function
+_start:
+ movl %ecx, environ # envp
+
+ # Arguments for main
+ push %ebx # argv
+ push %eax # argc
+
+ # Prepare signals, memory allocation, stdio and such.
+ call initialize_standard_library
+
+ # Run the global constructors.
+ call _init
+
+ # Run main
+ call main
+
+ # Terminate the process with main's exit code.
+ push %eax
+ call exit
diff --git a/libmaxsi/x86/crti.s b/libmaxsi/x86/crti.s
new file mode 100644
index 00000000..213f092e
--- /dev/null
+++ b/libmaxsi/x86/crti.s
@@ -0,0 +1,39 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2012.
+
+ This file is part of LibMaxsi.
+
+ LibMaxsi is free software: you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with LibMaxsi. If not, see .
+
+ crti.s
+ Provides the header of the _init and _fini functions.
+
+*******************************************************************************/
+
+.section .init
+.global _init
+.type _init, @function
+_init:
+ push %ebp
+ movl %esp, %ebp
+ /* gcc will nicely put the contents of crtbegin.o's .init section here. */
+
+.section .fini
+.global _fini
+.type _fini, @function
+_fini:
+ push %ebp
+ movl %esp, %ebp
+ /* gcc will nicely put the contents of crtbegin.o's .fini section here. */
diff --git a/libmaxsi/x86/crtn.s b/libmaxsi/x86/crtn.s
new file mode 100644
index 00000000..1a850924
--- /dev/null
+++ b/libmaxsi/x86/crtn.s
@@ -0,0 +1,33 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2012.
+
+ This file is part of LibMaxsi.
+
+ LibMaxsi is free software: you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with LibMaxsi. If not, see .
+
+ crtn.s
+ Provides the tail of the _init and _fini functions.
+
+*******************************************************************************/
+
+.section .init
+ /* gcc will nicely put the contents of crtend.o's .init section here. */
+ popl %ebp
+ ret
+
+.section .fini
+ /* gcc will nicely put the contents of crtend.o's .fini section here. */
+ popl %ebp
+ ret
diff --git a/libmaxsi/x86/start.s b/libmaxsi/x86/start.s
index 3fcbed0e..a71c4400 100644
--- a/libmaxsi/x86/start.s
+++ b/libmaxsi/x86/start.s
@@ -22,11 +22,16 @@
******************************************************************************/
+/* NOTE: This is almost identical to what is in crt1.s. crt1.s is used when
+ compiling with the real cross compiler, while start.s is used when
+ using the older hacky way of building Sortix. Please try to keep these
+ files alike by doing changes both places until we only build Sortix
+ with real cross compilers. */
+
.globl _start
.section .text
-.text 0x100000
.type _start, @function
_start: