Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kernel/arch/generic/include/types.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef TYPES_H_SNRJBAVH
#define TYPES_H_SNRJBAVH

#include "include/generic/ll64.h"
#include "include/generic/lp64.h"

#define __kernel_size_t __u32

Expand Down
17 changes: 4 additions & 13 deletions kernel/arch/x86/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@

#include "arch/generic/include/types.h"

/* TODO: Setup compiler toolchain and remove this */
#if 0

#ifdef CONFIG_64BIT
# define BITS_PER_LONG 64
# define __kernel_ulong_t __u64
# define __kernel_long_t __s64
#else
# define BITS_PER_LONG 32
# define __kernel_ulong_t __u32
# define __kernel_long_t __s32
#endif
typedef __u64 __kernel_ulong_t;
typedef __s64 __kernel_long_t;

#else

# define BITS_PER_LONG 32
# define __kernel_ulong_t unsigned long
# define __kernel_long_t unsigned long
typedef __u32 __kernel_ulong_t;
typedef __s32 __kernel_long_t;

#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ typedef unsigned short __u16;
typedef __signed__ int __s32;
typedef unsigned int __u32;

typedef __signed__ long long __s64;
typedef unsigned long long __u64;
typedef __signed__ long __s64;
typedef unsigned long __u64;


#endif /* end of include guard: LL64_H_UV2JD7IF */
8 changes: 4 additions & 4 deletions kernel/include/ll64.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef LL64_H_Q0MBWVFF
#define LL64_H_Q0MBWVFF
#ifndef LP64_H_Q0MBWVFF
#define LP64_H_Q0MBWVFF

#include <generic/ll64.h>
#include <generic/lp64.h>

#endif /* end of include guard: LL64_H_Q0MBWVFF */
#endif /* end of include guard: LP64_H_Q0MBWVFF */
9 changes: 5 additions & 4 deletions kernel/include/multiboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ void multiboot_dump_info (multiboot_info_t *info, uint32_t multiboot_magic);
#endif

#define FOREACH_MEMORY_MAP(MMAP, INFO) \
for(multiboot_memory_map_t *MMAP = \
for( \
multiboot_memory_map_t *MMAP = \
(multiboot_memory_map_t *)(uintptr_t)INFO->mmap_addr; \
(uintptr_t)MMAP < INFO->mmap_addr + INFO->mmap_len; \
MMAP = (multiboot_memory_map_t *) \
((uintptr_t)MMAP + MMAP->size + sizeof(MMAP->size)) \
)
MMAP = \
(multiboot_memory_map_t *)(MMAP + MMAP->size + sizeof(MMAP->size)) \
)

#endif /* end of include guard: MULTIBOOT_H_RKNBOMGQ */
4 changes: 2 additions & 2 deletions kernel/include/page_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
* Initializes the memory frames bitmap, which will be used later by alloc/free
* functions. It also allocates some pages to store the said bitmap.
*
* @param void * base address where kernel ends
* @param uintptr_t base address where kernel ends
* @param multiboot_into_t multiboot info
*/
void page_frame_init (void * base_address,
void page_frame_init (uintptr_t base_address,
multiboot_info_t *multiboot_info);

/**
Expand Down
8 changes: 4 additions & 4 deletions kernel/interrupt/interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ extern void double_fault_handler_int(void);

void isr_set_keyboard(void)
{
uint32_t keyboard_address = (uint32_t)&keyboard_handler_int;
uintptr_t keyboard_address = (uintptr_t)&keyboard_handler_int;
idt_set_gate(0x21, keyboard_address, 0x08, 0x8e);
}

void isr_set_double_fault(void)
{
idt_set_gate(0x08, (uint32_t)&double_fault_handler_int, 0x08, 0x8f);
idt_set_gate(0x08, (uintptr_t)&double_fault_handler_int, 0x08, 0x8f);
}

void isr_init_keyboard(void)
Expand All @@ -28,7 +28,7 @@ void isr_init_keyboard(void)

idt_t idt[IDT_SIZE];

void idt_set_gate(int offset, uint32_t base, uint16_t selector,
void idt_set_gate(int offset, uintptr_t base, uint16_t selector,
uint8_t type_attr)
{
idt[offset].offset_1 = base & 0xffff;
Expand All @@ -42,7 +42,7 @@ void idt_init(void)
{
klog_status_init("IDT");

uint32_t idt_address = (uint32_t)&idt;
uintptr_t idt_address = (uintptr_t)&idt;
idt_ptr_t idt_pointer = {
.limit = (sizeof(idt_t) * IDT_SIZE) - 1,
.base = idt_address
Expand Down
2 changes: 1 addition & 1 deletion kernel/interrupt/interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef struct _idt_ptr_t {
#define IDT_SIZE 256

void idt_init(void);
void idt_set_gate(int offset, uint32_t base, uint16_t selector,
void idt_set_gate(int offset, uintptr_t base, uint16_t selector,
uint8_t type_attr);

void isr_init_keyboard(void);
Expand Down
5 changes: 4 additions & 1 deletion kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ extern void kmain(multiboot_info_t *multiboot_info, uint32_t multiboot_magic)
multiboot_dump_info(multiboot_info, multiboot_magic);
#endif

page_frame_init(&endkernel, multiboot_info);
klog(LOG_DEBUG, "uintptr_t: %x\n", sizeof(uintptr_t));
klog(LOG_DEBUG, "unsigned long: %x\n", sizeof(unsigned long));
klog(LOG_DEBUG, "unsigned long long: %x\n", sizeof(unsigned long long));
page_frame_init((uintptr_t)&endkernel, multiboot_info);
#ifdef DEBUG
page_frame_dump_map();
void *page1 = NULL, *page2 = NULL;
Expand Down
3 changes: 2 additions & 1 deletion kernel/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ SECTIONS
*(.text)
}

.data ALIGN(0x1000) : {
.data : {
*(.data)
. = ALIGN(4096);
}

.bss : {
Expand Down
4 changes: 2 additions & 2 deletions kernel/makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ifndef TARGET
TARGET = i686-elf
TARGET = x86_64-elf
endif

CC = ../.deps/cross/bin/$(TARGET)-gcc
Expand Down Expand Up @@ -47,7 +47,7 @@ $(BIN): $(OBJS) $(INCLUDE) $(ASM_OBJS) $(BUILD_DIR)
$(LD) -T linker.ld $(OBJS) $(ASM_OBJS) -o $@

$(ASM_OBJS): %_asm.o:%.asm $(INCLUDE_DIR)/asm/*.asm
$(CC_ASM) -f elf32 $< -o $@
$(CC_ASM) -f elf64 $< -o $@

$(OBJS):%.o: %.c $(INCLUDE) $(INCLUDE_DIR)/*
$(CC) $(CC_FLAGS) $(CD_FLAGS) -I. -I${INCLUDE_DIR} -c $< -o $@
Expand Down
27 changes: 19 additions & 8 deletions kernel/mm/page_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ static uint32_t frames_bitmap_pages;


/* size of each frame that is allocated in bytes */
#define FRAME_SIZE (4096 / 8) /* 4KB */
#define FRAME_SIZE (4096 / 8) /* 4KB */
#define BITMAP_SIZE (8 * sizeof(*frames_bitmap))

#define FRAME_SIZE_KB 4

/* value in bitmap for used/free */
#define FRAME_FREE 0
Expand Down Expand Up @@ -56,25 +59,33 @@ static inline void memory_mark_free(uintptr_t low_address,
}


void page_frame_init (void *base_address, multiboot_info_t *multiboot_info)
void page_frame_init(uintptr_t base_address, multiboot_info_t *multiboot_info)
{
klog_status_init("page_frame");

/* calculate and allocate space for frames_bitmap */
frames_bitmap = base_address;
num_frames = (multiboot_info->mem_upper) / sizeof(*frames_bitmap);
frames_bitmap_size = (num_frames + 32 - 1) / 32;
memset(frames_bitmap, -1, frames_bitmap_size);
frames_bitmap = (void *)base_address;
num_frames = (multiboot_info->mem_upper + FRAME_SIZE_KB - 1) / FRAME_SIZE_KB;
frames_bitmap_size = (num_frames + BITMAP_SIZE - 1) / BITMAP_SIZE;
memset(frames_bitmap, FRAME_USED,
frames_bitmap_size * sizeof(*frames_bitmap));

/* start memory allocation after frames_bitmap. doing this ensures that there
* is memory allocated for the bitmap. */
frames_bitmap_pages = (frames_bitmap_size + FRAME_SIZE - 1) / FRAME_SIZE;
memory_base_address = (uintptr_t)(base_address + (FRAME_SIZE * frames_bitmap_pages));
memory_base_address =
base_address + (FRAME_SIZE * frames_bitmap_pages);

/* mark all free pages */
FOREACH_MEMORY_MAP(mmap, multiboot_info) {
if (mmap->type == MULTIBOOT_MEM_TYPE_FREE) {
memory_mark_free(mmap->base_addr_low, mmap->len_low);
klog(LOG_DEBUG, "size: %x\n", sizeof(uintptr_t));
klog(LOG_DEBUG, "size: %x\n", sizeof(uint32_t));
klog(LOG_DEBUG, "size: %x\n", sizeof(uint64_t));
uintptr_t address = 0// ((uintptr_t)mmap->base_addr_high << 32)
+ mmap->base_addr_low;
/*klog(LOG_DEBUG, "Free memory at 0x%x\n", address);*/
memory_mark_free(address, address + mmap->len_low);
}
}

Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GCC_VERSION = 5.4.0
BINUTILS_VERSION = 2.29
DEPS_PREFIX = $(shell pwd)/.deps/cross
TARGET = i686-elf
TARGET = x86_64-elf

BUILD_DIR = build
DISK_IMG = $(BUILD_DIR)/disk.img
Expand Down