Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Jenkins committed Dec 25, 2016
2 parents c98f3ab + 4f26c0c commit f74b8e4
Show file tree
Hide file tree
Showing 40 changed files with 1,027 additions and 254 deletions.
463 changes: 349 additions & 114 deletions MoltarOS.sublime-workspace

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ The below depicts an early "schedule" or rather a path I will be taking in terms
- [x] Interrupts (IRQ + ISR)
- [x] VGA Display Driver
- [x] Keyboard Driver
- [ ] Interactive Shell
- [ ] Memory Management (Physical + Virtual)
- [ ] Interactive Shell
- [ ] File System
- [ ] Multitasking and Scheduling
- [ ] Networking
- [ ] Process Creation and Managements
- [ ] ELF Binary Support
- [ ] Graphical User Interfaces

#Progress Update
#Progress Update & Changelog

## Version .001a

Expand All @@ -34,4 +34,17 @@ Implemented the GDT, IDT (and IRQs and ISRs), reprogrammed the PIC's (Master and
Implemented the keyboard driver, but it won't be able to communicate with other components (such as an interactive shell) until memory management is implemented... perhaps, not even until processes and scheduling is implemented. That is the next thing I will be releasing. Currently, when you execute
the OS, it will have a blank screen, until you use the keyboard. When executing the keyboard, it will display what key has been pressed and what has been released... but only one at a time unfortunaately, no multi-key press events are supported.

![Screenshot](/kbd_input.PNG)
![Screenshot](/kbd_input.PNG)

## Version .001c

Began implementation of memory management, but not finished yet. Paging SHOULD be implemented very soon (and most code has been written), as well the heap is also mainly written using Pancakes' Bitmap Heap implementation, and paired with the identity paging technique, development of all other parts of the OS should proceed as expected. Today, I also managed to make use of the multiboot info struct that GRUB
gives us that was pushed on the stack in 'kernel_init', and now it can detect the amount of physical memory (RAM) that the machine (or virtual machine) has to offer. This is crucial to finished memory management.

As well, there has been a huge restructure in terms of the hierarchy and logical structure of the operating system. For example, the folders 'mm' and 'drivers' now also have their own respective folders in the
include folder, I.E 'drivers/vga.c' will have it's header in 'include/drivers/vga.h'. While in terms of usability, it is not too much of an update (yet, memory management will be in version .002), there has been
a significant amount of work and should be pushed to master.

Lastly, I also added a nice logger macro, `KLOG`, and panic macro, `KPANIC`.

![Screenshot](/ram_and_kbd.PNG)
Binary file added ram_and_kbd.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ if [ $? -ne 0 ]; then
fi

# Finally, run the virtual machine.
bochs -f bochs.bxrc;
bochs -f bochsrc.bxrc;
4 changes: 2 additions & 2 deletions src/kernel/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Include directories
INCLUDE := kernel include arch/i686 display drivers
INCLUDE := kernel x86 drivers

# List of all headers from the included directories
HEADERS := $(shell find $(INCLUDE) -type f -name \*.h)
Expand All @@ -18,7 +18,7 @@ OBJECTS := $(C_OBJECTS) $(ASM_OBJECTS)
DEPENDENCIES := $(patsubst %.c, %.d, $(C_SOURCES))

# Linker to be used
LINKER := arch/i686/linker.ld
LINKER := x86/linker.ld

# Compilers used during specific build sections
LINKER_COMPILER := i686-elf-gcc -static
Expand Down
2 changes: 0 additions & 2 deletions src/kernel/arch/i686/exceptions.c

This file was deleted.

8 changes: 4 additions & 4 deletions src/kernel/drivers/kbd.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <include/kbd.h>
#include <include/vga.h>
#include <include/idt.h>
#include <include/io_port.h>
#include <include/drivers/kbd.h>
#include <include/drivers/vga.h>
#include <include/x86/idt.h>
#include <include/x86/io_port.h>
#include <include/helpers.h>
#include <stdbool.h>
#include <stdio.h>
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/drivers/rtc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <include/rtc.h>
#include <include/io_port.h>
#include <include/drivers/rtc.h>
#include <include/x86/io_port.h>
#include <stdio.h>
#include <stdbool.h>

Expand Down
7 changes: 4 additions & 3 deletions src/kernel/kernel/timer.c → src/kernel/drivers/timer.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <include/timer.h>
#include <include/io_port.h>
#include <include/drivers/timer.h>
#include <include/x86/io_port.h>
#include <include/helpers.h>
#include <stdio.h>
#include <limits.h>

static const uint32_t oscillator_frequency = 1193180;

static void timer_default_irq(struct registers *regs) {
static void timer_default_irq(struct registers *UNUSED(regs)) {
// NOP
}

Expand Down
4 changes: 2 additions & 2 deletions src/kernel/display/vga.c → src/kernel/drivers/vga.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <stdint.h>

#include <include/vga.h>
#include <include/io_port.h>
#include <include/drivers/vga.h>
#include <include/x86/io_port.h>

/* X and Y coordinates for current position in VGA buffer */
static size_t x, y;
Expand Down
22 changes: 0 additions & 22 deletions src/kernel/include/bit_array.h

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef MOLTAROS_KBD_HAL_H
#define MOLTAROS_KBD_HAL_H

#include <include/bit_array.h>
#include <include/kbd.h>
#include <include/helpers.h>
#include <include/drivers/kbd.h>
#import <stdint.h>

static struct {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#define PIT_REPEAT 0x36

#include <stdint.h>
#include <include/idt.h>
#include <include/x86/idt.h>

void init_timer(uint32_t frequency, void (*cb)(struct registers *registers));
void timer_init();

void timer_set_handler(uint32_t frequency, void (*cb)(struct registers *registers));

#endif /* MOLTAROS_TIMER_H */
File renamed without changes.
25 changes: 25 additions & 0 deletions src/kernel/include/helpers.h
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 */
25 changes: 25 additions & 0 deletions src/kernel/include/kernel/logger.h
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 */
87 changes: 87 additions & 0 deletions src/kernel/include/kernel/multiboot.h
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 */
19 changes: 19 additions & 0 deletions src/kernel/include/mm/alloc.h
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
39 changes: 39 additions & 0 deletions src/kernel/include/mm/heap.h
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 */
Loading

0 comments on commit f74b8e4

Please sign in to comment.