Dear all, I want to open just another can of worms... ;-) Do we have a common dependable definition of the standard hardware the Oberon software is expected to run on? I think that the defining document should be "The RISC Architecture" [1], which bears the date "NW 5.12.10, rev. 9.8.2018". This is the latest document on RISC5 I'm aware of. I think that this paper does not answer the following questions (please note that I myself guessed answers while writing my RISC5 simulator, but I was never sure to have guessed right): 1. What is the endianness of RISC5? 2. Is the offset in memory instructions (format F2) sign-extended? 3. The SUB instruction "also sets the C flag". How is this to be interpreted? Example: compute 3-5. If you really subtract in binary, the carry will be set. If you add -5 in 2's complement representation, the carry will be cleared. 4. What happens on (synchronous) exceptions? a) unaligned word access b) unknown instruction c) division by zero d) floating-point overflow e) floating-point underflow 5. What happens exactly on interrupt? 6. Are nested interrupts supported? 7. Does STI delay the setting of intenb by one instruction? Does RTI automatically set intenb? If both questions are answered negatively, then there is a race condition in the sequence (STI, RTI), with a nested interrupt as a possible result. 8. Can external devices other than the timer interrupt? 9. All external devices are grossly underspecified. (The list is not complete.) Although I really want these questions to be answered, what interests me most is: *how* do we find answers to them? Some alternatives are: - Anything that is not specified is intentionally left so. Implement at your free choice. This will severely hamper exchanging software, especially in binary form. - Take NW's implementation and analyze the circuits (or just try it out). This promotes his implementation to a "reference design". - Choose any one of the various simulators and declare it to be the "gold standard". Which one? - Discuss each question here on the list and come to an agreement. A bit cumbersome, but manageable. Other ideas? Thanks, Hellwig [1] https://people.inf.ethz.ch/wirth/FPGA-relatedWork/RISC-Arch.pdf
Hellwig Interesting questions. Most of them are left to the implementation...
1. What is the endianness of RISC5? Oberon code assuming a certain endianness is bad code. Why do you see the need to specify this? Of course, Oberon code can find out easily the endianness of the HW it‘s running on, but where does it matter? When I programmed the TCP stack, I could do certain shortcuts when I know the endianness. But whether net-order is the same as memory-order should not play a role: you should call in all curcumstances the translate procedure, even if it is empty. In my point of view, endianness is a property of the environment/memory (RISC5Top.v) not of the RISC-5 CPU.
2. Is the offset in memory instructions (format F2) sign-extended? As the Oberon machine only has 1 MB of memory, it makes no difference whether it is sign extended or not. However, the „official“ RISC-5 Verilog implementation has an address bus of 24bit (up to 16 MB). Yes: it sign extends „off“ as you can see here: assign adr = stallL0 ? B[23:0] + {{4{off[19]}}, off} : {pcmux, 2'b00}; 3. The SUB instruction "also sets the C flag". How is this to be interpreted? Example: compute 3-5. If you really subtract in binary, the carry will be set. If you add -5 in 2's complement representation, the carry will be cleared. If you subtract, RISC5.v sets the C bit according to this boolean expression (~sb&sc&~sa) | (sb&sc&sa) | (~sb&sa) Looking at your example a=3, b=5, c=-2 ==> C is set (1st rule) If you add, the C bit is set to the following boolean expression: (~sb&sc&~sa) | (sb&sc&sa) | (sb&~sa) Looking at your example a=3, b=-5, c=-2 ==> C is set. (3rd rule)
4. What happens on (synchronous) exceptions? a) unaligned word access Not detected by the CPU. The environment (RISC5Top.v) just ignores the two lowest bits when accessing memory. assign SRadr = vidreq ? vidadr : adr[19:2]; VAR m: INTEGER; SYSTEM.GET(0, m); SYSTEM.GET(1, m); SYSTEM.GET(2, m); SYSTEM(3, m) return exactly the same m. b) unknown instruction The „op“ field in F0 and F1 are decoded completely. The u flag is only looked at if needed. There is no check whether u=0, when there is no special meaning for u=1. So, as example: LSL behaves the same whether u=0 or u=1.
c) division by zero Integer (Divider.v): algorithm generates nonsense. So, the compiler generates check on 0 and generates a Trap. Floating point(FPDivder.v): result is +-infinity depending on the sign of the numerator.
d) floating-point overflow Denormalized or 0 is generated. e) floating-point underflow Result is NaN.
5. What happens exactly on interrupt? When the irq signals becomes high, an interrupt is pending. It causes intAck to become high, if a) interrupts are enabled (intEnb), b) the processor is not currently executing another interrupt handler (~intMd), and c) the processor is not stalled. When intAck is high, the current PC is saved in the new SPC register, and pcmux becomes 1, i.e. the next instruction is read from address 4. At the same time, the condition bits are also saved (in SPC[21:18]), and the processor enters the interrupt mode.
6. Are nested interrupts supported? No, see b) above
7. Does STI delay the setting of intenb by one instruction? No. After execution of STI 1, intenb is set. Does RTI automatically set intenb? No, RTI resets intMd, thus enabling interrupts again, if they were enabled before. intMd can be seen as filter for intEnb. Interrupts need one cycle to be detected. (irq1 <= irq; // edge detector)
If both questions are answered negatively, then there is a race condition in the sequence (STI, RTI), with a nested interrupt as a possible result.
8. Can external devices other than the timer interrupt? Yes. „irq“ is an input signal to the CPU. The current implementation of RISC5Top.v sets irq equal to cnt==24999, so an interrupt every millisec. Other RISC5Top.v might do differently.
9. All external devices are grossly underspecified. (The list is not complete.)
Although I really want these questions to be answered, what interests me most is: *how* do we find answers to them? Some alternatives are: - Anything that is not specified is intentionally left so. Implement at your free choice. This will severely hamper exchanging software, especially in binary form. - Take NW's implementation and analyze the circuits (or just try it out). This promotes his implementation to a "reference design". - Choose any one of the various simulators and declare it to be the "gold standard". Which one? - Discuss each question here on the list and come to an agreement. A bit cumbersome, but manageable. Other ideas?
Thanks, Hellwig
[1] https://people.inf.ethz.ch/wirth/FPGA-relatedWork/RISC-Arch.pdf
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Hellwig - Anything that is not specified is intentionally left so. Implement at your free choice. This will severely hamper exchanging software, especially in binary form. If you use Files (as the compiler does) this is not true. Files has its own presentation layer. Files.WriteInt does NOT just dump the internal (endian) presentation in a file!! It always uses little endian independent on the internal HW endianness. - Take NW's implementation and analyze the circuits (or just try it out). This promotes his implementation to a "reference design". This was my approach. I found some discrepancies in the behavior of the FPGA HW and some emulators. Eg. FLOOR(x), x >= 2^25. br Jörg
Jörg, thanks for your answers. You may have overlooked, however, my remark "please note that I myself guessed answers while writing my RISC5 simulator, but I was never sure to have guessed right"... :-) I did of course analyze the boolean expressions in NW's RISC5 implementation and incorporated this knowledge in my simulator; otherwise I would not have been able to run the system. I posed the list of open questions because I wanted to show that the "specification" of RISC5 (without its implementation) is incomplete, and does not guarantee that a new machine, while observing the specs, can run the existing software. I pick out only two points: On Mi, 2021-01-06 at 16:19 +0100, Jörg wrote:
1. What is the endianness of RISC5? Oberon code assuming a certain endianness is bad code. Why do you see the need to specify this? Of course, Oberon code can find out easily the endianness of the HW it‘s running on, but where does it matter? When I programmed the TCP stack, I could do certain shortcuts when I know the endianness. But whether net-order is the same as memory-order should not play a role: you should call in all curcumstances the translate procedure, even if it is empty. In my point of view, endianness is a property of the environment/memory (RISC5Top.v) not of the RISC-5 CPU.
With the wrong endianness, even the first instruction fetch will fail - the byte order is wrong, if the code has been produced on another machine with different endianness. You could argue: do only run code produced on the very same machine. Fine - how do I even start? (Please do not answer this rhetorical question. I know how to do that, and have done it in the past, which was difficult enough. It involves re-writing part of the compiler's back-end.) The compiler has to generate floating-point constants, right? Their endianness *must* be specified, otherwise the FP unit cannot work properly. So again: do only run code... That was the reason I wrote "This will severely hamper exchanging software, especially in binary form."
2. Is the offset in memory instructions (format F2) sign-extended? As the Oberon machine only has 1 MB of memory, it makes no difference whether it is sign extended or not. However, the „official“ RISC-5 Verilog implementation has an address bus of 24bit (up to 16 MB). Yes: it sign extends „off“ as you can see here: assign adr = stallL0 ? B[23:0] + {{4{off[19]}}, off} : {pcmux, 2'b00};
The "specification" does not define this behavior. etc. If I may sum up your argumentation: You propose to take NW's implementation as reference design. This is dangerous, regardless of which origin it is: Did you try lately to multiply (1 << 31) by (1 << 31) as unsigned numbers? The last time I did, the result was wrong (see my mail from Sun, 4 Mar 2018). Furthermore, it is in many cases unclear, if a specific behavior is part of the specification or a by-product of its implementation. Nevertheless, thanks again for your answers. Hellwig
Just a correction: On Mi, 2021-01-06 at 18:11 +0100, Hellwig Geisse wrote:
The compiler has to generate floating-point constants, right? Their endianness *must* be specified, otherwise the FP unit cannot work properly. So again: do only run code...
This argument is not correct, as Jörg kindly pointed out: .rsc-Files are written and read via the File interface, and this interface defines a specific endianness (little-endian) for 32-bit words. So the only conversion takes place when reading/writing these values from/to memory, which is automatically done in the correct endianness of the machine doing the operation. Hellwig
participants (3)
-
Hellwig Geisse -
Joerg -
Jörg