summaryrefslogtreecommitdiff
path: root/src/kernel.c
blob: 355067a424e575399ba7fa4e0cba0348cb95f359 (plain)
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
#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 "setjmp.h"

static jmp_buf panic_jmp_buf;

static vga_t vga;
static console_t console;
// static serial_t serial;

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 );
	interrupts_enable( );
		
//~ vga_put_char_at( &vga, 81, 20, 'X' );

	// exit point in case of kernel panic, do this as soon as
	// possible
	int v = setjmp( panic_jmp_buf );
	printf( "setjmp returned %d\n", v );
	if( v > 0 ) { 
		goto TERMINATE;
	}

	console_put_string( &console, "Running.." );
	
	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 < 10000; i++ ) {
		if( i % 1000 == 1 ) {
			vga_put_char_at( &vga, x_pos, y_pos, '.' );
			x_pos++;
//			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 );
}