Scrolling VGA terminal causing semi-null pointer dereference

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
sed4906h
Posts: 17
Joined: Thu Nov 25, 2021 7:11 pm

Scrolling VGA terminal causing semi-null pointer dereference

Post by sed4906h »

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: Select all

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);
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Scrolling VGA terminal causing semi-null pointer derefer

Post by Octocontrabass »

sed4906h wrote:

Code: Select all

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.
sed4906h
Posts: 17
Joined: Thu Nov 25, 2021 7:11 pm

Re: Scrolling VGA terminal causing semi-null pointer derefer

Post by sed4906h »

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.
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Scrolling VGA terminal causing semi-null pointer derefer

Post by Octocontrabass »

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.
Post Reply