Page 1 of 1

Load Kernel Error

Posted: Tue Mar 24, 2009 3:11 pm
by wererabit
hi guys,

I am a newbie in OS Dev, I am following Mike's tutorial and I really like it. :lol: I ran into a problem yesterday while trying to print some messages in PMode.

What I basically have is that a 2nd stage bootloader that load GDT, enable A20 and enter PMode. Everything is fine until this point, but once I put code for displaying a message in 32 bit pMode, it become unstable somehow. I mean sometimes it works and then it stops .... working :(

The goal is to clean up the screen with a blue background and display something like "Welcome to 32 bit, My friend". Sometimes the code does just that, and I am happy. =D>

But after a while, bochs just standing there doing nothing after booting from floppy drive. I think it failed to load stage 2 bootloader. But as I said I am a newbie so not very sure. This is abit of bochs log, hope you could help out.

Thanks in advance

Code: Select all

00000000000i[     ] Bochs x86 Emulator 2.3.7
00000000000i[     ]   Build from CVS snapshot, on June 3, 2008
00000000000i[     ] System configuration
00000000000i[     ]   processors: 1 (cores=1, HT threads=1)
00000000000i[     ]   A20 line support: yes
00000000000i[     ]   APIC support: yes
00000000000i[     ] CPU configuration
00000000000i[     ]   level: 6
00000000000i[     ]   SMP support: no
00000000000i[     ]   FPU support: yes
00000000000i[     ]   MMX support: yes
00000000000i[     ]   SSE support: 2
00000000000i[     ]   CLFLUSH support: yes
00000000000i[     ]   VME support: yes
00000000000i[     ]   3dnow! support: no
00000000000i[     ]   PAE support: yes
00000000000i[     ]   PGE support: yes
00000000000i[     ]   PSE support: yes
00000000000i[     ]   x86-64 support: yes
00000000000i[     ]   SEP support: yes
00000000000i[     ]   MWAIT support: no
00000000000i[     ]   XSAVE support: no
00000000000i[     ]   AES support: no
00000000000i[     ] Optimization configuration
00000000000i[     ]   Guest2HostTLB support: yes
00000000000i[     ]   RepeatSpeedups support: yes
00000000000i[     ]   Icache support: yes
00000000000i[     ]   Trace cache support: yes
00000000000i[     ]   Fast function calls: yes
00000000000i[     ] Devices configuration
00000000000i[     ]   ACPI support: yes
00000000000i[     ]   NE2000 support: yes
00000000000i[     ]   PCI support: yes
00000000000i[     ]   SB16 support: yes
00000000000i[     ]   USB support: yes
00000000000i[     ]   VGA extension support: vbe cirrus
00000000000i[MEM0 ] allocated memory at 02640020. after alignment, vector=02641000
00000000000i[MEM0 ] 32.00MB
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('BIOS-bochs-latest')
00000000000i[MEM0 ] rom at 0xc0000/38400 ('VGABIOS-lgpl-latest')
00000000000i[APIC?] set APIC ID to 0
00000000000i[APIC0] 80686
00000000000i[APIC0] local apic in CPU apicid=00 initializing
00000000000i[IOAP ] initializing I/O APIC
00000000000i[IOAP ] set APIC ID to 1
00000000000i[MEM0 ] Register memory access handlers: 0xfec00000 - 0xfec00fff
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Tue Mar 24 23:12:05 2009 (time0=1237889525)
00000000000i[DMA  ] channel 4 used by cascade
00000000000i[DMA  ] channel 2 used by Floppy Drive
00000000000i[FDD  ] fd0: 'a:' ro=0, h=2,t=80,spt=18
00000000000i[PCI  ] 440FX Host bridge present at device 0, function 0
00000000000i[PCI  ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[MEM0 ] Register memory access handlers: 0x000a0000 - 0x000bffff
00000000000i[WGUI ] Desktop Window dimensions: 1680 x 1050
00000000000i[WGUI ] Number of Mouse Buttons = 4
00000000000i[WGUI ] IME disabled
00000000000i[MEM0 ] Register memory access handlers: 0xe0000000 - 0xe07fffff
00000000000i[CLVGA] VBE Bochs Display Extension Enabled
00000000000i[CLVGA] interval=40000
00000000000i[     ] init_mem of 'harddrv' plugin device by virtual method
00000000000i[     ] init_mem of 'keyboard' plugin device by virtual method
00000000000i[     ] init_mem of 'serial' plugin device by virtual method
00000000000i[     ] init_mem of 'parallel' plugin device by virtual method
00000000000i[     ] init_mem of 'extfpuirq' plugin device by virtual method
00000000000i[     ] init_mem of 'gameport' plugin device by virtual method
00000000000i[     ] init_mem of 'speaker' plugin device by virtual method
00000000000i[     ] init_mem of 'pci_ide' plugin device by virtual method
00000000000i[     ] init_mem of 'acpi' plugin device by virtual method
00000000000i[     ] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD   ] Using boot sequence floppy, none, none
00000000000i[HD   ] Floppy boot signature check is enabled
00000000000i[     ] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD  ] will paste characters every 1000 keyboard ticks
00000000000i[     ] init_dev of 'serial' plugin device by virtual method
00000000000i[SER  ] com1 at 0x03f8 irq 4
00000000000i[     ] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR  ] parallel port 1 at 0x0378 irq 7
00000000000i[     ] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[     ] init_dev of 'gameport' plugin device by virtual method
00000000000i[     ] init_dev of 'speaker' plugin device by virtual method
00000000000i[     ] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[PCI  ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[     ] init_dev of 'acpi' plugin device by virtual method
00000000000i[PCI  ] ACPI Controller present at device 1, function 3
00000000000i[     ] register state of 'harddrv' plugin device by virtual method
00000000000i[     ] register state of 'keyboard' plugin device by virtual method
00000000000i[     ] register state of 'serial' plugin device by virtual method
00000000000i[     ] register state of 'parallel' plugin device by virtual method
00000000000i[     ] register state of 'extfpuirq' plugin device by virtual method
00000000000i[     ] register state of 'gameport' plugin device by virtual method
00000000000i[     ] register state of 'speaker' plugin device by virtual method
00000000000i[     ] register state of 'pci_ide' plugin device by virtual method
00000000000i[     ] register state of 'acpi' plugin device by virtual method
00000000000i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[CPU0 ] cpu hardware reset
00000000000i[APIC0] local apic in CPU 0 initializing
00000000000i[     ] reset of 'harddrv' plugin device by virtual method
00000000000i[     ] reset of 'keyboard' plugin device by virtual method
00000000000i[     ] reset of 'serial' plugin device by virtual method
00000000000i[     ] reset of 'parallel' plugin device by virtual method
00000000000i[     ] reset of 'extfpuirq' plugin device by virtual method
00000000000i[     ] reset of 'gameport' plugin device by virtual method
00000000000i[     ] reset of 'speaker' plugin device by virtual method
00000000000i[     ] reset of 'pci_ide' plugin device by virtual method
00000000000i[     ] reset of 'acpi' plugin device by virtual method
00000003302i[BIOS ] $Revision: 1.209 $ $Date: 2008/06/02 20:08:10 $
00000080000e[CLVGA] character height = 1, skipping text update
00000317069i[KBD  ] reset-disable command received
00000436653i[VBIOS] VGABios $Id: vgabios.c,v 1.67 2008/01/27 09:44:12 vruppert Exp $

00000436724i[CLVGA] VBE known Display Interface b0c0
00000436756i[CLVGA] VBE known Display Interface b0c4
00000439681i[VBIOS] VBE Bios $Id: vbe.c,v 1.60 2008/03/02 07:47:21 vruppert Exp $
00000480000i[WGUI ] dimension update x=720 y=400 fontheight=16 fontwidth=9 bpp=8
00000762682i[BIOS ] Starting rombios32
00000763509i[BIOS ] ram_size=0x02000000
00000784058i[BIOS ] Found 1 cpu(s)
00000800359i[BIOS ] bios_table_addr: 0x000fb778 end=0x000fcc00
00000800426i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001259233i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001718720i[P2I  ] PCI IRQ routing: PIRQA# set to 0x0b
00001718767i[P2I  ] PCI IRQ routing: PIRQB# set to 0x09
00001718814i[P2I  ] PCI IRQ routing: PIRQC# set to 0x0b
00001718861i[P2I  ] PCI IRQ routing: PIRQD# set to 0x09
00001718877i[P2I  ] write: ELCR2 = 0x0a
00001719814i[BIOS ] PIIX3 init: elcr=00 0a
00001740069i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237
00001743306i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000
00001746039i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010
00001746500i[PIDE ] new BM-DMA address: 0xc000
00001747383i[BIOS ] region 4: 0x0000c000
00001749959i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113
00001750459i[ACPI ] new irq line = 11
00001750496i[ACPI ] new PM base address: 0xb000
00001750558i[ACPI ] new SM base address: 0xb100
00001751026i[CPU0 ] Enter to System Management Mode
00001751036i[CPU0 ] RSM: Resuming from System Management Mode
00001751070i[PCI  ] setting SMRAM control register to 0x4a
00001751352i[PCI  ] setting SMRAM control register to 0x0a
00001774633i[BIOS ] MP table addr=0x000fb850 MPC table addr=0x000fb780 size=0xd0
00001776836i[BIOS ] SMBIOS table addr=0x000fb860
00001779880i[BIOS ] ACPI tables: RSDP addr=0x000fb970 ACPI DATA addr=0x01ff0000 size=0x9d8
00001799413i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001800425i[BIOS ] bios_table_cur_addr: 0x000fb994
00008023335i[BIOS ] Booting from 0000:7c00
00010313295e[CPU0 ] read_virtual_checks(): read beyond limit
00010313297e[CPU0 ] read_virtual_checks(): read beyond limit
00010313299e[CPU0 ] read_virtual_checks(): read beyond limit
00010313301e[CPU0 ] read_virtual_checks(): read beyond limit
;
[color=#BF0000];********************************************************************
; and It keeps saying "READ BEYOND LIMIT" almost forever. The log if is over 40mb 
; of this message. 
;********************************************************************[/color]
;
00011673999e[CPU0 ] read_virtual_checks(): read beyond limit
00011674000p[WGUI ] >>PANIC<< Window closed, exiting!
00011674000i[CPU0 ] CPU is in real mode (active)
00011674000i[CPU0 ] CS.d_b = 16 bit
00011674000i[CPU0 ] SS.d_b = 16 bit
00011674000i[CPU0 ] EFER   = 0x00000000
00011674000i[CPU0 ] | RAX=0000000000000022  RBX=000000000000daff
00011674000i[CPU0 ] | RCX=0000000000000000  RDX=0000000000000100
00011674000i[CPU0 ] | RSP=000000000000fff7  RBP=0000000000000000
00011674000i[CPU0 ] | RSI=00000000ffff01c0  RDI=0000000000080005
00011674000i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00011674000i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00011674000i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00011674000i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00011674000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf af PF cf
00011674000i[CPU0 ] | SEG selector     base    limit G D
00011674000i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00011674000i[CPU0 ] |  CS:f000( 0004| 0|  0) 000f0000 0000ffff 0 0
00011674000i[CPU0 ] |  DS:07c0( 0005| 0|  0) 00007c00 0000ffff 0 0
00011674000i[CPU0 ] |  SS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00011674000i[CPU0 ] |  ES:0050( 0005| 0|  0) 00000500 0000ffff 0 0
00011674000i[CPU0 ] |  FS:07c0( 0005| 0|  0) 00007c00 0000ffff 0 0
00011674000i[CPU0 ] |  GS:07c0( 0005| 0|  0) 00007c00 0000ffff 0 0
00011674000i[CPU0 ] |  MSR_FS_BASE:0000000000007c00
00011674000i[CPU0 ] |  MSR_GS_BASE:0000000000007c00
00011674000i[CPU0 ] | RIP=000000000000ff53 (0000000000007ba9)
00011674000i[CPU0 ] | CR0=0x60000010 CR1=0x0 CR2=0x0000000000000000
00011674000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00011674000i[CPU0 ] >> cld  : FC
00011674000i[CMOS ] Last time is 1237889530 (Tue Mar 24 23:12:10 2009)
00011674000i[     ] restoring default signal behavior
00011674000i[CTRL ] quit_sim called with exit code 1


Re: Load Kernel Error

Posted: Tue Mar 24, 2009 3:41 pm
by kmtdk
well
im not sure about the eror bochs gives you, but to me it sounds like you are acessing memory there is not there ( in the emulation)
so you "clean" and print might got a bad loop.
can we see the code ?

KMT dk

Re: Load Kernel Error

Posted: Tue Mar 24, 2009 3:57 pm
by wererabit
sure, this is the class (This is from Mike's tutorial. Might be a bit different though). But I doubt it is the problem because when I commented out all the calls of this class and try to display a single character using

Code: Select all

  mov edi, 0xB8000
  mov ah, 63
  mov al, 'A'
  mov word [edi], ax
I still get the same error. Here's the code. I was using ClrScr and Puts32

Code: Select all

;***********************************************************
;    stdio.inc
;    Input/Output routine
;***********************************************************

%ifndef __STDIO_INC_67343546FDCC56AAB872_INCLUDED__
%define __STDIO_INC_67343546FDCC56AAB872_INCLUDED__

;==========================================================
;	 16 Bit Real Mode Routines
;==========================================================

[bits 16]

;--------------------------------------------------------------
; Print a null terminated string in 16 bit real mode		  ;
; DS->SI terminated string			    					  ;
;--------------------------------------------------------------


Puts16:
	pusha

.Loop1:
	lodsb
	or al, al
	jz Puts16Done
	mov ah, 0x0E
	int 0x10
	jmp .Loop1
	
Puts16Done:
	popa
	ret
	
;==========================================================
;	 32 Bit Protected Mode Routines
;==========================================================
[bits 32]

%define VIDMEM			 0xB8000					; Video Memory
%define CHAR_ATTRIB 	 63		

%define COLS			 80							; there are 80 cols and 25 lines
%define LINES			 25

_curX 	db	 0										; initialize cursor position to be 0
_curY	db 	 0

;--------------------------------------------------------------
; Putch32: display a char in 32 bit protected mode	  		  ;
; BL: char to be printed							  		  ;
;--------------------------------------------------------------
Putch32:
	
	pusha											; save all the registries
	
	mov 	edi, VIDMEM
	
	; work out where to print. the location is calculated from curX, CurY
													; Note that when we display a char on screen, actually 
													; we write 2 bytes to te buffer, NOT 1.
													; the arrtibute first, and the char itself
													; ==> COLS = no of chars per line
													; so when we calculate the location, everything related 
													; to the width, need to be multiply by 2. That is the 
													; number of bytes per line
	
	; Get location: loc = (curY * (bytes per lines)) + curX		
	mov 	ecx, 	COLS * 2						; bytes per line
	mov 	al, 	byte [_curY]					; y pos
	mul		ecx										; eax = _curY * (COLS * 2)
	push 	eax										; save it
	
	mov		al, 	byte [_curX]					
	mov		cl, 	2
	mul 	cl										; 2 bytes per char
	pop 	ecx
	add		eax, ecx								; the result is here
	
													; Because the video buffer will print out 1 char after another
													; when it reaches teh end of a line, it go to the next line
													
													; That's mean eax contains the offset from the start
													; of the buffer where we need to display out char
	
	; Add to base address
	xor 	ecx, ecx								; clear ecx
	add 	edi, eax								; add to the base address													
	
	; watch out for newline char
	cmp		bl, 0x0A								; compare with newline char
	je		.Row
	
	;display the char
	mov		ah, CHAR_ATTRIB
	mov 	al, bl									; char to display
	mov 	word [edi], ax
	
	; update the cursor
	inc byte [_curX]
	cmp byte [_curX], COLS
	je .Row
	
	jmp .done													
	
.Row:												; go to the next row
	mov byte [_curX], 0
	inc byte [_curY]
	
.done:
	popa											; restore registries
	ret

;--------------------------------------------------------------
; Puts32: display a string in 32 bit protected mode	  		  ;
; EBX: address of the string to print terminated by 0  		  ;
;--------------------------------------------------------------
Puts32:
	
	pusha
	
													; copy teh string from ebx to edi
	push 	ebx										; save the string to be printed
	pop		edi										; store in edi
													; we can store in edi here and not afraid
													; of the string being vanished because we save all 
													; theregister in putch32
.loop:
	
	mov 	bl, byte [edi]							; copy 1 byte to bl
	cmp 	bl, 0									; make sure it not the end of teh string
	je 		.done
													
	Call Putch32									; print the char	
	
	inc 	edi										; next char
	
	jmp 	.loop


	
.done:	
													; update the cursor
	mov 	bh, 	byte [_curY]													
	mov 	bl, 	byte [_curX]
	Call 	MovCur
	popa
	ret

;--------------------------------------------------------------
; Move Cursor								  				  ;
;	bh = Y pos												  ;
;	bl = x pos												  ;
;--------------------------------------------------------------
MovCur:
	
	pusha
	;-------------------------------;
	;   Get current position        ;
	;-------------------------------;

	; Here, _CurX and _CurY are relitave to the current position on screen, not in memory.
	; That is, we don't need to worry about the byte alignment we do when displaying characters,
	; so just follow the forumla: location = _CurX + _CurY * COLS

	xor	eax, eax
	mov	ecx, COLS
	mov	al, bh			; get y pos
	mul	ecx				; multiply y*COLS
	add	al, bl			; Now add x
	mov	ebx, eax
	
	;--------------------------------------;
	;   Set low byte index to VGA register ;
	;--------------------------------------;
	mov al, 0x0F
	mov dx, 0x3D4
	out dx, al	

	mov	al, bl
	mov	dx, 0x03D5
	out	dx, al			; low byte

	;---------------------------------------;
	;   Set high byte index to VGA register ;
	;---------------------------------------;
	mov al, 0x0E
	mov dx, 0x3D4
	out dx, al
	
	mov al, bh
	mov dx, 0x3D5
	out dx, al			; high byte
	
	popa
	ret
	
;--------------------------------------------------------------
; Clear the screen in 32 bit protected mode	  				  ;
;--------------------------------------------------------------
ClrScr32:
	
	pusha
	cld												; clear direction flag, just to be on teh safe side
	
	mov edi, VIDMEM									; edi now represent the video buffer
													; write to it is to write to the screen
	
	mov cx, 2000									; excute for 2000 times
													; 80 cols * 25 lines = 2000
													
	mov ah, CHAR_ATTRIB
	mov al, ' '										
	
	rep stosw										; repeated copy ax to edi and inscrease edi by a word size
													; the ' ' char with blue background will appear on the screen
													; we dont call putch32 here to save the performence
													
	
	mov byte [_curX], 0								; reset the cursor
	mov byte [_curY], 0
													
	popa
	ret

%endif		;__STDIO_INC_67343546FDCC56AAB872_INCLUDED__




Re: Load Kernel Error

Posted: Tue Mar 24, 2009 4:02 pm
by neon
Hello,

That stdio.inc is not the updated one. Please try the one from the latest tutorial.

Also, put a cli+hlt at the beginning of your "second stage" and rebuild it. Please let us know if it stops in your second stage or not.

Re: Load Kernel Error

Posted: Tue Mar 24, 2009 4:04 pm
by wererabit
I will try to put cli and hlt at teh begiining of stage two and let you know.

About the stdio.inc, I believe I am having the same version as on the website, both file are identical.

Re: Load Kernel Error

Posted: Tue Mar 24, 2009 4:11 pm
by neon
I am not sure. I would try the one from tut 19 to make sure that you have the latest one.

Re: Load Kernel Error

Posted: Tue Mar 24, 2009 4:15 pm
by wererabit
thanks

Re: Load Kernel Error

Posted: Wed Mar 25, 2009 2:55 am
by AJ
Hi,

Looking at the instruction pointer, it's at 0xFF53. In bochs, that is often what is contained at linear address 0x0000, which probably means that you have loaded EIP from a NULL pointer (or it's a strange coincidence and you mean to be fetching instructions from 0xFF53).

Cheers,
Adam

Re: Load Kernel Error

Posted: Wed Mar 25, 2009 3:12 am
by wererabit
AJ wrote:Hi,

Looking at the instruction pointer, it's at 0xFF53. In bochs, that is often what is contained at linear address 0x0000, which probably means that you have loaded EIP from a NULL pointer (or it's a strange coincidence and you mean to be fetching instructions from 0xFF53).

Cheers,
Adam
thanks AJ, I found out what the problem was, I still wasn't be able to fix it though. The problem is that my bootloader only load 1 sector, so when the size of my second stage gets bigger than 512, it just stop working.