summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-08-18 16:20:26 +0200
committerMiguel <m.i@gmx.at>2018-08-18 16:20:26 +0200
commit639c3d47b09114628f8e1f8817c27c10bf1fb28c (patch)
treef0381de25cc8f2de96a87b47cc76f7d09548bf7e
parent7b0d88b2dff9b635d9ff69f6d51b6832c1ca4c40 (diff)
reviving old drivers: mouse, pci, e1000
-rw-r--r--Makefile4
-rw-r--r--driver/e1000.c (renamed from xxx/inactive/e1000.c)0
-rw-r--r--driver/e1000.h (renamed from xxx/inactive/e1000.h)0
-rw-r--r--driver/keyboard.c2
-rw-r--r--driver/mouse.c (renamed from xxx/inactive/mouse.c)25
-rw-r--r--driver/pci.c (renamed from xxx/inactive/pci.c)9
-rw-r--r--driver/serial.c37
-rw-r--r--driver/serial.h11
-rw-r--r--kernel/kernel.c76
-rw-r--r--kernel/kernel.h3
-rw-r--r--kernel/mem.c1
-rw-r--r--kernel/timer.c16
-rw-r--r--kernel/timer.h1
-rw-r--r--lib/logger/log.c20
-rw-r--r--userspace/cat.c9
-rw-r--r--userspace/crt0.S4
-rw-r--r--userspace/err.c6
-rw-r--r--xxx/inactive/floppy.c1
-rw-r--r--xxx/video/vesa.c6
19 files changed, 126 insertions, 105 deletions
diff --git a/Makefile b/Makefile
index 4878633..ce3dd82 100644
--- a/Makefile
+++ b/Makefile
@@ -143,13 +143,13 @@ $(KERNEL_IMG): $(ASM_MULTIBOOT_OBJ) $(ASM_OBJECTS) $(OBJECTS)
run-qemu: all
#qemu-system-i386 -enable-kvm disk.img -smp 4 -s
#qemu-system-i386 -enable-kvm -s -kernel foolos.img -smp 4 -initrd userspace/ext2.img
- qemu-system-i386 -enable-kvm $(FOOLOS_ISO) -smp 4
+ qemu-system-i386 -enable-kvm $(FOOLOS_ISO) -smp 4 -serial stdio
run-qemu-debug: all
# qemu -enable-kvm -s -S ~/temp/FoolOs/disk.img
# qemu -enable-kvm -s -singlestep disk.img
# qemu-system-i386 -enable-kvm -s -S -kernel foolos.img -smp 4 -initrd userspace/ext2.img
- qemu-system-i386 -s -S $(FOOLOS_ISO) -smp 4 #-enable-kvm -smp 1
+ qemu-system-i386 -s -S $(FOOLOS_ISO) -smp 4 -serial stdio #-enable-kvm -smp 1
stop-qemu:
killall qemu-system-i386
diff --git a/xxx/inactive/e1000.c b/driver/e1000.c
index 99194be..99194be 100644
--- a/xxx/inactive/e1000.c
+++ b/driver/e1000.c
diff --git a/xxx/inactive/e1000.h b/driver/e1000.h
index 5413fe1..5413fe1 100644
--- a/xxx/inactive/e1000.h
+++ b/driver/e1000.h
diff --git a/driver/keyboard.c b/driver/keyboard.c
index 8d7c8aa..55e3c41 100644
--- a/driver/keyboard.c
+++ b/driver/keyboard.c
@@ -4,6 +4,7 @@
#define FOOLOS_MODULE_NAME "keyboard"
#include <stdbool.h>
#include "kernel/x86.h"
+#include "lib/logger/log.h"
static bool ctrl_l=false;
static bool shift_l=false;
@@ -20,6 +21,7 @@ static void put(uint8_t c)
void keyboard_init(uint32_t s)
{
kb_stream=s;
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Keyboard Initialized");
}
void keyboard_handle(uint8_t in)
diff --git a/xxx/inactive/mouse.c b/driver/mouse.c
index 910f0cf..d676f45 100644
--- a/xxx/inactive/mouse.c
+++ b/driver/mouse.c
@@ -1,14 +1,13 @@
+#define FOOLOS_MODULE_NAME "mouse"
+
//http://forum.osdev.org/viewtopic.php?t=10247
//based on Mouse.inc by SANiK
//License: Use as you wish, except to cause damage
-#define FOOLOS_MODULE_NAME "mouse"
-
#include "lib/logger/log.h"
-#include "lib/int/stdint.h"
-
-#include "x86.h"
+#include <stdint.h>
+#include "kernel/x86.h"
static volatile uint8_t mouse_cycle;
static volatile uint8_t mouse_byte[3];
@@ -16,7 +15,6 @@ volatile int16_t mouse_x;
volatile int16_t mouse_y;
static volatile uint8_t mouse_a;
-
uint8_t mouse_read();
void mouse_wait(uint8_t a_type) //unsigned char
@@ -97,7 +95,6 @@ void mouse_init()
mouse_read(); //Acknowledge
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Mouse Initialized");
-
}
void mouse_log()
@@ -106,7 +103,6 @@ void mouse_log()
if(mouse_byte[0]&0x80||mouse_byte[0]&0x40)return; //skip packet on overflow
if(!(mouse_byte[0]&0x8))panic(FOOLOS_MODULE_NAME,"mouse packets out of sync!?"); // this bit is always 1, otherwise panic!
-
//
if(mouse_byte[1]>127){
@@ -125,24 +121,21 @@ void mouse_log()
{
mouse_y+=mouse_byte[2];
}
-
-
-
if(mouse_x<0)mouse_x=0;
if(mouse_y<0)mouse_y=0;
if(mouse_x>800)mouse_x=800;
if(mouse_y>600)mouse_y=600;
-
- //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d / %d / %02x ",mouse_x, mouse_y,mouse_byte[2]);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d / %d / %02x ",mouse_x, mouse_y,mouse_byte[2]);
//PutFont('X', mouse_x,600-mouse_y, 0xffffff);
}
+
//Mouse functions
void mouse_handler()//struct regs *a_r) //struct regs *a_r (not used but just there)
{
- X86_IRQ_BEGIN
+// X86_IRQ_BEGIN
switch(mouse_cycle)
{
@@ -159,11 +152,9 @@ void mouse_handler()//struct regs *a_r) //struct regs *a_r (not used but just th
mouse_cycle=0;
mouse_log();
break;
-
}
-
- X86_IRQ_END
+// X86_IRQ_END
}
uint8_t mouse_read()
diff --git a/xxx/inactive/pci.c b/driver/pci.c
index e5d9711..677f445 100644
--- a/xxx/inactive/pci.c
+++ b/driver/pci.c
@@ -1,9 +1,10 @@
-#include "kernel.h"
-#include "x86.h"
-#include "e1000.h"
-#include "../lib/logger/log.h" // logger facilities
#define FOOLOS_MODULE_NAME "pci"
+#include "kernel/kernel.h"
+#include "kernel/x86.h"
+#include "e1000.h"
+#include "lib/logger/log.h" // logger facilities
+
#define PCI_CONFIG_DATA 0xCFC
#define PCI_CONFIG_ADDRESS 0xCF8
diff --git a/driver/serial.c b/driver/serial.c
new file mode 100644
index 0000000..f402d0c
--- /dev/null
+++ b/driver/serial.c
@@ -0,0 +1,37 @@
+#define FOOLOS_MODULE_NAME "serial"
+// https://wiki.osdev.org/Serial_Ports
+
+#define PORT 0x3f8 /* COM1 */
+
+#include "lib/logger/log.h"
+
+void serial_init() {
+
+ x86_outb(PORT + 1, 0x00); // Disable all interrupts
+ x86_outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
+ x86_outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
+ x86_outb(PORT + 1, 0x00); // (hi byte)
+ x86_outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit
+ x86_outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
+ x86_outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"COM 1 - initialized");
+}
+
+int serial_received() {
+ return x86_inb(PORT + 5) & 1;
+}
+
+char serial_read() {
+ while (serial_received() == 0);
+ return x86_inb(PORT);
+}
+
+int is_transmit_empty() {
+ return x86_inb(PORT + 5) & 0x20;
+}
+
+void serial_write(char a) {
+ while (is_transmit_empty() == 0);
+ x86_outb(PORT,a);
+}
diff --git a/driver/serial.h b/driver/serial.h
new file mode 100644
index 0000000..2f287e6
--- /dev/null
+++ b/driver/serial.h
@@ -0,0 +1,11 @@
+void serial_init()
+
+char serial_read() {
+int is_transmit_empty() {
+ return x86_inb(PORT + 5) & 0x20;
+}
+
+void serial_write(char a) {
+ while (is_transmit_empty() == 0);
+ x86_outb(PORT,a);
+}
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 79acf18..5d19e11 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -20,99 +20,65 @@
#include "terminal/terminal.h"
#include "driver/screen.h"
-
/* F00L 0S Entry point (called directly from asm/multiboot.asm */
void kernel_main(uint32_t eax,uint32_t ebx)
{
+ // SERIAL PORT
+ serial_init();
+
+ // PR
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%s - compiled on %s at %s",KERNEL_VERSION,__DATE__,__TIME__);
+
+ // PIT TIMER
+ timer_init();
- //
- // STDIN & STDOUT
- //
+ // STREAMS
uint32_t sstdin = syscall_open("stdin",0,0); // stdin 0
uint32_t sstdout = syscall_open("term",0,0); // stdout 1
uint32_t sstderr = syscall_open("stderr",0,0); // stderr 2
- //
- // PR
- //
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%s - compiled on %s at %s",KERNEL_VERSION,__DATE__,__TIME__);
-
- //
- // Setup Keyboard Driver
- //
+ // KEYBOARD DRIVER
keyboard_init(sstdin);
- //
- // Configuring the PIT timer.
- //
- timer_init();
+ // MOUSE DRIVER
+ mouse_init(sstdin);
- //
// GDT
- //
gdt_setup();
- //
- // Setup Interrupts (code segment: 0x08)
- //
+ // INTERRUPTS (code segment: 0x08)
int_init(0x08);
- //
- // Process Multiboot Header
- //
+ // MULTIBOOT HEADER
multiboot_information *info=get_multiboot(eax, ebx);
- //
- // Gather Info about other processors. (APs = application processors)
- // ACPI or MP
- //
+ // 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!");
- //
- // Memory Init
- //
- // after this is set up we will be able to allocate and deallocate
- // blocks of physical memory :)
- //
+ // MEMORY INIT (allows allocating and deaclloating physical memory)
uint32_t kernel_blocks=mem_init(info);
- //
// Mount Root EXT2 ramimage (needs to be done before other processors started, because of /boot/mp.bin)
- //
fs_mount(info);
- //
// Start the other Processors (before paging because apic addr etc..?)
- //
//TODO: !!! Check commented out sleep ()!!!
smp_log_procdata(&procdata);
smp_start_aps(&procdata,"/boot/mp.bin"); //will be copied over mbr
- //
- // Activate Virtual Memory (paging)
- //
+ // VIRTUAL MEMORY (paging)
pdirectory *dir=vmem_init(kernel_blocks);
- //
- // Scan the PCI Bus
- //
- // We are interested in the E1000 Network Adapter in particular
- // Its driver will be hopefully implemented one day ;) TODO
- //
- //pci_init();
- //
+ // PCI Bus
+ pci_init();
- //
- // Initialize Multitasking
- //
+ // INIT MULTITASKING (and switch to usermode)
task_init(dir);
- //
- // Abvoe should never returon
- //
+ // we should never reach this
panic(FOOLOS_MODULE_NAME,"reached end of kernel.c !!");
}
diff --git a/kernel/kernel.h b/kernel/kernel.h
index 44b9b2d..8d2bce9 100644
--- a/kernel/kernel.h
+++ b/kernel/kernel.h
@@ -23,7 +23,7 @@
#define FOOLSOS_SHOW_VESAMODES
#define MEM_PRINT_MEMORYMAP
#define LOG_BUF_SIZE 4069
-//#define LOG_SYSCALLS
+#define LOG_SYSCALLS
#define BIN_INIT "/bin/init"
@@ -31,4 +31,3 @@
#define NUMBER_SPINLOCKS 16
#endif
-
diff --git a/kernel/mem.c b/kernel/mem.c
index 029ea10..a167d8b 100644
--- a/kernel/mem.c
+++ b/kernel/mem.c
@@ -17,7 +17,6 @@ extern uint32_t kernel_end[];
extern uint32_t stack_top[];
extern uint32_t stack_bottom[];
-
//memory map bit array. Each bit represents a 4KB memory block,
//so uint32_t represents 8*4 blocks
static uint32_t _mmngr_memory_map[PMMNGR_MAP_SIZE];
diff --git a/kernel/timer.c b/kernel/timer.c
index a339d70..3f7ab0f 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -38,6 +38,7 @@
// TODO: use mutex? do we need volatile at all!??
// abstract atomic variable set,get,increment
static volatile uint64_t task_system_clock=0;
+static volatile uint64_t task_system_clock_start=0;
//called by interrupt
void timer_tick()
@@ -52,12 +53,18 @@ uint64_t timer_get_ticks()
}
///
+
uint64_t timer_get_ms()
{
uint64_t t=timer_get_ticks();
uint64_t s=t/25;
- uint64_t ms=0; // TODO ms
- return s*1000;
+ uint64_t ms=t*1000/25-s*1000;
+ return s*1000+ms;
+}
+
+uint64_t timer_get_uptime_ms()
+{
+ return timer_get_ms()-task_system_clock_start*1000;
}
// CMOS RTC
@@ -213,8 +220,9 @@ uint64_t get_rtc_time()
void timer_init()
{
uint64_t epoch_time=get_rtc_time();
- epoch_time*=25;
- task_system_clock=epoch_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
diff --git a/kernel/timer.h b/kernel/timer.h
index 57ea21e..a39d433 100644
--- a/kernel/timer.h
+++ b/kernel/timer.h
@@ -3,3 +3,4 @@
void timer_init();
void timer_tick();
uint64_t timer_get_ticks();
+uint64_t timer_get_uptime_ms();
diff --git a/lib/logger/log.c b/lib/logger/log.c
index 5350eda..63e9558 100644
--- a/lib/logger/log.c
+++ b/lib/logger/log.c
@@ -12,8 +12,14 @@
static void log_string(char *str)
{
- if(get_max_fd()<2)return;
+// if(get_max_fd()<2)return;
// syscall_write(2,str,strlen(str));
+
+ // TODO: use FD abstraction!
+ while(*str!=0)
+ {
+ serial_write(*str++);
+ }
}
void log(char *module_name, int log_level, char *format_string, ...)
@@ -28,19 +34,18 @@ void log(char *module_name, int log_level, char *format_string, ...)
char buf_log[256];
char buf_time[20];
- uint32_t t=timer_get_ms();
- uint32_t s=t/25;
- uint32_t ms=t*1000/25-1000*s;
+ uint64_t t=timer_get_uptime_ms();
+ uint32_t ms=t%1000;
+ uint32_t s=t/1000;
- //tfp_sprintf(buf_time,"[%3d.%05d]",s,ms);
- tfp_sprintf(buf_time,"[ ]");
+ tfp_sprintf(buf_time,"[%04d %03d]",s,ms);
va_list va;
va_start(va,format_string);
tfp_vsprintf(buf_info,format_string,va);
va_end(va);
- tfp_sprintf(buf_log,"\033[36;40m%s\033[31;40m %s:\033[37;40m %s\n",buf_time,module_name,buf_info);
+ tfp_sprintf(buf_log,"\033[36;40m%s\033[31;40m %10s:\033[37;40m %s\n",buf_time,module_name,buf_info);
log_string(buf_log);
}
@@ -51,6 +56,7 @@ void panic(char *module_name, char *message)
tfp_sprintf(buf_log,"\033[41;37m\n !! KERNEL PANIC !! %s: %s\n\n",module_name,message);
// log_string(buf_log);
//PANIC DIRECTLY TO STDOUT//
+ log_string(buf_log);
syscall_write(1,buf_log,strlen(buf_log));
while(1)
diff --git a/userspace/cat.c b/userspace/cat.c
index 8980546..688ebcc 100644
--- a/userspace/cat.c
+++ b/userspace/cat.c
@@ -3,13 +3,16 @@
int main()
{
+ char c;
- char buf[256];
+ printf("-- read from stderr byte by byte --\n");
while(has_data_waiting(2)){
- fread(buf,1,5,stderr); // read stderr;
- printf("[%s]\n",buf);
+ fread(&c,1,1,stderr);
+ printf("%c",c);
}
+ printf("\n-- no more data on stderr --\n");
+
return 0;
}
diff --git a/userspace/crt0.S b/userspace/crt0.S
index 87f1995..30b56a9 100644
--- a/userspace/crt0.S
+++ b/userspace/crt0.S
@@ -6,7 +6,8 @@ pop %eax
mov %eax, environ
pop %eax
-#mov %eax, _impure_ptr
+# mov %eax, _impure_ptr # TODO: use this !
+
call main
push environ
@@ -14,6 +15,7 @@ push %eax
call _exit2
# this should never be reached anyway!
+
.wait:
hlt
jmp .wait
diff --git a/userspace/err.c b/userspace/err.c
index b8dc8ed..7a33e69 100644
--- a/userspace/err.c
+++ b/userspace/err.c
@@ -2,8 +2,8 @@
int main()
{
- char buf[]="errrrrrro\n";
- printf("writing some err\n");
- fwrite(buf,1,10,stderr); // write stderr;
+ char buf[]="This is a line written to stderr.\n";
+ int l=fwrite(buf,sizeof(char),strlen(buf),stderr); // write stderr;
+ printf("Written %i chars to stderr.\n",l);
return 0;
}
diff --git a/xxx/inactive/floppy.c b/xxx/inactive/floppy.c
index 1dbe137..ea9e76e 100644
--- a/xxx/inactive/floppy.c
+++ b/xxx/inactive/floppy.c
@@ -1,4 +1,3 @@
-
/*
* Fool OS Simple Floppy Driver.
*
diff --git a/xxx/video/vesa.c b/xxx/video/vesa.c
index a5ee4e5..b43ca50 100644
--- a/xxx/video/vesa.c
+++ b/xxx/video/vesa.c
@@ -1,4 +1,5 @@
//http://wiki.osdev.org/GUI
+
#include <stdarg.h>
#include "kernel/mem.h"
#include "vesa.h"
@@ -9,7 +10,6 @@
#define FOOLSOS_SHOW_VESAMODES
-
static foolfont *deffont;
static vbemodeinfo *VbeModeInfoBlock;
@@ -226,7 +226,6 @@ void vesa_render()
if(boxx>VbeModeInfoBlock->Xres-100)boxx=100;
// if(boxy>VbeModeInfoBlock->Yres-200)boxy=200;
-
vesa_switch_buffers();
}
@@ -244,6 +243,3 @@ void vesa_init_doublebuff()
VbeModeInfoBlock->physbase=buffer;
}
*/
-
-
-