Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
triazo
/
kernel
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
3
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7ff5b79f
authored
Sep 28, 2015
by
malcolm
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Added GDT code in C
parent
6f768eab
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
0 deletions
src/gdt.c
src/gdt.h
src/gdt.c
0 → 100644
View file @
7ff5b79f
#include "gdt.h"
struct
gdtr
{
uint16_t
limit
;
uint32_t
base
;
}
static
struct
gdt_desc
_gdt
[
MAX_GDT_DESC
];
static
struct
gdtr
_gdtr
;
static
void
gdt_install
()
{
//TODO: VOODOO MAGIC
}
void
gdt_set_desc
(
uint32_t
i
,
uint64_t
base
,
uint64_t
limit
,
uint8_t
access
,
uint8_t
gran
)
{
if
(
i
>
MAX_GDT_DESC
)
return
;
memset
((
void
*
)
&
_gdt
[
i
],
0
,
sizeof
(
gdt_descriptor
));
_gdt
[
i
].
low_base
=
uint16_t
(
base
&
0xffff
);
_gdt
[
i
].
mid_base
=
uint8_t
((
base
>>
16
)
&
0xff
);
_gdt
[
i
].
high_base
=
uint8_t
((
base
>>
24
)
&
0xff
);
_gdt
[
i
].
lim
=
uint16_t
(
limit
&
0xffff
);
//! set flags and grandularity bytes
_gdt
[
i
].
flags
=
access
;
_gdt
[
i
].
gran
=
uint8_t
((
limit
>>
16
)
&
0x0f
);
_gdt
[
i
].
gran
|=
gran
&
0xf0
;
}
gdt_descriptor
*
i86_gdt_get_descriptor
(
int
i
)
{
if
(
i
>
MAX_GDT_DESC
)
return
0
;
return
&
_gdt
[
i
];
}
int
i86_gdt_initialize
()
{
_gdtr
.
limit
=
(
sizeof
(
struct
gdt_desc
)
*
MAX_GDT_DESC
)
-
1
;
_gdtr
.
base
=
(
uint32_t
)
&
_gdt
[
0
];
//null
gdt_set_descriptor
(
0
,
0
,
0
,
0
,
0
);
//code
gdt_set_descriptor
(
1
,
0
,
0xffffffff
,
GDT_RW
|
GDT_EXE
|
GDT_CDT
|
GDT_MEM
,
GDT_GR_PG
|
GDT_GR_32
|
GDT_GR_HI
);
//data
gdt_set_descriptor
(
2
,
0
,
0xffffffff
,
GDT_RW
|
GDT_CDT
|
GDT_MEM
,
GDT_GR_PG
|
GDT_GR_32
|
GDT_GR_HI
);
gdt_install
();
return
0
;
}
src/gdt.h
0 → 100644
View file @
7ff5b79f
#ifndef _GDT_INC
#define _GDT_INC
#include <stdint.h>
#define MAX_GDT_DESC 3
#define GDT_ACC 0x0001
#define GDT_RW 0x0002
#define GDT_DIR 0x0004
#define GDT_EXE 0x0008
#define GDT_CDT 0x0010
#define GDT_DPL 0x0060
#define GDT_MEM 0x0080
#define GDT_GR_HI 0x0f
#define GDT_GR_OS 0x10
#define GDT_GR_32 0x40
#define GDT_GR_PG 0x80
struct
gdt_desc
{
uint16_t
lim
;
uint16_t
low_base
;
uint8_t
mid_base
;
uint8_t
flags
;
uint8_t
gran
;
uint8_t
high_base
;
};
extern
void
gdt_set_desc
(
uint32_t
i
,
uint64_t
base
,
uint64_t
limit
,
uint8_t
access
,
uint8_t
gran
);
extern
gdt_desc
*
gdt_get_desc
(
int
i
);
extern
int
gdt_init
();
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment