| 28 Mar 2025 |
K900 | github.com/NixOS/nixpkgs/pull/393655 | 15:27:58 |
K900 | * https://github.com/NixOS/nixpkgs/pull/393655 | 15:28:02 |
K900 | (on native) | 15:28:07 |
| scottytheengineer joined the room. | 18:15:50 |
n3tcat | K900 Alright this may be a NixOS related cross compiling question but maybe not.
I have a very simple C program that looks like this:
void _start() {
volatile long *a = (long *)0x1FFA0;
volatile long *b = (long *)0x1FFA8;
volatile long *c = (long *)0x1FFB0;
*c = *b / *a;
for(;;) {}
}
This relies on doing software division (the actual hardware instruction can only do 32 bit / 16 bit -> 16 bit or something like that). So it calls __divsi3.
__divsi3 seems to be compiled incorrectly. It tries to use a BSR.L instruction, which doesn't exist on the m68k. It only has the BSR.W and BSR.B instructions. I am wondering what I would need to do to fix this | 20:16:07 |
K900 | Maybe you need the right -march? | 20:16:52 |
n3tcat | I'm using -m68000 and I've tried playing around with the -march flags. It seems like my actual code compiles just fine but it's almost like the __whatever helpers are being compiled for the wrong CPU | 20:17:27 |
n3tcat | test.bin: test.o Linker.ld
m68k-unknown-none-elf-gcc -T Linker.ld -o test.bin -O2 -m68000 -Wall -Wextra -nostdlib test.o -ffreestanding -lgcc
%.o: %.c
m68k-unknown-none-elf-gcc -m68000 -c $< -o $@ -ffreestanding -nostdlib -O0 -Wall -Wextra -fno-PIC -static-libgcc
Here's my makefile btw | 20:17:43 |
K900 | Oh | 20:18:27 |
K900 | Yeah that could be it | 20:18:31 |
K900 | If those are coming from newlib | 20:18:37 |
K900 | And newlib is using a wrong -march too | 20:18:44 |
K900 | And you're just linking an already built newlib | 20:18:58 |
n3tcat | I think they might be? I am not entirely sure what -lgcc and -static-libgcc do - I assume they link into newlib | 20:19:12 |
K900 | No, that's libgcc | 20:19:31 |
K900 | But it could be the same thing | 20:19:45 |
K900 | Uhh there is a setting for this | 20:20:37 |
K900 | Somewhere | 20:20:39 |
n3tcat | Like for choosing how libgcc is compiled? | 20:20:57 |
K900 | Like you can set march in the platform definition | 20:20:59 |
K900 | Somewhere | 20:21:08 |
K900 | OK so here's the way I remember this can work | 20:23:09 |
n3tcat | would this be a gcc setting or a nix setting? I am struggling to find anything | 20:23:09 |
K900 | You can use lib.systems.elaborate "m68k-unknown-none-elf" | 20:23:32 |
K900 | In a REPL or something | 20:23:38 |
K900 | That will shit out a huge attrset | 20:23:44 |
K900 | That you can take and pass to crossSystem instead of just the triple | 20:24:04 |
K900 | And hopefully that attrset will have a place to put the right march value in | 20:24:27 |
K900 | That will hopefully be obvious from the name | 20:24:35 |
n3tcat | Sick! I have never used the nix repl before, do I have to do something to define lib? | 20:24:42 |