chore: sync repo

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-06-14 05:32:46 +02:00
parent 8589a5c433
commit c682f38209
4 changed files with 74 additions and 52 deletions

View file

@ -2,16 +2,26 @@
#include <stdio.h>
#include <coff.h>
# define BASE_ADDRESS = 0x100000
static char *prg_name;
static char *outfile = "a.out";
typedef struct {
size_t size;
uint8_t *raw;
} Section;
typedef struct object {
size_t section_count;
Section *sections;
struct object *next;
} Object;
typedef struct {
} Object;
} Symtab;
static void
usage(int retcode)
@ -36,7 +46,7 @@ usage(int retcode)
static void
version(void)
{
printf("%s commit %s\n", prg_name, MK_COMMIT);
printf("%s (%s) %s", prg_name, MK_PACKAGE, MK_COMMIT);
exit(EXIT_SUCCESS);
}
@ -77,49 +87,7 @@ main(int argc, char **argv)
if (argc <= 1) usage(EXIT_FAILURE);
fp = fopen(argv[1], "rb");
if (fp == NULL)
{
return (EXIT_FAILURE);
}
fread(&fhdr, 1, FILHSZ, fp);
printf("magic: 0x%hx\n", fhdr.f_magic);
printf("n section: %hd\n", fhdr.f_nscns);
printf("symtab: 0x%X\n", fhdr.f_symptr);
printf("sym entries: %d\n", fhdr.f_nsyms);
printf("optional hdr size: %hu\n", fhdr.f_opthdr);
printf("flags: 0x%hx\n", fhdr.f_flags);
if (fhdr.f_opthdr > 0)
{
buffer = malloc(fhdr.f_opthdr);
fread(buffer, 1, fhdr.f_opthdr, fp);
free(buffer);
}
for (idx = 0; idx < fhdr.f_nscns; idx++)
{
fread(&shdr, 1, SCNHSZ, fp);
printf("Section: %c%c%c%c%c%c%c%c\n", shdr.s_name[0], shdr.s_name[1],shdr.s_name[2],shdr.s_name[3],shdr.s_name[4],shdr.s_name[5],shdr.s_name[6],shdr.s_name[7]);
printf("\tflags: 0x%x\n", shdr.s_flags);
printf("\tsize: %d\n", shdr.s_size);
}
fseek(fp, fhdr.f_symptr, SEEK_SET);
for (idx = 0; idx < fhdr.f_nsyms; idx++)
{
fread(&entry, 1, SYMESZ, fp);
printf("name: %c%c%c%c%c%c%c%c\n", entry.n_name[0], entry.n_name[1],entry.n_name[2],entry.n_name[3],entry.n_name[4],entry.n_name[5],entry.n_name[6],entry.n_name[7]);
printf("\tvalue: %d\n", entry.n_value);
printf("\tscnum: %hd\n", entry.n_scnum);
printf("\ttype: %hd\n", entry.n_type);
printf("\tsclass: %d\n", entry.n_sclass);
printf("\tnumaux: %d\n", entry.n_numaux);
}
fclose(fp);
return (EXIT_SUCCESS);
}

View file

@ -71,6 +71,8 @@ main(int argc, char **argv)
FILE *fp;
int idx;
time_t timedat;
char *string_table;
size_t sz_stable;
#ifndef __stupidos__
prg_name = basename(argv[0]);
@ -139,6 +141,22 @@ main(int argc, char **argv)
printf(" Flags: 0x%hx\n\n", file_header.f_flags);
}
if (display_optional_header)
{
if (file_header.f_opthdr)
{
fread(&aout_header, 1, AOUTHSZ, fp);
printf("A.out header\n");
printf(" Magic: %hx\n", aout_header.magic);
printf(" Entry: 0x%08X\n", aout_header.entry);
printf("\n");
}
else
{
printf("There are no optional header.\n\n");
}
}
if (display_sections)
{
fseek(fp, file_header.f_opthdr + FILHSZ, SEEK_SET);
@ -177,6 +195,11 @@ main(int argc, char **argv)
if (display_symbol_table)
{
fseek(fp, 0L, SEEK_END);
sz_stable = ftell(fp) - file_header.f_symptr + (SYMESZ * file_header.f_nsyms);
string_table = malloc(sz_stable);
fseek(fp, file_header.f_symptr + (SYMESZ * file_header.f_nsyms), SEEK_SET);
fread(string_table, 1, sz_stable, fp);
printf("Symbol table contains %d entries:\n", file_header.f_nsyms);
printf(" Num: Value Type Name\n");
assert(sizeof(SYMENT) == SYMESZ);
@ -186,7 +209,18 @@ main(int argc, char **argv)
fread(&sym_entry, 1, SYMESZ, fp);
memset(name, 0, 9);
memcpy(name, sym_entry.n_name, 8);
printf(" %d: %08x %hd %s\n", idx, sym_entry.n_value, sym_entry.n_type, name);
if (sym_entry.n_zeroes == 0)
{
}
printf(" %2d: %08x %hd ", idx, sym_entry.n_value, sym_entry.n_type);
if (sym_entry.n_zeroes)
{
printf("%s\n", name);
}
else
{
printf("%s\n", string_table + sym_entry.n_offset);
}
}
}

View file

@ -81,6 +81,7 @@ fat_search_root:
ret
.file_found:
mov ax, [es:di + fat_entry.start]
mov ebx, [es:di + fat_entry.size]
clc
ret

View file

@ -55,11 +55,14 @@ _start:
@@:
; detect filesystem (FAT12/16 or StpdFS)
; load kernel from filesystem
; +---------+--------+---------+
; | bootsec | sect 1 | stpd sb |
; +---------+--------+---------+
; 0 512 1024
; StupidFS layout
; +---------+---------+---------....--+----....---+
; | bootsec | stpd sb | i-nodes ... | data |
; +---------+---------+---------0...--+----....---+
; 0 512 1024 XXXX XXXX
;
; for now fat12 is asumed
call fat_load_root
@ -67,8 +70,12 @@ _start:
mov si, szKernelFile
call fat_search_root
jc .error_not_found
mov [pKernelStartFat], ax
mov [uKernelSize], ebx
push ebx
mov si, szMsgKernelFound
call bios_log
; load fat
xor ax, ax
@ -141,9 +148,11 @@ uDrive rb 1
bDriveLBA db FALSE
pKernelStartFat dw 0
uKernelSize dd 0
szMsgStage2 db "StupidOS Loader", 0
szKernelFile db "VMSTUPIDSYS", 0
szMsgKernelFound db "Kernel found, size: %x", 0
szMsgErrorA20 db "ERROR: can't enable a20 line", 0
szMsgErrorMemory db "ERROR: can't detect available memory", 0
szMsgErrorSector db "ERROR: reading sector", CR, LF, 0
@ -170,6 +179,16 @@ common32:
; identity map first 1MB
; map kernel to 0xC000000
; -----------------------
mov edi, boot_768_page_table
mov esi, 0
mov ecx, 1023
.1:
cmp esi, MULTIBOOT_BASE
jl .2
.2:
.3:
push STPDBOOT_MAGIC