# HG changeset patch # User dietmar.hahn@xxxxxxxxxxxxxxxxxxx # Date 1171978487 -3600 # Node ID 0e0869793af2f614fd020d2f7f893225dc6021be # Parent b83cfb117bddc1f44be53bde49d86b5075bdaa2a First step to have big endian mini-os an little endian hypervisor for ia64. Signed-off-by: Dietmar Hahn diff -r b83cfb117bdd -r 0e0869793af2 extras/mini-os/arch/x86/arch.mk --- a/extras/mini-os/arch/x86/arch.mk Mon Feb 19 22:50:07 2007 +0000 +++ b/extras/mini-os/arch/x86/arch.mk Tue Feb 20 14:34:47 2007 +0100 @@ -3,6 +3,7 @@ # (including x86_32, x86_32y and x86_64). # +pae=y ifeq ($(TARGET_ARCH),x86_32) ARCH_CFLAGS := -m32 -march=i686 ARCH_LDFLAGS := -m elf_i386 diff -r b83cfb117bdd -r 0e0869793af2 extras/mini-os/console/xencons_ring.c --- a/extras/mini-os/console/xencons_ring.c Mon Feb 19 22:50:07 2007 +0000 +++ b/extras/mini-os/console/xencons_ring.c Tue Feb 20 14:34:47 2007 +0100 @@ -28,8 +28,8 @@ int xencons_ring_send_no_notify(const ch int sent = 0; struct xencons_interface *intf = xencons_interface(); XENCONS_RING_IDX cons, prod; - cons = intf->out_cons; - prod = intf->out_prod; + cons = SWAP(intf->out_cons); + prod = SWAP(intf->out_prod); mb(); BUG_ON((prod - cons) > sizeof(intf->out)); @@ -37,7 +37,7 @@ int xencons_ring_send_no_notify(const ch intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++]; wmb(); - intf->out_prod = prod; + intf->out_prod = SWAP(prod); return sent; } @@ -58,8 +58,8 @@ static void handle_input(evtchn_port_t p struct xencons_interface *intf = xencons_interface(); XENCONS_RING_IDX cons, prod; - cons = intf->in_cons; - prod = intf->in_prod; + cons = SWAP(intf->in_cons); + prod = SWAP(intf->in_prod); mb(); BUG_ON((prod - cons) > sizeof(intf->in)); @@ -69,7 +69,7 @@ static void handle_input(evtchn_port_t p } mb(); - intf->in_cons = cons; + intf->in_cons = SWAP(cons); notify_daemon(); diff -r b83cfb117bdd -r 0e0869793af2 extras/mini-os/events.c --- a/extras/mini-os/events.c Mon Feb 19 22:50:07 2007 +0000 +++ b/extras/mini-os/events.c Tue Feb 20 14:34:47 2007 +0100 @@ -46,7 +46,7 @@ void unbind_all_ports(void) { struct evtchn_close close; mask_evtchn(i); - close.port = i; + close.port = SWAP(i); HYPERVISOR_event_channel_op(EVTCHNOP_close, &close); } } @@ -107,16 +107,16 @@ int bind_virq(uint32_t virq, evtchn_hand evtchn_bind_virq_t op; /* Try to bind the virq to a port */ - op.virq = virq; - op.vcpu = smp_processor_id(); + op.virq = SWAP(virq); + op.vcpu = SWAP((uint32_t)smp_processor_id()); if ( HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, &op) != 0 ) { printk("Failed to bind virtual IRQ %d\n", virq); return 1; } - set_bit(op.port,bound_ports); - bind_evtchn(op.port, handler, data); + set_bit(SWAP(op.port),bound_ports); + bind_evtchn(SWAP(op.port), handler, data); return 0; } @@ -168,12 +168,12 @@ int evtchn_alloc_unbound(domid_t pal, ev void *data, evtchn_port_t *port) { evtchn_alloc_unbound_t op; - op.dom = DOMID_SELF; - op.remote_dom = pal; + op.dom = SWAP((domid_t)DOMID_SELF); + op.remote_dom = SWAP(pal); int err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op); if (err) return err; - *port = bind_evtchn(op.port, handler, data); + *port = bind_evtchn(SWAP(op.port), handler, data); return err; } @@ -185,13 +185,13 @@ int evtchn_bind_interdomain(domid_t pal, evtchn_port_t *local_port) { evtchn_bind_interdomain_t op; - op.remote_dom = pal; - op.remote_port = remote_port; + op.remote_dom = SWAP(pal); + op.remote_port = SWAP(remote_port); int err = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain, &op); if (err) return err; - set_bit(op.local_port,bound_ports); - evtchn_port_t port = op.local_port; + set_bit(SWAP(op.local_port),bound_ports); + evtchn_port_t port = SWAP(op.local_port); clear_evtchn(port); /* Without, handler gets invoked now! */ *local_port = bind_evtchn(port, handler, data); return err; diff -r b83cfb117bdd -r 0e0869793af2 extras/mini-os/gnttab.c --- a/extras/mini-os/gnttab.c Mon Feb 19 22:50:07 2007 +0000 +++ b/extras/mini-os/gnttab.c Tue Feb 20 14:34:47 2007 +0100 @@ -54,11 +54,12 @@ gnttab_grant_access(domid_t domid, unsig grant_ref_t ref; ref = get_free_entry(); - gnttab_table[ref].frame = frame; - gnttab_table[ref].domid = domid; + gnttab_table[ref].frame = SWAP((uint32_t)frame); + gnttab_table[ref].domid = SWAP(domid); wmb(); readonly *= GTF_readonly; - gnttab_table[ref].flags = GTF_permit_access | readonly; + uint16_t flags = (uint16_t) GTF_permit_access | (uint16_t) readonly; + gnttab_table[ref].flags = SWAP(flags); return ref; } @@ -69,10 +70,10 @@ gnttab_grant_transfer(domid_t domid, uns grant_ref_t ref; ref = get_free_entry(); - gnttab_table[ref].frame = pfn; - gnttab_table[ref].domid = domid; + gnttab_table[ref].frame = SWAP((uint32_t)pfn); + gnttab_table[ref].domid = SWAP(domid); wmb(); - gnttab_table[ref].flags = GTF_accept_transfer; + gnttab_table[ref].flags = SWAP((uint16_t)GTF_accept_transfer); return ref; } @@ -82,14 +83,14 @@ gnttab_end_access(grant_ref_t ref) { u16 flags, nflags; - nflags = gnttab_table[ref].flags; + nflags = SWAP(gnttab_table[ref].flags); do { if ((flags = nflags) & (GTF_reading|GTF_writing)) { printk("WARNING: g.e. still in use!\n"); return 0; } - } while ((nflags = synch_cmpxchg(&gnttab_table[ref].flags, flags, 0)) != - flags); + } while ((nflags = SWAP(synch_cmpxchg(&gnttab_table[ref].flags, + SWAP(flags), 0))) != flags); put_free_entry(ref); return 1; @@ -101,8 +102,9 @@ gnttab_end_transfer(grant_ref_t ref) unsigned long frame; u16 flags; - while (!((flags = gnttab_table[ref].flags) & GTF_transfer_committed)) { - if (synch_cmpxchg(&gnttab_table[ref].flags, flags, 0) == flags) { + while (!((flags = SWAP(gnttab_table[ref].flags)) & GTF_transfer_committed)) { + if (SWAP(synch_cmpxchg(&gnttab_table[ref].flags, SWAP(flags), 0)) == + flags) { printk("Release unused transfer grant.\n"); put_free_entry(ref); return 0; @@ -111,12 +113,12 @@ gnttab_end_transfer(grant_ref_t ref) /* If a transfer is in progress then wait until it is completed. */ while (!(flags & GTF_transfer_completed)) { - flags = gnttab_table[ref].flags; + flags = SWAP(gnttab_table[ref].flags); } /* Read the frame number /after/ reading completion status. */ rmb(); - frame = gnttab_table[ref].frame; + frame = SWAP(gnttab_table[ref].frame); put_free_entry(ref); @@ -157,9 +159,9 @@ init_gnttab(void) for (i = NR_RESERVED_ENTRIES; i < NR_GRANT_ENTRIES; i++) put_free_entry(i); - setup.dom = DOMID_SELF; - setup.nr_frames = NR_GRANT_FRAMES; - set_xen_guest_handle(setup.frame_list, frames); + setup.dom = SWAP((domid_t)DOMID_SELF); + setup.nr_frames = SWAP((uint32_t)NR_GRANT_FRAMES); + set_xen_guest_handle(setup.frame_list, (void*)SWAP((unsigned long)frames)); HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1); gnttab_table = map_frames(frames, NR_GRANT_FRAMES); diff -r b83cfb117bdd -r 0e0869793af2 extras/mini-os/hypervisor.c --- a/extras/mini-os/hypervisor.c Mon Feb 19 22:50:07 2007 +0000 +++ b/extras/mini-os/hypervisor.c Tue Feb 20 14:34:47 2007 +0100 @@ -30,8 +30,8 @@ #include #define active_evtchns(cpu,sh,idx) \ - ((sh)->evtchn_pending[idx] & \ - ~(sh)->evtchn_mask[idx]) + (SWAP((sh)->evtchn_pending[idx]) & \ + SWAP(~(sh)->evtchn_mask[idx])) void do_hypervisor_callback(struct pt_regs *regs) { @@ -44,7 +44,7 @@ void do_hypervisor_callback(struct pt_re vcpu_info->evtchn_upcall_pending = 0; /* NB. No need for a barrier here -- XCHG is a barrier on x86. */ - l1 = xchg(&vcpu_info->evtchn_pending_sel, 0); + l1 = SWAP(xchg(&vcpu_info->evtchn_pending_sel, 0)); while ( l1 != 0 ) { l1i = __ffs(l1); @@ -82,7 +82,7 @@ inline void unmask_evtchn(u32 port) if ( synch_test_bit (port, &s->evtchn_pending[0]) && !synch_test_and_set_bit(port>>5, &vcpu_info->evtchn_pending_sel) ) { - vcpu_info->evtchn_upcall_pending = 1; + vcpu_info->evtchn_upcall_pending = SWAP((uint8_t)1); if ( !vcpu_info->evtchn_upcall_mask ) force_evtchn_callback(); } diff -r b83cfb117bdd -r 0e0869793af2 extras/mini-os/include/events.h --- a/extras/mini-os/include/events.h Mon Feb 19 22:50:07 2007 +0000 +++ b/extras/mini-os/include/events.h Tue Feb 20 14:34:47 2007 +0100 @@ -41,7 +41,7 @@ static inline int notify_remote_via_evtc static inline int notify_remote_via_evtchn(evtchn_port_t port) { evtchn_send_t op; - op.port = port; + op.port = SWAP(port); return HYPERVISOR_event_channel_op(EVTCHNOP_send, &op); } diff -r b83cfb117bdd -r 0e0869793af2 extras/mini-os/include/x86/os.h --- a/extras/mini-os/include/x86/os.h Mon Feb 19 22:50:07 2007 +0000 +++ b/extras/mini-os/include/x86/os.h Tue Feb 20 14:34:47 2007 +0100 @@ -13,6 +13,9 @@ #define unlikely(x) __builtin_expect((x),0) #define smp_processor_id() 0 + +/* Used in ia64 mini-os to run big endian on little endian hypervisor. */ +#define SWAP(x) (x) #ifndef __ASSEMBLY__ diff -r b83cfb117bdd -r 0e0869793af2 extras/mini-os/xenbus/xenbus.c --- a/extras/mini-os/xenbus/xenbus.c Mon Feb 19 22:50:07 2007 +0000 +++ b/extras/mini-os/xenbus/xenbus.c Tue Feb 20 14:34:47 2007 +0100 @@ -99,33 +99,35 @@ char* xenbus_wait_for_value(const char* return NULL; } - static void xenbus_thread_func(void *ign) { struct xsd_sockmsg msg; - unsigned prod = 0; + XENSTORE_RING_IDX rsp_cons, rsp_prod = 0; for (;;) { - wait_event(xb_waitq, prod != xenstore_buf->rsp_prod); + wait_event(xb_waitq, rsp_prod != SWAP(xenstore_buf->rsp_prod)); while (1) { - prod = xenstore_buf->rsp_prod; - DEBUG("Rsp_cons %d, rsp_prod %d.\n", xenstore_buf->rsp_cons, - xenstore_buf->rsp_prod); - if (xenstore_buf->rsp_prod - xenstore_buf->rsp_cons < sizeof(msg)) + rsp_prod = SWAP(xenstore_buf->rsp_prod); + rsp_cons = SWAP(xenstore_buf->rsp_cons); + DEBUG("Rsp_cons %d, rsp_prod %d.\n", rsp_cons, rsp_prod); + if (rsp_prod - rsp_cons < sizeof(msg)) break; rmb(); memcpy_from_ring(xenstore_buf->rsp, &msg, - MASK_XENSTORE_IDX(xenstore_buf->rsp_cons), + MASK_XENSTORE_IDX(rsp_cons), sizeof(msg)); + msg.type = SWAP(msg.type); + msg.req_id = SWAP(msg.req_id); + msg.tx_id = SWAP(msg.tx_id); + msg.len = SWAP(msg.len); DEBUG("Msg len %d, %d avail, id %d.\n", msg.len + sizeof(msg), - xenstore_buf->rsp_prod - xenstore_buf->rsp_cons, + rsp_prod - rsp_cons, msg.req_id); - if (xenstore_buf->rsp_prod - xenstore_buf->rsp_cons < - sizeof(msg) + msg.len) + if (rsp_prod - rsp_cons < sizeof(msg) + msg.len) break; DEBUG("Message is good.\n"); @@ -137,13 +139,14 @@ static void xenbus_thread_func(void *ign memcpy_from_ring(xenstore_buf->rsp, payload, - MASK_XENSTORE_IDX(xenstore_buf->rsp_cons), + MASK_XENSTORE_IDX(rsp_cons), msg.len + sizeof(msg)); path = payload + sizeof(msg); token = path + strlen(path) + 1; - xenstore_buf->rsp_cons += msg.len + sizeof(msg); + rsp_cons += msg.len + sizeof(msg); + xenstore_buf->rsp_cons = SWAP(rsp_cons); free(payload); wake_up(&watch_queue); } @@ -153,9 +156,10 @@ static void xenbus_thread_func(void *ign req_info[msg.req_id].reply = malloc(sizeof(msg) + msg.len); memcpy_from_ring(xenstore_buf->rsp, req_info[msg.req_id].reply, - MASK_XENSTORE_IDX(xenstore_buf->rsp_cons), + MASK_XENSTORE_IDX(rsp_cons), msg.len + sizeof(msg)); - xenstore_buf->rsp_cons += msg.len + sizeof(msg); + rsp_cons += msg.len + sizeof(msg); + xenstore_buf->rsp_cons = SWAP(rsp_cons); wake_up(&req_info[msg.req_id].waitq); } } @@ -251,13 +255,13 @@ static void xb_write(int type, int req_i int req_off; int total_off; int this_chunk; - struct xsd_sockmsg m = {.type = type, .req_id = req_id, - .tx_id = trans_id }; + struct xsd_sockmsg m = {.type = SWAP(type), .req_id = SWAP(req_id), + .tx_id = SWAP(trans_id) }; struct write_req header_req = { &m, sizeof(m) }; for (r = 0; r < nr_reqs; r++) len += req[r].len; - m.len = len; + m.len = SWAP(len); len += sizeof(m); cur_req = &header_req; @@ -265,17 +269,17 @@ static void xb_write(int type, int req_i BUG_ON(len > XENSTORE_RING_SIZE); /* Wait for the ring to drain to the point where we can send the message. */ - prod = xenstore_buf->req_prod; - if (prod + len - xenstore_buf->req_cons > XENSTORE_RING_SIZE) + prod = SWAP(xenstore_buf->req_prod); + if (prod + len - SWAP(xenstore_buf->req_cons) > XENSTORE_RING_SIZE) { /* Wait for there to be space on the ring */ DEBUG("prod %d, len %d, cons %d, size %d; waiting.\n", - prod, len, xenstore_buf->req_cons, XENSTORE_RING_SIZE); + prod, len, SWAP(xenstore_buf->req_cons), XENSTORE_RING_SIZE); wait_event(xb_waitq, - xenstore_buf->req_prod + len - xenstore_buf->req_cons <= - XENSTORE_RING_SIZE); + SWAP(xenstore_buf->req_prod) + len - + SWAP(xenstore_buf->req_cons) <= XENSTORE_RING_SIZE); DEBUG("Back from wait.\n"); - prod = xenstore_buf->req_prod; + prod = SWAP(xenstore_buf->req_prod); } /* We're now guaranteed to be able to send the message without @@ -304,12 +308,13 @@ static void xb_write(int type, int req_i DEBUG("Complete main loop of xb_write.\n"); BUG_ON(req_off != 0); BUG_ON(total_off != len); - BUG_ON(prod > xenstore_buf->req_cons + XENSTORE_RING_SIZE); + BUG_ON(prod > SWAP(xenstore_buf->req_cons) + XENSTORE_RING_SIZE); /* Remote must see entire message before updating indexes */ wmb(); - xenstore_buf->req_prod += len; + XENSTORE_RING_IDX req_prod = SWAP(xenstore_buf->req_prod) + len; + xenstore_buf->req_prod = SWAP(req_prod); /* Send evtchn to notify remote */ notify_remote_via_evtchn(start_info.store_evtchn); @@ -337,6 +342,11 @@ xenbus_msg_reply(int type, wake(current); rep = req_info[id].reply; + rep->type = SWAP(rep->type); + rep->req_id = SWAP(rep->req_id); + rep->tx_id = SWAP(rep->tx_id); + rep->len = SWAP(rep->len); + BUG_ON(rep->req_id != id); release_xenbus_id(id); return rep; @@ -370,7 +380,7 @@ static void xenbus_debug_msg(const char reply = xenbus_msg_reply(XS_DEBUG, 0, req, ARRAY_SIZE(req)); DEBUG("Got a reply, type %d, id %d, len %d.\n", - reply->type, reply->req_id, reply->len); + SWAP(reply->type), SWAP(reply->req_id), SWAP(reply->len)); } /* List the contents of a directory. Returns a malloc()ed array of