-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,027 additions
and
254 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,4 @@ if [ $? -ne 0 ]; then | |
fi | ||
|
||
# Finally, run the virtual machine. | ||
bochs -f bochs.bxrc; | ||
bochs -f bochsrc.bxrc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
src/kernel/include/kbd_hal.h → src/kernel/include/drivers/kbd_hal.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
#ifndef MOLTAROS_HELPERS_H | ||
#define MOLTAROS_HELPERS_H | ||
|
||
#include <stdio.h> | ||
#include <stdbool.h> | ||
|
||
// Ceiling of integer divison. | ||
#define CEILING(x,y) (((x) + (y) - 1) / (y)) | ||
|
||
// Get rid of annoying compiler warnings | ||
#define UNUSED(x) (__attribute__((__unused__)) x) | ||
|
||
/* | ||
Helper macros for implementations of a bit array, normally used in the kernel for keeping arrays of flags. | ||
*/ | ||
|
||
// Declares a new bit array with the requested size | ||
#define BITMAP_SIZE(idx) CEILING(idx, 32) | ||
|
||
// Set bit | ||
#define BITMAP_SET(arr, idx) (arr[(idx / 32)] |= (1 << (idx % 32))) | ||
|
||
// Get raw value of bit | ||
#define BITMAP_GET(arr, idx) (arr[(idx / 32)] & (1 << (idx % 32))) | ||
|
||
// Get value as 0 (false) or 1 (true) | ||
#define BITMAP_TEST(arr, idx) (!!BIT_ARRAY_GET(arr, idx)) | ||
|
||
// Clear bit | ||
#define BITMAP_CLEAR(arr, idx) (arr[(idx / 32)] &= ~(1 << (idx % 32))) | ||
|
||
#endif /* end MLTAROS_HELPERS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef MOLTAROS_LOGGER_H | ||
#define MOLTAROS_LOGGER_H | ||
|
||
#include <stdio.h> | ||
|
||
#ifndef NDEBUG | ||
#define KLOG(format, ...) printf(format "\n", ##__VA_ARGS__) | ||
#else | ||
#define KLOG(format, ...) | ||
#endif | ||
|
||
|
||
// Kernel Panic which will just print error message and spin | ||
#define KPANIC(format, ...) \ | ||
do { \ | ||
printf("[%s:%s:%s] PANIC: \"" format "\"\n", __FILE__, __FUNCTION__, STRINGIFY(__LINE__), ##__VA_ARGS__); \ | ||
asm volatile ("cli"); \ | ||
while (true) \ | ||
asm volatile ("hlt"); \ | ||
} while (0) | ||
|
||
#define STRINGIFY(x) _STRINGIFY(x) | ||
#define _STRINGIFY(x) #x | ||
|
||
#endif /* MOLTAROS_LOGGER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#ifndef MOLTAROS_MULTIBOOT_H | ||
#define MOLTAROS_MULTIBOOT_H | ||
|
||
#include <include/kernel/logger.h> | ||
#include <stdint.h> | ||
|
||
#define MULTIBOOT_MMAP_RAM 1 | ||
|
||
// GRUB's Multiboot information structure, which we push on the stack for use during kernel_init. | ||
// It is used to determine hardware information, such as the amount of available RAM. | ||
struct multiboot_info { | ||
// Determines what information is available in this structure | ||
uint32_t flags; | ||
|
||
// Only valid if bit 0 of flags is set. | ||
// Indicate amount of low and high memory respectively | ||
uint32_t mem_low; | ||
uint32_t mem_high; | ||
|
||
// Only valid if bit 1 of flags is set. | ||
// Indicates which disk device we were loaded from. | ||
uint32_t boot_device; | ||
|
||
// Only valid if bit 2 of flags is set. | ||
uint32_t cmdline; | ||
|
||
// Only valid if bit 3 of flags is set. | ||
// Indicates the number of boot modules loaded | ||
// alongside us, with the addr being the physical | ||
// address an array of them. | ||
uint32_t mod_count; | ||
uint32_t mod_addr; | ||
|
||
// Symbol table, which we ignore | ||
uint8_t sym_table[16]; | ||
|
||
// Only valid if bit 6 of flags is set. | ||
// Describe the memory mappings and the size | ||
// of their buffers. Of notable importance is | ||
// RAM, which we use to obtain physical memory size. | ||
uint32_t mmap_length; | ||
uint32_t mmap_addr; | ||
}; | ||
|
||
// GRUB's memory map structure. The 'size' field is located at offset -4 | ||
// which means we have to take special care when going to the next entry. | ||
struct multiboot_mmap { | ||
// Size of this entry. | ||
uint32_t size; | ||
|
||
// The start address | ||
uint32_t start_low; | ||
uint32_t start_high; | ||
|
||
// The length of this memory mapping | ||
uint32_t length_low; | ||
uint32_t length_high; | ||
|
||
// Whether this memory mapping is for RAM or some reserved area. | ||
uint32_t type; | ||
}; | ||
|
||
|
||
static bool multiboot_RAM(struct multiboot_info *mbinfo, uint32_t *start, uint32_t *end) { | ||
bool found = false; | ||
printf("Flags: %d\n", mbinfo->flags); | ||
// Check if there is a memory mapping available | ||
if (mbinfo->flags & (1 << 6)) { | ||
KLOG("MMAP Entries: %d", mbinfo->mmap_length / 24); | ||
struct multiboot_mmap *mmap = mbinfo->mmap_addr; | ||
while(mmap < mbinfo->mmap_addr + mbinfo->mmap_length) { | ||
KLOG("MMAP Entry: {Type: %s, Start: %x, Length: %x}", mmap->type == MULTIBOOT_MMAP_RAM ? "RAM" : "RESERVED", mmap->start_low, mmap->length_low); | ||
// Jackpot... (The OS is 32-bit, so there is no upper currently.) | ||
if (mmap->type == MULTIBOOT_MMAP_RAM) { | ||
*start = mmap->start_low; | ||
*end = *start + mmap->length_low; | ||
found = true; | ||
} | ||
|
||
mmap = (struct multiboot_mmap *) ((uint32_t) mmap + mmap->size + sizeof(mmap->size)); | ||
} | ||
} | ||
|
||
return found; | ||
} | ||
|
||
#endif /* MOLTAROS_MULTIBOOT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef MOLTAROS_ALLOC_H | ||
#define MOLTAROS_ALLOC_H | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
void *kmalloc(size_t size); | ||
|
||
void *kcalloc(size_t size); | ||
|
||
void *kmalloc_aligned(size_t size); | ||
|
||
void *kcalloc_aligned_phys(size_t size, uint32_t *phys_ptr); | ||
|
||
void *kcalloc_aligned(size_t size); | ||
|
||
void kfree(void *ptr); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef MOLTAROS_MEMORY_MANAGEMENT_H | ||
#define MOLTAROS_MEMORY_MANAGEMENT_H | ||
|
||
#include <stdint.h> | ||
#include <stddef.h> | ||
|
||
typedef struct memblock memblock_t; | ||
typedef struct memheap memheap_t; | ||
|
||
// memblock_t is a simple memory "superblock", which is effectively a header to | ||
// a chunk of blocks of memory: it should not be confused with a block in and of itself. | ||
// It is the header for a contiguous chunk of memory, given by the user. It also uses some | ||
// space to hold a bitmap, acting as a descriptor for certain blocks. | ||
// Implementation based on Pancakes' Bitmap Heap, seen here: http://wiki.osdev.org/User:Pancakes/BitmapHeapImplementation | ||
struct memblock { | ||
// Pointer to the next superblock in a linked-list fashion. | ||
memblock_t *next; | ||
// The total size in raw bytes of this superblock. | ||
uint32_t total_size; | ||
// Number of blocks used. | ||
uint32_t used; | ||
// The size of the individual blocks of memory. | ||
uint32_t block_size; | ||
// Index to the bitmap entry after the last allocation, a naive optimization where | ||
// the next allocation is assumed to be more likely in the same superblock and contain | ||
// free space immediately after. This yields significant increase in performance when the | ||
// block has not filled the initial superblock, but may degrade performance when it has. | ||
uint32_t last_alloc; | ||
}; | ||
|
||
struct memheap { | ||
memblock_t *head; | ||
}; | ||
|
||
void *kmalloc(size_t size); | ||
|
||
void kfree(void *ptr); | ||
|
||
#endif /* endif MOLTAROS_MEMORY_MANAGEMENT_H */ |
Oops, something went wrong.