-
Notifications
You must be signed in to change notification settings - Fork 0
/
framebuffer.s
100 lines (77 loc) · 2.28 KB
/
framebuffer.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
.section .text
// frame buffer methods taken from tutorial
.globl InitFrameBuffer
/* Initialize the FrameBuffer using the FrameBufferInit structure
* Returns:
* r0 - 0 on failure, framebuffer pointer on success
*/
InitFrameBuffer:
// load the address of the mailbox interface
mbox .req r2
ldr mbox, =0x2000B880
// load the address of the framebuffer init structure
fbinit .req r3
ldr fbinit, =FrameBufferInit
mBoxFullLoop$:
// load the value of the mailbox status register
ldr r0, [mbox, #0x18]
// loop while bit 31 (Full) is set
tst r0, #0x80000000
bne mBoxFullLoop$
// add 0x40000000 to address of framebuffer init struct, store in r0
add r0, fbinit, #0x40000000
// or with the framebuffer channel (1)
orr r0, #0b0001
// write this value to the mailbox write register
str r0, [mbox, #0x20]
mBoxEmptyLoop$:
// load the value of the mailbox status register
ldr r0, [mbox, #0x18]
// loop while bit 30 (Empty) is set
tst r0, #0x40000000
bne mBoxEmptyLoop$
// read the response from the mailbox read register
ldr r0, [mbox, #0x00]
// and-mask out the channel information (lowest 4 bits)
and r1, r0, #0xF
// test if this message is for the framebuffer channel (1)
teq r1, #0b0001
// if not, we need to read another message from the mailbox
bne mBoxEmptyLoop$
// isolate the high 28 bits of the message
bic r1, r0, #0xF
// test if the high 28 bits of the message are 0 (ie: success)
teq r1, #0
// return 0 if high 28 bits of message are not 0
movne r0, #0
// return
bxne lr
pointerWaitLoop$:
// load the value of the pointer from the framebuffer init struct
ldr r0, [fbinit, #0x20]
// loop while the pointer is 0
teq r0, #0
beq pointerWaitLoop$
.unreq mbox
.unreq fbinit
ldr r3, =FrameBufferPointer
str r0, [r3]
// return the pointer value to indicate success
bx lr
.section .data
.align 4
FrameBufferInit:
.int 1024 // X Resolution (width)
.int 768 // Y Resolution (height)
.int 1024 // Virtual Width
.int 768 // Virtual Height
.int 0 // Pitch (Set by GPU)
.int 16 // Depth (bits per pixel)
.int 0 // Virtual X Offset
.int 0 // Virtual Y Offset
.int 0 // Pointer to FrameBuffer (Set by GPU)
.int 0 // Size of FrameBuffer (Set by GPU)
.align 4
.globl FrameBufferPointer
FrameBufferPointer:
.int 0