kernel problem (C Pointer)
Re:kernel problem (C Pointer)
the cpu crashes if i load the kernel at 0x1000 and jump to 0x1000. but also if jump to 0x10000. then i try to load the kernel to 0x100000 and jump to it. bochs print out:
00000553165i[CPU ] BxError: instruction with op1=0xff
00000553165i[CPU ] nnn was 7
00000553165i[CPU ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
00000554946i[CPU ] WARNING: HLT instruction with IF=0!
bootf02 load the kernel to 0x100000, enable paging and map the kernel to FFF80000 linear
00000553165i[CPU ] BxError: instruction with op1=0xff
00000553165i[CPU ] nnn was 7
00000553165i[CPU ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
00000554946i[CPU ] WARNING: HLT instruction with IF=0!
bootf02 load the kernel to 0x100000, enable paging and map the kernel to FFF80000 linear
Re:kernel problem (C Pointer)
Looking at your code, it reminds me..
You don't have a far jump after setting cr0 to 1
Do a far jump right after setting cr0.
It's neccessary for the cpu
You don't have a far jump after setting cr0 to 1
Do a far jump right after setting cr0.
It's neccessary for the cpu
Are you sure it crashes when it jumps?the cpu crashes if i load the kernel at 0x1000 and jump to 0x1000. but also if jump to 0x10000.
Re:kernel problem (C Pointer)
You're right if I load the kernel to 0x100000 the message is print out if I load. But else if I jump.Are you sure it crashes when it jumps?
I try to Change my code to this:Looking at your code, it reminds me..
You don't have a far jump after setting cr0 to 1
Do a far jump right after setting cr0.
It's neccessary for the cpu
Code: Select all
enter_pmode:
cli
lgdt [gdt_desc]
mov eax, cr0 ; enable pmode
or eax, 1
mov cr0, eax
jmp CODE_SEL:update_registers
update_registers:
mov eax, DATA_SEL ; error ???? ???
mov ds, eax
mov es, eax
mov ss, eax
mov ds,eax
mov gs,eax
mov fs,eax
mov ax, STACK_SEL
mov ss,ax
mov esp, 0xFFFF
jmp 0x1000
Re:kernel problem (C Pointer)
It has to be a far jump.jmp CODE_SEL:update_registers
...
jmp 0x1000
..
Try jmp dword CODESEL:update_registers and
jmp dword CODESEL:0x1000
Are you sure this loads the table?lgdt [gdt_desc]
Shoudn't it be lgdt[gdt] ?
Re:kernel problem (C Pointer)
It doesn't work. :'(
before all the changes I enter pmode and all (without the little function) works!!! but just nothing!!!
the gdt_desc is a descriptor:
see gdt.inc
before all the changes I enter pmode and all (without the little function) works!!! but just nothing!!!
the gdt_desc is a descriptor:
see gdt.inc
Re:kernel problem (C Pointer)
The little function?before all the changes I enter pmode and all (without the little function) works!!! but just nothing!!!
You mean mov cr0,eax?
Try this to check it has sucessfully switched to protected mode.
Code: Select all
enter_pmode:
cli
lgdt [gdt_desc]
mov eax, cr0 ; enable pmode
or eax, 1
mov cr0, eax
jmp dword CODE_SEL:update_registers
update_registers:
mov eax, DATA_SEL ; error ???? ???
mov ds, eax
mov es, eax
mov ss, eax
mov ds,eax
mov gs,eax
mov fs,eax
mov ax, STACK_SEL
mov ss,ax
mov esp, 0xFFFF
mov bx,0B800h
mov es,bx
mov byte [es:0],'F'
mov byte [es:1],1Fh
jmp hang
hang: jmp hang
Re:kernel problem (C Pointer)
Don't know if it matters but "jmp dword CODE_SEL:update_registers" doesn't need the dword and the line "mov eax, DATA_SEL" and the ones following it can use just ax rather than eax
Pete
Pete
Re:kernel problem (C Pointer)
OK I try it and it doesn't work. Is my GDT incorrect???Try this to check it has sucessfully switched to protected mode. ...
Re:kernel problem (C Pointer)
OK I have tried some things and the result is that i don't know whats going on with my bootloader. (I know that I know nothing)
Code: Select all
enter_pmode:
cli
lgdt [gdt_desc]
mov eax, cr0 ; enable pmode
or eax, 1
mov cr0, eax
jmp dword CODE_SEL:update_registers
update_registers:
xor eax,eax ; bochs shows that eax is 0x60000000
; after this operation :-\
; mov eax, DATA_SEL if I write this the CPU crashes (exception 13)
; bochs out: write_virtual_checks(): write beyond limit, r/w
cli
hlt
Re:kernel problem (C Pointer)
try adding [bits 16] and [bits 32] directives in the right places. If you don't, NASM will compile the instructions intended to be ran in pmode- as if they were ran in rmode.
Re:kernel problem (C Pointer)
OK i forgot it. TY
but when I load my kernel to 0x1000 and jump to 0x1000
bochs out: write_virtual_checks(): write beyond limit, r/w
when I load my kernel to 0x100 and jump to 0x1000 all works fine, without the array operations.
OK but when I if create an array of integers all items are zero, too. Where the **** is the problem.
>:( ??? :-\
but when I load my kernel to 0x1000 and jump to 0x1000
bochs out: write_virtual_checks(): write beyond limit, r/w
when I load my kernel to 0x100 and jump to 0x1000 all works fine, without the array operations.
OK but when I if create an array of integers all items are zero, too. Where the **** is the problem.
>:( ??? :-\
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:kernel problem (C Pointer)
if you load starting from 0x100:0x0000 in real mode and jump to ZERO_BASED_CODE_SELECTOR:0x1000, there's no surprise it will work better than if you load at 0x1000:0x0000 and jump at ZBCS:0x1000. Read Perica's tutorial (see BonaFide in .:QuickLinkz:.) about real mode addressing if it doesn't sound straightforward, obvious and a bit insulting to you that i remind it ;D
btw, it's generally unwise to start loading at 0x100:0x0000 as the bootsector itself is located at 0x7C0:0x0000 ... so if your kernel is above 0x6C00 bytes (that's roughly 32KB), you'll find yourself overwriting your preciousss bootloader in the process ... from there anything can occur ...
btw, it's generally unwise to start loading at 0x100:0x0000 as the bootsector itself is located at 0x7C0:0x0000 ... so if your kernel is above 0x6C00 bytes (that's roughly 32KB), you'll find yourself overwriting your preciousss bootloader in the process ... from there anything can occur ...
Re:kernel problem (C Pointer)
TY, now I load my kernel at 0xFFFF:0x0010 not to 0x100000 or something else and jump to 0x100000 and see all works fine .
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:kernel problem (C Pointer)
well, it will indeed work fine as long as the A20 gate is enable (remember that BOCHS does this by default, but not all BIOSes do so) and that your kernel is smaller than 65520 bytes ...
Re:kernel problem (C Pointer)
does this mean that if my kernel is greater than 64KB i cant load it above the 1MB mark? od i have t load it in the lower 1MB itself then?
Only Human