Fix issues with ASM
This commit is contained in:
parent
f5dc9b961b
commit
81d4d93c12
|
@ -1,29 +1,31 @@
|
||||||
MBOOT_ALIGN equ <<0
|
MBOOT_ALIGN equ 1<<0
|
||||||
MBOOT_MEMINFO equ 1<<1
|
MBOOT_MEMINFO equ 1<<1
|
||||||
MBOOT_FLAGS equ MBOOT_ALIGN | MBOOT_MEMINFO
|
MBOOT_FLAGS equ MBOOT_ALIGN | MBOOT_MEMINFO
|
||||||
MBOOT_MAGIC equ 0x1BADB002
|
MBOOT_MAGIC equ 0x1BADB002
|
||||||
MBOOT_CHECKSUM equ -(MAGIC + FLAGS)
|
MBOOT_CHECKSUM equ -(MBOOT_MAGIC + MBOOT_FLAGS)
|
||||||
|
|
||||||
[BITS 32]
|
[BITS 32]
|
||||||
|
|
||||||
[GLOBAL mboot]
|
[GLOBAL mboot]
|
||||||
|
[SECTION .multiboot]
|
||||||
[EXTERN code]
|
ALIGN 4
|
||||||
[EXTERN bss]
|
|
||||||
[EXTERN end]
|
|
||||||
mboot:
|
mboot:
|
||||||
dd MBOOT_MAGIC
|
dd MBOOT_MAGIC
|
||||||
dd MBOOT_FLAGS
|
dd MBOOT_FLAGS
|
||||||
dd mboot
|
dd MBOOT_CHECKSUM
|
||||||
dd code
|
|
||||||
dd bss
|
|
||||||
dd end
|
|
||||||
dd start
|
|
||||||
|
|
||||||
[GLOBAL start]
|
SECTION .bss
|
||||||
|
ALIGN 16
|
||||||
|
stack_bottom:
|
||||||
|
RESB 16384
|
||||||
|
stack_top:
|
||||||
|
|
||||||
|
|
||||||
|
SECTION .text
|
||||||
|
[GLOBAL _start]
|
||||||
[EXTERN kernel_main]
|
[EXTERN kernel_main]
|
||||||
|
|
||||||
start:
|
_start:
|
||||||
push ebx
|
push ebx
|
||||||
|
|
||||||
cli
|
cli
|
||||||
|
@ -31,7 +33,7 @@ start:
|
||||||
jmp $
|
jmp $
|
||||||
|
|
||||||
[GLOBAL load_gdt] ; Allows the C code to call gdt_flush().
|
[GLOBAL load_gdt] ; Allows the C code to call gdt_flush().
|
||||||
[EXTERN gp]
|
|
||||||
load_gdt:
|
load_gdt:
|
||||||
mov eax, [esp+4] ; Get the pointer to the GDT, passed as a parameter.
|
mov eax, [esp+4] ; Get the pointer to the GDT, passed as a parameter.
|
||||||
lgdt [eax] ; Load the new GDT pointer
|
lgdt [eax] ; Load the new GDT pointer
|
||||||
|
@ -176,6 +178,7 @@ irq_common:
|
||||||
add esp, 8
|
add esp, 8
|
||||||
iret
|
iret
|
||||||
|
|
||||||
|
[GLOBAL idt_load]
|
||||||
idt_load:
|
idt_load:
|
||||||
mov eax, [esp+4]
|
mov eax, [esp+4]
|
||||||
lidt [eax]
|
lidt [eax]
|
||||||
|
|
|
@ -5,7 +5,5 @@ KERNEL_ARCH_LIBS=
|
||||||
|
|
||||||
KERNEL_ARCH_OBJS= \
|
KERNEL_ARCH_OBJS= \
|
||||||
$(ARCHDIR)/boot.o \
|
$(ARCHDIR)/boot.o \
|
||||||
$(ARCHDIR)/gdt.o \
|
|
||||||
$(ARCHDIR)/isr.o \
|
|
||||||
$(ARCHDIR)/sys_clock.o \
|
$(ARCHDIR)/sys_clock.o \
|
||||||
$(ARCHDIR)/tty.o
|
$(ARCHDIR)/tty.o
|
||||||
|
|
25
makefile
25
makefile
|
@ -2,7 +2,7 @@ DEFAULT_HOST:=i686-elf
|
||||||
HOST?=DEFAULT_HOST
|
HOST?=DEFAULT_HOST
|
||||||
HOSTARCH:=i386
|
HOSTARCH:=i386
|
||||||
|
|
||||||
CFLAGS?= -O2 -g
|
CFLAGS?= -O2 -g -m32 -no-pie
|
||||||
CPPFLAGS?=
|
CPPFLAGS?=
|
||||||
LDFLAGS?=
|
LDFLAGS?=
|
||||||
LIBS?=
|
LIBS?=
|
||||||
|
@ -13,7 +13,7 @@ EXEC_PREFIX?=$(PREFIX)
|
||||||
BOOTDIR?=$(EXEC_PREFIX)/boot
|
BOOTDIR?=$(EXEC_PREFIX)/boot
|
||||||
INCLUDEDIR?=$(PREFIX)/include
|
INCLUDEDIR?=$(PREFIX)/include
|
||||||
|
|
||||||
CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra
|
CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra -I"../include" -I"../../include"
|
||||||
CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude
|
CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude
|
||||||
LDFLAGS:=$(LDFLAGS)
|
LDFLAGS:=$(LDFLAGS)
|
||||||
LIBS:=$(LIBS) -nostdlib -lgcc
|
LIBS:=$(LIBS) -nostdlib -lgcc
|
||||||
|
@ -36,20 +36,12 @@ kernel/idt.o \
|
||||||
kernel/kernel.o
|
kernel/kernel.o
|
||||||
|
|
||||||
OBJS=\
|
OBJS=\
|
||||||
$(ARCHDIR)/crti.o \
|
$(KERNEL_OBJS)
|
||||||
$(ARCHDIR)/crtbegin.o \
|
|
||||||
$(KERNEL_OBJS) \
|
|
||||||
$(ARCHDIR)/crtend.o \
|
|
||||||
$(ARCHDIR)/crtn.o
|
|
||||||
|
|
||||||
LINK_LIST=\
|
LINK_LIST=\
|
||||||
$(LDFLAGS) \
|
$(LDFLAGS) \
|
||||||
$(ARCHDIR)/crti.o \
|
|
||||||
$(ARCHDIR)/crtbegin.o \
|
|
||||||
$(KERNEL_OBJS) \
|
$(KERNEL_OBJS) \
|
||||||
$(LIBS) \
|
$(LIBS) \
|
||||||
$(ARCHDIR)/crtend.o \
|
|
||||||
$(ARCHDIR)/crtn.o
|
|
||||||
|
|
||||||
.PHONY: all clean install install-headers install-kernel
|
.PHONY: all clean install install-headers install-kernel
|
||||||
.SUFFIXES: .o .c .s
|
.SUFFIXES: .o .c .s
|
||||||
|
@ -58,20 +50,11 @@ all: red.kernel
|
||||||
|
|
||||||
red.kernel: $(OBJS) $(ARCHDIR)/linker.ld
|
red.kernel: $(OBJS) $(ARCHDIR)/linker.ld
|
||||||
$(CC) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(LINK_LIST)
|
$(CC) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(LINK_LIST)
|
||||||
|
|
||||||
$(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o:
|
|
||||||
OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@
|
|
||||||
|
|
||||||
$(ARCHDIR)/gdt.o:
|
|
||||||
nasm -f elf $(ARCHDIR)/gdt.s
|
|
||||||
|
|
||||||
$(ARCHDIR)/isr.o:
|
|
||||||
nasm -f elf $(ARCHDIR)/isr.s
|
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) -MD -c $< -o $@ -std=gnu11 $(CFLAGS) $(CPPFLAGS)
|
$(CC) -MD -c $< -o $@ -std=gnu11 $(CFLAGS) $(CPPFLAGS)
|
||||||
.s.o:
|
.s.o:
|
||||||
$(CC) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
|
nasm -f elf $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f red.kernel
|
rm -f red.kernel
|
||||||
|
|
Loading…
Reference in New Issue
Block a user