mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Slight cleanup and fixed SSP
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
#include <kernel.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <bitmap.h>
|
||||
|
||||
void* bmap_ptr(bitmap_t* map, size_t bit) {
|
||||
return (void*)(map->membase + bit * BLOCK_SIZE);
|
||||
}
|
||||
|
||||
void bmap_set(bitmap_t* map, size_t bit, int val) {
|
||||
uint32_t* p = (uint32_t*)map->map;
|
||||
if (val) p[bit / 32] |= (1 << (bit % 32));
|
||||
else p[bit / 32] &= ~(1 << (bit % 32));
|
||||
map->used += (val) ? 1 : -1;
|
||||
}
|
||||
|
||||
int bmap_get(bitmap_t* map, size_t bit) {
|
||||
uint32_t* p = (uint32_t*)map->map;
|
||||
return (p[bit / 32] & (1 << (bit % 32))) ? 1 : 0;
|
||||
}
|
||||
|
||||
void bmap_set_area(bitmap_t* map, size_t base, size_t len, int val) {
|
||||
uint32_t align = dceil(base, BLOCK_SIZE);
|
||||
uint32_t count = dceil(len, BLOCK_SIZE);
|
||||
|
||||
while (count-- > 0) bmap_set(map, align++, val);
|
||||
}
|
||||
|
||||
size_t bmap_get_area(bitmap_t* map, size_t len, int val) {
|
||||
if (len == 0) return BMAP_NOT_FOUND;
|
||||
|
||||
uint32_t found = 0;
|
||||
for (size_t i = 0; i < map->blocks; i++) {
|
||||
if (bmap_get(map, i) == val) found++;
|
||||
else found = 0;
|
||||
|
||||
if (found >= len) return i - found + 1;
|
||||
}
|
||||
|
||||
return BMAP_NOT_FOUND;
|
||||
}
|
||||
|
||||
void bmap_set_all(bitmap_t* map, int val) {
|
||||
uint8_t b = (val) ? 0xff : 0;
|
||||
for (size_t i = 0; i < map->bytes; i++) ((uint8_t*)map->map)[i] = b;
|
||||
if (val) map->used = map->blocks;
|
||||
else map->used = 0;
|
||||
}
|
||||
|
||||
+4
-14
@@ -1,15 +1,13 @@
|
||||
#include <bootloader.h>
|
||||
#include <kernel.h>
|
||||
#include <limine.h>
|
||||
#include <paging.h>
|
||||
#include <serial.h>
|
||||
#include <splash.h>
|
||||
#include <system.h>
|
||||
#include <timer.h>
|
||||
#include <gdt.h>
|
||||
#include <idt.h>
|
||||
#include <isr.h>
|
||||
#include <pmm.h>
|
||||
#include <isr.h>
|
||||
|
||||
#include <kernel.h>
|
||||
|
||||
__noreturn
|
||||
void _start(void) {
|
||||
@@ -35,16 +33,8 @@ void _start(void) {
|
||||
// Memory management
|
||||
if (pmm_init() != 0) panic("Failed to initalize Physical Memory Manager.");
|
||||
if (pag_init() != 0) panic("Failed to initalize Paging.");
|
||||
//if (kmalloc_init() != 0) panic("Failed to initialize kernel heap.");
|
||||
|
||||
// Tasking
|
||||
//if (timer_init() != 0) panic("Failed to initialize timer.");
|
||||
//if (syscall_init() != 0) panic("Failed to initialize syscalls.");
|
||||
//if (task_init() != 0) panic("Failed to initialize tasking.");
|
||||
|
||||
// TODO: Load & run /sbin/init
|
||||
|
||||
// We don't want to halt
|
||||
// Patiently wait for things to do :)
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
#include <kernel.h>
|
||||
#include <system.h>
|
||||
//#include <sched.h>
|
||||
#include <isr.h>
|
||||
|
||||
#include <timer.h>
|
||||
|
||||
size_t timer_ticks = 0;
|
||||
|
||||
int timer_init(void) {
|
||||
// TODO: Check what timer we can use and select the best one
|
||||
return pit_init();
|
||||
}
|
||||
|
||||
void timer_wait(size_t t) {
|
||||
size_t req = timer_ticks + t;
|
||||
while (req != timer_ticks);
|
||||
}
|
||||
|
||||
int pit_init(void) {
|
||||
isr_register(0, pit_handler);
|
||||
pit_phase(0, 2, TIMER_FREQ);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pit_phase(uint8_t ch, uint8_t mode, uint32_t hz) {
|
||||
if (ch > 2 || mode > 7) return;
|
||||
|
||||
cli();
|
||||
|
||||
outb(PIT_CMD, ((ch << 6) | (3 << 4) | (mode << 1)));
|
||||
|
||||
uint32_t div = PIT_DIV / hz;
|
||||
outb(PIT_CH0 + ch, div & 0xFF);
|
||||
outb(PIT_CH0 + ch, div >> 8);
|
||||
debugf("[pit] Set PIT divisor to %d (%d Hz).\n", div, hz);
|
||||
|
||||
sti();
|
||||
}
|
||||
|
||||
void pit_handler(struct isr_int_frame* iframe) {
|
||||
(void)iframe; // We must take it as an argument even if we don't use it
|
||||
timer_ticks++;
|
||||
|
||||
// TODO: This assumes the timer is at 1000 Hz
|
||||
//if (timer_ticks % SCHED_QUANTUM == 0) schedule();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user