├── CNAME ├── .github └── FUNDING.yml ├── part2-building ├── kernel.c ├── link.ld ├── Makefile ├── Makefile.gcc └── boot.S ├── part1-bootstrapping ├── kernel.c ├── link.ld └── boot.S ├── google69636ed483fc239e.html ├── part3-helloworld ├── io.h ├── images │ ├── 3-helloworld-cable.jpg │ ├── 3-helloworld-pinloc.png │ └── 3-helloworld-ctlpanel.png ├── kernel.c ├── link.ld ├── Makefile ├── Makefile.gcc └── boot.S ├── part12-wgt ├── bin │ ├── wgt1.blk │ ├── wgt2.blk │ ├── break.spr │ ├── mouse.spr │ ├── space.spr │ ├── BCM4345C0.hcd │ ├── invader.spr │ ├── letters.spr │ └── wgt1.pal ├── include │ ├── mem.h │ ├── multicore.h │ ├── bt.h │ ├── io.h │ └── mb.h ├── controller-ios │ ├── rpi4-osdev-ioscontrol │ │ ├── Assets.xcassets │ │ │ ├── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── Info.plist │ │ └── AppDelegate.swift │ └── rpi4-osdev-ioscontrol.xcodeproj │ │ ├── xcuserdata │ │ ├── Akshata.xcuserdatad │ │ │ ├── xcdebugger │ │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── xcschemes │ │ │ │ └── xcschememanagement.plist │ │ └── agb.xcuserdatad │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── project.xcworkspace │ │ ├── xcuserdata │ │ ├── agb.xcuserdatad │ │ │ ├── UserInterfaceState.xcuserstate │ │ │ └── WorkspaceSettings.xcsettings │ │ └── Akshata.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ ├── WorkspaceSettings.xcsettings │ │ └── IDEWorkspaceChecks.plist ├── samples │ ├── wgt01.c │ ├── wgt45.c │ ├── wgt46.c │ ├── wgt21.c │ ├── wgt10.c │ ├── wgt08.c │ ├── wgt09.c │ ├── wgt07.c │ ├── wgt15.c │ ├── wgt41.c │ ├── wgt16.c │ ├── wgt27.c │ ├── wgt02.c │ ├── wgt33.c │ ├── wgt39.c │ ├── wgt11.c │ └── wgt36.c ├── wgt │ ├── wpixel.c │ ├── wmiscb.c │ ├── wclip.c │ ├── wbutt.c │ ├── winitply.c │ ├── wdissolve.c │ ├── wblock.c │ ├── wsetcol.c │ ├── wvertres.c │ ├── wbox.c │ ├── wxor.c │ ├── wwipe.c │ ├── wticker.c │ ├── wbezier.c │ ├── wflipb.c │ ├── wsetmode.c │ ├── wwarp.c │ └── wskew.c ├── boot │ ├── link.ld │ └── sysregs.h ├── lib │ ├── multicore.c │ └── mem.c ├── controller-node │ ├── characteristic.js │ └── main.js └── Makefile ├── part9-sound ├── audio.bin ├── audio.wav ├── link.ld ├── io.h ├── fb.h ├── Makefile ├── Makefile.gcc ├── mb.h ├── boot.S └── mb.c ├── part10-multicore ├── audio.bin ├── audio.wav ├── images │ └── 10-multicore-running.jpg ├── multicore.h ├── io.h ├── fb.h ├── Makefile ├── Makefile.gcc ├── mb.h ├── link.ld ├── multicore.c ├── mb.c └── boot.S ├── part7-bluetooth ├── BCM4345C0.hcd ├── images │ └── 7-eddystone-beacon.png ├── bt.h ├── io.h ├── link.ld ├── fb.h ├── Makefile ├── Makefile.gcc ├── mb.h ├── boot.S └── mb.c ├── part11-breakout-smp ├── bin │ ├── audio.bin │ └── BCM4345C0.hcd ├── include │ ├── multicore.h │ ├── bt.h │ ├── io.h │ ├── fb.h │ ├── mb.h │ └── audio.h ├── breakout_snd.c ├── boot │ ├── link.ld │ └── boot.S ├── lib │ ├── multicore.c │ └── mb.c ├── Makefile ├── breakout.h └── README.md ├── part8-breakout-ble ├── BCM4345C0.hcd ├── images │ └── 8-opcode-1b.png ├── bt.h ├── io.h ├── link.ld ├── fb.h ├── Makefile ├── Makefile.gcc.windows ├── Makefile.gcc ├── mb.h ├── boot.S ├── controller │ ├── main.js │ └── characteristic.js └── mb.c ├── part14-spi-ethernet ├── net │ ├── enc28j60.c │ ├── enc28j60.h │ └── encspi.c ├── images │ ├── 14-spi-ethernet-arp.jpg │ └── 14-spi-ethernet-photo.jpg ├── include │ ├── spi.h │ ├── multicore.h │ ├── fb.h │ ├── io.h │ └── mb.h ├── kernel │ ├── utils.S │ ├── irq.c │ └── kernel.h ├── Makefile ├── Makefile.gcc ├── boot │ ├── link.ld │ └── sysregs.h └── lib │ ├── multicore.c │ └── mb.c ├── part15-tcpip-webserver ├── net │ ├── enc28j60.c │ ├── enc28j60.h │ └── encspi.c ├── kernel │ └── kernel.h ├── images │ ├── 15-tcpip-webserver-browser.png │ └── 15-tcpip-webserver-pinging.jpg ├── include │ ├── spi.h │ ├── multicore.h │ ├── fb.h │ ├── mb.h │ └── io.h ├── Makefile ├── Makefile.gcc ├── boot │ ├── link.ld │ └── sysregs.h ├── lib │ ├── multicore.c │ └── mb.c └── tcpip │ └── ip_config.h ├── part6-breakout ├── images │ ├── 6-breakout-wozniak.jpg │ └── 6-breakout-thefinishedgame.jpg ├── io.h ├── fb.h ├── link.ld ├── Makefile ├── Makefile.gcc ├── mb.h ├── boot.S └── mb.c ├── part13-interrupts ├── images │ └── 13-interrupts-running.jpg ├── kernel │ ├── utils.S │ ├── irq.c │ └── kernel.h ├── include │ ├── multicore.h │ ├── io.h │ ├── fb.h │ └── mb.h ├── Makefile ├── Makefile.gcc ├── boot │ ├── link.ld │ └── sysregs.h └── lib │ ├── multicore.c │ └── mb.c ├── part5-framebuffer ├── images │ └── 5-framebuffer-screen.jpg ├── io.h ├── fb.h ├── kernel.c ├── link.ld ├── Makefile ├── Makefile.gcc ├── mb.h ├── boot.S └── mb.c ├── _config.yml └── part4-miniuart ├── kernel.c ├── io.h ├── link.ld ├── Makefile ├── Makefile.gcc └── boot.S /CNAME: -------------------------------------------------------------------------------- 1 | www.rpi4os.com -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: isometimes 2 | -------------------------------------------------------------------------------- /part2-building/kernel.c: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | while (1); 4 | } 5 | -------------------------------------------------------------------------------- /part1-bootstrapping/kernel.c: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | while (1); 4 | } 5 | -------------------------------------------------------------------------------- /google69636ed483fc239e.html: -------------------------------------------------------------------------------- 1 | google-site-verification: google69636ed483fc239e.html -------------------------------------------------------------------------------- /part3-helloworld/io.h: -------------------------------------------------------------------------------- 1 | void uart_init(); 2 | void uart_writeText(char *buffer); 3 | -------------------------------------------------------------------------------- /part12-wgt/bin/wgt1.blk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part12-wgt/bin/wgt1.blk -------------------------------------------------------------------------------- /part12-wgt/bin/wgt2.blk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part12-wgt/bin/wgt2.blk -------------------------------------------------------------------------------- /part9-sound/audio.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part9-sound/audio.bin -------------------------------------------------------------------------------- /part9-sound/audio.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part9-sound/audio.wav -------------------------------------------------------------------------------- /part12-wgt/bin/break.spr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part12-wgt/bin/break.spr -------------------------------------------------------------------------------- /part12-wgt/bin/mouse.spr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part12-wgt/bin/mouse.spr -------------------------------------------------------------------------------- /part12-wgt/bin/space.spr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part12-wgt/bin/space.spr -------------------------------------------------------------------------------- /part12-wgt/include/mem.h: -------------------------------------------------------------------------------- 1 | void mem_init(); 2 | void *malloc(unsigned int size); 3 | void free(void *ptr); 4 | -------------------------------------------------------------------------------- /part10-multicore/audio.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part10-multicore/audio.bin -------------------------------------------------------------------------------- /part10-multicore/audio.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part10-multicore/audio.wav -------------------------------------------------------------------------------- /part12-wgt/bin/BCM4345C0.hcd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part12-wgt/bin/BCM4345C0.hcd -------------------------------------------------------------------------------- /part12-wgt/bin/invader.spr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part12-wgt/bin/invader.spr -------------------------------------------------------------------------------- /part12-wgt/bin/letters.spr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part12-wgt/bin/letters.spr -------------------------------------------------------------------------------- /part7-bluetooth/BCM4345C0.hcd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part7-bluetooth/BCM4345C0.hcd -------------------------------------------------------------------------------- /part11-breakout-smp/bin/audio.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part11-breakout-smp/bin/audio.bin -------------------------------------------------------------------------------- /part8-breakout-ble/BCM4345C0.hcd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part8-breakout-ble/BCM4345C0.hcd -------------------------------------------------------------------------------- /part14-spi-ethernet/net/enc28j60.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part14-spi-ethernet/net/enc28j60.c -------------------------------------------------------------------------------- /part14-spi-ethernet/net/enc28j60.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part14-spi-ethernet/net/enc28j60.h -------------------------------------------------------------------------------- /part11-breakout-smp/bin/BCM4345C0.hcd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part11-breakout-smp/bin/BCM4345C0.hcd -------------------------------------------------------------------------------- /part15-tcpip-webserver/net/enc28j60.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part15-tcpip-webserver/net/enc28j60.c -------------------------------------------------------------------------------- /part15-tcpip-webserver/net/enc28j60.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part15-tcpip-webserver/net/enc28j60.h -------------------------------------------------------------------------------- /part8-breakout-ble/images/8-opcode-1b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part8-breakout-ble/images/8-opcode-1b.png -------------------------------------------------------------------------------- /part6-breakout/images/6-breakout-wozniak.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part6-breakout/images/6-breakout-wozniak.jpg -------------------------------------------------------------------------------- /part7-bluetooth/images/7-eddystone-beacon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part7-bluetooth/images/7-eddystone-beacon.png -------------------------------------------------------------------------------- /part10-multicore/images/10-multicore-running.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part10-multicore/images/10-multicore-running.jpg -------------------------------------------------------------------------------- /part3-helloworld/images/3-helloworld-cable.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part3-helloworld/images/3-helloworld-cable.jpg -------------------------------------------------------------------------------- /part3-helloworld/images/3-helloworld-pinloc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part3-helloworld/images/3-helloworld-pinloc.png -------------------------------------------------------------------------------- /part13-interrupts/images/13-interrupts-running.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part13-interrupts/images/13-interrupts-running.jpg -------------------------------------------------------------------------------- /part14-spi-ethernet/images/14-spi-ethernet-arp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part14-spi-ethernet/images/14-spi-ethernet-arp.jpg -------------------------------------------------------------------------------- /part3-helloworld/images/3-helloworld-ctlpanel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part3-helloworld/images/3-helloworld-ctlpanel.png -------------------------------------------------------------------------------- /part5-framebuffer/images/5-framebuffer-screen.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part5-framebuffer/images/5-framebuffer-screen.jpg -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /part14-spi-ethernet/images/14-spi-ethernet-photo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part14-spi-ethernet/images/14-spi-ethernet-photo.jpg -------------------------------------------------------------------------------- /part3-helloworld/kernel.c: -------------------------------------------------------------------------------- 1 | #include "io.h" 2 | 3 | void main() 4 | { 5 | uart_init(); 6 | uart_writeText("Hello world!\n"); 7 | while (1); 8 | } 9 | -------------------------------------------------------------------------------- /part6-breakout/images/6-breakout-thefinishedgame.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part6-breakout/images/6-breakout-thefinishedgame.jpg -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | remote_theme: isometimes/cayman-ga4 2 | google_analytics: G-YL02TRV3C8 3 | url: "https://www.rpi4os.com" 4 | plugins: 5 | - jekyll-sitemap 6 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/kernel/kernel.h: -------------------------------------------------------------------------------- 1 | void enc28j60PacketSend(unsigned short buflen, void *buffer); 2 | void *memcpy(void *dest, const void *src, unsigned short len); 3 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/images/15-tcpip-webserver-browser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part15-tcpip-webserver/images/15-tcpip-webserver-browser.png -------------------------------------------------------------------------------- /part15-tcpip-webserver/images/15-tcpip-webserver-pinging.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part15-tcpip-webserver/images/15-tcpip-webserver-pinging.jpg -------------------------------------------------------------------------------- /part4-miniuart/kernel.c: -------------------------------------------------------------------------------- 1 | #include "io.h" 2 | 3 | void main() 4 | { 5 | uart_init(); 6 | uart_writeText("Hello world!\n"); 7 | 8 | while (1) uart_update(); 9 | } 10 | -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol.xcodeproj/xcuserdata/Akshata.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /part4-miniuart/io.h: -------------------------------------------------------------------------------- 1 | void uart_init(); 2 | void uart_writeText(char *buffer); 3 | void uart_loadOutputFifo(); 4 | unsigned char uart_readByte(); 5 | unsigned int uart_isReadByteReady(); 6 | void uart_writeByteBlocking(unsigned char ch); 7 | void uart_update(); 8 | -------------------------------------------------------------------------------- /part14-spi-ethernet/include/spi.h: -------------------------------------------------------------------------------- 1 | void spi_init(); 2 | void spi_send_recv(unsigned char *sbuffer, unsigned char *rbuffer, unsigned int size); 3 | void spi_send(unsigned char *data, unsigned int size); 4 | void spi_recv(unsigned char *data, unsigned int size); 5 | void spi_chip_select(unsigned char chip_select); 6 | -------------------------------------------------------------------------------- /part13-interrupts/kernel/utils.S: -------------------------------------------------------------------------------- 1 | .globl irq_init_vectors 2 | irq_init_vectors: 3 | adr x0, vectors 4 | msr vbar_el1, x0 5 | ret 6 | 7 | .globl irq_enable 8 | irq_enable: 9 | msr daifclr, #2 10 | ret 11 | 12 | .globl irq_disable 13 | irq_disable: 14 | msr daifset, #2 15 | ret 16 | -------------------------------------------------------------------------------- /part14-spi-ethernet/kernel/utils.S: -------------------------------------------------------------------------------- 1 | .globl irq_init_vectors 2 | irq_init_vectors: 3 | adr x0, vectors 4 | msr vbar_el1, x0 5 | ret 6 | 7 | .globl irq_enable 8 | irq_enable: 9 | msr daifclr, #2 10 | ret 11 | 12 | .globl irq_disable 13 | irq_disable: 14 | msr daifset, #2 15 | ret 16 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/include/spi.h: -------------------------------------------------------------------------------- 1 | void spi_init(); 2 | void spi_send_recv(unsigned char *sbuffer, unsigned char *rbuffer, unsigned int size); 3 | void spi_send(unsigned char *data, unsigned int size); 4 | void spi_recv(unsigned char *data, unsigned int size); 5 | void spi_chip_select(unsigned char chip_select); 6 | -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol.xcodeproj/project.xcworkspace/xcuserdata/agb.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part12-wgt/controller-ios/rpi4-osdev-ioscontrol.xcodeproj/project.xcworkspace/xcuserdata/agb.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol.xcodeproj/project.xcworkspace/xcuserdata/Akshata.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patterns/rpi4-osdev/master/part12-wgt/controller-ios/rpi4-osdev-ioscontrol.xcodeproj/project.xcworkspace/xcuserdata/Akshata.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt01.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | 3 | // ######## WGT EXAMPLES ######## 4 | 5 | void wgt01() 6 | { 7 | vga256 (); /* Initializes WGT system */ 8 | wsetcolor (vgapal[15]); 9 | wline (0, 0, 319, 199); /* Draw a line */ 10 | } 11 | 12 | void main() 13 | { 14 | wgt01(); 15 | while (1); 16 | } 17 | -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /part10-multicore/multicore.h: -------------------------------------------------------------------------------- 1 | extern unsigned int spin_cpu0; 2 | extern unsigned int spin_cpu1; 3 | extern unsigned int spin_cpu2; 4 | extern unsigned int spin_cpu3; 5 | 6 | void start_core1(void (*func)(void)); 7 | void start_core2(void (*func)(void)); 8 | void start_core3(void (*func)(void)); 9 | void clear_core1(void); 10 | void clear_core2(void); 11 | void clear_core3(void); 12 | -------------------------------------------------------------------------------- /part12-wgt/include/multicore.h: -------------------------------------------------------------------------------- 1 | extern unsigned int spin_cpu0; 2 | extern unsigned int spin_cpu1; 3 | extern unsigned int spin_cpu2; 4 | extern unsigned int spin_cpu3; 5 | 6 | void start_core1(void (*func)(void)); 7 | void start_core2(void (*func)(void)); 8 | void start_core3(void (*func)(void)); 9 | void clear_core1(void); 10 | void clear_core2(void); 11 | void clear_core3(void); 12 | -------------------------------------------------------------------------------- /part11-breakout-smp/include/multicore.h: -------------------------------------------------------------------------------- 1 | extern unsigned int spin_cpu0; 2 | extern unsigned int spin_cpu1; 3 | extern unsigned int spin_cpu2; 4 | extern unsigned int spin_cpu3; 5 | 6 | void start_core1(void (*func)(void)); 7 | void start_core2(void (*func)(void)); 8 | void start_core3(void (*func)(void)); 9 | void clear_core1(void); 10 | void clear_core2(void); 11 | void clear_core3(void); 12 | -------------------------------------------------------------------------------- /part13-interrupts/include/multicore.h: -------------------------------------------------------------------------------- 1 | extern unsigned int spin_cpu0; 2 | extern unsigned int spin_cpu1; 3 | extern unsigned int spin_cpu2; 4 | extern unsigned int spin_cpu3; 5 | 6 | void start_core1(void (*func)(void)); 7 | void start_core2(void (*func)(void)); 8 | void start_core3(void (*func)(void)); 9 | void clear_core1(void); 10 | void clear_core2(void); 11 | void clear_core3(void); 12 | -------------------------------------------------------------------------------- /part14-spi-ethernet/include/multicore.h: -------------------------------------------------------------------------------- 1 | extern unsigned int spin_cpu0; 2 | extern unsigned int spin_cpu1; 3 | extern unsigned int spin_cpu2; 4 | extern unsigned int spin_cpu3; 5 | 6 | void start_core1(void (*func)(void)); 7 | void start_core2(void (*func)(void)); 8 | void start_core3(void (*func)(void)); 9 | void clear_core1(void); 10 | void clear_core2(void); 11 | void clear_core3(void); 12 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/include/multicore.h: -------------------------------------------------------------------------------- 1 | extern unsigned int spin_cpu0; 2 | extern unsigned int spin_cpu1; 3 | extern unsigned int spin_cpu2; 4 | extern unsigned int spin_cpu3; 5 | 6 | void start_core1(void (*func)(void)); 7 | void start_core2(void (*func)(void)); 8 | void start_core3(void (*func)(void)); 9 | void clear_core1(void); 10 | void clear_core2(void); 11 | void clear_core3(void); 12 | -------------------------------------------------------------------------------- /part5-framebuffer/io.h: -------------------------------------------------------------------------------- 1 | #define PERIPHERAL_BASE 0xFE000000 2 | 3 | void uart_init(); 4 | void uart_writeText(char *buffer); 5 | void uart_loadOutputFifo(); 6 | unsigned char uart_readByte(); 7 | unsigned int uart_isReadByteReady(); 8 | void uart_writeByteBlocking(unsigned char ch); 9 | void uart_update(); 10 | void mmio_write(long reg, unsigned int val); 11 | unsigned int mmio_read(long reg); 12 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wpixel.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | 3 | unsigned int wgetpixel (short x, short y) 4 | { 5 | return abuf[y * WGT_SYS.xres + x]; 6 | } 7 | 8 | void wputpixel (short x, short y) 9 | { 10 | if ((y <= by) & (x <= bx) & (y >= ty) & (x >= tx)) 11 | abuf[y * WGT_SYS.xres + x] = currentcolor; 12 | } 13 | 14 | void wfastputpixel (short x, short y) 15 | { 16 | abuf[y * WGT_SYS.xres + x] = currentcolor; 17 | } 18 | -------------------------------------------------------------------------------- /part5-framebuffer/fb.h: -------------------------------------------------------------------------------- 1 | void fb_init(); 2 | void drawPixel(int x, int y, unsigned char attr); 3 | void drawChar(unsigned char ch, int x, int y, unsigned char attr); 4 | void drawString(int x, int y, char *s, unsigned char attr); 5 | void drawRect(int x1, int y1, int x2, int y2, unsigned char attr, int fill); 6 | void drawCircle(int x0, int y0, int radius, unsigned char attr, int fill); 7 | void drawLine(int x1, int y1, int x2, int y2, unsigned char attr); 8 | -------------------------------------------------------------------------------- /part6-breakout/io.h: -------------------------------------------------------------------------------- 1 | #define PERIPHERAL_BASE 0xFE000000 2 | #define SAFE_ADDRESS 0x00210000 // Somewhere safe to store a lot of data 3 | 4 | void uart_init(); 5 | void uart_writeText(char *buffer); 6 | void uart_loadOutputFifo(); 7 | unsigned char uart_readByte(); 8 | unsigned int uart_isReadByteReady(); 9 | void uart_writeByteBlocking(unsigned char ch); 10 | void uart_update(); 11 | void mmio_write(long reg, unsigned int val); 12 | unsigned int mmio_read(long reg); 13 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wmiscb.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | #include "../include/mem.h" 3 | 4 | extern short bx,by,tx,ty; 5 | 6 | void wfreeblock (block ptr) 7 | { 8 | free (ptr); 9 | } 10 | 11 | short wgetblockwidth (block ptr) 12 | { 13 | return *(short *)ptr; /* Width is first 2 bytes of data */ 14 | } 15 | 16 | short wgetblockheight (block ptr) 17 | { 18 | ptr ++; /* Skip width */ 19 | return *(short *)ptr; /* Height is second 2 bytes of data */ 20 | } 21 | -------------------------------------------------------------------------------- /part5-framebuffer/kernel.c: -------------------------------------------------------------------------------- 1 | #include "io.h" 2 | #include "fb.h" 3 | 4 | void main() 5 | { 6 | uart_init(); 7 | fb_init(); 8 | 9 | drawRect(150,150,400,400,0x03,0); 10 | drawRect(300,300,350,350,0x2e,1); 11 | 12 | drawCircle(960,540,250,0x0e,0); 13 | drawCircle(960,540,50,0x13,1); 14 | 15 | drawPixel(250,250,0x0e); 16 | 17 | drawChar('O',500,500,0x05); 18 | drawString(100,100,"Hello world!",0x0f); 19 | 20 | drawLine(100,500,350,700,0x0c); 21 | 22 | while (1); 23 | } 24 | -------------------------------------------------------------------------------- /part7-bluetooth/bt.h: -------------------------------------------------------------------------------- 1 | void bt_reset(); 2 | void bt_loadfirmware(); 3 | void bt_setbaud(); 4 | void bt_setbdaddr(); 5 | void bt_getbdaddr(unsigned char *bdaddr); 6 | void bt_init(); 7 | unsigned int bt_isReadByteReady(); 8 | unsigned char bt_readByte(); 9 | unsigned char bt_waitReadByte(); 10 | void setLEeventmask(unsigned char mask); 11 | void startActiveScanning(); 12 | void stopScanning(); 13 | void startActiveAdvertising(); 14 | void connect(unsigned char *addr); 15 | void sendACLsubscribe(unsigned int handle); 16 | -------------------------------------------------------------------------------- /part12-wgt/include/bt.h: -------------------------------------------------------------------------------- 1 | void bt_reset(); 2 | void bt_loadfirmware(); 3 | void bt_setbaud(); 4 | void bt_setbdaddr(); 5 | void bt_getbdaddr(unsigned char *bdaddr); 6 | void bt_init(); 7 | unsigned int bt_isReadByteReady(); 8 | unsigned char bt_readByte(); 9 | unsigned char bt_waitReadByte(); 10 | void setLEeventmask(unsigned char mask); 11 | void startActiveScanning(); 12 | void stopScanning(); 13 | void startActiveAdvertising(); 14 | void connect(unsigned char *addr); 15 | void sendACLsubscribe(unsigned int handle); 16 | -------------------------------------------------------------------------------- /part7-bluetooth/io.h: -------------------------------------------------------------------------------- 1 | #define PERIPHERAL_BASE 0xFE000000 2 | 3 | void uart_init(); 4 | void uart_writeText(char *buffer); 5 | void uart_loadOutputFifo(); 6 | unsigned char uart_readByte(); 7 | unsigned int uart_isReadByteReady(); 8 | void uart_writeByteBlockingActual(unsigned char ch); 9 | void uart_update(); 10 | void mmio_write(long reg, unsigned int val); 11 | unsigned int mmio_read(long reg); 12 | void gpio_useAsAlt3(unsigned int pin_number); 13 | void uart_hex(unsigned int d); 14 | void uart_byte(unsigned char b); 15 | -------------------------------------------------------------------------------- /part8-breakout-ble/bt.h: -------------------------------------------------------------------------------- 1 | void bt_reset(); 2 | void bt_loadfirmware(); 3 | void bt_setbaud(); 4 | void bt_setbdaddr(); 5 | void bt_getbdaddr(unsigned char *bdaddr); 6 | void bt_init(); 7 | unsigned int bt_isReadByteReady(); 8 | unsigned char bt_readByte(); 9 | unsigned char bt_waitReadByte(); 10 | void setLEeventmask(unsigned char mask); 11 | void startActiveScanning(); 12 | void stopScanning(); 13 | void startActiveAdvertising(); 14 | void connect(unsigned char *addr); 15 | void sendACLsubscribe(unsigned int handle); 16 | -------------------------------------------------------------------------------- /part11-breakout-smp/include/bt.h: -------------------------------------------------------------------------------- 1 | void bt_reset(); 2 | void bt_loadfirmware(); 3 | void bt_setbaud(); 4 | void bt_setbdaddr(); 5 | void bt_getbdaddr(unsigned char *bdaddr); 6 | void bt_init(); 7 | unsigned int bt_isReadByteReady(); 8 | unsigned char bt_readByte(); 9 | unsigned char bt_waitReadByte(); 10 | void setLEeventmask(unsigned char mask); 11 | void startActiveScanning(); 12 | void stopScanning(); 13 | void startActiveAdvertising(); 14 | void connect(unsigned char *addr); 15 | void sendACLsubscribe(unsigned int handle); 16 | -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol.xcodeproj/xcuserdata/Akshata.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | BLEPeripheralApp.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /part12-wgt/include/io.h: -------------------------------------------------------------------------------- 1 | #define PERIPHERAL_BASE 0xFE000000 2 | 3 | void uart_init(); 4 | void uart_writeText(char *buffer); 5 | void uart_loadOutputFifo(); 6 | unsigned char uart_readByte(); 7 | unsigned int uart_isReadByteReady(); 8 | void uart_writeByteBlockingActual(unsigned char ch); 9 | void uart_update(); 10 | void mmio_write(long reg, unsigned int val); 11 | unsigned int mmio_read(long reg); 12 | void gpio_useAsAlt0(unsigned int pin_number); 13 | void gpio_useAsAlt3(unsigned int pin_number); 14 | void uart_hex(unsigned int d); 15 | void uart_byte(unsigned char b); 16 | -------------------------------------------------------------------------------- /part11-breakout-smp/breakout_snd.c: -------------------------------------------------------------------------------- 1 | #include "include/multicore.h" 2 | #include "include/audio.h" 3 | 4 | void snd_core(void) 5 | { 6 | clear_core2(); 7 | 8 | // Initialise the audio 9 | audio_init(); 10 | 11 | // Write data out to FIFO and loop infinitely 12 | 13 | extern unsigned char _binary_bin_audio_bin_start[]; 14 | extern unsigned char _binary_bin_audio_bin_size[]; 15 | 16 | unsigned int size = (long)&_binary_bin_audio_bin_size; 17 | unsigned char *data = &(_binary_bin_audio_bin_start[0]); 18 | 19 | while (1) audio_play_cpu(data, size); 20 | } 21 | -------------------------------------------------------------------------------- /part8-breakout-ble/io.h: -------------------------------------------------------------------------------- 1 | #define PERIPHERAL_BASE 0xFE000000 2 | #define SAFE_ADDRESS 0x00210000 // Somewhere safe to store a lot of data 3 | 4 | void uart_init(); 5 | void uart_writeText(char *buffer); 6 | void uart_loadOutputFifo(); 7 | unsigned char uart_readByte(); 8 | unsigned int uart_isReadByteReady(); 9 | void uart_writeByteBlockingActual(unsigned char ch); 10 | void uart_update(); 11 | void mmio_write(long reg, unsigned int val); 12 | unsigned int mmio_read(long reg); 13 | void gpio_useAsAlt3(unsigned int pin_number); 14 | void uart_hex(unsigned int d); 15 | void uart_byte(unsigned char b); 16 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wclip.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | 3 | void wclip (short x, short y, short x2, short y2) 4 | { 5 | tx = x; /* Upper x limit */ 6 | ty = y; /* Upper y limit */ 7 | bx = x2; /* Lower x limit */ 8 | by = y2; /* Lower y limit */ 9 | /* Stay within screen bounds, no negatives */ 10 | if (tx < 0) tx = 0; 11 | if (ty < 0) ty = 0; 12 | if (bx >= WGT_SYS.xres) bx = WGT_SYS.xres - 1; 13 | if (by >= WGT_SYS.yres) by = WGT_SYS.yres - 1; 14 | } 15 | -------------------------------------------------------------------------------- /part6-breakout/fb.h: -------------------------------------------------------------------------------- 1 | void fb_init(); 2 | void drawPixel(int x, int y, unsigned char attr); 3 | void drawChar(unsigned char ch, int x, int y, unsigned char attr, int zoom); 4 | void drawString(int x, int y, char *s, unsigned char attr, int zoom); 5 | void drawRect(int x1, int y1, int x2, int y2, unsigned char attr, int fill); 6 | void drawCircle(int x0, int y0, int radius, unsigned char attr, int fill); 7 | void drawLine(int x1, int y1, int x2, int y2, unsigned char attr); 8 | void moveRect(int oldx, int oldy, int width, int height, int shiftx, int shifty, unsigned char attr); 9 | void wait_msec(unsigned int n); 10 | -------------------------------------------------------------------------------- /part11-breakout-smp/include/io.h: -------------------------------------------------------------------------------- 1 | #define PERIPHERAL_BASE 0xFE000000 2 | #define LEGACY_BASE 0x7E000000 3 | 4 | void uart_init(); 5 | void uart_writeText(char *buffer); 6 | void uart_loadOutputFifo(); 7 | unsigned char uart_readByte(); 8 | unsigned int uart_isReadByteReady(); 9 | void uart_writeByteBlockingActual(unsigned char ch); 10 | void uart_update(); 11 | void mmio_write(long reg, unsigned int val); 12 | unsigned int mmio_read(long reg); 13 | void gpio_useAsAlt0(unsigned int pin_number); 14 | void gpio_useAsAlt3(unsigned int pin_number); 15 | void uart_hex(unsigned int d); 16 | void uart_byte(unsigned char b); 17 | -------------------------------------------------------------------------------- /part2-building/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x80000; /* Kernel load address for AArch64 */ 4 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 5 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 6 | PROVIDE(_data = .); 7 | .data : { *(.data .data.* .gnu.linkonce.d*) } 8 | .bss (NOLOAD) : { 9 | . = ALIGN(16); 10 | __bss_start = .; 11 | *(.bss .bss.*) 12 | *(COMMON) 13 | __bss_end = .; 14 | } 15 | _end = .; 16 | 17 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 18 | } 19 | __bss_size = (__bss_end - __bss_start)>>3; 20 | -------------------------------------------------------------------------------- /part4-miniuart/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x80000; /* Kernel load address for AArch64 */ 4 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 5 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 6 | PROVIDE(_data = .); 7 | .data : { *(.data .data.* .gnu.linkonce.d*) } 8 | .bss (NOLOAD) : { 9 | . = ALIGN(16); 10 | __bss_start = .; 11 | *(.bss .bss.*) 12 | *(COMMON) 13 | __bss_end = .; 14 | } 15 | _end = .; 16 | 17 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 18 | } 19 | __bss_size = (__bss_end - __bss_start)>>3; 20 | -------------------------------------------------------------------------------- /part6-breakout/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x80000; /* Kernel load address for AArch64 */ 4 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 5 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 6 | PROVIDE(_data = .); 7 | .data : { *(.data .data.* .gnu.linkonce.d*) } 8 | .bss (NOLOAD) : { 9 | . = ALIGN(16); 10 | __bss_start = .; 11 | *(.bss .bss.*) 12 | *(COMMON) 13 | __bss_end = .; 14 | } 15 | _end = .; 16 | 17 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 18 | } 19 | __bss_size = (__bss_end - __bss_start)>>3; 20 | -------------------------------------------------------------------------------- /part7-bluetooth/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x80000; /* Kernel load address for AArch64 */ 4 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 5 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 6 | PROVIDE(_data = .); 7 | .data : { *(.data .data.* .gnu.linkonce.d*) } 8 | .bss (NOLOAD) : { 9 | . = ALIGN(16); 10 | __bss_start = .; 11 | *(.bss .bss.*) 12 | *(COMMON) 13 | __bss_end = .; 14 | } 15 | _end = .; 16 | 17 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 18 | } 19 | __bss_size = (__bss_end - __bss_start)>>3; 20 | -------------------------------------------------------------------------------- /part9-sound/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x80000; /* Kernel load address for AArch64 */ 4 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 5 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 6 | PROVIDE(_data = .); 7 | .data : { *(.data .data.* .gnu.linkonce.d*) } 8 | .bss (NOLOAD) : { 9 | . = ALIGN(16); 10 | __bss_start = .; 11 | *(.bss .bss.*) 12 | *(COMMON) 13 | __bss_end = .; 14 | } 15 | _end = .; 16 | 17 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 18 | } 19 | __bss_size = (__bss_end - __bss_start)>>3; 20 | -------------------------------------------------------------------------------- /part1-bootstrapping/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x80000; /* Kernel load address for AArch64 */ 4 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 5 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 6 | PROVIDE(_data = .); 7 | .data : { *(.data .data.* .gnu.linkonce.d*) } 8 | .bss (NOLOAD) : { 9 | . = ALIGN(16); 10 | __bss_start = .; 11 | *(.bss .bss.*) 12 | *(COMMON) 13 | __bss_end = .; 14 | } 15 | _end = .; 16 | 17 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 18 | } 19 | __bss_size = (__bss_end - __bss_start)>>3; 20 | -------------------------------------------------------------------------------- /part3-helloworld/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x80000; /* Kernel load address for AArch64 */ 4 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 5 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 6 | PROVIDE(_data = .); 7 | .data : { *(.data .data.* .gnu.linkonce.d*) } 8 | .bss (NOLOAD) : { 9 | . = ALIGN(16); 10 | __bss_start = .; 11 | *(.bss .bss.*) 12 | *(COMMON) 13 | __bss_end = .; 14 | } 15 | _end = .; 16 | 17 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 18 | } 19 | __bss_size = (__bss_end - __bss_start)>>3; 20 | -------------------------------------------------------------------------------- /part5-framebuffer/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x80000; /* Kernel load address for AArch64 */ 4 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 5 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 6 | PROVIDE(_data = .); 7 | .data : { *(.data .data.* .gnu.linkonce.d*) } 8 | .bss (NOLOAD) : { 9 | . = ALIGN(16); 10 | __bss_start = .; 11 | *(.bss .bss.*) 12 | *(COMMON) 13 | __bss_end = .; 14 | } 15 | _end = .; 16 | 17 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 18 | } 19 | __bss_size = (__bss_end - __bss_start)>>3; 20 | -------------------------------------------------------------------------------- /part8-breakout-ble/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x80000; /* Kernel load address for AArch64 */ 4 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 5 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 6 | PROVIDE(_data = .); 7 | .data : { *(.data .data.* .gnu.linkonce.d*) } 8 | .bss (NOLOAD) : { 9 | . = ALIGN(16); 10 | __bss_start = .; 11 | *(.bss .bss.*) 12 | *(COMMON) 13 | __bss_end = .; 14 | } 15 | _end = .; 16 | 17 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 18 | } 19 | __bss_size = (__bss_end - __bss_start)>>3; 20 | -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol.xcodeproj/xcuserdata/agb.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | BLEPeripheralApp.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | rpi4-osdev-ioscontrol.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /part13-interrupts/kernel/irq.c: -------------------------------------------------------------------------------- 1 | #include "kernel.h" 2 | 3 | void enable_interrupt_controller() { 4 | REGS_IRQ->irq0_enable_0 = SYS_TIMER_IRQ_1 | SYS_TIMER_IRQ_3; 5 | } 6 | 7 | void disable_interrupt_controller() { 8 | REGS_IRQ->irq0_enable_0 = 0; 9 | } 10 | 11 | void handle_irq() { 12 | unsigned int irq = REGS_IRQ->irq0_pending_0; 13 | 14 | while(irq) { 15 | if (irq & SYS_TIMER_IRQ_1) { 16 | irq &= ~SYS_TIMER_IRQ_1; 17 | 18 | handle_timer_1(); 19 | } 20 | 21 | if (irq & SYS_TIMER_IRQ_3) { 22 | irq &= ~SYS_TIMER_IRQ_3; 23 | 24 | handle_timer_3(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /part14-spi-ethernet/kernel/irq.c: -------------------------------------------------------------------------------- 1 | #include "kernel.h" 2 | 3 | void enable_interrupt_controller() { 4 | REGS_IRQ->irq0_enable_0 = SYS_TIMER_IRQ_1 | SYS_TIMER_IRQ_3; 5 | } 6 | 7 | void disable_interrupt_controller() { 8 | REGS_IRQ->irq0_enable_0 = 0; 9 | } 10 | 11 | void handle_irq() { 12 | unsigned int irq = REGS_IRQ->irq0_pending_0; 13 | 14 | while(irq) { 15 | if (irq & SYS_TIMER_IRQ_1) { 16 | irq &= ~SYS_TIMER_IRQ_1; 17 | 18 | handle_timer_1(); 19 | } 20 | 21 | if (irq & SYS_TIMER_IRQ_3) { 22 | irq &= ~SYS_TIMER_IRQ_3; 23 | 24 | handle_timer_3(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /part9-sound/io.h: -------------------------------------------------------------------------------- 1 | #define PERIPHERAL_BASE 0xFE000000 2 | #define LEGACY_BASE 0x7E000000 3 | #define SAFE_ADDRESS 0x00400000 // Somewhere safe to store a lot of data 4 | 5 | void uart_init(); 6 | void uart_writeText(char *buffer); 7 | void uart_loadOutputFifo(); 8 | unsigned char uart_readByte(); 9 | unsigned int uart_isReadByteReady(); 10 | void uart_writeByteBlockingActual(unsigned char ch); 11 | void uart_update(); 12 | void mmio_write(long reg, unsigned int val); 13 | unsigned int mmio_read(long reg); 14 | void gpio_useAsAlt0(unsigned int pin_number); 15 | void gpio_useAsAlt3(unsigned int pin_number); 16 | void uart_hex(unsigned int d); 17 | void uart_byte(unsigned char b); 18 | -------------------------------------------------------------------------------- /part10-multicore/io.h: -------------------------------------------------------------------------------- 1 | #define PERIPHERAL_BASE 0xFE000000 2 | #define LEGACY_BASE 0x7E000000 3 | #define SAFE_ADDRESS 0x00400000 // Somewhere safe to store a lot of data 4 | 5 | void uart_init(); 6 | void uart_writeText(char *buffer); 7 | void uart_loadOutputFifo(); 8 | unsigned char uart_readByte(); 9 | unsigned int uart_isReadByteReady(); 10 | void uart_writeByteBlockingActual(unsigned char ch); 11 | void uart_update(); 12 | void mmio_write(long reg, unsigned int val); 13 | unsigned int mmio_read(long reg); 14 | void gpio_useAsAlt0(unsigned int pin_number); 15 | void gpio_useAsAlt3(unsigned int pin_number); 16 | void uart_hex(unsigned int d); 17 | void uart_byte(unsigned char b); 18 | -------------------------------------------------------------------------------- /part13-interrupts/include/io.h: -------------------------------------------------------------------------------- 1 | #define PERIPHERAL_BASE 0xFE000000 2 | #define LEGACY_BASE 0x7E000000 3 | #define SAFE_ADDRESS 0x00400000 // Somewhere safe to store a lot of data 4 | 5 | void uart_init(); 6 | void uart_writeText(char *buffer); 7 | void uart_loadOutputFifo(); 8 | unsigned char uart_readByte(); 9 | unsigned int uart_isReadByteReady(); 10 | void uart_writeByteBlockingActual(unsigned char ch); 11 | void uart_update(); 12 | void mmio_write(long reg, unsigned int val); 13 | unsigned int mmio_read(long reg); 14 | void gpio_useAsAlt0(unsigned int pin_number); 15 | void gpio_useAsAlt3(unsigned int pin_number); 16 | void uart_hex(unsigned int d); 17 | void uart_byte(unsigned char b); 18 | -------------------------------------------------------------------------------- /part2-building/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | LLVMPATH = /opt/homebrew/opt/llvm/bin 4 | CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o 10 | 11 | %.o: %.c 12 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 13 | 14 | kernel8.img: boot.o $(OFILES) 15 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf 16 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 17 | 18 | clean: 19 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 20 | -------------------------------------------------------------------------------- /part3-helloworld/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | LLVMPATH = /opt/homebrew/opt/llvm/bin 4 | CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o 10 | 11 | %.o: %.c 12 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 13 | 14 | kernel8.img: boot.o $(OFILES) 15 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf 16 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 17 | 18 | clean: 19 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 20 | -------------------------------------------------------------------------------- /part4-miniuart/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | LLVMPATH = /opt/homebrew/opt/llvm/bin 4 | CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o 10 | 11 | %.o: %.c 12 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 13 | 14 | kernel8.img: boot.o $(OFILES) 15 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf 16 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 17 | 18 | clean: 19 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 20 | -------------------------------------------------------------------------------- /part5-framebuffer/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | LLVMPATH = /opt/homebrew/opt/llvm/bin 4 | CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o 10 | 11 | %.o: %.c 12 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 13 | 14 | kernel8.img: boot.o $(OFILES) 15 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf 16 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 17 | 18 | clean: 19 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 20 | -------------------------------------------------------------------------------- /part6-breakout/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | LLVMPATH = /opt/homebrew/opt/llvm/bin 4 | CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o 10 | 11 | %.o: %.c 12 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 13 | 14 | kernel8.img: boot.o $(OFILES) 15 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf 16 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 17 | 18 | clean: 19 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 20 | -------------------------------------------------------------------------------- /part2-building/Makefile.gcc: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles 4 | GCCPATH = ../../gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c boot.S -o boot.o 10 | 11 | %.o: %.c 12 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 13 | 14 | kernel8.img: boot.o $(OFILES) 15 | $(GCCPATH)/aarch64-none-elf-ld -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf 16 | $(GCCPATH)/aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 17 | 18 | clean: 19 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 20 | -------------------------------------------------------------------------------- /part3-helloworld/Makefile.gcc: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles 4 | GCCPATH = ../../gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c boot.S -o boot.o 10 | 11 | %.o: %.c 12 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 13 | 14 | kernel8.img: boot.o $(OFILES) 15 | $(GCCPATH)/aarch64-none-elf-ld -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf 16 | $(GCCPATH)/aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 17 | 18 | clean: 19 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 20 | -------------------------------------------------------------------------------- /part4-miniuart/Makefile.gcc: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles 4 | GCCPATH = ../../gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c boot.S -o boot.o 10 | 11 | %.o: %.c 12 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 13 | 14 | kernel8.img: boot.o $(OFILES) 15 | $(GCCPATH)/aarch64-none-elf-ld -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf 16 | $(GCCPATH)/aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 17 | 18 | clean: 19 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 20 | -------------------------------------------------------------------------------- /part5-framebuffer/Makefile.gcc: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles 4 | GCCPATH = ../../gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c boot.S -o boot.o 10 | 11 | %.o: %.c 12 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 13 | 14 | kernel8.img: boot.o $(OFILES) 15 | $(GCCPATH)/aarch64-none-elf-ld -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf 16 | $(GCCPATH)/aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 17 | 18 | clean: 19 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 20 | -------------------------------------------------------------------------------- /part6-breakout/Makefile.gcc: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles 4 | GCCPATH = ../../gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c boot.S -o boot.o 10 | 11 | %.o: %.c 12 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 13 | 14 | kernel8.img: boot.o $(OFILES) 15 | $(GCCPATH)/aarch64-none-elf-ld -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf 16 | $(GCCPATH)/aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 17 | 18 | clean: 19 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 20 | -------------------------------------------------------------------------------- /part9-sound/fb.h: -------------------------------------------------------------------------------- 1 | void fb_init(); 2 | void drawPixel(int x, int y, unsigned char attr); 3 | void drawChar(unsigned char ch, int x, int y, unsigned char attr, int zoom); 4 | void drawString(int x, int y, char *s, unsigned char attr, int zoom); 5 | void drawRect(int x1, int y1, int x2, int y2, unsigned char attr, int fill); 6 | void drawCircle(int x0, int y0, int radius, unsigned char attr, int fill); 7 | void drawLine(int x1, int y1, int x2, int y2, unsigned char attr); 8 | void moveRect(int oldx, int oldy, int width, int height, int shiftx, int shifty, unsigned char attr); 9 | void wait_msec(unsigned int n); 10 | void debugstr(char *str); 11 | void debugcrlf(void); 12 | void debugch(unsigned char b); 13 | void debughex(unsigned int d); 14 | -------------------------------------------------------------------------------- /part10-multicore/fb.h: -------------------------------------------------------------------------------- 1 | void fb_init(); 2 | void drawPixel(int x, int y, unsigned char attr); 3 | void drawChar(unsigned char ch, int x, int y, unsigned char attr, int zoom); 4 | void drawString(int x, int y, char *s, unsigned char attr, int zoom); 5 | void drawRect(int x1, int y1, int x2, int y2, unsigned char attr, int fill); 6 | void drawCircle(int x0, int y0, int radius, unsigned char attr, int fill); 7 | void drawLine(int x1, int y1, int x2, int y2, unsigned char attr); 8 | void moveRect(int oldx, int oldy, int width, int height, int shiftx, int shifty, unsigned char attr); 9 | void wait_msec(unsigned int n); 10 | void debugstr(char *str); 11 | void debugcrlf(void); 12 | void debugch(unsigned char b); 13 | void debughex(unsigned int d); 14 | -------------------------------------------------------------------------------- /part7-bluetooth/fb.h: -------------------------------------------------------------------------------- 1 | void fb_init(); 2 | void drawPixel(int x, int y, unsigned char attr); 3 | void drawChar(unsigned char ch, int x, int y, unsigned char attr, int zoom); 4 | void drawString(int x, int y, char *s, unsigned char attr, int zoom); 5 | void drawRect(int x1, int y1, int x2, int y2, unsigned char attr, int fill); 6 | void drawCircle(int x0, int y0, int radius, unsigned char attr, int fill); 7 | void drawLine(int x1, int y1, int x2, int y2, unsigned char attr); 8 | void moveRect(int oldx, int oldy, int width, int height, int shiftx, int shifty, unsigned char attr); 9 | void wait_msec(unsigned int n); 10 | void debugstr(char *str); 11 | void debugcrlf(void); 12 | void debugch(unsigned char b); 13 | void debughex(unsigned int d); 14 | -------------------------------------------------------------------------------- /part8-breakout-ble/fb.h: -------------------------------------------------------------------------------- 1 | void fb_init(); 2 | void drawPixel(int x, int y, unsigned char attr); 3 | void drawChar(unsigned char ch, int x, int y, unsigned char attr, int zoom); 4 | void drawString(int x, int y, char *s, unsigned char attr, int zoom); 5 | void drawRect(int x1, int y1, int x2, int y2, unsigned char attr, int fill); 6 | void drawCircle(int x0, int y0, int radius, unsigned char attr, int fill); 7 | void drawLine(int x1, int y1, int x2, int y2, unsigned char attr); 8 | void moveRectAbs(int oldx, int oldy, int width, int height, int newx, int newy, unsigned char attr); 9 | void wait_msec(unsigned int n); 10 | void debugstr(char *str); 11 | void debugcrlf(void); 12 | void debugch(unsigned char b); 13 | void debughex(unsigned int d); 14 | -------------------------------------------------------------------------------- /part11-breakout-smp/include/fb.h: -------------------------------------------------------------------------------- 1 | void fb_init(); 2 | void drawPixel(int x, int y, unsigned char attr); 3 | void drawChar(unsigned char ch, int x, int y, unsigned char attr, int zoom); 4 | void drawString(int x, int y, char *s, unsigned char attr, int zoom); 5 | void drawRect(int x1, int y1, int x2, int y2, unsigned char attr, int fill); 6 | void drawCircle(int x0, int y0, int radius, unsigned char attr, int fill); 7 | void drawLine(int x1, int y1, int x2, int y2, unsigned char attr); 8 | void moveRectAbs(int oldx, int oldy, int width, int height, int newx, int newy, unsigned char attr); 9 | void wait_msec(unsigned int n); 10 | void debugstr(char *str); 11 | void debugcrlf(void); 12 | void debugch(unsigned char b); 13 | void debughex(unsigned int d); 14 | -------------------------------------------------------------------------------- /part13-interrupts/include/fb.h: -------------------------------------------------------------------------------- 1 | void fb_init(); 2 | void drawPixel(int x, int y, unsigned char attr); 3 | void drawChar(unsigned char ch, int x, int y, unsigned char attr, int zoom); 4 | void drawString(int x, int y, char *s, unsigned char attr, int zoom); 5 | void drawRect(int x1, int y1, int x2, int y2, unsigned char attr, int fill); 6 | void drawCircle(int x0, int y0, int radius, unsigned char attr, int fill); 7 | void drawLine(int x1, int y1, int x2, int y2, unsigned char attr); 8 | void moveRect(int oldx, int oldy, int width, int height, int shiftx, int shifty, unsigned char attr); 9 | void wait_msec(unsigned int n); 10 | void debugstr(char *str); 11 | void debugcrlf(void); 12 | void debugch(unsigned char b); 13 | void debughex(unsigned int d); 14 | -------------------------------------------------------------------------------- /part14-spi-ethernet/include/fb.h: -------------------------------------------------------------------------------- 1 | void fb_init(); 2 | void drawPixel(int x, int y, unsigned char attr); 3 | void drawChar(unsigned char ch, int x, int y, unsigned char attr, int zoom); 4 | void drawString(int x, int y, char *s, unsigned char attr, int zoom); 5 | void drawRect(int x1, int y1, int x2, int y2, unsigned char attr, int fill); 6 | void drawCircle(int x0, int y0, int radius, unsigned char attr, int fill); 7 | void drawLine(int x1, int y1, int x2, int y2, unsigned char attr); 8 | void moveRect(int oldx, int oldy, int width, int height, int shiftx, int shifty, unsigned char attr); 9 | void wait_msec(unsigned int n); 10 | void debugstr(char *str); 11 | void debugcrlf(void); 12 | void debugch(unsigned char b); 13 | void debughex(unsigned int d); 14 | -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol.xcodeproj/project.xcworkspace/xcuserdata/agb.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildLocationStyle 6 | UseAppPreferences 7 | CustomBuildLocationType 8 | RelativeToDerivedData 9 | DerivedDataLocationStyle 10 | Default 11 | IssueFilterStyle 12 | ShowActiveSchemeOnly 13 | LiveSourceIssuesEnabled 14 | 15 | ShowSharedSchemesAutomaticallyEnabled 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /part13-interrupts/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c lib/*.c kernel/*.c) 2 | SFILES = $(wildcard boot/*.S lib/*.S kernel/*.S) 3 | OFILES = $(CFILES:.c=.o) $(SFILES:.S=.o) 4 | LLVMPATH = /opt/homebrew/opt/llvm/bin 5 | CLANGFLAGS = -Wall -O2 -ffreestanding -nostdlib -mcpu=cortex-a72+nosimd 6 | 7 | all: clean kernel8.img 8 | 9 | %.o: %.c 10 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 11 | 12 | %.o: %.S 13 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 14 | 15 | kernel8.img: $(OFILES) 16 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib $(OFILES) -T boot/link.ld -o kernel8.elf 17 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 18 | 19 | clean: 20 | /bin/rm kernel8.elf */*.o *.img > /dev/null 2> /dev/null || true 21 | -------------------------------------------------------------------------------- /part14-spi-ethernet/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c lib/*.c kernel/*.c net/*.c) 2 | SFILES = $(wildcard boot/*.S lib/*.S kernel/*.S) 3 | OFILES = $(CFILES:.c=.o) $(SFILES:.S=.o) 4 | LLVMPATH = /opt/homebrew/opt/llvm/bin 5 | CLANGFLAGS = -Wall -O0 -ffreestanding -nostdlib -mcpu=cortex-a72+nosimd 6 | 7 | all: clean kernel8.img 8 | 9 | %.o: %.c 10 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 11 | 12 | %.o: %.S 13 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 14 | 15 | kernel8.img: $(OFILES) 16 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib $(OFILES) -T boot/link.ld -o kernel8.elf 17 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 18 | 19 | clean: 20 | /bin/rm kernel8.elf */*.o *.img > /dev/null 2> /dev/null || true 21 | -------------------------------------------------------------------------------- /part14-spi-ethernet/net/encspi.c: -------------------------------------------------------------------------------- 1 | #include "../include/spi.h" 2 | 3 | void ENC_SPI_Select(unsigned char truefalse) { 4 | spi_chip_select(!truefalse); // If it's true, select 0 (the ENC), if false, select 1 (i.e. deselect the ENC) 5 | } 6 | 7 | void ENC_SPI_SendBuf(unsigned char *master2slave, unsigned char *slave2master, unsigned short bufferSize) { 8 | spi_chip_select(0); 9 | spi_send_recv(master2slave, slave2master, bufferSize); 10 | spi_chip_select(1); // De-select the ENC 11 | } 12 | 13 | void ENC_SPI_Send(unsigned char command) { 14 | spi_chip_select(0); 15 | spi_send(&command, 1); 16 | spi_chip_select(1); // De-select the ENC 17 | } 18 | 19 | void ENC_SPI_SendWithoutSelection(unsigned char command) { 20 | spi_send(&command, 1); 21 | } 22 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/net/encspi.c: -------------------------------------------------------------------------------- 1 | #include "../include/spi.h" 2 | 3 | void ENC_SPI_Select(unsigned char truefalse) { 4 | spi_chip_select(!truefalse); // If it's true, select 0 (the ENC), if false, select 1 (i.e. deselect the ENC) 5 | } 6 | 7 | void ENC_SPI_SendBuf(unsigned char *master2slave, unsigned char *slave2master, unsigned short bufferSize) { 8 | spi_chip_select(0); 9 | spi_send_recv(master2slave, slave2master, bufferSize); 10 | spi_chip_select(1); // De-select the ENC 11 | } 12 | 13 | void ENC_SPI_Send(unsigned char command) { 14 | spi_chip_select(0); 15 | spi_send(&command, 1); 16 | spi_chip_select(1); // De-select the ENC 17 | } 18 | 19 | void ENC_SPI_SendWithoutSelection(unsigned char command) { 20 | spi_send(&command, 1); 21 | } 22 | -------------------------------------------------------------------------------- /part12-wgt/bin/wgt1.pal: -------------------------------------------------------------------------------- 1 | ??????<<<:::777555222000---***(((%%%### 8?6=5;392806.4-3+1*/(-',%*$("'!%#!  8?6<4:2806.3,1*/(-&*$("& $!  2 |  ?<:8631/-*(&$! ??<<: :8 86 63 31 1/ /- 3 | -* 4 | *( (& &$$!!>;97420.+)'$"  ?$?&?(?*?-?/?1?3?6?8?:?????<<<:::888666333111///---***(((&&&$$$!!! ???????????? ?? 5 | ?? ?? ?? ???????????????????????????????????? ??!??"??#??$??%??&??'??(??)??*??+??,??-??.??/??0??1??2??3??4??5??6??7??8??9??:??;??<<<<--- -------------------------------------------------------------------------------- /part13-interrupts/Makefile.gcc: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c lib/*.c kernel/*.c) 2 | SFILES = $(wildcard boot/*.S lib/*.S kernel/*.S) 3 | OFILES = $(CFILES:.c=.o) $(SFILES:.S=.o) 4 | GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles 5 | GCCPATH = ../../gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin 6 | 7 | all: clean kernel8.img 8 | 9 | %.o: %.c 10 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 11 | 12 | %.o: %.S 13 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 14 | 15 | kernel8.img: $(OFILES) 16 | $(GCCPATH)/aarch64-none-elf-ld -nostdlib $(OFILES) -T boot/link.ld -o kernel8.elf 17 | $(GCCPATH)/aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 18 | 19 | clean: 20 | /bin/rm kernel8.elf */*.o *.img > /dev/null 2> /dev/null || true 21 | -------------------------------------------------------------------------------- /part14-spi-ethernet/Makefile.gcc: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c lib/*.c kernel/*.c net/*.c) 2 | SFILES = $(wildcard boot/*.S lib/*.S kernel/*.S) 3 | OFILES = $(CFILES:.c=.o) $(SFILES:.S=.o) 4 | GCCFLAGS = -Wall -O0 -ffreestanding -nostdlib -nostartfiles 5 | GCCPATH = ../../gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin 6 | 7 | all: clean kernel8.img 8 | 9 | %.o: %.c 10 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 11 | 12 | %.o: %.S 13 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 14 | 15 | kernel8.img: $(OFILES) 16 | $(GCCPATH)/aarch64-none-elf-ld -nostdlib $(OFILES) -T boot/link.ld -o kernel8.elf 17 | $(GCCPATH)/aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 18 | 19 | clean: 20 | /bin/rm kernel8.elf */*.o *.img > /dev/null 2> /dev/null || true 21 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c lib/*.c kernel/*.c net/*.c tcpip/*.c) 2 | SFILES = $(wildcard boot/*.S lib/*.S kernel/*.S) 3 | OFILES = $(CFILES:.c=.o) $(SFILES:.S=.o) 4 | LLVMPATH = /opt/homebrew/opt/llvm/bin 5 | CLANGFLAGS = -Wall -O0 -ffreestanding -nostdlib -mcpu=cortex-a72+nosimd 6 | 7 | all: clean kernel8.img 8 | 9 | %.o: %.c 10 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 11 | 12 | %.o: %.S 13 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 14 | 15 | kernel8.img: $(OFILES) 16 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib $(OFILES) -T boot/link.ld -o kernel8.elf 17 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 18 | 19 | clean: 20 | /bin/rm kernel8.elf */*.o *.img > /dev/null 2> /dev/null || true 21 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/include/fb.h: -------------------------------------------------------------------------------- 1 | void fb_init(); 2 | void drawPixel(int x, int y, unsigned char attr); 3 | void drawChar(unsigned char ch, int x, int y, unsigned char attr, int zoom); 4 | void drawString(int x, int y, char *s, unsigned char attr, int zoom); 5 | void drawRect(int x1, int y1, int x2, int y2, unsigned char attr, int fill); 6 | void drawCircle(int x0, int y0, int radius, unsigned char attr, int fill); 7 | void drawLine(int x1, int y1, int x2, int y2, unsigned char attr); 8 | void moveRect(int oldx, int oldy, int width, int height, int shiftx, int shifty, unsigned char attr); 9 | void wait_msec(unsigned int n); 10 | void debugstr(char *str); 11 | void debugcrlf(void); 12 | void debugch(unsigned char b); 13 | void debughex(unsigned int d); 14 | int strlen(const char *str); 15 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/Makefile.gcc: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c lib/*.c kernel/*.c net/*.c tcpip/*.c) 2 | SFILES = $(wildcard boot/*.S lib/*.S kernel/*.S) 3 | OFILES = $(CFILES:.c=.o) $(SFILES:.S=.o) 4 | GCCFLAGS = -Wall -O0 -ffreestanding -nostdlib -nostartfiles 5 | GCCPATH = ../../gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin 6 | 7 | all: clean kernel8.img 8 | 9 | %.o: %.c 10 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 11 | 12 | %.o: %.S 13 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 14 | 15 | kernel8.img: $(OFILES) 16 | $(GCCPATH)/aarch64-none-elf-ld -nostdlib $(OFILES) -T boot/link.ld -o kernel8.elf 17 | $(GCCPATH)/aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 18 | 19 | clean: 20 | /bin/rm kernel8.elf */*.o *.img > /dev/null 2> /dev/null || true 21 | -------------------------------------------------------------------------------- /part9-sound/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | LLVMPATH = /opt/homebrew/opt/llvm/bin 4 | CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o 10 | 11 | audio.o : audio.bin 12 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 13 | 14 | %.o: %.c 15 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 16 | 17 | kernel8.img: boot.o $(OFILES) audio.o 18 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) audio.o -T link.ld -o kernel8.elf 19 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 20 | 21 | clean: 22 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 23 | -------------------------------------------------------------------------------- /part10-multicore/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | LLVMPATH = /opt/homebrew/opt/llvm/bin 4 | CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o 10 | 11 | audio.o : audio.bin 12 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 13 | 14 | %.o: %.c 15 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 16 | 17 | kernel8.img: boot.o $(OFILES) audio.o 18 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) audio.o -T link.ld -o kernel8.elf 19 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 20 | 21 | clean: 22 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 23 | -------------------------------------------------------------------------------- /part14-spi-ethernet/include/io.h: -------------------------------------------------------------------------------- 1 | #define PERIPHERAL_BASE 0xFE000000 2 | #define LEGACY_BASE 0x7E000000 3 | #define SAFE_ADDRESS 0x00400000 // Somewhere safe to store a lot of data 4 | 5 | void uart_init(); 6 | void uart_writeText(char *buffer); 7 | void uart_loadOutputFifo(); 8 | unsigned char uart_readByte(); 9 | unsigned int uart_isReadByteReady(); 10 | void uart_writeByteBlockingActual(unsigned char ch); 11 | void uart_update(); 12 | void mmio_write(long reg, unsigned int val); 13 | unsigned int mmio_read(long reg); 14 | void gpio_useAsAlt0(unsigned int pin_number); 15 | void gpio_useAsAlt3(unsigned int pin_number); 16 | void gpio_setPinOutputBool(unsigned int pin_number, unsigned int onOrOff); 17 | void gpio_initOutputPinWithPullNone(unsigned int pin_number); 18 | void uart_hex(unsigned int d); 19 | void uart_byte(unsigned char b); 20 | -------------------------------------------------------------------------------- /part7-bluetooth/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | LLVMPATH = /opt/homebrew/opt/llvm/bin 4 | CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o 10 | 11 | BCM4345C0.o : BCM4345C0.hcd 12 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 13 | 14 | %.o: %.c 15 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 16 | 17 | kernel8.img: boot.o $(OFILES) BCM4345C0.o 18 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf 19 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 20 | 21 | clean: 22 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 23 | -------------------------------------------------------------------------------- /part8-breakout-ble/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | LLVMPATH = /opt/homebrew/opt/llvm/bin 4 | CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o 10 | 11 | BCM4345C0.o : BCM4345C0.hcd 12 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 13 | 14 | %.o: %.c 15 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 16 | 17 | kernel8.img: boot.o $(OFILES) BCM4345C0.o 18 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf 19 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 20 | 21 | clean: 22 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 23 | -------------------------------------------------------------------------------- /part8-breakout-ble/Makefile.gcc.windows: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles 4 | GCCPATH = ..\..\gcc-arm-10.2-2020.11-mingw-w64-i686-aarch64-none-elf\bin 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(GCCPATH)\aarch64-none-elf-gcc $(GCCFLAGS) -c boot.S -o boot.o 10 | 11 | BCM4345C0.o : BCM4345C0.hcd 12 | $(GCCPATH)\aarch64-none-elf-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 13 | 14 | %.o: %.c 15 | $(GCCPATH)\aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 16 | 17 | kernel8.img: boot.o $(OFILES) BCM4345C0.o 18 | $(GCCPATH)\aarch64-none-elf-ld -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf 19 | $(GCCPATH)\aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 20 | 21 | clean: 22 | del kernel8.elf *.o *.img 23 | -------------------------------------------------------------------------------- /part9-sound/Makefile.gcc: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles 4 | GCCPATH = ../../gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c boot.S -o boot.o 10 | 11 | audio.o : audio.bin 12 | $(GCCPATH)/aarch64-none-elf-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 13 | 14 | %.o: %.c 15 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 16 | 17 | kernel8.img: boot.o $(OFILES) audio.o 18 | $(GCCPATH)/aarch64-none-elf-ld -nostdlib boot.o $(OFILES) audio.o -T link.ld -o kernel8.elf 19 | $(GCCPATH)/aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 20 | 21 | clean: 22 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 23 | -------------------------------------------------------------------------------- /part10-multicore/Makefile.gcc: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles 4 | GCCPATH = ../../gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c boot.S -o boot.o 10 | 11 | audio.o : audio.bin 12 | $(GCCPATH)/aarch64-none-elf-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 13 | 14 | %.o: %.c 15 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 16 | 17 | kernel8.img: boot.o $(OFILES) audio.o 18 | $(GCCPATH)/aarch64-none-elf-ld -nostdlib boot.o $(OFILES) audio.o -T link.ld -o kernel8.elf 19 | $(GCCPATH)/aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 20 | 21 | clean: 22 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 23 | -------------------------------------------------------------------------------- /part7-bluetooth/Makefile.gcc: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles 4 | GCCPATH = ../../gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c boot.S -o boot.o 10 | 11 | BCM4345C0.o : BCM4345C0.hcd 12 | $(GCCPATH)/aarch64-none-elf-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 13 | 14 | %.o: %.c 15 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 16 | 17 | kernel8.img: boot.o $(OFILES) BCM4345C0.o 18 | $(GCCPATH)/aarch64-none-elf-ld -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf 19 | $(GCCPATH)/aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 20 | 21 | clean: 22 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 23 | -------------------------------------------------------------------------------- /part8-breakout-ble/Makefile.gcc: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c) 2 | OFILES = $(CFILES:.c=.o) 3 | GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles 4 | GCCPATH = ../../gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/bin 5 | 6 | all: clean kernel8.img 7 | 8 | boot.o: boot.S 9 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c boot.S -o boot.o 10 | 11 | BCM4345C0.o : BCM4345C0.hcd 12 | $(GCCPATH)/aarch64-none-elf-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 13 | 14 | %.o: %.c 15 | $(GCCPATH)/aarch64-none-elf-gcc $(GCCFLAGS) -c $< -o $@ 16 | 17 | kernel8.img: boot.o $(OFILES) BCM4345C0.o 18 | $(GCCPATH)/aarch64-none-elf-ld -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf 19 | $(GCCPATH)/aarch64-none-elf-objcopy -O binary kernel8.elf kernel8.img 20 | 21 | clean: 22 | /bin/rm kernel8.elf *.o *.img > /dev/null 2> /dev/null || true 23 | -------------------------------------------------------------------------------- /part9-sound/mb.h: -------------------------------------------------------------------------------- 1 | extern volatile unsigned int mbox[36]; 2 | 3 | enum { 4 | MBOX_REQUEST = 0 5 | }; 6 | 7 | enum { 8 | MBOX_CH_POWER = 0, 9 | MBOX_CH_FB = 1, 10 | MBOX_CH_VUART = 2, 11 | MBOX_CH_VCHIQ = 3, 12 | MBOX_CH_LEDS = 4, 13 | MBOX_CH_BTNS = 5, 14 | MBOX_CH_TOUCH = 6, 15 | MBOX_CH_COUNT = 7, 16 | MBOX_CH_PROP = 8 // Request from ARM for response by VideoCore 17 | }; 18 | 19 | enum { 20 | MBOX_TAG_SETPOWER = 0x28001, 21 | MBOX_TAG_SETCLKRATE = 0x38002, 22 | 23 | MBOX_TAG_SETPHYWH = 0x48003, 24 | MBOX_TAG_SETVIRTWH = 0x48004, 25 | MBOX_TAG_SETVIRTOFF = 0x48009, 26 | MBOX_TAG_SETDEPTH = 0x48005, 27 | MBOX_TAG_SETPXLORDR = 0x48006, 28 | MBOX_TAG_GETFB = 0x40001, 29 | MBOX_TAG_GETPITCH = 0x40008, 30 | 31 | MBOX_TAG_LAST = 0 32 | }; 33 | 34 | unsigned int mbox_call(unsigned char ch); 35 | -------------------------------------------------------------------------------- /part10-multicore/mb.h: -------------------------------------------------------------------------------- 1 | extern volatile unsigned int mbox[36]; 2 | 3 | enum { 4 | MBOX_REQUEST = 0 5 | }; 6 | 7 | enum { 8 | MBOX_CH_POWER = 0, 9 | MBOX_CH_FB = 1, 10 | MBOX_CH_VUART = 2, 11 | MBOX_CH_VCHIQ = 3, 12 | MBOX_CH_LEDS = 4, 13 | MBOX_CH_BTNS = 5, 14 | MBOX_CH_TOUCH = 6, 15 | MBOX_CH_COUNT = 7, 16 | MBOX_CH_PROP = 8 // Request from ARM for response by VideoCore 17 | }; 18 | 19 | enum { 20 | MBOX_TAG_SETPOWER = 0x28001, 21 | MBOX_TAG_SETCLKRATE = 0x38002, 22 | 23 | MBOX_TAG_SETPHYWH = 0x48003, 24 | MBOX_TAG_SETVIRTWH = 0x48004, 25 | MBOX_TAG_SETVIRTOFF = 0x48009, 26 | MBOX_TAG_SETDEPTH = 0x48005, 27 | MBOX_TAG_SETPXLORDR = 0x48006, 28 | MBOX_TAG_GETFB = 0x40001, 29 | MBOX_TAG_GETPITCH = 0x40008, 30 | 31 | MBOX_TAG_LAST = 0 32 | }; 33 | 34 | unsigned int mbox_call(unsigned char ch); 35 | -------------------------------------------------------------------------------- /part5-framebuffer/mb.h: -------------------------------------------------------------------------------- 1 | extern volatile unsigned int mbox[36]; 2 | 3 | enum { 4 | MBOX_REQUEST = 0 5 | }; 6 | 7 | enum { 8 | MBOX_CH_POWER = 0, 9 | MBOX_CH_FB = 1, 10 | MBOX_CH_VUART = 2, 11 | MBOX_CH_VCHIQ = 3, 12 | MBOX_CH_LEDS = 4, 13 | MBOX_CH_BTNS = 5, 14 | MBOX_CH_TOUCH = 6, 15 | MBOX_CH_COUNT = 7, 16 | MBOX_CH_PROP = 8 // Request from ARM for response by VideoCore 17 | }; 18 | 19 | enum { 20 | MBOX_TAG_SETPOWER = 0x28001, 21 | MBOX_TAG_SETCLKRATE = 0x38002, 22 | 23 | MBOX_TAG_SETPHYWH = 0x48003, 24 | MBOX_TAG_SETVIRTWH = 0x48004, 25 | MBOX_TAG_SETVIRTOFF = 0x48009, 26 | MBOX_TAG_SETDEPTH = 0x48005, 27 | MBOX_TAG_SETPXLORDR = 0x48006, 28 | MBOX_TAG_GETFB = 0x40001, 29 | MBOX_TAG_GETPITCH = 0x40008, 30 | 31 | MBOX_TAG_LAST = 0 32 | }; 33 | 34 | unsigned int mbox_call(unsigned char ch); 35 | -------------------------------------------------------------------------------- /part6-breakout/mb.h: -------------------------------------------------------------------------------- 1 | extern volatile unsigned int mbox[36]; 2 | 3 | enum { 4 | MBOX_REQUEST = 0 5 | }; 6 | 7 | enum { 8 | MBOX_CH_POWER = 0, 9 | MBOX_CH_FB = 1, 10 | MBOX_CH_VUART = 2, 11 | MBOX_CH_VCHIQ = 3, 12 | MBOX_CH_LEDS = 4, 13 | MBOX_CH_BTNS = 5, 14 | MBOX_CH_TOUCH = 6, 15 | MBOX_CH_COUNT = 7, 16 | MBOX_CH_PROP = 8 // Request from ARM for response by VideoCore 17 | }; 18 | 19 | enum { 20 | MBOX_TAG_SETPOWER = 0x28001, 21 | MBOX_TAG_SETCLKRATE = 0x38002, 22 | 23 | MBOX_TAG_SETPHYWH = 0x48003, 24 | MBOX_TAG_SETVIRTWH = 0x48004, 25 | MBOX_TAG_SETVIRTOFF = 0x48009, 26 | MBOX_TAG_SETDEPTH = 0x48005, 27 | MBOX_TAG_SETPXLORDR = 0x48006, 28 | MBOX_TAG_GETFB = 0x40001, 29 | MBOX_TAG_GETPITCH = 0x40008, 30 | 31 | MBOX_TAG_LAST = 0 32 | }; 33 | 34 | unsigned int mbox_call(unsigned char ch); 35 | -------------------------------------------------------------------------------- /part7-bluetooth/mb.h: -------------------------------------------------------------------------------- 1 | extern volatile unsigned int mbox[36]; 2 | 3 | enum { 4 | MBOX_REQUEST = 0 5 | }; 6 | 7 | enum { 8 | MBOX_CH_POWER = 0, 9 | MBOX_CH_FB = 1, 10 | MBOX_CH_VUART = 2, 11 | MBOX_CH_VCHIQ = 3, 12 | MBOX_CH_LEDS = 4, 13 | MBOX_CH_BTNS = 5, 14 | MBOX_CH_TOUCH = 6, 15 | MBOX_CH_COUNT = 7, 16 | MBOX_CH_PROP = 8 // Request from ARM for response by VideoCore 17 | }; 18 | 19 | enum { 20 | MBOX_TAG_SETPOWER = 0x28001, 21 | MBOX_TAG_SETCLKRATE = 0x38002, 22 | 23 | MBOX_TAG_SETPHYWH = 0x48003, 24 | MBOX_TAG_SETVIRTWH = 0x48004, 25 | MBOX_TAG_SETVIRTOFF = 0x48009, 26 | MBOX_TAG_SETDEPTH = 0x48005, 27 | MBOX_TAG_SETPXLORDR = 0x48006, 28 | MBOX_TAG_GETFB = 0x40001, 29 | MBOX_TAG_GETPITCH = 0x40008, 30 | 31 | MBOX_TAG_LAST = 0 32 | }; 33 | 34 | unsigned int mbox_call(unsigned char ch); 35 | -------------------------------------------------------------------------------- /part8-breakout-ble/mb.h: -------------------------------------------------------------------------------- 1 | extern volatile unsigned int mbox[36]; 2 | 3 | enum { 4 | MBOX_REQUEST = 0 5 | }; 6 | 7 | enum { 8 | MBOX_CH_POWER = 0, 9 | MBOX_CH_FB = 1, 10 | MBOX_CH_VUART = 2, 11 | MBOX_CH_VCHIQ = 3, 12 | MBOX_CH_LEDS = 4, 13 | MBOX_CH_BTNS = 5, 14 | MBOX_CH_TOUCH = 6, 15 | MBOX_CH_COUNT = 7, 16 | MBOX_CH_PROP = 8 // Request from ARM for response by VideoCore 17 | }; 18 | 19 | enum { 20 | MBOX_TAG_SETPOWER = 0x28001, 21 | MBOX_TAG_SETCLKRATE = 0x38002, 22 | 23 | MBOX_TAG_SETPHYWH = 0x48003, 24 | MBOX_TAG_SETVIRTWH = 0x48004, 25 | MBOX_TAG_SETVIRTOFF = 0x48009, 26 | MBOX_TAG_SETDEPTH = 0x48005, 27 | MBOX_TAG_SETPXLORDR = 0x48006, 28 | MBOX_TAG_GETFB = 0x40001, 29 | MBOX_TAG_GETPITCH = 0x40008, 30 | 31 | MBOX_TAG_LAST = 0 32 | }; 33 | 34 | unsigned int mbox_call(unsigned char ch); 35 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wbutt.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | 3 | void wbutt (short x, short y, short x2, short y2) 4 | { 5 | short ctr; 6 | 7 | if (y2 < y) 8 | { 9 | /* swap y's */ 10 | ctr = y; 11 | y = y2; 12 | y2 = ctr; 13 | } 14 | 15 | if (x2 < x) 16 | { 17 | /* swap x's */ 18 | ctr = x; 19 | x = x2; 20 | x2 = ctr; 21 | } 22 | wsetcolor (vgapal[0]); 23 | wrectangle (x - 1, y - 1, x2 + 1, y2 + 1); 24 | /* Clear area for button */ 25 | wsetcolor (vgapal[254]); 26 | wbar (x, y, x2, y2); /* Draw inner bar */ 27 | wsetcolor (vgapal[255]); 28 | wline (x2, y, x2, y2); /* Outline right and bottom edges */ 29 | wline (x2, y2, x, y2); 30 | 31 | wsetcolor (vgapal[253]); /* Use a different shade */ 32 | wline (x, y, x2, y); /* Outline upper and left edges */ 33 | wline (x, y, x, y2); 34 | } 35 | -------------------------------------------------------------------------------- /part11-breakout-smp/include/mb.h: -------------------------------------------------------------------------------- 1 | extern volatile unsigned int mbox[36]; 2 | 3 | enum { 4 | MBOX_REQUEST = 0 5 | }; 6 | 7 | enum { 8 | MBOX_CH_POWER = 0, 9 | MBOX_CH_FB = 1, 10 | MBOX_CH_VUART = 2, 11 | MBOX_CH_VCHIQ = 3, 12 | MBOX_CH_LEDS = 4, 13 | MBOX_CH_BTNS = 5, 14 | MBOX_CH_TOUCH = 6, 15 | MBOX_CH_COUNT = 7, 16 | MBOX_CH_PROP = 8 // Request from ARM for response by VideoCore 17 | }; 18 | 19 | enum { 20 | MBOX_TAG_SETPOWER = 0x28001, 21 | MBOX_TAG_SETCLKRATE = 0x38002, 22 | 23 | MBOX_TAG_SETPHYWH = 0x48003, 24 | MBOX_TAG_SETVIRTWH = 0x48004, 25 | MBOX_TAG_SETVIRTOFF = 0x48009, 26 | MBOX_TAG_SETDEPTH = 0x48005, 27 | MBOX_TAG_SETPXLORDR = 0x48006, 28 | MBOX_TAG_GETFB = 0x40001, 29 | MBOX_TAG_GETPITCH = 0x40008, 30 | 31 | MBOX_TAG_LAST = 0 32 | }; 33 | 34 | unsigned int mbox_call(unsigned char ch); 35 | -------------------------------------------------------------------------------- /part13-interrupts/include/mb.h: -------------------------------------------------------------------------------- 1 | extern volatile unsigned int mbox[36]; 2 | 3 | enum { 4 | MBOX_REQUEST = 0 5 | }; 6 | 7 | enum { 8 | MBOX_CH_POWER = 0, 9 | MBOX_CH_FB = 1, 10 | MBOX_CH_VUART = 2, 11 | MBOX_CH_VCHIQ = 3, 12 | MBOX_CH_LEDS = 4, 13 | MBOX_CH_BTNS = 5, 14 | MBOX_CH_TOUCH = 6, 15 | MBOX_CH_COUNT = 7, 16 | MBOX_CH_PROP = 8 // Request from ARM for response by VideoCore 17 | }; 18 | 19 | enum { 20 | MBOX_TAG_SETPOWER = 0x28001, 21 | MBOX_TAG_SETCLKRATE = 0x38002, 22 | 23 | MBOX_TAG_SETPHYWH = 0x48003, 24 | MBOX_TAG_SETVIRTWH = 0x48004, 25 | MBOX_TAG_SETVIRTOFF = 0x48009, 26 | MBOX_TAG_SETDEPTH = 0x48005, 27 | MBOX_TAG_SETPXLORDR = 0x48006, 28 | MBOX_TAG_GETFB = 0x40001, 29 | MBOX_TAG_GETPITCH = 0x40008, 30 | 31 | MBOX_TAG_LAST = 0 32 | }; 33 | 34 | unsigned int mbox_call(unsigned char ch); 35 | -------------------------------------------------------------------------------- /part14-spi-ethernet/include/mb.h: -------------------------------------------------------------------------------- 1 | extern volatile unsigned int mbox[36]; 2 | 3 | enum { 4 | MBOX_REQUEST = 0 5 | }; 6 | 7 | enum { 8 | MBOX_CH_POWER = 0, 9 | MBOX_CH_FB = 1, 10 | MBOX_CH_VUART = 2, 11 | MBOX_CH_VCHIQ = 3, 12 | MBOX_CH_LEDS = 4, 13 | MBOX_CH_BTNS = 5, 14 | MBOX_CH_TOUCH = 6, 15 | MBOX_CH_COUNT = 7, 16 | MBOX_CH_PROP = 8 // Request from ARM for response by VideoCore 17 | }; 18 | 19 | enum { 20 | MBOX_TAG_SETPOWER = 0x28001, 21 | MBOX_TAG_SETCLKRATE = 0x38002, 22 | 23 | MBOX_TAG_SETPHYWH = 0x48003, 24 | MBOX_TAG_SETVIRTWH = 0x48004, 25 | MBOX_TAG_SETVIRTOFF = 0x48009, 26 | MBOX_TAG_SETDEPTH = 0x48005, 27 | MBOX_TAG_SETPXLORDR = 0x48006, 28 | MBOX_TAG_GETFB = 0x40001, 29 | MBOX_TAG_GETPITCH = 0x40008, 30 | 31 | MBOX_TAG_LAST = 0 32 | }; 33 | 34 | unsigned int mbox_call(unsigned char ch); 35 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/include/mb.h: -------------------------------------------------------------------------------- 1 | extern volatile unsigned int mbox[36]; 2 | 3 | enum { 4 | MBOX_REQUEST = 0 5 | }; 6 | 7 | enum { 8 | MBOX_CH_POWER = 0, 9 | MBOX_CH_FB = 1, 10 | MBOX_CH_VUART = 2, 11 | MBOX_CH_VCHIQ = 3, 12 | MBOX_CH_LEDS = 4, 13 | MBOX_CH_BTNS = 5, 14 | MBOX_CH_TOUCH = 6, 15 | MBOX_CH_COUNT = 7, 16 | MBOX_CH_PROP = 8 // Request from ARM for response by VideoCore 17 | }; 18 | 19 | enum { 20 | MBOX_TAG_SETPOWER = 0x28001, 21 | MBOX_TAG_SETCLKRATE = 0x38002, 22 | 23 | MBOX_TAG_SETPHYWH = 0x48003, 24 | MBOX_TAG_SETVIRTWH = 0x48004, 25 | MBOX_TAG_SETVIRTOFF = 0x48009, 26 | MBOX_TAG_SETDEPTH = 0x48005, 27 | MBOX_TAG_SETPXLORDR = 0x48006, 28 | MBOX_TAG_GETFB = 0x40001, 29 | MBOX_TAG_GETPITCH = 0x40008, 30 | 31 | MBOX_TAG_LAST = 0 32 | }; 33 | 34 | unsigned int mbox_call(unsigned char ch); 35 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/include/io.h: -------------------------------------------------------------------------------- 1 | #define PERIPHERAL_BASE 0xFE000000 2 | #define LEGACY_BASE 0x7E000000 3 | #define SAFE_ADDRESS 0x00400000 // Somewhere safe to store a lot of data 4 | 5 | void uart_init(); 6 | void uart_writeText(char *buffer); 7 | void uart_loadOutputFifo(); 8 | unsigned char uart_readByte(); 9 | unsigned int uart_isReadByteReady(); 10 | void uart_writeByteBlockingActual(unsigned char ch); 11 | void uart_update(); 12 | void mmio_write(long reg, unsigned int val); 13 | unsigned int mmio_read(long reg); 14 | void gpio_useAsAlt0(unsigned int pin_number); 15 | void gpio_useAsAlt3(unsigned int pin_number); 16 | void gpio_setPinOutputBool(unsigned int pin_number, unsigned int onOrOff); 17 | void gpio_initOutputPinWithPullNone(unsigned int pin_number); 18 | void uart_hex(unsigned int d); 19 | void uart_byte(unsigned char b); 20 | unsigned long HAL_GetTick(void); 21 | void HAL_Delay(unsigned int ms); 22 | -------------------------------------------------------------------------------- /part10-multicore/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 4 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 5 | PROVIDE(_data = .); 6 | .data : { *(.data .data.* .gnu.linkonce.d*) } 7 | .bss (NOLOAD) : { 8 | . = ALIGN(16); 9 | __bss_start = .; 10 | *(.bss .bss.*) 11 | *(COMMON) 12 | __bss_end = .; 13 | __bss_size = (__bss_end - __bss_start)>>3; 14 | } 15 | .cpu1Stack : 16 | { 17 | . = ALIGN(16); 18 | __stack_start = .; 19 | . = . + 512; 20 | __cpu1_stack = .; 21 | } 22 | .cpu2Stack : 23 | { 24 | . = . + 512; 25 | __cpu2_stack = .; 26 | } 27 | .cpu3Stack : 28 | { 29 | . = . + 512; 30 | __cpu3_stack = .; 31 | } 32 | _end = .; 33 | 34 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 35 | } 36 | -------------------------------------------------------------------------------- /part12-wgt/boot/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 4 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 5 | PROVIDE(_data = .); 6 | .data : { *(.data .data.* .gnu.linkonce.d*) } 7 | .bss (NOLOAD) : { 8 | . = ALIGN(16); 9 | __bss_start = .; 10 | *(.bss .bss.*) 11 | *(COMMON) 12 | __bss_end = .; 13 | __bss_size = (__bss_end - __bss_start)>>3; 14 | } 15 | .cpu1Stack : 16 | { 17 | . = ALIGN(16); 18 | __stack_start = .; 19 | . = . + 512; 20 | __cpu1_stack = .; 21 | } 22 | .cpu2Stack : 23 | { 24 | . = . + 512; 25 | __cpu2_stack = .; 26 | } 27 | .cpu3Stack : 28 | { 29 | . = . + 512; 30 | __cpu3_stack = .; 31 | } 32 | _end = .; 33 | 34 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 35 | } 36 | -------------------------------------------------------------------------------- /part12-wgt/wgt/winitply.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | #include "../include/mem.h" 3 | 4 | short *pinit_array; 5 | short *pstartx; 6 | short *pendx; 7 | short *pinten1; 8 | short *pinten2; 9 | short *polyx2; 10 | short *polyy2; 11 | short polygon_buffer_size; 12 | 13 | void winitpoly (short maxrows) 14 | { 15 | int bytes; 16 | int ctr; 17 | 18 | polygon_buffer_size = maxrows; 19 | 20 | bytes = 2 * maxrows; 21 | pstartx = malloc (bytes); 22 | pendx = malloc (bytes); 23 | pinten1 = malloc (bytes); 24 | pinten2 = malloc (bytes); 25 | polyx2 = malloc (bytes); 26 | polyy2 = malloc (bytes); 27 | pinit_array = malloc (bytes); 28 | for (ctr = 0; ctr < maxrows; ctr++) 29 | pinit_array[ctr] = -16000; 30 | } 31 | 32 | void wdeinitpoly (void) 33 | { 34 | free (pstartx); 35 | free (pendx); 36 | free (pinten1); 37 | free (pinten2); 38 | free (polyx2); 39 | free (polyy2); 40 | free (pinit_array); 41 | } 42 | -------------------------------------------------------------------------------- /part11-breakout-smp/boot/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 4 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 5 | PROVIDE(_data = .); 6 | .data : { *(.data .data.* .gnu.linkonce.d*) } 7 | .bss (NOLOAD) : { 8 | . = ALIGN(16); 9 | __bss_start = .; 10 | *(.bss .bss.*) 11 | *(COMMON) 12 | __bss_end = .; 13 | __bss_size = (__bss_end - __bss_start)>>3; 14 | } 15 | .cpu1Stack : 16 | { 17 | . = ALIGN(16); 18 | __stack_start = .; 19 | . = . + 512; 20 | __cpu1_stack = .; 21 | } 22 | .cpu2Stack : 23 | { 24 | . = . + 512; 25 | __cpu2_stack = .; 26 | } 27 | .cpu3Stack : 28 | { 29 | . = . + 512; 30 | __cpu3_stack = .; 31 | } 32 | _end = .; 33 | 34 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 35 | } 36 | -------------------------------------------------------------------------------- /part13-interrupts/boot/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 4 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 5 | PROVIDE(_data = .); 6 | .data : { *(.data .data.* .gnu.linkonce.d*) } 7 | .bss (NOLOAD) : { 8 | . = ALIGN(16); 9 | __bss_start = .; 10 | *(.bss .bss.*) 11 | *(COMMON) 12 | __bss_end = .; 13 | __bss_size = (__bss_end - __bss_start)>>3; 14 | } 15 | .cpu1Stack : 16 | { 17 | . = ALIGN(16); 18 | __stack_start = .; 19 | . = . + 512; 20 | __cpu1_stack = .; 21 | } 22 | .cpu2Stack : 23 | { 24 | . = . + 512; 25 | __cpu2_stack = .; 26 | } 27 | .cpu3Stack : 28 | { 29 | . = . + 512; 30 | __cpu3_stack = .; 31 | } 32 | _end = .; 33 | 34 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 35 | } 36 | -------------------------------------------------------------------------------- /part14-spi-ethernet/boot/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 4 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 5 | PROVIDE(_data = .); 6 | .data : { *(.data .data.* .gnu.linkonce.d*) } 7 | .bss (NOLOAD) : { 8 | . = ALIGN(16); 9 | __bss_start = .; 10 | *(.bss .bss.*) 11 | *(COMMON) 12 | __bss_end = .; 13 | __bss_size = (__bss_end - __bss_start)>>3; 14 | } 15 | .cpu1Stack : 16 | { 17 | . = ALIGN(16); 18 | __stack_start = .; 19 | . = . + 512; 20 | __cpu1_stack = .; 21 | } 22 | .cpu2Stack : 23 | { 24 | . = . + 512; 25 | __cpu2_stack = .; 26 | } 27 | .cpu3Stack : 28 | { 29 | . = . + 512; 30 | __cpu3_stack = .; 31 | } 32 | _end = .; 33 | 34 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 35 | } 36 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/boot/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } 4 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } 5 | PROVIDE(_data = .); 6 | .data : { *(.data .data.* .gnu.linkonce.d*) } 7 | .bss (NOLOAD) : { 8 | . = ALIGN(16); 9 | __bss_start = .; 10 | *(.bss .bss.*) 11 | *(COMMON) 12 | __bss_end = .; 13 | __bss_size = (__bss_end - __bss_start)>>3; 14 | } 15 | .cpu1Stack : 16 | { 17 | . = ALIGN(16); 18 | __stack_start = .; 19 | . = . + 512; 20 | __cpu1_stack = .; 21 | } 22 | .cpu2Stack : 23 | { 24 | . = . + 512; 25 | __cpu2_stack = .; 26 | } 27 | .cpu3Stack : 28 | { 29 | . = . + 512; 30 | __cpu3_stack = .; 31 | } 32 | _end = .; 33 | 34 | /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } 35 | } 36 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wdissolve.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | 3 | void wdissolve (block sourceimage, short *pattern, short speed) 4 | { 5 | short j, k, l, t, a, b; 6 | unsigned short addr; 7 | 8 | t = *pattern; 9 | pattern++; 10 | 11 | for (j = 0; j < t; j++) 12 | { 13 | a = *pattern; 14 | pattern++; 15 | b = *pattern; 16 | pattern++; 17 | delay (speed); 18 | for (k = 0; k < WGT_SYS.yres; k += 16) 19 | /* Since the fade pattern matrix is 16x16, we change every 20 | 16th pixel at the same time. */ 21 | { 22 | for (l = 0; l < WGT_SYS.xres; l += 16) 23 | { 24 | if ((k + b < by + 1) & (l + a < bx + 1) & (k + b >= ty) 25 | & (l + a >= tx)) 26 | /* Make sure the pixel is within clipping */ 27 | { 28 | addr = ((k + b) * WGT_SYS.xres + l + a); 29 | abuf[addr] = sourceimage[addr + 2]; 30 | } 31 | } 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wblock.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | #include "../include/mem.h" 3 | 4 | block wloadblock (unsigned char *data) 5 | { 6 | block ptr; 7 | block orig = NULL; 8 | 9 | short *shortdata = (short *)data; 10 | unsigned int width, height, size; 11 | 12 | if (data == NULL) { 13 | return NULL; 14 | } 15 | 16 | width = *shortdata; 17 | shortdata ++; 18 | data += 2; 19 | height = *shortdata; 20 | shortdata ++; 21 | data += 2; 22 | 23 | size = 4 * (width * height) + 12; 24 | 25 | if (size > 12) 26 | { 27 | ptr = malloc (size); 28 | if (ptr == NULL) 29 | return NULL; 30 | orig = ptr; 31 | 32 | /* store width and height */ 33 | *ptr++ = width; 34 | *ptr++ = height; 35 | for (int i=0;i /dev/null 2> /dev/null || true 26 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/lib/multicore.c: -------------------------------------------------------------------------------- 1 | #include "../include/multicore.h" 2 | 3 | void store32(unsigned long address, unsigned long value) 4 | { 5 | *(unsigned long *) address = value; 6 | } 7 | 8 | unsigned long load32(unsigned long address) 9 | { 10 | return *(unsigned long *) address; 11 | } 12 | 13 | void start_core1(void (*func)(void)) 14 | { 15 | store32((unsigned long)&spin_cpu1, (unsigned long)func); 16 | asm volatile ("sev"); 17 | } 18 | 19 | void start_core2(void (*func)(void)) 20 | { 21 | store32((unsigned long)&spin_cpu2, (unsigned long)func); 22 | asm volatile ("sev"); 23 | } 24 | 25 | void start_core3(void (*func)(void)) 26 | { 27 | store32((unsigned long)&spin_cpu3, (unsigned long)func); 28 | asm volatile ("sev"); 29 | } 30 | 31 | void clear_core1(void) 32 | { 33 | store32((unsigned long)&spin_cpu1, 0); 34 | } 35 | 36 | void clear_core2(void) 37 | { 38 | store32((unsigned long)&spin_cpu2, 0); 39 | } 40 | 41 | void clear_core3(void) 42 | { 43 | store32((unsigned long)&spin_cpu3, 0); 44 | } 45 | -------------------------------------------------------------------------------- /part2-building/boot.S: -------------------------------------------------------------------------------- 1 | .section ".text.boot" // Make sure the linker puts this at the start of the kernel image 2 | 3 | .global _start // Execution starts here 4 | 5 | _start: 6 | // Check processor ID is zero (executing on main core), else hang 7 | mrs x1, mpidr_el1 8 | and x1, x1, #3 9 | cbz x1, 2f 10 | // We're not on the main core, so hang in an infinite wait loop 11 | 1: wfe 12 | b 1b 13 | 2: // We're on the main core! 14 | 15 | // Set stack to start below our code 16 | ldr x1, =_start 17 | mov sp, x1 18 | 19 | // Clean the BSS section 20 | ldr x1, =__bss_start // Start address 21 | ldr w2, =__bss_size // Size of the section 22 | 3: cbz w2, 4f // Quit loop if zero 23 | str xzr, [x1], #8 24 | sub w2, w2, #1 25 | cbnz w2, 3b // Loop if non-zero 26 | 27 | // Jump to our main() routine in C (make sure it doesn't return) 28 | 4: bl main 29 | // In case it does return, halt the master core too 30 | b 1b 31 | -------------------------------------------------------------------------------- /part4-miniuart/boot.S: -------------------------------------------------------------------------------- 1 | .section ".text.boot" // Make sure the linker puts this at the start of the kernel image 2 | 3 | .global _start // Execution starts here 4 | 5 | _start: 6 | // Check processor ID is zero (executing on main core), else hang 7 | mrs x1, mpidr_el1 8 | and x1, x1, #3 9 | cbz x1, 2f 10 | // We're not on the main core, so hang in an infinite wait loop 11 | 1: wfe 12 | b 1b 13 | 2: // We're on the main core! 14 | 15 | // Set stack to start below our code 16 | ldr x1, =_start 17 | mov sp, x1 18 | 19 | // Clean the BSS section 20 | ldr x1, =__bss_start // Start address 21 | ldr w2, =__bss_size // Size of the section 22 | 3: cbz w2, 4f // Quit loop if zero 23 | str xzr, [x1], #8 24 | sub w2, w2, #1 25 | cbnz w2, 3b // Loop if non-zero 26 | 27 | // Jump to our main() routine in C (make sure it doesn't return) 28 | 4: bl main 29 | // In case it does return, halt the master core too 30 | b 1b 31 | -------------------------------------------------------------------------------- /part6-breakout/boot.S: -------------------------------------------------------------------------------- 1 | .section ".text.boot" // Make sure the linker puts this at the start of the kernel image 2 | 3 | .global _start // Execution starts here 4 | 5 | _start: 6 | // Check processor ID is zero (executing on main core), else hang 7 | mrs x1, mpidr_el1 8 | and x1, x1, #3 9 | cbz x1, 2f 10 | // We're not on the main core, so hang in an infinite wait loop 11 | 1: wfe 12 | b 1b 13 | 2: // We're on the main core! 14 | 15 | // Set stack to start below our code 16 | ldr x1, =_start 17 | mov sp, x1 18 | 19 | // Clean the BSS section 20 | ldr x1, =__bss_start // Start address 21 | ldr w2, =__bss_size // Size of the section 22 | 3: cbz w2, 4f // Quit loop if zero 23 | str xzr, [x1], #8 24 | sub w2, w2, #1 25 | cbnz w2, 3b // Loop if non-zero 26 | 27 | // Jump to our main() routine in C (make sure it doesn't return) 28 | 4: bl main 29 | // In case it does return, halt the master core too 30 | b 1b 31 | -------------------------------------------------------------------------------- /part9-sound/boot.S: -------------------------------------------------------------------------------- 1 | .section ".text.boot" // Make sure the linker puts this at the start of the kernel image 2 | 3 | .global _start // Execution starts here 4 | 5 | _start: 6 | // Check processor ID is zero (executing on main core), else hang 7 | mrs x1, mpidr_el1 8 | and x1, x1, #3 9 | cbz x1, 2f 10 | // We're not on the main core, so hang in an infinite wait loop 11 | 1: wfe 12 | b 1b 13 | 2: // We're on the main core! 14 | 15 | // Set stack to start below our code 16 | ldr x1, =_start 17 | mov sp, x1 18 | 19 | // Clean the BSS section 20 | ldr x1, =__bss_start // Start address 21 | ldr w2, =__bss_size // Size of the section 22 | 3: cbz w2, 4f // Quit loop if zero 23 | str xzr, [x1], #8 24 | sub w2, w2, #1 25 | cbnz w2, 3b // Loop if non-zero 26 | 27 | // Jump to our main() routine in C (make sure it doesn't return) 28 | 4: bl main 29 | // In case it does return, halt the master core too 30 | b 1b 31 | -------------------------------------------------------------------------------- /part1-bootstrapping/boot.S: -------------------------------------------------------------------------------- 1 | .section ".text.boot" // Make sure the linker puts this at the start of the kernel image 2 | 3 | .global _start // Execution starts here 4 | 5 | _start: 6 | // Check processor ID is zero (executing on main core), else hang 7 | mrs x1, mpidr_el1 8 | and x1, x1, #3 9 | cbz x1, 2f 10 | // We're not on the main core, so hang in an infinite wait loop 11 | 1: wfe 12 | b 1b 13 | 2: // We're on the main core! 14 | 15 | // Set stack to start below our code 16 | ldr x1, =_start 17 | mov sp, x1 18 | 19 | // Clean the BSS section 20 | ldr x1, =__bss_start // Start address 21 | ldr w2, =__bss_size // Size of the section 22 | 3: cbz w2, 4f // Quit loop if zero 23 | str xzr, [x1], #8 24 | sub w2, w2, #1 25 | cbnz w2, 3b // Loop if non-zero 26 | 27 | // Jump to our main() routine in C (make sure it doesn't return) 28 | 4: bl main 29 | // In case it does return, halt the master core too 30 | b 1b 31 | -------------------------------------------------------------------------------- /part3-helloworld/boot.S: -------------------------------------------------------------------------------- 1 | .section ".text.boot" // Make sure the linker puts this at the start of the kernel image 2 | 3 | .global _start // Execution starts here 4 | 5 | _start: 6 | // Check processor ID is zero (executing on main core), else hang 7 | mrs x1, mpidr_el1 8 | and x1, x1, #3 9 | cbz x1, 2f 10 | // We're not on the main core, so hang in an infinite wait loop 11 | 1: wfe 12 | b 1b 13 | 2: // We're on the main core! 14 | 15 | // Set stack to start below our code 16 | ldr x1, =_start 17 | mov sp, x1 18 | 19 | // Clean the BSS section 20 | ldr x1, =__bss_start // Start address 21 | ldr w2, =__bss_size // Size of the section 22 | 3: cbz w2, 4f // Quit loop if zero 23 | str xzr, [x1], #8 24 | sub w2, w2, #1 25 | cbnz w2, 3b // Loop if non-zero 26 | 27 | // Jump to our main() routine in C (make sure it doesn't return) 28 | 4: bl main 29 | // In case it does return, halt the master core too 30 | b 1b 31 | -------------------------------------------------------------------------------- /part5-framebuffer/boot.S: -------------------------------------------------------------------------------- 1 | .section ".text.boot" // Make sure the linker puts this at the start of the kernel image 2 | 3 | .global _start // Execution starts here 4 | 5 | _start: 6 | // Check processor ID is zero (executing on main core), else hang 7 | mrs x1, mpidr_el1 8 | and x1, x1, #3 9 | cbz x1, 2f 10 | // We're not on the main core, so hang in an infinite wait loop 11 | 1: wfe 12 | b 1b 13 | 2: // We're on the main core! 14 | 15 | // Set stack to start below our code 16 | ldr x1, =_start 17 | mov sp, x1 18 | 19 | // Clean the BSS section 20 | ldr x1, =__bss_start // Start address 21 | ldr w2, =__bss_size // Size of the section 22 | 3: cbz w2, 4f // Quit loop if zero 23 | str xzr, [x1], #8 24 | sub w2, w2, #1 25 | cbnz w2, 3b // Loop if non-zero 26 | 27 | // Jump to our main() routine in C (make sure it doesn't return) 28 | 4: bl main 29 | // In case it does return, halt the master core too 30 | b 1b 31 | -------------------------------------------------------------------------------- /part7-bluetooth/boot.S: -------------------------------------------------------------------------------- 1 | .section ".text.boot" // Make sure the linker puts this at the start of the kernel image 2 | 3 | .global _start // Execution starts here 4 | 5 | _start: 6 | // Check processor ID is zero (executing on main core), else hang 7 | mrs x1, mpidr_el1 8 | and x1, x1, #3 9 | cbz x1, 2f 10 | // We're not on the main core, so hang in an infinite wait loop 11 | 1: wfe 12 | b 1b 13 | 2: // We're on the main core! 14 | 15 | // Set stack to start below our code 16 | ldr x1, =_start 17 | mov sp, x1 18 | 19 | // Clean the BSS section 20 | ldr x1, =__bss_start // Start address 21 | ldr w2, =__bss_size // Size of the section 22 | 3: cbz w2, 4f // Quit loop if zero 23 | str xzr, [x1], #8 24 | sub w2, w2, #1 25 | cbnz w2, 3b // Loop if non-zero 26 | 27 | // Jump to our main() routine in C (make sure it doesn't return) 28 | 4: bl main 29 | // In case it does return, halt the master core too 30 | b 1b 31 | -------------------------------------------------------------------------------- /part8-breakout-ble/boot.S: -------------------------------------------------------------------------------- 1 | .section ".text.boot" // Make sure the linker puts this at the start of the kernel image 2 | 3 | .global _start // Execution starts here 4 | 5 | _start: 6 | // Check processor ID is zero (executing on main core), else hang 7 | mrs x1, mpidr_el1 8 | and x1, x1, #3 9 | cbz x1, 2f 10 | // We're not on the main core, so hang in an infinite wait loop 11 | 1: wfe 12 | b 1b 13 | 2: // We're on the main core! 14 | 15 | // Set stack to start below our code 16 | ldr x1, =_start 17 | mov sp, x1 18 | 19 | // Clean the BSS section 20 | ldr x1, =__bss_start // Start address 21 | ldr w2, =__bss_size // Size of the section 22 | 3: cbz w2, 4f // Quit loop if zero 23 | str xzr, [x1], #8 24 | sub w2, w2, #1 25 | cbnz w2, 3b // Loop if non-zero 26 | 27 | // Jump to our main() routine in C (make sure it doesn't return) 28 | 4: bl main 29 | // In case it does return, halt the master core too 30 | b 1b 31 | -------------------------------------------------------------------------------- /part12-wgt/include/mb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern volatile unsigned int mbox[36]; 4 | 5 | enum { 6 | MBOX_REQUEST = 0 7 | }; 8 | 9 | enum { 10 | MBOX_CH_POWER = 0, 11 | MBOX_CH_FB = 1, 12 | MBOX_CH_VUART = 2, 13 | MBOX_CH_VCHIQ = 3, 14 | MBOX_CH_LEDS = 4, 15 | MBOX_CH_BTNS = 5, 16 | MBOX_CH_TOUCH = 6, 17 | MBOX_CH_COUNT = 7, 18 | MBOX_CH_PROP = 8 // Request from ARM for response by VideoCore 19 | }; 20 | 21 | enum { 22 | MBOX_TAG_SETPOWER = 0x28001, 23 | 24 | MBOX_TAG_GETCLKRATE = 0x30002, 25 | MBOX_TAG_GETCLKMAXM = 0x30004, 26 | MBOX_TAG_SETCLKRATE = 0x38002, 27 | 28 | MBOX_TAG_SETPHYWH = 0x48003, 29 | MBOX_TAG_SETVIRTWH = 0x48004, 30 | MBOX_TAG_SETVIRTOFF = 0x48009, 31 | MBOX_TAG_SETDEPTH = 0x48005, 32 | MBOX_TAG_SETPXLORDR = 0x48006, 33 | MBOX_TAG_GETFB = 0x40001, 34 | MBOX_TAG_GETPITCH = 0x40008, 35 | 36 | MBOX_TAG_LAST = 0 37 | }; 38 | 39 | unsigned int mbox_call(unsigned char ch); 40 | int get_max_clock(); 41 | int get_clock_rate(); 42 | int set_clock_rate(unsigned int rate); 43 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wsetcol.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | 3 | void wsetcolor (unsigned int col) 4 | { 5 | currentcolor = col; 6 | } 7 | 8 | void wsetrgb (unsigned char num, unsigned char red, unsigned char green, unsigned char blue, color *pal) 9 | { 10 | if (red > 255) red = 255; /* Check for maximum values */ 11 | if (green > 255) green = 255; 12 | if (blue > 255) blue = 255; 13 | 14 | pal += num; /* Adjust pointer to proper index */ 15 | pal->r = red; /* Set values for RGB */ 16 | pal->g = green; 17 | pal->b = blue; 18 | } 19 | 20 | void wsetpalette (unsigned char start, unsigned char finish, color *pal) 21 | { 22 | for (int i = start; i <= finish; i++) 23 | { 24 | vgapal[i] = rgb(i, pal[i].r, pal[i].g, pal[i].b); 25 | } 26 | } 27 | 28 | void wreadpalette (unsigned char start, unsigned char finish, color *palc) 29 | { 30 | for (int i = start; i <= finish; i++) 31 | { 32 | palc[i].r = (vgapal[i] >> 16) & 0xFF; 33 | palc[i].g = (vgapal[i] >> 8) & 0xFF; 34 | palc[i].b = vgapal[i] & 0xFF; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wvertres.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | 3 | #define fastcopy memcpy 4 | 5 | void wvertres (short x, short y, short y2, block image) 6 | { 7 | short width, height, base, yy, temp; 8 | long fy, ctr2; 9 | long same2, incr2; 10 | 11 | width = wgetblockwidth (image); 12 | height = wgetblockheight (image); /* store width and height */ 13 | 14 | if (y > y2) /* swap y's if needed */ 15 | { 16 | temp = y; 17 | y = y2; 18 | y2 = temp; 19 | } 20 | 21 | incr2 = (float)(y2 - y + 1) / height * 2000; 22 | /* find increment */ 23 | fy = y2; 24 | yy = y; 25 | ctr2 = 0; 26 | same2 = 0; 27 | base = 0; 28 | while (yy <= fy) 29 | { 30 | if (incr2 >= 2000) 31 | while ((same2 - ctr2 > 999) & (yy < fy)) 32 | { 33 | fastcopy (&abuf[(yy)*WGT_SYS.xres + x], &image[(base)*width + 2], 34 | width); 35 | yy ++; 36 | ctr2 += 2000; 37 | } 38 | else 39 | while (same2 < ctr2) 40 | { 41 | same2 += incr2; 42 | base ++; 43 | } 44 | if (yy < fy) 45 | fastcopy (&abuf[(yy)*WGT_SYS.xres + x], &image[(base)*width + 2], 46 | width); 47 | same2 += incr2; 48 | ctr2 += 2000; 49 | base ++; 50 | yy ++; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /part12-wgt/lib/mem.c: -------------------------------------------------------------------------------- 1 | // Define the heap 2 | 3 | extern unsigned char _end[]; 4 | // unsigned char *HEAP_START = &_end[0]; // End of kernel 5 | 6 | unsigned char *HEAP_START = (unsigned char *)0x400000; // Top of stack 7 | unsigned int HEAP_SIZE = 0x30000000; // Max heap size is 768Mb 8 | unsigned char *HEAP_END; 9 | 10 | // Set up some static globals 11 | 12 | static unsigned char *freeptr; 13 | static unsigned int bytes_allocated = 0; 14 | 15 | void mem_init() 16 | { 17 | // Align the start of heap to an 8-byte boundary 18 | 19 | if ((long)HEAP_START % 8 != 0) { 20 | HEAP_START += 8 - ((long)HEAP_START % 8); 21 | } 22 | HEAP_END = (unsigned char *)(HEAP_START + HEAP_SIZE); 23 | 24 | freeptr = HEAP_START; 25 | } 26 | 27 | void *malloc(unsigned int size) 28 | { 29 | if (size > 0) { 30 | void *allocated = freeptr; 31 | if ((long)allocated % 8 != 0) { 32 | allocated += 8 - ((long)allocated % 8); 33 | } 34 | 35 | if ((unsigned char *)(allocated + size) > HEAP_END) { 36 | return 0; 37 | } else { 38 | freeptr += size; 39 | bytes_allocated += size; 40 | 41 | return allocated; 42 | } 43 | } 44 | return 0; 45 | } 46 | 47 | void free(void *ptr) { 48 | // TODO 49 | } 50 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wbox.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | 3 | void wrectangle (short x, short y, short x2, short y2) 4 | { 5 | wline (x, y, x2, y); 6 | wline (x2, y2, x, y2); 7 | wline (x, y, x, y2); 8 | wline (x2, y, x2, y2); 9 | } 10 | 11 | void wbar (short x, short y, short x2, short y2) 12 | { 13 | short ctr,len; 14 | unsigned int *temp; 15 | 16 | if (y2 < y) 17 | { 18 | /* swap y's */ 19 | ctr = y; 20 | y = y2; 21 | y2 = ctr; 22 | } 23 | 24 | if (x2 < x) 25 | { 26 | ctr = x; 27 | x = x2; 28 | x2 = ctr; 29 | } 30 | 31 | if ((y <= by) & (y2 >= ty) & (x <= bx) & (x2 >= tx)) 32 | /* If anything is within clipping */ 33 | { 34 | if (y2 > by) y2 = by; /* Clip bar */ 35 | if (x2 > bx) x2 = bx; 36 | if (y < ty) y = ty; 37 | if (x < tx) x = tx; 38 | 39 | len = x2 - x + 1; /* Find number of pixels to set */ 40 | if (len > 0) 41 | { 42 | temp = &abuf[y*WGT_SYS.xres + x]; 43 | for (ctr = y; ctr <= y2; ctr++) 44 | { 45 | memset (temp, currentcolor, len); 46 | /* Draw a horizontal line */ 47 | temp += WGT_SYS.xres; /* Go to next row */ 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wxor.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | 3 | void wxorbox (short x, short y, short x2, short y2, unsigned char col) 4 | { 5 | short i, j; /* Loop Control */ 6 | block temp; /* Temp pointer to screen */ 7 | 8 | if (y2 < y) 9 | { 10 | /* swap y's */ 11 | i = y; 12 | y = y2; 13 | y2 = i; 14 | } 15 | 16 | if (x2 < x) 17 | { 18 | /* swap x's */ 19 | i = x; 20 | x = x2; 21 | x2 = i; 22 | } 23 | 24 | if (y2 > by) y2 = by; /* Clip box */ 25 | if (x2 > bx) x2 = bx; 26 | if (y < ty) y = ty; 27 | if (x < tx) x = tx; 28 | 29 | temp = &abuf[y*WGT_SYS.xres + x]; /* Move to first offset */ 30 | 31 | for (j = y; j <= y2; j++) 32 | { 33 | for (i = x; i <= x2; i++) 34 | { 35 | /* This can be change to perform any logical operation 36 | on the pixels, such as & or | */ 37 | *temp = vgapal[(*temp >> 24) ^ col]; /* XOR the pixel on screen with col and put it back on screen */ 38 | temp++; /* Go to next pixel */ 39 | } /* x loop */ 40 | temp += (WGT_SYS.xres - 1) - (x2 - x); /* Advance to next row */ 41 | } /* y loop */ 42 | } 43 | -------------------------------------------------------------------------------- /part8-breakout-ble/controller/main.js: -------------------------------------------------------------------------------- 1 | var bleno = require('bleno-mac'); 2 | 3 | var BlenoPrimaryService = bleno.PrimaryService; 4 | 5 | var EchoCharacteristic = require('./characteristic'); 6 | 7 | console.log('bleno - echo'); 8 | 9 | var e = new EchoCharacteristic(); 10 | 11 | bleno.on('stateChange', function(state) { 12 | console.log('on -> stateChange: ' + state); 13 | 14 | if (state === 'poweredOn') { 15 | bleno.startAdvertising('echo', ['ec00']); 16 | } else { 17 | bleno.stopAdvertising(); 18 | } 19 | }); 20 | 21 | bleno.on('advertisingStart', function(error) { 22 | console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success')); 23 | 24 | if (!error) { 25 | bleno.setServices([ 26 | new BlenoPrimaryService({ 27 | uuid: 'ec00', 28 | characteristics: [ 29 | e 30 | ] 31 | }) 32 | ]); 33 | } 34 | }); 35 | 36 | var ioHook = require('iohook'); 37 | 38 | var buf = Buffer.allocUnsafe(1); 39 | var obuf = Buffer.allocUnsafe(1); 40 | const scrwidth = 1440; 41 | const divisor = scrwidth / 100; 42 | 43 | ioHook.on( 'mousemove', event => { 44 | buf.writeUInt8(Math.round(event.x / divisor), 0); 45 | 46 | if (Buffer.compare(buf, obuf)) { 47 | e._value = buf; 48 | if (e._updateValueCallback) e._updateValueCallback(e._value); 49 | buf.copy(obuf); 50 | } 51 | }); 52 | 53 | ioHook.start(); 54 | -------------------------------------------------------------------------------- /part6-breakout/mb.c: -------------------------------------------------------------------------------- 1 | #include "io.h" 2 | 3 | // The buffer must be 16-byte aligned as only the upper 28 bits of the address can be passed via the mailbox 4 | volatile unsigned int __attribute__((aligned(16))) mbox[36]; 5 | 6 | enum { 7 | VIDEOCORE_MBOX = (PERIPHERAL_BASE + 0x0000B880), 8 | MBOX_READ = (VIDEOCORE_MBOX + 0x0), 9 | MBOX_POLL = (VIDEOCORE_MBOX + 0x10), 10 | MBOX_SENDER = (VIDEOCORE_MBOX + 0x14), 11 | MBOX_STATUS = (VIDEOCORE_MBOX + 0x18), 12 | MBOX_CONFIG = (VIDEOCORE_MBOX + 0x1C), 13 | MBOX_WRITE = (VIDEOCORE_MBOX + 0x20), 14 | MBOX_RESPONSE = 0x80000000, 15 | MBOX_FULL = 0x80000000, 16 | MBOX_EMPTY = 0x40000000 17 | }; 18 | 19 | unsigned int mbox_call(unsigned char ch) 20 | { 21 | // 28-bit address (MSB) and 4-bit value (LSB) 22 | unsigned int r = ((unsigned int)((long) &mbox) &~ 0xF) | (ch & 0xF); 23 | 24 | // Wait until we can write 25 | while (mmio_read(MBOX_STATUS) & MBOX_FULL); 26 | 27 | // Write the address of our buffer to the mailbox with the channel appended 28 | mmio_write(MBOX_WRITE, r); 29 | 30 | while (1) { 31 | // Is there a reply? 32 | while (mmio_read(MBOX_STATUS) & MBOX_EMPTY); 33 | 34 | // Is it a reply to our message? 35 | if (r == mmio_read(MBOX_READ)) return mbox[1]==MBOX_RESPONSE; // Is it successful? 36 | 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /part9-sound/mb.c: -------------------------------------------------------------------------------- 1 | #include "io.h" 2 | 3 | // The buffer must be 16-byte aligned as only the upper 28 bits of the address can be passed via the mailbox 4 | volatile unsigned int __attribute__((aligned(16))) mbox[36]; 5 | 6 | enum { 7 | VIDEOCORE_MBOX = (PERIPHERAL_BASE + 0x0000B880), 8 | MBOX_READ = (VIDEOCORE_MBOX + 0x0), 9 | MBOX_POLL = (VIDEOCORE_MBOX + 0x10), 10 | MBOX_SENDER = (VIDEOCORE_MBOX + 0x14), 11 | MBOX_STATUS = (VIDEOCORE_MBOX + 0x18), 12 | MBOX_CONFIG = (VIDEOCORE_MBOX + 0x1C), 13 | MBOX_WRITE = (VIDEOCORE_MBOX + 0x20), 14 | MBOX_RESPONSE = 0x80000000, 15 | MBOX_FULL = 0x80000000, 16 | MBOX_EMPTY = 0x40000000 17 | }; 18 | 19 | unsigned int mbox_call(unsigned char ch) 20 | { 21 | // 28-bit address (MSB) and 4-bit value (LSB) 22 | unsigned int r = ((unsigned int)((long) &mbox) &~ 0xF) | (ch & 0xF); 23 | 24 | // Wait until we can write 25 | while (mmio_read(MBOX_STATUS) & MBOX_FULL); 26 | 27 | // Write the address of our buffer to the mailbox with the channel appended 28 | mmio_write(MBOX_WRITE, r); 29 | 30 | while (1) { 31 | // Is there a reply? 32 | while (mmio_read(MBOX_STATUS) & MBOX_EMPTY); 33 | 34 | // Is it a reply to our message? 35 | if (r == mmio_read(MBOX_READ)) return mbox[1]==MBOX_RESPONSE; // Is it successful? 36 | 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /part10-multicore/mb.c: -------------------------------------------------------------------------------- 1 | #include "io.h" 2 | 3 | // The buffer must be 16-byte aligned as only the upper 28 bits of the address can be passed via the mailbox 4 | volatile unsigned int __attribute__((aligned(16))) mbox[36]; 5 | 6 | enum { 7 | VIDEOCORE_MBOX = (PERIPHERAL_BASE + 0x0000B880), 8 | MBOX_READ = (VIDEOCORE_MBOX + 0x0), 9 | MBOX_POLL = (VIDEOCORE_MBOX + 0x10), 10 | MBOX_SENDER = (VIDEOCORE_MBOX + 0x14), 11 | MBOX_STATUS = (VIDEOCORE_MBOX + 0x18), 12 | MBOX_CONFIG = (VIDEOCORE_MBOX + 0x1C), 13 | MBOX_WRITE = (VIDEOCORE_MBOX + 0x20), 14 | MBOX_RESPONSE = 0x80000000, 15 | MBOX_FULL = 0x80000000, 16 | MBOX_EMPTY = 0x40000000 17 | }; 18 | 19 | unsigned int mbox_call(unsigned char ch) 20 | { 21 | // 28-bit address (MSB) and 4-bit value (LSB) 22 | unsigned int r = ((unsigned int)((long) &mbox) &~ 0xF) | (ch & 0xF); 23 | 24 | // Wait until we can write 25 | while (mmio_read(MBOX_STATUS) & MBOX_FULL); 26 | 27 | // Write the address of our buffer to the mailbox with the channel appended 28 | mmio_write(MBOX_WRITE, r); 29 | 30 | while (1) { 31 | // Is there a reply? 32 | while (mmio_read(MBOX_STATUS) & MBOX_EMPTY); 33 | 34 | // Is it a reply to our message? 35 | if (r == mmio_read(MBOX_READ)) return mbox[1]==MBOX_RESPONSE; // Is it successful? 36 | 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /part5-framebuffer/mb.c: -------------------------------------------------------------------------------- 1 | #include "io.h" 2 | 3 | // The buffer must be 16-byte aligned as only the upper 28 bits of the address can be passed via the mailbox 4 | volatile unsigned int __attribute__((aligned(16))) mbox[36]; 5 | 6 | enum { 7 | VIDEOCORE_MBOX = (PERIPHERAL_BASE + 0x0000B880), 8 | MBOX_READ = (VIDEOCORE_MBOX + 0x0), 9 | MBOX_POLL = (VIDEOCORE_MBOX + 0x10), 10 | MBOX_SENDER = (VIDEOCORE_MBOX + 0x14), 11 | MBOX_STATUS = (VIDEOCORE_MBOX + 0x18), 12 | MBOX_CONFIG = (VIDEOCORE_MBOX + 0x1C), 13 | MBOX_WRITE = (VIDEOCORE_MBOX + 0x20), 14 | MBOX_RESPONSE = 0x80000000, 15 | MBOX_FULL = 0x80000000, 16 | MBOX_EMPTY = 0x40000000 17 | }; 18 | 19 | unsigned int mbox_call(unsigned char ch) 20 | { 21 | // 28-bit address (MSB) and 4-bit value (LSB) 22 | unsigned int r = ((unsigned int)((long) &mbox) &~ 0xF) | (ch & 0xF); 23 | 24 | // Wait until we can write 25 | while (mmio_read(MBOX_STATUS) & MBOX_FULL); 26 | 27 | // Write the address of our buffer to the mailbox with the channel appended 28 | mmio_write(MBOX_WRITE, r); 29 | 30 | while (1) { 31 | // Is there a reply? 32 | while (mmio_read(MBOX_STATUS) & MBOX_EMPTY); 33 | 34 | // Is it a reply to our message? 35 | if (r == mmio_read(MBOX_READ)) return mbox[1]==MBOX_RESPONSE; // Is it successful? 36 | 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /part7-bluetooth/mb.c: -------------------------------------------------------------------------------- 1 | #include "io.h" 2 | 3 | // The buffer must be 16-byte aligned as only the upper 28 bits of the address can be passed via the mailbox 4 | volatile unsigned int __attribute__((aligned(16))) mbox[36]; 5 | 6 | enum { 7 | VIDEOCORE_MBOX = (PERIPHERAL_BASE + 0x0000B880), 8 | MBOX_READ = (VIDEOCORE_MBOX + 0x0), 9 | MBOX_POLL = (VIDEOCORE_MBOX + 0x10), 10 | MBOX_SENDER = (VIDEOCORE_MBOX + 0x14), 11 | MBOX_STATUS = (VIDEOCORE_MBOX + 0x18), 12 | MBOX_CONFIG = (VIDEOCORE_MBOX + 0x1C), 13 | MBOX_WRITE = (VIDEOCORE_MBOX + 0x20), 14 | MBOX_RESPONSE = 0x80000000, 15 | MBOX_FULL = 0x80000000, 16 | MBOX_EMPTY = 0x40000000 17 | }; 18 | 19 | unsigned int mbox_call(unsigned char ch) 20 | { 21 | // 28-bit address (MSB) and 4-bit value (LSB) 22 | unsigned int r = ((unsigned int)((long) &mbox) &~ 0xF) | (ch & 0xF); 23 | 24 | // Wait until we can write 25 | while (mmio_read(MBOX_STATUS) & MBOX_FULL); 26 | 27 | // Write the address of our buffer to the mailbox with the channel appended 28 | mmio_write(MBOX_WRITE, r); 29 | 30 | while (1) { 31 | // Is there a reply? 32 | while (mmio_read(MBOX_STATUS) & MBOX_EMPTY); 33 | 34 | // Is it a reply to our message? 35 | if (r == mmio_read(MBOX_READ)) return mbox[1]==MBOX_RESPONSE; // Is it successful? 36 | 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /part8-breakout-ble/mb.c: -------------------------------------------------------------------------------- 1 | #include "io.h" 2 | 3 | // The buffer must be 16-byte aligned as only the upper 28 bits of the address can be passed via the mailbox 4 | volatile unsigned int __attribute__((aligned(16))) mbox[36]; 5 | 6 | enum { 7 | VIDEOCORE_MBOX = (PERIPHERAL_BASE + 0x0000B880), 8 | MBOX_READ = (VIDEOCORE_MBOX + 0x0), 9 | MBOX_POLL = (VIDEOCORE_MBOX + 0x10), 10 | MBOX_SENDER = (VIDEOCORE_MBOX + 0x14), 11 | MBOX_STATUS = (VIDEOCORE_MBOX + 0x18), 12 | MBOX_CONFIG = (VIDEOCORE_MBOX + 0x1C), 13 | MBOX_WRITE = (VIDEOCORE_MBOX + 0x20), 14 | MBOX_RESPONSE = 0x80000000, 15 | MBOX_FULL = 0x80000000, 16 | MBOX_EMPTY = 0x40000000 17 | }; 18 | 19 | unsigned int mbox_call(unsigned char ch) 20 | { 21 | // 28-bit address (MSB) and 4-bit value (LSB) 22 | unsigned int r = ((unsigned int)((long) &mbox) &~ 0xF) | (ch & 0xF); 23 | 24 | // Wait until we can write 25 | while (mmio_read(MBOX_STATUS) & MBOX_FULL); 26 | 27 | // Write the address of our buffer to the mailbox with the channel appended 28 | mmio_write(MBOX_WRITE, r); 29 | 30 | while (1) { 31 | // Is there a reply? 32 | while (mmio_read(MBOX_STATUS) & MBOX_EMPTY); 33 | 34 | // Is it a reply to our message? 35 | if (r == mmio_read(MBOX_READ)) return mbox[1]==MBOX_RESPONSE; // Is it successful? 36 | 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /part11-breakout-smp/lib/mb.c: -------------------------------------------------------------------------------- 1 | #include "../include/io.h" 2 | 3 | // The buffer must be 16-byte aligned as only the upper 28 bits of the address can be passed via the mailbox 4 | volatile unsigned int __attribute__((aligned(16))) mbox[36]; 5 | 6 | enum { 7 | VIDEOCORE_MBOX = (PERIPHERAL_BASE + 0x0000B880), 8 | MBOX_READ = (VIDEOCORE_MBOX + 0x0), 9 | MBOX_POLL = (VIDEOCORE_MBOX + 0x10), 10 | MBOX_SENDER = (VIDEOCORE_MBOX + 0x14), 11 | MBOX_STATUS = (VIDEOCORE_MBOX + 0x18), 12 | MBOX_CONFIG = (VIDEOCORE_MBOX + 0x1C), 13 | MBOX_WRITE = (VIDEOCORE_MBOX + 0x20), 14 | MBOX_RESPONSE = 0x80000000, 15 | MBOX_FULL = 0x80000000, 16 | MBOX_EMPTY = 0x40000000 17 | }; 18 | 19 | unsigned int mbox_call(unsigned char ch) 20 | { 21 | // 28-bit address (MSB) and 4-bit value (LSB) 22 | unsigned int r = ((unsigned int)((long) &mbox) &~ 0xF) | (ch & 0xF); 23 | 24 | // Wait until we can write 25 | while (mmio_read(MBOX_STATUS) & MBOX_FULL); 26 | 27 | // Write the address of our buffer to the mailbox with the channel appended 28 | mmio_write(MBOX_WRITE, r); 29 | 30 | while (1) { 31 | // Is there a reply? 32 | while (mmio_read(MBOX_STATUS) & MBOX_EMPTY); 33 | 34 | // Is it a reply to our message? 35 | if (r == mmio_read(MBOX_READ)) return mbox[1]==MBOX_RESPONSE; // Is it successful? 36 | 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /part13-interrupts/lib/mb.c: -------------------------------------------------------------------------------- 1 | #include "../include/io.h" 2 | 3 | // The buffer must be 16-byte aligned as only the upper 28 bits of the address can be passed via the mailbox 4 | volatile unsigned int __attribute__((aligned(16))) mbox[36]; 5 | 6 | enum { 7 | VIDEOCORE_MBOX = (PERIPHERAL_BASE + 0x0000B880), 8 | MBOX_READ = (VIDEOCORE_MBOX + 0x0), 9 | MBOX_POLL = (VIDEOCORE_MBOX + 0x10), 10 | MBOX_SENDER = (VIDEOCORE_MBOX + 0x14), 11 | MBOX_STATUS = (VIDEOCORE_MBOX + 0x18), 12 | MBOX_CONFIG = (VIDEOCORE_MBOX + 0x1C), 13 | MBOX_WRITE = (VIDEOCORE_MBOX + 0x20), 14 | MBOX_RESPONSE = 0x80000000, 15 | MBOX_FULL = 0x80000000, 16 | MBOX_EMPTY = 0x40000000 17 | }; 18 | 19 | unsigned int mbox_call(unsigned char ch) 20 | { 21 | // 28-bit address (MSB) and 4-bit value (LSB) 22 | unsigned int r = ((unsigned int)((long) &mbox) &~ 0xF) | (ch & 0xF); 23 | 24 | // Wait until we can write 25 | while (mmio_read(MBOX_STATUS) & MBOX_FULL); 26 | 27 | // Write the address of our buffer to the mailbox with the channel appended 28 | mmio_write(MBOX_WRITE, r); 29 | 30 | while (1) { 31 | // Is there a reply? 32 | while (mmio_read(MBOX_STATUS) & MBOX_EMPTY); 33 | 34 | // Is it a reply to our message? 35 | if (r == mmio_read(MBOX_READ)) return mbox[1]==MBOX_RESPONSE; // Is it successful? 36 | 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /part14-spi-ethernet/lib/mb.c: -------------------------------------------------------------------------------- 1 | #include "../include/io.h" 2 | 3 | // The buffer must be 16-byte aligned as only the upper 28 bits of the address can be passed via the mailbox 4 | volatile unsigned int __attribute__((aligned(16))) mbox[36]; 5 | 6 | enum { 7 | VIDEOCORE_MBOX = (PERIPHERAL_BASE + 0x0000B880), 8 | MBOX_READ = (VIDEOCORE_MBOX + 0x0), 9 | MBOX_POLL = (VIDEOCORE_MBOX + 0x10), 10 | MBOX_SENDER = (VIDEOCORE_MBOX + 0x14), 11 | MBOX_STATUS = (VIDEOCORE_MBOX + 0x18), 12 | MBOX_CONFIG = (VIDEOCORE_MBOX + 0x1C), 13 | MBOX_WRITE = (VIDEOCORE_MBOX + 0x20), 14 | MBOX_RESPONSE = 0x80000000, 15 | MBOX_FULL = 0x80000000, 16 | MBOX_EMPTY = 0x40000000 17 | }; 18 | 19 | unsigned int mbox_call(unsigned char ch) 20 | { 21 | // 28-bit address (MSB) and 4-bit value (LSB) 22 | unsigned int r = ((unsigned int)((long) &mbox) &~ 0xF) | (ch & 0xF); 23 | 24 | // Wait until we can write 25 | while (mmio_read(MBOX_STATUS) & MBOX_FULL); 26 | 27 | // Write the address of our buffer to the mailbox with the channel appended 28 | mmio_write(MBOX_WRITE, r); 29 | 30 | while (1) { 31 | // Is there a reply? 32 | while (mmio_read(MBOX_STATUS) & MBOX_EMPTY); 33 | 34 | // Is it a reply to our message? 35 | if (r == mmio_read(MBOX_READ)) return mbox[1]==MBOX_RESPONSE; // Is it successful? 36 | 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /part13-interrupts/kernel/kernel.h: -------------------------------------------------------------------------------- 1 | #define PERIPHERAL_BASE 0xFE000000 2 | #define CLOCKHZ 1000000 3 | 4 | struct timer_regs { 5 | volatile unsigned int control_status; 6 | volatile unsigned int counter_lo; 7 | volatile unsigned int counter_hi; 8 | volatile unsigned int compare[4]; 9 | }; 10 | 11 | #define REGS_TIMER ((struct timer_regs *)(PERIPHERAL_BASE + 0x00003000)) 12 | 13 | struct arm_irq_regs_2711 { 14 | volatile unsigned int irq0_pending_0; 15 | volatile unsigned int irq0_pending_1; 16 | volatile unsigned int irq0_pending_2; 17 | volatile unsigned int res0; 18 | volatile unsigned int irq0_enable_0; 19 | volatile unsigned int irq0_enable_1; 20 | volatile unsigned int irq0_enable_2; 21 | volatile unsigned int res1; 22 | volatile unsigned int irq0_disable_0; 23 | volatile unsigned int irq0_disable_1; 24 | volatile unsigned int irq0_disable_2; 25 | }; 26 | 27 | typedef struct arm_irq_regs_2711 arm_irq_regs; 28 | 29 | #define REGS_IRQ ((arm_irq_regs *)(PERIPHERAL_BASE + 0x0000B200)) 30 | 31 | enum vc_irqs { 32 | SYS_TIMER_IRQ_0 = 1, 33 | SYS_TIMER_IRQ_1 = 2, 34 | SYS_TIMER_IRQ_2 = 4, 35 | SYS_TIMER_IRQ_3 = 8, 36 | AUX_IRQ = (1 << 29) 37 | }; 38 | 39 | void irq_init_vectors(); 40 | void irq_enable(); 41 | void irq_disable(); 42 | void enable_interrupt_controller(); 43 | void disable_interrupt_controller(); 44 | 45 | void handle_timer_1(); 46 | void handle_timer_3(); 47 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/lib/mb.c: -------------------------------------------------------------------------------- 1 | #include "../include/io.h" 2 | 3 | // The buffer must be 16-byte aligned as only the upper 28 bits of the address can be passed via the mailbox 4 | volatile unsigned int __attribute__((aligned(16))) mbox[36]; 5 | 6 | enum { 7 | VIDEOCORE_MBOX = (PERIPHERAL_BASE + 0x0000B880), 8 | MBOX_READ = (VIDEOCORE_MBOX + 0x0), 9 | MBOX_POLL = (VIDEOCORE_MBOX + 0x10), 10 | MBOX_SENDER = (VIDEOCORE_MBOX + 0x14), 11 | MBOX_STATUS = (VIDEOCORE_MBOX + 0x18), 12 | MBOX_CONFIG = (VIDEOCORE_MBOX + 0x1C), 13 | MBOX_WRITE = (VIDEOCORE_MBOX + 0x20), 14 | MBOX_RESPONSE = 0x80000000, 15 | MBOX_FULL = 0x80000000, 16 | MBOX_EMPTY = 0x40000000 17 | }; 18 | 19 | unsigned int mbox_call(unsigned char ch) 20 | { 21 | // 28-bit address (MSB) and 4-bit value (LSB) 22 | unsigned int r = ((unsigned int)((long) &mbox) &~ 0xF) | (ch & 0xF); 23 | 24 | // Wait until we can write 25 | while (mmio_read(MBOX_STATUS) & MBOX_FULL); 26 | 27 | // Write the address of our buffer to the mailbox with the channel appended 28 | mmio_write(MBOX_WRITE, r); 29 | 30 | while (1) { 31 | // Is there a reply? 32 | while (mmio_read(MBOX_STATUS) & MBOX_EMPTY); 33 | 34 | // Is it a reply to our message? 35 | if (r == mmio_read(MBOX_READ)) return mbox[1]==MBOX_RESPONSE; // Is it successful? 36 | 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wwipe.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | 3 | void wwipe (short x, short y, short x2, short y2, block image) 4 | { 5 | short t, distance; 6 | short wx, wy, dx, dy, bdx, bdy, incx, incy; 7 | unsigned int col; 8 | short swidth; 9 | 10 | swidth = wgetblockwidth (image); 11 | 12 | /* Do the line formula */ 13 | dx = x2 - x; 14 | dy = y2 - y; 15 | t = 0; wx = 0; wy = 0; 16 | if (dy < 0) incy = - 1; else incy = 1; 17 | if (dx < 0) incx = - 1; else incx = 1; 18 | bdx = abs (dx); 19 | bdy = abs (dy); 20 | if (bdx > bdy) distance = bdx; 21 | else distance = bdy; 22 | if (distance == bdx) 23 | { 24 | while (t <= distance) 25 | { 26 | if ((x >= tx) & (y >= ty) & (y <= by) & (x <= bx)) 27 | /* inside clipping? */ 28 | { 29 | col = image[y * swidth + x + 2]; 30 | /* get the colour */ 31 | abuf[y * WGT_SYS.xres + x] = col; 32 | /* put the pixel */ 33 | } 34 | wy += bdy; 35 | x += incx; 36 | t++; 37 | if (wy >= distance) 38 | { 39 | wy -= distance; 40 | y += incy; 41 | } 42 | } 43 | } 44 | else 45 | { 46 | while (t <= distance) 47 | { 48 | if ((x >= tx) & (y >= ty) & (y <= by) & (x <= bx)) 49 | { 50 | col = image[y * swidth + x + 2]; 51 | abuf[y*WGT_SYS.xres + x] = col; 52 | } 53 | wx += bdx; 54 | if (wx >= distance) 55 | { 56 | wx -= distance; 57 | x += incx; 58 | } 59 | y += incy; 60 | t++; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wticker.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | #include "../include/multicore.h" 3 | 4 | short ticker_speed, ticker_running; 5 | unsigned int ticker_interval; 6 | void (*ticker_routine)(); 7 | 8 | void twait(unsigned int n) 9 | { 10 | register unsigned long f, t, r; 11 | 12 | // Get the current counter frequency 13 | asm volatile ("mrs %0, cntfrq_el0" : "=r"(f)); 14 | // Read the current counter 15 | asm volatile ("mrs %0, cntpct_el0" : "=r"(t)); 16 | // Calculate expire value for counter 17 | t+=((f/1000)*n)/1000; 18 | do{asm volatile ("mrs %0, cntpct_el0" : "=r"(r));}while(r= 0; tmp--) 34 | { 35 | sumx = combi[tmp]* rawpts[tmp].x + quot* sumx; 36 | sumy = combi[tmp]* rawpts[tmp].y + quot* sumy; 37 | } 38 | } 39 | else 40 | { 41 | quot = prod = temp; 42 | for (tmp = 1; tmp < numraw; tmp++) 43 | prod *= quot; 44 | 45 | quot = (1.0 - temp) / quot; 46 | sumx = rawpts[0].x; 47 | sumy = rawpts[0].y; 48 | for (tmp = 1; tmp <= numraw; tmp++) 49 | { 50 | sumx = combi[tmp]* rawpts[tmp].x + quot* sumx; 51 | sumy = combi[tmp]* rawpts[tmp].y + quot* sumy; 52 | } 53 | } 54 | curvepts[count].x = (sumx*prod); 55 | curvepts[count].y = (sumy*prod); 56 | } 57 | 58 | free (combi); 59 | } 60 | -------------------------------------------------------------------------------- /part12-wgt/controller-node/characteristic.js: -------------------------------------------------------------------------------- 1 | var util = require('util'); 2 | 3 | var bleno = require('bleno-mac'); 4 | 5 | var BlenoCharacteristic = bleno.Characteristic; 6 | 7 | var EchoCharacteristic = function() { 8 | EchoCharacteristic.super_.call(this, { 9 | uuid: 'ec0e', 10 | properties: ['read', 'write', 'notify'], 11 | value: null 12 | }); 13 | 14 | this._value = new Buffer(0); 15 | this._updateValueCallback = null; 16 | }; 17 | 18 | util.inherits(EchoCharacteristic, BlenoCharacteristic); 19 | 20 | EchoCharacteristic.prototype.onReadRequest = function(offset, callback) { 21 | console.log('EchoCharacteristic - onReadRequest: value = ' + this._value.toString('hex')); 22 | 23 | callback(this.RESULT_SUCCESS, this._value); 24 | }; 25 | 26 | EchoCharacteristic.prototype.onWriteRequest = function(data, offset, withoutResponse, callback) { 27 | this._value = data; 28 | 29 | console.log('EchoCharacteristic - onWriteRequest: value = ' + this._value.toString('hex')); 30 | 31 | if (this._updateValueCallback) { 32 | console.log('EchoCharacteristic - onWriteRequest: notifying'); 33 | 34 | this._updateValueCallback(this._value); 35 | } 36 | 37 | callback(this.RESULT_SUCCESS); 38 | }; 39 | 40 | EchoCharacteristic.prototype.onSubscribe = function(maxValueSize, updateValueCallback) { 41 | console.log('EchoCharacteristic - onSubscribe'); 42 | 43 | this._updateValueCallback = updateValueCallback; 44 | }; 45 | 46 | EchoCharacteristic.prototype.onUnsubscribe = function() { 47 | console.log('EchoCharacteristic - onUnsubscribe'); 48 | 49 | this._updateValueCallback = null; 50 | }; 51 | 52 | module.exports = EchoCharacteristic; 53 | -------------------------------------------------------------------------------- /part8-breakout-ble/controller/characteristic.js: -------------------------------------------------------------------------------- 1 | var util = require('util'); 2 | 3 | var bleno = require('bleno-mac'); 4 | 5 | var BlenoCharacteristic = bleno.Characteristic; 6 | 7 | var EchoCharacteristic = function() { 8 | EchoCharacteristic.super_.call(this, { 9 | uuid: 'ec0e', 10 | properties: ['read', 'write', 'notify'], 11 | value: null 12 | }); 13 | 14 | this._value = new Buffer(0); 15 | this._updateValueCallback = null; 16 | }; 17 | 18 | util.inherits(EchoCharacteristic, BlenoCharacteristic); 19 | 20 | EchoCharacteristic.prototype.onReadRequest = function(offset, callback) { 21 | console.log('EchoCharacteristic - onReadRequest: value = ' + this._value.toString('hex')); 22 | 23 | callback(this.RESULT_SUCCESS, this._value); 24 | }; 25 | 26 | EchoCharacteristic.prototype.onWriteRequest = function(data, offset, withoutResponse, callback) { 27 | this._value = data; 28 | 29 | console.log('EchoCharacteristic - onWriteRequest: value = ' + this._value.toString('hex')); 30 | 31 | if (this._updateValueCallback) { 32 | console.log('EchoCharacteristic - onWriteRequest: notifying'); 33 | 34 | this._updateValueCallback(this._value); 35 | } 36 | 37 | callback(this.RESULT_SUCCESS); 38 | }; 39 | 40 | EchoCharacteristic.prototype.onSubscribe = function(maxValueSize, updateValueCallback) { 41 | console.log('EchoCharacteristic - onSubscribe'); 42 | 43 | this._updateValueCallback = updateValueCallback; 44 | }; 45 | 46 | EchoCharacteristic.prototype.onUnsubscribe = function() { 47 | console.log('EchoCharacteristic - onUnsubscribe'); 48 | 49 | this._updateValueCallback = null; 50 | }; 51 | 52 | module.exports = EchoCharacteristic; 53 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wflipb.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | #include "../include/mem.h" 3 | 4 | #define fastcopy memcpy 5 | 6 | void wflipblock (block image, short direction) 7 | { 8 | int width,height; 9 | int ctr,ctr2; 10 | block temp, temp2; 11 | unsigned int *pr2; 12 | 13 | width = wgetblockwidth (image); /* Find width and height of block */ 14 | height = wgetblockheight (image); 15 | temp = malloc (width*4); 16 | temp2 = malloc (width*4); 17 | image += 2; 18 | 19 | if (direction == 1) /* Horizontal flip */ 20 | { 21 | for (ctr = 1; ctr <= height; ctr++) 22 | /* Use each row */ 23 | { 24 | fastcopy (temp, image, width); 25 | /* Copy row to buffer */ 26 | 27 | for (ctr2 = 0; ctr2 <= width - 1; ctr2++) 28 | temp2[width - 1 - ctr2] = temp[ctr2]; 29 | /* Reverse elements 30 | to another buffer */ 31 | 32 | fastcopy (image, temp2, width); /* Copy back to original block */ 33 | image += width; /* Advance pr to next row */ 34 | } 35 | } 36 | else if (direction == 0) /* Vertical flip */ 37 | { 38 | pr2 = image + (height*width) - width; /* pr2 points to last row */ 39 | for (ctr = 1; ctr <= (height / 2); ctr++) 40 | /* Only flip halfway */ 41 | { 42 | fastcopy (temp, image, width); /* Get row of image data */ 43 | fastcopy (image, pr2, width); /* Copy last row to first */ 44 | fastcopy (pr2, temp, width); /* Put first row on last */ 45 | image += width; /* Move to next row */ 46 | pr2 -= width; /* Decrement last row */ 47 | } 48 | } 49 | free (temp); 50 | free (temp2); 51 | } 52 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt45.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | 4 | // ######## REQUIRED FUNCTIONS ######## 5 | 6 | unsigned long state0 = 1000; 7 | unsigned long state1 = 2000; 8 | 9 | unsigned long rand(void) 10 | { 11 | unsigned long s1 = state0; 12 | unsigned long s0 = state1; 13 | 14 | state0 = s0; 15 | s1 ^= s1 << 23; 16 | s1 ^= s1 >> 17; 17 | s1 ^= s0; 18 | s1 ^= s0 >> 26; 19 | state1 = s1; 20 | 21 | return state0 + state1; 22 | } 23 | 24 | // ######## STUB FUNCTIONS ######## 25 | 26 | unsigned int kb = 0; 27 | 28 | unsigned int kbhit(void) { 29 | kb++; 30 | return kb / 500; 31 | } 32 | 33 | void getch(void) { 34 | wait_msec(0x500000); 35 | kb = 0; 36 | } 37 | 38 | // ######## WGT EXAMPLES ######## 39 | 40 | void wgt45() 41 | { 42 | block sprites[10]; /* An array of blocks to load the sprites into. 43 | Version 5.0 allows for any number to be 44 | loaded in, as long as you pass the same size 45 | of the array to the wloadsprites and wfreesprites 46 | commands. */ 47 | short i; 48 | color palette[256]; 49 | 50 | set_clock_rate(get_max_clock()); 51 | mem_init(); 52 | vga256 (); /* Initializes WGT system */ 53 | 54 | extern unsigned char _binary_bin_space_spr_start[]; 55 | wloadsprites (palette, &_binary_bin_space_spr_start[0], sprites, 0, 9); 56 | /* loads the first 10 sprites */ 57 | wsetpalette (0, 255, palette); 58 | 59 | for (i = 0; i < 10; i++) /* Display them */ 60 | wputblock (i * 30, 0, sprites[i], NORMAL); 61 | } 62 | 63 | void main() 64 | { 65 | wgt45(); 66 | while (1); 67 | } 68 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/tcpip/ip_config.h: -------------------------------------------------------------------------------- 1 | /********************************************* 2 | * vim:sw=8:ts=8:si:et 3 | * To use the above modeline in vim you must have "set modeline" in your .vimrc 4 | * Author: Guido Socher 5 | * Copyright:LGPL V2 6 | * See http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html 7 | * 8 | * This file can be used to decide which functionallity of the 9 | * TCP/IP stack shall be available. By picking the right functions 10 | * you can significantly reduce the size of the resulting code. 11 | * 12 | *********************************************/ 13 | //@{ 14 | #ifndef IP_CONFIG_H 15 | #define IP_CONFIG_H 16 | 17 | //------------- functions in ip_arp_udp_tcp.c -------------- 18 | // an NTP client (ntp clock): 19 | #undef NTP_client 20 | // a spontanious sending UDP client (needed as well for DNS and DHCP) 21 | #undef UDP_client 22 | // a server answering to UDP messages 23 | #define UDP_server 24 | // a web server 25 | #define WWW_server 26 | 27 | // to send out a ping: 28 | #undef PING_client 29 | #define PINGPATTERN 0x42 30 | 31 | // a UDP wake on lan sender: 32 | #undef WOL_client 33 | 34 | // function to send a gratuitous arp 35 | #undef GRATARP 36 | 37 | // a "web browser". This can be use to upload data 38 | // to a web server on the internet by encoding the data 39 | // into the url (like a Form action of type GET): 40 | #undef WWW_client 41 | // if you do not need a browser and just a server: 42 | //#undef WWW_client 43 | // 44 | //------------- functions in websrv_help_functions.c -------------- 45 | // 46 | // functions to decode cgi-form data: 47 | #undef FROMDECODE_websrv_help 48 | 49 | // function to encode a URL (mostly needed for a web client) 50 | #undef URLENCODE_websrv_help 51 | 52 | #endif /* IP_CONFIG_H */ 53 | //@} 54 | -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | NSBluetoothAlwaysUsageDescription 38 | Sending control information to the Raspberry Pi 4 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt46.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | 4 | // ######## REQUIRED FUNCTIONS ######## 5 | 6 | unsigned long state0 = 1000; 7 | unsigned long state1 = 2000; 8 | 9 | unsigned long rand(void) 10 | { 11 | unsigned long s1 = state0; 12 | unsigned long s0 = state1; 13 | 14 | state0 = s0; 15 | s1 ^= s1 << 23; 16 | s1 ^= s1 >> 17; 17 | s1 ^= s0; 18 | s1 ^= s0 >> 26; 19 | state1 = s1; 20 | 21 | return state0 + state1; 22 | } 23 | 24 | // ######## STUB FUNCTIONS ######## 25 | 26 | unsigned int kb = 0; 27 | 28 | unsigned int kbhit(void) { 29 | kb++; 30 | return kb / 500; 31 | } 32 | 33 | void getch(void) { 34 | wait_msec(0x500000); 35 | kb = 0; 36 | } 37 | 38 | // ######## WGT EXAMPLES ######## 39 | 40 | int loopctr; 41 | 42 | void timerctr(void) 43 | { 44 | loopctr++; 45 | } 46 | 47 | void wgt46() 48 | { 49 | short row; 50 | 51 | set_clock_rate(get_max_clock()); 52 | mem_init(); 53 | vga256 (); /* Initializes WGT system */ 54 | wcls (vgapal[0]); /* Clear screen with color 0 */ 55 | 56 | row = 0; /* Start drawing at top row of screen */ 57 | loopctr = 0; 58 | winittimer (); 59 | wstarttimer (timerctr, 100); /* Set timer to 100th of a second accuracy */ 60 | do { 61 | wsetcolor (vgapal[rand () % 256]); /* Pick a random color */ 62 | whline (0, 319, row++); /* Draw the line */ 63 | if (row > 199) /* Loop at end of screen */ 64 | row = 0; 65 | } while (loopctr < 500); 66 | 67 | /* As soon as we reach 500 hundredths of a second (5 secs), end the routine 68 | and reset the video mode */ 69 | wstoptimer (); 70 | wdonetimer (); 71 | } 72 | 73 | void main() 74 | { 75 | wgt46(); 76 | while (1); 77 | } 78 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt21.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | 4 | // ######## REQUIRED FUNCTIONS ######## 5 | 6 | unsigned long state0 = 1000; 7 | unsigned long state1 = 2000; 8 | 9 | unsigned long rand(void) 10 | { 11 | unsigned long s1 = state0; 12 | unsigned long s0 = state1; 13 | 14 | state0 = s0; 15 | s1 ^= s1 << 23; 16 | s1 ^= s1 >> 17; 17 | s1 ^= s0; 18 | s1 ^= s0 >> 26; 19 | state1 = s1; 20 | 21 | return state0 + state1; 22 | } 23 | 24 | // ######## STUB FUNCTIONS ######## 25 | 26 | unsigned int kb = 0; 27 | 28 | unsigned int kbhit(void) { 29 | kb++; 30 | return kb / 500; 31 | } 32 | 33 | void getch(void) { 34 | wait_msec(0x500000); 35 | kb = 0; 36 | } 37 | 38 | // ######## WGT EXAMPLES ######## 39 | 40 | block screen1, screen2; 41 | color pal[256]; 42 | 43 | void crush (block b1, block b2, int dir) 44 | { 45 | int q; 46 | 47 | for (q = 199; q >= 0; q -= dir) 48 | { 49 | wvertres (0, 0, q, b1); 50 | wvertres (0, q, 199, b2); 51 | } 52 | } 53 | 54 | void wgt21() 55 | { 56 | set_clock_rate(get_max_clock()); 57 | mem_init(); 58 | vga256 (); 59 | 60 | extern unsigned char _binary_bin_wgt1_pal_start[]; 61 | wloadpalette (&_binary_bin_wgt1_pal_start[0], pal); 62 | wsetpalette (0, 255, pal); 63 | 64 | extern unsigned char _binary_bin_wgt1_blk_start[]; 65 | screen1 = wloadblock (&_binary_bin_wgt1_blk_start[0]); 66 | 67 | extern unsigned char _binary_bin_wgt2_blk_start[]; 68 | screen2 = wloadblock (&_binary_bin_wgt2_blk_start[0]); 69 | 70 | wputblock (0, 0, screen1, 0); 71 | 72 | do { 73 | crush (screen1, screen2, 2); 74 | crush (screen2, screen1, 2); 75 | } while (1); 76 | 77 | wfreeblock (screen1); /* remember to free that memory */ 78 | wfreeblock (screen2); 79 | } 80 | 81 | void main() 82 | { 83 | wgt21(); 84 | while (1); 85 | } 86 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wsetmode.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | 3 | void vga256(void) 4 | { 5 | mbox[0] = 35*4; // Length of message in bytes 6 | mbox[1] = MBOX_REQUEST; 7 | 8 | mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier 9 | mbox[3] = 8; // Value size in bytes 10 | mbox[4] = 0; 11 | mbox[5] = 1920; // Value(width) 12 | mbox[6] = 1080; // Value(height) 13 | 14 | mbox[7] = MBOX_TAG_SETVIRTWH; 15 | mbox[8] = 8; 16 | mbox[9] = 8; 17 | //mbox[10] = 1920; 18 | //mbox[11] = 1080; 19 | mbox[10] = 320; 20 | mbox[11] = 200; 21 | 22 | mbox[12] = MBOX_TAG_SETVIRTOFF; 23 | mbox[13] = 8; 24 | mbox[14] = 8; 25 | mbox[15] = 0; // Value(x) 26 | mbox[16] = 0; // Value(y) 27 | 28 | mbox[17] = MBOX_TAG_SETDEPTH; 29 | mbox[18] = 4; 30 | mbox[19] = 4; 31 | mbox[20] = 32; // Bits per pixel 32 | 33 | mbox[21] = MBOX_TAG_SETPXLORDR; 34 | mbox[22] = 4; 35 | mbox[23] = 4; 36 | mbox[24] = 1; // RGB 37 | 38 | mbox[25] = MBOX_TAG_GETFB; 39 | mbox[26] = 8; 40 | mbox[27] = 8; 41 | mbox[28] = 4096; // FrameBufferInfo.pointer 42 | mbox[29] = 0; // FrameBufferInfo.size 43 | 44 | mbox[30] = MBOX_TAG_GETPITCH; 45 | mbox[31] = 4; 46 | mbox[32] = 4; 47 | mbox[33] = 0; // Bytes per line 48 | 49 | mbox[34] = MBOX_TAG_LAST; 50 | 51 | // Check call is successful and we have a pointer with depth 32 52 | if (mbox_call(MBOX_CH_PROP) && mbox[20] == 32 && mbox[28] != 0) { 53 | mbox[28] &= 0x3FFFFFFF; // Convert GPU address to ARM address 54 | WGT_SYS.xres = mbox[10]; // Actual physical width 55 | WGT_SYS.yres = mbox[11]; // Actual physical height 56 | WGT_SYS.screenwidth = mbox[10]; 57 | WGT_SYS.screenheight = mbox[11]; 58 | 59 | fbuf = (unsigned int *)((long)mbox[28]); 60 | abuf = fbuf; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /part12-wgt/boot/sysregs.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYSREGS_H 2 | #define _SYSREGS_H 3 | 4 | // *************************************** 5 | // SCTLR_EL1, System Control Register (EL1), Page 2654 of AArch64-Reference-Manual. 6 | // *************************************** 7 | 8 | #define SCTLR_RESERVED (3 << 28) | (3 << 22) | (1 << 20) | (1 << 11) 9 | #define SCTLR_EE_LITTLE_ENDIAN (0 << 25) 10 | #define SCTLR_EOE_LITTLE_ENDIAN (0 << 24) 11 | #define SCTLR_I_CACHE_DISABLED (0 << 12) 12 | #define SCTLR_D_CACHE_DISABLED (0 << 2) 13 | #define SCTLR_I_CACHE_ENABLED (1 << 12) 14 | #define SCTLR_D_CACHE_ENABLED (1 << 2) 15 | #define SCTLR_MMU_DISABLED (0 << 0) 16 | #define SCTLR_MMU_ENABLED (1 << 0) 17 | 18 | #define SCTLR_VALUE_MMU_DISABLED (SCTLR_RESERVED | SCTLR_EE_LITTLE_ENDIAN | SCTLR_I_CACHE_ENABLED | SCTLR_D_CACHE_ENABLED | SCTLR_MMU_DISABLED) 19 | 20 | // *************************************** 21 | // HCR_EL2, Hypervisor Configuration Register (EL2), Page 2487 of AArch64-Reference-Manual. 22 | // *************************************** 23 | 24 | #define HCR_RW (1 << 31) 25 | #define HCR_VALUE HCR_RW 26 | 27 | // *************************************** 28 | // SCR_EL3, Secure Configuration Register (EL3), Page 2648 of AArch64-Reference-Manual. 29 | // *************************************** 30 | 31 | #define SCR_RESERVED (3 << 4) 32 | #define SCR_RW (1 << 10) 33 | #define SCR_NS (1 << 0) 34 | #define SCR_VALUE (SCR_RESERVED | SCR_RW | SCR_NS) 35 | 36 | // *************************************** 37 | // SPSR_EL3, Saved Program Status Register (EL3) Page 389 of AArch64-Reference-Manual. 38 | // *************************************** 39 | 40 | #define SPSR_MASK_ALL (7 << 6) 41 | #define SPSR_EL1h (5 << 0) 42 | #define SPSR_VALUE (SPSR_MASK_ALL | SPSR_EL1h) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /part13-interrupts/boot/sysregs.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYSREGS_H 2 | #define _SYSREGS_H 3 | 4 | // *************************************** 5 | // SCTLR_EL1, System Control Register (EL1), Page 2654 of AArch64-Reference-Manual. 6 | // *************************************** 7 | 8 | #define SCTLR_RESERVED (3 << 28) | (3 << 22) | (1 << 20) | (1 << 11) 9 | #define SCTLR_EE_LITTLE_ENDIAN (0 << 25) 10 | #define SCTLR_EOE_LITTLE_ENDIAN (0 << 24) 11 | #define SCTLR_I_CACHE_DISABLED (0 << 12) 12 | #define SCTLR_D_CACHE_DISABLED (0 << 2) 13 | #define SCTLR_I_CACHE_ENABLED (1 << 12) 14 | #define SCTLR_D_CACHE_ENABLED (1 << 2) 15 | #define SCTLR_MMU_DISABLED (0 << 0) 16 | #define SCTLR_MMU_ENABLED (1 << 0) 17 | 18 | #define SCTLR_VALUE_MMU_DISABLED (SCTLR_RESERVED | SCTLR_EE_LITTLE_ENDIAN | SCTLR_I_CACHE_ENABLED | SCTLR_D_CACHE_ENABLED | SCTLR_MMU_DISABLED) 19 | 20 | // *************************************** 21 | // HCR_EL2, Hypervisor Configuration Register (EL2), Page 2487 of AArch64-Reference-Manual. 22 | // *************************************** 23 | 24 | #define HCR_RW (1 << 31) 25 | #define HCR_VALUE HCR_RW 26 | 27 | // *************************************** 28 | // SCR_EL3, Secure Configuration Register (EL3), Page 2648 of AArch64-Reference-Manual. 29 | // *************************************** 30 | 31 | #define SCR_RESERVED (3 << 4) 32 | #define SCR_RW (1 << 10) 33 | #define SCR_NS (1 << 0) 34 | #define SCR_VALUE (SCR_RESERVED | SCR_RW | SCR_NS) 35 | 36 | // *************************************** 37 | // SPSR_EL3, Saved Program Status Register (EL3) Page 389 of AArch64-Reference-Manual. 38 | // *************************************** 39 | 40 | #define SPSR_MASK_ALL (7 << 6) 41 | #define SPSR_EL1h (5 << 0) 42 | #define SPSR_VALUE (SPSR_MASK_ALL | SPSR_EL1h) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt10.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | #include "include/mb.h" 4 | 5 | // ######## REQUIRED FUNCTIONS ######## 6 | 7 | unsigned long state0 = 1000; 8 | unsigned long state1 = 2000; 9 | 10 | unsigned long rand(void) 11 | { 12 | unsigned long s1 = state0; 13 | unsigned long s0 = state1; 14 | 15 | state0 = s0; 16 | s1 ^= s1 << 23; 17 | s1 ^= s1 >> 17; 18 | s1 ^= s0; 19 | s1 ^= s0 >> 26; 20 | state1 = s1; 21 | 22 | return state0 + state1; 23 | } 24 | 25 | // ######## STUB FUNCTIONS ######## 26 | 27 | unsigned int kb = 0; 28 | 29 | unsigned int kbhit(void) { 30 | kb++; 31 | return kb / 500; 32 | } 33 | 34 | void getch(void) { 35 | wait_msec(0x500000); 36 | kb = 0; 37 | } 38 | 39 | // ######## WGT EXAMPLES ######## 40 | 41 | void wgt10() 42 | { 43 | short x,y; 44 | block part1; /* part of the screen */ 45 | 46 | set_clock_rate(get_max_clock()); 47 | mem_init(); 48 | vga256 (); 49 | 50 | for (y = 40; y >= 4; y--) 51 | { 52 | wfill_circle (y + 40, y + 10, y); /* draw a pattern */ 53 | wsetcolor (vgapal[y + 20]); 54 | } 55 | 56 | part1 = wnewblock (0, 0, 160, 100); /* get the circle in a block */ 57 | getch(); 58 | 59 | wcls (0); 60 | 61 | for (x = 0; x < 320; x++) 62 | { 63 | wsetcolor (vgapal[x % 255]); 64 | wline (x, 0, x, 199); 65 | } 66 | 67 | getch(); 68 | 69 | wputblock (160, 0, part1, 0); /* normal mode */ 70 | wflipblock (part1, 0); 71 | 72 | wputblock (160, 100, part1, 1); /* XRAY mode */ 73 | wflipblock (part1, 1); 74 | 75 | wputblock (0, 100, part1, 0); /* normal mode */ 76 | wflipblock (part1, 0); 77 | 78 | wputblock (0, 0, part1, 1); /* XRAY mode */ 79 | 80 | wfreeblock (part1); 81 | } 82 | 83 | void main() 84 | { 85 | wgt10(); 86 | while (1); 87 | } 88 | -------------------------------------------------------------------------------- /part14-spi-ethernet/boot/sysregs.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYSREGS_H 2 | #define _SYSREGS_H 3 | 4 | // *************************************** 5 | // SCTLR_EL1, System Control Register (EL1), Page 2654 of AArch64-Reference-Manual. 6 | // *************************************** 7 | 8 | #define SCTLR_RESERVED (3 << 28) | (3 << 22) | (1 << 20) | (1 << 11) 9 | #define SCTLR_EE_LITTLE_ENDIAN (0 << 25) 10 | #define SCTLR_EOE_LITTLE_ENDIAN (0 << 24) 11 | #define SCTLR_I_CACHE_DISABLED (0 << 12) 12 | #define SCTLR_D_CACHE_DISABLED (0 << 2) 13 | #define SCTLR_I_CACHE_ENABLED (1 << 12) 14 | #define SCTLR_D_CACHE_ENABLED (1 << 2) 15 | #define SCTLR_MMU_DISABLED (0 << 0) 16 | #define SCTLR_MMU_ENABLED (1 << 0) 17 | 18 | #define SCTLR_VALUE_MMU_DISABLED (SCTLR_RESERVED | SCTLR_EE_LITTLE_ENDIAN | SCTLR_I_CACHE_ENABLED | SCTLR_D_CACHE_ENABLED | SCTLR_MMU_DISABLED) 19 | 20 | // *************************************** 21 | // HCR_EL2, Hypervisor Configuration Register (EL2), Page 2487 of AArch64-Reference-Manual. 22 | // *************************************** 23 | 24 | #define HCR_RW (1 << 31) 25 | #define HCR_VALUE HCR_RW 26 | 27 | // *************************************** 28 | // SCR_EL3, Secure Configuration Register (EL3), Page 2648 of AArch64-Reference-Manual. 29 | // *************************************** 30 | 31 | #define SCR_RESERVED (3 << 4) 32 | #define SCR_RW (1 << 10) 33 | #define SCR_NS (1 << 0) 34 | #define SCR_VALUE (SCR_RESERVED | SCR_RW | SCR_NS) 35 | 36 | // *************************************** 37 | // SPSR_EL3, Saved Program Status Register (EL3) Page 389 of AArch64-Reference-Manual. 38 | // *************************************** 39 | 40 | #define SPSR_MASK_ALL (7 << 6) 41 | #define SPSR_EL1h (5 << 0) 42 | #define SPSR_VALUE (SPSR_MASK_ALL | SPSR_EL1h) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /part15-tcpip-webserver/boot/sysregs.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYSREGS_H 2 | #define _SYSREGS_H 3 | 4 | // *************************************** 5 | // SCTLR_EL1, System Control Register (EL1), Page 2654 of AArch64-Reference-Manual. 6 | // *************************************** 7 | 8 | #define SCTLR_RESERVED (3 << 28) | (3 << 22) | (1 << 20) | (1 << 11) 9 | #define SCTLR_EE_LITTLE_ENDIAN (0 << 25) 10 | #define SCTLR_EOE_LITTLE_ENDIAN (0 << 24) 11 | #define SCTLR_I_CACHE_DISABLED (0 << 12) 12 | #define SCTLR_D_CACHE_DISABLED (0 << 2) 13 | #define SCTLR_I_CACHE_ENABLED (1 << 12) 14 | #define SCTLR_D_CACHE_ENABLED (1 << 2) 15 | #define SCTLR_MMU_DISABLED (0 << 0) 16 | #define SCTLR_MMU_ENABLED (1 << 0) 17 | 18 | #define SCTLR_VALUE_MMU_DISABLED (SCTLR_RESERVED | SCTLR_EE_LITTLE_ENDIAN | SCTLR_I_CACHE_ENABLED | SCTLR_D_CACHE_ENABLED | SCTLR_MMU_DISABLED) 19 | 20 | // *************************************** 21 | // HCR_EL2, Hypervisor Configuration Register (EL2), Page 2487 of AArch64-Reference-Manual. 22 | // *************************************** 23 | 24 | #define HCR_RW (1 << 31) 25 | #define HCR_VALUE HCR_RW 26 | 27 | // *************************************** 28 | // SCR_EL3, Secure Configuration Register (EL3), Page 2648 of AArch64-Reference-Manual. 29 | // *************************************** 30 | 31 | #define SCR_RESERVED (3 << 4) 32 | #define SCR_RW (1 << 10) 33 | #define SCR_NS (1 << 0) 34 | #define SCR_VALUE (SCR_RESERVED | SCR_RW | SCR_NS) 35 | 36 | // *************************************** 37 | // SPSR_EL3, Saved Program Status Register (EL3) Page 389 of AArch64-Reference-Manual. 38 | // *************************************** 39 | 40 | #define SPSR_MASK_ALL (7 << 6) 41 | #define SPSR_EL1h (5 << 0) 42 | #define SPSR_VALUE (SPSR_MASK_ALL | SPSR_EL1h) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt08.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | 4 | // ######## REQUIRED FUNCTIONS ######## 5 | 6 | unsigned long state0 = 1000; 7 | unsigned long state1 = 2000; 8 | 9 | unsigned long rand(void) 10 | { 11 | unsigned long s1 = state0; 12 | unsigned long s0 = state1; 13 | 14 | state0 = s0; 15 | s1 ^= s1 << 23; 16 | s1 ^= s1 >> 17; 17 | s1 ^= s0; 18 | s1 ^= s0 >> 26; 19 | state1 = s1; 20 | 21 | return state0 + state1; 22 | } 23 | 24 | // ######## STUB FUNCTIONS ######## 25 | 26 | unsigned int kb = 0; 27 | 28 | unsigned int kbhit(void) { 29 | kb++; 30 | return kb / 500; 31 | } 32 | 33 | void getch(void) { 34 | wait_msec(0x500000); 35 | kb = 0; 36 | } 37 | 38 | // ######## WGT EXAMPLES ######## 39 | 40 | void wgt08() 41 | { 42 | short x; 43 | 44 | mem_init(); 45 | vga256 (); 46 | wcls (vgapal[0]); 47 | 48 | wsetcolor (vgapal[1]); 49 | wcircle (160, 100, 50); /* try filling a circle */ 50 | getch (); 51 | 52 | wsetcolor (vgapal[40]); 53 | wregionfill (160, 100); 54 | wsetcolor (vgapal[170]); 55 | wregionfill (0, 0); 56 | 57 | getch (); 58 | 59 | wcls (vgapal[0]); 60 | for (x = 1; x < 10000; x++) /* try filling 10,000 random pixels */ 61 | { 62 | wsetcolor (vgapal[rand() % 255]); 63 | wputpixel (rand() % 320, rand() % 200); 64 | } 65 | 66 | getch (); 67 | wsetcolor (vgapal[40]); 68 | wclip (50, 50, 250, 150); /* fill works with clipping too! */ 69 | wregionfill (160, 100); 70 | 71 | wsetcolor (vgapal[7]); 72 | wclip (10, 10, 40, 40); 73 | wregionfill (20, 20); 74 | 75 | wsetcolor (vgapal[9]); 76 | wclip (260, 160, 300, 190); 77 | wregionfill (270, 170); 78 | 79 | wsetcolor (vgapal[10]); 80 | wclip (0, 0, 319, 199); 81 | wregionfill (0, 0); 82 | 83 | getch (); 84 | } 85 | 86 | void main() 87 | { 88 | wgt08(); 89 | while (1); 90 | } 91 | -------------------------------------------------------------------------------- /part11-breakout-smp/README.md: -------------------------------------------------------------------------------- 1 | Writing a "bare metal" operating system for Raspberry Pi 4 (Part 11) 2 | ==================================================================== 3 | 4 | [< Go back to part10-multicore](../part10-multicore) 5 | 6 | Putting it all together 7 | ----------------------- 8 | Frankly, I'm unlikely to write much documentation for this part. I'm also only providing a Clang _Makefile_ for now. If you're using gcc, have a go at putting your own _Makefile_ together, referencing the previous parts. 9 | 10 | This part simply builds on the work we've done so far, and delivers a new Breakout codebase with: 11 | 12 | * Gameplay running in the foreground on the main CPU core 0 13 | * Graphics updated in the background on CPU core 1 14 | * Looped 8-bit music playing in the background on CPU core 2 15 | * Bluetooth communications managed in the background on CPU core 3 16 | 17 | I've taken the opportunity to organise the code a little better and so you'll see some changes to the _Makefile_, and a new directory structure in place. Tidy codebase = tidy mind! 18 | 19 | Important takeaway 20 | ------------------ 21 | As you read through this code, you'll maybe notice that a very different style has emerged. Multi-processing adds a dimension of complexity when coding and requires a total mindset shift. 22 | 23 | There's a lot more signalling/semaphores, so the cores can be sure they're doing the right thing at the right time. 24 | 25 | You're no longer "dry-running" a single, sequential thread. You're having to spot the potential for bugs/unexpected behaviour from the interplay of four concurrent threads! 26 | 27 | _Good luck as you explore the code!_ 28 | 29 | Progress video 30 | -------------- 31 | Click to watch a quick video of the game in action. 32 | 33 | https://user-images.githubusercontent.com/68182575/173157526-2b22f9b2-0f55-42a0-87e1-b8278930fefe.mp4 34 | 35 | PS: Sorry for the bad audio quality - the game itself sounds great in real life, I promise! 36 | 37 | [Go to part12-wgt >](../part12-wgt) 38 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt09.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | #include "include/mb.h" 4 | 5 | // ######## REQUIRED FUNCTIONS ######## 6 | 7 | unsigned long state0 = 1000; 8 | unsigned long state1 = 2000; 9 | 10 | unsigned long rand(void) 11 | { 12 | unsigned long s1 = state0; 13 | unsigned long s0 = state1; 14 | 15 | state0 = s0; 16 | s1 ^= s1 << 23; 17 | s1 ^= s1 >> 17; 18 | s1 ^= s0; 19 | s1 ^= s0 >> 26; 20 | state1 = s1; 21 | 22 | return state0 + state1; 23 | } 24 | 25 | // ######## STUB FUNCTIONS ######## 26 | 27 | unsigned int kb = 0; 28 | 29 | unsigned int kbhit(void) { 30 | kb++; 31 | return kb / 500; 32 | } 33 | 34 | void getch(void) { 35 | wait_msec(0x500000); 36 | kb = 0; 37 | } 38 | 39 | // ######## WGT EXAMPLES ######## 40 | 41 | void wgt09() 42 | { 43 | short i, x, y; 44 | block screen1; /* a full screen */ 45 | block part1; /* part of the screen */ 46 | 47 | set_clock_rate(get_max_clock()); 48 | mem_init(); 49 | vga256 (); 50 | 51 | for (i = 1; i < 200; i++) 52 | { 53 | wsetcolor (vgapal[i]); 54 | wline (0, 0, 319, i); 55 | wline (319, 199, 0, 199 - i); 56 | } 57 | 58 | getch(); 59 | 60 | screen1 = wnewblock (0, 0, 319, 199); /* capture the entire screen */ 61 | part1 = wnewblock (0, 0, 150, 150); /* get a part of the screen */ 62 | /* Note that wnewblock allocates the memory for the block */ 63 | 64 | wcls (vgapal[0]); 65 | 66 | do { 67 | x = rand() % 320; 68 | y = rand() % 200; 69 | wputblock (x, y, part1, 0); /* put the part somewhere */ 70 | } while (!kbhit ()); 71 | 72 | getch (); 73 | 74 | wputblock (0, 0, screen1, 0); /* replace the mess with the */ 75 | /* original screen */ 76 | 77 | wfreeblock (screen1); /* *** make sure to free the memory! */ 78 | wfreeblock (part1); 79 | } 80 | 81 | void main() 82 | { 83 | wgt09(); 84 | while (1); 85 | } 86 | -------------------------------------------------------------------------------- /part12-wgt/controller-node/main.js: -------------------------------------------------------------------------------- 1 | var bleno = require('bleno-mac'); 2 | 3 | var BlenoPrimaryService = bleno.PrimaryService; 4 | 5 | var EchoCharacteristic = require('./characteristic'); 6 | 7 | console.log('bleno - echo'); 8 | 9 | var e = new EchoCharacteristic(); 10 | 11 | bleno.on('stateChange', function(state) { 12 | console.log('on -> stateChange: ' + state); 13 | 14 | if (state === 'poweredOn') { 15 | bleno.startAdvertising('echo', ['ec00']); 16 | } else { 17 | bleno.stopAdvertising(); 18 | } 19 | }); 20 | 21 | bleno.on('advertisingStart', function(error) { 22 | console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success')); 23 | 24 | if (!error) { 25 | bleno.setServices([ 26 | new BlenoPrimaryService({ 27 | uuid: 'ec00', 28 | characteristics: [ 29 | e 30 | ] 31 | }) 32 | ]); 33 | } 34 | }); 35 | 36 | var ioHook = require('iohook'); 37 | 38 | var buf = Buffer.allocUnsafe(4); 39 | var obuf = Buffer.allocUnsafe(4); 40 | var buttbuf = Buffer.allocUnsafe(2); 41 | const scrwidth = 1440; 42 | const scrheight = 900; 43 | const divisorx = scrwidth / 320; 44 | const divisory = scrheight / 200; 45 | 46 | ioHook.on( 'mousemove', event => { 47 | buf.writeUInt16LE(Math.round(event.x / divisorx), 0); 48 | buf.writeUInt16LE(Math.round(event.y / divisory), 2); 49 | 50 | if (Buffer.compare(buf, obuf)) { 51 | e._value = buf; 52 | if (e._updateValueCallback) e._updateValueCallback(e._value); 53 | buf.copy(obuf); 54 | } 55 | }); 56 | 57 | ioHook.on( 'mousedown', event => { 58 | buttbuf.writeUInt8(1, 0); 59 | buttbuf.writeUInt8(event.button, 1); 60 | 61 | e._value = buttbuf; 62 | if (e._updateValueCallback) e._updateValueCallback(e._value); 63 | }); 64 | 65 | ioHook.on( 'mouseup', event => { 66 | buttbuf.writeUInt8(2, 0); 67 | buttbuf.writeUInt8(event.button, 1); 68 | 69 | e._value = buttbuf; 70 | if (e._updateValueCallback) e._updateValueCallback(e._value); 71 | }); 72 | 73 | ioHook.start(); 74 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt07.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | 3 | // ######## REQUIRED FUNCTIONS ######## 4 | 5 | unsigned long state0 = 1000; 6 | unsigned long state1 = 2000; 7 | 8 | unsigned long rand(void) 9 | { 10 | unsigned long s1 = state0; 11 | unsigned long s0 = state1; 12 | 13 | state0 = s0; 14 | s1 ^= s1 << 23; 15 | s1 ^= s1 >> 17; 16 | s1 ^= s0; 17 | s1 ^= s0 >> 26; 18 | state1 = s1; 19 | 20 | return state0 + state1; 21 | } 22 | 23 | // ######## STUB FUNCTIONS ######## 24 | 25 | unsigned int kb = 0; 26 | 27 | unsigned int kbhit(void) { 28 | kb++; 29 | return kb / 500; 30 | } 31 | 32 | void getch(void) { 33 | wait_msec(0x500000); 34 | kb = 0; 35 | } 36 | 37 | // ######## WGT EXAMPLES ######## 38 | 39 | void wgt07() 40 | { 41 | short x; 42 | short y; 43 | short col; 44 | color palette[255]; 45 | 46 | vga256 (); 47 | 48 | // Set our palette 49 | for (y = 0; y < 64; y++) 50 | wsetrgb (y, y*4, y*4, y*4, palette); 51 | for (y = 0; y < 64; y++) 52 | wsetrgb (y + 64, y*4, 0, 0, palette); 53 | for (y = 0; y < 64; y++) 54 | wsetrgb (y + 128, 0, y*4, 0, palette); 55 | for (y = 0; y < 64; y++) 56 | wsetrgb (y + 192, 0, 0, y*4, palette); 57 | wsetpalette (0, 255, palette); 58 | 59 | wcls (vgapal[0]); 60 | 61 | wtextgrid (TEXTGRID_OFF); 62 | wtexttransparent (TEXTFGBG); /* Turn foreground and background on */ 63 | 64 | do { 65 | x = rand() % 320; 66 | y = rand() % 200; 67 | col = rand() % 256; 68 | wtextcolor (vgapal[col]); 69 | wouttextxy (x, y, NULL, "WordUp Graphics Toolkit"); 70 | } while (!kbhit ()); 71 | getch (); 72 | 73 | wcls (0); 74 | wtextgrid (TEXTGRID_ON); 75 | 76 | do { 77 | x = rand() % 80; 78 | y = rand() % 25; 79 | col = rand() % 256; 80 | wtextcolor (vgapal[col]); 81 | wtextbackground (vgapal[rand() % 256]); 82 | wouttextxy (x, y, NULL, "WordUp Graphics Toolkit"); 83 | } while (!kbhit ()); 84 | 85 | getch (); 86 | } 87 | 88 | void main() 89 | { 90 | wgt07(); 91 | while (1); 92 | } 93 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt15.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | #include "include/multicore.h" 4 | 5 | // ######## REQUIRED FUNCTIONS ######## 6 | 7 | unsigned long state0 = 1000; 8 | unsigned long state1 = 2000; 9 | 10 | unsigned long rand(void) 11 | { 12 | unsigned long s1 = state0; 13 | unsigned long s0 = state1; 14 | 15 | state0 = s0; 16 | s1 ^= s1 << 23; 17 | s1 ^= s1 >> 17; 18 | s1 ^= s0; 19 | s1 ^= s0 >> 26; 20 | state1 = s1; 21 | 22 | return state0 + state1; 23 | } 24 | 25 | // ######## STUB FUNCTIONS ######## 26 | 27 | unsigned int kb = 0; 28 | 29 | unsigned int kbhit(void) { 30 | kb++; 31 | return kb / 500; 32 | } 33 | 34 | void getch(void) { 35 | wait_msec(0x500000); 36 | kb = 0; 37 | } 38 | 39 | // ######## WGT EXAMPLES ######## 40 | 41 | void wgt15() 42 | { 43 | short y; 44 | block screen1; 45 | 46 | set_clock_rate(get_max_clock()); 47 | mem_init(); 48 | vga256 (); /* Initializes WGT system */ 49 | 50 | start_core2(minit); // Start the comms engine (core 2) 51 | while (!comms_up); // Wait for comms up 52 | 53 | screen1 = wnewblock (0, 0, 119, 129); 54 | /* Virtual screens can now be any size, as long as they fit within one 55 | segment (64k) */ 56 | 57 | wtextcolor (vgapal[15]); 58 | wouttextxy (0, 0, NULL, "Click the mouse button in a few seconds"); 59 | wsetscreen (screen1); /* sets to screen1 */ 60 | 61 | for (y = 0; y < 200; y++) 62 | { 63 | wsetcolor (vgapal[y]); 64 | wline (0, 0, 319, y); /* draw something on another screen */ 65 | wline (319, 199, 0, y); 66 | } 67 | 68 | while (!but); // wait for a mouse press 69 | 70 | /* now use putblock to show what happened on the other screen */ 71 | 72 | wnormscreen (); /* make the putblock go onto the default screen */ 73 | wputblock (0, 10, screen1, 0); 74 | 75 | wfreeblock (screen1); 76 | /* remember to free that memory (64004 bytes for a screen) */ 77 | } 78 | 79 | void main() 80 | { 81 | wgt15(); 82 | while (1); 83 | } 84 | -------------------------------------------------------------------------------- /part12-wgt/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(wildcard *.c lib/*.c wgt/*.c) 2 | OFILES = $(CFILES:.c=.o) 3 | LLVMPATH = /opt/homebrew/opt/llvm/bin 4 | CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd 5 | 6 | all: clean kernel8.img 7 | 8 | boot/boot.o: boot/boot.S 9 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 10 | 11 | bin/BCM4345C0.o : bin/BCM4345C0.hcd 12 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 13 | 14 | bin/wgt1pal.o: bin/wgt1.pal 15 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 16 | 17 | bin/wgt1blk.o: bin/wgt1.blk 18 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 19 | 20 | bin/wgt2blk.o: bin/wgt2.blk 21 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 22 | 23 | bin/lettersspr.o: bin/letters.spr 24 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 25 | 26 | bin/breakspr.o: bin/break.spr 27 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 28 | 29 | bin/spacespr.o: bin/space.spr 30 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 31 | 32 | bin/invaderspr.o: bin/invader.spr 33 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 34 | 35 | bin/mousespr.o: bin/mouse.spr 36 | $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ 37 | 38 | %.o: %.c 39 | $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ 40 | 41 | kernel8.img: boot/boot.o $(OFILES) bin/BCM4345C0.o bin/wgt1pal.o bin/wgt1blk.o bin/wgt2blk.o bin/lettersspr.o bin/spacespr.o bin/invaderspr.o bin/mousespr.o bin/breakspr.o 42 | $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot/boot.o $(OFILES) bin/BCM4345C0.o bin/wgt1pal.o bin/wgt1blk.o bin/wgt2blk.o bin/lettersspr.o bin/spacespr.o bin/invaderspr.o bin/mousespr.o bin/breakspr.o -T boot/link.ld -o kernel8.elf 43 | $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img 44 | 45 | clean: 46 | /bin/rm kernel8.elf *.o bin/*.o boot/*.o lib/*.o wgt/*.o *.img > /dev/null 2> /dev/null || true 47 | -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /part12-wgt/samples/wgt41.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | #include "include/multicore.h" 4 | 5 | // ######## REQUIRED FUNCTIONS ######## 6 | 7 | unsigned long state0 = 1000; 8 | unsigned long state1 = 2000; 9 | 10 | unsigned long rand(void) 11 | { 12 | unsigned long s1 = state0; 13 | unsigned long s0 = state1; 14 | 15 | state0 = s0; 16 | s1 ^= s1 << 23; 17 | s1 ^= s1 >> 17; 18 | s1 ^= s0; 19 | s1 ^= s0 >> 26; 20 | state1 = s1; 21 | 22 | return state0 + state1; 23 | } 24 | 25 | // ######## STUB FUNCTIONS ######## 26 | 27 | unsigned int kb = 0; 28 | 29 | unsigned int kbhit(void) { 30 | kb++; 31 | return kb / 500; 32 | } 33 | 34 | void getch(void) { 35 | wait_msec(0x500000); 36 | kb = 0; 37 | } 38 | 39 | // ######## WGT EXAMPLES ######## 40 | 41 | void wgt41() 42 | { 43 | set_clock_rate(get_max_clock()); 44 | mem_init(); 45 | vga256 (); /* Initialize graphics mode */ 46 | 47 | char *message = malloc(15); 48 | message[0] = 'H'; 49 | message[1] = 'e'; 50 | message[2] = 'l'; 51 | message[3] = 'l'; 52 | message[4] = 'o'; 53 | message[5] = ' '; 54 | message[6] = 'w'; 55 | message[7] = 'o'; 56 | message[8] = 'r'; 57 | message[9] = 'l'; 58 | message[10] = 'd'; 59 | message[11] = '!'; 60 | message[12] = '\0'; 61 | 62 | wtextcolor (vgapal[15]); 63 | 64 | wgtprintf (0, 0, NULL, "%s", message); 65 | wgtprintf (0, 8, NULL, "String width : %i pixels", wgettextwidth (message, NULL)); 66 | wgtprintf (0, 16, NULL, "String height: %i pixels", wgettextheight (message, NULL)); 67 | 68 | wgtprintf(0, 32, NULL, "The color: %s", "blue"); 69 | wgtprintf(0, 40, NULL, "First number: %d", 12345); 70 | wgtprintf(0, 48, NULL, "Second number: %04d", 25); 71 | wgtprintf(0, 56, NULL, "Third number: %i", 1234); 72 | wgtprintf(0, 64, NULL, "Hexadecimal: %x", 255); 73 | wgtprintf(0, 72, NULL, "Octal: %o", 255); 74 | wgtprintf(0, 80, NULL, "Unsigned value: %u", 150); 75 | wgtprintf(0, 88, NULL, "Just print the percentage sign %%", 10); 76 | 77 | free(message); 78 | } 79 | 80 | void main() 81 | { 82 | wgt41(); 83 | while (1); 84 | } 85 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wwarp.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | 3 | void wsline (short x, short y, short x2, short y2, short *y_array) 4 | { 5 | short t, distance; 6 | short wx, wy, dx, dy, bdx, bdy, incx, incy; 7 | 8 | dx = x2 - x; 9 | dy = y2 - y; 10 | t = 0; wx = 0; wy = 0; 11 | if (dy < 0) incy = - 1; 12 | else incy = 1; 13 | if (dx < 0) incx = - 1; 14 | else incx = 1; 15 | bdx = abs (dx); 16 | bdy = abs (dy); 17 | if (bdx > bdy) distance = bdx; 18 | else distance = bdy; 19 | y_array += x; 20 | if (distance == bdx) 21 | { 22 | while (t <= distance) 23 | { 24 | if ((x >= tx) && (y >= ty) && (y <= by) && (x <= bx)) 25 | *y_array = y; 26 | /* instead of plotting pixels, just store the y value in an array */ 27 | 28 | wy += bdy; 29 | x += incx; 30 | y_array++; 31 | t ++; 32 | if (wy >= distance) 33 | { 34 | wy -= distance; 35 | y += incy; 36 | } 37 | } 38 | } 39 | else 40 | { 41 | while (t <= distance) 42 | { 43 | if ((x >= tx) && (y >= ty) && (y <= by) && (x <= bx)) 44 | *y_array = y; 45 | wx += bdx; 46 | if (wx >= distance) 47 | { 48 | wx -= distance; 49 | x += incx; 50 | y_array++; 51 | } 52 | y += incy; 53 | t ++; 54 | } 55 | } 56 | } 57 | 58 | void wwarp (short sx, short ex, short *tpy, short *bty, block ptr, short mode) 59 | { 60 | long column; 61 | int wid; 62 | 63 | short finalwidth; 64 | short origwidth; 65 | long xstepper; 66 | 67 | origwidth = wgetblockwidth (ptr); 68 | /* Get the original width of the block */ 69 | 70 | finalwidth = abs (ex - sx) + 1; 71 | /* Find the new width */ 72 | 73 | xstepper = ((long)(origwidth) << 16) / ((long)(finalwidth)); 74 | /* Calculate the amount to add to the source bitmap for every pixel across. 75 | This is done using a fixed point number by multiplying it by 65536 (<<16) 76 | and using 0-65535 as a fractional amount. */ 77 | 78 | column = 0; 79 | 80 | for (wid = sx; wid <= ex; wid++) 81 | { 82 | wresize_column (wid, tpy[wid], bty[wid], ptr, column >> 16, mode); 83 | column += xstepper; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt16.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | #include "include/multicore.h" 4 | 5 | // ######## REQUIRED FUNCTIONS ######## 6 | 7 | unsigned long state0 = 1000; 8 | unsigned long state1 = 2000; 9 | 10 | unsigned long rand(void) 11 | { 12 | unsigned long s1 = state0; 13 | unsigned long s0 = state1; 14 | 15 | state0 = s0; 16 | s1 ^= s1 << 23; 17 | s1 ^= s1 >> 17; 18 | s1 ^= s0; 19 | s1 ^= s0 >> 26; 20 | state1 = s1; 21 | 22 | return state0 + state1; 23 | } 24 | 25 | // ######## STUB FUNCTIONS ######## 26 | 27 | unsigned int kb = 0; 28 | 29 | unsigned int kbhit(void) { 30 | kb++; 31 | return kb / 500; 32 | } 33 | 34 | void getch(void) { 35 | wait_msec(0x500000); 36 | kb = 0; 37 | } 38 | 39 | // ######## WGT EXAMPLES ######## 40 | 41 | void wgt16() 42 | { 43 | short y, tempx, tempy; 44 | block screen1; 45 | 46 | set_clock_rate(get_max_clock()); 47 | mem_init(); 48 | vga256 (); /* Initializes WGT system */ 49 | 50 | start_core2(minit); // Start the comms engine (core 2) 51 | while (!comms_up); // Wait for comms up 52 | 53 | screen1 = wnewblock (0, 0, 319, 199); 54 | 55 | wsetscreen (screen1); /* sets to screen1 */ 56 | for (y = 0; y < 200; y++) 57 | { 58 | wsetcolor (vgapal[y]); 59 | wfline (0, 0, 319, y); /* draw something on another screen */ 60 | wfline (319, 199, 0, y); 61 | } 62 | 63 | wnormscreen (); /* make the putblock go onto the default screen */ 64 | 65 | do { 66 | tempx = mx; 67 | tempy = my; 68 | wcopyscreen (tempx, tempy, tempx + 19, tempy + 19, screen1, 69 | tempx, tempy, NULL); 70 | /* this means copy a square 20*20 from screen1 to the same spot 71 | on the default screen. Move the mouse around and watch the black 72 | wipe away as screen1 copies over. */ 73 | 74 | /* NULL means the default screen. */ 75 | } while (!but); 76 | 77 | mdeinit (); /* Deinitialize the mouse handler */ 78 | wfreeblock (screen1); 79 | } 80 | 81 | void main() 82 | { 83 | wgt16(); 84 | while (1); 85 | } 86 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt27.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | 4 | // ######## REQUIRED FUNCTIONS ######## 5 | 6 | unsigned long state0 = 1000; 7 | unsigned long state1 = 2000; 8 | 9 | unsigned long rand(void) 10 | { 11 | unsigned long s1 = state0; 12 | unsigned long s0 = state1; 13 | 14 | state0 = s0; 15 | s1 ^= s1 << 23; 16 | s1 ^= s1 >> 17; 17 | s1 ^= s0; 18 | s1 ^= s0 >> 26; 19 | state1 = s1; 20 | 21 | return state0 + state1; 22 | } 23 | 24 | // ######## STUB FUNCTIONS ######## 25 | 26 | unsigned int kb = 0; 27 | 28 | unsigned int kbhit(void) { 29 | kb++; 30 | return kb / 500; 31 | } 32 | 33 | void getch(void) { 34 | wait_msec(0x500000); 35 | kb = 0; 36 | } 37 | 38 | // ######## WGT EXAMPLES ######## 39 | 40 | void wgt27() 41 | { 42 | block skewit; /* Pointer to our block */ 43 | color palette[256]; /* Our palette */ 44 | int i = 0; /* Loop counter */ 45 | 46 | set_clock_rate(get_max_clock()); 47 | mem_init(); 48 | vga256 (); 49 | 50 | wreadpalette (0, 255, palette); /* Store our current palette */ 51 | 52 | wcls (vgapal[0]); /* Clear screen with black */ 53 | 54 | for (i = 100; i > 0; i--) /* Draw 100 filled circles */ 55 | { 56 | wsetcolor (vgapal[i]); 57 | wfill_circle (160, 100, i); 58 | } 59 | 60 | getch(); 61 | 62 | wsetcolor (vgapal[0]); /* Use black as active color */ 63 | wbar (0, 0, 104, 199); /* Draw two solid rectangles */ 64 | wbar (216, 0, 319, 199); 65 | skewit=wnewblock (100, 40, 220, 160); /* Grab a block for skewing */ 66 | 67 | getch(); 68 | 69 | wcls (vgapal[0]); /* Clear screen with black */ 70 | do { 71 | for (i = -100; i < 100; i += 2) /* Skew image 2 pixels at a time */ 72 | { 73 | wskew (100, 40, skewit, i); 74 | delay(2); 75 | } 76 | 77 | for (i = 100; i > -100; i -= 2) /* Skew image back to starting pos */ 78 | { 79 | wskew (100, 40, skewit, i); 80 | delay(2); 81 | } 82 | } while (1); 83 | } 84 | 85 | void main() 86 | { 87 | wgt27(); 88 | while (1); 89 | } 90 | -------------------------------------------------------------------------------- /part12-wgt/controller-ios/rpi4-osdev-ioscontrol/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // 4 | 5 | import UIKit 6 | 7 | @UIApplicationMain 8 | class AppDelegate: UIResponder, UIApplicationDelegate { 9 | var window: UIWindow? 10 | 11 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 12 | // Override point for customization after application launch. 13 | return true 14 | } 15 | 16 | func applicationWillResignActive(_ application: UIApplication) { 17 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 18 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 19 | } 20 | 21 | func applicationDidEnterBackground(_ application: UIApplication) { 22 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 23 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 24 | } 25 | 26 | func applicationWillEnterForeground(_ application: UIApplication) { 27 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 28 | } 29 | 30 | func applicationDidBecomeActive(_ application: UIApplication) { 31 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 32 | } 33 | 34 | func applicationWillTerminate(_ application: UIApplication) { 35 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt02.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | 3 | // ######## REQUIRED FUNCTIONS ######## 4 | 5 | unsigned long state0 = 1; 6 | unsigned long state1 = 2; 7 | 8 | unsigned long rand(void) 9 | { 10 | unsigned long s1 = state0; 11 | unsigned long s0 = state1; 12 | 13 | state0 = s0; 14 | s1 ^= s1 << 23; 15 | s1 ^= s1 >> 17; 16 | s1 ^= s0; 17 | s1 ^= s0 >> 26; 18 | state1 = s1; 19 | 20 | return state0 + state1; 21 | } 22 | 23 | // ######## STUB FUNCTIONS ######## 24 | 25 | unsigned int kb = 0; 26 | 27 | unsigned int kbhit(void) { 28 | kb++; 29 | return kb / 500; 30 | } 31 | 32 | void getch(void) { 33 | wait_msec(0x500000); 34 | } 35 | 36 | // ######## WGT EXAMPLES ######## 37 | 38 | void wgt02() 39 | { 40 | short x; 41 | short y; 42 | short i; 43 | 44 | vga256 (); 45 | wcls (vgapal[0]); /* Clear screen with color 0 */ 46 | 47 | /* Put randomly coloured pixels in random screen coordinates */ 48 | do { 49 | wsetcolor (vgapal[rand () % 255]); 50 | x = rand () % 320; 51 | y = rand() % 200; 52 | wputpixel (x, y); 53 | } while (kbhit () == 0); 54 | getch (); 55 | 56 | wcls (vgapal[0]); /* Clear screen with color 0 */ 57 | wsetcolor (vgapal[10]); /* Now we will draw with #10 */ 58 | for (x = 0; x < 320; x++) 59 | for (y = 0; y < 200; y++) 60 | wfastputpixel (x, y); /* Fast due to no clipping checking */ 61 | 62 | getch (); 63 | wcls (vgapal[0]); /* Clears screen with color 0 */ 64 | 65 | /* Put randomly coloured pixels in the top left corner of the screen */ 66 | for (i = 0; i < 15000; i++) 67 | { 68 | wsetcolor (vgapal[rand () % 255]); 69 | x = rand () % 160; 70 | y = rand () % 100; 71 | wputpixel (x, y); 72 | } 73 | 74 | /* Now use wgetpixel to read image off screen */ 75 | for (y = 0; y < 100; y++) 76 | for (x = 0; x < 160; x++) 77 | { 78 | wsetcolor (wgetpixel (x, y)); 79 | wputpixel (x + 160, y + 100); 80 | } 81 | 82 | getch (); 83 | 84 | while (1); 85 | } 86 | 87 | void main() 88 | { 89 | wgt02(); 90 | while (1); 91 | } 92 | -------------------------------------------------------------------------------- /part10-multicore/boot.S: -------------------------------------------------------------------------------- 1 | #define LOCAL_CONTROL 0xff800000 2 | #define LOCAL_PRESCALER 0xff800008 3 | #define OSC_FREQ 54000000 4 | #define MAIN_STACK 0x400000 5 | 6 | .section ".text.boot" // Make sure the linker puts this at the start of the kernel image 7 | 8 | .global _start // Execution starts here 9 | 10 | _start: 11 | ldr x0, =LOCAL_CONTROL // Sort out the timer 12 | str wzr, [x0] 13 | mov w1, 0x80000000 14 | str w1, [x0, #(LOCAL_PRESCALER - LOCAL_CONTROL)] 15 | 16 | ldr x0, =OSC_FREQ 17 | msr cntfrq_el0, x0 18 | msr cntvoff_el2, xzr 19 | 20 | // Check processor ID is zero (executing on main core), else hang 21 | mrs x1, mpidr_el1 22 | and x1, x1, #3 23 | cbz x1, 2f 24 | 25 | // We're not on the main core, so hang in an infinite wait loop 26 | adr x5, spin_cpu0 27 | 1: wfe 28 | ldr x4, [x5, x1, lsl #3] 29 | cbz x4, 1b 30 | 31 | ldr x2, =__stack_start // Get ourselves a fresh stack - location depends on CPU core asking 32 | lsl x1, x1, #9 // Multiply core_number by 512 33 | add x3, x2, x1 // Add to the address 34 | mov sp, x3 35 | 36 | mov x0, #0 37 | mov x1, #0 38 | mov x2, #0 39 | mov x3, #0 40 | br x4 41 | b 1b 42 | 2: // We're on the main core! 43 | 44 | // Set stack to start somewhere safe 45 | mov sp, #MAIN_STACK 46 | 47 | // Clean the BSS section 48 | ldr x1, =__bss_start // Start address 49 | ldr w2, =__bss_size // Size of the section 50 | 3: cbz w2, 4f // Quit loop if zero 51 | str xzr, [x1], #8 52 | sub w2, w2, #1 53 | cbnz w2, 3b // Loop if non-zero 54 | 55 | // Jump to our main() routine in C (make sure it doesn't return) 56 | 4: bl main 57 | // In case it does return, halt the master core too 58 | b 1b 59 | 60 | .ltorg 61 | 62 | .org 0xd8 63 | .globl spin_cpu0 64 | spin_cpu0: 65 | .quad 0 66 | 67 | .org 0xe0 68 | .globl spin_cpu1 69 | spin_cpu1: 70 | .quad 0 71 | 72 | .org 0xe8 73 | .globl spin_cpu2 74 | spin_cpu2: 75 | .quad 0 76 | 77 | .org 0xf0 78 | .globl spin_cpu3 79 | spin_cpu3: 80 | .quad 0 81 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt33.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | 4 | // ######## REQUIRED FUNCTIONS ######## 5 | 6 | unsigned long state0 = 1000; 7 | unsigned long state1 = 2000; 8 | 9 | unsigned long rand(void) 10 | { 11 | unsigned long s1 = state0; 12 | unsigned long s0 = state1; 13 | 14 | state0 = s0; 15 | s1 ^= s1 << 23; 16 | s1 ^= s1 >> 17; 17 | s1 ^= s0; 18 | s1 ^= s0 >> 26; 19 | state1 = s1; 20 | 21 | return state0 + state1; 22 | } 23 | 24 | // ######## STUB FUNCTIONS ######## 25 | 26 | unsigned int kb = 0; 27 | 28 | unsigned int kbhit(void) { 29 | kb++; 30 | return kb / 500; 31 | } 32 | 33 | void getch(void) { 34 | wait_msec(0x500000); 35 | kb = 0; 36 | } 37 | 38 | // ######## WGT EXAMPLES ######## 39 | 40 | #define NUM_IN 5 /* number of random points */ 41 | #define NUM_OUT 30 /* number of points of bezier curve */ 42 | /* Fewer points will make more chunky line */ 43 | 44 | void wgt33() 45 | { 46 | tpolypoint inpoint[NUM_IN]; /* Array with the normal curve points */ 47 | tpolypoint outpoint[NUM_OUT]; /* Array with smooth curve points */ 48 | block other; /* Pointer to our second screen */ 49 | int i; /* Loop counter */ 50 | 51 | set_clock_rate(get_max_clock()); 52 | mem_init(); 53 | vga256 (); /* Initialize graphics mode */ 54 | 55 | other = wnewblock (0, 0, 319, 199); /* Allocate second screen */ 56 | 57 | wsetcolor (vgapal[15]); /* Draw with white */ 58 | 59 | do { 60 | wsetscreen (other); /* We'll draw on the hidden screen */ 61 | wcls (vgapal[0]); /* Clear it with black */ 62 | 63 | for (i = 0; i < NUM_IN; i++) /* Randomize the BEZIER control pts */ 64 | { 65 | inpoint[i].x = rand() % 320; 66 | inpoint[i].y = rand() % 200; 67 | } 68 | 69 | wbezier (inpoint, NUM_IN, outpoint, NUM_OUT); /* Generate line */ 70 | 71 | whollowpoly (outpoint, NUM_OUT, 0, 0, OPEN_POLY); 72 | /* draw the smooth curve */ 73 | 74 | wnormscreen (); /* Reset drawing to visual screen */ 75 | wputblock (0, 0, other, 0); /* Show the screen */ 76 | getch(); 77 | } while (1); 78 | 79 | wfreeblock (other); /* Free our screen buffer */ 80 | } 81 | 82 | void main() 83 | { 84 | wgt33(); 85 | while (1); 86 | } 87 | -------------------------------------------------------------------------------- /part11-breakout-smp/boot/boot.S: -------------------------------------------------------------------------------- 1 | #define LOCAL_CONTROL 0xff800000 2 | #define LOCAL_PRESCALER 0xff800008 3 | #define OSC_FREQ 54000000 4 | #define MAIN_STACK 0x400000 5 | 6 | .section ".text.boot" // Make sure the linker puts this at the start of the kernel image 7 | 8 | .global _start // Execution starts here 9 | 10 | _start: 11 | ldr x0, =LOCAL_CONTROL // Sort out the timer 12 | str wzr, [x0] 13 | mov w1, 0x80000000 14 | str w1, [x0, #(LOCAL_PRESCALER - LOCAL_CONTROL)] 15 | 16 | ldr x0, =OSC_FREQ 17 | msr cntfrq_el0, x0 18 | msr cntvoff_el2, xzr 19 | 20 | // Check processor ID is zero (executing on main core), else hang 21 | mrs x1, mpidr_el1 22 | and x1, x1, #3 23 | cbz x1, 2f 24 | 25 | // We're not on the main core, so hang in an infinite wait loop 26 | adr x5, spin_cpu0 27 | 1: wfe 28 | ldr x4, [x5, x1, lsl #3] 29 | cbz x4, 1b 30 | 31 | ldr x2, =__stack_start // Get ourselves a fresh stack - location depends on CPU core asking 32 | lsl x1, x1, #9 // Multiply core_number by 512 33 | add x3, x2, x1 // Add to the address 34 | mov sp, x3 35 | 36 | mov x0, #0 37 | mov x1, #0 38 | mov x2, #0 39 | mov x3, #0 40 | br x4 41 | b 1b 42 | 2: // We're on the main core! 43 | 44 | // Set stack to start somewhere safe 45 | mov sp, #MAIN_STACK 46 | 47 | // Clean the BSS section 48 | ldr x1, =__bss_start // Start address 49 | ldr w2, =__bss_size // Size of the section 50 | 3: cbz w2, 4f // Quit loop if zero 51 | str xzr, [x1], #8 52 | sub w2, w2, #1 53 | cbnz w2, 3b // Loop if non-zero 54 | 55 | // Jump to our main() routine in C (make sure it doesn't return) 56 | 4: bl main 57 | // In case it does return, halt the master core too 58 | b 1b 59 | 60 | .ltorg 61 | 62 | .org 0xd8 63 | .globl spin_cpu0 64 | spin_cpu0: 65 | .quad 0 66 | 67 | .org 0xe0 68 | .globl spin_cpu1 69 | spin_cpu1: 70 | .quad 0 71 | 72 | .org 0xe8 73 | .globl spin_cpu2 74 | spin_cpu2: 75 | .quad 0 76 | 77 | .org 0xf0 78 | .globl spin_cpu3 79 | spin_cpu3: 80 | .quad 0 81 | -------------------------------------------------------------------------------- /part12-wgt/wgt/wskew.c: -------------------------------------------------------------------------------- 1 | #include "../include/wgt.h" 2 | 3 | #define fastcopy memcpy 4 | 5 | void wskew (short x, short y, block image, short degrees) 6 | { 7 | float newx, offs, slope; 8 | long lnewx, lslope; 9 | /* long values converted from floats (speed up) */ 10 | short ctr; /* y ctr */ 11 | short hgt, wid, display, shx, of2; 12 | short onewx; 13 | 14 | hgt = wgetblockheight (image); /* Find height of block */ 15 | wid = wgetblockwidth (image); /* Find width of block */ 16 | slope = (float)degrees / 45; /* Calculate slope of new image */ 17 | offs = ((float)hgt / 2)*slope; /* Find distance to shift horiz. */ 18 | newx = (float)x + offs; /* Calculate new x position */ 19 | onewx = newx; /* Store it as integer for clipping */ 20 | lnewx = (float)newx * 2000; /* Convert floating pt to long int */ 21 | lslope = (float)slope * 2000; /* Convert floating pt to long int */ 22 | 23 | /* Draw each row of image */ 24 | for (ctr = y; ctr < y + hgt - 1; ctr++) 25 | { 26 | if (onewx + wid > bx) display = bx + 1 - onewx; 27 | /* Clip width */ 28 | else display = wid; 29 | if (onewx < tx) /* See if image overlaps left clip */ 30 | { 31 | of2 = tx - onewx; /* Find offset into bitmap */ 32 | shx = tx; /* Set to draw starting here */ 33 | display = display - of2; /* New width to draw */ 34 | } 35 | else 36 | { 37 | shx = onewx; /* X value is fine */ 38 | of2 = 0; /* Use entire bitmap */ 39 | } 40 | /* If width to display >0, and <= original width, and 41 | we are within top and bottom Y clipping boundaries: 42 | Copy row of bitmap to visual screen, using DISPLAY contiguous 43 | bytes. 44 | */ 45 | if ((display > 0) & (display <= wid) & (ctr >= ty) & (ctr <= by)) 46 | fastcopy (&abuf[(ctr)*WGT_SYS.xres + shx], &image[(ctr - y)*wid + 2 47 | + of2], display); 48 | lnewx = lnewx - lslope; 49 | /* Find X position after shifting next row */ 50 | onewx = lnewx / 2000; 51 | /* Calculate integer value from long int */ 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt39.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | #include "include/multicore.h" 4 | 5 | // ######## REQUIRED FUNCTIONS ######## 6 | 7 | unsigned long state0 = 1000; 8 | unsigned long state1 = 2000; 9 | 10 | unsigned long rand(void) 11 | { 12 | unsigned long s1 = state0; 13 | unsigned long s0 = state1; 14 | 15 | state0 = s0; 16 | s1 ^= s1 << 23; 17 | s1 ^= s1 >> 17; 18 | s1 ^= s0; 19 | s1 ^= s0 >> 26; 20 | state1 = s1; 21 | 22 | return state0 + state1; 23 | } 24 | 25 | // ######## STUB FUNCTIONS ######## 26 | 27 | unsigned int kb = 0; 28 | 29 | unsigned int kbhit(void) { 30 | kb++; 31 | return kb / 500; 32 | } 33 | 34 | void getch(void) { 35 | wait_msec(0x500000); 36 | kb = 0; 37 | } 38 | 39 | // ######## WGT EXAMPLES ######## 40 | 41 | void wgt39() 42 | { 43 | int i; 44 | int px[256], py[256]; 45 | color p[256]; 46 | int numpix; 47 | 48 | set_clock_rate(get_max_clock()); 49 | mem_init(); 50 | vga256 (); /* Initialize graphics mode */ 51 | 52 | start_core2(minit); // Start the comms engine (core 2) 53 | while (!comms_up); // Wait for comms up 54 | 55 | numpix = 255; 56 | 57 | extern unsigned char _binary_bin_wgt1_pal_start[]; 58 | wloadpalette (&_binary_bin_wgt1_pal_start[0], p); 59 | wsetpalette (0, 255, p); 60 | 61 | for (i = 0; i < 256; i++) 62 | { 63 | px[i] = 0; 64 | py[i] = 0; 65 | } 66 | 67 | do { 68 | wsetcolor (vgapal[0]); 69 | wait_msec(0x3E9F); // wait for retrace (ish) 70 | 71 | for (i = numpix; i >= 1; i--) 72 | { 73 | wfastputpixel (px[i], py[i]); 74 | wfastputpixel (319 - px[i], 199 - py[i]); 75 | px[i] = px[i-1]; 76 | py[i] = py[i-1]; 77 | } 78 | 79 | wsetcolor (vgapal[0]); 80 | wfastputpixel (px[0], py[0]); 81 | wfastputpixel (319 - px[0], 199 - py[0]); 82 | 83 | px[0] = mx; 84 | py[0] = my; 85 | 86 | for (i = 0; i < numpix; i++) 87 | { 88 | wsetcolor (vgapal[i]); 89 | wfastputpixel (px[i], py[i]); 90 | wfastputpixel (319 - px[i], 199 - py[i]); 91 | } 92 | } while (!but); 93 | 94 | mdeinit (); /* Deinitialize the mouse handler */ 95 | } 96 | 97 | void main() 98 | { 99 | wgt39(); 100 | while (1); 101 | } 102 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt11.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | #include "include/mb.h" 4 | 5 | // ######## REQUIRED FUNCTIONS ######## 6 | 7 | unsigned long state0 = 1000; 8 | unsigned long state1 = 2000; 9 | 10 | unsigned long rand(void) 11 | { 12 | unsigned long s1 = state0; 13 | unsigned long s0 = state1; 14 | 15 | state0 = s0; 16 | s1 ^= s1 << 23; 17 | s1 ^= s1 >> 17; 18 | s1 ^= s0; 19 | s1 ^= s0 >> 26; 20 | state1 = s1; 21 | 22 | return state0 + state1; 23 | } 24 | 25 | // ######## STUB FUNCTIONS ######## 26 | 27 | unsigned int kb = 0; 28 | 29 | unsigned int kbhit(void) { 30 | kb++; 31 | return kb / 500; 32 | } 33 | 34 | void getch(void) { 35 | wait_msec(0x500000); 36 | kb = 0; 37 | } 38 | 39 | // ######## WGT EXAMPLES ######## 40 | 41 | #define TIMERSPEED 60 42 | int timer; 43 | int size; 44 | int direction = -1; 45 | 46 | void timer_routine (void) 47 | { 48 | timer++; 49 | } 50 | 51 | void wgt11() 52 | { 53 | block part1; /* part of the screen */ 54 | color pal[256]; 55 | 56 | set_clock_rate(get_max_clock()); 57 | mem_init(); 58 | vga256 (); 59 | 60 | extern unsigned char _binary_bin_wgt1_pal_start[]; 61 | unsigned char *newpal = &_binary_bin_wgt1_pal_start[0]; 62 | wloadpalette (newpal, pal); 63 | wsetpalette (0, 255, pal); 64 | 65 | extern unsigned char _binary_bin_wgt1_blk_start[]; 66 | unsigned char *newblk = &_binary_bin_wgt1_blk_start[0]; 67 | part1 = wloadblock (newblk); 68 | 69 | wputblock (0, 0, part1, 0); 70 | 71 | getch (); 72 | wcls (vgapal[0]); 73 | 74 | timer = 0; 75 | size = 50; 76 | winittimer (); 77 | wstarttimer (timer_routine, TIMERSPEED); 78 | 79 | wclip (0, 0, 319, 199); 80 | do { 81 | if (direction > 0) 82 | { 83 | size += timer * 2; 84 | timer = 0; 85 | if (size > 50) 86 | direction = -1; 87 | } 88 | else 89 | { 90 | size -= timer * 2; 91 | timer = 0; 92 | if (size < -1000) 93 | direction = 1; 94 | } 95 | 96 | wresize (size, size, 319 - size, 199 - size, part1, NORMAL); 97 | 98 | } while (1); 99 | getch (); 100 | 101 | wstoptimer (); 102 | wdonetimer (); 103 | 104 | wfreeblock(part1); 105 | } 106 | 107 | void main() 108 | { 109 | wgt11(); 110 | while (1); 111 | } 112 | -------------------------------------------------------------------------------- /part12-wgt/samples/wgt36.c: -------------------------------------------------------------------------------- 1 | #include "include/wgt.h" 2 | #include "include/mem.h" 3 | #include "include/multicore.h" 4 | 5 | // ######## REQUIRED FUNCTIONS ######## 6 | 7 | unsigned long state0 = 1000; 8 | unsigned long state1 = 2000; 9 | 10 | unsigned long rand(void) 11 | { 12 | unsigned long s1 = state0; 13 | unsigned long s0 = state1; 14 | 15 | state0 = s0; 16 | s1 ^= s1 << 23; 17 | s1 ^= s1 >> 17; 18 | s1 ^= s0; 19 | s1 ^= s0 >> 26; 20 | state1 = s1; 21 | 22 | return state0 + state1; 23 | } 24 | 25 | // ######## STUB FUNCTIONS ######## 26 | 27 | unsigned int kb = 0; 28 | 29 | unsigned int kbhit(void) { 30 | kb++; 31 | return kb / 500; 32 | } 33 | 34 | void getch(void) { 35 | wait_msec(0x500000); 36 | kb = 0; 37 | } 38 | 39 | // ######## WGT EXAMPLES ######## 40 | 41 | int ox, oy; /* old mouse coordinates */ 42 | int i; 43 | 44 | void wgt36() 45 | { 46 | set_clock_rate(get_max_clock()); 47 | mem_init(); 48 | vga256 (); /* Initialize graphics mode */ 49 | 50 | start_core2(minit); // Start the comms engine (core 2) 51 | while (!comms_up); // Wait for comms up 52 | 53 | for (i = 0; i < 200; i++) /* Draw a background */ 54 | { 55 | wsetcolor (vgapal[i]); 56 | wline (0, i, 319, i); 57 | } 58 | 59 | do { /* Draws a filled xorbox using mouse coordinates as one corner. */ 60 | ox = mx; 61 | oy = my; 62 | wxorbox (50, 50, ox, oy, 128); /* Draw the box */ 63 | while ((mx == ox) && (my == oy) && (!but)); /* Do nothing while mouse is 64 | stationary. */ 65 | wxorbox (50, 50, ox, oy, 128); 66 | /* Erase the box by drawing the same thing */ 67 | } while (but == 0); 68 | 69 | noclick (); 70 | 71 | do { /* Draws a hollow rubber box using mouse coordinates as one corner. */ 72 | ox = mx; 73 | oy = my; 74 | wxorbox (50, 50, ox, 50, 128); 75 | wxorbox (ox, 50, ox, oy, 128); /* Draw the box */ 76 | wxorbox (50, oy, ox, oy, 128); 77 | wxorbox (50, 50, 50, oy, 128); 78 | while ((mx == ox) && (my == oy) && (!but)); /* Do nothing while mouse is 79 | stationary. */ 80 | wxorbox (50, 50, ox, 50, 128); 81 | wxorbox (ox, 50, ox, oy, 128); /* Erase the box */ 82 | wxorbox (50, oy, ox, oy, 128); 83 | wxorbox (50, 50, 50, oy, 128); 84 | } while (but == 0); 85 | mdeinit (); /* Deinitialize the mouse handler */ 86 | } 87 | 88 | void main() 89 | { 90 | wgt36(); 91 | while (1); 92 | } 93 | -------------------------------------------------------------------------------- /part11-breakout-smp/include/audio.h: -------------------------------------------------------------------------------- 1 | #include "../include/io.h" 2 | 3 | #define PWM_BASE (PERIPHERAL_BASE + 0x20C000 + 0x800) /* PWM1 register base address on RPi4 */ 4 | #define PWM_LEGACY_BASE (LEGACY_BASE + 0x20C000 + 0x800) /* PWM1 register base legacy address on RPi4 */ 5 | #define CLOCK_BASE (PERIPHERAL_BASE + 0x101000) 6 | #define DMA_BASE (PERIPHERAL_BASE + 0x007100) /* DMA register base address */ 7 | #define DMA_ENABLE (DMA_BASE + 0xFF0) /* DMA global enable bits */ 8 | 9 | #define DMA_ADDRESS 0x00500000 /* A safe address to use for our DMA transfer */ 10 | 11 | #define BCM2711_PWMCLK_CNTL 40 12 | #define BCM2711_PWMCLK_DIV 41 13 | #define PM_PASSWORD 0x5A000000 14 | 15 | #define BCM2711_PWM_CONTROL 0 16 | #define BCM2711_PWM_STATUS 1 17 | #define BCM2711_PWM_DMAC 2 18 | #define BCM2711_PWM0_RANGE 4 19 | #define BCM2711_PWM0_DATA 5 20 | #define BCM2711_PWM_FIFO 6 21 | #define BCM2711_PWM1_RANGE 8 22 | #define BCM2711_PWM1_DATA 9 23 | 24 | #define BCM2711_PWM1_USEFIFO 0x2000 /* Data from FIFO */ 25 | #define BCM2711_PWM1_ENABLE 0x0100 /* Channel enable */ 26 | #define BCM2711_PWM0_USEFIFO 0x0020 /* Data from FIFO */ 27 | #define BCM2711_PWM0_ENABLE 0x0001 /* Channel enable */ 28 | #define BCM2711_PWM_ENAB 0x80000000 /* PWM DMA Configuration: DMA Enable (bit 31 set) */ 29 | 30 | #define BCM2711_GAPO2 0x20 31 | #define BCM2711_GAPO1 0x10 32 | #define BCM2711_RERR1 0x8 33 | #define BCM2711_WERR1 0x4 34 | #define BCM2711_FULL1 0x1 35 | #define ERRORMASK (BCM2711_GAPO2 | BCM2711_GAPO1 | BCM2711_RERR1 | BCM2711_WERR1) 36 | 37 | #define DMA_CS 0 /* Control/status register offset for DMA channel 0 */ 38 | #define DMA_CONBLK_AD 1 39 | #define DMA_EN1 1 << 1 /* Enable DMA engine 1 */ 40 | #define DMA_ACTIVE 1 /* Active bit set */ 41 | #define DMA_DEST_DREQ 0x40 /* Use DREQ to pace peripheral writes */ 42 | #define DMA_PERMAP_1 0x10000 /* PWM1 peripheral for DREQ */ 43 | #define DMA_SRC_INC 0x100 /* Increment source address */ 44 | 45 | struct dma_cb { 46 | unsigned int ti; 47 | unsigned int source_ad; 48 | unsigned int dest_ad; 49 | unsigned int txfr_len; 50 | unsigned int stride; 51 | unsigned int nextconbk; 52 | unsigned int null1; 53 | unsigned int null2; 54 | } __attribute__((aligned(32))); 55 | 56 | void audio_init(void); 57 | void audio_play_cpu(unsigned char *data, unsigned int size); 58 | void audio_play_dma(unsigned char *data, unsigned int size); 59 | void audio_wait_dma(void); 60 | --------------------------------------------------------------------------------