Skip to content

Commit b27254b

Browse files
author
Hellosun Wu
committed
Add options for N22 workaround
--no-n22- workaround-imprecise-ldst: Don’t apply this workaround to load, store, and atomic instructions. --no-n22- workaround-imprecise-div: Don’t apply this workaround to divide instructions.
1 parent dcc4d56 commit b27254b

File tree

1 file changed

+119
-52
lines changed

1 file changed

+119
-52
lines changed

iceman_adapter/iceman_adapter.c

Lines changed: 119 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ extern char *OPENOCD_VERSION_STR;
7272
#define LONGOPT_RV64 22
7373
#define LONGOPT_DETECT_2WIRE 23
7474
#define LONGOPT_NO_HALT_DETECT 24
75+
#define LONGOPT_NO_N22_WORKAROUND_IMPRECISE_LDST 25
76+
#define LONGOPT_NO_N22_WORKAROUND_IMPRECISE_DIV 26
77+
78+
7579
int long_opt_flag;
7680
uint32_t cop_reg_nums[4] = {0,0,0,0};
7781
const char *opt_string = "aAb:Bc:C:d:DeF:f:gGhHI:kK::l:L:M:N:o:O:p:P:r:R:sS:t:T:vx::Xy:z:Z:";
@@ -94,6 +98,8 @@ struct option long_option[] = {
9498
{"rv64-bus-only", no_argument, &long_opt_flag, LONGOPT_RV64},
9599
{"detect-2wire", no_argument, &long_opt_flag, LONGOPT_DETECT_2WIRE},
96100
{"no-halt-detect", no_argument, &long_opt_flag, LONGOPT_NO_HALT_DETECT},
101+
{"no-n22-workaround-imprecise-ldst", no_argument, &long_opt_flag, LONGOPT_NO_N22_WORKAROUND_IMPRECISE_LDST},
102+
{"no-n22-workaround-imprecise-div", no_argument, &long_opt_flag, LONGOPT_NO_N22_WORKAROUND_IMPRECISE_DIV},
97103

98104
{"reset-aice", no_argument, 0, 'a'},
99105
{"no-reset-detect", no_argument, 0, 'A'},
@@ -261,6 +267,8 @@ static unsigned int nds_v3_ftdi;
261267
static uint8_t dev_dnum = -1;
262268
static int vtarget_xlen;
263269
static int vtarget_enable;
270+
static unsigned int no_n22_workaround_imprecise_ldst;
271+
static unsigned int no_n22_workaround_imprecise_div;
264272

265273
static void show_version()
266274
{
@@ -450,6 +458,107 @@ int isDirectoryExist(const char *path)
450458
return 0;
451459
}
452460

461+
static int handle_long_option(int long_opt)
462+
{
463+
uint32_t cop_nums = 0;
464+
uint8_t num = 0;
465+
uint8_t bnum = 0, pnum = 0, dnum = 0;
466+
467+
switch (long_opt) {
468+
case LONGOPT_CP0:
469+
case LONGOPT_CP1:
470+
case LONGOPT_CP2:
471+
case LONGOPT_CP3:
472+
cop_nums = strtol(optarg, NULL, 0);
473+
if (cop_nums > 4096)
474+
printf("cop_nums max is 4096\n");
475+
else {
476+
cop_reg_nums[long_opt - LONGOPT_CP0] = cop_nums;
477+
printf("cop_reg_nums[%d]=%d\n", long_opt - LONGOPT_CP0, cop_reg_nums[long_opt - LONGOPT_CP0]);
478+
}
479+
break;
480+
481+
case LONGOPT_USE_SDM:
482+
use_sdm = 1;
483+
break;
484+
485+
case LONGOPT_AICE_INIT:
486+
custom_initial_script = optarg;
487+
if (access(custom_initial_script, F_OK)){
488+
printf("<-- ERROR: customer initial script (path: %s) not exist! -->\n", custom_initial_script);
489+
return ERROR_FAIL;
490+
}
491+
break;
492+
493+
case LONGOPT_L2C:
494+
enable_l2c = 1;
495+
if (optarg)
496+
sscanf(optarg, "%llx", &l2c_base);
497+
break;
498+
499+
case LONGOPT_DMI_DELAY:
500+
sscanf(optarg, "%d", &dmi_busy_delay_count);
501+
break;
502+
503+
case LONGOPT_USER_TARGET_CFG:
504+
custom_target_cfg = optarg;
505+
break;
506+
507+
case LONGOPT_SMP:
508+
use_smp = 1;
509+
break;
510+
511+
case LONGOPT_HALT_ON_RESET:
512+
usd_halt_on_reset = strtol(optarg, NULL, 0);
513+
break;
514+
515+
case LONGOPT_LIST_DEVICE:
516+
list_devices(-1);
517+
return ERROR_FAIL; /* Force ICEman exits*/
518+
break;
519+
520+
case LONGOPT_DEVICE:
521+
sscanf(optarg, "%"SCNu8, &num);
522+
dev_dnum = list_devices(num);
523+
break;
524+
525+
case LONGOPT_DEVICE_USB_COMBO:
526+
sscanf(optarg, "%"SCNu8 ":%"SCNu8 ":%"SCNu8, &bnum, &pnum, &dnum);
527+
dev_dnum = dnum;
528+
break;
529+
530+
case LONGOPT_RV32:
531+
vtarget_xlen = 32;
532+
vtarget_enable = 1;
533+
break;
534+
535+
case LONGOPT_RV64:
536+
vtarget_xlen = 64;
537+
vtarget_enable = 1;
538+
break;
539+
540+
case LONGOPT_DETECT_2WIRE:
541+
detect_2wire = 1;
542+
break;
543+
544+
case LONGOPT_NO_HALT_DETECT:
545+
aice_no_halt_detect = 1;
546+
break;
547+
548+
case LONGOPT_NO_N22_WORKAROUND_IMPRECISE_LDST:
549+
no_n22_workaround_imprecise_ldst = 1;
550+
break;
551+
552+
case LONGOPT_NO_N22_WORKAROUND_IMPRECISE_DIV:
553+
no_n22_workaround_imprecise_div = 1;
554+
break;
555+
default:
556+
return ERROR_FAIL;
557+
}
558+
559+
return ERROR_OK;
560+
}
561+
453562
static int parse_param(int a_argc, char **a_argv)
454563
{
455564
while(1) {
@@ -469,58 +578,8 @@ static int parse_param(int a_argc, char **a_argv)
469578
switch (c) {
470579
case 0:
471580
long_opt = *long_option[option_index].flag;
472-
if ((long_opt >= LONGOPT_CP0) &&
473-
(long_opt <= LONGOPT_CP3)) {
474-
cop_nums = strtol(optarg, NULL, 0);
475-
if (cop_nums > 4096)
476-
printf("cop_nums max is 4096\n");
477-
else {
478-
cop_reg_nums[long_opt - LONGOPT_CP0] = cop_nums;
479-
printf("cop_reg_nums[%d]=%d\n", long_opt - LONGOPT_CP0, cop_reg_nums[long_opt - LONGOPT_CP0]);
480-
}
481-
} else if (long_opt == LONGOPT_USE_SDM)
482-
use_sdm = 1;
483-
else if (long_opt == LONGOPT_AICE_INIT){
484-
custom_initial_script = optarg;
485-
if (access(custom_initial_script, F_OK)){
486-
printf("<-- ERROR: customer initial script (path: %s) not exist! -->\n", custom_initial_script);
487-
return ERROR_FAIL;
488-
}
489-
}
490-
else if (long_opt == LONGOPT_L2C) {
491-
enable_l2c = 1;
492-
if (optarg)
493-
sscanf(optarg, "%llx", &l2c_base);
494-
} else if (long_opt == LONGOPT_DMI_DELAY)
495-
sscanf(optarg, "%d", &dmi_busy_delay_count);
496-
else if (long_opt == LONGOPT_USER_TARGET_CFG)
497-
custom_target_cfg = optarg;
498-
else if (long_opt == LONGOPT_SMP)
499-
use_smp = 1;
500-
else if (long_opt == LONGOPT_HALT_ON_RESET)
501-
usd_halt_on_reset = strtol(optarg, NULL, 0);
502-
else if (long_opt == LONGOPT_LIST_DEVICE) {
503-
list_devices(-1);
504-
return ERROR_FAIL; /* Force ICEman exits*/
505-
} else if (long_opt == LONGOPT_DEVICE) {
506-
uint8_t num;
507-
sscanf(optarg, "%"SCNu8, &num);
508-
dev_dnum = list_devices(num);
509-
} else if (long_opt == LONGOPT_DEVICE_USB_COMBO) {
510-
uint8_t bnum = 0, pnum = 0, dnum = 0;
511-
sscanf(optarg, "%"SCNu8 ":%"SCNu8 ":%"SCNu8, &bnum, &pnum, &dnum);
512-
dev_dnum = dnum;
513-
} else if (long_opt == LONGOPT_RV32) {
514-
vtarget_xlen = 32;
515-
vtarget_enable = 1;
516-
} else if (long_opt == LONGOPT_RV64) {
517-
vtarget_xlen = 64;
518-
vtarget_enable = 1;
519-
} else if (long_opt == LONGOPT_DETECT_2WIRE) {
520-
detect_2wire = 1;
521-
} else if (long_opt == LONGOPT_NO_HALT_DETECT) {
522-
aice_no_halt_detect = 1;
523-
}
581+
if (handle_long_option(long_opt))
582+
return ERROR_FAIL;
524583
break;
525584
case 'a': /* reset-aice */
526585
reset_aice_as_startup = 1;
@@ -1211,6 +1270,14 @@ static void update_openocd_cfg_v5()
12111270
fprintf(openocd_cfg, "nds configure l2c_base 0x%llx\n", l2c_base);
12121271
}
12131272

1273+
if (no_n22_workaround_imprecise_ldst) {
1274+
fprintf(openocd_cfg, "nds configure no-n22-workaround-imprecise-ldst on\n");
1275+
}
1276+
1277+
if (no_n22_workaround_imprecise_div) {
1278+
fprintf(openocd_cfg, "nds configure no-n22-workaround-imprecise-div on\n");
1279+
}
1280+
12141281
if (aice_no_reset_detect != 0)
12151282
fprintf(openocd_cfg, "nds no_reset_detect %d\n", aice_no_reset_detect);
12161283

0 commit comments

Comments
 (0)