Using LLVM and NASM now.

I need to reimplement the GDT, although hopefully now I can get it to
work in C.
This commit is contained in:
Nicolás Ortega Froysa 2018-03-14 15:08:02 +01:00
parent 2ca0402fba
commit ea6b0f69d2
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF
2 changed files with 47 additions and 135 deletions

View File

@ -17,17 +17,18 @@
# General options # General options
TARGET=i686 TARGET=i686
ARCH=$(shell echo $(TARGET) | sed s/i.86/x86/) ARCH=$(shell echo $(TARGET) | sed s/i.86/x86/)
CROSSFLAGS=--target=$(TARGET)-pc-none-elf -march=$(TARGET)
# Assembly options # Assembly options
AS=i686-elf-as AS=nasm
AFLAGS= AFLAGS=-felf32
# C options # C options
CC=i686-elf-gcc CC=clang
CFLAGS?=-O0 -g CFLAGS?=-O0 -g
CFLAGS:=$(CFLAGS) -std=gnu99 -ffreestanding -Wall -Wextra -Isrc/ CFLAGS:=$(CFLAGS) $(CROSSFLAGS) -std=c99 -ffreestanding -fno-builtin -nostdlibinc -Wall -Wextra -Isrc/
# Linker options # Linker options
LDFLAGS?=-O0 LDFLAGS?=-O0
LDFLAGS:=$(LDFLAGS) -ffreestanding -nostdlib LDFLAGS:=$(LDFLAGS) $(CROSSFLAGS) -ffreestanding -nostdlib
LIBS=-lgcc LIBS=
# Binary variables # Binary variables
OBJS=src/kernel/arch/$(ARCH)/boot.o src/kernel/kernel.o src/kernel/arch/$(ARCH)/tty.o OBJS=src/kernel/arch/$(ARCH)/boot.o src/kernel/kernel.o src/kernel/arch/$(ARCH)/tty.o

View File

@ -1,139 +1,50 @@
/* ; Copyright (C) 2018 Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
* Copyright (C) 2018 Ortega Froysa, Nicolás <nortega@themusicinnoise.net> ; Author: 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
* 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
* it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or
* the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version.
* (at your option) any later version. ;
* ; This program is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details.
* GNU General Public License for more details. ;
* ; You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License ; along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
# declare constants for the multiboot header MBALIGN equ 1<<0 ; align loaded modules on page boundaries
.set ALIGN, 1 << 0 # align loaded modules on page boundaries MEMINFO equ 1<<1 ; provide memory map
.set MEMINFO, 1 << 1 # provide memory map FLAGS equ MBALIGN | MEMINFO ; multiboot flag field
.set FLAGS, ALIGN | MEMINFO # the multiboot `FLAG' field MAGIC equ 0x1BADB002 ; magic number to help bootloader find the header
.set MAGIC, 0x1BADB002 # 'magic number' letting the boot loader know we're here CHECKSUM equ -(MAGIC + FLAGS) ; checksum of the above data
.set CHECKSUM , -(MAGIC + FLAGS) # checksum of the above to prove we're multiboot
/* section .multiboot
* Declare the multiboot header marking this program as a kernel. The bootloader align 4
* will search for these values in the first 8 KiB of the kernel file aligned at dd MAGIC
* 32-bit boundaries (4 bytes). We put the signature in its own section to force dd FLAGS
* it within the first 8 KiB of the kernel file. dd CHECKSUM
*/
.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM
/* section .bss
* Create a 16 byte aligned stack with 16 KiB of size. We create labels at the align 16
* bottom and top of the stack.
*/
.section .bss
.align 16
stack_bottom: stack_bottom:
.skip 16384 # 16 KiB resb 16384 ; 16KiB
stack_top: stack_top:
/* section .text
* Create the GDT global _start:function (_start.end - _start)
*/
.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
/*
* The linker script specifies the `_start' label as the entry point to the kernel
* and the bootloader will jump to this position. That is, this is where the kernel
* starts.
*/
.section .text
.global _start
.type _start, @function
_start: _start:
# set the position of `%esp' to the top of the stack ; setup the stack
mov $stack_top, %esp mov esp, stack_top
# GDT, paging, and other features ; call the kernel
flush_gdt: extern kernel_main
cli
lgdt (gdtr)
movw $0x10, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs
movw %ax, %ss
ljmp $0x08, $flush_end
flush_end:
boot_kernel:
# enter high-level kernel (C)
call kernel_main call kernel_main
# put computer into infinite loop ; hang
cli # disable interrupts by clearing the interrupt flag in `eflags' cli
end_loop: .hang:
hlt # wait for next interrupt hlt
jmp end_loop # jump to the `hlt' instruction if it ever leaves it jmp .hang
.end:
.size _start, . - _start