btw, on Linux syscalls pass arguments using rax (syscall), rdi (arg 0), rsi (arg 1), rdx, (arg 2), r10 (arg 3), r8 (arg 4), r9 (arg 5) chromiumos has some good documentation on Linux syscalls.
21:40 "I don't know what E stands for" referring to the prefix on the 32 bit x86 register names. I always assumed it stood for "extended", since they were quite literally just an extension of the original 16 bit registers.
it took me embarrassingly long to realize that boot_loader_name is an address to a c string and not 8 chars packed into a u32... the multiboot info stuff was annoying to add (I've been working on my own implementation while watching).
you can do char *x = malloc(5); (you need an exta one because it's null terminated) strncpy(x, "Hello", 5); (avoids buffer overflow because you only copy 5 chars) printf("%s ", x); (printing it) free(x); (freeing the memory)
do you still need to use rust nightly on bare metal like this? i remember reading a blog post back in the day where you had to be on the nightly version.
I'm definitely on nightly. I thought I have to be, but you have me second guessing myself. I set up a quick test, and I'm honestly not sure. I'm having trouble defining the custom target as the standard libraries aren't build by default. Apparently the feature to build-std is unstable (nightly) only (cargo -Z build-std) It seems like it might be doable, it's possible to make a no-std executable with stable rust, but I'm not sure if I could get as far as easily.
ok i only have the stable release version on my mac but i guess that makes sense then that you would need to use the nighly version. thanks. @@sphaerophoria
I think it's pretty easy if you've installed via rustup to just override to nightly for a single project. `cargo +nightly build` or `rustup override set nightly` or something
btw, on Linux syscalls pass arguments using
rax (syscall), rdi (arg 0), rsi (arg 1), rdx, (arg 2), r10 (arg 3), r8 (arg 4), r9 (arg 5)
chromiumos has some good documentation on Linux syscalls.
21:40 "I don't know what E stands for" referring to the prefix on the 32 bit x86 register names. I always assumed it stood for "extended", since they were quite literally just an extension of the original 16 bit registers.
I think the pages and fragmentation thing is correct.
The solution I have seen is something called virtual memory.
it's better to do
int *x = (int*) malloc(sizeof(int));
since the size of int may change depending on your compiler
iirc the e in esp is because it's 32 bit
if it was 64 bit it would be rsp
so if you were in 64 bit esp would be the lower half of the rsp register
AFAICT (without actually looking it up), this is right. There's also 8/16 byte versions (ax, dax, eax, rax) IIRC
@@sphaerophoria Yes. rax = 64 bit, eax = 32 bit, ax = 16 bit, ah/al = 8 bit high and low bytes, respectively.
it took me embarrassingly long to realize that boot_loader_name is an address to a c string and not 8 chars packed into a u32... the multiboot info stuff was annoying to add (I've been working on my own implementation while watching).
you can do
char *x = malloc(5); (you need an exta one because it's null terminated)
strncpy(x, "Hello", 5); (avoids buffer overflow because you only copy 5 chars)
printf("%s
", x); (printing it)
free(x); (freeing the memory)
do you still need to use rust nightly on bare metal like this? i remember reading a blog post back in the day where you had to be on the nightly version.
I'm definitely on nightly. I thought I have to be, but you have me second guessing myself. I set up a quick test, and I'm honestly not sure. I'm having trouble defining the custom target as the standard libraries aren't build by default. Apparently the feature to build-std is unstable (nightly) only (cargo -Z build-std)
It seems like it might be doable, it's possible to make a no-std executable with stable rust, but I'm not sure if I could get as far as easily.
ok i only have the stable release version on my mac but i guess that makes sense then that you would need to use the nighly version. thanks. @@sphaerophoria
I think it's pretty easy if you've installed via rustup to just override to nightly for a single project. `cargo +nightly build` or `rustup override set nightly` or something