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
259f274a
Commit
259f274a
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
feat: returning from permute mode as user
parent
68308105
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
assembleur.s
+10
-2
10 additions, 2 deletions
assembleur.s
mpu_user_console_etu.c
+10
-9
10 additions, 9 deletions
mpu_user_console_etu.c
with
20 additions
and
11 deletions
assembleur.s
+
10
−
2
View file @
259f274a
...
@@ -6,12 +6,13 @@
...
@@ -6,12 +6,13 @@
#include "globals.h"
#include "globals.h"
.
global
asm_test_fault
.
global
asm_test_fault
.
global
reset_user_stack
.
global
switch_to_user_mode
.
global
switch_to_user_mode
.
global
switch_to_supervisor_mode
.
global
switch_to_supervisor_mode
.
global
change_ret
.
global
change_ret
.
extern
user_stack
DATA
//
this
adress
can
be
read
like
:
ldr
Rx
,
=
user_stack
.
extern
user_stack
DATA
//
this
adress
can
be
read
like
:
ldr
Rx
,
=
user_stack
switch_to
_user_
mode
:
reset
_user_
stack
:
ldr
r0
,
=
user_stack
ldr
r0
,
=
user_stack
add
r0
,
r0
,
#
8192
//
2048
*
word_size
add
r0
,
r0
,
#
8192
//
2048
*
word_size
msr
PSP
,
r0
msr
PSP
,
r0
...
@@ -20,9 +21,16 @@ switch_to_user_mode:
...
@@ -20,9 +21,16 @@ switch_to_user_mode:
isb
isb
bx
lr
bx
lr
switch_to_user_mode
:
mrs
r0
,
control
mov
r0
,
#
3
msr
control
,
r0
isb
bx
lr
switch_to_supervisor_mode
:
switch_to_supervisor_mode
:
mrs
r0
,
control
mrs
r0
,
control
mov
r0
,
#
2
mov
r0
,
#
0
msr
control
,
r0
msr
control
,
r0
isb
isb
bx
lr
bx
lr
...
...
This diff is collapsed.
Click to expand it.
mpu_user_console_etu.c
+
10
−
9
View file @
259f274a
...
@@ -36,6 +36,7 @@ unsigned arr_err_code[BUF_SIZE] = { 0 };
...
@@ -36,6 +36,7 @@ unsigned arr_err_code[BUF_SIZE] = { 0 };
volatile
static
unsigned
idx_error
;
volatile
static
unsigned
idx_error
;
extern
bool
is_supervisor_mode
;
extern
bool
is_supervisor_mode
;
void
reset_user_stack
();
void
switch_to_user_mode
();
void
switch_to_user_mode
();
void
asm_test_fault
();
void
asm_test_fault
();
void
change_ret
(
void
*
addr
);
void
change_ret
(
void
*
addr
);
...
@@ -61,13 +62,15 @@ void test_supervisor_mode() {
...
@@ -61,13 +62,15 @@ 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
svc_call
(
void
)
{
void
permute_mode
(
void
)
{
char
buff
[
64
];
char
buff
[
64
]
=
{
0
};
printf
(
"Current: %s
\n
Type 'switch' to toggle between USER and SUPERVISOR: "
,
is_supervisor_mode
?
"Supervisor"
:
"User"
);
printf
(
"Current: %s
\n
Type 'switch' to toggle between USER and SUPERVISOR: "
,
is_supervisor_mode
?
"Supervisor"
:
"User"
);
fflush
(
stdin
);
fflush
(
stdin
);
fscanf
(
stdin
,
"%s"
,
buff
);
fscanf
(
stdin
,
"%s"
,
buff
);
if
(
strncmp
(
buff
,
"switch"
,
64
)
==
0
){
char
cmd
[]
=
"switch"
;
if
(
strncmp
(
buff
,
cmd
,
strlen
(
cmd
))
==
0
)
{
if
(
!
is_supervisor_mode
)
{
// If user mode
if
(
!
is_supervisor_mode
)
{
// If user mode
__asm
volatile
(
"svc 0x32"
);
__asm
volatile
(
"svc 0x32"
);
}
else
{
// If supervisor
}
else
{
// If supervisor
...
@@ -75,8 +78,7 @@ void svc_call(void) {
...
@@ -75,8 +78,7 @@ void svc_call(void) {
}
}
is_supervisor_mode
=
!
is_supervisor_mode
;
is_supervisor_mode
=
!
is_supervisor_mode
;
}
}
printf
(
"Current: %s
\n
"
,
is_supervisor_mode
?
"Supervisor"
:
"User"
);
printf
(
"Current: %s
\n
"
,
is_supervisor_mode
?
"Supervisor"
:
"User"
);
}
}
void
test_user_mode
()
{
void
test_user_mode
()
{
...
@@ -100,7 +102,6 @@ int main(void) {
...
@@ -100,7 +102,6 @@ int main(void) {
MPU
->
RBAR
=
0x00000000
;
MPU
->
RBAR
=
0x00000000
;
MPU
->
RASR
=
RO
|
BTEX_NORMAL_NOT_SHAREABLE
|
SET_SIZE_512KB
|
REGION_ENABLE
;
MPU
->
RASR
=
RO
|
BTEX_NORMAL_NOT_SHAREABLE
|
SET_SIZE_512KB
|
REGION_ENABLE
;
// Region 1 (SRAM1)
// Region 1 (SRAM1)
MPU
->
RNR
=
1
;
MPU
->
RNR
=
1
;
MPU
->
RBAR
=
0x10000000
;
MPU
->
RBAR
=
0x10000000
;
...
@@ -137,13 +138,13 @@ int main(void) {
...
@@ -137,13 +138,13 @@ int main(void) {
user_start:
user_stating_address
=
&&
user_start
;
// save the address of the label 'user_start' (for exercise 2)
user_start:
user_stating_address
=
&&
user_start
;
// save the address of the label 'user_start' (for exercise 2)
switch_to
_user_
mode
();
// to be implemented
reset
_user_
stack
();
// to be implemented
// testing memory accesses in user mode:
// testing memory accesses in user mode:
//test_user_mode(); // to be removed after checking
//test_user_mode(); // to be removed after checking
while
(
1
)
{
while
(
1
)
{
svc_call
();
permute_mode
();
exec_user_read_write
();
exec_user_read_write
();
}
}
...
...
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