Code Monkey home page Code Monkey logo

Comments (9)

pavelkryukov avatar pavelkryukov commented on May 26, 2024

I would like to have a real stress test with many cases of self-modifying code (SMC). It should be in a single file (smc.s). The trace begins with the simplest case: modifying instruction is executed ~10 instruction before instruction it modifies, than the gap becomes closer: 4, 3, 2, 1, 0 instructions.

What instructions should we not use for filling?

  • Branches
  • Loads
  • Multiplication/Division

so we use only simplest logical instructions and stores to create SMC context.

Each modified instruction must be followed by a checking instruction which compares its result with the expected result. If the actual result does not match expected result, execution jumps to error output (please, copy it exactly from tt.core.s).

Please check at least 3 types of modification of ALU instructions:

  • Modification of immediate (addi %r1, %r2, $5 -> addi %r1, %r2, $a5)
  • Modification of register (addi %r1, %r2, $5 -> addi %r3, %r1, $5)
  • Modification of opcode (add %r1, %r2, %r2 -> sub %r1, %r2, %r2)

Then you check SMC on branches. I suggest to use one case but test it with different gaps (10, 4, 3, 2, 1, 0):

  • j $old_target β†’ j $new_target

It would be nice to add the new trace to our test suites, but I'll create separate issue for this.

from mips-traces.

pavelkryukov avatar pavelkryukov commented on May 26, 2024

@qsuo I would like to use this trace for demonstration on lecture on 10 Nov. It would be nice if you complete the task before that deadline.

from mips-traces.

pavelkryukov avatar pavelkryukov commented on May 26, 2024

@qsuo Danil, do you have any progress with that?

from mips-traces.

qsuo avatar qsuo commented on May 26, 2024

@pavelkryukov yes, I'm in process

from mips-traces.

pavelkryukov avatar pavelkryukov commented on May 26, 2024

Ok, nice to hear. Please let me know if there is a problem.

from mips-traces.

pavelkryukov avatar pavelkryukov commented on May 26, 2024

Example of SMC: https://github.com/rweics/Curry-fun

To load absolute address of a label, use la pseudoinstruction

from mips-traces.

pavelkryukov avatar pavelkryukov commented on May 26, 2024

By the way, the author uses a nice trick: he loads an instruction from some unreachable code and than stores it.

smc:
  add $t0, $t1, $t2
  la $t0, new_instr
  lw $t0, 0x0($t0)
  la $t1, smc
  sw $t0, 0x0($t1)
  jr $ra ; something to never reach code below
new_instr:
  and $t0, $t1, $t2

from mips-traces.

qsuo avatar qsuo commented on May 26, 2024

@pavelkryukov I don't understand task completely. We should insert ~10 instructions between intruction, which we want to modificate, and the instruction which modificate, shouldn't we? Somthing like this

    la $t1, new
    lw $t0, 0($t1)
    la $t1, smc

    sw $t0, 0($t1)

    #~10 insrtuctions
 
smc:
    
    add $t0, $t1, $t2 

new:
    and $t0, $t1, $t2

from mips-traces.

pavelkryukov avatar pavelkryukov commented on May 26, 2024

Yes, you understood it correctly.

Let me give some motivation. On previous lecture we studied a "single-cycle" implementation of CPU, it executes next instruction if and only if the previous one is completed. That approach is very naïve. Real high-end CPUs overlap execution of different instructions through pipelines, so the old version of instruction may be executed if there is no special handling introduced. If there is a 10 instructions gap, MIPT-MIPS CPU won't be affected, but decreasing the gap will introduce some problems.

from mips-traces.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.