- Removed bogus 32-bit and 64-bit mixed hal entrance. The new entrance is ke_main.

- Removed grub dependency.
This commit is contained in:
secXsQuared 2018-02-17 23:00:54 -05:00
parent 7a297165fc
commit a64afda294
34 changed files with 65 additions and 2059 deletions

View File

@ -1,8 +1,8 @@
CROSS_DIR = ~/opt/cross/bin
CROSS_PATH = ~/opt/cross/bin
AS = nasm
CC = $(CROSS_DIR)/x86_64-elf-gcc
LD = $(CROSS_DIR)/x86_64-elf-gcc
DAS = $(CROSS_DIR)/x86_64-elf-objdump
CC = $(CROSS_PATH)/x86_64-elf-gcc
LD = $(CROSS_PATH)/x86_64-elf-gcc
DAS = $(CROSS_PATH)/x86_64-elf-objdump
INCLUDE_DIR = include
MK = mk
@ -28,13 +28,9 @@ C_FLAGS = -std=c11 \
-c \
-O2 \
-mcmodel=kernel \
-fno-exceptions \
-fno-stack-protector \
-ffreestanding \
-mno-red-zone \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-masm=intel \
$(C_WARNINGS) \
$(addprefix -I, $(INCLUDE_DIR))
@ -46,12 +42,9 @@ AS_FLAGS = -w+all \
$(addprefix -I, $(INCLUDE_DIR)/)
LD_FLAGS = -lgcc \
-nodefaultlibs \
-nostartfiles \
-nostdlib \
-mno-red-zone \
-Wl,-n \
-Wl,--build-id=none
-Wl,--fatal-warnings \
-mno-red-zone
DUMP_FLAGS = -M intel \
-D

View File

@ -15,14 +15,14 @@ include $(dir)/Rules.mk
dir := mk
include $(dir)/Rules.mk
LD_SCRIPT = $(OUT)/$(MK)/linker.ld
GRUB_CFG = $(OUT)/$(MK)/grub.cfg
LD_SCRIPT := $(OUT)/$(MK)/linker.ld
TGT := $(OUT)/secxkrnl.elf
DMP := $(OUT)/secxkrnl.dmp
ISO := $(OUT)/secxkrnl.iso
$(TGT): $(OBJ) $(LD_SCRIPT)
@echo ================libgcc path===================
$(LD) $(LD_FLAGS) -print-libgcc-file-name
@echo ==============================================
$(LINK) -T $(LD_SCRIPT)
$(DMP): $(TGT)
@ -39,17 +39,7 @@ compile: $(TGT)
.PHONY: dump
dump: $(DMP)
.PHONY: iso
iso: $(TGT) $(GRUB_CFG)
mkdir -p temp/secX
mkdir -p temp/boot
mkdir -p temp/boot/grub
cp $(TGT) temp/secX/
cp $(GRUB_CFG) temp/boot/grub/
grub-mkrescue -o $(ISO) temp
rm -r temp
.PHONY: all
all: compile dump iso
all: compile dump
include $(MK)/epilogue.mk

5
bootstrap.sh Normal file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
# Find x86_64-elf-gcc
export PATH="~/opt/cross/bin:$PATH"

View File

@ -10,15 +10,6 @@ SRCAS_$(d) := $(d)/cpu.asm \
SRCIN_$(d) := $(d)/boot.asm.in
#special rules for boot.asm
#no dependencies for ASM objects
$(OUT)/$(d)/boot.a: $(OUT)/$(d)/boot.asm
$(MKDIR)
$(COMPAS)
OBJ := $(OBJ) $(OUT)/$(d)/boot.a
CLEAN := $(CLEAN) $(OUT)/$(d)/boot.a
# include this at last
include $(MK)/stdrules.mk

View File

@ -1,216 +0,0 @@
#define ASM_FILE
#include "kernel/hal/mem.h"
#include "hal/multiboot2.h"
%define GET_PADDR(x) ((x) - KERNEL_IMAGE_VADDR + KERNEL_IMAGE_PADDR)
%define BOCHS_BREAK xchg bx,bx
extern hal_main
extern hal_write_initial_page_table
global hal_entry_32
section .multiboot_header
bits 32
MULTIBOOT_ARCH equ 0
MULTIBOOT_CHECK_SUM equ (0xFFFFFFFF - (MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_HEADER_SIZE + MULTIBOOT_ARCH) + 1)
MULTIBOOT_REQ_LOADERNAME equ 2
MULTIBOOT_REQ_MMAP equ 6
MULTIBOOT_REQ_ACPI_RSDP equ 15
;====================
;header tag
align MULTIBOOT_HEADER_ALIGN
multiboot_header_tag:
dd MULTIBOOT2_HEADER_MAGIC
dd MULTIBOOT_ARCH
dd MULTIBOOT_HEADER_SIZE
dd MULTIBOOT_CHECK_SUM
;====================
;INFO_REQUEST_TAG
align MULTIBOOT_INFO_ALIGN
multiboot_info_tag:
dw 0x1 ; type=1
dw 0x0 ; flag=0
dd MULTIBOOT_INFO_TAG_SIZE
dd MULTIBOOT_REQ_LOADERNAME
dd MULTIBOOT_REQ_MMAP
MULTIBOOT_INFO_TAG_SIZE equ ($ - multiboot_info_tag)
;====================
;MODULE ALIGNMENT TAG
align MULTIBOOT_INFO_ALIGN
dw 0x6; type=6
dw 0x0; flag=0
dd 0x8
;====================
align MULTIBOOT_INFO_ALIGN
;End_tag
dw 0x0
dw 0x0
dd 0x8
;====================
MULTIBOOT_HEADER_SIZE equ ($ - multiboot_header_tag)
section .text
bits 32
align KERNEL_PAGE_SIZE
hal_entry_32:
cli
cld
cmp eax,MULTIBOOT2_BOOTLOADER_MAGIC
je .loaded_by_grub
hlt
.loaded_by_grub:
; save multiboot_info*
mov esi,ebx
call halp_check_long_mode
cmp eax,1
je .init_long_mode
hlt
.init_long_mode:
; disable paging first
mov eax, cr0 ; Set the A-register to control register 0.
and eax, 0x7FFFFFFF ; Clear the PG-bit, which is bit 31.
mov cr0, eax ; Set control register 0 to the A-register.
; identity map the first 4GB
; ATTRIBUTE = READ/WRITE + SU
mov eax, GET_PADDR(_pml4)
mov dword [eax], GET_PADDR(_pdpt) + 11b
; write values for pdpt
mov ecx, 10000011b
mov eax, GET_PADDR(_pdpt)
mov dword [eax], ecx
add eax,8
add ecx,0x40000000 ;1G
mov dword [eax], ecx
add eax,8
add ecx,0x40000000 ;1G
mov dword [eax], ecx
add eax,8
add ecx,0x40000000 ;1G
mov dword [eax], ecx
BOCHS_BREAK
; enable PAE
mov eax, cr4 ; Set the A-register to control register 4.
or eax, 1 << 5 ; Set the PAE-bit, which is the 6th bit (bit 5).
mov cr4, eax ; Set control register 4 to the A-register.
; enable long mode
mov ecx, 0xC0000080 ; Set the C-register to 0xC0000080, which is the EFER MSR.
rdmsr ; Read from the model-specific register.
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, GET_PADDR(_pml4)
mov cr3, eax
; enable paging, enter compatibility mode
mov eax, cr0 ; Set the A-register to control register 0.
or eax, 1 << 31 ; Set the PG-bit, which is bit 31.
mov cr0, eax ; Set control register 0 to the A-register.
; enter long mode
lgdt [GET_PADDR(_gdt.ptr)]
jmp _gdt.code:GET_PADDR(halp_entry_64)
hlt
halp_check_long_mode:
push ebp
mov ebp,esp
pushfd
pop eax
mov ecx, eax
xor eax, 1 << 21
push eax
popfd
pushfd
pop eax
push ecx
popfd
xor eax, ecx
jz .not_supported
mov eax, 0x80000000 ; Set the A-register to 0x80000000.
cpuid ; CPU identification.
cmp eax, 0x80000001 ; Compare the A-register with 0x80000001.
jb .not_supported ; It is less, there is no long mode.
mov eax, 0x80000001 ; Set the A-register to 0x80000001.
cpuid ; CPU identification.
test edx, 1 << 29 ; Test if the LM-bit, which is bit 29, is set in the D-register.
jz .not_supported ; They aren't, there is no long mode.
mov eax,1
jmp .end
.not_supported:
xor eax,eax
.end:
mov esp,ebp
pop ebp
ret
section .text
bits 64
halp_entry_64:
; note that we are still at the identity mapping
mov ax,_gdt.data
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
mov rsp, GET_PADDR(_stack)
mov rdi, rsi ; multiboot_info*
call hal_write_initial_page_table
test rax,rax
jne .end
call hal_main
.end:
hlt
section .data
bits 64
align KERNEL_PAGE_SIZE
times 4096 db 0
_stack:
_pml4:
align KERNEL_PAGE_SIZE
times 4096 db 0
_pdpt:
align KERNEL_PAGE_SIZE
times 4096 db 0
_gdt: ; Global Descriptor Table (long mode).
.null: equ $ - _gdt ; The null descriptor.
dw 0 ; Limit (low).
dw 0 ; Base (low).
db 0 ; Base (middle)
db 0 ; Access.
db 0 ; Granularity.
db 0 ; Base (high).
.code: equ $ - _gdt ; The code descriptor.
dw 0 ; Limit (low).
dw 0 ; Base (low).
db 0 ; Base (middle)
db 10011010b ; Access (exec/read).
db 00100000b ; Granularity.
db 0 ; Base (high).
.data: equ $ - _gdt ; The data descriptor.
dw 0 ; Limit (low).
dw 0 ; Base (low).
db 0 ; Base (middle)
db 10010010b ; Access (read/write).
db 00000000b ; Granularity.
db 0 ; Base (high).
.ptr:
; GDT PTR
dw $ - _gdt - 1 ; Limit.
dq GET_PADDR(_gdt) ; Base.

View File

@ -1,14 +1,10 @@
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
#include "hal/print.h"
#include "hal/mem.h"
#include "hal/intr.h"
#include "hal/cpu.h"
#include "lib/sxtdlib.h"
#include "hal/boot.h"
#include "status.h"
static void KABI halp_obtain_cpu_info(boot_info_t *hal_info)
{
@ -22,10 +18,10 @@ static void KABI halp_obtain_cpu_info(boot_info_t *hal_info)
hal_info->cpu_vd_str[12] = 0;
}
void KABI hal_main(void *m_info)
status_t KABI hal_init(void *m_info)
{
if (m_info == NULL || (uint64_t) m_info & lb_bit_field_mask(0, 2))
return;
return STATUS_FAIL;
// init HAL infrastructures
hal_print_init();
@ -34,17 +30,14 @@ void KABI hal_main(void *m_info)
boot_info_t* boot_info = halloc(sizeof(boot_info_t));
boot_info->krnl_end = KERNEL_IMAGE_END_VADDR;
// obtain cpu info
halp_obtain_cpu_info(boot_info);
// init interrupt
if(hal_interrupt_init() != 0)
{
return;
return STATUS_FAIL;
}
// pass the control to the kernel
ke_main(boot_info);
return;
return STATUS_SUCCESS;
}

View File

@ -1,7 +1,3 @@
; Copyright 2016 secXsQuared
; Distributed under GPL license
; See COPYING under root for details
;Functions preserve the registers rbx, rsp, rbp, r12, r13, r14, and 15
;rax, rdi, rsi, rdx, rcx, r8, r9, r10, r11 are scratch registers.
;function parameter: rdi,rsi,rdx,rcx,r8,r9

View File

@ -1,7 +1,3 @@
; Copyright 2016 secXsQuared
; Distributed under GPL license
; See COPYING under root for details
%macro PUSHAQ 0
push rax ;save current rax
push rbx ;save current rbx

View File

@ -1,8 +1,3 @@
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
#include "type.h"
#include "lib/sxtdlib.h"
#include "hal/print.h"

View File

@ -1,375 +0,0 @@
/* multiboot2.h - Multiboot 2 header file. */
/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
* DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _HAL_MULTIBOOT_H_
#define _HAL_MULTIBOOT_H_
/* How many bytes from the start of the file we search for the header. */
#define MULTIBOOT_SEARCH 32768
#define MULTIBOOT_HEADER_ALIGN 8
/* The magic field should contain this. */
#define MULTIBOOT2_HEADER_MAGIC 0xe85250d6
/* This should be in %eax. */
#define MULTIBOOT2_BOOTLOADER_MAGIC 0x36d76289
/* Alignment of multiboot modules. */
#define MULTIBOOT_MOD_ALIGN 0x00001000
/* Alignment of the multiboot info structure. */
#define MULTIBOOT_INFO_ALIGN 0x00000008
/* Flags set in the 'flags' member of the multiboot header. */
#define MULTIBOOT_TAG_ALIGN 8
#define MULTIBOOT_TAG_TYPE_END 0
#define MULTIBOOT_TAG_TYPE_CMDLINE 1
#define MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME 2
#define MULTIBOOT_TAG_TYPE_MODULE 3
#define MULTIBOOT_TAG_TYPE_BASIC_MEMINFO 4
#define MULTIBOOT_TAG_TYPE_BOOTDEV 5
#define MULTIBOOT_TAG_TYPE_MMAP 6
#define MULTIBOOT_TAG_TYPE_VBE 7
#define MULTIBOOT_TAG_TYPE_FRAMEBUFFER 8
#define MULTIBOOT_TAG_TYPE_ELF_SECTIONS 9
#define MULTIBOOT_TAG_TYPE_APM 10
#define MULTIBOOT_TAG_TYPE_EFI32 11
#define MULTIBOOT_TAG_TYPE_EFI64 12
#define MULTIBOOT_TAG_TYPE_SMBIOS 13
#define MULTIBOOT_TAG_TYPE_ACPI_OLD 14
#define MULTIBOOT_TAG_TYPE_ACPI_NEW 15
#define MULTIBOOT_TAG_TYPE_NETWORK 16
#define MULTIBOOT_TAG_TYPE_EFI_MMAP 17
#define MULTIBOOT_TAG_TYPE_EFI_BS 18
#define MULTIBOOT_HEADER_TAG_END 0
#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1
#define MULTIBOOT_HEADER_TAG_ADDRESS 2
#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS 3
#define MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS 4
#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5
#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6
#define MULTIBOOT_HEADER_TAG_EFI_BS 7
#define MULTIBOOT_ARCHITECTURE_I386 0
#define MULTIBOOT_ARCHITECTURE_MIPS32 4
#define MULTIBOOT_HEADER_TAG_OPTIONAL 1
#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
#ifndef ASM_FILE
typedef unsigned char multiboot_uint8_t;
typedef unsigned short multiboot_uint16_t;
typedef unsigned int multiboot_uint32_t;
typedef unsigned long long multiboot_uint64_t;
struct multiboot_header
{
/* Must be MULTIBOOT_MAGIC - see above. */
multiboot_uint32_t magic;
/* ISA */
multiboot_uint32_t architecture;
/* Total header length. */
multiboot_uint32_t header_length;
/* The above fields plus this one must equal 0 mod 2^32. */
multiboot_uint32_t checksum;
};
struct multiboot_header_tag
{
multiboot_uint16_t type;
multiboot_uint16_t flags;
multiboot_uint32_t size;
};
struct multiboot_header_tag_information_request
{
multiboot_uint16_t type;
multiboot_uint16_t flags;
multiboot_uint32_t size;
multiboot_uint32_t requests[0];
};
struct multiboot_header_tag_address
{
multiboot_uint16_t type;
multiboot_uint16_t flags;
multiboot_uint32_t size;
multiboot_uint32_t header_addr;
multiboot_uint32_t load_addr;
multiboot_uint32_t load_end_addr;
multiboot_uint32_t bss_end_addr;
};
struct multiboot_header_tag_entry_address
{
multiboot_uint16_t type;
multiboot_uint16_t flags;
multiboot_uint32_t size;
multiboot_uint32_t entry_addr;
};
struct multiboot_header_tag_console_flags
{
multiboot_uint16_t type;
multiboot_uint16_t flags;
multiboot_uint32_t size;
multiboot_uint32_t console_flags;
};
struct multiboot_header_tag_framebuffer
{
multiboot_uint16_t type;
multiboot_uint16_t flags;
multiboot_uint32_t size;
multiboot_uint32_t width;
multiboot_uint32_t height;
multiboot_uint32_t depth;
};
struct multiboot_header_tag_module_align
{
multiboot_uint16_t type;
multiboot_uint16_t flags;
multiboot_uint32_t size;
};
struct multiboot_color
{
multiboot_uint8_t red;
multiboot_uint8_t green;
multiboot_uint8_t blue;
};
struct multiboot_mmap_entry
{
multiboot_uint64_t addr;
multiboot_uint64_t len;
#define MULTIBOOT_MEMORY_AVAILABLE 1
#define MULTIBOOT_MEMORY_RESERVED 2
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
#define MULTIBOOT_MEMORY_NVS 4
#define MULTIBOOT_MEMORY_BADRAM 5
multiboot_uint32_t type;
multiboot_uint32_t zero;
} GRUB_PACKED;
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
struct multiboot_tag
{
multiboot_uint32_t type;
multiboot_uint32_t size;
};
struct multiboot_tag_string
{
multiboot_uint32_t type;
multiboot_uint32_t size;
char string[0];
};
struct multiboot_tag_module
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint32_t mod_start;
multiboot_uint32_t mod_end;
char cmdline[0];
};
struct multiboot_tag_basic_meminfo
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint32_t mem_lower;
multiboot_uint32_t mem_upper;
};
struct multiboot_tag_bootdev
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint32_t biosdev;
multiboot_uint32_t slice;
multiboot_uint32_t part;
};
struct multiboot_tag_mmap
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint32_t entry_size;
multiboot_uint32_t entry_version;
struct multiboot_mmap_entry entries[0];
};
struct multiboot_vbe_info_block
{
multiboot_uint8_t external_specification[512];
};
struct multiboot_vbe_mode_info_block
{
multiboot_uint8_t external_specification[256];
};
struct multiboot_tag_vbe
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint16_t vbe_mode;
multiboot_uint16_t vbe_interface_seg;
multiboot_uint16_t vbe_interface_off;
multiboot_uint16_t vbe_interface_len;
struct multiboot_vbe_info_block vbe_control_info;
struct multiboot_vbe_mode_info_block vbe_mode_info;
};
struct multiboot_tag_framebuffer_common
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint64_t framebuffer_addr;
multiboot_uint32_t framebuffer_pitch;
multiboot_uint32_t framebuffer_width;
multiboot_uint32_t framebuffer_height;
multiboot_uint8_t framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_uint8_t framebuffer_type;
multiboot_uint16_t reserved;
};
struct multiboot_tag_framebuffer
{
struct multiboot_tag_framebuffer_common common;
union
{
struct
{
multiboot_uint16_t framebuffer_palette_num_colors;
struct multiboot_color framebuffer_palette[0];
};
struct
{
multiboot_uint8_t framebuffer_red_field_position;
multiboot_uint8_t framebuffer_red_mask_size;
multiboot_uint8_t framebuffer_green_field_position;
multiboot_uint8_t framebuffer_green_mask_size;
multiboot_uint8_t framebuffer_blue_field_position;
multiboot_uint8_t framebuffer_blue_mask_size;
};
};
};
struct multiboot_tag_elf_sections
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint32_t num;
multiboot_uint32_t entsize;
multiboot_uint32_t shndx;
char sections[0];
};
struct multiboot_tag_apm
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint16_t version;
multiboot_uint16_t cseg;
multiboot_uint32_t offset;
multiboot_uint16_t cseg_16;
multiboot_uint16_t dseg;
multiboot_uint16_t flags;
multiboot_uint16_t cseg_len;
multiboot_uint16_t cseg_16_len;
multiboot_uint16_t dseg_len;
};
struct multiboot_tag_efi32
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint32_t pointer;
};
struct multiboot_tag_efi64
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint64_t pointer;
};
struct multiboot_tag_smbios
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint8_t major;
multiboot_uint8_t minor;
multiboot_uint8_t reserved[6];
multiboot_uint8_t tables[0];
};
struct multiboot_tag_old_acpi
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint8_t rsdp[0];
};
struct multiboot_tag_new_acpi
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint8_t rsdp[0];
};
struct multiboot_tag_network
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint8_t dhcpack[0];
};
struct multiboot_tag_efi_mmap
{
multiboot_uint32_t type;
multiboot_uint32_t size;
multiboot_uint32_t descr_size;
multiboot_uint32_t descr_vers;
multiboot_uint8_t efi_mmap[0];
};
#endif /* ! ASM_FILE */
#endif /* ! MULTIBOOT_HEADER */

View File

@ -4,6 +4,7 @@
#include "type.h"
#include "kernel/hal/intr.h"
#include "kernel/hal/mem.h"
#include "status.h"
/**
* Required OS boot info
@ -16,6 +17,6 @@ typedef struct
char cpu_vd_str[13];
} boot_info_t;
void KABI ke_main(boot_info_t* info);
status_t KABI hal_init(void *m_info);
#endif

View File

@ -36,11 +36,6 @@
#include "type.h"
#include "lib/linked_list.h"
/**
* From linker.inc
*/
extern char KERNEL_IMAGE_END_VADDR[];
/**
* PMM init info
*/

View File

@ -6,6 +6,8 @@
#define BUG_CHECK_IRQL_MISMATCH 0
#define BUG_CHECK_PMM_UNALIGNED 1
void KABI ke_bug_check(uint64_t reason);
void KABI ke_panic(uint64_t reason);
void KABI ke_trap(void);
#endif

View File

@ -1,8 +1,3 @@
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
#ifndef _LIB_AVL_TREE_H_
#define _LIB_AVL_TREE_H_

View File

@ -1,8 +1,3 @@
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
#ifndef _LIB_LINKED_LIST_H_
#define _LIB_LINKED_LIST_H_

View File

@ -1,8 +1,3 @@
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
#ifndef _LIB_SALLOC_H_
#define _LIB_SALLOC_H_

View File

@ -1,8 +1,3 @@
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
#ifndef _LIB_SXTDLIB_H_
#define _LIB_SXTDLIB_H_

View File

@ -17,7 +17,7 @@ typedef uint32_t status_t;
// bits 15-29 - Facility 32768 in total
//
#define SX_MAKE_STATUS(Severity, Facility, Return) (((Severity) << 30) | ((Facility) << 16) | (Return))
#define SX_MAKE_STATUS(Severity, Facility, Return) ((status_t)(((Severity) << 30) | ((Facility) << 16) | (Return)))
#define SEVERITY_ERROR 0x3
#define SEVERITY_SUCCESS 0x0

View File

@ -1,8 +1,3 @@
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
#ifndef _TYPE_H_
#define _TYPE_H_

View File

@ -1,42 +1,19 @@
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
#include "kernel/ke/boot.h"
#include "kernel/ke/alloc.h"
#include "test/test_case.h"
#include "kernel/ke/print.h"
#include "kernel/ke/bug_check.h"
// returning from this function results in halting the cpu
/**
* Kernel entry point
* @param boot_info passed by the bootloader
*/
void KABI ke_main(boot_info_t *boot_info)
{
if (boot_info == NULL)
status_t status = STATUS_SUCCESS;
status = hal_init(boot_info);
if (!sx_success(status))
{
// failed.
ke_printf("KERNEL: HAL init failed.\n");
ke_panic(status);
return;
}
// init kernel heap
//sx_pmm_init(boot_info->pmm_info);
ke_alloc_init();
// ke_printf("KERNEL: Base Addr is 0x%X. Size is %uB, %uKB.\n",
// boot_info->krnl_start,
// (boot_info->krnl_end - boot_info->krnl_start),
// (boot_info->krnl_end - boot_info->krnl_start) / 1024);
ke_printf("KERNEL: CPU Vendor is \"%s\".\n", boot_info->cpu_vd_str);
linked_list_test();
avl_tree_test();
salloc_test();
ke_printf("KERNEL: Kernel tasks finished.\n");
return;
ke_trap();
}

View File

@ -2,8 +2,13 @@
#include "kernel/ke/print.h"
#include "kernel/ke/bug_check.h"
void KABI ke_bug_check(uint64_t reason)
void KABI ke_trap(void)
{
while(true){};
}
void KABI ke_panic(uint64_t reason)
{
ke_printf("BugCheck: Reason - %ul\n", reason);
while(true){};
ke_trap();
}

View File

@ -1,8 +1,3 @@
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
#include "lib/avl_tree.h"
static inline int32_t KABI lbp_avl_tree_node_get_height(avl_tree_node_t *node)

View File

@ -1,8 +1,3 @@
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
#include "lib/linked_list.h"
static void KABI lbp_init_linked_list_node(linked_list_node_t *node)

View File

@ -1,7 +1,3 @@
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
#include "type.h"
#include "lib/sxtdlib.h"

View File

@ -1,8 +1,3 @@
/* Copyright 2016 secXsQuared
* Distributed under GPL license
* See COPYING under root for details
*/
#include "type.h"
#include "lib/sxtdlib.h"

View File

@ -1,7 +1,6 @@
include $(MK)/prologue.mk
SRCIN_$(d) := $(d)/linker.ld.in \
$(d)/grub.cfg.in
SRCIN_$(d) := $(d)/linker.ld.in
include $(MK)/stdrules.mk

View File

@ -1,3 +0,0 @@
menuentry "secX" {
multiboot2 /secX/secxkrnl.elf
}

View File

@ -3,43 +3,31 @@
OUTPUT_FORMAT(elf64-x86-64)
OUTPUT_ARCH(i386:x86-64)
ENTRY(hal_entry_32)
ENTRY(ke_main)
SECTIONS
{
. = KERNEL_IMAGE_VADDR;
. = KERNEL_IMAGE_VADDR;
.multiboot_header ALIGN(KERNEL_PAGE_SIZE) : AT(ADDR(.multiboot_header) + KERNEL_IMAGE_PADDR - KERNEL_IMAGE_VADDR)
{
*(.multiboot_header)
}
.multiboot_header ALIGN(KERNEL_PAGE_SIZE) : AT(ADDR(.multiboot_header) + KERNEL_IMAGE_PADDR - KERNEL_IMAGE_VADDR)
{
*(.multiboot_header)
}
.text ALIGN(KERNEL_PAGE_SIZE) : AT(ADDR(.text) + KERNEL_IMAGE_PADDR - KERNEL_IMAGE_VADDR)
{
*(.text)
}
.text ALIGN(KERNEL_PAGE_SIZE) : AT(ADDR(.text) + KERNEL_IMAGE_PADDR - KERNEL_IMAGE_VADDR)
{
*(.text)
}
.data ALIGN(KERNEL_PAGE_SIZE) : AT(ADDR(.data) + KERNEL_IMAGE_PADDR - KERNEL_IMAGE_VADDR)
{
*(.data)
*(.rodata*)
}
.data ALIGN(KERNEL_PAGE_SIZE) : AT(ADDR(.data) + KERNEL_IMAGE_PADDR - KERNEL_IMAGE_VADDR)
{
*(.data)
*(.rodata*)
}
.bss ALIGN(KERNEL_PAGE_SIZE) : AT(ADDR(.bss) + KERNEL_IMAGE_PADDR - KERNEL_IMAGE_VADDR)
{
*(.bss)
*(COMMON)
}
KERNEL_IMAGE_END_VADDR = .;
/DISCARD/ :
{
*(.gcc_except_table)
*(.eh_frame)
*(.note)
*(.comment)
*(.rel.*)
*(.rela.*)
.bss ALIGN(KERNEL_PAGE_SIZE) : AT(ADDR(.bss) + KERNEL_IMAGE_PADDR - KERNEL_IMAGE_VADDR)
{
*(.bss)
*(COMMON)
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,49 +0,0 @@
# configuration file generated by Bochs
plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1, gameport=1
config_interface: win32config
display_library: win32, options="gui_debug"
memory: host=256, guest=256
romimage: file="$BXSHARE/BIOS-bochs-latest"
vgaromimage: file="$BXSHARE/VGABIOS-lgpl-latest"
boot: cdrom
magic_break: enabled=1
floppy_bootsig_check: disabled=0
# no floppya
# no floppyb
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=cdrom, path="out/secxkrnl.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
ata1-slave: type=none
ata2: enabled=0
ata3: enabled=0
pci: enabled=1, chipset=i440fx
vga: extension=vbe, update_freq=5
cpu: count=1, ips=4000000, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
cpuid: level=6, stepping=3, model=3, family=6, vendor_string="GenuineIntel", brand_string=" Intel(R) Pentium(R) 4 CPU "
cpuid: mmx=1, apic=xapic, simd=sse2, sse4a=0, misaligned_sse=0, sep=1, movbe=0, adx=0
cpuid: aes=0, sha=0, xsave=0, xsaveopt=0, x86_64=1, 1g_pages=1, pcid=0, fsgsbase=1
cpuid: smep=0, smap=0, mwait=1, vmx=1
print_timestamps: enabled=0
port_e9_hack: enabled=0
private_colormap: enabled=0
clock: sync=none, time0=local, rtc_sync=0
# no cmosimage
# no loader
log: -
logprefix: %t%e%d
debug: action=ignore
info: action=report
error: action=report
panic: action=ask
keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none
mouse: type=ps2, enabled=0, toggle=ctrl+mbutton
sound: driver="default", waveout=none, wavein=none
speaker: enabled=1, mode=sound
parport1: enabled=1, file=none
parport2: enabled=0
com1: enabled=1, mode=null
com2: enabled=0
com3: enabled=0
com4: enabled=0

View File

@ -1,2 +0,0 @@
@echo off
qemu-system-x86_64 -bios sim/qemu/qemu_bios.bin -cdrom out/secxkrnl.iso -s -S

View File

@ -1,2 +0,0 @@
#!/bin/bash
qemu-system-x86_64 -bios sim/qemu/qemu_bios.bin -cdrom out/secxkrnl.iso -s -S

Binary file not shown.

View File

@ -1,3 +0,0 @@
target remote localhost:1234
symbol-file secxkrnl.elf
break *0x1003000