Add support for C++
This was a doozy. I had to recompile gcc with a custom target to get it to output the CRT{BEGIN/END}.o files with proper 64 bit relocations. The CMakeLists.txt file was also edited to allow these files to be linked (thereby actually adding the support) as well as to automatically create the boot image upon build.
This commit is contained in:
parent
4c9108bc87
commit
aba82eaacb
|
@ -9,26 +9,46 @@ project(chroma)
|
|||
|
||||
|
||||
SET(src_files
|
||||
chroma/kernel.c
|
||||
chroma/video/draw.c
|
||||
chroma/video/print.c
|
||||
chroma/system/cpu.c
|
||||
chroma/system/rw.c
|
||||
chroma/system/serial.c
|
||||
chroma/system/memory/paging.c
|
||||
chroma/system/memory/physmem.c
|
||||
chroma/system/drivers/keyboard.c
|
||||
${CMAKE_SOURCE_DIR}/chroma/kernel.c
|
||||
${CMAKE_SOURCE_DIR}/chroma/video/draw.c
|
||||
${CMAKE_SOURCE_DIR}/chroma/video/print.c
|
||||
${CMAKE_SOURCE_DIR}/chroma/system/cpu.c
|
||||
${CMAKE_SOURCE_DIR}/chroma/system/rw.c
|
||||
${CMAKE_SOURCE_DIR}/chroma/system/serial.c
|
||||
${CMAKE_SOURCE_DIR}/chroma/system/pci.c
|
||||
${CMAKE_SOURCE_DIR}/chroma/system/memory/paging.c
|
||||
${CMAKE_SOURCE_DIR}/chroma/system/memory/physmem.c
|
||||
${CMAKE_SOURCE_DIR}/chroma/system/drivers/keyboard.c
|
||||
)
|
||||
|
||||
include_directories("chroma/inc")
|
||||
|
||||
SET(src_no_sse
|
||||
chroma/system/interrupts.c
|
||||
${CMAKE_SOURCE_DIR}/chroma/system/interrupts.c
|
||||
)
|
||||
|
||||
SET(src_preamble
|
||||
${CMAKE_SOURCE_DIR}/global/crt0.o
|
||||
${CMAKE_SOURCE_DIR}/global/crti.o
|
||||
${CMAKE_SOURCE_DIR}/global/crtbegin.o
|
||||
)
|
||||
|
||||
set(src_epilogue
|
||||
${CMAKE_SOURCE_DIR}/global/crtend.o
|
||||
${CMAKE_SOURCE_DIR}/global/crtn.o
|
||||
)
|
||||
|
||||
set_property(SOURCE ${src_no_sse} PROPERTY COMPILE_FLAGS -mgeneral-regs-only)
|
||||
|
||||
add_executable(kernel.elf ${src_files} ${src_no_sse} font.o)
|
||||
target_compile_options(kernel.elf PRIVATE -ffreestanding -O2 -Wall -Wextra -Wall -Werror -pedantic -fPIC)
|
||||
target_link_options(kernel.elf PRIVATE -T linker.ld -ffreestanding -O2 -nostdlib -lgcc)
|
||||
add_executable(kernel)
|
||||
|
||||
target_sources(kernel PUBLIC ${src_preamble} PUBLIC ${src_files} PUBLIC ${src_no_sse} PUBLIC ${CMAKE_SOURCE_DIR}/font.o PUBLIC ${src_epilogue})
|
||||
target_compile_options(kernel PRIVATE -ffreestanding -O2 -Wall -Wextra -Wall -Werror -pedantic -fPIC -fno-exceptions)
|
||||
target_link_options(kernel PRIVATE -T linker.ld -ffreestanding -O2 -nostdlib -nostartfiles -lgcc)
|
||||
|
||||
add_custom_command(
|
||||
TARGET kernel
|
||||
POST_BUILD
|
||||
COMMAND cp ${CMAKE_SOURCE_DIR}/kernel ${CMAKE_SOURCE_DIR}/img/boot/exe
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/mkbootimg chroma.json chroma.img
|
||||
)
|
|
@ -58,3 +58,7 @@ void InitPrint();
|
|||
|
||||
void SetupInitialGDT();
|
||||
void SetupIDT();
|
||||
|
||||
int Main();
|
||||
|
||||
void Exit();
|
||||
|
|
|
@ -16,12 +16,16 @@ size_t KernelAddr = (size_t) &LoadAddr;
|
|||
size_t KernelEnd = (size_t) &end;
|
||||
|
||||
|
||||
void _start(void) {
|
||||
int Main(void) {
|
||||
|
||||
|
||||
SerialPrintf("\r\nBooting Chroma..\r\n");
|
||||
SerialPrintf("Kernel loaded at 0x%p, ends at 0x%p, is %d bytes long.\r\n", KernelAddr, KernelEnd, KernelEnd - KernelAddr);
|
||||
|
||||
SerialPrintf("The bootloader has put the paging tables at 0x%p.\r\n", ReadControlRegister(3));
|
||||
|
||||
TraversePageTables();
|
||||
|
||||
ListMemoryMap();
|
||||
|
||||
InitPrint();
|
||||
|
@ -42,4 +46,12 @@ void _start(void) {
|
|||
|
||||
for(;;) { }
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Exit(int ExitCode) {
|
||||
SerialPrintf("Kernel stopped with code %x\r\n", ExitCode);
|
||||
|
||||
}
|
BIN
global/a.out
Normal file
BIN
global/a.out
Normal file
Binary file not shown.
11
global/crt0.c
Normal file
11
global/crt0.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
extern void Exit(int code);
|
||||
extern int Main();
|
||||
|
||||
extern void _init();
|
||||
|
||||
void _start() {
|
||||
_init();
|
||||
int ex = Main();
|
||||
Exit(ex);
|
||||
}
|
BIN
global/crt0.o
Normal file
BIN
global/crt0.o
Normal file
Binary file not shown.
10
global/crt0.s
Normal file
10
global/crt0.s
Normal file
|
@ -0,0 +1,10 @@
|
|||
.section .text
|
||||
.global _start
|
||||
.global _init
|
||||
.global main
|
||||
.global _fini
|
||||
.type _start, @function
|
||||
_start:
|
||||
call _init
|
||||
call main
|
||||
call _fini
|
BIN
global/crtbegin.o
Normal file
BIN
global/crtbegin.o
Normal file
Binary file not shown.
BIN
global/crtend.o
Normal file
BIN
global/crtend.o
Normal file
Binary file not shown.
BIN
global/crti.o
Normal file
BIN
global/crti.o
Normal file
Binary file not shown.
13
global/crti.s
Normal file
13
global/crti.s
Normal file
|
@ -0,0 +1,13 @@
|
|||
.section .init
|
||||
.global _init
|
||||
.type _init, @function
|
||||
_init:
|
||||
push %rbp
|
||||
movq %rsp, %rbp
|
||||
|
||||
.section .fini
|
||||
.global _fini
|
||||
.type _fini, @function
|
||||
_fini:
|
||||
push %rbp
|
||||
movq %rsp, %rbp
|
BIN
global/crtn.o
Normal file
BIN
global/crtn.o
Normal file
Binary file not shown.
9
global/crtn.s
Normal file
9
global/crtn.s
Normal file
|
@ -0,0 +1,9 @@
|
|||
.section .init
|
||||
|
||||
popq %rbp
|
||||
ret
|
||||
|
||||
.section .fini
|
||||
|
||||
popq %rbp
|
||||
ret
|
Loading…
Reference in New Issue
Block a user