Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
my-kernel
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ASE-2021
my-kernel
Commits
3d139216
Commit
3d139216
authored
4 years ago
by
Thierno souleymane Bah
Browse files
Options
Downloads
Patches
Plain Diff
feat(getc function tested without semanphore, personal putc function renamed to add_to_queue)
parent
1fa0fe5b
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/keyboard.h
+1
-3
1 addition, 3 deletions
include/keyboard.h
src/keyboard.c
+17
-6
17 additions, 6 deletions
src/keyboard.c
src/main.c
+28
-42
28 additions, 42 deletions
src/main.c
with
46 additions
and
51 deletions
include/keyboard.h
+
1
−
3
View file @
3d139216
...
...
@@ -37,9 +37,7 @@ char keyboard_map(unsigned char code);
void
init_queue
();
void
putc
(
unsigned
char
c
);
void
putc
(
unsigned
char
c
);
void
add_to_queue
(
unsigned
char
c
);
char
getc
();
...
...
This diff is collapsed.
Click to expand it.
src/keyboard.c
+
17
−
6
View file @
3d139216
#include
"keyboard.h"
#include
"sem.h"
#include
"utils.h"
sem_t
keyboard_sem
;
void
init_keymapping
()
{
...
...
@@ -86,15 +90,16 @@ void init_queue()
keyboard_queue
.
first_free
=
0
;
}
void
putc
(
unsigned
char
c
)
void
add_to_queue
(
unsigned
char
c
)
{
irq_disable
();
if
(
c
!=
NONE
&&
keyboard_queue
.
cpt
<
QUEUE_SIZE
)
{
keyboard_queue
.
cpt
++
;
keyboard_queue
.
first_free
=
(
keyboard_queue
.
first_free
+
1
)
%
QUEUE_SIZE
;
keyboard_queue
.
array
[
keyboard_queue
.
first_free
]
=
c
;
keyboard_queue
.
first_free
=
(
keyboard_queue
.
first_free
+
1
)
%
QUEUE_SIZE
;
keyboard_queue
.
cpt
++
;
// sem_up(&keyboard_sem);
}
irq_enable
();
...
...
@@ -104,9 +109,15 @@ char getc()
{
irq_disable
();
char
idx
=
(
keyboard_queue
.
first_free
+
QUEUE_SIZE
-
keyboard_queue
.
cpt
)
%
QUEUE_SIZE
;
char
c
=
NONE
;
if
(
keyboard_queue
.
cpt
)
{
// sem_down(&keyboard_sem);
int
idx
=
(
keyboard_queue
.
first_free
+
QUEUE_SIZE
-
keyboard_queue
.
cpt
)
%
QUEUE_SIZE
;
c
=
keyboard_queue
.
array
[
idx
];
keyboard_queue
.
cpt
--
;
}
irq_enable
();
return
keyboard_queue
.
array
[
idx
]
;
return
c
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main.c
+
28
−
42
View file @
3d139216
...
...
@@ -8,6 +8,7 @@
extern
int
cursor_x
;
extern
int
cursor_y
;
extern
sem_t
keyboard_sem
;
int
counter
=
0
;
...
...
@@ -26,6 +27,21 @@ void timer_it(int_regs_t *r)
yield
();
}
void
keyboard_it
(
int_regs_t
*
r
)
{
irq_disable
();
// puts("keyboard_it\n");
if
(
_inb
(
0x64
)
==
(
0x1D
))
{
_outb
(
0x64
,
0x1C
);
char
c
=
keyboard_map
(
_inb
(
0x60
));
add_to_queue
(
c
);
}
irq_enable
();
}
void
counter_handler
(
void
*
args
)
{
while
(
1
)
...
...
@@ -39,51 +55,20 @@ void counter_handler(void *args)
cursor_x
=
tmp_cursor
[
0
];
cursor_y
=
tmp_cursor
[
1
];
irq_enable
();
}
}
void
keyboard_handler
(
void
*
args
)
{
init_keymapping
();
while
(
1
)
{
irq_disable
();
if
(
_inb
(
0x64
)
==
(
0x1D
))
{
_outb
(
0x64
,
0x1C
);
unsigned
char
s
=
_inb
(
0x60
);
char
c
=
keyboard_map
(
s
);
if
(
c
)
char
c
=
getc
();
if
(
c
!=
NONE
)
putc
(
c
);
// puthex(s);
}
irq_enable
();
}
}
void
ping
(
void
*
arg
)
{
while
(
1
)
{
puts
(
"PING
\n
"
);
for
(
int
i
=
0
;
i
<
100000000
;
i
++
)
;
sem_up
(
&
spong
);
sem_down
(
&
sping
);
}
}
void
pong
(
void
*
arg
)
{
while
(
1
)
{
puts
(
"PONG
\n
"
);
for
(
int
i
=
0
;
i
<
100000000
;
i
++
)
;
sem_up
(
&
sping
);
sem_down
(
&
spong
);
irq_enable
();
}
}
...
...
@@ -103,8 +88,8 @@ void main(unsigned int *mboot_info)
puts
(
"
\n\n
"
);
idt_setup_handler
(
0
,
empty_irq
);
idt_setup_handler
(
1
,
empty_irq
);
idt_setup_handler
(
0
,
timer_it
);
idt_setup_handler
(
1
,
keyboard_it
);
__asm
volatile
(
"sti"
);
...
...
@@ -112,13 +97,14 @@ void main(unsigned int *mboot_info)
puts
(
"Hello world
\n\n
"
);
sem_init
(
&
sping
,
-
1
);
sem_init
(
&
spong
,
0
);
init_keymapping
();
init_queue
();
sem_init
(
&
keyboard_sem
,
0
);
ctx_t
*
ping
_ctx
=
create_ctx
(
ping
,
NULL
);
ctx_t
*
pong
_ctx
=
create_ctx
(
pong
,
NULL
);
ctx_t
*
counter
_ctx
=
create_ctx
(
&
counter_handler
,
NULL
);
ctx_t
*
keyboard
_ctx
=
create_ctx
(
&
keyboard_handler
,
NULL
);
//sem_down(&sping);
yield
();
for
(;;)
...
...
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