summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-08-20 00:47:53 +0200
committerMiguel <m.i@gmx.at>2018-08-20 00:47:53 +0200
commit39100c30b7a16103e75187c9840a79c7df54f3da (patch)
treeea54cd41375e3cc38a291dfff47abffbdb468a7e
parentdc5b5d1e5cf82b06fe97ffc8c9374c055e12a748 (diff)
schicophrenic cleanup after realizing many fundamental desgin problems!
-rw-r--r--asm/int_clock_handler.asm2
-rw-r--r--asm/int_default_handler.asm6
-rw-r--r--asm/int_kb_handler.asm13
-rw-r--r--asm/int_mouse_handler.asm8
-rw-r--r--fs/ext2.h1
-rw-r--r--fs/foolfs.h0
-rw-r--r--fs/fs.c2
-rw-r--r--fs/fs.h2
-rw-r--r--fs/mount.c2
-rw-r--r--fs/mount.h8
-rw-r--r--kernel/interrupts.c2
-rw-r--r--kernel/kernel.c21
-rw-r--r--kernel/ringbuffer.c16
-rw-r--r--kernel/syscalls.c8
-rw-r--r--kernel/timer.c95
-rw-r--r--kernel/timer.h46
-rw-r--r--xxx/copy_page_physical.asm (renamed from asm/copy_page_physical.asm)4
17 files changed, 116 insertions, 120 deletions
diff --git a/asm/int_clock_handler.asm b/asm/int_clock_handler.asm
index 7b0afaf..f6c056a 100644
--- a/asm/int_clock_handler.asm
+++ b/asm/int_clock_handler.asm
@@ -5,7 +5,6 @@ global int_clock_handler
int_clock_handler:
-cli
pusha ;Push all standard registers
mov eax, esp ;save current stack pointer in esp
@@ -20,6 +19,5 @@ mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
popa ;Put the standard registers back
-sti
iretd ;Interrupt-Return
diff --git a/asm/int_default_handler.asm b/asm/int_default_handler.asm
index b86eeae..00aa1ac 100644
--- a/asm/int_default_handler.asm
+++ b/asm/int_default_handler.asm
@@ -1,12 +1,9 @@
global int_default_handler
[extern int_default]
-
[bits 32]
int_default_handler:
-
- cli
pusha
call int_default
@@ -15,7 +12,4 @@ int_default_handler:
out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
popa
- sti
-
-
iret ;Interrupt-Return
diff --git a/asm/int_kb_handler.asm b/asm/int_kb_handler.asm
index acf6208..cd1b32c 100644
--- a/asm/int_kb_handler.asm
+++ b/asm/int_kb_handler.asm
@@ -6,9 +6,7 @@ global int_kb_handler
int_kb_handler:
-cli
-
-pusha
+ pusha
mov eax,0x0
in al,0x60
@@ -17,13 +15,10 @@ pusha
call keyboard_handle
pop eax
-; call int_default
-
- mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
- out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
-popa
+ mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
+ out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
-sti
+ popa
iretd ;Interrupt-Return
diff --git a/asm/int_mouse_handler.asm b/asm/int_mouse_handler.asm
index 4e4882b..6872af0 100644
--- a/asm/int_mouse_handler.asm
+++ b/asm/int_mouse_handler.asm
@@ -2,18 +2,14 @@ global int_mouse_handler
[extern mouse_handler]
[bits 32]
-int_mouse_handler:
-
- cli
- pusha
+int_mouse_handler:
+ pusha
call mouse_handler
mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
out 0xa0, al ; came from slave
out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
-
popa
- sti
iret ;Interrupt-Return
diff --git a/fs/ext2.h b/fs/ext2.h
index 07f4153..066a769 100644
--- a/fs/ext2.h
+++ b/fs/ext2.h
@@ -1,5 +1,6 @@
#include <stdint.h>
#include "fs.h"
+
int ext2_check(uint8_t *ram);
int ext2_inode_content(char *ram,int inode_nr,uint8_t *ramdest,int max);
int ext2_read_dir(uint8_t *ram, int inode_nr,fs_dirent *dirs,int max);
diff --git a/fs/foolfs.h b/fs/foolfs.h
deleted file mode 100644
index e69de29..0000000
--- a/fs/foolfs.h
+++ /dev/null
diff --git a/fs/fs.c b/fs/fs.c
index 0810735..74ed010 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -29,11 +29,9 @@ void fs_mount(multiboot_information *info)
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"mounting mod from 0x%08X-0x%08X : %s",
mod->mod_start,mod->mod_end, mod->string);
-
//pmmngr_deinit_region(mod->mod_start,((uint32_t)mod->mod_end-(uint32_t)mod->mod_start)+1);
root_ext2_ramimage=mod->mod_start;
-
mod++;
}
diff --git a/fs/fs.h b/fs/fs.h
index b90b4f1..aa38180 100644
--- a/fs/fs.h
+++ b/fs/fs.h
@@ -19,7 +19,7 @@ typedef struct fs_dirent_struct
char name[256];
}fs_dirent;
-int fs_readdir(const char *name,fs_dirent *dirs,int max);
+int fs_readdir(const char *name,fs_dirent *dirs,int max);
void fs_mount(multiboot_information *info); // mounts ext2 ramimage from module as root
#endif
diff --git a/fs/mount.c b/fs/mount.c
index 616262d..cb741f9 100644
--- a/fs/mount.c
+++ b/fs/mount.c
@@ -1,7 +1,7 @@
#include "mount.h"
void mount_add(char *path, void *data,
- file (*open)(struct mount_struct*,char *path),
+ file (*open) (struct mount_struct*,char *path),
int (*getdents)(struct mount_struct*, uint32_t file_desciptor, fs_dirent *entries, uint32_t max_count))
{
}
diff --git a/fs/mount.h b/fs/mount.h
index 372e051..0a330a6 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -9,9 +9,9 @@
typedef struct mount_struct
{
- char path[256]; // where are we mounted
- int (*getdents)(struct mount_struct*, uint32_t file_desciptor, fs_dirent *entries, uint32_t max_count);
- file (*open)(struct mount_struct*,char *path);
+ char path[256]; // where are we mounted
+ int (*getdents) (struct mount_struct*, uint32_t file_desciptor, fs_dirent *entries, uint32_t max_count);
+ file (*open) (struct mount_struct*,char *path);
void *data //opaque
}mount;
@@ -19,7 +19,5 @@ typedef struct mount_struct
mount *mounts_get();
void mount_add(char *path, void *data,file (*open)(struct mount_struct*,char *path),int (*getdents)(struct mount_struct*, uint32_t file_desciptor, fs_dirent *entries, uint32_t max_count));
-
-
//
#endif
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index 41d0a9c..46883d6 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -167,7 +167,7 @@ void int_init(uint16_t sel)
// now we can enable interrupts back again
// x86_sti();
- x86_cli();
+ //x86_cli();
}
void int_install()
diff --git a/kernel/kernel.c b/kernel/kernel.c
index ba6bc5d..62556cb 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -24,13 +24,14 @@
void kernel_main(uint32_t eax,uint32_t ebx)
{
serial_init();
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"COM 1 - initialized");
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%s - BUILD: git-%s (%s %s)",
KERNEL_NAME,GIT_REVISION,__DATE__,__TIME__);
- // PIT TIMER
- timer_init();
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"COM 1 - initialized");
+
+ uint64_t epoch_time=timer_init();
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"PIT - initialized. %u seconds passed since 1970.",epoch_time);
// STREAMS
uint32_t sstdin = syscall_open("stdin",0,0); // stdin 0
@@ -53,11 +54,11 @@ void kernel_main(uint32_t eax,uint32_t ebx)
multiboot_information *info=get_multiboot(eax, ebx);
// Gather Info about other processors. (APs = application processors) // ACPI or MP
- smp_processors procdata;
-
- if(!acpi_find(&procdata))
- if(!mp_find(&procdata))
- panic(FOOLOS_MODULE_NAME,"ACPI and MP search failed! I do not want to continue!");
+ //smp_processors procdata;
+ //
+ //if(!acpi_find(&procdata))
+ // if(!mp_find(&procdata))
+ // panic(FOOLOS_MODULE_NAME,"ACPI and MP search failed! I do not want to continue!");
// MEMORY INIT (allows allocating and deaclloating physical memory)
uint32_t kernel_blocks=mem_init(info);
@@ -75,9 +76,9 @@ void kernel_main(uint32_t eax,uint32_t ebx)
pdirectory *dir=vmem_init(kernel_blocks,(uint32_t)info->framebuffer_addr);
// PCI Bus
- pci_init();
+ //pci_init();
- // INIT VESA
+ // 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);
diff --git a/kernel/ringbuffer.c b/kernel/ringbuffer.c
index 099e96a..6085aaf 100644
--- a/kernel/ringbuffer.c
+++ b/kernel/ringbuffer.c
@@ -20,11 +20,11 @@ ringbuffer ringbuffer_init(uint32_t size)
bool ringbuffer_put(ringbuffer* f,uint8_t c)
{
- x86_cli();
+// x86_cli();
if((f->back-1+f->size)%f->size==f->front)
{
- x86_sti();
+// x86_sti();
return false;
}
@@ -33,30 +33,30 @@ bool ringbuffer_put(ringbuffer* f,uint8_t c)
f->back+=f->size;
f->back%=f->size;
- x86_sti();
+// x86_sti();
return true;
}
bool ringbuffer_has(ringbuffer* f)
{
- x86_cli();
+// x86_cli();
bool res=true;
if(f->front==f->back)
res=false;
- x86_sti();
+// x86_sti();
return res;
}
uint8_t ringbuffer_get(ringbuffer* f) // non blocking . please check first
{
- x86_cli();
+// x86_cli();
char c;
if(f->front==f->back)
{
- x86_sti();
+// x86_sti();
return ' ';
}
@@ -66,6 +66,6 @@ uint8_t ringbuffer_get(ringbuffer* f) // non blocking . please check first
f->front+=f->size;
f->front%=f->size;
- x86_sti();
+ // x86_sti();
return c;
}
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 3f2a811..0c334bc 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -149,15 +149,15 @@ int syscall_tune(int v1,int v2, int v3)
int copy_args(char **in, char **out)
{
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"copy_args(0x%08x, 0x%08X)",in,out);
+ //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"copy_args(0x%08x, 0x%08X)",in,out);
int count=0;
while(in[count]!=NULL)
{
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"args(0x%08x: %s)",in[count],out);
+// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"args(0x%08x: %s)",in[count],out);
count++;
};
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"copy_args : count: %d",count);
+ // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"copy_args : count: %d",count);
char **pos=out;
pos+=sizeof(char **)*(count+1);
@@ -218,7 +218,7 @@ int syscall_execve(char *name, char **argv, char **env)
/* try to move this to asm */
// asm volatile("jmp ."); // loop forever
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"returning to jump addy (0x%08X)", entry_global);
+ //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"returning to jump addy (0x%08X)", entry_global);
asm volatile("mov $0x8fff000,%esp"); // set stack at high end of process image
diff --git a/kernel/timer.c b/kernel/timer.c
index e5e26b4..2bf1592 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -1,58 +1,29 @@
-/// PIT /// Timer stuff // CMOS
-
-/*
- 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)
- ....
- */
-
#define FOOLOS_MODULE_NAME "timer"
-
#include "timer.h"
+
#include "asm/x86.h"
-#include "lib/logger/log.h"
-// TODO: use mutex? do we need volatile at all!??
-// abstract atomic variable set,get,increment
+//TODO: volatile? spinlock?
static volatile uint64_t task_system_clock=0;
static volatile uint64_t task_system_clock_start=0;
+static volatile uint8_t interrupts_on = 0;
-//called by interrupt
+// interrupt handler (do NOT call yourself!)
void timer_tick()
{
task_system_clock++;
+ interrupts_on=1;
}
// get value
uint64_t timer_get_ticks()
{
- return task_system_clock;
+ uint64_t ret;
+// x86_cli(); // do not disturb by timer_tick!
+ ret=task_system_clock;
+ // if(interrupts_on!=0)x86_sti(); // reenable (if clock was running already)
+ return ret;
}
-///
-
uint64_t timer_get_ms()
{
@@ -68,24 +39,22 @@ uint64_t timer_get_uptime_ms()
}
// CMOS RTC
-
// read real time clock register
-unsigned char get_rtc_reg(int reg) {
+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
-int get_rtc_update_flag() {
+static int get_rtc_update_flag() {
x86_outb(0x70, 0x0A);
return (x86_inb(0x71) & 0x80);
}
// get real time clock rom cmos (seconds since jan)
-uint64_t get_rtc_time()
+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
@@ -209,26 +178,13 @@ uint64_t get_rtc_time()
((year-1900 - 1) / 100) * 86400 +
((year-1900 + 299) / 400) * 86400;
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"CMOS Hardware Clock: %u-%u-%u %u:%u:%u",day,month,year,hour,minute,second);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"CMOS Hardware Clock: %u seconds since Epoch",epoch_seconds);
-
return epoch_seconds;
}
-// PIT
-// TODO: move to asm file
-void timer_init()
-{
- uint64_t epoch_time=get_rtc_time();
-
- task_system_clock_start=epoch_time;
- task_system_clock=epoch_time*25;
- // config out timer on channel 0 : mode 2 (sys timer)
- // http://en.wikipedia.org/wiki/Intel_8253#Control_Word_Register
- // http://www.brokenthorn.com/Resources/OSDevPit.html
- // int0 will be triggered ~25 times a second.
-
+// TODO: put in asm file!
+static void timer_config()
+{
__asm__("pusha");
__asm__("mov %0, %%dx"::"X" (1193180 / 25));
@@ -244,6 +200,23 @@ void timer_init()
__asm__("popa");
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Configured PIT Channel 0 : Mode 2 : 1/25 s.");
}
+// PIT
+uint64_t timer_init()
+{
+ uint64_t epoch_time=get_rtc_time();
+
+ task_system_clock_start=epoch_time;
+ task_system_clock=epoch_time*25;
+
+ timer_config();
+
+ // config out timer on channel 0 : mode 2 (sys timer)
+ // http://en.wikipedia.org/wiki/Intel_8253#Control_Word_Register
+ // http://www.brokenthorn.com/Resources/OSDevPit.html
+ // int0 will be triggered ~25 times a second.
+
+ //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Configured PIT Channel 0 : Mode 2 : 1/25 s.");
+ return epoch_time;
+}
diff --git a/kernel/timer.h b/kernel/timer.h
index a39d433..15488ff 100644
--- a/kernel/timer.h
+++ b/kernel/timer.h
@@ -1,6 +1,48 @@
+
+/**
+ * @file
+/// PIT /// Timer stuff // CMOS
+ 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>
-void timer_init();
-void timer_tick();
+/**
+ * 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/asm/copy_page_physical.asm b/xxx/copy_page_physical.asm
index f8d3af1..8e26050 100644
--- a/asm/copy_page_physical.asm
+++ b/xxx/copy_page_physical.asm
@@ -1,7 +1,7 @@
[bits 32]
-global copy_page_physical
-copy_page_physical:
+global copy_page_physical_XXX
+copy_page_physical_XXX:
push ebx ; According to __cdecl, we must preserve the contents of EBX.
pushf ; push EFLAGS, so we can pop it and reenable interrupts
; later, if they were enabled anyway.