[Oberon] FPGA Oberon Article in Xilinx Xcell Journal
Jörg Straube
joerg.straube at iaeth.ch
Fri May 15 08:50:08 CEST 2015
By writing MODULE* you disable run time checking :-)
Compile it as MODULE and you will get your trap.
Br, Jörg
> Am 15.05.2015 um 01:06 schrieb David Hunter <drhunter at frontiernet.net>:
>
> It was a good article.
>
> I concur that system integrity can definitely be violated. I did a quick example of an array overflow. (see the code at the end of this post) I ran it on a Spartan FPGA and it printed all 12 characters without a problem. From what I can tell looking at the disassembled code, the RISC5 compiler does not add "run time checking."
>
> Dave
>
>> On 5/14/2015 6:00 AM, oberon-request at lists.inf.ethz.ch wrote:
>> ------------------------------
>>
>> Message: 4
>> Date: Wed, 13 May 2015 19:47:49 +0200
>> From: Michael Schierl <schierlm at gmx.de>
>> Subject: Re: [Oberon] FPGA Oberon Article in Xilinx Xcell Journal
>> (Issue 91)
>> To: oberon at lists.inf.ethz.ch
>> Message-ID: <55538E45.5020303 at gmx.de>
>> Content-Type: text/plain; charset=windows-1252
>>
>> Am 13.05.2015 um 15:15 schrieb Srinivas Nayak:
>>
>>> > Good to see the article.
>>> > Here is the pdf.
>>> > www.xilinx.com/publications/archives/xcell/Xcell91.pdf
>> Quoted from the article:
>>
>> "In fact, system integrity can be violated only by the use of operations
>> in the pseudo-module SYSTEM, namely PUT and COPY"
>>
>>
>> That's wishful thinking... System integrity can easily be violated by
>> accessing uninitialized variables on the stack (it is left as an
>> exercise to the reader to abuse this for implementing SYSTEM.PUT for the
>> RISC processor in pure Oberon without importing the SYSTEM module). And
>> there is no easy way of fixing this that does not impact performance
>> (like initializing all variables on the stack), as the Oberon language
>> neither has a notion of uninitialized variables, nor of "out" parameters.
>>
>> I think the bug in System.Clear that sometimes overwrites some random
>> piece of memory due to accessing an uninitialized pointer has not been
>> fixed yet in the source published on Project Oberon, either.
>>
>>
>> But apart from that, I like the article, too :)
>>
>>
>> Regards,
>>
>>
>> Michael
>>
>
>
> =================================================================================================
> Source:
>
> (* Overflow.Mod
> *
> * (c) SkuTek Instrumentation
> * D. Hunter
> * This program tests if array bounds checking is done
> * Versions:
> * 0.1 05/14/15 DH - initial version
> *)
>
> MODULE* Overflow; (* embedded module *)
> IMPORT SYSTEM;
>
> CONST
> (* ASCII characters *)
> LF = 0AX;
> CR = 0DX; (* CR / LF characters *)
> SPC = 20X; (* space character *)
> PRMPT = 23X; (* prompt character = # *)
> DOT = 2EX; (* period or decimal point *)
>
> (* I/O addresses at top of memory map,
> NOTE: the values need to be negative to generate the correct instructions *)
> UDATA = -56; (* UART data *)
> USTAT = -52; (* UART status *)
>
> (* UART status flags *)
> RXF = 0; (* receive ready flag is in bit 0 *)
> TXF = 1; (* transmit ready flag is in bit 1 *)
>
> (* test parameters *)
> SIZE = 10; (* array size *)
> STOP = 12; (* stop index *)
>
>
> VAR
> i : INTEGER;
> test: ARRAY SIZE OF CHAR;
> (* ========================================= *)
> (* UART transmit procedures *)
>
> (* send a character to the UART
> NOTE: the extra time converting to a set helps slow down
> the polling, which is desired with such a fast processor *)
> PROCEDURE PutChar(c: CHAR);
> VAR
> s: SET; (* status bit field *)
> stat: INTEGER; (* integer status *)
> BEGIN
> REPEAT (* wait for a transmitter ready *)
> SYSTEM.GET(USTAT,stat); (* get UART status *)
> s := SYSTEM.VAL(SET,stat) (* convert to set *)
> UNTIL (TXF IN s); (* loop until transmit ready is set *)
>
> SYSTEM.PUT(UDATA,ORD(c)) (* send character *)
> END PutChar;
>
> (* ========================================= *)
> (* send a CR/LF to the UART *)
> PROCEDURE WriteLn;
> BEGIN
> PutChar(CR);
> PutChar(LF)
> END WriteLn;
>
> (* main program *)
>
> BEGIN
> REPEAT
> LED(0);
> PutChar(PRMPT); PutChar(SPC);
> FOR i := 0 TO STOP DO;
> test[i] := CHR(41H + i); (* store character into the array *)
> PutChar(test[i])
> END;
> PutChar(DOT); WriteLn;
> LED(2);
> FOR i := 0 TO 100000 DO; (* pause *)
> END;
> UNTIL FALSE;
>
> END Overflow.
>
> =================================================================================================
> Compiled code with Oberon module added:
>
> ORTool 29.10.2014
> decode Overflow.rsc
> Overflow E9D4E4B5 0 340
> imports:
> type descriptors
>
> data 16
> strings
>
> code
> 0 E7000021 B 33 ; branch start
> 1 00000000 MOV R0 R0 R0
> 2 00000000 MOV R0 R0 R0
> 3 00000000 MOV R0 R0 R0
> 4 00000000 MOV R0 R0 R0
> 5 00000000 MOV R0 R0 R0
> 6 00000000 MOV R0 R0 R0
> 7 00000000 MOV R0 R0 R0
> 8 4EE90010 SUB SP SP 16 PROCEDURE PutChar(c);
> 9 AFE00000 STR LNK SP 0 BEGIN
> 10 A0E00004 STR R0 SP 4 [ save c on stack ]
> 11 5000FFCC MOV R0 R0 -52 REPEAT
> 12 80000000 LDR R0 R0 0 SYSTEM.GET(USTAT,stat);
> 13 A0E0000C STR R0 SP 12
> 14 80E0000C LDR R0 SP 12
> 15 A0E00008 STR R0 SP 8 s := SYSTEM.VAL(SET, stat)
> 16 80E00008 LDR R0 SP 8
> 17 40030002 ROR R0 R0 2
> 18 E8FFFFF8 BPL -8 UNTIL (TXF in s);
> 19 90E00004 LDR R0 SP 4
> 20 5100FFC8 MOV R1 R0 -56
> 21 A0100000 STR R0 R1 0 SYSTEM.PUT(UDATA,ORD(c))
> 22 8FE00000 LDR LNK SP 0
> 23 4EE80010 ADD SP SP 16
> 24 C700000F B LNK END PutChar;
> 25 4EE90004 SUB SP SP 4 PROCEDURE WriteLn;
> 26 AFE00000 STR LNK SP 0 BEGIN
> 27 4000000D MOV R0 R0 13
> 28 F7FFFFEB BL -21 PutChar(CR);
> 29 4000000A MOV R0 R0 10
> 30 F7FFFFE9 BL -23 PutChar(LF);
> 31 8FE00000 LDR LNK SP 0
> 32 4EE80004 ADD SP SP 4
> 33 C700000F B LNK END WriteLn;
> 34 4D000010 MOV SB R0 16 Entry: set SB = 16
> 35 4E008000 MOV SP R0 -32768 set SP = 8000H
> 36 40000000 MOV R0 R0 0 BEGIN REPEAT
> 37 5100FFC4 MOV R1 R0 -60
> 38 A0100000 STR R0 R1 0 LED(0);
> 39 40000023 MOV R0 R0 35
> 40 F7FFFFDF BL -33 PutChar(PRMPT);
> 41 40000020 MOV R0 R0 32
> 42 F7FFFFDD BL -35 PutChar(SPC);
> 43 40000000 MOV R0 R0 0 FOR i := 0 TO STOP DO;
> 44 4109000C SUB R1 R0 12
> 45 EE00000E BGT 14
> 46 A0D00000 STR R0 SB 0
> 47 80D00000 LDR R0 SB 0
> 48 00D80000 ADD R0 SB R0
> 49 41000041 MOV R1 R0 65
> 50 82D00000 LDR R2 SB 0
> 51 01180002 ADD R1 R1 R2
> 52 B1000004 STR R1 R0 4 test[i] := CHR(41H + 1);
> 53 80D00000 LDR R0 SB 0
> 54 00D80000 ADD R0 SB R0
> 55 90000004 LDR R0 R0 4
> 56 F7FFFFCF BL -49 PutChar(test[i]);
> 57 80D00000 LDR R0 SB 0
> 58 40080001 ADD R0 R0 1
> 59 E7FFFFF0 B -16 END;
> 60 4000002E MOV R0 R0 46
> 61 F7FFFFCA BL -54 PutChar(DOT);
> 62 F7FFFFDA BL -38 WriteLn;
> 63 40000002 MOV R0 R0 2
> 64 5100FFC4 MOV R1 R0 -60
> 65 A0100000 STR R0 R1 0 LED(2);
> 66 40000000 MOV R0 R0 0 FOR i := 0 TO 100000 DO;
> 67 61000001 MOV' R1 R0 1
> 68 411686A0 IOR R1 R1 -31072
> 69 01090001 SUB R1 R0 R1
> 70 EE000004 BGT 4
> 71 A0D00000 STR R0 SB 0
> 72 80D00000 LDR R0 SB 0
> 73 40080001 ADD R0 R0 1
> 74 E7FFFFF8 B -8 END;
> 75 E7FFFFD8 B -40 UNTIL FALSE;
> 76 40000000 MOV R0 R0 0
> 77 C7000000 B R0 Branch to 00000H [never executed]
>
>
>
> This email has been checked for viruses by Avast antivirus software.
> www.avast.com
>
>
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.inf.ethz.ch/pipermail/oberon/attachments/20150515/3f8fd529/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2376 bytes
Desc: not available
Url : https://lists.inf.ethz.ch/pipermail/oberon/attachments/20150515/3f8fd529/attachment.bin
More information about the Oberon
mailing list