By the way - my segmenting problem has disappeared without delving into compiler internals. I think someone has added the correct segment prefix overrides when generating x86 code, and that has fixed my problem. I'm not going to investigate exactly who fixed what; I'm just happy that it works. Now I can concentrate on writing user code, and fixing the kernel when it breaks. Things are starting to move ahead, and there is light at the end of the tunnel. I have loadable modules that load (using GRUB). I can then parse the elf header, map the various elf segments to virtual memory addresses, and execute them. If I don't use stdlib it works great. My next job is to figure out why I can link with stdlib, but printf doesn't print. I can call puts() and it works just fine (which is a user-space function that calls a kernel-space function) so I know the overall mechanism is ok - I wonder why printf doesn't work. It may have to do with me not porting newlib as I should have.
Monday, June 1, 2009
GCC versions and features
Just a quick update:
I have finally managed to get multitasking working. It was working before, but not exactly what I wanted - now it runs all in user mode. So to try it out, I created 2 loadable modules for GRUB, so I could see how to load an executable. The modules are elf executables that I created with my newly ported GCC 4.3.3. Everything went well until link time. Then I discovered that I needed a file called crt0.o. It's a bit hard to find information on this file, because its standard, but OS specific. Anyway, again thanks to the guys as OSDEV I ported newlib (stdclib) and created the crt0.o file as well. So then I was suprised to find out that I needed 2 more files - crtbegin.o and crtend.o. These are even harder to find information about, and to this day I am not clear on their responsibilities, and how it is different from crt0.o. I think it has to do with C++, but my load modules are written in pure C, so I don't really know why I need them. Well, I found out that GCC is supposed to provide implementations of these files, and since I'm using ELF format I figured if I copied their configuration files everything would be ok. For some reason when I built GCC 4.3.3 as a cross compiler for KOS, these files were not created. I didn't even know where I should start looking for them, so I did a search to find the native-compiled versions. Interestingly enough, I did find cross-compiled versions, but in my GCC 4.2.1 directory. I guess back when I was testing different versions of GCC to find out why I couldn't port them to Cygwin without major headaches, I build 4.2.1 as a cross-compiler as well, and created these files. So now it seems that 4.3.3 has a bug that won't let me create crtbegin.o and crtend.o when building as a cross compiler. I will have to try 4.4 one of these days to see if it is still the case.
Subscribe to:
Posts (Atom)