Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
3a3795d524 | ||
|
917988e871 | ||
|
883afe0753 |
@@ -6,7 +6,9 @@ This kernel is written as a educative project. The goal is to have a kernel able
|
|||||||
- [X] Manage IRQ (enable PIC)
|
- [X] Manage IRQ (enable PIC)
|
||||||
- [X] Running and Userland (TSS)
|
- [X] Running and Userland (TSS)
|
||||||
- [X] Let the userland call the kernel (syscall)
|
- [X] Let the userland call the kernel (syscall)
|
||||||
|
- [ ] Use paging
|
||||||
- [ ] Running multiple userland (ordonnanceur)
|
- [ ] Running multiple userland (ordonnanceur)
|
||||||
|
- [ ] Using ext2 File System
|
||||||
- [ ] Running elf binary
|
- [ ] Running elf binary
|
||||||
- [ ] Having a small libc and needed syscall to run the shell
|
- [ ] Having a small libc and needed syscall to run the shell
|
||||||
- [ ] (Bonus) Having a basic visual interface (VGA ?)
|
- [ ] (Bonus) Having a basic visual interface (VGA ?)
|
||||||
@@ -19,4 +21,4 @@ https://github.com/Galli24/kernel-k-project
|
|||||||
- The ressources on the website OSDev:
|
- The ressources on the website OSDev:
|
||||||
https://wiki.osdev.org/Main_Page
|
https://wiki.osdev.org/Main_Page
|
||||||
- The in Intel® 64 and IA-32 Architectures, Software Developer’s Manual, Volume 3A: System Programming Guide, Part 1:
|
- The in Intel® 64 and IA-32 Architectures, Software Developer’s Manual, Volume 3A: System Programming Guide, Part 1:
|
||||||
https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html
|
https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html
|
||||||
|
11
src/isr.c
11
src/isr.c
@@ -4,6 +4,7 @@
|
|||||||
#include "pic_controler.h"
|
#include "pic_controler.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "syscall.h"
|
#include "syscall.h"
|
||||||
|
#include "userland.h"
|
||||||
|
|
||||||
void isr_default_int(void)
|
void isr_default_int(void)
|
||||||
{
|
{
|
||||||
@@ -17,7 +18,15 @@ void isr_page_fault(void)
|
|||||||
|
|
||||||
void isr_clock_int(void)
|
void isr_clock_int(void)
|
||||||
{
|
{
|
||||||
DEBUG_INFO("Enterring clock interrupt handler.");
|
DEBUG_INFO("Clock interrupt handler.");
|
||||||
|
for (int i = (userland_data->curent_process + 1) % 128; i != userland_data->curent_process; i = (i + 1) % 128)
|
||||||
|
{
|
||||||
|
if (userland_data->active_process[i / 32] & (1 << (i % 32)))
|
||||||
|
{
|
||||||
|
switch_to_process(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void isr_kbd_int(void)
|
void isr_kbd_int(void)
|
||||||
|
@@ -22,8 +22,12 @@ void main(void)
|
|||||||
char *data_end = _binary_a_out_end;
|
char *data_end = _binary_a_out_end;
|
||||||
size_t data_size = (size_t)_binary_a_out_size;
|
size_t data_size = (size_t)_binary_a_out_size;
|
||||||
|
|
||||||
|
u16 tss = 0x28;
|
||||||
|
|
||||||
create_process(0, data_start);
|
create_process(0, data_start);
|
||||||
switch_to_process(0);
|
create_process(1, data_start);
|
||||||
|
userland_data->active_process[0] |= 1 << (1 % 32);
|
||||||
|
switch_to_ring_3(0);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
@@ -2,32 +2,33 @@
|
|||||||
|
|
||||||
#include "tss.h"
|
#include "tss.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "userland.h"
|
||||||
|
|
||||||
void launch_process(u16 tss, int memory_start, int userland_stack, int userland_code, u16 userland_data)
|
void launch_process(u16 tss, int memory_start, int userland_stack, int userland_code, u16 userland_data_seg)
|
||||||
{
|
{
|
||||||
// Setting DPL and GDT bits
|
// Setting DPL and GDT bits
|
||||||
userland_stack += 3;
|
userland_stack += 3;
|
||||||
userland_code += 3;
|
userland_code += 3;
|
||||||
userland_data += 3;
|
userland_data_seg += 3;
|
||||||
|
|
||||||
DEBUG_INFO("LAUCHING USER LAND PROCESS");
|
DEBUG_INFO("LAUCHING USER LAND PROCESS");
|
||||||
|
|
||||||
asm volatile (" \n \
|
asm volatile (" \n \
|
||||||
mov %0, %%ax \n \
|
mov %0, %%ax \n \
|
||||||
ltr %%ax \n \
|
ltr %%ax \n \
|
||||||
movw %%ss, %1 \n \
|
movw %%ss, %1 \n \
|
||||||
movl %%esp, %2 \n \
|
movl %%esp, %2 \n \
|
||||||
movw $0x23, %%ax \n \
|
movw $0x23, %%ax \n \
|
||||||
movw %%ax, %%ds \n \
|
movw %%ax, %%ds \n \
|
||||||
movw %%ax, %%es \n \
|
movw %%ax, %%es \n \
|
||||||
movw %%ax, %%fs \n \
|
movw %%ax, %%fs \n \
|
||||||
movw %%ax, %%gs \n \
|
movw %%ax, %%gs \n \
|
||||||
mov %%esp, %%eax \n \
|
mov %%esp, %%eax \n \
|
||||||
push $0x23 \n \
|
push $0x23 \n \
|
||||||
push $0x7FFFEFFF \n \
|
push $0x7FFFEFFF \n \
|
||||||
pushfl \n \
|
pushfl \n \
|
||||||
push $0x1B \n \
|
push $0x1B \n \
|
||||||
push $0x6000000 \n \
|
push $0x6000000 \n \
|
||||||
iret" : "+r" (tss),
|
iret" : "+r" (tss),
|
||||||
"=m" (user_land_tss.ss0),
|
"=m" (user_land_tss.ss0),
|
||||||
"=m" (user_land_tss.esp0));
|
"=m" (user_land_tss.esp0));
|
||||||
|
@@ -101,6 +101,8 @@ void pic_init(void)
|
|||||||
IRQ_set_mask(i);
|
IRQ_set_mask(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEBUG_INFO("Unmasking IRQ 0 - Clock");
|
||||||
|
IRQ_clear_mask(0);
|
||||||
DEBUG_INFO("Unmasking IRQ 1 - Keyboard");
|
DEBUG_INFO("Unmasking IRQ 1 - Keyboard");
|
||||||
IRQ_clear_mask(1);
|
IRQ_clear_mask(1);
|
||||||
|
|
||||||
|
@@ -30,6 +30,21 @@ int create_process(int uid, char *data_start)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int switch_to_ring_3(int uid){
|
||||||
|
DEBUG_INFO("SWITCHING TO RING 3");
|
||||||
|
void *process_page_dir_adress = userland_data->userland_data[uid].page_directories;
|
||||||
|
|
||||||
|
// load cr3
|
||||||
|
asm volatile (" \
|
||||||
|
mov %0, %%eax \n \
|
||||||
|
mov %%eax, %%cr3" : "+r" (process_page_dir_adress));
|
||||||
|
|
||||||
|
userland_data->curent_process = uid;
|
||||||
|
userland_data->active_process[uid / 32] |= 1 << (uid % 32);
|
||||||
|
|
||||||
|
launch_process(0x28, 0x6000000, 0x20, 0x18, 0x20);
|
||||||
|
}
|
||||||
|
|
||||||
int switch_to_process(int uid)
|
int switch_to_process(int uid)
|
||||||
{
|
{
|
||||||
DEBUG_INFO("SWITCHING TO PROCESS");
|
DEBUG_INFO("SWITCHING TO PROCESS");
|
||||||
@@ -40,6 +55,8 @@ int switch_to_process(int uid)
|
|||||||
mov %0, %%eax \n \
|
mov %0, %%eax \n \
|
||||||
mov %%eax, %%cr3" : "+r" (process_page_dir_adress));
|
mov %%eax, %%cr3" : "+r" (process_page_dir_adress));
|
||||||
|
|
||||||
// TODO : once data by process has been implemented, load the right one
|
userland_data->curent_process = uid;
|
||||||
launch_process(0x28, 0x6000000, 0x20, 0x18, 0x20);
|
userland_data->active_process[uid / 32] |= 1 << (uid % 32);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -10,17 +10,19 @@ struct userland_data
|
|||||||
{
|
{
|
||||||
struct page_directory_entry page_directories[1024];
|
struct page_directory_entry page_directories[1024];
|
||||||
struct page_table_entry page_table[1024];
|
struct page_table_entry page_table[1024];
|
||||||
};
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
|
||||||
struct userlands_data {
|
struct userlands_data {
|
||||||
struct userland_data userland_data[128];
|
struct userland_data userland_data[128];
|
||||||
u32 page_dir[4];
|
int curent_process;
|
||||||
};
|
u32 active_process[4];
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
extern struct userlands_data *userland_data;
|
extern struct userlands_data *userland_data;
|
||||||
|
|
||||||
int create_process(int uid, char *data_start);
|
int create_process(int uid, char *data_start);
|
||||||
|
int switch_to_ring_3(int uid);
|
||||||
int switch_to_process(int uid);
|
int switch_to_process(int uid);
|
||||||
|
|
||||||
#endif /* !USERLAND_H */
|
#endif /* !USERLAND_H */
|
||||||
|
Reference in New Issue
Block a user