mirror of
https://github.com/fergalmoran/ferglos.git
synced 2025-12-22 09:28:22 +00:00
Linker stage
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
.vscode
|
||||
loader.o
|
||||
*.o
|
||||
*.bin
|
||||
|
||||
4
Makefile
4
Makefile
@@ -1,4 +1,4 @@
|
||||
GPPPARAMS = -m32
|
||||
GPPPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore
|
||||
ASPARAMS = --32
|
||||
LDPARAMS = -melf_i386
|
||||
|
||||
@@ -11,7 +11,7 @@ objs = loader.o kernel.o
|
||||
as $(ASPARAMS) -o $@ $<
|
||||
|
||||
ferglos.bin: linker.ld $(objs)
|
||||
ld $(LDPARAMS) -T linker.ld $< -o $@ $(objs)
|
||||
ld $(LDPARAMS) -T $< -o $@ $(objs)
|
||||
|
||||
install: ferglos.bin
|
||||
sudo cp $< /boot/ferglos.bin
|
||||
|
||||
16
kernel.cpp
16
kernel.cpp
@@ -1,8 +1,22 @@
|
||||
// yip - ya'boy is writing his own printf
|
||||
// libc doesn't exist yet so got no choice
|
||||
|
||||
void printf(char* str) {
|
||||
unsigned short* vid_mem = (unsigned short*)0xb8000;
|
||||
for (int i = 0; str[i] != '\0'; i++) {
|
||||
//high byte is colour, so just need to copy to text address
|
||||
vid_mem[i] = (vid_mem[i] * 0xFF00) | str[i];
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" constructor start_ctors;
|
||||
extern "C" constructor end_ctors;
|
||||
|
||||
/*
|
||||
take in the multiboot structure and the GRUB magic number
|
||||
not sure I actually need magic_num though
|
||||
*/
|
||||
void ferglos_Main(void* mb_struct, unsigned int magic_num) {
|
||||
extern "C" void ferglos_Main(void* mb_struct, unsigned int magic_num) {
|
||||
printf("Hello, Sailor!");
|
||||
|
||||
while (1)
|
||||
|
||||
35
linker.ld
35
linker.ld
@@ -0,0 +1,35 @@
|
||||
ENTRY(loader)
|
||||
OUTPUT_FORMAT(elf32-i386)
|
||||
OUTPUT_ARCH(i386:i386)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x0100000;
|
||||
.text :
|
||||
{
|
||||
*(.multiboot)
|
||||
*(.text*)
|
||||
*(.rodata)
|
||||
}
|
||||
|
||||
.data :
|
||||
{
|
||||
start_ctors = .;
|
||||
KEEP(*(.init_array ));
|
||||
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*)));
|
||||
end_ctors = .;
|
||||
|
||||
*(.data)
|
||||
}
|
||||
|
||||
.bss :
|
||||
{
|
||||
*.(.bss)
|
||||
}
|
||||
|
||||
/DISCARD/ :
|
||||
{
|
||||
*(.fini_array*)
|
||||
*(.comment)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user