@@ -39,13 +39,9 @@ static char *welcome_string = ""
39
39
" "
40
40
"" ;
41
41
42
- void trigger_page_fault () {
43
- uint32_t * unmapped_address = (uint32_t * ) 0x400000 ; // 4 MB
44
- log ("Trying to access address " );
45
- print_uint32 (LOG , (uint32_t ) unmapped_address );
46
- log (":\n" );
47
- print_uint8 (LOG , * unmapped_address );
48
- log ("\n. Successfully accessed.\n" );
42
+ uint32_t trigger_page_fault () {
43
+ uint32_t * unmapped_address = (uint32_t * ) 0x400000 ; // 4 MB
44
+ return * unmapped_address ;
49
45
}
50
46
51
47
struct test_struct_t {
@@ -63,68 +59,83 @@ void kmain(struct kernel_memory_descriptor_t kernel_memory, uint32_t ebx) {
63
59
printf (welcome_string );
64
60
65
61
serial_init ();
66
- log ("\n--------------------\ncstackOS is booting!\n--------------------\n\nInitialized serial port.\ n" );
62
+ log ("\n--------------------\ncstackOS is booting!\n--------------------\n\n" );
67
63
64
+ #ifdef DEBUG
68
65
log ("\nMultiboot info passed to kernel from GRUB:\n" );
69
66
print_multiboot_info (LOG , mbinfo );
70
67
log ("\n" );
68
+ #endif
71
69
70
+ log ("- Initializing symbol table...\n" );
72
71
if (load_symbol_table (get_elf_section (mbinfo , ".symtab" ), get_elf_section (mbinfo , ".strtab" ))) {
73
- log ("Initialized symbol table. \n" );
72
+ log (" - done \n" );
74
73
} else {
75
74
log ("ERROR: Could not initialize symbol table.\n" );
75
+ while (1 ){}
76
76
}
77
77
78
+ log ("- Initializing global descriptor table...\n" );
78
79
initialize_gdt ();
79
- log ("Loaded global descriptor table. \n" );
80
+ log (" - done \n" );
80
81
82
+ log ("- Initializing interrupt descriptor table...\n" );
81
83
initialize_idt ();
82
- log ("Loaded interrupt descriptor table. \n" );
84
+ log (" - done \n" );
83
85
84
- log ("Issuing test interrupt.\n" );
86
+ log ("- Issuing test interrupt.. .\n" );
85
87
interrupt (49 );
86
- log ("Returned from test interrupt() \n" );
88
+ log (" - done \n" );
87
89
90
+ log ("- Initializing programable interrupt controller...\n" );
88
91
pic_init ();
89
- log ("Initialized PIC \n" );
92
+ log (" - done \n" );
90
93
94
+ log ("- Initializing page allocator...\n" );
91
95
uint32_t free_pages = initialize_page_allocator (kernel_memory , mbinfo );
92
- log ("Initialized page allocator.\n" );
96
+ log (" - done\n" );
97
+ log (" - " );
93
98
print_uint32 (LOG , free_pages );
94
99
log (" free pages (" );
95
100
print_uint32 (LOG , free_pages / 256 );
96
101
log (" MB)\n" );
97
102
103
+ log ("- Initializing page directory...\n" );
98
104
page_directory_t pd = initialize_page_directory ();
99
- log ("Initialized page directory. \n" );
100
- log ("Address of page directory: " );
105
+ log (" - done \n" );
106
+ log (" - Address of page directory: " );
101
107
print_uint32 (LOG , (uint32_t ) pd );
102
108
log ("\n" );
109
+ uint32_t num_pages = num_present_pages (pd );
110
+ log (" - " );
111
+ print_uint32 (LOG , num_pages );
112
+ log (" present pages\n" );
113
+
114
+ log ("- Triggering a page fault...\n" );
115
+ uint32_t value = trigger_page_fault ();
116
+ log (" - done\n" );
117
+ log (" - value at unmapped address was " );
118
+ print_uint32 (LOG , value );
119
+ log ("\n" );
103
120
104
- print_page_directory (LOG , pd );
105
-
106
- trigger_page_fault ();
107
-
121
+ log ("- Dynamically allocating a struct...\n" );
108
122
struct test_struct_t * test = (struct test_struct_t * ) malloc (sizeof (struct test_struct_t ));
109
-
110
- log ("Dynamically allocated a struct\nAddress is: " );
123
+ log ( " - done\n" );
124
+ log (" - address is: " );
111
125
print_uint32 (LOG , (uint32_t ) test );
112
126
log ("\n" );
113
-
114
- test -> character = 'A' ;
115
- test -> string = "Hello World" ;
116
127
117
128
uint32_t local = 0xDEADBEEF ;
118
129
119
- log ("local variable at: " );
130
+ log (" - local variable at: " );
120
131
print_uint32 (LOG , (uint32_t ) & local );
121
132
log ("\n" );
122
- log ("local variable value: " );
133
+ log (" - local variable value: " );
123
134
print_uint32 (LOG , (uint32_t ) local );
124
135
log ("\n" );
125
136
126
137
void * sp = current_stack_pointer ();
127
- log ("stack pointer is: " );
138
+ log (" - stack pointer is: " );
128
139
print_uint32 (LOG , (uint32_t ) sp );
129
140
log ("\n" );
130
141
0 commit comments