Add user file size before the file
As a quick fix before FS support
This commit is contained in:
parent
9e528320cf
commit
08a9d7442e
3
Makefile
3
Makefile
@ -45,7 +45,8 @@ disk.img: disk.sfdisk userspace
|
||||
sfdisk $@ < $<
|
||||
# Before having filesystem support, just dump the user prog into the first partition
|
||||
strip userspace/user -o userspace/user.strip
|
||||
dd if=userspace/user.strip of=disk.img seek=2048 bs=512
|
||||
$(eval file_size:=$(shell du -b userspace/user.strip|awk '{print $$1}' | xargs printf "%016d" )) \
|
||||
sed '1s/^/$(file_size)/' userspace/user.strip | dd of=disk.img seek=2048 bs=512
|
||||
|
||||
# NASM without preprocessing
|
||||
%.o:%.asm
|
||||
|
28
core/main.c
28
core/main.c
@ -215,6 +215,8 @@ static uaddr_t loadElfProg(const char *prog)
|
||||
return elf_hdr->e_entry;
|
||||
}
|
||||
|
||||
#define FILE_HEADER_SIZE 16
|
||||
#define FILE_MAX_SIZE 64
|
||||
void loadUserSpace()
|
||||
{
|
||||
struct ata_partition *part = ATAGetPartition(0);
|
||||
@ -224,13 +226,33 @@ void loadUserSpace()
|
||||
return;
|
||||
}
|
||||
|
||||
char *buf = malloc(26 * 512);
|
||||
char *buf = malloc(FILE_MAX_SIZE * 512);
|
||||
if (buf == NULL) {
|
||||
printf("ENOMEM\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ATAReadPartitionSector(part, 0, 26, buf)) {
|
||||
if (ATAReadPartitionSector(part, 0, 1, buf)) {
|
||||
printf("Fail to read from disk\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int sectorToRead;
|
||||
{
|
||||
char size[FILE_HEADER_SIZE + 1];
|
||||
memcpy(size, buf, FILE_HEADER_SIZE);
|
||||
size[FILE_HEADER_SIZE] = '\0';
|
||||
int sizeInt = atoi(size);
|
||||
sectorToRead = DIV_ROUND_UP(sizeInt, DISK_SECTOR_SIZE) - 1;
|
||||
}
|
||||
|
||||
if (sectorToRead > FILE_MAX_SIZE - 1) {
|
||||
printf("File too long");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ATAReadPartitionSector(part, 1, sectorToRead,
|
||||
buf + DISK_SECTOR_SIZE)) {
|
||||
printf("Fail to read from disk\n");
|
||||
return;
|
||||
}
|
||||
@ -238,7 +260,7 @@ void loadUserSpace()
|
||||
struct process *proc = processCreate("UserSpace");
|
||||
|
||||
threadChangeCurrentContext(processGetMMUContext(proc));
|
||||
uaddr_t prog = loadElfProg(buf);
|
||||
uaddr_t prog = loadElfProg(buf + FILE_HEADER_SIZE);
|
||||
if (prog == (uaddr_t)NULL) {
|
||||
free(buf);
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user