Compare commits

...

10 Commits

Author SHA1 Message Date
Nicolás Ortega Froysa
0cc0abae35
Enable paging first before loading GDT. 2018-04-12 16:42:15 +02:00
Nicolás Ortega Froysa
003e3d9604
Create a variable for 64-bit to check uint64_t. 2018-04-12 13:49:56 +02:00
Nicolás Ortega Froysa
5cea65e807
Check for data types. 2018-04-11 20:54:13 +02:00
Nicolás Ortega Froysa
4170a3d5ae
Properly check the compiler. 2018-04-11 20:53:38 +02:00
Nicolás Ortega Froysa
6b05d87153
C++ is not used in this project. 2018-04-11 19:32:37 +02:00
Nicolás Ortega Froysa
1f325b4854
Enable paging. 2018-04-11 18:04:14 +02:00
Nicolás Ortega Froysa
794c4e0dd2
Remove parameter name.
It's assembly code, so no need to name it.
2018-04-11 18:03:29 +02:00
Nicolás Ortega Froysa
e0eb1a92be
Move TSS load to boot.s 2018-04-05 10:31:21 +02:00
Nicolás Ortega Froysa
bb36ab3656
Load the TSS. 2018-04-05 10:23:23 +02:00
Nicolás Ortega Froysa
d46ee029ad
Entry for TSS created. 2018-04-05 10:01:51 +02:00
6 changed files with 85 additions and 7 deletions

View File

@ -35,6 +35,17 @@ 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/")
@ -49,9 +60,10 @@ 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 -ffreestanding -nostdlib") "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/arch/x86/linker.ld ${CMAKE_EXE_LINKER_FLAGS}")
include_directories( include_directories(
"src/kernel/arch/x86/") "src/kernel/arch/x86/")
endif() endif()

View File

@ -61,8 +61,20 @@ _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,6 +28,7 @@
#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,
@ -57,9 +58,13 @@ 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
// TODO: create a proper TSS tss.ss0 = 0x10;
gdt_entry_set(&gdt[5], 0, 0, 0x91, 0x40); // TODO: set esp0 for system interrupts
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 *gdtr); extern void gdt_flush(struct segreg*);
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

@ -0,0 +1,47 @@
/*
* 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,7 +2,9 @@ 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_COMPILER_WORKS TRUE) set(CMAKE_C_FLAGS "-ffreestanding -fno-builtin" CACHE STRING "C flags for test compilation.")
set(CMAKE_CXX_COMPILER i686-elf-g++) set(CMAKE_EXE_LINKER_FLAGS "-ffreestanding -nostdlib" CACHE STRING "Linker flags for test compilation.")
set(CMAKE_CXX_COMPILER_WORKS TRUE) set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_C_FLAGS)
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.")