Error Handling: Unterschied zwischen den Versionen

Aus C und Assembler mit Raspberry
Die Seite wurde neu angelegt: „Since we currently have no means to send information to ourselves consciously, we will use the LED to indicate when something goes wrong. To achieve this, we will create a function that can display an error code using the LED. We will extend our '''led.s''' code with this function: <syntaxhighlight lang="asm"> .globl LED_Error // In w0 = Error code LED_Error: mov w10, w0 // Save w0 as the function "wait" uses w0 as a timer 1: mov w11,…“
 
KKeine Bearbeitungszusammenfassung
Zeile 47: Zeile 47:


As long as we have no other means to detect an error, we will use this function.
As long as we have no other means to detect an error, we will use this function.
You can download the source code as a ZIP file from the following link: https://www.satyria.de/arm/sources/assem/error.zip

Version vom 19. August 2024, 20:21 Uhr

Since we currently have no means to send information to ourselves consciously, we will use the LED to indicate when something goes wrong. To achieve this, we will create a function that can display an error code using the LED.

We will extend our led.s code with this function:

.globl LED_Error      // In w0 = Error code
LED_Error:
    mov w10, w0       // Save w0 as the function "wait" uses w0 as a timer
1:
    mov w11, #0       // Set counter to NULL
2:
    cmp w11, w10      // Compare the values with the error code
    bhs 3f            // If greater, exit the inner loop

    bl LED_on         // Turn the LED on
    mov w0, 0x100000  // Wait for 0x100000 cycles
    bl wait

    bl LED_off        // Turn the LED off
    mov w0, 0x100000  // Wait again for 0x100000 cycles
    bl wait

    add w11, w11, 1   // Increment w11 by 1
    b 2b              // Repeat the loop
3:
    mov w0, 0x100000 // Wait an additional 0x100000 cycles to separate the code
    bl wait

    b 1b              // Repeat the code until we shut everything down

To test this function, we will modify our kernel.S code:

//
// kernel.S
//

.section .text
.globl main
main:
    bl LED_off

    mov w0, #2
    bl LED_Error
    b main

First, we turn off the LED. In register w0, our parameter register, we write the error code #2 and then jump to our LED_Error function. This function will now make the LED blink twice in quick succession, pause briefly, and repeat the process.

As long as we have no other means to detect an error, we will use this function.

You can download the source code as a ZIP file from the following link: https://www.satyria.de/arm/sources/assem/error.zip