-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
282 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
all: | ||
fasm cmd.asm | ||
|
||
clean: | ||
|
||
install: | ||
install: all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
format ELF | ||
entry start | ||
format COFF | ||
|
||
include 'builtins.inc' | ||
section '.text' code | ||
|
||
start: | ||
public main | ||
main: | ||
int 0x2A | ||
|
||
int 0x2A | ||
section '.data' data | ||
|
||
INCLUDE 'builtins.inc' |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
INCDIR = $(DESTDIR)/usr/include | ||
|
||
INCS = coff.h | ||
|
||
.PHONY: all | ||
all: | ||
|
||
.PHONY: clean | ||
clean: | ||
|
||
.PHONY: install | ||
install: $(INCS) | ||
@ mkdir -p $(INCDIR) | ||
install $< $(INCDIR) | ||
|
||
.PHONY: all clean install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#ifndef COFF_H | ||
# define COFF_H 1 | ||
|
||
# include <stdint.h> | ||
|
||
typedef struct filehdr | ||
{ | ||
uint16_t f_magic; | ||
uint16_t f_nscns; | ||
int32_t f_timdat; | ||
int32_t f_symptr; | ||
int32_t f_nsyms; | ||
uint16_t f_opthdr; | ||
uint16_t f_flags; | ||
} FILHDR; | ||
|
||
# define FILHSZ sizeof(FILHDR) | ||
|
||
# define F_MACH_I386 0x014c | ||
|
||
# define F_RELFLG 0x0001 | ||
# define F_EXEC 0x0002 | ||
# define F_LNNO 0x0004 | ||
# define F_LSYMS 0x0008 | ||
# define F_LITTLE 0x0100 | ||
# define F_BIG 0x0200 | ||
# define F_SYMMERGE 0x1000 | ||
|
||
typedef struct aouthdr | ||
{ | ||
int16_t magic; | ||
int16_t vstamp; | ||
int32_t tsize; | ||
int32_t dsize; | ||
int32_t bsize; | ||
int32_t entry; | ||
int32_t text_start; | ||
int32_t data_start; | ||
} AOUTHDR; | ||
|
||
# define AOUTHSZ sizeof(AOUTHDR) | ||
|
||
# define OMAGIC 0404 | ||
# define ZMAGIC 0413 | ||
# define STMAGIC 0401 | ||
# define SHMAGIC 0443 | ||
|
||
typedef struct scnhdr | ||
{ | ||
int8_t s_name[8]; | ||
int32_t s_paddr; | ||
int32_t s_vaddr; | ||
int32_t s_size; | ||
int32_t s_scnptr; | ||
int32_t s_relptr; | ||
int32_t s_lnnoptr; | ||
uint16_t s_nreloc; | ||
uint16_t s_nlnno; | ||
int32_t s_flags; | ||
} SCNHDR; | ||
|
||
# define SCNHSZ sizeof(SCNHDR) | ||
|
||
# define STYP_REG 0x000 | ||
# define STYP_DSECT 0x001 | ||
# define STYP_NOLOAD 0x002 | ||
# define STYP_GROUP 0x004 | ||
# define STYP_PAD 0x008 | ||
# define STYP_COPY 0x010 | ||
# define STYP_TEXT 0x020 | ||
# define STYP_DATA 0x040 | ||
# define STYP_BSS 0x080 | ||
# define STYP_INFO 0x200 | ||
# define STYP_OVER 0x400 | ||
# define STYP_LIB 0x800 | ||
|
||
typedef struct reloc | ||
{ | ||
uint32_t r_vaddr; | ||
uint32_t r_symndx; | ||
uint16_t r_type; | ||
} RELOC; | ||
# define RELSZ 10 | ||
|
||
# define R_ABS 0x000 | ||
# define R_DIR16 0x001 | ||
# define R_REL16 0x002 | ||
# define R_DIR32 0x006 | ||
# define R_PCRLONG 0x024 | ||
|
||
typedef struct lineno | ||
{ | ||
union | ||
{ | ||
uint32_t l_symndx; | ||
uint32_t l_paddr; | ||
} l_addr; | ||
uint16_t l_lnno; | ||
} LINENO; | ||
|
||
# define LINESZ 6 | ||
|
||
#endif /* !COFF_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
AS = fasm | ||
RM = rm -f | ||
INSTALL = install | ||
|
||
KERNEL = vmstupid.sys | ||
SRCS = kernel.asm \ | ||
const.inc \ | ||
mm/mm.inc | ||
|
||
.PHONY: all | ||
all: $(KERNEL) | ||
|
||
$(KERNEL): $(SRCS) | ||
$(AS) kernel.asm $@ | ||
|
||
.PHONY: clean | ||
clean: | ||
$(RM) $(KERNEL) | ||
|
||
.PHONY: install | ||
install: $(KERNEL) | ||
@ mkdir -p $(DESTDIR) | ||
install $< $(DESTDIR) | ||
|
||
.PHONY: all clean | ||
AS = fasm | ||
RM = rm -f | ||
INSTALL = install | ||
|
||
KERNEL = vmstupid.sys | ||
SRCS = kernel.asm \ | ||
const.inc \ | ||
mm/mm.inc | ||
|
||
.PHONY: all | ||
all: $(KERNEL) | ||
|
||
$(KERNEL): $(SRCS) | ||
$(AS) kernel.asm $@ | ||
|
||
.PHONY: clean | ||
clean: | ||
$(RM) $(KERNEL) | ||
|
||
.PHONY: install | ||
install: $(KERNEL) | ||
@ mkdir -p $(DESTDIR) | ||
install $< $(DESTDIR) | ||
|
||
.PHONY: all clean install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
INCLUDE 'const.inc' | ||
|
||
ORG KBASE | ||
USE32 | ||
|
||
jmp kmain | ||
|
||
INCLUDE 'mm/mm.inc' | ||
|
||
kmain: | ||
nop | ||
|
||
_edata: | ||
|
||
; BSS | ||
rb 0x4000 | ||
|
||
_end: | ||
INCLUDE 'const.inc' | ||
|
||
ORG KBASE | ||
USE32 | ||
|
||
jmp kmain | ||
|
||
INCLUDE 'mm/mm.inc' | ||
|
||
kmain: | ||
nop | ||
|
||
_edata: | ||
|
||
; BSS | ||
rb 0x4000 | ||
|
||
_end: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <coff.h> | ||
|
||
static char *prg_name; | ||
static char *outfile = "a.out"; | ||
|
||
static void | ||
usage(int retcode) | ||
{ | ||
if (retcode == EXIT_FAILURE) | ||
{ | ||
fprintf(stderr, "Try '%s -h' form more information.\n", prg_name); | ||
} | ||
else | ||
{ | ||
printf("Usage: %s [-hV] [-o outfile] [OBJS...]\n", prg_name); | ||
printf("\t-h\tdisplay this help and exit\n"); | ||
printf("\t-V\toutput version information\n"); | ||
printf("\t-o outfile\tout file (default: %s)\n", outfile); | ||
|
||
printf("\nReport bugs to <%s>\n", MK_BUGREPORT); | ||
} | ||
|
||
exit(retcode); | ||
} | ||
|
||
static void | ||
version(void) | ||
{ | ||
printf("%s commit %s\n", prg_name, MK_COMMIT); | ||
exit(EXIT_SUCCESS); | ||
} | ||
|
||
int | ||
main(int argc, char **argv) | ||
{ | ||
FILE *fp; | ||
FILHDR fhdr; | ||
SCNHDR shdr; | ||
AOUTHDR aout; | ||
|
||
prg_name = argv[0]; | ||
|
||
while ((argc > 1) && (argv[1][0] == '-')) | ||
{ | ||
switch (argv[1][1]) | ||
{ | ||
case 'h': | ||
usage(EXIT_SUCCESS); | ||
break; | ||
case 'V': | ||
version(); | ||
break; | ||
case 'o': | ||
argv++; | ||
argc--; | ||
if (argc <= 1) usage(EXIT_FAILURE); | ||
outfile = argv[1]; | ||
break; | ||
} | ||
|
||
argv++; | ||
argc--; | ||
} | ||
|
||
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) | ||
{ | ||
fread(&aout, 1, AOUTHSZ, fp); | ||
} | ||
|
||
fread(&shdr, 1, SCNHSZ, fp); | ||
printf("name: %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("flags: 0x%x\n", shdr.s_flags); | ||
|
||
fclose(fp); | ||
|
||
return (EXIT_SUCCESS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.