kbd stuff needs volatile, start structure changes
This commit is contained in:
7
include/disk.h
Normal file
7
include/disk.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
void InitDisk();
|
||||
|
||||
uint32_t Disk_ReadSector(uint8_t unit, uint8_t *buffer, uint32_t sector, uint32_t count);
|
||||
uint32_t Disk_WriteSector(uint8_t unit, uint8_t *buffer, uint32_t sector, uint32_t count);
|
36
include/file.h
Normal file
36
include/file.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include "file_s.h"
|
||||
|
||||
// Returns 0 on success, non-zero error code on error. Fills provided struct FILE
|
||||
int file_open(FILE *file, char *path, char mode);
|
||||
|
||||
// Returns 0 on success, non-zero error code on error.
|
||||
int file_seek(FILE *file, uint32_t offset);
|
||||
|
||||
// Returns 0 on error, bytes read on success.
|
||||
int file_read(FILE *file, uint8_t *dest, uint32_t len);
|
||||
|
||||
// Returns 0 on error, bytes written on success.
|
||||
int file_write(FILE *file, uint8_t *src, uint32_t len);
|
||||
|
||||
void file_close(FILE *file);
|
||||
|
||||
// Returns 0 on success, non-zero error code on error. Fills provided struct DIR
|
||||
int dir_open(DIR *dir, char *path);
|
||||
|
||||
// Return 0 on success, non-zero error code on error. Fills provided struct dirent.
|
||||
int dir_nextentry(DIR *dir, dirent *ent);
|
||||
|
||||
void dir_close(DIR *dir);
|
||||
|
||||
// Returns 0 on success, non-zero error code on error. Fills provided struct dirent.
|
||||
int path_getinfo(char *path, dirent *ent);
|
||||
|
||||
// Returns 0 on success, non-zero error code on error.
|
||||
int path_mkdir(char *path);
|
||||
|
||||
// Returns 0 on success, non-zero error code on error.
|
||||
int path_rmdir(char *path);
|
||||
|
||||
// Returns 0 on success, non-zero error code on error.
|
||||
int path_rmfile(char *path);
|
31
include/file_s.h
Normal file
31
include/file_s.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct FILE {
|
||||
uint8_t filesystem_id;
|
||||
uint8_t bytes[0x3F];
|
||||
} __attribute__((__packed__)) FILE;
|
||||
|
||||
typedef struct DIR {
|
||||
uint8_t filesystem_id;
|
||||
uint8_t bytes[0x3F];
|
||||
} __attribute__((__packed__)) DIR;
|
||||
|
||||
typedef enum filetype {
|
||||
FT_UNKNOWN,
|
||||
FT_REG,
|
||||
FT_DIR
|
||||
} filetype;
|
||||
|
||||
typedef struct dirent {
|
||||
filetype type;
|
||||
uint32_t size;
|
||||
uint32_t last_modified;
|
||||
uint32_t last_accessed;
|
||||
uint32_t created;
|
||||
uint8_t namelen;
|
||||
char name[255];
|
||||
} dirent;
|
||||
|
||||
#define OPENREAD 1
|
||||
#define OPENWRITE 2
|
32
include/fs.h
Normal file
32
include/fs.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "file_s.h"
|
||||
|
||||
typedef struct filesystem {
|
||||
uint32_t resv0;
|
||||
uint32_t type;
|
||||
struct fs_operations {
|
||||
int (*file_open)(uint8_t *, FILE *, char *, char);
|
||||
int (*file_seek)(uint8_t *, FILE *, uint32_t);
|
||||
int (*file_read)(uint8_t *, FILE *, uint8_t *, uint32_t);
|
||||
int (*file_write)(uint8_t *, FILE *, uint8_t *, uint32_t);
|
||||
void (*file_close)(uint8_t *, FILE *);
|
||||
int (*dir_open)(uint8_t *, DIR *, char *);
|
||||
int (*dir_nextentry)(uint8_t *, DIR *, dirent *);
|
||||
void (*dir_close)(uint8_t *, DIR *);
|
||||
int (*path_getinfo)(uint8_t *, char *, dirent *);
|
||||
int (*path_mkdir)(uint8_t *, char *);
|
||||
int (*path_rmdir)(uint8_t *, char *);
|
||||
int (*path_rmfile)(uint8_t *, char *);
|
||||
void (*endfs)(uint8_t *);
|
||||
} ops;
|
||||
uint8_t labellen;
|
||||
char label[255];
|
||||
uint8_t fs_data[2048-4-4-44-256];
|
||||
} __attribute__((packed)) filesystem;
|
||||
|
||||
filesystem *GetFilesystem(uint8_t idx);
|
||||
filesystem *GetActiveFilesystem();
|
||||
uint8_t GetActiveFilesystemId();
|
||||
filesystem *SetActiveFilesystem(uint8_t idx);
|
||||
void ActiveFilesystemBitmap(char *bitmap);
|
17
include/helper.h
Normal file
17
include/helper.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include "interrupt.h"
|
||||
#include "v86defs.h"
|
||||
#include "file.h"
|
||||
|
||||
void V8086Int(uint8_t interrupt, union V86Regs_t *regs);
|
||||
|
||||
void SetVideo25Lines();
|
||||
void SetVideo50Lines();
|
||||
void SetCursorDisabled();
|
||||
|
||||
uint16_t *nextLine(uint16_t *p, uint16_t *b);
|
||||
void trimPath(char *path, char *buff, uint32_t maxLen);
|
||||
|
||||
void GetFileList(DIR *dir, dirent *entries, int32_t *entCount, int32_t maxEntries);
|
13
include/interrupt.h
Normal file
13
include/interrupt.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
struct interrupt_frame {
|
||||
uint32_t eip, cs;
|
||||
uint32_t eflags;
|
||||
uint32_t esp, ss;
|
||||
uint32_t es, ds, fs, gs;
|
||||
};
|
||||
__attribute__ ((interrupt))
|
||||
void gpf_handler_v86(struct interrupt_frame volatile *frame, unsigned long error_code);
|
||||
|
||||
void setup_interrupts();
|
48
include/kbd.h
Normal file
48
include/kbd.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "interrupt.h"
|
||||
|
||||
__attribute((__no_caller_saved_registers__))
|
||||
void kbd_wait();
|
||||
|
||||
__attribute((__no_caller_saved_registers__))
|
||||
void kbd_clear();
|
||||
|
||||
__attribute((__no_caller_saved_registers__))
|
||||
uint8_t get_key();
|
||||
|
||||
__attribute((__no_caller_saved_registers__))
|
||||
uint16_t get_scancode();
|
||||
|
||||
__attribute__ ((interrupt))
|
||||
void keyboardHandler(struct interrupt_frame volatile *frame);
|
||||
|
||||
typedef enum {
|
||||
KEY_ESCAPE=0x01, KEY_1=0x02, KEY_2=0x03,
|
||||
KEY_3=0x04, KEY_4=0x05, KEY_5=0x06, KEY_6=0x07,
|
||||
KEY_7=0x08, KEY_8=0x09, KEY_9=0x0A, KEY_0=0x0B,
|
||||
KEY_HYPHEN=0x0C, KEY_EQUALS=0x0D, KEY_BACKSPACE=0x0E, KEY_TAB=0x0F,
|
||||
KEY_Q=0x10, KEY_W=0x11, KEY_E=0x12, KEY_R=0x13,
|
||||
KEY_T=0x14, KEY_Y=0x15, KEY_U=0x16, KEY_I=0x17,
|
||||
KEY_O=0x18, KEY_P=0x19, KEY_SQBRKLEFT=0x1A, KEY_SQBRKRIGHT=0x1B,
|
||||
KEY_ENTER=0x1C, KEY_CTRL=0x1D, KEY_A=0x1E, KEY_S=0x1F,
|
||||
KEY_D=0x20, KEY_F=0x21, KEY_G=0x22, KEY_H=0x23,
|
||||
KEY_J=0x24, KEY_K=0x25, KEY_L=0x26, KEY_SEMICOLON=0x27,
|
||||
KEY_QUOTE=0x28, KEY_BACKTICK=0x29, KEY_SHIFTLEFT=0x2A, KEY_BACKSTROKE=0x2B,
|
||||
KEY_Z=0x2C, KEY_X=0x2D, KEY_C=0x2E, KEY_V=0x2F,
|
||||
KEY_B=0x30, KEY_N=0x31, KEY_M=0x32, KEY_COMMA=0x33,
|
||||
KEY_PERIOD=0x34, KEY_SLASH=0x35, KEY_SHIFTRIGHT=0x36, KEY_KPDSTAR=0x37,
|
||||
KEY_ALT=0x38, KEY_SPACE=0x39, KEY_CAPSLOCK=0x3A, KEY_F1=0x3B,
|
||||
KEY_F2=0x3C, KEY_F3=0x3D, KEY_F4=0x3E, KEY_F5=0x3F,
|
||||
KEY_F6=0x40, KEY_F7=0x41, KEY_F8=0x42, KEY_F9=0x43,
|
||||
KEY_F10=0x44, KEY_NUMLOCK=0x45, KEY_SCROLLLOCK=0x46, KEY_KPD7=0x47,
|
||||
KEY_KPD8=0x48, KEY_KPD9=0x49, KEY_KPDMINUS=0x4A, KEY_KPD4=0x4B,
|
||||
KEY_KPD5=0x4C, KEY_KPD6=0x4D, KEY_KPDPLUS=0x4E, KEY_KPD1=0x4F,
|
||||
KEY_KPD2=0x50, KEY_KPD3=0x51, KEY_KPD0=0x52, KEY_KPDPERIOD=0x53,
|
||||
KEY_F11=0x57, KEY_F12=0x58,
|
||||
KEY_DOWN=KEY_KPD2,KEY_UP=KEY_KPD8,
|
||||
KEY_LEFT=KEY_KPD4,KEY_RIGHT=KEY_KPD6,
|
||||
KEY_PGUP=KEY_KPD9,KEY_PGDOWN=KEY_KPD3,
|
||||
KEY_HOME=KEY_KPD7,KEY_END=KEY_KPD1,
|
||||
KEY_INSERT=KEY_KPD0, KEY_DELETE=KEY_KPDPERIOD
|
||||
} SCANCODE;
|
3
include/paging.h
Normal file
3
include/paging.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#include <stdint.h>
|
||||
|
||||
void init_paging();
|
8
include/print.h
Normal file
8
include/print.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <stdint.h>
|
||||
|
||||
uintptr_t printByte(uint8_t v, uint16_t *buff);
|
||||
uintptr_t printWord(uint16_t v, uint16_t *buff);
|
||||
uintptr_t printDword(uint32_t v, uint16_t *buff);
|
||||
uintptr_t printStr(char *v, uint16_t *buff);
|
||||
uintptr_t printDec(uint32_t v, uint16_t *buff);
|
||||
uintptr_t printChar(char v, uint16_t *buff);
|
12
include/progs.h
Normal file
12
include/progs.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include "print.h"
|
||||
#include "kbd.h"
|
||||
#include "v86defs.h"
|
||||
#include "helper.h"
|
||||
#include "file.h"
|
||||
|
||||
void HexEditor(char *path);
|
||||
void TextViewTest(char *path);
|
||||
void ProgramLoadTest(char *path);
|
8
include/tests.h
Normal file
8
include/tests.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "print.h"
|
||||
#include "interrupt.h"
|
||||
#include "v86defs.h"
|
||||
#include "kbd.h"
|
||||
#include "helper.h"
|
||||
|
||||
void RunTests();
|
1
include/tss.h
Normal file
1
include/tss.h
Normal file
@@ -0,0 +1 @@
|
||||
void setup_tss();
|
84
include/v86defs.h
Normal file
84
include/v86defs.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
// Labels of v8086 programs
|
||||
// TODO Remove these and use
|
||||
// a single define for location?
|
||||
extern void v86Test();
|
||||
extern void v86TransFlag();
|
||||
extern void v86Interrupt();
|
||||
extern void v86TextMode();
|
||||
extern void v86DiskOp();
|
||||
extern void v86DiskGetGeometry();
|
||||
extern void v86DiskReadCHS();
|
||||
|
||||
union __attribute((__packed__)) V86Regs_t {
|
||||
struct dword_regs {
|
||||
uint32_t ebp;
|
||||
uint32_t edi;
|
||||
uint32_t esi;
|
||||
uint32_t ebx;
|
||||
uint32_t edx;
|
||||
uint32_t ecx;
|
||||
uint32_t eax;
|
||||
} d;
|
||||
struct word_regs {
|
||||
uint16_t bp, _upper_bp;
|
||||
uint16_t di, _upper_di;
|
||||
uint16_t si, _upper_si;
|
||||
uint16_t bx, _upper_bx;
|
||||
uint16_t dx, _upper_dx;
|
||||
uint16_t cx, _upper_cx;
|
||||
uint16_t ax, _upper_ax;
|
||||
} w;
|
||||
struct byte_regs {
|
||||
uint32_t ebp;
|
||||
uint32_t edi;
|
||||
uint32_t esi;
|
||||
uint8_t bl, bh;
|
||||
uint16_t _upper_bx;
|
||||
uint8_t dl, dh;
|
||||
uint16_t _upper_dx;
|
||||
uint8_t cl, ch;
|
||||
uint16_t _upper_cx;
|
||||
uint8_t al, ah;
|
||||
uint16_t _upper_ax;
|
||||
} h;
|
||||
};
|
||||
|
||||
extern uint32_t enter_v86(uint32_t ss, uint32_t esp, uint32_t cs, uint32_t eip, union V86Regs_t *regs);
|
||||
|
||||
void V8086Int(uint8_t interrupt, union V86Regs_t *regs);
|
||||
|
||||
struct __attribute((__packed__)) Int13DiskPacket_t {
|
||||
uint8_t size; // 0x10
|
||||
uint8_t reserved; // 0x00
|
||||
uint16_t blocks;
|
||||
uint32_t transfer_buffer; // 0x2300:0000
|
||||
uint64_t start_block;
|
||||
};
|
||||
|
||||
extern struct Int13DiskPacket_t v86disk_addr_packet;
|
||||
|
||||
/* Real Mode helper macros */
|
||||
/* segment:offset pair */
|
||||
typedef uint32_t FARPTR;
|
||||
|
||||
/* Make a FARPTR from a segment and an offset */
|
||||
#define MK_FP(seg, off) ((FARPTR) (((uint32_t) (seg) << 16) | (uint16_t) (off)))
|
||||
|
||||
/* Extract the segment part of a FARPTR */
|
||||
#define FP_SEG(fp) (((FARPTR) fp) >> 16)
|
||||
|
||||
/* Extract the offset part of a FARPTR */
|
||||
#define FP_OFF(fp) (((FARPTR) fp) & 0xffff)
|
||||
|
||||
/* Convert a segment:offset pair to a linear address */
|
||||
#define FP_TO_LINEAR(seg, off) ((void*)(uintptr_t)((((uint32_t)seg) << 4) + ((uint32_t)off)))
|
||||
|
||||
#define EFLAG_IF ((uint32_t)1 << 9)
|
||||
#define EFLAG_VM ((uint32_t)1 << 17)
|
||||
|
||||
FARPTR i386LinearToFp(void *ptr);
|
||||
|
||||
void ensure_v86env();
|
Reference in New Issue
Block a user