initial import
[ps3linux_ps3lv1write.git] / ps3lv1write.c
blob165483206fe6be9b256c8c7dee7302ecaf165909
1 /*-
2 * Copyright (C) 2014 glevand <geoffrey.levand@mail.ru>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <stdint.h>
31 #include <getopt.h>
32 #include <errno.h>
34 #include "dev.h"
36 #define CONS_ID 1
37 #define CONS_LENGTH 0xff0
39 static struct option long_opts[] = {
40 { "device", no_argument, NULL, 'd' },
41 { NULL, 0, NULL, 0 }
44 static const char *device = "/dev/ps3lv1call";
47 * parse_opts
49 static int parse_opts(int argc, char **argv)
51 int c;
53 while ((c = getopt_long(argc, argv, "d:", long_opts, NULL)) != -1) {
54 switch (c) {
55 case 'd':
56 device = optarg;
57 break;
58 default:
59 fprintf(stderr, "invalid option specified: %c\n", c);
60 return (-1);
61 break;
65 return (0);
68 static void lv1_console_init(uint64_t id, uint64_t len)
70 uint64_t in_args[8];
71 int num_in_args;
72 uint64_t out_args[8];
73 int64_t result;
75 in_args[0] = id;
76 in_args[1] = 0;
77 in_args[2] = 0;
78 in_args[3] = len;
79 in_args[4] = len;
80 in_args[5] = 0;
81 in_args[5] = 0;
82 num_in_args = 7;
84 dev_do_lv1call(device, 105, in_args, num_in_args, out_args, &result);
87 static void lv1_console_putchar(uint64_t id, int c)
89 uint64_t in_args[8];
90 int num_in_args;
91 uint64_t out_args[8];
92 int64_t result;
93 uint64_t data;
95 if (c == '\n')
96 c = '\r';
98 data = c;
99 data <<= 56;
101 in_args[0] = id;
102 in_args[1] = 1;
103 in_args[2] = data;
104 in_args[3] = 0;
105 in_args[4] = 0;
106 in_args[5] = 0;
107 num_in_args = 6;
109 dev_do_lv1call(device, 107, in_args, num_in_args, out_args, &result);
112 static void lv1_console_flush(uint64_t id)
114 uint64_t in_args[8];
115 int num_in_args;
116 uint64_t out_args[8];
117 int64_t result;
119 in_args[0] = id;
120 num_in_args = 1;
122 dev_do_lv1call(device, 109, in_args, num_in_args, out_args, &result);
126 * main
128 int main(int argc, char **argv)
130 int i, j;
131 int ret;
133 ret = parse_opts(argc, argv);
134 if (ret)
135 return (255);
137 lv1_console_init(CONS_ID, CONS_LENGTH);
139 for (i = optind; i < argc; i++) {
140 for (j = 0; j < strlen(argv[i]); j++)
141 lv1_console_putchar(CONS_ID, argv[i][j]);
142 lv1_console_putchar(CONS_ID, '\n');
143 lv1_console_flush(CONS_ID);
146 return (0);