RSSAmplifier

Blog

Edgar Luque

Software Developer

edgl.devRSS feed ↗25 posts

Latest posts

Creating an x86_64 kernel in Rust: Part 4

The frame allocator from Part 3 hands out physical frames, but the kernel can't touch one until something maps it to a virtual address. That mapping is the last piece missing before alloc works, so by the end of this part Vec , Box and String all do something useful. Writing an OS in Rust covers this ground too, in Paging Implementation and Heap Allocation , and it's the thing to read if…

Creating an x86_64 kernel in Rust: Part 3

Next we will add a frame allocator, needed to do proper memory mapping which will result in us having the ability to add a heap allocator for our kernel. Allowing us to use Rust's alloc crate, giving us access to Vec and more. To implement a frame allocator, we need to get a memory map, this map gives us the information of what regions of memory are usable by the kernel. Some regions of…

How Block Access Lists are implemented in ethrex

A Block Access List is a structured, per-block record of every account and storage slot touched during execution, with the post-execution values. The top-level shape is List[AccountChanges] , one entry per touched address. It lives in two places: a new block_access_list_hash field in the block header ( keccak256(rlp.encode(bal)) ), and the BAL itself transmitted alongside the block via the Engine…

New Programming Languages Have an AI Problem

There's a playbook for getting a new programming language adopted. Find a niche, build a community, grow the ecosystem, get some corporate backing if you can. It's hard, but it works. Rust did it. Go did it. Kotlin did it. The path was known. I think that path just got a lot harder, and the reason is AI. The old game New languages always had barriers to overcome. No libraries. No Stack…

Creating an x86_64 kernel in Rust: Part 2

Adding Serial output QEMU provides serial output by specifying it in the cli options: -device isa-debug-exit,iobase=0xf4,iosize= 0x04 \ -serial stdio \ The device isa-debug-exit allows us to exit QEMU easily. The serial output is a 16550 UART universal asynchronous receiver-transmitter. For this, we will use the uart_16550 crate, which interfaces with the port-mapped I/O (basically…

Creating an x86_64 kernel in Rust: Part 1

This is some kind of blog series about my journey as I learn and implement my own Rust kernel. Any knowledge shared here may not be fully true, since I do this as a hobby and I'm not an experienced kernel developer. I'm just doing this for fun, learning about the true low level bits that make running a computer with the x86_64 architecture possible. Sometimes I will mention some names or…

A 2024 wrap up

In 2024, I started some side projects: My own programming language, edlang , which I made mostly to learn more about compilers, it uses the inkwell rust library, which is a nice wrapper for the LLVM codegen library. A RISCV (RV64G) emulator, which I called rysk , this helped me learn about the RISCV architecture. It's pretty bare-bones but cool nonetheless. At work, we use a lot MLIR, thanks…

Rust Generic Function Size Trick

When using generics in Rust (and any language that supports this), what happens under the hood is that the compiler generates a function implementation when it finds a call for each combination of different types used in the generic parameters. This can produce a lot of code if the function body is big. pub fn work_with_path < T : AsRef < Path >>(path : T ) { &#x2F;&#x2F; Here the body is small,…

Intro to LLVM and MLIR with Rust and Melior

If you haven&#x27;t heard about MLIR yet, it is a novel project born within LLVM, also what powers MOJO , the Torch-MLIR project , the high level IR of flang , iree and more . But in case you don&#x27;t know much about LLVM yet, I&#x27;ll try to explain a bit. A primer on LLVM LLVM, as their web says, is a collection of modular and reusable compiler and toolchain technologies. But in this post I…

Implementing a simple Hashmap in Rust

Have you ever wondered how a hash map works internally? The idea is quite simple: you map a key to a value, but how do you do that efficiently? This is where hashes come into play. You get a key, then hash it, which gives you an integer value, but we want to map that value into an index inside the backing storage, so you need to calculate the number modulo the current capacity of the backing…

UI Code in DDraceNetwork

This is some kind of guide into how the UI code works in DDNet. Probably can be considered part 1, in case I continue it. Foremost, since this is a game, the UI is rendered using immediate mode , which means, every render tick, the logic on whether something is hovered, rendered, clicked, etc is done. There are some optimizations around this, DDNet uses text containers to cache the rendered text…

Gentoo as a daily driver

I&#x27;ve been using GNU&#x2F;Linux for quite a while now, I don&#x27;t remember exactly what my first distro was, probably Ubuntu or Debian. I eventually switched to Arch Linux and stayed with it for a long time, I really enjoyed it, but I have a thing for trying new stuff, and eventually delved into it. Filesystem Coming from an Arch Linux installation using LVM on LUKS, this time I decided it…

Creating a bencode parser with nom

Since long I wanted try out nom, at first I boldly started parsing PDFs but after realizing the scope of such project, I put it off and started with a way smaller idea: a bencode parser. If you have never delved into the BitTorrent protocol you probably don&#x27;t know what bencoding is so let me explain it. The Bencode Spec Bencode is the encoding used by the BitTorrent protocol to store data,…

Parsing compressed files efficiently with Rust

I recently wanted to create a tool to create plots showing concurrent players each day on the open-source game DDraceNetwork (DDNet for short). DDNet hosts an HTTP "master server", which is what the game client uses to fetch information about game servers they can join. Thankfully they keep online the master server status of previous days . Each .tar.zstd file contains a JSON file every 5 seconds…

The Rust dbg! macro

The dbg! macro is a useful macro to debug, and I think a not well known one, not to be confused with debug logs using format strings, this macro is useful when you are about to put println calls everywhere in your code to know if it reached a path, what value a variable has, etc. It uses the Debug trait implementation of the type of the given expression. Since Rust is an expression oriented…

Wrapping errors in Rust

While I was developing a rust crate ( paypal-rs ) I noticed my error handling was pretty bad. In that crate I had to handle 2 different types of errors: HTTP related errors, in this case reqwest::Error Paypal API errors, which I represent with my own struct PaypalError . Initially I used anyhow but then I found out this is pretty much only good to be used on binary applications, not in libraries.…

Implementing a chat command in DDraceNetwork

This is the part 3 of my series of articles about coding in DDraceNetwork, you can find the first article here . We will implement a command that shows info about our player: &#x2F;aboutme <times> Times will be how many times we print this info. Go to src&#x2F;game&#x2F;server&#x2F;ddracechat.h Here you can see all the chat commands, they are created using a macro. The chat command macro The macro…

Rust Iterators: Fibonacci series

In this article we will implement an iterator that generates Fibonacci numbers, where each number is the sum of the preceding ones, starting with 0 and 1. First we define our data structure: struct Fibonacci { a : u64 , b : u64 , } impl Fibonacci { fn new () -> Self { Fibonacci { a : 1 , b : 0 } } } Here a and b represent the preceding numbers. To implement the iterator we need to implement the…

Code conventions in DDraceNetwork

This is the part 2 of my series of articles about coding in DDraceNetwork, you can find the previous one here . What are coding conventions? They are a set of rules that dictate how the code should be written, so that the code style is consistent among the codebase. DDNet naming conventions Note: There is an ongoing discussion about variable naming, find out more here . Currently, this is how we…

Creating precompiled headers with cmake

What are precompiled headers? They are a partially processed version of header files, this speeds up compilation because it doesn&#x27;t have to repeatedly parse the original header. How to use it The way to do it is to pass the header files you want precompiled to the target_precompile_headers command. Imagine this folder structure: . ├── CMakeLists.txt └── src ├── header.h └── main.cpp 1…

What&#x27;s new in Python 3.9

Python 3.9 Python 3.9 has been released on October 5, 2020. Add Union Operators To dict (PEP 584) This allows the union operation to be performed on dicts: >>> a = { 'x' : 1 , 'y' : 2 , 'z' : 3 } >>> e = { 'w' : 'hello world' } >>> a | e { 'x' : 1 , 'y' : 2 , 'z' : 3 , 'w' : 'hello world' } And also: >>> x = a >>> x { 'x' : 1 , 'y' : 2 , 'z' : 3 } >>> x |= e >>> x { 'x' : 1 , 'y' : 2 , 'z' : 3 ,…

Modernize your linux workflow with Rust

exa, a replacement for &#x27;ls&#x27; A replacement for ls which features better defaults and more features. github.com&#x2F;ogham&#x2F;exa bat, a cat(1) clone with wings. Bat supports syntax highlighting, git integration, paging and more. If you use (neo)vim with fzf.vim and have ripgrep and bat installed your search will have a preview window with highlighted code: fd, a simple, fast and…

An intro to the DDraceNetwork game source code

What is DDraceNetwork? It&#x27;s an open source mod of teeworlds which was released on steam not long ago. The language used is C++ along with some python scripts to generate the network protocol, it uses CMake for building. It&#x27;s made on top of SDL2 with a custom OpenGL renderer. The source can be located here: github.com&#x2F;ddnet&#x2F;ddnet My story on DDNet This mod, also called ddnet was…

An intro to MiniUPNP

If you have a software that requires port forwarding, you may want to implement UPnP to make things easy for your end users. When I wanted to implement it, the first library I found was MiniUPnP , sadly it doesn&#x27;t have much documentation but a quick look at the header files and some examples on the internet I managed to make it work, here is how: First the required include directives we need:…

Setting Up SDL2 with CMake

Installing CMake Most common distributions have cmake available on their package manager repostories: # Debian based sudo apt install cmake # Arch pacman -S cmake Install SDL2 libraries I only know about the debian based ones, if you are on another distro you should look them up. sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-net-dev libsdl2-ttf-dev libsdl2-gfx-dev…