Browse Source

Okay, with some mucking around, there is now a /bin/id and it runs!

It statically links against everything in LibC that it needs.
This will work just fine for a long time to come!
Andreas Kling 6 years ago
parent
commit
befeabd8fe
4 changed files with 10 additions and 11 deletions
  1. BIN
      Kernel/_fs_contents
  2. 2 2
      Kernel/init.cpp
  3. 7 8
      LibC/stdio.cpp
  4. 1 1
      Userland/Makefile

BIN
Kernel/_fs_contents


+ 2 - 2
Kernel/init.cpp

@@ -150,14 +150,14 @@ static void init_stage2()
 
 
 #ifdef TEST_ELF_LOADER
 #ifdef TEST_ELF_LOADER
     {
     {
-        auto testExecutable = vfs->open("/_test.o");
+        auto testExecutable = vfs->open("/bin/id");
         ASSERT(testExecutable);
         ASSERT(testExecutable);
         auto testExecutableData = testExecutable->readEntireFile();
         auto testExecutableData = testExecutable->readEntireFile();
         ASSERT(testExecutableData);
         ASSERT(testExecutableData);
 
 
         ExecSpace space;
         ExecSpace space;
         space.loadELF(move(testExecutableData));
         space.loadELF(move(testExecutableData));
-        auto* elf_entry = space.symbolPtr("elf_entry");
+        auto* elf_entry = space.symbolPtr("_start");
         ASSERT(elf_entry);
         ASSERT(elf_entry);
 
 
         typedef int (*MainFunctionPtr)(void);
         typedef int (*MainFunctionPtr)(void);

+ 7 - 8
LibC/stdio.cpp

@@ -3,14 +3,13 @@
 #include "types.h"
 #include "types.h"
 #include <Kernel/Syscall.h>
 #include <Kernel/Syscall.h>
 
 
+#define ALWAYS_INLINE __attribute__ ((always_inline))
+
+static const char h[] = { '0','1','2','3','4','5','6','7', '8','9','a','b','c','d','e','f' };
+
 template<typename PutChFunc>
 template<typename PutChFunc>
-int printHex(PutChFunc putch, char*& bufptr, dword number, byte fields)
+ALWAYS_INLINE int printHex(PutChFunc putch, char*& bufptr, dword number, byte fields)
 {
 {
-    static const char h[] = {
-        '0','1','2','3','4','5','6','7',
-        '8','9','a','b','c','d','e','f'
-    };
-
     int ret = 0;
     int ret = 0;
     byte shr_count = fields * 4;
     byte shr_count = fields * 4;
     while (shr_count) {
     while (shr_count) {
@@ -22,7 +21,7 @@ int printHex(PutChFunc putch, char*& bufptr, dword number, byte fields)
 }
 }
 
 
 template<typename PutChFunc>
 template<typename PutChFunc>
-int printNumber(PutChFunc putch, char*& bufptr, dword number)
+ALWAYS_INLINE int printNumber(PutChFunc putch, char*& bufptr, dword number)
 {
 {
     dword divisor = 1000000000;
     dword divisor = 1000000000;
     char ch;
     char ch;
@@ -49,7 +48,7 @@ int printNumber(PutChFunc putch, char*& bufptr, dword number)
 }
 }
 
 
 template<typename PutChFunc>
 template<typename PutChFunc>
-static int printSignedNumber(PutChFunc putch, char*& bufptr, int number)
+ALWAYS_INLINE int printSignedNumber(PutChFunc putch, char*& bufptr, int number)
 {
 {
     if (number < 0) {
     if (number < 0) {
         putch(bufptr, '-');
         putch(bufptr, '-');

+ 1 - 1
Userland/Makefile

@@ -18,7 +18,7 @@ CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(USERLAND_FLAGS) $(FLAVOR_FLA
 CXX = g++
 CXX = g++
 LD = ld
 LD = ld
 AR = ar
 AR = ar
-LDFLAGS = --strip-debug -melf_i386 --gc-sections --build-id=none -z norelro -z now
+LDFLAGS = -r -static --strip-debug -melf_i386 --build-id=none -z norelro -z now -e _start
 
 
 all: $(OBJS) $(APPS)
 all: $(OBJS) $(APPS)