diff --git a/mpu_user_console_etu.c b/mpu_user_console_etu.c index a5806ea0f90bc6aa4a854f7600cf9e9ccc5b16ef..ca3af7cc5a2e52ca367e61d0dcfe6c50289c9d8d 100644 --- a/mpu_user_console_etu.c +++ b/mpu_user_console_etu.c @@ -37,7 +37,6 @@ volatile static unsigned idx_error; extern bool is_supervisor_mode; void reset_user_stack(); -void switch_to_user_mode(); void asm_test_fault(); void change_ret(void *addr); @@ -62,23 +61,35 @@ void test_supervisor_mode() { a = *p_out_of_mem; // not OK (out of regions) } -void permute_mode(void) { +void ask_user_input(void) { char buff[64] = { 0 }; - printf("Current: %s\nType 'switch' to toggle between USER and SUPERVISOR: ", + char switch_cmd[] = "switch"; + char status_cmd[] = "status"; + + printf("(%s) Would you like to `switch` or display `status` errors : ", is_supervisor_mode ? "Supervisor" : "User"); fflush(stdin); fscanf(stdin, "%s", buff); - char cmd[] = "switch"; - if (strncmp(buff, cmd, strlen(cmd)) == 0) { - if (!is_supervisor_mode) { // If user mode - __asm volatile ("svc 0x32"); - } else { // If supervisor - switch_to_user_mode(); + if (strncmp(buff, switch_cmd, strlen(switch_cmd)) == 0) { + // permute through svc depending on flag + __asm volatile ("svc 0x69"); + return; + } + + if (strncmp(buff, status_cmd, strlen(status_cmd)) == 0) { + if (idx_error == 0) { + printf("No errors have occurred yet\n"); + return; + } + + for (int i = 0; i < idx_error; i++) { + if (i < BUF_SIZE) { + printf("Address that shat the bed : 0x%x\tError code : 0x%x\n", + arr_addr[i], arr_err_code[i]); + } } - is_supervisor_mode = !is_supervisor_mode; } - printf("Current: %s\n", is_supervisor_mode ? "Supervisor" : "User"); } void test_user_mode() { @@ -144,7 +155,7 @@ int main(void) { //test_user_mode(); // to be removed after checking while (1) { - permute_mode(); + ask_user_input(); exec_user_read_write(); } diff --git a/user_cmd.c b/user_cmd.c index 54cf4542efe67c9f9f2a1940f62d07c63c91dfba..9fe526fac8eb2f8da4a8d1c47f0ee4f3e2a63b53 100644 --- a/user_cmd.c +++ b/user_cmd.c @@ -15,63 +15,58 @@ #define PRINT_SYNTAX_ERROR() PRINT("Syntax error! Expected syntax is either <8 characters hexadecimal address> for reading\n or " \ "<8 characters hexadecimal address>=<8 characters hexadecimal value> for writing\n"); -bool is_supervisor_mode=false; +bool is_supervisor_mode = false; +void switch_to_user_mode(); void switch_to_supervisor_mode(void); -void SVC_Handler() -{ - switch_to_supervisor_mode(); +void SVC_Handler() { + if (!is_supervisor_mode) { // If user mode + switch_to_supervisor_mode(); + } else { // If supervisor + switch_to_user_mode(); + } + is_supervisor_mode = !is_supervisor_mode; } - -void exec_user_read_write() -{ +void exec_user_read_write() { char str[200]; - int i=0, coma_nb=0, value_idx; + int i = 0, coma_nb = 0, value_idx; unsigned addr, value; - PRINT("Write an hexadecimal address for reading <addr> or <addr>,<value> for writing (%s):\n", is_supervisor_mode?"Supervisor":"User"); + PRINT( + "Write an hexadecimal address for reading <addr> or <addr>,<value> for writing (%s):\n", + is_supervisor_mode ? "Supervisor" : "User"); fflush(stdin); - fscanf(stdin, "%s",str); + fscanf(stdin, "%s", str); - for (i=0; i<strlen(str); i++) - { - if (str[i] == ',') - { - if (i==0 || ++coma_nb>1) - { + for (i = 0; i < strlen(str); i++) { + if (str[i] == ',') { + if (i == 0 || ++coma_nb > 1) { PRINT_SYNTAX_ERROR(); return; } - str[i]=0; - value_idx=i+1; - } else if (!isxdigit(str[i])) - { + str[i] = 0; + value_idx = i + 1; + } else if (!isxdigit(str[i])) { PRINT_SYNTAX_ERROR(); return; } } - if ((coma_nb&(i<2)) || i>17) - { + if ((coma_nb & (i < 2)) || i > 17) { PRINT_SYNTAX_ERROR(); PRINT("(Bad length!)"); return; } sscanf(str, "%x", &addr); - if (!coma_nb) // if read - { + if (!coma_nb) { // if read PRINT("reading address: 0x%08x\n", addr); - PRINT("value read: 0x%08x\n", *(unsigned *)addr); - } - else // write - { - sscanf(str+value_idx, "%x", &value); + PRINT("value read: 0x%08x\n", *(unsigned*) addr); + } else { // write + sscanf(str + value_idx, "%x", &value); PRINT("writing address: 0x%08x with 0x%08x\n", addr, value); - *(unsigned *)addr=value; + *(unsigned*) addr = value; } } - -