make disk with kernel
This commit is contained in:
parent
7c505804f2
commit
28514b4efa
@ -21,11 +21,37 @@ add_subdirectory(src)
|
|||||||
add_subdirectory(boot)
|
add_subdirectory(boot)
|
||||||
add_subdirectory(kernel)
|
add_subdirectory(kernel)
|
||||||
|
|
||||||
add_custom_target(
|
block()
|
||||||
run
|
set(boot_file ${CMAKE_CURRENT_BINARY_DIR}/boot/boot.bin)
|
||||||
DEPENDS emu build-boot.bin
|
set(kernel_file ${CMAKE_CURRENT_BINARY_DIR}/kernel/kernel.bin)
|
||||||
COMMAND emu boot/boot.bin
|
set(fs_file ${CMAKE_CURRENT_BINARY_DIR}/fs.bin)
|
||||||
|
set(disk_file ${CMAKE_CURRENT_BINARY_DIR}/disk.bin)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${fs_file}
|
||||||
|
COMMAND fstool ${fs_file} mkfile /kernel.bin
|
||||||
|
COMMAND fstool ${fs_file} import ${kernel_file} /kernel.bin
|
||||||
|
DEPENDS fstool ${kernel_file}
|
||||||
VERBATIM
|
VERBATIM
|
||||||
USES_TERMINAL
|
USES_TERMINAL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${disk_file}
|
||||||
|
COMMAND mkdisk ${disk_file} ${boot_file} ${fs_file}:0800
|
||||||
|
DEPENDS mkdisk ${boot_file} ${fs_file}
|
||||||
|
VERBATIM
|
||||||
|
USES_TERMINAL
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(disk.bin.target ALL DEPENDS ${disk_file})
|
||||||
|
|
||||||
|
add_custom_target(
|
||||||
|
run
|
||||||
|
COMMAND emu ${disk_file}
|
||||||
|
DEPENDS emu ${disk_file}
|
||||||
|
VERBATIM
|
||||||
|
USES_TERMINAL
|
||||||
|
)
|
||||||
|
endblock()
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
|
|
||||||
add_vc6asm_bin_target(boot.bin boot.vc6asm)
|
vc6_asm_target(boot.bin boot.vc6asm)
|
||||||
|
|
||||||
|
|||||||
@ -13,11 +13,11 @@ start:
|
|||||||
mov sp, bp
|
mov sp, bp
|
||||||
|
|
||||||
mov r1, text
|
mov r1, text
|
||||||
mov r2, VCD_BEGIN + 80
|
mov r2, VCD_BEGIN + (1 * 40 + 0)
|
||||||
call println
|
call println
|
||||||
|
|
||||||
mov r1, prompt
|
mov r1, prompt
|
||||||
mov r2, VCD_BEGIN + 120
|
mov r2, VCD_BEGIN + (3 * 40 + 0)
|
||||||
mov r0, ip
|
mov r0, ip
|
||||||
call println
|
call println
|
||||||
|
|
||||||
@ -38,6 +38,20 @@ start:
|
|||||||
and fl, FL_LT
|
and fl, FL_LT
|
||||||
cmov ip, r2
|
cmov ip, r2
|
||||||
|
|
||||||
|
mov r0, 8
|
||||||
|
store [DISK_BLOCK_ID], r0
|
||||||
|
mov r0, 0x0400
|
||||||
|
store [DISK_ADDR], r0
|
||||||
|
mov r0, DISK_CTL_START
|
||||||
|
store [DISK_CTL], r0
|
||||||
|
|
||||||
|
mov r1, 0x0400
|
||||||
|
mov r2, VCD_BEGIN + (2 * 40 + 0)
|
||||||
|
mov r0, ip
|
||||||
|
call println
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mov r0, keydown_handler
|
mov r0, keydown_handler
|
||||||
store [KBD_KEYDOWN_HANDLER], r0
|
store [KBD_KEYDOWN_HANDLER], r0
|
||||||
mov r1, 0
|
mov r1, 0
|
||||||
@ -92,7 +106,7 @@ println:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
text:
|
text:
|
||||||
dw "hello world\0"
|
dw "boot loader\0"
|
||||||
prompt:
|
prompt:
|
||||||
dw "> \0"
|
dw "> \0"
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
|
|
||||||
add_vc6asm_bin_target(kernel.bin kernel.vc6asm)
|
vc6_asm_target(kernel.bin kernel.vc6asm)
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
@include "../boot/arch.vc6asm"
|
@include "../boot/arch.vc6asm"
|
||||||
@include "../boot/macros.vc6asm"
|
@include "../boot/macros.vc6asm"
|
||||||
|
|
||||||
@org 0x0100
|
@org 0x0800
|
||||||
|
|
||||||
|
dw "haiiiiiiiiiiiiiiiiiii\0"
|
||||||
|
|
||||||
main:
|
main:
|
||||||
mov r1, 'V'
|
mov r1, 'V'
|
||||||
|
|||||||
@ -48,19 +48,22 @@ target_link_libraries(fscli PRIVATE opts fs)
|
|||||||
add_executable(fstool fstool.c)
|
add_executable(fstool fstool.c)
|
||||||
target_link_libraries(fstool PRIVATE opts fs)
|
target_link_libraries(fstool PRIVATE opts fs)
|
||||||
|
|
||||||
function(add_vc6asm_bin_target TARGET_NAME SOURCE_FILE)
|
add_executable(mkdisk mkdisk.c)
|
||||||
|
target_link_libraries(mkdisk PRIVATE opts)
|
||||||
|
|
||||||
|
function(vc6_asm_target target_name source_file)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target_name}
|
||||||
COMMAND asm ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE} -o ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} -M
|
COMMAND asm ${CMAKE_CURRENT_SOURCE_DIR}/${source_file} -o ${CMAKE_CURRENT_BINARY_DIR}/${target_name} -M
|
||||||
DEPENDS asm ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE}
|
DEPENDS asm ${CMAKE_CURRENT_SOURCE_DIR}/${source_file}
|
||||||
DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}.d
|
DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.d
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
${TARGET_NAME}.target
|
${target_name}.target
|
||||||
ALL
|
ALL
|
||||||
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${target_name}
|
||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|||||||
@ -672,6 +672,7 @@ void assembler_init(Assembler *a, Lexer *lexer)
|
|||||||
.dep_str_map = { },
|
.dep_str_map = { },
|
||||||
.dep_file = nullptr,
|
.dep_file = nullptr,
|
||||||
.directive_depth = 0,
|
.directive_depth = 0,
|
||||||
|
.org_offset = 0,
|
||||||
.second_pass = false,
|
.second_pass = false,
|
||||||
.print = false,
|
.print = false,
|
||||||
};
|
};
|
||||||
@ -695,6 +696,7 @@ void assembler_rewind(Assembler *a)
|
|||||||
a->labels_counter = 0;
|
a->labels_counter = 0;
|
||||||
a->current_label = 0;
|
a->current_label = 0;
|
||||||
a->expan_ids = 0;
|
a->expan_ids = 0;
|
||||||
|
a->org_offset = 0;
|
||||||
a->second_pass = true;
|
a->second_pass = true;
|
||||||
|
|
||||||
map_clear(&a->guard_set);
|
map_clear(&a->guard_set);
|
||||||
|
|||||||
@ -406,7 +406,7 @@ void filedisk_read_block(Disk *disk, uint16_t *data, uint16_t block_id)
|
|||||||
{
|
{
|
||||||
FileDisk *d = (FileDisk *)disk;
|
FileDisk *d = (FileDisk *)disk;
|
||||||
fseek(d->file, sizeof(uint16_t) * disk->block_size * block_id, SEEK_SET);
|
fseek(d->file, sizeof(uint16_t) * disk->block_size * block_id, SEEK_SET);
|
||||||
fread(data, d->disk.block_size, sizeof(uint16_t), d->file);
|
fread(data, sizeof(uint16_t), d->disk.block_size, d->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void filedisk_write_block(Disk *disk, const uint16_t *data, uint16_t block_id)
|
void filedisk_write_block(Disk *disk, const uint16_t *data, uint16_t block_id)
|
||||||
|
|||||||
18
src/fstool.c
18
src/fstool.c
@ -40,7 +40,7 @@ static void save(Fs *fs, Disk *disk, const char *filename)
|
|||||||
size_t words_written = fwrite(
|
size_t words_written = fwrite(
|
||||||
disk->blocks, sizeof(uint16_t), block_size * amount_of_blocks, file);
|
disk->blocks, sizeof(uint16_t), block_size * amount_of_blocks, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
printf("wrote %zu words to %s\n", words_written, filename);
|
printf("%zu words written\n", words_written);
|
||||||
|
|
||||||
fs_destroy(fs);
|
fs_destroy(fs);
|
||||||
free(disk->blocks);
|
free(disk->blocks);
|
||||||
@ -120,7 +120,7 @@ int main(int argc, char *argv[])
|
|||||||
INode parent;
|
INode parent;
|
||||||
resolve_path(fs, &parent, path_copy);
|
resolve_path(fs, &parent, path_copy);
|
||||||
|
|
||||||
printf("creating directory '%s' in %d.\n", name, parent.id);
|
printf("creating directory '%s' in %d\n", name, parent.id);
|
||||||
INode inode;
|
INode inode;
|
||||||
fs_make_dir(fs, &inode, &parent, name);
|
fs_make_dir(fs, &inode, &parent, name);
|
||||||
|
|
||||||
@ -139,9 +139,13 @@ int main(int argc, char *argv[])
|
|||||||
name += 1;
|
name += 1;
|
||||||
|
|
||||||
INode parent;
|
INode parent;
|
||||||
|
if (!path_copy[0]) {
|
||||||
|
fs_root(fs, &parent);
|
||||||
|
} else {
|
||||||
resolve_path(fs, &parent, path_copy);
|
resolve_path(fs, &parent, path_copy);
|
||||||
|
}
|
||||||
|
|
||||||
printf("creating file %s in %s.\n", name, path_copy);
|
printf("creating file %s in %s\n", name, *path_copy ? path_copy : "/");
|
||||||
INode inode;
|
INode inode;
|
||||||
fs_make_file(fs, &inode, &parent, name);
|
fs_make_file(fs, &inode, &parent, name);
|
||||||
|
|
||||||
@ -190,16 +194,12 @@ int main(int argc, char *argv[])
|
|||||||
size_t buffer_size = (file_size + 1) / 2;
|
size_t buffer_size = (file_size + 1) / 2;
|
||||||
uint16_t *buffer = calloc(buffer_size, sizeof(uint16_t));
|
uint16_t *buffer = calloc(buffer_size, sizeof(uint16_t));
|
||||||
size_t words_read = fread(buffer, sizeof(uint16_t), buffer_size, file);
|
size_t words_read = fread(buffer, sizeof(uint16_t), buffer_size, file);
|
||||||
printf("file_size = %zu, words_read = %zu, buffer_size = %zu\n",
|
|
||||||
file_size,
|
|
||||||
words_read,
|
|
||||||
buffer_size);
|
|
||||||
assert(words_read == buffer_size);
|
assert(words_read == buffer_size);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
fs_write(fs, &inode, buffer, buffer_size);
|
fs_write(fs, &inode, buffer, buffer_size);
|
||||||
|
|
||||||
printf("wrote %zu words to file %s.\n", words_read, vpath);
|
printf("imported %zu words to file %s\n", words_read, vpath);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
save(fs, &disk, disk_filename);
|
save(fs, &disk, disk_filename);
|
||||||
} else if (strcmp(cmd, "importb") == 0) {
|
} else if (strcmp(cmd, "importb") == 0) {
|
||||||
@ -235,7 +235,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
fs_write(fs, &inode, buffer, buffer_size);
|
fs_write(fs, &inode, buffer, buffer_size);
|
||||||
|
|
||||||
printf("wrote %zu words to file %s.\n", words_read, vpath);
|
printf("imported %zu words to file %s\n", words_read, vpath);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
save(fs, &disk, disk_filename);
|
save(fs, &disk, disk_filename);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
62
src/mkdisk.c
Normal file
62
src/mkdisk.c
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
assert(argc >= 2);
|
||||||
|
|
||||||
|
const char *path = argv[1];
|
||||||
|
|
||||||
|
FILE *file = fopen(path, "w");
|
||||||
|
assert(file);
|
||||||
|
|
||||||
|
size_t words = 0;
|
||||||
|
|
||||||
|
for (int i = 2; i < argc; ++i) {
|
||||||
|
char *input_filename = strdup(argv[i]);
|
||||||
|
|
||||||
|
char *sep = strchr(input_filename, ':');
|
||||||
|
|
||||||
|
if (sep)
|
||||||
|
*sep = '\0';
|
||||||
|
|
||||||
|
FILE *input_file = fopen(input_filename, "r");
|
||||||
|
assert(input_file);
|
||||||
|
|
||||||
|
if (sep) {
|
||||||
|
size_t offset = strtoull(sep + 1, nullptr, 16);
|
||||||
|
|
||||||
|
assert(words <= offset);
|
||||||
|
printf("padding %zu words\n", offset - words);
|
||||||
|
|
||||||
|
while (words < offset) {
|
||||||
|
fwrite((uint16_t[]) { 0 }, sizeof(uint16_t), 1, file);
|
||||||
|
words += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("appending %s at 0x%04lx\n", input_filename, words);
|
||||||
|
size_t bytes_written = 0;
|
||||||
|
int ch;
|
||||||
|
while ((ch = fgetc(input_file)) != EOF) {
|
||||||
|
fputc(ch, file);
|
||||||
|
bytes_written += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytes_written % 1) {
|
||||||
|
fputc('\0', file);
|
||||||
|
bytes_written += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
words += bytes_written / 2;
|
||||||
|
|
||||||
|
free(input_filename);
|
||||||
|
fclose(input_file);
|
||||||
|
};
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
@ -9,6 +9,7 @@ endif
|
|||||||
|
|
||||||
syn keyword vcKeyword nop hlt mov load store cmp cmov
|
syn keyword vcKeyword nop hlt mov load store cmp cmov
|
||||||
syn keyword vcKeyword or xor and not shr shl rshr rshl add sub
|
syn keyword vcKeyword or xor and not shr shl rshr rshl add sub
|
||||||
|
syn keyword vcKeyword dw
|
||||||
syn keyword vcOperator r0 r1 r2 r3 sp bp fl ip
|
syn keyword vcOperator r0 r1 r2 r3 sp bp fl ip
|
||||||
|
|
||||||
syn match vcOperator '|'
|
syn match vcOperator '|'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user