clang-format -i *.cc *.c *.h
This commit is contained in:
178
polmon.cc
178
polmon.cc
@@ -43,27 +43,21 @@ namespace {
|
||||
#if WOZMON
|
||||
|
||||
int getchar() {
|
||||
register char c asm ("al");
|
||||
asm volatile (
|
||||
"movb $0x00, %%ah\n\t"
|
||||
"int $0x16"
|
||||
: "=r" (c)
|
||||
:: "ah", "cc"
|
||||
);
|
||||
register char c asm("al");
|
||||
asm volatile("movb $0x00, %%ah\n\t"
|
||||
"int $0x16"
|
||||
: "=r"(c)::"ah", "cc");
|
||||
return c;
|
||||
}
|
||||
|
||||
void putchar(int c) {
|
||||
asm volatile (
|
||||
"push %%bp \n\t"
|
||||
"mov %0, %%ax \n\t"
|
||||
"movb $0x0e, %%ah \n\t"
|
||||
"movb $0, %%bh \n\t"
|
||||
"int $0x10 \n\t"
|
||||
"pop %%bp \n\t"
|
||||
:: "r" (c)
|
||||
: "ax", "bh", "cc"
|
||||
);
|
||||
asm volatile("push %%bp \n\t"
|
||||
"mov %0, %%ax \n\t"
|
||||
"movb $0x0e, %%ah \n\t"
|
||||
"movb $0, %%bh \n\t"
|
||||
"int $0x10 \n\t"
|
||||
"pop %%bp \n\t" ::"r"(c)
|
||||
: "ax", "bh", "cc");
|
||||
}
|
||||
|
||||
#endif // WOZMON
|
||||
@@ -72,29 +66,28 @@ constexpr int kDumpSize = 16;
|
||||
|
||||
// arguments on the stack in reverse order
|
||||
extern "C" uint16_t Int80h(uint8_t fun, int nargs);
|
||||
asm (
|
||||
".section .text.Int80h \n"
|
||||
"Int80h: \n"
|
||||
" push %si \n"
|
||||
" push %bp \n"
|
||||
" mov %al, %ah \n"
|
||||
" mov %sp, %bp \n"
|
||||
" lea 6(%bp), %si \n" // 4 for pushed stuff, 2 for return addr
|
||||
"0: \n"
|
||||
" test %dx, %dx \n"
|
||||
" jz 1f \n"
|
||||
" push (%si) \n"
|
||||
" dec %dx \n"
|
||||
" add $2, %si \n"
|
||||
" jmp 0b \n"
|
||||
"1: \n"
|
||||
" int $0x80 \n"
|
||||
" mov %bp, %sp \n"
|
||||
" pop %bp \n"
|
||||
" pop %si \n"
|
||||
" ret"
|
||||
// return value in ax
|
||||
);
|
||||
asm(".section .text.Int80h \n"
|
||||
"Int80h: \n"
|
||||
" push %si \n"
|
||||
" push %bp \n"
|
||||
" mov %al, %ah \n"
|
||||
" mov %sp, %bp \n"
|
||||
" lea 6(%bp), %si \n" // 4 for pushed stuff, 2 for return addr
|
||||
"0: \n"
|
||||
" test %dx, %dx \n"
|
||||
" jz 1f \n"
|
||||
" push (%si) \n"
|
||||
" dec %dx \n"
|
||||
" add $2, %si \n"
|
||||
" jmp 0b \n"
|
||||
"1: \n"
|
||||
" int $0x80 \n"
|
||||
" mov %bp, %sp \n"
|
||||
" pop %bp \n"
|
||||
" pop %si \n"
|
||||
" ret"
|
||||
// return value in ax
|
||||
);
|
||||
|
||||
constexpr uint8_t kBackspace = 0x7f;
|
||||
constexpr uint8_t kOtherBackspace = 0x08;
|
||||
@@ -119,13 +112,9 @@ uint16_t ReadUintN(int n, const char* buf) {
|
||||
return out;
|
||||
}
|
||||
|
||||
uint8_t ReadUint8(const char* buf) {
|
||||
return ReadUintN(2, buf);
|
||||
}
|
||||
uint8_t ReadUint8(const char* buf) { return ReadUintN(2, buf); }
|
||||
|
||||
uint16_t ReadUint16(const char* buf) {
|
||||
return ReadUintN(4, buf);
|
||||
}
|
||||
uint16_t ReadUint16(const char* buf) { return ReadUintN(4, buf); }
|
||||
|
||||
void WriteHexNibble(uint8_t c) {
|
||||
if (c > 9) {
|
||||
@@ -146,35 +135,24 @@ void WriteUint16(uint16_t a) {
|
||||
}
|
||||
|
||||
uint8_t __get_far_u8__(uint16_t addr, uint16_t seg) {
|
||||
register uint16_t ad asm ("si") = addr;
|
||||
register uint16_t sg asm ("ds") = seg;
|
||||
register uint8_t ret asm ("al");
|
||||
asm (
|
||||
"lodsb \n\t"
|
||||
: "=r" (ret)
|
||||
: "r" (ad), "r" (sg)
|
||||
);
|
||||
register uint16_t ad asm("si") = addr;
|
||||
register uint16_t sg asm("ds") = seg;
|
||||
register uint8_t ret asm("al");
|
||||
asm("lodsb \n\t" : "=r"(ret) : "r"(ad), "r"(sg));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void __set_far_u8__(uint16_t addr, uint16_t seg, uint8_t val) {
|
||||
register uint16_t ad asm ("di") = addr;
|
||||
register uint16_t sg asm ("es") = seg;
|
||||
register uint8_t v asm ("al") = val;
|
||||
asm (
|
||||
"stosb \n\t"
|
||||
:: "r" (sg), "r" (ad), "r" (v)
|
||||
: "memory"
|
||||
);
|
||||
register uint16_t ad asm("di") = addr;
|
||||
register uint16_t sg asm("es") = seg;
|
||||
register uint8_t v asm("al") = val;
|
||||
asm("stosb \n\t" ::"r"(sg), "r"(ad), "r"(v) : "memory");
|
||||
}
|
||||
|
||||
__attribute__((noreturn))
|
||||
inline static void __basic__() {
|
||||
asm volatile (
|
||||
"movw $0x40, %ax \n\t"
|
||||
"mov %ax, %ds \n\t"
|
||||
"int $0x18"
|
||||
);
|
||||
__attribute__((noreturn)) inline static void __basic__() {
|
||||
asm volatile("movw $0x40, %ax \n\t"
|
||||
"mov %ax, %ds \n\t"
|
||||
"int $0x18");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
@@ -213,30 +191,26 @@ void DumpHex(uint16_t addr, uint16_t seg) {
|
||||
}
|
||||
|
||||
void ClearScreen() {
|
||||
asm volatile (
|
||||
"movw $0x0002, %%ax \n\t"
|
||||
"int $0x10"
|
||||
::: "ax", "cc"
|
||||
);
|
||||
asm volatile("movw $0x0002, %%ax \n\t"
|
||||
"int $0x10" ::
|
||||
: "ax", "cc");
|
||||
}
|
||||
|
||||
void Status(uint8_t status) {
|
||||
asm volatile (
|
||||
"xorb %%bh, %%bh \n\t"
|
||||
"movb $0x03, %%ah \n\t"
|
||||
"int $0x10 \n\t"
|
||||
"mov %%dx, %%di \n\t"
|
||||
"movb $0x02, %%ah \n\t"
|
||||
"movw $77, %%dx \n\t"
|
||||
"int $0x10 \n\t"
|
||||
"movb %0, %%al \n\t"
|
||||
"call %1 \n\t"
|
||||
"movb $0x02, %%ah \n\t"
|
||||
"movw %%di, %%dx \n\t"
|
||||
"int $0x10"
|
||||
:: "rm" (status), "l" (WriteUint8)
|
||||
: "ax", "bh", "dx", "cx", "di", "cc"
|
||||
);
|
||||
asm volatile("xorb %%bh, %%bh \n\t"
|
||||
"movb $0x03, %%ah \n\t"
|
||||
"int $0x10 \n\t"
|
||||
"mov %%dx, %%di \n\t"
|
||||
"movb $0x02, %%ah \n\t"
|
||||
"movw $77, %%dx \n\t"
|
||||
"int $0x10 \n\t"
|
||||
"movb %0, %%al \n\t"
|
||||
"call %1 \n\t"
|
||||
"movb $0x02, %%ah \n\t"
|
||||
"movw %%di, %%dx \n\t"
|
||||
"int $0x10" ::"rm"(status),
|
||||
"l"(WriteUint8)
|
||||
: "ax", "bh", "dx", "cx", "di", "cc");
|
||||
}
|
||||
|
||||
bool ParseCommand(const char* buf, uint16_t& cur_addr, uint16_t& cur_seg) {
|
||||
@@ -244,14 +218,14 @@ bool ParseCommand(const char* buf, uint16_t& cur_addr, uint16_t& cur_seg) {
|
||||
for (const char* ptr = buf; *ptr;) {
|
||||
if (*ptr == 's') {
|
||||
cur_addr = 0;
|
||||
cur_seg = ReadUint16(ptr+1);
|
||||
cur_seg = ReadUint16(ptr + 1);
|
||||
ptr += 5;
|
||||
} else if (*ptr == '$') {
|
||||
__basic__();
|
||||
} else if (*ptr == 'j') {
|
||||
dump = false;
|
||||
ptr++;
|
||||
auto jump = reinterpret_cast<uint16_t(*)()>(cur_addr);
|
||||
auto jump = reinterpret_cast<uint16_t (*)()>(cur_addr);
|
||||
uint16_t ret = jump();
|
||||
WriteUint16(ret);
|
||||
putchar('\r');
|
||||
@@ -269,17 +243,14 @@ bool ParseCommand(const char* buf, uint16_t& cur_addr, uint16_t& cur_seg) {
|
||||
continue;
|
||||
}
|
||||
uint16_t d = ReadUint16(ptr);
|
||||
asm volatile ("push %0" :: "r" (d));
|
||||
asm volatile("push %0" ::"r"(d));
|
||||
nargs++;
|
||||
ptr += 4;
|
||||
}
|
||||
uint16_t ret = Int80h(fun, nargs);
|
||||
asm volatile (
|
||||
"shl %0 \n\t"
|
||||
"add %0, %%sp"
|
||||
:: "r"(nargs)
|
||||
);
|
||||
WriteUint16(ret);
|
||||
asm volatile("shl %0 \n\t"
|
||||
"add %0, %%sp" ::"r"(nargs));
|
||||
WriteUint16(ret);
|
||||
putchar('\r');
|
||||
putchar('\n');
|
||||
#endif // INT80H
|
||||
@@ -324,7 +295,7 @@ void polmon() {
|
||||
char* inptr = inbuf;
|
||||
|
||||
ClearScreen();
|
||||
#if SHOWTITLE
|
||||
#if SHOWTITLE
|
||||
puts("PolMon 0.2\r\n");
|
||||
#endif // SHOWTITLE
|
||||
DisplayPrompt();
|
||||
@@ -368,13 +339,10 @@ void polmon() {
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
polmon();
|
||||
}
|
||||
int main() { polmon(); }
|
||||
|
||||
#if BOOTSTRAP
|
||||
__attribute__((section(".init"), noreturn, used))
|
||||
void _start() {
|
||||
__attribute__((section(".init"), noreturn, used)) void _start() {
|
||||
main();
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
Reference in New Issue
Block a user