Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ KERNEL_CCFLAGS=-Wall -c -ffreestanding -fno-pie -g -std=gnu99
# which is likely to work on native linux-x86.
#
CC=gcc -m32
LD=ld -melf_i386
#LD=ld -arch i386
LD=ld
KERNEL_LD=ld -melf_i386
AR=ar
OBJCOPY=objcopy
ISOGEN=genisoimage
Expand All @@ -15,6 +15,7 @@ ISOGEN=genisoimage
# add cross/bin to your path, and uncomment these lines:
#CC=i686-elf-gcc
#LD=i686-elf-ld
#KERNEL_LD=i686-elf-ld
#AR=i686-elf-ar
#OBJCOPY=i686-elf-objcopy

Expand Down
6 changes: 3 additions & 3 deletions kernel/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include ../Makefile.config

KERNEL_OBJECTS=kernelcore.o main.o console.o page.o keyboard.o mouse.o event_queue.o clock.o interrupt.o kmalloc.o pic.o ata.o cdromfs.o string.o bitmap.o graphics.o font.o syscall_handler.o process.o mutex.o list.o pagetable.o rtc.o kshell.o fs.o hash_set.o diskfs.o serial.o elf.o device.o kobject.o pipe.o bcache.o printf.o is_valid.o window.o
KERNEL_OBJECTS=kernelcore.o main.o console.o page.o keyboard.o mouse.o event_queue.o clock.o interrupt.o kmalloc.o pic.o ata.o cdromfs.o string.o bitmap.o graphics.o font.o syscall_handler.o process.o mutex.o list.o pagetable.o rtc.o kshell.o fs.o hash_set.o diskfs.o serial.o loader.o device.o kobject.o pipe.o bcache.o printf.o is_valid.o window.o

basekernel.img: bootblock kernel
cat bootblock kernel /dev/zero | head -c 1474560 > basekernel.img
Expand All @@ -12,10 +12,10 @@ bootblock: bootblock.elf
${OBJCOPY} -O binary $< $@

kernel.elf: ${KERNEL_OBJECTS}
${LD} ${KERNEL_LDFLAGS} -Ttext 0x10000 ${KERNEL_OBJECTS} -o $@
${KERNEL_LD} ${KERNEL_LDFLAGS} -Ttext 0x10000 ${KERNEL_OBJECTS} -o $@

bootblock.elf: bootblock.o
${LD} ${KERNEL_LDFLAGS} -Ttext 0 $< -o $@
${KERNEL_LD} ${KERNEL_LDFLAGS} -Ttext 0 $< -o $@

%.o: %.c
${CC} ${KERNEL_CCFLAGS} -I ../include $< -o $@
Expand Down
182 changes: 0 additions & 182 deletions kernel/elf.c

This file was deleted.

99 changes: 89 additions & 10 deletions kernel/elf.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2015-2019 The University of Notre Dame
Copyright (C) 2015-2025 The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file LICENSE for details.
*/
Expand All @@ -8,16 +8,95 @@ See the file LICENSE for details.
#define ELF_H

#include "kernel/types.h"
#include "process.h"
#include "fs.h"

/*
elf_load opens the given filename, and if it contains a valid
ELF executable, allocates space in the current process' pagetable,
loads the text, data, and bss into memory, and updates the
entry point value in the current process structure.
*/
struct elf_header {
char ident[16];
uint16_t type;
uint16_t machine;
uint32_t version;
uint32_t entry;
uint32_t program_offset;
uint32_t section_offset;
uint32_t flags;
uint16_t header_size;
uint16_t phentsize;
uint16_t phnum;
uint16_t shentsize;
uint16_t shnum;
uint16_t shstrndx;
};

#define ELF_HEADER_TYPE_NONE 0
#define ELF_HEADER_TYPE_OBJECT 1
#define ELF_HEADER_TYPE_EXECUTABLE 2
#define ELF_HEADER_TYPE_DYNAMIC 3
#define ELF_HEADER_TYPE_CORE 4

#define ELF_HEADER_MACHINE_I386 3
#define ELF_HEADER_MACHINE_ARM 40
#define ELF_HEADER_MACHINE_X86_64 62

#define ELF_HEADER_VERSION 1

struct elf_program {
uint32_t type;
uint32_t offset;
uint32_t vaddr;
uint32_t paddr;
uint32_t file_size;
uint32_t memory_size;
uint32_t flags;
uint32_t align;
};

#define ELF_PROGRAM_TYPE_NULL 0
#define ELF_PROGRAM_TYPE_LOADABLE 1
#define ELF_PROGRAM_TYPE_DYNAMIC 2
#define ELF_PROGRAM_TYPE_INTERPRETER 3
#define ELF_PROGRAM_TYPE_NOTE 4
#define ELF_PROGRAM_TYPE_SHARED_LIBRARY 5
#define ELF_PROGRAM_TYPE_PROGRAM_HEADER 6
#define ELF_PROGRAM_TYPE_THREAD_LOCAL 7
#define ELF_PROGRAM_TYPE_GNU_EH_FRAME 0x6474e550
#define ELF_PROGRAM_TYPE_GNU_STACK 0x6474e551
#define ELF_PROGRAM_TYPE_GNU_RELRO 0x6474e552

#define ELF_PROGRAM_FLAGS_EXEC 1
#define ELF_PROGRAM_FLAGS_WRITE 2
#define ELF_PROGRAM_FLAGS_READ 4

struct elf_section {
uint32_t name;
uint32_t type;
uint32_t flags;
uint32_t address;
uint32_t offset;
uint32_t size;
uint32_t link;
uint32_t info;
uint32_t alignment;
uint32_t entry_size;
};

#define ELF_SECTION_TYPE_NULL 0
#define ELF_SECTION_TYPE_PROGRAM 1
#define ELF_SECTION_TYPE_SYMBOL_TABLE 2
#define ELF_SECTION_TYPE_STRING_TABLE 3
#define ELF_SECTION_TYPE_RELA 4
#define ELF_SECTION_TYPE_HASH 5
#define ELF_SECTION_TYPE_DYNAMIC 6
#define ELF_SECTION_TYPE_NOTE 7
#define ELF_SECTION_TYPE_BSS 8

int elf_load(struct process *p, struct fs_dirent *d, addr_t * entry);
#define ELF_SECTION_FLAGS_WRITE 1
#define ELF_SECTION_FLAGS_MEMORY 2
#define ELF_SECTION_FLAGS_EXEC 8
#define ELF_SECTION_FLAGS_MERGE 16
#define ELF_SECTION_FLAGS_STRINGS 32
#define ELF_SECTION_FLAGS_INFO_LINK 64
#define ELF_SECTION_FLAGS_LINK_ORDER 128
#define ELF_SECTION_FLAGS_NONSTANDARD 256
#define ELF_SECTION_FLAGS_GROUP 512
#define ELF_SECTION_FLAGS_TLS 1024

#endif
Loading