PeterLemon / RaspberryPi

Raspberry Pi Bare Metal Assembly Programming
447 stars 67 forks source link

HelloWord demo #2

Closed nandor closed 10 years ago

nandor commented 10 years ago

Hello,

I am working on an ARM emulator for a university project and I am trying to get the HelloWorld demo running on it. I think that I might have noticed a small error in the code:

imm32 r0,PERIPHERAL_BASE + MAIL_BASE
imm32 r1,FB_STRUCT
orr r1,MAIL_FB
str r1,[r0,MAIL_WRITE + MAIL_FB] ; Mail Box Write

The value of r1 is written to 0x2000b8a1, an unaligned address. Isn't it redundant to add MAIL_FB to r0 + MAIL_WRITE, the channel information already being encoded in the least significant bits of r1?

PeterLemon commented 10 years ago

Hi nandor, I'd like to say thanks, for using my minimal bare metal examples for testing your emu, this makes me very happy =D I checked out your findings and you are indeed right, there is no need for that + MAIL_FB in r0 + MAIL_WRITE.

My code now looks like this:

imm32 r0,PERIPHERAL_BASE + MAIL_BASE imm32 r1,FB_STRUCT orr r1,MAIL_FB str r1,[r0,MAIL_WRITE] ; Mail Box Write

Which now writes to address 0x2000B8A0, and still shows the "Hello World" characters.

I am going to update all my GitHub sources that use the frame buffer, with the new correct code (thanks so much for spotting this).

So now we must look at why the unaligned address worked on hardware in the 1st place... Some buggy code like this will work on hardware, because when an unaligned address is written to on the ARM, the ARM CPU will try it's best to just use it anyway, which must have translated it to the address $2000B8A0 in it's internal logic. For your ARM CPU emulation you will need to emulate unaligned address accesses correctly, which would then run my old buggy "hello world" code. Also to make matters hard, I have heard different ARM CPU's deal with unaligned addresses in different ways...

Good luck with your emu, I think you will find it a fun & interesting project, which should score you lots of points in your university project =D