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
f98f0cda
authored
Oct 01, 2015
by
malcolm
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Interrupts work now, fixed up GDT and IDT
parent
b7c23627
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
13 deletions
src/gdt.c
src/idt.c
src/kern.c
src/makefile
src/string.c
src/string.h
src/gdt.c
View file @
f98f0cda
#include "gdt.h"
#include "gdt.h"
#include "string.h"
#include "string.h"
#include "serial.h"
#include "term.h"
uint16_t
gdt_limit
;
uint16_t
gdt_limit
;
uint32_t
gdt_base
;
uint32_t
gdt_base
;
static
gdt_desc
_gdt
[
MAX_GDT_DESC
];
gdt_desc
_gdt
[
MAX_GDT_DESC
];
static
void
gdt_install
(){
#define set_cs( cs ) asm volatile ( "ljmp %0, $1337f \n\t 1337: \n\t" :: "i"(cs) )
void
gdt_install
(){
struct
{
struct
{
uint16_t
limit
;
uint16_t
limit
;
uint32_t
base
;
uint32_t
base
;
...
@@ -14,6 +17,20 @@ static void gdt_install(){
...
@@ -14,6 +17,20 @@ static void gdt_install(){
gdtr
.
limit
=
gdt_limit
;
gdtr
.
limit
=
gdt_limit
;
gdtr
.
base
=
gdt_base
;
gdtr
.
base
=
gdt_base
;
asm
volatile
(
"lgdt (%0)"
:
:
"r"
(
&
gdtr
));
asm
volatile
(
"lgdt (%0)"
:
:
"r"
(
&
gdtr
));
//serial_writestring("gdt installed, now setting cs\n");
set_cs
(
8
);
//serial_writestring("cs set, setting ds\n");
//asm volatile ("ljmp $0x8,$1f;
// 1:
asm
volatile
(
" mov $0x10, %ax;\
mov %ax, %ds;\
mov %ax, %es;\
mov %ax, %fs;\
mov %ax, %gs;\
mov %ax, %ss;"
);
//serial_writestring("ds set, we done here. moving on to idt\n");
//terminal_writestring("");
strlen
(
""
);
}
}
void
gdt_set_desc
(
uint32_t
i
,
uint64_t
base
,
uint64_t
limit
,
uint8_t
access
,
uint8_t
gran
){
void
gdt_set_desc
(
uint32_t
i
,
uint64_t
base
,
uint64_t
limit
,
uint8_t
access
,
uint8_t
gran
){
if
(
i
>
MAX_GDT_DESC
)
if
(
i
>
MAX_GDT_DESC
)
...
@@ -30,7 +47,6 @@ void gdt_set_desc(uint32_t i, uint64_t base, uint64_t limit, uint8_t access, uin
...
@@ -30,7 +47,6 @@ void gdt_set_desc(uint32_t i, uint64_t base, uint64_t limit, uint8_t access, uin
_gdt
[
i
].
gran
|=
gran
&
0xf0
;
_gdt
[
i
].
gran
|=
gran
&
0xf0
;
}
}
gdt_desc
*
gdt_get_desc
(
int
i
)
{
gdt_desc
*
gdt_get_desc
(
int
i
)
{
if
(
i
>
MAX_GDT_DESC
)
if
(
i
>
MAX_GDT_DESC
)
return
0
;
return
0
;
return
&
_gdt
[
i
];
return
&
_gdt
[
i
];
...
@@ -44,6 +60,7 @@ int gdt_init() {
...
@@ -44,6 +60,7 @@ int gdt_init() {
gdt_set_desc
(
1
,
0
,
0xffffffff
,
GDT_RW
|
GDT_EXE
|
GDT_CDT
|
GDT_MEM
,
GDT_GR_PG
|
GDT_GR_32
|
GDT_GR_HI
);
gdt_set_desc
(
1
,
0
,
0xffffffff
,
GDT_RW
|
GDT_EXE
|
GDT_CDT
|
GDT_MEM
,
GDT_GR_PG
|
GDT_GR_32
|
GDT_GR_HI
);
//data
//data
gdt_set_desc
(
2
,
0
,
0xffffffff
,
GDT_RW
|
GDT_CDT
|
GDT_MEM
,
GDT_GR_PG
|
GDT_GR_32
|
GDT_GR_HI
);
gdt_set_desc
(
2
,
0
,
0xffffffff
,
GDT_RW
|
GDT_CDT
|
GDT_MEM
,
GDT_GR_PG
|
GDT_GR_32
|
GDT_GR_HI
);
//serial_writestring("gdt filled, now installing\n");
gdt_install
();
gdt_install
();
return
0
;
return
0
;
}
}
src/idt.c
View file @
f98f0cda
...
@@ -5,22 +5,33 @@
...
@@ -5,22 +5,33 @@
uint16_t
idt_limit
;
uint16_t
idt_limit
;
uint32_t
idt_base
;
uint32_t
idt_base
;
static
idt_desc
_idt
[
MAX_IDT_INT
];
idt_desc
_idt
[
MAX_IDT_INT
];
static
void
idt_install
()
{
void
idt_install
()
{
struct
{
struct
{
uint16_t
limit
;
uint16_t
limit
;
uint32_t
base
;
uint32_t
base
;
}
__attribute__
((
packed
))
idtr
;
}
__attribute__
((
packed
))
idtr
;
//char s[1];
//itoa(sizeof(idtr),s);
//serial_writestring(s);
idtr
.
limit
=
idt_limit
;
idtr
.
limit
=
idt_limit
;
idtr
.
base
=
idt_base
;
idtr
.
base
=
idt_base
;
char
f
[
20
];
itoa
(
idtr
.
limit
,
f
);
//serial_writestring(f);
//serial_writestring("\n");
itoa
(
idtr
.
base
,
f
);
//serial_writestring(f);
//serial_writestring("\n");
asm
volatile
(
"lidt (%0)"
:
:
"r"
(
&
idtr
));
asm
volatile
(
"lidt (%0)"
:
:
"r"
(
&
idtr
));
}
}
static
void
default_handler
()
{
static
void
default_handler
()
{
//DEBUG OUTPUT MAYBE?
//DEBUG OUTPUT MAYBE?
serial_writestring
(
"int caught
\n
"
);
serial_writestring
(
"int caught
\n
"
);
for
(;;);
//for(;;);
return
;
}
}
idt_desc
*
get_ir
(
uint32_t
i
)
{
idt_desc
*
get_ir
(
uint32_t
i
)
{
...
@@ -28,6 +39,7 @@ idt_desc* get_ir (uint32_t i) {
...
@@ -28,6 +39,7 @@ idt_desc* get_ir (uint32_t i) {
return
0
;
return
0
;
return
&
_idt
[
i
];
return
&
_idt
[
i
];
}
}
int
install_ir
(
uint32_t
i
,
uint16_t
flags
,
uint16_t
code_sel
,
IRQ_HANDLER
irq
)
{
int
install_ir
(
uint32_t
i
,
uint16_t
flags
,
uint16_t
code_sel
,
IRQ_HANDLER
irq
)
{
if
(
i
>
MAX_IDT_INT
)
if
(
i
>
MAX_IDT_INT
)
return
0
;
return
0
;
...
@@ -37,16 +49,20 @@ int install_ir (uint32_t i, uint16_t flags, uint16_t code_sel, IRQ_HANDLER irq)
...
@@ -37,16 +49,20 @@ int install_ir (uint32_t i, uint16_t flags, uint16_t code_sel, IRQ_HANDLER irq)
_idt
[
i
].
low_base
=
(
uint16_t
)(
uiBase
&
0xffff
);
_idt
[
i
].
low_base
=
(
uint16_t
)(
uiBase
&
0xffff
);
_idt
[
i
].
high_base
=
(
uint16_t
)((
uiBase
>>
16
)
&
0xffff
);
_idt
[
i
].
high_base
=
(
uint16_t
)((
uiBase
>>
16
)
&
0xffff
);
_idt
[
i
].
reserved
=
0
;
_idt
[
i
].
reserved
=
0
;
_idt
[
i
].
flags
=
(
uint8_t
)(
flags
);
_idt
[
i
].
flags
=
(
uint8_t
)(
flags
);
_idt
[
i
].
code_sel
=
code_sel
;
_idt
[
i
].
code_sel
=
code_sel
;
return
0
;
return
0
;
}
}
int
idt_init
(
uint16_t
code_sel
)
{
int
idt_init
(
uint16_t
code_sel
)
{
idt_limit
=
sizeof
(
idt_desc
)
*
MAX_IDT_INT
-
1
;
idt_limit
=
sizeof
(
idt_desc
)
*
MAX_IDT_INT
-
1
;
idt_base
=
(
uint32_t
)
&
_idt
[
0
];
idt_base
=
(
uint32_t
)
&
_idt
[
0
];
memset
((
void
*
)
&
_idt
[
0
],
0
,
sizeof
(
idt_desc
)
*
MAX_IDT_INT
-
1
);
memset
((
void
*
)
&
_idt
[
0
],
0
,
sizeof
(
idt_desc
)
*
MAX_IDT_INT
-
1
);
for
(
int
i
=
0
;
i
<
MAX_IDT_INT
;
i
++
)
for
(
int
i
=
0
;
i
<
MAX_IDT_INT
;
i
++
)
install_ir
(
i
,
IDT_PR
|
IDT_32
,
code_sel
,(
IRQ_HANDLER
)
default_handler
);
install_ir
(
i
,
IDT_PR
|
IDT_32
,
code_sel
,(
IRQ_HANDLER
)
default_handler
);
idt_install
();
idt_install
();
char
f
[
20
];
itoa
((
uintptr_t
)
&
_idt
,
f
);
//serial_writestring(f);
return
0
;
return
0
;
}
}
src/kern.c
View file @
f98f0cda
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include <stddef.h>
#include <stddef.h>
#include <stdint.h>
#include <stdint.h>
#include "string.h"
#include "serial.h"
#include "serial.h"
#include "term.h"
#include "term.h"
#include "mem.h"
#include "mem.h"
...
@@ -13,18 +14,23 @@ extern "C" /* Use C linkage for kernel_main. */
...
@@ -13,18 +14,23 @@ extern "C" /* Use C linkage for kernel_main. */
#endif
#endif
void
kernel_main
()
{
void
kernel_main
()
{
/* Initialize terminal and serial interfaces */
/* Initialize terminal and serial interfaces */
terminal_initialize
();
terminal_initialize
();
serial_init
();
serial_init
();
char
b
[
2
];
int
a
=
strlen
(
""
);
itoa
(
a
,
b
);
terminal_writestring
(
b
);
gdt_init
();
gdt_init
();
idt_init
(
0x
0
);
idt_init
(
0x
8
);
/* Since there is no support for newlines in terminal_putchar
/* Since there is no support for newlines in terminal_putchar
* yet, '\n' will produce some VGA specific character instead.
* yet, '\n' will produce some VGA specific character instead.
* This is normal.
* This is normal.
*/
*/
serial_writestring
(
"
First Serial Test!
\n
"
);
serial_writestring
(
"
IDT initialized
\n
"
);
terminal_writestring
(
"Hello, kernel World!
\n
"
);
terminal_writestring
(
"Hello, kernel World!
\n
"
);
serial_writestring
(
"Second Serial Test
\n
"
);
//
serial_writestring("Second Serial Test\n");
// Enable paging of memory. For now there is only one virtual
// Enable paging of memory. For now there is only one virtual
// memory space defined by page_dir
// memory space defined by page_dir
...
@@ -35,4 +41,7 @@ void kernel_main() {
...
@@ -35,4 +41,7 @@ void kernel_main() {
enablePaging
();
enablePaging
();
serial_writestring
(
"Finished Initilizing memory
\n
"
);
serial_writestring
(
"Finished Initilizing memory
\n
"
);
asm
(
"int $0x80"
);
asm
(
"int $0x90"
);
asm
(
"hlt"
);
}
}
src/makefile
View file @
f98f0cda
C
=
/home/adam/college/kernel/cross/bin/
i686-elf-gcc
C
=
i686-elf-gcc
all
:
all
:
/usr/bin/nasm
-felf32
head.asm
-o
boot.o
/usr/bin/nasm
-felf32
head.asm
-o
boot.o
...
...
src/string.c
View file @
f98f0cda
...
@@ -6,3 +6,19 @@ void *memset(void *s, int c, size_t n){
...
@@ -6,3 +6,19 @@ void *memset(void *s, int c, size_t n){
*
p
++=
(
unsigned
char
)
c
;
*
p
++=
(
unsigned
char
)
c
;
return
s
;
return
s
;
}
}
void
itoa
(
int
n
,
char
s
[])
{
int
i
,
sign
;
if
((
sign
=
n
)
<
0
)
/* record sign */
n
=
-
n
;
/* make n positive */
i
=
0
;
do
{
/* generate digits in reverse order */
s
[
i
++
]
=
n
%
10
+
'0'
;
/* get next digit */
}
while
((
n
/=
10
)
>
0
);
/* delete it */
if
(
sign
<
0
)
s
[
i
++
]
=
'-'
;
s
[
i
]
=
'\0'
;
//reverse(s);
}
src/string.h
View file @
f98f0cda
...
@@ -3,4 +3,6 @@
...
@@ -3,4 +3,6 @@
#include<stddef.h>
#include<stddef.h>
void
*
memset
(
void
*
s
,
int
c
,
size_t
n
);
void
*
memset
(
void
*
s
,
int
c
,
size_t
n
);
void
itoa
(
int
n
,
char
s
[]);
#endif
#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