summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/gdt.c (renamed from kernel/GDT.c)2
-rw-r--r--kernel/gdt.h1
-rw-r--r--kernel/interrupts.c4
-rw-r--r--kernel/interrupts.h5
-rw-r--r--kernel/kernel.c25
-rw-r--r--kernel/scheduler.c (renamed from kernel/task.c)3
-rw-r--r--kernel/scheduler.h1
-rw-r--r--kernel/task.h1
-rw-r--r--kernel/timer.c167
-rw-r--r--kernel/timer.h50
-rw-r--r--kernel/vmem.h1
11 files changed, 22 insertions, 238 deletions
diff --git a/kernel/GDT.c b/kernel/gdt.c
index 4bc7ca2..06a0949 100644
--- a/kernel/GDT.c
+++ b/kernel/gdt.c
@@ -89,7 +89,7 @@ void encodeGdtEntry(uint8_t *target, GDT source)
}
-void gdt_setup()
+void gdt_init()
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"setting up Global Descriptor Table");
//selector 0x0
diff --git a/kernel/gdt.h b/kernel/gdt.h
new file mode 100644
index 0000000..4081a75
--- /dev/null
+++ b/kernel/gdt.h
@@ -0,0 +1 @@
+void gdt_init();
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index 9b08475..0dccba4 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -8,6 +8,8 @@
#include "interrupts.h"
#include "asm/x86.h"
+#define INT_MAX 255 // size of our interrupts table
+
void errlog(uint32_t error_code)
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"error_code: 0x%08X",error_code);
@@ -116,7 +118,7 @@ void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr)
}
// set default handler for all interrupts for a start
-void int_init(uint16_t sel)
+void interrupts_init(uint16_t sel)
{
// Setup PIC
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"setting up PIC",&idt,&idtd);
diff --git a/kernel/interrupts.h b/kernel/interrupts.h
index bd110d4..637fcfd 100644
--- a/kernel/interrupts.h
+++ b/kernel/interrupts.h
@@ -3,8 +3,5 @@
#include <stdint.h>
-#define INT_MAX 255 // size of our interrupts table
-
-void int_install();
-void int_init(uint16_t sel);
+void interrupts_init(uint16_t sel);
#endif
diff --git a/kernel/kernel.c b/kernel/kernel.c
index e1076a9..67f1355 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -2,20 +2,25 @@
#include "kernel.h"
#include <stdint.h>
-#include <stddef.h>
+
+#include "driver/serial.h"
+#include "driver/timer.h"
+#include "driver/keyboard.h"
+#include "driver/mouse.h"
+
+#include "kernel/gdt.h"
+#include "kernel/scheduler.h"
#include "syscalls.h"
#include "types.h"
#include "lib/logger/log.h"
#include "fifo.h"
-#include "timer.h"
#include "mem.h"
#include "vmem.h"
#include "mp.h"
#include "interrupts.h"
#include "multiboot.h"
#include "ringbuffer.h"
-#include "task.h"
#include "multiboot.h"
#include "terminal/terminal.h"
#include "driver/screen.h"
@@ -33,15 +38,14 @@ void kernel_main(uint32_t eax,uint32_t ebx)
uint64_t epoch_time=timer_init();
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"PIT - initialized. %u seconds passed since 1970.",epoch_time);
- // KEYBOARD DRIVER
keyboard_init(0); //sstdin
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Keyboard Initialized");
- // MOUSE DRIVER
mouse_init();
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Mouse Initialized");
- // GDT
- gdt_setup();
+ gdt_init();
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"GDT Initialized");
// MULTIBOOT HEADER
multiboot_information *info=get_multiboot(eax, ebx);
@@ -74,6 +78,7 @@ void kernel_main(uint32_t eax,uint32_t ebx)
// INIT VESA: TODO: stop and say if not 32bit colormode!
uint32_t addr=kballoc(1);
fs_content("/binfont.bin",addr,0x100); // copy 0x100 bytes to 0x7000
+
vesa_init(info->vbe_control_info,info->vbe_mode_info,addr);
// STREAMS
@@ -81,10 +86,8 @@ void kernel_main(uint32_t eax,uint32_t ebx)
uint32_t sstdout = syscall_open("term",0,0); // stdout 1
uint32_t sstderr = syscall_open("stderr",0,0); // stderr 2
- // INSTALL INTERRUPTS (code segment: 0x08)
- int_init(0x08);
+ interrupts_init(0x08);
- // INIT MULTITASKING (and start scheduler)
- task_init(dir);
+ scheduler_init(dir);
}
diff --git a/kernel/task.c b/kernel/scheduler.c
index 395c196..4823276 100644
--- a/kernel/task.c
+++ b/kernel/scheduler.c
@@ -6,7 +6,6 @@
#include "kernel.h"
#include "lib/logger/log.h" // logger facilities
#include "mem.h"
-#include "timer.h"
#include "asm/x86.h"
#include "vmem.h"
@@ -158,7 +157,7 @@ volatile uint32_t task_fork(uint32_t oldesp)
}
// init task (root of all other tasks / processes) //
-volatile void task_init(pdirectory *dir)
+volatile void scheduler_init(pdirectory *dir)
{
current_task=0;
diff --git a/kernel/scheduler.h b/kernel/scheduler.h
new file mode 100644
index 0000000..db0e3ae
--- /dev/null
+++ b/kernel/scheduler.h
@@ -0,0 +1 @@
+void scheduler_init(void *pdirectory_dir);
diff --git a/kernel/task.h b/kernel/task.h
deleted file mode 100644
index c934d6d..0000000
--- a/kernel/task.h
+++ /dev/null
@@ -1 +0,0 @@
-void task_init(pdirectory *dir);
diff --git a/kernel/timer.c b/kernel/timer.c
deleted file mode 100644
index 2d4c7ff..0000000
--- a/kernel/timer.c
+++ /dev/null
@@ -1,167 +0,0 @@
-#define FOOLOS_MODULE_NAME "timer"
-#include "timer.h"
-
-#include "asm/x86.h"
-
-static volatile uint64_t task_system_clock_start=0;
-
-// CMOS RTC
-
-// read real time clock register
-static unsigned char get_rtc_reg(int reg) {
- x86_outb(0x70, reg); //cmos at addr 0x70
- return x86_inb(0x71); //cmos data at addr 0x71
-}
-
-// check if cmos rtc update in progress
-static int get_rtc_update_flag() {
- x86_outb(0x70, 0x0A);
- return (x86_inb(0x71) & 0x80);
-}
-
-// get real time clock rom cmos (seconds since jan)
-static uint64_t get_rtc_time()
-{
- int CURRENT_YEAR = 2018; // Change this each year!
-
- int century_register = 0x00; // Set by ACPI table parsing code if possible
-
- unsigned char second;
- unsigned char minute;
- unsigned char hour;
- unsigned char day;
- unsigned char month;
- unsigned int year;
-
- unsigned char century;
- unsigned char last_second;
- unsigned char last_minute;
- unsigned char last_hour;
- unsigned char last_day;
- unsigned char last_month;
- unsigned char last_year;
- unsigned char last_century;
- unsigned char registerB;
-
- // Note: This uses the "read registers until you get the same values twice in a row" technique
- // to avoid getting dodgy/inconsistent values due to RTC updates
-
- while (get_rtc_update_flag()); // Make sure an update isn't in progress
- second = get_rtc_reg(0x00);
- minute = get_rtc_reg(0x02);
- hour = get_rtc_reg(0x04);
- day = get_rtc_reg(0x07);
- month = get_rtc_reg(0x08);
- year = get_rtc_reg(0x09);
-
- if(century_register != 0) {
- century = get_rtc_reg(century_register);
- }
-
- do {
- last_second = second;
- last_minute = minute;
- last_hour = hour;
- last_day = day;
- last_month = month;
- last_year = year;
- last_century = century;
-
- while (get_rtc_update_flag()); // Make sure an update isn't in progress
- second = get_rtc_reg(0x00);
- minute = get_rtc_reg(0x02);
- hour = get_rtc_reg(0x04);
- day = get_rtc_reg(0x07);
- month = get_rtc_reg(0x08);
- year = get_rtc_reg(0x09);
- if(century_register != 0) {
- century = get_rtc_reg(century_register);
- }
- } while( (last_second != second) || (last_minute != minute) || (last_hour != hour) ||
- (last_day != day) || (last_month != month) || (last_year != year) ||
- (last_century != century) );
-
- registerB = get_rtc_reg(0x0B);
-
- // Convert BCD to binary values if necessary
- if (!(registerB & 0x04)) {
- second = (second & 0x0F) + ((second / 16) * 10);
- minute = (minute & 0x0F) + ((minute / 16) * 10);
- hour = ( (hour & 0x0F) + (((hour & 0x70) / 16) * 10) ) | (hour & 0x80);
- day = (day & 0x0F) + ((day / 16) * 10);
- month = (month & 0x0F) + ((month / 16) * 10);
- year = (year & 0x0F) + ((year / 16) * 10);
- if(century_register != 0) {
- century = (century & 0x0F) + ((century / 16) * 10);
- }
- }
-
- // Convert 12 hour clock to 24 hour clock if necessary
- if (!(registerB & 0x02) && (hour & 0x80)) {
- hour = ((hour & 0x7F) + 12) % 24;
- }
-
- // Calculate the full (4-digit) year
- if(century_register != 0) {
- year += century * 100;
- } else {
- year += (CURRENT_YEAR / 100) * 100;
- if(year < CURRENT_YEAR) year += 100;
- }
-
- // thank you doug16k @ #osdev
- // https://github.com/doug65536/dgos/blob/eab7080e69360493381669e7ce0ff27587d3127a/kernel/lib/time.cc
- int days[] = {
- 31,
- (year-1900) % 4 ? 28 :
- (year-1900) % 100 ? 29 :
- (year-1900) % 400 ? 28 :
- 29,
- 31,
- 30,
- 31,
- 30,
- 31,
- 31,
- 30,
- 31,
- 30,
- 31
- };
-
- int yday = 0;
- for (int m = 1; m < month; ++m)
- yday += days[m-1];
- yday += day - 1;
-
- uint64_t epoch_seconds= ((uint64_t)(second)) +
- minute * 60 +
- hour * 3600 +
- (yday) * 86400 +
- (year-1900 - 70) * 365 * 86400 +
- ((year-1900 - 69) / 4) * 86400 -
- ((year-1900 - 1) / 100) * 86400 +
- ((year-1900 + 299) / 400) * 86400;
-
- return epoch_seconds;
-}
-
-
-// PIT
-uint64_t timer_init()
-{
- uint64_t epoch_time=get_rtc_time();
- task_system_clock_start=epoch_time*25; // since pit ticks 25times a second
- pit_init();
- return epoch_time;
-}
-
-uint64_t timer_get_ms()
-{
- return (pit_get_ticks()+task_system_clock_start)*40;
-}
-
-uint64_t timer_get_uptime_ms()
-{
- return pit_get_ticks()*40;
-}
diff --git a/kernel/timer.h b/kernel/timer.h
deleted file mode 100644
index 1e3d066..0000000
--- a/kernel/timer.h
+++ /dev/null
@@ -1,50 +0,0 @@
-
-/**
- * @file
- * References
- * ----------
- * * http://www.brokenthorn.com/Resources/OSDevPit.html
- * * https://wiki.osdev.org/CMOS
-
-
- vcc/gnd - voltage/ground
-
- D0-D7 - data lines (data bus)
- wr/rd - writing / reading (system control bus)
- cs - ignore wr/rd or not (address bus)
- a0-a1 (address bus)
-
- // the three 16bit down counters/timers/channels
- clk 0-2 (in)
- gate 0-2 (in)
- out 0-2 (out)
-
- //typical
- out1 -> pic interrupt on every tick (system timer)
- out2 - was used for genearting dram memory refresh (Do not use)
- out3 -> pc speaker
-
- gate pins : depend on mode of operation
- we do have modes 0-5.
- mode0: counts down to zero , triggers interrupt and waits
- mode1:
- mode2: rate generator (sys timer)
- ....
- */
-
-#include <stdint.h>
-
-/**
- * Initilize time and PIT (trigger 25 times a second).
- * Returns the number of seconds passed since 1970.
- */
-uint64_t timer_init();
-
-/** get number of ticks since boot */
-uint64_t timer_get_ticks();
-
-/** get number of milliseconds since boot */
-uint64_t timer_get_uptime_ms();
-
-/** get number of milliseconds since 1970 */
-uint64_t timer_get_ms();
diff --git a/kernel/vmem.h b/kernel/vmem.h
index 104e5ab..ae1e134 100644
--- a/kernel/vmem.h
+++ b/kernel/vmem.h
@@ -30,7 +30,6 @@ typedef struct ptable_struct {
//! page directory
typedef struct pdirectory_struct {
-
pd_entry m_entries[PAGES_PER_DIR];
}pdirectory;