How to jump to kernel ?

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
Mattx
Posts: 20
Joined: Fri Jul 11, 2008 5:10 am

How to jump to kernel ?

Post by Mattx »

After all hard fights with pmode I evetually did it, my bootloader switch do pmode but i have probelm with jumping to kernel. Bochs give me message like this : bx_dbg_read_linear: physical memory read error(phy=...)
exception (): 3rdshut down...
I'am loading kernel like this :

Code: Select all


use16
org 0x7C00

start:
		xor eax,eax
		mov es,ax
		mov bx,01000h

		mov ah,2
		mov al,10
		xor ch,ch
		mov cl,2
		mov dh,0
		int 13h

		cli

		xor ax,ax
		mov ds,ax
		
		lgdt [gdt_desc]
		
		mov eax, cr0
		or eax, 1
		mov cr0, eax

		jmp 08h:pmode
		
		
use32
pmode:
		mov ax, 10h
		mov ds, ax
		mov ss, ax
		mov gs, ax
		mov fs, ax
		mov esp,09000h
		
kernel32:		
		jmp 08h:01000h
			
		
gdt:

gdt_null:
			dd 0
			dd 0
gdt_code:
			dw 0FFFFh
			dw 0
			db 0
			db 10011010b
			db 11001111b
			db 0
gdt_data:
			dw 0FFFFh
			dw 0
			db 0
			db 10010010b
			db 11001111b
			db 0
gdt_end:
gdt_desc:
			dw gdt_end - gdt - 1
			dd gdt
		
times 510 - ($ - $$) db 0
db 0x55
db 0xAA

Code: Select all

use32
org 01000h

main32
			;mov byte[gs:0B8000h], '+'
			;mov byte[gs:0B8001h],1Bh
			jmp main32

Please help...
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: How to jump to kernel ?

Post by thepowersgang »

Could you post the address that bochs wants to access and on what instruction the code crashes.

As a sugesstion, use the bochs debugger and put a breakpoint at the start of you code (0x7C00) and step though it until it crashes.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Mattx
Posts: 20
Joined: Fri Jul 11, 2008 5:10 am

Re: How to jump to kernel ?

Post by Mattx »

Debuging using Bochs gave me a lot of infos... instruction jmp 08h:01000h run good and he really moves on 0008:0001000 but on this address is strange instruction ( sertenly not mine) mov eax,0xd08 ble ble ble next is strange instruction number two - mov esp , some value and the last is some call instruction... and after this there is physicalmemory read error and that all.... Can somebody help me please.... What I doing wrong
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: How to jump to kernel ?

Post by Combuster »

Please, *always* post a full bochs dump when one's available.
"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 ]
Mattx
Posts: 20
Joined: Fri Jul 11, 2008 5:10 am

Re: How to jump to kernel ?

Post by Mattx »

What does it mean full dump ? Dump of memory, code , I'm beginner I set breakpoint after int 13h and then work on step mode, what should i do ? Thanks for answer.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: How to jump to kernel ?

Post by AJ »

Hi,
What does it mean full dump ?
When Bochs stops running your kernel (e.g. because of a triple fault), it normally outputs a register dump (which can be recorded in a log file by making a change to your bochsrc file.

It is the end of the dump which is usually interesting - there will be a message such as "PANIC: Main Window Closed", or "CPU[0] 3rd Fault Without Resolution." or something like that. This is followed by a dump of the general purpose registers, segment registers, control registers, instruction pointer and last executed instruction.

Cheers,
Adam
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: How to jump to kernel ?

Post by Omega »

Well, here is what I saw and I might be wrong, so if another can correct me then please do so:

01. You didn't reset the drive first.
02. Try changing this: mov esp,09000h, To this: mov esp,090000h
03. You didn't setup A20, you should do that after you disable interrupts and before your lgdt instruction.
04. I don't notice a second stage. This means your loader will break soon. I don't think you have surpassed your 18 sector limit yet, so it probably isn't anything to do with that, but just something to think about in the near future.

Other than that, if those suggestion won't help, I have no other idea as it looks pretty close to my single stage loader. Good Luck
Free energy is indeed evil for it absorbs the light.
Mattx
Posts: 20
Joined: Fri Jul 11, 2008 5:10 am

Re: How to jump to kernel ?

Post by Mattx »

Thanks guys first of all thanks for answer , and really sure if it is what you wre talking about :

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 01DE0020. after alignment, vector=01DE1000
00000000000i[MEM0 ] 32,00MB
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('C:\Program Files\Bochs-2.3.7/BIOS-bochs-latest')
00000000000i[MEM0 ] rom at 0xc0000/38400 ('C:\Program Files\Bochs-2.3.7/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 Aug 05 13:01:57 2008 (time0=1217934117)
00000000000i[DMA  ] channel 4 used by cascade
00000000000i[DMA  ] channel 2 used by Floppy Drive
00000000000i[FDD  ] fd0: 'os.img' ro=0, h=2,t=80,spt=9
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: 1280 x 1024
00000000000i[WGUI ] Number of Mouse Buttons = 3
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
00000000000i[     ] set SIGINT handler to bx_debug_ctrlc_handler
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
00008045546i[BIOS ] Booting from 0000:7c00
00008496444i[CPU0 ] CPU is in protected mode (active)
00008496444i[CPU0 ] CS.d_b = 32 bit
00008496444i[CPU0 ] SS.d_b = 32 bit
00008496444i[CPU0 ] EFER   = 0x00000000
00008496444i[CPU0 ] | RAX=00000000d08e07c0  RBX=0000000000001000
00008496444i[CPU0 ] | RCX=0000000000000002  RDX=0000000000000000
00008496444i[CPU0 ] | RSP=00000000a4e803fa  RBP=0000000000000000
00008496444i[CPU0 ] | RSI=00000000ffff0000  RDI=000000000008ffac
00008496444i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00008496444i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00008496444i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00008496444i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00008496444i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af PF CF
00008496444i[CPU0 ] | SEG selector     base    limit G D
00008496444i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00008496444i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 1 1
00008496444i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00008496444i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00008496444i[CPU0 ] |  ES:0008( 0005| 0|  0) 00000080 0000ffff 0 0
00008496444i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00008496444i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00008496444i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00008496444i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00008496444i[CPU0 ] | RIP=00000000bce81169 (00000000bce81169)
00008496444i[CPU0 ] | CR0=0x60000011 CR1=0x0 CR2=0x0000000000000000
00008496444i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00008496444e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
00008496444i[SYS  ] bx_pc_system_c::Reset(SOFTWARE) called
00008496444i[CPU0 ] cpu software reset
00008496444i[APIC0] local apic in CPU 0 initializing
I will try to check adviceses thank really !!!
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: How to jump to kernel ?

Post by Combuster »

I spotted two things, neither of which should be the problem:
- ES wasn't reloaded
- main32 is missing a colon (orphaned label)

Right now I would suggest to look at what is actually loaded into memory, probably it isn't what you think you are loading.
"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