1
0
Fork 0
mirror of https://github.com/tailix/loadwarka.git synced 2024-12-02 14:05:11 -05:00

Remove old code

This commit is contained in:
Alex Kotov 2022-06-02 17:36:16 +03:00
parent 437cbc4ebe
commit 6c71a0345e
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
9 changed files with 0 additions and 506 deletions

View file

@ -1,26 +0,0 @@
#!/bin/sh
set -e
BIN='vendor/cross/root/bin'
SRC='src/x86'
CROSS="$BIN/i386-elf-"
STAGE1_LDFLAGS='--defsym=program_start=0x7c00'
STAGE2_LDFLAGS='--defsym=program_start=0x7e00'
STAGE1_OBJS="$SRC/common.o $SRC/stage1.o"
STAGE2_OBJS="$SRC/common.o $SRC/stage2.o $SRC/main.o"
./clean.sh
${CROSS}gcc -c $SRC/common.S -o $SRC/common.o
${CROSS}gcc -c $SRC/stage1.S -o $SRC/stage1.o
${CROSS}gcc -c $SRC/stage2.S -o $SRC/stage2.o
${CROSS}gcc -c $SRC/main.c -o $SRC/main.o
${CROSS}ld -T$SRC/linker.ld -o $SRC/stage1.bin $STAGE1_LDFLAGS $STAGE1_OBJS
${CROSS}ld -T$SRC/linker.ld -o $SRC/stage2.bin $STAGE2_LDFLAGS $STAGE2_OBJS
./loadwarka mbr mbr.bin $SRC/stage1.bin
cat mbr.bin $SRC/stage2.bin > disk.img

View file

@ -1,5 +0,0 @@
#!/bin/sh
set -e
rm -fv disk.img mbr.bin src/*.o src/x86/*.bin src/x86/*.o

7
run.sh
View file

@ -1,7 +0,0 @@
#!/bin/sh
set -e
./build.sh
qemu-system-i386 disk.img

View file

@ -1,125 +1,4 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <kernaux/mbr.h>
static bool create_mbr_file(
bool print_debug,
const char *output_filename,
uint32_t disk_id,
const char *bootstrap_filename
);
int main(const int argc, char **const argv)
{
if (argc < 2) {
fprintf(stderr, "Invalid usage\n");
return 1;
}
const char *const format = argv[1];
if (strcmp(format, "mbr") == 0) {
if (argc != 3 && argc != 4) {
fprintf(stderr, "Invalid usage\n");
return 1;
}
const char *const output_filename = argv[2];
const char *const bootstrap_filename = argc == 3 ? NULL :argv[3];
const bool result = create_mbr_file(
true,
output_filename,
0xf01834d0,
bootstrap_filename
);
if (!result) return 1;
} else {
fprintf(stderr, "Invalid format: %s\n", format);
}
return 0;
}
bool create_mbr_file(
const bool print_debug,
const char *const output_filename,
const uint32_t disk_id,
const char *const bootstrap_filename
) {
struct KernAux_Mbr mbr;
{
memset(&mbr, 0, sizeof(mbr));
mbr.info.magic = KERNAUX_MBR_MAGIC;
mbr.info.disk_id = disk_id;
mbr.info.reserved = 0;
// 00
mbr.info.entries[0].drive_attributes = 0;
// 00 02 00
mbr.info.entries[0].first_sector_chs_addr = 0x0200;
// 01
mbr.info.entries[0].partition_type = 1;
// 02 03 00
mbr.info.entries[0].last_sector_chs_addr = 0x0302;
// 01 00 00 00
mbr.info.entries[0].first_sector_lba_addr = 0x01;
// 80 00 00 00
mbr.info.entries[0].sectors_count = 0x80;
}
if (bootstrap_filename) {
FILE *fd = fopen(bootstrap_filename, "r");
if (fd == NULL) {
fprintf(stderr, "Can't open bootstrap file\n");
return false;
}
const size_t size = fread(&mbr.bootstrap, 1, KERNAUX_MBR_BOOTSTRAP_SIZE, fd);
if (size == 0) {
fprintf(stderr, "Empty bootstrap file\n");
return false;
}
if (!feof(fd)) {
fprintf(stderr, "Too long bootstrap file\n");
return false;
}
fclose(fd);
}
uint8_t *mbr_ptr = (uint8_t*)&mbr;
if (print_debug) {
for (size_t i = 0; i < 512 / 16; ++i) {
printf("%02x", mbr_ptr[i * 16]);
for (size_t j = 1; j < 16; ++j) {
printf(" %02x", mbr_ptr[i * 16 + j]);
}
printf("\n");
}
}
{
FILE *fd = fopen(output_filename, "wb");
if (fd == NULL) {
fprintf(stderr, "Can't open image file\n");
return false;
}
const size_t size = fwrite(mbr_ptr, 1, sizeof(mbr), fd);
if (size != sizeof(mbr)) {
fprintf(stderr, "Can't write image file\n");
return false;
}
fclose(fd);
}
return true;
}

View file

@ -1,101 +0,0 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define STACK_BASE 0x2000
.code16
.global newline
.global disk_number
.global restore_disk_number
.global hang
.global print_char
.global print_str
.global print_number
.section .rodata
newline: .string "\r\n"
.section .data
disk_number: .byte 0
.section .header
ljmp $0, $init
.align 4
.word program_size
init:
cli
xor %ax, %ax
mov %ax, %ss
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov $STACK_BASE, %sp
mov %dl, disk_number
ljmp $0, $_start
.section .text
restore_disk_number:
mov $disk_number, %bx
mov (%bx), %dl
ret
hang:
cli
hlt
jmp hang
do_ret:
ret
// AL - char
print_char:
mov $0x0E, %ah
mov $0x0001, %bx
int $0x10
ret
// SI - string pointer
print_str:
lodsb
test %al, %al
jz do_ret
call print_char
jmp print_str
// AX - number
print_number:
test %ax, %ax
jnz print_number_notnull
mov $0x0e, %ah
mov $'0', %al
int $0x10
ret
// AX - number
print_number_notnull:
test %ax, %ax
jz do_ret
// DX - dividend high (always zero)
// AX - dividend low
xor %dx, %dx
// BX - divisor (always 10)
mov $10, %bx
// AX - quotient
// DX - remainder
div %bx
push %dx
call print_number_notnull
pop %dx
mov $0x0e, %ah
mov %dl, %al
add $'0', %al
int $0x10
ret

View file

@ -1,28 +0,0 @@
OUTPUT_ARCH(i386)
OUTPUT_FORMAT(binary)
ENTRY(_start)
program_size = program_end - program_start;
SECTIONS
{
. = program_start;
.text : ALIGN(4)
{
*(.header);
*(.text);
}
.rodata : ALIGN(4)
{
*(.rodata);
}
.data : ALIGN(4)
{
*(.data);
}
program_end = .;
}

View file

@ -1,7 +0,0 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
int main()
{
}

View file

@ -1,181 +0,0 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define STAGE2_BASE 0x7e00
#define STAGE2_SIZE (STAGE2_BASE + 8)
.code16
.global _start
.section .rodata
size_str: .string "Stage 2 size: "
reading_sector: .string "Reading sector "
parenth: .string " ("
of: .string " of "
to_address: .string ") to address "
.section .text
_start:
mov $1, %ax
mov $STAGE2_BASE, %bx
xor %cx, %cx
call print_reading_state
mov $0x02, %ah
mov $1, %al // Sectors count
mov $0x80, %dl // Drive
mov $0, %ch // Cylinder
mov $0, %dh // Head
mov $2, %cl // Cylinder and sector
mov $STAGE2_BASE, %bx // Address
int $0x13
mov $STAGE2_SIZE, %bx
mov (%bx), %ax
call print_stage2_size
// DX - dividend high (always zero)
xor %dx, %dx
// AX - dividend low
mov $STAGE2_SIZE, %bx
mov (%bx), %ax
// BX - divisor (always 512)
mov $512, %bx
// AX - quotient
// DX - remainder
div %bx
test %dx, %dx
jz no_rem
inc %ax
no_rem:
mov %ax, %cx
mov $STAGE2_BASE, %bx
mov $1, %ax
// AX - current sector index
// BX - current address
// CX - total number of sectors
read_loop:
cmp %ax, %cx
je finish
add $512, %bx
inc %ax
push %ax
push %bx
push %cx
call print_reading_state
pop %cx
pop %bx
pop %ax
push %ax
push %bx
push %cx
add $1, %ax
mov %al, %cl // Cylinder and sector
mov $0x02, %ah
mov $1, %al // Sectors count
mov $0x80, %dl // Drive
mov $0, %ch // Cylinder
mov $0, %dh // Head
int $0x13
pop %cx
pop %bx
pop %ax
jmp read_loop
finish:
mov $newline, %si
call print_str
call restore_disk_number
ljmp $0, $STAGE2_BASE
// AX - size
print_stage2_size:
push %ax
mov $size_str, %si
call print_str
pop %ax
call print_number
mov $newline, %si
call print_str
ret
// AX - current sector index
// BX - current address
// CX - total number of sectors
print_reading_state:
push %ax
push %bx
push %cx
mov $reading_sector, %si
call print_str
pop %cx
pop %bx
pop %ax
push %ax
push %bx
push %cx
inc %ax
call print_number
mov $parenth, %si
call print_str
pop %cx
pop %bx
pop %ax
push %ax
push %bx
push %cx
call print_number
mov $of, %si
call print_str
pop %cx
// pop %bx
// pop %ax
// push %ax
// push %bx
push %cx
mov %cx, %ax
call print_number
mov $to_address, %si
call print_str
pop %cx
pop %bx
// pop %ax
// push %ax
push %bx
push %cx
mov %bx, %ax
call print_number
mov $newline, %si
call print_str
pop %cx
pop %bx
pop %ax
ret

View file

@ -1,30 +0,0 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
.code16
.global _start
.section .rodata
disk_number: .string "Disk number: "
main_returned: .string "Main returned\r\n"
.section .text
_start:
mov $disk_number, %si
call print_str
call restore_disk_number
xor %ax, %ax
mov %dl, %al
call print_number
mov $newline, %si
call print_str
call main
mov $main_returned, %si
call print_str
ljmp $0, $hang