No Coprocessor Exception after enabling paging

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
leledumbo
Member
Member
Posts: 103
Joined: Wed Apr 23, 2008 8:46 pm

No Coprocessor Exception after enabling paging

Post by leledumbo »

Here's my paging unit:

Code: Select all

unit paging;

interface

procedure InstallPaging;

implementation

uses
  screen;

var
  PageDirectory: PLongWord; external name 'page_directory';
  PageTable: PLongWord; external name 'page_table';

function ReadCr0: LongWord; external name 'read_cr0';
procedure WriteCr0(Value: LongWord); external name 'write_cr0';
function ReadCr3: LongWord; external name 'read_cr3';
procedure WriteCr3(Value: LongWord); external name 'write_cr3';

procedure FillPageTable;
var
  i: Word;
begin
  for i:=0 to 1023 do
    PageTable[i]:=(i*4096) or 3; // 011 (supervisor, read/write, present)
end;

procedure FillPageDirectory;
var
  i: Word;
begin
  PageDirectory[0]:=PtrUInt(PageTable);
  PageDirectory[0]:=PageDirectory[0] or 3;
  for i:=1 to 1023 do
    PageDirectory[i]:=2; // 010 (supervisor, read/write, NOT present)
end;

procedure InstallPaging;
begin
  WriteStr('Installing Paging... ');
  FillPageDirectory;
  FillPageTable;
  WriteCr3(PtrUInt(PageDirectory)); // put PageDirectory address into CR3
  WriteCr0(ReadCr0 or $80000000); // set the paging bit in CR0 to 1
  WriteStrLn('Done.');
end;

end.
External variables and functions in asm:

Code: Select all

section .text
...
; Paging helper functions
global read_cr0
read_cr0:
  mov  eax,cr0
  retn

global write_cr0
write_cr0:
  push ebp
  mov  ebp,esp
  mov  eax,[ebp+8]
  mov  cr0,eax
  pop  ebp
  retn

global read_cr3
read_cr3:
  mov  eax,cr3
  retn

global write_cr3
write_cr3:
  push ebp
  mov  ebp,esp
  mov  eax,[ebp+8]
  mov  cr3,eax
  pop  ebp
  retn
...
section .bss
;
; Page directory & page table
;
align 4096

global page_directory
page_directory:
  resd 1024

global page_table
page_table:
  resd 1024
I install paging my executing InstallPaging above, since then, every time I move memory contents via Move procedure (C's memcpy equivalent), I always got No Coprocessor Exception. However, I can't print any register contents. Trying to do so results in Triple Fault.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: No Coprocessor Exception after enabling paging

Post by JamesM »

I highly doubt that you're actually getting a no coprocessor exception. It sounds to me like your interrupt handlers are reporting the wrong exception number; This is backed up by the fact that you can't read your registers.

Testing your interrupt handlers in some way may help diagnose the problem.
Laksen
Member
Member
Posts: 140
Joined: Fri Nov 09, 2007 3:30 am
Location: Aalborg, Denmark

Re: No Coprocessor Exception after enabling paging

Post by Laksen »

You have to use another calling convention for your external procedures. It looks you are using cdecl, but you probably call them with fastcall, which is the default. This will cause big problems if that's the problem :P
http://j-software.dk | JPasKernel - My Object Pascal kernel
Post Reply