klange changed the topic of #osdev to: Operating System Development || Don't ask to ask---just ask! || For 3+ LoC, use a pastebin (for example https://gist.github.com/) || Stats + Old logs: http://osdev-logs.qzx.com New Logs: https://libera.irclog.whitequark.org/osdev || Visit https://wiki.osdev.org and https://forum.osdev.org || Books: https://wiki.osdev.org/Books
gog has quit [Ping timeout: 260 seconds]
vdamewood has joined #osdev
<heat> wow i found the bug, my radix tree copy was slightly borked
<heat> literal one line patch
eddof13 has quit [Quit: eddof13]
* vdamewood adds a semicolon to heat's code
* mjg adds typos
<heat> aww sweet i can compile GNU hello now
<kof673> https://github.com/reinderien/mimic it used to be monster-in-a-box logo :)
<bslsk05> ​reinderien/mimic - [ab]using Unicode to create tragedy (102 forks/3743 stargazers/MIT)
wantyapps has quit [Server closed connection]
wantyapps has joined #osdev
gcoakes has joined #osdev
eddof13 has joined #osdev
eddof13 has quit [Client Quit]
<adder> heat?
<heat> adder!
<adder> paging then long?
<heat> sure
<bslsk05> ​gist.github.com: make.svg · GitHub
<heat> a *lot* of waiting, and i'm pretty sure a good bit of it is just waiting for the vterm ://
<heat> (can't be arsed to make an off-cpu one atm)
edr has quit [Quit: Leaving]
<mjg> do the test i dpasted
<mjg> i'm bailin'
<heat> no i'm busy doing more fun stuff
<heat> important to note that my system sucks harder in some will-it-scales cuz i didn't actually batch LRU yet
PublicWiFi has quit [Server closed connection]
PublicWiFi has joined #osdev
eddof13 has joined #osdev
eddof13 has quit [Ping timeout: 246 seconds]
FreeFull has quit [Server closed connection]
FreeFull has joined #osdev
skipwich has quit [Quit: DISCONNECT]
skipwich has joined #osdev
sprock has quit [Ping timeout: 256 seconds]
xvmt has quit [Server closed connection]
xvmt has joined #osdev
sprock has joined #osdev
X-Scale has joined #osdev
X-Scale has quit [Ping timeout: 250 seconds]
X-Scale has joined #osdev
Arthuria has joined #osdev
frkazoid333 has quit [Server closed connection]
foudfou_ has joined #osdev
foudfou has quit [Ping timeout: 260 seconds]
vinleod has joined #osdev
vdamewood has quit [Ping timeout: 260 seconds]
khimaros has quit [Server closed connection]
khimaros has joined #osdev
heat has quit [Ping timeout: 246 seconds]
netbsduser has joined #osdev
Arthuria has quit [Ping timeout: 272 seconds]
vinleod is now known as vdamewood
netbsduser has quit [Ping timeout: 246 seconds]
goliath has joined #osdev
navi has joined #osdev
navi has quit [Ping timeout: 272 seconds]
GeDaMo has joined #osdev
ZipCPU has quit [Server closed connection]
ZipCPU has joined #osdev
<geist> yes.
smeso has quit [Server closed connection]
smeso has joined #osdev
X-Scale86 has joined #osdev
X-Scale has quit [Ping timeout: 250 seconds]
X-Scale86 has quit [Quit: Client closed]
<kazinsal> someone on the internet challenged me to write an amd64 emulator that runs on an 8088 and I'm having a very VERY hard time not rising to the obvious nerd sniping bait
<bslsk05> ​news.ycombinator.com: Things I learned while writing an x86 emulator (2013) | Hacker News
<GeDaMo> The link is actually from 2023
<mjg> oh no
<mjg> > Most of it totally useless unless you want to write an emulator (which I highly recommend if you ever get the chance).
<mjg> i get you have a kink mate, but don't recommend it to people ffs :P
<kazinsal> the idea of emulating an x64 system at like, 30 instructions per second on a 4.77 MHz 8088 intrigues me in the "purely theoretical dumb idea" sense
<vdamewood> kazinsal: Don't forget working around memory lim its
<vdamewood> limits
<kazinsal> but it's up there with "actually make a serious attempt at my hypothetical osdev project" and "quit my job and reinvent space combat MMORPGs"
<mjg> despite what the osdev wiki used to say there are jobs doing kernel stuff
<kazinsal> my degree's in the wrong field
<mjg> and chances are you can get both the weird shit you want *and* get paid to do it
<kazinsal> but thankfully I'm in a wonderful unionized position with a few people above me who are planning on retiring soon and thus giving me fat promotion tracks
* kazinsal I will never need to argue for raises ever again and can write off many thousands of dollars on my taxes until I retire
<kazinsal> so I can just eventually go back to doing weird kernel shit for fun
<kazinsal> once I get motivated to do so
<GeDaMo> https://www.youtube.com/watch?v=5RF45uEaFlU 8-bit CPU emulating a 386
<bslsk05> ​'Flea86 PC board running Windows 3.0' by dosgamer74 (00:03:33)
vdamewood has quit [Quit: Life beckons]
<kazinsal> my longstanding april fools osdev joke idea was to reimplement one of the early C versions of research unix for the 5150, as a pastiche of the dozens of early partial reimplementations of unix that were posted to the osdev forums over the years and then immediately abandoned
<kazinsal> but it feels kind of pointless now that nobody seems to have any sort of control or ownership of the forums and wiki
Left_Turn has joined #osdev
<Mondenkind> '30 instructions per second' nahhh i bet you can do more than that
<Mondenkind> only one way to find out though~
<kazinsal> someone uploaded a new forums theme a while back but apart from that the forums are basically abandoned
<kazinsal> chase used to check in a couple times a year but now no one has sudo perms on the server
<kazinsal> so I expect osdev dot org will disappear when his credit card expires
<Mondenkind> :\
<adder> I'm trying to iterate over multiboot mmap and map those ranges before going long, but I'm getting these pretty pics instead of output: https://imgur.com/uZN7xty.png
<bslsk05> ​imgur.com <no title>
<kazinsal> I logged into the forums to check and apparently a month ago chase just gave everyone with a higher post count than him moderator permissions.
<kazinsal> I believe the kids would call this a big yikes
<adder> I'd guess somehow VGA buffer ends up fucked up but how?
<adder> I even have a check if address is lower than 1MB then not map it
<zid> and where did you write those mappings to?
<zid> Looks like you picked b8000 to have a page table on it, visually :P
<adder> hey zid
<adder> hope ya don't mind, I'm using your bootstrap example as a reference
<adder> I'm pretty much following along, I have code up on github if you wanna look?
<kazinsal> identity mapping identity mapping *banging on table* IDENTITY MAPPING IDENTITY MAPPING
<adder> displaced* identity mapping
<adder> this doesn't look good CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
<adder> right?
<adder> ok, pretty pic gone, pretty sure it was ub
Turn_Left has joined #osdev
Left_Turn has quit [Ping timeout: 268 seconds]
spare has joined #osdev
xenos1984 has quit [Read error: Connection reset by peer]
zetef has joined #osdev
zetef has quit [Client Quit]
<adder> I need help understanding/fixing a linker error
xenos1984 has joined #osdev
<adder> kernel/main.c:4:(.text+0x5): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.1'
<clever> adder: try running `objdump -dr main.o`, you there should be a type code on the relocation at offset 5
<adder> this is what I see, clever
<clever> ah, the code was in the original error, R_X86_64_32
<clever> i think it wants a 32bit absolute address for that string in .rodata
<clever> so the question then becomes, what does your linker script say about .rodata?
<adder> I have two scripts, one for bootloader, one for kernel
<clever> the kernel one matters when linking the kernel
<adder> I'll paste in a moment
<bslsk05> ​bpa.st: View paste COFQ
<clever> yeah, that wont fit into a 32bit address without some sign extension
<clever> there is probably a better fix, but try -mcmodel=large?
<adder> would that be a linker flag?
<clever> compiler flag
<clever> 4:bf 00 00 00 00 mov $0x0,%edi
<clever> 5: R_X86_64_32.rodata.str1.1
<clever> the problem, is that this opcode only accepts a 32bit addr
<clever> so when turning c into asm, it has to make a different choice
<adder> right, this compiles
<adder> thannks clever
<clever> the thing i dont understand, is that kernels typically dont use the large model
<clever> so what is the proper fix?
<clever> pc relative? try -fPIC without large?
<clever> compare what the `objdump -dr` says for each?
<clever> ah yeah, thats doing pc relative
<clever> so now the requirement is that .rodata is within 2gig of .text
<clever> and 64bit addressing is possible
<clever> adder: https://bpa.st/QEOA you can see it better in here
<bslsk05> ​bpa.st: View paste QEOA
<clever> by default, it wanted a 32bit addr, large made it a 64bit addr (but now your .text is much larger)
<clever> pic made it a 32bit offset
<adder> I'm pretty sure I'm doing something dumb somewhere as I'm still trying to learn the ropes
<adder> does anyone see anything obvious at first sight, why are cr3/etc not changing? https://github.com/NukedOne/rzav/blob/long/boot/boot.S#L48
<bslsk05> ​github.com: rzav/boot/boot.S at long · NukedOne/rzav · GitHub
<clever> i'm less familiar with x86, so i cant help there
<zid> AT&T
Ermine has quit [Remote host closed the connection]
Ermine has joined #osdev
Ermine has quit [Remote host closed the connection]
Ermine has joined #osdev
<nikolapdp> adder you are using multiboot, no?
Ermine has quit [Remote host closed the connection]
<adder> yeah nikolapdp
Ermine has joined #osdev
gsekulski has joined #osdev
<adder> why nikolar? please don't suggest limine :D
<nikolapdp> why not
<adder> it's cheating
<nikolapdp> how's that cheating
<adder> idk, somehow feels so
X-Scale has joined #osdev
<adder> fuck, I'm getting 0xe
X-Scale has quit [Ping timeout: 250 seconds]
X-Scale has joined #osdev
wgrant has quit [Server closed connection]
wgrant has joined #osdev
<adder> could be that my printf call from kernel is triggering a page fault?
<clever> adder: how is the stack pointer being configured before kmain gets ran?
<adder> I set it to the stack_top label
<clever> where is it set?
<bslsk05> ​github.com: rzav/boot/boot.S at long · NukedOne/rzav · GitHub
<adder> stack_top is at the bottom
<clever> and the jmp on line 80, jumps to where?
<bslsk05> ​github.com: rzav/boot/mem.c at long · NukedOne/rzav · GitHub
<clever> ah, the entry from the kernel elf headers
<clever> so, is $stack_top a virtual or physical addr? is the MMU mapping that correct?
<adder> I'm not sure tbh
<clever> do `objdump -d bootloader.elf` and read the generated code
<adder> 71:bc 00 40 00 00 mov $0x4000,%esp
<adder> how can I tell if it's virtual or physical?
<clever> did you map 0x4000 in your paging tables?
<adder> no, it's too low
<clever> then its probably physical
<clever> keep in mind, your kernel is trying to use the bootloader stack, thats generally bad
<adder> ah yes fuck
<clever> you need another boot.S for the kernel, that uses the kernel stack
<adder> alright
<clever> https://bpa.st/COFQ and the ENTRY here, needs to point to the helper in the kernel boot.S
<bslsk05> ​bpa.st: View paste COFQ
<clever> which sets the sp, and calls kmain
<adder> ok
<clever> adder: another thing to keep in mind, when switching from physical to virtual, you need an identity map in place
<bslsk05> ​github.com: rzav/boot/boot.S at long · NukedOne/rzav · GitHub
<clever> adder: is the $longmode on line 70 going to be physical or virtual? between lines 60 and 70, the PC will still be physical
<clever> so you need to map that region in identity mode
edr has joined #osdev
<adder> clever: the region... around $longmode?
<clever> adder: and also go_long
<adder> but how can I know which region is that?
<adder> do I need to hardcode something?
<clever> you need to take the address of the function (or just the whole bootloader), page-align it, and map it
<adder> thanks clever
<clever> adder: there is also a trick i use for the stack, that doesnt use .skip in asm
<bslsk05> ​github.com: rpi-open-firmware/firmware/linker.ld at master · librerpi/rpi-open-firmware · GitHub
<ddevault> anyone happen to have the ARMv7 ABI specification handy
<clever> adder: one example, where its using math in the linker script, to just put it at the top of ram
<clever> ah, the other examples i had, do the same thing
X-Scale has quit [Ping timeout: 250 seconds]
X-Scale has joined #osdev
Left_Turn has joined #osdev
Turn_Left has quit [Ping timeout: 268 seconds]
Turn_Left has joined #osdev
Left_Turn has quit [Ping timeout: 246 seconds]
navi has joined #osdev
navi has quit [Ping timeout: 246 seconds]
navi has joined #osdev
gsekulski has quit [Remote host closed the connection]
rustyy has quit [Ping timeout: 272 seconds]
exit70 has quit [Quit: ZNC 1.8.2+deb3.1 - https://znc.in]
exit70 has joined #osdev
rustyy has joined #osdev
<adder> I'm not sure how to align what goes into CR3
<Mutabah> In what way?
<Mutabah> Just allocate a 4KB aligned piece of memory (e.g. at link time, or with your page frame allocator)
<adder> Mutabah, can you show me how? no matter what I do, it ends up something like CR3=00105868
<adder> wait, that's aligned?
<Mutabah> It's worth noting that there are flag bits in there - although, I think most are writable
<Mutabah> How are you setting it? and how is that value generated?
<adder> so I have struct page_table *pml4; as a global variable, and then when I call asm routine to transition into long mode, I pass (uintptr_t)pml4
<Mutabah> and how is `pml4` set?
<adder> minor correction... I realized I was passing a pointer-to-pointer, now when I just pass a pointer directly I'm seeing CR3=00004000
<Mutabah> (also, that's a logical/linear address - not a physical one, that's only correct _before_ paging is enabled)
<adder> pml4 is alloc'd
<Mutabah> I assume you've found your bug?, now that you have an aligned value
<adder> well, almost, still getting a page fault
<Mutabah> is the contents of PML4 valid?
<adder> wait... need to debug
<Mutabah> And you need to ensure that the code you're currently running is still mapped in this new address space
frkazoid333 has joined #osdev
navi has quit [Quit: WeeChat 4.2.1]
goliath has quit [Quit: SIGSEGV]
hwpplayer1 has joined #osdev
navi has joined #osdev
heat has joined #osdev
Terlisimo has quit [Quit: Connection reset by beer]
navi has quit [Ping timeout: 260 seconds]
Terlisimo has joined #osdev
qubasa has joined #osdev
Arthuria has joined #osdev
nur has joined #osdev
joe9 has joined #osdev
<kof673> > for the 5150 i notice openwatcom says it can generate i86 code, but seems to be missing library functions (unless this is just the way linux binaries were built, or maybe was never "fixed" when it went "open") :/ so possibly it still can, but is perhaps "freestanding"
<kof673> i also notice it needs target specified for both compiling and linking...else like smallerc, it will just output elf even if you specified the compiling target otherwise lol the latter only, unrecognized objects lol
X-Scale has quit [Ping timeout: 250 seconds]
josuedhg has joined #osdev
netbsduser has joined #osdev
Arthuria has quit [Ping timeout: 268 seconds]
goliath has joined #osdev
[Kalisto]8 has joined #osdev
[Kalisto]8 is now known as [Kalisto]
[Kalisto] has quit [Ping timeout: 246 seconds]
Gooberpatrol66 has quit [Ping timeout: 268 seconds]
hwpplayer1 has quit [Quit: I'll be back later]
xenos1984 has quit [Ping timeout: 256 seconds]
xenos1984 has joined #osdev
navi has joined #osdev
Gooberpatrol66 has joined #osdev
qubasa has quit [Remote host closed the connection]
xenos1984 has quit [Ping timeout: 268 seconds]
<nikolapdp> KERNAL
<heat> kern
<mjg> uts
<nikolapdp> krnl
SGautam has joined #osdev
<SGautam> So I've a problem, for some reason INT 1Ah, AH=00h seems to misbehave in both BOCHS and QEMU
<SGautam> Sometimes I get the value of ticks in DX, but other times, I simply get 0.
<SGautam> I'm not sure what could cause it.
<Ermine> k
<heat> korn
<SGautam> kornography?
<Ermine> SGautam: I think it's seabios issue
<SGautam> hmm
<SGautam> BOCHS uses SeaBIOS as well?
<heat> probably yeah
<Ermine> idk about bochs, but qemu definitely uses it
<netbsduser> i would've thought bochs would've invented their own
<netbsduser> seabios seems to be very new
<netbsduser> only invented in 2008
xenos1984 has joined #osdev
<heat> who the heck uses bochs anyway
<netbsduser> it's everywhere in old posts on the osdev forums
<netbsduser> i think it was once regarded as excellent in debuggability
<netbsduser> now QEMU has that really useful GDB remote server built in
<SGautam> Yep, even in 2016 it was the standard go to. QEMU was looked down upon.
<heat> no it wasn't?
<heat> some randos thought bochs was great, but the vast majority of people used qemu
<SGautam> if u used bochs u were part of the cool kids club or something
<SGautam> i guess it was a small community
<heat> the only thing bochs gives you is more info if basic x86 stuff goes wrong
<heat> like, you get a bad segment GPF and it tells you why, exactly, in a log
<SGautam> Yep the console really helps in debugging GDT/IDT faults
<heat> but this is the sort of hello world exceptions that go away quickly
<SGautam> not if you're starting out sir
<heat> >that go away quickly
<SGautam> I recall debugging GDT faults for days at one point
<SGautam> more often than not
<SGautam> a basic course in boolean mathematics and bitwise manipulations is required before osdeving tbh.
<heat> no?
<SGautam> i sort of realised this when x86 docs started making more sense when I understood bitwise math
<heat> bit goes 1, bit goes 0. or, and, xor
<heat> no need for any course in mathematics lol
<SGautam> boolean mathematics is that lol
<SGautam> heat: I used to be that guy reading MUL docs when I wanted to multiply a number by 2 in asm
<heat> thats ok i don't know how to multiply numbers in x86 asm either
<heat> you have mul and imul i think? one of those is good, the other is bad
<heat> might be imul
<SGautam> nah bruh
<SGautam> shl ax, 2
<SGautam> *shl ax, 1 -- actually
<SGautam> that blew my mind when I first realised it
<heat> wonderful obfuscation
<heat> so wonderful you fucked it up
<GeDaMo> Uh, you can use add to multiply by 2 :|
gog has joined #osdev
<SGautam> ah yea
<heat> shl will be faster
<Ermine> maybe bochs is MINIMAL?
<SGautam> no way
<heat> bochs is definitely MINIMAL
<Ermine> hah
<SGautam> its a bit of pain to set up
<SGautam> you need a bochsrc
<heat> so MINIMAL it's garbage, as the s6 fans would like it
<SGautam> than just firing up qemu with args
<heat> ideally bochs would have PIPES
<Ermine> R you trying to trigger me?
<heat> yes
<Ermine> mofo
<heat> mofer*
<Ermine> ok mofer
<heat> think about it, an x86 emulator but every instruction spawns a separate process and pipes the result back
<heat> i love it
<heat> but now the separate process is a POSIX sh script running on busybox ash
<Ermine> s6 fans use execline you know
navi has quit [Ping timeout: 246 seconds]
spare has quit [Remote host closed the connection]
op has joined #osdev
<heat> gog
<gog> heat
<kof673> bochs i thought was c++...qemu ...i don't recall
<kof673> this is not a criticism, just what is needed to build...
xvmt has quit [Ping timeout: 252 seconds]
xvmt has joined #osdev
<heat> gog, do you have that dawg in you
<gog> can i pet that dawg
<gog> can i pet that daaaaaaawwwg
navi has joined #osdev
<mjg> you ok fellaz
<heat> do you have that dawg in you
<nikolapdp> > an x86 emulator but every instruction spawns a separate process
<nikolapdp> there was a guy who wrote a cloud native gameboy emulator
<heat> OH new idea: x86emufs
<bslsk05> ​blog.davetcode.co.uk: Bringing emulation into the 21st century - David Tyler's Blog
<heat> every instruction is a file
<heat> registers are files
<nikolapdp> wasn't a gameboy actually
X-Scale has joined #osdev
JerryXia1 has quit [Server closed connection]
JerryXiao has joined #osdev
Bonstra_ has quit [Server closed connection]
Bonstra has joined #osdev
navi has quit [Ping timeout: 260 seconds]
<kof673> well minus the cloud part it was inevitable, it is just unix shell/pipeline model, each process does "one thing." conversely, bash/etc. added more built-ins, i.e. part of the same process.
<kof673> juts different levels of granularity lol
navi has joined #osdev
joe9 has quit [Quit: leaving]
Jari-- has joined #osdev
<Jari--> Hi, which OSDEV book to buy if wanting to do application module for the kernel, and trim the memory management?
<Jari--> I had an application module before, but I am rewriting it
X-Scale has quit [Ping timeout: 250 seconds]
<Jari--> Operating System Design and Implementation (3rd Edition) by Andrew S. Tanenbaum? good?
X-Scale has joined #osdev
gbowne1 has joined #osdev
op has quit [Remote host closed the connection]
<Ermine> Jari--: so you need to implement a linux kernel module? You can look at LDD3 book, though it's outdated. And you'll need to study kernel documentation
<Ermine> Tanenbaum's book is about development of operating systems with minix 3 as an example. It won't teach you writing kernel modules
<Jari--> Ermine I missed DJGPP, so I wrote lots of DOS compatibility, too, BTW
<heat> it's about minix 3?? i'm afraid it won't teach you anything :(
<Ermine> it will
<Ermine> it contains some generic stuff
<heat> the author of minix writing a book about operating systems is like theo deraadt writing a book about social norms
<heat> change my mind
<Ermine> you can discuss paging in os-independent way for example
<Ermine> that there are pages, there's how processor translates virtual addresses into physical, there is a TLB
<Ermine> that sort of things
<heat> does it ramble about pessimality and crapper code for 300 pages
<heat> if not, pessimal bok
<heat> book
<mjg> the only sensible book describes a shit idea
<mjg> then a less shit idea and claims genius
<Ermine> and theo can write that it is social norm to be cisgender, but many, including me, will disagree
<mjg> anything short of that is not worh reading
<netbsduser> Ermine: de Raadt doesn't write anything about cisgenderism
<Ermine> netbsduser: it's nice, isn't it?
<netbsduser> Ermine: yes, i don't think there is any evidence to suggest de Raadt is bigoted about anything other than anything that isn't under the BSD licence
<heat> theo is bigoted about other people in general
<Ermine> netbsduser: I've got a feeling that he can spew bigotry while reading some mails from openbsd ml. But, indeed, these's no hard evidence
<heat> 'ate the freebsd, 'ate the netbsd, 'ate the linox, luv me openbsd, simple 'as
<heat> Ermine, also worth noting that you'd probably get the same vibe from linus but he's clearly not a bigot
<Ermine> heat: yeah, as far as pre-2018 linus is concerned
qookie has quit [Server closed connection]
<gimli> that guys doug16k is not here anymore right?
<gimli> s/guys/guy
<GeDaMo> Haven't seen him for a while
<kof673> he was sort of in other channels ....within the past year or two maybe...
SGautam has quit [Quit: Connection closed for inactivity]
<chiselfuse> i am trying to understand segments and ldt but i can't find a way to experiment with them on linux. i thought i could step through a process in gdb and print the ldt. i also looked in ida and didn't find anything. do i patch the program memory with a sequence of instructions that syscall modify_ldt(2) in order to check it? is there a simpler way to examine this structure for a running process?
qookie has joined #osdev
<Ermine> better write some assembly which tweaks ldt and run it in qemu
goliath has quit [Quit: SIGSEGV]
<netbsduser> i'm still stunned openbsd has an rcu-ish thing now
<Ermine> And nowadays it's not really a useful knowledge, since everyone uses paging
<netbsduser> quite
GeDaMo has quit [Quit: 0wt 0f v0w3ls.]
<zid> you can mess with the ldt with syscalls in linux userspace
<chiselfuse> i can't figure how FS and ldt is used in threads in linux. does each thread have a different ldt? i checked FS and it seems like it's the same for each thread so i assume each must have a different ldt
<zid> idk why you'd want to, but you can!
<Ermine> ldt is unused
<chiselfuse> zid: yea i found modify_ldt(2)
<zid> Linux allows processes to configure
<zid> a per-process (actually per-mm) LDT.
<zid> it's not per thread
<chiselfuse> zid: what's 'mm'?
<zid> no idea, but it isn't a thread
<blockhead> mickey mouse
<chiselfuse> Ermine: but i read that FS must point to a different point for each thread so that they can use it to access local variables at different offsets
<chiselfuse> the FS descriptor i mean
<Ermine> where did you read that
<bslsk05> ​docs.kernel.org: 29.8. Using FS and GS segments in user space applications — The Linux Kernel documentation
<chiselfuse> Ermine: 29.8.1 specifically
<zid> are fsbase and gsbase in x86
<zid> I never did much x86, only amd64
<zid> anyway, WRFSBASE
<chiselfuse> zid: yea they're the only ones allowed to have non-zero base address in their descriptors. all other segment registers are forced to zero AFAIU
<zid> is how you do it, fs just needs to contain a valid *descriptor*, it doesn't actually hold the real base address that [fs:...] uses
<zid> WRFSBASE sets that
<zid> arch_prctl(ARCH_SET_FS, fsbase);
<chiselfuse> zid: okay but this doesn't answer my question. i want to know whether each thread has a different value of FS (apparently not after i checked in debugger), and that since they're the same value, whether that implies that each thread has a different LDT so that they may provide a different base for each thread so that they don't write over each others' local variables
<zid> no, they all use the same fs value
vdamewood has joined #osdev
<zid> the base is *independent* to the selector, as I mentioned
<Ermine> chiselfuse: you can use arch_prctl call as described in that page
<zid> the base just has to not be invalid wrt to the selector, I think. And most people just.. set the selectors up for 0-4GB range anyway
<chiselfuse> zid: so you say that they have the same FS but that the base address is different in the selector for each thread, ie that each thread has a different segment selector pointed to by the same FS, and since that selector is part of the LDT, that each thread has its own LDT
<chiselfuse> oh wait you said the base is independent to the *selector*
<zid> same segement selector
<zid> different *completely seperate*, weirdly set with a special opcode, base
<chiselfuse> i thought the segment selector contained the base address
<zid> it does, for what addresses are valid
<zid> but not the actual base address used by the *addressing*
<gimli> kof673: which channles?
<zid> do you know the 16bit segmentation scheme? it's kind of a weird mix of that, and pmode segmentation
<zid> fs and gs act like 16bit segmentation, where they contain a base address which is added to the pointers that use that selector, but it also has a pmode style selector which does range checking
<gcoakes> Could someone help me to understand the available options for pivoting execution from physical memory to virtual memory for a kernel? I've been reading up on some of the different methods used, and I'm either misunderstanding it or dissatisfied with the status quo. As I understand it, you can either:
<gcoakes> - Write your pre-MMU code in architecture specific assembly and your kernel is linked as if it runs from virtual memory. (Linux, I think)
<gcoakes> - Compile two different artifacts which are linked for (1) physical memory and (2) virtual memory. Then, you embed #2 within #1. (seL4 elfloader)
<zid> not sure what assembly has to do with it
<zid> but either way you need a page you know the address of, which contains the 'switch the mmu on' code, which is identity mapped, and another, virtual map of everything
<gcoakes> Well, I guess you write the pre-MMU code in such a way that no pointers leak past the MMU enable barrier.
<zid> You need that identity mapped page, else the instruction that switches virtual memory on will stop having a valid instruction pointer underneath it at the moment you switch
<zid> you can unmap it after
<zid> (and you will want to, lest you have a small hole in the low addresses)
<chiselfuse> zid: [this](https://wiki.osdev.org/Segment_Selector) structure is one of the entries in the LDT, right? if FS is 3, then it refers to LDTR+(16*3). the base address [3-15] in this entry is the base address. so if i see an instruction `mov rax [fs:0xA]` that gets executed by multiple threads, they'll be adding 0xA to the same base address (specified in that entry). so how is it that they end up with
<bslsk05> ​wiki.osdev.org: Just a moment...
<chiselfuse> separate local variables?
<zid> am I reddit now
<zid> chiselfuse: again, that is for the *range checking*
<zid> the address calculation is fsbase+offset
<zid> checked against selector.base - selector.base+selector.limit
<chiselfuse> and what's fsbase? a completely different register than FS or what?
<zid> yes!
<zid> 21:46] <zid> different *completely seperate*, weirdly set with a special opcode, base
<chiselfuse> zid: are you sure? both in the AMD manual and resources like this one https://wiki.osdev.org/Segment_Selector refer to FS, not fsbase
<zid> why would they not refer to fs
<zid> they're about selectors
<zid> intel manual calls it IA32_FS_BASE MSR btw
<zid> If you can't find that, try C0000100H
<chiselfuse> zid: is this it https://0x0.st/XMwe.png
<zid> I guess?
X-Scale has quit [Ping timeout: 250 seconds]
<chiselfuse> hmm i'm reading that they're originially supposed to be caches for the base,limit in the ldt
<kof673> gimli, i think there is a #dos, i say "sort of" because other side of bridge, may be named differently here :D doesn't irc have whois or something? maybe people can be "invisible" to hide though (and hide channels)
<kof673> IIRC he has github, should not be impossible to find
<kof673> some "old" channel anyways, whatever it was :D
<heat> chiselfuse, an 'mm' = address space
<heat> gcoakes, linux's pre-mmu code is not written in assembly but generally careful C
<heat> it's a risky business to write position-independent C, but it usually works fine if you know what you're doing
<kof673> maybe an asm or hw channel, i don't keep logs :D
<netbsduser> i love that linux terminology
<heat> it comes from mm_struct fwiw
<netbsduser> address spaces are mms and vm objects are address spaces
<heat> to be fair, vm objects are also a garbage name
<netbsduser> what's wrong with them?
<heat> it's a horrendously vague undescriptive name
<netbsduser> it seems to be descriptive to me
<heat> what's a "vm object"? object in the vm system? what does this object do?
<netbsduser> in any case it's traditional and accepted
<heat> it really is a terrible name. alas mach came up with it and now we're stuck with that in a bunch of systems
<netbsduser> in mach it has a subtly different purpose and the combination of memory objects and vm objects match more closely how vm objects are understood today, but it's close enough
<netbsduser> i would accept segment as well
<netbsduser> though i might prefer segment to denote the map entry rather than the object mapped
<gcoakes> @heat, I think I was incorrectly generalizing RISC-V to all of Linux's bootstrap. I was reading through `arch/riscv/kernel/head.S` which seems to be where the initial switch happens.
<heat> vm_mappable? or maybe just struct pagecache :^)
<gcoakes> I really just grep'ed for satp register. I don't even really know how head.S fits into the overall build.
xenos1984 has quit [Read error: Connection reset by peer]
<netbsduser> gcoakes: to your question about transitioning from physical to virtual addressing, i see it as a bootloader duty
<netbsduser> on amd64 limine does it for me and on m68k (qemu virt and amiga) i do it myself in a minimal loader
Gooberpatrol66 has quit [Ping timeout: 256 seconds]
<bslsk05> ​elixir.bootlin.com: init.c - arch/riscv/mm/init.c - Linux source code (v6.9.8) - Bootlin
<netbsduser> since i only deal with it on the m68k i just enable a transparent translation region for the lower half of the address space and in the kernel i make away with that
<gcoakes> I've used it for years but never quite understood the purpose of the bootloader to this level. So, when GRUB or similar hands over control to Linux, is the MMU typically enabled?
<heat> this is where linux does early page table init for riscv
<heat> gcoakes, no, that's not how bootloaders usually work
<heat> at least on the UNIX/linux side
<netbsduser> grub doesn't do it, multiboot is a more basic protocol
op has joined #osdev
xenos1984 has joined #osdev
heat has quit [Remote host closed the connection]
heat_ has joined #osdev
<Jari--> ppl apparently have problems with grub, it has bugs
<bslsk05> ​www.youtube.com <no title>
<heat_> grub has never had bugs no sir never nuh uh
<chiselfuse> what does segment_selector.rpl=3 do?
<heat_> changes your ring level
<chiselfuse> isn't it only valid from 0-2? what's 3?
<heat_> ring 3...?
<mjg> let me tell what's not going to have bugs: the in-kernel grub replacfement
<Jari--> chiselfuse RPL is the field you're specifically asking about. It is a 2-bit field representing the privilege level of the code that is using the segment selector. The possible values are: 0: Ring 0 (highest privilege), 1: Ring 1, 2: Ring 2, 3: Ring 3 (lowest privilege)
<chiselfuse> oh nvm i thought there were only 3 rings not 4
<zid> What *is* 3?
<zid> you thought ring3 was ring numerical 2?
<zid> good thing about binary is that you get a fourth for FREE
<zid> because otherwise you're just wasting the 0b11 encoding
<chiselfuse> zid> you thought ring3 was ring numerical 2?
<chiselfuse> yea lol
<Jari--> just run the shit in root level
<Jari--> add features later :)
<heat_> linus torvalds vs andrew tannenbaum, colorized
<zid> Everybody asks what is three, but nobody ever asks HOW is three? :(
<chiselfuse> king terry
* kof673 inserts terrance howard joke
<Jari--> and the order matters? I think not. You can have Ring0 as an application mode processes, if you want? not?
<Jari--> chiselfuse so basically it is just an order number, it can be set as anything you want it to be
<chiselfuse> huh?
netbsduser has quit [Ping timeout: 246 seconds]
Pixi has quit [Quit: Leaving]
vdamewood has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
Gooberpatrol66 has joined #osdev
<adder> I need help figuring out why I'm getting a page fault. when I grep for exceptions, I see (old, new) = {(0xffffffff, 0xe), (0xe, 0xd), (0x8, 0xd)} (which kind of doesn't make sense to me). these are my control registers `CR0=80010011 CR2=0000000000000024 CR3=0000000000111000 CR4=000000a0` I tried disassembling address in CR2 to see what is causing the fault but no luck, out of bounds / no function contains that address
<adder> thoughts?
<heat_> you're trying to access 0x24 but it's unmapped
<adder> just one sec... I am compiling the whole thing in a really weird way
<heat_> and then what looks like subsequently faulting for related/unrelated corruption
<adder> how am I supposed to compile this?
<heat_> this = what?
<adder> like I have a sprinkle of .code64
<adder> and then I have a x86_64 kernel
<adder> and using my 32-bit cross compiler gets me in all kinds of issues
<adder> so I'm using -fPIC
<adder> (no idea what that is)
<heat_> obviously if its a x86_64 kernel you can't use your 32-bit cross compiler
<adder> do I need two compilers?
<heat_> you need a single x86_64-elf compiler
<adder> yeah but one for the bootloader?
<heat_> why do you have a bootloader?
<heat_> and in any case x86_64-elf with -m32 should probably work
<adder> wdym why do I have a bootloader? genuine question
<heat_> are you not using grub?
<adder> yeah I am
<heat_> or limite or whatever
<heat_> well, then that's the bootloader
<adder> by bootloader I meant the part the inits idt,gdt,remaps pic, transitions into long, and transfers control to kernel
<heat_> that's not how things are usually done
<heat_> usually it's all a single kernel, a very very minimal bit in 32-bit that bootstraps you up to long mode. idt, gdt, pic, whatever are all post-long-mode
<adder> oh
<adder> heat I think I'll start over
<adder> this is a fuckin mess
<Reinhilde> that's valid
<adder> .text 0xfffffffff80002f0 0x18 kernel/main.o
<adder> 0xfffffffff80002f0 kmain
<gcoakes> @adder, you mentioned not knowing what -fPIC is. It should be position independent code.
op has quit [Remote host closed the connection]
navi has quit [Quit: WeeChat 4.2.1]
Gooberpatrol66 has quit [Ping timeout: 268 seconds]
<adder> so do we want pic in osdev or not?
<adder> I think it's pagefaulting when I try to panic
<adder> how on earth is this not mapped
<adder> .eh_frame 0x0000000000105360 0x24 boot/panic.o