Skip to content

Commit

Permalink
Implement yield
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Nehab committed Mar 22, 2020
1 parent 8080d55 commit 2d6123c
Show file tree
Hide file tree
Showing 22 changed files with 410 additions and 244 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
uses: Legion2/[email protected]
with:
repository: ${{ steps.git_org.outputs.current_organization }}/image-kernel
tag: 'v0.3.0'
tag: 'v0.4.0'
file: kernel.bin
token: ${{ secrets.CI_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion lib/grpc-interfaces
61 changes: 48 additions & 13 deletions src/cartesi-machine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ where options are:
--cmdline pass additional command-line arguments to kernel
--batch run in batch mode
--batch run in non-interactive mode
--yield honor yield requests by target
--initial-hash prints initial hash before running
Expand All @@ -84,6 +86,7 @@ where options are:
--store=<directory> store machine to directory
]=], arg[0]))
os.exit()
end
Expand All @@ -100,6 +103,7 @@ local rom_image = "rom.bin"
local cmdline = ""
local memory_size = 64
local batch = false
local yield = false
local initial_hash = false
local final_hash = false
local ignore_payload = false
Expand Down Expand Up @@ -131,6 +135,11 @@ local options = {
batch = true
return true
end },
{ "^%-%-yield$", function(all)
if not all then return false end
yield = true
return true
end },
{ "^%-%-(%w+)-backing%=(.+)$", function(d, f)
if not d or not f then return false end
if not backing[d] then
Expand Down Expand Up @@ -299,11 +308,19 @@ function config_meta.__index:append_cmdline(cmdline)
return self
end

function config_meta.__index:set_interactive(interactive)
self.interactive = interactive
function config_meta.__index:set_interact(interact)
self.htif = self.htif or {}
self.htif.interact = interact
return self
end

function config_meta.__index:set_yield(yield)
self.htif = self.htif or {}
self.htif.yield = yield
return self
end


function config_meta.__index:set_memory_size(memory_size)
self.ram.length = memory_size << 20
return self
Expand Down Expand Up @@ -332,7 +349,9 @@ local function new_config()
rom = {
bootargs = "console=hvc0 rootfstype=ext2 root=/dev/mtdblock0 rw",
},
interactive = true,
htif = {
interact = true,
},
flash = {},
_flash_id = 1,
}, config_meta)
Expand Down Expand Up @@ -543,8 +562,10 @@ else
"mtdparts=" .. table.concat(mtdparts, ";")
):append_cmdline(
cmdline
):set_interactive(
):set_interact(
not batch
):set_yield(
yield
)

io.stderr:write("Building machine: please wait\n")
Expand All @@ -558,17 +579,31 @@ if not json_steps then
if initial_hash then
print_root_hash(machine)
end
machine:run(max_mcycle)
local payload = 0
if machine:read_iflags_H() then
payload = (machine:read_tohost() & (~1 >> 16)) >> 1
io.stderr:write("payload: ", payload, "\n")
elseif step then
local cycles = 0
while cycles < max_mcycle do
machine:run(max_mcycle)
cycles = machine:read_mcycle()
if machine:read_iflags_H() then
local payload = machine:read_tohost() << 16 >> 17
io.stderr:write("\nHalted with payload: ", payload, "\n")
io.stderr:write("Cycles: ", cycles, "\n")
break
elseif machine:read_iflags_Y() then
local tohost = machine:read_tohost()
local cmd = tohost << 8 >> 56
local data = tohost << 16 >> 16
if cmd == 0 then
io.stderr:write("Progress: ", data, "\r")
else
io.stderr:write("\nYielded cmd: ", cmd, ", data: ", data, "\n")
io.stderr:write("Cycles: ", cycles, "\n")
end
end
end
if step then
io.stderr:write("Gathering step proof: please wait\n")
print_log(machine:step())
end
local cycles = machine:read_mcycle()
io.stderr:write("cycles: ", cycles, "\n")
if final_hash then
print_root_hash(machine)
end
Expand Down
Loading

0 comments on commit 2d6123c

Please sign in to comment.