Scheduling + setting up files
This commit is contained in:
parent
8ae88cf3e7
commit
0e2cfab914
|
|
@ -352,3 +352,19 @@ _irq_common_stub:
|
|||
popad
|
||||
add esp, 8
|
||||
iret
|
||||
|
||||
global panic_hold
|
||||
|
||||
panic_hold:
|
||||
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
mov esp, [ebp + 8]
|
||||
|
||||
pop gs
|
||||
pop fs
|
||||
pop es
|
||||
pop ds
|
||||
popad
|
||||
jmp $
|
||||
|
|
@ -41,17 +41,16 @@ void _irq_handler(cpu_registers_t *regs){
|
|||
}
|
||||
else if(interrupt_handlers[regs->int_no - 32])
|
||||
{
|
||||
if(regs->int_no == 32){
|
||||
// printf("Tick\n");
|
||||
// printf("%x\n", regs->int_no);
|
||||
}
|
||||
// printf("found one for an int");
|
||||
regs = interrupt_handlers[regs->int_no - 32](regs);
|
||||
// printf("returned;")
|
||||
// printf("eip: %x", regs->eip);
|
||||
}
|
||||
outb(0x20, 0x20);
|
||||
if(regs->int_no >= 0x28){
|
||||
outb(0xa0, 0x20);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
void _isr_handler(cpu_registers_t *regs){
|
||||
printf("Error!! %x\n", regs->eip);
|
||||
|
|
@ -62,6 +61,16 @@ cpu_registers_t *syscall(cpu_registers_t *regs){
|
|||
|
||||
}
|
||||
|
||||
extern void panic_hold(cpu_registers_t *regs);
|
||||
|
||||
void kernel_panic(char *message, cpu_registers_t *regs){
|
||||
printf("Kernel Panic!\nAn fatal error occured, and could not be recovered.\nError: ");
|
||||
printf(message);
|
||||
printf("System halting...\n");
|
||||
if(regs != 0) panic_hold(regs);
|
||||
asm volatile ("jmp .");
|
||||
}
|
||||
|
||||
void install_irq_handler(void (*handler)(), uint8_t irqno){
|
||||
interrupt_handlers[irqno] = handler;
|
||||
}
|
||||
|
|
@ -74,7 +83,7 @@ void init_idt(){
|
|||
// printf("last ")
|
||||
for(uint32_t i = 0; i < 16; i++){
|
||||
set_idt_entry(i + 32, (_irq0 + ((_irq1 - _irq0) * i)), IDT_GATE_INT, 0x10);
|
||||
printf("int %d: address: %x\n", i + 32, _irq0 + (_irq1 - _irq0) * i);
|
||||
// printf("int %d: address: %x\n", i + 32, _irq0 + (_irq1 - _irq0) * i);
|
||||
}
|
||||
|
||||
idt_desc.pointer = (uint32_t)&idt_table;
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
#define mmap_count 0x20000
|
||||
|
||||
uint8_t pm_map[mmap_count];
|
||||
uint8_t volatile pm_map[mmap_count];
|
||||
|
||||
uint32_t total_memory = 0;
|
||||
uint32_t total_memory_usable = 0;
|
||||
uint32_t last_allocated = 0;
|
||||
uint32_t volatile last_allocated = 0;
|
||||
extern uint32_t _start;
|
||||
|
||||
uint32_t pm_alloc(){
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "shared/interrupts.h"
|
||||
#include "drivers/serial.h"
|
||||
#include "drivers/pic.h"
|
||||
#include "system/scheduler.h"
|
||||
|
||||
extern void kmain(kernel_info_t *kernel_info){
|
||||
init_serial();
|
||||
|
|
@ -11,9 +12,10 @@ extern void kmain(kernel_info_t *kernel_info){
|
|||
init_idt();
|
||||
init_pic(32);
|
||||
pic_disable();
|
||||
init_scheduler();
|
||||
pic_setmask(0xfe, PIC1_DATA);
|
||||
enable_interrupts();
|
||||
printf("done\n");
|
||||
// printf("done\n");
|
||||
for(;;);
|
||||
return;
|
||||
}
|
||||
|
|
@ -29,4 +29,5 @@ inline void enable_interrupts(){
|
|||
inline void disable_interrupts(){
|
||||
asm volatile("cli");
|
||||
}
|
||||
void kernel_panic(char *msg, cpu_registers_t *regs);
|
||||
void install_irq_handler(void (*handler)(), uint8_t irqno);
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
#pragma once
|
||||
// #include "memory.h"
|
||||
#include "../drivers/serial.h"
|
||||
#include "interrupts.h"
|
||||
|
||||
typedef struct kernel_info{
|
||||
void *mmap_ptr;
|
||||
uint16_t mmap_entry_count;
|
||||
|
|
@ -12,3 +14,5 @@ typedef struct kernel_info{
|
|||
void *loaded_modues;
|
||||
uint32_t loaded_module_count;
|
||||
}__attribute__((packed)) kernel_info_t;
|
||||
|
||||
#define PANIC(m) kernel_panic(m, 0)
|
||||
|
|
@ -67,5 +67,12 @@ uint32_t get_paddr(void *addr);
|
|||
uint32_t pm_alloc();
|
||||
void pm_reserve(uint32_t addr);
|
||||
void pm_free(uint32_t addr);
|
||||
|
||||
inline void set_cr3(void *cr3){
|
||||
asm volatile("mov %0, %%eax; mov %%eax, %%cr3":: "r"(cr3));
|
||||
}
|
||||
inline void *get_cr3(){
|
||||
void *cr3;
|
||||
asm volatile("mov %%cr3, %%eax;mov %0, %%eax": "=r"(cr3));
|
||||
return cr3;
|
||||
}
|
||||
int pm_init(kernel_info_t *kernel_info);
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
#include<stdint.h>
|
||||
|
||||
typedef struct{
|
||||
uint32_t devid;
|
||||
enum DeviceType{
|
||||
NULL_TYPE,
|
||||
DEV_TYPE_DISK,
|
||||
DEV_TYPE_AUDIO,
|
||||
DEV_TYPE_KBD,
|
||||
DEV_TYPE_MOUSE,
|
||||
DEV_TYPE_VIDEO,
|
||||
DEV_TYPE_OTHER,
|
||||
DEV_TYPE_NAT,
|
||||
}device_type;
|
||||
uint32_t driver_pid;
|
||||
}device_t;
|
||||
typedef struct{
|
||||
uint64_t start_sector; //Register or sector (depending on command and or device type)
|
||||
uint64_t total_sectors;//hard disks only
|
||||
volatile void *buffer;
|
||||
uint32_t buffer_size;//size of each object in buffer
|
||||
uint32_t buffer_count;//Number of objects of size buffer_size in buffer
|
||||
enum DeviceCommand{
|
||||
NULLOP,
|
||||
DEVICE_READ,
|
||||
DEVICE_WRITE,
|
||||
DEVICE_INIT,
|
||||
DEVICE_COMMAND,
|
||||
DEVICE_SET_MMAP,
|
||||
DEVICE_SET_DMA,
|
||||
}command;
|
||||
uint32_t requesting_pid;
|
||||
}device_packet_t;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
#include "modules.h"
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
#include "../shared/interrupts.h"
|
||||
#include "scheduler.h"
|
||||
#include "../shared/kstdlib.h"
|
||||
|
||||
process_t volatile processes[0x10000];
|
||||
uint32_t volatile process_queue[0x10000];
|
||||
uint32_t volatile current_pid;
|
||||
|
||||
void init_scheduler(){
|
||||
for(uint32_t i = 0; i < 0x10000; i++){
|
||||
processes[i].flags.present = 0;
|
||||
process_queue[i] = 0;
|
||||
}
|
||||
current_pid = 0;
|
||||
install_irq_handler(schedule, 0);
|
||||
printf("Installing scheduler");
|
||||
}
|
||||
|
||||
cpu_registers_t *schedule(cpu_registers_t *regs){
|
||||
uint32_t i = current_pid;
|
||||
// printf("Test");
|
||||
while(processes[process_queue[i]].flags.blocked){
|
||||
i++;
|
||||
if(i == current_pid) return regs;
|
||||
if(i >= 0x10000) i = 0;
|
||||
}
|
||||
current_pid = i;
|
||||
return &(processes[i].cpuregs);
|
||||
// return regs;
|
||||
}
|
||||
|
||||
void spawn_new_process(cpu_registers_t defaultregs, char **argv, uint32_t argc, void *cr3){
|
||||
uint32_t i = current_pid;
|
||||
while(processes[i].flags.present){
|
||||
i++;
|
||||
if(i >= 0x10000) i = 0;
|
||||
if(i == current_pid) return;
|
||||
}
|
||||
process_t new_proc = {0};
|
||||
new_proc.argc = argc;
|
||||
new_proc.argv = argv;
|
||||
new_proc.page_dir = cr3;
|
||||
new_proc.cpuregs = defaultregs;
|
||||
new_proc.parent = current_pid;
|
||||
new_proc.flags.present = 1;
|
||||
new_proc.flags.cpu_lvl = 1;
|
||||
new_proc.flags.priority = 0;
|
||||
new_proc.flags.system = processes[current_pid].flags.system;
|
||||
return;
|
||||
}
|
||||
|
||||
void fork(){
|
||||
|
||||
}
|
||||
void exec(){
|
||||
|
||||
}
|
||||
void exit(){
|
||||
|
||||
}
|
||||
void thread_start(void (*function)(), uint32_t *exit_code){
|
||||
|
||||
}
|
||||
void thread_join(uint32_t thread_id, uint32_t **exit_code){
|
||||
|
||||
}
|
||||
void thread_exit(uint32_t *exit_code){
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "../shared/interrupts.h"
|
||||
typedef struct{
|
||||
char **argv;
|
||||
uint32_t argc;
|
||||
cpu_registers_t cpuregs;
|
||||
void *page_dir;
|
||||
struct pflags{
|
||||
uint8_t blocked :1;
|
||||
uint8_t system :1;
|
||||
uint8_t cpu_lvl :1;
|
||||
uint8_t priority:3;
|
||||
uint8_t present :1;
|
||||
uint8_t unused :1;
|
||||
}flags;
|
||||
uint32_t thread_id;
|
||||
uint32_t parent;
|
||||
uint32_t uid;
|
||||
uint32_t gid;
|
||||
}process_t;
|
||||
|
||||
cpu_registers_t* schedule(cpu_registers_t *regs);
|
||||
void init_scheduler();
|
||||
Loading…
Reference in New Issue