Added GDT.
Unfortunately I can't do it in C, but whatever.
This commit is contained in:
parent
ea6b0f69d2
commit
9703f2484c
2
Makefile
2
Makefile
@ -20,7 +20,7 @@ ARCH=$(shell echo $(TARGET) | sed s/i.86/x86/)
|
||||
CROSSFLAGS=--target=$(TARGET)-pc-none-elf -march=$(TARGET)
|
||||
# Assembly options
|
||||
AS=nasm
|
||||
AFLAGS=-felf32
|
||||
AFLAGS=-felf32 -Isrc/kernel/arch/$(ARCH)/ -Isrc/
|
||||
# C options
|
||||
CC=clang
|
||||
CFLAGS?=-O0 -g
|
||||
|
@ -32,12 +32,27 @@ stack_bottom:
|
||||
resb 16384 ; 16KiB
|
||||
stack_top:
|
||||
|
||||
section .data
|
||||
%include "gdt.s"
|
||||
|
||||
section .text
|
||||
global _start:function (_start.end - _start)
|
||||
_start:
|
||||
; setup the stack
|
||||
mov esp, stack_top
|
||||
|
||||
; TODO: setup GDT, IDT, paging, etc. here
|
||||
cli
|
||||
lgdt [gdtr]
|
||||
jmp 0x08:.reload_segs
|
||||
.reload_segs:
|
||||
mov ax, 0x10
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov ss, ax
|
||||
|
||||
; call the kernel
|
||||
extern kernel_main
|
||||
call kernel_main
|
||||
|
68
src/kernel/arch/x86/gdt.s
Normal file
68
src/kernel/arch/x86/gdt.s
Normal file
@ -0,0 +1,68 @@
|
||||
; 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/>.
|
||||
|
||||
gdt_start:
|
||||
|
||||
gdt_null:
|
||||
dd 0x0
|
||||
dd 0x0
|
||||
|
||||
gdt_kcode:
|
||||
dw 0xFFFF ; limit (bits 0-15)
|
||||
dw 0x0 ; base (bits 0-15)
|
||||
|
||||
db 0x0 ; base (bits 16-23)
|
||||
db 10011010b ; 1st flags | type flags
|
||||
db 11001111b ; 2nd flags | limit (bits 16-19)
|
||||
db 0x0 ; base (bits 24-31)
|
||||
|
||||
gdt_kdata:
|
||||
dw 0xFFFF
|
||||
dw 0x0
|
||||
|
||||
db 0x0
|
||||
db 10010010b
|
||||
db 11001111b
|
||||
db 0x0
|
||||
|
||||
gdt_ucode:
|
||||
dw 0xFFFF
|
||||
dw 0x0
|
||||
|
||||
db 0x0
|
||||
db 11111010b
|
||||
db 11001111b
|
||||
db 0x0
|
||||
|
||||
gdt_udata:
|
||||
dw 0xFFFF
|
||||
dw 0x0
|
||||
|
||||
db 0x0
|
||||
db 11110010b
|
||||
db 11001111b
|
||||
db 0x0
|
||||
|
||||
; TODO: fill this in later
|
||||
gdt_tss:
|
||||
dd 0x0
|
||||
dd 0x0
|
||||
|
||||
gdt_end:
|
||||
|
||||
gdtr:
|
||||
dw gdt_end - gdt_start - 1
|
||||
dd gdt_start
|
@ -18,7 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
volatile struct tss {
|
||||
struct tss {
|
||||
uint16_t link;
|
||||
uint16_t link_r; // reserved
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user