Skip to content

Commit

Permalink
being able to view and compare all libraries from a centralized place…
Browse files Browse the repository at this point in the history
… is one of the main benefits of package managers. just being able to search "websocket" for example. I imagine jai could work without a real package manager but I think something to solve the problem of information centralization would still be necessary psdrndm — Today at 00:56 A searchable list of modules can be just that without all the negatives of a package manager MisterSkeltal — Today at 00:59 As soon as you have a searchable list of modules, you can run a script to download them, and then that list becomes a package manager, so I don't understand this comment. Maybe it doesn't do semantic versioning or whatever but that's an ancillary detail farzher — Today at 01:00 atm, sharing / using jai libraries is a huge mess that needs some solution. most installation instructions are: "download this code, rename the folder to JSON, and paste it into jai/modules directory" "oh and btw this code depends on the unicode_utils module, so do the same for that too" most people don't even store local copies because it's a bit too much effort to copy them everywhere manually, also then you're forced to use -import_dir or a metaprogram MisterSkeltal — Today at 01:02 JaIDE solves this farzher — Today at 01:02 if jai included -import_dir ./modules by default that'd be very useful, but still not enough psdrndm — Today at 01:20 I think there are more things than a list and a script to download items for it that are implicit in a thing called “package manager,” but maybe that’s just me Kuju — Today at 01:22 if youre arguing for no centralized management of repos at all itll just turn into the cpp free for all hellscape I thought at least it would be pretty agreed upon that the current method of download this repo and the dependencies and put them in the modules folder, isnt ideal MisterSkeltal — Today at 01:24 I am not arguing for that, I'm saying that the suggestion of "you don't need a package manager if you can look up code in a centralized location" is practically a package manager I agree that a package manager could be useful Kuju — Today at 01:27 ah thats not my preference. it feels like an awkward middle ground to me. I was adding onto what @psdrndm said that in the scenario described a searchable repo list is still a bonus (at the very least) almost feels like this whole discussion should be in syntax-suggestions or something :cool_think: MisterSkeltal — Today at 01:31 No, like, if you have a "searchable repo list" or whatever, and that searchable repo list has a canonical location of the source code of that repo, then someone can make a metaprogram which searches the repo list and downloads the source, recursing as necessary, and boom you have a package manager. It would probably be a good idea to have a package manager that is a bit better than this, because this is what will become the "package manager" once you have a repo list. I'm not a package manager expert, but I feel like this isn't going to be a good approach. It's likely just going to be like the current situation, but slightly more automated. ("but that's just all package managers!" har har) Andrew the hacker — Today at 04:07 Maybe it would be better to have the package manager integrated with version control rather than with the language. Something like a better version of git sub modules. So the language can stay agnostic to where any modules came from, and you don’t have two systems doing two layers of fetching and versioning.
  • Loading branch information
dlandahl committed Nov 6, 2022
1 parent ede7cc3 commit d7949b8
Show file tree
Hide file tree
Showing 22 changed files with 592 additions and 516 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ files/wait
files/copy_file
files/assemble
files/inspect_exe
files/equals
files/get_people

.#*

Expand All @@ -54,4 +56,3 @@ update
test.jai
files/code/x86_64.json
/modules/.build/*
files/shutdown
121 changes: 6 additions & 115 deletions build_theos_app.jai
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

// 1

entry_point :: #string END

Expand Down Expand Up @@ -201,122 +201,13 @@ build_theos_app :: (name: string) {

write_string("\n=== Patching ELF ===\n");
{
elf_header := cast(*Elf64_Ehdr) elf.data;

get_section_header :: (index: int) -> *Elf64_Shdr #expand {
base := `elf.data + `elf_header.e_shoff;
base += index * `elf_header.e_shentsize; //`
header := cast(*Elf64_Shdr) base;
return header;
}

Patch :: struct {
source: string;
target: string;
virtual_address: int;
plt_index: int = -1;
}

patches := Patch.[
.{ source="crt_memset", target="memset" },
.{ source="crt_memcpy", target="memcpy" },
.{ source="crt_memcmp", target="memcmp" },
patches := Plt_Patch.[
.{source = "crt_memset", target = "memset"},
.{source = "crt_memcpy", target = "memcpy"},
.{source = "crt_memcmp", target = "memcmp"},
];

for 0..elf_header.e_shnum - 1 {
header := get_section_header(it);
if header.sh_type != SHT_SYMTAB continue;

string_table_section_header := get_section_header(header.sh_link);
table := elf.data + string_table_section_header.sh_offset;

entry_count := header.sh_size / header.sh_entsize;
assert(header.sh_size % header.sh_entsize == 0);

for * patch: patches {
for 0..entry_count - 1 {
base := elf.data + header.sh_offset;
base += it * header.sh_entsize;
symbol := cast(*Elf64_Sym) base;

name := to_string(table + symbol.st_name);
if starts_with(name, patch.source) {
patch.virtual_address = xx symbol.st_value;
print("Found patch target % at virtual address %.\n", name, symbol.st_value);
break;
}
}
}
}

for 0..elf_header.e_shnum - 1 {
header := get_section_header(it);
if header.sh_type != SHT_RELA continue;

{
section_name_table_header := get_section_header(elf_header.e_shstrndx);
name := to_string(elf.data + section_name_table_header.sh_offset + header.sh_name);
if name != ".rela.plt" continue;
}

symbol_table_section_header := get_section_header(header.sh_link);
string_table_section_header := get_section_header(symbol_table_section_header.sh_link);

symbol_table := elf.data + symbol_table_section_header.sh_offset;
string_table := elf.data + string_table_section_header.sh_offset;

entry_count := header.sh_size / header.sh_entsize;

for * patch: patches {
for 0..entry_count - 1 {
base := elf.data + header.sh_offset;
base += it * header.sh_entsize;
rela := cast(*Elf64_Rela) base;

index := (rela.r_info >> 32);
symbol := cast(*Elf64_Sym) (symbol_table + index * symbol_table_section_header.sh_entsize);
name := to_string(string_table + symbol.st_name);

if name == patch.target {
patch.plt_index = xx it;
print("Found plt entry for patch \"%\" at index %.\n", name, it);
break;
}
}
}
}

for 0..elf_header.e_shnum - 1 {
header := get_section_header(it);
if header.sh_type != SHT_PROGBITS continue;

section_name_table_header := get_section_header(elf_header.e_shstrndx);
name := to_string(elf.data + section_name_table_header.sh_offset + header.sh_name);
if name != ".plt" continue;

PLT_ENTRY_SIZE :: 16;

for patch: patches {
plt_offset := PLT_ENTRY_SIZE * (patch.plt_index + 1);
patch_target := plt_offset + xx header.sh_offset;
source_virtual_address := plt_offset + xx header.sh_addr + 5;

jump := patch.virtual_address - source_virtual_address;

if patch.plt_index == -1 {
continue;
}

if patch.virtual_address == 0 {
print("Could not find target address for patch \"%\". This is probably a build failure, but we'll continue.\n", patch.source);
continue;
}

elf.data[patch_target] = 0xe9;
<< (cast(*s32) (elf.data + patch_target + 1)) = xx jump;
}
break;
}
patch_procedure_linkage_table(cast([] u8) elf, patches);
}

write_string("\n=== Writing executable ===\n");
Expand Down
2 changes: 1 addition & 1 deletion config.jai
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ VESA_WIDTH :: 1600 /* 640 1920 1440 1024 2560 */;
VESA_HEIGHT :: 1200 /* 480 1080 900 768 1440 */;
VESA_DEPTH :: 32;

PROGRAM_PARAMETER_BASE_ADDRESS :: 0x80_000;
PROGRAM_PARAMETER_BASE_ADDRESS :: 0xffff_ffff_a000_0000;
PAGE_FAULT_STACK_TRACE :: true;

ENABLE_IST :: false;
Expand Down
27 changes: 0 additions & 27 deletions files/source_code/test_app.jai

This file was deleted.

4 changes: 0 additions & 4 deletions files/system/startup
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@

theos
assemble "code/welcome.asm", welcome

2 changes: 1 addition & 1 deletion files/themes/mash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
00283618 00fefae0 00dda15e 00dda15e 00b0be88 00bc6c25 true
00283618 00fefae0 00dda15e 01dda15e 00b0be88 00bc6c25 true
2 changes: 1 addition & 1 deletion files/themes/mash_light
Original file line number Diff line number Diff line change
@@ -1 +1 @@
00fefae0 00283618 00cd914e 00cd914e 00848438 00bc6c25 false
00fefae0 00283618 00cd914e 01cd914e 00848438 00bc6c25 false
22 changes: 14 additions & 8 deletions first.jai
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ interrupt_handlers: [] struct {
.{ "page_fault_handler", 0x0e },
];

#import "POSIX";
#if OS == .LINUX {
#import "POSIX";
}

#run {
write_string("\n=== Theos Build Begin ===\n");
Expand Down Expand Up @@ -115,7 +117,7 @@ interrupt_handlers: [] struct {

make_directory_if_it_does_not_exist(".build");

if false {
#if OS == .LINUX if false {
write_string("\n=== Applying Module Patches ===\n");

success, exit_code, stdout, stderr := shell("which jai-linux", print_output = false);
Expand Down Expand Up @@ -205,10 +207,10 @@ interrupt_handlers: [] struct {
script: Linker_Script;
script.entry_point_name = "kernel_entry";
script.sections = .[
.{ base, "text" },
.{ base, "rodata" },
.{ base, "data" },
.{ base, "bass" },
.{ base, "text", 0x1000 },
.{ base, "rodata", 0x1000 },
.{ base, "data", 0x1000 },
.{ base, "bass", 0x1000 },
];
set_linker_script(*options, w, script);

Expand Down Expand Up @@ -736,10 +738,14 @@ task_switch:
; push_all

mov rcx, [rax]
mov [rcx], rsp ; Remember the current stack pointer for when we switch back TO the task we're currently switching from

mov [rcx], rsp ; Store current stack on current (old) task

mov [rax], rbx ; Set the current task to the new task
mov rsp, [rbx] ; Restore the stack pointer from the new current task

mov rsp, [rbx] ; Restore the stack pointer from the current (new) task
mov rdx, [rbx + 8]
mov cr3, rdx ; Restore the page table from the current (new) task
; pop_all

iretq
Expand Down
Loading

0 comments on commit d7949b8

Please sign in to comment.