3 Commits

Author SHA1 Message Date
brice.boisson
3a3795d524 Add: basic scheduler 2023-10-01 00:40:00 +09:00
BOISSON Brice
917988e871 Merge pull request #3 from BriceBoisson/brice-elf
Brice elf
2023-09-27 10:39:36 +09:00
BOISSON Brice
883afe0753 Update README.md 2023-09-07 14:41:46 +09:00
7 changed files with 63 additions and 26 deletions

View File

@@ -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] Running and Userland (TSS)
- [X] Let the userland call the kernel (syscall)
- [ ] Use paging
- [ ] Running multiple userland (ordonnanceur)
- [ ] Using ext2 File System
- [ ] Running elf binary
- [ ] Having a small libc and needed syscall to run the shell
- [ ] (Bonus) Having a basic visual interface (VGA ?)
@@ -19,4 +21,4 @@ https://github.com/Galli24/kernel-k-project
- The ressources on the website OSDev:
https://wiki.osdev.org/Main_Page
- The in Intel® 64 and IA-32 Architectures, Software Developers 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

View File

@@ -4,6 +4,7 @@
#include "pic_controler.h"
#include "debug.h"
#include "syscall.h"
#include "userland.h"
void isr_default_int(void)
{
@@ -17,7 +18,15 @@ void isr_page_fault(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)

View File

@@ -22,8 +22,12 @@ void main(void)
char *data_end = _binary_a_out_end;
size_t data_size = (size_t)_binary_a_out_size;
u16 tss = 0x28;
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 (;;)
{

View File

@@ -2,32 +2,33 @@
#include "tss.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
userland_stack += 3;
userland_code += 3;
userland_data += 3;
userland_data_seg += 3;
DEBUG_INFO("LAUCHING USER LAND PROCESS");
asm volatile (" \n \
mov %0, %%ax \n \
ltr %%ax \n \
movw %%ss, %1 \n \
movl %%esp, %2 \n \
movw $0x23, %%ax \n \
movw %%ax, %%ds \n \
movw %%ax, %%es \n \
movw %%ax, %%fs \n \
movw %%ax, %%gs \n \
mov %%esp, %%eax \n \
push $0x23 \n \
push $0x7FFFEFFF \n \
pushfl \n \
push $0x1B \n \
push $0x6000000 \n \
asm volatile (" \n \
mov %0, %%ax \n \
ltr %%ax \n \
movw %%ss, %1 \n \
movl %%esp, %2 \n \
movw $0x23, %%ax \n \
movw %%ax, %%ds \n \
movw %%ax, %%es \n \
movw %%ax, %%fs \n \
movw %%ax, %%gs \n \
mov %%esp, %%eax \n \
push $0x23 \n \
push $0x7FFFEFFF \n \
pushfl \n \
push $0x1B \n \
push $0x6000000 \n \
iret" : "+r" (tss),
"=m" (user_land_tss.ss0),
"=m" (user_land_tss.esp0));

View File

@@ -101,6 +101,8 @@ void pic_init(void)
IRQ_set_mask(i);
}
DEBUG_INFO("Unmasking IRQ 0 - Clock");
IRQ_clear_mask(0);
DEBUG_INFO("Unmasking IRQ 1 - Keyboard");
IRQ_clear_mask(1);

View File

@@ -30,6 +30,21 @@ int create_process(int uid, char *data_start)
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)
{
DEBUG_INFO("SWITCHING TO PROCESS");
@@ -40,6 +55,8 @@ int switch_to_process(int uid)
mov %0, %%eax \n \
mov %%eax, %%cr3" : "+r" (process_page_dir_adress));
// TODO : once data by process has been implemented, load the right one
launch_process(0x28, 0x6000000, 0x20, 0x18, 0x20);
userland_data->curent_process = uid;
userland_data->active_process[uid / 32] |= 1 << (uid % 32);
return 0;
}

View File

@@ -10,17 +10,19 @@ struct userland_data
{
struct page_directory_entry page_directories[1024];
struct page_table_entry page_table[1024];
};
} __attribute__((packed));
struct userlands_data {
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;
int create_process(int uid, char *data_start);
int switch_to_ring_3(int uid);
int switch_to_process(int uid);
#endif /* !USERLAND_H */