Switched to cross compiler
This commit is contained in:
parent
bc62176374
commit
f2d4797be1
28
Makefile
28
Makefile
|
@ -9,19 +9,19 @@ CONFIG_DIR := config/
|
|||
|
||||
# Compiler settings
|
||||
|
||||
CC = gcc
|
||||
CCFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector \
|
||||
-nostartfiles -nodefaultlibs -Wall -Wextra -Werror -c
|
||||
CC = i686-elf-gcc
|
||||
CCFLAGS = -ffreestanding -mno-red-zone -c
|
||||
CCFLAGS += -Wall -Wextra -Werror -pedantic
|
||||
|
||||
# Linker settings
|
||||
|
||||
LD = ld
|
||||
LDFLAGS = -T $(CONFIG_DIR)/link.ld -m elf_i386
|
||||
LD = i686-elf-gcc
|
||||
LDFLAGS = -T $(CONFIG_DIR)/link.ld -nostdlib -ffreestanding -lgcc
|
||||
|
||||
# Assembler settings
|
||||
|
||||
AS = nasm
|
||||
ASFLAGS = -f elf32
|
||||
AS = i686-elf-as
|
||||
ASFLAGS =
|
||||
|
||||
# Libraries directory. Normally I don't want to include the library headers
|
||||
# in kmain, but given the fact that in the module interfaces there are includes
|
||||
|
@ -59,8 +59,6 @@ LIBS = -lklib
|
|||
|
||||
.PHONY: all clean module_all
|
||||
|
||||
# Build
|
||||
|
||||
all: lib_all | module_all kernel.elf
|
||||
|
||||
# module_all - Recursively build all modules.
|
||||
|
@ -70,6 +68,8 @@ module_all:
|
|||
@$(MAKE) -C $(MODULES_ROOT_DIR)
|
||||
@echo
|
||||
|
||||
# lib_all - Recursively build the library
|
||||
|
||||
lib_all:
|
||||
@$(call print_banner, "Building the library")
|
||||
@$(MAKE) -C $(LIB_DIR)
|
||||
|
@ -80,7 +80,7 @@ lib_all:
|
|||
|
||||
kernel.elf: $(OBJ)
|
||||
@$(call print_banner, "Building the kernel")
|
||||
$(LD) $(LDFLAGS) $(OBJ) $(MODULE_OBJ) -o kernel.elf $(LIBFLAGS) $(LIBS)
|
||||
$(LD) $(OBJ) $(MODULE_OBJ) -o kernel.elf $(LIBFLAGS) $(LIBS) $(LDFLAGS)
|
||||
|
||||
# os.iso - Create the OS image and place the kernel fiel in GRUB directory.
|
||||
|
||||
|
@ -104,16 +104,14 @@ BOCHS_CONFIG := $(CONFIG_DIR)/bochsrc.txt
|
|||
run: os.iso
|
||||
bochs -f $(BOCHS_CONFIG) -q
|
||||
|
||||
# Compile and assemble c and s files.
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CCFLAGS) $(INCFLAGS) $< -o $@
|
||||
$(CC) $< -o $@ $(CCFLAGS) $(INCFLAGS)
|
||||
|
||||
%.o: %.s
|
||||
$(AS) $(ASFLAGS) $< -o $@
|
||||
$(AS) $< -o $@ $(ASFLAGS)
|
||||
|
||||
clean: mclean lclean
|
||||
@$(call print_banner, "Cealning root directory")
|
||||
@$(call print_banner, "Cleaning root directory")
|
||||
@$(RM) *.o kernel.elf os.iso bochslog.txt iso/boot/kernel.elf
|
||||
|
||||
mclean:
|
||||
|
|
|
@ -24,7 +24,7 @@ SO := libklib.a
|
|||
|
||||
# Archiver
|
||||
|
||||
AR = ar
|
||||
AR = i686-elf-ar
|
||||
ARFLAGS = rcs
|
||||
|
||||
# Makefile for each library
|
||||
|
|
|
@ -1,16 +1,35 @@
|
|||
global outb
|
||||
global inb
|
||||
.global outb
|
||||
.global inb
|
||||
|
||||
/*
|
||||
* outb:
|
||||
* -----
|
||||
*
|
||||
* Passes the port number in %dx and the value to be written in %al. Using
|
||||
* the outb instruction, the value is written in the I/O port.
|
||||
*
|
||||
*/
|
||||
|
||||
outb:
|
||||
|
||||
mov al, [esp + 8]
|
||||
mov dx, [esp + 4]
|
||||
mov 0x04(%esp), %dx
|
||||
mov 0x08(%esp), %al
|
||||
|
||||
out dx, al
|
||||
outb %al, %dx
|
||||
ret
|
||||
|
||||
/*
|
||||
* inb:
|
||||
* ----
|
||||
*
|
||||
* Passes the port number in %dx. It will return the value in that port after
|
||||
* after calling the inb instruction.
|
||||
*
|
||||
*/
|
||||
|
||||
inb:
|
||||
|
||||
mov dx, [esp + 4]
|
||||
in al, dx
|
||||
mov 0x04(%esp), %dx
|
||||
inb %dx, %al
|
||||
|
||||
ret
|
||||
|
|
58
loader.s
58
loader.s
|
@ -1,43 +1,53 @@
|
|||
global loader
|
||||
.global loader
|
||||
|
||||
; Entry point in the kernel.
|
||||
/* Entry point in the kernel. */
|
||||
|
||||
extern kmain
|
||||
.extern kmain
|
||||
|
||||
; GRUB will load the kernel only if it compiles with the multiboot spec.
|
||||
; The header must contain a magic number, a flag (which can be set to 0x00)
|
||||
; and the checksum (checksum = - (flag + magic_number))
|
||||
/*
|
||||
* GRUB will load the kernel only if it compiles with the multiboot spec.
|
||||
* The header must contain a magic number, a flag (which can be set to 0x00)
|
||||
* and the checksum (checksum = - (flag + magic_number))
|
||||
*
|
||||
*/
|
||||
|
||||
MAGIC_NUMBER equ 0x1BADB002
|
||||
FLAGS equ 0x00
|
||||
CHECKSUM equ -(MAGIC_NUMBER + FLAGS)
|
||||
.set MAGIC_NUMBER, 0x1BADB002
|
||||
.set FLAGS, 0x00
|
||||
.set CHECKSUM, -(MAGIC_NUMBER + FLAGS)
|
||||
|
||||
; Put the header in multiboot section so that it is placed in the first 8Kib
|
||||
; of the executable.
|
||||
/*
|
||||
* Put the header in multiboot section so that it is placed in the first 8Kib
|
||||
* of the executable.
|
||||
*
|
||||
*/
|
||||
|
||||
section .multiboot
|
||||
align 4
|
||||
.section .multiboot
|
||||
.align 4
|
||||
|
||||
dd MAGIC_NUMBER
|
||||
dd FLAGS
|
||||
dd CHECKSUM
|
||||
.int MAGIC_NUMBER
|
||||
.int FLAGS
|
||||
.int CHECKSUM
|
||||
|
||||
; Create a kstack so that the entry point in the kernel can be called.
|
||||
/* Create a kstack so that the entry point in the kernel can be called. */
|
||||
|
||||
KSTACK_SIZE equ 4096
|
||||
.set KSTACK_SIZE, 4096
|
||||
|
||||
section .bss
|
||||
align 4
|
||||
.bss
|
||||
.align 16
|
||||
|
||||
kstack resb KSTACK_SIZE
|
||||
kstack: .skip KSTACK_SIZE
|
||||
|
||||
; Set the stack and call kmain.
|
||||
/* Set the stack and call kmain. */
|
||||
|
||||
section .text
|
||||
.text
|
||||
|
||||
loader:
|
||||
mov esp, kstack + KSTACK_SIZE
|
||||
|
||||
mov $kstack, %esp
|
||||
add KSTACK_SIZE, %esp
|
||||
|
||||
call kmain
|
||||
cli
|
||||
|
||||
.halt:
|
||||
jmp .halt
|
||||
|
|
|
@ -28,20 +28,15 @@ OBJ += $(ASM:$(ASM_DIR)/%.s=$(OBJ_DIR)/%.o)
|
|||
|
||||
# Compiler settings.
|
||||
|
||||
CC = gcc
|
||||
CCFLAGS = -m32 -fPIC -nostdlib -lgcc -nostdinc -fno-builtin -fno-stack-protector \
|
||||
-nostartfiles -nodefaultlibs -Wall -Wextra -Werror -c
|
||||
CC = i686-elf-gcc
|
||||
CCFLAGS = -ffreestanding -mno-red-zone -c
|
||||
CCFLAGS += -Wall -Wextra -Werror -pedantic
|
||||
HFLAGS = -MMD
|
||||
|
||||
# Linker settings.
|
||||
|
||||
LD = ld
|
||||
LDFLAGS = -relocatable -m elf_i386
|
||||
|
||||
# Archiver
|
||||
|
||||
AR = ar
|
||||
ARFLAGS = rcs
|
||||
LD = i686-elf-gcc
|
||||
LDFLAGS = -r -nostdlib -ffreestanding -lgcc
|
||||
|
||||
# Include flags.
|
||||
|
||||
|
@ -49,8 +44,8 @@ INCFLAGS := $(foreach TMP, $(INC_DIR), -I$(TMP))
|
|||
|
||||
# Assembler and flags for assembler.
|
||||
|
||||
AS = nasm
|
||||
ASFLAGS = -f elf32
|
||||
AS = i686-elf-as
|
||||
ASFLAGS =
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
|
@ -59,13 +54,13 @@ ASFLAGS = -f elf32
|
|||
all: $(LIB_OBJ)
|
||||
|
||||
$(LIB_OBJ): $(OBJ) | $(LOBJ_DIR)
|
||||
$(LD) $(LDFLAGS) $(OBJ) -o $@
|
||||
$(LD) $(OBJ) -o $@ $(LDFLAGS)
|
||||
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
|
||||
$(CC) $(CCFLAGS) $(HFLAGS) $(INCFLAGS) $< -o $@
|
||||
$(CC) $< -o $@ $(CCFLAGS) $(HFLAGS) $(INCFLAGS)
|
||||
|
||||
$(OBJ_DIR)/%.o: $(ASM_DIR)/%.s | $(OBJ_DIR)
|
||||
$(AS) $(ASFLAGS) $< -o $@
|
||||
$(AS) $< -o $@ $(ASFLAGS)
|
||||
|
||||
$(LOBJ_DIR) $(OBJ_DIR):
|
||||
mkdir -p $@
|
||||
|
|
|
@ -27,15 +27,15 @@ OBJ := $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
|
|||
|
||||
# Compiler settings
|
||||
|
||||
CC = gcc
|
||||
CCFLAGS = -m32 -nostdlib -lgcc -nostdinc -fno-builtin -fno-stack-protector \
|
||||
-nostartfiles -nodefaultlibs -Wall -Wextra -Werror -c
|
||||
CC = i686-elf-gcc
|
||||
CCFLAGS = -ffreestanding -mno-red-zone -c
|
||||
CCFLAGS += -Wall -Wextra -Werror -pedantic
|
||||
HFLAGS = -MMD
|
||||
|
||||
# Linker settings
|
||||
|
||||
LD = ld
|
||||
LDFLAGS = -relocatable -m elf_i386
|
||||
LD = i686-elf-gcc
|
||||
LDFLAGS = -r -nostdlib -ffreestanding -lgcc
|
||||
|
||||
# Include directories
|
||||
|
||||
|
@ -47,10 +47,10 @@ INCFLAGS += $(foreach TMP, $(INC_DIR), -I$(TMP))
|
|||
all: $(MOD_OBJ)
|
||||
|
||||
$(MOD_OBJ): $(OBJ) | $(MOBJ_DIR)
|
||||
$(LD) $(LDFLAGS) $(OBJ) -o $@
|
||||
$(LD) $(OBJ) -o $@ $(LDFLAGS)
|
||||
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
|
||||
$(CC) $(CCFLAGS) $(HFLAGS) $(INCFLAGS) $< -o $@
|
||||
$(CC) $< -o $@ $(CCFLAGS) $(HFLAGS) $(INCFLAGS)
|
||||
|
||||
$(OBJ_DIR) $(MOBJ_DIR):
|
||||
mkdir -p $@
|
||||
|
|
Loading…
Reference in New Issue