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
a8d7d234
Commit
a8d7d234
authored
4 years ago
by
Thierno souleymane Bah
Browse files
Options
Downloads
Patches
Plain Diff
feat(main file refactorized)
parent
18efe156
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
src/utils.c
+121
-0
121 additions, 0 deletions
src/utils.c
with
122 additions
and
0 deletions
.gitignore
0 → 100644
+
1
−
0
View file @
a8d7d234
.DS_Store
This diff is collapsed.
Click to expand it.
src/utils.c
0 → 100644
+
121
−
0
View file @
a8d7d234
#include
"ioport.h"
#include
"gdt.h"
#include
"utils.h"
/* print a char on the screen */
int
cursor_x
=
0
;
/* here is the cursor position on X [0..79] */
int
cursor_y
=
0
;
/* here is the cursor position on Y [0..24] */
void
assert0
(
char
b
,
const
char
*
filename
,
const
char
*
fct_name
,
const
int
line
)
{
if
(
!
b
)
{
puts
(
"Assertion error in "
);
puts
(
filename
);
puts
(
" in "
);
puts
(
fct_name
);
puts
(
" at 0x"
);
puthex
(
line
);
puts
(
"
\n
"
);
}
}
void
irq_disable
()
{
__asm
volatile
(
"cli"
);
}
void
irq_enable
()
{
__asm
volatile
(
"sti"
);
_outb
(
0xA0
,
0x20
);
_outb
(
0x20
,
0x20
);
}
/* base address for the video output assume to be set as character oriented by the multiboot */
unsigned
char
*
video_memory
=
(
unsigned
char
*
)
0xB8000
;
/* clear screen */
void
clear_screen
()
{
int
i
;
for
(
i
=
0
;
i
<
80
*
25
;
i
++
)
{
/* for each one of the 80 char by 25 lines */
video_memory
[
i
*
2
+
1
]
=
0x0F
;
/* color is set to black background and white char */
video_memory
[
i
*
2
]
=
(
unsigned
char
)
' '
;
/* character shown is the space char */
}
}
/* print a string on the screen */
void
puts
(
const
char
*
aString
)
{
const
char
*
current_char
=
aString
;
while
(
*
current_char
!=
0
)
{
putc
(
*
current_char
++
);
}
}
/* print an number in hexa */
char
*
hex_digit
=
"0123456789ABCDEF"
;
void
puthex
(
int
aNumber
)
{
int
i
;
int
started
=
0
;
for
(
i
=
28
;
i
>=
0
;
i
-=
4
)
{
int
k
=
(
aNumber
>>
i
)
&
0xF
;
if
(
k
!=
0
||
started
)
{
putc
(
hex_digit
[
k
]);
started
=
1
;
}
}
}
void
setCursor
()
{
int
cursor_offset
=
cursor_x
+
cursor_y
*
80
;
_outb
(
0x3d4
,
14
);
_outb
(
0x3d5
,
((
cursor_offset
>>
8
)
&
0xFF
));
_outb
(
0x3d4
,
15
);
_outb
(
0x3d5
,
(
cursor_offset
&
0xFF
));
}
void
putc
(
char
c
)
{
if
(
cursor_x
>
79
)
{
cursor_x
=
0
;
cursor_y
++
;
}
if
(
cursor_y
>
24
)
{
cursor_y
=
0
;
clear_screen
();
}
switch
(
c
)
{
/* deal with a special char */
case
'\r'
:
cursor_x
=
0
;
break
;
/* carriage return */
case
'\n'
:
cursor_x
=
0
;
cursor_y
++
;
break
;
/* new ligne */
case
0x8
:
if
(
cursor_x
>
0
)
cursor_x
--
;
break
;
/* backspace */
case
0x9
:
cursor_x
=
(
cursor_x
+
8
)
&
~
7
;
break
;
/* tabulation */
/* or print a simple character */
default:
video_memory
[(
cursor_x
+
80
*
cursor_y
)
*
2
]
=
c
;
cursor_x
++
;
break
;
}
setCursor
();
}
\ No newline at end of file
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