Made kernel C++ now
This commit is contained in:
parent
cd8bd42ebb
commit
2a68860bef
4
Makefile
4
Makefile
@ -1,5 +1,5 @@
|
|||||||
CFLAGS = -std=gnu11 -m32 -mgeneral-regs-only -nostdlib -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pie -fno-stack-protector -Wno-pointer-to-int-cast
|
CFLAGS = -std=gnu11 -m32 -mgeneral-regs-only -nostdlib -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pie -fno-stack-protector -Wno-pointer-to-int-cast
|
||||||
CXXFLAGS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore
|
CXXFLAGS = -m32 -fno-use-cxa-atexit -mgeneral-regs-only -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -fpermissive -fno-pie -fno-stack-protector
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
|
|
||||||
DISK_IMG_FILES = build/kernel/kernel.bin
|
DISK_IMG_FILES = build/kernel/kernel.bin
|
||||||
@ -52,7 +52,7 @@ build/kernel/%.o: src/kernel/%.c
|
|||||||
gcc $(CFLAGS) -o $@ -c $<
|
gcc $(CFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
build/kernel/%.o: src/kernel/%.cpp
|
build/kernel/%.o: src/kernel/%.cpp
|
||||||
g++ $(CFLAGS) -o $@ -c $<
|
g++ $(CXXFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
build/kernel/%.o: src/kernel/%.asm
|
build/kernel/%.o: src/kernel/%.asm
|
||||||
nasm -felf32 $< -o $@
|
nasm -felf32 $< -o $@
|
||||||
|
@ -66,7 +66,7 @@ void init_atapio() {
|
|||||||
|
|
||||||
// We've initialised now, let's load the FAT and RootDirEntries.
|
// We've initialised now, let's load the FAT and RootDirEntries.
|
||||||
read_sectors(sectorsPerFAT * countFATs + countReserved, countRDEs / 16, rootDirEntries);
|
read_sectors(sectorsPerFAT * countFATs + countReserved, countRDEs / 16, rootDirEntries);
|
||||||
read_sectors(countReserved, sectorsPerFAT, FAT1);
|
read_sectors(countReserved, sectorsPerFAT, (uint8_t*)FAT1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_sector(uint32_t address, uint8_t* buffer) {
|
void read_sector(uint32_t address, uint8_t* buffer) {
|
||||||
@ -101,7 +101,7 @@ uint16_t file_exists(char* filename) {
|
|||||||
for (int i=0; i<countRDEs; i++) {
|
for (int i=0; i<countRDEs; i++) {
|
||||||
bool found = strcmp(rootDirEntries+(i*32), filename, 11);
|
bool found = strcmp(rootDirEntries+(i*32), filename, 11);
|
||||||
if (found) {
|
if (found) {
|
||||||
uint16_t* correctEntry = (rootDirEntries+(i*32));
|
uint16_t* correctEntry = (uint16_t*)(rootDirEntries+(i*32));
|
||||||
return correctEntry[13];
|
return correctEntry[13];
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,10 +3,8 @@
|
|||||||
gdt_entry gdt[] = {
|
gdt_entry gdt[] = {
|
||||||
(gdt_entry){ // Null Segment
|
(gdt_entry){ // Null Segment
|
||||||
.limit_lo = 0,
|
.limit_lo = 0,
|
||||||
.limit_hi = 0,
|
|
||||||
.base_lo = 0,
|
.base_lo = 0,
|
||||||
.base_mid = 0,
|
.base_mid = 0,
|
||||||
.base_hi = 0,
|
|
||||||
.accessed = 0,
|
.accessed = 0,
|
||||||
.read_write = 0,
|
.read_write = 0,
|
||||||
.direction = 0,
|
.direction = 0,
|
||||||
@ -14,17 +12,16 @@ gdt_entry gdt[] = {
|
|||||||
.system_segment = 0,
|
.system_segment = 0,
|
||||||
.privilege = 0,
|
.privilege = 0,
|
||||||
.present = 0,
|
.present = 0,
|
||||||
|
.limit_hi = 0,
|
||||||
|
.__ignored__ = 0,
|
||||||
.size = 0,
|
.size = 0,
|
||||||
.granularity = 0,
|
.granularity = 0,
|
||||||
|
.base_hi = 0,
|
||||||
.__ignored__ = 0,
|
|
||||||
},
|
},
|
||||||
(gdt_entry){ // Code Segment
|
(gdt_entry){ // Code Segment
|
||||||
.limit_lo = 0xffff,
|
.limit_lo = 0xffff,
|
||||||
.limit_hi = 0xf,
|
|
||||||
.base_lo = 0,
|
.base_lo = 0,
|
||||||
.base_mid = 0,
|
.base_mid = 0,
|
||||||
.base_hi = 0,
|
|
||||||
.accessed = 0,
|
.accessed = 0,
|
||||||
.read_write = 1,
|
.read_write = 1,
|
||||||
.direction = 0,
|
.direction = 0,
|
||||||
@ -32,17 +29,16 @@ gdt_entry gdt[] = {
|
|||||||
.system_segment = 1,
|
.system_segment = 1,
|
||||||
.privilege = 0,
|
.privilege = 0,
|
||||||
.present = 1,
|
.present = 1,
|
||||||
|
.limit_hi = 0xf,
|
||||||
|
.__ignored__ = 0,
|
||||||
.size = 1,
|
.size = 1,
|
||||||
.granularity = 1,
|
.granularity = 1,
|
||||||
|
.base_hi = 0
|
||||||
.__ignored__ = 0,
|
|
||||||
},
|
},
|
||||||
(gdt_entry){ // Data Segment
|
(gdt_entry){ // Data Segment
|
||||||
.limit_lo = 0xffff,
|
.limit_lo = 0xffff,
|
||||||
.limit_hi = 0xf,
|
|
||||||
.base_lo = 0,
|
.base_lo = 0,
|
||||||
.base_mid = 0,
|
.base_mid = 0,
|
||||||
.base_hi = 0,
|
|
||||||
.accessed = 0,
|
.accessed = 0,
|
||||||
.read_write = 1,
|
.read_write = 1,
|
||||||
.direction = 0,
|
.direction = 0,
|
||||||
@ -50,11 +46,11 @@ gdt_entry gdt[] = {
|
|||||||
.system_segment = 1,
|
.system_segment = 1,
|
||||||
.privilege = 0,
|
.privilege = 0,
|
||||||
.present = 1,
|
.present = 1,
|
||||||
|
.limit_hi = 0xf,
|
||||||
|
.__ignored__ = 0,
|
||||||
.size = 1,
|
.size = 1,
|
||||||
.granularity = 1,
|
.granularity = 1,
|
||||||
|
.base_hi = 0
|
||||||
.__ignored__ = 0,
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
typedef struct {
|
struct __attribute__((packed)) gdt_entry {
|
||||||
uint32_t limit_lo : 16;
|
uint32_t limit_lo : 16;
|
||||||
uint32_t base_lo : 16;
|
uint32_t base_lo : 16;
|
||||||
|
|
||||||
@ -22,11 +22,13 @@ typedef struct {
|
|||||||
uint32_t granularity : 1;
|
uint32_t granularity : 1;
|
||||||
|
|
||||||
uint32_t base_hi : 8;
|
uint32_t base_hi : 8;
|
||||||
}__attribute__((packed)) gdt_entry;
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct __attribute__((packed)) gdt_descr {
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
}__attribute__((packed)) gdt_descr;
|
};
|
||||||
|
|
||||||
|
void init_gdt();
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -14,18 +14,18 @@ void set_entry(uint8_t interrupt_number, uint16_t code_segment, void* handler, u
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((interrupt)) void interrupt_20(struct interrupt_frame* frame) {
|
__attribute__((interrupt)) void interrupt_20(interrupt_frame* frame) {
|
||||||
// printf("Interrupt 20 received!!\n");
|
// printf("Interrupt 20 received!!\n");
|
||||||
outb(0x20, 0x20);
|
outb(0x20, 0x20);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((interrupt)) void page_fault(struct interrupt_frame* frame, uint32_t err_code) {
|
__attribute__((interrupt)) void page_fault(interrupt_frame* frame, uint32_t err_code) {
|
||||||
uint32_t problem_address;
|
uint32_t problem_address;
|
||||||
asm("mov %%cr2, %0" : "=a" (problem_address) :);
|
asm("mov %%cr2, %0" : "=a" (problem_address) :);
|
||||||
printf("Page Fault at %x\n", problem_address);
|
printf("Page Fault at %x\n", problem_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((interrupt)) void ignore_interrupt(struct interrupt_frame* frame) {
|
__attribute__((interrupt)) void ignore_interrupt(interrupt_frame* frame) {
|
||||||
outb(0x20, 0x20);
|
outb(0x20, 0x20);
|
||||||
}
|
}
|
||||||
|
|
@ -16,17 +16,17 @@ void set_entry(uint8_t interrupt_number, uint16_t code_segment, void* handler, u
|
|||||||
void init_idt();
|
void init_idt();
|
||||||
void enable_idt();
|
void enable_idt();
|
||||||
|
|
||||||
typedef struct {
|
struct __attribute__((packed)) GateEntry{
|
||||||
uint16_t offset_low;
|
uint16_t offset_low;
|
||||||
uint16_t selector;
|
uint16_t selector;
|
||||||
uint8_t zero;
|
uint8_t zero;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint16_t offset_high;
|
uint16_t offset_high;
|
||||||
}__attribute__((packed)) GateEntry;
|
} ;
|
||||||
|
|
||||||
typedef struct {
|
struct __attribute__((packed)) idt_desc {
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
}__attribute__((packed)) idt_desc;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,65 +1,62 @@
|
|||||||
#include "paging.h"
|
#include "paging.h"
|
||||||
|
|
||||||
typedef struct {
|
struct __attribute__((packed)) split_addr {
|
||||||
uint32_t page_offset : 12;
|
uint32_t page_offset : 12;
|
||||||
uint32_t pt_index : 10;
|
uint32_t pt_index : 10;
|
||||||
uint32_t pd_index : 10;
|
uint32_t pd_index : 10;
|
||||||
}__attribute__((packed)) split_addr;
|
};
|
||||||
|
|
||||||
void map_4k_phys_to_virt(uint32_t physical, uint32_t virtual, PDE* page_directory, PTE** page_tables) {
|
void map_4k_phys_to_virt(uint32_t physical, uint32_t virt, PDE* page_directory, PTE** page_tables) {
|
||||||
split_addr* split = (split_addr*)&virtual;
|
split_addr* split = (split_addr*)&virt;
|
||||||
|
|
||||||
page_directory[split->pd_index] = (PDE){
|
page_directory[split->pd_index] = (PDE){
|
||||||
.address = (uint32_t)(page_tables[split->pd_index]) >> 12,
|
.present = 1,
|
||||||
.available = 0,
|
.read_write = 1,
|
||||||
|
.privilege = 0,
|
||||||
|
.write_through_cache = 0,
|
||||||
|
.disable_cache = 0,
|
||||||
|
.accessed = 0,
|
||||||
|
.ignored2 = 0,
|
||||||
.page_4mb = 0,
|
.page_4mb = 0,
|
||||||
.accessed = 0,
|
|
||||||
.disable_cache = 0,
|
|
||||||
.write_through_cache = 0,
|
|
||||||
.privilege = 0,
|
|
||||||
.present = 1,
|
|
||||||
.read_write = 1,
|
|
||||||
|
|
||||||
.ignored = 0,
|
.ignored = 0,
|
||||||
.ignored2 = 0
|
.available = 0,
|
||||||
|
.address = (uint32_t)(page_tables[split->pd_index]) >> 12
|
||||||
};
|
};
|
||||||
|
|
||||||
((PTE*)((uint32_t)page_tables[split->pd_index] + 0xbffe0000))[split->pt_index] = (PTE){
|
((PTE*)((uint32_t)page_tables[split->pd_index] + 0xbffe0000))[split->pt_index] = (PTE){
|
||||||
.address = physical >> 12,
|
|
||||||
.available = 0,
|
|
||||||
.global = 0,
|
|
||||||
.accessed = 0,
|
|
||||||
.disable_cache = 0,
|
|
||||||
.dirty = 0,
|
|
||||||
.write_through_cache = 0,
|
|
||||||
.privilege = 0,
|
|
||||||
.present = 1,
|
.present = 1,
|
||||||
.read_write = 1,
|
.read_write = 1,
|
||||||
|
.privilege = 0,
|
||||||
.ignored = 0
|
.write_through_cache = 0,
|
||||||
|
.disable_cache = 0,
|
||||||
|
.accessed = 0,
|
||||||
|
.dirty = 0,
|
||||||
|
.ignored = 0,
|
||||||
|
.global = 0,
|
||||||
|
.available = 0,
|
||||||
|
.address = physical >> 12
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void map_many_4k_phys_to_virt(uint32_t physical, uint32_t virtual, PDE* page_directory, PTE** page_tables, uint32_t count) {
|
void map_many_4k_phys_to_virt(uint32_t physical, uint32_t virt, PDE* page_directory, PTE** page_tables, uint32_t count) {
|
||||||
for (int i=0; i<count; i++)
|
for (int i=0; i<count; i++)
|
||||||
map_4k_phys_to_virt(physical + 4096*i, virtual + 4096*i, page_directory, page_tables);
|
map_4k_phys_to_virt(physical + 4096*i, virt + 4096*i, page_directory, page_tables);
|
||||||
}
|
}
|
||||||
|
|
||||||
void unmap_4k_virt(uint32_t virtual, PDE* page_directory, PTE** page_tables) {
|
void unmap_4k_virt(uint32_t virt, PDE* page_directory, PTE** page_tables) {
|
||||||
split_addr* split = (split_addr*)&virtual;
|
split_addr* split = (split_addr*)&virt;
|
||||||
|
|
||||||
((PTE*)((uint32_t)page_tables[split->pd_index] + 0xbffe0000))[split->pt_index] = (PTE){
|
((PTE*)((uint32_t)page_tables[split->pd_index] + 0xbffe0000))[split->pt_index] = (PTE){
|
||||||
.address = 0,
|
|
||||||
.available = 0,
|
|
||||||
.global = 0,
|
|
||||||
.accessed = 0,
|
|
||||||
.disable_cache = 0,
|
|
||||||
.dirty = 0,
|
|
||||||
.write_through_cache = 0,
|
|
||||||
.privilege = 0,
|
|
||||||
.present = 0,
|
.present = 0,
|
||||||
.read_write = 0,
|
.read_write = 0,
|
||||||
|
.privilege = 0,
|
||||||
.ignored = 0
|
.write_through_cache = 0,
|
||||||
|
.disable_cache = 0,
|
||||||
|
.accessed = 0,
|
||||||
|
.dirty = 0,
|
||||||
|
.ignored = 0,
|
||||||
|
.global = 0,
|
||||||
|
.available = 0,
|
||||||
|
.address = 0
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -4,7 +4,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
typedef struct {
|
struct __attribute__((packed)) PDE {
|
||||||
uint32_t present : 1;
|
uint32_t present : 1;
|
||||||
uint32_t read_write : 1;
|
uint32_t read_write : 1;
|
||||||
uint32_t privilege : 1;
|
uint32_t privilege : 1;
|
||||||
@ -16,9 +16,9 @@ typedef struct {
|
|||||||
uint32_t ignored : 1;
|
uint32_t ignored : 1;
|
||||||
uint32_t available : 3;
|
uint32_t available : 3;
|
||||||
uint32_t address : 20;
|
uint32_t address : 20;
|
||||||
}__attribute__((packed)) PDE;
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct __attribute__((packed)) PTE {
|
||||||
uint32_t present : 1;
|
uint32_t present : 1;
|
||||||
uint32_t read_write : 1;
|
uint32_t read_write : 1;
|
||||||
uint32_t privilege : 1;
|
uint32_t privilege : 1;
|
||||||
@ -30,10 +30,10 @@ typedef struct {
|
|||||||
uint32_t global : 1;
|
uint32_t global : 1;
|
||||||
uint32_t available : 3;
|
uint32_t available : 3;
|
||||||
uint32_t address : 20;
|
uint32_t address : 20;
|
||||||
}__attribute__((packed)) PTE;
|
};
|
||||||
|
|
||||||
void map_4k_phys_to_virt(uint32_t physical, uint32_t virtual, PDE* page_directory, PTE** page_tables);
|
void map_4k_phys_to_virt(uint32_t physical, uint32_t virt, PDE* page_directory, PTE** page_tables);
|
||||||
void map_many_4k_phys_to_virt(uint32_t physical, uint32_t virtual, PDE* page_directory, PTE** page_tables, uint32_t count);
|
void map_many_4k_phys_to_virt(uint32_t physical, uint32_t virt, PDE* page_directory, PTE** page_tables, uint32_t count);
|
||||||
|
|
||||||
void unmap_4k_virt(uint32_t virtual, PDE* page_directory, PTE** page_tables);
|
void unmap_4k_virt(uint32_t virt, PDE* page_directory, PTE** page_tables);
|
||||||
#endif
|
#endif
|
@ -69,7 +69,7 @@ int int_to_decimal(unsigned int number, char* string_buffer) {
|
|||||||
return (index+1);
|
return (index+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
char dec_to_hex[16] = "0123456789abcdef";
|
char dec_to_hex[17] = "0123456789abcdef";
|
||||||
int int_to_hex(unsigned int number, char* string_buffer) {
|
int int_to_hex(unsigned int number, char* string_buffer) {
|
||||||
for (int i=0; i<8; i++)
|
for (int i=0; i<8; i++)
|
||||||
string_buffer[i] = '0';
|
string_buffer[i] = '0';
|
Loading…
x
Reference in New Issue
Block a user