Port remaining x86 nasm assembly to GNU as.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-10-12 11:56:51 +02:00
parent 2cb81aae33
commit db57bb6336
8 changed files with 104 additions and 60 deletions

14
README
View File

@ -154,14 +154,12 @@ Building
To build the Sortix source code you need to install a few dependencies. First of
all you need the GNU Compiler Collection (C and C++), GNU Make, and GNU
Binutils. You then need to build and install the included macro preprocessor
(mxmpp) somewhere in your PATH such as /usr/bin. If you wish to build the 32-bit
version of Sortix, you need the Netwide Assembler (nasm) as parts of it hasn't
been ported to the GNU assembler yet. You need a GNU/Linux build system to build
Sortix, although, it wouldn't be difficult to port the build system to other
platforms. You can then build the Sortix kernel and user-space utilities by
running make in the Sortix root source directory. By default it will build to
your CPU architecture (64-bit on 64-bit systems, 32-bit otherwise). Use
CPU=x86 or CPU=x64 as arguments to make to control which target is built.
(mxmpp) somewhere in your PATH such as /usr/bin. You need a GNU/Linux build
system to build Sortix, although, it wouldn't be difficult to port the build
system to other platforms. You can then build the Sortix kernel and user-space
utilities by running make in the Sortix root source directory. By default it
will build to your CPU architecture (64-bit on 64-bit systems, 32-bit otherwise).
Use CPU=x86 or CPU=x64 as arguments to make to control which target is built.
To build a bootable ISO you need GNU GRUB 2, as that is used by "make iso" to
generate the iso. In turn, GNU GRUB relies on xorriso to create the iso file.

View File

@ -11,7 +11,6 @@ ifeq ($(CPU),x86)
X86FAMILY=1
CPUFLAGS=
CPULDFLAGS=
CPUNASMFLAGS=-felf32
CPUOBJS:=$(CPU)/boot.o $(CPU)/base.o $(CPU)/x86.o
endif
@ -20,7 +19,6 @@ ifeq ($(CPU),x64)
X86FAMILY=1
CPUFLAGS=-ffreestanding -mno-red-zone
CPULDFLAGS=
CPUNASMFLAGS=-felf64
CPUOBJS:=$(CPU)/base.o $(CPU)/x64.o
endif
@ -75,7 +73,6 @@ FLAGS=$(CPUFLAGS) -Wall -Wall -Wextra -nostdlib -nostartfiles \
CFLAGS=$(FLAGS)
CXXFLAGS=$(FLAGS) -std=gnu++0x -fno-exceptions -fno-rtti
ASFLAGS=
NASMFLAGS=$(CPUNASMFLAGS)
STATICLIBS=\
-lc-sortix \
@ -176,9 +173,6 @@ sortix.bin: sortix-$(BUILDID).tmp
%.o: %.s
$(HOSTAS) $< -o $@ $(ASFLAGS)
%.o: %.asm
nasm $(NASMFLAGS) $< -o $@
clean:
for D in $(DIRS); do rm -f $$D/*.o $$D/*.bin $$D/*.out $$D/*.tmp; done

View File

@ -1,6 +1,6 @@
/*******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
This file is part of Sortix.

View File

@ -1,6 +1,6 @@
/*******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
This file is part of Sortix.

View File

@ -1,31 +0,0 @@
;
; Gdt.s -- contains global descriptor table and interrupt descriptor table
; setup code.
; Based on code from Bran's kernel development tutorials.
; Rewritten for JamesM's kernel development tutorials.
[GLOBAL gdt_flush] ; Allows the C code to call gdt_flush().
gdt_flush:
mov eax, [esp+4] ; Get the pointer to the GDT, passed as a parameter.
lgdt [eax] ; Load the new GDT pointer
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
mov ds, ax ; Load all data segment selectors
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:.flush ; 0x08 is the offset to our code segment: Far jump!
.flush:
ret
[GLOBAL tss_flush] ; Allows our C code to call tss_flush().
tss_flush:
mov ax, 0x2B ; Load the index of our TSS structure - The index is
; 0x28, as it is the 5th selector and each is 8 bytes
; long, but we set the bottom two bits (making 0x2B)
; so that it has an RPL of 3, not zero.
ltr ax ; Load 0x2B into the task state register.
ret

63
sortix/x86/gdt.s Normal file
View File

@ -0,0 +1,63 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
This file is part of Sortix.
Sortix 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.
Sortix 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
Sortix. If not, see <http://www.gnu.org/licenses/>.
x86/gdt.s
Handles initialization of the 32-bit global descriptor table.
*******************************************************************************/
.section .text
.global gdt_flush
.type gdt_flush, @function
gdt_flush:
# Load the new GDT pointer
mov 4(%esp), %eax
lgdtl (%eax)
# 0x10 is the offset in the GDT to our data segment
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss
# Far jump to our new code segment!
movl $GDT_FLUSH_POSTJMP, %eax
ljmp *(%eax)
gdt_flush_postjmp:
ret
.global tss_flush
.type tss_flush, @function
tss_flush:
# Load the index of our TSS structure - The index is 0x28, as it is the 5th
# selector and each is 8 bytes long, but we set the bottom two bits (making
# 0x2B) so that it has an RPL of 3, not zero.
mov $0x2B, %ax
# Load the task state register.
ltr %ax
ret
.section .data
GDT_FLUSH_POSTJMP:
.long gdt_flush_postjmp
.word 0x08 # 0x08 is the offset to our code segment

View File

@ -1,13 +0,0 @@
;
; idt.s -- contains global descriptor table and interrupt descriptor table
; setup code.
; Based on code from Bran's kernel development tutorials.
; Rewritten for JamesM's kernel development tutorials.
[GLOBAL idt_flush] ; Allows the C code to call idt_flush().
idt_flush:
mov eax, [esp+4] ; Get the pointer to the IDT, passed as a parameter.
lidt [eax] ; Load the IDT pointer.
ret

33
sortix/x86/idt.s Normal file
View File

@ -0,0 +1,33 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
This file is part of Sortix.
Sortix 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.
Sortix 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
Sortix. If not, see <http://www.gnu.org/licenses/>.
x86/idt.s
Handles initialization of the 32-bit IDT.
*******************************************************************************/
.section .text
.global idt_flush
.type idt_flush, @function
idt_flush:
# Load the IDT pointer.
mov 4(%esp), %eax
lidt (%eax)
ret