Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP-OS
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
Container 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
Putegnat Theo
TP-OS
Commits
0ba76570
Commit
0ba76570
authored
4 years ago
by
Wilke Pierre
Browse files
Options
Downloads
Patches
Plain Diff
MAJ squelette
parent
bb70ca7e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Makefile
+1
-0
1 addition, 0 deletions
Makefile
kernel/defs.h
+1
-0
1 addition, 0 deletions
kernel/defs.h
kernel/riscv.h
+4
-0
4 additions, 0 deletions
kernel/riscv.h
kernel/trap.c
+2
-0
2 additions, 0 deletions
kernel/trap.c
user/stack-exec.c
+129
-0
129 additions, 0 deletions
user/stack-exec.c
with
137 additions
and
0 deletions
Makefile
+
1
−
0
View file @
0ba76570
...
...
@@ -148,6 +148,7 @@ UPROGS=\
$U
/_suicide
\
$U
/_rwtest
\
$U
/_naivefib
\
$u
/_stack-exec
\
fs.img
:
mkfs/mkfs README $(UPROGS)
mkfs/mkfs fs.img README
$(
UPROGS
)
...
...
This diff is collapsed.
Click to expand it.
kernel/defs.h
+
1
−
0
View file @
0ba76570
...
...
@@ -225,5 +225,6 @@ int lst_empty(struct list*);
#define ENOMEM (-(1L << 2))
#define ENOFILE (-(1L << 3))
#define EMAPFAILED (-(1L << 4))
#define EBADPERM (-(1L << 5))
#endif
This diff is collapsed.
Click to expand it.
kernel/riscv.h
+
4
−
0
View file @
0ba76570
...
...
@@ -355,4 +355,8 @@ sfence_vma()
typedef
uint64
pte_t
;
typedef
uint64
*
pagetable_t
;
// 512 PTEs
#define CAUSE_R 0xd
#define CAUSE_W 0xf
#define CAUSE_X 0xc
#endif
This diff is collapsed.
Click to expand it.
kernel/trap.c
+
2
−
0
View file @
0ba76570
...
...
@@ -47,6 +47,8 @@ int handle_page_fault(struct proc* p, uint64 scause, uint64 stval, uint64 sepc){
printf
(
"Could not read file associated with memory area
\n
"
);
}
else
if
(
flags
==
EMAPFAILED
){
printf
(
"mappages failed for an unknown reason
\n
"
);
}
else
if
(
flags
==
EBADPERM
){
printf
(
"Bad permission addr=%p, scause=%p
\n
"
,
addr
,
scause
);
}
proc_vmprint
(
p
);
...
...
This diff is collapsed.
Click to expand it.
user/stack-exec.c
0 → 100644
+
129
−
0
View file @
0ba76570
#include
"kernel/types.h"
#include
"kernel/memlayout.h"
#include
"user/user.h"
char
code
[]
=
{
// li a0, 1
0x05
,
0x45
,
// li a7, 16
0xc1
,
0x48
,
// auipc a1, 0
0x97
,
0x05
,
0x00
,
0x00
,
// .loop:
// lbu t0, 0(a1)
0x83
,
0xc2
,
0x05
,
0x00
,
// addi a1, a1, 1
0x85
,
0x05
,
//li t1, 0x80
0x13
,
0x03
,
0x00
,
0x08
,
// beq t0 t1, .endloop
0x63
,
0x83
,
0x62
,
0x00
,
// j .loop
0xcd
,
0xbf
,
// .endloop:
// mv a2, a1
0x2e
,
0x86
,
// .loop2:
// lbu t0, 0(a2)
0x83
,
0x42
,
0x06
,
0x00
,
// addi a2, a2, 1
0x05
,
0x06
,
// beqz t0, .endloop2
0x63
,
0x83
,
0x02
,
0x00
,
// j .loop2
0xdd
,
0xbf
,
// .endloop2
// sub a2, a2, a1
0x0d
,
0x8e
,
// ecall
0x73
,
0x00
,
0x00
,
0x00
,
// ret
0x82
,
0x80
,
'H'
,
'e'
,
'l'
,
'l'
,
'o'
,
'!'
,
0x0a
,
0
};
int
main
(
int
argc
,
char
*
argv
[])
{
/*
# test.S
# riscv64-unknown-elf-as -march=rv64gc -fpic test.S
# riscv64-unknown-elf-objdump -d /tmp/a.out
# write(1, s, sizeof(s))
# fd = 1
li a0, 1
# syscall write -> a7 = 16
li a7, 16
# looking for the address of the string to print, after ret (0x82, 0x80)
auipc a1, 0
.loop:
lbu t0, 0(a1)
addi a1, a1, 1
li t1, 0x80
beq t0, t1, .endloop
j .loop
.endloop:
# computing the length of the string, look for 0 byte
mv a2, a1
.loop2:
lbu t0, 0(a2)
addi a2, a2, 1
beq t0, zero, .endloop2
j .loop2
.endloop2:
sub a2, a2, a1
ecall
ret
.mystring:
auipc a1, 4
ret
"Hello"
.mystringend:
auipc a2, -4
ret
*/
char
code_stack
[
100
];
for
(
int
i
=
0
;
i
<
sizeof
(
code
);
i
++
){
code_stack
[
i
]
=
code
[
i
];
}
int
pid
=
fork
();
if
(
pid
<
0
){
printf
(
"fork failed
\n
"
);
exit
(
1
);
}
if
(
pid
==
0
){
((
void
(
*
)(
void
))(
code_stack
))();
printf
(
"I successfully ran the stack.
\n
"
);
exit
(
0
);
}
else
{
// in .rodata
pid
=
fork
();
if
(
pid
<
0
){
printf
(
"fork failed
\n
"
);
exit
(
1
);
}
if
(
pid
==
0
){
((
void
(
*
)(
void
))(
code
))();
printf
(
"I successfully ran the rodata.
\n
"
);
exit
(
0
);
}
else
{
wait
(
0
);
wait
(
0
);
}
}
exit
(
0
);
}
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