Page 1 of 1

I have some problem with my OS [I have solved my problem.]

Posted: Wed Oct 28, 2015 9:49 pm
by 626788149
I have solved my problem.

The bug is this line memset(_bss_start,0,_bss_end - _bss_start) while set PDE of entry_pgdir to zero;











hello everyone,I have some problem with my OS,something odd.

my kernel is mapped to 0xF0000000 (phys. 0x100000)

zz@zz:~/myOS$ readelf -s kern | grep '_bss'
42: f0109000 0 NOTYPE GLOBAL DEFAULT 7 _bss_start
46: f010a038 0 NOTYPE GLOBAL DEFAULT 8 _bss_end

When i run OS in qeum, my OS will crash.
memset(_bss_start,0,4096) is ok.
memset(_bss_start,0,4097) while crash.
And why gdb debug infomation is inconsistent with objdump disassembling infomation?
I apologize for my English...

entry.S

Code: Select all

#define	RELOC(x) ((x) - KERNEL_BASE_ADDR)
#define MULTIBOOT_HEADER_MAGIC (0x1BADB002)
#define MULTIBOOT_HEADER_FLAGS (0x00000007)
#define CHECKSUM (-(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS))


.section .mbHeader
mboot:
	.long MULTIBOOT_HEADER_MAGIC
	.long MULTIBOOT_HEADER_FLAGS
	.long CHECKSUM
	.fill 5 ,4 ,0
	.long 0x00
	.long 640
	.long 480
	.long 32


.text
// entry point
.globl  start, _start  
start: 
_start:
	movl	$(RELOC(bootstacktop)),%esp
	
	call    init_entrypgdir

	movl	$(RELOC(entry_pgdir)),%eax
	movl	%eax,%cr3
	
	movl	%cr4,%eax
	orl     $CR4_PSE,%eax	
	movl	%eax, %cr4

	movl	%cr0, %eax
	orl	$(CR0_PE|CR0_PG|CR0_WP), %eax
	movl	%eax, %cr0

	movl	$redir,%eax

	jmp	*%eax
redir:
	movl	$0x0,%ebp
	push 	%ebx
	call	os_init_main

spin:	jmp	spin



.data
// boot stack
	.p2align	12		# force page alignment
	.globl		bootstack
bootstack:
	.space		4096
	.globl		bootstacktop   
bootstacktop:

entry_pgdir.c

Code: Select all

__attribute__((__aligned__(PGSIZE)))
pde_t  entry_pgdir[NPDENTRIES];


void init_entrypgdir(void){
	uint32_t bar;
	pde_t* foo = (pde_t*)((char*)entry_pgdir - KERNEL_BASE_ADDR);
	for(bar = 0; bar < 1024; bar++){
		foo[bar] = (bar << 22 ) | 0x00000083;
	}
		foo[(KERNEL_BASE_ADDR >> 22)] = 0x00000083;

}	



kentry.c

Code: Select all

#include<multi/multiboot.h>
#include<video/console.h>
#include<lib/x86.h>
#include<lib/stdio.h>
#include<lib/string.h>
extern char _bss_start[];
extern char _bss_end[];


void os_init_main(multiboot_info_t *p)
{
	memset(_bss_start,_bss_end-_bss_start);	
	while(1);
}



My gdb debug infomations

Code: Select all

[  10:1013f0]    0x1014f0:	jns    0x101512

Breakpoint 1, 0x001013f0 in ?? ()
(gdb) si
[  10:1013f5]    0x1014f5:	gs
0x001013f5 in ?? ()
(gdb) si
[  10:100040]    0x100140:	or     %cl,0x2404(%bx,%di)
0x00100040 in ?? ()
(gdb) si
[  10:100041]    0x100141:	mov    %ax,(%si)
0x00100041 in ?? ()
(gdb) si
[  10:100043]    0x100143:	and    $0xe8,%al
0x00100043 in ?? ()
(gdb) si
[  10:100046]    0x100146:	(bad)  
0x00100046 in ?? ()
(gdb) si
[  10:10004d]    0x10014d:	inc    %bp
0x0010004d in ?? ()
(gdb) si
[  10:100054]    0x100154:	sub    $0x28,%sp
0x00100054 in ?? ()
objdump disassembling infomations

Code: Select all

f01013f0 <_start>:
f01013f0:	bc 00 80 10 00       	mov    $0x108000,%esp
f01013f5:	e8 46 ec ff ff       	call   f0100040 <init_entrypgdir>
f01013fa:	b8 00 90 10 00       	mov    $0x109000,%eax
f01013ff:	0f 22 d8             	mov    %eax,%cr3
f0101402:	0f 20 e0             	mov    %cr4,%eax
f0101405:	83 c8 10             	or     $0x10,%eax
f0101408:	0f 22 e0             	mov    %eax,%cr4
f010140b:	0f 20 c0             	mov    %cr0,%eax
f010140e:	0d 01 00 01 80       	or     $0x80010001,%eax
f0101413:	0f 22 c0             	mov    %eax,%cr0
f0101416:	b8 1d 14 10 f0       	mov    $0xf010141d,%eax
f010141b:	ff e0                	jmp    *%eax

f010141d <redir>:
f010141d:	bd 00 00 00 00       	mov    $0x0,%ebp
f0101422:	53                   	push   %ebx
f0101423:	e8 65 ec ff ff       	call   f010008d <os_init_main>