Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
G4_mpu
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
pro
G4_mpu
Commits
314d9910
Commit
314d9910
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
feat: ex3 completely done, moving to UART
parent
259f274a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mpu_user_console_etu.c
+23
-12
23 additions, 12 deletions
mpu_user_console_etu.c
user_cmd.c
+27
-32
27 additions, 32 deletions
user_cmd.c
with
50 additions
and
44 deletions
mpu_user_console_etu.c
+
23
−
12
View file @
314d9910
...
@@ -37,7 +37,6 @@ volatile static unsigned idx_error;
...
@@ -37,7 +37,6 @@ volatile static unsigned idx_error;
extern
bool
is_supervisor_mode
;
extern
bool
is_supervisor_mode
;
void
reset_user_stack
();
void
reset_user_stack
();
void
switch_to_user_mode
();
void
asm_test_fault
();
void
asm_test_fault
();
void
change_ret
(
void
*
addr
);
void
change_ret
(
void
*
addr
);
...
@@ -62,23 +61,35 @@ void test_supervisor_mode() {
...
@@ -62,23 +61,35 @@ void test_supervisor_mode() {
a
=
*
p_out_of_mem
;
// not OK (out of regions)
a
=
*
p_out_of_mem
;
// not OK (out of regions)
}
}
void
permute_mode
(
void
)
{
void
ask_user_input
(
void
)
{
char
buff
[
64
]
=
{
0
};
char
buff
[
64
]
=
{
0
};
printf
(
"Current: %s
\n
Type '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"
);
is_supervisor_mode
?
"Supervisor"
:
"User"
);
fflush
(
stdin
);
fflush
(
stdin
);
fscanf
(
stdin
,
"%s"
,
buff
);
fscanf
(
stdin
,
"%s"
,
buff
);
char
cmd
[]
=
"switch"
;
if
(
strncmp
(
buff
,
switch_cmd
,
strlen
(
switch_cmd
))
==
0
)
{
if
(
strncmp
(
buff
,
cmd
,
strlen
(
cmd
))
==
0
)
{
// permute through svc depending on flag
if
(
!
is_supervisor_mode
)
{
// If user mode
__asm
volatile
(
"svc 0x69"
);
__asm
volatile
(
"svc 0x32"
);
return
;
}
else
{
// If supervisor
}
switch_to_user_mode
();
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
\t
Error 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
()
{
void
test_user_mode
()
{
...
@@ -144,7 +155,7 @@ int main(void) {
...
@@ -144,7 +155,7 @@ int main(void) {
//test_user_mode(); // to be removed after checking
//test_user_mode(); // to be removed after checking
while
(
1
)
{
while
(
1
)
{
permute_mode
();
ask_user_input
();
exec_user_read_write
();
exec_user_read_write
();
}
}
...
...
This diff is collapsed.
Click to expand it.
user_cmd.c
+
27
−
32
View file @
314d9910
...
@@ -15,63 +15,58 @@
...
@@ -15,63 +15,58 @@
#define PRINT_SYNTAX_ERROR() PRINT("Syntax error! Expected syntax is either <8 characters hexadecimal address> for reading\n or " \
#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
"
);
"<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
switch_to_supervisor_mode
(
void
);
void
SVC_Handler
()
void
SVC_Handler
()
{
{
if
(
!
is_supervisor_mode
)
{
// If user mode
switch_to_supervisor_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
];
char
str
[
200
];
int
i
=
0
,
coma_nb
=
0
,
value_idx
;
int
i
=
0
,
coma_nb
=
0
,
value_idx
;
unsigned
addr
,
value
;
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
);
fflush
(
stdin
);
fscanf
(
stdin
,
"%s"
,
str
);
fscanf
(
stdin
,
"%s"
,
str
);
for
(
i
=
0
;
i
<
strlen
(
str
);
i
++
)
for
(
i
=
0
;
i
<
strlen
(
str
);
i
++
)
{
{
if
(
str
[
i
]
==
','
)
{
if
(
str
[
i
]
==
','
)
if
(
i
==
0
||
++
coma_nb
>
1
)
{
{
if
(
i
==
0
||
++
coma_nb
>
1
)
{
PRINT_SYNTAX_ERROR
();
PRINT_SYNTAX_ERROR
();
return
;
return
;
}
}
str
[
i
]
=
0
;
str
[
i
]
=
0
;
value_idx
=
i
+
1
;
value_idx
=
i
+
1
;
}
else
if
(
!
isxdigit
(
str
[
i
]))
}
else
if
(
!
isxdigit
(
str
[
i
]))
{
{
PRINT_SYNTAX_ERROR
();
PRINT_SYNTAX_ERROR
();
return
;
return
;
}
}
}
}
if
((
coma_nb
&
(
i
<
2
))
||
i
>
17
)
if
((
coma_nb
&
(
i
<
2
))
||
i
>
17
)
{
{
PRINT_SYNTAX_ERROR
();
PRINT_SYNTAX_ERROR
();
PRINT
(
"(Bad length!)"
);
PRINT
(
"(Bad length!)"
);
return
;
return
;
}
}
sscanf
(
str
,
"%x"
,
&
addr
);
sscanf
(
str
,
"%x"
,
&
addr
);
if
(
!
coma_nb
)
// if read
if
(
!
coma_nb
)
{
// if read
{
PRINT
(
"reading address: 0x%08x
\n
"
,
addr
);
PRINT
(
"reading address: 0x%08x
\n
"
,
addr
);
PRINT
(
"value read: 0x%08x
\n
"
,
*
(
unsigned
*
)
addr
);
PRINT
(
"value read: 0x%08x
\n
"
,
*
(
unsigned
*
)
addr
);
}
}
else
{
// write
else
// write
sscanf
(
str
+
value_idx
,
"%x"
,
&
value
);
{
sscanf
(
str
+
value_idx
,
"%x"
,
&
value
);
PRINT
(
"writing address: 0x%08x with 0x%08x
\n
"
,
addr
,
value
);
PRINT
(
"writing address: 0x%08x with 0x%08x
\n
"
,
addr
,
value
);
*
(
unsigned
*
)
addr
=
value
;
*
(
unsigned
*
)
addr
=
value
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment