2021-05-10 20:33:25 +00:00
|
|
|
#include "kernel.h"
|
2021-11-06 15:27:13 +00:00
|
|
|
#define GB4 524288
|
|
|
|
#define GB2 262144
|
2021-11-25 21:05:16 +00:00
|
|
|
|
|
|
|
int memcmp( const void* ptr1, const void* ptr2, size_t num);
|
|
|
|
|
|
|
|
extern "C" void kernel_main (void);
|
|
|
|
|
2021-11-03 19:03:38 +00:00
|
|
|
extern "C" void early_main(unsigned long magic, unsigned long addr){
|
2021-11-25 21:05:16 +00:00
|
|
|
/** initialize terminal interface */
|
2021-07-22 19:02:47 +00:00
|
|
|
kterm_init();
|
2021-11-25 21:05:16 +00:00
|
|
|
|
2021-07-22 19:02:47 +00:00
|
|
|
if (magic != MULTIBOOT_BOOTLOADER_MAGIC){
|
2021-10-23 11:26:15 +00:00
|
|
|
printf("Invalid magic number: 0x%x\n", magic);
|
2021-07-22 19:02:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-11-25 21:05:16 +00:00
|
|
|
|
2021-10-23 11:26:15 +00:00
|
|
|
CheckMBT( (multiboot_info_t *) addr);
|
2021-07-22 19:02:47 +00:00
|
|
|
|
2021-10-23 11:26:15 +00:00
|
|
|
multiboot_info_t* mbt = (multiboot_info_t*) addr;
|
2021-07-22 19:02:47 +00:00
|
|
|
|
|
|
|
/* Are mmap_* valid? */
|
2021-10-23 11:26:15 +00:00
|
|
|
if (CHECK_FLAG(mbt->flags, 6)){
|
2021-11-06 15:27:13 +00:00
|
|
|
PhysicalMemoryManager_initialise( mbt->mmap_addr, GB2/* Seriously dangerous hardcoded memory value*/);
|
|
|
|
PhysicalMemoryManager_initialise_available_regions(mbt->mmap_addr, mbt->mmap_addr + mbt->mmap_length);
|
|
|
|
PhysicalMemoryManager_deinitialise_kernel();
|
|
|
|
extern uint8_t* kernel_begin;
|
|
|
|
extern uint8_t* kernel_end;
|
|
|
|
|
|
|
|
printf("Kernel MemoryMap:\n");
|
|
|
|
printf("kernel: 0x%x - 0x%x\n", &kernel_begin , &kernel_end);
|
2021-07-22 19:02:47 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 20:17:49 +00:00
|
|
|
initGDT();
|
2021-11-25 21:05:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kernel_main();
|
|
|
|
}
|
|
|
|
|
|
|
|
int memcmp( const void* ptr1, const void* ptr2, size_t num)
|
|
|
|
{
|
|
|
|
const unsigned char * cs = (const unsigned char*) ptr1;
|
|
|
|
const unsigned char * ct = (const unsigned char*) ptr2;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0 ; i < num ; i++, cs++, ct++ ){
|
|
|
|
if( *cs < *ct){
|
|
|
|
return -1;
|
|
|
|
} else if( *cs > *ct){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2021-07-22 21:14:58 +00:00
|
|
|
|
2021-05-12 22:03:00 +00:00
|
|
|
}
|
|
|
|
|
2021-11-03 19:03:38 +00:00
|
|
|
extern "C" void kernel_main (void) {
|
2021-05-12 22:03:00 +00:00
|
|
|
|
2021-11-06 20:56:42 +00:00
|
|
|
printf("call to init serial\n");
|
2021-07-22 19:02:47 +00:00
|
|
|
init_serial();
|
2021-11-25 21:05:16 +00:00
|
|
|
print_serial("Serial port initialized!");
|
|
|
|
|
2021-11-28 15:46:16 +00:00
|
|
|
|
|
|
|
|
2021-11-25 21:05:16 +00:00
|
|
|
// Enumerate the PCI bus
|
2021-11-29 19:00:28 +00:00
|
|
|
PCI_Enumerate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TestIDEController();
|
2021-11-25 21:05:16 +00:00
|
|
|
|
2021-11-30 23:00:45 +00:00
|
|
|
int devNumber = 0 ;
|
|
|
|
for ( auto device : ide_devices){
|
|
|
|
if (!device.Reserved)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
printf("Device %d\n" , devNumber);
|
|
|
|
printf (" Device on Channel: (0x%x) %s\n" ,device.Channel, device.Channel == 0 ? "Primary" : "Secondary");
|
|
|
|
printf (" Device drive:(0x%x) %s\n" , device.Drive, device.Drive? "Slave" : "Master");
|
|
|
|
printf (" Device Type:(0x%x) %s\n" , device.Type, device.Type ? "ATAPI" : "ATA");
|
|
|
|
devNumber ++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ATAPI_DEVICE::isPacketDevice();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ATAPI_DEVICE::Identify(ATA_SECONDARY, DEVICE_DRIVE::MASTER);
|
|
|
|
|
|
|
|
|
2021-07-22 19:02:47 +00:00
|
|
|
|
2021-11-06 20:56:42 +00:00
|
|
|
while (true){
|
2021-05-28 21:20:13 +00:00
|
|
|
//Read time indefinetely
|
2021-11-28 15:46:16 +00:00
|
|
|
read_rtc();
|
|
|
|
printf( "UTC time: %02d-%02d-%02d %02d:%02d:%02d [ Formatted as YY-MM-DD h:mm:ss]\r" ,year, month, day, hour, minute, second);
|
2021-05-18 20:14:26 +00:00
|
|
|
delay(1000);
|
|
|
|
}
|
2021-11-16 12:57:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-22 21:14:58 +00:00
|
|
|
|
2021-05-10 20:33:25 +00:00
|
|
|
}
|
2021-11-03 19:03:38 +00:00
|
|
|
|