small fixes

This commit is contained in:
Benji Dial 2020-09-06 01:26:56 -04:00
parent e8c6577617
commit cbc85f6e89
9 changed files with 16 additions and 15 deletions

View file

@ -1,9 +1,8 @@
target remote | qemu-system-i386 -m 768 -S -gdb stdio out/disk.img target remote | qemu-system-i386 -m 512 -S -gdb stdio out/disk.img
add-symbol-file obj/kernel.elf add-symbol-file obj/kernel.elf
add-symbol-file obj/init.elf add-symbol-file obj/init.elf
set disassembly-flavor intel set disassembly-flavor intel
layout reg layout reg
break main break main
break panic break panic
break _before_start_task
cont cont

View file

@ -70,9 +70,7 @@ static char sc_get_key() {
} }
static void *sc_allocate_ram(uint32_t pages) { static void *sc_allocate_ram(uint32_t pages) {
//switch_to_kernel_cr3(); return pd_user_allocate_anywhere_writable(active_task->page_directory, pages);
void *result = pd_user_allocate_anywhere_writable(active_task->page_directory, pages);
//switch_to_task_cr3();
} }
void const *syscall_table[] = { void const *syscall_table[] = {
@ -90,7 +88,7 @@ extern void syscall_isr;
extern void quit_isr; extern void quit_isr;
extern void yield_isr; extern void yield_isr;
void register_int(uint8_t n, void *isr, uint8_t dpl) { static void register_int(uint8_t n, void *isr, uint8_t dpl) {
idt[n].addr_low = (uint32_t)isr & 0xffff; idt[n].addr_low = (uint32_t)isr & 0xffff;
idt[n].addr_high = (uint32_t)isr >> 16; idt[n].addr_high = (uint32_t)isr >> 16;
idt[n].cs = 0x10; idt[n].cs = 0x10;

View file

@ -4,6 +4,5 @@
#include <stdint.h> #include <stdint.h>
void init_idt(); void init_idt();
void enable_idt();
#endif #endif

View file

@ -86,6 +86,9 @@ _before_start_task:
iret iret
_start_user_mode: _start_user_mode:
mov ax, 0x2b
mov ds, ax
push dword 0x2b push dword 0x2b
sub esp, 4 sub esp, 4
push dword 0x00000200;interrupt flag push dword 0x00000200;interrupt flag

View file

@ -4,7 +4,7 @@
#define INFO_COM COM1 #define INFO_COM COM1
void init_log() { void init_log() {
vga_set_color(0x2f); vga_set_color(0x30);
vga_blank(); vga_blank();
} }

View file

@ -12,6 +12,7 @@
#include "pci.h" #include "pci.h"
#include "log.h" #include "log.h"
#include "elf.h" #include "elf.h"
#include "vga.h"
void reset_tree(); void reset_tree();
void tree(struct drive *d); void tree(struct drive *d);
@ -143,9 +144,8 @@ void main() {
logsz(nbuf); logsz(nbuf);
logsz("k user memory free.\n"); logsz("k user memory free.\n");
//while (1)
// asm ("hlt");
init_idt(); init_idt();
vga_set_color(0x07);
_start_user_mode(); _start_user_mode();
} }

View file

@ -45,7 +45,8 @@ void pd_map(void *pd, uint32_t physical_addr, uint32_t virtual_addr, bool writab
((uint32_t *)(*ptp & PE_ADDR_MASK))[(virtual_addr >> 12) % 1024] = physical_addr | PE_USER | PE_PRESENT | (PE_WRITABLE * writable); ((uint32_t *)(*ptp & PE_ADDR_MASK))[(virtual_addr >> 12) % 1024] = physical_addr | PE_USER | PE_PRESENT | (PE_WRITABLE * writable);
} }
bool pd_is_mapped(void *pd, uint32_t vma) { __attribute__ ((pure))
static bool pd_is_mapped(void *pd, uint32_t vma) {
uint32_t pde = ((uint32_t *)pd)[vma >> 22]; uint32_t pde = ((uint32_t *)pd)[vma >> 22];
return (pde & PE_PRESENT) && (((uint32_t *)(pde & PE_ADDR_MASK))[(vma >> 12) % 1024] & PE_PRESENT); return (pde & PE_PRESENT) && (((uint32_t *)(pde & PE_ADDR_MASK))[(vma >> 12) % 1024] & PE_PRESENT);
} }
@ -85,7 +86,7 @@ void *pd_user_allocate(void *pd, uint32_t vma, uint32_t pages, bool writable) {
void *pd_user_allocate_anywhere_writable(void *pd, uint32_t pages) { void *pd_user_allocate_anywhere_writable(void *pd, uint32_t pages) {
uint32_t run = 0; uint32_t run = 0;
for (void *vma = (void *)KERNEL_END; vma; vma += 4096) { for (void *vma = (void *)KERNEL_END; vma; vma += 4096) {
if (pd_is_mapped(pd, vma)) if (pd_is_mapped(pd, (uint32_t)vma))
run = 0; run = 0;
else if (++run == pages) { else if (++run == pages) {
vma -= (pages - 1) * 4096; vma -= (pages - 1) * 4096;
@ -94,6 +95,7 @@ void *pd_user_allocate_anywhere_writable(void *pd, uint32_t pages) {
return vma; return vma;
} }
} }
return 0;
} }
#define KPAGE_DIR ((uint32_t *)0x00005000) #define KPAGE_DIR ((uint32_t *)0x00005000)

View file

@ -6,7 +6,6 @@ void init_paging();
void *new_pd(); void *new_pd();
void free_pd(void *pd); void free_pd(void *pd);
void pd_map(void *pd, uint32_t physical_addr, uint32_t virtual_addr, bool writable); void pd_map(void *pd, uint32_t physical_addr, uint32_t virtual_addr, bool writable);
void switch_pd(void *pd);
void free_task_pd(void *pd); void free_task_pd(void *pd);
void *new_task_pd(); void *new_task_pd();

View file

@ -1,6 +1,7 @@
#include "panic.h" #include "panic.h"
#include "task.h" #include "task.h"
#include "paging.h" #include "paging.h"
#include "log.h"
struct tss { struct tss {
struct tss *prev; struct tss *prev;
@ -41,7 +42,7 @@ struct tss {
#define MAX_TASKS 64 #define MAX_TASKS 64
struct task_state tasks[MAX_TASKS]; static struct task_state tasks[MAX_TASKS];
struct task_state *active_task; struct task_state *active_task;
void init_tasks() { void init_tasks() {