Skip to content

Commit

Permalink
xelix-utils: Add ld-xelix dynamic linker
Browse files Browse the repository at this point in the history
  • Loading branch information
lutoma committed Dec 4, 2023
1 parent db46639 commit edad296
Show file tree
Hide file tree
Showing 6 changed files with 654 additions and 8 deletions.
8 changes: 4 additions & 4 deletions land/xelix-utils/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
pkgname=xelix-utils
pkgver=r2576.fb8939c5
pkgrel=2
pkgver=r.
pkgrel=1
epoch=
pkgdesc="A suite of Xelix-specific standard system utilities."
arch=('i786')
url="https://github.com/lutoma/xelix/tree/main/land/xelix-utils"
license=('GPL')
depends=('font-fira-code' 'gfxcompd')
makedepends=('flac' 'freetype' 'libpng')
depend=('font-fira-code' 'gfxcompd')
makedepend=('flac' 'freetype' 'libpng' 'zlib' 'bzip2')
source=()

pkgver() {
Expand Down
1 change: 1 addition & 0 deletions land/xelix-utils/src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ host
telnetd
mount
umount
ld-xelix.so
14 changes: 10 additions & 4 deletions land/xelix-utils/src/Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
PATH += :../../toolchain/local/bin/
CC := i786-pc-xelix-gcc
LD := i786-pc-xelix-ld
CFLAGS += -std=gnu18 -O3 -g -D_GNU_SOURCE
CFLAGS += -std=gnu18 -O3 -ggdb -D_GNU_SOURCE
DESTDIR ?= ../../../mnt

TARGETS=basictest init ps uptime free login dmesg su play strace host telnetd mount umount gfxterm png

.PHONY: all
all: $(TARGETS)
all: $(TARGETS) ld-xelix.so

.PHONY: clean
clean:
rm -f $(TARGETS) util.o libutil.a basictest.o
rm -f $(TARGETS) util.o libutil.a basictest.o ld-xelix.so ld-xelix.o ld-xelix-i386.o

init: init.c ini.c libutil.a
$(CC) $(CFLAGS) -o $@ init.c ini.c -L. -lutil
Expand All @@ -25,6 +24,11 @@ gfxterm: gfxterm.c tmt.c tmt.h
png: png.c
$(CC) $(CFLAGS) -o $@ png.c -lxelixgfx -lpng -lz -lm

ld-xelix.so: ld-xelix.c ld-xelix-i386.asm ld-xelix.ld
$(CC) $(CFLAGS) -o ld-xelix.o -c ld-xelix.c
nasm -g -f elf ld-xelix-i386.asm -o ld-xelix-i386.o
$(CC) $(CFLAGS) -o $@ ld-xelix.o ld-xelix-i386.o -static -T ld-xelix.ld

libutil.a: util.c argparse.c
$(CC) $(CFLAGS) -c -o util.o util.c
$(CC) $(CFLAGS) -c -o argparse.o argparse.c
Expand All @@ -40,5 +44,7 @@ libutil.a: util.c argparse.c
.PHONY: install
install:
install -d $(DESTDIR)/usr/bin/
install -d $(DESTDIR)/usr/lib/
install -D $(TARGETS) $(DESTDIR)/usr/bin/
install -D ld-xelix.so $(DESTDIR)/usr/lib/
chmod u+s $(DESTDIR)/usr/bin/su
35 changes: 35 additions & 0 deletions land/xelix-utils/src/ld-xelix-i386.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
; ld-xelix.asm: Trampoline functions for ld-xelix
; Copyright © 2023 Lukas Martini

; This file is part of Xelix.
;
; Xelix 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.
;
; Xelix 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 Xelix. If not, see <http://www.gnu.org/licenses/>.

[EXTERN resolve_callback]
[GLOBAL plt_trampoline]

plt_trampoline:
pop edx
pop ecx

; push ebp
; mov ebp, esp

; mov eax, 0x60012f8
; mov dword [eax], 0x6000166
call resolve_callback

; mov esp, ebp
; pop ebp
jmp eax
Loading

0 comments on commit edad296

Please sign in to comment.