IRC channel logs

2022-06-29.log

back to list of logs

***dongcarl3 is now known as dongcarl
<oriansj>To port stage0 to OSX one would just need to use: https://opensource.apple.com/source/xnu/xnu-1504.3.12/bsd/kern/syscalls.master to get the correct syscall numbers.
<oriansj>BSDs and OSX pass arguments to the kernel on the stack; pushed right-to-left (first argument is the last one pushed and the last argument is the first pushed onto the stack), syscall number in the eax register and call by interrupt 0x80
<oriansj>So the only things one would need to change to port is the syscalls and nothing else as that is the only part that is Operating system specific
<oriansj>it might be easiest if we did the port for M2libc first so that you have a good reference point for the system syscalls needed
<oriansj>oh and that above is only for 32bit OSX, they do something completely different for 64bit OSX
<oriansj>arguments are passed on the registers rdi, rsi, rdx, r10, r8 and r9 and the syscall number in the rax register with the call is done via the syscall instruction and appears to follow: http://x86-64.org/documentation/abi.pdf but seems to add 0x20000000 to the syscall number for some odd reason
<oriansj>oh and for extra fun: Apple is also known to break the syscall ABI between MacOS versions
<stikonas_>I guess that's what you get with closed platforms...
<stikonas_>even if it's insane to break syscall ABI
***stikonas_ is now known as stikonas
<stikonas>they can get away with it since they also update libc at the same time
<unable_to_execut>if i wanted to change the syscalls for the elf / a.out file "tape02" output executable. should i be looking to edit "VM" "M0" the stage1 assemblers , all of the above , or something different entirely ?
<unable_to_execut>im wanting to make cc_x86 work on MAC os
<unable_to_execut>figured i would just ask before going an installing something like "linuxulator"
<unable_to_execut>last time i was here skitonas said it would be fairly easy if i learned a bit of assembly
<unable_to_execut>thanks again for help last time btw i was able to get the vm going by adding more mem
<unable_to_execut> https://www.lurklurk.org/concordance.html
<unable_to_execut>i grabbed these , im willing to change the syscalls but any help would be really great
<unable_to_execut>i really wouldn't know what im doing im not an asm programmer but i really want this to work on Mac
<unable_to_execut>oh i see you answered this right before i showed up in logs
<unable_to_execut>thanks let me check that
<unable_to_execut>ok i guess i will look at this , but ofc i have no experience or clue what im doing i will start with m2 maybe? even tho i haven't been able to compile m2 without cc_x86 i can cheat or w/e... anyways thanks i guess ill just hang out or check by later to see if you have any more info
<unable_to_execut>im gonna go look at this stuff i may be a while but will def check in later thanks alot oriansj stikonas[m] (y)
<stikonas>unable_to_execut: syscalls are directly called in all programs written in hex or assembly programs, so hex0, hex1, hex2, M0 and cc_x86. Then for C programs they are hidden inside C library (M2libc), so you would have to port it once and all C programs would work
<stikonas>but syscalls are only important for stage0-posix, not baremetal stuff from stage0
<stikonas>so no tapes
<stikonas>this is higher level prototype but similar principle: https://github.com/oriansj/stage0-posix-x86/blob/73ac62f4a89a2f9dc4fe1da7987913c820f5598a/NASM/hex0_x86.S#L29
<stikonas>as you can see function open on x86 on Linux has sycall number 5 which is hardcoded in hex0
<stikonas>that 5 might be different on different OSes
<stikonas>or even different instruction sets (e.g. arm) on Linux, but different CPU arches of course require significant porting, where as same arch but different OS is easier, just need to adjust a few constants
<unmatched-paren>I don't really see the point of porting bootstrap to mac, but if you think you'll enjoy and learn from it, then okay
<unmatched-paren>s/bootstrap/stage0 et cetera/
<checkup>i like to work on my mac
<checkup>so if i wanted to use vm's how do i execute cc_x86 ? / cc_knight?
<checkup>not as an executable?
<checkup>heres what i have been doing , i rather use the vms
<unmatched-paren>I suppose Darwin could benefit from it. I wonder if anyone is actually using Darwin standalone though.
<checkup>maybe oneday
<checkup>would be nice once i figure out how this works, yea i rather use vm's tapes, but i dont know what to do with the output from the cc_x86 tape? how does it execute with vM theres no instructions past that in "bootstrapping_steps.org"
<stikonas>yeah, personally I wouldn't port bootstrap to mac, but I wouldn't oppose it. One can then start on Mac and e.g. bootstrap linux from just source
<checkup>Our C compiler will read any code in tape_01 and output the compiled output to tape_02.
<checkup>The compiled output is macro assembly (allowing for easy inspection) which then must go through the appropriate macro assembler and hex2 steps to become a working binary.
<checkup>Should you wish to port the C compiler to a different target, one need only update the strings and a few minor places in the code; looking at M2-Planet's multi-arch support will cover all of those questions quickly.
<checkup>im basically stuck right here , with the "VM"
<checkup>1b44b454b8e7beab41ecc4fb81220ef0a396bfeb954a3589861b6807dea0c313
<checkup> i have this hash but dont know how to use it
<checkup>theres no instructions for how to run compile or hash check anything from the bootstrapsteps c compiler
<checkup>its actually really dissapointing and frustrating cuz the instructions were so clear up till then...
<checkup>i tried just running m2 thru it maybe i need 2 do something with the M2 tape just keep pushing past
<checkup>yea no im not married to mac, i rather have this work on w/e machine
<checkup>i thought thats what the promise of the vm was
<stikonas>checkup: so have you tried increasing vm ram?
<checkup>yea i did that it worked for sure
<stikonas>I haven't worked much with stage0 stuff but I think you input C source (if you have a few files you need to first combined them into one file in the right order) in tape_01
<checkup>ill check back later im probably just confused about the jump from cc_x86 to m2 cuz the gap  / lack of instructions on bootstrapping steps
<stikonas>and M0 assembly will be spit out in tape_02
<checkup>what do i do with that tho ?
<stikonas>put it to M0
<checkup>is it executable ?
<checkup>thru m0 ?
<stikonas>well, that's how all compilers work
<stikonas>including gcc
<stikonas>compiler spits out assembly
<stikonas>then assembler spits out unliked binary code
<stikonas>then linker links it
<stikonas>take a look at some stage0-posix steps, it might become clearer
<stikonas>one moment, I'll find a link
<checkup>i cant run posix on mac and like using the vm but i can do that for sure
<stikonas>see phase 5 https://github.com/oriansj/stage0-posix-x86/blob/73ac62f4a89a2f9dc4fe1da7987913c820f5598a/mescc-tools-mini-kaem.kaem
<unmatched-paren>Mac is more posix than Linux
<unmatched-paren>iirc macOS is Officially POSIX Certified(TM)
<stikonas>unmatched-paren: yes, but posix in stage0-posix right now is linux
<checkup>yea i dont wanna use nasm
<unmatched-paren>Ah, right, I thought they were talking about actual POSIX
<checkup>if i can use vm
<unmatched-paren>not stage0-posix
<checkup>the vm has an assembler i dont want to use nasm its bloated
<stikonas>checkup: so as you can see to go from C to binary you need a few steps
<checkup>and non portable
<stikonas>1) cat C files into single file (or tape in stage0)
<checkup>yea i will check it out i appreciate your help
<checkup>then run it in m0
<stikonas>2) run cc_x86 to get m0
<checkup>then run that thru stage1 asm 2
<checkup>i get that
<checkup>i just dont know wut 2 do after
<checkup>or are u saying thats not the way?
<checkup>hold on i will show u exactly wut i do
<stikonas>then 3) cat M0 definitions, C entry point and tape from step2 into one M0 file
<stikonas>4) run that through M0
<checkup>how does m0 run on the vm , do. u have much experience with the vm?
<checkup>also i really would love 2 run that vm on fpga
<checkup>so im really into the vm
<stikonas>then next step where ELF header is attached is not relevant to stage0 and so 5) run everything through hex2
<stikonas>well, that VM is just a small emulator for knight architecture
<checkup>wut is knight architecture  ? z80 ?
<stikonas>and we compiled M0 program for that architecture in the previous step
<stikonas>checkup: some old CPU arch from seventies
<stikonas>oriansj found it somewhere
<checkup>kjnights landing?
<stikonas>I don't think it's z80
<stikonas>though from similar time
<checkup>Knights Hill (KNH) was a planned successor to Knights Landing, a 10 nm many-core microarchitecture designed by intel for high performance computin
<checkup>this is all i see about that
<stikonas>no not that
<stikonas>I don't think you'll find it online
<checkup>;(
<stikonas>there is some description here https://github.com/oriansj/knight-vm/blob/master/ISA_HEX_Map.org
<stikonas>but right now consider it an arch that only has emulators and no real hardware
<checkup>its portable tho
<checkup>works on my mac and bsd
<stikonas>yes, tapes are simple abstraction
<checkup>thats why i like it
<stikonas>well, emulator is of course portable
<stikonas>that's not hard
<checkup>i want to beable 2 bootstrap the same compiler on both my computers
<checkup>mac and bsd
<checkup>thats what im trying 2 do
<stikonas>the good thing about knight is that it only has 2 tapes, 1 in and 1 out. You don't need to worry about e.g. disk, how to deal with drivers, etc
<stikonas>anyway, try those 5 steps
<checkup>im def gonna look thru this chat and try to get this goin on the vm
<checkup>thanks for your time
<stikonas>checkup: and once you get everything working, it would be nice if you could update documentation
<stikonas>cause stage0 is less used and hence more poorly documented
<checkup>yea bootstrapping.steps.org is what i have been using
<checkup>and it pretty much drops off after cc_x86
<checkup>insetad of going into m2 so if i figure it out and get it able to peirce thru 2 mes tcc
<stikonas>oh also when building m2-planet you need to use cc-mini.c instead of cc.c
<checkup>and get my  high level compilers going i wiill definately be more confident about telling anyone else how to do it
<checkup>with the vm ?
<stikonas>well, when you combine m2-planet source into a single file
<checkup>there is one out there already
<checkup>i just trust that one
<stikonas>oh ok
<stikonas>I didn't realize it ships with M2.c
<checkup>i have like all the different versions from savana etc
<checkup>so im just grapping peices and using w/e works
<stikonas>yeah, ok, it's some older version
<stikonas>but should be fine
<checkup>its called M2-Planet_x86.c
<stikonas>yes, but it's like 10 versions behind :)
<checkup>i did a cat but didnt' have much more luck with that
<stikonas>M2-Planet in git repo is way more capable now, it has some support for preprocessor, etc
<checkup>like i definately try everything in the docs its whats not in the docs thats getting me messed up
<stikonas>oh, but keep in mind that M2-Planet_x86.c would be x86 version
<stikonas>it won't run on Knight
<stikonas>so maybe if you want to run it on Knight, you'll have to grab files from M2-Planet.git repo
<checkup>lfs.master@lfsmasters-MacBook-Pro CC_KNIGHT]DEV]M2]ON]0002 % ./bin]vm/vm --rom cc_x86/cc_x86 --tape_01 M2-Planet_x86.c --tape_02 tape02]OUTS/M2planet --memory 2500K
<checkup>Computer Program has Halted
<checkup>After Executing 16966733 instructions
<checkup>lfs.master@lfsmasters-MacBook-Pro CC_KNIGHT]DEV]M2]ON]0002 % cat defs tape02]OUTS/M2planet > temp
<checkup>lfs.master@lfsmasters-MacBook-Pro CC_KNIGHT]DEV]M2]ON]0002 % ./bin]vm/vm --rom M0/M0 --tape_01 temp --tape_02 temp2 --memory 1500000k
<checkup>Computer Program has Halted
<checkup>After Executing 112690395 instructions
<checkup>lfs.master@lfsmasters-MacBook-Pro CC_KNIGHT]DEV]M2]ON]0002 % ./bin]vm/vm --rom stage1_assembler-2/stage1_assembler-2 --tape_01 temp2 --tape_02 tape02]OUTS/cc_Out]M2planet --memory 50000K
<checkup>Computer Program has Halted
<checkup>After Executing 16359742 instructions
<checkup>lfs.master@lfsmasters-MacBook-Pro CC_KNIGHT]DEV]M2]ON]0002 %
<checkup>so i have this "cc_Out]M2planet" files
<checkup>apperantly its not an executable
<stikonas>looking through that list...
<checkup>]0002 % file tape02\]OUTS/cc_Out\]M2planet
<checkup>tape02]OUTS/cc_Out]M2planet: data
<checkup>≠ÌÆÍ:fiˇÏ͛ӥ≠ÓÎÎŒÏ≠ÌÆÌÍ˸˛ÕÍfi⁄Ó°Ífi⁄Ó§≠Ô˛Œ≠fiÎJfiÓ∫fiˇÏ͛ӻ≠ÌÆÌ≠Ô˛Œ≠fiÎ≠ÓÎ≠Ô˛Œ≠fiÏäfiÓ fiˇÏ͛ӑ≠ÓÌ≠ÌÆÍXÍ≠ÌÆÍû™€Æ≠fiÍäfiÓ™fi⁄Ó†Î≠fi晀Ó∞PÓÎÓÓ˛
<checkup>looks like that inside
<stikonas>oh inside would be unreadable
<stikonas>it's machine dode
<stikonas>code
<stikonas>oriansj: is M0 from knight architecture compatible with x86 one?
<checkup>i imagine some part of stage0 is equipped to read it or vm?
<stikonas>checkup: no, I think that is x86 machine code
<checkup>i think knight and x86 give same result.
<stikonas>vm is for knight code
<checkup>oh ok i can use the cc_knight compiler and try again
<stikonas>checkup: ok, M0(x86) and M0(knight version) might be giving the same result
<checkup>i believe they do
<stikonas>well, cc_knight might be more interesting for you
<stikonas>if you want to keep things running
<checkup>and thats past bootstrapping.steps.org
<checkup>thats just me doing stuff on my own trying 2 work thru
<checkup>parts.rst
<checkup>  hex0 (seed)
<checkup>- hex0 compiles hex1
<checkup>- hex0 compiles catm
<checkup>- hex1 compiles hex2 (v1)
<checkup>- hex2 (v1) compiles M0
<checkup>- M0 compiles cc_x86
<checkup>- cc_x86 compiles M2-Planet (v1)
<checkup>- M2-Planet (v1) compiles blood-elf (v1)
<checkup>- M2-Planet (v1) compiles hex2 (final)
<checkup>- M2-Planet (v1) compiles M1
<checkup>- M2-Planet (v1) compiles kaem
<checkup>- M2-Planet (v1) compiles blood-elf (final)
<checkup>- M2-Planet (v1) compiles get_machine
<checkup>- M2-Planet (v1) compiles M2-Planet (final)
<checkup>- M2-Planet (final) compiles mescc-tools-extra (see next step)
<stikonas>yes, that's a summary for steps, but on knight architecture you won't be able to go beyond M2-Planet
<checkup>oh
<stikonas>M2-Planet should build on knight
<stikonas>but then mes would not
<stikonas>nobody ported it
<checkup>so i guess i should forget about knight if im trying to do mes.
<checkup>would that be a hard port ?
<checkup>im def trying 2 bootstrap gnu/clang
<stikonas>hmm
<stikonas>mes itself maybe not so hard, but mescc would be hard
<stikonas>checkup: bootstrap till gnu would be a very hard project
<checkup>you mean on vm?
<stikonas>anywhere
<stikonas>with lots of different people working on different parts we only got x86 on Linux
<stikonas>even amd64 (x86_64) does not work
<checkup>oh i was under the impression you got tcc / gcc
<stikonas>only on x86
<checkup>you mean no arm ? risc32?
<stikonas>yes
<checkup>shame
<stikonas>arm and risc stop at either stage0-posix or mes
<stikonas>there is somebody porting mes/mescc to riscv64
<stikonas>well, mes is a few hours of work but mescc is tricier
<stikonas>trickier
<stikonas>well, building GCC is no easy task
<stikonas>it has lots of dependencies
<checkup>yea
<stikonas>we have to go through lots of old software
<stikonas>that was not written with portability to other arches in mind
<checkup>does it require python?
<stikonas>no, no python necessary
<checkup>i dont mind python but compilers needing that is weird
<checkup>oh cool
<stikonas>though we are going to add python to live-bootstrap
<stikonas>glibc needs it
<stikonas>(new versions of glibc)
<stikonas>there are some python scripts here https://sourceware.org/git/?p=glibc.git;a=tree;f=scripts;h=1c8772090e6d41b9d3de987a664846f904738c27;hb=8521001731d6539382fa875f1cac9864c466ef27
<stikonas>checkup: but gcc needs Perl for its build system
<stikonas>(GNU Autotools)
<checkup>if im being stubborn, i guess my best bet would be to try to install "LTP" linuxulator on my bsd, and bootstrap posix to gcc and see where that gets me? thats what i was planning on doing today
<checkup>i dont really know what else to do if vm isn't gonna perform fully
<stikonas>or just run full emulator
<stikonas>(QEMU()
<stikonas>QEMU
<checkup>i haven't really mastered porability of qemu and bridged networking etc
<stikonas>networking is not really needed
<checkup>i wanna move files around
<stikonas>live-bootstrap can run without network
<checkup>how would i get it out lol?
<checkup>im really trying to go for a portable bootstrapper
<stikonas>I mount qemu disk on host
<stikonas>to get stuff out
<checkup>yea i haven't really mastered that but that sounds like solid advice
<stikonas>checkup: as for knight, keep in mind that baremetal stuff can only get you so far... You are basically limitted to one input file and one output. Forget about shells, etc, no bash, so no autotools, etc...
<checkup>sorry i got disconnected.. yea i just been really bummed about building software only to have the underlying compiler change etc. especially on mac/ios was hoping i could get a stable enviornment
<checkup>mandatory macos updates and what not
<stikonas>I just said: "checkup: as for knight, keep in mind that baremetal stuff can only get you so far... You are basically limitted to one input file and one output. Forget about shells, etc, no bash, so no autotools, etc..."
<checkup>thinking about that
<checkup>ive seen a forth c compiler for "2klinux"
<stikonas>you can do some easy steps without OS, but at some point you need OS for bootstrapping and knight VM wouldn't be good for that
<checkup> https://github.com/NieDzejkob/2klinux wonder if this would be meaningful at all
<checkup>yea. i wanted to use freebsd
<stikonas>yeah, NieDzejkob is occasionally on this channel
<checkup>oh cool
<stikonas>we also have (that's a recent thing) https://github.com/ironmeld/boot2now
<checkup>yea i looked at that first, dont really know what to make of it
<stikonas>this is a x86 kernel that can run all steps in stage0-posix
<stikonas>(but not mes)
<checkup>it doens't uefi boot tho?
<stikonas>no, I think it's MBR
<checkup>im really trying to push towards a portable uefi boot kernel with a portable compiler
<checkup>that can boostrap itself
<checkup>right?
<stikonas>one could right something similar for UEFI I guess
<checkup>thats why i need the compiler
<checkup>was really hoping vm would see thru 2 that but i guess it was a pipe dream
<stikonas>anyway, bootstrapping is probably harder than what you thought :)
<stikonas>well, vm can build M2-Planet compiler
<stikonas>but not GCC
<checkup>can m2 build tcc ?
<stikonas>no
<stikonas>we want to write some kernel in M2-Planet dialect
<stikonas>but there is nothing yet
<stikonas>and if there will be, initially it will be x86 only
<stikonas>though I guess one could build M2-Planet for knight in thatvm
<stikonas>and then build x86 kernel
<checkup>would have been really cool even if u had a knight fpga
<checkup>that could host clang/gcc
<checkup>that way u could be on x86 or fpga or emulate either or
<stikonas>yeah, that might be cool project but we don't have anybody working on that
<stikonas>I haven't coded for FPGAs myself...
<checkup>not really a whole lot of other players in the game it seems u guys are the only ones who really care about bootstrapping trusted compiler
<stikonas>though we do use them at work
<checkup>unfortunately
<checkup>yea i would like to take a pi shaped fpga and put it in a "kano" pi laptop and call it a day
<checkup>get a x86 emulator and uefi going on it and just have self bootstrapping laptop
<checkup>i just prefer doing work on laptop is the problem
<stikonas>well, uefi is not really requirement
<stikonas>for bootstrapping it is more important to have an implementation
<stikonas>not necesserily standard compatible implementation
<checkup>all new laptops use uefi. they dont even allow mbr. it seems at least the ones i have. so i kinda wanted my machines 2 work , be mine
<stikonas>do they not?
<checkup>nah
<stikonas>everywhere I saw you could switch on legacy mode
<checkup>i have a surface pro
<checkup>seems that now they dont even let u use uefi (msft)
<checkup>they want a vm on the machien so u have no bootccontrol
<checkup>i guess its for security
<stikonas>but e.g. in live-bootstrap the shell scripts are bash specific, they are not POSIX compatible scripts
<checkup>*microsoft hololense
<stikonas>checkup: well, those are "tablets"
<stikonas>which I guess is why they don't enable legacy mode
<checkup>i guess im a hacker or something lol
<checkup>just wanna beable 2 use my property
<stikonas>personally I wouldn't buy microsoft stuff...
<checkup>the way i want. w/e i dont wanna complain
<checkup>yea i only would really trust fpga nowadays i dont wanna champion different vendors and then be let down later on down the road
<checkup>thats basically how i feel about mac
<stikonas>they might also have some secure boot stuff on those things
<stikonas>so you can't even boot your stuff, nevermind about bootstrapping compiler
<checkup>well thats easy 2 shutoff or bypass with a hash
<checkup>like u can literally get a secure hash for your stuff its pretty ez
<checkup>if u have a kernel u want 2 secure boot, u maybe a vendor or something , but yea i think thats goin away with msft going 2wards these vm only boots
<checkup>i mean thats really scary
<checkup>it just boots right into a vm no uefi no mbr nothing
<checkup> https://shop.trenz-electronic.de/en/TE0726-03-41C64-A-ZynqBerry-SoC-Module-with-Xilinx-Zynq-7010.-Raspberry-Pi-2-compatible
<checkup>im sure this is basically what apple is using
<checkup> https://www.walmart.com/ip/Kano-Computer-Kit-Complete-Build-Code-your-own-Laptop-10-1-HD-Screen-1005-02/629416665
<checkup>inside something like this. maybe 100 bucks to make shipping for 3k +
<checkup>so yea. knight vm full thru 2 clang/gcc2 uefi would be really nice
<checkup>*knight fpga
<checkup>but maybe overly ambitious giving the current state of stuff. but yea. if ur gonna keep deving definately keep that in mind pls !thanks for your time i will mess around with some of this stuff and see if i can get anything going