Skip to content

Commit 47fa1ad

Browse files
committed
Merge remote-tracking branch 'remotes/vivier/tags/m68k-for-7.0-pull-request' into staging
m68k pull request 20220120 Fix virt-m68k reboot # gpg: Signature made Thu 20 Jan 2022 08:35:50 GMT # gpg: using RSA key CD2F75DDC8E3A4DC2E4F5173F30C38BD3F2FBE3C # gpg: issuer "[email protected]" # gpg: Good signature from "Laurent Vivier <[email protected]>" [full] # gpg: aka "Laurent Vivier <[email protected]>" [full] # gpg: aka "Laurent Vivier (Red Hat) <[email protected]>" [full] # Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F 5173 F30C 38BD 3F2F BE3C * remotes/vivier/tags/m68k-for-7.0-pull-request: m68k: virt: correctly set the initial PC hw/elf_ops: clear uninitialized segment space exec/memory: Extract address_space_set() from dma_memory_set() Signed-off-by: Peter Maydell <[email protected]>
2 parents b10d00d + e48b140 commit 47fa1ad

File tree

6 files changed

+70
-19
lines changed

6 files changed

+70
-19
lines changed

hw/core/loader.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,9 +1164,13 @@ static void rom_reset(void *unused)
11641164
if (rom->mr) {
11651165
void *host = memory_region_get_ram_ptr(rom->mr);
11661166
memcpy(host, rom->data, rom->datasize);
1167+
memset(host + rom->datasize, 0, rom->romsize - rom->datasize);
11671168
} else {
11681169
address_space_write_rom(rom->as, rom->addr, MEMTXATTRS_UNSPECIFIED,
11691170
rom->data, rom->datasize);
1171+
address_space_set(rom->as, rom->addr + rom->datasize, 0,
1172+
rom->romsize - rom->datasize,
1173+
MEMTXATTRS_UNSPECIFIED);
11701174
}
11711175
if (rom->isrom) {
11721176
/* rom needs to be written only once */

hw/m68k/virt.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,21 @@
8585
#define VIRT_VIRTIO_MMIO_BASE 0xff010000 /* MMIO: 0xff010000 - 0xff01ffff */
8686
#define VIRT_VIRTIO_IRQ_BASE PIC_IRQ(2, 1) /* PIC: 2, 3, 4, 5, IRQ: ALL */
8787

88+
typedef struct {
89+
M68kCPU *cpu;
90+
hwaddr initial_pc;
91+
hwaddr initial_stack;
92+
} ResetInfo;
93+
8894
static void main_cpu_reset(void *opaque)
8995
{
90-
M68kCPU *cpu = opaque;
96+
ResetInfo *reset_info = opaque;
97+
M68kCPU *cpu = reset_info->cpu;
9198
CPUState *cs = CPU(cpu);
9299

93100
cpu_reset(cs);
94-
cpu->env.aregs[7] = ldl_phys(cs->as, 0);
95-
cpu->env.pc = ldl_phys(cs->as, 4);
101+
cpu->env.aregs[7] = reset_info->initial_stack;
102+
cpu->env.pc = reset_info->initial_pc;
96103
}
97104

98105
static void virt_init(MachineState *machine)
@@ -113,6 +120,7 @@ static void virt_init(MachineState *machine)
113120
SysBusDevice *sysbus;
114121
hwaddr io_base;
115122
int i;
123+
ResetInfo *reset_info;
116124

117125
if (ram_size > 3399672 * KiB) {
118126
/*
@@ -124,9 +132,13 @@ static void virt_init(MachineState *machine)
124132
exit(1);
125133
}
126134

135+
reset_info = g_malloc0(sizeof(ResetInfo));
136+
127137
/* init CPUs */
128138
cpu = M68K_CPU(cpu_create(machine->cpu_type));
129-
qemu_register_reset(main_cpu_reset, cpu);
139+
140+
reset_info->cpu = cpu;
141+
qemu_register_reset(main_cpu_reset, reset_info);
130142

131143
/* RAM */
132144
memory_region_add_subregion(get_system_memory(), 0, machine->ram);
@@ -206,7 +218,7 @@ static void virt_init(MachineState *machine)
206218
error_report("could not load kernel '%s'", kernel_filename);
207219
exit(1);
208220
}
209-
stl_phys(cs->as, 4, elf_entry); /* reset initial PC */
221+
reset_info->initial_pc = elf_entry;
210222
parameters_base = (high + 1) & ~1;
211223

212224
BOOTINFO1(cs->as, parameters_base, BI_MACHTYPE, MACH_VIRT);

include/exec/memory.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,6 +2908,22 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
29082908
}
29092909
}
29102910

2911+
/**
2912+
* address_space_set: Fill address space with a constant byte.
2913+
*
2914+
* Return a MemTxResult indicating whether the operation succeeded
2915+
* or failed (eg unassigned memory, device rejected the transaction,
2916+
* IOMMU fault).
2917+
*
2918+
* @as: #AddressSpace to be accessed
2919+
* @addr: address within that address space
2920+
* @c: constant byte to fill the memory
2921+
* @len: the number of bytes to fill with the constant byte
2922+
* @attrs: memory transaction attributes
2923+
*/
2924+
MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
2925+
uint8_t c, hwaddr len, MemTxAttrs attrs);
2926+
29112927
#ifdef NEED_CPU_H
29122928
/* enum device_endian to MemOp. */
29132929
static inline MemOp devend_memop(enum device_endian end)

include/hw/elf_ops.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,19 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
555555
if (res != MEMTX_OK) {
556556
goto fail;
557557
}
558+
/*
559+
* We need to zero'ify the space that is not copied
560+
* from file
561+
*/
562+
if (file_size < mem_size) {
563+
res = address_space_set(as ? as : &address_space_memory,
564+
addr + file_size, 0,
565+
mem_size - file_size,
566+
MEMTXATTRS_UNSPECIFIED);
567+
if (res != MEMTX_OK) {
568+
goto fail;
569+
}
570+
}
558571
}
559572
}
560573

softmmu/dma-helpers.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,7 @@ MemTxResult dma_memory_set(AddressSpace *as, dma_addr_t addr,
2323
{
2424
dma_barrier(as, DMA_DIRECTION_FROM_DEVICE);
2525

26-
#define FILLBUF_SIZE 512
27-
uint8_t fillbuf[FILLBUF_SIZE];
28-
int l;
29-
MemTxResult error = MEMTX_OK;
30-
31-
memset(fillbuf, c, FILLBUF_SIZE);
32-
while (len > 0) {
33-
l = len < FILLBUF_SIZE ? len : FILLBUF_SIZE;
34-
error |= address_space_write(as, addr, attrs, fillbuf, l);
35-
len -= l;
36-
addr += l;
37-
}
38-
39-
return error;
26+
return address_space_set(as, addr, c, len, attrs);
4027
}
4128

4229
void qemu_sglist_init(QEMUSGList *qsg, DeviceState *dev, int alloc_hint,

softmmu/physmem.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,25 @@ MemTxResult address_space_rw(AddressSpace *as, hwaddr addr, MemTxAttrs attrs,
29272927
}
29282928
}
29292929

2930+
MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
2931+
uint8_t c, hwaddr len, MemTxAttrs attrs)
2932+
{
2933+
#define FILLBUF_SIZE 512
2934+
uint8_t fillbuf[FILLBUF_SIZE];
2935+
int l;
2936+
MemTxResult error = MEMTX_OK;
2937+
2938+
memset(fillbuf, c, FILLBUF_SIZE);
2939+
while (len > 0) {
2940+
l = len < FILLBUF_SIZE ? len : FILLBUF_SIZE;
2941+
error |= address_space_write(as, addr, attrs, fillbuf, l);
2942+
len -= l;
2943+
addr += l;
2944+
}
2945+
2946+
return error;
2947+
}
2948+
29302949
void cpu_physical_memory_rw(hwaddr addr, void *buf,
29312950
hwaddr len, bool is_write)
29322951
{

0 commit comments

Comments
 (0)