Skip to content

Commit 402ea85

Browse files
committed
Added IDT support. (v2)
1 parent ca3ccb8 commit 402ea85

File tree

8 files changed

+49
-9
lines changed

8 files changed

+49
-9
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Latest commits supports:
99
- Textmode printf()
1010
- panic()
1111
- semi-modules and mprint()
12-
- GDT (WIP)
12+
- GDT
13+
- IDT
1314
- Minecraft as well
1415

arch/makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
all:
2-
echo -n "arch/gdt.o " >> ../objs.txt
2+
echo -n "arch/gdt.o arch/idt.o " >> ../objs.txt
33
i586-elf-gcc -c gdt.c -o gdt.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
4+
i586-elf-gcc -c idt.c -o idt.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra

boot.s

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# foglalunk a stack-nek 16KiB-ot
1717
.section .bootstrap_stack
1818
stack_bottom:
19-
.skip 16384 # 16 KiB
19+
.skip 32768 # 16 KiB
2020
stack_top:
2121

2222
# az elf-ben a .text szekcio tartalmazza a kodot amit futtatni fogunk
@@ -28,6 +28,19 @@ _set_gdtr:
2828
movl %esp, %ebp
2929

3030
lgdt 0x400000
31+
32+
movl %ebp, %esp
33+
pop %ebp
34+
ret
35+
36+
.global _set_idtr
37+
.type _set_idtr, @function
38+
_set_idtr:
39+
push %ebp
40+
movl %esp, %ebp
41+
42+
lidt 0x401F00
43+
3144
movl %ebp, %esp
3245
pop %ebp
3346
ret

display/textmode/dispi_textmode.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ inline uint16_t __textmode_create_entry(char c, uint8_t color)
1818
return _char | _color << 8;
1919
}
2020

21-
inline void __textmode_scrollup()
21+
static inline void __textmode_scrollup()
2222
{
23-
23+
uint16_t nullentry = __textmode_create_entry(' ', __textmode_make_color(d.con.fgcol, d.con.bgcol));
24+
for(int y = 0; y < TEXTMODE_HEIGHT; y++)
25+
{
26+
memcpy(VGA_MEMORY + y*TEXTMODE_WIDTH*2 ,
27+
VGA_MEMORY + (y+1)*TEXTMODE_WIDTH*2,
28+
TEXTMODE_WIDTH*2);
29+
}
2430
}
2531

2632
void __textmode_onregister()
@@ -85,6 +91,11 @@ void textmode_putc(char c)
8591
d.con.cx = 0;
8692
d.con.cy ++;
8793
}
94+
if(d.con.cy >= TEXTMODE_HEIGHT-1)
95+
{
96+
__textmode_scrollup();
97+
d.con.cy --;
98+
}
8899
/* list of special characters */
89100
if(c == '\n' || c == 0) return;
90101
/* write it to video memory */

include/display.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ typedef struct {
1919
void (*clear)();
2020
} DISPLAY;
2121
#define MODULE(name) static char* __MODULE_NAME = name;
22-
#define panic(...) kprintf("***KERNEL PANIC*** in %s at line %d in function: %s\n%s", __FILE__, __LINE__, __func__, __VA_ARGS__); for(;;);
22+
#define panic(...) {kprintf("***KERNEL PANIC*** in %s at line %d in function: %s\n%s", __FILE__, __LINE__, __func__, __VA_ARGS__); for(;;);}
2323
#define mprint(...) {kprintf("[%s]: ", __MODULE_NAME); kprintf(__VA_ARGS__);}
24+
#define kerror(...) {kprintf("***KERNEL OOPS***: "); kprintf(__VA_ARGS__);}
2425
extern uint8_t display_register(DISPLAY d);
2526
extern uint8_t display_setcurrent(uint8_t id);
2627
extern DISPLAY* display_getcurrent();

include/memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
#include <stddef.h>
66
extern void* memcpy(const void* dest, const void* src, size_t num );
77
extern void* memset (void * ptr, int value, size_t num );
8+
extern void* memset16 (void *ptr, uint16_t value, size_t num);
89

910
#endif

main.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "include/display.h"
1111
#include "display/textmode/dispi_textmode.h"
1212
#include "include/x86/gdt.h"
13+
#include "include/x86/idt.h"
1314

1415
static DISPLAY* disp = 0;
1516

@@ -31,6 +32,11 @@ void kernel_main()
3132
* tables, timers and memory to continue to tasking.
3233
*/
3334
gdt_init();
34-
/* start tasking */
35-
panic("Init couldn't be started.");
35+
/* Now, we have the GDT setup, let's load the IDT as well */
36+
idt_init();
37+
/* Next step, setup PIT. */
38+
/* Setup memory manager */
39+
/* Setup paging. */
40+
/* Enable interrupts and tasking. */
41+
panic("Reached end of main(), but no init was started.");
3642
}

memory/memutils.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ void* memcpy(const void* dest, const void* src, size_t count )
2525
}
2626
return (void*)dest;
2727
}
28-
28+
void* memset16 (void *ptr, uint16_t value, size_t num)
29+
{
30+
uint8_t* p = ptr;
31+
while(num--)
32+
*p++ = value;
33+
return ptr;
34+
}
2935
void* memset (void * ptr, int value, size_t num )
3036
{
3137
unsigned char* p=ptr;

0 commit comments

Comments
 (0)