Page 1 of 1
Scrolling VGA terminal causing semi-null pointer dereference
Posted: Wed Dec 01, 2021 6:48 pm
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);
Re: Scrolling VGA terminal causing semi-null pointer derefer
Posted: Wed Dec 01, 2021 7:57 pm
by Octocontrabass
The multiplication operator has higher precedence than the subtraction operator. You need parentheses to perform the subtraction before the multiplication.
Re: Scrolling VGA terminal causing semi-null pointer derefer
Posted: Wed Dec 01, 2021 8:27 pm
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.
Re: Scrolling VGA terminal causing semi-null pointer derefer
Posted: Wed Dec 01, 2021 9:27 pm
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.