1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#include <stdint.h>
#include <stdarg.h>
#include "vga.h"
#include "serial.h"
#include "console.h"
#include "stdlib.h"
#include "stdio.h"
#include "interrupts.h"
#include "keyboard.h"
#include "setjmp.h"
static jmp_buf panic_jmp_buf;
void entry( void )
{
serial_t serial;
serial_init( &serial );
vga_t vga;
vga_init( &vga );
vga_set_color( &vga, VGA_COLOR_LIGHT_GREY );
vga_set_background_color( &vga, VGA_COLOR_BLACK );
console_t console;
console_init( &console );
console_add_vga_output( &console, &vga );
// console_add_serial_output( &console, &serial );
// initialize the early console of the kernel
stdio_set_console( &console );
puts( "Started early kernel console" );
printf( "Kernel code and data is at 0x%X, kernel stack at 0x%X\n", 0x8400, 0x90000 );
puts( "Initializing interrupts" );
interrupt_t interrupt;
interrupts_init( &interrupt );
keyboard_t keyboard;
keyboard_init( &keyboard );
interrupt_handler_t keyboard_interrupt_handler;
interrupt_handler_init( &keyboard_interrupt_handler, IRQ_BASE + 0x01, &interrupt, keyboard_handle_interrupt, &keyboard );
interrupts_register_interrupt_handler( keyboard_interrupt_handler );
// exit point in case of kernel panic, do this as soon as
// possible
if( setjmp( panic_jmp_buf ) > 0 ) {
goto TERMINATE;
}
// TODO: initialize hardware here
interrupts_enable( );
//~ vga_put_char_at( &vga, 81, 20, 'X' );
console_put_string( &console, "Running.." );
// endless loop doing nothing, later we have to get events
// here from queues and for instance print characters received
// from the keyboard to stdout
for( int i = 0; i < 1000000000; i++ ) {
if( i % 10000000 == 1 ) {
printf( "M" );
}
}
//~ 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( "Terminating" );
}
void kernel_panic( const char *format, ... )
{
(void)printf( "\n*** KERNEL PANIC ***\n" );
va_list args;
va_start( args, format );
(void)vprintf( format, args );
va_end( args );
longjmp( panic_jmp_buf, 47 );
}
|