OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:27 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Scrolling VGA terminal causing semi-null pointer dereference
PostPosted: Wed Dec 01, 2021 6:48 pm 
Offline

Joined: Thu Nov 25, 2021 7:11 pm
Posts: 17
Somehow, calling memmove to scroll the terminal ends up dereferencing some value in the first page of memory, which I deliberately leave unpaged. A page fault occurs.
Code:
memmove((void*)VGA_MEMORY,(void*)(&VGA_MEMORY[VGA_WIDTH]),(VGA_WIDTH*2)*(VGA_HEIGHT-1));
memset((void*)(&VGA_MEMORY[VGA_WIDTH*VGA_HEIGHT-1]),0,VGA_WIDTH*2);


Top
 Profile  
 
 Post subject: Re: Scrolling VGA terminal causing semi-null pointer derefer
PostPosted: Wed Dec 01, 2021 7:57 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
sed4906h wrote:
Code:
VGA_WIDTH*VGA_HEIGHT-1

The multiplication operator has higher precedence than the subtraction operator. You need parentheses to perform the subtraction before the multiplication.


Top
 Profile  
 
 Post subject: Re: Scrolling VGA terminal causing semi-null pointer derefer
PostPosted: Wed Dec 01, 2021 8:27 pm 
Offline

Joined: Thu Nov 25, 2021 7:11 pm
Posts: 17
I didn't see that, thanks. Still, the problem occurs in the memmove. Looking at the stack trace in GDB, the parameters are clearly trashed. Perhaps improperly returning from the page fault handler messed up the stack.


Top
 Profile  
 
 Post subject: Re: Scrolling VGA terminal causing semi-null pointer derefer
PostPosted: Wed Dec 01, 2021 9:27 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Isn't the page fault happening after the parameters are trashed?

But you're right that your interrupt handlers don't preserve registers. That'll cause problems. They also need to clear the direction flag and set the data segment registers appropriately for your kernel's use.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 62 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group