From e74b55936bd90b9d9b7e465677a564d1046dd53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Thu, 22 Mar 2018 10:50:58 +0100 Subject: [PATCH] Move GDT to its own file. --- src/kernel/arch/x86/boot.s | 55 +---------------------------- src/kernel/arch/x86/gdt.s | 72 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 54 deletions(-) create mode 100644 src/kernel/arch/x86/gdt.s diff --git a/src/kernel/arch/x86/boot.s b/src/kernel/arch/x86/boot.s index cbb2926..3b498ed 100644 --- a/src/kernel/arch/x86/boot.s +++ b/src/kernel/arch/x86/boot.s @@ -45,61 +45,8 @@ stack_bottom: .skip 16384 # 16 KiB stack_top: -/* - * Create the GDT - */ .section .data -gdt_start: -gdt_null: -.long 0x0 -.long 0x0 - -gdt_kcode: -.word 0xFFFF # limit -.word 0x0 # base -.byte 0x0 # base -.byte 0b10011010 # 1st flags | type flags -.byte 0b11001111 # 2nd flags | limit -.byte 0x0 # base - -gdt_kdata: -.word 0xFFFF # limit -.word 0x0 # base -.byte 0x0 # base -.byte 0b10010010 # 1st flags | type flags -.byte 0b11001111 # 2nd flags | limit -.byte 0x0 # base - -gdt_ucode: -.word 0xFFFF # limit -.word 0x0 # base -.byte 0x0 # base -.byte 0b11111010 # 1st flags | type flags -.byte 0b11001111 # 2nd flags | limit -.byte 0x0 # base - -gdt_udata: -.word 0xFFFF # limit -.word 0x0 # base -.byte 0x0 # base -.byte 0b11110010 # 1st flags | type flags -.byte 0b11001111 # 2nd flags | limit -.byte 0x0 # base - -# TODO: setup the TSS -gdt_tss: -.word 0x0 # size of TSS (set later) -.word 0x0 # address of TSS (set later) -.byte 0x0 # address of TSS (set later) -.byte 0b10010001 # 1st flags | type flags -.byte 0b01000000 # 2nd flags | size of TSS (set later -.byte 0x0 # address of TSS (set later) - -gdt_end: - -gdtr: -.word (gdt_end - gdt_start - 1) -.long gdt_start +.include "gdt.s" /* * The linker script specifies the `_start' label as the entry point to the kernel diff --git a/src/kernel/arch/x86/gdt.s b/src/kernel/arch/x86/gdt.s new file mode 100644 index 0000000..e3896ab --- /dev/null +++ b/src/kernel/arch/x86/gdt.s @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2018 Ortega Froysa, Nicolás + * Author: Ortega Froysa, Nicolás + * + * 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 . + */ + +/* + * Create the GDT + */ +gdt_start: +gdt_null: +.long 0x0 +.long 0x0 + +gdt_kcode: +.word 0xFFFF # limit +.word 0x0 # base +.byte 0x0 # base +.byte 0b10011010 # 1st flags | type flags +.byte 0b11001111 # 2nd flags | limit +.byte 0x0 # base + +gdt_kdata: +.word 0xFFFF # limit +.word 0x0 # base +.byte 0x0 # base +.byte 0b10010010 # 1st flags | type flags +.byte 0b11001111 # 2nd flags | limit +.byte 0x0 # base + +gdt_ucode: +.word 0xFFFF # limit +.word 0x0 # base +.byte 0x0 # base +.byte 0b11111010 # 1st flags | type flags +.byte 0b11001111 # 2nd flags | limit +.byte 0x0 # base + +gdt_udata: +.word 0xFFFF # limit +.word 0x0 # base +.byte 0x0 # base +.byte 0b11110010 # 1st flags | type flags +.byte 0b11001111 # 2nd flags | limit +.byte 0x0 # base + +# TODO: setup the TSS +gdt_tss: +.word 0x0 # size of TSS (set later) +.word 0x0 # address of TSS (set later) +.byte 0x0 # address of TSS (set later) +.byte 0b10010001 # 1st flags | type flags +.byte 0b01000000 # 2nd flags | size of TSS (set later +.byte 0x0 # address of TSS (set later) + +gdt_end: + +gdtr: +.word (gdt_end - gdt_start - 1) +.long gdt_start