Fusion OS: a hobby kernel written in Nim

2024-08-22 Thread khaledh-nim
> What's the problem? Patch alloc.nim to offer what you need. I am planning to patch at least `osalloc.nim` to allocate VM pages, which seems to be simple enough. Patching `alloc.nim` to allow multiple heaps is a good idea, but I'm not sure I fully understand the internals yet. Thanks for the p

Fusion OS: a hobby kernel written in Nim

2024-08-22 Thread khaledh-nim
This is actually one of the challenges I'm facing right now with channels (IPC) in Fusion. Since it's a single address space OS, a design goal I'm aiming for is to create a "shared heap" between the sender and the receiver processes, allowing for sharing pointers across process boundaries. *

Fusion OS: a hobby kernel written in Nim

2024-08-21 Thread khaledh-nim
> The world is often stuck in a limited view of just "What caught on, often in > a limited community for historically contingent reasons" and declaring > something a hobby/research is often a good way to break out of that mold. That's exactly why I'm doing it. There are too many Unix-like OSs, b

Fusion OS: a hobby kernel written in Nim

2024-08-21 Thread khaledh-nim
>From a kernel point of view, a resource used by a process (e.g. file, socket, >channel) is just an entry in some process resource table. The entry is created >when the process asks for the resource, and is removed when it's done with it. >The kernel itself has no awareness of >_[when](https://

Forum logo issue

2024-08-20 Thread khaledh-nim
Is it just me or does was the forum logo changed to a comment icon? It's hard to see because it's black against the dark header background.

New OSX weirdness - extraneous ld warning

2024-08-17 Thread khaledh-nim
I just came across this today. It's happening because of the multiple use of the `{.passl: "-lm".}` pragma as @matthesoundman mentioned. I was able to suppress the warning by adding this to my `nim.cfg` file: # suppress warning about duplicate "-lm" flag clang.options.linker = "

Newbie Here! Can I have some feedback on my code?

2024-08-11 Thread khaledh-nim
Thanks. I'm not sure there's a name for this style. It's just precomputing some variables to make a complex if expression readable. There's a downside to it though: if a precomputed variable is not used (e.g. due to an early branch being taken), then it's wasted. For example: all variables exce

Newbie Here! Can I have some feedback on my code?

2024-08-10 Thread khaledh-nim
I see you do a lot of looping and calling string functions to make some decisions and assign them to variables. I'd make those decisions once at the beginning and use them in an if/elif/else expression. A good way to go about this is to construct the decision tree first, then go back and popula

Objects of size 32+ bytes get zero-mem'd twice upon construction

2024-08-10 Thread khaledh-nim
Consider the following, if the size of array `a` is 1, 2, or 3, the object is zero-mem'd once: type MyObj = object a: array[3, int] proc main() = var src = MyObj() Run generates: N_LIB_PRIVATE N_NIMCALL(void, main__mem_u24)(vo

Best location to declare variables in a proc

2024-08-04 Thread khaledh-nim
> There is overhead to create and destroy a variable 100 times. I tested this, and it seems that the variable memory location (on the stack) is reused; i.e. the space is reserved for it once on the stack. Note: Keep in mind that string objects store a pointer to the actual string data on the he

Using Nim's heap allocator on a pre-allocated memory region

2024-07-31 Thread khaledh-nim
> I did an experiment where I wrapped `mmap` make all the memory used by a Nim > process shared so I could run a second program which loaded all the shared > memory and allowed the two programs to pass memory addresses between them. This is very similar to what I'm trying to do with my OS. Howev

Using Nim's heap allocator on a pre-allocated memory region

2024-07-31 Thread khaledh-nim
Is it possible to use the heap allocator on a memory region that I provide during runtime? Typically Nim would use the OS allocator (mmap, VirtualAlloc) to grab memory pages for its allocator, but what if I have a fixed memory region that I'd like to use as a heap, is there a way to _[attach](h

Fusion OS: a hobby kernel written in Nim

2024-07-16 Thread khaledh-nim
> And an interrupt can be scheduled on a different thread This sounds very close to [scheduler activations](https://en.wikipedia.org/wiki/Scheduler_activations), a formalized way for an upcall mechanism from the kernel to userspace. I need to give this more thought, but it is an interesting ide

Fusion OS: a hobby kernel written in Nim

2024-07-16 Thread khaledh-nim
Thanks! This is intentionally not going to be a Unix-like OS, so no POSIX :) I haven't thought about the API yet, there's much to be done before I get to that stage. But I have some rough ideas: * User tasks should communicate with the kernel and other userspace tasks through statically typed

Fusion OS: a hobby kernel written in Nim

2024-07-14 Thread khaledh-nim
This is a hobby OS I've been working on for a while. It's currently not doing much, but it has the critical foundations to build on. My progress on it has been slower lately, but I plan to pick it up again soon. Currently it has the following features * UEFI Bootloader * Physical Memory Man

Page allocation for a custom OS

2024-02-05 Thread khaledh-nim
Thanks! It works now. I had to remove `-d:useMalloc` from my configs as well, since it bypasses osalloc altogether.

Page allocation for a custom OS

2024-02-04 Thread khaledh-nim
Oh, interesting. Didn't know about `patchFile`. Now that I read the docs on nimscript and did some research on the compiler code, I can't seem to get it to work. This is what I have: # src/kernel/config.nims patchFile("nim", "osalloc", "../nimpatches/osalloc")

Page allocation for a custom OS

2024-02-04 Thread khaledh-nim
I'm working on a hobby OS, and one thing I'm tackling next is trying to leverage Nim's heap allocator instead of writing my own allocator. I know that in [osalloc.nim](https://github.com/nim-lang/Nim/blob/devel/lib/system/osalloc.nim) Nim uses the underlying OS page allocator to allocate/free p

Niklaus Wirth has died

2024-01-03 Thread khaledh-nim
Wirth had a great impact on the programming languages field. He received the [Turing Award](https://amturing.acm.org/award_winners/wirth_1025774.cfm) in 1984 for his contributions. I believe Nim has been inspired by some Wirthian languages (particularly Modula 3, Delphi, and Oberon), according t

Sum types, 2024 variant

2024-01-02 Thread khaledh-nim
This is great! Looking forward to having this in the language. Any chance we can have some sugar to avoid declaring a payload object for branches? i.e. the following would implicitly declare anonymous types for `BinaryOpr` and `UnaryOpr`: type Node = enum of BinaryOpr

ref types and the align pragma

2023-12-19 Thread khaledh-nim
@mratsim Thanks for the context. I created an RFC here:

ref types and the align pragma

2023-12-19 Thread khaledh-nim
Sure. But what's the use of aligning a pointer? I'd expect the object being pointed to to be aligned instead.

ref types and the align pragma

2023-12-19 Thread khaledh-nim
@demotomohiro That's what I realized as well, that the references (i.e. pointers) themselves are aligned, but not what they point to. IMHO, this is counter-intuitive. > The alignment is not passed over to the heap allocator. @Araq is this a bug, or by design?

ref types and the align pragma

2023-12-18 Thread khaledh-nim
I'm not sure why the first two cases aren't aligned: type MyArr = ref array[4, int] MyObj = ref object MyArrObj = ref object arr {.align(256).}: array[4, int] var arr {.align(256).}: MyArr var obj {.align(256).}: MyObj var arrObj: MyA

os:any vs os:standalone

2023-11-29 Thread khaledh-nim
I just thought I'd close the loop on my last message. It turns out that on Mac, the default is `cc = clang`. I had to set add `cc = gcc` in the config file for it to pick up the `amd.any.gcc.*` configs. Otherwise it assumes the configs should be in `amd.any.clang.*`.

os:any vs os:standalone

2023-11-21 Thread khaledh-nim
I think I found a reproducible scenario. It has to do with using a cross-compiler (e.g. mingw) and `os:any` together. I'm using mingw because I need to produce a PE32+ image, which is required by the UEFI spec for bootloaders. --listCmd cpu = amd64 os = any mm = ar

os:any vs os:standalone

2023-11-21 Thread khaledh-nim
I can try to provide a minimal example. Is there an easy way to tell nim to dump what it thinks current option values are?

os:any vs os:standalone

2023-11-20 Thread khaledh-nim
Sorry, follow up question. I noticed that if I put `--os:any` in a `nim.cfg` file, it doesn't take effect. It has to be passed on the command line to work. Is this by design or something overlooked?

os:any vs os:standalone

2023-11-20 Thread khaledh-nim
Great! Thanks for the confirmation 👍🏼

os:any vs os:standalone

2023-11-19 Thread khaledh-nim
That was my guess as well. Versions of the compiler manual up to [1.0](https://nim-lang.org/1.0.0/nimc.html#nim-for-embedded-systems) mention `os:standalone`. As of version [1.2](https://nim-lang.org/1.2.0/nimc.html#nim-for-embedded-systems), the manual mentions `os:any`, which lines up with th

os:any vs os:standalone

2023-11-19 Thread khaledh-nim
I've been in the process of developing a kernel in Nim. I've made a lot of progress and I'm planning to write a blog series about it. But when I came back to some of the basics, I'm not sure I quite understand the difference between `--os:any` and `--os:standalone`. The section on [embedded sys

With what parameters does echo call fwrite? Trying to implement fwrite in Nim.

2023-11-04 Thread khaledh-nim
Here's how I implemented [fwrite](https://github.com/khaledh/axiom/blob/e8c96c564c476a1d67ae372f8dfbab2dfdc74c5d/src/lib/libc.nim#L75-L83) in my [kernel](https://github.com/khaledh/axiom): type constCstringImpl {.importc: "const char *".} = cstring constCstring = distinc

Why is building the community and ecosystem such a struggle?

2023-10-30 Thread khaledh-nim
Tooling is definitely an area that needs much improvement. I prefer JetBrains IDEs over VSCode, but unfortunately the development of the current JetBrains [Nim plugin](https://plugins.jetbrains.com/plugin/15128-nim/versions) seems to have stagnated. So I thought I'd try developing a new plugin,

Why is building the community and ecosystem such a struggle?

2023-10-25 Thread khaledh-nim
> I've seen many time comments that are quite harsh, and honestly people, even > lurkers, don't want to deal with that. This. I'm torn because I love the language, but I get doubts about whether it's worth it or not due to the harshness of some of the interactions I see repeated here and on is

Nim grammar top-level stmt vs complexOrSimpleStmt

2023-07-24 Thread khaledh-nim
Thanks for confirming. I submitted a [PR](https://github.com/nim-lang/Nim/pull/22325) to fix the docs.

Nim grammar top-level stmt vs complexOrSimpleStmt

2023-07-23 Thread khaledh-nim
Nim's [grammar](https://nim-lang.org/docs/manual.html#syntax-grammar) defines the top-level term to be: module = stmt ^* (';' / IND{=}) Run where `stmt` is: stmt = (IND{>} complexOrSimpleStmt^+(IND{=} / ';') DED) / simpleStmt ^+ ';'

Subtype cannot be implicitly converted to base type (without ref)?

2022-06-14 Thread khaledh-nim
type Liquid = object of RootObj color: int Water = object of Liquid sparkling: bool var w = Water() var l: Liquid = w # invalid object assignment [ObjectAssignmentError] type RefLiquid = ref Liquid RefWater = ref Water var