Skip to content

Commit

Permalink
rename blk to brk, change some log level
Browse files Browse the repository at this point in the history
  • Loading branch information
weilzkm committed Jun 7, 2024
1 parent cddba34 commit 2db4a70
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/cpu/exit_kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) fn generate_exit_kernel<F: RichField>(state: &mut GenerationState<F>,
registers_value[34] = state.registers.heap as u32;
registers_value[35] = state.registers.program_counter as u32;
registers_value[36] = state.registers.next_pc as u32;
registers_value[37] = state.registers.blk as u32;
registers_value[37] = state.registers.brk as u32;
registers_value[38] = state.registers.local_user as u32;

let register_addr_value: Vec<_> = registers_addr.iter().zip(registers_value).collect();
Expand Down
10 changes: 5 additions & 5 deletions src/cpu/kernel/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct Program {
pub lo: usize,
pub hi: usize,
pub heap: usize,
pub blk: usize,
pub brk: usize,
pub local_user: usize,
pub end_pc: usize,
pub image_id: [u8; 32],
Expand Down Expand Up @@ -137,7 +137,7 @@ impl Program {
}
}

let blk = hiaddr - (hiaddr & (PAGE_SIZE - 1)) + PAGE_SIZE;
let brk = hiaddr - (hiaddr & (PAGE_SIZE - 1)) + PAGE_SIZE;

let (symtab, strtab) = elf
.symbol_table()
Expand Down Expand Up @@ -245,7 +245,7 @@ impl Program {
lo,
hi,
heap,
blk: blk as usize,
brk: brk as usize,
local_user: 0,
end_pc: end_pc as usize,
image_id: image_id.try_into().unwrap(),
Expand Down Expand Up @@ -290,7 +290,7 @@ impl Program {
.unwrap()
.to_be() as usize;

let blk: usize = image
let brk: usize = image
.get(&(REGISTERS_START + (37 << 2) as u32))
.unwrap()
.to_be() as usize;
Expand Down Expand Up @@ -323,7 +323,7 @@ impl Program {
lo,
hi,
heap,
blk,
brk,
local_user,
end_pc,
image_id: segment.image_id,
Expand Down
20 changes: 11 additions & 9 deletions src/mips_emulator/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ pub struct State {

/// heap handles the mmap syscall.
heap: u32,
blk: u32,

/// brk handles the brk syscall
brk: u32,

// tlb addr
local_user: u32,
Expand Down Expand Up @@ -87,7 +89,7 @@ impl State {
heap: 0,
local_user: 0,
step: 0,
blk: 0,
brk: 0,
exited: false,
exit_code: 0,
dump_info: false,
Expand All @@ -107,7 +109,7 @@ impl State {
heap: 0x20000000,
local_user: 0,
step: 0,
blk: 0,
brk: 0,
exited: false,
exit_code: 0,
dump_info: false,
Expand Down Expand Up @@ -171,7 +173,7 @@ impl State {
})
}
}
s.blk = hiaddr - (hiaddr & (PAGE_ADDR_MASK as u32)) + PAGE_SIZE as u32;
s.brk = hiaddr - (hiaddr & (PAGE_ADDR_MASK as u32)) + PAGE_SIZE as u32;
(s, program)
}

Expand Down Expand Up @@ -403,7 +405,7 @@ impl State {
regs_bytes_be[34 * 4..34 * 4 + 4].copy_from_slice(&self.heap.to_be_bytes());
regs_bytes_be[35 * 4..35 * 4 + 4].copy_from_slice(&self.pc.to_be_bytes());
regs_bytes_be[36 * 4..36 * 4 + 4].copy_from_slice(&self.next_pc.to_be_bytes());
regs_bytes_be[37 * 4..37 * 4 + 4].copy_from_slice(&self.blk.to_be_bytes());
regs_bytes_be[37 * 4..37 * 4 + 4].copy_from_slice(&self.brk.to_be_bytes());
regs_bytes_be[38 * 4..38 * 4 + 4].copy_from_slice(&self.local_user.to_be_bytes());
regs_bytes_be
}
Expand Down Expand Up @@ -482,10 +484,10 @@ impl InstrumentedState {
}
4045 => {
// brk
if a0 > self.state.blk {
if a0 > self.state.brk {
v0 = a0;
} else {
v0 = self.state.blk;
v0 = self.state.brk;
}
}
4120 => {
Expand Down Expand Up @@ -564,7 +566,7 @@ impl InstrumentedState {
}
}
4283 => {
log::debug!("set local user {:X} {:X} {:X}", a0, a1, a2);
log::trace!("set local user {:X} {:X} {:X}", a0, a1, a2);
self.state.local_user = a0;
}
_ => {}
Expand Down Expand Up @@ -985,7 +987,7 @@ impl InstrumentedState {
if rd == 0 {
return 1; // cpu number
} else if rd == 29 {
log::debug!("pc: {:X} rdhwr {:X}", self.state.pc, self.state.local_user);
log::trace!("pc: {:X} rdhwr {:X}", self.state.pc, self.state.local_user);
//return 0x946490; // a pointer to a thread-specific storage block
return self.state.local_user;
} else {
Expand Down
4 changes: 0 additions & 4 deletions src/witness/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ impl MemoryState {
self.contexts.push(MemoryContextState::default());
}

if address.segment == Segment::Code as usize {
log::trace!("write mem {:X} : {:X} ({})", address.virt, val, val);
}

let _segment = Segment::all()[address.segment];
/*
assert!(
Expand Down
6 changes: 3 additions & 3 deletions src/witness/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,12 @@ pub(crate) fn generate_syscall<F: RichField>(
}
SYSBRK => {
row.general.syscall_mut().sysnum[2] = F::ONE;
let (blk, log_in5) = reg_read_with_log(37, 6, state, &mut row)?;
if a0 > blk {
let (brk, log_in5) = reg_read_with_log(37, 6, state, &mut row)?;
if a0 > brk {
v0 = a0;
row.general.syscall_mut().cond[10] = F::ONE;
} else {
v0 = blk;
v0 = brk;
row.general.syscall_mut().cond[11] = F::ONE;
}
state.traces.push_memory(log_in5);
Expand Down
4 changes: 2 additions & 2 deletions src/witness/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct RegistersState {
pub heap: usize,
pub program_counter: usize,
pub next_pc: usize,
pub blk: usize,
pub brk: usize,
pub local_user: usize,
pub is_kernel: bool,
pub context: usize,
Expand All @@ -36,7 +36,7 @@ impl RegistersState {
heap: kernel.program.heap,
program_counter: kernel.program.entry as usize,
next_pc: kernel.program.next_pc,
blk: kernel.program.blk,
brk: kernel.program.brk,
local_user: kernel.program.local_user,
is_kernel: true,
context: 0,
Expand Down
4 changes: 2 additions & 2 deletions src/witness/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub(crate) fn reg_read_with_log<F: Field>(
} else if index == 36 {
state.registers.next_pc
} else if index == 37 {
state.registers.blk
state.registers.brk
} else if index == 38 {
state.registers.local_user
} else {
Expand Down Expand Up @@ -165,7 +165,7 @@ pub(crate) fn reg_write_with_log<F: Field>(
} else if index == 36 {
state.registers.next_pc = value;
} else if index == 37 {
state.registers.blk = value;
state.registers.brk = value;
} else if index == 38 {
state.registers.local_user = value;
} else {
Expand Down

0 comments on commit 2db4a70

Please sign in to comment.