Linker stage

This commit is contained in:
Fergal Moran
2020-06-04 22:59:47 +01:00
parent 316553b3af
commit 5cddaac0b7
5 changed files with 55 additions and 4 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.vscode
loader.o
*.o
*.bin

View File

@@ -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

1
README.md Normal file
View File

@@ -0,0 +1 @@
Ya boy wrote his own operating system!!!!

View File

@@ -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)

View File

@@ -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)
}
}