3.1.debug存取识别信号控制 当debug exception发生后,CPU将进入debug mode.然后CPU将会留在debug access mode直到CPU执行到IRET instruction并且trusted_debug_exit 是处于high后CPU将离开debug access mode,反之trusted_debug_exit如果是low,CPU将会保留在debug access mode.
实现控制trusted_debug_exit信号,有二种可供选择的方式如下:
trusted_debug_exit信号总是给high
增加一个权限管理逻辑去控制trusted_debug_exit信号是high或是low权限管理逻辑方块图如下所示:
图表6 权限管理逻辑方块图
如何控制trusted_debug_exit信号时序图如下所示:
图表7 如何控制trusted_debug_exit信号时序图
如下例子说明了如何产生trusted_debug_exit控制信号的verilog code:
The code example (Verilog) of trusted_debug_exit generation is described below:
//
//--- Utilize passcode to generate trusted_debug_exit in AHB Bus Controller
//* assume zero-wait-state AHB access
…
parameter AUTH_CODE = 32'h0a0b0c0d;
…
always @(posedge hclk or negedge hreset_n) begin
if (!hreset_n) begin
passcode_reg <= 32'd0;
end
else if (passcode_wen) begin //debugger enters passcode through debug access
passcode_reg <= hwdata[31:0];
end
end
…
//validate passcode to generate trusted_debug_exit
assign trusted_debug_exit = (passcode_reg == AUTH_CODE);
3.2.debug存取指示应用
下图说明AHB bus如何使用hdebug_access和验证逻辑来防止恶意的debug存取
图表8 AHB bus如何使用hdebug_access和验证逻辑来防止恶意的debug存取
如下verilog code说明了如何使用hdebug_access信号:
//--- Use hdebug_access to prevent malicious debug access in AHB Bus Controller
//* assume zero-wait-state AHB access
…
parameter IRRELEVANT_DATA = 32'hcafe0001;
parameter AUTH_CODE = 32'h01020304;
…
always @(posedge hclk or negedge hreset_n) begin
if (!hreset_n) begin
dbg_acc_d1 <= 1'b0;
end
else begin // data phase indication of debug access
dbg_acc_d1 <= hdebug_access;
end
end
…
always @(posedge hclk or negedge hreset_n) begin
if (!hreset_n) begin
passcode_reg <= 32'd0;
end
else if (passcode_wen) begin //debugger enters passcode through debug access
passcode_reg <= hwdata[31:0];
end
end
…
//validate passcode to check authentication
assign auth_check_fail = (passcode_reg != AUTH_CODE);
//return irrelevant data if the authentication check of debug access fails
assign hrdata_out = {32{data_read_en}} &
((dbg_acc_d1 & auth_check_fail) IRRELEVANT_DATA : normal_data_out); |