-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This splits the build system even more.
- Loading branch information
Showing
11 changed files
with
264 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ if [ ! -f configure ]; then | |
|
||
do_sub thunk_gen | ||
do_sub kernel | ||
do_sub loader | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* FDPP - freedos port to modern C++ | ||
* Copyright (C) 2018-2023 Stas Sergeev (stsp) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#define _GNU_SOURCE | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <assert.h> | ||
#include "elf_priv.h" | ||
#include "loader.h" | ||
|
||
#define __S(x) #x | ||
#define _S(x) __S(x) | ||
const char *FdppKernelDir(void) | ||
{ | ||
return _S(FDPPKRNLDIR); | ||
} | ||
|
||
const char *FdppKernelMapName(void) | ||
{ | ||
return _S(KRNL_MAP_NAME); | ||
} | ||
|
||
struct krnl_hndl { | ||
void *elf; | ||
const void *start; | ||
unsigned load_off; | ||
}; | ||
|
||
void *FdppKernelLoad(const char *dname, int *len, struct fdpp_bss_list **bss, | ||
uint32_t *_start) | ||
{ | ||
struct fdpp_bss_list *bl; | ||
void *start, *end; | ||
void *bstart, *bend; | ||
void *ibstart, *ibend; | ||
char *kname; | ||
void *handle; | ||
struct krnl_hndl *h; | ||
int i, s; | ||
|
||
asprintf(&kname, "%s/%s", dname, _S(KRNL_ELFNAME)); | ||
handle = elf_open(kname); | ||
if (!handle) { | ||
fprintf(stderr, "failed to open %s\n", kname); | ||
free(kname); | ||
return NULL; | ||
} | ||
free(kname); | ||
start = elf_getsym(handle, "_start"); | ||
s = elf_getsymoff(handle, "_start"); | ||
if (s == -1) | ||
goto err_close; | ||
*_start = s; | ||
end = elf_getsym(handle, "__InitTextEnd"); | ||
if (!end) | ||
goto err_close; | ||
bstart = elf_getsym(handle, "__bss_start"); | ||
if (!bstart) | ||
goto err_close; | ||
bend = elf_getsym(handle, "__bss_end"); | ||
if (!bend) | ||
goto err_close; | ||
ibstart = elf_getsym(handle, "__ibss_start"); | ||
if (!ibstart) | ||
goto err_close; | ||
ibend = elf_getsym(handle, "__ibss_end"); | ||
if (!ibend) | ||
goto err_close; | ||
*len = (uintptr_t)end - (uintptr_t)start; | ||
|
||
bl = (struct fdpp_bss_list *)malloc(sizeof(*bl) + | ||
sizeof(struct fdpp_bss_ent) * 2); | ||
i = 0; | ||
if (bend != bstart) { | ||
bl->ent[i].off = (uintptr_t)bstart - (uintptr_t)start; | ||
bl->ent[i].len = (uintptr_t)bend - (uintptr_t)bstart; | ||
i++; | ||
} | ||
if (ibend != ibstart) { | ||
bl->ent[i].off = (uintptr_t)ibstart - (uintptr_t)start; | ||
bl->ent[i].len = (uintptr_t)ibend - (uintptr_t)ibstart; | ||
i++; | ||
} | ||
bl->num = i; | ||
*bss = bl; | ||
|
||
h = (struct krnl_hndl *)malloc(sizeof(*h)); | ||
h->elf = handle; | ||
h->start = start; | ||
h->load_off = s; | ||
return h; | ||
|
||
err_close: | ||
elf_close(handle); | ||
return NULL; | ||
} | ||
|
||
const void *FdppKernelReloc(void *handle, uint16_t seg, uint16_t *r_seg, | ||
reloc_hook_t hook) | ||
{ | ||
struct krnl_hndl *h = (struct krnl_hndl *)handle; | ||
|
||
assert(!(h->load_off & 0xf)); | ||
seg -= h->load_off >> 4; | ||
elf_reloc(h->elf, seg); | ||
|
||
hook(seg, elf_getsymoff, h->elf); | ||
|
||
*r_seg = seg; | ||
return h->start; | ||
} | ||
|
||
void FdppKernelFree(void *handle) | ||
{ | ||
struct krnl_hndl *h = (struct krnl_hndl *)handle; | ||
|
||
elf_close(h->elf); | ||
free(h); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
T = .. | ||
-include config.mak | ||
-include $(T)/local.mak | ||
srcdir ?= $(CURDIR) | ||
|
||
include $(srcdir)/$(T)/clang.mak | ||
include $(srcdir)/$(T)/defs.mak | ||
|
||
TOP = $(abspath $(srcdir)/$(T)/..) | ||
HDR = $(TOP)/hdr | ||
PPINC = $(TOP)/include/fdpp | ||
AVER = $(shell echo FDPP_API_VER | cpp -include $(PPINC)/thunks.h - | tail -n 1) | ||
BVER = $(shell echo BPRM_VER | cpp -include $(PPINC)/bprm.h - | tail -n 1) | ||
TARGET=fdppkrnl.$(AVER).$(BVER) | ||
FDPPDEVL = libfdldr.so | ||
FDPPLIB = $(FDPPDEVL).$(AVER).$(BVER) | ||
LDFLAGS += -Wl,-soname=$(FDPPLIB) -L.. | ||
SOURCES = elf.c loader.c | ||
HEADERS = elf_priv.h | ||
OBJECTS = $(SOURCES:.c=.o) | ||
|
||
CFLAGS += -I . -I $(PPINC) \ | ||
-DFDPPKRNLDIR=$(DATADIR)/fdpp \ | ||
-DKRNL_ELFNAME=$(TARGET).elf -DKRNL_MAP_NAME=$(TARGET).map \ | ||
-fpic | ||
LIBELF := $(shell $(PKG_CONFIG) --libs libelf) | ||
ifeq ($(LIBELF),) | ||
$(error libelf not installed) | ||
endif | ||
LIBS += $(LIBELF) | ||
|
||
ALL = $(T)/$(FDPPLIB) | ||
|
||
all: $(ALL) | ||
|
||
$(T)/$(FDPPLIB): $(OBJECTS) | ||
$(CL) -o $@ $^ $(LDFLAGS) $(LIBS) | ||
|
||
$(OBJECTS): %.o: $(srcdir)/%.c $(addprefix $(srcdir)/,$(HEADERS)) $(srcdir)/makefile | ||
$(CC) $(CFLAGS) -c -o $@ $< | ||
|
||
clean: | ||
$(RM) *.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.