Page 1 of 1

Proposed changes for os specific toolchain

Posted: Mon Oct 20, 2008 12:18 am
by uglyoldbob
I have some changes I want to propose for the os specific toolchain. It allows the newlib library to be used in the kernel and user space.

Binutils gets no changes.

For GCC, add these lines to the end of the gcc/config/myos.h
GCC suggests modifying libgcc/config.host in a similar manner to gcc/config.gcc

Code: Select all

#undef ENDFILE_SPEC
#define ENDFILE_SPEC "crtend.o%s \
				crtn.o%s"

#undef STARTFILE_SPEC
#define STARTFILE_SPEC "%{!shared: \
			 %{!symbolic: \
			  %{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}}}\
			crti.o%s \
			crtbegin.o%s"
For newlib, this is where I applied the most changes, although some are duplicate and could be eliminated.
Modify libgloss/configure.in and modify near the beginning so it looks like this.

Code: Select all

AC_CONFIG_SUBDIRS(libnosys)

case "${target}" in
  *-*-myos*)
	AC_CONFIG_SUBDIRS(myos)
	config_testsuite=true
	;;
  i[[3456]]86-*-elf* | i[[3456]]86-*-coff*)
	AC_CONFIG_SUBDIRS(i386)
	config_testsuite=true
	;;
Make the directory libgloss/myos and copy all files from the libnosys directory there.
Modify the libgloss/myos/Makefile.in and replace libnosys with libmyos.
Also modify this line to say the following.

Code: Select all

OUTPUTS = libmyos.a crti.o crtn.o
Modify CRT0.s to say this

Code: Select all

 .global _start
 .extern main
 .extern exit
 _start:
 call _init
 call main
 call exit
 .wait: hlt
 jmp .wait
Create files crti.s and crtn.s and put these in them.
CRTN.S

Code: Select all

	.section	.init,"ax"
        ret

	.section	.fini,"ax"
        ret
CRTI.S

Code: Select all

	.section	.init,"ax"
	.align 1
	.globl _init
_init:	

	.section	.fini,"ax"
	.align 1
	.globl _fini
_fini:	
Alrighty then. Once all that is complete and you get your cross-compiler compiled, here is the way it is setup to be used. For the kernel, overrides for the newlib glue functions are provided (no need for syscalls because the kernel IS the system). In the kernels linker script, the entry point will not be _start, although control will be passed to _start. The kernel entry point will setup anything that is required before the "regular" initializers get called (for example setup the screen, memory managment, etc). Then call/jump to _start. This method eliminates the need for hand-written language specific initializer code (support.c). I didn't have to use any special linker flags for the kernel either.
For usermode programs, nothing is required besides the usual command (system name)-gcc source.c.

I didn't want to modify the page myself. Let me know what you guys think.

Re: Proposed changes for os specific toolchain

Posted: Tue Nov 11, 2008 12:59 pm
by uglyoldbob
Hehe... This probably belongs in the Wiki category. Oops.