Custom machine: Forcing initial boot address
Sensitive / Proprietary
Hello all,
I am currently trying to modify the MPS2 board to emulate an ARMv7m device I am working on, as none of the included machines provide an environment close enough to what I'm working on to be sufficient. I am running into an issue in which I cannot get the machine to execute the bootROM from address 0xFFFF0000. The specs for the specific device I have (cannot share the device model, unfortunately) state that there is a control register that I assume is present in all v7m chips that selects whether to boot at 0x0 or 0xFFFF0000. I can also see evidence of this register being emulated in QEMU in 'target/arm/cpu.c'. However, since there is little API documentation I have been able to find, I've effectively been reverse-engineering QEMU to figure out what needs to be set. So far, all of my attempts to modify control registers and addresses directly have resulted in unexpected behavior and partial implementation of my goals. I have had success in forcing the ROM to load at the desired address, and with GDB I can force the PC and SP to where I want, but the IVT must be at 0x0 by default. I was hoping someone knew how to enable the control register that sets the boot address so that the IVT can be loaded from a different address.
I am running QEMU version 2.11.
Apologies if this is the wrong place or not the expected format. I haven't used a mailing list before and I couldn't find any guidelines or etiquette rules. Thanks!
NOTICE: This email message and all attachments transmitted with it may contain privileged and confidential information, and information that is protected by, and proprietary to, Parsons Corporation, and is intended solely for the use of the addressee for the specific purpose set forth in this communication. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited, and you should delete this message and all copies and backups thereof. The recipient may not further distribute or use any of the information contained herein without the express written authorization of the sender. If you have received this message in error, or if you have any questions regarding the use of the proprietary information contained therein, please contact the sender of this message immediately, and the sender will provide you with further instructions.
Quoted 2 lines · Alexander
Sensitive / Proprietary
Er, you just sent this to a public mailing list...
Quoted 1 line
I am currently trying to modify the MPS2 board to emulate an ARMv7m device I am working on, as none of the included machines provide an environment close enough to what I’m working on to be sufficient. I am running into an issue in which I cannot get the machine to execute the bootROM from address
0xFFFF0000. The specs for the specific device I have (cannot share the device model, unfortunately) state that there is a control register that I assume is present in all v7m chips that selects whether to boot at0x0or0xFFFF0000. I can also see evidence of this register being emulated in QEMU in ‘target/arm/cpu.c’.
It would help if you said what the register name was! "ARMv7M" is an architecture family, which covers some things which must be implemented, and allows some other things to be implementation defined. There are various CPUs that implement ARMv7M, like the Cortex-M3. Then these CPUs can be found in SoCs (like the stm32f205, for example), which add extra memory mapped devices with their own registers.
Quoted 1 line
However, since there is little API documentation I have been able to find, I’ve effectively been reverse-engineering QEMU to figure out what needs to be set. So far, all of my attempts to modify control registers and addresses directly have resulted in unexpected behavior and partial implementation of my goals. I have had success in forcing the ROM to load at the desired address, and with GDB I can force the PC and SP to where I want, but the IVT must be at
0x0by default. I was hoping someone knew how to enable the control register that sets the boot address so that the IVT can be loaded from a different address.
Architecturally the vector table starts at the address specified by the CPU's VTOR register ("Vector Table Offset Register"). QEMU does implement this, but we don't currently provide a mechanism for allowing an SoC model or board model to specify a reset value for it other than zero (because for all the boards we model they use a zero reset value, so we didn't need it). We do provide this mechanism for the v8M secure-banked VTOR -- this is exposed to the rest of QEMU via the "init-svtor" qdev property, which the board can then set. So for a v7M CPU you would need to add something similar for "init-vtor" to set the non-secure VTOR reset value. Then the CPU would come out of reset by loading the PC and SP from the vector table at that address.
Quoted 1 line
I am running QEMU version 2.11.
If you're modifying QEMU you should start with a much newer version than that. There have been a lot of M-profile related bugfixes since then. Generally for development of QEMU we recommend working with the head of git.
thanks
-- PMM
It's always fun to get in on a Monday morning and immediately realize I'm an idiot! Disregard the 'Sensitive / Proprietary'; that was just a complete goof by me when selecting the email sensitivity. Everything in my original question is alright to discuss.
Sorry for missing some of the details, as well. The CPU I'm currently trying to base my emulation off of the Cortex-M3, although I'm not actually sure whether the device I'm attempting to emulate is an M3 or M4. From what I've read the only real difference is some Thumb support and a DSP module, neither of which I need hopefully.
The register that I was referring to was control register 15, which in the docs I have is referred to simply as "CPU control register." My version of QEMU (which I will try updating as you suggested) refers to 'cp15.mvbar' and 'cp15.vbar', which I have been investigating as the likely base address for execution.
You mention v8M. I haven't looked into that version of the arch, but could it be possible to execute v7M instructions on a v8M CPU? I'd like to avoid modifying QEMU as much as possible, so if there's any workarounds like that I'm receptive to them.
Thank you so much for the detailed response!
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Monday, June 17, 2019 5:46 AM
To: Bensch, Alexander <[email protected]>
Cc: [email protected]
Subject: [EXTERNAL] Re: [Qemu-arm] Custom machine: Forcing initial boot address
Quoted 2 lines · Alexander
Sensitive / Proprietary
Er, you just sent this to a public mailing list...
Quoted 1 line
I am currently trying to modify the MPS2 board to emulate an ARMv7m device I am working on, as none of the included machines provide an environment close enough to what I’m working on to be sufficient. I am running into an issue in which I cannot get the machine to execute the bootROM from address
0xFFFF0000. The specs for the specific device I have (cannot share the device model, unfortunately) state that there is a control register that I assume is present in all v7m chips that selects whether to boot at0x0or0xFFFF0000. I can also see evidence of this register being emulated in QEMU in ‘target/arm/cpu.c’.
It would help if you said what the register name was! "ARMv7M" is an architecture family, which covers some things which must be implemented, and allows some other things to be implementation defined. There are various CPUs that implement ARMv7M, like the Cortex-M3. Then these CPUs can be found in SoCs (like the stm32f205, for example), which add extra memory mapped devices with their own registers.
Quoted 1 line
However, since there is little API documentation I have been able to find, I’ve effectively been reverse-engineering QEMU to figure out what needs to be set. So far, all of my attempts to modify control registers and addresses directly have resulted in unexpected behavior and partial implementation of my goals. I have had success in forcing the ROM to load at the desired address, and with GDB I can force the PC and SP to where I want, but the IVT must be at
0x0by default. I was hoping someone knew how to enable the control register that sets the boot address so that the IVT can be loaded from a different address.
Architecturally the vector table starts at the address specified by the CPU's VTOR register ("Vector Table Offset Register"). QEMU does implement this, but we don't currently provide a mechanism for allowing an SoC model or board model to specify a reset value for it other than zero (because for all the boards we model they use a zero reset value, so we didn't need it). We do provide this mechanism for the v8M secure-banked VTOR -- this is exposed to the rest of QEMU via the "init-svtor" qdev property, which the board can then set. So for a v7M CPU you would need to add something similar for "init-vtor"
to set the non-secure VTOR reset value. Then the CPU would come out of reset by loading the PC and SP from the vector table at that address.
Quoted 1 line
I am running QEMU version 2.11.
If you're modifying QEMU you should start with a much newer version than that. There have been a lot of M-profile related bugfixes since then. Generally for development of QEMU we recommend working with the head of git.
thanks
-- PMM
NOTICE: This email message and all attachments transmitted with it may contain privileged and confidential information, and information that is protected by, and proprietary to, Parsons Corporation, and is intended solely for the use of the addressee for the specific purpose set forth in this communication. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited, and you should delete this message and all copies and backups thereof. The recipient may not further distribute or use any of the information contained herein without the express written authorization of the sender. If you have received this message in error, or if you have any questions regarding the use of the proprietary information contained therein, please contact the sender of this message immediately, and the sender will provide you with further instructions.
Quoted 3 lines · Alexander
Sorry for missing some of the details, as well. The CPU I'm currently trying to base my emulation off of the Cortex-M3, although I'm not actually sure whether the device I'm attempting to emulate is an M3 or M4. From what I've read the only real difference is some Thumb support and a DSP module, neither of which I need hopefully.
The register that I was referring to was control register 15, which in the docs I have is referred to simply as "CPU control register." My version of QEMU (which I will try updating as you suggested) refers to 'cp15.mvbar' and 'cp15.vbar', which I have been investigating as the likely base address for execution.
MVBAR and VBAR are registers for A-profile CPUs. M-profile is significantly different. (In particular M-profile does not have a "cp15".) QEMU supports both, but changing things related to A-profile will either have no effect or bad effects on emulating an M-profile CPU.
M-profile does have a register called "CONTROL", but this doesn't have anything related to the vector table address in it.
Is it possible this register is not part of the CPU but is in the SoC?
I would definitely recommend if you don't have them already getting a copy of the v7M architecture reference manual and the Cortex-M3/M4 technical reference manuals. Then you can cross-reference against whatever docs you have so you can see what's actually architectural and what's specific to the thing you're trying to emulate, and you can use the architecture's names for things that are architectural, which will make this conversation less confusing :-)
Quoted 1 line
You mention v8M. I haven't looked into that version of the arch, but could it be possible to execute v7M instructions on a v8M CPU?
v8M is the next version that supports (among other things) TrustZone for M profile. You would still want to deal with the v7M CPUs though. I mention it just because the v8M init-svtor implementation is a useful guide to implementing the v7M init-vtor.
Quoted 1 line
I'd like to avoid modifying QEMU as much as possible, so if there's any workarounds like that I'm receptive to them.
If you are trying to get QEMU to model a board/SoC that it does not already model, then you are inherently looking at modifying QEMU, I'm afraid. That is the only way to add new board models.
thanks
-- PMM
Sounds like I need to look over the documentation again. I may have misidentified which CPU the target device is using if cp15 is only present on the A series. As a side note, is there an overview for implementing a new board in QEMU? I've searched for a week but haven't been able to turn up anything comprehensive, and none of the currently existing boards seem to have followed any clear structure for implementation. Reference material for creating a device would really help me out.
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Monday, June 17, 2019 9:37 AM
To: Bensch, Alexander <[email protected]>
Cc: [email protected]
Subject: Re: [EXTERNAL] Re: [Qemu-arm] Custom machine: Forcing initial boot address
Quoted 3 lines · Alexander
Sorry for missing some of the details, as well. The CPU I'm currently trying to base my emulation off of the Cortex-M3, although I'm not actually sure whether the device I'm attempting to emulate is an M3 or M4. From what I've read the only real difference is some Thumb support and a DSP module, neither of which I need hopefully.
The register that I was referring to was control register 15, which in the docs I have is referred to simply as "CPU control register." My version of QEMU (which I will try updating as you suggested) refers to 'cp15.mvbar' and 'cp15.vbar', which I have been investigating as the likely base address for execution.
MVBAR and VBAR are registers for A-profile CPUs. M-profile is significantly different. (In particular M-profile does not have a "cp15".) QEMU supports both, but changing things related to A-profile will either have no effect or bad effects on emulating an M-profile CPU.
M-profile does have a register called "CONTROL", but this doesn't have anything related to the vector table address in it.
Is it possible this register is not part of the CPU but is in the SoC?
I would definitely recommend if you don't have them already getting a copy of the v7M architecture reference manual and the Cortex-M3/M4 technical reference manuals. Then you can cross-reference against whatever docs you have so you can see what's actually architectural and what's specific to the thing you're trying to emulate, and you can use the architecture's names for things that are architectural, which will make this conversation less confusing :-)
Quoted 1 line
You mention v8M. I haven't looked into that version of the arch, but could it be possible to execute v7M instructions on a v8M CPU?
v8M is the next version that supports (among other things) TrustZone for M profile. You would still want to deal with the v7M CPUs though. I mention it just because the v8M init-svtor implementation is a useful guide to implementing the v7M init-vtor.
Quoted 1 line
I'd like to avoid modifying QEMU as much as possible, so if there's any workarounds like that I'm receptive to them.
If you are trying to get QEMU to model a board/SoC that it does not already model, then you are inherently looking at modifying QEMU, I'm afraid. That is the only way to add new board models.
thanks
-- PMM
NOTICE: This email message and all attachments transmitted with it may contain privileged and confidential information, and information that is protected by, and proprietary to, Parsons Corporation, and is intended solely for the use of the addressee for the specific purpose set forth in this communication. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited, and you should delete this message and all copies and backups thereof. The recipient may not further distribute or use any of the information contained herein without the express written authorization of the sender. If you have received this message in error, or if you have any questions regarding the use of the proprietary information contained therein, please contact the sender of this message immediately, and the sender will provide you with further instructions.
Quoted 1 line · Alexander
Sounds like I need to look over the documentation again. I may have misidentified which CPU the target device is using if cp15 is only present on the A series. As a side note, is there an overview for implementing a new board in QEMU? I've searched for a week but haven't been able to turn up anything comprehensive, and none of the currently existing boards seem to have followed any clear structure for implementation. Reference material for creating a device would really help me out.
No, I'm afraid we don't have documentation for creating new boards. The best advice is to look at one of the more recently added existing boards, and follow the kinds of things that it does. Older board models and device models tend to use styles or APIs that are deprecated or have better approaches nowadays.
thanks
-- PMM
I finally located some device specific documentation. It turns out the SoC I am targeting has its own bootrom header format that looks deceptively similar to ARMv7-M. The device is actually using a Cortex-A9, and has some headers and execution Thumb code at address 0x0 in the binary that are processed and executed in place on ROM. I am currently working under the assumption that the main bootrom code that gets loaded into DRAM at 0x0 is called by this Thumb code.
There's pretty much no question that I'll need to do a custom board for this, but I haven't been able to find any boards that bypass the built-in mini-bootloader that QEMU uses (defined as ArmInsnFixup bootloader[] in qemu-src/hw/arm/boot.c). Also, because I am unsure if this bootrom addresses statically, I may need to find a way to execute code in place without loading it into memory so that the execution header Thumb code can load at address 0x0 without interfering with the primary bootrom segment loading into DRAM at 0x0.
My questions, given that the previous vector issue has been resolved, are the following:
- Is there a clean way for me to bypass the QEMU simple bootloader that loads at address 0x0 without messing with the core ARM files? In other words, can I do such a thing from a board class?
- Do I need to specify an MVBAR for QEMU if it appears that the device I'm emulating does not expect that component to be loaded into memory? I believe it may be defined in hardware, but so far documentation has not been clear.
- Can I execute code in-place in QEMU? i.e. can I provide QEMU with a Thumb code segment and have it execute that code as if it were present on ROM?
I've tried finding answers to these questions in the QEMU source but haven’t had much luck. Thank you again for your patience, this is all still pretty new to me! Let me know if anything is unclear and hopefully I can clarify. Alex Bensch
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Monday, June 17, 2019 10:41 AM
To: Bensch, Alexander <[email protected]>
Cc: [email protected]
Subject: Re: [EXTERNAL] Re: [Qemu-arm] Custom machine: Forcing initial boot address
Quoted 1 line · Alexander
Sounds like I need to look over the documentation again. I may have misidentified which CPU the target device is using if cp15 is only present on the A series. As a side note, is there an overview for implementing a new board in QEMU? I've searched for a week but haven't been able to turn up anything comprehensive, and none of the currently existing boards seem to have followed any clear structure for implementation. Reference material for creating a device would really help me out.
No, I'm afraid we don't have documentation for creating new boards.
The best advice is to look at one of the more recently added existing boards, and follow the kinds of things that it does. Older board models and device models tend to use styles or APIs that are deprecated or have better approaches nowadays.
thanks
-- PMM
NOTICE: This email message and all attachments transmitted with it may contain privileged and confidential information, and information that is protected by, and proprietary to, Parsons Corporation, and is intended solely for the use of the addressee for the specific purpose set forth in this communication. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited, and you should delete this message and all copies and backups thereof. The recipient may not further distribute or use any of the information contained herein without the express written authorization of the sender. If you have received this message in error, or if you have any questions regarding the use of the proprietary information contained therein, please contact the sender of this message immediately, and the sender will provide you with further instructions.