summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-06-05 18:14:32 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-06-05 18:14:32 +0200
commit25753a453b5da16583ace92dc8f9c426dd4a1388 (patch)
tree9d9ce77d7db945ee1e5ea44c37b0f15aa8049845
parentd42328ec3e07c7c76d1ba0a253f982f57ead41e7 (diff)
downloadabaos-25753a453b5da16583ace92dc8f9c426dd4a1388.tar.gz
abaos-25753a453b5da16583ace92dc8f9c426dd4a1388.tar.bz2
added deinit in drivers
added some debug flags and code in drivers 32 sectors size of kernel
-rw-r--r--src/Makefile4
-rw-r--r--src/kernel.c40
-rw-r--r--src/keyboard.c34
-rw-r--r--src/keyboard.h1
-rw-r--r--src/mouse.c12
-rw-r--r--src/mouse.h1
-rw-r--r--src/stage1_functions.asm2
7 files changed, 49 insertions, 45 deletions
diff --git a/src/Makefile b/src/Makefile
index 3388eb4..6e52754 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -13,10 +13,10 @@ all: image.bin kernel.sym
# + M * 512 (M is currently 7) = 3144 for kernel.bin
# + 1 * 512 = 512 for magic.bin
# (M + N + 1 is the number of sectors to be read in stage 2, as stage 1
-# loads only the first sector, so adapt NOF_LOAD_SECTORS to 27)
+# loads only the first sector, so adapt NOF_LOAD_SECTORS to 32)
image.bin: boot.bin kernel.bin magic.bin
cat boot.bin kernel.bin > image.tmp
- truncate -s 13824 image.tmp
+ truncate -s 16384 image.tmp
cat image.tmp magic.bin > image.bin
boot.bin: boot.asm boot_gdt.asm stage1_functions.asm stage2_functions.asm stage2_switch_mode.asm stage2_a20.asm
diff --git a/src/kernel.c b/src/kernel.c
index ec121ce..8fec39c 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -33,6 +33,8 @@ void entry( void )
console_t console;
console_init( &console );
console_add_vga_output( &console, &vga );
+// TODO: breaks on real hardware, we need proper interrupt handling
+// and driver implementation as for the mouse and the keyboard
// console_add_serial_output( &console, &serial );
// initialize the early console of the kernel
@@ -67,8 +69,6 @@ void entry( void )
puts( "Enabling interrupt handing now.." );
interrupts_enable( );
-//~ vga_put_char_at( &vga, 81, 20, 'X' );
-
puts( "Running.." );
// endless loop doing nothing, later we have to get events
@@ -83,37 +83,13 @@ void entry( void )
}
}
- //~ const char bar[] = "\\|/-";
- //~ int y_pos = vga_get_cursor_y( &vga );
- //~ int x_pos = vga_get_cursor_x( &vga );
- //~ int i = 0;
- //~ for( i = 0; i < 100000; i++ ) {
- //~ if( i % 1000 == 1 ) {
- //~ vga_put_char_at( &vga, x_pos, y_pos, '.' );
- //~ x_pos++;
- //~ if( x_pos > vga.res_x ) {
- //~ x_pos = 0;
- //~ y_pos++;
- //~ if( y_pos > vga.res_y ) {
- //~ y_pos = 0;
- //~ }
- //~ }
-//~ // serial_put_char( &serial, '.' );
-//~ int y = 0;
-//~ int x = 12 / y;
-//~ printf( "Hex number is 0x%X and string is '%s'\n", x, "abaos" );
-
- //~ }
- //~ vga_put_char_at( &vga, x_pos, y_pos, bar[i%4] );
- //~ for( int j = 0; j < 1500; j++ ) {
- //~ }
- //~ }
- //~ vga_put_char_at( &vga, x_pos, y_pos, '.' );
-//~ // serial_put_char( &serial, '.' );
-
- //~ console_put_newline( &console );
-
TERMINATE:
+ puts( "Deinitializing PS/2 mouse.." );
+ mouse_deinit( &mouse );
+
+ puts( "Deinitializing PS/2 keyboard.." );
+ keyboard_deinit( &keyboard );
+
puts( "Terminating" );
}
diff --git a/src/keyboard.c b/src/keyboard.c
index f73eda3..b4c5085 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1,6 +1,5 @@
-#include <stdbool.h>
-
#include "keyboard.h"
+#include "stdio.h"
// status register on command port (read)
#define STATUS_REG_OUTPUT_BUF_FULL 0x01
@@ -33,6 +32,8 @@
#define KBD_SCANCODE_2 0x02
#define KBD_SCANCODE_3 0x03
+#undef DEBUG
+
static uint8_t read_data( keyboard_t *keyboard )
{
while( ( port8_read( &keyboard->command_port ) & STATUS_REG_OUTPUT_BUF_FULL ) == 0 ) { }
@@ -51,6 +52,18 @@ static void write_data( keyboard_t *keyboard, uint8_t data )
port8_write( &keyboard->data_port, data );
}
+/*
+static void read_ack( keyboard_t *keyboard )
+{
+ uint8_t data = read_data( keyboard );
+ if( data == 0xFA ) {
+ return;
+ } else {
+ kernel_warn( "ERR PS/2 keyboard: acknoledgment failed 0x%X\n", data );
+ }
+}
+*/
+
void keyboard_init( keyboard_t *keyboard, keyboard_event_handler_t handler, void *context )
{
memset( keyboard, 0, sizeof( keyboard_t ) );
@@ -86,12 +99,18 @@ void keyboard_init( keyboard_t *keyboard, keyboard_event_handler_t handler, void
//~ write_data( keyboard, KBD_SCANCODE_2 );
// activate keyboard
- //~ send_command( keyboard, KBD_ACTIVATE );
+ //send_command( keyboard, KBD_ACTIVATE );
+ //read_ack( keyboard );
// enable port 1
send_command( keyboard, COMMAND_ENABLE_PORT1 );
}
+void keyboard_deinit( keyboard_t *keyboard )
+{
+ send_command( keyboard, COMMAND_DISABLE_PORT1 );
+}
+
typedef enum {
KEYCODE_UNKNOWN,
KEYCODE_ASCII_CHAR
@@ -234,9 +253,12 @@ uint32_t keyboard_handle_interrupt( interrupt_handler_t *handler, uint32_t esp )
}
keycode_t key_code = scancode_to_keycode( code_set, scan_code );
-// printf( "KBD SCAN:0x%X S:%d B:%d S:%d T:0x%X '%c' 0x%X\n",
-// scan_code, code_set, break_code, keyboard->shift,
-// key_code.type, key_code.c, key_code.c );
+
+#ifdef DEBUG
+ printf( "KBD SCAN:0x%X S:%d B:%d S:%d T:0x%X '%c' 0x%X\n",
+ scan_code, code_set, break_code, keyboard->shift,
+ key_code.type, key_code.c, key_code.c );
+#endif
keyboard_event_t event;
if( break_code ) {
diff --git a/src/keyboard.h b/src/keyboard.h
index 6b8406b..167a901 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -52,6 +52,7 @@ typedef struct {
} keyboard_t;
void keyboard_init( keyboard_t *keyboard, keyboard_event_handler_t handler, void *context );
+void keyboard_deinit( keyboard_t *keyboard );
uint32_t keyboard_handle_interrupt( interrupt_handler_t *handler, uint32_t esp );
diff --git a/src/mouse.c b/src/mouse.c
index 74c9231..d9d36e9 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -35,7 +35,7 @@
#define MOUSE_BYTE1_X_OVERFLOW 0x40
#define MOUSE_BYTE1_Y_OVERFLOW 0x80
-#define DEBUG
+#undef DEBUG
static uint8_t read_data( mouse_t *mouse )
{
@@ -68,7 +68,6 @@ static void read_ack( mouse_t *mouse )
static void set_sample_rate( mouse_t *mouse, uint8_t samples )
{
send_command( mouse, COMMAND_SEND_TO_PORT2 );
- //read_ack( mouse );
write_data( mouse, MOUSE_COMMAND_SET_SAMPLE_RATE );
read_ack( mouse );
@@ -94,8 +93,6 @@ void mouse_init( mouse_t *mouse, mouse_event_handler_t handler, void *context, u
port8_init( &mouse->command_port, 0x64 );
port8_init( &mouse->data_port, 0x60 );
- // first switch off port 2
-// send_command( mouse, COMMAND_DISABLE_PORT2 );
// enable port 2
send_command( mouse, COMMAND_ENABLE_PORT2 );
@@ -127,6 +124,13 @@ void mouse_init( mouse_t *mouse, mouse_event_handler_t handler, void *context, u
// enable mouse on second port
send_command( mouse, COMMAND_SEND_TO_PORT2 );
write_data( mouse, MOUSE_COMMAND_ENABLE_DATAREPORTING );
+ read_ack( mouse );
+}
+
+void mouse_deinit( mouse_t *mouse )
+{
+ // disable mouse on second port
+ send_command( mouse, COMMAND_DISABLE_PORT2 );
}
uint32_t mouse_handle_interrupt( interrupt_handler_t *handler, uint32_t esp )
diff --git a/src/mouse.h b/src/mouse.h
index 20af4d0..8099922 100644
--- a/src/mouse.h
+++ b/src/mouse.h
@@ -48,6 +48,7 @@ typedef struct {
} mouse_t;
void mouse_init( mouse_t *mouse, mouse_event_handler_t handler, void *context, uint32_t res_x, uint32_t res_y );
+void mouse_deinit( mouse_t *mouse );
uint32_t mouse_handle_interrupt( interrupt_handler_t *handler, uint32_t esp );
diff --git a/src/stage1_functions.asm b/src/stage1_functions.asm
index 95d4489..293f105 100644
--- a/src/stage1_functions.asm
+++ b/src/stage1_functions.asm
@@ -2,7 +2,7 @@
; 3 * 512 for bootloader stage2 and the kernel code
; (note: the first sector gets loaded by the BIOS, so
; subtract 1 here!)
-NOF_LOAD_SECTORS equ 27
+NOF_LOAD_SECTORS equ 32
; IN bx: begin of memory area to dump
; IN ax: number of words to dump