On 10.01.19 13:23, David Hildenbrand wrote: > On 03.01.19 11:08, Janosch Frank wrote: >> z/VM isn't fond of vt220, so we need line mode when running under z/VM. >> >> Signed-off-by: Janosch Frank <frankja@xxxxxxxxxxxxx> >> --- >> lib/s390x/sclp-console.c | 178 ++++++++++++++++++++++++++++++++++++++++++----- >> lib/s390x/sclp.h | 67 ++++++++++++++++++ >> 2 files changed, 228 insertions(+), 17 deletions(-) >> >> diff --git a/lib/s390x/sclp-console.c b/lib/s390x/sclp-console.c >> index a5ef45f..6b30fab 100644 >> --- a/lib/s390x/sclp-console.c >> +++ b/lib/s390x/sclp-console.c >> @@ -11,21 +11,167 @@ >> #include <libcflat.h> >> #include <string.h> >> #include <asm/page.h> >> +#include <asm/arch_def.h> >> +#include <asm/io.h> >> #include "sclp.h" >> [...] >> + >> +static void sclp_print_ascii(const char *str) >> +{ >> + int len = strlen(str); >> + WriteEventData *sccb = (void *)_sccb; >> + >> + sclp_mark_busy(); >> + memset(sccb, 0, sizeof(*sccb)); >> + sccb->h.length = sizeof(WriteEventData) + len; >> + sccb->h.function_code = SCLP_FC_NORMAL_WRITE; >> + sccb->ebh.length = sizeof(EventBufferHeader) + len; >> + sccb->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA; >> + memcpy(sccb->data, str, len); > > Soooo ... what would happen when printing more than 4000 + something > characters? (same applies to lm below) I wouldn't advise on that, because you'll overwrite memory and sclp might have a length limit. But that wasn't a problem before, was it? Do you plan on printing the memory in one go? :-) > >> + >> + sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb); >> +} >> + >> +static void sclp_print_lm(const char *str) >> +{ >> + unsigned char *ptr, *end, ch; >> + unsigned int count, offset, len; >> + struct write_sccb *sccb; >> + struct msg_buf *msg; >> + struct mdb *mdb; >> + struct mto *mto; >> + struct go *go; >> + >> + sclp_mark_busy(); >> + sccb = (struct write_sccb *) _sccb; >> + end = (unsigned char *) sccb + 4096 - 1; > > PAGE_SIZE? (char _sccb[PAGE_SIZE]) > >> + memset(sccb, 0, sizeof(*sccb)); >> + ptr = (unsigned char *) &sccb->msg.mdb.mto; >> + len = strlen(str); >> + offset = 0; >> + do { >> + for (count = sizeof(*mto); offset < len; count++) { >> + ch = str[offset++]; >> + if ((ch == 0x0a) || (ptr + count > end)) >> + break; >> + ptr[count] = _ascebc[ch]; >> + } >> + mto = (struct mto *) ptr; >> + memset(mto, 0, sizeof(*mto)); > > Shouldn't this already be 0? Yup > >> + mto->length = count; >> + mto->type = 4; >> + mto->line_type_flags = LNTPFLGS_ENDTEXT; >> + ptr += count; >> + } while (offset < len && ptr + sizeof(*mto) <= end); >> + len = ptr - (unsigned char *) sccb; >> + sccb->header.length = len - offsetof(struct write_sccb, header); >> + msg = &sccb->msg; >> + msg->header.type = EVTYP_MSG; >> + msg->header.length = len - offsetof(struct write_sccb, msg.header); >> + mdb = &msg->mdb; >> + mdb->header.type = 1; >> + mdb->header.tag = 0xD4C4C240; >> + mdb->header.revision_code = 1; >> + mdb->header.length = len - offsetof(struct write_sccb, msg.mdb.header); >> + go = &mdb->go; >> + go->length = sizeof(*go); >> + go->type = 1; >> + sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb); >> +} >> + >> +/* >> + * SCLP needs to be initialized by setting a send and receive mask, >> + * indicating which messages the control program (we) want(s) to >> + * send/receive. >> + */ >> static void sclp_set_write_mask(void) >> { >> WriteEventMask *sccb = (void *)_sccb; >> >> sclp_mark_busy(); >> + memset(_sccb, 0, sizeof(*sccb)); >> sccb->h.length = sizeof(WriteEventMask); >> - sccb->mask_length = sizeof(unsigned int); >> - sccb->receive_mask = SCLP_EVENT_MASK_MSG_ASCII; >> - sccb->cp_receive_mask = SCLP_EVENT_MASK_MSG_ASCII; >> - sccb->send_mask = SCLP_EVENT_MASK_MSG_ASCII; >> - sccb->cp_send_mask = SCLP_EVENT_MASK_MSG_ASCII; >> + sccb->h.function_code = 0; > > Already 0'ed out. Yes, this one is here to make absolutely clear which function we execute. > >> + sccb->mask_length = sizeof(sccb_mask_t); >> + >> + /* For now we don't process sclp input. */ >> + sccb->cp_receive_mask = 0; > > dito Same If you want, I'll add a comment instead. > >> + /* We send ASCII and line mode. */ >> + sccb->cp_send_mask = SCLP_EVENT_MASK_MSG_ASCII | SCLP_EVENT_MASK_MSG; >> >> sclp_service_call(SCLP_CMD_WRITE_EVENT_MASK, sccb); >> + assert(sccb->h.response_code == SCLP_RC_NORMAL_COMPLETION); >> } >> >> void sclp_console_setup(void) >> @@ -35,16 +181,14 @@ void sclp_console_setup(void) >> >> void sclp_print(const char *str) >> { >> - int len = strlen(str); >> - WriteEventData *sccb = (void *)_sccb; >> - >> - sclp_mark_busy(); >> - sccb->h.length = sizeof(WriteEventData) + len; >> - sccb->h.function_code = SCLP_FC_NORMAL_WRITE; >> - sccb->ebh.length = sizeof(EventBufferHeader) + len; >> - sccb->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA; >> - sccb->ebh.flags = 0; >> - memcpy(sccb->data, str, len); >> - >> - sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb); >> + /* >> + * z/VM advertises a vt220 console which is not functional: >> + * (response code 05F0, "not active because of the state of >> + * the machine"). Hence testing the masks would only work if >> + * we also use stsi data to distinguish z/VM. >> + * >> + * Let's rather print on all available consoles. >> + */ >> + sclp_print_ascii(str); >> + sclp_print_lm(str); >> } >> diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h >> index 63cf609..408bbaf 100644 >> --- a/lib/s390x/sclp.h >> +++ b/lib/s390x/sclp.h >> @@ -179,6 +179,7 @@ typedef struct SCCB { >> /* SCLP event masks */ >> #define SCLP_EVENT_MASK_SIGNAL_QUIESCE 0x00000008 >> #define SCLP_EVENT_MASK_MSG_ASCII 0x00000040 >> +#define SCLP_EVENT_MASK_MSG 0x40000000 >> >> #define SCLP_UNCONDITIONAL_READ 0x00 >> #define SCLP_SELECTIVE_READ 0x01 >> @@ -212,6 +213,72 @@ typedef struct ReadEventData { >> uint32_t mask; >> } __attribute__((packed)) ReadEventData; >> >> +#define MDBTYP_GO 0x0001 >> +#define MDBTYP_MTO 0x0004 >> +#define EVTYP_MSG 0x02 >> +#define LNTPFLGS_CNTLTEXT 0x8000 >> +#define LNTPFLGS_LABELTEXT 0x4000 >> +#define LNTPFLGS_DATATEXT 0x2000 >> +#define LNTPFLGS_ENDTEXT 0x1000 >> +#define LNTPFLGS_PROMPTTEXT 0x0800 >> + >> +typedef uint32_t sccb_mask_t; >> + >> +/* SCLP line mode console related structures. */ >> + >> +struct mto { >> + u16 length; >> + u16 type; >> + u16 line_type_flags; >> + u8 alarm_control; >> + u8 _reserved[3]; >> +} __attribute__((packed)); >> + >> +struct go { >> + u16 length; >> + u16 type; >> + u32 domid; >> + u8 hhmmss_time[8]; >> + u8 th_time[3]; >> + u8 reserved_0; >> + u8 dddyyyy_date[7]; >> + u8 _reserved_1; >> + u16 general_msg_flags; >> + u8 _reserved_2[10]; >> + u8 originating_system_name[8]; >> + u8 job_guest_name[8]; >> +} __attribute__((packed)); >> + >> +struct mdb_header { >> + u16 length; >> + u16 type; >> + u32 tag; >> + u32 revision_code; >> +} __attribute__((packed)); >> + >> +struct mdb { >> + struct mdb_header header; >> + struct go go; >> + struct mto mto; >> +} __attribute__((packed)); >> + >> +struct evbuf_header { >> + u16 length; >> + u8 type; >> + u8 flags; >> + u16 _reserved; >> +} __attribute__((packed)); >> + >> +struct msg_buf { >> + struct evbuf_header header; >> + struct mdb mdb; >> +} __attribute__((packed)); >> + >> +struct write_sccb { >> + struct SCCBHeader header; >> + struct msg_buf msg; >> +} __packed; >> + >> extern char _sccb[]; >> void sclp_handle_ext(void); >> void sclp_wait_busy(void); >> > > I have to trust you on the LM specific parts ;) > I trust the ones that developed that in the kernel.
Attachment:
signature.asc
Description: OpenPGP digital signature