Commit 9913e7bf authored by Charles Jacobsen's avatar Charles Jacobsen Committed by Vikram Narayanan

Fixed some bugs in blob build and run.

Per Anton's findings (see lcd commit), updated
location and install for include/linux/lcd-domains.h.

blob build appears correct. blob run won't be testable
until I get (minimal) guest virtual paging setup (I
forgot instruction fetches need paging properly set
up).
parent 4e0064bc
......@@ -471,3 +471,5 @@ header-y += xilinx-v4l2-controls.h
header-y += zorro.h
header-y += zorro_ids.h
header-y += userfaultfd.h
header-y += hw_breakpoint.h
header-y += lcd-domains.h
#ifndef LCD_DOMAINS_H
#define LCD_DOMAINS_H
/*
* lcd-domains.h - public header for LCD support
*/
#include <linux/types.h>
/*
* IOCTL interface
*/
/* FIXME: this must be reserved in miscdevice.h */
#define LCD_MINOR 234
struct lcd_pv_kernel_config {
char *file_name;
unsigned int file_name_length;
__u64 length;
} __attribute__((packed));
struct lcd_blob_info {
unsigned char *blob;
unsigned int blob_order;
} __attribute__((packed));
#define LCD_LOAD_PV_KERNEL _IOR(LCD_MINOR, 0x01, struct lcd_pv_kernel_config)
#define LCD_RUN_BLOB _IOR(LCD_MINOR, 0x02, struct lcd_blob_info)
#endif /* LCD_DOMAINS_H */
run: blob-run blob
./blob-run blob $(python blob-size.py blob.bin -o)
./blob-run blob `python blob-size.py blob.bin -o`
blob-run: blob-run.c
gcc $^ -o $@
blob: blob.S
as blob.S -o blob.bin &&
objdump --output-target=binary \
--pad-to=$(python blob-size.py blob.bin -s) blob.bin blob
\ No newline at end of file
blob: blob.bin
objcopy --output-target=binary \
--pad-to=`python blob-size.py blob.bin -s` blob.bin blob
blob.bin: blob.S
as blob.S -o blob.bin
clean:
rm -f blob blob.bin blob-run *~
\ No newline at end of file
/*
* Code for mapping and running blob in lcd.
*
* Depending on where linux headers are installed,
* may need to change header includes. For example,
*
* sudo headers_install INSTALL_HDR_DIR=/usr/include/temp
*
* will install all include/uapi headers in /usr/include/temp/include/...
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/lcd-domains.h>
#include <temp/linux/lcd-domains.h>
#define PAGE_SIZE 4096
#define DEVICE_NAME "/dev/lcd"
int do_mmap(FILE *f, size_t order, unsigned char **blob_addr_out)
{
void *ret;
size_t len;
len = (1 << size) * PAGE_SIZE;
len = (1 << order) * PAGE_SIZE;
ret = mmap(NULL, len,
PROT_EXEC | PROT_READ | PROT_WRITE,
MAP_ANONYMOUS, fileno(f), 0);
MAP_ANONYMOUS | MAP_PRIVATE, fileno(f), 0);
if (ret == MAP_FAILED) {
return -1;
}
......@@ -23,7 +37,7 @@ int do_mmap(FILE *f, size_t order, unsigned char **blob_addr_out)
void usage(void)
{
fprintf(stderr, "blob: usage: ./blob <blob fname> <blob order>\n");
fprintf(stderr, "blob-run: usage: ./blob <blob fname> <blob order>\n");
fprintf(stderr, " blob should be 2^(blob order) pages\n");
exit(1);
}
......@@ -35,6 +49,7 @@ int main(int argc, char *argv[])
char *fname;
int order;
FILE *f;
int lcd_fd;
/*
* Get blob file name
......@@ -50,26 +65,41 @@ int main(int argc, char *argv[])
*/
f = fopen(fname, "r");
if (!f) {
fprintf(stderr, "blob: error opening file %s\n",
fprintf(stderr, "blob-run: error opening file %s\n",
fname);
exit(-1);
goto fail;
}
if (do_mmap(f, size, &(bi.blob))) {
fprintf(stderr, "blob: error mapping file %s\n",
if (do_mmap(f, order, &(bi.blob))) {
fprintf(stderr, "blob-run: error mapping file %s\n",
fname);
fclose(f);
exit(-1);
goto fail_map;
}
bi.blob_order = order;
/*
* Run in lcd
*/
ret = ioctl(LCD_MINOR, LCD_RUN_BLOB, &bi);
lcd_fd = open(DEVICE_NAME, O_RDONLY);
if (lcd_fd < 0) {
printf("blob-run: error opening lcd device\n");
goto fail_open;
}
ret = ioctl(lcd_fd, LCD_RUN_BLOB, &bi);
if (ret) {
printf("blob: ioctl returned error %d\n", ret);
return -1;
printf("blob-run: ioctl returned error %d\n", ret);
goto fail_ioctl;
}
close(lcd_fd);
fclose(f);
return 0;
fail_ioctl:
close(lcd_fd);
fail_open:
fail_map:
fclose(f);
fail:
return -1;
}
......@@ -17,9 +17,9 @@ if 2 ** order != npages:
order += 1
if sys.argv[2] == "-s":
print str(int((2 ** order) * 4096))
else if sys.argv[2] == "-o":
print str(int(order))
sys.stdout.write(str((2 ** order) * 4096))
elif sys.argv[2] == "-o":
sys.stdout.write(str(order))
else:
sys.stderr.write("blob-size.py: unexpected second option " + sys.argv[2] + "\n")
exit(-1)
.text
;; code goes here
;; no mem accesses allowed for now
\ No newline at end of file
movq $1, %rax
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment