Compare commits

..

No commits in common. "0cc0abae3588b7f867d31a21e662193f2620118f" and "9e2eb539a63e6334d326b7490801843eeafbb777" have entirely different histories.

6 changed files with 7 additions and 85 deletions

View File

@ -35,17 +35,6 @@ set(CMAKE_ASM_FLAGS "")
set(CMAKE_ASM_FLAGS_DEBUG "-g") set(CMAKE_ASM_FLAGS_DEBUG "-g")
set(CMAKE_ASM_FLAGS_RELEASE "") set(CMAKE_ASM_FLAGS_RELEASE "")
set(CMAKE_EXE_LINKER_FLAGS "-ffreestanding -nostdlib")
# perform data type checks
include(CheckTypeSize)
if(64BIT)
check_type_size("uint64_t" UINT64_T)
endif()
check_type_size("uint32_t" UINT32_T)
check_type_size("uint16_t" UINT16_T)
check_type_size("uint8_t" UINT8_T)
include_directories( include_directories(
"src/") "src/")
@ -60,10 +49,9 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "i.86")
${SRCS} ${SRCS}
src/kernel/arch/x86/gdt.s src/kernel/arch/x86/gdt.s
src/kernel/arch/x86/gdt.c src/kernel/arch/x86/gdt.c
src/kernel/arch/x86/paging.c
src/kernel/arch/x86/tty.c) src/kernel/arch/x86/tty.c)
set(CMAKE_EXE_LINKER_FLAGS set(CMAKE_EXE_LINKER_FLAGS
"-T ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/arch/x86/linker.ld ${CMAKE_EXE_LINKER_FLAGS}") "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/arch/x86/linker.ld -ffreestanding -nostdlib")
include_directories( include_directories(
"src/kernel/arch/x86/") "src/kernel/arch/x86/")
endif() endif()

View File

@ -61,20 +61,8 @@ _start:
mov $stack_top, %esp mov $stack_top, %esp
mov %esp, %ebp mov %esp, %ebp
# paging
call setup_paging # will return pointer to page directory
# load page directory
movl %eax, %cr3
# enable the paging
movl %cr0, %eax
orl $0x80000000, %eax
movl %eax, %cr0
# GDT, paging, and other features # GDT, paging, and other features
call gdt_install call gdt_install
# load the TSS which is in the 6th entry of the GDT
movw $0x28, %ax
ltr %ax
boot_kernel: boot_kernel:
# enter high-level kernel (C) # enter high-level kernel (C)

View File

@ -28,7 +28,6 @@
#define GDT_SIZE 6 #define GDT_SIZE 6
struct segdesc gdt[GDT_SIZE]; struct segdesc gdt[GDT_SIZE];
struct tss tss;
struct segreg gdtr; struct segreg gdtr;
void gdt_entry_set(struct segdesc *entry, uint32_t base, void gdt_entry_set(struct segdesc *entry, uint32_t base,
@ -58,13 +57,9 @@ void gdt_install() {
// user // user
gdt_entry_set(&gdt[3], 0, 0xFFFFFFFF, 0xFA, 0xCF); gdt_entry_set(&gdt[3], 0, 0xFFFFFFFF, 0xFA, 0xCF);
gdt_entry_set(&gdt[4], 0, 0xFFFFFFFF, 0xF2, 0xCF); gdt_entry_set(&gdt[4], 0, 0xFFFFFFFF, 0xF2, 0xCF);
// TSS // TSS
tss.ss0 = 0x10; // TODO: create a proper TSS
// TODO: set esp0 for system interrupts gdt_entry_set(&gdt[5], 0, 0, 0x91, 0x40);
tss.iopb = sizeof(tss);
gdt_entry_set(&gdt[5], (uint32_t)&tss,
sizeof(tss), 0x89, 0x40);
gdt_flush(&gdtr); gdt_flush(&gdtr);
} }

View File

@ -20,7 +20,7 @@
#include "structs.h" #include "structs.h"
extern void gdt_flush(struct segreg*); extern void gdt_flush(struct segreg *gdtr);
void gdt_entry_set(struct segdesc *entry, uint32_t base, void gdt_entry_set(struct segdesc *entry, uint32_t base,
uint32_t limit, uint8_t access, uint8_t gran); uint32_t limit, uint8_t access, uint8_t gran);
void gdt_install(); void gdt_install();

View File

@ -1,47 +0,0 @@
/*
* Copyright (C) 2018 Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
* Author: Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stddef.h>
uint32_t page_dir[1024] __attribute__((aligned(4096)));
uint32_t page_table[1024] __attribute__((aligned(4096)));
uint32_t *setup_paging() {
/*
* set all pages to:
* - supervisor: only kernel-mode can access
* - write enabled: can be read and written
* - not present: the page table is not present
*/
for(size_t i = 0; i < 1024; ++i)
page_dir[i] = 0x00000002;
/*
* fill the 1024 entries of the table with the flags
* supervisor, write enabled, and PRESENT.
*/
for(size_t i = 0; i < 1024; ++i)
page_table[i] = (i * 0x1000) | 3;
// put page table in first directory and enable the present
// flag
page_dir[0] = ((uint32_t) page_table) | 3;
return page_dir;
}

View File

@ -2,9 +2,7 @@ set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR i686) set(CMAKE_SYSTEM_PROCESSOR i686)
set(CMAKE_C_COMPILER i686-elf-gcc) set(CMAKE_C_COMPILER i686-elf-gcc)
set(CMAKE_C_FLAGS "-ffreestanding -fno-builtin" CACHE STRING "C flags for test compilation.") set(CMAKE_C_COMPILER_WORKS TRUE)
set(CMAKE_EXE_LINKER_FLAGS "-ffreestanding -nostdlib" CACHE STRING "Linker flags for test compilation.") set(CMAKE_CXX_COMPILER i686-elf-g++)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_C_FLAGS) set(CMAKE_CXX_COMPILER_WORKS TRUE)
set(CMAKE_ASM_COMPILER i686-elf-as) set(CMAKE_ASM_COMPILER i686-elf-as)
set(64BIT FALSE CACHE BOOL "Whether the architecture supports 64-bit.")