-
GDB all the way down!
03/27/2021 at 15:18 • 0 commentsIn this week's episode we leveled-up our debugging capabilities. Continuing our last week effort to plug GDB into the emulator, we added single-stepping breakpoints, and memory/register writes.
This means we'll be harness the full power of GDB to debug the emulated code: step through the lines of source code, break at certain locations, travel through the stack trace and inspect/modify the values of local and global variables.
To sweeten the deal, we even managed to hook the Visual Studio Code debugger into the simulator, allowing us to use a modern and convenient user-interface for debugging.
In the episode recording you will see all the work that led into that magical moment: how our naïve implementation of the gdbserver "c" command failed to work with stepping and breakpoints, the intensive troubleshooting and debugging that followed, and how eventually comparing our implementation with the physicals Pi Pico's debugger revealed the answer.
The first 22 minutes of the episode show how I review a pull-request from Brain Popeck, adding 3 new instructions: sxtb, asrs, eors, and uncovering a sneaky bug in our signExtend implementation. Then we dive right into hacking on gdbserver!
The next episode will air on Tuesday. If you want the link right in your inbox, you can sign up for email updates.
-
Hardcore GDB Debuggin'
03/22/2021 at 23:36 • 0 commentsHow do you debug the code that is running in your emulator?
In the previous episodes, we printed a trace log of every single instruction that the emulator executes. This allowed us to find various bugs in our virtual RP2040 chip. This method worked, but was a very slow and inefficient: we had to go back and forth between the trace file, the assembly listing and the source code.
The last episode started as usual, hacking on a few more instructions. But midway it totally changed course: we tried to make it possible to connect GDB, the GNU debugger, into the emulator.
It took us about an hour of coding, but eventually we got it to work: GDB connected and was able to read the CPU state, registers, and even show us what line of code the emulated MCU was running!
You can watch the whole process here. GDB hacking starts at 1:24:12 👇
This week I'm planning to continue hacking on the GDB integration. We'll also take a look at a pull request some nice guy sent us, and hopefully also merge it. It adds the few missing instructions: sxtb, asrs, eors.
You can watch the stream on YouTube.
-
LDR, STR, hard_assertion_failure() and panic!
03/16/2021 at 10:59 • 0 commentsLast week, we implemented a bunch of missing instructions and completed the family of LDR/STR instructions, as well as LSLS and ADD (register).
chegewaras, who watched the stream, suggested that we also decode the 4-byte instructions DMB, MSR, and MRS to avoid a situation where the second pair of bytes is interpreted as a different instruction that might affect the execution of the code. So we did.
Finally, we tried running hello_usart, and ran into panic(). We started looking into it, and you can watch the complete debugging session in the live stream recording:
The next episode will be streamed today, you can watch it here. See you then!
-
Sneaky Bugs
03/05/2021 at 19:04 • 0 commentsThis time, we deciphered the internals of the bootrom, while hunting for two subtle bugs that made our emulator go crazy. We thickened our virtual RP2040 with a bunch of new instructions: MOV, SBCS, ANDS, ADDS, SUBS, ORRS and ADD/SUB with the stack pointer (SP).
You can watch the complete stream here:
I personally find the bug-hunting process most interesting. The first part starts at 1:15:44, where you see how I close down on the bug until it has no choice but to reveal itself, while teaching me a painful lesson about writing good test cases.
The second hunt starts at 2:18:30, where we try to figure out why BL jumps to the wrong memory address.
So it feels like we made a good progress, but we're not quite there yet. There are a few more missing instructions, and then... 🤞
You can join the next live stream on Tuesday to figure it out together. And if you are forgetful like me, why not add it to your calendar?
-
Building MicroPython for the Raspberry Pi Pico
03/02/2021 at 12:29 • 0 commentsI woke up this morning, and saw this message in the YouTube chat for the live stream today. Thank you Andreas!
I'm not sure if we'll actually get to try MicroPython today. The chances are slim, but I'm optimist, so better be prepared.
Here is how I compiled MicroPython for the RP2040:
git clone https://github.com/micropython/micropython cd micropython git submodule update --init lib/pico-sdk lib/tinyusb make -C mpy-cross cd ports/rp2 make
The compiled files can be found inside
ports/rp2/build
, and you'll also find there a disassembly of the firmware (similar to the ones we looked at in the previous live streams). Enjoy! -
Got past boot_stage2!
02/26/2021 at 21:22 • 0 commentsThis week's session was very fruitful: after fiddling with some of the XIP Flash registers, we eventually got boot_stage2 to execute and jump to the application's code. We also implemented a bunch of new instructions: BX (thanks to pyTony who sent us a PR), POP, STMIA, ADR, BLX, BICS and LDRH:
Overall, it feels like we are pretty close to hitting our goal of running a program from start to end. In the next live stream we'll implement the missing instructions: MOV, SBCS, ANDS, and then... who knows? join to see!
If you wish, you can also add the stream to your calendar ;-)
-
Exploring the Bootrom
02/22/2021 at 20:31 • 0 commentsLast week, we spent some time exploring the Pi Pico's bootrom and stage-2 bootloader. We explored
__vector_entry
, found some nice ASCII art buried deep in the Pico's SDK, and also implemented BL, LSRS and LDMIA:The next live-stream will take place tomorrow, 7pm GMT (11am PST, 2pm EST, 8pm CET).
If you wish, add it to your Google calendar.
-
UART working!!1
02/14/2021 at 23:07 • 0 commentsThis week's coding session ended with a glorious victory: UART works! 🎉
You can watch the exciting moment at 1:43:15.
Or, you can watch all the work that led into it: implementing ADDS, SUBS, NEGS, LDRB, ADCS, and UXTB.
We also spent some time tidying-up the code, came up with our own mini-assembler for the unit-tests, implemented memory write hooks and and split the code into smaller modules (e.g. UART).
To conclude the party, we started looking at the Raspberry Pi Pico's bootrom which I'll try to run inside the emulator in the next episode. 🤞
Episode replay:
-
Thank You
02/08/2021 at 21:54 • 0 commentsThanks to your support, our emulator made it to the week's most liked projects on Hackaday!
Thanks ;-)
p.s. I will be streaming the next episode tomorrow, the usual time. Watch here: https://youtu.be/GtM800DFPNo
-
Taming UART, Flags, and 7 new instructions!
02/07/2021 at 23:45 • 0 commentsIn the second episode of the RP2040 Emulator coding live-stream we had an ambitious goal: implement UART so we can see debug prints from the simulated program.
We loaded the hello_uart example program, looked at the disassembly, and started implementing the instructions in a TDD (test-driven development) manner, similar to the first live-stream:
- LDR (Load Register) - both literal and immediate variants
- TST, which also means we had to implement the APSR (flags) register
- BNE.N - in fact, we took care of all the conditional branches!
- LDRSH
- CMP - just as with LDR, we did both literal and immediate variants
We also took care of implementing CPU Read Hooks, which allow peripherals to intercept memory reads from their mapped regions. This allowed us to mimic the behavior of the UARTFR, indicating to the simulated code that the UART hardware is ready to receive the next character.
You can watch the complete episode here:
And check out the project's code on GitHub: https://github.com/wokwi/rp2040js
If you don't want to miss out the next episode, make sure to sign up and get a reminder when it goes live!