Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
feat: pit and sleep, and new bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
austanss committed Feb 17, 2021
1 parent 4cc68fc commit ef4939a
Show file tree
Hide file tree
Showing 23 changed files with 382 additions and 403 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ kernel: dirs
$(ASM) $(KERNEL_SRC_DIR)/gdt.asm -o $(OBJ_DIR)/gdt.o
$(ASM) $(KERNEL_SRC_DIR)/interrupts.asm -o $(OBJ_DIR)/interrupts.o
$(ASM) $(KERNEL_SRC_DIR)/kernel_entry.asm -o $(OBJ_DIR)/kernel_entry.o
$(ASM) $(KERNEL_SRC_DIR)/sleep.asm -o $(OBJ_DIR)/sleep.o
$(CXX) -MF$(OBJ_DIR)/idt.cxx.o.d -o $(OBJ_DIR)/idt.cxx.o -c $(KERNEL_SRC_DIR)/idt.cxx
$(CXX) -MF$(OBJ_DIR)/pic.cxx.o.d -o $(OBJ_DIR)/pic.cxx.o -c $(KERNEL_SRC_DIR)/pic.cxx
$(CXX) -MF$(OBJ_DIR)/io.cxx.o.d -o $(OBJ_DIR)/io.cxx.o -c $(KERNEL_SRC_DIR)/io.cxx
Expand All @@ -60,7 +61,8 @@ kernel: dirs
$(CXX) -MF$(OBJ_DIR)/power.cxx.o.d -o $(OBJ_DIR)/power.cxx.o -c $(KERNEL_SRC_DIR)/power.cxx
$(CXX) -MF$(OBJ_DIR)/serialcon.cxx.o.d -o $(OBJ_DIR)/serialcon.cxx.o -c $(KERNEL_SRC_DIR)/serialcon.cxx
$(CXX) -MF$(OBJ_DIR)/memory.cxx.o.d -o $(OBJ_DIR)/memory.cxx.o -c $(KERNEL_SRC_DIR)/memory.cxx
$(CXX_LINK) -o $(BUILD_DIR)/microCORE.kernel $(OBJ_DIR)/kernel_entry.o $(OBJ_DIR)/kmain.cxx.o $(OBJ_DIR)/boot.cxx.o $(OBJ_DIR)/bitmap.cxx.o $(OBJ_DIR)/serialcon.cxx.o $(OBJ_DIR)/printf.cxx.o $(OBJ_DIR)/power.cxx.o $(OBJ_DIR)/tui.cxx.o $(OBJ_DIR)/gdt.o $(OBJ_DIR)/idt.o $(OBJ_DIR)/interrupts.o $(OBJ_DIR)/idt.cxx.o $(OBJ_DIR)/io.cxx.o $(OBJ_DIR)/kconfigf.cxx.o $(OBJ_DIR)/memory.cxx.o $(OBJ_DIR)/terminal.cxx.o $(OBJ_DIR)/pic.cxx.o $(OBJ_DIR)/kutil.cxx.o $(OBJ_DIR)/kbd.cxx.o $(OBJ_DIR)/gfx.cxx.o -T $(RES_DIR)/Linkerscript
$(CXX) -MF$(OBJ_DIR)/timer.cxx.o.d -o $(OBJ_DIR)/timer.cxx.o -c $(KERNEL_SRC_DIR)/timer.cxx
$(CXX_LINK) -o $(BUILD_DIR)/microCORE.kernel $(OBJ_DIR)/kernel_entry.o $(OBJ_DIR)/sleep.o $(OBJ_DIR)/kmain.cxx.o $(OBJ_DIR)/boot.cxx.o $(OBJ_DIR)/timer.cxx.o $(OBJ_DIR)/bitmap.cxx.o $(OBJ_DIR)/serialcon.cxx.o $(OBJ_DIR)/printf.cxx.o $(OBJ_DIR)/power.cxx.o $(OBJ_DIR)/tui.cxx.o $(OBJ_DIR)/gdt.o $(OBJ_DIR)/idt.o $(OBJ_DIR)/interrupts.o $(OBJ_DIR)/idt.cxx.o $(OBJ_DIR)/io.cxx.o $(OBJ_DIR)/kconfigf.cxx.o $(OBJ_DIR)/memory.cxx.o $(OBJ_DIR)/terminal.cxx.o $(OBJ_DIR)/pic.cxx.o $(OBJ_DIR)/kutil.cxx.o $(OBJ_DIR)/kbd.cxx.o $(OBJ_DIR)/gfx.cxx.o -T $(RES_DIR)/Linkerscript

clean:
rm -rfv $(BUILD_DIR)/*.* $(OBJ_DIR)/*.* iso
Expand Down
306 changes: 76 additions & 230 deletions include/kernel/boot.hxx
Original file line number Diff line number Diff line change
@@ -1,233 +1,79 @@
/**
* @file boot.h
* @author ajxs
* @date Aug 2019
* @brief Boot functionality.
* Contains definitions for boot structures.
*/

#pragma once
#ifndef __STIVALE__STIVALE_H__
#define __STIVALE__STIVALE_H__

#include <stdint.h>

extern "C"
{
/**
* @brief Memory region descriptor.
* Describes a region of memory. This is passed to the kernel by the bootloader.
*/
namespace boot {

typedef struct {
uint16_t year; // 1998 - 20XX
uint8_t month; // 1 - 12
uint8_t day; // 1 - 31
uint8_t hour; // 0 - 23
uint8_t ninute; // 0 - 59
uint8_t second; // 0 - 59
uint8_t pad1;
uint32_t nanosecond; // 0 - 999,999,999
int16_t timezone; // -1440 to 1440 or 2047
uint8_t daylight;
uint8_t pad2;
} efi_time;

typedef struct {
uint32_t resolution; // 1e-6 parts per million
uint32_t accuracy; // hertz
int sets_to_zero; // Set clears sub-second time
} efi_time_capabillities;

#define efi_api __attribute__((ms_abi))

typedef struct s_memory_region_desc {
uint32_t type;
uintptr_t physical_start;
uintptr_t virtual_start;
uint64_t count;
uint64_t attributes;
} memory_map_descriptor;

typedef struct {
uint32_t data1;
uint16_t data2;
uint16_t data3;
uint8_t data4[8];
} efi_guid;

typedef struct {
efi_guid capsule_guid;
uint32_t header_size;
uint32_t flags;
uint32_t capsule_image_size;
} efi_capsule_header;

typedef enum {
efi_reset_cold,
efi_reset_warm,
efi_reset_shutdown
} efi_reset_type;

typedef
uint64_t
(efi_api *efi_get_time) (
efi_time *time,
efi_time_capabillities *capabilities
);

typedef
uint64_t
(efi_api *efi_set_time) (
efi_time *time);

typedef
uint64_t
(efi_api *efi_get_wakeup_time) (
int *enabled,
int *pending,
efi_time *time
);

typedef
uint64_t
(efi_api *efi_set_wakeup_time) (
int enable,
efi_time *time
);

typedef
uint64_t
(efi_api *efi_set_virtual_address_map) (
uint64_t memory_map_size,
uint64_t descriptor_size,
uint64_t descriptor_version,
memory_map_descriptor *virtual_map
);

typedef
uint64_t
(efi_api *efi_convert_pointer) (
uint64_t debug_disposition,
void **address
);

typedef
uint64_t
(efi_api *efi_get_variable) (
uint16_t *variable_name,
efi_guid *vendor_guid,
uint32_t *attribute,
uint64_t *data_size,
void *data
);

typedef
uint64_t
(efi_api *efi_get_next_variable_name) (
uint64_t *variable_name_size,
uint16_t *variable_name,
efi_guid *vendor_guid
);

typedef
uint64_t
(efi_api *efi_set_variable) (
uint16_t *variable_name,
efi_guid *vendor_guid,
uint32_t attributes,
uint64_t data_size,
void *data
);

typedef
uint64_t
(efi_api *efi_get_next_high_mono_count) (
uint32_t *high_count
);

typedef
uint64_t
(efi_api *efi_reset_system) (
efi_reset_type reset_type,
uint64_t reset_status,
uint64_t data_size,
uint16_t *reset_data
);

typedef
uint64_t
(efi_api *efi_update_capsule) (
efi_capsule_header **capsule_header_array,
uint64_t capsule_count,
int scatter_gather_list
);

typedef
uint64_t
(efi_api *efi_query_capsule_capabilities) (
efi_capsule_header **capsule_header_array,
uint64_t capsule_count,
uint64_t *maximum_capsule_size,
efi_reset_type *reset_type
);

typedef
uint64_t
(efi_api *efi_query_variable_info) (
uint32_t attributes,
uint64_t *maximum_variable_storage_size,
uint64_t *remaining_variable_storage_size,
uint64_t *maximum_variable_size
);

typedef struct s_efi_table_header {
uint64_t signature;
uint32_t rev;
uint32_t size;
uint32_t crc;
uint32_t reserved;
} efi_table_header;

typedef struct s_efi_runtime_service_handle {
efi_table_header header;
efi_get_time get_time;
efi_set_time set_time;
efi_get_wakeup_time get_wakeup_time;
efi_set_wakeup_time set_wakeup_time;
efi_set_virtual_address_map set_virtual_address_map;
efi_convert_pointer convert_pointer;
efi_get_variable get_variable;
efi_get_next_variable_name get_next_variable_name;
efi_set_variable set_variable;
efi_get_next_high_mono_count get_next_high_monotonic_count;
efi_reset_system reset_system;
efi_update_capsule update_capsule;
efi_query_capsule_capabilities query_capsule_capabilities;
efi_query_variable_info query_variable_info;
} efi_runtime_services;

extern efi_runtime_services *uefi;

typedef struct s_framebuffer {
uint32_t *framebuffer_base;
uint64_t framebuffer_size;
uint32_t framebuffer_mode;
uint32_t x_resolution;
uint32_t y_resolution;
uint32_t pixels_per_scan_line;
} gop_framebuffer;

/**
* @brief Boot info struct.
* Contains information passed to the kernel at boot time by the bootloader.
*/
typedef struct s_boot_info {
uint64_t verification;
gop_framebuffer *vbe_framebuffer;
memory_map_descriptor *memory_map;
uint64_t mmap_size;
uint64_t mmap_descriptor_size;
efi_runtime_services *runtime_services;
} boot_info;
}
}
/* --- Header --------------------------------------------------------------- */
/* Information passed from the kernel to the bootloader */



struct stivale_header {
uint64_t stack;
uint16_t flags;
uint16_t framebuffer_width;
uint16_t framebuffer_height;
uint16_t framebuffer_bpp;
uint64_t entry_point;
} __attribute__((__packed__));

/* --- Struct --------------------------------------------------------------- */
/* Information passed from the bootloader to the kernel */

struct stivale_module {
uint64_t begin;
uint64_t end;
char string[128];
uint64_t next;
} __attribute__((__packed__));

#define STIVALE_MMAP_USABLE 1
#define STIVALE_MMAP_RESERVED 2
#define STIVALE_MMAP_ACPI_RECLAIMABLE 3
#define STIVALE_MMAP_ACPI_NVS 4
#define STIVALE_MMAP_BAD_MEMORY 5
#define STIVALE_MMAP_KERNEL_AND_MODULES 10
#define STIVALE_MMAP_BOOTLOADER_RECLAIMABLE 0x1000

struct stivale_mmap_entry {
uint64_t base;
uint64_t length;
uint32_t type;
uint32_t unused;
} __attribute__((__packed__));

struct stivale_framebuffer {
uint64_t framebuffer_addr;
uint16_t framebuffer_pitch;
uint16_t framebuffer_width;
uint16_t framebuffer_height;
uint16_t framebuffer_bpp;
} __attribute__((__packed__));

struct stivale_memory_map {
uint64_t memory_map_addr;
uint64_t memory_map_entries;
} __attribute__((__packed__));

#define STIVALE_FBUF_MMODEL_RGB 1

struct stivale_struct {
uint64_t cmdline;
stivale_memory_map memory_map;
stivale_framebuffer framebuffer;
uint64_t rsdp;
uint64_t module_count;
uint64_t modules;
uint64_t epoch;
uint64_t flags; // bit 0: 1 if booted with BIOS, 0 if booted with UEFI
// bit 1: 1 if extended colour information passed, 0 if not
uint8_t fb_memory_model;
uint8_t fb_red_mask_size;
uint8_t fb_red_mask_shift;
uint8_t fb_green_mask_size;
uint8_t fb_green_mask_shift;
uint8_t fb_blue_mask_size;
uint8_t fb_blue_mask_shift;
} __attribute__((__packed__));

#endif
8 changes: 4 additions & 4 deletions include/kernel/gfx.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace gfx {

extern uint32_t* buffer;
extern boot::gop_framebuffer gop;
extern uint32_t* buffer;
extern stivale_framebuffer gop;

namespace fonts {
uint64_t get_character_font(char c);
Expand All @@ -32,12 +32,12 @@ namespace gfx {

inline void plot_pixel(gfx::shapes::positional_point posi, uint32_t pixel)
{
gop.framebuffer_base[gop.x_resolution * posi.y + posi.x] = pixel;
((uint32_t *)gop.framebuffer_addr)[gop.framebuffer_width * posi.y + posi.x] = pixel;
}

inline void plot_pixel_buffer(gfx::shapes::positional_point posi, uint32_t pixel)
{
gop.framebuffer_base[gop.x_resolution * posi.y + posi.x] = pixel;
((uint32_t *)gop.framebuffer_addr)[gop.framebuffer_width * posi.y + posi.x] = pixel;
}

void save_screen();
Expand Down
2 changes: 1 addition & 1 deletion include/kernel/kbd.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace io {

namespace keyboard {
void init();
char scan_code_to_char(uint16_t keycode);
char scan_code_to_char(uint8_t keycode);
void keyboard_event_publisher();
void keyboard_event_subscribe(void (*subscriber_function)());
void keyboard_event_unsubscribe(void (*subscriber_function)());
Expand Down
7 changes: 3 additions & 4 deletions include/kernel/kconfigf.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ namespace sys {
extern uint64_t _kernel_size;
extern uint64_t _kernel_pages;
void calculate_kernel_size();
void setup_paging(boot::boot_info* bootloader_info);
void configure_memory(boot::boot_info* bootloader_info);
void configure_graphics(boot::boot_info* bootloader_info);
void boot_info_copy(boot::boot_info* dst, boot::boot_info* src);
void setup_paging(stivale_framebuffer *framebuffer);
void configure_memory(stivale_framebuffer *framebuffer, stivale_memory_map *memory_map);
void configure_graphics(stivale_framebuffer *framebuffer);
}
}
4 changes: 2 additions & 2 deletions include/kernel/memory.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ namespace memory {
void* malloc(size_t bytes);
void free(void* data);
void initialize_heap(void* heap_address, size_t heap_length);
void map_memory(boot::memory_map_descriptor* memory_map, uint64_t map_size, uint64_t desc_size);
uint64_t get_total_memory_size(boot::memory_map_descriptor* memory_map, uint64_t map_size, uint64_t desc_size);
void map_memory(stivale_memory_map* memory_map, uint64_t map_size, uint64_t desc_size);
uint64_t get_total_memory_size(stivale_memory_map* memory_map, uint64_t map_size, uint64_t desc_size);
};

namespace operations {
Expand Down
1 change: 1 addition & 0 deletions include/kernel/terminal.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public:
VGA_COLOR_LIGHT_BROWN = 14,
VGA_COLOR_WHITE = 15
};

size_t row;
size_t column;
static terminal &instance();
Expand Down
Loading

0 comments on commit ef4939a

Please sign in to comment.