Memory allocation is now a syscall

This commit is contained in:
pjht 2019-03-17 12:22:00 -05:00
parent d9252649d8
commit bfc3964804
10 changed files with 41 additions and 27 deletions

View File

@ -23,7 +23,7 @@ os.iso: kernel/kernel.elf initrd/*
kernel/kernel.elf: $(OBJ)
i386-elf-ld -T linker.ld -o $@ $^
%.o: %.c h_files
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
%.o: %.asm
@ -32,9 +32,5 @@ kernel/kernel.elf: $(OBJ)
%.o: %.s
i386-elf-as $< -o $@
h_files: cpu/$(PLAT)/memory.h
rm -f cpu/memory.h
cp cpu/$(PLAT)/memory.h cpu/memory.h
clean:
rm -rf $(OBJ) kernel/cstart.o cpu/memory.h os.iso */*.elf iso/boot/initrd.tar

View File

@ -2,6 +2,7 @@
#include "idt.h"
#include "gdt.h"
#include "ports.h"
#include "paging.h"
#include "../halt.h"
#include "../drivers/vga.h"
#include "../tasking.h"
@ -172,6 +173,10 @@ void isr_handler(registers_t r) {
tasking_yield();
} else if (r.eax==2) {
tasking_createTask((void*)r.ebx);
} else if (r.eax==3) {
r.ebx=(uint32_t)alloc_pages(r.ebx);
} else if (r.eax==4) {
alloc_pages_virt(r.ebx,(void*)r.ecx);
}
break;
}

View File

@ -1,10 +0,0 @@
#include "paging.h"
#include <stdint.h>
void* alloc_memory(uint32_t num_blocks) {
return alloc_pages(num_blocks);
}
void alloc_memory_virt(uint32_t num_blocks,void* addr) {
return alloc_pages_virt(num_blocks,addr);
}

View File

@ -1,10 +0,0 @@
#ifndef CPU_MEMORY_H
#define CPU_MEMORY_H
#include <stdint.h>
#define BLK_SZ 4096
void* alloc_memory(uint32_t blocks);
void alloc_memory_virt(uint32_t num_blocks,void* addr);
#endif

View File

@ -3,6 +3,8 @@
#include "paging_helpers.h"
#include "paging.h"
#include "pmem.h"
#include <klog.h>
static uint32_t page_directory[1024] __attribute__((aligned(4096)));
static uint32_t kern_page_tables[NUM_KERN_DIRS*1024] __attribute__((aligned(4096)));
static uint32_t smap_page_tables[2048] __attribute__((aligned(4096)));

View File

@ -10,6 +10,7 @@ push %eax; \
#include "../../libc/stdlib.h"
#include "../../libc/stdio.h"
#include "memory.h"
#include "gdt.h"
#include <stdint.h>
#define STACK_PAGES 2

View File

@ -3,7 +3,6 @@
#include "../drivers/pci.h"
#include "../drivers/serial.h"
#include "../cpu/i386/ports.h"
#include "../cpu/memory.h"
#include "vfs.h"
#include "../fs/devfs.h"
#include "../fs/initrd.h"
@ -11,6 +10,7 @@
#include <stdlib.h>
#include <tasking.h>
#include <string.h>
#include <memory.h>
#include <grub/multiboot.h>
#include "klog.h"
#include "elf.h"

18
libc/memory.c Normal file
View File

@ -0,0 +1,18 @@
#include <stdint.h>
void* alloc_memory(uint32_t num_pages) {
void* address;
asm volatile(" \
mov $3, %%eax; \
int $80; \
":"=b"(address):"b"(num_pages));
return address;
}
void alloc_memory_virt(uint32_t num_pages,void* addr) {
void* address;
asm volatile(" \
mov $3, %%eax; \
int $80; \
"::"b"(num_pages),"c"(addr));
}

11
libc/memory.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef MEMORY_H
#define MEMORY_H
#include <stdint.h>
#define BLK_SZ 4096
void* alloc_memory(uint32_t num_pages);
void alloc_memory_virt(uint32_t num_pages,void* addr);
#endif

View File

@ -1,8 +1,9 @@
#include "../cpu/memory.h"
#include "string.h"
#include "stdlib.h"
#include "math.h"
#include <stdint.h>
#include <memory.h>
#define MAX_BLOCKS 512
typedef struct {