Problem with GRUB

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Haghiri75
Member
Member
Posts: 29
Joined: Fri Nov 16, 2012 4:16 am
Location: Iran
Contact:

Problem with GRUB

Post by Haghiri75 »

I worte a simple kernel in C, and this is the code :
https://github.com/prp-e/Tinix
Everything is OK, and I could generate kernel file using cross-compiler, but when I boot OS using GRUB, and choose
kernel, it says "out of memory" What's the problem?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problem with GRUB

Post by Combuster »

Normally that means your ELF file tries to load sections in places where there's no memory. What does objdump tell you?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Haghiri75
Member
Member
Posts: 29
Joined: Fri Nov 16, 2012 4:16 am
Location: Iran
Contact:

Re: Problem with GRUB

Post by Haghiri75 »

This is what objdump gave me.

Code: Select all

Tinix.bin:     file format elf32-i386


Disassembly of section .text:

08049000 <_start>:
 8049000:	bc 10 f0 04 08       	mov    $0x804f010,%esp
 8049005:	e8 a6 01 00 00       	call   80491b0 <kernel_main>
 804900a:	fa                   	cli    

0804900b <_start.hang>:
 804900b:	f4                   	hlt    
 804900c:	eb fd                	jmp    804900b <_start.hang>
 804900e:	66 90                	xchg   %ax,%ax

08049010 <make_color>:
 8049010:	0f b6 44 24 08       	movzbl 0x8(%esp),%eax
 8049015:	c1 e0 04             	shl    $0x4,%eax
 8049018:	0a 44 24 04          	or     0x4(%esp),%al
 804901c:	c3                   	ret    
 804901d:	8d 76 00             	lea    0x0(%esi),%esi

08049020 <make_vgaentry>:
 8049020:	0f b6 44 24 08       	movzbl 0x8(%esp),%eax
 8049025:	66 0f be 54 24 04    	movsbw 0x4(%esp),%dx
 804902b:	c1 e0 08             	shl    $0x8,%eax
 804902e:	09 d0                	or     %edx,%eax
 8049030:	c3                   	ret    
 8049031:	eb 0d                	jmp    8049040 <strlen>
 8049033:	90                   	nop
 8049034:	90                   	nop
 8049035:	90                   	nop
 8049036:	90                   	nop
 8049037:	90                   	nop
 8049038:	90                   	nop
 8049039:	90                   	nop
 804903a:	90                   	nop
 804903b:	90                   	nop
 804903c:	90                   	nop
 804903d:	90                   	nop
 804903e:	90                   	nop
 804903f:	90                   	nop

08049040 <strlen>:
 8049040:	8b 54 24 04          	mov    0x4(%esp),%edx
 8049044:	31 c0                	xor    %eax,%eax
 8049046:	80 3a 00             	cmpb   $0x0,(%edx)
 8049049:	74 10                	je     804905b <strlen+0x1b>
 804904b:	90                   	nop
 804904c:	8d 74 26 00          	lea    0x0(%esi,%eiz,1),%esi
 8049050:	83 c0 01             	add    $0x1,%eax
 8049053:	80 3c 02 00          	cmpb   $0x0,(%edx,%eax,1)
 8049057:	75 f7                	jne    8049050 <strlen+0x10>
 8049059:	f3 c3                	repz ret 
 804905b:	f3 c3                	repz ret 
 804905d:	8d 76 00             	lea    0x0(%esi),%esi

08049060 <terminal_initialize>:
 8049060:	c7 05 0c b0 04 08 00 	movl   $0x0,0x804b00c
 8049067:	00 00 00 
 804906a:	c7 05 04 b0 04 08 00 	movl   $0x0,0x804b004
 8049071:	00 00 00 
 8049074:	b8 00 80 0b 00       	mov    $0xb8000,%eax
 8049079:	c6 05 00 b0 04 08 1f 	movb   $0x1f,0x804b000
 8049080:	c7 05 08 b0 04 08 00 	movl   $0xb8000,0x804b008
 8049087:	80 0b 00 
 804908a:	8d b6 00 00 00 00    	lea    0x0(%esi),%esi
 8049090:	8d 90 a0 00 00 00    	lea    0xa0(%eax),%edx
 8049096:	8d 76 00             	lea    0x0(%esi),%esi
 8049099:	8d bc 27 00 00 00 00 	lea    0x0(%edi,%eiz,1),%edi
 80490a0:	b9 20 1f 00 00       	mov    $0x1f20,%ecx
 80490a5:	83 c0 02             	add    $0x2,%eax
 80490a8:	66 89 48 fe          	mov    %cx,-0x2(%eax)
 80490ac:	39 d0                	cmp    %edx,%eax
 80490ae:	75 f0                	jne    80490a0 <terminal_initialize+0x40>
 80490b0:	3d a0 8f 0b 00       	cmp    $0xb8fa0,%eax
 80490b5:	75 d9                	jne    8049090 <terminal_initialize+0x30>
 80490b7:	f3 c3                	repz ret 
 80490b9:	8d b4 26 00 00 00 00 	lea    0x0(%esi,%eiz,1),%esi

080490c0 <terminal_setcolor>:
 80490c0:	8b 44 24 04          	mov    0x4(%esp),%eax
 80490c4:	a2 00 b0 04 08       	mov    %al,0x804b000
 80490c9:	c3                   	ret    
 80490ca:	8d b6 00 00 00 00    	lea    0x0(%esi),%esi

080490d0 <terminal_putentryat>:
 80490d0:	8b 44 24 10          	mov    0x10(%esp),%eax
 80490d4:	0f b6 54 24 08       	movzbl 0x8(%esp),%edx
 80490d9:	66 0f be 4c 24 04    	movsbw 0x4(%esp),%cx
 80490df:	8d 04 80             	lea    (%eax,%eax,4),%eax
 80490e2:	c1 e2 08             	shl    $0x8,%edx
 80490e5:	c1 e0 04             	shl    $0x4,%eax
 80490e8:	03 44 24 0c          	add    0xc(%esp),%eax
 80490ec:	09 ca                	or     %ecx,%edx
 80490ee:	8b 0d 08 b0 04 08    	mov    0x804b008,%ecx
 80490f4:	66 89 14 41          	mov    %dx,(%ecx,%eax,2)
 80490f8:	c3                   	ret    
 80490f9:	8d b4 26 00 00 00 00 	lea    0x0(%esi,%eiz,1),%esi

08049100 <terminal_putchar>:
 8049100:	0f b6 15 00 b0 04 08 	movzbl 0x804b000,%edx
 8049107:	56                   	push   %esi
 8049108:	8b 0d 0c b0 04 08    	mov    0x804b00c,%ecx
 804910e:	53                   	push   %ebx
 804910f:	66 0f be 74 24 0c    	movsbw 0xc(%esp),%si
 8049115:	8b 1d 04 b0 04 08    	mov    0x804b004,%ebx
 804911b:	c1 e2 08             	shl    $0x8,%edx
 804911e:	8d 04 89             	lea    (%ecx,%ecx,4),%eax
 8049121:	09 f2                	or     %esi,%edx
 8049123:	8b 35 08 b0 04 08    	mov    0x804b008,%esi
 8049129:	c1 e0 04             	shl    $0x4,%eax
 804912c:	01 d8                	add    %ebx,%eax
 804912e:	66 89 14 46          	mov    %dx,(%esi,%eax,2)
 8049132:	8d 43 01             	lea    0x1(%ebx),%eax
 8049135:	83 f8 50             	cmp    $0x50,%eax
 8049138:	74 16                	je     8049150 <terminal_putchar+0x50>
 804913a:	5b                   	pop    %ebx
 804913b:	a3 04 b0 04 08       	mov    %eax,0x804b004
 8049140:	5e                   	pop    %esi
 8049141:	c3                   	ret    
 8049142:	8d b4 26 00 00 00 00 	lea    0x0(%esi,%eiz,1),%esi
 8049149:	8d bc 27 00 00 00 00 	lea    0x0(%edi,%eiz,1),%edi
 8049150:	8d 41 01             	lea    0x1(%ecx),%eax
 8049153:	ba 00 00 00 00       	mov    $0x0,%edx
 8049158:	c7 05 04 b0 04 08 00 	movl   $0x0,0x804b004
 804915f:	00 00 00 
 8049162:	5b                   	pop    %ebx
 8049163:	83 f8 19             	cmp    $0x19,%eax
 8049166:	0f 44 c2             	cmove  %edx,%eax
 8049169:	a3 0c b0 04 08       	mov    %eax,0x804b00c
 804916e:	5e                   	pop    %esi
 804916f:	c3                   	ret    

08049170 <terminal_writestring>:
 8049170:	57                   	push   %edi
 8049171:	56                   	push   %esi
 8049172:	53                   	push   %ebx
 8049173:	8b 7c 24 10          	mov    0x10(%esp),%edi
 8049177:	80 3f 00             	cmpb   $0x0,(%edi)
 804917a:	74 26                	je     80491a2 <terminal_writestring+0x32>
 804917c:	31 db                	xor    %ebx,%ebx
 804917e:	66 90                	xchg   %ax,%ax
 8049180:	83 c3 01             	add    $0x1,%ebx
 8049183:	80 3c 1f 00          	cmpb   $0x0,(%edi,%ebx,1)
 8049187:	75 f7                	jne    8049180 <terminal_writestring+0x10>
 8049189:	31 f6                	xor    %esi,%esi
 804918b:	39 de                	cmp    %ebx,%esi
 804918d:	73 13                	jae    80491a2 <terminal_writestring+0x32>
 804918f:	90                   	nop
 8049190:	0f be 04 37          	movsbl (%edi,%esi,1),%eax
 8049194:	83 c6 01             	add    $0x1,%esi
 8049197:	50                   	push   %eax
 8049198:	e8 63 ff ff ff       	call   8049100 <terminal_putchar>
 804919d:	39 de                	cmp    %ebx,%esi
 804919f:	58                   	pop    %eax
 80491a0:	72 ee                	jb     8049190 <terminal_writestring+0x20>
 80491a2:	5b                   	pop    %ebx
 80491a3:	5e                   	pop    %esi
 80491a4:	5f                   	pop    %edi
 80491a5:	c3                   	ret    
 80491a6:	8d 76 00             	lea    0x0(%esi),%esi
 80491a9:	8d bc 27 00 00 00 00 	lea    0x0(%edi,%eiz,1),%edi

080491b0 <kernel_main>:
 80491b0:	c7 05 0c b0 04 08 00 	movl   $0x0,0x804b00c
 80491b7:	00 00 00 
 80491ba:	c7 05 04 b0 04 08 00 	movl   $0x0,0x804b004
 80491c1:	00 00 00 
 80491c4:	b8 00 80 0b 00       	mov    $0xb8000,%eax
 80491c9:	c6 05 00 b0 04 08 1f 	movb   $0x1f,0x804b000
 80491d0:	c7 05 08 b0 04 08 00 	movl   $0xb8000,0x804b008
 80491d7:	80 0b 00 
 80491da:	8d b6 00 00 00 00    	lea    0x0(%esi),%esi
 80491e0:	8d 90 a0 00 00 00    	lea    0xa0(%eax),%edx
 80491e6:	8d 76 00             	lea    0x0(%esi),%esi
 80491e9:	8d bc 27 00 00 00 00 	lea    0x0(%edi,%eiz,1),%edi
 80491f0:	b9 20 1f 00 00       	mov    $0x1f20,%ecx
 80491f5:	83 c0 02             	add    $0x2,%eax
 80491f8:	66 89 48 fe          	mov    %cx,-0x2(%eax)
 80491fc:	39 d0                	cmp    %edx,%eax
 80491fe:	75 f0                	jne    80491f0 <kernel_main+0x40>
 8049200:	3d a0 8f 0b 00       	cmp    $0xb8fa0,%eax
 8049205:	75 d9                	jne    80491e0 <kernel_main+0x30>
 8049207:	68 00 a0 04 08       	push   $0x804a000
 804920c:	e8 5f ff ff ff       	call   8049170 <terminal_writestring>
 8049211:	58                   	pop    %eax
 8049212:	c3                   	ret    
 8049213:	90                   	nop
 8049214:	02 b0 ad 1b 03 00    	add    0x31bad(%eax),%dh
 804921a:	00 00                	add    %al,(%eax)
 804921c:	fb                   	sti    
 804921d:	4f                   	dec    %edi
 804921e:	52                   	push   %edx
 804921f:	e4                   	.byte 0xe4
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problem with GRUB

Post by Combuster »

I mentioned "sections", what does this particular objdump listing tell you about that? That there's only a .text section?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Haghiri75
Member
Member
Posts: 29
Joined: Fri Nov 16, 2012 4:16 am
Location: Iran
Contact:

Re: Problem with GRUB

Post by Haghiri75 »

Yes. There's only one .text section. Do I need more?
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Problem with GRUB

Post by Kevin »

The addresses (08049000 etc.) already tell that your kernel is linked to somewhere just above 128 MB. I'm not sure how you're testing your OS, but for example if you're using qemu, you get 128 MB RAM by default, so GRUB can't load the kernel to the proper address. You probably want to have your code linked to a much lower physical address (like 1 MB).
Developer of tyndur - community OS of Lowlevel (German)
Haghiri75
Member
Member
Posts: 29
Joined: Fri Nov 16, 2012 4:16 am
Location: Iran
Contact:

Re: Problem with GRUB

Post by Haghiri75 »

Thanks Kevin, where can I set it?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problem with GRUB

Post by Combuster »

He has a linker script in his repository, so I don't trust his compilation steps.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Haghiri75
Member
Member
Posts: 29
Joined: Fri Nov 16, 2012 4:16 am
Location: Iran
Contact:

Re: Problem with GRUB

Post by Haghiri75 »

Combuster wrote:He has a linker script in his repository, so I don't trust his compilation steps.
This is my compile process :

Code: Select all

i686-elf-gcc -c kernel.c -o kernel.o
nasm -felf32 -o boot.o boot.s
i686-elf-ld linker.ld boot.o kernel.o -o Tinix.bin
Is there any problems?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problem with GRUB

Post by Combuster »

Several, actually. Mainly, it looks like you did a bad job at copy-pasting whatever tutorials you sourced from.

Your linker command line has omissions, and your linker script has omissions, and I'm sure the source provides you with more accurate ones. You can use "man ld" to figure out what those changes mean in practice.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Haghiri75
Member
Member
Posts: 29
Joined: Fri Nov 16, 2012 4:16 am
Location: Iran
Contact:

Re: Problem with GRUB

Post by Haghiri75 »

My source was this thread : http://wiki.osdev.org/Bare_Bones#Writing_a_kernel_in_C

I only replaced GNU Assembler boot loader with NASM one.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problem with GRUB

Post by Combuster »

This little homework game of spot-the-differences isn't over yet :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Haghiri75
Member
Member
Posts: 29
Joined: Fri Nov 16, 2012 4:16 am
Location: Iran
Contact:

Re: Problem with GRUB

Post by Haghiri75 »

So, my problem has been solved by using "-shared" and "-Bsymbolic" flags of ld.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problem with GRUB

Post by Combuster »

So, my problem has been solved by using "-shared" and "-Bsymbolic" flags of ld.
Considering that's not in the tutorial either, I wish you good luck and I suppose I'll see you around for the next "unrelated" question. :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply