core: change types from uint32_t to u32 (e.g)
This commit is contained in:
@ -13,8 +13,8 @@
|
||||
#define PIT_COUNT (65535 / 2)
|
||||
#define DELAY (1000 / (PIT_FREQUENCY / PIT_COUNT))
|
||||
|
||||
static uint32_t sleep_counter;
|
||||
static uint32_t scheduler_counter;
|
||||
static u32 sleep_counter;
|
||||
static u32 scheduler_counter;
|
||||
|
||||
static void clock_handler(struct registers *regs);
|
||||
|
||||
@ -38,7 +38,7 @@ void clock_init(struct registers *regs)
|
||||
static void clock_handler(struct registers *regs)
|
||||
{
|
||||
(void)regs;
|
||||
if (scheduler_counter % 10 == 0) {
|
||||
if (scheduler_counter % 100 == 0) {
|
||||
cli();
|
||||
scheduler();
|
||||
sti();
|
||||
@ -47,7 +47,7 @@ static void clock_handler(struct registers *regs)
|
||||
sleep_counter--;
|
||||
}
|
||||
|
||||
void sleep(uint64_t delay)
|
||||
void sleep(u64 delay)
|
||||
{
|
||||
sleep_counter = delay / DELAY;
|
||||
while (sleep_counter)
|
||||
|
@ -3,17 +3,17 @@
|
||||
|
||||
struct vbe_interface display;
|
||||
|
||||
void put_pixel(uint32_t color, uint32_t x, uint32_t y)
|
||||
void put_pixel(u32 color, u32 x, u32 y)
|
||||
{
|
||||
// divide by 4 because display.buff is in 32bit instead of 8bit
|
||||
const uint32_t coords = x + y * display.pitch / 4;
|
||||
const u32 coords = x + y * display.pitch / 4;
|
||||
display.buff[coords] = color;
|
||||
}
|
||||
|
||||
void draw_icon(uint32_t pos_x, uint32_t pos_y, struct icon *img)
|
||||
void draw_icon(u32 pos_x, u32 pos_y, struct icon *img)
|
||||
{
|
||||
for (uint32_t y = 0; y < img->height; y++) {
|
||||
for (uint32_t x = 0; x < img->width; x++) {
|
||||
for (u32 y = 0; y < img->height; y++) {
|
||||
for (u32 x = 0; x < img->width; x++) {
|
||||
put_pixel(img->pixels[y * img->width + x], pos_x + x,
|
||||
pos_y + y);
|
||||
}
|
||||
|
@ -3,14 +3,14 @@
|
||||
#include "gdt.h"
|
||||
#include "kprintf.h"
|
||||
|
||||
extern void set_gdt(uint32_t gdt_ptr);
|
||||
extern void set_gdt(u32 gdt_ptr);
|
||||
|
||||
struct tss TSS;
|
||||
uint8_t gdt_entries[GDT_SIZE * 8];
|
||||
u8 gdt_entries[GDT_SIZE * 8];
|
||||
struct gdt_descriptor gdtr;
|
||||
|
||||
static void set_gdt_entry_value(uint8_t *target, uint32_t base, uint32_t limit,
|
||||
uint8_t access, uint8_t granularity)
|
||||
static void set_gdt_entry_value(u8 *target, u32 base, u32 limit,
|
||||
u8 access, u8 granularity)
|
||||
{
|
||||
if (limit > 0xFFFFF) {
|
||||
kprintf(KERN_ERR
|
||||
@ -38,7 +38,7 @@ static void set_gdt_entry_value(uint8_t *target, uint32_t base, uint32_t limit,
|
||||
void init_gdt(void)
|
||||
{
|
||||
gdtr.size = 8 * GDT_SIZE - 1;
|
||||
gdtr.base = (uint32_t)&gdt_entries[0];
|
||||
gdtr.base = (u32)&gdt_entries[0];
|
||||
|
||||
set_gdt_entry_value(gdt_entries + 0x00, 0, 0, 0, 0); // Null segment
|
||||
|
||||
@ -92,8 +92,8 @@ void init_gdt(void)
|
||||
GDT_ACCESS_A_ACCESSED,
|
||||
GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // User stack
|
||||
// TSS
|
||||
set_gdt_entry_value(gdt_entries + GDT_OFFSET_TSS, (uint32_t)&TSS,
|
||||
set_gdt_entry_value(gdt_entries + GDT_OFFSET_TSS, (u32)&TSS,
|
||||
sizeof(struct tss) - 1, 0x89, 0);
|
||||
|
||||
set_gdt(((uint32_t)&gdtr));
|
||||
set_gdt(((u32)&gdtr));
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ static isr_t interrupt_handlers[16];
|
||||
|
||||
void isr_handler(struct registers *regs)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
u8 i = 0;
|
||||
while (i < ARRAY_SIZE(faults)) {
|
||||
if (i == regs->int_no)
|
||||
kpanic("interrupt: %s\n", faults[i]);
|
||||
|
@ -21,27 +21,27 @@ static struct idt_descriptor idtr;
|
||||
|
||||
void load_idt(struct idt_descriptor *idtr);
|
||||
|
||||
void idt_set_descriptor(uint8_t index, void *isr, uint8_t flags)
|
||||
void idt_set_descriptor(u8 index, void *isr, u8 flags)
|
||||
{
|
||||
struct idt_entry *descriptor = &idt_entries[index];
|
||||
|
||||
descriptor->isr_low = (uint32_t)isr & 0xFFFF;
|
||||
descriptor->isr_low = (u32)isr & 0xFFFF;
|
||||
descriptor->kernel_cs = GDT_OFFSET_KERNEL_CODE;
|
||||
descriptor->attributes = flags;
|
||||
descriptor->isr_high = (uint32_t)isr >> 16;
|
||||
descriptor->isr_high = (u32)isr >> 16;
|
||||
descriptor->reserved = 0;
|
||||
}
|
||||
|
||||
void init_idt(void)
|
||||
{
|
||||
idtr.offset = (uintptr_t)&idt_entries[0];
|
||||
idtr.size = (uint16_t)sizeof(struct idt_entry) * IDT_SIZE - 1;
|
||||
idtr.size = (u16)sizeof(struct idt_entry) * IDT_SIZE - 1;
|
||||
|
||||
uint8_t i;
|
||||
u8 i;
|
||||
for (i = 0; i < 32; i++)
|
||||
idt_set_descriptor(i, isr_stub_table[i], 0x8E);
|
||||
pic_remap(0x20, 0x28);
|
||||
for (uint8_t j = 0; j < 16; j++)
|
||||
for (u8 j = 0; j < 16; j++)
|
||||
idt_set_descriptor(i + j, irq_stub_table[j], 0x8E);
|
||||
load_idt(&idtr);
|
||||
__asm__ volatile("sti");
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include "types.h"
|
||||
#include <cpuid.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
const uint32_t CPUID_FLAG_MSR = 1 << 5;
|
||||
const u32 CPUID_FLAG_MSR = 1 << 5;
|
||||
|
||||
bool cpu_has_msr()
|
||||
{
|
||||
@ -11,12 +12,12 @@ bool cpu_has_msr()
|
||||
return edx & CPUID_FLAG_MSR;
|
||||
}
|
||||
|
||||
void cpu_get_msr(uint32_t msr, uint32_t *lo, uint32_t *hi)
|
||||
void cpu_get_msr(u32 msr, u32 *lo, u32 *hi)
|
||||
{
|
||||
asm volatile("rdmsr" : "=a"(*lo), "=d"(*hi) : "c"(msr));
|
||||
}
|
||||
|
||||
void cpu_set_msr(uint32_t msr, uint32_t lo, uint32_t hi)
|
||||
void cpu_set_msr(u32 msr, u32 lo, u32 hi)
|
||||
{
|
||||
asm volatile("wrmsr" : : "a"(lo), "d"(hi), "c"(msr));
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
void pic_remap(int offset_master, int offset_slave)
|
||||
{
|
||||
uint8_t a1, a2;
|
||||
u8 a1, a2;
|
||||
|
||||
a1 = inb(PIC1_DATA); // save masks
|
||||
a2 = inb(PIC2_DATA);
|
||||
@ -56,7 +56,7 @@ void pic_remap(int offset_master, int offset_slave)
|
||||
outb(PIC2_DATA, a2);
|
||||
}
|
||||
|
||||
void pic_send_eoi(uint8_t irq)
|
||||
void pic_send_eoi(u8 irq)
|
||||
{
|
||||
if (irq >= 8)
|
||||
outb(PIC2_COMMAND, PIC_EOI);
|
||||
|
14
src/kernel.c
14
src/kernel.c
@ -38,17 +38,16 @@ static void uwu(void)
|
||||
static void owo(void)
|
||||
{
|
||||
while (true)
|
||||
kprintf("owo\n");
|
||||
kprintf("owoooooooooooooooooooooooooooooooooooo\n");
|
||||
}
|
||||
|
||||
static void awa(void)
|
||||
{
|
||||
kprintf("awa\n");
|
||||
while (true)
|
||||
;
|
||||
kprintf("awaille\n");
|
||||
}
|
||||
|
||||
void kernel_main(multiboot_info_t *mbd, uint32_t magic)
|
||||
void kernel_main(multiboot_info_t *mbd, u32 magic)
|
||||
{
|
||||
terminal_initialize();
|
||||
init_gdt();
|
||||
@ -62,9 +61,10 @@ void kernel_main(multiboot_info_t *mbd, uint32_t magic)
|
||||
*/
|
||||
/* "Martin 03:50, 22 March 2009 (UTC)\n"); */
|
||||
create_kernel_task();
|
||||
exec_fn(owo);
|
||||
exec_fn(awa);
|
||||
exec_fn(awa);
|
||||
exec_fn(awa);
|
||||
exec_fn(awa);
|
||||
/* exec_fn(owo); */
|
||||
/* exec_fn(owo); */
|
||||
/* exec_fn(owo); */
|
||||
shell_init();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "power.h"
|
||||
#include "terminal.h"
|
||||
|
||||
extern uint32_t page_table1[1024];
|
||||
extern u32 page_table1[1024];
|
||||
|
||||
__attribute__((noreturn)) void kpanic(const char *format, ...)
|
||||
{
|
||||
@ -17,7 +17,7 @@ __attribute__((noreturn)) void kpanic(const char *format, ...)
|
||||
va_start(va, format);
|
||||
kvprintf(format, &va);
|
||||
va_end(va);
|
||||
uint32_t faulting_address;
|
||||
u32 faulting_address;
|
||||
__asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address));
|
||||
kprintf("fault at address: %p\n", faulting_address);
|
||||
/* for (int i = 16; i < 32; i++) */
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int print_int_base(int64_t number, const char *prefix, const char *base);
|
||||
int print_int_base(i64 number, const char *prefix, const char *base);
|
||||
|
||||
static int get_level(const char *str)
|
||||
{
|
||||
@ -20,19 +20,19 @@ static int print_flag(char flag, va_list *ap)
|
||||
case '%':
|
||||
return terminal_putchar('%');
|
||||
case 'i':
|
||||
return print_int_base(va_arg(*ap, int32_t), NULL, BASE_DECA);
|
||||
return print_int_base(va_arg(*ap, i32), NULL, BASE_DECA);
|
||||
case 'd':
|
||||
return print_int_base(va_arg(*ap, int32_t), NULL, BASE_DECA);
|
||||
return print_int_base(va_arg(*ap, i32), NULL, BASE_DECA);
|
||||
case 'c':
|
||||
return terminal_putchar(va_arg(*ap, int));
|
||||
case 's':
|
||||
return terminal_writestring(va_arg(*ap, char *));
|
||||
case 'p':
|
||||
return print_int_base(va_arg(*ap, uint32_t), "0x", BASE_HEXA);
|
||||
return print_int_base(va_arg(*ap, u32), "0x", BASE_HEXA);
|
||||
case 'x':
|
||||
return print_int_base(va_arg(*ap, int32_t), "0x", BASE_HEXA);
|
||||
return print_int_base(va_arg(*ap, i32), "0x", BASE_HEXA);
|
||||
case 'u':
|
||||
return print_int_base(va_arg(*ap, uint32_t), NULL, BASE_DECA);
|
||||
return print_int_base(va_arg(*ap, u32), NULL, BASE_DECA);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -3,11 +3,11 @@
|
||||
#include "string.h"
|
||||
#include "terminal.h"
|
||||
|
||||
int print_int_base(int64_t number, const char *prefix, const char *base)
|
||||
int print_int_base(i64 number, const char *prefix, const char *base)
|
||||
{
|
||||
const int base_size = strlen(base);
|
||||
uint64_t div = 1;
|
||||
uint32_t tmp;
|
||||
u64 div = 1;
|
||||
u32 tmp;
|
||||
int rv = 0;
|
||||
|
||||
if (prefix)
|
||||
|
@ -34,7 +34,7 @@ int free_frame(void *frame_ptr)
|
||||
frame_ptr >= it->addr + it->total_frames * PAGE_SIZE))
|
||||
it = it->next;
|
||||
|
||||
uint32_t index = ((frame_ptr - it->addr) / PAGE_SIZE);
|
||||
u32 index = ((frame_ptr - it->addr) / PAGE_SIZE);
|
||||
SET_FRAME(it->frame_table, index, 0);
|
||||
if (it->first_free_frame > index)
|
||||
it->first_free_frame = index;
|
||||
|
@ -4,10 +4,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t *page_directory = &boot_page_directory;
|
||||
uint32_t page_table_default[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||
uint32_t frame_zones_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||
uint32_t mem_size;
|
||||
u32 *page_directory = &boot_page_directory;
|
||||
u32 page_table_default[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||
u32 frame_zones_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||
u32 mem_size;
|
||||
struct frame_zone *head;
|
||||
|
||||
static void lst_add_back(struct frame_zone **root, struct frame_zone *element)
|
||||
@ -24,16 +24,16 @@ static void lst_add_back(struct frame_zone **root, struct frame_zone *element)
|
||||
|
||||
static void add_frame_node(multiboot_memory_map_t *mmmt)
|
||||
{
|
||||
static uint32_t index;
|
||||
static u32 index;
|
||||
|
||||
/**
|
||||
* # = kernel code
|
||||
* - = blank
|
||||
*/
|
||||
|
||||
uint64_t start_addr = mmmt->addr;
|
||||
uint64_t end_addr = mmmt->addr + mmmt->len;
|
||||
uint64_t len = mmmt->len;
|
||||
u64 start_addr = mmmt->addr;
|
||||
u64 end_addr = mmmt->addr + mmmt->len;
|
||||
u64 len = mmmt->len;
|
||||
|
||||
/** Kernel code cover all the block
|
||||
* this situation:
|
||||
@ -62,21 +62,21 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
|
||||
|
||||
init_page_table(frame_zones_page_table, 0);
|
||||
page_directory[1022] =
|
||||
((uint32_t)frame_zones_page_table - HEAP_END) | 0x03;
|
||||
((u32)frame_zones_page_table - HEAP_END) | 0x03;
|
||||
frame_zones_page_table[index] =
|
||||
((uint32_t)start_addr & PAGE_MASK) | INIT_FLAGS;
|
||||
((u32)start_addr & PAGE_MASK) | INIT_FLAGS;
|
||||
|
||||
struct frame_zone *current =
|
||||
(struct frame_zone *)GET_PAGE_ADDR(1022, index++);
|
||||
|
||||
current->frame_table = (uint8_t *)current + sizeof(struct frame_zone);
|
||||
current->frame_table = (u8 *)current + sizeof(struct frame_zone);
|
||||
|
||||
/** 8 is cause we are using uint8_t
|
||||
/** 8 is cause we are using u8
|
||||
nb_frame = size / (PAGE_SIZE + 1 / 8)
|
||||
cause we are using non decimal number
|
||||
nb_frame = ((size * 8) / (PAGE_SIZE * 8 + 1))
|
||||
*/
|
||||
const uint32_t nb_frame = ((len * 8) / (PAGE_SIZE * 8 + 1));
|
||||
const u32 nb_frame = ((len * 8) / (PAGE_SIZE * 8 + 1));
|
||||
current->first_free_frame = 0;
|
||||
current->next = NULL;
|
||||
current->remaining_frames = nb_frame;
|
||||
@ -85,10 +85,10 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
|
||||
memset(current->frame_table, 0,
|
||||
nb_frame * sizeof(*current->frame_table));
|
||||
|
||||
uint32_t i = 1;
|
||||
u32 i = 1;
|
||||
for (; i < CEIL(nb_frame, PAGE_SIZE); i++)
|
||||
frame_zones_page_table[index + i] =
|
||||
((uint32_t)(start_addr + i * PAGE_SIZE) & PAGE_MASK) |
|
||||
((u32)(start_addr + i * PAGE_SIZE) & PAGE_MASK) |
|
||||
INIT_FLAGS;
|
||||
current->addr = (void *)start_addr + i * PAGE_SIZE;
|
||||
index += i - 1;
|
||||
@ -97,7 +97,7 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
|
||||
|
||||
static void init_frame_zones(void)
|
||||
{
|
||||
for (uint32_t i = 0; i < mmap_length; i++) {
|
||||
for (u32 i = 0; i < mmap_length; i++) {
|
||||
multiboot_memory_map_t *mmmt =
|
||||
(multiboot_memory_map_t *)mmap_addr + i;
|
||||
if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE)
|
||||
@ -105,12 +105,12 @@ static void init_frame_zones(void)
|
||||
}
|
||||
}
|
||||
|
||||
void init_memory(multiboot_info_t *mbd, uint32_t magic)
|
||||
void init_memory(multiboot_info_t *mbd, u32 magic)
|
||||
{
|
||||
for (uint16_t i = 0; i < 0x300; i++)
|
||||
for (u16 i = 0; i < 0x300; i++)
|
||||
page_directory[i] = 0x02;
|
||||
init_page_table(page_table_default, 0);
|
||||
page_directory[0] = ((uint32_t)page_table_default - HEAP_END) | 0x03;
|
||||
page_directory[0] = ((u32)page_table_default - HEAP_END) | 0x03;
|
||||
init_multiboot(mbd, magic);
|
||||
init_frame_zones();
|
||||
}
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include "string.h"
|
||||
#include "utils.h"
|
||||
|
||||
static int16_t find_next_block(size_t nb_pages, uint16_t *pd_index_ptr,
|
||||
uint32_t **page_table_ptr)
|
||||
static i16 find_next_block(size_t nb_pages, u16 *pd_index_ptr,
|
||||
u32 **page_table_ptr)
|
||||
{
|
||||
for (*pd_index_ptr = 1; *pd_index_ptr < 768; (*pd_index_ptr)++) {
|
||||
if (page_directory[(*pd_index_ptr)] == 0x02) {
|
||||
@ -17,9 +17,9 @@ static int16_t find_next_block(size_t nb_pages, uint16_t *pd_index_ptr,
|
||||
return -2;
|
||||
}
|
||||
*page_table_ptr =
|
||||
(uint32_t *)GET_PAGE_ADDR(0, *pd_index_ptr + PT_START);
|
||||
for (uint16_t i = 0; i + nb_pages - 1 < PT_SIZE; i++) {
|
||||
uint16_t j;
|
||||
(u32 *)GET_PAGE_ADDR(0, *pd_index_ptr + PT_START);
|
||||
for (u16 i = 0; i + nb_pages - 1 < PT_SIZE; i++) {
|
||||
u16 j;
|
||||
for (j = 0; (*page_table_ptr)[i + j] >> 12 == i + j &&
|
||||
j < nb_pages;
|
||||
j++)
|
||||
@ -32,12 +32,26 @@ static int16_t find_next_block(size_t nb_pages, uint16_t *pd_index_ptr,
|
||||
return -1;
|
||||
}
|
||||
|
||||
i8 add_single_page(void *frame)
|
||||
{
|
||||
u16 pd_index;
|
||||
u32 *page_table;
|
||||
const i16 i = find_next_block(1, &pd_index, &page_table);
|
||||
|
||||
if (i < 0) {
|
||||
kprintf(KERN_CRIT "impossible to add page to page directory\n");
|
||||
return -1;
|
||||
}
|
||||
page_table[i] = ((u32)frame & PAGE_MASK) | INIT_FLAGS;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *alloc_pages(size_t size, void **phys_addr)
|
||||
{
|
||||
const uint32_t nb_pages = CEIL(size, PAGE_SIZE);
|
||||
uint16_t pd_index;
|
||||
uint32_t *page_table;
|
||||
const int16_t index = find_next_block(nb_pages, &pd_index, &page_table);
|
||||
const u32 nb_pages = CEIL(size, PAGE_SIZE);
|
||||
u16 pd_index;
|
||||
u32 *page_table;
|
||||
const i16 index = find_next_block(nb_pages, &pd_index, &page_table);
|
||||
|
||||
if (index < 0) {
|
||||
kprintf(KERN_CRIT "%d: Not enough pages (max: %d)\n", index,
|
||||
@ -53,7 +67,7 @@ void *alloc_pages(size_t size, void **phys_addr)
|
||||
}
|
||||
if (phys_addr)
|
||||
*phys_addr = frame;
|
||||
page_table[i] = ((uint32_t)frame & PAGE_MASK) | INIT_FLAGS;
|
||||
page_table[i] = ((u32)frame & PAGE_MASK) | INIT_FLAGS;
|
||||
}
|
||||
memset((void *)GET_PAGE_ADDR(pd_index, index), 0, nb_pages * PAGE_SIZE);
|
||||
return (void *)GET_PAGE_ADDR(pd_index, index);
|
||||
@ -61,13 +75,13 @@ void *alloc_pages(size_t size, void **phys_addr)
|
||||
|
||||
int free_pages(void *page_ptr, size_t size)
|
||||
{
|
||||
const uint32_t page_addr = (uint32_t)page_ptr;
|
||||
const uint32_t nb_pages = CEIL(size, PAGE_SIZE);
|
||||
const uint32_t page_index = page_addr / PAGE_SIZE;
|
||||
const uint32_t pd_index = page_index / PD_SIZE;
|
||||
const uint32_t pt_index = page_index % PD_SIZE;
|
||||
const u32 page_addr = (u32)page_ptr;
|
||||
const u32 nb_pages = CEIL(size, PAGE_SIZE);
|
||||
const u32 page_index = page_addr / PAGE_SIZE;
|
||||
const u32 pd_index = page_index / PD_SIZE;
|
||||
const u32 pt_index = page_index % PD_SIZE;
|
||||
|
||||
if ((uint32_t)pd_index > 0x300) {
|
||||
if ((u32)pd_index > 0x300) {
|
||||
kprintf(KERN_WARNING "Address out of range\n");
|
||||
return -1;
|
||||
} else if (page_addr % PAGE_SIZE) {
|
||||
@ -77,9 +91,9 @@ int free_pages(void *page_ptr, size_t size)
|
||||
kprintf(KERN_WARNING "Invalid number of frames\n");
|
||||
return -1;
|
||||
}
|
||||
uint32_t *page_table =
|
||||
(uint32_t *)GET_PAGE_ADDR(0, PT_START + pd_index);
|
||||
for (uint16_t i = pt_index; i < pt_index + nb_pages; i++) {
|
||||
u32 *page_table =
|
||||
(u32 *)GET_PAGE_ADDR(0, PT_START + pd_index);
|
||||
for (u16 i = pt_index; i < pt_index + nb_pages; i++) {
|
||||
if (page_table[i] >> 12 == i) {
|
||||
kprintf(KERN_WARNING "Page already free\n");
|
||||
return -2;
|
||||
|
@ -1,22 +1,22 @@
|
||||
#include "debug.h"
|
||||
#include "kprintf.h"
|
||||
#include "memory.h"
|
||||
void init_page_table(uint32_t page_table[1024], uint16_t start)
|
||||
void init_page_table(u32 page_table[1024], u16 start)
|
||||
{
|
||||
for (uint16_t i = start; i < 1024; i++)
|
||||
for (u16 i = start; i < 1024; i++)
|
||||
page_table[i] = (i << 12) | 0x03;
|
||||
}
|
||||
|
||||
int16_t add_page_table(uint16_t pd_index)
|
||||
i16 add_page_table(u16 pd_index)
|
||||
{
|
||||
void *frame = alloc_frame();
|
||||
if (!frame)
|
||||
return -1;
|
||||
page_table_default[PT_START + pd_index] =
|
||||
((uint32_t)frame & PAGE_MASK) | 0x03;
|
||||
uint32_t *page_table =
|
||||
(uint32_t *)GET_PAGE_ADDR(0, PT_START + pd_index);
|
||||
((u32)frame & PAGE_MASK) | 0x03;
|
||||
u32 *page_table =
|
||||
(u32 *)GET_PAGE_ADDR(0, PT_START + pd_index);
|
||||
init_page_table(page_table, 0);
|
||||
page_directory[pd_index] = ((uint32_t)frame & PAGE_MASK) | 0x03;
|
||||
page_directory[pd_index] = ((u32)frame & PAGE_MASK) | 0x03;
|
||||
return 0;
|
||||
}
|
||||
|
@ -17,15 +17,15 @@ static void add_zone(Zone *zone, block_type_t type)
|
||||
zones[type] = zone;
|
||||
}
|
||||
|
||||
static void new_block(Zone *zone, uint32_t zone_size)
|
||||
static void new_block(Zone *zone, u32 zone_size)
|
||||
{
|
||||
Block *new_block = (Block *)align_mem((uint32_t)zone + sizeof(Zone));
|
||||
Block *new_block = (Block *)align_mem((u32)zone + sizeof(Zone));
|
||||
|
||||
// Metadata
|
||||
new_block->in_use = false;
|
||||
new_block->size = zone_size - sizeof(Zone) - sizeof(Block);
|
||||
new_block->sub_size = new_block->size;
|
||||
new_block->ptr = (Block *)((uint32_t)new_block + sizeof(Block));
|
||||
new_block->ptr = (Block *)((u32)new_block + sizeof(Block));
|
||||
new_block->zone = zone;
|
||||
|
||||
// Init future linked lists
|
||||
@ -46,7 +46,7 @@ static void new_block(Zone *zone, uint32_t zone_size)
|
||||
assert(zone->free == new_block);
|
||||
}
|
||||
|
||||
int new_vzone(block_type_t type, uint32_t size)
|
||||
int new_vzone(block_type_t type, u32 size)
|
||||
{
|
||||
void *heap = alloc_pages(size, NULL);
|
||||
if (heap == NULL) {
|
||||
|
@ -8,7 +8,7 @@
|
||||
void show_valloc_mem(void)
|
||||
{
|
||||
char *const zones_name[3] = {"TINY", "SMALL", "LARGE"};
|
||||
uint32_t total_size = 0;
|
||||
u32 total_size = 0;
|
||||
|
||||
for (block_type_t type = 0; type < 3; ++type) {
|
||||
int count = 0;
|
||||
@ -23,7 +23,7 @@ void show_valloc_mem(void)
|
||||
/* i++; */
|
||||
/* if (i < 10) */
|
||||
kprintf("%p - %p : %u bytes\n", block_it->ptr,
|
||||
(uint32_t)block_it->ptr +
|
||||
(u32)block_it->ptr +
|
||||
block_it->sub_size + sizeof(Block),
|
||||
block_it->sub_size);
|
||||
total_size += block_it->sub_size;
|
||||
@ -39,7 +39,7 @@ void show_valloc_mem(void)
|
||||
for (Block *block_it = zone_it->free; block_it != NULL;
|
||||
block_it = block_it->next_free) {
|
||||
kprintf("%p - %p : %u bytes\n", block_it->ptr,
|
||||
(uint32_t)block_it->ptr +
|
||||
(u32)block_it->ptr +
|
||||
block_it->sub_size + sizeof(Block),
|
||||
block_it->sub_size);
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ void vfree(void *ptr)
|
||||
{
|
||||
if (ptr == NULL)
|
||||
return;
|
||||
Block *to_free = (Block *)((uint32_t)ptr - sizeof(Block));
|
||||
Block *to_free = (Block *)((u32)ptr - sizeof(Block));
|
||||
Block *to_merge = NULL;
|
||||
to_free->in_use = false;
|
||||
remove_used(to_free);
|
||||
|
@ -8,7 +8,7 @@
|
||||
* Find first available (not in_use) block
|
||||
* in a zone matching the size we need
|
||||
*/
|
||||
static Block *find_block(Zone *head, uint32_t size)
|
||||
static Block *find_block(Zone *head, u32 size)
|
||||
{
|
||||
for (Zone *zone_it = head; zone_it != NULL; zone_it = zone_it->next) {
|
||||
for (Block *block_it = zone_it->free; block_it != NULL;
|
||||
@ -46,17 +46,17 @@ static Block *find_block(Zone *head, uint32_t size)
|
||||
* We can see that it now has its own metadata and available
|
||||
* data and it points towards [6]
|
||||
*/
|
||||
static void frag_block(Zone *zone, Block *old_block, uint32_t size)
|
||||
static void frag_block(Zone *zone, Block *old_block, u32 size)
|
||||
{
|
||||
Block *new_block = (Block *)align_mem((uint32_t)old_block + size);
|
||||
Block *new_block = (Block *)align_mem((u32)old_block + size);
|
||||
assert(new_block <
|
||||
(Block *)((uint32_t)zone + get_zone_size(zone->type)));
|
||||
(Block *)((u32)zone + get_zone_size(zone->type)));
|
||||
|
||||
// Newly created block metadata
|
||||
new_block->size = old_block->size - align_mem(size);
|
||||
new_block->sub_size = new_block->size;
|
||||
new_block->in_use = false;
|
||||
new_block->ptr = (void *)((uint32_t)new_block + sizeof(Block));
|
||||
new_block->ptr = (void *)((u32)new_block + sizeof(Block));
|
||||
new_block->zone = zone;
|
||||
|
||||
new_block->prev = old_block;
|
||||
@ -120,7 +120,7 @@ static void save_block(Zone *head, Block *block, Zone *zone)
|
||||
*
|
||||
* ptr: returns the aligned pointer of the block (after the metadata)
|
||||
*/
|
||||
void *vmalloc(uint32_t size)
|
||||
void *vmalloc(u32 size)
|
||||
{
|
||||
void *ptr = NULL;
|
||||
|
||||
@ -136,7 +136,7 @@ void *vmalloc(uint32_t size)
|
||||
// Find an available block in a zone of type "type"
|
||||
Block *available = find_block(head, size);
|
||||
if (available == NULL) {
|
||||
uint32_t full_size;
|
||||
u32 full_size;
|
||||
if (type == LARGE)
|
||||
full_size = size + sizeof(Block) + sizeof(Zone);
|
||||
else
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
// Prototype for kfree and vmalloc
|
||||
void kfree(void *ptr);
|
||||
void *vmalloc(uint32_t size);
|
||||
void *vmalloc(u32 size);
|
||||
|
||||
/*
|
||||
* ptr: block to resize (undefined behavior if invalid)
|
||||
@ -18,12 +18,12 @@ void *vmalloc(uint32_t size);
|
||||
*
|
||||
* ptr: returns the aligned pointer of the vreallocated block
|
||||
*/
|
||||
void *vrealloc(void *ptr, uint32_t size)
|
||||
void *vrealloc(void *ptr, u32 size)
|
||||
{
|
||||
void *new_ptr = NULL;
|
||||
if (ptr == NULL)
|
||||
return NULL;
|
||||
Block *block = (Block *)((uint32_t)ptr - sizeof(Block));
|
||||
Block *block = (Block *)((u32)ptr - sizeof(Block));
|
||||
if (block->size >= size) {
|
||||
block->sub_size = size;
|
||||
return (ptr);
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "alloc.h"
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t vsize(void *ptr)
|
||||
u32 vsize(void *ptr)
|
||||
{
|
||||
Block *meta_data = (Block *)((uint32_t)ptr - sizeof(Block));
|
||||
Block *meta_data = (Block *)((u32)ptr - sizeof(Block));
|
||||
|
||||
return meta_data->sub_size;
|
||||
}
|
||||
|
@ -9,21 +9,21 @@
|
||||
#include "utils.h"
|
||||
#include "vbe.h"
|
||||
|
||||
uint32_t multiboot_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||
uint32_t vbe_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||
u32 multiboot_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||
u32 vbe_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||
multiboot_memory_map_t *mmap_addr;
|
||||
multiboot_uint32_t mmap_length;
|
||||
multiboot_u32 mmap_length;
|
||||
|
||||
static void init_mmap(multiboot_info_t *mbd_virt, size_t *pt_index)
|
||||
{
|
||||
// Index mbd->mmap_addr pointers
|
||||
uint32_t i = 0;
|
||||
u32 i = 0;
|
||||
for (; i < mbd_virt->mmap_length; i++)
|
||||
multiboot_page_table[i + *pt_index] =
|
||||
((mbd_virt->mmap_addr + i * PAGE_SIZE) & PAGE_MASK) |
|
||||
INIT_FLAGS;
|
||||
mmap_addr = (multiboot_memory_map_t *)(GET_PAGE_ADDR(1023, *pt_index) +
|
||||
(uint32_t)mbd_virt->mmap_addr %
|
||||
(u32)mbd_virt->mmap_addr %
|
||||
PAGE_SIZE);
|
||||
mmap_length = mbd_virt->mmap_length / sizeof(multiboot_memory_map_t);
|
||||
*pt_index += i;
|
||||
@ -31,15 +31,15 @@ static void init_mmap(multiboot_info_t *mbd_virt, size_t *pt_index)
|
||||
|
||||
static void init_vbe(multiboot_info_t *mbd_virt)
|
||||
{
|
||||
const uint32_t framebuffer_size =
|
||||
const u32 framebuffer_size =
|
||||
mbd_virt->framebuffer_height * mbd_virt->framebuffer_pitch;
|
||||
for (uint32_t i = 0; i < CEIL(framebuffer_size, PAGE_SIZE); i++) {
|
||||
for (u32 i = 0; i < CEIL(framebuffer_size, PAGE_SIZE); i++) {
|
||||
vbe_page_table[i % 1024] =
|
||||
((mbd_virt->framebuffer_addr + i * PAGE_SIZE) & PAGE_MASK) |
|
||||
INIT_FLAGS;
|
||||
}
|
||||
page_directory[800] = ((uint32_t)vbe_page_table - HEAP_END) | 0x03;
|
||||
display.buff = (uint32_t *)GET_PAGE_ADDR(800, 0) +
|
||||
page_directory[800] = ((u32)vbe_page_table - HEAP_END) | 0x03;
|
||||
display.buff = (u32 *)GET_PAGE_ADDR(800, 0) +
|
||||
(mbd_virt->framebuffer_addr % PAGE_SIZE);
|
||||
display.height = mbd_virt->framebuffer_height;
|
||||
display.width = mbd_virt->framebuffer_width;
|
||||
@ -47,24 +47,24 @@ static void init_vbe(multiboot_info_t *mbd_virt)
|
||||
display.bpp = mbd_virt->framebuffer_bpp;
|
||||
}
|
||||
|
||||
void init_multiboot(multiboot_info_t *mbd, uint32_t magic)
|
||||
void init_multiboot(multiboot_info_t *mbd, u32 magic)
|
||||
{
|
||||
if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
|
||||
kpanic("invalid magic number! (git good skill issue)");
|
||||
|
||||
init_page_table(multiboot_page_table, 0);
|
||||
page_directory[1023] =
|
||||
((uint32_t)multiboot_page_table - HEAP_END) | 0x03;
|
||||
((u32)multiboot_page_table - HEAP_END) | 0x03;
|
||||
size_t pt_index = CEIL(
|
||||
(uint32_t)mbd % PAGE_SIZE + sizeof(multiboot_info_t), PAGE_SIZE);
|
||||
(u32)mbd % PAGE_SIZE + sizeof(multiboot_info_t), PAGE_SIZE);
|
||||
|
||||
// Index multiboot_info_t struct
|
||||
for (uint32_t i = 0; i < pt_index; i++)
|
||||
for (u32 i = 0; i < pt_index; i++)
|
||||
multiboot_page_table[i] =
|
||||
(((uint32_t)mbd + PAGE_SIZE * i) & PAGE_MASK) | INIT_FLAGS;
|
||||
(((u32)mbd + PAGE_SIZE * i) & PAGE_MASK) | INIT_FLAGS;
|
||||
multiboot_info_t *mbd_virt =
|
||||
(multiboot_info_t *)(GET_PAGE_ADDR(1023, 0) +
|
||||
(uint32_t)mbd % PAGE_SIZE);
|
||||
(u32)mbd % PAGE_SIZE);
|
||||
init_mmap(mbd_virt, &pt_index);
|
||||
init_vbe(mbd_virt);
|
||||
}
|
||||
|
@ -7,18 +7,18 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t esp_backup;
|
||||
u32 esp_backup;
|
||||
|
||||
static struct task *create_task(uint8_t owner_id)
|
||||
static struct task *create_task(u8 owner_id)
|
||||
{
|
||||
static uint32_t pid = 1;
|
||||
static u32 pid = 1;
|
||||
struct task *new_task = vmalloc(sizeof(struct task));
|
||||
if (!new_task)
|
||||
return NULL;
|
||||
new_task->next = current_task->next;
|
||||
new_task->prev = current_task;
|
||||
current_task->next = new_task;
|
||||
new_task->owner_id = owner_id;
|
||||
new_task->uid = owner_id;
|
||||
new_task->esp0 = alloc_pages(STACK_SIZE, NULL);
|
||||
if (!new_task->esp0) {
|
||||
vfree(new_task);
|
||||
@ -35,13 +35,13 @@ static struct task *create_task(uint8_t owner_id)
|
||||
return new_task;
|
||||
}
|
||||
|
||||
int create_kernel_task(void)
|
||||
i8 create_kernel_task(void)
|
||||
{
|
||||
struct task *new_task = vmalloc(sizeof(struct task));
|
||||
if (!new_task)
|
||||
return -1;
|
||||
new_task->status = RUN;
|
||||
new_task->owner_id = 0;
|
||||
new_task->uid = 0;
|
||||
new_task->pid = 0;
|
||||
new_task->heap = page_directory;
|
||||
new_task->cr3 = page_directory - KERNEL_START;
|
||||
@ -57,7 +57,7 @@ void exec_fn(void (*fn)(void))
|
||||
if (!new_task)
|
||||
kpanic("failed to create new task");
|
||||
new_task->status = RUN;
|
||||
new_task->eip = (uint32_t *)fn;
|
||||
new_task->eip = (u32 *)fn;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
void reboot(void)
|
||||
{
|
||||
uint8_t tmp;
|
||||
u8 tmp;
|
||||
|
||||
__asm__ volatile("cli"); /* disable all interrupts */
|
||||
do {
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "kprintf.h"
|
||||
|
||||
static uint16_t raw_read_register(uint16_t cmos_register)
|
||||
static u16 raw_read_register(u16 cmos_register)
|
||||
{
|
||||
// selecting the register
|
||||
outb(CMOS_ADDRESS, cmos_register);
|
||||
@ -12,19 +12,19 @@ static uint16_t raw_read_register(uint16_t cmos_register)
|
||||
return inb(CMOS_DATA);
|
||||
}
|
||||
|
||||
static uint8_t update_is_in_progress(void)
|
||||
static u8 update_is_in_progress(void)
|
||||
{
|
||||
return raw_read_register(REGISTER_A) & 0x80;
|
||||
}
|
||||
|
||||
static uint16_t read_register(uint16_t cmos_register)
|
||||
static u16 read_register(u16 cmos_register)
|
||||
{
|
||||
while (update_is_in_progress())
|
||||
kprintf("%d\n", update_is_in_progress());
|
||||
return raw_read_register(cmos_register);
|
||||
}
|
||||
|
||||
uint8_t bcd_mode_to_bin(uint8_t value)
|
||||
u8 bcd_mode_to_bin(u8 value)
|
||||
{
|
||||
return (value & 0x0F) + ((value / 16) * 10);
|
||||
}
|
||||
@ -32,7 +32,7 @@ uint8_t bcd_mode_to_bin(uint8_t value)
|
||||
struct rtc_date get_date(void)
|
||||
{
|
||||
struct rtc_date rv = {};
|
||||
uint8_t century;
|
||||
u8 century;
|
||||
|
||||
rv.second = read_register(SECOND_REGISTER);
|
||||
rv.minute = read_register(MINUTE_REGISTER);
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
void color_cmd(char *arg)
|
||||
{
|
||||
uint8_t tmp_color;
|
||||
u8 tmp_color;
|
||||
static const char *colors[] = {
|
||||
"BLACK", "BLUE", "GREEN", "CYAN",
|
||||
"RED", "MAGENTA", "BROWN", "LIGHT_GREY",
|
||||
|
@ -8,7 +8,7 @@ struct key_event terminal_getkey(void)
|
||||
{
|
||||
static bool caps_mode = false;
|
||||
struct key_event ev = {0};
|
||||
uint8_t scan_code;
|
||||
u8 scan_code;
|
||||
|
||||
scan_code = inb(KEYBOARD_PORT);
|
||||
if (scan_code == 0x3A || scan_code == 0x58) {
|
||||
|
@ -42,18 +42,18 @@ void terminal_remove_last_char(void)
|
||||
screen->column = VGA_WIDTH - 1;
|
||||
screen->row--;
|
||||
}
|
||||
uint32_t pos_x = (screen->column) * FONT_WIDTH;
|
||||
uint32_t pos_y = screen->row * FONT_HEIGHT;
|
||||
u32 pos_x = (screen->column) * FONT_WIDTH;
|
||||
u32 pos_y = screen->row * FONT_HEIGHT;
|
||||
|
||||
struct font node = get_font_node(
|
||||
screen->buffer[screen->row * VGA_WIDTH + screen->column]);
|
||||
screen->buffer[screen->row * VGA_WIDTH + screen->column] = '\0';
|
||||
for (uint32_t y = 0; y < node.height; y++) {
|
||||
for (uint32_t x = 0; x < node.width; x++) {
|
||||
for (u32 y = 0; y < node.height; y++) {
|
||||
for (u32 x = 0; x < node.width; x++) {
|
||||
// Current bg is taking too much memory
|
||||
// so we do a black bg for now
|
||||
/* struct icon *bg = screen->background; */
|
||||
/* uint32_t pixel = 0; */
|
||||
/* u32 pixel = 0; */
|
||||
/* if (bg->width > pos_x + x && bg->height > pos_y + y)
|
||||
*/
|
||||
/* pixel = bg->pixels[(pos_y + y) * bg->width + */
|
||||
@ -74,38 +74,38 @@ void terminal_set_screen(int pos)
|
||||
/* kprintf(PROMPT); */
|
||||
}
|
||||
|
||||
void terminal_set_bg_color(uint32_t bg_color)
|
||||
void terminal_set_bg_color(u32 bg_color)
|
||||
{
|
||||
screen->bg_color = bg_color;
|
||||
}
|
||||
|
||||
void terminal_set_fg_color(uint32_t fg_color)
|
||||
void terminal_set_fg_color(u32 fg_color)
|
||||
{
|
||||
screen->fg_color = screen->fg_color;
|
||||
}
|
||||
|
||||
void terminal_set_color(uint32_t fg_color, uint32_t bg_color)
|
||||
void terminal_set_color(u32 fg_color, u32 bg_color)
|
||||
{
|
||||
screen->fg_color = fg_color;
|
||||
screen->bg_color = bg_color;
|
||||
}
|
||||
|
||||
void terminal_set_default_fg_color(uint32_t fg_color)
|
||||
void terminal_set_default_fg_color(u32 fg_color)
|
||||
{
|
||||
screen->default_color = fg_color;
|
||||
}
|
||||
|
||||
uint32_t terminal_get_default_color(void)
|
||||
u32 terminal_get_default_color(void)
|
||||
{
|
||||
return screen->default_color;
|
||||
}
|
||||
|
||||
uint8_t terminal_get_char(int x, int y)
|
||||
u8 terminal_get_char(int x, int y)
|
||||
{
|
||||
return screen->buffer[y * VGA_WIDTH + x];
|
||||
}
|
||||
|
||||
void terminal_putentryat(struct font node, uint32_t fg_color, uint32_t bg_color,
|
||||
void terminal_putentryat(struct font node, u32 fg_color, u32 bg_color,
|
||||
size_t x, size_t y)
|
||||
{
|
||||
char *glyph = node.bitmap;
|
||||
@ -128,8 +128,8 @@ static void terminal_scroll(void)
|
||||
screen->row--;
|
||||
memset(display.buff, 0, display.height * display.pitch);
|
||||
for (size_t i = 0; i < VGA_WIDTH * (VGA_HEIGHT - 1); i++) {
|
||||
const uint32_t x = (i % VGA_WIDTH) * FONT_WIDTH;
|
||||
const uint32_t y = (i / VGA_WIDTH) * FONT_HEIGHT;
|
||||
const u32 x = (i % VGA_WIDTH) * FONT_WIDTH;
|
||||
const u32 y = (i / VGA_WIDTH) * FONT_HEIGHT;
|
||||
screen->buffer[i] = screen->buffer[i + VGA_WIDTH];
|
||||
terminal_putentryat(get_font_node(screen->buffer[i]),
|
||||
screen->fg_color, screen->bg_color, x, y);
|
||||
@ -143,7 +143,7 @@ static void terminal_new_line(void)
|
||||
terminal_scroll();
|
||||
}
|
||||
|
||||
void terminal_change_default_color(uint32_t color)
|
||||
void terminal_change_default_color(u32 color)
|
||||
{
|
||||
// TODO
|
||||
/* terminal_set_color(color); */
|
||||
@ -151,7 +151,7 @@ void terminal_change_default_color(uint32_t color)
|
||||
/* for (size_t x = 0; x < VGA_WIDTH; x++) { */
|
||||
/* const size_t index = y * VGA_WIDTH + x;
|
||||
*/
|
||||
/* uint8_t entry_color =
|
||||
/* u8 entry_color =
|
||||
* get_entry_color(TERM_BUF[index]);
|
||||
*/
|
||||
/* TERM_BUF[index] = vga_entry( */
|
||||
@ -170,7 +170,7 @@ void terminal_change_default_color(uint32_t color)
|
||||
/* screen->color = color; */
|
||||
}
|
||||
|
||||
void terminal_change_default_fg_color(uint32_t fg_color)
|
||||
void terminal_change_default_fg_color(u32 fg_color)
|
||||
{
|
||||
terminal_set_fg_color(fg_color);
|
||||
/* terminal_change_default_color(screen->fg_color); */
|
||||
@ -228,7 +228,7 @@ int terminal_writestring(const char *data)
|
||||
|
||||
void update_cursor(void)
|
||||
{
|
||||
/* uint16_t pos = screen->row * VGA_WIDTH +
|
||||
/* u16 pos = screen->row * VGA_WIDTH +
|
||||
* screen->column; */
|
||||
|
||||
/* outb(0x3D4, 0x0F); */
|
||||
|
Reference in New Issue
Block a user