Monday, August 29, 2016

Program Write-up!

"Right now every core has a register, typically called the PC for programmer counter, and that register determines where the next location in memory will be interpreted as an instruction. Right now it is a register that can only be written directly too using one instruction, and branch always instruction and as an absolute mode instruction the value to write to the register is is part of the program. Other instructions can modify this register indirectly such as by adding a certain value to the current PC, or writing the current to the top of the stack and replacing it with another, but it is very difficult for a program to change this value from outside the program.
One method is the return from subroutine” which places the value on top of the system stack into the PC, thus returning from a previous “jump to subroutine”. If can be very difficult to get the program to change this value to something other than what was intended in the program (stack smashing).
WRITEUP
One of the reasons this register is carefully guarded is because it involves security of the system. If this value were easy to change, say another program in running in the computer, then it could be made to run any code at all and that would mean not only the security of the system was in jeopardy but the integrity since not all of memory is stored instructions. Suppose there was a location in memory you could write a value to that would be moved into the PC within the next second? That would mean that code on the system could call other code on the system simply by writing to memory. Or even self modifying code that change the value on the fly to call different routines at the end of the same entry point.
This latter feature, or something built into the CPU itself, would allow a computer to program itself, either by modifying its own code or writing code into memory and them doing a “jump to address” by directly changing the PC. If you did that computers will do exactly what they will do long before 25 years and simply write code themselves, whether for their purposes or ours. Maybe even if they don’t have such a mechanism, maybe they’ll figure it out on their own.
Will they write code on the fly for each function they choose or will they start storing often used code in various locations in memory, remembering where it is and what it is for so they can simply jump there in the future? If anybody has ported Forth in ITC mode they know exactly what I’m talking about.
No need for returns, just call and jump back to the main routine. Or like in the old days, write the address of the function you choose to call at the end of another calling routine, and jump around from one to another in the order you need to get things done. Write some code at $a843c5c2 that ends with a jump back to PC+1 instruction, jump there and return back to here with no need to involve the stack.
I’m not sure what code or even operating systems will look like in 25 years but I do know they won’t be written by us."

No comments:

Post a Comment