Add preemptive multitasking
This commit is contained in:
parent
0522941a1d
commit
c0929a4eea
5
Makefile
5
Makefile
@ -1,6 +1,7 @@
|
|||||||
PLAT=i386
|
PLAT=i386
|
||||||
C_SOURCES = $(wildcard kernel/*.c kernel/cpu/$(PLAT)/*.c kernel/cpu/*.c)
|
TIMER_TYPE=$(shell cat psinfo/$(PLAT)/timer_type.txt)
|
||||||
C_HEADERS = $(wildcard kernel/*.h kernel/cpu/$(PLAT)/*.h kernel/cpu/*.h)
|
C_SOURCES = $(wildcard kernel/*.c kernel/cpu/$(PLAT)/*.c kernel/cpu/*.c kernel/timer/$(TIMER_TYPE)/*.c)
|
||||||
|
C_HEADERS = $(wildcard kernel/*.h kernel/cpu/$(PLAT)/*.h kernel/cpu/*.h kernel/timer/$(TIMER_TYPE)/*.h)
|
||||||
ASM = $(wildcard kernel/cpu/$(PLAT)/*.asm)
|
ASM = $(wildcard kernel/cpu/$(PLAT)/*.asm)
|
||||||
S_ASM = $(wildcard kernel/cpu/$(PLAT)/*.s)
|
S_ASM = $(wildcard kernel/cpu/$(PLAT)/*.s)
|
||||||
LIBC_SOURCES = $(wildcard libc/*.c libc/*/*.c)
|
LIBC_SOURCES = $(wildcard libc/*.c libc/*/*.c)
|
||||||
|
@ -294,7 +294,7 @@ void irq_handler(registers_t* r) {
|
|||||||
port_byte_out(0x20,0x20); /* master */
|
port_byte_out(0x20,0x20); /* master */
|
||||||
/* Handle the interrupt in a more modular way */
|
/* Handle the interrupt in a more modular way */
|
||||||
if (irq_handlers[r->int_no-32] != NULL) {
|
if (irq_handlers[r->int_no-32] != NULL) {
|
||||||
isr_t handler = irq_handlers[r->int_no];
|
isr_t handler = irq_handlers[r->int_no-32];
|
||||||
handler(r);
|
handler(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <tasking.h>
|
#include <tasking.h>
|
||||||
|
#include "timer/timer.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* REspresents a TAR file header
|
* REspresents a TAR file header
|
||||||
@ -66,6 +67,7 @@ void kmain(struct multiboot_boot_header_tag* hdr) {
|
|||||||
asm volatile("sti");
|
asm volatile("sti");
|
||||||
tasking_init();
|
tasking_init();
|
||||||
vga_init((char*)0xC00B8000);
|
vga_init((char*)0xC00B8000);
|
||||||
|
timer_init(1000);
|
||||||
read_initrd(tags);
|
read_initrd(tags);
|
||||||
int pos=0;
|
int pos=0;
|
||||||
size_t datapos;
|
size_t datapos;
|
||||||
@ -115,13 +117,14 @@ void kmain(struct multiboot_boot_header_tag* hdr) {
|
|||||||
copy_data(address_space,ptr,pheader.memsz,(void*)pheader.vaddr);
|
copy_data(address_space,ptr,pheader.memsz,(void*)pheader.vaddr);
|
||||||
}
|
}
|
||||||
create_proc((void*)header.entry,address_space,NULL,NULL);
|
create_proc((void*)header.entry,address_space,NULL,NULL);
|
||||||
for (int i=0;i<4;i++) {
|
// for (int i=0;i<4;i++) {
|
||||||
yield();
|
// yield();
|
||||||
}
|
// }
|
||||||
unblock_thread(1,0);
|
// unblock_thread(1,0);
|
||||||
for (int i=0;i<4;i++) {
|
// for (int i=0;i<4;i++) {
|
||||||
yield();
|
// yield();
|
||||||
}
|
// }
|
||||||
|
// for (;;);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
kernel/timer/pit/timer.c
Normal file
26
kernel/timer/pit/timer.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include "../../cpu/isr.h"
|
||||||
|
#include "../../tasking.h"
|
||||||
|
#include "../../cpu/serial.h"
|
||||||
|
#include <cpu/ports.h>
|
||||||
|
|
||||||
|
void timer_handler(registers_t* r);
|
||||||
|
|
||||||
|
void timer_init(int freq) {
|
||||||
|
int div=1193180/freq;
|
||||||
|
if (div>65535) {
|
||||||
|
serial_printf("Frequency of %dHz too slow, min freq is 18 Hz\n");
|
||||||
|
div=65535;
|
||||||
|
freq=18;
|
||||||
|
if (div==0) {
|
||||||
|
serial_printf("Frequency of %dHz too slow, max freq is 1193180 Hz\n");
|
||||||
|
div=1;
|
||||||
|
freq=1193180;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
serial_printf("Setting PIT to %dHz using divisor of %d\n",freq,div);
|
||||||
|
}
|
||||||
|
isr_register_handler(0,timer_handler);
|
||||||
|
port_byte_out(0x43,(div>>8)&0xFF);
|
||||||
|
port_byte_out(0x40,div&0xFF);
|
||||||
|
port_byte_out(0x40,0x2E);
|
||||||
|
}
|
14
kernel/timer/timer.h
Normal file
14
kernel/timer/timer.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TIMER_H
|
||||||
|
#define TIMER_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the timer
|
||||||
|
* \param freq The freqency to set the timer to
|
||||||
|
*/
|
||||||
|
void timer_init(int freq);
|
||||||
|
|
||||||
|
#endif
|
14
kernel/timer_handler.c
Normal file
14
kernel/timer_handler.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tasking.h"
|
||||||
|
#include "cpu/isr.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interrupt handler for the timer interrupt
|
||||||
|
* \param r The saved state of the CPU when the interrupt occured
|
||||||
|
*/
|
||||||
|
void timer_handler(registers_t* r) {
|
||||||
|
tasking_yield();
|
||||||
|
}
|
1
psinfo/i386/timer_type.txt
Normal file
1
psinfo/i386/timer_type.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
pit
|
Loading…
Reference in New Issue
Block a user