ZaneDubya / YCPU

An imaginary 16-bit cpu, with a complete specification, emulator, assembler, and disassembler, in C#.
24 stars 3 forks source link

Conflicting information about control registers in user mode #21

Closed ghost closed 3 years ago

ghost commented 3 years ago

In 3.B, it is implied that user cannot write to FL, PC, PS, and SP, although they all can still be read.

https://github.com/ZaneDubya/YCPU/blob/0af90f8e6ad8adb4e19847ad9d636b685b8520f7/Documentation/ycpu.txt#L559

In 4.A (ALU Bit Pattern), user can only write to FL, PC, and USP, but not PS.

https://github.com/ZaneDubya/YCPU/blob/0af90f8e6ad8adb4e19847ad9d636b685b8520f7/Documentation/ycpu.txt#L1342-L1355

Additionally, in the C# source, user cannot read from PS.

https://github.com/ZaneDubya/YCPU/blob/0af90f8e6ad8adb4e19847ad9d636b685b8520f7/Source/Libraries/YpsilonCPU/Emulation/Processor/YCPU.cs#L163-L166

I think 4.A makes sense, but I'm not sure if user should be able to read PS. 🤔

ZaneDubya commented 3 years ago

Hello @Naryosha,

Thank you kindly for the review of the specification and the model emulator! I also appreciate the excellent issue formatting.

The correct behavior is reflected by the specification at 4.A: FL, PC, and SP are readable and writable in user mode. PS is readable but not writeable. The implication on line 559 of the specification is incorrect: only the Processor Status register is not writeable in user mode. In addition, the model emulator is incorrect in that it would raise a fault if a program in user mode attempted to read from the Processor Status register. The hardware YCPU allows this behavior and would return the value of PS.

If you have the time, I would sincerely appreciate it if you would correct the specification and model emulator where they do not conform to 4.A.

Best wishes!

ghost commented 3 years ago

Thank you for the explanation. I have some more questions but don't think it worths another issue. So, here goes:

P.S. here's my WIP :) Screenshot from 2020-11-11 22-29-38

ZaneDubya commented 3 years ago

@Naryosha This is phenomenal. Thanks for your work here. I am reviewing it today.

Your WIP looks amazing as well. 💯