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
88806bb4
authored
Oct 19, 2015
by
malcolm
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Overhaul of interrupts, now actually captures useful info.
parent
beb05e9f
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
128 additions
and
9 deletions
src/idt.c
src/idt.h
src/idta.asm
src/makefile
src/string.c
src/idt.c
View file @
88806bb4
...
...
@@ -5,11 +5,14 @@
#pragma GCC push_options
#pragma GCC optimize ("0")
#define serial_val(i) itoa(i,f);serial_writestring(f);serial_writestring(" ");
uint16_t
idt_limit
;
uint32_t
idt_base
;
idt_desc
_idt
[
MAX_IDT_INT
];
uint16_t
_code_sel
;
void
idt_install
()
{
struct
...
...
@@ -22,10 +25,16 @@ void idt_install()
asm
volatile
(
"lidt (%0)"
:
:
"r"
(
&
idtr
));
}
static
void
default_handler
(
)
void
default_handler
(
struct
reg_state
reg
,
uint32_t
interrupt
,
uint32_t
error
,
struct
stack_state
stack
)
{
//DEBUG OUTPUT MAYBE?
serial_writestring
(
"int caught
\n
"
);
serial_writestring
(
"int caught "
);
char
f
[
20
];
serial_val
(
interrupt
);
serial_val
(
error
);
serial_val
(
stack
.
eip
);
serial_val
(
stack
.
cd
);
serial_val
(
stack
.
eflags
);
serial_writestring
(
"
\n
"
);
return
;
}
...
...
@@ -57,15 +66,22 @@ int install_ir(uint32_t i, uint16_t flags, uint16_t code_sel, IRQ_HANDLER irq)
return
0
;
}
void
idt_ftoi
(
int
a
,
IRQ_HANDLER
irq
)
{
install_ir
(
a
,
IDT_PR
|
IDT_32
,
_code_sel
,
irq
);
}
int
idt_init
(
uint16_t
code_sel
)
{
idt_limit
=
sizeof
(
idt_desc
)
*
MAX_IDT_INT
-
1
;
idt_base
=
(
uint32_t
)
&
_idt
[
0
];
memset
((
void
*
)
&
_idt
[
0
],
0
,
sizeof
(
idt_desc
)
*
MAX_IDT_INT
-
1
);
for
(
int
i
=
0
;
i
<
MAX_IDT_INT
;
i
++
)
{
install_ir
(
i
,
IDT_PR
|
IDT_32
,
code_sel
,
(
IRQ_HANDLER
)
default_handler
);
}
//for (int i=0; i<MAX_IDT_INT; i++)
//{
// install_ir (i, IDT_PR|IDT_32, code_sel, (IRQ_HANDLER)default_handler);
//}
_code_sel
=
code_sel
;
idtsetup
();
idt_install
();
return
0
;
}
...
...
src/idt.h
View file @
88806bb4
...
...
@@ -23,8 +23,31 @@ typedef struct
uint16_t
high_base
;
}
__attribute__
((
packed
))
idt_desc
;
struct
reg_state
{
uint32_t
eax
;
uint32_t
ecx
;
uint32_t
edx
;
uint32_t
ebx
;
uint32_t
ebp
;
uint32_t
esi
;
uint32_t
edi
;
uint32_t
esp
;
}
__attribute__
((
packed
));
struct
stack_state
{
uint32_t
eip
;
uint32_t
cd
;
uint32_t
eflags
;
}
__attribute__
((
packed
));
extern
void
default_handler
(
struct
reg_state
reg
,
uint32_t
interrupt
,
uint32_t
error
,
struct
stack_state
stack
);
extern
idt_desc
*
get_ir
(
uint32_t
i
);
extern
int
install_ir
(
uint32_t
i
,
uint16_t
flags
,
uint16_t
code_sel
,
IRQ_HANDLER
);
extern
int
idt_init
(
uint16_t
code_sel
);
extern
void
idt_ftoi
(
int
a
,
IRQ_HANDLER
irq
);
extern
void
idtsetup
();
#endif
src/idta.asm
0 → 100644
View file @
88806bb4
extern
default_handler
extern
idt_ftoi
%macro
error_interrupt
1
global
interrupt_handler_
%1
interrupt_handler_
%1
:
push
dword
%1
jmp
common_handler
%endmacro
%macro
regular_interrupt
1
global
interrupt_handler_
%1
interrupt_handler_
%1
:
push
dword
0
push
dword
%1
jmp
common_handler
%endmacro
common_handler
:
pusha
call
default_handler
popa
add
esp
,
8
iret
regular_interrupt
0
regular_interrupt
1
regular_interrupt
2
regular_interrupt
3
regular_interrupt
4
regular_interrupt
5
regular_interrupt
6
regular_interrupt
7
error_interrupt
8
regular_interrupt
9
error_interrupt
10
error_interrupt
11
error_interrupt
12
error_interrupt
13
error_interrupt
14
regular_interrupt
15
regular_interrupt
16
error_interrupt
17
%assign
i
18
%rep
12
regular_interrupt
i
%assign
i
i
+
1
%endrep
error_interrupt
30
%assign
i
31
%rep
225
regular_interrupt
i
%assign
i
i
+
1
%endrep
global
idtsetup
idtsetup
:
%
assign
i
0
%
rep
256
push
interrupt_handler_
%
[i]
push
i
call
idt_ftoi
add
esp
,
8
%
assign
i
i
+
1
%
endrep
ret
src/makefile
View file @
88806bb4
...
...
@@ -3,6 +3,7 @@ C=i686-elf-gcc
all
:
/usr/bin/nasm
-felf32
head.asm
-o
boot.o
/usr/bin/nasm
-felf32
paging.asm
/usr/bin/nasm
-felf32
idta.asm
$C
*
.c
-std
=
gnu99
-ffreestanding
-O2
-Wall
-Wextra
-c
$C
-T
linker.ld
-o
myos.bin
-ffreestanding
-O2
-nostdlib
*
.o
-lgcc
...
...
src/string.c
View file @
88806bb4
...
...
@@ -7,6 +7,18 @@ void *memset(void *s, int c, size_t n){
return
s
;
}
void
reverse
(
char
s
[]
)
{
int
c
,
i
,
j
;
for
(
i
=
0
,
j
=
strlen
(
s
)
-
1
;
i
<
j
;
i
++
,
j
--
)
{
c
=
s
[
i
];
s
[
i
]
=
s
[
j
];
s
[
j
]
=
c
;
}
}
void
itoa
(
int
n
,
char
s
[])
{
int
i
,
sign
;
...
...
@@ -25,9 +37,10 @@ void itoa(int n, char s[])
s
[
i
++
]
=
'-'
;
}
s
[
i
]
=
'\0'
;
//
reverse(s);
reverse
(
s
);
}
size_t
strlen
(
const
char
*
str
)
{
size_t
ret
=
0
;
...
...
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