ugly Exception 14.....

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
viral

ugly Exception 14.....

Post by viral »

Hello...
My kernel is in C++.I am having problem with my paging code. I am enabling paging in kstart.asm stub (the asm file which call _main function).I remap kernel from 0x100000 to 0xC0100000. now the problem comes, it crashes when 'call _main' instruction is executed. the kernel runs well if i dont remap it to 0xC0100000.
I have tried " .text 0xC0100000: {" in linker script but still it crashes. Bochs givin me EXCEPTION 14. The paging is enabled successfully as CR0 is showing correct value. I know the problem comes when call _main inst comes. I have map GDT to 4gb code and data descriptor.



; Loader.asm
[BITS 32] ; protected mode

[global start]
[extern __main]    ; this is our C support code


start:
;/////////////////////////////////////////////////////////////////////; Change the base address of kernel from 0x0 to 0xC0000000 and enables paging
;/////////////////////////////////////////////////////////////////////   mov eax, 0x9C000      
   clearpagedir:
      mov dword [eax], 2
      add eax, 4
      ;cmp eax, 0xA0000
      cmp eax, 0x9D000
      jne clearpagedir
   
   mov eax, 0x9D400
   mov ebx, 0x100000

   bindkernel:
      mov ecx, ebx
      or ecx, 3
      mov dword [eax], ecx
      add eax, 4
      add ebx, 4096
      cmp eax, 0x9D800
      jne bindkernel

   bindothers:
      mov dword [0x9D03C], 0xF003
      mov dword [0x9D2E0], 0xB8003
      mov dword [0x9E000], 0x9B003

      mov dword [0x9C000], 0x9D003
      mov dword [0x9CC00], 0x9D003
      mov dword [0x9CD00], 0x9E003
      mov dword [0x9CFFC], 0x9C003
      mov dword [0x9CFF8], 0x9F003
      
      mov eax, 0x9C000
      mov cr3, eax

      cli
      mov eax, cr0
      or eax, 0x80000000
      mov cr0, eax
      ;hlt

      jmp 0xC0000000 + getsetup
   getsetup:
      
      ;mov eax, 0xC0000000
      ;add esp, eax
      
      add esp, 0xC0000000
   unpage0x0:
      mov dword [0xFFFFF000], 0x2   
      mov eax, cr3
      mov cr3, eax

hlt
call _main

cli    ; interrupts will disturb the halt
hlt    ; halt the CPU
viral

Re:ugly Exception 14.....

Post by viral »

Please ignore that "HLT" instruction above "call _main". Its in comment.

;hlt
call _main
cli
hlt
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:ugly Exception 14.....

Post by Pype.Clicker »

what's the value of eax when _start is called ?
Kim

Re:ugly Exception 14.....

Post by Kim »

mov eax, 0x9C000 <- formating messed it up :)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:ugly Exception 14.....

Post by Pype.Clicker »

Code: Select all

      cli
      mov eax, cr0
      or eax, 0x80000000
      mov cr0, eax
      ;hlt

      jmp 0xC0000000 + getsetup
   getsetup:
Imho, that's where things are messed up. I don't see you self-mapping the current code, which means when you enable paging, the current code page magically becomes non-present and the attempt to read "jmp ..." instruction fails.

There's no such thing like "you need to reload XYZ so that new things apply" concerning paging: when it's enabled, it's enabled and if you don't have things properly set up, you're doomed.

Btw, i *strongly* suggest you give names to your page table address (e.g. [ PGDIR+KERNELTABLE ] instead of [ 9C400 ] or whatever)
viral

Re:ugly Exception 14.....

Post by viral »

I found this code from Viridis kernel. I dont knw why its doing
"jmp 0xC0000000+getsetup" may be to change value of EIP so that it point to 0xC0100000 instead of 0x100000. Can you give me some example to remap kernel from 0x100000 to 0xC0000000.
AR

Re:ugly Exception 14.....

Post by AR »

The point Pype is telling you is that you need to map the kernel at BOTH 0x100000 and 0xC0100000, once you execute the jump to 0xC0100000 then you can unmap 0x100000.
viral

Re:ugly Exception 14.....

Post by viral »

Ya thats right... the following code map both 0x100000 and 0xC0100000 to page:
mov dword [0x9C000], 0x9D003 ; map 0x100000
mov dword [0x9CC00], 0x9D003 ; map 0xC0100000
then i enable paging and update EIP & ESP and then unmap 0x100000.....
Hence i am doing so... .but still its not working....
viral

Re:ugly Exception 14.....

Post by viral »

BTW the bochs output on exception 14 is:

00002784352e[CPU0 ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
00002784352i[SYS ] Last time is 1118208615
00002784352i[CPU0 ] protected mode
00002784352i[CPU0 ] CS.d_b = 32 bit
00002784352i[CPU0 ] SS.d_b = 32 bit
00002784352i[CPU0 ] | EAX=0009c000 EBX=00200000 ECX=001ff003 EDX=534d4150
00002784352i[CPU0 ] | ESP=c0000800 EBP=00000021 ESI=00007de5 EDI=00000005
00002784352i[CPU0 ] | IOPL=0 NV UP DI NG NZ NA PE NC
00002784352i[CPU0 ] | SEG selector base limit G D
00002784352i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00002784352i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00002784352i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00002784352i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00002784352i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00002784352i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00002784352i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00002784352i[CPU0 ] | EIP=c0101414 (c0101414)
00002784352i[CPU0 ] | CR0=0x80000011 CR1=0 CR2=0x00000040
00002784352i[CPU0 ] | CR3=0x0009c000 CR4=0x00000000
00002784352i[ ] restoring default signal behavior
00002784352i[CTRL ] quit_sim called with exit code 1
Post Reply