Compiled + linked with the given cross compiler. Now I need to build a cross compiler myself

This commit is contained in:
Oscar 2017-02-02 17:14:23 -08:00
parent 3a88034c22
commit adaca1d72e
7 changed files with 69 additions and 60 deletions

6
.gitignore vendored
View File

@ -1,3 +1,9 @@
#################
## secX makefile and bochs
#################
x64/target
x64/*.ini
#################
## Eclipse
#################

View File

@ -11,7 +11,7 @@ floppy_bootsig_check: disabled=0
# no floppya
# no floppyb
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=cdrom, path="secX.iso", status=inserted, model="Generic 1234", biosdetect=auto
ata0-master: type=cdrom, path="target\secX.iso", status=inserted, model="Generic 1234", biosdetect=auto
ata0-slave: type=none
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata1-master: type=none

View File

@ -1,14 +1,14 @@
OUTPUT_FORMAT(elf64-x86-64)
ENTRY(HAL_ENTRY32_PADDR)
OUTPUT_ARCH(i386:x86-64)
ENTRY(hal_entry_32)
SECTIONS
{
. = HAL_KERNEL_BASE_VADDR + HAL_KERNEL_BASE_PADDR;
kernel_start = .;
HAL_KERNEL_START_VADDR = .;
.multiboot_header ALIGN(0x1000) : AT(ADDR(.multiboot_header) - HAL_KERNEL_BASE_VADDR)
.multiboot_header : AT(ADDR(.multiboot_header) - HAL_KERNEL_BASE_VADDR)
{
*(.multiboot_header)
}
@ -30,5 +30,15 @@ SECTIONS
*(COMMON)
}
kernel_end = .;
HAL_KERNEL_END_VADDR = .;
/DISCARD/ :
{
*(.gcc_except_table)
*(.eh_frame)
*(.note)
*(.comment)
*(.rel.*)
*(.rela.*)
}
}

View File

@ -1,6 +1,6 @@
ASM = nasm
CC = gcc
LD = ld
ASM := nasm
CC := x86_64-linux-gnu-gcc
LD := x86_64-linux-gnu-gcc
#Recursive Wildcard
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
@ -11,16 +11,18 @@ rdircardex=$(sort $(dir $(call rwildcard,$1,$2)))
LD_SCRIPT := build/linker.ld
GRUB_CFG := build/grub.cfg
TEMP_DIR := tmp
HEADER_DIRS := $(call rdircardex, *,*.h)
ALL_TEMP_DIRS := $(addprefix $(TEMP_DIR)/,$(call rdircard,*))
SOURCE_DIR := src
TARGET_DIR := target
HEADER_DIRS := $(call rdircardex, $(SOURCE_DIR), *.h)
ALL_TARGET_DIRS := $(addprefix $(TARGET_DIR)/,$(call rdircard, $(SOURCE_DIR)))
ASM_HEADER_DIRS := $(call rdircardex, $(SOURCE_DIR), *.inc)
C_FLAGS := -m64 -std=c11 -g -c $(addprefix -I, $(HEADER_DIRS)) -mcmodel=kernel -ffreestanding -nostdlib -lgcc -fno-stack-protector -fno-builtin -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -masm=intel -Wall -Werror -Wextra -Wno-comment
ASM_FLAGS := -f elf64 -g -I $(ASM_SRC_PATH_64)/
LD_FLAGS := -melf_x86_64 -I
C_FLAGS := -std=c11 -g -c -mcmodel=kernel -fno-exceptions -ffreestanding -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -masm=intel -Wall -Werror -Wextra -Wno-comment $(addprefix -I, $(HEADER_DIRS))
ASM_FLAGS := -f elf64 -F dwarf -g $(addprefix -I, $(ASM_HEADER_DIRS))
LD_FLAGS := -lgcc -nodefaultlibs -nostartfiles -nostdlib -Wl,-n -Wl,--build-id=none
C_SRC := $(call rwildcard, ./, *.c)
ASM_SRC := $(call rwildcard, ./, *.asm)
C_SRC := $(call rwildcard, $(SOURCE_DIR), *.c)
ASM_SRC := $(call rwildcard, $(SOURCE_DIR), *.asm)
KERNEL_ELF := kernel.elf
KERNEL_DASM := kernel.dasm
@ -28,45 +30,38 @@ KERNEL_DASM := kernel.dasm
#Object files
C_OBJ := $(C_SRC:.c=.o)
ASM_OBJ := $(ASM_SRC:.asm=.oasm)
ALL_OBJ := $(addprefix $(TEMP_DIR)/,$(C_OBJ)) $(addprefix $(TEMP_DIR)/,$(ASM_OBJ))
ALL_OBJ := $(addprefix $(TARGET_DIR)/,$(C_OBJ)) $(addprefix $(TARGET_DIR)/,$(ASM_OBJ))
#Commands
all: init compile link buildiso disasm clean_temp
all: init compile link buildiso disasm
init:
mkdir -p $(ALL_TEMP_DIRS)
mkdir -p $(ALL_TARGET_DIRS)
compile: $(C_OBJ) $(ASM_OBJ)
link: $(KERNEL_ELF)
buildiso:
mkdir -p $(TEMP_DIR)/temp_iso/secX
mkdir -p $(TEMP_DIR)/temp_iso/boot
mkdir -p $(TEMP_DIR)/temp_iso/boot/grub
cp $(TEMP_DIR)/$(KERNEL_ELF) $(TEMP_DIR)/temp_iso/secX/$(KERNEL_ELF)
cp $(TEMP_DIR)/$(KERNEL_ELF) ./
cp $(GRUB_CFG) $(TEMP_DIR)/temp_iso/boot/grub/
grub-mkrescue -o secX.iso $(TEMP_DIR)/temp_iso
mkdir -p $(TARGET_DIR)/temp_iso/secX
mkdir -p $(TARGET_DIR)/temp_iso/boot
mkdir -p $(TARGET_DIR)/temp_iso/boot/grub
cp $(TARGET_DIR)/$(KERNEL_ELF) $(TARGET_DIR)/temp_iso/secX/$(KERNEL_ELF)
cp $(GRUB_CFG) $(TARGET_DIR)/temp_iso/boot/grub/
grub-mkrescue -o $(TARGET_DIR)/secX.iso $(TARGET_DIR)/temp_iso
clean_temp:
rm -rf $(TEMP_DIR)
clean: clean_temp
rm -rf $(KERNEL_DASM)
rm -rf secX.iso
rm -rf *.log
rm -rf $(KERNEL_ELF)
clean:
rm -rf $(TARGET_DIR)
%.o: %.c
$(CC) $(C_FLAGS) -o $(TEMP_DIR)/$@ $^
$(CC) $(C_FLAGS) -o $(TARGET_DIR)/$@ $^
%.oasm: %.asm
$(ASM) $(ASM_FLAGS) -o $(TEMP_DIR)/$@ $^
$(ASM) $(ASM_FLAGS) -o $(TARGET_DIR)/$@ $^
$(KERNEL_ELF): $(ALL_OBJ)
$(LD) $(LD_FLAGS) -T $(LD_SCRIPT) -o $(TEMP_DIR)/$(KERNEL_ELF) $(ALL_OBJ)
$(LD) $(LD_FLAGS) -T $(LD_SCRIPT) -o $(TARGET_DIR)/$(KERNEL_ELF) $(ALL_OBJ)
disasm:
objdump -M intel -D $(TEMP_DIR)/$(KERNEL_ELF) > $(KERNEL_DASM)
objdump -M intel -D $(TARGET_DIR)/$(KERNEL_ELF) > $(TARGET_DIR)/$(KERNEL_DASM)

View File

@ -2,23 +2,15 @@
; Distributed under GPL license
; See COPYING under root for details
extern hal_main
HAL_KERNEL_BASE_VADDR equ 0xFFFFFFFF80000000
global HAL_KERNEL_BASE_VADDR
HAL_KERNEL_BASE_PADDR equ 0x4000000
global HAL_KERNEL_BASE_PADDR
HAL_ENTRY32_PADDR equ hal_entry_32 - HAL_KERNEL_BASE_VADDR
global HAL_ENTRY32_PADDR
%include "hal_addr.inc"
MULTIBOOT_TAG_ALIGNMENT equ 8
MULTIBOOT_HEADER_ALIGNMENT equ 8
MULTIBOOT_LOADED_MAGIC equ 0x36d76289
MULTIBOOT_MAGIC_NUMBER equ 0xE85250D6
MULTIBOOT_ARCH equ 0
MULTIBOOT_CHECK_SUM equ (0 - (MULTIBOOT_MAGIC_NUMBER + MULTIBOOT_HEADER_SIZE + MULTIBOOT_ARCH))
; NASM does not like
MULTIBOOT_CHECK_SUM equ (0xFFFFFFFF - (MULTIBOOT_MAGIC_NUMBER + MULTIBOOT_HEADER_SIZE + MULTIBOOT_ARCH) + 1)
MULTIBOOT_REQ_MINFO equ 4
MULTIBOOT_REQ_MMAP equ 6
MULTIBOOT_REQ_APM equ 10
@ -61,8 +53,8 @@ MULTIBOOT_HEADER_SIZE equ ($ - multiboot_header_tag)
[SECTION .text]
[BITS 32]
align 4096
global hal_entry_32
hal_entry_32:
; close interrupt
cli
@ -93,14 +85,14 @@ and eax, 01111111111111111111111111111111b ; Clear the PG-bit, which is bit
mov cr0, eax ; Set control register 0 to the A-register.
; write values for pml4
mov eax,PML4_BASE
mov dword [eax], PDPT_BASE + 3
mov eax,PML4_BASE - HAL_KERNEL_BASE_VADDR
mov dword [eax], PDPT_BASE + 3 - HAL_KERNEL_BASE_VADDR
; write values for pdpt
xor ecx, ecx
add ecx, 131
mov eax, PDPT_BASE
mov eax, PDPT_BASE- HAL_KERNEL_BASE_VADDR
mov dword [eax], ecx
add eax,8
@ -127,7 +119,7 @@ or eax, 1 << 8 ; Set the LM-bit which is the 9th bit (bit 8).
wrmsr ; Write to the model-specific register.
; let cr3 point at page table
mov eax, PML4_BASE
mov eax, PML4_BASE- HAL_KERNEL_BASE_VADDR
mov cr3,eax
; enable paging, enter compatibility mode
@ -136,8 +128,8 @@ or eax, 1 << 31 ; Set the PG-bit, which is bit 31
mov cr0, eax ; Set control register 0 to the A-register.
; enter x64
lgdt [GDT64.GDT64_PTR]
jmp SLCT_CODE:halp_entry_64
lgdt [GDT64.GDT64_PTR - HAL_KERNEL_BASE_VADDR]
jmp $ ;SLCT_CODE:halp_entry_64 - HAL_KERNEL_BASE_VADDR
hlt
halp_ensure_support_x64:
@ -174,6 +166,7 @@ ret
[SECTION .text]
[BITS 64]
extern hal_main
halp_entry_64:
cli
mov ax,SLCT_DATA

View File

@ -10,8 +10,8 @@
#include "sxtdlib.h"
#include "s_boot.h"
extern char kernel_start[];
extern char kernel_end[];
extern char HAL_KERNEL_START_VADDR[];
extern char HAL_KERNEL_END_VADDR[];
static void KABI _hal_obtain_cpu_info(boot_info_t *hal_info)
{
@ -38,8 +38,8 @@ void KABI hal_main(void *m_info)
boot_info_t* boot_info = halloc(sizeof(boot_info_t));
// set up HAL def
boot_info->krnl_start = (uint64_t)kernel_start;
boot_info->krnl_end = (uint64_t)kernel_end;
boot_info->krnl_start = (uint64_t)HAL_KERNEL_START_VADDR;
boot_info->krnl_end = (uint64_t)HAL_KERNEL_END_VADDR;
// obtain cpu info
_hal_obtain_cpu_info(boot_info);

View File

@ -0,0 +1,5 @@
HAL_KERNEL_BASE_PADDR equ 0x1000000 ; #16 MB
global HAL_KERNEL_BASE_PADDR
HAL_KERNEL_BASE_VADDR equ 0xFFFFFFFF80000000
global HAL_KERNEL_BASE_VADDR