2022-07-25 02:09:15 +03:00
|
|
|
/**
|
|
|
|
* Entry point of rockOS
|
|
|
|
* Copyright (C) 2022 Furkan Mudanyali
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, _either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2022-07-20 02:23:23 +03:00
|
|
|
|
2022-07-25 02:09:15 +03:00
|
|
|
#include <stdio.h>
|
2022-07-20 02:23:23 +03:00
|
|
|
#include <rockos/tty.h>
|
2022-07-21 12:20:35 +03:00
|
|
|
#include <rockos/keyboard.h>
|
|
|
|
#include <rockos/pic.h>
|
|
|
|
#include <rockos/hal.h>
|
|
|
|
#include <rockos/timer.h>
|
2022-07-22 17:50:10 +03:00
|
|
|
#include <rockos/paging.h>
|
2022-07-25 02:09:15 +03:00
|
|
|
#include <rockos/kheap.h>
|
2022-07-24 07:16:00 +03:00
|
|
|
#include <rockos/multiboot.h>
|
2022-07-25 02:09:15 +03:00
|
|
|
#include <rockos/rockos.h>
|
2022-07-24 07:16:00 +03:00
|
|
|
#include <string.h>
|
2022-07-20 02:23:23 +03:00
|
|
|
|
2022-07-24 07:16:00 +03:00
|
|
|
extern char _rockos_start, _rockos_end;
|
|
|
|
|
|
|
|
static multiboot_info_t* multiboot_info;
|
|
|
|
|
|
|
|
void bootloader_init(multiboot_info_t* mbd, unsigned int magic) {
|
|
|
|
/* Make sure the magic number matches for memory mapping*/
|
|
|
|
if(magic != MULTIBOOT_BOOTLOADER_MAGIC) {
|
|
|
|
panic("invalid magic number!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check bit 6 to see if we have a valid memory map */
|
|
|
|
if(!(mbd->flags >> 6 & 0x1)) {
|
|
|
|
panic("invalid memory map given by GRUB bootloader");
|
|
|
|
}
|
|
|
|
multiboot_info = mbd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void kernel_main() {
|
2022-07-20 02:23:23 +03:00
|
|
|
printf("Hello, kernel World!\n");
|
|
|
|
printf("String test: %s\n", "HELLOOOOO");
|
|
|
|
printf("Float test: %.10f\n", 0.123456789);
|
|
|
|
printf("Int test: %d\n", 747474);
|
|
|
|
printf("Hex test: 0x%x\n", 0xDEADBEEF);
|
|
|
|
printf("And now for 0.1 + 0.2...... which is: %.17f\n", 0.1 + 0.2);
|
2022-07-21 12:20:35 +03:00
|
|
|
initialize_keyset();
|
|
|
|
|
2022-07-22 17:50:10 +03:00
|
|
|
outb(0x70, 0x0); // Seconds
|
2022-07-21 12:20:35 +03:00
|
|
|
uint8_t sec = inb(0x71);
|
2022-07-22 17:50:10 +03:00
|
|
|
outb(0x70, 0x02); // Minutes
|
2022-07-21 12:20:35 +03:00
|
|
|
uint8_t min = inb(0x71);
|
2022-07-22 17:50:10 +03:00
|
|
|
outb(0x70, 0x04); // Hours
|
2022-07-21 12:20:35 +03:00
|
|
|
uint8_t hour = inb(0x71);
|
2022-07-22 17:50:10 +03:00
|
|
|
// BCD to binary conversion
|
|
|
|
sec = (sec & 0x0F) + ((sec / 16) * 10);
|
|
|
|
min = (min & 0x0F) + ((min / 16) * 10);
|
|
|
|
hour = ((hour & 0x0F) + (((hour & 0x70) / 16) * 10)) | (hour & 0x80);
|
|
|
|
printf("Time: %02d:%02d:%02d UTC+3\n", (hour + 3) % 24, min, sec);
|
2022-07-24 07:16:00 +03:00
|
|
|
|
|
|
|
printf("RockOS Start: %#08X, RockOS End: %#08X\n", &_rockos_start, &_rockos_end);
|
2022-07-22 17:50:10 +03:00
|
|
|
|
2022-07-24 07:16:00 +03:00
|
|
|
for(multiboot_uint32_t i = 0; i < multiboot_info->mmap_length; i += sizeof(multiboot_memory_map_t)) {
|
|
|
|
multiboot_memory_map_t* mmmt =
|
|
|
|
(multiboot_memory_map_t*) (multiboot_info->mmap_addr + i);
|
|
|
|
|
|
|
|
printf("Start Addr: %#08X | Length: %#08X | Size: %#08X | Type: %X\n",
|
|
|
|
mmmt->addr_low, mmmt->len_low, mmmt->size, mmmt->type);
|
|
|
|
|
|
|
|
if(mmmt->type == MULTIBOOT_MEMORY_AVAILABLE) {
|
|
|
|
//
|
|
|
|
}
|
2022-07-22 17:50:10 +03:00
|
|
|
}
|
2022-07-25 02:09:15 +03:00
|
|
|
|
|
|
|
uint32_t a = kmalloc(8);
|
|
|
|
uint32_t b = kmalloc(8);
|
|
|
|
uint32_t c = kmalloc(8);
|
|
|
|
printf("A: %#08X B: %#08X C: %#08X\n",a,b,c);
|
|
|
|
kfree(c);
|
|
|
|
kfree(b);
|
|
|
|
uint32_t d = kmalloc(8);
|
|
|
|
printf("D: %#08X\n", d);
|
2022-07-20 02:23:23 +03:00
|
|
|
|
2022-07-22 00:24:26 +03:00
|
|
|
unsigned char key;
|
|
|
|
for(;;) {
|
2022-07-20 02:23:23 +03:00
|
|
|
key = readkey();
|
2022-07-22 00:24:26 +03:00
|
|
|
if(key)
|
2022-07-20 02:23:23 +03:00
|
|
|
putchar(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
asm("cli; hlt");
|
|
|
|
}
|