Hi Im just trying to do get to grips with certain things before I go diving into any development anyway I followed the gentoo cross compiler guide from
http://wiki.osdev.org/GCC_Cross-Compiler
Ok so heres my standard non cross compiler system gcc
gcc (GCC) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)
I installed binutils and gcc-core+g++, now I followed the tutorial to the letter , it said to extract core-gcc and g++ to the same directory. I did this by in the directory /usr/src doing tar xvf gcc-core-Vx then tar xvf g++Vx and this put both these apps in the same directory.
In the end everything was built but in my /usr/cross/bin has the following files
i586-elf-addr2line
-rwxr-xr-x 2 root root 2415935 2008-06-24 20:20 i586-elf-ar
-rwxr-xr-x 2 root root 3342386 2008-06-24 20:21 i586-elf-as
-rwxr-xr-x 1 root root 2268466 2008-06-24 20:20 i586-elf-c++filt
-rwxr-xr-x 1 root root 2662434 2008-06-24 20:21 i586-elf-gprof
-rwxr-xr-x 2 root root 3145469 2008-06-24 20:21 i586-elf-ld
-rwxr-xr-x 2 root root 2323392 2008-06-24 20:20 i586-elf-nm
-rwxr-xr-x 2 root root 2837644 2008-06-24 20:20 i586-elf-objcopy
-rwxr-xr-x 2 root root 3124668 2008-06-24 20:20 i586-elf-objdump
-rwxr-xr-x 2 root root 2415934 2008-06-24 20:20 i586-elf-ranlib
-rwxr-xr-x 1 root root 504687 2008-06-24 20:20 i586-elf-readelf
-rwxr-xr-x 1 root root 2316856 2008-06-24 20:20 i586-elf-size
-rwxr-xr-x 1 root root 2295609 2008-06-24 20:20 i586-elf-strings
-rwxr-xr-x 2 root root 2837643 2008-06-24 20:20 i586-elf-strip
Now according to the tutorial I should have a file /usr/cross/bin/i586-elf-gcc but I dont? I figured i586-elf-gcc would be the cross compiler as I can see ld is there ^^ I put alot of time into this and the article has help me understand the cross compiling concept better but I could do with some input of anyone who can manage
edit.........
bahhhh lol less than 20 secs after posting I figured it out! I did make install as I must have got muddled reading a section on the page and what I should have put was make install-gcc
This is the first time Ive actually bothered to attempt to do a cross compiler, when I in the past was on these forums I was reccomended to read about cross compilers and toolchains but I didnt do it, glad I have now.
(I have probably went overboard as to me reasons for wantinmg a crosscompiler, its so I can compile the files from brans tutorial in their native format on linux, because even though I added fnoleading underscore and eventually got everything to compile on linux well when i run in from floppy disk with grub on it says unknown executable format which tells me I am getting muddled between the 2 formats somewhere along the line. I really want to get it to work the silly way Im doing atm if possible because Its long overdue for me to learn about cross compiling hehe and at least this gives it purpose in the short term!
Thanks again!
built my first cross compiler:)+my stupid mistake <solved>
built my first cross compiler:)+my stupid mistake <solved>
Last edited by eax on Tue Jun 24, 2008 5:22 pm, edited 2 times in total.
-
- Member
- Posts: 391
- Joined: Wed Jul 25, 2007 8:45 am
- Libera.chat IRC: aejsmith
- Location: London, UK
- Contact:
Re: built my first cross compiler:) unsure of where $targgcc is?
It looks as though you haven't installed GCC, or gave an incorrect prefix to configure. Are you sure you specified the right prefix and ran the "make install-gcc" command? Also, what versions of binutils and GCC did you compile?
Try looking for i586-pc-elf-gcc with find/locate or whatever to see if it's in the wrong location
Try looking for i586-pc-elf-gcc with find/locate or whatever to see if it's in the wrong location
Brans tutorial seems to work but then reboots. what have Ido
[goto bottom of post for latest problem - kinda hoping I get this sorted then all my silly mistakes in one place may help someone else hehe ]
Just edited above I did exactly that, did make install instead of the one thats specific to gcc see edited post above and cheers for the prompt reply.
Im still getting incorrect format errors with brans tutorial compiling on linux, I see quite a few are getting the same grub error 13 when doing it for linux, heres the thing I want to compile it as per tutorial as kernel.bin (binary format) but then after I know my crosscompiler works I run it on vmware , Im close but am missing some obscure syntactical thing I reckon to do with they way Im setting it up and being on linux
Ok have been searching like hell and there has been many posts on similiar issues,I have got over one issue into a really dam obscure one,compilation and linking goes great and grub fires up kernel bin and it says
0x3004 Starting up ? I was expecting hello world or even hex values similiar to this as per tutorial? Im just wandeirng if someone can tell me what Ive done wrong this time lol, I want to be able to usemy cross compiler i.e i586-gcc to compile and link in linux and then run the grub floppy in vmware on linux and also boot into windows and be able to run the samw bin in bochs, as it stands it does run in vmware in linux(windows nt 4 emulated OS) and it links in linux/compiles i586 , the problem is I dont understand where that crazy output is comming from? This is the first time I have booted the small kernel.bin from grub you see and I really want to get comfortable with all the tools this time around so what is this crazy message about, has anyone seen anything like this?
0x3004 Starting up
puts("Hello Word"!) and it ends up like that ^^^lol crazy !
btw my grub is just
root (fd0)
kernel kernel.bin
finally I did what curt22 did from this forum in this post
http://forum.osdev.org/viewtopic.php?f=1&p=129962
heres my makefile
Even if my makefile isnt 100% I have tried both with and without makefile ,same result.
Ok nor for link.ld
nowmain.c
now system.h
now the screen file
Anyway reallystuck getting this working with my current setup and im certain it will be stupid things as well:) there were lots of posts on my prior issues but tbh lots of information but Im finding it tricky to find out in simple terms how certain file formats relate between compiler , linker , assembler , would be much easier if they didnt all have there own variant names for file formats of the same types, then again I may just be getting confusedlol
edit:Please do not tell me its because this line is commented out
//init_video();
or Im away to kill myself anyways gn ! I need sleep I think.
Update:
Man it was what I suspected lol , I stupidly didnt notice that commented line I put earlier for init video and now it working . Actually just goes to show how writing stuff out can help
I know it was a stupid stupid mistake but maybe somewhere along the line this will help someone who gets the same funky grub output ! Great its working now and via a cross compiler aswell class!
Update: Latest issue
in the vmware server in ubuntu hello world indeed gets printed and then the system rebooted, I figured this would be something to do with the vm but when I run my kernel by physically booting from floppy it prints hello world then reboots, Im just wandering why this is because I have an infinite loop setup in the asm file and in main as per brans tutorial?
.......Ok just found some info , I would like to know if I have this correct, is it the case that what Im experiancing is a triple fault caused by grub setting up its own gdt and then myself by using brans first code without setting up a gdt of my own I must be writing to somewhere in memmory that grub uses? Im just curious because the program does work in the sense it prints out but would like to know why the reboot is happening specifically. I never had all this when I run brans guide way back but I wasnt using grub.
Just edited above I did exactly that, did make install instead of the one thats specific to gcc see edited post above and cheers for the prompt reply.
Im still getting incorrect format errors with brans tutorial compiling on linux, I see quite a few are getting the same grub error 13 when doing it for linux, heres the thing I want to compile it as per tutorial as kernel.bin (binary format) but then after I know my crosscompiler works I run it on vmware , Im close but am missing some obscure syntactical thing I reckon to do with they way Im setting it up and being on linux
Ok have been searching like hell and there has been many posts on similiar issues,I have got over one issue into a really dam obscure one,compilation and linking goes great and grub fires up kernel bin and it says
0x3004 Starting up ? I was expecting hello world or even hex values similiar to this as per tutorial? Im just wandeirng if someone can tell me what Ive done wrong this time lol, I want to be able to usemy cross compiler i.e i586-gcc to compile and link in linux and then run the grub floppy in vmware on linux and also boot into windows and be able to run the samw bin in bochs, as it stands it does run in vmware in linux(windows nt 4 emulated OS) and it links in linux/compiles i586 , the problem is I dont understand where that crazy output is comming from? This is the first time I have booted the small kernel.bin from grub you see and I really want to get comfortable with all the tools this time around so what is this crazy message about, has anyone seen anything like this?
0x3004 Starting up
puts("Hello Word"!) and it ends up like that ^^^lol crazy !
btw my grub is just
root (fd0)
kernel kernel.bin
finally I did what curt22 did from this forum in this post
http://forum.osdev.org/viewtopic.php?f=1&p=129962
heres my makefile
Code: Select all
all: myinst
myinst : start.asm
@echo started assembling
nasm -f aout -o start.o start.asm
@echo finished assembling
@echo started compile with gcc
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -fleading-underscore -nostdinc -fno-builtin -I./include -c -o main.o main.c
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -fleading-underscore -nostdinc -fno-builtin -I./include -c -o scrn.o scrn.c
@echo ended compile with gcc
@echo started linking
ld -T link.ld -o kernel.bin start.o main.o scrn.o
@echo finished linking
clean :
rm *.bin
rm *.o
crosscompile: start.asm
@echo started assembling
nasm -f elf -o start.o start.asm
@echo finished assembling
@echo started compile with gcc
i586-elf-gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -fleading-underscore -nostdinc -fno-builtin -I./include -c -o main.o main.c
i586-elf-gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -fleading-underscore -nostdinc -fno-builtin -I./include -c -o scrn.o scrn.c
@echo ended compile with gcc
@echo started linking
ld -T link.ld -o kernel.bin start.o main.o scrn.o
@echo finished linking
Ok nor for link.ld
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
Code: Select all
/* bkerndev - Bran's Kernel Development Tutorial
* By: Brandon F. ([email protected])
* Desc: Main.c: C code entry.
*
* Notes: No warranty expressed or implied. Use at own risk. */
#include<system.h>
void *memcpy(void *dest, const void *src, size_t count)
{
const char *sp = (const char *)src;
char *dp = (char *)dest;
for(; count != 0; count--) *dp++ = *sp++;
return dest;
}
void *memset(void *dest, char val, size_t count)
{
char *temp = (char *)dest;
for( ; count != 0; count--) *temp++ = val;
return dest;
}
unsigned short *memsetw(unsigned short *dest, unsigned short val, size_t count)
{
unsigned short *temp = (unsigned short *)dest;
for( ; count != 0; count--) *temp++ = val;
return dest;
}
size_t strlen(const char *str)
{
size_t retval;
for(retval = 0; *str != '\0'; str++) retval++;
return retval;
}
unsigned char inportb (unsigned short _port)
{
unsigned char rv;
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
return rv;
}
void outportb (unsigned short _port, unsigned char _data)
{
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}
void main()
{
int i;
//gdt_install();
//idt_install();
//isrs_install();
//irq_install();
//init_video();
//timer_install();
//keyboard_install();
__asm__ __volatile__ ("sti");
puts("Hello World!\n");
// i = 10 / 0;
// putch(i);
for (;;);
}
Code: Select all
#ifndef __SYSTEM_H
#define __SYSTEM_H
#define size_t int
/* MAIN.C */
extern void *memcpy(void *dest, const void *src, size_t count);
extern void *memset(void *dest, char val, size_t count);
extern unsigned short *memsetw(unsigned short *dest, unsigned short, size_t count);
extern size_t strlen(const char *str);
extern unsigned char inportb (unsigned short _port);
extern void outportb (unsigned short _port, unsigned char _data);
extern void cls();
extern void putch(unsigned char c);
extern void puts(unsigned char *str);
extern void settextcolor(unsigned char forecolor, unsigned char backcolor);
extern void init_video();
/*old
extern unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count);
extern unsigned char *memset(unsigned char *dest, unsigned char val, int count);
extern unsigned short *memsetw(unsigned short *dest, unsigned short val, int count);
extern int strlen(const char *str);
extern unsigned char inportb (unsigned short _port);
extern void outportb (unsigned short _port, unsigned char _data);
*/
#endif
Code: Select all
#include <system.h>
/* These define our textpointer, our background and foreground
* colors (attributes), and x and y cursor coordinates */
unsigned short *textmemptr;
int attrib = 0x0F;
int csr_x = 0, csr_y = 0;
/* Scrolls the screen */
void scroll(void)
{
unsigned blank, temp;
/* A blank is defined as a space... we need to give it
* backcolor too */
blank = 0x20 | (attrib << 8);
/* Row 25 is the end, this means we need to scroll up */
if(csr_y >= 25)
{
/* Move the current text chunk that makes up the screen
* back in the buffer by a line */
temp = csr_y - 25 + 1;
memcpy (textmemptr, textmemptr + temp * 80, (25 - temp) * 80 * 2);
/* Finally, we set the chunk of memory that occupies
* the last line of text to our 'blank' character */
memsetw (textmemptr + (25 - temp) * 80, blank, 80);
csr_y = 25 - 1;
}
}
/* Updates the hardware cursor: the little blinking line
* on the screen under the last character pressed! */
void move_csr(void)
{
unsigned temp;
/* The equation for finding the index in a linear
* chunk of memory can be represented by:
* Index = [(y * width) + x] */
temp = csr_y * 80 + csr_x;
/* This sends a command to indicies 14 and 15 in the
* CRT Control Register of the VGA controller. These
* are the high and low bytes of the index that show
* where the hardware cursor is to be 'blinking'. To
* learn more, you should look up some VGA specific
* programming documents. A great start to graphics:
* http://www.brackeen.com/home/vga */
outportb(0x3D4, 14);
outportb(0x3D5, temp >> 8);
outportb(0x3D4, 15);
outportb(0x3D5, temp);
}
/* Clears the screen */
void cls()
{
unsigned blank;
int i;
/* Again, we need the 'short' that will be used to
* represent a space with color */
blank = 0x20 | (attrib << 8);
/* Sets the entire screen to spaces in our current
* color */
for(i = 0; i < 25; i++)
memsetw (textmemptr + i * 80, blank, 80);
/* Update out virtual cursor, and then move the
* hardware cursor */
csr_x = 0;
csr_y = 0;
move_csr();
}
/* Puts a single character on the screen */
void putch(unsigned char c)
{
unsigned short *where;
unsigned att = attrib << 8;
/* Handle a backspace, by moving the cursor back one space */
if(c == 0x08)
{
if(csr_x != 0) csr_x--;
}
/* Handles a tab by incrementing the cursor's x, but only
* to a point that will make it divisible by 8 */
else if(c == 0x09)
{
csr_x = (csr_x + 8) & ~(8 - 1);
}
/* Handles a 'Carriage Return', which simply brings the
* cursor back to the margin */
else if(c == '\r')
{
csr_x = 0;
}
/* We handle our newlines the way DOS and the BIOS do: we
* treat it as if a 'CR' was also there, so we bring the
* cursor to the margin and we increment the 'y' value */
else if(c == '\n')
{
csr_x = 0;
csr_y++;
}
/* Any character greater than and including a space, is a
* printable character. The equation for finding the index
* in a linear chunk of memory can be represented by:
* Index = [(y * width) + x] */
else if(c >= ' ')
{
where = textmemptr + (csr_y * 80 + csr_x);
*where = c | att; /* Character AND attributes: color */
csr_x++;
}
/* If the cursor has reached the edge of the screen's width, we
* insert a new line in there */
if(csr_x >= 80)
{
csr_x = 0;
csr_y++;
}
/* Scroll the screen if needed, and finally move the cursor */
scroll();
move_csr();
}
/* Uses the above routine to output a string... */
void puts(unsigned char *text)
{
int i;
for (i = 0; i < strlen(text); i++)
{
putch(text[i]);
}
}
/* Sets the forecolor and backcolor that we will use */
void settextcolor(unsigned char forecolor, unsigned char backcolor)
{
/* Top 4 bytes are the background, bottom 4 bytes
* are the foreground color */
attrib = (backcolor << 4) | (forecolor & 0x0F);
}
/* Sets our text-mode VGA pointer, then clears the screen for us */
void init_video(void)
{
textmemptr = (unsigned short *)0xB8000;
cls();
}
edit:Please do not tell me its because this line is commented out
//init_video();
or Im away to kill myself anyways gn ! I need sleep I think.
Update:
Man it was what I suspected lol , I stupidly didnt notice that commented line I put earlier for init video and now it working . Actually just goes to show how writing stuff out can help
I know it was a stupid stupid mistake but maybe somewhere along the line this will help someone who gets the same funky grub output ! Great its working now and via a cross compiler aswell class!
Update: Latest issue
in the vmware server in ubuntu hello world indeed gets printed and then the system rebooted, I figured this would be something to do with the vm but when I run my kernel by physically booting from floppy it prints hello world then reboots, Im just wandering why this is because I have an infinite loop setup in the asm file and in main as per brans tutorial?
.......Ok just found some info , I would like to know if I have this correct, is it the case that what Im experiancing is a triple fault caused by grub setting up its own gdt and then myself by using brans first code without setting up a gdt of my own I must be writing to somewhere in memmory that grub uses? Im just curious because the program does work in the sense it prints out but would like to know why the reboot is happening specifically. I never had all this when I run brans guide way back but I wasnt using grub.