Skip to content

Commit 958ded1

Browse files
committed
Corrected last commit. The new function was merge (bitwise OR) with the former instead replacing it.
1 parent 2daee75 commit 958ded1

File tree

4 files changed

+70
-54
lines changed

4 files changed

+70
-54
lines changed

kernel.img

16 Bytes
Binary file not shown.

kernel.list

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ build/output.elf: file format elf32-littlearm
44
Disassembly of section .init:
55

66
00008000 <_start>:
7-
8000: ea00001f b 8084 <main>
7+
8000: ea000023 b 8094 <main>
88
Disassembly of section .text:
99

1010
00008004 <GetGpioAddress>:
11-
8004: e59f0074 ldr r0, [pc, #116] ; 8080 <SetGpio+0x3c>
11+
8004: e59f0084 ldr r0, [pc, #132] ; 8090 <SetGpio+0x3c>
1212
8008: e1a0f00e mov pc, lr
1313

1414
0000800c <SetGpioFunction>:
1515
800c: e3500035 cmp r0, #53 ; 0x35
1616
8010: 93500007 cmpls r0, #7 ; 0x7
1717
8014: 81a0f00e movhi pc, lr
18-
8018: e59f2060 ldr r2, [pc, #96] ; 8080 <SetGpio+0x3c>
18+
8018: e59f2070 ldr r2, [pc, #112] ; 8090 <SetGpio+0x3c>
1919

2020
0000801c <funcCalcLoop$>:
2121
801c: e3500009 cmp r0, #9 ; 0x9
@@ -24,52 +24,56 @@ Disassembly of section .text:
2424
8028: 8afffffb bhi 801c <funcCalcLoop$>
2525
802c: e0800080 add r0, r0, r0, lsl #1
2626
8030: e1a01011 lsl r1, r1, r0
27-
8034: e5920000 ldr r0, [r2]
28-
8038: e1811000 orr r1, r1, r0
29-
803c: e5821000 str r1, [r2]
30-
8040: e1a0f00e mov pc, lr
27+
8034: e3a03007 mov r3, #7 ; 0x7
28+
8038: e1a03013 lsl r3, r3, r0
29+
803c: e1e03003 mvn r3, r3
30+
8040: e5920000 ldr r0, [r2]
31+
8044: e0000003 and r0, r0, r3
32+
8048: e1811000 orr r1, r1, r0
33+
804c: e5821000 str r1, [r2]
34+
8050: e1a0f00e mov pc, lr
3135

32-
00008044 <SetGpio>:
33-
8044: e3500035 cmp r0, #53 ; 0x35
34-
8048: 81a0f00e movhi pc, lr
35-
804c: e92d4000 push {lr}
36-
8050: e1a02000 mov r2, r0
37-
8054: ebffffea bl 8004 <GetGpioAddress>
38-
8058: e1a032a2 lsr r3, r2, #5
39-
805c: e1a03103 lsl r3, r3, #2
40-
8060: e0800003 add r0, r0, r3
41-
8064: e202201f and r2, r2, #31 ; 0x1f
42-
8068: e3a03001 mov r3, #1 ; 0x1
43-
806c: e1a03213 lsl r3, r3, r2
44-
8070: e3310000 teq r1, #0 ; 0x0
45-
8074: 05803028 streq r3, [r0, #40]
46-
8078: 1580301c strne r3, [r0, #28]
47-
807c: e8bd8000 pop {pc}
48-
8080: 20200000 .word 0x20200000
36+
00008054 <SetGpio>:
37+
8054: e3500035 cmp r0, #53 ; 0x35
38+
8058: 81a0f00e movhi pc, lr
39+
805c: e92d4000 push {lr}
40+
8060: e1a02000 mov r2, r0
41+
8064: ebffffe6 bl 8004 <GetGpioAddress>
42+
8068: e1a032a2 lsr r3, r2, #5
43+
806c: e1a03103 lsl r3, r3, #2
44+
8070: e0800003 add r0, r0, r3
45+
8074: e202201f and r2, r2, #31 ; 0x1f
46+
8078: e3a03001 mov r3, #1 ; 0x1
47+
807c: e1a03213 lsl r3, r3, r2
48+
8080: e3310000 teq r1, #0 ; 0x0
49+
8084: 05803028 streq r3, [r0, #40]
50+
8088: 1580301c strne r3, [r0, #28]
51+
808c: e8bd8000 pop {pc}
52+
8090: 20200000 .word 0x20200000
4953

50-
00008084 <main>:
51-
8084: e3a0d902 mov sp, #32768 ; 0x8000
52-
8088: e3a00010 mov r0, #16 ; 0x10
53-
808c: e3a01001 mov r1, #1 ; 0x1
54-
8090: ebffffdd bl 800c <SetGpioFunction>
54+
00008094 <main>:
55+
8094: e3a0d902 mov sp, #32768 ; 0x8000
56+
8098: e3a00010 mov r0, #16 ; 0x10
57+
809c: e3a01001 mov r1, #1 ; 0x1
58+
80a0: ebffffd9 bl 800c <SetGpioFunction>
5559

56-
00008094 <mainloop$>:
57-
8094: e3a00010 mov r0, #16 ; 0x10
58-
8098: e3a01000 mov r1, #0 ; 0x0
59-
809c: ebffffe8 bl 8044 <SetGpio>
60-
80a0: e3a0283f mov r2, #4128768 ; 0x3f0000
60+
000080a4 <mainloop$>:
61+
80a4: e3a00010 mov r0, #16 ; 0x10
62+
80a8: e3a01000 mov r1, #0 ; 0x0
63+
80ac: ebffffe8 bl 8054 <SetGpio>
64+
80b0: e3a0283f mov r2, #4128768 ; 0x3f0000
6165

62-
000080a4 <wait1$>:
63-
80a4: e2422001 sub r2, r2, #1 ; 0x1
64-
80a8: e3520000 cmp r2, #0 ; 0x0
65-
80ac: 1afffffc bne 80a4 <wait1$>
66-
80b0: e3a00010 mov r0, #16 ; 0x10
67-
80b4: e3a01001 mov r1, #1 ; 0x1
68-
80b8: ebffffe1 bl 8044 <SetGpio>
69-
80bc: e3a0283f mov r2, #4128768 ; 0x3f0000
66+
000080b4 <wait1$>:
67+
80b4: e2422001 sub r2, r2, #1 ; 0x1
68+
80b8: e3520000 cmp r2, #0 ; 0x0
69+
80bc: 1afffffc bne 80b4 <wait1$>
70+
80c0: e3a00010 mov r0, #16 ; 0x10
71+
80c4: e3a01001 mov r1, #1 ; 0x1
72+
80c8: ebffffe1 bl 8054 <SetGpio>
73+
80cc: e3a0283f mov r2, #4128768 ; 0x3f0000
7074

71-
000080c0 <wait2$>:
72-
80c0: e2422001 sub r2, r2, #1 ; 0x1
73-
80c4: e3520000 cmp r2, #0 ; 0x0
74-
80c8: 1afffffc bne 80c0 <wait2$>
75-
80cc: eafffff0 b 8094 <mainloop$>
75+
000080d0 <wait2$>:
76+
80d0: e2422001 sub r2, r2, #1 ; 0x1
77+
80d4: e3520000 cmp r2, #0 ; 0x0
78+
80d8: 1afffffc bne 80d0 <wait2$>
79+
80dc: eafffff0 b 80a4 <mainloop$>

kernel.map

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ LOAD build/main.o
3737
.init 0x00008000 0x4 build/main.o
3838
0x00008000 _start
3939

40-
.text 0x00008004 0xcc
40+
.text 0x00008004 0xdc
4141
*(.text)
42-
.text 0x00008004 0x80 build/gpio.o
42+
.text 0x00008004 0x90 build/gpio.o
4343
0x0000800c SetGpioFunction
4444
0x00008004 GetGpioAddress
45-
0x00008044 SetGpio
46-
.text 0x00008084 0x4c build/main.o
45+
0x00008054 SetGpio
46+
.text 0x00008094 0x4c build/main.o
4747

4848
/DISCARD/
4949
*(*)

src/gpio.s

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ GetGpioAddress:
2424

2525
@
2626
@ Apply a GPIO function to a pin.
27-
@ ~> r0: The previous content of the block
27+
@ ~> r0: The offset of the 3 bits of the function pin in the block
2828
@ ~> r1: The pin function at the right offset in the block (content of the block)
2929
@ ~> r2: The address of the block containing the given pin function.
30-
@ == r3
30+
@ ~> r3: The previous content of the block
3131
SetGpioFunction:
3232
pinNum .req r0 @ <- GPIO pin [0, GPIO_NB_PINS[
3333
pinFunc .req r1 @ <- Function [0, GPIO_NB_FUNCS[
@@ -53,11 +53,23 @@ SetGpioFunction:
5353
.unreq pinNum
5454
pinOffset .req r0
5555

56-
@ Set the pin function
56+
@ Set the pin function at the right offset
5757
lsl pinFunc, pinOffset
58+
59+
@ Create a mask to keep other pins unchanged
60+
blockMask .req r3
61+
mov blockMask, #[GPIO_NB_FUNCS-1]
62+
lsl blockMask, pinOffset
5863
.unreq pinOffset
64+
mvn blockMask, blockMask
65+
66+
@ Load the current value of the block and reset the function of the wanted pin
5967
blockValue .req r0
6068
ldr blockValue, [funcPinAddr]
69+
and blockValue, blockMask
70+
.unreq blockMask
71+
72+
@ Merge new pin function
6173
orr pinFunc, blockValue
6274
.unreq blockValue
6375
str pinFunc, [funcPinAddr]

0 commit comments

Comments
 (0)